aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg KH <gregkh@suse.de>2005-09-12 15:45:04 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2005-09-12 15:45:04 -0400
commitd58dde0f552a5c5c4485b962d8b6e9dd54fefb30 (patch)
treed9a7e35eb88fea6265d5aadcc3d4ed39122b052a
parent877599fdef5ea4a7dd1956e22fa9d6923add97f8 (diff)
parent2ade81473636b33aaac64495f89a7dc572c529f0 (diff)
Merge ../torvalds-2.6/
-rw-r--r--COPYING4
-rw-r--r--Documentation/00-INDEX4
-rw-r--r--Documentation/CodingStyle3
-rw-r--r--Documentation/DMA-API.txt2
-rw-r--r--Documentation/DMA-ISA-LPC.txt151
-rw-r--r--Documentation/DocBook/journal-api.tmpl4
-rw-r--r--Documentation/DocBook/kernel-hacking.tmpl310
-rw-r--r--Documentation/DocBook/usb.tmpl2
-rw-r--r--Documentation/MSI-HOWTO.txt2
-rw-r--r--Documentation/RCU/RTFP.txt36
-rw-r--r--Documentation/RCU/UP.txt79
-rw-r--r--Documentation/RCU/checklist.txt23
-rw-r--r--Documentation/RCU/rcu.txt48
-rw-r--r--Documentation/RCU/rcuref.txt74
-rw-r--r--Documentation/RCU/whatisRCU.txt902
-rw-r--r--Documentation/applying-patches.txt439
-rw-r--r--Documentation/cpu-freq/cpufreq-stats.txt2
-rw-r--r--Documentation/cpusets.txt2
-rw-r--r--Documentation/crypto/descore-readme.txt2
-rw-r--r--Documentation/dvb/bt8xx.txt89
-rw-r--r--Documentation/dvb/ci.txt9
-rw-r--r--Documentation/fb/cyblafb/bugs14
-rw-r--r--Documentation/fb/cyblafb/credits7
-rw-r--r--Documentation/fb/cyblafb/documentation17
-rw-r--r--Documentation/fb/cyblafb/fb.modes155
-rw-r--r--Documentation/fb/cyblafb/performance80
-rw-r--r--Documentation/fb/cyblafb/todo32
-rw-r--r--Documentation/fb/cyblafb/usage206
-rw-r--r--Documentation/fb/cyblafb/whycyblafb85
-rw-r--r--Documentation/fb/intel810.txt56
-rw-r--r--Documentation/fb/modedb.txt73
-rw-r--r--Documentation/feature-removal-schedule.txt8
-rw-r--r--Documentation/filesystems/files.txt123
-rw-r--r--Documentation/filesystems/fuse.txt315
-rw-r--r--Documentation/filesystems/proc.txt42
-rw-r--r--Documentation/filesystems/v9fs.txt95
-rw-r--r--Documentation/filesystems/vfs.txt435
-rw-r--r--Documentation/ioctl/cdrom.txt2
-rw-r--r--Documentation/kbuild/makefiles.txt14
-rw-r--r--Documentation/kdump/kdump.txt16
-rw-r--r--Documentation/kernel-parameters.txt10
-rw-r--r--Documentation/mono.txt2
-rw-r--r--Documentation/networking/bonding.txt4
-rw-r--r--Documentation/networking/wan-router.txt4
-rw-r--r--Documentation/pci.txt2
-rw-r--r--Documentation/powerpc/eeh-pci-error-recovery.txt2
-rw-r--r--Documentation/s390/s390dbf.txt2
-rw-r--r--Documentation/scsi/ibmmca.txt2
-rw-r--r--Documentation/sound/alsa/ALSA-Configuration.txt2
-rw-r--r--Documentation/sparse.txt2
-rw-r--r--Documentation/sysrq.txt2
-rw-r--r--Documentation/uml/UserModeLinux-HOWTO.txt2
-rw-r--r--Documentation/usb/gadget_serial.txt2
-rw-r--r--Documentation/video4linux/CARDLIST.bttv4
-rw-r--r--Documentation/video4linux/CARDLIST.saa71343
-rw-r--r--Documentation/video4linux/CARDLIST.tuner1
-rw-r--r--Documentation/video4linux/Zoran2
-rw-r--r--Documentation/x86_64/boot-options.txt5
-rw-r--r--Kbuild49
-rw-r--r--MAINTAINERS24
-rw-r--r--Makefile80
-rw-r--r--REPORTING-BUGS14
-rw-r--r--arch/alpha/Makefile11
-rw-r--r--arch/alpha/kernel/alpha_ksyms.c9
-rw-r--r--arch/alpha/kernel/entry.S2
-rw-r--r--arch/alpha/kernel/head.S2
-rw-r--r--arch/alpha/kernel/module.c8
-rw-r--r--arch/alpha/kernel/osf_sys.c7
-rw-r--r--arch/alpha/kernel/smp.c172
-rw-r--r--arch/alpha/lib/dbg_stackcheck.S2
-rw-r--r--arch/alpha/lib/dbg_stackkill.S2
-rw-r--r--arch/arm/Kconfig4
-rw-r--r--arch/arm/Kconfig.debug2
-rw-r--r--arch/arm/Makefile11
-rw-r--r--arch/arm/common/scoop.c2
-rw-r--r--arch/arm/kernel/calls.S5
-rw-r--r--arch/arm/kernel/entry-common.S4
-rw-r--r--arch/arm/kernel/entry-header.S2
-rw-r--r--arch/arm/kernel/head.S2
-rw-r--r--arch/arm/kernel/iwmmxt.S2
-rw-r--r--arch/arm/lib/copy_page.S2
-rw-r--r--arch/arm/lib/csumpartialcopyuser.S2
-rw-r--r--arch/arm/lib/getuser.S2
-rw-r--r--arch/arm/lib/putuser.S2
-rw-r--r--arch/arm/mach-pxa/corgi.c28
-rw-r--r--arch/arm/mach-pxa/corgi_ssp.c2
-rw-r--r--arch/arm/mach-s3c2410/devs.c11
-rw-r--r--arch/arm/mach-s3c2410/mach-h1940.c51
-rw-r--r--arch/arm/mm/copypage-v3.S2
-rw-r--r--arch/arm/mm/copypage-v4wb.S2
-rw-r--r--arch/arm/mm/copypage-v4wt.S2
-rw-r--r--arch/arm/mm/proc-arm1020.S2
-rw-r--r--arch/arm/mm/proc-arm1020e.S2
-rw-r--r--arch/arm/mm/proc-arm1022.S2
-rw-r--r--arch/arm/mm/proc-arm1026.S2
-rw-r--r--arch/arm/mm/proc-arm6_7.S2
-rw-r--r--arch/arm/mm/proc-arm720.S2
-rw-r--r--arch/arm/mm/proc-macros.S2
-rw-r--r--arch/arm/mm/proc-sa110.S2
-rw-r--r--arch/arm/mm/proc-sa1100.S2
-rw-r--r--arch/arm/mm/proc-v6.S2
-rw-r--r--arch/arm/mm/tlb-v3.S2
-rw-r--r--arch/arm/mm/tlb-v4.S2
-rw-r--r--arch/arm/mm/tlb-v4wb.S2
-rw-r--r--arch/arm/mm/tlb-v4wbi.S2
-rw-r--r--arch/arm/mm/tlb-v6.S2
-rw-r--r--arch/arm/nwfpe/entry26.S2
-rw-r--r--arch/arm/vfp/entry.S2
-rw-r--r--arch/arm26/Makefile10
-rw-r--r--arch/arm26/kernel/entry.S2
-rw-r--r--arch/arm26/lib/copy_page.S2
-rw-r--r--arch/arm26/lib/csumpartialcopyuser.S2
-rw-r--r--arch/arm26/lib/getuser.S2
-rw-r--r--arch/arm26/lib/putuser.S2
-rw-r--r--arch/arm26/mm/proc-funcs.S2
-rw-r--r--arch/arm26/nwfpe/entry.S2
-rw-r--r--arch/cris/Makefile10
-rw-r--r--arch/cris/arch-v10/kernel/entry.S2
-rw-r--r--arch/cris/arch-v32/kernel/entry.S2
-rw-r--r--arch/frv/kernel/asm-offsets.c1
-rw-r--r--arch/h8300/Makefile8
-rw-r--r--arch/i386/Makefile9
-rw-r--r--arch/i386/boot/video.S7
-rw-r--r--arch/i386/kernel/acpi/earlyquirk.c7
-rw-r--r--arch/i386/kernel/acpi/wakeup.S6
-rw-r--r--arch/i386/kernel/cpu/common.c2
-rw-r--r--arch/i386/kernel/entry.S4
-rw-r--r--arch/i386/kernel/head.S2
-rw-r--r--arch/i386/kernel/io_apic.c7
-rw-r--r--arch/i386/kernel/mpparse.c24
-rw-r--r--arch/i386/kernel/ptrace.c22
-rw-r--r--arch/i386/kernel/setup.c22
-rw-r--r--arch/i386/kernel/smpboot.c3
-rw-r--r--arch/i386/kernel/srat.c8
-rw-r--r--arch/i386/kernel/time.c3
-rw-r--r--arch/i386/kernel/vmlinux.lds.S11
-rw-r--r--arch/i386/kernel/vsyscall-sigreturn.S2
-rw-r--r--arch/i386/kernel/vsyscall.lds.S2
-rw-r--r--arch/i386/pci/acpi.c17
-rw-r--r--arch/i386/pci/mmconfig.c7
-rw-r--r--arch/i386/power/swsusp.S2
-rw-r--r--arch/ia64/Makefile21
-rw-r--r--arch/ia64/hp/sim/boot/boot_head.S31
-rw-r--r--arch/ia64/ia32/ia32_entry.S2
-rw-r--r--arch/ia64/ia32/sys_ia32.c2
-rw-r--r--arch/ia64/kernel/asm-offsets.c40
-rw-r--r--arch/ia64/kernel/entry.S25
-rw-r--r--arch/ia64/kernel/fsys.S2
-rw-r--r--arch/ia64/kernel/gate.S2
-rw-r--r--arch/ia64/kernel/head.S2
-rw-r--r--arch/ia64/kernel/ivt.S3
-rw-r--r--arch/ia64/kernel/mca.c830
-rw-r--r--arch/ia64/kernel/mca_asm.S1358
-rw-r--r--arch/ia64/kernel/mca_drv.c37
-rw-r--r--arch/ia64/kernel/minstate.h88
-rw-r--r--arch/ia64/kernel/palinfo.c115
-rw-r--r--arch/ia64/kernel/perfmon.c9
-rw-r--r--arch/ia64/kernel/salinfo.c62
-rw-r--r--arch/ia64/kernel/unwind.c22
-rw-r--r--arch/ia64/mm/init.c15
-rw-r--r--arch/ia64/sn/kernel/setup.c30
-rw-r--r--arch/ia64/sn/kernel/xpnet.c2
-rw-r--r--arch/m32r/Kconfig4
-rw-r--r--arch/m32r/kernel/asm-offsets.c1
-rw-r--r--arch/m32r/kernel/smp.c48
-rw-r--r--arch/m68k/Makefile9
-rw-r--r--arch/m68k/amiga/amisound.c2
-rw-r--r--arch/m68k/fpsp040/skeleton.S2
-rw-r--r--arch/m68k/ifpsp060/iskeleton.S2
-rw-r--r--arch/m68k/kernel/entry.S2
-rw-r--r--arch/m68k/kernel/head.S2
-rw-r--r--arch/m68k/mac/macboing.c3
-rw-r--r--arch/m68k/math-emu/fp_emu.h2
-rw-r--r--arch/m68knommu/Makefile10
-rw-r--r--arch/m68knommu/platform/68360/head-ram.S408
-rw-r--r--arch/m68knommu/platform/68360/head-rom.S420
-rw-r--r--arch/mips/Kconfig7
-rw-r--r--arch/mips/Makefile35
-rw-r--r--arch/mips/configs/tb0287_defconfig1041
-rw-r--r--arch/mips/kernel/asm-offsets.c (renamed from arch/mips/kernel/offset.c)0
-rw-r--r--arch/mips/kernel/genrtc.c2
-rw-r--r--arch/mips/kernel/i8259.c2
-rw-r--r--arch/mips/kernel/irixioctl.c5
-rw-r--r--arch/mips/kernel/irixsig.c17
-rw-r--r--arch/mips/kernel/r2300_fpu.S2
-rw-r--r--arch/mips/kernel/r2300_switch.S2
-rw-r--r--arch/mips/kernel/r4k_fpu.S2
-rw-r--r--arch/mips/kernel/r4k_switch.S2
-rw-r--r--arch/mips/kernel/r6000_fpu.S2
-rw-r--r--arch/mips/kernel/scall32-o32.S2
-rw-r--r--arch/mips/kernel/scall64-64.S2
-rw-r--r--arch/mips/kernel/syscall.c2
-rw-r--r--arch/mips/kernel/sysirix.c3
-rw-r--r--arch/mips/lib-32/memset.S2
-rw-r--r--arch/mips/lib-64/memset.S2
-rw-r--r--arch/mips/lib/dec_and_lock.c8
-rw-r--r--arch/mips/lib/memcpy.S2
-rw-r--r--arch/mips/lib/strlen_user.S2
-rw-r--r--arch/mips/lib/strncpy_user.S2
-rw-r--r--arch/mips/lib/strnlen_user.S2
-rw-r--r--arch/mips/pci/Makefile1
-rw-r--r--arch/mips/pci/fixup-tb0287.c65
-rw-r--r--arch/parisc/Makefile10
-rw-r--r--arch/parisc/hpux/gate.S2
-rw-r--r--arch/parisc/hpux/wrappers.S2
-rw-r--r--arch/parisc/kernel/entry.S2
-rw-r--r--arch/parisc/kernel/head.S2
-rw-r--r--arch/parisc/kernel/process.c2
-rw-r--r--arch/parisc/kernel/ptrace.c2
-rw-r--r--arch/parisc/kernel/signal.c2
-rw-r--r--arch/parisc/kernel/syscall.S2
-rw-r--r--arch/parisc/lib/Makefile2
-rw-r--r--arch/parisc/lib/bitops.c4
-rw-r--r--arch/parisc/lib/debuglocks.c277
-rw-r--r--arch/parisc/lib/fixup.S2
-rw-r--r--arch/ppc/8xx_io/cs4218_tdm.c2
-rw-r--r--arch/ppc/Kconfig19
-rw-r--r--arch/ppc/Makefile28
-rw-r--r--arch/ppc/boot/common/ns16550.c8
-rw-r--r--arch/ppc/boot/common/util.S2
-rw-r--r--arch/ppc/kernel/Makefile3
-rw-r--r--arch/ppc/kernel/cpu_setup_6xx.S3
-rw-r--r--arch/ppc/kernel/cpu_setup_power4.S3
-rw-r--r--arch/ppc/kernel/dma-mapping.c2
-rw-r--r--arch/ppc/kernel/entry.S2
-rw-r--r--arch/ppc/kernel/fpu.S2
-rw-r--r--arch/ppc/kernel/head.S30
-rw-r--r--arch/ppc/kernel/head_44x.S2
-rw-r--r--arch/ppc/kernel/head_4xx.S2
-rw-r--r--arch/ppc/kernel/head_8xx.S2
-rw-r--r--arch/ppc/kernel/head_fsl_booke.S2
-rw-r--r--arch/ppc/kernel/idle.c6
-rw-r--r--arch/ppc/kernel/idle_6xx.S2
-rw-r--r--arch/ppc/kernel/idle_power4.S2
-rw-r--r--arch/ppc/kernel/misc.S2
-rw-r--r--arch/ppc/kernel/smp.c44
-rw-r--r--arch/ppc/kernel/swsusp.S2
-rw-r--r--arch/ppc/kernel/traps.c24
-rw-r--r--arch/ppc/lib/Makefile1
-rw-r--r--arch/ppc/lib/dec_and_lock.c8
-rw-r--r--arch/ppc/mm/fault.c6
-rw-r--r--arch/ppc/mm/hashtable.S2
-rw-r--r--arch/ppc/platforms/4xx/ebony.c13
-rw-r--r--arch/ppc/platforms/hdpu.c2
-rw-r--r--arch/ppc/platforms/pmac_sleep.S4
-rw-r--r--arch/ppc/platforms/pmac_smp.c85
-rw-r--r--arch/ppc/syslib/cpc700_pic.c12
-rw-r--r--arch/ppc/syslib/i8259.c13
-rw-r--r--arch/ppc/syslib/ibm440gx_common.c7
-rw-r--r--arch/ppc/syslib/mv64x60.c2
-rw-r--r--arch/ppc/syslib/open_pic2.c12
-rw-r--r--arch/ppc/syslib/ppc403_pic.c11
-rw-r--r--arch/ppc/syslib/qspan_pci.c2
-rw-r--r--arch/ppc/syslib/xilinx_pic.c13
-rw-r--r--arch/ppc64/Makefile22
-rw-r--r--arch/ppc64/kernel/cpu_setup_power4.S3
-rw-r--r--arch/ppc64/kernel/entry.S2
-rw-r--r--arch/ppc64/kernel/head.S2
-rw-r--r--arch/ppc64/kernel/iSeries_pci.c2
-rw-r--r--arch/ppc64/kernel/idle_power4.S2
-rw-r--r--arch/ppc64/kernel/maple_pci.c56
-rw-r--r--arch/ppc64/kernel/misc.S2
-rw-r--r--arch/ppc64/kernel/pSeries_setup.c8
-rw-r--r--arch/ppc64/kernel/pSeries_smp.c13
-rw-r--r--arch/ppc64/kernel/pci.c425
-rw-r--r--arch/ppc64/kernel/pmac_pci.c60
-rw-r--r--arch/ppc64/kernel/pmac_setup.c13
-rw-r--r--arch/ppc64/kernel/pmc.c2
-rw-r--r--arch/ppc64/kernel/process.c34
-rw-r--r--arch/ppc64/kernel/ptrace.c28
-rw-r--r--arch/ppc64/kernel/ptrace32.c34
-rw-r--r--arch/ppc64/kernel/ras.c2
-rw-r--r--arch/ppc64/kernel/setup.c16
-rw-r--r--arch/ppc64/kernel/signal.c9
-rw-r--r--arch/ppc64/kernel/signal32.c8
-rw-r--r--arch/ppc64/kernel/vdso32/cacheflush.S2
-rw-r--r--arch/ppc64/kernel/vdso32/datapage.S2
-rw-r--r--arch/ppc64/kernel/vdso32/gettimeofday.S2
-rw-r--r--arch/ppc64/kernel/vdso64/cacheflush.S2
-rw-r--r--arch/ppc64/kernel/vdso64/datapage.S2
-rw-r--r--arch/ppc64/kernel/vdso64/gettimeofday.S2
-rw-r--r--arch/ppc64/kernel/xics.c44
-rw-r--r--arch/ppc64/lib/dec_and_lock.c8
-rw-r--r--arch/ppc64/lib/locks.c14
-rw-r--r--arch/ppc64/mm/fault.c31
-rw-r--r--arch/ppc64/mm/hash_low.S2
-rw-r--r--arch/ppc64/mm/slb_low.S2
-rw-r--r--arch/ppc64/xmon/privinst.h1
-rw-r--r--arch/ppc64/xmon/xmon.c20
-rw-r--r--arch/s390/Makefile10
-rw-r--r--arch/s390/kernel/compat_linux.c2
-rw-r--r--arch/s390/kernel/entry.S2
-rw-r--r--arch/s390/kernel/entry64.S2
-rw-r--r--arch/s390/kernel/head.S2
-rw-r--r--arch/s390/kernel/head64.S2
-rw-r--r--arch/s390/lib/spinlock.c12
-rw-r--r--arch/s390/lib/uaccess.S2
-rw-r--r--arch/s390/lib/uaccess64.S2
-rw-r--r--arch/sh/Makefile13
-rw-r--r--arch/sh/boards/adx/irq_maskreg.c14
-rw-r--r--arch/sh/boards/bigsur/io.c8
-rw-r--r--arch/sh/boards/bigsur/irq.c28
-rw-r--r--arch/sh/boards/cqreek/irq.c14
-rw-r--r--arch/sh/boards/harp/irq.c14
-rw-r--r--arch/sh/boards/overdrive/irq.c14
-rw-r--r--arch/sh/boards/renesas/hs7751rvoip/irq.c14
-rw-r--r--arch/sh/boards/renesas/rts7751r2d/irq.c14
-rw-r--r--arch/sh/boards/renesas/systemh/irq.c14
-rw-r--r--arch/sh/boards/superh/microdev/irq.c14
-rw-r--r--arch/sh/cchips/hd6446x/hd64465/io.c8
-rw-r--r--arch/sh/cchips/voyagergx/irq.c14
-rw-r--r--arch/sh/kernel/cpu/irq_imask.c14
-rw-r--r--arch/sh/kernel/cpu/irq_ipr.c28
-rw-r--r--arch/sh/kernel/cpu/sh4/irq_intc2.c14
-rw-r--r--arch/sh64/Makefile8
-rw-r--r--arch/sh64/kernel/irq_intc.c14
-rw-r--r--arch/sparc/Makefile12
-rw-r--r--arch/sparc/kernel/entry.S2
-rw-r--r--arch/sparc/kernel/sclow.S2
-rw-r--r--arch/sparc/kernel/sparc_ksyms.c10
-rw-r--r--arch/sparc/lib/Makefile2
-rw-r--r--arch/sparc/lib/atomic32.c2
-rw-r--r--arch/sparc/lib/debuglocks.c202
-rw-r--r--arch/sparc/mm/hypersparc.S2
-rw-r--r--arch/sparc/mm/swift.S2
-rw-r--r--arch/sparc/mm/tsunami.S2
-rw-r--r--arch/sparc/mm/viking.S2
-rw-r--r--arch/sparc64/kernel/asm-offsets.c1
-rw-r--r--arch/sparc64/kernel/process.c5
-rw-r--r--arch/sparc64/kernel/sparc64_ksyms.c5
-rw-r--r--arch/sparc64/lib/Makefile1
-rw-r--r--arch/sparc64/lib/debuglocks.c366
-rw-r--r--arch/sparc64/solaris/ioctl.c15
-rw-r--r--arch/sparc64/solaris/timod.c29
-rw-r--r--arch/um/Makefile25
-rw-r--r--arch/um/include/mem.h12
-rw-r--r--arch/um/kernel/asm-offsets.c1
-rw-r--r--arch/um/kernel/dyn.lds.S37
-rw-r--r--arch/um/kernel/ksyms.c5
-rw-r--r--arch/um/kernel/physmem.c35
-rw-r--r--arch/um/kernel/trap_kern.c6
-rw-r--r--arch/um/kernel/uml.lds.S14
-rw-r--r--arch/v850/Makefile14
-rw-r--r--arch/v850/kernel/asm-offsets.c (renamed from arch/v850/kernel/asm-consts.c)0
-rw-r--r--arch/v850/kernel/entry.S2
-rw-r--r--arch/v850/kernel/irq.c14
-rw-r--r--arch/v850/kernel/setup.c14
-rw-r--r--arch/v850/kernel/sim.c14
-rw-r--r--arch/x86_64/Makefile10
-rw-r--r--arch/x86_64/boot/Makefile2
-rw-r--r--arch/x86_64/boot/compressed/misc.c6
-rw-r--r--arch/x86_64/defconfig65
-rw-r--r--arch/x86_64/ia32/ia32_ioctl.c17
-rw-r--r--arch/x86_64/ia32/ia32entry.S53
-rw-r--r--arch/x86_64/ia32/sys_ia32.c2
-rw-r--r--arch/x86_64/ia32/vsyscall-syscall.S2
-rw-r--r--arch/x86_64/ia32/vsyscall-sysenter.S2
-rw-r--r--arch/x86_64/kernel/Makefile1
-rw-r--r--arch/x86_64/kernel/acpi/sleep.c1
-rw-r--r--arch/x86_64/kernel/aperture.c2
-rw-r--r--arch/x86_64/kernel/apic.c42
-rw-r--r--arch/x86_64/kernel/asm-offsets.c1
-rw-r--r--arch/x86_64/kernel/crash.c1
-rw-r--r--arch/x86_64/kernel/e820.c18
-rw-r--r--arch/x86_64/kernel/early_printk.c46
-rw-r--r--arch/x86_64/kernel/entry.S224
-rw-r--r--arch/x86_64/kernel/genapic.c18
-rw-r--r--arch/x86_64/kernel/genapic_cluster.c4
-rw-r--r--arch/x86_64/kernel/genapic_flat.c22
-rw-r--r--arch/x86_64/kernel/head.S2
-rw-r--r--arch/x86_64/kernel/i8259.c23
-rw-r--r--arch/x86_64/kernel/init_task.c2
-rw-r--r--arch/x86_64/kernel/io_apic.c34
-rw-r--r--arch/x86_64/kernel/irq.c1
-rw-r--r--arch/x86_64/kernel/mce.c42
-rw-r--r--arch/x86_64/kernel/mpparse.c5
-rw-r--r--arch/x86_64/kernel/msr.c279
-rw-r--r--arch/x86_64/kernel/nmi.c5
-rw-r--r--arch/x86_64/kernel/pci-gart.c8
-rw-r--r--arch/x86_64/kernel/process.c38
-rw-r--r--arch/x86_64/kernel/setup.c89
-rw-r--r--arch/x86_64/kernel/setup64.c3
-rw-r--r--arch/x86_64/kernel/smp.c129
-rw-r--r--arch/x86_64/kernel/smpboot.c66
-rw-r--r--arch/x86_64/kernel/suspend.c17
-rw-r--r--arch/x86_64/kernel/suspend_asm.S2
-rw-r--r--arch/x86_64/kernel/time.c2
-rw-r--r--arch/x86_64/kernel/traps.c57
-rw-r--r--arch/x86_64/kernel/vmlinux.lds.S19
-rw-r--r--arch/x86_64/kernel/vsyscall.c8
-rw-r--r--arch/x86_64/lib/copy_user.S2
-rw-r--r--arch/x86_64/lib/getuser.S2
-rw-r--r--arch/x86_64/lib/putuser.S2
-rw-r--r--arch/x86_64/mm/fault.c10
-rw-r--r--arch/x86_64/mm/init.c79
-rw-r--r--arch/x86_64/mm/k8topology.c13
-rw-r--r--arch/x86_64/mm/numa.c9
-rw-r--r--arch/x86_64/mm/srat.c68
-rw-r--r--arch/x86_64/pci/k8-bus.c10
-rw-r--r--arch/x86_64/pci/mmconfig.c7
-rw-r--r--arch/xtensa/Makefile10
-rw-r--r--arch/xtensa/kernel/align.S2
-rw-r--r--arch/xtensa/kernel/entry.S2
-rw-r--r--arch/xtensa/kernel/process.c2
-rw-r--r--arch/xtensa/kernel/vectors.S2
-rw-r--r--drivers/acorn/block/fd1772.c12
-rw-r--r--drivers/acpi/sleep/main.c8
-rw-r--r--drivers/acpi/sleep/poweroff.c4
-rw-r--r--drivers/acpi/sleep/proc.c2
-rw-r--r--drivers/atm/idt77105.c6
-rw-r--r--drivers/atm/iphase.c2
-rw-r--r--drivers/base/dmapool.c3
-rw-r--r--drivers/block/acsi.c2
-rw-r--r--drivers/block/acsi_slm.c2
-rw-r--r--drivers/block/ataflop.c14
-rw-r--r--drivers/block/cciss.c7
-rw-r--r--drivers/block/cfq-iosched.c3
-rw-r--r--drivers/block/deadline-iosched.c5
-rw-r--r--drivers/block/floppy.c4
-rw-r--r--drivers/block/paride/pcd.c3
-rw-r--r--drivers/block/paride/pf.c3
-rw-r--r--drivers/block/paride/pg.c3
-rw-r--r--drivers/block/paride/pt.c3
-rw-r--r--drivers/block/ps2esdi.c3
-rw-r--r--drivers/block/swim3.c9
-rw-r--r--drivers/block/swim_iop.c3
-rw-r--r--drivers/block/umem.c11
-rw-r--r--drivers/block/xd.c21
-rw-r--r--drivers/block/z2ram.c2
-rw-r--r--drivers/cdrom/aztcd.c2
-rw-r--r--drivers/cdrom/gscd.c2
-rw-r--r--drivers/cdrom/optcd.c2
-rw-r--r--drivers/cdrom/sbpcd.c18
-rw-r--r--drivers/cdrom/sjcd.c2
-rw-r--r--drivers/cdrom/sonycd535.c3
-rw-r--r--drivers/char/agp/backend.c7
-rw-r--r--drivers/char/applicom.c24
-rw-r--r--drivers/char/cyclades.c2
-rw-r--r--drivers/char/ftape/lowlevel/fdc-io.c6
-rw-r--r--drivers/char/hangcheck-timer.c3
-rw-r--r--drivers/char/hpet.c4
-rw-r--r--drivers/char/hw_random.c5
-rw-r--r--drivers/char/ip2/i2lib.c6
-rw-r--r--drivers/char/ip2main.c2
-rw-r--r--drivers/char/ipmi/ipmi_devintf.c5
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c18
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c6
-rw-r--r--drivers/char/istallion.c2
-rw-r--r--drivers/char/keyboard.c114
-rw-r--r--drivers/char/lcd.c7
-rw-r--r--drivers/char/lp.c3
-rw-r--r--drivers/char/mxser.c12
-rw-r--r--drivers/char/n_tty.c2
-rw-r--r--drivers/char/pcmcia/synclink_cs.c16
-rw-r--r--drivers/char/pty.c5
-rw-r--r--drivers/char/synclink.c29
-rw-r--r--drivers/char/synclinkmp.c40
-rw-r--r--drivers/char/tty_io.c87
-rw-r--r--drivers/char/vt.c37
-rw-r--r--drivers/char/watchdog/mixcomwd.c2
-rw-r--r--drivers/ide/ide-io.c6
-rw-r--r--drivers/ide/ide-tape.c3
-rw-r--r--drivers/ide/ide-timing.h25
-rw-r--r--drivers/ide/legacy/ide-cs.c10
-rw-r--r--drivers/ide/pci/hpt366.c8
-rw-r--r--drivers/ieee1394/video1394.c2
-rw-r--r--drivers/infiniband/Kconfig25
-rw-r--r--drivers/infiniband/core/Makefile5
-rw-r--r--drivers/infiniband/core/cm.c5
-rw-r--r--drivers/infiniband/core/mad_rmpp.c4
-rw-r--r--drivers/infiniband/core/sa_query.c30
-rw-r--r--drivers/infiniband/core/ucm.c287
-rw-r--r--drivers/infiniband/core/ucm.h11
-rw-r--r--drivers/infiniband/core/uverbs.h26
-rw-r--r--drivers/infiniband/core/uverbs_cmd.c155
-rw-r--r--drivers/infiniband/core/uverbs_main.c98
-rw-r--r--drivers/infiniband/hw/mthca/mthca_qp.c45
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c2
-rw-r--r--drivers/input/evdev.c4
-rw-r--r--drivers/input/joystick/iforce/iforce-packets.c32
-rw-r--r--drivers/input/joystick/iforce/iforce-usb.c1
-rw-r--r--drivers/input/keyboard/atkbd.c10
-rw-r--r--drivers/input/keyboard/sunkbd.c2
-rw-r--r--drivers/input/mouse/Makefile2
-rw-r--r--drivers/input/mouse/alps.c2
-rw-r--r--drivers/input/mouse/logips2pp.c13
-rw-r--r--drivers/input/mouse/psmouse-base.c132
-rw-r--r--drivers/input/mouse/psmouse.h52
-rw-r--r--drivers/input/mouse/trackpoint.c304
-rw-r--r--drivers/input/mouse/trackpoint.h147
-rw-r--r--drivers/input/serio/i8042-io.h6
-rw-r--r--drivers/input/serio/i8042-ip22io.h2
-rw-r--r--drivers/input/serio/i8042-jazzio.h2
-rw-r--r--drivers/input/serio/i8042-sparcio.h12
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h72
-rw-r--r--drivers/input/serio/i8042.c199
-rw-r--r--drivers/isdn/i4l/isdn_bsdcomp.c14
-rw-r--r--drivers/isdn/i4l/isdn_common.c3
-rw-r--r--drivers/md/bitmap.c183
-rw-r--r--drivers/md/dm-exception-store.c9
-rw-r--r--drivers/md/dm-raid1.c12
-rw-r--r--drivers/md/linear.c100
-rw-r--r--drivers/md/md.c227
-rw-r--r--drivers/md/multipath.c5
-rw-r--r--drivers/md/raid0.c5
-rw-r--r--drivers/md/raid1.c234
-rw-r--r--drivers/md/raid10.c46
-rw-r--r--drivers/md/raid5.c138
-rw-r--r--drivers/md/raid6main.c138
-rw-r--r--drivers/media/Makefile5
-rw-r--r--drivers/media/common/ir-common.c68
-rw-r--r--drivers/media/common/saa7146_core.c6
-rw-r--r--drivers/media/common/saa7146_fops.c1
-rw-r--r--drivers/media/common/saa7146_i2c.c6
-rw-r--r--drivers/media/dvb/b2c2/flexcop-fe-tuner.c102
-rw-r--r--drivers/media/dvb/bt8xx/bt878.c4
-rw-r--r--drivers/media/dvb/bt8xx/bt878.h2
-rw-r--r--drivers/media/dvb/bt8xx/dst.c763
-rw-r--r--drivers/media/dvb/bt8xx/dst_ca.c554
-rw-r--r--drivers/media/dvb/bt8xx/dst_common.h8
-rw-r--r--drivers/media/dvb/bt8xx/dvb-bt8xx.c282
-rw-r--r--drivers/media/dvb/bt8xx/dvb-bt8xx.h2
-rw-r--r--drivers/media/dvb/cinergyT2/Kconfig2
-rw-r--r--drivers/media/dvb/cinergyT2/cinergyT2.c94
-rw-r--r--drivers/media/dvb/dvb-core/demux.h36
-rw-r--r--drivers/media/dvb/dvb-core/dmxdev.c20
-rw-r--r--drivers/media/dvb/dvb-core/dvb_ca_en50221.c2
-rw-r--r--drivers/media/dvb/dvb-core/dvb_demux.c532
-rw-r--r--drivers/media/dvb/dvb-core/dvb_demux.h116
-rw-r--r--drivers/media/dvb/dvb-core/dvb_net.c9
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig23
-rw-r--r--drivers/media/dvb/dvb-usb/Makefile3
-rw-r--r--drivers/media/dvb/dvb-usb/a800.c2
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.c66
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.h27
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mb.c20
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mc.c2
-rw-r--r--drivers/media/dvb/dvb-usb/digitv.c40
-rw-r--r--drivers/media/dvb/dvb-usb/dtt200u-fe.c4
-rw-r--r--drivers/media/dvb/dvb-usb/dtt200u.c21
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h10
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-init.c20
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb.h4
-rw-r--r--drivers/media/dvb/dvb-usb/nova-t-usb2.c2
-rw-r--r--drivers/media/dvb/dvb-usb/umt-010.c2
-rw-r--r--drivers/media/dvb/dvb-usb/vp702x-fe.c339
-rw-r--r--drivers/media/dvb/dvb-usb/vp702x.c290
-rw-r--r--drivers/media/dvb/dvb-usb/vp702x.h109
-rw-r--r--drivers/media/dvb/dvb-usb/vp7045.c7
-rw-r--r--drivers/media/dvb/frontends/cx24110.c22
-rw-r--r--drivers/media/dvb/frontends/cx24110.h2
-rw-r--r--drivers/media/dvb/frontends/dib3000mb.c1
-rw-r--r--drivers/media/dvb/frontends/dib3000mc.c1
-rw-r--r--drivers/media/dvb/frontends/mt352.c6
-rw-r--r--drivers/media/dvb/frontends/nxt6000.c9
-rw-r--r--drivers/media/dvb/frontends/or51132.c29
-rw-r--r--drivers/media/dvb/frontends/s5h1420.c162
-rw-r--r--drivers/media/dvb/frontends/s5h1420.h3
-rw-r--r--drivers/media/dvb/frontends/stv0297.c129
-rw-r--r--drivers/media/dvb/frontends/stv0297.h8
-rw-r--r--drivers/media/dvb/frontends/stv0299.c19
-rw-r--r--drivers/media/dvb/frontends/stv0299.h4
-rw-r--r--drivers/media/dvb/frontends/tda1004x.c3
-rw-r--r--drivers/media/dvb/frontends/ves1820.c15
-rw-r--r--drivers/media/dvb/ttpci/av7110.c201
-rw-r--r--drivers/media/dvb/ttpci/av7110.h11
-rw-r--r--drivers/media/dvb/ttpci/av7110_hw.c8
-rw-r--r--drivers/media/dvb/ttpci/av7110_ir.c140
-rw-r--r--drivers/media/dvb/ttpci/av7110_v4l.c74
-rw-r--r--drivers/media/dvb/ttpci/budget-av.c9
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c197
-rw-r--r--drivers/media/dvb/ttpci/budget-patch.c5
-rw-r--r--drivers/media/dvb/ttpci/budget.c6
-rw-r--r--drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c10
-rw-r--r--drivers/media/dvb/ttusb-dec/ttusb_dec.c1
-rw-r--r--drivers/media/video/Kconfig15
-rw-r--r--drivers/media/video/Makefile2
-rw-r--r--drivers/media/video/btcx-risc.c1
-rw-r--r--drivers/media/video/btcx-risc.h1
-rw-r--r--drivers/media/video/bttv-cards.c1180
-rw-r--r--drivers/media/video/bttv-driver.c67
-rw-r--r--drivers/media/video/bttv-gpio.c1
-rw-r--r--drivers/media/video/bttv-i2c.c2
-rw-r--r--drivers/media/video/bttv-if.c1
-rw-r--r--drivers/media/video/bttv-risc.c1
-rw-r--r--drivers/media/video/bttv-vbi.c1
-rw-r--r--drivers/media/video/bttv.h3
-rw-r--r--drivers/media/video/bttvp.h1
-rw-r--r--drivers/media/video/cpia_usb.c30
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c73
-rw-r--r--drivers/media/video/cx88/cx88-cards.c26
-rw-r--r--drivers/media/video/cx88/cx88-core.c21
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c53
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c1
-rw-r--r--drivers/media/video/cx88/cx88-input.c97
-rw-r--r--drivers/media/video/cx88/cx88-mpeg.c37
-rw-r--r--drivers/media/video/cx88/cx88-reg.h24
-rw-r--r--drivers/media/video/cx88/cx88-tvaudio.c742
-rw-r--r--drivers/media/video/cx88/cx88-vbi.c1
-rw-r--r--drivers/media/video/cx88/cx88-video.c408
-rw-r--r--drivers/media/video/cx88/cx88.h41
-rw-r--r--drivers/media/video/ir-kbd-gpio.c2
-rw-r--r--drivers/media/video/ir-kbd-i2c.c1
-rw-r--r--drivers/media/video/msp3400.c10
-rw-r--r--drivers/media/video/msp3400.h1
-rw-r--r--drivers/media/video/mt20xx.c2
-rw-r--r--drivers/media/video/rds.h48
-rw-r--r--drivers/media/video/saa6588.c534
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c132
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c1
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c2
-rw-r--r--drivers/media/video/saa7134/saa7134-empress.c1
-rw-r--r--drivers/media/video/saa7134/saa7134-i2c.c1
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c2
-rw-r--r--drivers/media/video/saa7134/saa7134-oss.c1
-rw-r--r--drivers/media/video/saa7134/saa7134-reg.h1
-rw-r--r--drivers/media/video/saa7134/saa7134-ts.c1
-rw-r--r--drivers/media/video/saa7134/saa7134-tvaudio.c1
-rw-r--r--drivers/media/video/saa7134/saa7134-vbi.c1
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c25
-rw-r--r--drivers/media/video/saa7134/saa7134.h4
-rw-r--r--drivers/media/video/stradis.c32
-rw-r--r--drivers/media/video/tda8290.c19
-rw-r--r--drivers/media/video/tda9887.c52
-rw-r--r--drivers/media/video/tea5767.c37
-rw-r--r--drivers/media/video/tuner-core.c91
-rw-r--r--drivers/media/video/tuner-simple.c54
-rw-r--r--drivers/media/video/tvaudio.c206
-rw-r--r--drivers/media/video/tveeprom.c362
-rw-r--r--drivers/media/video/tvmixer.c1
-rw-r--r--drivers/media/video/v4l1-compat.c16
-rw-r--r--drivers/media/video/v4l2-common.c18
-rw-r--r--drivers/media/video/video-buf-dvb.c1
-rw-r--r--drivers/media/video/video-buf.c9
-rw-r--r--drivers/media/video/zoran_driver.c2
-rw-r--r--drivers/media/video/zr36120.c6
-rw-r--r--drivers/mfd/Kconfig9
-rw-r--r--drivers/mfd/Makefile6
-rw-r--r--drivers/mfd/ucb1x00-assabet.c73
-rw-r--r--drivers/mfd/ucb1x00-core.c665
-rw-r--r--drivers/mfd/ucb1x00-ts.c399
-rw-r--r--drivers/mfd/ucb1x00.h256
-rw-r--r--drivers/misc/hdpuftrs/hdpu_cpustate.c23
-rw-r--r--drivers/mmc/wbsd.c27
-rw-r--r--drivers/mtd/devices/mtdram.c3
-rw-r--r--drivers/mtd/ftl.c11
-rw-r--r--drivers/mtd/maps/uclinux.c13
-rw-r--r--drivers/net/Kconfig13
-rw-r--r--drivers/net/atari_bionet.c2
-rw-r--r--drivers/net/atari_pamsnet.c2
-rw-r--r--drivers/net/bsd_comp.c28
-rw-r--r--drivers/net/cris/eth_v10.c6
-rw-r--r--drivers/net/cs89x0.c19
-rw-r--r--drivers/net/fec.c478
-rw-r--r--drivers/net/fec.h7
-rw-r--r--drivers/net/hamradio/yam.c2
-rw-r--r--drivers/net/mv643xx_eth.c2
-rw-r--r--drivers/net/ppp_generic.c23
-rw-r--r--drivers/net/sungem.c36
-rw-r--r--drivers/net/sunhme.c43
-rw-r--r--drivers/net/tulip/de4x5.c4
-rw-r--r--drivers/parisc/iosapic.c2
-rw-r--r--drivers/parisc/lasi.c1
-rw-r--r--drivers/parport/ieee1284.c7
-rw-r--r--drivers/parport/ieee1284_ops.c10
-rw-r--r--drivers/parport/parport_pc.c3
-rw-r--r--drivers/pci/hotplug.c53
-rw-r--r--drivers/pci/hotplug/pciehprm_acpi.c8
-rw-r--r--drivers/pci/pci-sysfs.c10
-rw-r--r--drivers/pci/pci.h1
-rw-r--r--drivers/pci/probe.c56
-rw-r--r--drivers/pci/quirks.c6
-rw-r--r--drivers/pci/setup-bus.c4
-rw-r--r--drivers/pcmcia/Kconfig7
-rw-r--r--drivers/pcmcia/Makefile1
-rw-r--r--drivers/pcmcia/cs.c9
-rw-r--r--drivers/pcmcia/cs_internal.h4
-rw-r--r--drivers/pcmcia/ds.c34
-rw-r--r--drivers/pcmcia/omap_cf.c373
-rw-r--r--drivers/pcmcia/pcmcia_resource.c11
-rw-r--r--drivers/pcmcia/yenta_socket.c47
-rw-r--r--drivers/sbus/char/aurora.c3
-rw-r--r--drivers/sbus/char/bbc_envctrl.c3
-rw-r--r--drivers/sbus/char/envctrl.c4
-rw-r--r--drivers/scsi/53c7xx.c4
-rw-r--r--drivers/scsi/ch.c29
-rw-r--r--drivers/scsi/cpqfcTSinit.c3
-rw-r--r--drivers/scsi/ibmmca.c1
-rw-r--r--drivers/scsi/osst.c13
-rw-r--r--drivers/scsi/pluto.c3
-rw-r--r--drivers/scsi/qla2xxx/qla_dbg.c2
-rw-r--r--drivers/serial/8250.c2
-rw-r--r--drivers/serial/mcfserial.c13
-rw-r--r--drivers/serial/serial_txx9.c118
-rw-r--r--drivers/telephony/ixj.c116
-rw-r--r--drivers/usb/host/hc_crisv10.c4
-rw-r--r--drivers/usb/input/hid-core.c76
-rw-r--r--drivers/usb/input/hid-debug.h34
-rw-r--r--drivers/usb/input/hid-input.c66
-rw-r--r--drivers/usb/input/hid.h9
-rw-r--r--drivers/usb/input/hiddev.c1
-rw-r--r--drivers/usb/media/stv680.c26
-rw-r--r--drivers/video/Kconfig82
-rw-r--r--drivers/video/Makefile7
-rw-r--r--drivers/video/aty/aty128fb.c4
-rw-r--r--drivers/video/aty/atyfb_base.c14
-rw-r--r--drivers/video/aty/radeon_base.c34
-rw-r--r--drivers/video/console/bitblit.c148
-rw-r--r--drivers/video/console/fbcon.c185
-rw-r--r--drivers/video/console/fbcon.h3
-rw-r--r--drivers/video/console/vgacon.c71
-rw-r--r--drivers/video/cyblafb.c1456
-rw-r--r--drivers/video/fbcvt.c380
-rw-r--r--drivers/video/fbmem.c69
-rw-r--r--drivers/video/fbmon.c39
-rw-r--r--drivers/video/geode/Kconfig10
-rw-r--r--drivers/video/geode/display_gx1.c2
-rw-r--r--drivers/video/geode/geodefb.h1
-rw-r--r--drivers/video/geode/gx1fb_core.c182
-rw-r--r--drivers/video/geode/video_cs5530.c4
-rw-r--r--drivers/video/i810/Makefile5
-rw-r--r--drivers/video/i810/i810-i2c.c257
-rw-r--r--drivers/video/i810/i810.h14
-rw-r--r--drivers/video/i810/i810_main.c223
-rw-r--r--drivers/video/i810/i810_main.h16
-rw-r--r--drivers/video/intelfb/intelfb.h1
-rw-r--r--drivers/video/intelfb/intelfbdrv.c21
-rw-r--r--drivers/video/intelfb/intelfbhw.c4
-rw-r--r--drivers/video/matrox/matroxfb_misc.c30
-rw-r--r--drivers/video/modedb.c62
-rw-r--r--drivers/video/nvidia/nv_i2c.c16
-rw-r--r--drivers/video/nvidia/nv_local.h4
-rw-r--r--drivers/video/nvidia/nv_of.c3
-rw-r--r--drivers/video/nvidia/nv_proto.h2
-rw-r--r--drivers/video/nvidia/nv_setup.c6
-rw-r--r--drivers/video/nvidia/nvidia.c14
-rw-r--r--drivers/video/pxafb.c32
-rw-r--r--drivers/video/pxafb.h2
-rw-r--r--drivers/video/s3c2410fb.c915
-rw-r--r--drivers/video/s3c2410fb.h56
-rw-r--r--drivers/video/savage/savagefb-i2c.c16
-rw-r--r--drivers/video/savage/savagefb.h13
-rw-r--r--drivers/video/savage/savagefb_driver.c152
-rw-r--r--drivers/video/sis/300vtbl.h1363
-rw-r--r--drivers/video/sis/310vtbl.h2125
-rw-r--r--drivers/video/sis/Makefile2
-rw-r--r--drivers/video/sis/init.c5603
-rw-r--r--drivers/video/sis/init.h1732
-rw-r--r--drivers/video/sis/init301.c9630
-rw-r--r--drivers/video/sis/init301.h351
-rw-r--r--drivers/video/sis/initdef.h145
-rw-r--r--drivers/video/sis/initextlfb.c238
-rw-r--r--drivers/video/sis/oem300.h335
-rw-r--r--drivers/video/sis/oem310.h421
-rw-r--r--drivers/video/sis/osdef.h27
-rw-r--r--drivers/video/sis/sis.h746
-rw-r--r--drivers/video/sis/sis_accel.c479
-rw-r--r--drivers/video/sis/sis_accel.h9
-rw-r--r--drivers/video/sis/sis_main.c7525
-rw-r--r--drivers/video/sis/sis_main.h602
-rw-r--r--drivers/video/sis/vgatypes.h155
-rw-r--r--drivers/video/sis/vstruct.h1097
-rw-r--r--drivers/video/tridentfb.c5
-rw-r--r--drivers/video/vesafb.c38
-rw-r--r--drivers/video/vgastate.c15
-rw-r--r--fs/9p/9p.c359
-rw-r--r--fs/9p/9p.h341
-rw-r--r--fs/9p/Makefile17
-rw-r--r--fs/9p/conv.c693
-rw-r--r--fs/9p/conv.h36
-rw-r--r--fs/9p/debug.h70
-rw-r--r--fs/9p/error.c93
-rw-r--r--fs/9p/error.h178
-rw-r--r--fs/9p/fid.c241
-rw-r--r--fs/9p/fid.h57
-rw-r--r--fs/9p/mux.c475
-rw-r--r--fs/9p/mux.h41
-rw-r--r--fs/9p/trans_fd.c172
-rw-r--r--fs/9p/trans_sock.c290
-rw-r--r--fs/9p/transport.h46
-rw-r--r--fs/9p/v9fs.c452
-rw-r--r--fs/9p/v9fs.h103
-rw-r--r--fs/9p/v9fs_vfs.h53
-rw-r--r--fs/9p/vfs_dentry.c126
-rw-r--r--fs/9p/vfs_dir.c226
-rw-r--r--fs/9p/vfs_file.c401
-rw-r--r--fs/9p/vfs_inode.c1338
-rw-r--r--fs/9p/vfs_super.c280
-rw-r--r--fs/Kconfig24
-rw-r--r--fs/Makefile2
-rw-r--r--fs/affs/inode.c1
-rw-r--r--fs/aio.c34
-rw-r--r--fs/autofs/autofs_i.h3
-rw-r--r--fs/autofs/dirhash.c5
-rw-r--r--fs/autofs/inode.c3
-rw-r--r--fs/bfs/bfs.h1
-rw-r--r--fs/bfs/dir.c25
-rw-r--r--fs/bfs/file.c23
-rw-r--r--fs/bfs/inode.c104
-rw-r--r--fs/buffer.c1
-rw-r--r--fs/cifs/connect.c6
-rw-r--r--fs/compat.c6
-rw-r--r--fs/compat_ioctl.c7
-rw-r--r--fs/cramfs/uncompress.c1
-rw-r--r--fs/dcache.c16
-rw-r--r--fs/exec.c8
-rw-r--r--fs/ext2/ialloc.c5
-rw-r--r--fs/ext2/inode.c2
-rw-r--r--fs/ext2/xattr.h8
-rw-r--r--fs/ext2/xattr_security.c22
-rw-r--r--fs/ext3/ialloc.c5
-rw-r--r--fs/ext3/inode.c2
-rw-r--r--fs/ext3/xattr.h11
-rw-r--r--fs/ext3/xattr_security.c22
-rw-r--r--fs/fat/inode.c2
-rw-r--r--fs/fcntl.c60
-rw-r--r--fs/file.c387
-rw-r--r--fs/file_table.c40
-rw-r--r--fs/fuse/Makefile7
-rw-r--r--fs/fuse/dev.c877
-rw-r--r--fs/fuse/dir.c982
-rw-r--r--fs/fuse/file.c555
-rw-r--r--fs/fuse/fuse_i.h451
-rw-r--r--fs/fuse/inode.c591
-rw-r--r--fs/hostfs/hostfs_kern.c1
-rw-r--r--fs/hpfs/inode.c1
-rw-r--r--fs/inode.c12
-rw-r--r--fs/jbd/transaction.c3
-rw-r--r--fs/jffs/inode-v23.c1
-rw-r--r--fs/jffs/intrep.c22
-rw-r--r--fs/jfs/acl.c24
-rw-r--r--fs/jfs/inode.c26
-rw-r--r--fs/jfs/jfs_acl.h12
-rw-r--r--fs/jfs/jfs_xattr.h14
-rw-r--r--fs/jfs/namei.c85
-rw-r--r--fs/jfs/xattr.c94
-rw-r--r--fs/lockd/clntproc.c3
-rw-r--r--fs/locks.c8
-rw-r--r--fs/minix/inode.c1
-rw-r--r--fs/namei.c26
-rw-r--r--fs/namespace.c4
-rw-r--r--fs/ncpfs/inode.c2
-rw-r--r--fs/nfs/inode.c2
-rw-r--r--fs/nfs/nfs3proc.c3
-rw-r--r--fs/nfs/nfs4proc.c12
-rw-r--r--fs/ntfs/aops.c1
-rw-r--r--fs/open.c43
-rw-r--r--fs/pipe.c6
-rw-r--r--fs/proc/array.c5
-rw-r--r--fs/proc/base.c33
-rw-r--r--fs/proc/inode.c2
-rw-r--r--fs/qnx4/inode.c1
-rw-r--r--fs/reiserfs/inode.c2
-rw-r--r--fs/reiserfs/journal.c3
-rw-r--r--fs/reiserfs/super.c3
-rw-r--r--fs/select.c23
-rw-r--r--fs/smbfs/inode.c1
-rw-r--r--fs/smbfs/proc.c3
-rw-r--r--fs/sysv/inode.c1
-rw-r--r--fs/udf/inode.c2
-rw-r--r--fs/ufs/inode.c1
-rw-r--r--fs/xfs/linux-2.6/time.h3
-rw-r--r--fs/xfs/linux-2.6/xfs_buf.c6
-rw-r--r--fs/xfs/linux-2.6/xfs_super.c12
-rw-r--r--fs/xfs/support/ktrace.c2
-rw-r--r--include/asm-alpha/spinlock.h96
-rw-r--r--include/asm-alpha/spinlock_types.h20
-rw-r--r--include/asm-arm/arch-pxa/pxafb.h1
-rw-r--r--include/asm-arm/arch-s3c2410/fb.h69
-rw-r--r--include/asm-arm/arch-s3c2410/regs-lcd.h17
-rw-r--r--include/asm-arm/spinlock.h50
-rw-r--r--include/asm-arm/spinlock_types.h20
-rw-r--r--include/asm-arm/unistd.h3
-rw-r--r--include/asm-arm26/hardirq.h2
-rw-r--r--include/asm-generic/tlb.h6
-rw-r--r--include/asm-generic/vmlinux.lds.h38
-rw-r--r--include/asm-i386/apic.h2
-rw-r--r--include/asm-i386/div64.h2
-rw-r--r--include/asm-i386/mach-default/mach_reboot.h10
-rw-r--r--include/asm-i386/mmzone.h2
-rw-r--r--include/asm-i386/numa.h3
-rw-r--r--include/asm-i386/processor.h4
-rw-r--r--include/asm-i386/spinlock.h200
-rw-r--r--include/asm-i386/spinlock_types.h20
-rw-r--r--include/asm-i386/thread_info.h2
-rw-r--r--include/asm-i386/topology.h2
-rw-r--r--include/asm-i386/unistd.h12
-rw-r--r--include/asm-ia64/mca.h102
-rw-r--r--include/asm-ia64/mca_asm.h125
-rw-r--r--include/asm-ia64/ptrace.h4
-rw-r--r--include/asm-ia64/sn/sn_feature_sets.h57
-rw-r--r--include/asm-ia64/sn/sn_sal.h36
-rw-r--r--include/asm-ia64/spinlock.h69
-rw-r--r--include/asm-ia64/spinlock_types.h21
-rw-r--r--include/asm-ia64/system.h1
-rw-r--r--include/asm-ia64/thread_info.h4
-rw-r--r--include/asm-ia64/unwind.h7
-rw-r--r--include/asm-m32r/spinlock.h127
-rw-r--r--include/asm-m32r/spinlock_types.h23
-rw-r--r--include/asm-m68knommu/bitops.h2
-rw-r--r--include/asm-m68knommu/checksum.h7
-rw-r--r--include/asm-m68knommu/m527xsim.h21
-rw-r--r--include/asm-m68knommu/m528xsim.h112
-rw-r--r--include/asm-m68knommu/mcfcache.h25
-rw-r--r--include/asm-m68knommu/mcfdma.h2
-rw-r--r--include/asm-mips/asmmacro-32.h2
-rw-r--r--include/asm-mips/asmmacro-64.h2
-rw-r--r--include/asm-mips/irq.h3
-rw-r--r--include/asm-mips/sim.h2
-rw-r--r--include/asm-mips/spinlock.h75
-rw-r--r--include/asm-mips/spinlock_types.h20
-rw-r--r--include/asm-mips/stackframe.h2
-rw-r--r--include/asm-mips/vr41xx/tb0287.h43
-rw-r--r--include/asm-parisc/assembly.h2
-rw-r--r--include/asm-parisc/atomic.h12
-rw-r--r--include/asm-parisc/bitops.h2
-rw-r--r--include/asm-parisc/cacheflush.h1
-rw-r--r--include/asm-parisc/processor.h1
-rw-r--r--include/asm-parisc/spinlock.h163
-rw-r--r--include/asm-parisc/spinlock_types.h21
-rw-r--r--include/asm-parisc/system.h24
-rw-r--r--include/asm-powerpc/siginfo.h8
-rw-r--r--include/asm-ppc/irq.h4
-rw-r--r--include/asm-ppc/ptrace.h7
-rw-r--r--include/asm-ppc/reg.h6
-rw-r--r--include/asm-ppc/smp.h6
-rw-r--r--include/asm-ppc/spinlock.h91
-rw-r--r--include/asm-ppc/spinlock_types.h20
-rw-r--r--include/asm-ppc/system.h1
-rw-r--r--include/asm-ppc64/hvcall.h6
-rw-r--r--include/asm-ppc64/machdep.h5
-rw-r--r--include/asm-ppc64/pci-bridge.h5
-rw-r--r--include/asm-ppc64/plpar_wrappers.h9
-rw-r--r--include/asm-ppc64/processor.h1
-rw-r--r--include/asm-ppc64/ptrace-common.h92
-rw-r--r--include/asm-ppc64/ptrace.h128
-rw-r--r--include/asm-ppc64/spinlock.h191
-rw-r--r--include/asm-ppc64/spinlock_types.h20
-rw-r--r--include/asm-ppc64/system.h3
-rw-r--r--include/asm-s390/spinlock.h63
-rw-r--r--include/asm-s390/spinlock_types.h21
-rw-r--r--include/asm-sh/irq.h4
-rw-r--r--include/asm-sh/spinlock.h61
-rw-r--r--include/asm-sh/spinlock_types.h22
-rw-r--r--include/asm-sparc/ptrace.h4
-rw-r--r--include/asm-sparc/spinlock.h140
-rw-r--r--include/asm-sparc/spinlock_types.h20
-rw-r--r--include/asm-sparc64/spinlock.h160
-rw-r--r--include/asm-sparc64/spinlock_types.h20
-rw-r--r--include/asm-um/page.h3
-rw-r--r--include/asm-um/pgtable.h16
-rw-r--r--include/asm-um/spinlock_types.h6
-rw-r--r--include/asm-x86_64/apic.h3
-rw-r--r--include/asm-x86_64/apicdef.h1
-rw-r--r--include/asm-x86_64/bug.h10
-rw-r--r--include/asm-x86_64/calling.h23
-rw-r--r--include/asm-x86_64/current.h2
-rw-r--r--include/asm-x86_64/desc.h2
-rw-r--r--include/asm-x86_64/dma-mapping.h5
-rw-r--r--include/asm-x86_64/dwarf2.h8
-rw-r--r--include/asm-x86_64/fixmap.h2
-rw-r--r--include/asm-x86_64/hardirq.h9
-rw-r--r--include/asm-x86_64/hw_irq.h18
-rw-r--r--include/asm-x86_64/io.h14
-rw-r--r--include/asm-x86_64/ipi.h23
-rw-r--r--include/asm-x86_64/irq.h4
-rw-r--r--include/asm-x86_64/kdebug.h4
-rw-r--r--include/asm-x86_64/local.h4
-rw-r--r--include/asm-x86_64/mmzone.h4
-rw-r--r--include/asm-x86_64/msr.h49
-rw-r--r--include/asm-x86_64/numa.h3
-rw-r--r--include/asm-x86_64/page.h4
-rw-r--r--include/asm-x86_64/pci.h6
-rw-r--r--include/asm-x86_64/pda.h14
-rw-r--r--include/asm-x86_64/pgalloc.h8
-rw-r--r--include/asm-x86_64/pgtable.h6
-rw-r--r--include/asm-x86_64/processor.h12
-rw-r--r--include/asm-x86_64/proto.h6
-rw-r--r--include/asm-x86_64/signal.h10
-rw-r--r--include/asm-x86_64/smp.h2
-rw-r--r--include/asm-x86_64/spinlock.h164
-rw-r--r--include/asm-x86_64/spinlock_types.h20
-rw-r--r--include/asm-x86_64/system.h8
-rw-r--r--include/asm-x86_64/timex.h1
-rw-r--r--include/asm-x86_64/tlbflush.h4
-rw-r--r--include/asm-x86_64/topology.h3
-rw-r--r--include/asm-x86_64/vsyscall.h1
-rw-r--r--include/asm-xtensa/ptrace.h2
-rw-r--r--include/asm-xtensa/uaccess.h2
-rw-r--r--include/linux/bfs_fs.h23
-rw-r--r--include/linux/bio.h7
-rw-r--r--include/linux/bit_spinlock.h77
-rw-r--r--include/linux/blkdev.h2
-rw-r--r--include/linux/chio.h2
-rw-r--r--include/linux/dccp.h3
-rw-r--r--include/linux/dmapool.h3
-rw-r--r--include/linux/dmi.h2
-rw-r--r--include/linux/fb.h28
-rw-r--r--include/linux/file.h30
-rw-r--r--include/linux/fs.h6
-rw-r--r--include/linux/fuse.h259
-rw-r--r--include/linux/in6.h56
-rw-r--r--include/linux/init_task.h18
-rw-r--r--include/linux/input.h8
-rw-r--r--include/linux/interrupt.h7
-rw-r--r--include/linux/ipv6.h2
-rw-r--r--include/linux/jbd.h1
-rw-r--r--include/linux/jiffies.h40
-rw-r--r--include/linux/pci.h8
-rw-r--r--include/linux/radix-tree.h4
-rw-r--r--include/linux/raid/bitmap.h15
-rw-r--r--include/linux/raid/linear.h4
-rw-r--r--include/linux/raid/md_k.h81
-rw-r--r--include/linux/raid/md_p.h16
-rw-r--r--include/linux/raid/raid1.h13
-rw-r--r--include/linux/raid/raid5.h14
-rw-r--r--include/linux/rcupdate.h4
-rw-r--r--include/linux/rcuref.h220
-rw-r--r--include/linux/reiserfs_fs.h6
-rw-r--r--include/linux/sched.h10
-rw-r--r--include/linux/security.h180
-rw-r--r--include/linux/slab.h3
-rw-r--r--include/linux/spinlock.h627
-rw-r--r--include/linux/spinlock_api_smp.h57
-rw-r--r--include/linux/spinlock_api_up.h80
-rw-r--r--include/linux/spinlock_types.h67
-rw-r--r--include/linux/spinlock_types_up.h51
-rw-r--r--include/linux/spinlock_up.h74
-rw-r--r--include/linux/time.h9
-rw-r--r--include/linux/timer.h4
-rw-r--r--include/linux/tty.h3
-rw-r--r--include/linux/videodev.h3
-rw-r--r--include/linux/videodev2.h4
-rw-r--r--include/linux/writeback.h2
-rw-r--r--include/media/audiochip.h1
-rw-r--r--include/media/id.h1
-rw-r--r--include/media/ir-common.h4
-rw-r--r--include/media/saa7146.h13
-rw-r--r--include/media/tuner.h193
-rw-r--r--include/media/tveeprom.h9
-rw-r--r--include/media/video-buf.h1
-rw-r--r--include/pcmcia/ds.h2
-rw-r--r--include/rdma/ib_cm.h1
-rw-r--r--include/rdma/ib_mad.h21
-rw-r--r--include/rdma/ib_sa.h31
-rw-r--r--include/rdma/ib_user_cm.h72
-rw-r--r--include/rdma/ib_user_verbs.h21
-rw-r--r--include/sound/pcm.h5
-rw-r--r--include/sound/tea575x-tuner.h2
-rw-r--r--include/video/cyblafb.h171
-rw-r--r--include/video/sisfb.h188
-rw-r--r--ipc/mqueue.c2
-rw-r--r--kernel/Makefile1
-rw-r--r--kernel/acct.c43
-rw-r--r--kernel/compat.c9
-rw-r--r--kernel/cpuset.c109
-rw-r--r--kernel/exit.c26
-rw-r--r--kernel/fork.c101
-rw-r--r--kernel/rcupdate.c14
-rw-r--r--kernel/sched.c277
-rw-r--r--kernel/signal.c3
-rw-r--r--kernel/softirq.c2
-rw-r--r--kernel/spinlock.c15
-rw-r--r--kernel/timer.c32
-rw-r--r--lib/Kconfig.debug8
-rw-r--r--lib/Makefile1
-rw-r--r--lib/dec_and_lock.c3
-rw-r--r--lib/kernel_lock.c3
-rw-r--r--lib/radix-tree.c2
-rw-r--r--lib/sort.c5
-rw-r--r--lib/spinlock_debug.c257
-rw-r--r--mm/bootmem.c14
-rw-r--r--mm/filemap.c17
-rw-r--r--mm/memory.c2
-rw-r--r--mm/nommu.c17
-rw-r--r--mm/oom_kill.c3
-rw-r--r--mm/page-writeback.c6
-rw-r--r--mm/page_alloc.c2
-rw-r--r--mm/shmem.c21
-rw-r--r--mm/slab.c1138
-rw-r--r--mm/swap_state.c4
-rw-r--r--mm/swapfile.c3
-rw-r--r--mm/vmalloc.c7
-rw-r--r--net/atm/mpc.c2
-rw-r--r--net/core/dst.c3
-rw-r--r--net/core/netpoll.c4
-rw-r--r--net/core/pktgen.c2
-rw-r--r--net/dccp/ccids/ccid3.c317
-rw-r--r--net/dccp/ccids/ccid3.h16
-rw-r--r--net/dccp/ccids/lib/packet_history.h3
-rw-r--r--net/dccp/dccp.h16
-rw-r--r--net/dccp/input.c4
-rw-r--r--net/dccp/ipv4.c5
-rw-r--r--net/dccp/minisocks.c1
-rw-r--r--net/dccp/options.c90
-rw-r--r--net/dccp/output.c3
-rw-r--r--net/decnet/dn_route.c3
-rw-r--r--net/ipv4/af_inet.c13
-rw-r--r--net/ipv4/fib_trie.c804
-rw-r--r--net/ipv4/inetpeer.c3
-rw-r--r--net/ipv4/netfilter/ipt_owner.c1
-rw-r--r--net/ipv4/tcp_output.c5
-rw-r--r--net/ipv6/addrconf.c3
-rw-r--r--net/ipv6/exthdrs.c3
-rw-r--r--net/ipv6/ip6_fib.c2
-rw-r--r--net/ipv6/ip6_flowlabel.c2
-rw-r--r--net/ipv6/netfilter/ip6t_owner.c1
-rw-r--r--net/ipv6/netfilter/ip6t_rt.c14
-rw-r--r--net/netrom/nr_loopback.c2
-rw-r--r--net/sched/sch_api.c2
-rw-r--r--scripts/Kbuild.include3
-rw-r--r--scripts/reference_discarded.pl7
-rw-r--r--security/dummy.c52
-rw-r--r--security/selinux/hooks.c178
-rw-r--r--sound/isa/sb/sb16_csp.c44
-rw-r--r--sound/oss/midibuf.c2
-rw-r--r--sound/oss/skeleton.c219
-rw-r--r--sound/oss/soundcard.c3
-rw-r--r--sound/oss/sys_timer.c3
-rw-r--r--sound/oss/uart6850.c3
1120 files changed, 54845 insertions, 33314 deletions
diff --git a/COPYING b/COPYING
index 2a7e338ec2..ca442d313d 100644
--- a/COPYING
+++ b/COPYING
@@ -18,7 +18,7 @@
18 Version 2, June 1991 18 Version 2, June 1991
19 19
20 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 20 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
21 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 Everyone is permitted to copy and distribute verbatim copies 22 Everyone is permitted to copy and distribute verbatim copies
23 of this license document, but changing it is not allowed. 23 of this license document, but changing it is not allowed.
24 24
@@ -321,7 +321,7 @@ the "copyright" line and a pointer to where the full notice is found.
321 321
322 You should have received a copy of the GNU General Public License 322 You should have received a copy of the GNU General Public License
323 along with this program; if not, write to the Free Software 323 along with this program; if not, write to the Free Software
324 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 324 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
325 325
326 326
327Also add information on how to contact you by electronic and paper mail. 327Also add information on how to contact you by electronic and paper mail.
diff --git a/Documentation/00-INDEX b/Documentation/00-INDEX
index f28a24e027..433cf5e9ae 100644
--- a/Documentation/00-INDEX
+++ b/Documentation/00-INDEX
@@ -46,6 +46,8 @@ SubmittingPatches
46 - procedure to get a source patch included into the kernel tree. 46 - procedure to get a source patch included into the kernel tree.
47VGA-softcursor.txt 47VGA-softcursor.txt
48 - how to change your VGA cursor from a blinking underscore. 48 - how to change your VGA cursor from a blinking underscore.
49applying-patches.txt
50 - description of various trees and how to apply their patches.
49arm/ 51arm/
50 - directory with info about Linux on the ARM architecture. 52 - directory with info about Linux on the ARM architecture.
51basic_profiling.txt 53basic_profiling.txt
@@ -275,7 +277,7 @@ tty.txt
275unicode.txt 277unicode.txt
276 - info on the Unicode character/font mapping used in Linux. 278 - info on the Unicode character/font mapping used in Linux.
277uml/ 279uml/
278 - directory with infomation about User Mode Linux. 280 - directory with information about User Mode Linux.
279usb/ 281usb/
280 - directory with info regarding the Universal Serial Bus. 282 - directory with info regarding the Universal Serial Bus.
281video4linux/ 283video4linux/
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
index f25b3953f5..22e5f9036f 100644
--- a/Documentation/CodingStyle
+++ b/Documentation/CodingStyle
@@ -236,6 +236,9 @@ ugly), but try to avoid excess. Instead, put the comments at the head
236of the function, telling people what it does, and possibly WHY it does 236of the function, telling people what it does, and possibly WHY it does
237it. 237it.
238 238
239When commenting the kernel API functions, please use the kerneldoc format.
240See the files Documentation/kernel-doc-nano-HOWTO.txt and scripts/kernel-doc
241for details.
239 242
240 Chapter 8: You've made a mess of it 243 Chapter 8: You've made a mess of it
241 244
diff --git a/Documentation/DMA-API.txt b/Documentation/DMA-API.txt
index 6ee3cd6134..1af0f2d502 100644
--- a/Documentation/DMA-API.txt
+++ b/Documentation/DMA-API.txt
@@ -121,7 +121,7 @@ pool's device.
121 dma_addr_t addr); 121 dma_addr_t addr);
122 122
123This puts memory back into the pool. The pool is what was passed to 123This puts memory back into the pool. The pool is what was passed to
124the the pool allocation routine; the cpu and dma addresses are what 124the pool allocation routine; the cpu and dma addresses are what
125were returned when that routine allocated the memory being freed. 125were returned when that routine allocated the memory being freed.
126 126
127 127
diff --git a/Documentation/DMA-ISA-LPC.txt b/Documentation/DMA-ISA-LPC.txt
new file mode 100644
index 0000000000..705f6be92b
--- /dev/null
+++ b/Documentation/DMA-ISA-LPC.txt
@@ -0,0 +1,151 @@
1 DMA with ISA and LPC devices
2 ============================
3
4 Pierre Ossman <drzeus@drzeus.cx>
5
6This document describes how to do DMA transfers using the old ISA DMA
7controller. Even though ISA is more or less dead today the LPC bus
8uses the same DMA system so it will be around for quite some time.
9
10Part I - Headers and dependencies
11---------------------------------
12
13To do ISA style DMA you need to include two headers:
14
15#include <linux/dma-mapping.h>
16#include <asm/dma.h>
17
18The first is the generic DMA API used to convert virtual addresses to
19physical addresses (see Documentation/DMA-API.txt for details).
20
21The second contains the routines specific to ISA DMA transfers. Since
22this is not present on all platforms make sure you construct your
23Kconfig to be dependent on ISA_DMA_API (not ISA) so that nobody tries
24to build your driver on unsupported platforms.
25
26Part II - Buffer allocation
27---------------------------
28
29The ISA DMA controller has some very strict requirements on which
30memory it can access so extra care must be taken when allocating
31buffers.
32
33(You usually need a special buffer for DMA transfers instead of
34transferring directly to and from your normal data structures.)
35
36The DMA-able address space is the lowest 16 MB of _physical_ memory.
37Also the transfer block may not cross page boundaries (which are 64
38or 128 KiB depending on which channel you use).
39
40In order to allocate a piece of memory that satisfies all these
41requirements you pass the flag GFP_DMA to kmalloc.
42
43Unfortunately the memory available for ISA DMA is scarce so unless you
44allocate the memory during boot-up it's a good idea to also pass
45__GFP_REPEAT and __GFP_NOWARN to make the allocater try a bit harder.
46
47(This scarcity also means that you should allocate the buffer as
48early as possible and not release it until the driver is unloaded.)
49
50Part III - Address translation
51------------------------------
52
53To translate the virtual address to a physical use the normal DMA
54API. Do _not_ use isa_virt_to_phys() even though it does the same
55thing. The reason for this is that the function isa_virt_to_phys()
56will require a Kconfig dependency to ISA, not just ISA_DMA_API which
57is really all you need. Remember that even though the DMA controller
58has its origins in ISA it is used elsewhere.
59
60Note: x86_64 had a broken DMA API when it came to ISA but has since
61been fixed. If your arch has problems then fix the DMA API instead of
62reverting to the ISA functions.
63
64Part IV - Channels
65------------------
66
67A normal ISA DMA controller has 8 channels. The lower four are for
688-bit transfers and the upper four are for 16-bit transfers.
69
70(Actually the DMA controller is really two separate controllers where
71channel 4 is used to give DMA access for the second controller (0-3).
72This means that of the four 16-bits channels only three are usable.)
73
74You allocate these in a similar fashion as all basic resources:
75
76extern int request_dma(unsigned int dmanr, const char * device_id);
77extern void free_dma(unsigned int dmanr);
78
79The ability to use 16-bit or 8-bit transfers is _not_ up to you as a
80driver author but depends on what the hardware supports. Check your
81specs or test different channels.
82
83Part V - Transfer data
84----------------------
85
86Now for the good stuff, the actual DMA transfer. :)
87
88Before you use any ISA DMA routines you need to claim the DMA lock
89using claim_dma_lock(). The reason is that some DMA operations are
90not atomic so only one driver may fiddle with the registers at a
91time.
92
93The first time you use the DMA controller you should call
94clear_dma_ff(). This clears an internal register in the DMA
95controller that is used for the non-atomic operations. As long as you
96(and everyone else) uses the locking functions then you only need to
97reset this once.
98
99Next, you tell the controller in which direction you intend to do the
100transfer using set_dma_mode(). Currently you have the options
101DMA_MODE_READ and DMA_MODE_WRITE.
102
103Set the address from where the transfer should start (this needs to
104be 16-bit aligned for 16-bit transfers) and how many bytes to
105transfer. Note that it's _bytes_. The DMA routines will do all the
106required translation to values that the DMA controller understands.
107
108The final step is enabling the DMA channel and releasing the DMA
109lock.
110
111Once the DMA transfer is finished (or timed out) you should disable
112the channel again. You should also check get_dma_residue() to make
113sure that all data has been transfered.
114
115Example:
116
117int flags, residue;
118
119flags = claim_dma_lock();
120
121clear_dma_ff();
122
123set_dma_mode(channel, DMA_MODE_WRITE);
124set_dma_addr(channel, phys_addr);
125set_dma_count(channel, num_bytes);
126
127dma_enable(channel);
128
129release_dma_lock(flags);
130
131while (!device_done());
132
133flags = claim_dma_lock();
134
135dma_disable(channel);
136
137residue = dma_get_residue(channel);
138if (residue != 0)
139 printk(KERN_ERR "driver: Incomplete DMA transfer!"
140 " %d bytes left!\n", residue);
141
142release_dma_lock(flags);
143
144Part VI - Suspend/resume
145------------------------
146
147It is the driver's responsibility to make sure that the machine isn't
148suspended while a DMA transfer is in progress. Also, all DMA settings
149are lost when the system suspends so if your driver relies on the DMA
150controller being in a certain state then you have to restore these
151registers upon resume.
diff --git a/Documentation/DocBook/journal-api.tmpl b/Documentation/DocBook/journal-api.tmpl
index 1ef6f43c6d..341aaa4ce4 100644
--- a/Documentation/DocBook/journal-api.tmpl
+++ b/Documentation/DocBook/journal-api.tmpl
@@ -116,7 +116,7 @@ filesystem. Almost.
116 116
117You still need to actually journal your filesystem changes, this 117You still need to actually journal your filesystem changes, this
118is done by wrapping them into transactions. Additionally you 118is done by wrapping them into transactions. Additionally you
119also need to wrap the modification of each of the the buffers 119also need to wrap the modification of each of the buffers
120with calls to the journal layer, so it knows what the modifications 120with calls to the journal layer, so it knows what the modifications
121you are actually making are. To do this use journal_start() which 121you are actually making are. To do this use journal_start() which
122returns a transaction handle. 122returns a transaction handle.
@@ -128,7 +128,7 @@ and its counterpart journal_stop(), which indicates the end of a transaction
128are nestable calls, so you can reenter a transaction if necessary, 128are nestable calls, so you can reenter a transaction if necessary,
129but remember you must call journal_stop() the same number of times as 129but remember you must call journal_stop() the same number of times as
130journal_start() before the transaction is completed (or more accurately 130journal_start() before the transaction is completed (or more accurately
131leaves the the update phase). Ext3/VFS makes use of this feature to simplify 131leaves the update phase). Ext3/VFS makes use of this feature to simplify
132quota support. 132quota support.
133</para> 133</para>
134 134
diff --git a/Documentation/DocBook/kernel-hacking.tmpl b/Documentation/DocBook/kernel-hacking.tmpl
index 49a9ef82d5..6367bba32d 100644
--- a/Documentation/DocBook/kernel-hacking.tmpl
+++ b/Documentation/DocBook/kernel-hacking.tmpl
@@ -8,8 +8,7 @@
8 8
9 <authorgroup> 9 <authorgroup>
10 <author> 10 <author>
11 <firstname>Paul</firstname> 11 <firstname>Rusty</firstname>
12 <othername>Rusty</othername>
13 <surname>Russell</surname> 12 <surname>Russell</surname>
14 <affiliation> 13 <affiliation>
15 <address> 14 <address>
@@ -20,7 +19,7 @@
20 </authorgroup> 19 </authorgroup>
21 20
22 <copyright> 21 <copyright>
23 <year>2001</year> 22 <year>2005</year>
24 <holder>Rusty Russell</holder> 23 <holder>Rusty Russell</holder>
25 </copyright> 24 </copyright>
26 25
@@ -64,7 +63,7 @@
64 <chapter id="introduction"> 63 <chapter id="introduction">
65 <title>Introduction</title> 64 <title>Introduction</title>
66 <para> 65 <para>
67 Welcome, gentle reader, to Rusty's Unreliable Guide to Linux 66 Welcome, gentle reader, to Rusty's Remarkably Unreliable Guide to Linux
68 Kernel Hacking. This document describes the common routines and 67 Kernel Hacking. This document describes the common routines and
69 general requirements for kernel code: its goal is to serve as a 68 general requirements for kernel code: its goal is to serve as a
70 primer for Linux kernel development for experienced C 69 primer for Linux kernel development for experienced C
@@ -96,13 +95,13 @@
96 95
97 <listitem> 96 <listitem>
98 <para> 97 <para>
99 not associated with any process, serving a softirq, tasklet or bh; 98 not associated with any process, serving a softirq or tasklet;
100 </para> 99 </para>
101 </listitem> 100 </listitem>
102 101
103 <listitem> 102 <listitem>
104 <para> 103 <para>
105 running in kernel space, associated with a process; 104 running in kernel space, associated with a process (user context);
106 </para> 105 </para>
107 </listitem> 106 </listitem>
108 107
@@ -114,11 +113,12 @@
114 </itemizedlist> 113 </itemizedlist>
115 114
116 <para> 115 <para>
117 There is a strict ordering between these: other than the last 116 There is an ordering between these. The bottom two can preempt
118 category (userspace) each can only be pre-empted by those above. 117 each other, but above that is a strict hierarchy: each can only be
119 For example, while a softirq is running on a CPU, no other 118 preempted by the ones above it. For example, while a softirq is
120 softirq will pre-empt it, but a hardware interrupt can. However, 119 running on a CPU, no other softirq will preempt it, but a hardware
121 any other CPUs in the system execute independently. 120 interrupt can. However, any other CPUs in the system execute
121 independently.
122 </para> 122 </para>
123 123
124 <para> 124 <para>
@@ -130,10 +130,10 @@
130 <title>User Context</title> 130 <title>User Context</title>
131 131
132 <para> 132 <para>
133 User context is when you are coming in from a system call or 133 User context is when you are coming in from a system call or other
134 other trap: you can sleep, and you own the CPU (except for 134 trap: like userspace, you can be preempted by more important tasks
135 interrupts) until you call <function>schedule()</function>. 135 and by interrupts. You can sleep, by calling
136 In other words, user context (unlike userspace) is not pre-emptable. 136 <function>schedule()</function>.
137 </para> 137 </para>
138 138
139 <note> 139 <note>
@@ -153,7 +153,7 @@
153 153
154 <caution> 154 <caution>
155 <para> 155 <para>
156 Beware that if you have interrupts or bottom halves disabled 156 Beware that if you have preemption or softirqs disabled
157 (see below), <function>in_interrupt()</function> will return a 157 (see below), <function>in_interrupt()</function> will return a
158 false positive. 158 false positive.
159 </para> 159 </para>
@@ -168,10 +168,10 @@
168 <hardware>keyboard</hardware> are examples of real 168 <hardware>keyboard</hardware> are examples of real
169 hardware which produce interrupts at any time. The kernel runs 169 hardware which produce interrupts at any time. The kernel runs
170 interrupt handlers, which services the hardware. The kernel 170 interrupt handlers, which services the hardware. The kernel
171 guarantees that this handler is never re-entered: if another 171 guarantees that this handler is never re-entered: if the same
172 interrupt arrives, it is queued (or dropped). Because it 172 interrupt arrives, it is queued (or dropped). Because it
173 disables interrupts, this handler has to be fast: frequently it 173 disables interrupts, this handler has to be fast: frequently it
174 simply acknowledges the interrupt, marks a `software interrupt' 174 simply acknowledges the interrupt, marks a 'software interrupt'
175 for execution and exits. 175 for execution and exits.
176 </para> 176 </para>
177 177
@@ -188,60 +188,52 @@
188 </sect1> 188 </sect1>
189 189
190 <sect1 id="basics-softirqs"> 190 <sect1 id="basics-softirqs">
191 <title>Software Interrupt Context: Bottom Halves, Tasklets, softirqs</title> 191 <title>Software Interrupt Context: Softirqs and Tasklets</title>
192 192
193 <para> 193 <para>
194 Whenever a system call is about to return to userspace, or a 194 Whenever a system call is about to return to userspace, or a
195 hardware interrupt handler exits, any `software interrupts' 195 hardware interrupt handler exits, any 'software interrupts'
196 which are marked pending (usually by hardware interrupts) are 196 which are marked pending (usually by hardware interrupts) are
197 run (<filename>kernel/softirq.c</filename>). 197 run (<filename>kernel/softirq.c</filename>).
198 </para> 198 </para>
199 199
200 <para> 200 <para>
201 Much of the real interrupt handling work is done here. Early in 201 Much of the real interrupt handling work is done here. Early in
202 the transition to <acronym>SMP</acronym>, there were only `bottom 202 the transition to <acronym>SMP</acronym>, there were only 'bottom
203 halves' (BHs), which didn't take advantage of multiple CPUs. Shortly 203 halves' (BHs), which didn't take advantage of multiple CPUs. Shortly
204 after we switched from wind-up computers made of match-sticks and snot, 204 after we switched from wind-up computers made of match-sticks and snot,
205 we abandoned this limitation. 205 we abandoned this limitation and switched to 'softirqs'.
206 </para> 206 </para>
207 207
208 <para> 208 <para>
209 <filename class="headerfile">include/linux/interrupt.h</filename> lists the 209 <filename class="headerfile">include/linux/interrupt.h</filename> lists the
210 different BH's. No matter how many CPUs you have, no two BHs will run at 210 different softirqs. A very important softirq is the
211 the same time. This made the transition to SMP simpler, but sucks hard for 211 timer softirq (<filename
212 scalable performance. A very important bottom half is the timer 212 class="headerfile">include/linux/timer.h</filename>): you can
213 BH (<filename class="headerfile">include/linux/timer.h</filename>): you 213 register to have it call functions for you in a given length of
214 can register to have it call functions for you in a given length of time. 214 time.
215 </para> 215 </para>
216 216
217 <para> 217 <para>
218 2.3.43 introduced softirqs, and re-implemented the (now 218 Softirqs are often a pain to deal with, since the same softirq
219 deprecated) BHs underneath them. Softirqs are fully-SMP 219 will run simultaneously on more than one CPU. For this reason,
220 versions of BHs: they can run on as many CPUs at once as 220 tasklets (<filename
221 required. This means they need to deal with any races in shared 221 class="headerfile">include/linux/interrupt.h</filename>) are more
222 data using their own locks. A bitmask is used to keep track of 222 often used: they are dynamically-registrable (meaning you can have
223 which are enabled, so the 32 available softirqs should not be 223 as many as you want), and they also guarantee that any tasklet
224 used up lightly. (<emphasis>Yes</emphasis>, people will 224 will only run on one CPU at any time, although different tasklets
225 notice). 225 can run simultaneously.
226 </para>
227
228 <para>
229 tasklets (<filename class="headerfile">include/linux/interrupt.h</filename>)
230 are like softirqs, except they are dynamically-registrable (meaning you
231 can have as many as you want), and they also guarantee that any tasklet
232 will only run on one CPU at any time, although different tasklets can
233 run simultaneously (unlike different BHs).
234 </para> 226 </para>
235 <caution> 227 <caution>
236 <para> 228 <para>
237 The name `tasklet' is misleading: they have nothing to do with `tasks', 229 The name 'tasklet' is misleading: they have nothing to do with 'tasks',
238 and probably more to do with some bad vodka Alexey Kuznetsov had at the 230 and probably more to do with some bad vodka Alexey Kuznetsov had at the
239 time. 231 time.
240 </para> 232 </para>
241 </caution> 233 </caution>
242 234
243 <para> 235 <para>
244 You can tell you are in a softirq (or bottom half, or tasklet) 236 You can tell you are in a softirq (or tasklet)
245 using the <function>in_softirq()</function> macro 237 using the <function>in_softirq()</function> macro
246 (<filename class="headerfile">include/linux/interrupt.h</filename>). 238 (<filename class="headerfile">include/linux/interrupt.h</filename>).
247 </para> 239 </para>
@@ -288,11 +280,10 @@
288 <term>A rigid stack limit</term> 280 <term>A rigid stack limit</term>
289 <listitem> 281 <listitem>
290 <para> 282 <para>
291 The kernel stack is about 6K in 2.2 (for most 283 Depending on configuration options the kernel stack is about 3K to 6K for most 32-bit architectures: it's
292 architectures: it's about 14K on the Alpha), and shared 284 about 14K on most 64-bit archs, and often shared with interrupts
293 with interrupts so you can't use it all. Avoid deep 285 so you can't use it all. Avoid deep recursion and huge local
294 recursion and huge local arrays on the stack (allocate 286 arrays on the stack (allocate them dynamically instead).
295 them dynamically instead).
296 </para> 287 </para>
297 </listitem> 288 </listitem>
298 </varlistentry> 289 </varlistentry>
@@ -339,7 +330,7 @@ asmlinkage long sys_mycall(int arg)
339 330
340 <para> 331 <para>
341 If all your routine does is read or write some parameter, consider 332 If all your routine does is read or write some parameter, consider
342 implementing a <function>sysctl</function> interface instead. 333 implementing a <function>sysfs</function> interface instead.
343 </para> 334 </para>
344 335
345 <para> 336 <para>
@@ -417,7 +408,10 @@ cond_resched(); /* Will sleep */
417 </para> 408 </para>
418 409
419 <para> 410 <para>
420 You will eventually lock up your box if you break these rules. 411 You should always compile your kernel
412 <symbol>CONFIG_DEBUG_SPINLOCK_SLEEP</symbol> on, and it will warn
413 you if you break these rules. If you <emphasis>do</emphasis> break
414 the rules, you will eventually lock up your box.
421 </para> 415 </para>
422 416
423 <para> 417 <para>
@@ -515,8 +509,7 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
515 success). 509 success).
516 </para> 510 </para>
517 </caution> 511 </caution>
518 [Yes, this moronic interface makes me cringe. Please submit a 512 [Yes, this moronic interface makes me cringe. The flamewar comes up every year or so. --RR.]
519 patch and become my hero --RR.]
520 </para> 513 </para>
521 <para> 514 <para>
522 The functions may sleep implicitly. This should never be called 515 The functions may sleep implicitly. This should never be called
@@ -587,10 +580,11 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
587 </variablelist> 580 </variablelist>
588 581
589 <para> 582 <para>
590 If you see a <errorname>kmem_grow: Called nonatomically from int 583 If you see a <errorname>sleeping function called from invalid
591 </errorname> warning message you called a memory allocation function 584 context</errorname> warning message, then maybe you called a
592 from interrupt context without <constant>GFP_ATOMIC</constant>. 585 sleeping allocation function from interrupt context without
593 You should really fix that. Run, don't walk. 586 <constant>GFP_ATOMIC</constant>. You should really fix that.
587 Run, don't walk.
594 </para> 588 </para>
595 589
596 <para> 590 <para>
@@ -639,16 +633,16 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
639 </sect1> 633 </sect1>
640 634
641 <sect1 id="routines-udelay"> 635 <sect1 id="routines-udelay">
642 <title><function>udelay()</function>/<function>mdelay()</function> 636 <title><function>mdelay()</function>/<function>udelay()</function>
643 <filename class="headerfile">include/asm/delay.h</filename> 637 <filename class="headerfile">include/asm/delay.h</filename>
644 <filename class="headerfile">include/linux/delay.h</filename> 638 <filename class="headerfile">include/linux/delay.h</filename>
645 </title> 639 </title>
646 640
647 <para> 641 <para>
648 The <function>udelay()</function> function can be used for small pauses. 642 The <function>udelay()</function> and <function>ndelay()</function> functions can be used for small pauses.
649 Do not use large values with <function>udelay()</function> as you risk 643 Do not use large values with them as you risk
650 overflow - the helper function <function>mdelay()</function> is useful 644 overflow - the helper function <function>mdelay()</function> is useful
651 here, or even consider <function>schedule_timeout()</function>. 645 here, or consider <function>msleep()</function>.
652 </para> 646 </para>
653 </sect1> 647 </sect1>
654 648
@@ -698,8 +692,8 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
698 These routines disable soft interrupts on the local CPU, and 692 These routines disable soft interrupts on the local CPU, and
699 restore them. They are reentrant; if soft interrupts were 693 restore them. They are reentrant; if soft interrupts were
700 disabled before, they will still be disabled after this pair 694 disabled before, they will still be disabled after this pair
701 of functions has been called. They prevent softirqs, tasklets 695 of functions has been called. They prevent softirqs and tasklets
702 and bottom halves from running on the current CPU. 696 from running on the current CPU.
703 </para> 697 </para>
704 </sect1> 698 </sect1>
705 699
@@ -708,10 +702,16 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
708 <filename class="headerfile">include/asm/smp.h</filename></title> 702 <filename class="headerfile">include/asm/smp.h</filename></title>
709 703
710 <para> 704 <para>
711 <function>smp_processor_id()</function> returns the current 705 <function>get_cpu()</function> disables preemption (so you won't
712 processor number, between 0 and <symbol>NR_CPUS</symbol> (the 706 suddenly get moved to another CPU) and returns the current
713 maximum number of CPUs supported by Linux, currently 32). These 707 processor number, between 0 and <symbol>NR_CPUS</symbol>. Note
714 values are not necessarily continuous. 708 that the CPU numbers are not necessarily continuous. You return
709 it again with <function>put_cpu()</function> when you are done.
710 </para>
711 <para>
712 If you know you cannot be preempted by another task (ie. you are
713 in interrupt context, or have preemption disabled) you can use
714 smp_processor_id().
715 </para> 715 </para>
716 </sect1> 716 </sect1>
717 717
@@ -722,19 +722,14 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
722 <para> 722 <para>
723 After boot, the kernel frees up a special section; functions 723 After boot, the kernel frees up a special section; functions
724 marked with <type>__init</type> and data structures marked with 724 marked with <type>__init</type> and data structures marked with
725 <type>__initdata</type> are dropped after boot is complete (within 725 <type>__initdata</type> are dropped after boot is complete: similarly
726 modules this directive is currently ignored). <type>__exit</type> 726 modules discard this memory after initialization. <type>__exit</type>
727 is used to declare a function which is only required on exit: the 727 is used to declare a function which is only required on exit: the
728 function will be dropped if this file is not compiled as a module. 728 function will be dropped if this file is not compiled as a module.
729 See the header file for use. Note that it makes no sense for a function 729 See the header file for use. Note that it makes no sense for a function
730 marked with <type>__init</type> to be exported to modules with 730 marked with <type>__init</type> to be exported to modules with
731 <function>EXPORT_SYMBOL()</function> - this will break. 731 <function>EXPORT_SYMBOL()</function> - this will break.
732 </para> 732 </para>
733 <para>
734 Static data structures marked as <type>__initdata</type> must be initialised
735 (as opposed to ordinary static data which is zeroed BSS) and cannot be
736 <type>const</type>.
737 </para>
738 733
739 </sect1> 734 </sect1>
740 735
@@ -762,9 +757,8 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
762 <para> 757 <para>
763 The function can return a negative error number to cause 758 The function can return a negative error number to cause
764 module loading to fail (unfortunately, this has no effect if 759 module loading to fail (unfortunately, this has no effect if
765 the module is compiled into the kernel). For modules, this is 760 the module is compiled into the kernel). This function is
766 called in user context, with interrupts enabled, and the 761 called in user context with interrupts enabled, so it can sleep.
767 kernel lock held, so it can sleep.
768 </para> 762 </para>
769 </sect1> 763 </sect1>
770 764
@@ -779,6 +773,34 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
779 reached zero. This function can also sleep, but cannot fail: 773 reached zero. This function can also sleep, but cannot fail:
780 everything must be cleaned up by the time it returns. 774 everything must be cleaned up by the time it returns.
781 </para> 775 </para>
776
777 <para>
778 Note that this macro is optional: if it is not present, your
779 module will not be removable (except for 'rmmod -f').
780 </para>
781 </sect1>
782
783 <sect1 id="routines-module-use-counters">
784 <title> <function>try_module_get()</function>/<function>module_put()</function>
785 <filename class="headerfile">include/linux/module.h</filename></title>
786
787 <para>
788 These manipulate the module usage count, to protect against
789 removal (a module also can't be removed if another module uses one
790 of its exported symbols: see below). Before calling into module
791 code, you should call <function>try_module_get()</function> on
792 that module: if it fails, then the module is being removed and you
793 should act as if it wasn't there. Otherwise, you can safely enter
794 the module, and call <function>module_put()</function> when you're
795 finished.
796 </para>
797
798 <para>
799 Most registerable structures have an
800 <structfield>owner</structfield> field, such as in the
801 <structname>file_operations</structname> structure. Set this field
802 to the macro <symbol>THIS_MODULE</symbol>.
803 </para>
782 </sect1> 804 </sect1>
783 805
784 <!-- add info on new-style module refcounting here --> 806 <!-- add info on new-style module refcounting here -->
@@ -821,7 +843,7 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
821 There is a macro to do this: 843 There is a macro to do this:
822 <function>wait_event_interruptible()</function> 844 <function>wait_event_interruptible()</function>
823 845
824 <filename class="headerfile">include/linux/sched.h</filename> The 846 <filename class="headerfile">include/linux/wait.h</filename> The
825 first argument is the wait queue head, and the second is an 847 first argument is the wait queue head, and the second is an
826 expression which is evaluated; the macro returns 848 expression which is evaluated; the macro returns
827 <returnvalue>0</returnvalue> when this expression is true, or 849 <returnvalue>0</returnvalue> when this expression is true, or
@@ -847,10 +869,11 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
847 <para> 869 <para>
848 Call <function>wake_up()</function> 870 Call <function>wake_up()</function>
849 871
850 <filename class="headerfile">include/linux/sched.h</filename>;, 872 <filename class="headerfile">include/linux/wait.h</filename>;,
851 which will wake up every process in the queue. The exception is 873 which will wake up every process in the queue. The exception is
852 if one has <constant>TASK_EXCLUSIVE</constant> set, in which case 874 if one has <constant>TASK_EXCLUSIVE</constant> set, in which case
853 the remainder of the queue will not be woken. 875 the remainder of the queue will not be woken. There are other variants
876 of this basic function available in the same header.
854 </para> 877 </para>
855 </sect1> 878 </sect1>
856 </chapter> 879 </chapter>
@@ -863,7 +886,7 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
863 first class of operations work on <type>atomic_t</type> 886 first class of operations work on <type>atomic_t</type>
864 887
865 <filename class="headerfile">include/asm/atomic.h</filename>; this 888 <filename class="headerfile">include/asm/atomic.h</filename>; this
866 contains a signed integer (at least 24 bits long), and you must use 889 contains a signed integer (at least 32 bits long), and you must use
867 these functions to manipulate or read atomic_t variables. 890 these functions to manipulate or read atomic_t variables.
868 <function>atomic_read()</function> and 891 <function>atomic_read()</function> and
869 <function>atomic_set()</function> get and set the counter, 892 <function>atomic_set()</function> get and set the counter,
@@ -882,13 +905,12 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
882 905
883 <para> 906 <para>
884 Note that these functions are slower than normal arithmetic, and 907 Note that these functions are slower than normal arithmetic, and
885 so should not be used unnecessarily. On some platforms they 908 so should not be used unnecessarily.
886 are much slower, like 32-bit Sparc where they use a spinlock.
887 </para> 909 </para>
888 910
889 <para> 911 <para>
890 The second class of atomic operations is atomic bit operations on a 912 The second class of atomic operations is atomic bit operations on an
891 <type>long</type>, defined in 913 <type>unsigned long</type>, defined in
892 914
893 <filename class="headerfile">include/linux/bitops.h</filename>. These 915 <filename class="headerfile">include/linux/bitops.h</filename>. These
894 operations generally take a pointer to the bit pattern, and a bit 916 operations generally take a pointer to the bit pattern, and a bit
@@ -899,7 +921,7 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
899 <function>test_and_clear_bit()</function> and 921 <function>test_and_clear_bit()</function> and
900 <function>test_and_change_bit()</function> do the same thing, 922 <function>test_and_change_bit()</function> do the same thing,
901 except return true if the bit was previously set; these are 923 except return true if the bit was previously set; these are
902 particularly useful for very simple locking. 924 particularly useful for atomically setting flags.
903 </para> 925 </para>
904 926
905 <para> 927 <para>
@@ -907,12 +929,6 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
907 than BITS_PER_LONG. The resulting behavior is strange on big-endian 929 than BITS_PER_LONG. The resulting behavior is strange on big-endian
908 platforms though so it is a good idea not to do this. 930 platforms though so it is a good idea not to do this.
909 </para> 931 </para>
910
911 <para>
912 Note that the order of bits depends on the architecture, and in
913 particular, the bitfield passed to these operations must be at
914 least as large as a <type>long</type>.
915 </para>
916 </chapter> 932 </chapter>
917 933
918 <chapter id="symbols"> 934 <chapter id="symbols">
@@ -932,11 +948,8 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
932 <filename class="headerfile">include/linux/module.h</filename></title> 948 <filename class="headerfile">include/linux/module.h</filename></title>
933 949
934 <para> 950 <para>
935 This is the classic method of exporting a symbol, and it works 951 This is the classic method of exporting a symbol: dynamically
936 for both modules and non-modules. In the kernel all these 952 loaded modules will be able to use the symbol as normal.
937 declarations are often bundled into a single file to help
938 genksyms (which searches source files for these declarations).
939 See the comment on genksyms and Makefiles below.
940 </para> 953 </para>
941 </sect1> 954 </sect1>
942 955
@@ -949,7 +962,8 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
949 symbols exported by <function>EXPORT_SYMBOL_GPL()</function> can 962 symbols exported by <function>EXPORT_SYMBOL_GPL()</function> can
950 only be seen by modules with a 963 only be seen by modules with a
951 <function>MODULE_LICENSE()</function> that specifies a GPL 964 <function>MODULE_LICENSE()</function> that specifies a GPL
952 compatible license. 965 compatible license. It implies that the function is considered
966 an internal implementation issue, and not really an interface.
953 </para> 967 </para>
954 </sect1> 968 </sect1>
955 </chapter> 969 </chapter>
@@ -962,12 +976,13 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
962 <filename class="headerfile">include/linux/list.h</filename></title> 976 <filename class="headerfile">include/linux/list.h</filename></title>
963 977
964 <para> 978 <para>
965 There are three sets of linked-list routines in the kernel 979 There used to be three sets of linked-list routines in the kernel
966 headers, but this one seems to be winning out (and Linus has 980 headers, but this one is the winner. If you don't have some
967 used it). If you don't have some particular pressing need for 981 particular pressing need for a single list, it's a good choice.
968 a single list, it's a good choice. In fact, I don't care 982 </para>
969 whether it's a good choice or not, just use it so we can get 983
970 rid of the others. 984 <para>
985 In particular, <function>list_for_each_entry</function> is useful.
971 </para> 986 </para>
972 </sect1> 987 </sect1>
973 988
@@ -979,14 +994,13 @@ printk(KERN_INFO "my ip: %d.%d.%d.%d\n", NIPQUAD(ipaddress));
979 convention, and return <returnvalue>0</returnvalue> for success, 994 convention, and return <returnvalue>0</returnvalue> for success,
980 and a negative error number 995 and a negative error number
981 (eg. <returnvalue>-EFAULT</returnvalue>) for failure. This can be 996 (eg. <returnvalue>-EFAULT</returnvalue>) for failure. This can be
982 unintuitive at first, but it's fairly widespread in the networking 997 unintuitive at first, but it's fairly widespread in the kernel.
983 code, for example.
984 </para> 998 </para>
985 999
986 <para> 1000 <para>
987 The filesystem code uses <function>ERR_PTR()</function> 1001 Using <function>ERR_PTR()</function>
988 1002
989 <filename class="headerfile">include/linux/fs.h</filename>; to 1003 <filename class="headerfile">include/linux/err.h</filename>; to
990 encode a negative error number into a pointer, and 1004 encode a negative error number into a pointer, and
991 <function>IS_ERR()</function> and <function>PTR_ERR()</function> 1005 <function>IS_ERR()</function> and <function>PTR_ERR()</function>
992 to get it back out again: avoids a separate pointer parameter for 1006 to get it back out again: avoids a separate pointer parameter for
@@ -1040,7 +1054,7 @@ static struct block_device_operations opt_fops = {
1040 supported, due to lack of general use, but the following are 1054 supported, due to lack of general use, but the following are
1041 considered standard (see the GCC info page section "C 1055 considered standard (see the GCC info page section "C
1042 Extensions" for more details - Yes, really the info page, the 1056 Extensions" for more details - Yes, really the info page, the
1043 man page is only a short summary of the stuff in info): 1057 man page is only a short summary of the stuff in info).
1044 </para> 1058 </para>
1045 <itemizedlist> 1059 <itemizedlist>
1046 <listitem> 1060 <listitem>
@@ -1091,7 +1105,7 @@ static struct block_device_operations opt_fops = {
1091 </listitem> 1105 </listitem>
1092 <listitem> 1106 <listitem>
1093 <para> 1107 <para>
1094 Function names as strings (__FUNCTION__) 1108 Function names as strings (__func__).
1095 </para> 1109 </para>
1096 </listitem> 1110 </listitem>
1097 <listitem> 1111 <listitem>
@@ -1164,63 +1178,35 @@ static struct block_device_operations opt_fops = {
1164 <listitem> 1178 <listitem>
1165 <para> 1179 <para>
1166 Usually you want a configuration option for your kernel hack. 1180 Usually you want a configuration option for your kernel hack.
1167 Edit <filename>Config.in</filename> in the appropriate directory 1181 Edit <filename>Kconfig</filename> in the appropriate directory.
1168 (but under <filename>arch/</filename> it's called 1182 The Config language is simple to use by cut and paste, and there's
1169 <filename>config.in</filename>). The Config Language used is not 1183 complete documentation in
1170 bash, even though it looks like bash; the safe way is to use only 1184 <filename>Documentation/kbuild/kconfig-language.txt</filename>.
1171 the constructs that you already see in
1172 <filename>Config.in</filename> files (see
1173 <filename>Documentation/kbuild/kconfig-language.txt</filename>).
1174 It's good to run "make xconfig" at least once to test (because
1175 it's the only one with a static parser).
1176 </para>
1177
1178 <para>
1179 Variables which can be Y or N use <type>bool</type> followed by a
1180 tagline and the config define name (which must start with
1181 CONFIG_). The <type>tristate</type> function is the same, but
1182 allows the answer M (which defines
1183 <symbol>CONFIG_foo_MODULE</symbol> in your source, instead of
1184 <symbol>CONFIG_FOO</symbol>) if <symbol>CONFIG_MODULES</symbol>
1185 is enabled.
1186 </para> 1185 </para>
1187 1186
1188 <para> 1187 <para>
1189 You may well want to make your CONFIG option only visible if 1188 You may well want to make your CONFIG option only visible if
1190 <symbol>CONFIG_EXPERIMENTAL</symbol> is enabled: this serves as a 1189 <symbol>CONFIG_EXPERIMENTAL</symbol> is enabled: this serves as a
1191 warning to users. There many other fancy things you can do: see 1190 warning to users. There many other fancy things you can do: see
1192 the various <filename>Config.in</filename> files for ideas. 1191 the various <filename>Kconfig</filename> files for ideas.
1193 </para> 1192 </para>
1194 </listitem>
1195 1193
1196 <listitem>
1197 <para> 1194 <para>
1198 Edit the <filename>Makefile</filename>: the CONFIG variables are 1195 In your description of the option, make sure you address both the
1199 exported here so you can conditionalize compilation with `ifeq'. 1196 expert user and the user who knows nothing about your feature. Mention
1200 If your file exports symbols then add the names to 1197 incompatibilities and issues here. <emphasis> Definitely
1201 <varname>export-objs</varname> so that genksyms will find them. 1198 </emphasis> end your description with <quote> if in doubt, say N
1202 <caution> 1199 </quote> (or, occasionally, `Y'); this is for people who have no
1203 <para> 1200 idea what you are talking about.
1204 There is a restriction on the kernel build system that objects
1205 which export symbols must have globally unique names.
1206 If your object does not have a globally unique name then the
1207 standard fix is to move the
1208 <function>EXPORT_SYMBOL()</function> statements to their own
1209 object with a unique name.
1210 This is why several systems have separate exporting objects,
1211 usually suffixed with ksyms.
1212 </para>
1213 </caution>
1214 </para> 1201 </para>
1215 </listitem> 1202 </listitem>
1216 1203
1217 <listitem> 1204 <listitem>
1218 <para> 1205 <para>
1219 Document your option in Documentation/Configure.help. Mention 1206 Edit the <filename>Makefile</filename>: the CONFIG variables are
1220 incompatibilities and issues here. <emphasis> Definitely 1207 exported here so you can usually just add a "obj-$(CONFIG_xxx) +=
1221 </emphasis> end your description with <quote> if in doubt, say N 1208 xxx.o" line. The syntax is documented in
1222 </quote> (or, occasionally, `Y'); this is for people who have no 1209 <filename>Documentation/kbuild/makefiles.txt</filename>.
1223 idea what you are talking about.
1224 </para> 1210 </para>
1225 </listitem> 1211 </listitem>
1226 1212
@@ -1253,20 +1239,12 @@ static struct block_device_operations opt_fops = {
1253 </para> 1239 </para>
1254 1240
1255 <para> 1241 <para>
1256 <filename>include/linux/brlock.h:</filename> 1242 <filename>include/asm-i386/delay.h:</filename>
1257 </para> 1243 </para>
1258 <programlisting> 1244 <programlisting>
1259extern inline void br_read_lock (enum brlock_indices idx) 1245#define ndelay(n) (__builtin_constant_p(n) ? \
1260{ 1246 ((n) > 20000 ? __bad_ndelay() : __const_udelay((n) * 5ul)) : \
1261 /* 1247 __ndelay(n))
1262 * This causes a link-time bug message if an
1263 * invalid index is used:
1264 */
1265 if (idx >= __BR_END)
1266 __br_lock_usage_bug();
1267
1268 read_lock(&amp;__brlock_array[smp_processor_id()][idx]);
1269}
1270 </programlisting> 1248 </programlisting>
1271 1249
1272 <para> 1250 <para>
diff --git a/Documentation/DocBook/usb.tmpl b/Documentation/DocBook/usb.tmpl
index f3ef0bf435..705c442c7b 100644
--- a/Documentation/DocBook/usb.tmpl
+++ b/Documentation/DocBook/usb.tmpl
@@ -841,7 +841,7 @@ usbdev_ioctl (int fd, int ifno, unsigned request, void *param)
841 File modification time is not updated by this request. 841 File modification time is not updated by this request.
842 </para><para> 842 </para><para>
843 Those struct members are from some interface descriptor 843 Those struct members are from some interface descriptor
844 applying to the the current configuration. 844 applying to the current configuration.
845 The interface number is the bInterfaceNumber value, and 845 The interface number is the bInterfaceNumber value, and
846 the altsetting number is the bAlternateSetting value. 846 the altsetting number is the bAlternateSetting value.
847 (This resets each endpoint in the interface.) 847 (This resets each endpoint in the interface.)
diff --git a/Documentation/MSI-HOWTO.txt b/Documentation/MSI-HOWTO.txt
index d5032eb480..63edc5f847 100644
--- a/Documentation/MSI-HOWTO.txt
+++ b/Documentation/MSI-HOWTO.txt
@@ -430,7 +430,7 @@ which may result in system hang. The software driver of specific
430MSI-capable hardware is responsible for whether calling 430MSI-capable hardware is responsible for whether calling
431pci_enable_msi or not. A return of zero indicates the kernel 431pci_enable_msi or not. A return of zero indicates the kernel
432successfully initializes the MSI/MSI-X capability structure of the 432successfully initializes the MSI/MSI-X capability structure of the
433device funtion. The device function is now running on MSI/MSI-X mode. 433device function. The device function is now running on MSI/MSI-X mode.
434 434
4355.6 How to tell whether MSI/MSI-X is enabled on device function 4355.6 How to tell whether MSI/MSI-X is enabled on device function
436 436
diff --git a/Documentation/RCU/RTFP.txt b/Documentation/RCU/RTFP.txt
index 9c6d450138..fcbcbc35b1 100644
--- a/Documentation/RCU/RTFP.txt
+++ b/Documentation/RCU/RTFP.txt
@@ -2,7 +2,8 @@ Read the F-ing Papers!
2 2
3 3
4This document describes RCU-related publications, and is followed by 4This document describes RCU-related publications, and is followed by
5the corresponding bibtex entries. 5the corresponding bibtex entries. A number of the publications may
6be found at http://www.rdrop.com/users/paulmck/RCU/.
6 7
7The first thing resembling RCU was published in 1980, when Kung and Lehman 8The first thing resembling RCU was published in 1980, when Kung and Lehman
8[Kung80] recommended use of a garbage collector to defer destruction 9[Kung80] recommended use of a garbage collector to defer destruction
@@ -113,6 +114,10 @@ describing how to make RCU safe for soft-realtime applications [Sarma04c],
113and a paper describing SELinux performance with RCU [JamesMorris04b]. 114and a paper describing SELinux performance with RCU [JamesMorris04b].
114 115
115 116
1172005 has seen further adaptation of RCU to realtime use, permitting
118preemption of RCU realtime critical sections [PaulMcKenney05a,
119PaulMcKenney05b].
120
116Bibtex Entries 121Bibtex Entries
117 122
118@article{Kung80 123@article{Kung80
@@ -410,3 +415,32 @@ Oregon Health and Sciences University"
410\url{http://www.livejournal.com/users/james_morris/2153.html} 415\url{http://www.livejournal.com/users/james_morris/2153.html}
411[Viewed December 10, 2004]" 416[Viewed December 10, 2004]"
412} 417}
418
419@unpublished{PaulMcKenney05a
420,Author="Paul E. McKenney"
421,Title="{[RFC]} {RCU} and {CONFIG\_PREEMPT\_RT} progress"
422,month="May"
423,year="2005"
424,note="Available:
425\url{http://lkml.org/lkml/2005/5/9/185}
426[Viewed May 13, 2005]"
427,annotation="
428 First publication of working lock-based deferred free patches
429 for the CONFIG_PREEMPT_RT environment.
430"
431}
432
433@conference{PaulMcKenney05b
434,Author="Paul E. McKenney and Dipankar Sarma"
435,Title="Towards Hard Realtime Response from the Linux Kernel on SMP Hardware"
436,Booktitle="linux.conf.au 2005"
437,month="April"
438,year="2005"
439,address="Canberra, Australia"
440,note="Available:
441\url{http://www.rdrop.com/users/paulmck/RCU/realtimeRCU.2005.04.23a.pdf}
442[Viewed May 13, 2005]"
443,annotation="
444 Realtime turns into making RCU yet more realtime friendly.
445"
446}
diff --git a/Documentation/RCU/UP.txt b/Documentation/RCU/UP.txt
index 3bfb84b3b7..aab4a9ec39 100644
--- a/Documentation/RCU/UP.txt
+++ b/Documentation/RCU/UP.txt
@@ -8,7 +8,7 @@ is that since there is only one CPU, it should not be necessary to
8wait for anything else to get done, since there are no other CPUs for 8wait for anything else to get done, since there are no other CPUs for
9anything else to be happening on. Although this approach will -sort- -of- 9anything else to be happening on. Although this approach will -sort- -of-
10work a surprising amount of the time, it is a very bad idea in general. 10work a surprising amount of the time, it is a very bad idea in general.
11This document presents two examples that demonstrate exactly how bad an 11This document presents three examples that demonstrate exactly how bad an
12idea this is. 12idea this is.
13 13
14 14
@@ -26,6 +26,9 @@ from softirq, the list scan would find itself referencing a newly freed
26element B. This situation can greatly decrease the life expectancy of 26element B. This situation can greatly decrease the life expectancy of
27your kernel. 27your kernel.
28 28
29This same problem can occur if call_rcu() is invoked from a hardware
30interrupt handler.
31
29 32
30Example 2: Function-Call Fatality 33Example 2: Function-Call Fatality
31 34
@@ -44,8 +47,37 @@ its arguments would cause it to fail to make the fundamental guarantee
44underlying RCU, namely that call_rcu() defers invoking its arguments until 47underlying RCU, namely that call_rcu() defers invoking its arguments until
45all RCU read-side critical sections currently executing have completed. 48all RCU read-side critical sections currently executing have completed.
46 49
47Quick Quiz: why is it -not- legal to invoke synchronize_rcu() in 50Quick Quiz #1: why is it -not- legal to invoke synchronize_rcu() in
48this case? 51 this case?
52
53
54Example 3: Death by Deadlock
55
56Suppose that call_rcu() is invoked while holding a lock, and that the
57callback function must acquire this same lock. In this case, if
58call_rcu() were to directly invoke the callback, the result would
59be self-deadlock.
60
61In some cases, it would possible to restructure to code so that
62the call_rcu() is delayed until after the lock is released. However,
63there are cases where this can be quite ugly:
64
651. If a number of items need to be passed to call_rcu() within
66 the same critical section, then the code would need to create
67 a list of them, then traverse the list once the lock was
68 released.
69
702. In some cases, the lock will be held across some kernel API,
71 so that delaying the call_rcu() until the lock is released
72 requires that the data item be passed up via a common API.
73 It is far better to guarantee that callbacks are invoked
74 with no locks held than to have to modify such APIs to allow
75 arbitrary data items to be passed back up through them.
76
77If call_rcu() directly invokes the callback, painful locking restrictions
78or API changes would be required.
79
80Quick Quiz #2: What locking restriction must RCU callbacks respect?
49 81
50 82
51Summary 83Summary
@@ -53,12 +85,35 @@ Summary
53Permitting call_rcu() to immediately invoke its arguments or permitting 85Permitting call_rcu() to immediately invoke its arguments or permitting
54synchronize_rcu() to immediately return breaks RCU, even on a UP system. 86synchronize_rcu() to immediately return breaks RCU, even on a UP system.
55So do not do it! Even on a UP system, the RCU infrastructure -must- 87So do not do it! Even on a UP system, the RCU infrastructure -must-
56respect grace periods. 88respect grace periods, and -must- invoke callbacks from a known environment
57 89in which no locks are held.
58 90
59Answer to Quick Quiz 91
60 92Answer to Quick Quiz #1:
61The calling function is scanning an RCU-protected linked list, and 93 Why is it -not- legal to invoke synchronize_rcu() in this case?
62is therefore within an RCU read-side critical section. Therefore, 94
63the called function has been invoked within an RCU read-side critical 95 Because the calling function is scanning an RCU-protected linked
64section, and is not permitted to block. 96 list, and is therefore within an RCU read-side critical section.
97 Therefore, the called function has been invoked within an RCU
98 read-side critical section, and is not permitted to block.
99
100Answer to Quick Quiz #2:
101 What locking restriction must RCU callbacks respect?
102
103 Any lock that is acquired within an RCU callback must be
104 acquired elsewhere using an _irq variant of the spinlock
105 primitive. For example, if "mylock" is acquired by an
106 RCU callback, then a process-context acquisition of this
107 lock must use something like spin_lock_irqsave() to
108 acquire the lock.
109
110 If the process-context code were to simply use spin_lock(),
111 then, since RCU callbacks can be invoked from softirq context,
112 the callback might be called from a softirq that interrupted
113 the process-context critical section. This would result in
114 self-deadlock.
115
116 This restriction might seem gratuitous, since very few RCU
117 callbacks acquire locks directly. However, a great many RCU
118 callbacks do acquire locks -indirectly-, for example, via
119 the kfree() primitive.
diff --git a/Documentation/RCU/checklist.txt b/Documentation/RCU/checklist.txt
index 8f3fb77c9c..e118a7c1a0 100644
--- a/Documentation/RCU/checklist.txt
+++ b/Documentation/RCU/checklist.txt
@@ -43,6 +43,10 @@ over a rather long period of time, but improvements are always welcome!
43 rcu_read_lock_bh()) in the read-side critical sections, 43 rcu_read_lock_bh()) in the read-side critical sections,
44 and are also an excellent aid to readability. 44 and are also an excellent aid to readability.
45 45
46 As a rough rule of thumb, any dereference of an RCU-protected
47 pointer must be covered by rcu_read_lock() or rcu_read_lock_bh()
48 or by the appropriate update-side lock.
49
463. Does the update code tolerate concurrent accesses? 503. Does the update code tolerate concurrent accesses?
47 51
48 The whole point of RCU is to permit readers to run without 52 The whole point of RCU is to permit readers to run without
@@ -90,7 +94,11 @@ over a rather long period of time, but improvements are always welcome!
90 94
91 The rcu_dereference() primitive is used by the various 95 The rcu_dereference() primitive is used by the various
92 "_rcu()" list-traversal primitives, such as the 96 "_rcu()" list-traversal primitives, such as the
93 list_for_each_entry_rcu(). 97 list_for_each_entry_rcu(). Note that it is perfectly
98 legal (if redundant) for update-side code to use
99 rcu_dereference() and the "_rcu()" list-traversal
100 primitives. This is particularly useful in code
101 that is common to readers and updaters.
94 102
95 b. If the list macros are being used, the list_add_tail_rcu() 103 b. If the list macros are being used, the list_add_tail_rcu()
96 and list_add_rcu() primitives must be used in order 104 and list_add_rcu() primitives must be used in order
@@ -150,16 +158,9 @@ over a rather long period of time, but improvements are always welcome!
150 158
151 Use of the _rcu() list-traversal primitives outside of an 159 Use of the _rcu() list-traversal primitives outside of an
152 RCU read-side critical section causes no harm other than 160 RCU read-side critical section causes no harm other than
153 a slight performance degradation on Alpha CPUs and some 161 a slight performance degradation on Alpha CPUs. It can
154 confusion on the part of people trying to read the code. 162 also be quite helpful in reducing code bloat when common
155 163 code is shared between readers and updaters.
156 Another way of thinking of this is "If you are holding the
157 lock that prevents the data structure from changing, why do
158 you also need RCU-based protection?" That said, there may
159 well be situations where use of the _rcu() list-traversal
160 primitives while the update-side lock is held results in
161 simpler and more maintainable code. The jury is still out
162 on this question.
163 164
16410. Conversely, if you are in an RCU read-side critical section, 16510. Conversely, if you are in an RCU read-side critical section,
165 you -must- use the "_rcu()" variants of the list macros. 166 you -must- use the "_rcu()" variants of the list macros.
diff --git a/Documentation/RCU/rcu.txt b/Documentation/RCU/rcu.txt
index eb44400668..6fa0922515 100644
--- a/Documentation/RCU/rcu.txt
+++ b/Documentation/RCU/rcu.txt
@@ -64,6 +64,54 @@ o I hear that RCU is patented? What is with that?
64 Of these, one was allowed to lapse by the assignee, and the 64 Of these, one was allowed to lapse by the assignee, and the
65 others have been contributed to the Linux kernel under GPL. 65 others have been contributed to the Linux kernel under GPL.
66 66
67o I hear that RCU needs work in order to support realtime kernels?
68
69 Yes, work in progress.
70
67o Where can I find more information on RCU? 71o Where can I find more information on RCU?
68 72
69 See the RTFP.txt file in this directory. 73 See the RTFP.txt file in this directory.
74 Or point your browser at http://www.rdrop.com/users/paulmck/RCU/.
75
76o What are all these files in this directory?
77
78
79 NMI-RCU.txt
80
81 Describes how to use RCU to implement dynamic
82 NMI handlers, which can be revectored on the fly,
83 without rebooting.
84
85 RTFP.txt
86
87 List of RCU-related publications and web sites.
88
89 UP.txt
90
91 Discussion of RCU usage in UP kernels.
92
93 arrayRCU.txt
94
95 Describes how to use RCU to protect arrays, with
96 resizeable arrays whose elements reference other
97 data structures being of the most interest.
98
99 checklist.txt
100
101 Lists things to check for when inspecting code that
102 uses RCU.
103
104 listRCU.txt
105
106 Describes how to use RCU to protect linked lists.
107 This is the simplest and most common use of RCU
108 in the Linux kernel.
109
110 rcu.txt
111
112 You are reading it!
113
114 whatisRCU.txt
115
116 Overview of how the RCU implementation works. Along
117 the way, presents a conceptual view of RCU.
diff --git a/Documentation/RCU/rcuref.txt b/Documentation/RCU/rcuref.txt
new file mode 100644
index 0000000000..a23fee6606
--- /dev/null
+++ b/Documentation/RCU/rcuref.txt
@@ -0,0 +1,74 @@
1Refcounter framework for elements of lists/arrays protected by
2RCU.
3
4Refcounting on elements of lists which are protected by traditional
5reader/writer spinlocks or semaphores are straight forward as in:
6
71. 2.
8add() search_and_reference()
9{ {
10 alloc_object read_lock(&list_lock);
11 ... search_for_element
12 atomic_set(&el->rc, 1); atomic_inc(&el->rc);
13 write_lock(&list_lock); ...
14 add_element read_unlock(&list_lock);
15 ... ...
16 write_unlock(&list_lock); }
17}
18
193. 4.
20release_referenced() delete()
21{ {
22 ... write_lock(&list_lock);
23 atomic_dec(&el->rc, relfunc) ...
24 ... delete_element
25} write_unlock(&list_lock);
26 ...
27 if (atomic_dec_and_test(&el->rc))
28 kfree(el);
29 ...
30 }
31
32If this list/array is made lock free using rcu as in changing the
33write_lock in add() and delete() to spin_lock and changing read_lock
34in search_and_reference to rcu_read_lock(), the rcuref_get in
35search_and_reference could potentially hold reference to an element which
36has already been deleted from the list/array. rcuref_lf_get_rcu takes
37care of this scenario. search_and_reference should look as;
38
391. 2.
40add() search_and_reference()
41{ {
42 alloc_object rcu_read_lock();
43 ... search_for_element
44 atomic_set(&el->rc, 1); if (rcuref_inc_lf(&el->rc)) {
45 write_lock(&list_lock); rcu_read_unlock();
46 return FAIL;
47 add_element }
48 ... ...
49 write_unlock(&list_lock); rcu_read_unlock();
50} }
513. 4.
52release_referenced() delete()
53{ {
54 ... write_lock(&list_lock);
55 rcuref_dec(&el->rc, relfunc) ...
56 ... delete_element
57} write_unlock(&list_lock);
58 ...
59 if (rcuref_dec_and_test(&el->rc))
60 call_rcu(&el->head, el_free);
61 ...
62 }
63
64Sometimes, reference to the element need to be obtained in the
65update (write) stream. In such cases, rcuref_inc_lf might be an overkill
66since the spinlock serialising list updates are held. rcuref_inc
67is to be used in such cases.
68For arches which do not have cmpxchg rcuref_inc_lf
69api uses a hashed spinlock implementation and the same hashed spinlock
70is acquired in all rcuref_xxx primitives to preserve atomicity.
71Note: Use rcuref_inc api only if you need to use rcuref_inc_lf on the
72refcounter atleast at one place. Mixing rcuref_inc and atomic_xxx api
73might lead to races. rcuref_inc_lf() must be used in lockfree
74RCU critical sections only.
diff --git a/Documentation/RCU/whatisRCU.txt b/Documentation/RCU/whatisRCU.txt
new file mode 100644
index 0000000000..354d89c783
--- /dev/null
+++ b/Documentation/RCU/whatisRCU.txt
@@ -0,0 +1,902 @@
1What is RCU?
2
3RCU is a synchronization mechanism that was added to the Linux kernel
4during the 2.5 development effort that is optimized for read-mostly
5situations. Although RCU is actually quite simple once you understand it,
6getting there can sometimes be a challenge. Part of the problem is that
7most of the past descriptions of RCU have been written with the mistaken
8assumption that there is "one true way" to describe RCU. Instead,
9the experience has been that different people must take different paths
10to arrive at an understanding of RCU. This document provides several
11different paths, as follows:
12
131. RCU OVERVIEW
142. WHAT IS RCU'S CORE API?
153. WHAT ARE SOME EXAMPLE USES OF CORE RCU API?
164. WHAT IF MY UPDATING THREAD CANNOT BLOCK?
175. WHAT ARE SOME SIMPLE IMPLEMENTATIONS OF RCU?
186. ANALOGY WITH READER-WRITER LOCKING
197. FULL LIST OF RCU APIs
208. ANSWERS TO QUICK QUIZZES
21
22People who prefer starting with a conceptual overview should focus on
23Section 1, though most readers will profit by reading this section at
24some point. People who prefer to start with an API that they can then
25experiment with should focus on Section 2. People who prefer to start
26with example uses should focus on Sections 3 and 4. People who need to
27understand the RCU implementation should focus on Section 5, then dive
28into the kernel source code. People who reason best by analogy should
29focus on Section 6. Section 7 serves as an index to the docbook API
30documentation, and Section 8 is the traditional answer key.
31
32So, start with the section that makes the most sense to you and your
33preferred method of learning. If you need to know everything about
34everything, feel free to read the whole thing -- but if you are really
35that type of person, you have perused the source code and will therefore
36never need this document anyway. ;-)
37
38
391. RCU OVERVIEW
40
41The basic idea behind RCU is to split updates into "removal" and
42"reclamation" phases. The removal phase removes references to data items
43within a data structure (possibly by replacing them with references to
44new versions of these data items), and can run concurrently with readers.
45The reason that it is safe to run the removal phase concurrently with
46readers is the semantics of modern CPUs guarantee that readers will see
47either the old or the new version of the data structure rather than a
48partially updated reference. The reclamation phase does the work of reclaiming
49(e.g., freeing) the data items removed from the data structure during the
50removal phase. Because reclaiming data items can disrupt any readers
51concurrently referencing those data items, the reclamation phase must
52not start until readers no longer hold references to those data items.
53
54Splitting the update into removal and reclamation phases permits the
55updater to perform the removal phase immediately, and to defer the
56reclamation phase until all readers active during the removal phase have
57completed, either by blocking until they finish or by registering a
58callback that is invoked after they finish. Only readers that are active
59during the removal phase need be considered, because any reader starting
60after the removal phase will be unable to gain a reference to the removed
61data items, and therefore cannot be disrupted by the reclamation phase.
62
63So the typical RCU update sequence goes something like the following:
64
65a. Remove pointers to a data structure, so that subsequent
66 readers cannot gain a reference to it.
67
68b. Wait for all previous readers to complete their RCU read-side
69 critical sections.
70
71c. At this point, there cannot be any readers who hold references
72 to the data structure, so it now may safely be reclaimed
73 (e.g., kfree()d).
74
75Step (b) above is the key idea underlying RCU's deferred destruction.
76The ability to wait until all readers are done allows RCU readers to
77use much lighter-weight synchronization, in some cases, absolutely no
78synchronization at all. In contrast, in more conventional lock-based
79schemes, readers must use heavy-weight synchronization in order to
80prevent an updater from deleting the data structure out from under them.
81This is because lock-based updaters typically update data items in place,
82and must therefore exclude readers. In contrast, RCU-based updaters
83typically take advantage of the fact that writes to single aligned
84pointers are atomic on modern CPUs, allowing atomic insertion, removal,
85and replacement of data items in a linked structure without disrupting
86readers. Concurrent RCU readers can then continue accessing the old
87versions, and can dispense with the atomic operations, memory barriers,
88and communications cache misses that are so expensive on present-day
89SMP computer systems, even in absence of lock contention.
90
91In the three-step procedure shown above, the updater is performing both
92the removal and the reclamation step, but it is often helpful for an
93entirely different thread to do the reclamation, as is in fact the case
94in the Linux kernel's directory-entry cache (dcache). Even if the same
95thread performs both the update step (step (a) above) and the reclamation
96step (step (c) above), it is often helpful to think of them separately.
97For example, RCU readers and updaters need not communicate at all,
98but RCU provides implicit low-overhead communication between readers
99and reclaimers, namely, in step (b) above.
100
101So how the heck can a reclaimer tell when a reader is done, given
102that readers are not doing any sort of synchronization operations???
103Read on to learn about how RCU's API makes this easy.
104
105
1062. WHAT IS RCU'S CORE API?
107
108The core RCU API is quite small:
109
110a. rcu_read_lock()
111b. rcu_read_unlock()
112c. synchronize_rcu() / call_rcu()
113d. rcu_assign_pointer()
114e. rcu_dereference()
115
116There are many other members of the RCU API, but the rest can be
117expressed in terms of these five, though most implementations instead
118express synchronize_rcu() in terms of the call_rcu() callback API.
119
120The five core RCU APIs are described below, the other 18 will be enumerated
121later. See the kernel docbook documentation for more info, or look directly
122at the function header comments.
123
124rcu_read_lock()
125
126 void rcu_read_lock(void);
127
128 Used by a reader to inform the reclaimer that the reader is
129 entering an RCU read-side critical section. It is illegal
130 to block while in an RCU read-side critical section, though
131 kernels built with CONFIG_PREEMPT_RCU can preempt RCU read-side
132 critical sections. Any RCU-protected data structure accessed
133 during an RCU read-side critical section is guaranteed to remain
134 unreclaimed for the full duration of that critical section.
135 Reference counts may be used in conjunction with RCU to maintain
136 longer-term references to data structures.
137
138rcu_read_unlock()
139
140 void rcu_read_unlock(void);
141
142 Used by a reader to inform the reclaimer that the reader is
143 exiting an RCU read-side critical section. Note that RCU
144 read-side critical sections may be nested and/or overlapping.
145
146synchronize_rcu()
147
148 void synchronize_rcu(void);
149
150 Marks the end of updater code and the beginning of reclaimer
151 code. It does this by blocking until all pre-existing RCU
152 read-side critical sections on all CPUs have completed.
153 Note that synchronize_rcu() will -not- necessarily wait for
154 any subsequent RCU read-side critical sections to complete.
155 For example, consider the following sequence of events:
156
157 CPU 0 CPU 1 CPU 2
158 ----------------- ------------------------- ---------------
159 1. rcu_read_lock()
160 2. enters synchronize_rcu()
161 3. rcu_read_lock()
162 4. rcu_read_unlock()
163 5. exits synchronize_rcu()
164 6. rcu_read_unlock()
165
166 To reiterate, synchronize_rcu() waits only for ongoing RCU
167 read-side critical sections to complete, not necessarily for
168 any that begin after synchronize_rcu() is invoked.
169
170 Of course, synchronize_rcu() does not necessarily return
171 -immediately- after the last pre-existing RCU read-side critical
172 section completes. For one thing, there might well be scheduling
173 delays. For another thing, many RCU implementations process
174 requests in batches in order to improve efficiencies, which can
175 further delay synchronize_rcu().
176
177 Since synchronize_rcu() is the API that must figure out when
178 readers are done, its implementation is key to RCU. For RCU
179 to be useful in all but the most read-intensive situations,
180 synchronize_rcu()'s overhead must also be quite small.
181
182 The call_rcu() API is a callback form of synchronize_rcu(),
183 and is described in more detail in a later section. Instead of
184 blocking, it registers a function and argument which are invoked
185 after all ongoing RCU read-side critical sections have completed.
186 This callback variant is particularly useful in situations where
187 it is illegal to block.
188
189rcu_assign_pointer()
190
191 typeof(p) rcu_assign_pointer(p, typeof(p) v);
192
193 Yes, rcu_assign_pointer() -is- implemented as a macro, though it
194 would be cool to be able to declare a function in this manner.
195 (Compiler experts will no doubt disagree.)
196
197 The updater uses this function to assign a new value to an
198 RCU-protected pointer, in order to safely communicate the change
199 in value from the updater to the reader. This function returns
200 the new value, and also executes any memory-barrier instructions
201 required for a given CPU architecture.
202
203 Perhaps more important, it serves to document which pointers
204 are protected by RCU. That said, rcu_assign_pointer() is most
205 frequently used indirectly, via the _rcu list-manipulation
206 primitives such as list_add_rcu().
207
208rcu_dereference()
209
210 typeof(p) rcu_dereference(p);
211
212 Like rcu_assign_pointer(), rcu_dereference() must be implemented
213 as a macro.
214
215 The reader uses rcu_dereference() to fetch an RCU-protected
216 pointer, which returns a value that may then be safely
217 dereferenced. Note that rcu_deference() does not actually
218 dereference the pointer, instead, it protects the pointer for
219 later dereferencing. It also executes any needed memory-barrier
220 instructions for a given CPU architecture. Currently, only Alpha
221 needs memory barriers within rcu_dereference() -- on other CPUs,
222 it compiles to nothing, not even a compiler directive.
223
224 Common coding practice uses rcu_dereference() to copy an
225 RCU-protected pointer to a local variable, then dereferences
226 this local variable, for example as follows:
227
228 p = rcu_dereference(head.next);
229 return p->data;
230
231 However, in this case, one could just as easily combine these
232 into one statement:
233
234 return rcu_dereference(head.next)->data;
235
236 If you are going to be fetching multiple fields from the
237 RCU-protected structure, using the local variable is of
238 course preferred. Repeated rcu_dereference() calls look
239 ugly and incur unnecessary overhead on Alpha CPUs.
240
241 Note that the value returned by rcu_dereference() is valid
242 only within the enclosing RCU read-side critical section.
243 For example, the following is -not- legal:
244
245 rcu_read_lock();
246 p = rcu_dereference(head.next);
247 rcu_read_unlock();
248 x = p->address;
249 rcu_read_lock();
250 y = p->data;
251 rcu_read_unlock();
252
253 Holding a reference from one RCU read-side critical section
254 to another is just as illegal as holding a reference from
255 one lock-based critical section to another! Similarly,
256 using a reference outside of the critical section in which
257 it was acquired is just as illegal as doing so with normal
258 locking.
259
260 As with rcu_assign_pointer(), an important function of
261 rcu_dereference() is to document which pointers are protected
262 by RCU. And, again like rcu_assign_pointer(), rcu_dereference()
263 is typically used indirectly, via the _rcu list-manipulation
264 primitives, such as list_for_each_entry_rcu().
265
266The following diagram shows how each API communicates among the
267reader, updater, and reclaimer.
268
269
270 rcu_assign_pointer()
271 +--------+
272 +---------------------->| reader |---------+
273 | +--------+ |
274 | | |
275 | | | Protect:
276 | | | rcu_read_lock()
277 | | | rcu_read_unlock()
278 | rcu_dereference() | |
279 +---------+ | |
280 | updater |<---------------------+ |
281 +---------+ V
282 | +-----------+
283 +----------------------------------->| reclaimer |
284 +-----------+
285 Defer:
286 synchronize_rcu() & call_rcu()
287
288
289The RCU infrastructure observes the time sequence of rcu_read_lock(),
290rcu_read_unlock(), synchronize_rcu(), and call_rcu() invocations in
291order to determine when (1) synchronize_rcu() invocations may return
292to their callers and (2) call_rcu() callbacks may be invoked. Efficient
293implementations of the RCU infrastructure make heavy use of batching in
294order to amortize their overhead over many uses of the corresponding APIs.
295
296There are no fewer than three RCU mechanisms in the Linux kernel; the
297diagram above shows the first one, which is by far the most commonly used.
298The rcu_dereference() and rcu_assign_pointer() primitives are used for
299all three mechanisms, but different defer and protect primitives are
300used as follows:
301
302 Defer Protect
303
304a. synchronize_rcu() rcu_read_lock() / rcu_read_unlock()
305 call_rcu()
306
307b. call_rcu_bh() rcu_read_lock_bh() / rcu_read_unlock_bh()
308
309c. synchronize_sched() preempt_disable() / preempt_enable()
310 local_irq_save() / local_irq_restore()
311 hardirq enter / hardirq exit
312 NMI enter / NMI exit
313
314These three mechanisms are used as follows:
315
316a. RCU applied to normal data structures.
317
318b. RCU applied to networking data structures that may be subjected
319 to remote denial-of-service attacks.
320
321c. RCU applied to scheduler and interrupt/NMI-handler tasks.
322
323Again, most uses will be of (a). The (b) and (c) cases are important
324for specialized uses, but are relatively uncommon.
325
326
3273. WHAT ARE SOME EXAMPLE USES OF CORE RCU API?
328
329This section shows a simple use of the core RCU API to protect a
330global pointer to a dynamically allocated structure. More typical
331uses of RCU may be found in listRCU.txt, arrayRCU.txt, and NMI-RCU.txt.
332
333 struct foo {
334 int a;
335 char b;
336 long c;
337 };
338 DEFINE_SPINLOCK(foo_mutex);
339
340 struct foo *gbl_foo;
341
342 /*
343 * Create a new struct foo that is the same as the one currently
344 * pointed to by gbl_foo, except that field "a" is replaced
345 * with "new_a". Points gbl_foo to the new structure, and
346 * frees up the old structure after a grace period.
347 *
348 * Uses rcu_assign_pointer() to ensure that concurrent readers
349 * see the initialized version of the new structure.
350 *
351 * Uses synchronize_rcu() to ensure that any readers that might
352 * have references to the old structure complete before freeing
353 * the old structure.
354 */
355 void foo_update_a(int new_a)
356 {
357 struct foo *new_fp;
358 struct foo *old_fp;
359
360 new_fp = kmalloc(sizeof(*fp), GFP_KERNEL);
361 spin_lock(&foo_mutex);
362 old_fp = gbl_foo;
363 *new_fp = *old_fp;
364 new_fp->a = new_a;
365 rcu_assign_pointer(gbl_foo, new_fp);
366 spin_unlock(&foo_mutex);
367 synchronize_rcu();
368 kfree(old_fp);
369 }
370
371 /*
372 * Return the value of field "a" of the current gbl_foo
373 * structure. Use rcu_read_lock() and rcu_read_unlock()
374 * to ensure that the structure does not get deleted out
375 * from under us, and use rcu_dereference() to ensure that
376 * we see the initialized version of the structure (important
377 * for DEC Alpha and for people reading the code).
378 */
379 int foo_get_a(void)
380 {
381 int retval;
382
383 rcu_read_lock();
384 retval = rcu_dereference(gbl_foo)->a;
385 rcu_read_unlock();
386 return retval;
387 }
388
389So, to sum up:
390
391o Use rcu_read_lock() and rcu_read_unlock() to guard RCU
392 read-side critical sections.
393
394o Within an RCU read-side critical section, use rcu_dereference()
395 to dereference RCU-protected pointers.
396
397o Use some solid scheme (such as locks or semaphores) to
398 keep concurrent updates from interfering with each other.
399
400o Use rcu_assign_pointer() to update an RCU-protected pointer.
401 This primitive protects concurrent readers from the updater,
402 -not- concurrent updates from each other! You therefore still
403 need to use locking (or something similar) to keep concurrent
404 rcu_assign_pointer() primitives from interfering with each other.
405
406o Use synchronize_rcu() -after- removing a data element from an
407 RCU-protected data structure, but -before- reclaiming/freeing
408 the data element, in order to wait for the completion of all
409 RCU read-side critical sections that might be referencing that
410 data item.
411
412See checklist.txt for additional rules to follow when using RCU.
413
414
4154. WHAT IF MY UPDATING THREAD CANNOT BLOCK?
416
417In the example above, foo_update_a() blocks until a grace period elapses.
418This is quite simple, but in some cases one cannot afford to wait so
419long -- there might be other high-priority work to be done.
420
421In such cases, one uses call_rcu() rather than synchronize_rcu().
422The call_rcu() API is as follows:
423
424 void call_rcu(struct rcu_head * head,
425 void (*func)(struct rcu_head *head));
426
427This function invokes func(head) after a grace period has elapsed.
428This invocation might happen from either softirq or process context,
429so the function is not permitted to block. The foo struct needs to
430have an rcu_head structure added, perhaps as follows:
431
432 struct foo {
433 int a;
434 char b;
435 long c;
436 struct rcu_head rcu;
437 };
438
439The foo_update_a() function might then be written as follows:
440
441 /*
442 * Create a new struct foo that is the same as the one currently
443 * pointed to by gbl_foo, except that field "a" is replaced
444 * with "new_a". Points gbl_foo to the new structure, and
445 * frees up the old structure after a grace period.
446 *
447 * Uses rcu_assign_pointer() to ensure that concurrent readers
448 * see the initialized version of the new structure.
449 *
450 * Uses call_rcu() to ensure that any readers that might have
451 * references to the old structure complete before freeing the
452 * old structure.
453 */
454 void foo_update_a(int new_a)
455 {
456 struct foo *new_fp;
457 struct foo *old_fp;
458
459 new_fp = kmalloc(sizeof(*fp), GFP_KERNEL);
460 spin_lock(&foo_mutex);
461 old_fp = gbl_foo;
462 *new_fp = *old_fp;
463 new_fp->a = new_a;
464 rcu_assign_pointer(gbl_foo, new_fp);
465 spin_unlock(&foo_mutex);
466 call_rcu(&old_fp->rcu, foo_reclaim);
467 }
468
469The foo_reclaim() function might appear as follows:
470
471 void foo_reclaim(struct rcu_head *rp)
472 {
473 struct foo *fp = container_of(rp, struct foo, rcu);
474
475 kfree(fp);
476 }
477
478The container_of() primitive is a macro that, given a pointer into a
479struct, the type of the struct, and the pointed-to field within the
480struct, returns a pointer to the beginning of the struct.
481
482The use of call_rcu() permits the caller of foo_update_a() to
483immediately regain control, without needing to worry further about the
484old version of the newly updated element. It also clearly shows the
485RCU distinction between updater, namely foo_update_a(), and reclaimer,
486namely foo_reclaim().
487
488The summary of advice is the same as for the previous section, except
489that we are now using call_rcu() rather than synchronize_rcu():
490
491o Use call_rcu() -after- removing a data element from an
492 RCU-protected data structure in order to register a callback
493 function that will be invoked after the completion of all RCU
494 read-side critical sections that might be referencing that
495 data item.
496
497Again, see checklist.txt for additional rules governing the use of RCU.
498
499
5005. WHAT ARE SOME SIMPLE IMPLEMENTATIONS OF RCU?
501
502One of the nice things about RCU is that it has extremely simple "toy"
503implementations that are a good first step towards understanding the
504production-quality implementations in the Linux kernel. This section
505presents two such "toy" implementations of RCU, one that is implemented
506in terms of familiar locking primitives, and another that more closely
507resembles "classic" RCU. Both are way too simple for real-world use,
508lacking both functionality and performance. However, they are useful
509in getting a feel for how RCU works. See kernel/rcupdate.c for a
510production-quality implementation, and see:
511
512 http://www.rdrop.com/users/paulmck/RCU
513
514for papers describing the Linux kernel RCU implementation. The OLS'01
515and OLS'02 papers are a good introduction, and the dissertation provides
516more details on the current implementation.
517
518
5195A. "TOY" IMPLEMENTATION #1: LOCKING
520
521This section presents a "toy" RCU implementation that is based on
522familiar locking primitives. Its overhead makes it a non-starter for
523real-life use, as does its lack of scalability. It is also unsuitable
524for realtime use, since it allows scheduling latency to "bleed" from
525one read-side critical section to another.
526
527However, it is probably the easiest implementation to relate to, so is
528a good starting point.
529
530It is extremely simple:
531
532 static DEFINE_RWLOCK(rcu_gp_mutex);
533
534 void rcu_read_lock(void)
535 {
536 read_lock(&rcu_gp_mutex);
537 }
538
539 void rcu_read_unlock(void)
540 {
541 read_unlock(&rcu_gp_mutex);
542 }
543
544 void synchronize_rcu(void)
545 {
546 write_lock(&rcu_gp_mutex);
547 write_unlock(&rcu_gp_mutex);
548 }
549
550[You can ignore rcu_assign_pointer() and rcu_dereference() without
551missing much. But here they are anyway. And whatever you do, don't
552forget about them when submitting patches making use of RCU!]
553
554 #define rcu_assign_pointer(p, v) ({ \
555 smp_wmb(); \
556 (p) = (v); \
557 })
558
559 #define rcu_dereference(p) ({ \
560 typeof(p) _________p1 = p; \
561 smp_read_barrier_depends(); \
562 (_________p1); \
563 })
564
565
566The rcu_read_lock() and rcu_read_unlock() primitive read-acquire
567and release a global reader-writer lock. The synchronize_rcu()
568primitive write-acquires this same lock, then immediately releases
569it. This means that once synchronize_rcu() exits, all RCU read-side
570critical sections that were in progress before synchonize_rcu() was
571called are guaranteed to have completed -- there is no way that
572synchronize_rcu() would have been able to write-acquire the lock
573otherwise.
574
575It is possible to nest rcu_read_lock(), since reader-writer locks may
576be recursively acquired. Note also that rcu_read_lock() is immune
577from deadlock (an important property of RCU). The reason for this is
578that the only thing that can block rcu_read_lock() is a synchronize_rcu().
579But synchronize_rcu() does not acquire any locks while holding rcu_gp_mutex,
580so there can be no deadlock cycle.
581
582Quick Quiz #1: Why is this argument naive? How could a deadlock
583 occur when using this algorithm in a real-world Linux
584 kernel? How could this deadlock be avoided?
585
586
5875B. "TOY" EXAMPLE #2: CLASSIC RCU
588
589This section presents a "toy" RCU implementation that is based on
590"classic RCU". It is also short on performance (but only for updates) and
591on features such as hotplug CPU and the ability to run in CONFIG_PREEMPT
592kernels. The definitions of rcu_dereference() and rcu_assign_pointer()
593are the same as those shown in the preceding section, so they are omitted.
594
595 void rcu_read_lock(void) { }
596
597 void rcu_read_unlock(void) { }
598
599 void synchronize_rcu(void)
600 {
601 int cpu;
602
603 for_each_cpu(cpu)
604 run_on(cpu);
605 }
606
607Note that rcu_read_lock() and rcu_read_unlock() do absolutely nothing.
608This is the great strength of classic RCU in a non-preemptive kernel:
609read-side overhead is precisely zero, at least on non-Alpha CPUs.
610And there is absolutely no way that rcu_read_lock() can possibly
611participate in a deadlock cycle!
612
613The implementation of synchronize_rcu() simply schedules itself on each
614CPU in turn. The run_on() primitive can be implemented straightforwardly
615in terms of the sched_setaffinity() primitive. Of course, a somewhat less
616"toy" implementation would restore the affinity upon completion rather
617than just leaving all tasks running on the last CPU, but when I said
618"toy", I meant -toy-!
619
620So how the heck is this supposed to work???
621
622Remember that it is illegal to block while in an RCU read-side critical
623section. Therefore, if a given CPU executes a context switch, we know
624that it must have completed all preceding RCU read-side critical sections.
625Once -all- CPUs have executed a context switch, then -all- preceding
626RCU read-side critical sections will have completed.
627
628So, suppose that we remove a data item from its structure and then invoke
629synchronize_rcu(). Once synchronize_rcu() returns, we are guaranteed
630that there are no RCU read-side critical sections holding a reference
631to that data item, so we can safely reclaim it.
632
633Quick Quiz #2: Give an example where Classic RCU's read-side
634 overhead is -negative-.
635
636Quick Quiz #3: If it is illegal to block in an RCU read-side
637 critical section, what the heck do you do in
638 PREEMPT_RT, where normal spinlocks can block???
639
640
6416. ANALOGY WITH READER-WRITER LOCKING
642
643Although RCU can be used in many different ways, a very common use of
644RCU is analogous to reader-writer locking. The following unified
645diff shows how closely related RCU and reader-writer locking can be.
646
647 @@ -13,15 +14,15 @@
648 struct list_head *lp;
649 struct el *p;
650
651 - read_lock();
652 - list_for_each_entry(p, head, lp) {
653 + rcu_read_lock();
654 + list_for_each_entry_rcu(p, head, lp) {
655 if (p->key == key) {
656 *result = p->data;
657 - read_unlock();
658 + rcu_read_unlock();
659 return 1;
660 }
661 }
662 - read_unlock();
663 + rcu_read_unlock();
664 return 0;
665 }
666
667 @@ -29,15 +30,16 @@
668 {
669 struct el *p;
670
671 - write_lock(&listmutex);
672 + spin_lock(&listmutex);
673 list_for_each_entry(p, head, lp) {
674 if (p->key == key) {
675 list_del(&p->list);
676 - write_unlock(&listmutex);
677 + spin_unlock(&listmutex);
678 + synchronize_rcu();
679 kfree(p);
680 return 1;
681 }
682 }
683 - write_unlock(&listmutex);
684 + spin_unlock(&listmutex);
685 return 0;
686 }
687
688Or, for those who prefer a side-by-side listing:
689
690 1 struct el { 1 struct el {
691 2 struct list_head list; 2 struct list_head list;
692 3 long key; 3 long key;
693 4 spinlock_t mutex; 4 spinlock_t mutex;
694 5 int data; 5 int data;
695 6 /* Other data fields */ 6 /* Other data fields */
696 7 }; 7 };
697 8 spinlock_t listmutex; 8 spinlock_t listmutex;
698 9 struct el head; 9 struct el head;
699
700 1 int search(long key, int *result) 1 int search(long key, int *result)
701 2 { 2 {
702 3 struct list_head *lp; 3 struct list_head *lp;
703 4 struct el *p; 4 struct el *p;
704 5 5
705 6 read_lock(); 6 rcu_read_lock();
706 7 list_for_each_entry(p, head, lp) { 7 list_for_each_entry_rcu(p, head, lp) {
707 8 if (p->key == key) { 8 if (p->key == key) {
708 9 *result = p->data; 9 *result = p->data;
70910 read_unlock(); 10 rcu_read_unlock();
71011 return 1; 11 return 1;
71112 } 12 }
71213 } 13 }
71314 read_unlock(); 14 rcu_read_unlock();
71415 return 0; 15 return 0;
71516 } 16 }
716
717 1 int delete(long key) 1 int delete(long key)
718 2 { 2 {
719 3 struct el *p; 3 struct el *p;
720 4 4
721 5 write_lock(&listmutex); 5 spin_lock(&listmutex);
722 6 list_for_each_entry(p, head, lp) { 6 list_for_each_entry(p, head, lp) {
723 7 if (p->key == key) { 7 if (p->key == key) {
724 8 list_del(&p->list); 8 list_del(&p->list);
725 9 write_unlock(&listmutex); 9 spin_unlock(&listmutex);
726 10 synchronize_rcu();
72710 kfree(p); 11 kfree(p);
72811 return 1; 12 return 1;
72912 } 13 }
73013 } 14 }
73114 write_unlock(&listmutex); 15 spin_unlock(&listmutex);
73215 return 0; 16 return 0;
73316 } 17 }
734
735Either way, the differences are quite small. Read-side locking moves
736to rcu_read_lock() and rcu_read_unlock, update-side locking moves from
737from a reader-writer lock to a simple spinlock, and a synchronize_rcu()
738precedes the kfree().
739
740However, there is one potential catch: the read-side and update-side
741critical sections can now run concurrently. In many cases, this will
742not be a problem, but it is necessary to check carefully regardless.
743For example, if multiple independent list updates must be seen as
744a single atomic update, converting to RCU will require special care.
745
746Also, the presence of synchronize_rcu() means that the RCU version of
747delete() can now block. If this is a problem, there is a callback-based
748mechanism that never blocks, namely call_rcu(), that can be used in
749place of synchronize_rcu().
750
751
7527. FULL LIST OF RCU APIs
753
754The RCU APIs are documented in docbook-format header comments in the
755Linux-kernel source code, but it helps to have a full list of the
756APIs, since there does not appear to be a way to categorize them
757in docbook. Here is the list, by category.
758
759Markers for RCU read-side critical sections:
760
761 rcu_read_lock
762 rcu_read_unlock
763 rcu_read_lock_bh
764 rcu_read_unlock_bh
765
766RCU pointer/list traversal:
767
768 rcu_dereference
769 list_for_each_rcu (to be deprecated in favor of
770 list_for_each_entry_rcu)
771 list_for_each_safe_rcu (deprecated, not used)
772 list_for_each_entry_rcu
773 list_for_each_continue_rcu (to be deprecated in favor of new
774 list_for_each_entry_continue_rcu)
775 hlist_for_each_rcu (to be deprecated in favor of
776 hlist_for_each_entry_rcu)
777 hlist_for_each_entry_rcu
778
779RCU pointer update:
780
781 rcu_assign_pointer
782 list_add_rcu
783 list_add_tail_rcu
784 list_del_rcu
785 list_replace_rcu
786 hlist_del_rcu
787 hlist_add_head_rcu
788
789RCU grace period:
790
791 synchronize_kernel (deprecated)
792 synchronize_net
793 synchronize_sched
794 synchronize_rcu
795 call_rcu
796 call_rcu_bh
797
798See the comment headers in the source code (or the docbook generated
799from them) for more information.
800
801
8028. ANSWERS TO QUICK QUIZZES
803
804Quick Quiz #1: Why is this argument naive? How could a deadlock
805 occur when using this algorithm in a real-world Linux
806 kernel? [Referring to the lock-based "toy" RCU
807 algorithm.]
808
809Answer: Consider the following sequence of events:
810
811 1. CPU 0 acquires some unrelated lock, call it
812 "problematic_lock".
813
814 2. CPU 1 enters synchronize_rcu(), write-acquiring
815 rcu_gp_mutex.
816
817 3. CPU 0 enters rcu_read_lock(), but must wait
818 because CPU 1 holds rcu_gp_mutex.
819
820 4. CPU 1 is interrupted, and the irq handler
821 attempts to acquire problematic_lock.
822
823 The system is now deadlocked.
824
825 One way to avoid this deadlock is to use an approach like
826 that of CONFIG_PREEMPT_RT, where all normal spinlocks
827 become blocking locks, and all irq handlers execute in
828 the context of special tasks. In this case, in step 4
829 above, the irq handler would block, allowing CPU 1 to
830 release rcu_gp_mutex, avoiding the deadlock.
831
832 Even in the absence of deadlock, this RCU implementation
833 allows latency to "bleed" from readers to other
834 readers through synchronize_rcu(). To see this,
835 consider task A in an RCU read-side critical section
836 (thus read-holding rcu_gp_mutex), task B blocked
837 attempting to write-acquire rcu_gp_mutex, and
838 task C blocked in rcu_read_lock() attempting to
839 read_acquire rcu_gp_mutex. Task A's RCU read-side
840 latency is holding up task C, albeit indirectly via
841 task B.
842
843 Realtime RCU implementations therefore use a counter-based
844 approach where tasks in RCU read-side critical sections
845 cannot be blocked by tasks executing synchronize_rcu().
846
847Quick Quiz #2: Give an example where Classic RCU's read-side
848 overhead is -negative-.
849
850Answer: Imagine a single-CPU system with a non-CONFIG_PREEMPT
851 kernel where a routing table is used by process-context
852 code, but can be updated by irq-context code (for example,
853 by an "ICMP REDIRECT" packet). The usual way of handling
854 this would be to have the process-context code disable
855 interrupts while searching the routing table. Use of
856 RCU allows such interrupt-disabling to be dispensed with.
857 Thus, without RCU, you pay the cost of disabling interrupts,
858 and with RCU you don't.
859
860 One can argue that the overhead of RCU in this
861 case is negative with respect to the single-CPU
862 interrupt-disabling approach. Others might argue that
863 the overhead of RCU is merely zero, and that replacing
864 the positive overhead of the interrupt-disabling scheme
865 with the zero-overhead RCU scheme does not constitute
866 negative overhead.
867
868 In real life, of course, things are more complex. But
869 even the theoretical possibility of negative overhead for
870 a synchronization primitive is a bit unexpected. ;-)
871
872Quick Quiz #3: If it is illegal to block in an RCU read-side
873 critical section, what the heck do you do in
874 PREEMPT_RT, where normal spinlocks can block???
875
876Answer: Just as PREEMPT_RT permits preemption of spinlock
877 critical sections, it permits preemption of RCU
878 read-side critical sections. It also permits
879 spinlocks blocking while in RCU read-side critical
880 sections.
881
882 Why the apparent inconsistency? Because it is it
883 possible to use priority boosting to keep the RCU
884 grace periods short if need be (for example, if running
885 short of memory). In contrast, if blocking waiting
886 for (say) network reception, there is no way to know
887 what should be boosted. Especially given that the
888 process we need to boost might well be a human being
889 who just went out for a pizza or something. And although
890 a computer-operated cattle prod might arouse serious
891 interest, it might also provoke serious objections.
892 Besides, how does the computer know what pizza parlor
893 the human being went to???
894
895
896ACKNOWLEDGEMENTS
897
898My thanks to the people who helped make this human-readable, including
899Jon Walpole, Josh Triplett, Serge Hallyn, and Suzanne Wood.
900
901
902For more information, see http://www.rdrop.com/users/paulmck/RCU.
diff --git a/Documentation/applying-patches.txt b/Documentation/applying-patches.txt
new file mode 100644
index 0000000000..681e426e24
--- /dev/null
+++ b/Documentation/applying-patches.txt
@@ -0,0 +1,439 @@
1
2 Applying Patches To The Linux Kernel
3 ------------------------------------
4
5 (Written by Jesper Juhl, August 2005)
6
7
8
9A frequently asked question on the Linux Kernel Mailing List is how to apply
10a patch to the kernel or, more specifically, what base kernel a patch for
11one of the many trees/branches should be applied to. Hopefully this document
12will explain this to you.
13
14In addition to explaining how to apply and revert patches, a brief
15description of the different kernel trees (and examples of how to apply
16their specific patches) is also provided.
17
18
19What is a patch?
20---
21 A patch is a small text document containing a delta of changes between two
22different versions of a source tree. Patches are created with the `diff'
23program.
24To correctly apply a patch you need to know what base it was generated from
25and what new version the patch will change the source tree into. These
26should both be present in the patch file metadata or be possible to deduce
27from the filename.
28
29
30How do I apply or revert a patch?
31---
32 You apply a patch with the `patch' program. The patch program reads a diff
33(or patch) file and makes the changes to the source tree described in it.
34
35Patches for the Linux kernel are generated relative to the parent directory
36holding the kernel source dir.
37
38This means that paths to files inside the patch file contain the name of the
39kernel source directories it was generated against (or some other directory
40names like "a/" and "b/").
41Since this is unlikely to match the name of the kernel source dir on your
42local machine (but is often useful info to see what version an otherwise
43unlabeled patch was generated against) you should change into your kernel
44source directory and then strip the first element of the path from filenames
45in the patch file when applying it (the -p1 argument to `patch' does this).
46
47To revert a previously applied patch, use the -R argument to patch.
48So, if you applied a patch like this:
49 patch -p1 < ../patch-x.y.z
50
51You can revert (undo) it like this:
52 patch -R -p1 < ../patch-x.y.z
53
54
55How do I feed a patch/diff file to `patch'?
56---
57 This (as usual with Linux and other UNIX like operating systems) can be
58done in several different ways.
59In all the examples below I feed the file (in uncompressed form) to patch
60via stdin using the following syntax:
61 patch -p1 < path/to/patch-x.y.z
62
63If you just want to be able to follow the examples below and don't want to
64know of more than one way to use patch, then you can stop reading this
65section here.
66
67Patch can also get the name of the file to use via the -i argument, like
68this:
69 patch -p1 -i path/to/patch-x.y.z
70
71If your patch file is compressed with gzip or bzip2 and you don't want to
72uncompress it before applying it, then you can feed it to patch like this
73instead:
74 zcat path/to/patch-x.y.z.gz | patch -p1
75 bzcat path/to/patch-x.y.z.bz2 | patch -p1
76
77If you wish to uncompress the patch file by hand first before applying it
78(what I assume you've done in the examples below), then you simply run
79gunzip or bunzip2 on the file - like this:
80 gunzip patch-x.y.z.gz
81 bunzip2 patch-x.y.z.bz2
82
83Which will leave you with a plain text patch-x.y.z file that you can feed to
84patch via stdin or the -i argument, as you prefer.
85
86A few other nice arguments for patch are -s which causes patch to be silent
87except for errors which is nice to prevent errors from scrolling out of the
88screen too fast, and --dry-run which causes patch to just print a listing of
89what would happen, but doesn't actually make any changes. Finally --verbose
90tells patch to print more information about the work being done.
91
92
93Common errors when patching
94---
95 When patch applies a patch file it attempts to verify the sanity of the
96file in different ways.
97Checking that the file looks like a valid patch file, checking the code
98around the bits being modified matches the context provided in the patch are
99just two of the basic sanity checks patch does.
100
101If patch encounters something that doesn't look quite right it has two
102options. It can either refuse to apply the changes and abort or it can try
103to find a way to make the patch apply with a few minor changes.
104
105One example of something that's not 'quite right' that patch will attempt to
106fix up is if all the context matches, the lines being changed match, but the
107line numbers are different. This can happen, for example, if the patch makes
108a change in the middle of the file but for some reasons a few lines have
109been added or removed near the beginning of the file. In that case
110everything looks good it has just moved up or down a bit, and patch will
111usually adjust the line numbers and apply the patch.
112
113Whenever patch applies a patch that it had to modify a bit to make it fit
114it'll tell you about it by saying the patch applied with 'fuzz'.
115You should be wary of such changes since even though patch probably got it
116right it doesn't /always/ get it right, and the result will sometimes be
117wrong.
118
119When patch encounters a change that it can't fix up with fuzz it rejects it
120outright and leaves a file with a .rej extension (a reject file). You can
121read this file to see exactely what change couldn't be applied, so you can
122go fix it up by hand if you wish.
123
124If you don't have any third party patches applied to your kernel source, but
125only patches from kernel.org and you apply the patches in the correct order,
126and have made no modifications yourself to the source files, then you should
127never see a fuzz or reject message from patch. If you do see such messages
128anyway, then there's a high risk that either your local source tree or the
129patch file is corrupted in some way. In that case you should probably try
130redownloading the patch and if things are still not OK then you'd be advised
131to start with a fresh tree downloaded in full from kernel.org.
132
133Let's look a bit more at some of the messages patch can produce.
134
135If patch stops and presents a "File to patch:" prompt, then patch could not
136find a file to be patched. Most likely you forgot to specify -p1 or you are
137in the wrong directory. Less often, you'll find patches that need to be
138applied with -p0 instead of -p1 (reading the patch file should reveal if
139this is the case - if so, then this is an error by the person who created
140the patch but is not fatal).
141
142If you get "Hunk #2 succeeded at 1887 with fuzz 2 (offset 7 lines)." or a
143message similar to that, then it means that patch had to adjust the location
144of the change (in this example it needed to move 7 lines from where it
145expected to make the change to make it fit).
146The resulting file may or may not be OK, depending on the reason the file
147was different than expected.
148This often happens if you try to apply a patch that was generated against a
149different kernel version than the one you are trying to patch.
150
151If you get a message like "Hunk #3 FAILED at 2387.", then it means that the
152patch could not be applied correctly and the patch program was unable to
153fuzz its way through. This will generate a .rej file with the change that
154caused the patch to fail and also a .orig file showing you the original
155content that couldn't be changed.
156
157If you get "Reversed (or previously applied) patch detected! Assume -R? [n]"
158then patch detected that the change contained in the patch seems to have
159already been made.
160If you actually did apply this patch previously and you just re-applied it
161in error, then just say [n]o and abort this patch. If you applied this patch
162previously and actually intended to revert it, but forgot to specify -R,
163then you can say [y]es here to make patch revert it for you.
164This can also happen if the creator of the patch reversed the source and
165destination directories when creating the patch, and in that case reverting
166the patch will in fact apply it.
167
168A message similar to "patch: **** unexpected end of file in patch" or "patch
169unexpectedly ends in middle of line" means that patch could make no sense of
170the file you fed to it. Either your download is broken or you tried to feed
171patch a compressed patch file without uncompressing it first.
172
173As I already mentioned above, these errors should never happen if you apply
174a patch from kernel.org to the correct version of an unmodified source tree.
175So if you get these errors with kernel.org patches then you should probably
176assume that either your patch file or your tree is broken and I'd advice you
177to start over with a fresh download of a full kernel tree and the patch you
178wish to apply.
179
180
181Are there any alternatives to `patch'?
182---
183 Yes there are alternatives. You can use the `interdiff' program
184(http://cyberelk.net/tim/patchutils/) to generate a patch representing the
185differences between two patches and then apply the result.
186This will let you move from something like 2.6.12.2 to 2.6.12.3 in a single
187step. The -z flag to interdiff will even let you feed it patches in gzip or
188bzip2 compressed form directly without the use of zcat or bzcat or manual
189decompression.
190
191Here's how you'd go from 2.6.12.2 to 2.6.12.3 in a single step:
192 interdiff -z ../patch-2.6.12.2.bz2 ../patch-2.6.12.3.gz | patch -p1
193
194Although interdiff may save you a step or two you are generally advised to
195do the additional steps since interdiff can get things wrong in some cases.
196
197 Another alternative is `ketchup', which is a python script for automatic
198downloading and applying of patches (http://www.selenic.com/ketchup/).
199
200Other nice tools are diffstat which shows a summary of changes made by a
201patch, lsdiff which displays a short listing of affected files in a patch
202file, along with (optionally) the line numbers of the start of each patch
203and grepdiff which displays a list of the files modified by a patch where
204the patch contains a given regular expression.
205
206
207Where can I download the patches?
208---
209 The patches are available at http://kernel.org/
210Most recent patches are linked from the front page, but they also have
211specific homes.
212
213The 2.6.x.y (-stable) and 2.6.x patches live at
214 ftp://ftp.kernel.org/pub/linux/kernel/v2.6/
215
216The -rc patches live at
217 ftp://ftp.kernel.org/pub/linux/kernel/v2.6/testing/
218
219The -git patches live at
220 ftp://ftp.kernel.org/pub/linux/kernel/v2.6/snapshots/
221
222The -mm kernels live at
223 ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/
224
225In place of ftp.kernel.org you can use ftp.cc.kernel.org, where cc is a
226country code. This way you'll be downloading from a mirror site that's most
227likely geographically closer to you, resulting in faster downloads for you,
228less bandwidth used globally and less load on the main kernel.org servers -
229these are good things, do use mirrors when possible.
230
231
232The 2.6.x kernels
233---
234 These are the base stable releases released by Linus. The highest numbered
235release is the most recent.
236
237If regressions or other serious flaws are found then a -stable fix patch
238will be released (see below) on top of this base. Once a new 2.6.x base
239kernel is released, a patch is made available that is a delta between the
240previous 2.6.x kernel and the new one.
241
242To apply a patch moving from 2.6.11 to 2.6.12 you'd do the following (note
243that such patches do *NOT* apply on top of 2.6.x.y kernels but on top of the
244base 2.6.x kernel - if you need to move from 2.6.x.y to 2.6.x+1 you need to
245first revert the 2.6.x.y patch).
246
247Here are some examples:
248
249# moving from 2.6.11 to 2.6.12
250$ cd ~/linux-2.6.11 # change to kernel source dir
251$ patch -p1 < ../patch-2.6.12 # apply the 2.6.12 patch
252$ cd ..
253$ mv linux-2.6.11 linux-2.6.12 # rename source dir
254
255# moving from 2.6.11.1 to 2.6.12
256$ cd ~/linux-2.6.11.1 # change to kernel source dir
257$ patch -p1 -R < ../patch-2.6.11.1 # revert the 2.6.11.1 patch
258 # source dir is now 2.6.11
259$ patch -p1 < ../patch-2.6.12 # apply new 2.6.12 patch
260$ cd ..
261$ mv linux-2.6.11.1 inux-2.6.12 # rename source dir
262
263
264The 2.6.x.y kernels
265---
266 Kernels with 4 digit versions are -stable kernels. They contain small(ish)
267critical fixes for security problems or significant regressions discovered
268in a given 2.6.x kernel.
269
270This is the recommended branch for users who want the most recent stable
271kernel and are not interested in helping test development/experimental
272versions.
273
274If no 2.6.x.y kernel is available, then the highest numbered 2.6.x kernel is
275the current stable kernel.
276
277These patches are not incremental, meaning that for example the 2.6.12.3
278patch does not apply on top of the 2.6.12.2 kernel source, but rather on top
279of the base 2.6.12 kernel source.
280So, in order to apply the 2.6.12.3 patch to your existing 2.6.12.2 kernel
281source you have to first back out the 2.6.12.2 patch (so you are left with a
282base 2.6.12 kernel source) and then apply the new 2.6.12.3 patch.
283
284Here's a small example:
285
286$ cd ~/linux-2.6.12.2 # change into the kernel source dir
287$ patch -p1 -R < ../patch-2.6.12.2 # revert the 2.6.12.2 patch
288$ patch -p1 < ../patch-2.6.12.3 # apply the new 2.6.12.3 patch
289$ cd ..
290$ mv linux-2.6.12.2 linux-2.6.12.3 # rename the kernel source dir
291
292
293The -rc kernels
294---
295 These are release-candidate kernels. These are development kernels released
296by Linus whenever he deems the current git (the kernel's source management
297tool) tree to be in a reasonably sane state adequate for testing.
298
299These kernels are not stable and you should expect occasional breakage if
300you intend to run them. This is however the most stable of the main
301development branches and is also what will eventually turn into the next
302stable kernel, so it is important that it be tested by as many people as
303possible.
304
305This is a good branch to run for people who want to help out testing
306development kernels but do not want to run some of the really experimental
307stuff (such people should see the sections about -git and -mm kernels below).
308
309The -rc patches are not incremental, they apply to a base 2.6.x kernel, just
310like the 2.6.x.y patches described above. The kernel version before the -rcN
311suffix denotes the version of the kernel that this -rc kernel will eventually
312turn into.
313So, 2.6.13-rc5 means that this is the fifth release candidate for the 2.6.13
314kernel and the patch should be applied on top of the 2.6.12 kernel source.
315
316Here are 3 examples of how to apply these patches:
317
318# first an example of moving from 2.6.12 to 2.6.13-rc3
319$ cd ~/linux-2.6.12 # change into the 2.6.12 source dir
320$ patch -p1 < ../patch-2.6.13-rc3 # apply the 2.6.13-rc3 patch
321$ cd ..
322$ mv linux-2.6.12 linux-2.6.13-rc3 # rename the source dir
323
324# now let's move from 2.6.13-rc3 to 2.6.13-rc5
325$ cd ~/linux-2.6.13-rc3 # change into the 2.6.13-rc3 dir
326$ patch -p1 -R < ../patch-2.6.13-rc3 # revert the 2.6.13-rc3 patch
327$ patch -p1 < ../patch-2.6.13-rc5 # apply the new 2.6.13-rc5 patch
328$ cd ..
329$ mv linux-2.6.13-rc3 linux-2.6.13-rc5 # rename the source dir
330
331# finally let's try and move from 2.6.12.3 to 2.6.13-rc5
332$ cd ~/linux-2.6.12.3 # change to the kernel source dir
333$ patch -p1 -R < ../patch-2.6.12.3 # revert the 2.6.12.3 patch
334$ patch -p1 < ../patch-2.6.13-rc5 # apply new 2.6.13-rc5 patch
335$ cd ..
336$ mv linux-2.6.12.3 linux-2.6.13-rc5 # rename the kernel source dir
337
338
339The -git kernels
340---
341 These are daily snapshots of Linus' kernel tree (managed in a git
342repository, hence the name).
343
344These patches are usually released daily and represent the current state of
345Linus' tree. They are more experimental than -rc kernels since they are
346generated automatically without even a cursory glance to see if they are
347sane.
348
349-git patches are not incremental and apply either to a base 2.6.x kernel or
350a base 2.6.x-rc kernel - you can see which from their name.
351A patch named 2.6.12-git1 applies to the 2.6.12 kernel source and a patch
352named 2.6.13-rc3-git2 applies to the source of the 2.6.13-rc3 kernel.
353
354Here are some examples of how to apply these patches:
355
356# moving from 2.6.12 to 2.6.12-git1
357$ cd ~/linux-2.6.12 # change to the kernel source dir
358$ patch -p1 < ../patch-2.6.12-git1 # apply the 2.6.12-git1 patch
359$ cd ..
360$ mv linux-2.6.12 linux-2.6.12-git1 # rename the kernel source dir
361
362# moving from 2.6.12-git1 to 2.6.13-rc2-git3
363$ cd ~/linux-2.6.12-git1 # change to the kernel source dir
364$ patch -p1 -R < ../patch-2.6.12-git1 # revert the 2.6.12-git1 patch
365 # we now have a 2.6.12 kernel
366$ patch -p1 < ../patch-2.6.13-rc2 # apply the 2.6.13-rc2 patch
367 # the kernel is now 2.6.13-rc2
368$ patch -p1 < ../patch-2.6.13-rc2-git3 # apply the 2.6.13-rc2-git3 patch
369 # the kernel is now 2.6.13-rc2-git3
370$ cd ..
371$ mv linux-2.6.12-git1 linux-2.6.13-rc2-git3 # rename source dir
372
373
374The -mm kernels
375---
376 These are experimental kernels released by Andrew Morton.
377
378The -mm tree serves as a sort of proving ground for new features and other
379experimental patches.
380Once a patch has proved its worth in -mm for a while Andrew pushes it on to
381Linus for inclusion in mainline.
382
383Although it's encouraged that patches flow to Linus via the -mm tree, this
384is not always enforced.
385Subsystem maintainers (or individuals) sometimes push their patches directly
386to Linus, even though (or after) they have been merged and tested in -mm (or
387sometimes even without prior testing in -mm).
388
389You should generally strive to get your patches into mainline via -mm to
390ensure maximum testing.
391
392This branch is in constant flux and contains many experimental features, a
393lot of debugging patches not appropriate for mainline etc and is the most
394experimental of the branches described in this document.
395
396These kernels are not appropriate for use on systems that are supposed to be
397stable and they are more risky to run than any of the other branches (make
398sure you have up-to-date backups - that goes for any experimental kernel but
399even more so for -mm kernels).
400
401These kernels in addition to all the other experimental patches they contain
402usually also contain any changes in the mainline -git kernels available at
403the time of release.
404
405Testing of -mm kernels is greatly appreciated since the whole point of the
406tree is to weed out regressions, crashes, data corruption bugs, build
407breakage (and any other bug in general) before changes are merged into the
408more stable mainline Linus tree.
409But testers of -mm should be aware that breakage in this tree is more common
410than in any other tree.
411
412The -mm kernels are not released on a fixed schedule, but usually a few -mm
413kernels are released in between each -rc kernel (1 to 3 is common).
414The -mm kernels apply to either a base 2.6.x kernel (when no -rc kernels
415have been released yet) or to a Linus -rc kernel.
416
417Here are some examples of applying the -mm patches:
418
419# moving from 2.6.12 to 2.6.12-mm1
420$ cd ~/linux-2.6.12 # change to the 2.6.12 source dir
421$ patch -p1 < ../2.6.12-mm1 # apply the 2.6.12-mm1 patch
422$ cd ..
423$ mv linux-2.6.12 linux-2.6.12-mm1 # rename the source appropriately
424
425# moving from 2.6.12-mm1 to 2.6.13-rc3-mm3
426$ cd ~/linux-2.6.12-mm1
427$ patch -p1 -R < ../2.6.12-mm1 # revert the 2.6.12-mm1 patch
428 # we now have a 2.6.12 source
429$ patch -p1 < ../patch-2.6.13-rc3 # apply the 2.6.13-rc3 patch
430 # we now have a 2.6.13-rc3 source
431$ patch -p1 < ../2.6.13-rc3-mm3 # apply the 2.6.13-rc3-mm3 patch
432$ cd ..
433$ mv linux-2.6.12-mm1 linux-2.6.13-rc3-mm3 # rename the source dir
434
435
436This concludes this list of explanations of the various kernel trees and I
437hope you are now crystal clear on how to apply the various patches and help
438testing the kernel.
439
diff --git a/Documentation/cpu-freq/cpufreq-stats.txt b/Documentation/cpu-freq/cpufreq-stats.txt
index e2d1e760b4..6a82948ff4 100644
--- a/Documentation/cpu-freq/cpufreq-stats.txt
+++ b/Documentation/cpu-freq/cpufreq-stats.txt
@@ -36,7 +36,7 @@ cpufreq stats provides following statistics (explained in detail below).
36 36
37All the statistics will be from the time the stats driver has been inserted 37All the statistics will be from the time the stats driver has been inserted
38to the time when a read of a particular statistic is done. Obviously, stats 38to the time when a read of a particular statistic is done. Obviously, stats
39driver will not have any information about the the frequcny transitions before 39driver will not have any information about the frequency transitions before
40the stats driver insertion. 40the stats driver insertion.
41 41
42-------------------------------------------------------------------------------- 42--------------------------------------------------------------------------------
diff --git a/Documentation/cpusets.txt b/Documentation/cpusets.txt
index 47f4114fbf..d17b7d2dd7 100644
--- a/Documentation/cpusets.txt
+++ b/Documentation/cpusets.txt
@@ -277,7 +277,7 @@ rewritten to the 'tasks' file of its cpuset. This is done to avoid
277impacting the scheduler code in the kernel with a check for changes 277impacting the scheduler code in the kernel with a check for changes
278in a tasks processor placement. 278in a tasks processor placement.
279 279
280There is an exception to the above. If hotplug funtionality is used 280There is an exception to the above. If hotplug functionality is used
281to remove all the CPUs that are currently assigned to a cpuset, 281to remove all the CPUs that are currently assigned to a cpuset,
282then the kernel will automatically update the cpus_allowed of all 282then the kernel will automatically update the cpus_allowed of all
283tasks attached to CPUs in that cpuset to allow all CPUs. When memory 283tasks attached to CPUs in that cpuset to allow all CPUs. When memory
diff --git a/Documentation/crypto/descore-readme.txt b/Documentation/crypto/descore-readme.txt
index 166474c2ee..16e9e63507 100644
--- a/Documentation/crypto/descore-readme.txt
+++ b/Documentation/crypto/descore-readme.txt
@@ -1,4 +1,4 @@
1Below is the orginal README file from the descore.shar package. 1Below is the original README file from the descore.shar package.
2------------------------------------------------------------------------------ 2------------------------------------------------------------------------------
3 3
4des - fast & portable DES encryption & decryption. 4des - fast & portable DES encryption & decryption.
diff --git a/Documentation/dvb/bt8xx.txt b/Documentation/dvb/bt8xx.txt
index 4b8c326c6a..cb63b7a93c 100644
--- a/Documentation/dvb/bt8xx.txt
+++ b/Documentation/dvb/bt8xx.txt
@@ -1,55 +1,74 @@
1How to get the Nebula Electronics DigiTV, Pinnacle PCTV Sat, Twinhan DST + clones working 1How to get the Nebula, PCTV and Twinhan DST cards working
2========================================================================================= 2=========================================================
3 3
41) General information 4This class of cards has a bt878a as the PCI interface, and
5====================== 5require the bttv driver.
6 6
7This class of cards has a bt878a chip as the PCI interface. 7Please pay close attention to the warning about the bttv module
8The different card drivers require the bttv driver to provide the means 8options below for the DST card.
9to access the i2c bus and the gpio pins of the bt8xx chipset.
10 9
112) Compilation rules for Kernel >= 2.6.12 101) General informations
12========================================= 11=======================
13 12
14Enable the following options: 13These drivers require the bttv driver to provide the means to access
14the i2c bus and the gpio pins of the bt8xx chipset.
15 15
16Because of this, you need to enable
16"Device drivers" => "Multimedia devices" 17"Device drivers" => "Multimedia devices"
17 => "Video For Linux" => "BT848 Video For Linux" 18 => "Video For Linux" => "BT848 Video For Linux"
19
20Furthermore you need to enable
18"Device drivers" => "Multimedia devices" => "Digital Video Broadcasting Devices" 21"Device drivers" => "Multimedia devices" => "Digital Video Broadcasting Devices"
19 => "DVB for Linux" "DVB Core Support" "BT8xx based PCI cards" 22 => "DVB for Linux" "DVB Core Support" "BT8xx based PCI cards"
20 23
213) Loading Modules, described by two approaches 242) Loading Modules
22=============================================== 25==================
23 26
24In general you need to load the bttv driver, which will handle the gpio and 27In general you need to load the bttv driver, which will handle the gpio and
25i2c communication for us, plus the common dvb-bt8xx device driver, 28i2c communication for us, plus the common dvb-bt8xx device driver.
26which is called the backend. 29The frontends for Nebula (nxt6000), Pinnacle PCTV (cx24110) and
27The frontends for Nebula DigiTV (nxt6000), Pinnacle PCTV Sat (cx24110), 30TwinHan (dst) are loaded automatically by the dvb-bt8xx device driver.
28TwinHan DST + clones (dst and dst-ca) are loaded automatically by the backend.
29For further details about TwinHan DST + clones see /Documentation/dvb/ci.txt.
30 31
313a) The manual approach 323a) Nebula / Pinnacle PCTV
32----------------------- 33--------------------------
33 34
34Loading modules: 35 $ modprobe bttv (normally bttv is being loaded automatically by kmod)
35modprobe bttv 36 $ modprobe dvb-bt8xx (or just place dvb-bt8xx in /etc/modules for automatic loading)
36modprobe dvb-bt8xx
37 37
38Unloading modules:
39modprobe -r dvb-bt8xx
40modprobe -r bttv
41 38
423b) The automatic approach 393b) TwinHan and Clones
43-------------------------- 40--------------------------
44 41
45If not already done by installation, place a line either in 42 $ modprobe bttv i2c_hw=1 card=0x71
46/etc/modules.conf or in /etc/modprobe.conf containing this text: 43 $ modprobe dvb-bt8xx
47alias char-major-81 bttv 44 $ modprobe dst
45
46The value 0x71 will override the PCI type detection for dvb-bt8xx,
47which is necessary for TwinHan cards.
48
49If you're having an older card (blue color circuit) and card=0x71 locks
50your machine, try using 0x68, too. If that does not work, ask on the
51mailing list.
52
53The DST module takes a couple of useful parameters.
54
55verbose takes values 0 to 4. These values control the verbosity level,
56and can be used to debug also.
57
58verbose=0 means complete disabling of messages
59 1 only error messages are displayed
60 2 notifications are also displayed
61 3 informational messages are also displayed
62 4 debug setting
63
64dst_addons takes values 0 and 0x20. A value of 0 means it is a FTA card.
650x20 means it has a Conditional Access slot.
66
67The autodected values are determined bythe cards 'response
68string' which you can see in your logs e.g.
48 69
49Then place a line in /etc/modules containing this text: 70dst_get_device_id: Recognise [DSTMCI]
50dvb-bt8xx
51 71
52Reboot your system and have fun!
53 72
54-- 73--
55Authors: Richard Walker, Jamie Honan, Michael Hunold, Manu Abraham, Uwe Bugla 74Authors: Richard Walker, Jamie Honan, Michael Hunold, Manu Abraham
diff --git a/Documentation/dvb/ci.txt b/Documentation/dvb/ci.txt
index 62e0701b54..95f0e73b21 100644
--- a/Documentation/dvb/ci.txt
+++ b/Documentation/dvb/ci.txt
@@ -23,7 +23,6 @@ This application requires the following to function properly as of now.
23 eg: $ szap -c channels.conf -r "TMC" -x 23 eg: $ szap -c channels.conf -r "TMC" -x
24 24
25 (b) a channels.conf containing a valid PMT PID 25 (b) a channels.conf containing a valid PMT PID
26
27 eg: TMC:11996:h:0:27500:278:512:650:321 26 eg: TMC:11996:h:0:27500:278:512:650:321
28 27
29 here 278 is a valid PMT PID. the rest of the values are the 28 here 278 is a valid PMT PID. the rest of the values are the
@@ -31,13 +30,7 @@ This application requires the following to function properly as of now.
31 30
32 (c) after running a szap, you have to run ca_zap, for the 31 (c) after running a szap, you have to run ca_zap, for the
33 descrambler to function, 32 descrambler to function,
34 33 eg: $ ca_zap channels.conf "TMC"
35 eg: $ ca_zap patched_channels.conf "TMC"
36
37 The patched means a patch to apply to scan, such that scan can
38 generate a channels.conf_with pmt, which has this PMT PID info
39 (NOTE: szap cannot use this channels.conf with the PMT_PID)
40
41 34
42 (d) Hopeflly Enjoy your favourite subscribed channel as you do with 35 (d) Hopeflly Enjoy your favourite subscribed channel as you do with
43 a FTA card. 36 a FTA card.
diff --git a/Documentation/fb/cyblafb/bugs b/Documentation/fb/cyblafb/bugs
new file mode 100644
index 0000000000..f90cc66ea9
--- /dev/null
+++ b/Documentation/fb/cyblafb/bugs
@@ -0,0 +1,14 @@
1Bugs
2====
3
4I currently don't know of any bug. Please do send reports to:
5 - linux-fbdev-devel@lists.sourceforge.net
6 - Knut_Petersen@t-online.de.
7
8
9Untested features
10=================
11
12All LCD stuff is untested. If it worked in tridentfb, it should work in
13cyblafb. Please test and report the results to Knut_Petersen@t-online.de.
14
diff --git a/Documentation/fb/cyblafb/credits b/Documentation/fb/cyblafb/credits
new file mode 100644
index 0000000000..0eb3b443dc
--- /dev/null
+++ b/Documentation/fb/cyblafb/credits
@@ -0,0 +1,7 @@
1Thanks to
2=========
3 * Alan Hourihane, for writing the X trident driver
4 * Jani Monoses, for writing the tridentfb driver
5 * Antonino A. Daplas, for review of the first published
6 version of cyblafb and some code
7 * Jochen Hein, for testing and a helpfull bug report
diff --git a/Documentation/fb/cyblafb/documentation b/Documentation/fb/cyblafb/documentation
new file mode 100644
index 0000000000..bb1aac0484
--- /dev/null
+++ b/Documentation/fb/cyblafb/documentation
@@ -0,0 +1,17 @@
1Available Documentation
2=======================
3
4Apollo PLE 133 Chipset VT8601A North Bridge Datasheet, Rev. 1.82, October 22,
52001, available from VIA:
6
7 http://www.viavpsd.com/product/6/15/DS8601A182.pdf
8
9The datasheet is incomplete, some registers that need to be programmed are not
10explained at all and important bits are listed as "reserved". But you really
11need the datasheet to understand the code. "p. xxx" comments refer to page
12numbers of this document.
13
14XFree/XOrg drivers are available and of good quality, looking at the code
15there is a good idea if the datasheet does not provide enough information
16or if the datasheet seems to be wrong.
17
diff --git a/Documentation/fb/cyblafb/fb.modes b/Documentation/fb/cyblafb/fb.modes
new file mode 100644
index 0000000000..cf4351fc32
--- /dev/null
+++ b/Documentation/fb/cyblafb/fb.modes
@@ -0,0 +1,155 @@
1#
2# Sample fb.modes file
3#
4# Provides an incomplete list of working modes for
5# the cyberblade/i1 graphics core.
6#
7# The value 4294967256 is used instead of -40. Of course, -40 is not
8# a really reasonable value, but chip design does not always follow
9# logic. Believe me, it's ok, and it's the way the BIOS does it.
10#
11# fbset requires 4294967256 in fb.modes and -40 as an argument to
12# the -t parameter. That's also not too reasonable, and it might change
13# in the future or might even be differt for your current version.
14#
15
16mode "640x480-50"
17 geometry 640 480 640 3756 8
18 timings 47619 4294967256 24 17 0 216 3
19endmode
20
21mode "640x480-60"
22 geometry 640 480 640 3756 8
23 timings 39682 4294967256 24 17 0 216 3
24endmode
25
26mode "640x480-70"
27 geometry 640 480 640 3756 8
28 timings 34013 4294967256 24 17 0 216 3
29endmode
30
31mode "640x480-72"
32 geometry 640 480 640 3756 8
33 timings 33068 4294967256 24 17 0 216 3
34endmode
35
36mode "640x480-75"
37 geometry 640 480 640 3756 8
38 timings 31746 4294967256 24 17 0 216 3
39endmode
40
41mode "640x480-80"
42 geometry 640 480 640 3756 8
43 timings 29761 4294967256 24 17 0 216 3
44endmode
45
46mode "640x480-85"
47 geometry 640 480 640 3756 8
48 timings 28011 4294967256 24 17 0 216 3
49endmode
50
51mode "800x600-50"
52 geometry 800 600 800 3221 8
53 timings 30303 96 24 14 0 136 11
54endmode
55
56mode "800x600-60"
57 geometry 800 600 800 3221 8
58 timings 25252 96 24 14 0 136 11
59endmode
60
61mode "800x600-70"
62 geometry 800 600 800 3221 8
63 timings 21645 96 24 14 0 136 11
64endmode
65
66mode "800x600-72"
67 geometry 800 600 800 3221 8
68 timings 21043 96 24 14 0 136 11
69endmode
70
71mode "800x600-75"
72 geometry 800 600 800 3221 8
73 timings 20202 96 24 14 0 136 11
74endmode
75
76mode "800x600-80"
77 geometry 800 600 800 3221 8
78 timings 18939 96 24 14 0 136 11
79endmode
80
81mode "800x600-85"
82 geometry 800 600 800 3221 8
83 timings 17825 96 24 14 0 136 11
84endmode
85
86mode "1024x768-50"
87 geometry 1024 768 1024 2815 8
88 timings 19054 144 24 29 0 120 3
89endmode
90
91mode "1024x768-60"
92 geometry 1024 768 1024 2815 8
93 timings 15880 144 24 29 0 120 3
94endmode
95
96mode "1024x768-70"
97 geometry 1024 768 1024 2815 8
98 timings 13610 144 24 29 0 120 3
99endmode
100
101mode "1024x768-72"
102 geometry 1024 768 1024 2815 8
103 timings 13232 144 24 29 0 120 3
104endmode
105
106mode "1024x768-75"
107 geometry 1024 768 1024 2815 8
108 timings 12703 144 24 29 0 120 3
109endmode
110
111mode "1024x768-80"
112 geometry 1024 768 1024 2815 8
113 timings 11910 144 24 29 0 120 3
114endmode
115
116mode "1024x768-85"
117 geometry 1024 768 1024 2815 8
118 timings 11209 144 24 29 0 120 3
119endmode
120
121mode "1280x1024-50"
122 geometry 1280 1024 1280 2662 8
123 timings 11114 232 16 39 0 160 3
124endmode
125
126mode "1280x1024-60"
127 geometry 1280 1024 1280 2662 8
128 timings 9262 232 16 39 0 160 3
129endmode
130
131mode "1280x1024-70"
132 geometry 1280 1024 1280 2662 8
133 timings 7939 232 16 39 0 160 3
134endmode
135
136mode "1280x1024-72"
137 geometry 1280 1024 1280 2662 8
138 timings 7719 232 16 39 0 160 3
139endmode
140
141mode "1280x1024-75"
142 geometry 1280 1024 1280 2662 8
143 timings 7410 232 16 39 0 160 3
144endmode
145
146mode "1280x1024-80"
147 geometry 1280 1024 1280 2662 8
148 timings 6946 232 16 39 0 160 3
149endmode
150
151mode "1280x1024-85"
152 geometry 1280 1024 1280 2662 8
153 timings 6538 232 16 39 0 160 3
154endmode
155
diff --git a/Documentation/fb/cyblafb/performance b/Documentation/fb/cyblafb/performance
new file mode 100644
index 0000000000..eb4e47a9ce
--- /dev/null
+++ b/Documentation/fb/cyblafb/performance
@@ -0,0 +1,80 @@
1Speed
2=====
3
4CyBlaFB is much faster than tridentfb and vesafb. Compare the performance data
5for mode 1280x1024-[8,16,32]@61 Hz.
6
7Test 1: Cat a file with 2000 lines of 0 characters.
8Test 2: Cat a file with 2000 lines of 80 characters.
9Test 3: Cat a file with 2000 lines of 160 characters.
10
11All values show system time use in seconds, kernel 2.6.12 was used for
12the measurements. 2.6.13 is a bit slower, 2.6.14 hopefully will include a
13patch that speeds up kernel bitblitting a lot ( > 20%).
14
15+-----------+-----------------------------------------------------+
16| | not accelerated |
17| TRIDENTFB +-----------------+-----------------+-----------------+
18| of 2.6.12 | 8 bpp | 16 bpp | 32 bpp |
19| | noypan | ypan | noypan | ypan | noypan | ypan |
20+-----------+--------+--------+--------+--------+--------+--------+
21| Test 1 | 4.31 | 4.33 | 6.05 | 12.81 | ---- | ---- |
22| Test 2 | 67.94 | 5.44 | 123.16 | 14.79 | ---- | ---- |
23| Test 3 | 131.36 | 6.55 | 240.12 | 16.76 | ---- | ---- |
24+-----------+--------+--------+--------+--------+--------+--------+
25| Comments | | | completely bro- |
26| | | | ken, monitor |
27| | | | switches off |
28+-----------+-----------------+-----------------+-----------------+
29
30
31+-----------+-----------------------------------------------------+
32| | accelerated |
33| TRIDENTFB +-----------------+-----------------+-----------------+
34| of 2.6.12 | 8 bpp | 16 bpp | 32 bpp |
35| | noypan | ypan | noypan | ypan | noypan | ypan |
36+-----------+--------+--------+--------+--------+--------+--------+
37| Test 1 | ---- | ---- | 20.62 | 1.22 | ---- | ---- |
38| Test 2 | ---- | ---- | 22.61 | 3.19 | ---- | ---- |
39| Test 3 | ---- | ---- | 24.59 | 5.16 | ---- | ---- |
40+-----------+--------+--------+--------+--------+--------+--------+
41| Comments | broken, writing | broken, ok only | completely bro- |
42| | to wrong places | if bgcolor is | ken, monitor |
43| | on screen + bug | black, bug in | switches off |
44| | in fillrect() | fillrect() | |
45+-----------+-----------------+-----------------+-----------------+
46
47
48+-----------+-----------------------------------------------------+
49| | not accelerated |
50| VESAFB +-----------------+-----------------+-----------------+
51| of 2.6.12 | 8 bpp | 16 bpp | 32 bpp |
52| | noypan | ypan | noypan | ypan | noypan | ypan |
53+-----------+--------+--------+--------+--------+--------+--------+
54| Test 1 | 4.26 | 3.76 | 5.99 | 7.23 | ---- | ---- |
55| Test 2 | 65.65 | 4.89 | 120.88 | 9.08 | ---- | ---- |
56| Test 3 | 126.91 | 5.94 | 235.77 | 11.03 | ---- | ---- |
57+-----------+--------+--------+--------+--------+--------+--------+
58| Comments | vga=0x307 | vga=0x31a | vga=0x31b not |
59| | fh=80kHz | fh=80kHz | supported by |
60| | fv=75kHz | fv=75kHz | video BIOS and |
61| | | | hardware |
62+-----------+-----------------+-----------------+-----------------+
63
64
65+-----------+-----------------------------------------------------+
66| | accelerated |
67| CYBLAFB +-----------------+-----------------+-----------------+
68| | 8 bpp | 16 bpp | 32 bpp |
69| | noypan | ypan | noypan | ypan | noypan | ypan |
70+-----------+--------+--------+--------+--------+--------+--------+
71| Test 1 | 8.02 | 0.23 | 19.04 | 0.61 | 57.12 | 2.74 |
72| Test 2 | 8.38 | 0.55 | 19.39 | 0.92 | 57.54 | 3.13 |
73| Test 3 | 8.73 | 0.86 | 19.74 | 1.24 | 57.95 | 3.51 |
74+-----------+--------+--------+--------+--------+--------+--------+
75| Comments | | | |
76| | | | |
77| | | | |
78| | | | |
79+-----------+-----------------+-----------------+-----------------+
80
diff --git a/Documentation/fb/cyblafb/todo b/Documentation/fb/cyblafb/todo
new file mode 100644
index 0000000000..80fb2f89b6
--- /dev/null
+++ b/Documentation/fb/cyblafb/todo
@@ -0,0 +1,32 @@
1TODO / Missing features
2=======================
3
4Verify LCD stuff "stretch" and "center" options are
5 completely untested ... this code needs to be
6 verified. As I don't have access to such
7 hardware, please contact me if you are
8 willing run some tests.
9
10Interlaced video modes The reason that interleaved
11 modes are disabled is that I do not know
12 the meaning of the vertical interlace
13 parameter. Also the datasheet mentions a
14 bit d8 of a horizontal interlace parameter,
15 but nowhere the lower 8 bits. Please help
16 if you can.
17
18low-res double scan modes Who needs it?
19
20accelerated color blitting Who needs it? The console driver does use color
21 blitting for nothing but drawing the penguine,
22 everything else is done using color expanding
23 blitting of 1bpp character bitmaps.
24
25xpanning Who needs it?
26
27ioctls Who needs it?
28
29TV-out Will be done later
30
31??? Feel free to contact me if you have any
32 feature requests
diff --git a/Documentation/fb/cyblafb/usage b/Documentation/fb/cyblafb/usage
new file mode 100644
index 0000000000..e627c8f542
--- /dev/null
+++ b/Documentation/fb/cyblafb/usage
@@ -0,0 +1,206 @@
1CyBlaFB is a framebuffer driver for the Cyberblade/i1 graphics core integrated
2into the VIA Apollo PLE133 (aka vt8601) south bridge. It is developed and
3tested using a VIA EPIA 5000 board.
4
5Cyblafb - compiled into the kernel or as a module?
6==================================================
7
8You might compile cyblafb either as a module or compile it permanently into the
9kernel.
10
11Unless you have a real reason to do so you should not compile both vesafb and
12cyblafb permanently into the kernel. It's possible and it helps during the
13developement cycle, but it's useless and will at least block some otherwise
14usefull memory for ordinary users.
15
16Selecting Modes
17===============
18
19 Startup Mode
20 ============
21
22 First of all, you might use the "vga=???" boot parameter as it is
23 documented in vesafb.txt and svga.txt. Cyblafb will detect the video
24 mode selected and will use the geometry and timings found by
25 inspecting the hardware registers.
26
27 video=cyblafb vga=0x317
28
29 Alternatively you might use a combination of the mode, ref and bpp
30 parameters. If you compiled the driver into the kernel, add something
31 like this to the kernel command line:
32
33 video=cyblafb:1280x1024,bpp=16,ref=50 ...
34
35 If you compiled the driver as a module, the same mode would be
36 selected by the following command:
37
38 modprobe cyblafb mode=1280x1024 bpp=16 ref=50 ...
39
40 None of the modes possible to select as startup modes are affected by
41 the problems described at the end of the next subsection.
42
43 Mode changes using fbset
44 ========================
45
46 You might use fbset to change the video mode, see "man fbset". Cyblafb
47 generally does assume that you know what you are doing. But it does
48 some checks, especially those that are needed to prevent you from
49 damaging your hardware.
50
51 - only 8, 16, 24 and 32 bpp video modes are accepted
52 - interlaced video modes are not accepted
53 - double scan video modes are not accepted
54 - if a flat panel is found, cyblafb does not allow you
55 to program a resolution higher than the physical
56 resolution of the flat panel monitor
57 - cyblafb does not allow xres to differ from xres_virtual
58 - cyblafb does not allow vclk to exceed 230 MHz. As 32 bpp
59 and (currently) 24 bit modes use a doubled vclk internally,
60 the dotclock limit as seen by fbset is 115 MHz for those
61 modes and 230 MHz for 8 and 16 bpp modes.
62
63 Any request that violates the rules given above will be ignored and
64 fbset will return an error.
65
66 If you program a virtual y resolution higher than the hardware limit,
67 cyblafb will silently decrease that value to the highest possible
68 value.
69
70 Attempts to disable acceleration are ignored.
71
72 Some video modes that should work do not work as expected. If you use
73 the standard fb.modes, fbset 640x480-60 will program that mode, but
74 you will see a vertical area, about two characters wide, with only
75 much darker characters than the other characters on the screen.
76 Cyblafb does allow that mode to be set, as it does not violate the
77 official specifications. It would need a lot of code to reliably sort
78 out all invalid modes, playing around with the margin values will
79 give a valid mode quickly. And if cyblafb would detect such an invalid
80 mode, should it silently alter the requested values or should it
81 report an error? Both options have some pros and cons. As stated
82 above, none of the startup modes are affected, and if you set
83 verbosity to 1 or higher, cyblafb will print the fbset command that
84 would be needed to program that mode using fbset.
85
86
87Other Parameters
88================
89
90
91crt don't autodetect, assume monitor connected to
92 standard VGA connector
93
94fp don't autodetect, assume flat panel display
95 connected to flat panel monitor interface
96
97nativex inform driver about native x resolution of
98 flat panel monitor connected to special
99 interface (should be autodetected)
100
101stretch stretch image to adapt low resolution modes to
102 higer resolutions of flat panel monitors
103 connected to special interface
104
105center center image to adapt low resolution modes to
106 higer resolutions of flat panel monitors
107 connected to special interface
108
109memsize use if autodetected memsize is wrong ...
110 should never be necessary
111
112nopcirr disable PCI read retry
113nopciwr disable PCI write retry
114nopcirb disable PCI read bursts
115nopciwb disable PCI write bursts
116
117bpp bpp for specified modes
118 valid values: 8 || 16 || 24 || 32
119
120ref refresh rate for specified mode
121 valid values: 50 <= ref <= 85
122
123mode 640x480 or 800x600 or 1024x768 or 1280x1024
124 if not specified, the startup mode will be detected
125 and used, so you might also use the vga=??? parameter
126 described in vesafb.txt. If you do not specify a mode,
127 bpp and ref parameters are ignored.
128
129verbosity 0 is the default, increase to at least 2 for every
130 bug report!
131
132vesafb allows cyblafb to be loaded after vesafb has been
133 loaded. See sections "Module unloading ...".
134
135
136Development hints
137=================
138
139It's much faster do compile a module and to load the new version after
140unloading the old module than to compile a new kernel and to reboot. So if you
141try to work on cyblafb, it might be a good idea to use cyblafb as a module.
142In real life, fast often means dangerous, and that's also the case here. If
143you introduce a serious bug when cyblafb is compiled into the kernel, the
144kernel will lock or oops with a high probability before the file system is
145mounted, and the danger for your data is low. If you load a broken own version
146of cyblafb on a running system, the danger for the integrity of the file
147system is much higher as you might need a hard reset afterwards. Decide
148yourself.
149
150Module unloading, the vfb method
151================================
152
153If you want to unload/reload cyblafb using the virtual framebuffer, you need
154to enable vfb support in the kernel first. After that, load the modules as
155shown below:
156
157 modprobe vfb vfb_enable=1
158 modprobe fbcon
159 modprobe cyblafb
160 fbset -fb /dev/fb1 1280x1024-60 -vyres 2662
161 con2fb /dev/fb1 /dev/tty1
162 ...
163
164If you now made some changes to cyblafb and want to reload it, you might do it
165as show below:
166
167 con2fb /dev/fb0 /dev/tty1
168 ...
169 rmmod cyblafb
170 modprobe cyblafb
171 con2fb /dev/fb1 /dev/tty1
172 ...
173
174Of course, you might choose another mode, and most certainly you also want to
175map some other /dev/tty* to the real framebuffer device. You might also choose
176to compile fbcon as a kernel module or place it permanently in the kernel.
177
178I do not know of any way to unload fbcon, and fbcon will prevent the
179framebuffer device loaded first from unloading. [If there is a way, then
180please add a description here!]
181
182Module unloading, the vesafb method
183===================================
184
185Configure the kernel:
186
187 <*> Support for frame buffer devices
188 [*] VESA VGA graphics support
189 <M> Cyberblade/i1 support
190
191Add e.g. "video=vesafb:ypan vga=0x307" to the kernel parameters. The ypan
192parameter is important, choose any vga parameter you like as long as it is
193a graphics mode.
194
195After booting, load cyblafb without any mode and bpp parameter and assign
196cyblafb to individual ttys using con2fb, e.g.:
197
198 modprobe cyblafb vesafb=1
199 con2fb /dev/fb1 /dev/tty1
200
201Unloading cyblafb works without problems after you assign vesafb to all
202ttys again, e.g.:
203
204 con2fb /dev/fb0 /dev/tty1
205 rmmod cyblafb
206
diff --git a/Documentation/fb/cyblafb/whycyblafb b/Documentation/fb/cyblafb/whycyblafb
new file mode 100644
index 0000000000..a123bc11e6
--- /dev/null
+++ b/Documentation/fb/cyblafb/whycyblafb
@@ -0,0 +1,85 @@
1I tried the following framebuffer drivers:
2
3 - TRIDENTFB is full of bugs. Acceleration is broken for Blade3D
4 graphics cores like the cyberblade/i1. It claims to support a great
5 number of devices, but documentation for most of these devices is
6 unfortunately not available. There is _no_ reason to use tridentfb
7 for cyberblade/i1 + CRT users. VESAFB is faster, and the one
8 advantage, mode switching, is broken in tridentfb.
9
10 - VESAFB is used by many distributions as a standard. Vesafb does
11 not support mode switching. VESAFB is a bit faster than the working
12 configurations of TRIDENTFB, but it is still too slow, even if you
13 use ypan.
14
15 - EPIAFB (you'll find it on sourceforge) supports the Cyberblade/i1
16 graphics core, but it still has serious bugs and developement seems
17 to have stopped. This is the one driver with TV-out support. If you
18 do need this feature, try epiafb.
19
20None of these drivers was a real option for me.
21
22I believe that is unreasonable to change code that announces to support 20
23devices if I only have more or less sufficient documentation for exactly one
24of these. The risk of breaking device foo while fixing device bar is too high.
25
26So I decided to start CyBlaFB as a stripped down tridentfb.
27
28All code specific to other Trident chips has been removed. After that there
29were a lot of cosmetic changes to increase the readability of the code. All
30register names were changed to those mnemonics used in the datasheet. Function
31and macro names were changed if they hindered easy understanding of the code.
32
33After that I debugged the code and implemented some new features. I'll try to
34give a little summary of the main changes:
35
36 - calculation of vertical and horizontal timings was fixed
37
38 - video signal quality has been improved dramatically
39
40 - acceleration:
41
42 - fillrect and copyarea were fixed and reenabled
43
44 - color expanding imageblit was newly implemented, color
45 imageblit (only used to draw the penguine) still uses the
46 generic code.
47
48 - init of the acceleration engine was improved and moved to a
49 place where it really works ...
50
51 - sync function has a timeout now and tries to reset and
52 reinit the accel engine if necessary
53
54 - fewer slow copyarea calls when doing ypan scrolling by using
55 undocumented bit d21 of screen start address stored in
56 CR2B[5]. BIOS does use it also, so this should be safe.
57
58 - cyblafb rejects any attempt to set modes that would cause vclk
59 values above reasonable 230 MHz. 32bit modes use a clock
60 multiplicator of 2, so fbset does show the correct values for
61 pixclock but not for vclk in this case. The fbset limit is 115 MHz
62 for 32 bpp modes.
63
64 - cyblafb rejects modes known to be broken or unimplemented (all
65 interlaced modes, all doublescan modes for now)
66
67 - cyblafb now works independant of the video mode in effect at startup
68 time (tridentfb does not init all needed registers to reasonable
69 values)
70
71 - switching between video modes does work reliably now
72
73 - the first video mode now is the one selected on startup using the
74 vga=???? mechanism or any of
75 - 640x480, 800x600, 1024x768, 1280x1024
76 - 8, 16, 24 or 32 bpp
77 - refresh between 50 Hz and 85 Hz, 1 Hz steps (1280x1024-32
78 is limited to 63Hz)
79
80 - pci retry and pci burst mode are settable (try to disable if you
81 experience latency problems)
82
83 - built as a module cyblafb might be unloaded and reloaded using
84 the vfb module and con2vt or might be used together with vesafb
85
diff --git a/Documentation/fb/intel810.txt b/Documentation/fb/intel810.txt
index fd68b162e4..4f0d6bc789 100644
--- a/Documentation/fb/intel810.txt
+++ b/Documentation/fb/intel810.txt
@@ -5,6 +5,7 @@ Intel 810/815 Framebuffer driver
5 March 17, 2002 5 March 17, 2002
6 6
7 First Released: July 2001 7 First Released: July 2001
8 Last Update: September 12, 2005
8================================================================ 9================================================================
9 10
10A. Introduction 11A. Introduction
@@ -44,6 +45,8 @@ B. Features
44 45
45 - Hardware Cursor Support 46 - Hardware Cursor Support
46 47
48 - Supports EDID probing either by DDC/I2C or through the BIOS
49
47C. List of available options 50C. List of available options
48 51
49 a. "video=i810fb" 52 a. "video=i810fb"
@@ -52,14 +55,17 @@ C. List of available options
52 Recommendation: required 55 Recommendation: required
53 56
54 b. "xres:<value>" 57 b. "xres:<value>"
55 select horizontal resolution in pixels 58 select horizontal resolution in pixels. (This parameter will be
59 ignored if 'mode_option' is specified. See 'o' below).
56 60
57 Recommendation: user preference 61 Recommendation: user preference
58 (default = 640) 62 (default = 640)
59 63
60 c. "yres:<value>" 64 c. "yres:<value>"
61 select vertical resolution in scanlines. If Discrete Video Timings 65 select vertical resolution in scanlines. If Discrete Video Timings
62 is enabled, this will be ignored and computed as 3*xres/4. 66 is enabled, this will be ignored and computed as 3*xres/4. (This
67 parameter will be ignored if 'mode_option' is specified. See 'o'
68 below)
63 69
64 Recommendation: user preference 70 Recommendation: user preference
65 (default = 480) 71 (default = 480)
@@ -86,7 +92,8 @@ C. List of available options
86 g. "hsync1/hsync2:<value>" 92 g. "hsync1/hsync2:<value>"
87 select the minimum and maximum Horizontal Sync Frequency of the 93 select the minimum and maximum Horizontal Sync Frequency of the
88 monitor in KHz. If a using a fixed frequency monitor, hsync1 must 94 monitor in KHz. If a using a fixed frequency monitor, hsync1 must
89 be equal to hsync2. 95 be equal to hsync2. If EDID probing is successful, these will be
96 ignored and values will be taken from the EDID block.
90 97
91 Recommendation: check monitor manual for correct values 98 Recommendation: check monitor manual for correct values
92 default (29/30) 99 default (29/30)
@@ -94,7 +101,8 @@ C. List of available options
94 h. "vsync1/vsync2:<value>" 101 h. "vsync1/vsync2:<value>"
95 select the minimum and maximum Vertical Sync Frequency of the monitor 102 select the minimum and maximum Vertical Sync Frequency of the monitor
96 in Hz. You can also use this option to lock your monitor's refresh 103 in Hz. You can also use this option to lock your monitor's refresh
97 rate. 104 rate. If EDID probing is successful, these will be ignored and values
105 will be taken from the EDID block.
98 106
99 Recommendation: check monitor manual for correct values 107 Recommendation: check monitor manual for correct values
100 (default = 60/60) 108 (default = 60/60)
@@ -154,7 +162,11 @@ C. List of available options
154 162
155 Recommendation: do not set 163 Recommendation: do not set
156 (default = not set) 164 (default = not set)
157 165 o. <xres>x<yres>[-<bpp>][@<refresh>]
166 The driver will now accept specification of boot mode option. If this
167 is specified, the options 'xres' and 'yres' will be ignored. See
168 Documentation/fb/modedb.txt for usage.
169
158D. Kernel booting 170D. Kernel booting
159 171
160Separate each option/option-pair by commas (,) and the option from its value 172Separate each option/option-pair by commas (,) and the option from its value
@@ -176,7 +188,10 @@ will be computed based on the hsync1/hsync2 and vsync1/vsync2 values.
176 188
177IMPORTANT: 189IMPORTANT:
178You must include hsync1, hsync2, vsync1 and vsync2 to enable video modes 190You must include hsync1, hsync2, vsync1 and vsync2 to enable video modes
179better than 640x480 at 60Hz. 191better than 640x480 at 60Hz. HOWEVER, if your chipset/display combination
192supports I2C and has an EDID block, you can safely exclude hsync1, hsync2,
193vsync1 and vsync2 parameters. These parameters will be taken from the EDID
194block.
180 195
181E. Module options 196E. Module options
182 197
@@ -217,32 +232,21 @@ F. Setup
217 This is required. The option is under "Character Devices" 232 This is required. The option is under "Character Devices"
218 233
219 d. Under "Graphics Support", select "Intel 810/815" either statically 234 d. Under "Graphics Support", select "Intel 810/815" either statically
220 or as a module. Choose "use VESA GTF for video timings" if you 235 or as a module. Choose "use VESA Generalized Timing Formula" if
221 need to maximize the capability of your display. To be on the 236 you need to maximize the capability of your display. To be on the
222 safe side, you can leave this unselected. 237 safe side, you can leave this unselected.
223 238
224 e. If you want a framebuffer console, enable it under "Console 239 e. If you want support for DDC/I2C probing (Plug and Play Displays),
240 set 'Enable DDC Support' to 'y'. To make this option appear, set
241 'use VESA Generalized Timing Formula' to 'y'.
242
243 f. If you want a framebuffer console, enable it under "Console
225 Drivers" 244 Drivers"
226 245
227 f. Compile your kernel. 246 g. Compile your kernel.
228 247
229 g. Load the driver as described in section D and E. 248 h. Load the driver as described in section D and E.
230 249
231 Optional:
232 h. If you are going to run XFree86 with its native drivers, the
233 standard XFree86 4.1.0 and 4.2.0 drivers should work as is.
234 However, there's a bug in the XFree86 i810 drivers. It attempts
235 to use XAA even when switched to the console. This will crash
236 your server. I have a fix at this site:
237
238 http://i810fb.sourceforge.net.
239
240 You can either use the patch, or just replace
241
242 /usr/X11R6/lib/modules/drivers/i810_drv.o
243
244 with the one provided at the website.
245
246 i. Try the DirectFB (http://www.directfb.org) + the i810 gfxdriver 250 i. Try the DirectFB (http://www.directfb.org) + the i810 gfxdriver
247 patch to see the chipset in action (or inaction :-). 251 patch to see the chipset in action (or inaction :-).
248 252
diff --git a/Documentation/fb/modedb.txt b/Documentation/fb/modedb.txt
index e04458b319..4fcdb4cf4c 100644
--- a/Documentation/fb/modedb.txt
+++ b/Documentation/fb/modedb.txt
@@ -20,12 +20,83 @@ in a video= option, fbmem considers that to be a global video mode option.
20 20
21Valid mode specifiers (mode_option argument): 21Valid mode specifiers (mode_option argument):
22 22
23 <xres>x<yres>[-<bpp>][@<refresh>] 23 <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m]
24 <name>[-<bpp>][@<refresh>] 24 <name>[-<bpp>][@<refresh>]
25 25
26with <xres>, <yres>, <bpp> and <refresh> decimal numbers and <name> a string. 26with <xres>, <yres>, <bpp> and <refresh> decimal numbers and <name> a string.
27Things between square brackets are optional. 27Things between square brackets are optional.
28 28
29If 'M' is specified in the mode_option argument (after <yres> and before
30<bpp> and <refresh>, if specified) the timings will be calculated using
31VESA(TM) Coordinated Video Timings instead of looking up the mode from a table.
32If 'R' is specified, do a 'reduced blanking' calculation for digital displays.
33If 'i' is specified, calculate for an interlaced mode. And if 'm' is
34specified, add margins to the calculation (1.8% of xres rounded down to 8
35pixels and 1.8% of yres).
36
37 Sample usage: 1024x768M@60m - CVT timing with margins
38
39***** oOo ***** oOo ***** oOo ***** oOo ***** oOo ***** oOo ***** oOo *****
40
41What is the VESA(TM) Coordinated Video Timings (CVT)?
42
43From the VESA(TM) Website:
44
45 "The purpose of CVT is to provide a method for generating a consistent
46 and coordinated set of standard formats, display refresh rates, and
47 timing specifications for computer display products, both those
48 employing CRTs, and those using other display technologies. The
49 intention of CVT is to give both source and display manufacturers a
50 common set of tools to enable new timings to be developed in a
51 consistent manner that ensures greater compatibility."
52
53This is the third standard approved by VESA(TM) concerning video timings. The
54first was the Discrete Video Timings (DVT) which is a collection of
55pre-defined modes approved by VESA(TM). The second is the Generalized Timing
56Formula (GTF) which is an algorithm to calculate the timings, given the
57pixelclock, the horizontal sync frequency, or the vertical refresh rate.
58
59The GTF is limited by the fact that it is designed mainly for CRT displays.
60It artificially increases the pixelclock because of its high blanking
61requirement. This is inappropriate for digital display interface with its high
62data rate which requires that it conserves the pixelclock as much as possible.
63Also, GTF does not take into account the aspect ratio of the display.
64
65The CVT addresses these limitations. If used with CRT's, the formula used
66is a derivation of GTF with a few modifications. If used with digital
67displays, the "reduced blanking" calculation can be used.
68
69From the framebuffer subsystem perspective, new formats need not be added
70to the global mode database whenever a new mode is released by display
71manufacturers. Specifying for CVT will work for most, if not all, relatively
72new CRT displays and probably with most flatpanels, if 'reduced blanking'
73calculation is specified. (The CVT compatibility of the display can be
74determined from its EDID. The version 1.3 of the EDID has extra 128-byte
75blocks where additional timing information is placed. As of this time, there
76is no support yet in the layer to parse this additional blocks.)
77
78CVT also introduced a new naming convention (should be seen from dmesg output):
79
80 <pix>M<a>[-R]
81
82 where: pix = total amount of pixels in MB (xres x yres)
83 M = always present
84 a = aspect ratio (3 - 4:3; 4 - 5:4; 9 - 15:9, 16:9; A - 16:10)
85 -R = reduced blanking
86
87 example: .48M3-R - 800x600 with reduced blanking
88
89Note: VESA(TM) has restrictions on what is a standard CVT timing:
90
91 - aspect ratio can only be one of the above values
92 - acceptable refresh rates are 50, 60, 70 or 85 Hz only
93 - if reduced blanking, the refresh rate must be at 60Hz
94
95If one of the above are not satisfied, the kernel will print a warning but the
96timings will still be calculated.
97
98***** oOo ***** oOo ***** oOo ***** oOo ***** oOo ***** oOo ***** oOo *****
99
29To find a suitable video mode, you just call 100To find a suitable video mode, you just call
30 101
31int __init fb_find_mode(struct fb_var_screeninfo *var, 102int __init fb_find_mode(struct fb_var_screeninfo *var,
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index 5f95d4b3ca..784e08c1c8 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -17,14 +17,6 @@ Who: Greg Kroah-Hartman <greg@kroah.com>
17 17
18--------------------------- 18---------------------------
19 19
20What: ACPI S4bios support
21When: May 2005
22Why: Noone uses it, and it probably does not work, anyway. swsusp is
23 faster, more reliable, and people are actually using it.
24Who: Pavel Machek <pavel@suse.cz>
25
26---------------------------
27
28What: io_remap_page_range() (macro or function) 20What: io_remap_page_range() (macro or function)
29When: September 2005 21When: September 2005
30Why: Replaced by io_remap_pfn_range() which allows more memory space 22Why: Replaced by io_remap_pfn_range() which allows more memory space
diff --git a/Documentation/filesystems/files.txt b/Documentation/filesystems/files.txt
new file mode 100644
index 0000000000..8c206f4e02
--- /dev/null
+++ b/Documentation/filesystems/files.txt
@@ -0,0 +1,123 @@
1File management in the Linux kernel
2-----------------------------------
3
4This document describes how locking for files (struct file)
5and file descriptor table (struct files) works.
6
7Up until 2.6.12, the file descriptor table has been protected
8with a lock (files->file_lock) and reference count (files->count).
9->file_lock protected accesses to all the file related fields
10of the table. ->count was used for sharing the file descriptor
11table between tasks cloned with CLONE_FILES flag. Typically
12this would be the case for posix threads. As with the common
13refcounting model in the kernel, the last task doing
14a put_files_struct() frees the file descriptor (fd) table.
15The files (struct file) themselves are protected using
16reference count (->f_count).
17
18In the new lock-free model of file descriptor management,
19the reference counting is similar, but the locking is
20based on RCU. The file descriptor table contains multiple
21elements - the fd sets (open_fds and close_on_exec, the
22array of file pointers, the sizes of the sets and the array
23etc.). In order for the updates to appear atomic to
24a lock-free reader, all the elements of the file descriptor
25table are in a separate structure - struct fdtable.
26files_struct contains a pointer to struct fdtable through
27which the actual fd table is accessed. Initially the
28fdtable is embedded in files_struct itself. On a subsequent
29expansion of fdtable, a new fdtable structure is allocated
30and files->fdtab points to the new structure. The fdtable
31structure is freed with RCU and lock-free readers either
32see the old fdtable or the new fdtable making the update
33appear atomic. Here are the locking rules for
34the fdtable structure -
35
361. All references to the fdtable must be done through
37 the files_fdtable() macro :
38
39 struct fdtable *fdt;
40
41 rcu_read_lock();
42
43 fdt = files_fdtable(files);
44 ....
45 if (n <= fdt->max_fds)
46 ....
47 ...
48 rcu_read_unlock();
49
50 files_fdtable() uses rcu_dereference() macro which takes care of
51 the memory barrier requirements for lock-free dereference.
52 The fdtable pointer must be read within the read-side
53 critical section.
54
552. Reading of the fdtable as described above must be protected
56 by rcu_read_lock()/rcu_read_unlock().
57
583. For any update to the the fd table, files->file_lock must
59 be held.
60
614. To look up the file structure given an fd, a reader
62 must use either fcheck() or fcheck_files() APIs. These
63 take care of barrier requirements due to lock-free lookup.
64 An example :
65
66 struct file *file;
67
68 rcu_read_lock();
69 file = fcheck(fd);
70 if (file) {
71 ...
72 }
73 ....
74 rcu_read_unlock();
75
765. Handling of the file structures is special. Since the look-up
77 of the fd (fget()/fget_light()) are lock-free, it is possible
78 that look-up may race with the last put() operation on the
79 file structure. This is avoided using the rcuref APIs
80 on ->f_count :
81
82 rcu_read_lock();
83 file = fcheck_files(files, fd);
84 if (file) {
85 if (rcuref_inc_lf(&file->f_count))
86 *fput_needed = 1;
87 else
88 /* Didn't get the reference, someone's freed */
89 file = NULL;
90 }
91 rcu_read_unlock();
92 ....
93 return file;
94
95 rcuref_inc_lf() detects if refcounts is already zero or
96 goes to zero during increment. If it does, we fail
97 fget()/fget_light().
98
996. Since both fdtable and file structures can be looked up
100 lock-free, they must be installed using rcu_assign_pointer()
101 API. If they are looked up lock-free, rcu_dereference()
102 must be used. However it is advisable to use files_fdtable()
103 and fcheck()/fcheck_files() which take care of these issues.
104
1057. While updating, the fdtable pointer must be looked up while
106 holding files->file_lock. If ->file_lock is dropped, then
107 another thread expand the files thereby creating a new
108 fdtable and making the earlier fdtable pointer stale.
109 For example :
110
111 spin_lock(&files->file_lock);
112 fd = locate_fd(files, file, start);
113 if (fd >= 0) {
114 /* locate_fd() may have expanded fdtable, load the ptr */
115 fdt = files_fdtable(files);
116 FD_SET(fd, fdt->open_fds);
117 FD_CLR(fd, fdt->close_on_exec);
118 spin_unlock(&files->file_lock);
119 .....
120
121 Since locate_fd() can drop ->file_lock (and reacquire ->file_lock),
122 the fdtable pointer (fdt) must be loaded after locate_fd().
123
diff --git a/Documentation/filesystems/fuse.txt b/Documentation/filesystems/fuse.txt
new file mode 100644
index 0000000000..6b5741e651
--- /dev/null
+++ b/Documentation/filesystems/fuse.txt
@@ -0,0 +1,315 @@
1Definitions
2~~~~~~~~~~~
3
4Userspace filesystem:
5
6 A filesystem in which data and metadata are provided by an ordinary
7 userspace process. The filesystem can be accessed normally through
8 the kernel interface.
9
10Filesystem daemon:
11
12 The process(es) providing the data and metadata of the filesystem.
13
14Non-privileged mount (or user mount):
15
16 A userspace filesystem mounted by a non-privileged (non-root) user.
17 The filesystem daemon is running with the privileges of the mounting
18 user. NOTE: this is not the same as mounts allowed with the "user"
19 option in /etc/fstab, which is not discussed here.
20
21Mount owner:
22
23 The user who does the mounting.
24
25User:
26
27 The user who is performing filesystem operations.
28
29What is FUSE?
30~~~~~~~~~~~~~
31
32FUSE is a userspace filesystem framework. It consists of a kernel
33module (fuse.ko), a userspace library (libfuse.*) and a mount utility
34(fusermount).
35
36One of the most important features of FUSE is allowing secure,
37non-privileged mounts. This opens up new possibilities for the use of
38filesystems. A good example is sshfs: a secure network filesystem
39using the sftp protocol.
40
41The userspace library and utilities are available from the FUSE
42homepage:
43
44 http://fuse.sourceforge.net/
45
46Mount options
47~~~~~~~~~~~~~
48
49'fd=N'
50
51 The file descriptor to use for communication between the userspace
52 filesystem and the kernel. The file descriptor must have been
53 obtained by opening the FUSE device ('/dev/fuse').
54
55'rootmode=M'
56
57 The file mode of the filesystem's root in octal representation.
58
59'user_id=N'
60
61 The numeric user id of the mount owner.
62
63'group_id=N'
64
65 The numeric group id of the mount owner.
66
67'default_permissions'
68
69 By default FUSE doesn't check file access permissions, the
70 filesystem is free to implement it's access policy or leave it to
71 the underlying file access mechanism (e.g. in case of network
72 filesystems). This option enables permission checking, restricting
73 access based on file mode. This is option is usually useful
74 together with the 'allow_other' mount option.
75
76'allow_other'
77
78 This option overrides the security measure restricting file access
79 to the user mounting the filesystem. This option is by default only
80 allowed to root, but this restriction can be removed with a
81 (userspace) configuration option.
82
83'max_read=N'
84
85 With this option the maximum size of read operations can be set.
86 The default is infinite. Note that the size of read requests is
87 limited anyway to 32 pages (which is 128kbyte on i386).
88
89How do non-privileged mounts work?
90~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91
92Since the mount() system call is a privileged operation, a helper
93program (fusermount) is needed, which is installed setuid root.
94
95The implication of providing non-privileged mounts is that the mount
96owner must not be able to use this capability to compromise the
97system. Obvious requirements arising from this are:
98
99 A) mount owner should not be able to get elevated privileges with the
100 help of the mounted filesystem
101
102 B) mount owner should not get illegitimate access to information from
103 other users' and the super user's processes
104
105 C) mount owner should not be able to induce undesired behavior in
106 other users' or the super user's processes
107
108How are requirements fulfilled?
109~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110
111 A) The mount owner could gain elevated privileges by either:
112
113 1) creating a filesystem containing a device file, then opening
114 this device
115
116 2) creating a filesystem containing a suid or sgid application,
117 then executing this application
118
119 The solution is not to allow opening device files and ignore
120 setuid and setgid bits when executing programs. To ensure this
121 fusermount always adds "nosuid" and "nodev" to the mount options
122 for non-privileged mounts.
123
124 B) If another user is accessing files or directories in the
125 filesystem, the filesystem daemon serving requests can record the
126 exact sequence and timing of operations performed. This
127 information is otherwise inaccessible to the mount owner, so this
128 counts as an information leak.
129
130 The solution to this problem will be presented in point 2) of C).
131
132 C) There are several ways in which the mount owner can induce
133 undesired behavior in other users' processes, such as:
134
135 1) mounting a filesystem over a file or directory which the mount
136 owner could otherwise not be able to modify (or could only
137 make limited modifications).
138
139 This is solved in fusermount, by checking the access
140 permissions on the mountpoint and only allowing the mount if
141 the mount owner can do unlimited modification (has write
142 access to the mountpoint, and mountpoint is not a "sticky"
143 directory)
144
145 2) Even if 1) is solved the mount owner can change the behavior
146 of other users' processes.
147
148 i) It can slow down or indefinitely delay the execution of a
149 filesystem operation creating a DoS against the user or the
150 whole system. For example a suid application locking a
151 system file, and then accessing a file on the mount owner's
152 filesystem could be stopped, and thus causing the system
153 file to be locked forever.
154
155 ii) It can present files or directories of unlimited length, or
156 directory structures of unlimited depth, possibly causing a
157 system process to eat up diskspace, memory or other
158 resources, again causing DoS.
159
160 The solution to this as well as B) is not to allow processes
161 to access the filesystem, which could otherwise not be
162 monitored or manipulated by the mount owner. Since if the
163 mount owner can ptrace a process, it can do all of the above
164 without using a FUSE mount, the same criteria as used in
165 ptrace can be used to check if a process is allowed to access
166 the filesystem or not.
167
168 Note that the ptrace check is not strictly necessary to
169 prevent B/2/i, it is enough to check if mount owner has enough
170 privilege to send signal to the process accessing the
171 filesystem, since SIGSTOP can be used to get a similar effect.
172
173I think these limitations are unacceptable?
174~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
175
176If a sysadmin trusts the users enough, or can ensure through other
177measures, that system processes will never enter non-privileged
178mounts, it can relax the last limitation with a "user_allow_other"
179config option. If this config option is set, the mounting user can
180add the "allow_other" mount option which disables the check for other
181users' processes.
182
183Kernel - userspace interface
184~~~~~~~~~~~~~~~~~~~~~~~~~~~~
185
186The following diagram shows how a filesystem operation (in this
187example unlink) is performed in FUSE.
188
189NOTE: everything in this description is greatly simplified
190
191 | "rm /mnt/fuse/file" | FUSE filesystem daemon
192 | |
193 | | >sys_read()
194 | | >fuse_dev_read()
195 | | >request_wait()
196 | | [sleep on fc->waitq]
197 | |
198 | >sys_unlink() |
199 | >fuse_unlink() |
200 | [get request from |
201 | fc->unused_list] |
202 | >request_send() |
203 | [queue req on fc->pending] |
204 | [wake up fc->waitq] | [woken up]
205 | >request_wait_answer() |
206 | [sleep on req->waitq] |
207 | | <request_wait()
208 | | [remove req from fc->pending]
209 | | [copy req to read buffer]
210 | | [add req to fc->processing]
211 | | <fuse_dev_read()
212 | | <sys_read()
213 | |
214 | | [perform unlink]
215 | |
216 | | >sys_write()
217 | | >fuse_dev_write()
218 | | [look up req in fc->processing]
219 | | [remove from fc->processing]
220 | | [copy write buffer to req]
221 | [woken up] | [wake up req->waitq]
222 | | <fuse_dev_write()
223 | | <sys_write()
224 | <request_wait_answer() |
225 | <request_send() |
226 | [add request to |
227 | fc->unused_list] |
228 | <fuse_unlink() |
229 | <sys_unlink() |
230
231There are a couple of ways in which to deadlock a FUSE filesystem.
232Since we are talking about unprivileged userspace programs,
233something must be done about these.
234
235Scenario 1 - Simple deadlock
236-----------------------------
237
238 | "rm /mnt/fuse/file" | FUSE filesystem daemon
239 | |
240 | >sys_unlink("/mnt/fuse/file") |
241 | [acquire inode semaphore |
242 | for "file"] |
243 | >fuse_unlink() |
244 | [sleep on req->waitq] |
245 | | <sys_read()
246 | | >sys_unlink("/mnt/fuse/file")
247 | | [acquire inode semaphore
248 | | for "file"]
249 | | *DEADLOCK*
250
251The solution for this is to allow requests to be interrupted while
252they are in userspace:
253
254 | [interrupted by signal] |
255 | <fuse_unlink() |
256 | [release semaphore] | [semaphore acquired]
257 | <sys_unlink() |
258 | | >fuse_unlink()
259 | | [queue req on fc->pending]
260 | | [wake up fc->waitq]
261 | | [sleep on req->waitq]
262
263If the filesystem daemon was single threaded, this will stop here,
264since there's no other thread to dequeue and execute the request.
265In this case the solution is to kill the FUSE daemon as well. If
266there are multiple serving threads, you just have to kill them as
267long as any remain.
268
269Moral: a filesystem which deadlocks, can soon find itself dead.
270
271Scenario 2 - Tricky deadlock
272----------------------------
273
274This one needs a carefully crafted filesystem. It's a variation on
275the above, only the call back to the filesystem is not explicit,
276but is caused by a pagefault.
277
278 | Kamikaze filesystem thread 1 | Kamikaze filesystem thread 2
279 | |
280 | [fd = open("/mnt/fuse/file")] | [request served normally]
281 | [mmap fd to 'addr'] |
282 | [close fd] | [FLUSH triggers 'magic' flag]
283 | [read a byte from addr] |
284 | >do_page_fault() |
285 | [find or create page] |
286 | [lock page] |
287 | >fuse_readpage() |
288 | [queue READ request] |
289 | [sleep on req->waitq] |
290 | | [read request to buffer]
291 | | [create reply header before addr]
292 | | >sys_write(addr - headerlength)
293 | | >fuse_dev_write()
294 | | [look up req in fc->processing]
295 | | [remove from fc->processing]
296 | | [copy write buffer to req]
297 | | >do_page_fault()
298 | | [find or create page]
299 | | [lock page]
300 | | * DEADLOCK *
301
302Solution is again to let the the request be interrupted (not
303elaborated further).
304
305An additional problem is that while the write buffer is being
306copied to the request, the request must not be interrupted. This
307is because the destination address of the copy may not be valid
308after the request is interrupted.
309
310This is solved with doing the copy atomically, and allowing
311interruption while the page(s) belonging to the write buffer are
312faulted with get_user_pages(). The 'req->locked' flag indicates
313when the copy is taking place, and interruption is delayed until
314this flag is unset.
315
diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt
index 5024ba7a59..d4773565ea 100644
--- a/Documentation/filesystems/proc.txt
+++ b/Documentation/filesystems/proc.txt
@@ -1241,16 +1241,38 @@ swap-intensive.
1241overcommit_memory 1241overcommit_memory
1242----------------- 1242-----------------
1243 1243
1244This file contains one value. The following algorithm is used to decide if 1244Controls overcommit of system memory, possibly allowing processes
1245there's enough memory: if the value of overcommit_memory is positive, then 1245to allocate (but not use) more memory than is actually available.
1246there's always enough memory. This is a useful feature, since programs often 1246
1247malloc() huge amounts of memory 'just in case', while they only use a small 1247
1248part of it. Leaving this value at 0 will lead to the failure of such a huge 12480 - Heuristic overcommit handling. Obvious overcommits of
1249malloc(), when in fact the system has enough memory for the program to run. 1249 address space are refused. Used for a typical system. It
1250 1250 ensures a seriously wild allocation fails while allowing
1251On the other hand, enabling this feature can cause you to run out of memory 1251 overcommit to reduce swap usage. root is allowed to
1252and thrash the system to death, so large and/or important servers will want to 1252 allocate slighly more memory in this mode. This is the
1253set this value to 0. 1253 default.
1254
12551 - Always overcommit. Appropriate for some scientific
1256 applications.
1257
12582 - Don't overcommit. The total address space commit
1259 for the system is not permitted to exceed swap plus a
1260 configurable percentage (default is 50) of physical RAM.
1261 Depending on the percentage you use, in most situations
1262 this means a process will not be killed while attempting
1263 to use already-allocated memory but will receive errors
1264 on memory allocation as appropriate.
1265
1266overcommit_ratio
1267----------------
1268
1269Percentage of physical memory size to include in overcommit calculations
1270(see above.)
1271
1272Memory allocation limit = swapspace + physmem * (overcommit_ratio / 100)
1273
1274 swapspace = total size of all swap areas
1275 physmem = size of physical memory in system
1254 1276
1255nr_hugepages and hugetlb_shm_group 1277nr_hugepages and hugetlb_shm_group
1256---------------------------------- 1278----------------------------------
diff --git a/Documentation/filesystems/v9fs.txt b/Documentation/filesystems/v9fs.txt
new file mode 100644
index 0000000000..4e92feb6b5
--- /dev/null
+++ b/Documentation/filesystems/v9fs.txt
@@ -0,0 +1,95 @@
1 V9FS: 9P2000 for Linux
2 ======================
3
4ABOUT
5=====
6
7v9fs is a Unix implementation of the Plan 9 9p remote filesystem protocol.
8
9This software was originally developed by Ron Minnich <rminnich@lanl.gov>
10and Maya Gokhale <maya@lanl.gov>. Additional development by Greg Watson
11<gwatson@lanl.gov> and most recently Eric Van Hensbergen
12<ericvh@gmail.com> and Latchesar Ionkov <lucho@ionkov.net>.
13
14USAGE
15=====
16
17For remote file server:
18
19 mount -t 9P 10.10.1.2 /mnt/9
20
21For Plan 9 From User Space applications (http://swtch.com/plan9)
22
23 mount -t 9P `namespace`/acme /mnt/9 -o proto=unix,name=$USER
24
25OPTIONS
26=======
27
28 proto=name select an alternative transport. Valid options are
29 currently:
30 unix - specifying a named pipe mount point
31 tcp - specifying a normal TCP/IP connection
32 fd - used passed file descriptors for connection
33 (see rfdno and wfdno)
34
35 name=name user name to attempt mount as on the remote server. The
36 server may override or ignore this value. Certain user
37 names may require authentication.
38
39 aname=name aname specifies the file tree to access when the server is
40 offering several exported file systems.
41
42 debug=n specifies debug level. The debug level is a bitmask.
43 0x01 = display verbose error messages
44 0x02 = developer debug (DEBUG_CURRENT)
45 0x04 = display 9P trace
46 0x08 = display VFS trace
47 0x10 = display Marshalling debug
48 0x20 = display RPC debug
49 0x40 = display transport debug
50 0x80 = display allocation debug
51
52 rfdno=n the file descriptor for reading with proto=fd
53
54 wfdno=n the file descriptor for writing with proto=fd
55
56 maxdata=n the number of bytes to use for 9P packet payload (msize)
57
58 port=n port to connect to on the remote server
59
60 timeout=n request timeouts (in ms) (default 60000ms)
61
62 noextend force legacy mode (no 9P2000.u semantics)
63
64 uid attempt to mount as a particular uid
65
66 gid attempt to mount with a particular gid
67
68 afid security channel - used by Plan 9 authentication protocols
69
70 nodevmap do not map special files - represent them as normal files.
71 This can be used to share devices/named pipes/sockets between
72 hosts. This functionality will be expanded in later versions.
73
74RESOURCES
75=========
76
77The Linux version of the 9P server, along with some client-side utilities
78can be found at http://v9fs.sf.net (along with a CVS repository of the
79development branch of this module). There are user and developer mailing
80lists here, as well as a bug-tracker.
81
82For more information on the Plan 9 Operating System check out
83http://plan9.bell-labs.com/plan9
84
85For information on Plan 9 from User Space (Plan 9 applications and libraries
86ported to Linux/BSD/OSX/etc) check out http://swtch.com/plan9
87
88
89STATUS
90======
91
92The 2.6 kernel support is working on PPC and x86.
93
94PLEASE USE THE SOURCEFORGE BUG-TRACKER TO REPORT PROBLEMS.
95
diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt
index 3f318dd44c..f042c12e0e 100644
--- a/Documentation/filesystems/vfs.txt
+++ b/Documentation/filesystems/vfs.txt
@@ -1,35 +1,27 @@
1/* -*- auto-fill -*- */
2 1
3 Overview of the Virtual File System 2 Overview of the Linux Virtual File System
4 3
5 Richard Gooch <rgooch@atnf.csiro.au> 4 Original author: Richard Gooch <rgooch@atnf.csiro.au>
6 5
7 5-JUL-1999 6 Last updated on August 25, 2005
8 7
8 Copyright (C) 1999 Richard Gooch
9 Copyright (C) 2005 Pekka Enberg
9 10
10Conventions used in this document <section> 11 This file is released under the GPLv2.
11=================================
12 12
13Each section in this document will have the string "<section>" at the
14right-hand side of the section title. Each subsection will have
15"<subsection>" at the right-hand side. These strings are meant to make
16it easier to search through the document.
17 13
18NOTE that the master copy of this document is available online at: 14What is it?
19http://www.atnf.csiro.au/~rgooch/linux/docs/vfs.txt
20
21
22What is it? <section>
23=========== 15===========
24 16
25The Virtual File System (otherwise known as the Virtual Filesystem 17The Virtual File System (otherwise known as the Virtual Filesystem
26Switch) is the software layer in the kernel that provides the 18Switch) is the software layer in the kernel that provides the
27filesystem interface to userspace programs. It also provides an 19filesystem interface to userspace programs. It also provides an
28abstraction within the kernel which allows different filesystem 20abstraction within the kernel which allows different filesystem
29implementations to co-exist. 21implementations to coexist.
30 22
31 23
32A Quick Look At How It Works <section> 24A Quick Look At How It Works
33============================ 25============================
34 26
35In this section I'll briefly describe how things work, before 27In this section I'll briefly describe how things work, before
@@ -38,7 +30,8 @@ when user programs open and manipulate files, and then look from the
38other view which is how a filesystem is supported and subsequently 30other view which is how a filesystem is supported and subsequently
39mounted. 31mounted.
40 32
41Opening a File <subsection> 33
34Opening a File
42-------------- 35--------------
43 36
44The VFS implements the open(2), stat(2), chmod(2) and similar system 37The VFS implements the open(2), stat(2), chmod(2) and similar system
@@ -77,7 +70,7 @@ back to userspace.
77 70
78Opening a file requires another operation: allocation of a file 71Opening a file requires another operation: allocation of a file
79structure (this is the kernel-side implementation of file 72structure (this is the kernel-side implementation of file
80descriptors). The freshly allocated file structure is initialised with 73descriptors). The freshly allocated file structure is initialized with
81a pointer to the dentry and a set of file operation member functions. 74a pointer to the dentry and a set of file operation member functions.
82These are taken from the inode data. The open() file method is then 75These are taken from the inode data. The open() file method is then
83called so the specific filesystem implementation can do it's work. You 76called so the specific filesystem implementation can do it's work. You
@@ -102,7 +95,8 @@ filesystem or driver code at the same time, on different
102processors. You should ensure that access to shared resources is 95processors. You should ensure that access to shared resources is
103protected by appropriate locks. 96protected by appropriate locks.
104 97
105Registering and Mounting a Filesystem <subsection> 98
99Registering and Mounting a Filesystem
106------------------------------------- 100-------------------------------------
107 101
108If you want to support a new kind of filesystem in the kernel, all you 102If you want to support a new kind of filesystem in the kernel, all you
@@ -123,17 +117,21 @@ updated to point to the root inode for the new filesystem.
123It's now time to look at things in more detail. 117It's now time to look at things in more detail.
124 118
125 119
126struct file_system_type <section> 120struct file_system_type
127======================= 121=======================
128 122
129This describes the filesystem. As of kernel 2.1.99, the following 123This describes the filesystem. As of kernel 2.6.13, the following
130members are defined: 124members are defined:
131 125
132struct file_system_type { 126struct file_system_type {
133 const char *name; 127 const char *name;
134 int fs_flags; 128 int fs_flags;
135 struct super_block *(*read_super) (struct super_block *, void *, int); 129 struct super_block *(*get_sb) (struct file_system_type *, int,
136 struct file_system_type * next; 130 const char *, void *);
131 void (*kill_sb) (struct super_block *);
132 struct module *owner;
133 struct file_system_type * next;
134 struct list_head fs_supers;
137}; 135};
138 136
139 name: the name of the filesystem type, such as "ext2", "iso9660", 137 name: the name of the filesystem type, such as "ext2", "iso9660",
@@ -141,51 +139,97 @@ struct file_system_type {
141 139
142 fs_flags: various flags (i.e. FS_REQUIRES_DEV, FS_NO_DCACHE, etc.) 140 fs_flags: various flags (i.e. FS_REQUIRES_DEV, FS_NO_DCACHE, etc.)
143 141
144 read_super: the method to call when a new instance of this 142 get_sb: the method to call when a new instance of this
145 filesystem should be mounted 143 filesystem should be mounted
146 144
147 next: for internal VFS use: you should initialise this to NULL 145 kill_sb: the method to call when an instance of this filesystem
146 should be unmounted
147
148 owner: for internal VFS use: you should initialize this to THIS_MODULE in
149 most cases.
148 150
149The read_super() method has the following arguments: 151 next: for internal VFS use: you should initialize this to NULL
152
153The get_sb() method has the following arguments:
150 154
151 struct super_block *sb: the superblock structure. This is partially 155 struct super_block *sb: the superblock structure. This is partially
152 initialised by the VFS and the rest must be initialised by the 156 initialized by the VFS and the rest must be initialized by the
153 read_super() method 157 get_sb() method
158
159 int flags: mount flags
160
161 const char *dev_name: the device name we are mounting.
154 162
155 void *data: arbitrary mount options, usually comes as an ASCII 163 void *data: arbitrary mount options, usually comes as an ASCII
156 string 164 string
157 165
158 int silent: whether or not to be silent on error 166 int silent: whether or not to be silent on error
159 167
160The read_super() method must determine if the block device specified 168The get_sb() method must determine if the block device specified
161in the superblock contains a filesystem of the type the method 169in the superblock contains a filesystem of the type the method
162supports. On success the method returns the superblock pointer, on 170supports. On success the method returns the superblock pointer, on
163failure it returns NULL. 171failure it returns NULL.
164 172
165The most interesting member of the superblock structure that the 173The most interesting member of the superblock structure that the
166read_super() method fills in is the "s_op" field. This is a pointer to 174get_sb() method fills in is the "s_op" field. This is a pointer to
167a "struct super_operations" which describes the next level of the 175a "struct super_operations" which describes the next level of the
168filesystem implementation. 176filesystem implementation.
169 177
178Usually, a filesystem uses generic one of the generic get_sb()
179implementations and provides a fill_super() method instead. The
180generic methods are:
181
182 get_sb_bdev: mount a filesystem residing on a block device
170 183
171struct super_operations <section> 184 get_sb_nodev: mount a filesystem that is not backed by a device
185
186 get_sb_single: mount a filesystem which shares the instance between
187 all mounts
188
189A fill_super() method implementation has the following arguments:
190
191 struct super_block *sb: the superblock structure. The method fill_super()
192 must initialize this properly.
193
194 void *data: arbitrary mount options, usually comes as an ASCII
195 string
196
197 int silent: whether or not to be silent on error
198
199
200struct super_operations
172======================= 201=======================
173 202
174This describes how the VFS can manipulate the superblock of your 203This describes how the VFS can manipulate the superblock of your
175filesystem. As of kernel 2.1.99, the following members are defined: 204filesystem. As of kernel 2.6.13, the following members are defined:
176 205
177struct super_operations { 206struct super_operations {
178 void (*read_inode) (struct inode *); 207 struct inode *(*alloc_inode)(struct super_block *sb);
179 int (*write_inode) (struct inode *, int); 208 void (*destroy_inode)(struct inode *);
180 void (*put_inode) (struct inode *); 209
181 void (*drop_inode) (struct inode *); 210 void (*read_inode) (struct inode *);
182 void (*delete_inode) (struct inode *); 211
183 int (*notify_change) (struct dentry *, struct iattr *); 212 void (*dirty_inode) (struct inode *);
184 void (*put_super) (struct super_block *); 213 int (*write_inode) (struct inode *, int);
185 void (*write_super) (struct super_block *); 214 void (*put_inode) (struct inode *);
186 int (*statfs) (struct super_block *, struct statfs *, int); 215 void (*drop_inode) (struct inode *);
187 int (*remount_fs) (struct super_block *, int *, char *); 216 void (*delete_inode) (struct inode *);
188 void (*clear_inode) (struct inode *); 217 void (*put_super) (struct super_block *);
218 void (*write_super) (struct super_block *);
219 int (*sync_fs)(struct super_block *sb, int wait);
220 void (*write_super_lockfs) (struct super_block *);
221 void (*unlockfs) (struct super_block *);
222 int (*statfs) (struct super_block *, struct kstatfs *);
223 int (*remount_fs) (struct super_block *, int *, char *);
224 void (*clear_inode) (struct inode *);
225 void (*umount_begin) (struct super_block *);
226
227 void (*sync_inodes) (struct super_block *sb,
228 struct writeback_control *wbc);
229 int (*show_options)(struct seq_file *, struct vfsmount *);
230
231 ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
232 ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
189}; 233};
190 234
191All methods are called without any locks being held, unless otherwise 235All methods are called without any locks being held, unless otherwise
@@ -193,43 +237,62 @@ noted. This means that most methods can block safely. All methods are
193only called from a process context (i.e. not from an interrupt handler 237only called from a process context (i.e. not from an interrupt handler
194or bottom half). 238or bottom half).
195 239
240 alloc_inode: this method is called by inode_alloc() to allocate memory
241 for struct inode and initialize it.
242
243 destroy_inode: this method is called by destroy_inode() to release
244 resources allocated for struct inode.
245
196 read_inode: this method is called to read a specific inode from the 246 read_inode: this method is called to read a specific inode from the
197 mounted filesystem. The "i_ino" member in the "struct inode" 247 mounted filesystem. The i_ino member in the struct inode is
198 will be initialised by the VFS to indicate which inode to 248 initialized by the VFS to indicate which inode to read. Other
199 read. Other members are filled in by this method 249 members are filled in by this method.
250
251 You can set this to NULL and use iget5_locked() instead of iget()
252 to read inodes. This is necessary for filesystems for which the
253 inode number is not sufficient to identify an inode.
254
255 dirty_inode: this method is called by the VFS to mark an inode dirty.
200 256
201 write_inode: this method is called when the VFS needs to write an 257 write_inode: this method is called when the VFS needs to write an
202 inode to disc. The second parameter indicates whether the write 258 inode to disc. The second parameter indicates whether the write
203 should be synchronous or not, not all filesystems check this flag. 259 should be synchronous or not, not all filesystems check this flag.
204 260
205 put_inode: called when the VFS inode is removed from the inode 261 put_inode: called when the VFS inode is removed from the inode
206 cache. This method is optional 262 cache.
207 263
208 drop_inode: called when the last access to the inode is dropped, 264 drop_inode: called when the last access to the inode is dropped,
209 with the inode_lock spinlock held. 265 with the inode_lock spinlock held.
210 266
211 This method should be either NULL (normal unix filesystem 267 This method should be either NULL (normal UNIX filesystem
212 semantics) or "generic_delete_inode" (for filesystems that do not 268 semantics) or "generic_delete_inode" (for filesystems that do not
213 want to cache inodes - causing "delete_inode" to always be 269 want to cache inodes - causing "delete_inode" to always be
214 called regardless of the value of i_nlink) 270 called regardless of the value of i_nlink)
215 271
216 The "generic_delete_inode()" behaviour is equivalent to the 272 The "generic_delete_inode()" behavior is equivalent to the
217 old practice of using "force_delete" in the put_inode() case, 273 old practice of using "force_delete" in the put_inode() case,
218 but does not have the races that the "force_delete()" approach 274 but does not have the races that the "force_delete()" approach
219 had. 275 had.
220 276
221 delete_inode: called when the VFS wants to delete an inode 277 delete_inode: called when the VFS wants to delete an inode
222 278
223 notify_change: called when VFS inode attributes are changed. If this
224 is NULL the VFS falls back to the write_inode() method. This
225 is called with the kernel lock held
226
227 put_super: called when the VFS wishes to free the superblock 279 put_super: called when the VFS wishes to free the superblock
228 (i.e. unmount). This is called with the superblock lock held 280 (i.e. unmount). This is called with the superblock lock held
229 281
230 write_super: called when the VFS superblock needs to be written to 282 write_super: called when the VFS superblock needs to be written to
231 disc. This method is optional 283 disc. This method is optional
232 284
285 sync_fs: called when VFS is writing out all dirty data associated with
286 a superblock. The second parameter indicates whether the method
287 should wait until the write out has been completed. Optional.
288
289 write_super_lockfs: called when VFS is locking a filesystem and forcing
290 it into a consistent state. This function is currently used by the
291 Logical Volume Manager (LVM).
292
293 unlockfs: called when VFS is unlocking a filesystem and making it writable
294 again.
295
233 statfs: called when the VFS needs to get filesystem statistics. This 296 statfs: called when the VFS needs to get filesystem statistics. This
234 is called with the kernel lock held 297 is called with the kernel lock held
235 298
@@ -238,21 +301,31 @@ or bottom half).
238 301
239 clear_inode: called then the VFS clears the inode. Optional 302 clear_inode: called then the VFS clears the inode. Optional
240 303
304 umount_begin: called when the VFS is unmounting a filesystem.
305
306 sync_inodes: called when the VFS is writing out dirty data associated with
307 a superblock.
308
309 show_options: called by the VFS to show mount options for /proc/<pid>/mounts.
310
311 quota_read: called by the VFS to read from filesystem quota file.
312
313 quota_write: called by the VFS to write to filesystem quota file.
314
241The read_inode() method is responsible for filling in the "i_op" 315The read_inode() method is responsible for filling in the "i_op"
242field. This is a pointer to a "struct inode_operations" which 316field. This is a pointer to a "struct inode_operations" which
243describes the methods that can be performed on individual inodes. 317describes the methods that can be performed on individual inodes.
244 318
245 319
246struct inode_operations <section> 320struct inode_operations
247======================= 321=======================
248 322
249This describes how the VFS can manipulate an inode in your 323This describes how the VFS can manipulate an inode in your
250filesystem. As of kernel 2.1.99, the following members are defined: 324filesystem. As of kernel 2.6.13, the following members are defined:
251 325
252struct inode_operations { 326struct inode_operations {
253 struct file_operations * default_file_ops; 327 int (*create) (struct inode *,struct dentry *,int, struct nameidata *);
254 int (*create) (struct inode *,struct dentry *,int); 328 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
255 int (*lookup) (struct inode *,struct dentry *);
256 int (*link) (struct dentry *,struct inode *,struct dentry *); 329 int (*link) (struct dentry *,struct inode *,struct dentry *);
257 int (*unlink) (struct inode *,struct dentry *); 330 int (*unlink) (struct inode *,struct dentry *);
258 int (*symlink) (struct inode *,struct dentry *,const char *); 331 int (*symlink) (struct inode *,struct dentry *,const char *);
@@ -261,25 +334,22 @@ struct inode_operations {
261 int (*mknod) (struct inode *,struct dentry *,int,dev_t); 334 int (*mknod) (struct inode *,struct dentry *,int,dev_t);
262 int (*rename) (struct inode *, struct dentry *, 335 int (*rename) (struct inode *, struct dentry *,
263 struct inode *, struct dentry *); 336 struct inode *, struct dentry *);
264 int (*readlink) (struct dentry *, char *,int); 337 int (*readlink) (struct dentry *, char __user *,int);
265 struct dentry * (*follow_link) (struct dentry *, struct dentry *); 338 void * (*follow_link) (struct dentry *, struct nameidata *);
266 int (*readpage) (struct file *, struct page *); 339 void (*put_link) (struct dentry *, struct nameidata *, void *);
267 int (*writepage) (struct page *page, struct writeback_control *wbc);
268 int (*bmap) (struct inode *,int);
269 void (*truncate) (struct inode *); 340 void (*truncate) (struct inode *);
270 int (*permission) (struct inode *, int); 341 int (*permission) (struct inode *, int, struct nameidata *);
271 int (*smap) (struct inode *,int); 342 int (*setattr) (struct dentry *, struct iattr *);
272 int (*updatepage) (struct file *, struct page *, const char *, 343 int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *);
273 unsigned long, unsigned int, int); 344 int (*setxattr) (struct dentry *, const char *,const void *,size_t,int);
274 int (*revalidate) (struct dentry *); 345 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
346 ssize_t (*listxattr) (struct dentry *, char *, size_t);
347 int (*removexattr) (struct dentry *, const char *);
275}; 348};
276 349
277Again, all methods are called without any locks being held, unless 350Again, all methods are called without any locks being held, unless
278otherwise noted. 351otherwise noted.
279 352
280 default_file_ops: this is a pointer to a "struct file_operations"
281 which describes how to open and then manipulate open files
282
283 create: called by the open(2) and creat(2) system calls. Only 353 create: called by the open(2) and creat(2) system calls. Only
284 required if you want to support regular files. The dentry you 354 required if you want to support regular files. The dentry you
285 get should not have an inode (i.e. it should be a negative 355 get should not have an inode (i.e. it should be a negative
@@ -328,31 +398,143 @@ otherwise noted.
328 you want to support reading symbolic links 398 you want to support reading symbolic links
329 399
330 follow_link: called by the VFS to follow a symbolic link to the 400 follow_link: called by the VFS to follow a symbolic link to the
331 inode it points to. Only required if you want to support 401 inode it points to. Only required if you want to support
332 symbolic links 402 symbolic links. This function returns a void pointer cookie
403 that is passed to put_link().
404
405 put_link: called by the VFS to release resources allocated by
406 follow_link(). The cookie returned by follow_link() is passed to
407 to this function as the last parameter. It is used by filesystems
408 such as NFS where page cache is not stable (i.e. page that was
409 installed when the symbolic link walk started might not be in the
410 page cache at the end of the walk).
411
412 truncate: called by the VFS to change the size of a file. The i_size
413 field of the inode is set to the desired size by the VFS before
414 this function is called. This function is called by the truncate(2)
415 system call and related functionality.
416
417 permission: called by the VFS to check for access rights on a POSIX-like
418 filesystem.
419
420 setattr: called by the VFS to set attributes for a file. This function is
421 called by chmod(2) and related system calls.
422
423 getattr: called by the VFS to get attributes of a file. This function is
424 called by stat(2) and related system calls.
425
426 setxattr: called by the VFS to set an extended attribute for a file.
427 Extended attribute is a name:value pair associated with an inode. This
428 function is called by setxattr(2) system call.
429
430 getxattr: called by the VFS to retrieve the value of an extended attribute
431 name. This function is called by getxattr(2) function call.
432
433 listxattr: called by the VFS to list all extended attributes for a given
434 file. This function is called by listxattr(2) system call.
435
436 removexattr: called by the VFS to remove an extended attribute from a file.
437 This function is called by removexattr(2) system call.
438
439
440struct address_space_operations
441===============================
442
443This describes how the VFS can manipulate mapping of a file to page cache in
444your filesystem. As of kernel 2.6.13, the following members are defined:
445
446struct address_space_operations {
447 int (*writepage)(struct page *page, struct writeback_control *wbc);
448 int (*readpage)(struct file *, struct page *);
449 int (*sync_page)(struct page *);
450 int (*writepages)(struct address_space *, struct writeback_control *);
451 int (*set_page_dirty)(struct page *page);
452 int (*readpages)(struct file *filp, struct address_space *mapping,
453 struct list_head *pages, unsigned nr_pages);
454 int (*prepare_write)(struct file *, struct page *, unsigned, unsigned);
455 int (*commit_write)(struct file *, struct page *, unsigned, unsigned);
456 sector_t (*bmap)(struct address_space *, sector_t);
457 int (*invalidatepage) (struct page *, unsigned long);
458 int (*releasepage) (struct page *, int);
459 ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
460 loff_t offset, unsigned long nr_segs);
461 struct page* (*get_xip_page)(struct address_space *, sector_t,
462 int);
463};
464
465 writepage: called by the VM write a dirty page to backing store.
466
467 readpage: called by the VM to read a page from backing store.
468
469 sync_page: called by the VM to notify the backing store to perform all
470 queued I/O operations for a page. I/O operations for other pages
471 associated with this address_space object may also be performed.
472
473 writepages: called by the VM to write out pages associated with the
474 address_space object.
475
476 set_page_dirty: called by the VM to set a page dirty.
477
478 readpages: called by the VM to read pages associated with the address_space
479 object.
333 480
481 prepare_write: called by the generic write path in VM to set up a write
482 request for a page.
334 483
335struct file_operations <section> 484 commit_write: called by the generic write path in VM to write page to
485 its backing store.
486
487 bmap: called by the VFS to map a logical block offset within object to
488 physical block number. This method is use by for the legacy FIBMAP
489 ioctl. Other uses are discouraged.
490
491 invalidatepage: called by the VM on truncate to disassociate a page from its
492 address_space mapping.
493
494 releasepage: called by the VFS to release filesystem specific metadata from
495 a page.
496
497 direct_IO: called by the VM for direct I/O writes and reads.
498
499 get_xip_page: called by the VM to translate a block number to a page.
500 The page is valid until the corresponding filesystem is unmounted.
501 Filesystems that want to use execute-in-place (XIP) need to implement
502 it. An example implementation can be found in fs/ext2/xip.c.
503
504
505struct file_operations
336====================== 506======================
337 507
338This describes how the VFS can manipulate an open file. As of kernel 508This describes how the VFS can manipulate an open file. As of kernel
3392.1.99, the following members are defined: 5092.6.13, the following members are defined:
340 510
341struct file_operations { 511struct file_operations {
342 loff_t (*llseek) (struct file *, loff_t, int); 512 loff_t (*llseek) (struct file *, loff_t, int);
343 ssize_t (*read) (struct file *, char *, size_t, loff_t *); 513 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
344 ssize_t (*write) (struct file *, const char *, size_t, loff_t *); 514 ssize_t (*aio_read) (struct kiocb *, char __user *, size_t, loff_t);
515 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
516 ssize_t (*aio_write) (struct kiocb *, const char __user *, size_t, loff_t);
345 int (*readdir) (struct file *, void *, filldir_t); 517 int (*readdir) (struct file *, void *, filldir_t);
346 unsigned int (*poll) (struct file *, struct poll_table_struct *); 518 unsigned int (*poll) (struct file *, struct poll_table_struct *);
347 int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long); 519 int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
520 long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
521 long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
348 int (*mmap) (struct file *, struct vm_area_struct *); 522 int (*mmap) (struct file *, struct vm_area_struct *);
349 int (*open) (struct inode *, struct file *); 523 int (*open) (struct inode *, struct file *);
524 int (*flush) (struct file *);
350 int (*release) (struct inode *, struct file *); 525 int (*release) (struct inode *, struct file *);
351 int (*fsync) (struct file *, struct dentry *); 526 int (*fsync) (struct file *, struct dentry *, int datasync);
352 int (*fasync) (struct file *, int); 527 int (*aio_fsync) (struct kiocb *, int datasync);
353 int (*check_media_change) (kdev_t dev); 528 int (*fasync) (int, struct file *, int);
354 int (*revalidate) (kdev_t dev);
355 int (*lock) (struct file *, int, struct file_lock *); 529 int (*lock) (struct file *, int, struct file_lock *);
530 ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
531 ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
532 ssize_t (*sendfile) (struct file *, loff_t *, size_t, read_actor_t, void *);
533 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
534 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
535 int (*check_flags)(int);
536 int (*dir_notify)(struct file *filp, unsigned long arg);
537 int (*flock) (struct file *, int, struct file_lock *);
356}; 538};
357 539
358Again, all methods are called without any locks being held, unless 540Again, all methods are called without any locks being held, unless
@@ -362,8 +544,12 @@ otherwise noted.
362 544
363 read: called by read(2) and related system calls 545 read: called by read(2) and related system calls
364 546
547 aio_read: called by io_submit(2) and other asynchronous I/O operations
548
365 write: called by write(2) and related system calls 549 write: called by write(2) and related system calls
366 550
551 aio_write: called by io_submit(2) and other asynchronous I/O operations
552
367 readdir: called when the VFS needs to read the directory contents 553 readdir: called when the VFS needs to read the directory contents
368 554
369 poll: called by the VFS when a process wants to check if there is 555 poll: called by the VFS when a process wants to check if there is
@@ -372,18 +558,25 @@ otherwise noted.
372 558
373 ioctl: called by the ioctl(2) system call 559 ioctl: called by the ioctl(2) system call
374 560
561 unlocked_ioctl: called by the ioctl(2) system call. Filesystems that do not
562 require the BKL should use this method instead of the ioctl() above.
563
564 compat_ioctl: called by the ioctl(2) system call when 32 bit system calls
565 are used on 64 bit kernels.
566
375 mmap: called by the mmap(2) system call 567 mmap: called by the mmap(2) system call
376 568
377 open: called by the VFS when an inode should be opened. When the VFS 569 open: called by the VFS when an inode should be opened. When the VFS
378 opens a file, it creates a new "struct file" and initialises 570 opens a file, it creates a new "struct file". It then calls the
379 the "f_op" file operations member with the "default_file_ops" 571 open method for the newly allocated file structure. You might
380 field in the inode structure. It then calls the open method 572 think that the open method really belongs in
381 for the newly allocated file structure. You might think that 573 "struct inode_operations", and you may be right. I think it's
382 the open method really belongs in "struct inode_operations", 574 done the way it is because it makes filesystems simpler to
383 and you may be right. I think it's done the way it is because 575 implement. The open() method is a good place to initialize the
384 it makes filesystems simpler to implement. The open() method 576 "private_data" member in the file structure if you want to point
385 is a good place to initialise the "private_data" member in the 577 to a device structure
386 file structure if you want to point to a device structure 578
579 flush: called by the close(2) system call to flush a file
387 580
388 release: called when the last reference to an open file is closed 581 release: called when the last reference to an open file is closed
389 582
@@ -392,6 +585,23 @@ otherwise noted.
392 fasync: called by the fcntl(2) system call when asynchronous 585 fasync: called by the fcntl(2) system call when asynchronous
393 (non-blocking) mode is enabled for a file 586 (non-blocking) mode is enabled for a file
394 587
588 lock: called by the fcntl(2) system call for F_GETLK, F_SETLK, and F_SETLKW
589 commands
590
591 readv: called by the readv(2) system call
592
593 writev: called by the writev(2) system call
594
595 sendfile: called by the sendfile(2) system call
596
597 get_unmapped_area: called by the mmap(2) system call
598
599 check_flags: called by the fcntl(2) system call for F_SETFL command
600
601 dir_notify: called by the fcntl(2) system call for F_NOTIFY command
602
603 flock: called by the flock(2) system call
604
395Note that the file operations are implemented by the specific 605Note that the file operations are implemented by the specific
396filesystem in which the inode resides. When opening a device node 606filesystem in which the inode resides. When opening a device node
397(character or block special) most filesystems will call special 607(character or block special) most filesystems will call special
@@ -400,29 +610,28 @@ driver information. These support routines replace the filesystem file
400operations with those for the device driver, and then proceed to call 610operations with those for the device driver, and then proceed to call
401the new open() method for the file. This is how opening a device file 611the new open() method for the file. This is how opening a device file
402in the filesystem eventually ends up calling the device driver open() 612in the filesystem eventually ends up calling the device driver open()
403method. Note the devfs (the Device FileSystem) has a more direct path 613method.
404from device node to device driver (this is an unofficial kernel
405patch).
406 614
407 615
408Directory Entry Cache (dcache) <section> 616Directory Entry Cache (dcache)
409------------------------------ 617==============================
618
410 619
411struct dentry_operations 620struct dentry_operations
412======================== 621------------------------
413 622
414This describes how a filesystem can overload the standard dentry 623This describes how a filesystem can overload the standard dentry
415operations. Dentries and the dcache are the domain of the VFS and the 624operations. Dentries and the dcache are the domain of the VFS and the
416individual filesystem implementations. Device drivers have no business 625individual filesystem implementations. Device drivers have no business
417here. These methods may be set to NULL, as they are either optional or 626here. These methods may be set to NULL, as they are either optional or
418the VFS uses a default. As of kernel 2.1.99, the following members are 627the VFS uses a default. As of kernel 2.6.13, the following members are
419defined: 628defined:
420 629
421struct dentry_operations { 630struct dentry_operations {
422 int (*d_revalidate)(struct dentry *); 631 int (*d_revalidate)(struct dentry *, struct nameidata *);
423 int (*d_hash) (struct dentry *, struct qstr *); 632 int (*d_hash) (struct dentry *, struct qstr *);
424 int (*d_compare) (struct dentry *, struct qstr *, struct qstr *); 633 int (*d_compare) (struct dentry *, struct qstr *, struct qstr *);
425 void (*d_delete)(struct dentry *); 634 int (*d_delete)(struct dentry *);
426 void (*d_release)(struct dentry *); 635 void (*d_release)(struct dentry *);
427 void (*d_iput)(struct dentry *, struct inode *); 636 void (*d_iput)(struct dentry *, struct inode *);
428}; 637};
@@ -451,6 +660,7 @@ Each dentry has a pointer to its parent dentry, as well as a hash list
451of child dentries. Child dentries are basically like files in a 660of child dentries. Child dentries are basically like files in a
452directory. 661directory.
453 662
663
454Directory Entry Cache APIs 664Directory Entry Cache APIs
455-------------------------- 665--------------------------
456 666
@@ -471,7 +681,7 @@ manipulate dentries:
471 "d_delete" method is called 681 "d_delete" method is called
472 682
473 d_drop: this unhashes a dentry from its parents hash list. A 683 d_drop: this unhashes a dentry from its parents hash list. A
474 subsequent call to dput() will dellocate the dentry if its 684 subsequent call to dput() will deallocate the dentry if its
475 usage count drops to 0 685 usage count drops to 0
476 686
477 d_delete: delete a dentry. If there are no other open references to 687 d_delete: delete a dentry. If there are no other open references to
@@ -507,16 +717,16 @@ up by walking the tree starting with the first component
507of the pathname and using that dentry along with the next 717of the pathname and using that dentry along with the next
508component to look up the next level and so on. Since it 718component to look up the next level and so on. Since it
509is a frequent operation for workloads like multiuser 719is a frequent operation for workloads like multiuser
510environments and webservers, it is important to optimize 720environments and web servers, it is important to optimize
511this path. 721this path.
512 722
513Prior to 2.5.10, dcache_lock was acquired in d_lookup and thus 723Prior to 2.5.10, dcache_lock was acquired in d_lookup and thus
514in every component during path look-up. Since 2.5.10 onwards, 724in every component during path look-up. Since 2.5.10 onwards,
515fastwalk algorithm changed this by holding the dcache_lock 725fast-walk algorithm changed this by holding the dcache_lock
516at the beginning and walking as many cached path component 726at the beginning and walking as many cached path component
517dentries as possible. This signficantly decreases the number 727dentries as possible. This significantly decreases the number
518of acquisition of dcache_lock. However it also increases the 728of acquisition of dcache_lock. However it also increases the
519lock hold time signficantly and affects performance in large 729lock hold time significantly and affects performance in large
520SMP machines. Since 2.5.62 kernel, dcache has been using 730SMP machines. Since 2.5.62 kernel, dcache has been using
521a new locking model that uses RCU to make dcache look-up 731a new locking model that uses RCU to make dcache look-up
522lock-free. 732lock-free.
@@ -527,7 +737,7 @@ protected the hash chain, d_child, d_alias, d_lru lists as well
527as d_inode and several other things like mount look-up. RCU-based 737as d_inode and several other things like mount look-up. RCU-based
528changes affect only the way the hash chain is protected. For everything 738changes affect only the way the hash chain is protected. For everything
529else the dcache_lock must be taken for both traversing as well as 739else the dcache_lock must be taken for both traversing as well as
530updating. The hash chain updations too take the dcache_lock. 740updating. The hash chain updates too take the dcache_lock.
531The significant change is the way d_lookup traverses the hash chain, 741The significant change is the way d_lookup traverses the hash chain,
532it doesn't acquire the dcache_lock for this and rely on RCU to 742it doesn't acquire the dcache_lock for this and rely on RCU to
533ensure that the dentry has not been *freed*. 743ensure that the dentry has not been *freed*.
@@ -535,14 +745,15 @@ ensure that the dentry has not been *freed*.
535 745
536Dcache locking details 746Dcache locking details
537---------------------- 747----------------------
748
538For many multi-user workloads, open() and stat() on files are 749For many multi-user workloads, open() and stat() on files are
539very frequently occurring operations. Both involve walking 750very frequently occurring operations. Both involve walking
540of path names to find the dentry corresponding to the 751of path names to find the dentry corresponding to the
541concerned file. In 2.4 kernel, dcache_lock was held 752concerned file. In 2.4 kernel, dcache_lock was held
542during look-up of each path component. Contention and 753during look-up of each path component. Contention and
543cacheline bouncing of this global lock caused significant 754cache-line bouncing of this global lock caused significant
544scalability problems. With the introduction of RCU 755scalability problems. With the introduction of RCU
545in linux kernel, this was worked around by making 756in Linux kernel, this was worked around by making
546the look-up of path components during path walking lock-free. 757the look-up of path components during path walking lock-free.
547 758
548 759
@@ -562,7 +773,7 @@ Some of the important changes are :
5622. Insertion of a dentry into the hash table is done using 7732. Insertion of a dentry into the hash table is done using
563 hlist_add_head_rcu() which take care of ordering the writes - 774 hlist_add_head_rcu() which take care of ordering the writes -
564 the writes to the dentry must be visible before the dentry 775 the writes to the dentry must be visible before the dentry
565 is inserted. This works in conjuction with hlist_for_each_rcu() 776 is inserted. This works in conjunction with hlist_for_each_rcu()
566 while walking the hash chain. The only requirement is that 777 while walking the hash chain. The only requirement is that
567 all initialization to the dentry must be done before hlist_add_head_rcu() 778 all initialization to the dentry must be done before hlist_add_head_rcu()
568 since we don't have dcache_lock protection while traversing 779 since we don't have dcache_lock protection while traversing
@@ -584,7 +795,7 @@ Some of the important changes are :
584 the same. In some sense, dcache_rcu path walking looks like 795 the same. In some sense, dcache_rcu path walking looks like
585 the pre-2.5.10 version. 796 the pre-2.5.10 version.
586 797
5875. All dentry hash chain updations must take the dcache_lock as well as 7985. All dentry hash chain updates must take the dcache_lock as well as
588 the per-dentry lock in that order. dput() does this to ensure 799 the per-dentry lock in that order. dput() does this to ensure
589 that a dentry that has just been looked up in another CPU 800 that a dentry that has just been looked up in another CPU
590 doesn't get deleted before dget() can be done on it. 801 doesn't get deleted before dget() can be done on it.
@@ -640,10 +851,10 @@ handled as described below :
640 Since we redo the d_parent check and compare name while holding 851 Since we redo the d_parent check and compare name while holding
641 d_lock, lock-free look-up will not race against d_move(). 852 d_lock, lock-free look-up will not race against d_move().
642 853
6434. There can be a theoritical race when a dentry keeps coming back 8544. There can be a theoretical race when a dentry keeps coming back
644 to original bucket due to double moves. Due to this look-up may 855 to original bucket due to double moves. Due to this look-up may
645 consider that it has never moved and can end up in a infinite loop. 856 consider that it has never moved and can end up in a infinite loop.
646 But this is not any worse that theoritical livelocks we already 857 But this is not any worse that theoretical livelocks we already
647 have in the kernel. 858 have in the kernel.
648 859
649 860
diff --git a/Documentation/ioctl/cdrom.txt b/Documentation/ioctl/cdrom.txt
index 4ccdcc6fe3..8ec32cc49e 100644
--- a/Documentation/ioctl/cdrom.txt
+++ b/Documentation/ioctl/cdrom.txt
@@ -878,7 +878,7 @@ DVD_READ_STRUCT Read structure
878 878
879 error returns: 879 error returns:
880 EINVAL physical.layer_num exceeds number of layers 880 EINVAL physical.layer_num exceeds number of layers
881 EIO Recieved invalid response from drive 881 EIO Received invalid response from drive
882 882
883 883
884 884
diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
index 9a1586590d..d802ce88be 100644
--- a/Documentation/kbuild/makefiles.txt
+++ b/Documentation/kbuild/makefiles.txt
@@ -31,7 +31,7 @@ This document describes the Linux kernel Makefiles.
31 31
32 === 6 Architecture Makefiles 32 === 6 Architecture Makefiles
33 --- 6.1 Set variables to tweak the build to the architecture 33 --- 6.1 Set variables to tweak the build to the architecture
34 --- 6.2 Add prerequisites to prepare: 34 --- 6.2 Add prerequisites to archprepare:
35 --- 6.3 List directories to visit when descending 35 --- 6.3 List directories to visit when descending
36 --- 6.4 Architecture specific boot images 36 --- 6.4 Architecture specific boot images
37 --- 6.5 Building non-kbuild targets 37 --- 6.5 Building non-kbuild targets
@@ -734,18 +734,18 @@ When kbuild executes the following steps are followed (roughly):
734 for loadable kernel modules. 734 for loadable kernel modules.
735 735
736 736
737--- 6.2 Add prerequisites to prepare: 737--- 6.2 Add prerequisites to archprepare:
738 738
739 The prepare: rule is used to list prerequisites that needs to be 739 The archprepare: rule is used to list prerequisites that needs to be
740 built before starting to descend down in the subdirectories. 740 built before starting to descend down in the subdirectories.
741 This is usual header files containing assembler constants. 741 This is usual header files containing assembler constants.
742 742
743 Example: 743 Example:
744 #arch/s390/Makefile 744 #arch/arm/Makefile
745 prepare: include/asm-$(ARCH)/offsets.h 745 archprepare: maketools
746 746
747 In this example the file include/asm-$(ARCH)/offsets.h will 747 In this example the file target maketools will be processed
748 be built before descending down in the subdirectories. 748 before descending down in the subdirectories.
749 See also chapter XXX-TODO that describe how kbuild supports 749 See also chapter XXX-TODO that describe how kbuild supports
750 generating offset header files. 750 generating offset header files.
751 751
diff --git a/Documentation/kdump/kdump.txt b/Documentation/kdump/kdump.txt
index 7ff213f4be..1f5f7d28c9 100644
--- a/Documentation/kdump/kdump.txt
+++ b/Documentation/kdump/kdump.txt
@@ -39,8 +39,7 @@ SETUP
39 and apply http://lse.sourceforge.net/kdump/patches/kexec-tools-1.101-kdump.patch 39 and apply http://lse.sourceforge.net/kdump/patches/kexec-tools-1.101-kdump.patch
40 and after that build the source. 40 and after that build the source.
41 41
422) Download and build the appropriate (latest) kexec/kdump (-mm) kernel 422) Download and build the appropriate (2.6.13-rc1 onwards) vanilla kernel.
43 patchset and apply it to the vanilla kernel tree.
44 43
45 Two kernels need to be built in order to get this feature working. 44 Two kernels need to be built in order to get this feature working.
46 45
@@ -84,15 +83,16 @@ SETUP
84 83
854) Load the second kernel to be booted using: 844) Load the second kernel to be booted using:
86 85
87 kexec -p <second-kernel> --crash-dump --args-linux --append="root=<root-dev> 86 kexec -p <second-kernel> --args-linux --elf32-core-headers
88 init 1 irqpoll" 87 --append="root=<root-dev> init 1 irqpoll"
89 88
90 Note: i) <second-kernel> has to be a vmlinux image. bzImage will not work, 89 Note: i) <second-kernel> has to be a vmlinux image. bzImage will not work,
91 as of now. 90 as of now.
92 ii) By default ELF headers are stored in ELF32 format (for i386). This 91 ii) By default ELF headers are stored in ELF64 format. Option
93 is sufficient to represent the physical memory up to 4GB. To store 92 --elf32-core-headers forces generation of ELF32 headers. gdb can
94 headers in ELF64 format, specifiy "--elf64-core-headers" on the 93 not open ELF64 headers on 32 bit systems. So creating ELF32
95 kexec command line additionally. 94 headers can come handy for users who have got non-PAE systems and
95 hence have memory less than 4GB.
96 iii) Specify "irqpoll" as command line parameter. This reduces driver 96 iii) Specify "irqpoll" as command line parameter. This reduces driver
97 initialization failures in second kernel due to shared interrupts. 97 initialization failures in second kernel due to shared interrupts.
98 98
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index d2f0c67ba1..7086f0a90d 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -164,6 +164,15 @@ running once the system is up.
164 over-ride platform specific driver. 164 over-ride platform specific driver.
165 See also Documentation/acpi-hotkey.txt. 165 See also Documentation/acpi-hotkey.txt.
166 166
167 enable_timer_pin_1 [i386,x86-64]
168 Enable PIN 1 of APIC timer
169 Can be useful to work around chipset bugs (in particular on some ATI chipsets)
170 The kernel tries to set a reasonable default.
171
172 disable_timer_pin_1 [i386,x86-64]
173 Disable PIN 1 of APIC timer
174 Can be useful to work around chipset bugs.
175
167 ad1816= [HW,OSS] 176 ad1816= [HW,OSS]
168 Format: <io>,<irq>,<dma>,<dma2> 177 Format: <io>,<irq>,<dma>,<dma2>
169 See also Documentation/sound/oss/AD1816. 178 See also Documentation/sound/oss/AD1816.
@@ -549,6 +558,7 @@ running once the system is up.
549 keyboard and can not control its state 558 keyboard and can not control its state
550 (Don't attempt to blink the leds) 559 (Don't attempt to blink the leds)
551 i8042.noaux [HW] Don't check for auxiliary (== mouse) port 560 i8042.noaux [HW] Don't check for auxiliary (== mouse) port
561 i8042.nokbd [HW] Don't check/create keyboard port
552 i8042.nomux [HW] Don't check presence of an active multiplexing 562 i8042.nomux [HW] Don't check presence of an active multiplexing
553 controller 563 controller
554 i8042.nopnp [HW] Don't use ACPIPnP / PnPBIOS to discover KBD/AUX 564 i8042.nopnp [HW] Don't use ACPIPnP / PnPBIOS to discover KBD/AUX
diff --git a/Documentation/mono.txt b/Documentation/mono.txt
index 6739ab9615..807a0c7b47 100644
--- a/Documentation/mono.txt
+++ b/Documentation/mono.txt
@@ -30,7 +30,7 @@ other program after you have done the following:
30 Read the file 'binfmt_misc.txt' in this directory to know 30 Read the file 'binfmt_misc.txt' in this directory to know
31 more about the configuration process. 31 more about the configuration process.
32 32
333) Add the following enries to /etc/rc.local or similar script 333) Add the following entries to /etc/rc.local or similar script
34 to be run at system startup: 34 to be run at system startup:
35 35
36# Insert BINFMT_MISC module into the kernel 36# Insert BINFMT_MISC module into the kernel
diff --git a/Documentation/networking/bonding.txt b/Documentation/networking/bonding.txt
index 24d029455b..a55f0f95b1 100644
--- a/Documentation/networking/bonding.txt
+++ b/Documentation/networking/bonding.txt
@@ -1241,7 +1241,7 @@ traffic while still maintaining carrier on.
1241 1241
1242 If running SNMP agents, the bonding driver should be loaded 1242 If running SNMP agents, the bonding driver should be loaded
1243before any network drivers participating in a bond. This requirement 1243before any network drivers participating in a bond. This requirement
1244is due to the the interface index (ipAdEntIfIndex) being associated to 1244is due to the interface index (ipAdEntIfIndex) being associated to
1245the first interface found with a given IP address. That is, there is 1245the first interface found with a given IP address. That is, there is
1246only one ipAdEntIfIndex for each IP address. For example, if eth0 and 1246only one ipAdEntIfIndex for each IP address. For example, if eth0 and
1247eth1 are slaves of bond0 and the driver for eth0 is loaded before the 1247eth1 are slaves of bond0 and the driver for eth0 is loaded before the
@@ -1937,7 +1937,7 @@ switches currently available support 802.3ad.
1937 If not explicitly configured (with ifconfig or ip link), the 1937 If not explicitly configured (with ifconfig or ip link), the
1938MAC address of the bonding device is taken from its first slave 1938MAC address of the bonding device is taken from its first slave
1939device. This MAC address is then passed to all following slaves and 1939device. This MAC address is then passed to all following slaves and
1940remains persistent (even if the the first slave is removed) until the 1940remains persistent (even if the first slave is removed) until the
1941bonding device is brought down or reconfigured. 1941bonding device is brought down or reconfigured.
1942 1942
1943 If you wish to change the MAC address, you can set it with 1943 If you wish to change the MAC address, you can set it with
diff --git a/Documentation/networking/wan-router.txt b/Documentation/networking/wan-router.txt
index aea20cd2a5..c96897aa08 100644
--- a/Documentation/networking/wan-router.txt
+++ b/Documentation/networking/wan-router.txt
@@ -355,7 +355,7 @@ REVISION HISTORY
355 There is no functional difference between the two packages 355 There is no functional difference between the two packages
356 356
3572.0.7 Aug 26, 1999 o Merged X25API code into WANPIPE. 3572.0.7 Aug 26, 1999 o Merged X25API code into WANPIPE.
358 o Fixed a memeory leak for X25API 358 o Fixed a memory leak for X25API
359 o Updated the X25API code for 2.2.X kernels. 359 o Updated the X25API code for 2.2.X kernels.
360 o Improved NEM handling. 360 o Improved NEM handling.
361 361
@@ -514,7 +514,7 @@ beta2-2.2.0 Jan 8 2001
514 o Patches for 2.4.0 kernel 514 o Patches for 2.4.0 kernel
515 o Patches for 2.2.18 kernel 515 o Patches for 2.2.18 kernel
516 o Minor updates to PPP and CHLDC drivers. 516 o Minor updates to PPP and CHLDC drivers.
517 Note: No functinal difference. 517 Note: No functional difference.
518 518
519beta3-2.2.9 Jan 10 2001 519beta3-2.2.9 Jan 10 2001
520 o I missed the 2.2.18 kernel patches in beta2-2.2.0 520 o I missed the 2.2.18 kernel patches in beta2-2.2.0
diff --git a/Documentation/pci.txt b/Documentation/pci.txt
index 76d28d0336..711210b38f 100644
--- a/Documentation/pci.txt
+++ b/Documentation/pci.txt
@@ -84,7 +84,7 @@ Each entry consists of:
84 84
85Most drivers don't need to use the driver_data field. Best practice 85Most drivers don't need to use the driver_data field. Best practice
86for use of driver_data is to use it as an index into a static list of 86for use of driver_data is to use it as an index into a static list of
87equivalant device types, not to use it as a pointer. 87equivalent device types, not to use it as a pointer.
88 88
89Have a table entry {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID} 89Have a table entry {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID}
90to have probe() called for every PCI device known to the system. 90to have probe() called for every PCI device known to the system.
diff --git a/Documentation/powerpc/eeh-pci-error-recovery.txt b/Documentation/powerpc/eeh-pci-error-recovery.txt
index 2bfe71beec..e75d747432 100644
--- a/Documentation/powerpc/eeh-pci-error-recovery.txt
+++ b/Documentation/powerpc/eeh-pci-error-recovery.txt
@@ -134,7 +134,7 @@ pci_get_device_by_addr() will find the pci device associated
134with that address (if any). 134with that address (if any).
135 135
136The default include/asm-ppc64/io.h macros readb(), inb(), insb(), 136The default include/asm-ppc64/io.h macros readb(), inb(), insb(),
137etc. include a check to see if the the i/o read returned all-0xff's. 137etc. include a check to see if the i/o read returned all-0xff's.
138If so, these make a call to eeh_dn_check_failure(), which in turn 138If so, these make a call to eeh_dn_check_failure(), which in turn
139asks the firmware if the all-ff's value is the sign of a true EEH 139asks the firmware if the all-ff's value is the sign of a true EEH
140error. If it is not, processing continues as normal. The grand 140error. If it is not, processing continues as normal. The grand
diff --git a/Documentation/s390/s390dbf.txt b/Documentation/s390/s390dbf.txt
index e24fdeada9..e321a8ed2a 100644
--- a/Documentation/s390/s390dbf.txt
+++ b/Documentation/s390/s390dbf.txt
@@ -468,7 +468,7 @@ The hex_ascii view shows the data field in hex and ascii representation
468The raw view returns a bytestream as the debug areas are stored in memory. 468The raw view returns a bytestream as the debug areas are stored in memory.
469 469
470The sprintf view formats the debug entries in the same way as the sprintf 470The sprintf view formats the debug entries in the same way as the sprintf
471function would do. The sprintf event/expection fuctions write to the 471function would do. The sprintf event/expection functions write to the
472debug entry a pointer to the format string (size = sizeof(long)) 472debug entry a pointer to the format string (size = sizeof(long))
473and for each vararg a long value. So e.g. for a debug entry with a format 473and for each vararg a long value. So e.g. for a debug entry with a format
474string plus two varargs one would need to allocate a (3 * sizeof(long)) 474string plus two varargs one would need to allocate a (3 * sizeof(long))
diff --git a/Documentation/scsi/ibmmca.txt b/Documentation/scsi/ibmmca.txt
index 2814491600..2ffb3ae0ef 100644
--- a/Documentation/scsi/ibmmca.txt
+++ b/Documentation/scsi/ibmmca.txt
@@ -344,7 +344,7 @@
344 /proc/scsi/ibmmca/<host_no>. ibmmca_proc_info() provides this information. 344 /proc/scsi/ibmmca/<host_no>. ibmmca_proc_info() provides this information.
345 345
346 This table is quite informative for interested users. It shows the load 346 This table is quite informative for interested users. It shows the load
347 of commands on the subsystem and wether you are running the bypassed 347 of commands on the subsystem and whether you are running the bypassed
348 (software) or integrated (hardware) SCSI-command set (see below). The 348 (software) or integrated (hardware) SCSI-command set (see below). The
349 amount of accesses is shown. Read, write, modeselect is shown separately 349 amount of accesses is shown. Read, write, modeselect is shown separately
350 in order to help debugging problems with CD-ROMs or tapedrives. 350 in order to help debugging problems with CD-ROMs or tapedrives.
diff --git a/Documentation/sound/alsa/ALSA-Configuration.txt b/Documentation/sound/alsa/ALSA-Configuration.txt
index 5c49ba07e7..ebfcdf2848 100644
--- a/Documentation/sound/alsa/ALSA-Configuration.txt
+++ b/Documentation/sound/alsa/ALSA-Configuration.txt
@@ -1459,7 +1459,7 @@ devices where %i is sound card number from zero to seven.
1459To auto-load an ALSA driver for OSS services, define the string 1459To auto-load an ALSA driver for OSS services, define the string
1460'sound-slot-%i' where %i means the slot number for OSS, which 1460'sound-slot-%i' where %i means the slot number for OSS, which
1461corresponds to the card index of ALSA. Usually, define this 1461corresponds to the card index of ALSA. Usually, define this
1462as the the same card module. 1462as the same card module.
1463 1463
1464An example configuration for a single emu10k1 card is like below: 1464An example configuration for a single emu10k1 card is like below:
1465----- /etc/modprobe.conf 1465----- /etc/modprobe.conf
diff --git a/Documentation/sparse.txt b/Documentation/sparse.txt
index f978414784..5df44dc894 100644
--- a/Documentation/sparse.txt
+++ b/Documentation/sparse.txt
@@ -57,7 +57,7 @@ With BK, you can just get it from
57 57
58and DaveJ has tar-balls at 58and DaveJ has tar-balls at
59 59
60 http://www.codemonkey.org.uk/projects/bitkeeper/sparse/ 60 http://www.codemonkey.org.uk/projects/git-snapshots/sparse/
61 61
62 62
63Once you have it, just do 63Once you have it, just do
diff --git a/Documentation/sysrq.txt b/Documentation/sysrq.txt
index 136d817c01..baf17b3815 100644
--- a/Documentation/sysrq.txt
+++ b/Documentation/sysrq.txt
@@ -171,7 +171,7 @@ the header 'include/linux/sysrq.h', this will define everything else you need.
171Next, you must create a sysrq_key_op struct, and populate it with A) the key 171Next, you must create a sysrq_key_op struct, and populate it with A) the key
172handler function you will use, B) a help_msg string, that will print when SysRQ 172handler function you will use, B) a help_msg string, that will print when SysRQ
173prints help, and C) an action_msg string, that will print right before your 173prints help, and C) an action_msg string, that will print right before your
174handler is called. Your handler must conform to the protoype in 'sysrq.h'. 174handler is called. Your handler must conform to the prototype in 'sysrq.h'.
175 175
176After the sysrq_key_op is created, you can call the macro 176After the sysrq_key_op is created, you can call the macro
177register_sysrq_key(int key, struct sysrq_key_op *op_p) that is defined in 177register_sysrq_key(int key, struct sysrq_key_op *op_p) that is defined in
diff --git a/Documentation/uml/UserModeLinux-HOWTO.txt b/Documentation/uml/UserModeLinux-HOWTO.txt
index 0c7b654fec..544430e399 100644
--- a/Documentation/uml/UserModeLinux-HOWTO.txt
+++ b/Documentation/uml/UserModeLinux-HOWTO.txt
@@ -2176,7 +2176,7 @@
2176 If you want to access files on the host machine from inside UML, you 2176 If you want to access files on the host machine from inside UML, you
2177 can treat it as a separate machine and either nfs mount directories 2177 can treat it as a separate machine and either nfs mount directories
2178 from the host or copy files into the virtual machine with scp or rcp. 2178 from the host or copy files into the virtual machine with scp or rcp.
2179 However, since UML is running on the the host, it can access those 2179 However, since UML is running on the host, it can access those
2180 files just like any other process and make them available inside the 2180 files just like any other process and make them available inside the
2181 virtual machine without needing to use the network. 2181 virtual machine without needing to use the network.
2182 2182
diff --git a/Documentation/usb/gadget_serial.txt b/Documentation/usb/gadget_serial.txt
index a938c3dd13..815f5c2301 100644
--- a/Documentation/usb/gadget_serial.txt
+++ b/Documentation/usb/gadget_serial.txt
@@ -20,7 +20,7 @@ License along with this program; if not, write to the Free
20Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 20Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21MA 02111-1307 USA. 21MA 02111-1307 USA.
22 22
23This document and the the gadget serial driver itself are 23This document and the gadget serial driver itself are
24Copyright (C) 2004 by Al Borchers (alborchers@steinerpoint.com). 24Copyright (C) 2004 by Al Borchers (alborchers@steinerpoint.com).
25 25
26If you have questions, problems, or suggestions for this driver 26If you have questions, problems, or suggestions for this driver
diff --git a/Documentation/video4linux/CARDLIST.bttv b/Documentation/video4linux/CARDLIST.bttv
index 62a12a08e2..ec785f9f15 100644
--- a/Documentation/video4linux/CARDLIST.bttv
+++ b/Documentation/video4linux/CARDLIST.bttv
@@ -126,10 +126,12 @@ card=124 - AverMedia AverTV DVB-T 761
126card=125 - MATRIX Vision Sigma-SQ 126card=125 - MATRIX Vision Sigma-SQ
127card=126 - MATRIX Vision Sigma-SLC 127card=126 - MATRIX Vision Sigma-SLC
128card=127 - APAC Viewcomp 878(AMAX) 128card=127 - APAC Viewcomp 878(AMAX)
129card=128 - DVICO FusionHDTV DVB-T Lite 129card=128 - DViCO FusionHDTV DVB-T Lite
130card=129 - V-Gear MyVCD 130card=129 - V-Gear MyVCD
131card=130 - Super TV Tuner 131card=130 - Super TV Tuner
132card=131 - Tibet Systems 'Progress DVR' CS16 132card=131 - Tibet Systems 'Progress DVR' CS16
133card=132 - Kodicom 4400R (master) 133card=132 - Kodicom 4400R (master)
134card=133 - Kodicom 4400R (slave) 134card=133 - Kodicom 4400R (slave)
135card=134 - Adlink RTV24 135card=134 - Adlink RTV24
136card=135 - DViCO FusionHDTV 5 Lite
137card=136 - Acorp Y878F
diff --git a/Documentation/video4linux/CARDLIST.saa7134 b/Documentation/video4linux/CARDLIST.saa7134
index 1b5a3a9ffb..dc57225f39 100644
--- a/Documentation/video4linux/CARDLIST.saa7134
+++ b/Documentation/video4linux/CARDLIST.saa7134
@@ -62,3 +62,6 @@
62 61 -> Philips TOUGH DVB-T reference design [1131:2004] 62 61 -> Philips TOUGH DVB-T reference design [1131:2004]
63 62 -> Compro VideoMate TV Gold+II 63 62 -> Compro VideoMate TV Gold+II
64 63 -> Kworld Xpert TV PVR7134 64 63 -> Kworld Xpert TV PVR7134
65 64 -> FlyTV mini Asus Digimatrix [1043:0210,1043:0210]
66 65 -> V-Stream Studio TV Terminator
67 66 -> Yuan TUN-900 (saa7135)
diff --git a/Documentation/video4linux/CARDLIST.tuner b/Documentation/video4linux/CARDLIST.tuner
index f3302e1b1b..f5876be658 100644
--- a/Documentation/video4linux/CARDLIST.tuner
+++ b/Documentation/video4linux/CARDLIST.tuner
@@ -64,3 +64,4 @@ tuner=62 - Philips TEA5767HN FM Radio
64tuner=63 - Philips FMD1216ME MK3 Hybrid Tuner 64tuner=63 - Philips FMD1216ME MK3 Hybrid Tuner
65tuner=64 - LG TDVS-H062F/TUA6034 65tuner=64 - LG TDVS-H062F/TUA6034
66tuner=65 - Ymec TVF66T5-B/DFF 66tuner=65 - Ymec TVF66T5-B/DFF
67tuner=66 - LG NTSC (TALN mini series)
diff --git a/Documentation/video4linux/Zoran b/Documentation/video4linux/Zoran
index 01425c2198..52c94bd7dc 100644
--- a/Documentation/video4linux/Zoran
+++ b/Documentation/video4linux/Zoran
@@ -222,7 +222,7 @@ was introduced in 1991, is used in the DC10 old
222can generate: PAL , NTSC , SECAM 222can generate: PAL , NTSC , SECAM
223 223
224The adv717x, should be able to produce PAL N. But you find nothing PAL N 224The adv717x, should be able to produce PAL N. But you find nothing PAL N
225specific in the the registers. Seem that you have to reuse a other standard 225specific in the registers. Seem that you have to reuse a other standard
226to generate PAL N, maybe it would work if you use the PAL M settings. 226to generate PAL N, maybe it would work if you use the PAL M settings.
227 227
228========================== 228==========================
diff --git a/Documentation/x86_64/boot-options.txt b/Documentation/x86_64/boot-options.txt
index 678e8f192d..ffe1c06208 100644
--- a/Documentation/x86_64/boot-options.txt
+++ b/Documentation/x86_64/boot-options.txt
@@ -11,6 +11,11 @@ Machine check
11 If your BIOS doesn't do that it's a good idea to enable though 11 If your BIOS doesn't do that it's a good idea to enable though
12 to make sure you log even machine check events that result 12 to make sure you log even machine check events that result
13 in a reboot. 13 in a reboot.
14 mce=tolerancelevel (number)
15 0: always panic, 1: panic if deadlock possible,
16 2: try to avoid panic, 3: never panic or exit (for testing)
17 default is 1
18 Can be also set using sysfs which is preferable.
14 19
15 nomce (for compatibility with i386): same as mce=off 20 nomce (for compatibility with i386): same as mce=off
16 21
diff --git a/Kbuild b/Kbuild
new file mode 100644
index 0000000000..79003918f3
--- /dev/null
+++ b/Kbuild
@@ -0,0 +1,49 @@
1#
2# Kbuild for top-level directory of the kernel
3# This file takes care of the following:
4# 1) Generate asm-offsets.h
5
6#####
7# 1) Generate asm-offsets.h
8#
9
10offsets-file := include/asm-$(ARCH)/asm-offsets.h
11
12always := $(offsets-file)
13targets := $(offsets-file)
14targets += arch/$(ARCH)/kernel/asm-offsets.s
15
16# Default sed regexp - multiline due to syntax constraints
17define sed-y
18 "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"
19endef
20# Override default regexp for specific architectures
21sed-$(CONFIG_MIPS) := "/^@@@/s///p"
22
23quiet_cmd_offsets = GEN $@
24define cmd_offsets
25 mkdir -p $(dir $@); \
26 cat $< | \
27 (set -e; \
28 echo "#ifndef __ASM_OFFSETS_H__"; \
29 echo "#define __ASM_OFFSETS_H__"; \
30 echo "/*"; \
31 echo " * DO NOT MODIFY."; \
32 echo " *"; \
33 echo " * This file was generated by $(srctree)/Kbuild"; \
34 echo " *"; \
35 echo " */"; \
36 echo ""; \
37 sed -ne $(sed-y); \
38 echo ""; \
39 echo "#endif" ) > $@
40endef
41
42# We use internal kbuild rules to avoid the "is up to date" message from make
43arch/$(ARCH)/kernel/asm-offsets.s: arch/$(ARCH)/kernel/asm-offsets.c FORCE
44 $(Q)mkdir -p $(dir $@)
45 $(call if_changed_dep,cc_s_c)
46
47$(obj)/$(offsets-file): arch/$(ARCH)/kernel/asm-offsets.s Kbuild
48 $(call cmd,offsets)
49
diff --git a/MAINTAINERS b/MAINTAINERS
index eaa46594f0..f038dca34e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -626,6 +626,12 @@ M: rmk@arm.linux.org.uk
626W: http://www.arm.linux.org.uk/ 626W: http://www.arm.linux.org.uk/
627S: Maintained 627S: Maintained
628 628
629CYBLAFB FRAMEBUFFER DRIVER
630P: Knut Petersen
631M: Knut_Petersen@t-online.de
632L: linux-fbdev-devel@lists.sourceforge.net
633S: Maintained
634
629CYCLADES 2X SYNC CARD DRIVER 635CYCLADES 2X SYNC CARD DRIVER
630P: Arnaldo Carvalho de Melo 636P: Arnaldo Carvalho de Melo
631M: acme@conectiva.com.br 637M: acme@conectiva.com.br
@@ -925,6 +931,13 @@ L: linux-tape@vger.kernel.org
925W: http://sourceforge.net/projects/ftape 931W: http://sourceforge.net/projects/ftape
926S: Orphan 932S: Orphan
927 933
934FUSE: FILESYSTEM IN USERSPACE
935P: Miklos Szeredi
936M: miklos@szeredi.hu
937L: fuse-devel@lists.sourceforge.net
938W: http://fuse.sourceforge.net/
939S: Maintained
940
928FUTURE DOMAIN TMC-16x0 SCSI DRIVER (16-bit) 941FUTURE DOMAIN TMC-16x0 SCSI DRIVER (16-bit)
929P: Rik Faith 942P: Rik Faith
930M: faith@cs.unc.edu 943M: faith@cs.unc.edu
@@ -2684,6 +2697,17 @@ L: rio500-users@lists.sourceforge.net
2684W: http://rio500.sourceforge.net 2697W: http://rio500.sourceforge.net
2685S: Maintained 2698S: Maintained
2686 2699
2700V9FS FILE SYSTEM
2701P: Eric Van Hensbergen
2702M: ericvh@gmail.com
2703P: Ron Minnich
2704M: rminnich@lanl.gov
2705P: Latchesar Ionkov
2706M: lucho@ionkov.net
2707L: v9fs-developer@lists.sourceforge.net
2708W: http://v9fs.sf.net
2709S: Maintained
2710
2687VIDEO FOR LINUX 2711VIDEO FOR LINUX
2688P: Mauro Carvalho Chehab 2712P: Mauro Carvalho Chehab
2689M: mchehab@brturbo.com.br 2713M: mchehab@brturbo.com.br
diff --git a/Makefile b/Makefile
index 63e5c9f0bc..45e5a38fbc 100644
--- a/Makefile
+++ b/Makefile
@@ -334,7 +334,7 @@ KALLSYMS = scripts/kallsyms
334PERL = perl 334PERL = perl
335CHECK = sparse 335CHECK = sparse
336 336
337CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ 337CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ $(CF)
338MODFLAGS = -DMODULE 338MODFLAGS = -DMODULE
339CFLAGS_MODULE = $(MODFLAGS) 339CFLAGS_MODULE = $(MODFLAGS)
340AFLAGS_MODULE = $(MODFLAGS) 340AFLAGS_MODULE = $(MODFLAGS)
@@ -382,6 +382,9 @@ RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exclude CV
382scripts_basic: 382scripts_basic:
383 $(Q)$(MAKE) $(build)=scripts/basic 383 $(Q)$(MAKE) $(build)=scripts/basic
384 384
385# To avoid any implicit rule to kick in, define an empty command.
386scripts/basic/%: scripts_basic ;
387
385.PHONY: outputmakefile 388.PHONY: outputmakefile
386# outputmakefile generate a Makefile to be placed in output directory, if 389# outputmakefile generate a Makefile to be placed in output directory, if
387# using a seperate output directory. This allows convinient use 390# using a seperate output directory. This allows convinient use
@@ -444,9 +447,8 @@ ifeq ($(config-targets),1)
444include $(srctree)/arch/$(ARCH)/Makefile 447include $(srctree)/arch/$(ARCH)/Makefile
445export KBUILD_DEFCONFIG 448export KBUILD_DEFCONFIG
446 449
447config: scripts_basic outputmakefile FORCE 450config %config: scripts_basic outputmakefile FORCE
448 $(Q)$(MAKE) $(build)=scripts/kconfig $@ 451 $(Q)mkdir -p include/linux
449%config: scripts_basic outputmakefile FORCE
450 $(Q)$(MAKE) $(build)=scripts/kconfig $@ 452 $(Q)$(MAKE) $(build)=scripts/kconfig $@
451 453
452else 454else
@@ -489,6 +491,7 @@ include .config
489# If .config is newer than include/linux/autoconf.h, someone tinkered 491# If .config is newer than include/linux/autoconf.h, someone tinkered
490# with it and forgot to run make oldconfig 492# with it and forgot to run make oldconfig
491include/linux/autoconf.h: .config 493include/linux/autoconf.h: .config
494 $(Q)mkdir -p include/linux
492 $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig 495 $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
493else 496else
494# Dummy target needed, because used as prerequisite 497# Dummy target needed, because used as prerequisite
@@ -641,8 +644,13 @@ quiet_cmd_vmlinux__ ?= LD $@
641# Generate new vmlinux version 644# Generate new vmlinux version
642quiet_cmd_vmlinux_version = GEN .version 645quiet_cmd_vmlinux_version = GEN .version
643 cmd_vmlinux_version = set -e; \ 646 cmd_vmlinux_version = set -e; \
644 . $(srctree)/scripts/mkversion > .tmp_version; \ 647 if [ ! -r .version ]; then \
645 mv -f .tmp_version .version; \ 648 rm -f .version; \
649 echo 1 >.version; \
650 else \
651 mv .version .old_version; \
652 expr 0$$(cat .old_version) + 1 >.version; \
653 fi; \
646 $(MAKE) $(build)=init 654 $(MAKE) $(build)=init
647 655
648# Generate System.map 656# Generate System.map
@@ -756,6 +764,7 @@ endif # ifdef CONFIG_KALLSYMS
756# vmlinux image - including updated kernel symbols 764# vmlinux image - including updated kernel symbols
757vmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) $(kallsyms.o) FORCE 765vmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) $(kallsyms.o) FORCE
758 $(call if_changed_rule,vmlinux__) 766 $(call if_changed_rule,vmlinux__)
767 $(Q)rm -f .old_version
759 768
760# The actual objects are generated when descending, 769# The actual objects are generated when descending,
761# make sure no implicit rule kicks in 770# make sure no implicit rule kicks in
@@ -768,22 +777,27 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
768# Error messages still appears in the original language 777# Error messages still appears in the original language
769 778
770.PHONY: $(vmlinux-dirs) 779.PHONY: $(vmlinux-dirs)
771$(vmlinux-dirs): prepare-all scripts 780$(vmlinux-dirs): prepare scripts
772 $(Q)$(MAKE) $(build)=$@ 781 $(Q)$(MAKE) $(build)=$@
773 782
774# Things we need to do before we recursively start building the kernel 783# Things we need to do before we recursively start building the kernel
775# or the modules are listed in "prepare-all". 784# or the modules are listed in "prepare".
776# A multi level approach is used. prepare1 is updated first, then prepare0. 785# A multi level approach is used. prepareN is processed before prepareN-1.
777# prepare-all is the collection point for the prepare targets. 786# archprepare is used in arch Makefiles and when processed asm symlink,
787# version.h and scripts_basic is processed / created.
788
789# Listed in dependency order
790.PHONY: prepare archprepare prepare0 prepare1 prepare2 prepare3
778 791
779.PHONY: prepare-all prepare prepare0 prepare1 prepare2 792# prepare-all is deprecated, use prepare as valid replacement
793.PHONY: prepare-all
780 794
781# prepare2 is used to check if we are building in a separate output directory, 795# prepare3 is used to check if we are building in a separate output directory,
782# and if so do: 796# and if so do:
783# 1) Check that make has not been executed in the kernel src $(srctree) 797# 1) Check that make has not been executed in the kernel src $(srctree)
784# 2) Create the include2 directory, used for the second asm symlink 798# 2) Create the include2 directory, used for the second asm symlink
785 799
786prepare2: 800prepare3:
787ifneq ($(KBUILD_SRC),) 801ifneq ($(KBUILD_SRC),)
788 @echo ' Using $(srctree) as source for kernel' 802 @echo ' Using $(srctree) as source for kernel'
789 $(Q)if [ -f $(srctree)/.config ]; then \ 803 $(Q)if [ -f $(srctree)/.config ]; then \
@@ -795,18 +809,23 @@ ifneq ($(KBUILD_SRC),)
795 $(Q)ln -fsn $(srctree)/include/asm-$(ARCH) include2/asm 809 $(Q)ln -fsn $(srctree)/include/asm-$(ARCH) include2/asm
796endif 810endif
797 811
798# prepare1 creates a makefile if using a separate output directory 812# prepare2 creates a makefile if using a separate output directory
799prepare1: prepare2 outputmakefile 813prepare2: prepare3 outputmakefile
800 814
801prepare0: prepare1 include/linux/version.h include/asm \ 815prepare1: prepare2 include/linux/version.h include/asm \
802 include/config/MARKER 816 include/config/MARKER
803ifneq ($(KBUILD_MODULES),) 817ifneq ($(KBUILD_MODULES),)
804 $(Q)rm -rf $(MODVERDIR) 818 $(Q)rm -rf $(MODVERDIR)
805 $(Q)mkdir -p $(MODVERDIR) 819 $(Q)mkdir -p $(MODVERDIR)
806endif 820endif
807 821
822archprepare: prepare1 scripts_basic
823
824prepare0: archprepare FORCE
825 $(Q)$(MAKE) $(build)=.
826
808# All the preparing.. 827# All the preparing..
809prepare-all: prepare0 prepare 828prepare prepare-all: prepare0
810 829
811# Leave this as default for preprocessing vmlinux.lds.S, which is now 830# Leave this as default for preprocessing vmlinux.lds.S, which is now
812# done in arch/$(ARCH)/kernel/Makefile 831# done in arch/$(ARCH)/kernel/Makefile
@@ -845,7 +864,7 @@ include/asm:
845 864
846# Split autoconf.h into include/linux/config/* 865# Split autoconf.h into include/linux/config/*
847 866
848include/config/MARKER: include/linux/autoconf.h 867include/config/MARKER: scripts/basic/split-include include/linux/autoconf.h
849 @echo ' SPLIT include/linux/autoconf.h -> include/config/*' 868 @echo ' SPLIT include/linux/autoconf.h -> include/config/*'
850 @scripts/basic/split-include include/linux/autoconf.h include/config 869 @scripts/basic/split-include include/linux/autoconf.h include/config
851 @touch $@ 870 @touch $@
@@ -897,7 +916,7 @@ modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)
897 916
898# Target to prepare building external modules 917# Target to prepare building external modules
899.PHONY: modules_prepare 918.PHONY: modules_prepare
900modules_prepare: prepare-all scripts 919modules_prepare: prepare scripts
901 920
902# Target to install modules 921# Target to install modules
903.PHONY: modules_install 922.PHONY: modules_install
@@ -949,26 +968,6 @@ modules modules_install: FORCE
949 968
950endif # CONFIG_MODULES 969endif # CONFIG_MODULES
951 970
952# Generate asm-offsets.h
953# ---------------------------------------------------------------------------
954
955define filechk_gen-asm-offsets
956 (set -e; \
957 echo "#ifndef __ASM_OFFSETS_H__"; \
958 echo "#define __ASM_OFFSETS_H__"; \
959 echo "/*"; \
960 echo " * DO NOT MODIFY."; \
961 echo " *"; \
962 echo " * This file was generated by arch/$(ARCH)/Makefile"; \
963 echo " *"; \
964 echo " */"; \
965 echo ""; \
966 sed -ne "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"; \
967 echo ""; \
968 echo "#endif" )
969endef
970
971
972### 971###
973# Cleaning is done on three levels. 972# Cleaning is done on three levels.
974# make clean Delete most generated files 973# make clean Delete most generated files
@@ -991,7 +990,7 @@ MRPROPER_FILES += .config .config.old include/asm .version \
991# 990#
992clean: rm-dirs := $(CLEAN_DIRS) 991clean: rm-dirs := $(CLEAN_DIRS)
993clean: rm-files := $(CLEAN_FILES) 992clean: rm-files := $(CLEAN_FILES)
994clean-dirs := $(addprefix _clean_,$(vmlinux-alldirs)) 993clean-dirs := $(addprefix _clean_,$(srctree) $(vmlinux-alldirs))
995 994
996.PHONY: $(clean-dirs) clean archclean 995.PHONY: $(clean-dirs) clean archclean
997$(clean-dirs): 996$(clean-dirs):
@@ -1070,6 +1069,7 @@ help:
1070 @echo ' rpm - Build a kernel as an RPM package' 1069 @echo ' rpm - Build a kernel as an RPM package'
1071 @echo ' tags/TAGS - Generate tags file for editors' 1070 @echo ' tags/TAGS - Generate tags file for editors'
1072 @echo ' cscope - Generate cscope index' 1071 @echo ' cscope - Generate cscope index'
1072 @echo ' kernelrelease - Output the release version string'
1073 @echo '' 1073 @echo ''
1074 @echo 'Static analysers' 1074 @echo 'Static analysers'
1075 @echo ' buildcheck - List dangling references to vmlinux discarded sections' 1075 @echo ' buildcheck - List dangling references to vmlinux discarded sections'
diff --git a/REPORTING-BUGS b/REPORTING-BUGS
index 224c34741d..f9da827a0c 100644
--- a/REPORTING-BUGS
+++ b/REPORTING-BUGS
@@ -9,7 +9,7 @@ screen please read "Documentation/oops-tracing.txt" before posting your
9bug report. This explains what you should do with the "Oops" information 9bug report. This explains what you should do with the "Oops" information
10to make it useful to the recipient. 10to make it useful to the recipient.
11 11
12 Send the output the maintainer of the kernel area that seems to 12 Send the output to the maintainer of the kernel area that seems to
13be involved with the problem. Don't worry too much about getting the 13be involved with the problem. Don't worry too much about getting the
14wrong person. If you are unsure send it to the person responsible for the 14wrong person. If you are unsure send it to the person responsible for the
15code relevant to what you were doing. If it occurs repeatably try and 15code relevant to what you were doing. If it occurs repeatably try and
@@ -18,15 +18,15 @@ The list of maintainers is in the MAINTAINERS file in this directory.
18 18
19 If it is a security bug, please copy the Security Contact listed 19 If it is a security bug, please copy the Security Contact listed
20in the MAINTAINERS file. They can help coordinate bugfix and disclosure. 20in the MAINTAINERS file. They can help coordinate bugfix and disclosure.
21See Documentation/SecurityBugs for more infomation. 21See Documentation/SecurityBugs for more information.
22 22
23 If you are totally stumped as to whom to send the report, send it to 23 If you are totally stumped as to whom to send the report, send it to
24linux-kernel@vger.kernel.org. (For more information on the linux-kernel 24linux-kernel@vger.kernel.org. (For more information on the linux-kernel
25mailing list see http://www.tux.org/lkml/). 25mailing list see http://www.tux.org/lkml/).
26 26
27This is a suggested format for a bug report sent to the Linux kernel mailing 27This is a suggested format for a bug report sent to the Linux kernel mailing
28list. Having a standardized bug report form makes it easier for you not to 28list. Having a standardized bug report form makes it easier for you not to
29overlook things, and easier for the developers to find the pieces of 29overlook things, and easier for the developers to find the pieces of
30information they're really interested in. Don't feel you have to follow it. 30information they're really interested in. Don't feel you have to follow it.
31 31
32 First run the ver_linux script included as scripts/ver_linux, which 32 First run the ver_linux script included as scripts/ver_linux, which
@@ -35,9 +35,9 @@ the command "sh scripts/ver_linux".
35 35
36Use that information to fill in all fields of the bug report form, and 36Use that information to fill in all fields of the bug report form, and
37post it to the mailing list with a subject of "PROBLEM: <one line 37post it to the mailing list with a subject of "PROBLEM: <one line
38summary from [1.]>" for easy identification by the developers 38summary from [1.]>" for easy identification by the developers.
39 39
40[1.] One line summary of the problem: 40[1.] One line summary of the problem:
41[2.] Full description of the problem/report: 41[2.] Full description of the problem/report:
42[3.] Keywords (i.e., modules, networking, kernel): 42[3.] Keywords (i.e., modules, networking, kernel):
43[4.] Kernel version (from /proc/version): 43[4.] Kernel version (from /proc/version):
diff --git a/arch/alpha/Makefile b/arch/alpha/Makefile
index 22ebfb2be0..1b704ee54b 100644
--- a/arch/alpha/Makefile
+++ b/arch/alpha/Makefile
@@ -108,20 +108,9 @@ $(boot)/vmlinux.gz: vmlinux
108bootimage bootpfile bootpzfile: vmlinux 108bootimage bootpfile bootpzfile: vmlinux
109 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 109 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
110 110
111
112prepare: include/asm-$(ARCH)/asm_offsets.h
113
114arch/$(ARCH)/kernel/asm-offsets.s: include/asm include/linux/version.h \
115 include/config/MARKER
116
117include/asm-$(ARCH)/asm_offsets.h: arch/$(ARCH)/kernel/asm-offsets.s
118 $(call filechk,gen-asm-offsets)
119
120archclean: 111archclean:
121 $(Q)$(MAKE) $(clean)=$(boot) 112 $(Q)$(MAKE) $(clean)=$(boot)
122 113
123CLEAN_FILES += include/asm-$(ARCH)/asm_offsets.h
124
125define archhelp 114define archhelp
126 echo '* boot - Compressed kernel image (arch/alpha/boot/vmlinux.gz)' 115 echo '* boot - Compressed kernel image (arch/alpha/boot/vmlinux.gz)'
127 echo ' bootimage - SRM bootable image (arch/alpha/boot/bootimage)' 116 echo ' bootimage - SRM bootable image (arch/alpha/boot/bootimage)'
diff --git a/arch/alpha/kernel/alpha_ksyms.c b/arch/alpha/kernel/alpha_ksyms.c
index fc5ef90c4f..24ae9a3660 100644
--- a/arch/alpha/kernel/alpha_ksyms.c
+++ b/arch/alpha/kernel/alpha_ksyms.c
@@ -185,15 +185,6 @@ EXPORT_SYMBOL(smp_num_cpus);
185EXPORT_SYMBOL(smp_call_function); 185EXPORT_SYMBOL(smp_call_function);
186EXPORT_SYMBOL(smp_call_function_on_cpu); 186EXPORT_SYMBOL(smp_call_function_on_cpu);
187EXPORT_SYMBOL(_atomic_dec_and_lock); 187EXPORT_SYMBOL(_atomic_dec_and_lock);
188#ifdef CONFIG_DEBUG_SPINLOCK
189EXPORT_SYMBOL(_raw_spin_unlock);
190EXPORT_SYMBOL(debug_spin_lock);
191EXPORT_SYMBOL(debug_spin_trylock);
192#endif
193#ifdef CONFIG_DEBUG_RWLOCK
194EXPORT_SYMBOL(_raw_write_lock);
195EXPORT_SYMBOL(_raw_read_lock);
196#endif
197EXPORT_SYMBOL(cpu_present_mask); 188EXPORT_SYMBOL(cpu_present_mask);
198#endif /* CONFIG_SMP */ 189#endif /* CONFIG_SMP */
199 190
diff --git a/arch/alpha/kernel/entry.S b/arch/alpha/kernel/entry.S
index f0927ee53f..76cc0cb5fc 100644
--- a/arch/alpha/kernel/entry.S
+++ b/arch/alpha/kernel/entry.S
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7#include <linux/config.h> 7#include <linux/config.h>
8#include <asm/asm_offsets.h> 8#include <asm/asm-offsets.h>
9#include <asm/thread_info.h> 9#include <asm/thread_info.h>
10#include <asm/pal.h> 10#include <asm/pal.h>
11#include <asm/errno.h> 11#include <asm/errno.h>
diff --git a/arch/alpha/kernel/head.S b/arch/alpha/kernel/head.S
index 4ca2e40470..0905721fcb 100644
--- a/arch/alpha/kernel/head.S
+++ b/arch/alpha/kernel/head.S
@@ -9,7 +9,7 @@
9 9
10#include <linux/config.h> 10#include <linux/config.h>
11#include <asm/system.h> 11#include <asm/system.h>
12#include <asm/asm_offsets.h> 12#include <asm/asm-offsets.h>
13 13
14.globl swapper_pg_dir 14.globl swapper_pg_dir
15.globl _stext 15.globl _stext
diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
index fc271e316a..aac6d4b22f 100644
--- a/arch/alpha/kernel/module.c
+++ b/arch/alpha/kernel/module.c
@@ -47,7 +47,7 @@ module_free(struct module *mod, void *module_region)
47 47
48struct got_entry { 48struct got_entry {
49 struct got_entry *next; 49 struct got_entry *next;
50 Elf64_Addr r_offset; 50 Elf64_Sxword r_addend;
51 int got_offset; 51 int got_offset;
52}; 52};
53 53
@@ -57,14 +57,14 @@ process_reloc_for_got(Elf64_Rela *rela,
57{ 57{
58 unsigned long r_sym = ELF64_R_SYM (rela->r_info); 58 unsigned long r_sym = ELF64_R_SYM (rela->r_info);
59 unsigned long r_type = ELF64_R_TYPE (rela->r_info); 59 unsigned long r_type = ELF64_R_TYPE (rela->r_info);
60 Elf64_Addr r_offset = rela->r_offset; 60 Elf64_Sxword r_addend = rela->r_addend;
61 struct got_entry *g; 61 struct got_entry *g;
62 62
63 if (r_type != R_ALPHA_LITERAL) 63 if (r_type != R_ALPHA_LITERAL)
64 return; 64 return;
65 65
66 for (g = chains + r_sym; g ; g = g->next) 66 for (g = chains + r_sym; g ; g = g->next)
67 if (g->r_offset == r_offset) { 67 if (g->r_addend == r_addend) {
68 if (g->got_offset == 0) { 68 if (g->got_offset == 0) {
69 g->got_offset = *poffset; 69 g->got_offset = *poffset;
70 *poffset += 8; 70 *poffset += 8;
@@ -74,7 +74,7 @@ process_reloc_for_got(Elf64_Rela *rela,
74 74
75 g = kmalloc (sizeof (*g), GFP_KERNEL); 75 g = kmalloc (sizeof (*g), GFP_KERNEL);
76 g->next = chains[r_sym].next; 76 g->next = chains[r_sym].next;
77 g->r_offset = r_offset; 77 g->r_addend = r_addend;
78 g->got_offset = *poffset; 78 g->got_offset = *poffset;
79 *poffset += 8; 79 *poffset += 8;
80 chains[r_sym].next = g; 80 chains[r_sym].next = g;
diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index 167fd89f87..0636116210 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -974,6 +974,7 @@ osf_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp,
974 size_t size; 974 size_t size;
975 long timeout; 975 long timeout;
976 int ret = -EINVAL; 976 int ret = -EINVAL;
977 struct fdtable *fdt;
977 978
978 timeout = MAX_SCHEDULE_TIMEOUT; 979 timeout = MAX_SCHEDULE_TIMEOUT;
979 if (tvp) { 980 if (tvp) {
@@ -995,7 +996,8 @@ osf_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp,
995 } 996 }
996 } 997 }
997 998
998 if (n < 0 || n > current->files->max_fdset) 999 fdt = files_fdtable(current->files);
1000 if (n < 0 || n > fdt->max_fdset)
999 goto out_nofds; 1001 goto out_nofds;
1000 1002
1001 /* 1003 /*
@@ -1152,8 +1154,7 @@ osf_usleep_thread(struct timeval32 __user *sleep, struct timeval32 __user *remai
1152 1154
1153 ticks = timeval_to_jiffies(&tmp); 1155 ticks = timeval_to_jiffies(&tmp);
1154 1156
1155 current->state = TASK_INTERRUPTIBLE; 1157 ticks = schedule_timeout_interruptible(ticks);
1156 ticks = schedule_timeout(ticks);
1157 1158
1158 if (remain) { 1159 if (remain) {
1159 jiffies_to_timeval(ticks, &tmp); 1160 jiffies_to_timeval(ticks, &tmp);
diff --git a/arch/alpha/kernel/smp.c b/arch/alpha/kernel/smp.c
index e211aa7404..da0be34657 100644
--- a/arch/alpha/kernel/smp.c
+++ b/arch/alpha/kernel/smp.c
@@ -989,175 +989,3 @@ flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
989 989
990 preempt_enable(); 990 preempt_enable();
991} 991}
992
993#ifdef CONFIG_DEBUG_SPINLOCK
994void
995_raw_spin_unlock(spinlock_t * lock)
996{
997 mb();
998 lock->lock = 0;
999
1000 lock->on_cpu = -1;
1001 lock->previous = NULL;
1002 lock->task = NULL;
1003 lock->base_file = "none";
1004 lock->line_no = 0;
1005}
1006
1007void
1008debug_spin_lock(spinlock_t * lock, const char *base_file, int line_no)
1009{
1010 long tmp;
1011 long stuck;
1012 void *inline_pc = __builtin_return_address(0);
1013 unsigned long started = jiffies;
1014 int printed = 0;
1015 int cpu = smp_processor_id();
1016
1017 stuck = 1L << 30;
1018 try_again:
1019
1020 /* Use sub-sections to put the actual loop at the end
1021 of this object file's text section so as to perfect
1022 branch prediction. */
1023 __asm__ __volatile__(
1024 "1: ldl_l %0,%1\n"
1025 " subq %2,1,%2\n"
1026 " blbs %0,2f\n"
1027 " or %0,1,%0\n"
1028 " stl_c %0,%1\n"
1029 " beq %0,3f\n"
1030 "4: mb\n"
1031 ".subsection 2\n"
1032 "2: ldl %0,%1\n"
1033 " subq %2,1,%2\n"
1034 "3: blt %2,4b\n"
1035 " blbs %0,2b\n"
1036 " br 1b\n"
1037 ".previous"
1038 : "=r" (tmp), "=m" (lock->lock), "=r" (stuck)
1039 : "m" (lock->lock), "2" (stuck) : "memory");
1040
1041 if (stuck < 0) {
1042 printk(KERN_WARNING
1043 "%s:%d spinlock stuck in %s at %p(%d)"
1044 " owner %s at %p(%d) %s:%d\n",
1045 base_file, line_no,
1046 current->comm, inline_pc, cpu,
1047 lock->task->comm, lock->previous,
1048 lock->on_cpu, lock->base_file, lock->line_no);
1049 stuck = 1L << 36;
1050 printed = 1;
1051 goto try_again;
1052 }
1053
1054 /* Exiting. Got the lock. */
1055 lock->on_cpu = cpu;
1056 lock->previous = inline_pc;
1057 lock->task = current;
1058 lock->base_file = base_file;
1059 lock->line_no = line_no;
1060
1061 if (printed) {
1062 printk(KERN_WARNING
1063 "%s:%d spinlock grabbed in %s at %p(%d) %ld ticks\n",
1064 base_file, line_no, current->comm, inline_pc,
1065 cpu, jiffies - started);
1066 }
1067}
1068
1069int
1070debug_spin_trylock(spinlock_t * lock, const char *base_file, int line_no)
1071{
1072 int ret;
1073 if ((ret = !test_and_set_bit(0, lock))) {
1074 lock->on_cpu = smp_processor_id();
1075 lock->previous = __builtin_return_address(0);
1076 lock->task = current;
1077 } else {
1078 lock->base_file = base_file;
1079 lock->line_no = line_no;
1080 }
1081 return ret;
1082}
1083#endif /* CONFIG_DEBUG_SPINLOCK */
1084
1085#ifdef CONFIG_DEBUG_RWLOCK
1086void _raw_write_lock(rwlock_t * lock)
1087{
1088 long regx, regy;
1089 int stuck_lock, stuck_reader;
1090 void *inline_pc = __builtin_return_address(0);
1091
1092 try_again:
1093
1094 stuck_lock = 1<<30;
1095 stuck_reader = 1<<30;
1096
1097 __asm__ __volatile__(
1098 "1: ldl_l %1,%0\n"
1099 " blbs %1,6f\n"
1100 " blt %1,8f\n"
1101 " mov 1,%1\n"
1102 " stl_c %1,%0\n"
1103 " beq %1,6f\n"
1104 "4: mb\n"
1105 ".subsection 2\n"
1106 "6: blt %3,4b # debug\n"
1107 " subl %3,1,%3 # debug\n"
1108 " ldl %1,%0\n"
1109 " blbs %1,6b\n"
1110 "8: blt %4,4b # debug\n"
1111 " subl %4,1,%4 # debug\n"
1112 " ldl %1,%0\n"
1113 " blt %1,8b\n"
1114 " br 1b\n"
1115 ".previous"
1116 : "=m" (*(volatile int *)lock), "=&r" (regx), "=&r" (regy),
1117 "=&r" (stuck_lock), "=&r" (stuck_reader)
1118 : "m" (*(volatile int *)lock), "3" (stuck_lock), "4" (stuck_reader) : "memory");
1119
1120 if (stuck_lock < 0) {
1121 printk(KERN_WARNING "write_lock stuck at %p\n", inline_pc);
1122 goto try_again;
1123 }
1124 if (stuck_reader < 0) {
1125 printk(KERN_WARNING "write_lock stuck on readers at %p\n",
1126 inline_pc);
1127 goto try_again;
1128 }
1129}
1130
1131void _raw_read_lock(rwlock_t * lock)
1132{
1133 long regx;
1134 int stuck_lock;
1135 void *inline_pc = __builtin_return_address(0);
1136
1137 try_again:
1138
1139 stuck_lock = 1<<30;
1140
1141 __asm__ __volatile__(
1142 "1: ldl_l %1,%0;"
1143 " blbs %1,6f;"
1144 " subl %1,2,%1;"
1145 " stl_c %1,%0;"
1146 " beq %1,6f;"
1147 "4: mb\n"
1148 ".subsection 2\n"
1149 "6: ldl %1,%0;"
1150 " blt %2,4b # debug\n"
1151 " subl %2,1,%2 # debug\n"
1152 " blbs %1,6b;"
1153 " br 1b\n"
1154 ".previous"
1155 : "=m" (*(volatile int *)lock), "=&r" (regx), "=&r" (stuck_lock)
1156 : "m" (*(volatile int *)lock), "2" (stuck_lock) : "memory");
1157
1158 if (stuck_lock < 0) {
1159 printk(KERN_WARNING "read_lock stuck at %p\n", inline_pc);
1160 goto try_again;
1161 }
1162}
1163#endif /* CONFIG_DEBUG_RWLOCK */
diff --git a/arch/alpha/lib/dbg_stackcheck.S b/arch/alpha/lib/dbg_stackcheck.S
index cc5ce3a5fc..3c1f3e6522 100644
--- a/arch/alpha/lib/dbg_stackcheck.S
+++ b/arch/alpha/lib/dbg_stackcheck.S
@@ -5,7 +5,7 @@
5 * Verify that we have not overflowed the stack. Oops if we have. 5 * Verify that we have not overflowed the stack. Oops if we have.
6 */ 6 */
7 7
8#include <asm/asm_offsets.h> 8#include <asm/asm-offsets.h>
9 9
10 .text 10 .text
11 .set noat 11 .set noat
diff --git a/arch/alpha/lib/dbg_stackkill.S b/arch/alpha/lib/dbg_stackkill.S
index e09f2ae1e0..e9f6a9dcf2 100644
--- a/arch/alpha/lib/dbg_stackkill.S
+++ b/arch/alpha/lib/dbg_stackkill.S
@@ -6,7 +6,7 @@
6 * uninitialized local variables in the act. 6 * uninitialized local variables in the act.
7 */ 7 */
8 8
9#include <asm/asm_offsets.h> 9#include <asm/asm-offsets.h>
10 10
11 .text 11 .text
12 .set noat 12 .set noat
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 0f2899b415..11fff042aa 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -326,8 +326,8 @@ config SMP
326 processor machines. On a single processor machine, the kernel will 326 processor machines. On a single processor machine, the kernel will
327 run faster if you say N here. 327 run faster if you say N here.
328 328
329 See also the <file:Documentation/smp.tex>, 329 See also the <file:Documentation/smp.txt>,
330 <file:Documentation/smp.txt>, <file:Documentation/i386/IO-APIC.txt>, 330 <file:Documentation/i386/IO-APIC.txt>,
331 <file:Documentation/nmi_watchdog.txt> and the SMP-HOWTO available at 331 <file:Documentation/nmi_watchdog.txt> and the SMP-HOWTO available at
332 <http://www.linuxdoc.org/docs.html#howto>. 332 <http://www.linuxdoc.org/docs.html#howto>.
333 333
diff --git a/arch/arm/Kconfig.debug b/arch/arm/Kconfig.debug
index 45a5709eaa..5d3acff8c5 100644
--- a/arch/arm/Kconfig.debug
+++ b/arch/arm/Kconfig.debug
@@ -53,7 +53,7 @@ config DEBUG_LL
53 bool "Kernel low-level debugging functions" 53 bool "Kernel low-level debugging functions"
54 depends on DEBUG_KERNEL 54 depends on DEBUG_KERNEL
55 help 55 help
56 Say Y here to include definitions of printascii, printchar, printhex 56 Say Y here to include definitions of printascii, printch, printhex
57 in the kernel. This is helpful if you are debugging code that 57 in the kernel. This is helpful if you are debugging code that
58 executes before the console is initialized. 58 executes before the console is initialized.
59 59
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 67f1453ade..130e6228b5 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -175,10 +175,10 @@ else
175endif 175endif
176 @touch $@ 176 @touch $@
177 177
178prepare: maketools include/asm-arm/.arch 178archprepare: maketools include/asm-arm/.arch
179 179
180.PHONY: maketools FORCE 180.PHONY: maketools FORCE
181maketools: include/asm-arm/constants.h include/linux/version.h FORCE 181maketools: include/linux/version.h FORCE
182 $(Q)$(MAKE) $(build)=arch/arm/tools include/asm-arm/mach-types.h 182 $(Q)$(MAKE) $(build)=arch/arm/tools include/asm-arm/mach-types.h
183 183
184# Convert bzImage to zImage 184# Convert bzImage to zImage
@@ -190,7 +190,7 @@ zImage Image xipImage bootpImage uImage: vmlinux
190zinstall install: vmlinux 190zinstall install: vmlinux
191 $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $@ 191 $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $@
192 192
193CLEAN_FILES += include/asm-arm/constants.h* include/asm-arm/mach-types.h \ 193CLEAN_FILES += include/asm-arm/mach-types.h \
194 include/asm-arm/arch include/asm-arm/.arch 194 include/asm-arm/arch include/asm-arm/.arch
195 195
196# We use MRPROPER_FILES and CLEAN_FILES now 196# We use MRPROPER_FILES and CLEAN_FILES now
@@ -201,11 +201,6 @@ archclean:
201bp:; $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/bootpImage 201bp:; $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/bootpImage
202i zi:; $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $@ 202i zi:; $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $@
203 203
204arch/$(ARCH)/kernel/asm-offsets.s: include/asm include/linux/version.h \
205 include/asm-arm/.arch
206
207include/asm-$(ARCH)/constants.h: arch/$(ARCH)/kernel/asm-offsets.s
208 $(call filechk,gen-asm-offsets)
209 204
210define archhelp 205define archhelp
211 echo '* zImage - Compressed kernel image (arch/$(ARCH)/boot/zImage)' 206 echo '* zImage - Compressed kernel image (arch/$(ARCH)/boot/zImage)'
diff --git a/arch/arm/common/scoop.c b/arch/arm/common/scoop.c
index 688a595598..d3a04c2a2c 100644
--- a/arch/arm/common/scoop.c
+++ b/arch/arm/common/scoop.c
@@ -91,7 +91,7 @@ EXPORT_SYMBOL(read_scoop_reg);
91EXPORT_SYMBOL(write_scoop_reg); 91EXPORT_SYMBOL(write_scoop_reg);
92 92
93#ifdef CONFIG_PM 93#ifdef CONFIG_PM
94static int scoop_suspend(struct device *dev, uint32_t state, uint32_t level) 94static int scoop_suspend(struct device *dev, pm_message_t state, uint32_t level)
95{ 95{
96 if (level == SUSPEND_POWER_DOWN) { 96 if (level == SUSPEND_POWER_DOWN) {
97 struct scoop_dev *sdev = dev_get_drvdata(dev); 97 struct scoop_dev *sdev = dev_get_drvdata(dev);
diff --git a/arch/arm/kernel/calls.S b/arch/arm/kernel/calls.S
index db07ce42b3..949ec4427f 100644
--- a/arch/arm/kernel/calls.S
+++ b/arch/arm/kernel/calls.S
@@ -10,7 +10,7 @@
10 * This file is included twice in entry-common.S 10 * This file is included twice in entry-common.S
11 */ 11 */
12#ifndef NR_syscalls 12#ifndef NR_syscalls
13#define NR_syscalls 320 13#define NR_syscalls 328
14#else 14#else
15 15
16__syscall_start: 16__syscall_start:
@@ -333,6 +333,9 @@ __syscall_start:
333 .long sys_inotify_init 333 .long sys_inotify_init
334 .long sys_inotify_add_watch 334 .long sys_inotify_add_watch
335 .long sys_inotify_rm_watch 335 .long sys_inotify_rm_watch
336 .long sys_mbind_wrapper
337/* 320 */ .long sys_get_mempolicy
338 .long sys_set_mempolicy
336__syscall_end: 339__syscall_end:
337 340
338 .rept NR_syscalls - (__syscall_end - __syscall_start) / 4 341 .rept NR_syscalls - (__syscall_end - __syscall_start) / 4
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index 6281d488ac..db302c6e53 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -269,6 +269,10 @@ sys_arm_fadvise64_64_wrapper:
269 str r5, [sp, #4] @ push r5 to stack 269 str r5, [sp, #4] @ push r5 to stack
270 b sys_arm_fadvise64_64 270 b sys_arm_fadvise64_64
271 271
272sys_mbind_wrapper:
273 str r5, [sp, #4]
274 b sys_mbind
275
272/* 276/*
273 * Note: off_4k (r5) is always units of 4K. If we can't do the requested 277 * Note: off_4k (r5) is always units of 4K. If we can't do the requested
274 * offset, we return EINVAL. 278 * offset, we return EINVAL.
diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
index afef212739..648cfff931 100644
--- a/arch/arm/kernel/entry-header.S
+++ b/arch/arm/kernel/entry-header.S
@@ -3,7 +3,7 @@
3#include <linux/linkage.h> 3#include <linux/linkage.h>
4 4
5#include <asm/assembler.h> 5#include <asm/assembler.h>
6#include <asm/constants.h> 6#include <asm/asm-offsets.h>
7#include <asm/errno.h> 7#include <asm/errno.h>
8#include <asm/thread_info.h> 8#include <asm/thread_info.h>
9 9
diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
index 1155cf07c8..5396263513 100644
--- a/arch/arm/kernel/head.S
+++ b/arch/arm/kernel/head.S
@@ -20,7 +20,7 @@
20#include <asm/mach-types.h> 20#include <asm/mach-types.h>
21#include <asm/procinfo.h> 21#include <asm/procinfo.h>
22#include <asm/ptrace.h> 22#include <asm/ptrace.h>
23#include <asm/constants.h> 23#include <asm/asm-offsets.h>
24#include <asm/thread_info.h> 24#include <asm/thread_info.h>
25#include <asm/system.h> 25#include <asm/system.h>
26 26
diff --git a/arch/arm/kernel/iwmmxt.S b/arch/arm/kernel/iwmmxt.S
index 8f74e24536..24c7b0477a 100644
--- a/arch/arm/kernel/iwmmxt.S
+++ b/arch/arm/kernel/iwmmxt.S
@@ -17,7 +17,7 @@
17#include <linux/linkage.h> 17#include <linux/linkage.h>
18#include <asm/ptrace.h> 18#include <asm/ptrace.h>
19#include <asm/thread_info.h> 19#include <asm/thread_info.h>
20#include <asm/constants.h> 20#include <asm/asm-offsets.h>
21 21
22#define MMX_WR0 (0x00) 22#define MMX_WR0 (0x00)
23#define MMX_WR1 (0x08) 23#define MMX_WR1 (0x08)
diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
index 4c38abdbe4..6811796848 100644
--- a/arch/arm/lib/copy_page.S
+++ b/arch/arm/lib/copy_page.S
@@ -11,7 +11,7 @@
11 */ 11 */
12#include <linux/linkage.h> 12#include <linux/linkage.h>
13#include <asm/assembler.h> 13#include <asm/assembler.h>
14#include <asm/constants.h> 14#include <asm/asm-offsets.h>
15 15
16#define COPY_COUNT (PAGE_SZ/64 PLD( -1 )) 16#define COPY_COUNT (PAGE_SZ/64 PLD( -1 ))
17 17
diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
index 46a2dc962e..333bca292d 100644
--- a/arch/arm/lib/csumpartialcopyuser.S
+++ b/arch/arm/lib/csumpartialcopyuser.S
@@ -13,7 +13,7 @@
13#include <linux/linkage.h> 13#include <linux/linkage.h>
14#include <asm/assembler.h> 14#include <asm/assembler.h>
15#include <asm/errno.h> 15#include <asm/errno.h>
16#include <asm/constants.h> 16#include <asm/asm-offsets.h>
17 17
18 .text 18 .text
19 19
diff --git a/arch/arm/lib/getuser.S b/arch/arm/lib/getuser.S
index 64aa6f4fe5..d204018070 100644
--- a/arch/arm/lib/getuser.S
+++ b/arch/arm/lib/getuser.S
@@ -26,7 +26,7 @@
26 * Note that ADDR_LIMIT is either 0 or 0xc0000000. 26 * Note that ADDR_LIMIT is either 0 or 0xc0000000.
27 * Note also that it is intended that __get_user_bad is not global. 27 * Note also that it is intended that __get_user_bad is not global.
28 */ 28 */
29#include <asm/constants.h> 29#include <asm/asm-offsets.h>
30#include <asm/thread_info.h> 30#include <asm/thread_info.h>
31#include <asm/errno.h> 31#include <asm/errno.h>
32 32
diff --git a/arch/arm/lib/putuser.S b/arch/arm/lib/putuser.S
index b09398d95a..4593e9c07f 100644
--- a/arch/arm/lib/putuser.S
+++ b/arch/arm/lib/putuser.S
@@ -26,7 +26,7 @@
26 * Note that ADDR_LIMIT is either 0 or 0xc0000000 26 * Note that ADDR_LIMIT is either 0 or 0xc0000000
27 * Note also that it is intended that __put_user_bad is not global. 27 * Note also that it is intended that __put_user_bad is not global.
28 */ 28 */
29#include <asm/constants.h> 29#include <asm/asm-offsets.h>
30#include <asm/thread_info.h> 30#include <asm/thread_info.h>
31#include <asm/errno.h> 31#include <asm/errno.h>
32 32
diff --git a/arch/arm/mach-pxa/corgi.c b/arch/arm/mach-pxa/corgi.c
index 29185acdd9..07b5dd4535 100644
--- a/arch/arm/mach-pxa/corgi.c
+++ b/arch/arm/mach-pxa/corgi.c
@@ -131,27 +131,12 @@ static struct platform_device corgits_device = {
131/* 131/*
132 * MMC/SD Device 132 * MMC/SD Device
133 * 133 *
134 * The card detect interrupt isn't debounced so we delay it by HZ/4 134 * The card detect interrupt isn't debounced so we delay it by 250ms
135 * to give the card a chance to fully insert/eject. 135 * to give the card a chance to fully insert/eject.
136 */ 136 */
137static struct mmc_detect { 137static struct pxamci_platform_data corgi_mci_platform_data;
138 struct timer_list detect_timer;
139 void *devid;
140} mmc_detect;
141 138
142static void mmc_detect_callback(unsigned long data) 139static int corgi_mci_init(struct device *dev, irqreturn_t (*corgi_detect_int)(int, void *, struct pt_regs *), void *data)
143{
144 mmc_detect_change(mmc_detect.devid);
145}
146
147static irqreturn_t corgi_mmc_detect_int(int irq, void *devid, struct pt_regs *regs)
148{
149 mmc_detect.devid=devid;
150 mod_timer(&mmc_detect.detect_timer, jiffies + HZ/4);
151 return IRQ_HANDLED;
152}
153
154static int corgi_mci_init(struct device *dev, irqreturn_t (*unused_detect_int)(int, void *, struct pt_regs *), void *data)
155{ 140{
156 int err; 141 int err;
157 142
@@ -161,11 +146,9 @@ static int corgi_mci_init(struct device *dev, irqreturn_t (*unused_detect_int)(i
161 pxa_gpio_mode(CORGI_GPIO_nSD_DETECT | GPIO_IN); 146 pxa_gpio_mode(CORGI_GPIO_nSD_DETECT | GPIO_IN);
162 pxa_gpio_mode(CORGI_GPIO_SD_PWR | GPIO_OUT); 147 pxa_gpio_mode(CORGI_GPIO_SD_PWR | GPIO_OUT);
163 148
164 init_timer(&mmc_detect.detect_timer); 149 corgi_mci_platform_data.detect_delay = msecs_to_jiffies(250);
165 mmc_detect.detect_timer.function = mmc_detect_callback;
166 mmc_detect.detect_timer.data = (unsigned long) &mmc_detect;
167 150
168 err = request_irq(CORGI_IRQ_GPIO_nSD_DETECT, corgi_mmc_detect_int, SA_INTERRUPT, 151 err = request_irq(CORGI_IRQ_GPIO_nSD_DETECT, corgi_detect_int, SA_INTERRUPT,
169 "MMC card detect", data); 152 "MMC card detect", data);
170 if (err) { 153 if (err) {
171 printk(KERN_ERR "corgi_mci_init: MMC/SD: can't request MMC card detect IRQ\n"); 154 printk(KERN_ERR "corgi_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
@@ -198,7 +181,6 @@ static int corgi_mci_get_ro(struct device *dev)
198static void corgi_mci_exit(struct device *dev, void *data) 181static void corgi_mci_exit(struct device *dev, void *data)
199{ 182{
200 free_irq(CORGI_IRQ_GPIO_nSD_DETECT, data); 183 free_irq(CORGI_IRQ_GPIO_nSD_DETECT, data);
201 del_timer(&mmc_detect.detect_timer);
202} 184}
203 185
204static struct pxamci_platform_data corgi_mci_platform_data = { 186static struct pxamci_platform_data corgi_mci_platform_data = {
diff --git a/arch/arm/mach-pxa/corgi_ssp.c b/arch/arm/mach-pxa/corgi_ssp.c
index 8ccffba001..366a9bde3d 100644
--- a/arch/arm/mach-pxa/corgi_ssp.c
+++ b/arch/arm/mach-pxa/corgi_ssp.c
@@ -22,7 +22,7 @@
22#include <asm/arch/corgi.h> 22#include <asm/arch/corgi.h>
23#include <asm/arch/pxa-regs.h> 23#include <asm/arch/pxa-regs.h>
24 24
25static spinlock_t corgi_ssp_lock = SPIN_LOCK_UNLOCKED; 25static DEFINE_SPINLOCK(corgi_ssp_lock);
26static struct ssp_dev corgi_ssp_dev; 26static struct ssp_dev corgi_ssp_dev;
27static struct ssp_state corgi_ssp_state; 27static struct ssp_state corgi_ssp_state;
28 28
diff --git a/arch/arm/mach-s3c2410/devs.c b/arch/arm/mach-s3c2410/devs.c
index 4664bd11ad..0077937a7a 100644
--- a/arch/arm/mach-s3c2410/devs.c
+++ b/arch/arm/mach-s3c2410/devs.c
@@ -29,7 +29,7 @@
29#include <asm/mach/arch.h> 29#include <asm/mach/arch.h>
30#include <asm/mach/map.h> 30#include <asm/mach/map.h>
31#include <asm/mach/irq.h> 31#include <asm/mach/irq.h>
32 32#include <asm/arch/fb.h>
33#include <asm/hardware.h> 33#include <asm/hardware.h>
34#include <asm/io.h> 34#include <asm/io.h>
35#include <asm/irq.h> 35#include <asm/irq.h>
@@ -103,6 +103,15 @@ struct platform_device s3c_device_lcd = {
103 103
104EXPORT_SYMBOL(s3c_device_lcd); 104EXPORT_SYMBOL(s3c_device_lcd);
105 105
106static struct s3c2410fb_mach_info s3c2410fb_info;
107
108void __init set_s3c2410fb_info(struct s3c2410fb_mach_info *hard_s3c2410fb_info)
109{
110 memcpy(&s3c2410fb_info,hard_s3c2410fb_info,sizeof(struct s3c2410fb_mach_info));
111 s3c_device_lcd.dev.platform_data = &s3c2410fb_info;
112}
113EXPORT_SYMBOL(set_s3c2410fb_info);
114
106/* NAND Controller */ 115/* NAND Controller */
107 116
108static struct resource s3c_nand_resource[] = { 117static struct resource s3c_nand_resource[] = {
diff --git a/arch/arm/mach-s3c2410/mach-h1940.c b/arch/arm/mach-s3c2410/mach-h1940.c
index ea4fb1a97a..6ff1889fbd 100644
--- a/arch/arm/mach-s3c2410/mach-h1940.c
+++ b/arch/arm/mach-s3c2410/mach-h1940.c
@@ -45,6 +45,9 @@
45 45
46//#include <asm/debug-ll.h> 46//#include <asm/debug-ll.h>
47#include <asm/arch/regs-serial.h> 47#include <asm/arch/regs-serial.h>
48#include <asm/arch/regs-lcd.h>
49
50#include <asm/arch/fb.h>
48 51
49#include <linux/serial_core.h> 52#include <linux/serial_core.h>
50 53
@@ -88,6 +91,48 @@ static struct s3c2410_uartcfg h1940_uartcfgs[] = {
88 91
89 92
90 93
94/**
95 * Set lcd on or off
96 **/
97static struct s3c2410fb_mach_info h1940_lcdcfg __initdata = {
98 .fixed_syncs= 1,
99 .regs={
100 .lcdcon1= S3C2410_LCDCON1_TFT16BPP | \
101 S3C2410_LCDCON1_TFT | \
102 S3C2410_LCDCON1_CLKVAL(0x0C),
103
104 .lcdcon2= S3C2410_LCDCON2_VBPD(7) | \
105 S3C2410_LCDCON2_LINEVAL(319) | \
106 S3C2410_LCDCON2_VFPD(6) | \
107 S3C2410_LCDCON2_VSPW(0),
108
109 .lcdcon3= S3C2410_LCDCON3_HBPD(19) | \
110 S3C2410_LCDCON3_HOZVAL(239) | \
111 S3C2410_LCDCON3_HFPD(7),
112
113 .lcdcon4= S3C2410_LCDCON4_MVAL(0) | \
114 S3C2410_LCDCON4_HSPW(3),
115
116 .lcdcon5= S3C2410_LCDCON5_FRM565 | \
117 S3C2410_LCDCON5_INVVLINE | \
118 S3C2410_LCDCON5_HWSWP,
119 },
120 .lpcsel= 0x02,
121 .gpccon= 0xaa940659,
122 .gpccon_mask= 0xffffffff,
123 .gpcup= 0x0000ffff,
124 .gpcup_mask= 0xffffffff,
125 .gpdcon= 0xaa84aaa0,
126 .gpdcon_mask= 0xffffffff,
127 .gpdup= 0x0000faff,
128 .gpdup_mask= 0xffffffff,
129
130 .width= 240,
131 .height= 320,
132 .xres= {240,240,240},
133 .yres= {320,320,320},
134 .bpp= {16,16,16},
135};
91 136
92static struct platform_device *h1940_devices[] __initdata = { 137static struct platform_device *h1940_devices[] __initdata = {
93 &s3c_device_usb, 138 &s3c_device_usb,
@@ -116,6 +161,11 @@ void __init h1940_init_irq(void)
116 161
117} 162}
118 163
164void __init h1940_init(void)
165{
166 set_s3c2410fb_info(&h1940_lcdcfg);
167}
168
119MACHINE_START(H1940, "IPAQ-H1940") 169MACHINE_START(H1940, "IPAQ-H1940")
120 /* Maintainer: Ben Dooks <ben@fluff.org> */ 170 /* Maintainer: Ben Dooks <ben@fluff.org> */
121 .phys_ram = S3C2410_SDRAM_PA, 171 .phys_ram = S3C2410_SDRAM_PA,
@@ -124,5 +174,6 @@ MACHINE_START(H1940, "IPAQ-H1940")
124 .boot_params = S3C2410_SDRAM_PA + 0x100, 174 .boot_params = S3C2410_SDRAM_PA + 0x100,
125 .map_io = h1940_map_io, 175 .map_io = h1940_map_io,
126 .init_irq = h1940_init_irq, 176 .init_irq = h1940_init_irq,
177 .init_machine = h1940_init,
127 .timer = &s3c24xx_timer, 178 .timer = &s3c24xx_timer,
128MACHINE_END 179MACHINE_END
diff --git a/arch/arm/mm/copypage-v3.S b/arch/arm/mm/copypage-v3.S
index 4940f19083..3c58ebbf03 100644
--- a/arch/arm/mm/copypage-v3.S
+++ b/arch/arm/mm/copypage-v3.S
@@ -12,7 +12,7 @@
12#include <linux/linkage.h> 12#include <linux/linkage.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <asm/assembler.h> 14#include <asm/assembler.h>
15#include <asm/constants.h> 15#include <asm/asm-offsets.h>
16 16
17 .text 17 .text
18 .align 5 18 .align 5
diff --git a/arch/arm/mm/copypage-v4wb.S b/arch/arm/mm/copypage-v4wb.S
index b94c345ceb..83117354b1 100644
--- a/arch/arm/mm/copypage-v4wb.S
+++ b/arch/arm/mm/copypage-v4wb.S
@@ -11,7 +11,7 @@
11 */ 11 */
12#include <linux/linkage.h> 12#include <linux/linkage.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <asm/constants.h> 14#include <asm/asm-offsets.h>
15 15
16 .text 16 .text
17 .align 5 17 .align 5
diff --git a/arch/arm/mm/copypage-v4wt.S b/arch/arm/mm/copypage-v4wt.S
index 976793937a..e1f2af28d5 100644
--- a/arch/arm/mm/copypage-v4wt.S
+++ b/arch/arm/mm/copypage-v4wt.S
@@ -14,7 +14,7 @@
14 */ 14 */
15#include <linux/linkage.h> 15#include <linux/linkage.h>
16#include <linux/init.h> 16#include <linux/init.h>
17#include <asm/constants.h> 17#include <asm/asm-offsets.h>
18 18
19 .text 19 .text
20 .align 5 20 .align 5
diff --git a/arch/arm/mm/proc-arm1020.S b/arch/arm/mm/proc-arm1020.S
index 5c0ae5260d..1d739d282a 100644
--- a/arch/arm/mm/proc-arm1020.S
+++ b/arch/arm/mm/proc-arm1020.S
@@ -28,7 +28,7 @@
28#include <linux/config.h> 28#include <linux/config.h>
29#include <linux/init.h> 29#include <linux/init.h>
30#include <asm/assembler.h> 30#include <asm/assembler.h>
31#include <asm/constants.h> 31#include <asm/asm-offsets.h>
32#include <asm/pgtable.h> 32#include <asm/pgtable.h>
33#include <asm/procinfo.h> 33#include <asm/procinfo.h>
34#include <asm/ptrace.h> 34#include <asm/ptrace.h>
diff --git a/arch/arm/mm/proc-arm1020e.S b/arch/arm/mm/proc-arm1020e.S
index d69389c4d4..9b725665b5 100644
--- a/arch/arm/mm/proc-arm1020e.S
+++ b/arch/arm/mm/proc-arm1020e.S
@@ -28,7 +28,7 @@
28#include <linux/config.h> 28#include <linux/config.h>
29#include <linux/init.h> 29#include <linux/init.h>
30#include <asm/assembler.h> 30#include <asm/assembler.h>
31#include <asm/constants.h> 31#include <asm/asm-offsets.h>
32#include <asm/pgtable.h> 32#include <asm/pgtable.h>
33#include <asm/procinfo.h> 33#include <asm/procinfo.h>
34#include <asm/ptrace.h> 34#include <asm/ptrace.h>
diff --git a/arch/arm/mm/proc-arm1022.S b/arch/arm/mm/proc-arm1022.S
index 747ed963e1..37b70fa21c 100644
--- a/arch/arm/mm/proc-arm1022.S
+++ b/arch/arm/mm/proc-arm1022.S
@@ -17,7 +17,7 @@
17#include <linux/config.h> 17#include <linux/config.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <asm/assembler.h> 19#include <asm/assembler.h>
20#include <asm/constants.h> 20#include <asm/asm-offsets.h>
21#include <asm/pgtable.h> 21#include <asm/pgtable.h>
22#include <asm/procinfo.h> 22#include <asm/procinfo.h>
23#include <asm/ptrace.h> 23#include <asm/ptrace.h>
diff --git a/arch/arm/mm/proc-arm1026.S b/arch/arm/mm/proc-arm1026.S
index 248110c9cf..931b690d1b 100644
--- a/arch/arm/mm/proc-arm1026.S
+++ b/arch/arm/mm/proc-arm1026.S
@@ -17,7 +17,7 @@
17#include <linux/config.h> 17#include <linux/config.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <asm/assembler.h> 19#include <asm/assembler.h>
20#include <asm/constants.h> 20#include <asm/asm-offsets.h>
21#include <asm/pgtable.h> 21#include <asm/pgtable.h>
22#include <asm/procinfo.h> 22#include <asm/procinfo.h>
23#include <asm/ptrace.h> 23#include <asm/ptrace.h>
diff --git a/arch/arm/mm/proc-arm6_7.S b/arch/arm/mm/proc-arm6_7.S
index 189ef6a71b..d0f1bbb48f 100644
--- a/arch/arm/mm/proc-arm6_7.S
+++ b/arch/arm/mm/proc-arm6_7.S
@@ -13,7 +13,7 @@
13#include <linux/linkage.h> 13#include <linux/linkage.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <asm/assembler.h> 15#include <asm/assembler.h>
16#include <asm/constants.h> 16#include <asm/asm-offsets.h>
17#include <asm/pgtable.h> 17#include <asm/pgtable.h>
18#include <asm/procinfo.h> 18#include <asm/procinfo.h>
19#include <asm/ptrace.h> 19#include <asm/ptrace.h>
diff --git a/arch/arm/mm/proc-arm720.S b/arch/arm/mm/proc-arm720.S
index 57cfa6a2f5..c69c9de323 100644
--- a/arch/arm/mm/proc-arm720.S
+++ b/arch/arm/mm/proc-arm720.S
@@ -33,7 +33,7 @@
33#include <linux/linkage.h> 33#include <linux/linkage.h>
34#include <linux/init.h> 34#include <linux/init.h>
35#include <asm/assembler.h> 35#include <asm/assembler.h>
36#include <asm/constants.h> 36#include <asm/asm-offsets.h>
37#include <asm/pgtable.h> 37#include <asm/pgtable.h>
38#include <asm/procinfo.h> 38#include <asm/procinfo.h>
39#include <asm/ptrace.h> 39#include <asm/ptrace.h>
diff --git a/arch/arm/mm/proc-macros.S b/arch/arm/mm/proc-macros.S
index 9137fe5635..7cfc2604a1 100644
--- a/arch/arm/mm/proc-macros.S
+++ b/arch/arm/mm/proc-macros.S
@@ -4,7 +4,7 @@
4 * VMA_VM_FLAGS 4 * VMA_VM_FLAGS
5 * VM_EXEC 5 * VM_EXEC
6 */ 6 */
7#include <asm/constants.h> 7#include <asm/asm-offsets.h>
8#include <asm/thread_info.h> 8#include <asm/thread_info.h>
9 9
10/* 10/*
diff --git a/arch/arm/mm/proc-sa110.S b/arch/arm/mm/proc-sa110.S
index 360cae9056..34f7e7d3f4 100644
--- a/arch/arm/mm/proc-sa110.S
+++ b/arch/arm/mm/proc-sa110.S
@@ -15,7 +15,7 @@
15#include <linux/linkage.h> 15#include <linux/linkage.h>
16#include <linux/init.h> 16#include <linux/init.h>
17#include <asm/assembler.h> 17#include <asm/assembler.h>
18#include <asm/constants.h> 18#include <asm/asm-offsets.h>
19#include <asm/procinfo.h> 19#include <asm/procinfo.h>
20#include <asm/hardware.h> 20#include <asm/hardware.h>
21#include <asm/pgtable.h> 21#include <asm/pgtable.h>
diff --git a/arch/arm/mm/proc-sa1100.S b/arch/arm/mm/proc-sa1100.S
index d447cd5f3d..ca14f80d5a 100644
--- a/arch/arm/mm/proc-sa1100.S
+++ b/arch/arm/mm/proc-sa1100.S
@@ -20,7 +20,7 @@
20#include <linux/linkage.h> 20#include <linux/linkage.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <asm/assembler.h> 22#include <asm/assembler.h>
23#include <asm/constants.h> 23#include <asm/asm-offsets.h>
24#include <asm/procinfo.h> 24#include <asm/procinfo.h>
25#include <asm/hardware.h> 25#include <asm/hardware.h>
26#include <asm/pgtable.h> 26#include <asm/pgtable.h>
diff --git a/arch/arm/mm/proc-v6.S b/arch/arm/mm/proc-v6.S
index 139a38670c..eb34823c9d 100644
--- a/arch/arm/mm/proc-v6.S
+++ b/arch/arm/mm/proc-v6.S
@@ -11,7 +11,7 @@
11 */ 11 */
12#include <linux/linkage.h> 12#include <linux/linkage.h>
13#include <asm/assembler.h> 13#include <asm/assembler.h>
14#include <asm/constants.h> 14#include <asm/asm-offsets.h>
15#include <asm/procinfo.h> 15#include <asm/procinfo.h>
16#include <asm/pgtable.h> 16#include <asm/pgtable.h>
17 17
diff --git a/arch/arm/mm/tlb-v3.S b/arch/arm/mm/tlb-v3.S
index 44b0daeaff..c10786ec8e 100644
--- a/arch/arm/mm/tlb-v3.S
+++ b/arch/arm/mm/tlb-v3.S
@@ -13,7 +13,7 @@
13 */ 13 */
14#include <linux/linkage.h> 14#include <linux/linkage.h>
15#include <linux/init.h> 15#include <linux/init.h>
16#include <asm/constants.h> 16#include <asm/asm-offsets.h>
17#include <asm/tlbflush.h> 17#include <asm/tlbflush.h>
18#include "proc-macros.S" 18#include "proc-macros.S"
19 19
diff --git a/arch/arm/mm/tlb-v4.S b/arch/arm/mm/tlb-v4.S
index db82ee4682..d6c94457c2 100644
--- a/arch/arm/mm/tlb-v4.S
+++ b/arch/arm/mm/tlb-v4.S
@@ -14,7 +14,7 @@
14 */ 14 */
15#include <linux/linkage.h> 15#include <linux/linkage.h>
16#include <linux/init.h> 16#include <linux/init.h>
17#include <asm/constants.h> 17#include <asm/asm-offsets.h>
18#include <asm/tlbflush.h> 18#include <asm/tlbflush.h>
19#include "proc-macros.S" 19#include "proc-macros.S"
20 20
diff --git a/arch/arm/mm/tlb-v4wb.S b/arch/arm/mm/tlb-v4wb.S
index 7908d5f1f1..cb829ca784 100644
--- a/arch/arm/mm/tlb-v4wb.S
+++ b/arch/arm/mm/tlb-v4wb.S
@@ -14,7 +14,7 @@
14 */ 14 */
15#include <linux/linkage.h> 15#include <linux/linkage.h>
16#include <linux/init.h> 16#include <linux/init.h>
17#include <asm/constants.h> 17#include <asm/asm-offsets.h>
18#include <asm/tlbflush.h> 18#include <asm/tlbflush.h>
19#include "proc-macros.S" 19#include "proc-macros.S"
20 20
diff --git a/arch/arm/mm/tlb-v4wbi.S b/arch/arm/mm/tlb-v4wbi.S
index efbe94bbe1..60cfc4a25d 100644
--- a/arch/arm/mm/tlb-v4wbi.S
+++ b/arch/arm/mm/tlb-v4wbi.S
@@ -14,7 +14,7 @@
14 */ 14 */
15#include <linux/linkage.h> 15#include <linux/linkage.h>
16#include <linux/init.h> 16#include <linux/init.h>
17#include <asm/constants.h> 17#include <asm/asm-offsets.h>
18#include <asm/tlbflush.h> 18#include <asm/tlbflush.h>
19#include "proc-macros.S" 19#include "proc-macros.S"
20 20
diff --git a/arch/arm/mm/tlb-v6.S b/arch/arm/mm/tlb-v6.S
index 99ed26e78a..6f76b89ef4 100644
--- a/arch/arm/mm/tlb-v6.S
+++ b/arch/arm/mm/tlb-v6.S
@@ -11,7 +11,7 @@
11 * These assume a split I/D TLB. 11 * These assume a split I/D TLB.
12 */ 12 */
13#include <linux/linkage.h> 13#include <linux/linkage.h>
14#include <asm/constants.h> 14#include <asm/asm-offsets.h>
15#include <asm/page.h> 15#include <asm/page.h>
16#include <asm/tlbflush.h> 16#include <asm/tlbflush.h>
17#include "proc-macros.S" 17#include "proc-macros.S"
diff --git a/arch/arm/nwfpe/entry26.S b/arch/arm/nwfpe/entry26.S
index 0ed38b0913..51940a96d6 100644
--- a/arch/arm/nwfpe/entry26.S
+++ b/arch/arm/nwfpe/entry26.S
@@ -20,7 +20,7 @@
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/ 21*/
22 22
23#include <asm/constants.h> 23#include <asm/asm-offsets.h>
24 24
25/* This is the kernel's entry point into the floating point emulator. 25/* This is the kernel's entry point into the floating point emulator.
26It is called from the kernel with code similar to this: 26It is called from the kernel with code similar to this:
diff --git a/arch/arm/vfp/entry.S b/arch/arm/vfp/entry.S
index e73c8deca5..6f17187ab3 100644
--- a/arch/arm/vfp/entry.S
+++ b/arch/arm/vfp/entry.S
@@ -17,7 +17,7 @@
17 */ 17 */
18#include <linux/linkage.h> 18#include <linux/linkage.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <asm/constants.h> 20#include <asm/asm-offsets.h>
21#include <asm/vfpmacros.h> 21#include <asm/vfpmacros.h>
22 22
23 .globl do_vfp 23 .globl do_vfp
diff --git a/arch/arm26/Makefile b/arch/arm26/Makefile
index e9cb8ef4f3..844a9e4688 100644
--- a/arch/arm26/Makefile
+++ b/arch/arm26/Makefile
@@ -49,10 +49,6 @@ all: zImage
49 49
50boot := arch/arm26/boot 50boot := arch/arm26/boot
51 51
52prepare: include/asm-$(ARCH)/asm_offsets.h
53CLEAN_FILES += include/asm-$(ARCH)/asm_offsets.h
54
55
56.PHONY: maketools FORCE 52.PHONY: maketools FORCE
57maketools: FORCE 53maketools: FORCE
58 54
@@ -94,12 +90,6 @@ zi:; $(Q)$(MAKE) $(build)=$(boot) zinstall
94 fi; \ 90 fi; \
95 ) 91 )
96 92
97arch/$(ARCH)/kernel/asm-offsets.s: include/asm include/linux/version.h \
98 include/config/MARKER
99
100include/asm-$(ARCH)/asm_offsets.h: arch/$(ARCH)/kernel/asm-offsets.s
101 $(call filechk,gen-asm-offsets)
102
103define archhelp 93define archhelp
104 echo '* zImage - Compressed kernel image (arch/$(ARCH)/boot/zImage)' 94 echo '* zImage - Compressed kernel image (arch/$(ARCH)/boot/zImage)'
105 echo ' Image - Uncompressed kernel image (arch/$(ARCH)/boot/Image)' 95 echo ' Image - Uncompressed kernel image (arch/$(ARCH)/boot/Image)'
diff --git a/arch/arm26/kernel/entry.S b/arch/arm26/kernel/entry.S
index a231dd88d0..6d910ea43d 100644
--- a/arch/arm26/kernel/entry.S
+++ b/arch/arm26/kernel/entry.S
@@ -10,7 +10,7 @@
10#include <linux/linkage.h> 10#include <linux/linkage.h>
11 11
12#include <asm/assembler.h> 12#include <asm/assembler.h>
13#include <asm/asm_offsets.h> 13#include <asm/asm-offsets.h>
14#include <asm/errno.h> 14#include <asm/errno.h>
15#include <asm/hardware.h> 15#include <asm/hardware.h>
16#include <asm/sysirq.h> 16#include <asm/sysirq.h>
diff --git a/arch/arm26/lib/copy_page.S b/arch/arm26/lib/copy_page.S
index 2d79ee12ea..c7511a2739 100644
--- a/arch/arm26/lib/copy_page.S
+++ b/arch/arm26/lib/copy_page.S
@@ -11,7 +11,7 @@
11 */ 11 */
12#include <linux/linkage.h> 12#include <linux/linkage.h>
13#include <asm/assembler.h> 13#include <asm/assembler.h>
14#include <asm/asm_offsets.h> 14#include <asm/asm-offsets.h>
15 15
16 .text 16 .text
17 .align 5 17 .align 5
diff --git a/arch/arm26/lib/csumpartialcopyuser.S b/arch/arm26/lib/csumpartialcopyuser.S
index 5b821188e4..261dd154c1 100644
--- a/arch/arm26/lib/csumpartialcopyuser.S
+++ b/arch/arm26/lib/csumpartialcopyuser.S
@@ -11,7 +11,7 @@
11#include <linux/linkage.h> 11#include <linux/linkage.h>
12#include <asm/assembler.h> 12#include <asm/assembler.h>
13#include <asm/errno.h> 13#include <asm/errno.h>
14#include <asm/asm_offsets.h> 14#include <asm/asm-offsets.h>
15 15
16 .text 16 .text
17 17
diff --git a/arch/arm26/lib/getuser.S b/arch/arm26/lib/getuser.S
index e6d59b3348..2b1de7fbfe 100644
--- a/arch/arm26/lib/getuser.S
+++ b/arch/arm26/lib/getuser.S
@@ -26,7 +26,7 @@
26 * Note that ADDR_LIMIT is either 0 or 0xc0000000. 26 * Note that ADDR_LIMIT is either 0 or 0xc0000000.
27 * Note also that it is intended that __get_user_bad is not global. 27 * Note also that it is intended that __get_user_bad is not global.
28 */ 28 */
29#include <asm/asm_offsets.h> 29#include <asm/asm-offsets.h>
30#include <asm/thread_info.h> 30#include <asm/thread_info.h>
31#include <asm/errno.h> 31#include <asm/errno.h>
32 32
diff --git a/arch/arm26/lib/putuser.S b/arch/arm26/lib/putuser.S
index 87588cbe46..46c7f15f9f 100644
--- a/arch/arm26/lib/putuser.S
+++ b/arch/arm26/lib/putuser.S
@@ -26,7 +26,7 @@
26 * Note that ADDR_LIMIT is either 0 or 0xc0000000 26 * Note that ADDR_LIMIT is either 0 or 0xc0000000
27 * Note also that it is intended that __put_user_bad is not global. 27 * Note also that it is intended that __put_user_bad is not global.
28 */ 28 */
29#include <asm/asm_offsets.h> 29#include <asm/asm-offsets.h>
30#include <asm/thread_info.h> 30#include <asm/thread_info.h>
31#include <asm/errno.h> 31#include <asm/errno.h>
32 32
diff --git a/arch/arm26/mm/proc-funcs.S b/arch/arm26/mm/proc-funcs.S
index c3d4cd3f45..f9fca524c5 100644
--- a/arch/arm26/mm/proc-funcs.S
+++ b/arch/arm26/mm/proc-funcs.S
@@ -14,7 +14,7 @@
14 */ 14 */
15#include <linux/linkage.h> 15#include <linux/linkage.h>
16#include <asm/assembler.h> 16#include <asm/assembler.h>
17#include <asm/asm_offsets.h> 17#include <asm/asm-offsets.h>
18#include <asm/procinfo.h> 18#include <asm/procinfo.h>
19#include <asm/ptrace.h> 19#include <asm/ptrace.h>
20 20
diff --git a/arch/arm26/nwfpe/entry.S b/arch/arm26/nwfpe/entry.S
index 7d6dfaad80..e6312000d9 100644
--- a/arch/arm26/nwfpe/entry.S
+++ b/arch/arm26/nwfpe/entry.S
@@ -20,7 +20,7 @@
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/ 21*/
22 22
23#include <asm/asm_offsets.h> 23#include <asm/asm-offsets.h>
24 24
25/* This is the kernel's entry point into the floating point emulator. 25/* This is the kernel's entry point into the floating point emulator.
26It is called from the kernel with code similar to this: 26It is called from the kernel with code similar to this:
diff --git a/arch/cris/Makefile b/arch/cris/Makefile
index 90ca8730b1..ea65d585cf 100644
--- a/arch/cris/Makefile
+++ b/arch/cris/Makefile
@@ -107,8 +107,7 @@ archclean:
107 rm -f timage vmlinux.bin decompress.bin rescue.bin cramfs.img 107 rm -f timage vmlinux.bin decompress.bin rescue.bin cramfs.img
108 rm -rf $(LD_SCRIPT).tmp 108 rm -rf $(LD_SCRIPT).tmp
109 109
110prepare: $(SRC_ARCH)/.links $(srctree)/include/asm-$(ARCH)/.arch \ 110archprepare: $(SRC_ARCH)/.links $(srctree)/include/asm-$(ARCH)/.arch
111 include/asm-$(ARCH)/$(SARCH)/offset.h
112 111
113# Create some links to make all tools happy 112# Create some links to make all tools happy
114$(SRC_ARCH)/.links: 113$(SRC_ARCH)/.links:
@@ -120,6 +119,7 @@ $(SRC_ARCH)/.links:
120 @ln -sfn $(SRC_ARCH)/$(SARCH)/lib $(SRC_ARCH)/lib 119 @ln -sfn $(SRC_ARCH)/$(SARCH)/lib $(SRC_ARCH)/lib
121 @ln -sfn $(SRC_ARCH)/$(SARCH) $(SRC_ARCH)/arch 120 @ln -sfn $(SRC_ARCH)/$(SARCH) $(SRC_ARCH)/arch
122 @ln -sfn $(SRC_ARCH)/$(SARCH)/vmlinux.lds.S $(SRC_ARCH)/kernel/vmlinux.lds.S 121 @ln -sfn $(SRC_ARCH)/$(SARCH)/vmlinux.lds.S $(SRC_ARCH)/kernel/vmlinux.lds.S
122 @ln -sfn $(SRC_ARCH)/$(SARCH)/asm-offsets.c $(SRC_ARCH)/kernel/asm-offsets.c
123 @touch $@ 123 @touch $@
124 124
125# Create link to sub arch includes 125# Create link to sub arch includes
@@ -128,9 +128,3 @@ $(srctree)/include/asm-$(ARCH)/.arch: $(wildcard include/config/arch/*.h)
128 @rm -f include/asm-$(ARCH)/arch 128 @rm -f include/asm-$(ARCH)/arch
129 @ln -sf $(srctree)/include/asm-$(ARCH)/$(SARCH) $(srctree)/include/asm-$(ARCH)/arch 129 @ln -sf $(srctree)/include/asm-$(ARCH)/$(SARCH) $(srctree)/include/asm-$(ARCH)/arch
130 @touch $@ 130 @touch $@
131
132arch/$(ARCH)/$(SARCH)/kernel/asm-offsets.s: include/asm include/linux/version.h \
133 include/config/MARKER
134
135include/asm-$(ARCH)/$(SARCH)/offset.h: arch/$(ARCH)/$(SARCH)/kernel/asm-offsets.s
136 $(call filechk,gen-asm-offsets)
diff --git a/arch/cris/arch-v10/kernel/entry.S b/arch/cris/arch-v10/kernel/entry.S
index c0163bf94a..c808005e84 100644
--- a/arch/cris/arch-v10/kernel/entry.S
+++ b/arch/cris/arch-v10/kernel/entry.S
@@ -270,7 +270,7 @@
270#include <asm/arch/sv_addr_ag.h> 270#include <asm/arch/sv_addr_ag.h>
271#include <asm/errno.h> 271#include <asm/errno.h>
272#include <asm/thread_info.h> 272#include <asm/thread_info.h>
273#include <asm/arch/offset.h> 273#include <asm/asm-offsets.h>
274#include <asm/page.h> 274#include <asm/page.h>
275#include <asm/pgtable.h> 275#include <asm/pgtable.h>
276 276
diff --git a/arch/cris/arch-v32/kernel/entry.S b/arch/cris/arch-v32/kernel/entry.S
index a8ed55e5b4..3bd8503fec 100644
--- a/arch/cris/arch-v32/kernel/entry.S
+++ b/arch/cris/arch-v32/kernel/entry.S
@@ -23,7 +23,7 @@
23#include <asm/unistd.h> 23#include <asm/unistd.h>
24#include <asm/errno.h> 24#include <asm/errno.h>
25#include <asm/thread_info.h> 25#include <asm/thread_info.h>
26#include <asm/arch/offset.h> 26#include <asm/asm-offsets.h>
27 27
28#include <asm/arch/hwregs/asm/reg_map_asm.h> 28#include <asm/arch/hwregs/asm/reg_map_asm.h>
29#include <asm/arch/hwregs/asm/intr_vect_defs_asm.h> 29#include <asm/arch/hwregs/asm/intr_vect_defs_asm.h>
diff --git a/arch/frv/kernel/asm-offsets.c b/arch/frv/kernel/asm-offsets.c
new file mode 100644
index 0000000000..9e263112a6
--- /dev/null
+++ b/arch/frv/kernel/asm-offsets.c
@@ -0,0 +1 @@
/* Dummy asm-offsets.c file. Required by kbuild and ready to be used - hint! */
diff --git a/arch/h8300/Makefile b/arch/h8300/Makefile
index c9b80cffd7..40b3f56f36 100644
--- a/arch/h8300/Makefile
+++ b/arch/h8300/Makefile
@@ -61,12 +61,6 @@ archmrproper:
61archclean: 61archclean:
62 $(Q)$(MAKE) $(clean)=$(boot) 62 $(Q)$(MAKE) $(clean)=$(boot)
63 63
64prepare: include/asm-$(ARCH)/asm-offsets.h
65
66include/asm-$(ARCH)/asm-offsets.h: arch/$(ARCH)/kernel/asm-offsets.s \
67 include/asm include/linux/version.h
68 $(call filechk,gen-asm-offsets)
69
70vmlinux.srec vmlinux.bin: vmlinux 64vmlinux.srec vmlinux.bin: vmlinux
71 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 65 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
72 66
@@ -74,5 +68,3 @@ define archhelp
74 echo 'vmlinux.bin - Create raw binary' 68 echo 'vmlinux.bin - Create raw binary'
75 echo 'vmlinux.srec - Create srec binary' 69 echo 'vmlinux.srec - Create srec binary'
76endef 70endef
77
78CLEAN_FILES += include/asm-$(ARCH)/asm-offsets.h
diff --git a/arch/i386/Makefile b/arch/i386/Makefile
index bf7c9ba709..09951990a6 100644
--- a/arch/i386/Makefile
+++ b/arch/i386/Makefile
@@ -156,15 +156,6 @@ install: vmlinux
156install kernel_install: 156install kernel_install:
157 $(Q)$(MAKE) $(build)=$(boot) BOOTIMAGE=$(KBUILD_IMAGE) install 157 $(Q)$(MAKE) $(build)=$(boot) BOOTIMAGE=$(KBUILD_IMAGE) install
158 158
159prepare: include/asm-$(ARCH)/asm_offsets.h
160CLEAN_FILES += include/asm-$(ARCH)/asm_offsets.h
161
162arch/$(ARCH)/kernel/asm-offsets.s: include/asm include/linux/version.h \
163 include/config/MARKER
164
165include/asm-$(ARCH)/asm_offsets.h: arch/$(ARCH)/kernel/asm-offsets.s
166 $(call filechk,gen-asm-offsets)
167
168archclean: 159archclean:
169 $(Q)$(MAKE) $(clean)=arch/i386/boot 160 $(Q)$(MAKE) $(clean)=arch/i386/boot
170 161
diff --git a/arch/i386/boot/video.S b/arch/i386/boot/video.S
index 0587477c99..92f6694701 100644
--- a/arch/i386/boot/video.S
+++ b/arch/i386/boot/video.S
@@ -97,6 +97,7 @@
97#define PARAM_VESAPM_OFF 0x30 97#define PARAM_VESAPM_OFF 0x30
98#define PARAM_LFB_PAGES 0x32 98#define PARAM_LFB_PAGES 0x32
99#define PARAM_VESA_ATTRIB 0x34 99#define PARAM_VESA_ATTRIB 0x34
100#define PARAM_CAPABILITIES 0x36
100 101
101/* Define DO_STORE according to CONFIG_VIDEO_RETAIN */ 102/* Define DO_STORE according to CONFIG_VIDEO_RETAIN */
102#ifdef CONFIG_VIDEO_RETAIN 103#ifdef CONFIG_VIDEO_RETAIN
@@ -233,6 +234,10 @@ mopar_gr:
233 movw 18(%di), %ax 234 movw 18(%di), %ax
234 movl %eax, %fs:(PARAM_LFB_SIZE) 235 movl %eax, %fs:(PARAM_LFB_SIZE)
235 236
237# store mode capabilities
238 movl 10(%di), %eax
239 movl %eax, %fs:(PARAM_CAPABILITIES)
240
236# switching the DAC to 8-bit is for <= 8 bpp only 241# switching the DAC to 8-bit is for <= 8 bpp only
237 movw %fs:(PARAM_LFB_DEPTH), %ax 242 movw %fs:(PARAM_LFB_DEPTH), %ax
238 cmpw $8, %ax 243 cmpw $8, %ax
@@ -1944,7 +1949,7 @@ store_edid:
1944 movw $0x4f15, %ax # do VBE/DDC 1949 movw $0x4f15, %ax # do VBE/DDC
1945 movw $0x01, %bx 1950 movw $0x01, %bx
1946 movw $0x00, %cx 1951 movw $0x00, %cx
1947 movw $0x01, %dx 1952 movw $0x00, %dx
1948 movw $0x140, %di 1953 movw $0x140, %di
1949 int $0x10 1954 int $0x10
1950 1955
diff --git a/arch/i386/kernel/acpi/earlyquirk.c b/arch/i386/kernel/acpi/earlyquirk.c
index f1b9d2a46d..087ecc67e9 100644
--- a/arch/i386/kernel/acpi/earlyquirk.c
+++ b/arch/i386/kernel/acpi/earlyquirk.c
@@ -15,6 +15,13 @@ static int __init check_bridge(int vendor, int device)
15 if (vendor == PCI_VENDOR_ID_NVIDIA) { 15 if (vendor == PCI_VENDOR_ID_NVIDIA) {
16 acpi_skip_timer_override = 1; 16 acpi_skip_timer_override = 1;
17 } 17 }
18 /*
19 * ATI IXP chipsets get double timer interrupts.
20 * For now just do this for all ATI chipsets.
21 * FIXME: this needs to be checked for the non ACPI case too.
22 */
23 if (vendor == PCI_VENDOR_ID_ATI)
24 disable_timer_pin_1 = 1;
18 return 0; 25 return 0;
19} 26}
20 27
diff --git a/arch/i386/kernel/acpi/wakeup.S b/arch/i386/kernel/acpi/wakeup.S
index 44d886c745..7c74fe0dc9 100644
--- a/arch/i386/kernel/acpi/wakeup.S
+++ b/arch/i386/kernel/acpi/wakeup.S
@@ -304,12 +304,6 @@ ret_point:
304 call restore_processor_state 304 call restore_processor_state
305 ret 305 ret
306 306
307ENTRY(do_suspend_lowlevel_s4bios)
308 call save_processor_state
309 call save_registers
310 call acpi_enter_sleep_state_s4bios
311 ret
312
313ALIGN 307ALIGN
314# saved registers 308# saved registers
315saved_gdt: .long 0,0 309saved_gdt: .long 0,0
diff --git a/arch/i386/kernel/cpu/common.c b/arch/i386/kernel/cpu/common.c
index 46ce9b248f..9ad43be9a0 100644
--- a/arch/i386/kernel/cpu/common.c
+++ b/arch/i386/kernel/cpu/common.c
@@ -151,7 +151,7 @@ static char __devinit *table_lookup_model(struct cpuinfo_x86 *c)
151} 151}
152 152
153 153
154void __devinit get_cpu_vendor(struct cpuinfo_x86 *c, int early) 154static void __devinit get_cpu_vendor(struct cpuinfo_x86 *c, int early)
155{ 155{
156 char *v = c->x86_vendor_id; 156 char *v = c->x86_vendor_id;
157 int i; 157 int i;
diff --git a/arch/i386/kernel/entry.S b/arch/i386/kernel/entry.S
index 3aad038396..9e24f7b207 100644
--- a/arch/i386/kernel/entry.S
+++ b/arch/i386/kernel/entry.S
@@ -319,7 +319,7 @@ work_notifysig: # deal with pending signals and
319 # vm86-space 319 # vm86-space
320 xorl %edx, %edx 320 xorl %edx, %edx
321 call do_notify_resume 321 call do_notify_resume
322 jmp restore_all 322 jmp resume_userspace
323 323
324 ALIGN 324 ALIGN
325work_notifysig_v86: 325work_notifysig_v86:
@@ -329,7 +329,7 @@ work_notifysig_v86:
329 movl %eax, %esp 329 movl %eax, %esp
330 xorl %edx, %edx 330 xorl %edx, %edx
331 call do_notify_resume 331 call do_notify_resume
332 jmp restore_all 332 jmp resume_userspace
333 333
334 # perform syscall exit tracing 334 # perform syscall exit tracing
335 ALIGN 335 ALIGN
diff --git a/arch/i386/kernel/head.S b/arch/i386/kernel/head.S
index 0480ca9e9e..e437fb3674 100644
--- a/arch/i386/kernel/head.S
+++ b/arch/i386/kernel/head.S
@@ -17,7 +17,7 @@
17#include <asm/desc.h> 17#include <asm/desc.h>
18#include <asm/cache.h> 18#include <asm/cache.h>
19#include <asm/thread_info.h> 19#include <asm/thread_info.h>
20#include <asm/asm_offsets.h> 20#include <asm/asm-offsets.h>
21#include <asm/setup.h> 21#include <asm/setup.h>
22 22
23/* 23/*
diff --git a/arch/i386/kernel/io_apic.c b/arch/i386/kernel/io_apic.c
index 1efdc76ae9..378313b0cc 100644
--- a/arch/i386/kernel/io_apic.c
+++ b/arch/i386/kernel/io_apic.c
@@ -60,6 +60,8 @@ int sis_apic_bug = -1;
60 */ 60 */
61int nr_ioapic_registers[MAX_IO_APICS]; 61int nr_ioapic_registers[MAX_IO_APICS];
62 62
63int disable_timer_pin_1 __initdata;
64
63/* 65/*
64 * Rough estimation of how many shared IRQs there are, can 66 * Rough estimation of how many shared IRQs there are, can
65 * be changed anytime. 67 * be changed anytime.
@@ -573,8 +575,7 @@ static int balanced_irq(void *unused)
573 } 575 }
574 576
575 for ( ; ; ) { 577 for ( ; ; ) {
576 set_current_state(TASK_INTERRUPTIBLE); 578 time_remaining = schedule_timeout_interruptible(time_remaining);
577 time_remaining = schedule_timeout(time_remaining);
578 try_to_freeze(); 579 try_to_freeze();
579 if (time_after(jiffies, 580 if (time_after(jiffies,
580 prev_balance_time+balanced_irq_interval)) { 581 prev_balance_time+balanced_irq_interval)) {
@@ -2212,6 +2213,8 @@ static inline void check_timer(void)
2212 setup_nmi(); 2213 setup_nmi();
2213 enable_8259A_irq(0); 2214 enable_8259A_irq(0);
2214 } 2215 }
2216 if (disable_timer_pin_1 > 0)
2217 clear_IO_APIC_pin(0, pin1);
2215 return; 2218 return;
2216 } 2219 }
2217 clear_IO_APIC_pin(0, pin1); 2220 clear_IO_APIC_pin(0, pin1);
diff --git a/arch/i386/kernel/mpparse.c b/arch/i386/kernel/mpparse.c
index cafaeffe38..15949fd081 100644
--- a/arch/i386/kernel/mpparse.c
+++ b/arch/i386/kernel/mpparse.c
@@ -122,8 +122,8 @@ static int MP_valid_apicid(int apicid, int version)
122 122
123static void __init MP_processor_info (struct mpc_config_processor *m) 123static void __init MP_processor_info (struct mpc_config_processor *m)
124{ 124{
125 int ver, apicid, cpu, found_bsp = 0; 125 int ver, apicid;
126 physid_mask_t tmp; 126 physid_mask_t phys_cpu;
127 127
128 if (!(m->mpc_cpuflag & CPU_ENABLED)) 128 if (!(m->mpc_cpuflag & CPU_ENABLED))
129 return; 129 return;
@@ -181,7 +181,6 @@ static void __init MP_processor_info (struct mpc_config_processor *m)
181 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) { 181 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
182 Dprintk(" Bootup CPU\n"); 182 Dprintk(" Bootup CPU\n");
183 boot_cpu_physical_apicid = m->mpc_apicid; 183 boot_cpu_physical_apicid = m->mpc_apicid;
184 found_bsp = 1;
185 } 184 }
186 185
187 if (num_processors >= NR_CPUS) { 186 if (num_processors >= NR_CPUS) {
@@ -195,29 +194,26 @@ static void __init MP_processor_info (struct mpc_config_processor *m)
195 " Processor ignored.\n", maxcpus); 194 " Processor ignored.\n", maxcpus);
196 return; 195 return;
197 } 196 }
198 num_processors++;
199 ver = m->mpc_apicver; 197 ver = m->mpc_apicver;
200 198
201 if (!MP_valid_apicid(apicid, ver)) { 199 if (!MP_valid_apicid(apicid, ver)) {
202 printk(KERN_WARNING "Processor #%d INVALID. (Max ID: %d).\n", 200 printk(KERN_WARNING "Processor #%d INVALID. (Max ID: %d).\n",
203 m->mpc_apicid, MAX_APICS); 201 m->mpc_apicid, MAX_APICS);
204 --num_processors;
205 return; 202 return;
206 } 203 }
207 204
208 if (found_bsp) 205 cpu_set(num_processors, cpu_possible_map);
209 cpu = 0; 206 num_processors++;
210 else 207 phys_cpu = apicid_to_cpu_present(apicid);
211 cpu = num_processors - 1; 208 physids_or(phys_cpu_present_map, phys_cpu_present_map, phys_cpu);
212 cpu_set(cpu, cpu_possible_map); 209
213 tmp = apicid_to_cpu_present(apicid);
214 physids_or(phys_cpu_present_map, phys_cpu_present_map, tmp);
215
216 /* 210 /*
217 * Validate version 211 * Validate version
218 */ 212 */
219 if (ver == 0x0) { 213 if (ver == 0x0) {
220 printk(KERN_WARNING "BIOS bug, APIC version is 0 for CPU#%d! fixing up to 0x10. (tell your hw vendor)\n", m->mpc_apicid); 214 printk(KERN_WARNING "BIOS bug, APIC version is 0 for CPU#%d! "
215 "fixing up to 0x10. (tell your hw vendor)\n",
216 m->mpc_apicid);
221 ver = 0x10; 217 ver = 0x10;
222 } 218 }
223 apic_version[m->mpc_apicid] = ver; 219 apic_version[m->mpc_apicid] = ver;
diff --git a/arch/i386/kernel/ptrace.c b/arch/i386/kernel/ptrace.c
index 340980203b..7b6368bf89 100644
--- a/arch/i386/kernel/ptrace.c
+++ b/arch/i386/kernel/ptrace.c
@@ -694,17 +694,22 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code)
694__attribute__((regparm(3))) 694__attribute__((regparm(3)))
695int do_syscall_trace(struct pt_regs *regs, int entryexit) 695int do_syscall_trace(struct pt_regs *regs, int entryexit)
696{ 696{
697 int is_sysemu = test_thread_flag(TIF_SYSCALL_EMU), ret = 0; 697 int is_sysemu = test_thread_flag(TIF_SYSCALL_EMU);
698 /* With TIF_SYSCALL_EMU set we want to ignore TIF_SINGLESTEP for syscall 698 /*
699 * interception. */ 699 * With TIF_SYSCALL_EMU set we want to ignore TIF_SINGLESTEP for syscall
700 * interception
701 */
700 int is_singlestep = !is_sysemu && test_thread_flag(TIF_SINGLESTEP); 702 int is_singlestep = !is_sysemu && test_thread_flag(TIF_SINGLESTEP);
703 int ret = 0;
701 704
702 /* do the secure computing check first */ 705 /* do the secure computing check first */
703 secure_computing(regs->orig_eax); 706 if (!entryexit)
707 secure_computing(regs->orig_eax);
704 708
705 if (unlikely(current->audit_context)) { 709 if (unlikely(current->audit_context)) {
706 if (entryexit) 710 if (entryexit)
707 audit_syscall_exit(current, AUDITSC_RESULT(regs->eax), regs->eax); 711 audit_syscall_exit(current, AUDITSC_RESULT(regs->eax),
712 regs->eax);
708 /* Debug traps, when using PTRACE_SINGLESTEP, must be sent only 713 /* Debug traps, when using PTRACE_SINGLESTEP, must be sent only
709 * on the syscall exit path. Normally, when TIF_SYSCALL_AUDIT is 714 * on the syscall exit path. Normally, when TIF_SYSCALL_AUDIT is
710 * not used, entry.S will call us only on syscall exit, not 715 * not used, entry.S will call us only on syscall exit, not
@@ -738,7 +743,7 @@ int do_syscall_trace(struct pt_regs *regs, int entryexit)
738 /* the 0x80 provides a way for the tracing parent to distinguish 743 /* the 0x80 provides a way for the tracing parent to distinguish
739 between a syscall stop and SIGTRAP delivery */ 744 between a syscall stop and SIGTRAP delivery */
740 /* Note that the debugger could change the result of test_thread_flag!*/ 745 /* Note that the debugger could change the result of test_thread_flag!*/
741 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) ? 0x80 : 0)); 746 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) ? 0x80:0));
742 747
743 /* 748 /*
744 * this isn't the same as continuing with a signal, but it will do 749 * this isn't the same as continuing with a signal, but it will do
@@ -750,7 +755,7 @@ int do_syscall_trace(struct pt_regs *regs, int entryexit)
750 current->exit_code = 0; 755 current->exit_code = 0;
751 } 756 }
752 ret = is_sysemu; 757 ret = is_sysemu;
753 out: 758out:
754 if (unlikely(current->audit_context) && !entryexit) 759 if (unlikely(current->audit_context) && !entryexit)
755 audit_syscall_entry(current, AUDIT_ARCH_I386, regs->orig_eax, 760 audit_syscall_entry(current, AUDIT_ARCH_I386, regs->orig_eax,
756 regs->ebx, regs->ecx, regs->edx, regs->esi); 761 regs->ebx, regs->ecx, regs->edx, regs->esi);
@@ -759,6 +764,7 @@ int do_syscall_trace(struct pt_regs *regs, int entryexit)
759 764
760 regs->orig_eax = -1; /* force skip of syscall restarting */ 765 regs->orig_eax = -1; /* force skip of syscall restarting */
761 if (unlikely(current->audit_context)) 766 if (unlikely(current->audit_context))
762 audit_syscall_exit(current, AUDITSC_RESULT(regs->eax), regs->eax); 767 audit_syscall_exit(current, AUDITSC_RESULT(regs->eax),
768 regs->eax);
763 return 1; 769 return 1;
764} 770}
diff --git a/arch/i386/kernel/setup.c b/arch/i386/kernel/setup.c
index a659d27491..dc39ca6a7e 100644
--- a/arch/i386/kernel/setup.c
+++ b/arch/i386/kernel/setup.c
@@ -139,6 +139,7 @@ struct sys_desc_table_struct {
139 unsigned char table[0]; 139 unsigned char table[0];
140}; 140};
141struct edid_info edid_info; 141struct edid_info edid_info;
142EXPORT_SYMBOL_GPL(edid_info);
142struct ist_info ist_info; 143struct ist_info ist_info;
143#if defined(CONFIG_X86_SPEEDSTEP_SMI) || \ 144#if defined(CONFIG_X86_SPEEDSTEP_SMI) || \
144 defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE) 145 defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
@@ -850,6 +851,11 @@ static void __init parse_cmdline_early (char ** cmdline_p)
850#endif 851#endif
851 852
852#ifdef CONFIG_X86_LOCAL_APIC 853#ifdef CONFIG_X86_LOCAL_APIC
854 if (!memcmp(from, "disable_timer_pin_1", 19))
855 disable_timer_pin_1 = 1;
856 if (!memcmp(from, "enable_timer_pin_1", 18))
857 disable_timer_pin_1 = -1;
858
853 /* disable IO-APIC */ 859 /* disable IO-APIC */
854 else if (!memcmp(from, "noapic", 6)) 860 else if (!memcmp(from, "noapic", 6))
855 disable_ioapic_setup(); 861 disable_ioapic_setup();
@@ -1299,7 +1305,7 @@ legacy_init_iomem_resources(struct resource *code_resource, struct resource *dat
1299 */ 1305 */
1300static void __init register_memory(void) 1306static void __init register_memory(void)
1301{ 1307{
1302 unsigned long gapstart, gapsize; 1308 unsigned long gapstart, gapsize, round;
1303 unsigned long long last; 1309 unsigned long long last;
1304 int i; 1310 int i;
1305 1311
@@ -1344,14 +1350,14 @@ static void __init register_memory(void)
1344 } 1350 }
1345 1351
1346 /* 1352 /*
1347 * Start allocating dynamic PCI memory a bit into the gap, 1353 * See how much we want to round up: start off with
1348 * aligned up to the nearest megabyte. 1354 * rounding to the next 1MB area.
1349 *
1350 * Question: should we try to pad it up a bit (do something
1351 * like " + (gapsize >> 3)" in there too?). We now have the
1352 * technology.
1353 */ 1355 */
1354 pci_mem_start = (gapstart + 0xfffff) & ~0xfffff; 1356 round = 0x100000;
1357 while ((gapsize >> 4) > round)
1358 round += round;
1359 /* Fun with two's complement */
1360 pci_mem_start = (gapstart + round) & -round;
1355 1361
1356 printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n", 1362 printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n",
1357 pci_mem_start, gapstart, gapsize); 1363 pci_mem_start, gapstart, gapsize);
diff --git a/arch/i386/kernel/smpboot.c b/arch/i386/kernel/smpboot.c
index 5e4893d2b9..c70cd2a083 100644
--- a/arch/i386/kernel/smpboot.c
+++ b/arch/i386/kernel/smpboot.c
@@ -1330,8 +1330,7 @@ void __cpu_die(unsigned int cpu)
1330 printk ("CPU %d is now offline\n", cpu); 1330 printk ("CPU %d is now offline\n", cpu);
1331 return; 1331 return;
1332 } 1332 }
1333 current->state = TASK_UNINTERRUPTIBLE; 1333 msleep(100);
1334 schedule_timeout(HZ/10);
1335 } 1334 }
1336 printk(KERN_ERR "CPU %u didn't die...\n", cpu); 1335 printk(KERN_ERR "CPU %u didn't die...\n", cpu);
1337} 1336}
diff --git a/arch/i386/kernel/srat.c b/arch/i386/kernel/srat.c
index 7b3b27d644..516bf5653b 100644
--- a/arch/i386/kernel/srat.c
+++ b/arch/i386/kernel/srat.c
@@ -213,12 +213,18 @@ static __init void node_read_chunk(int nid, struct node_memory_chunk_s *memory_c
213 node_end_pfn[nid] = memory_chunk->end_pfn; 213 node_end_pfn[nid] = memory_chunk->end_pfn;
214} 214}
215 215
216static u8 pxm_to_nid_map[MAX_PXM_DOMAINS];/* _PXM to logical node ID map */
217
218int pxm_to_node(int pxm)
219{
220 return pxm_to_nid_map[pxm];
221}
222
216/* Parse the ACPI Static Resource Affinity Table */ 223/* Parse the ACPI Static Resource Affinity Table */
217static int __init acpi20_parse_srat(struct acpi_table_srat *sratp) 224static int __init acpi20_parse_srat(struct acpi_table_srat *sratp)
218{ 225{
219 u8 *start, *end, *p; 226 u8 *start, *end, *p;
220 int i, j, nid; 227 int i, j, nid;
221 u8 pxm_to_nid_map[MAX_PXM_DOMAINS];/* _PXM to logical node ID map */
222 u8 nid_to_pxm_map[MAX_NUMNODES];/* logical node ID to _PXM map */ 228 u8 nid_to_pxm_map[MAX_NUMNODES];/* logical node ID to _PXM map */
223 229
224 start = (u8 *)(&(sratp->reserved) + 1); /* skip header */ 230 start = (u8 *)(&(sratp->reserved) + 1); /* skip header */
diff --git a/arch/i386/kernel/time.c b/arch/i386/kernel/time.c
index eefea7c550..2883a4d4f0 100644
--- a/arch/i386/kernel/time.c
+++ b/arch/i386/kernel/time.c
@@ -329,8 +329,7 @@ EXPORT_SYMBOL(get_cmos_time);
329 329
330static void sync_cmos_clock(unsigned long dummy); 330static void sync_cmos_clock(unsigned long dummy);
331 331
332static struct timer_list sync_cmos_timer = 332static DEFINE_TIMER(sync_cmos_timer, sync_cmos_clock, 0, 0);
333 TIMER_INITIALIZER(sync_cmos_clock, 0, 0);
334 333
335static void sync_cmos_clock(unsigned long dummy) 334static void sync_cmos_clock(unsigned long dummy)
336{ 335{
diff --git a/arch/i386/kernel/vmlinux.lds.S b/arch/i386/kernel/vmlinux.lds.S
index 13b9c62cbb..4710195b6b 100644
--- a/arch/i386/kernel/vmlinux.lds.S
+++ b/arch/i386/kernel/vmlinux.lds.S
@@ -144,12 +144,7 @@ SECTIONS
144 *(.exitcall.exit) 144 *(.exitcall.exit)
145 } 145 }
146 146
147 /* Stabs debugging sections. */ 147 STABS_DEBUG
148 .stab 0 : { *(.stab) } 148
149 .stabstr 0 : { *(.stabstr) } 149 DWARF_DEBUG
150 .stab.excl 0 : { *(.stab.excl) }
151 .stab.exclstr 0 : { *(.stab.exclstr) }
152 .stab.index 0 : { *(.stab.index) }
153 .stab.indexstr 0 : { *(.stab.indexstr) }
154 .comment 0 : { *(.comment) }
155} 150}
diff --git a/arch/i386/kernel/vsyscall-sigreturn.S b/arch/i386/kernel/vsyscall-sigreturn.S
index 68afa50dd7..fadb5bc3c3 100644
--- a/arch/i386/kernel/vsyscall-sigreturn.S
+++ b/arch/i386/kernel/vsyscall-sigreturn.S
@@ -7,7 +7,7 @@
7 */ 7 */
8 8
9#include <asm/unistd.h> 9#include <asm/unistd.h>
10#include <asm/asm_offsets.h> 10#include <asm/asm-offsets.h>
11 11
12 12
13/* XXX 13/* XXX
diff --git a/arch/i386/kernel/vsyscall.lds.S b/arch/i386/kernel/vsyscall.lds.S
index a7977707c8..98699ca6e5 100644
--- a/arch/i386/kernel/vsyscall.lds.S
+++ b/arch/i386/kernel/vsyscall.lds.S
@@ -3,7 +3,7 @@
3 * object prelinked to its virtual address, and with only one read-only 3 * object prelinked to its virtual address, and with only one read-only
4 * segment (that fits in one page). This script controls its layout. 4 * segment (that fits in one page). This script controls its layout.
5 */ 5 */
6#include <asm/asm_offsets.h> 6#include <asm/asm-offsets.h>
7 7
8SECTIONS 8SECTIONS
9{ 9{
diff --git a/arch/i386/pci/acpi.c b/arch/i386/pci/acpi.c
index 42913f43fe..2941674f35 100644
--- a/arch/i386/pci/acpi.c
+++ b/arch/i386/pci/acpi.c
@@ -3,16 +3,31 @@
3#include <linux/init.h> 3#include <linux/init.h>
4#include <linux/irq.h> 4#include <linux/irq.h>
5#include <asm/hw_irq.h> 5#include <asm/hw_irq.h>
6#include <asm/numa.h>
6#include "pci.h" 7#include "pci.h"
7 8
8struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum) 9struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum)
9{ 10{
11 struct pci_bus *bus;
12
10 if (domain != 0) { 13 if (domain != 0) {
11 printk(KERN_WARNING "PCI: Multiple domains not supported\n"); 14 printk(KERN_WARNING "PCI: Multiple domains not supported\n");
12 return NULL; 15 return NULL;
13 } 16 }
14 17
15 return pcibios_scan_root(busnum); 18 bus = pcibios_scan_root(busnum);
19#ifdef CONFIG_ACPI_NUMA
20 if (bus != NULL) {
21 int pxm = acpi_get_pxm(device->handle);
22 if (pxm >= 0) {
23 bus->sysdata = (void *)(unsigned long)pxm_to_node(pxm);
24 printk("bus %d -> pxm %d -> node %ld\n",
25 busnum, pxm, (long)(bus->sysdata));
26 }
27 }
28#endif
29
30 return bus;
16} 31}
17 32
18extern int pci_routeirq; 33extern int pci_routeirq;
diff --git a/arch/i386/pci/mmconfig.c b/arch/i386/pci/mmconfig.c
index 60f0e7a116..dfbf80cff8 100644
--- a/arch/i386/pci/mmconfig.c
+++ b/arch/i386/pci/mmconfig.c
@@ -127,13 +127,6 @@ static int __init pci_mmcfg_init(void)
127 (pci_mmcfg_config[0].base_address == 0)) 127 (pci_mmcfg_config[0].base_address == 0))
128 goto out; 128 goto out;
129 129
130 /* Kludge for now. Don't use mmconfig on AMD systems because
131 those have some busses where mmconfig doesn't work,
132 and we don't parse ACPI MCFG well enough to handle that.
133 Remove when proper handling is added. */
134 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
135 goto out;
136
137 printk(KERN_INFO "PCI: Using MMCONFIG\n"); 130 printk(KERN_INFO "PCI: Using MMCONFIG\n");
138 raw_pci_ops = &pci_mmcfg; 131 raw_pci_ops = &pci_mmcfg;
139 pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF; 132 pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF;
diff --git a/arch/i386/power/swsusp.S b/arch/i386/power/swsusp.S
index c4105286ff..c893b89721 100644
--- a/arch/i386/power/swsusp.S
+++ b/arch/i386/power/swsusp.S
@@ -12,7 +12,7 @@
12#include <linux/linkage.h> 12#include <linux/linkage.h>
13#include <asm/segment.h> 13#include <asm/segment.h>
14#include <asm/page.h> 14#include <asm/page.h>
15#include <asm/asm_offsets.h> 15#include <asm/asm-offsets.h>
16 16
17 .text 17 .text
18 18
diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile
index f9bd88ada7..70f8ed2748 100644
--- a/arch/ia64/Makefile
+++ b/arch/ia64/Makefile
@@ -82,25 +82,18 @@ unwcheck: vmlinux
82archclean: 82archclean:
83 $(Q)$(MAKE) $(clean)=$(boot) 83 $(Q)$(MAKE) $(clean)=$(boot)
84 84
85CLEAN_FILES += include/asm-ia64/.offsets.h.stamp vmlinux.gz bootloader 85archprepare: include/asm-ia64/.offsets.h.stamp
86
87MRPROPER_FILES += include/asm-ia64/offsets.h
88
89prepare: include/asm-ia64/offsets.h
90
91arch/ia64/kernel/asm-offsets.s: include/asm include/linux/version.h include/config/MARKER
92
93include/asm-ia64/offsets.h: arch/ia64/kernel/asm-offsets.s
94 $(call filechk,gen-asm-offsets)
95
96arch/ia64/kernel/asm-offsets.s: include/asm-ia64/.offsets.h.stamp
97 86
98include/asm-ia64/.offsets.h.stamp: 87include/asm-ia64/.offsets.h.stamp:
99 mkdir -p include/asm-ia64 88 mkdir -p include/asm-ia64
100 [ -s include/asm-ia64/offsets.h ] \ 89 [ -s include/asm-ia64/asm-offsets.h ] \
101 || echo "#define IA64_TASK_SIZE 0" > include/asm-ia64/offsets.h 90 || echo "#define IA64_TASK_SIZE 0" > include/asm-ia64/asm-offsets.h
102 touch $@ 91 touch $@
103 92
93
94
95CLEAN_FILES += vmlinux.gz bootloader include/asm-ia64/.offsets.h.stamp
96
104boot: lib/lib.a vmlinux 97boot: lib/lib.a vmlinux
105 $(Q)$(MAKE) $(build)=$(boot) $@ 98 $(Q)$(MAKE) $(build)=$(boot) $@
106 99
diff --git a/arch/ia64/hp/sim/boot/boot_head.S b/arch/ia64/hp/sim/boot/boot_head.S
index 1c8c7e6a9a..a9bd71ac78 100644
--- a/arch/ia64/hp/sim/boot/boot_head.S
+++ b/arch/ia64/hp/sim/boot/boot_head.S
@@ -4,6 +4,7 @@
4 */ 4 */
5 5
6#include <asm/asmmacro.h> 6#include <asm/asmmacro.h>
7#include <asm/pal.h>
7 8
8 .bss 9 .bss
9 .align 16 10 .align 16
@@ -49,7 +50,11 @@ GLOBAL_ENTRY(jmp_to_kernel)
49 br.sptk.few b7 50 br.sptk.few b7
50END(jmp_to_kernel) 51END(jmp_to_kernel)
51 52
52 53/*
54 * r28 contains the index of the PAL function
55 * r29--31 the args
56 * Return values in ret0--3 (r8--11)
57 */
53GLOBAL_ENTRY(pal_emulator_static) 58GLOBAL_ENTRY(pal_emulator_static)
54 mov r8=-1 59 mov r8=-1
55 mov r9=256 60 mov r9=256
@@ -62,7 +67,7 @@ GLOBAL_ENTRY(pal_emulator_static)
62 cmp.gtu p6,p7=r9,r28 67 cmp.gtu p6,p7=r9,r28
63(p6) br.cond.sptk.few stacked 68(p6) br.cond.sptk.few stacked
64 ;; 69 ;;
65static: cmp.eq p6,p7=6,r28 /* PAL_PTCE_INFO */ 70static: cmp.eq p6,p7=PAL_PTCE_INFO,r28
66(p7) br.cond.sptk.few 1f 71(p7) br.cond.sptk.few 1f
67 ;; 72 ;;
68 mov r8=0 /* status = 0 */ 73 mov r8=0 /* status = 0 */
@@ -70,21 +75,21 @@ static: cmp.eq p6,p7=6,r28 /* PAL_PTCE_INFO */
70 movl r10=0x0000000200000003 /* count[0], count[1] */ 75 movl r10=0x0000000200000003 /* count[0], count[1] */
71 movl r11=0x1000000000002000 /* stride[0], stride[1] */ 76 movl r11=0x1000000000002000 /* stride[0], stride[1] */
72 br.cond.sptk.few rp 77 br.cond.sptk.few rp
731: cmp.eq p6,p7=14,r28 /* PAL_FREQ_RATIOS */ 781: cmp.eq p6,p7=PAL_FREQ_RATIOS,r28
74(p7) br.cond.sptk.few 1f 79(p7) br.cond.sptk.few 1f
75 mov r8=0 /* status = 0 */ 80 mov r8=0 /* status = 0 */
76 movl r9 =0x100000064 /* proc_ratio (1/100) */ 81 movl r9 =0x100000064 /* proc_ratio (1/100) */
77 movl r10=0x100000100 /* bus_ratio<<32 (1/256) */ 82 movl r10=0x100000100 /* bus_ratio<<32 (1/256) */
78 movl r11=0x100000064 /* itc_ratio<<32 (1/100) */ 83 movl r11=0x100000064 /* itc_ratio<<32 (1/100) */
79 ;; 84 ;;
801: cmp.eq p6,p7=19,r28 /* PAL_RSE_INFO */ 851: cmp.eq p6,p7=PAL_RSE_INFO,r28
81(p7) br.cond.sptk.few 1f 86(p7) br.cond.sptk.few 1f
82 mov r8=0 /* status = 0 */ 87 mov r8=0 /* status = 0 */
83 mov r9=96 /* num phys stacked */ 88 mov r9=96 /* num phys stacked */
84 mov r10=0 /* hints */ 89 mov r10=0 /* hints */
85 mov r11=0 90 mov r11=0
86 br.cond.sptk.few rp 91 br.cond.sptk.few rp
871: cmp.eq p6,p7=1,r28 /* PAL_CACHE_FLUSH */ 921: cmp.eq p6,p7=PAL_CACHE_FLUSH,r28 /* PAL_CACHE_FLUSH */
88(p7) br.cond.sptk.few 1f 93(p7) br.cond.sptk.few 1f
89 mov r9=ar.lc 94 mov r9=ar.lc
90 movl r8=524288 /* flush 512k million cache lines (16MB) */ 95 movl r8=524288 /* flush 512k million cache lines (16MB) */
@@ -102,7 +107,7 @@ static: cmp.eq p6,p7=6,r28 /* PAL_PTCE_INFO */
102 mov ar.lc=r9 107 mov ar.lc=r9
103 mov r8=r0 108 mov r8=r0
104 ;; 109 ;;
1051: cmp.eq p6,p7=15,r28 /* PAL_PERF_MON_INFO */ 1101: cmp.eq p6,p7=PAL_PERF_MON_INFO,r28
106(p7) br.cond.sptk.few 1f 111(p7) br.cond.sptk.few 1f
107 mov r8=0 /* status = 0 */ 112 mov r8=0 /* status = 0 */
108 movl r9 =0x08122f04 /* generic=4 width=47 retired=8 cycles=18 */ 113 movl r9 =0x08122f04 /* generic=4 width=47 retired=8 cycles=18 */
@@ -138,6 +143,20 @@ static: cmp.eq p6,p7=6,r28 /* PAL_PTCE_INFO */
138 st8 [r29]=r0,16 /* clear remaining bits */ 143 st8 [r29]=r0,16 /* clear remaining bits */
139 st8 [r18]=r0,16 /* clear remaining bits */ 144 st8 [r18]=r0,16 /* clear remaining bits */
140 ;; 145 ;;
1461: cmp.eq p6,p7=PAL_VM_SUMMARY,r28
147(p7) br.cond.sptk.few 1f
148 mov r8=0 /* status = 0 */
149 movl r9=0x2044040020F1865 /* num_tc_levels=2, num_unique_tcs=4 */
150 /* max_itr_entry=64, max_dtr_entry=64 */
151 /* hash_tag_id=2, max_pkr=15 */
152 /* key_size=24, phys_add_size=50, vw=1 */
153 movl r10=0x183C /* rid_size=24, impl_va_msb=60 */
154 ;;
1551: cmp.eq p6,p7=PAL_MEM_ATTRIB,r28
156(p7) br.cond.sptk.few 1f
157 mov r8=0 /* status = 0 */
158 mov r9=0x80|0x01 /* NatPage|WB */
159 ;;
1411: br.cond.sptk.few rp 1601: br.cond.sptk.few rp
142stacked: 161stacked:
143 br.ret.sptk.few rp 162 br.ret.sptk.few rp
diff --git a/arch/ia64/ia32/ia32_entry.S b/arch/ia64/ia32/ia32_entry.S
index 0708edb06c..494fad6bf3 100644
--- a/arch/ia64/ia32/ia32_entry.S
+++ b/arch/ia64/ia32/ia32_entry.S
@@ -1,6 +1,6 @@
1#include <asm/asmmacro.h> 1#include <asm/asmmacro.h>
2#include <asm/ia32.h> 2#include <asm/ia32.h>
3#include <asm/offsets.h> 3#include <asm/asm-offsets.h>
4#include <asm/signal.h> 4#include <asm/signal.h>
5#include <asm/thread_info.h> 5#include <asm/thread_info.h>
6 6
diff --git a/arch/ia64/ia32/sys_ia32.c b/arch/ia64/ia32/sys_ia32.c
index e29a8a5548..3fa67ecebc 100644
--- a/arch/ia64/ia32/sys_ia32.c
+++ b/arch/ia64/ia32/sys_ia32.c
@@ -2327,7 +2327,7 @@ sys32_sendfile (int out_fd, int in_fd, int __user *offset, unsigned int count)
2327 ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *) &of : NULL, count); 2327 ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *) &of : NULL, count);
2328 set_fs(old_fs); 2328 set_fs(old_fs);
2329 2329
2330 if (!ret && offset && put_user(of, offset)) 2330 if (offset && put_user(of, offset))
2331 return -EFAULT; 2331 return -EFAULT;
2332 2332
2333 return ret; 2333 return ret;
diff --git a/arch/ia64/kernel/asm-offsets.c b/arch/ia64/kernel/asm-offsets.c
index 7d1ae2982c..f6a2342893 100644
--- a/arch/ia64/kernel/asm-offsets.c
+++ b/arch/ia64/kernel/asm-offsets.c
@@ -211,17 +211,41 @@ void foo(void)
211#endif 211#endif
212 212
213 BLANK(); 213 BLANK();
214 DEFINE(IA64_MCA_CPU_PROC_STATE_DUMP_OFFSET, 214 DEFINE(IA64_MCA_CPU_MCA_STACK_OFFSET,
215 offsetof (struct ia64_mca_cpu, proc_state_dump)); 215 offsetof (struct ia64_mca_cpu, mca_stack));
216 DEFINE(IA64_MCA_CPU_STACK_OFFSET,
217 offsetof (struct ia64_mca_cpu, stack));
218 DEFINE(IA64_MCA_CPU_STACKFRAME_OFFSET,
219 offsetof (struct ia64_mca_cpu, stackframe));
220 DEFINE(IA64_MCA_CPU_RBSTORE_OFFSET,
221 offsetof (struct ia64_mca_cpu, rbstore));
222 DEFINE(IA64_MCA_CPU_INIT_STACK_OFFSET, 216 DEFINE(IA64_MCA_CPU_INIT_STACK_OFFSET,
223 offsetof (struct ia64_mca_cpu, init_stack)); 217 offsetof (struct ia64_mca_cpu, init_stack));
224 BLANK(); 218 BLANK();
219 DEFINE(IA64_SAL_OS_STATE_COMMON_OFFSET,
220 offsetof (struct ia64_sal_os_state, sal_ra));
221 DEFINE(IA64_SAL_OS_STATE_OS_GP_OFFSET,
222 offsetof (struct ia64_sal_os_state, os_gp));
223 DEFINE(IA64_SAL_OS_STATE_PAL_MIN_STATE_OFFSET,
224 offsetof (struct ia64_sal_os_state, pal_min_state));
225 DEFINE(IA64_SAL_OS_STATE_PROC_STATE_PARAM_OFFSET,
226 offsetof (struct ia64_sal_os_state, proc_state_param));
227 DEFINE(IA64_SAL_OS_STATE_SIZE,
228 sizeof (struct ia64_sal_os_state));
229 DEFINE(IA64_PMSA_GR_OFFSET,
230 offsetof (struct pal_min_state_area_s, pmsa_gr));
231 DEFINE(IA64_PMSA_BANK1_GR_OFFSET,
232 offsetof (struct pal_min_state_area_s, pmsa_bank1_gr));
233 DEFINE(IA64_PMSA_PR_OFFSET,
234 offsetof (struct pal_min_state_area_s, pmsa_pr));
235 DEFINE(IA64_PMSA_BR0_OFFSET,
236 offsetof (struct pal_min_state_area_s, pmsa_br0));
237 DEFINE(IA64_PMSA_RSC_OFFSET,
238 offsetof (struct pal_min_state_area_s, pmsa_rsc));
239 DEFINE(IA64_PMSA_IIP_OFFSET,
240 offsetof (struct pal_min_state_area_s, pmsa_iip));
241 DEFINE(IA64_PMSA_IPSR_OFFSET,
242 offsetof (struct pal_min_state_area_s, pmsa_ipsr));
243 DEFINE(IA64_PMSA_IFS_OFFSET,
244 offsetof (struct pal_min_state_area_s, pmsa_ifs));
245 DEFINE(IA64_PMSA_XIP_OFFSET,
246 offsetof (struct pal_min_state_area_s, pmsa_xip));
247 BLANK();
248
225 /* used by fsys_gettimeofday in arch/ia64/kernel/fsys.S */ 249 /* used by fsys_gettimeofday in arch/ia64/kernel/fsys.S */
226 DEFINE(IA64_TIME_INTERPOLATOR_ADDRESS_OFFSET, offsetof (struct time_interpolator, addr)); 250 DEFINE(IA64_TIME_INTERPOLATOR_ADDRESS_OFFSET, offsetof (struct time_interpolator, addr));
227 DEFINE(IA64_TIME_INTERPOLATOR_SOURCE_OFFSET, offsetof (struct time_interpolator, source)); 251 DEFINE(IA64_TIME_INTERPOLATOR_SOURCE_OFFSET, offsetof (struct time_interpolator, source));
diff --git a/arch/ia64/kernel/entry.S b/arch/ia64/kernel/entry.S
index 3c88210245..ba0b6a1f42 100644
--- a/arch/ia64/kernel/entry.S
+++ b/arch/ia64/kernel/entry.S
@@ -37,7 +37,7 @@
37#include <asm/cache.h> 37#include <asm/cache.h>
38#include <asm/errno.h> 38#include <asm/errno.h>
39#include <asm/kregs.h> 39#include <asm/kregs.h>
40#include <asm/offsets.h> 40#include <asm/asm-offsets.h>
41#include <asm/pgtable.h> 41#include <asm/pgtable.h>
42#include <asm/percpu.h> 42#include <asm/percpu.h>
43#include <asm/processor.h> 43#include <asm/processor.h>
@@ -470,6 +470,29 @@ ENTRY(load_switch_stack)
470 br.cond.sptk.many b7 470 br.cond.sptk.many b7
471END(load_switch_stack) 471END(load_switch_stack)
472 472
473GLOBAL_ENTRY(prefetch_stack)
474 add r14 = -IA64_SWITCH_STACK_SIZE, sp
475 add r15 = IA64_TASK_THREAD_KSP_OFFSET, in0
476 ;;
477 ld8 r16 = [r15] // load next's stack pointer
478 lfetch.fault.excl [r14], 128
479 ;;
480 lfetch.fault.excl [r14], 128
481 lfetch.fault [r16], 128
482 ;;
483 lfetch.fault.excl [r14], 128
484 lfetch.fault [r16], 128
485 ;;
486 lfetch.fault.excl [r14], 128
487 lfetch.fault [r16], 128
488 ;;
489 lfetch.fault.excl [r14], 128
490 lfetch.fault [r16], 128
491 ;;
492 lfetch.fault [r16], 128
493 br.ret.sptk.many rp
494END(prefetch_switch_stack)
495
473GLOBAL_ENTRY(execve) 496GLOBAL_ENTRY(execve)
474 mov r15=__NR_execve // put syscall number in place 497 mov r15=__NR_execve // put syscall number in place
475 break __BREAK_SYSCALL 498 break __BREAK_SYSCALL
diff --git a/arch/ia64/kernel/fsys.S b/arch/ia64/kernel/fsys.S
index 7d7684a369..2ddbac6f49 100644
--- a/arch/ia64/kernel/fsys.S
+++ b/arch/ia64/kernel/fsys.S
@@ -14,7 +14,7 @@
14 14
15#include <asm/asmmacro.h> 15#include <asm/asmmacro.h>
16#include <asm/errno.h> 16#include <asm/errno.h>
17#include <asm/offsets.h> 17#include <asm/asm-offsets.h>
18#include <asm/percpu.h> 18#include <asm/percpu.h>
19#include <asm/thread_info.h> 19#include <asm/thread_info.h>
20#include <asm/sal.h> 20#include <asm/sal.h>
diff --git a/arch/ia64/kernel/gate.S b/arch/ia64/kernel/gate.S
index 86948ce63e..86064ca989 100644
--- a/arch/ia64/kernel/gate.S
+++ b/arch/ia64/kernel/gate.S
@@ -10,7 +10,7 @@
10 10
11#include <asm/asmmacro.h> 11#include <asm/asmmacro.h>
12#include <asm/errno.h> 12#include <asm/errno.h>
13#include <asm/offsets.h> 13#include <asm/asm-offsets.h>
14#include <asm/sigcontext.h> 14#include <asm/sigcontext.h>
15#include <asm/system.h> 15#include <asm/system.h>
16#include <asm/unistd.h> 16#include <asm/unistd.h>
diff --git a/arch/ia64/kernel/head.S b/arch/ia64/kernel/head.S
index 8d3a9291b4..bfe65b2e86 100644
--- a/arch/ia64/kernel/head.S
+++ b/arch/ia64/kernel/head.S
@@ -25,7 +25,7 @@
25#include <asm/fpu.h> 25#include <asm/fpu.h>
26#include <asm/kregs.h> 26#include <asm/kregs.h>
27#include <asm/mmu_context.h> 27#include <asm/mmu_context.h>
28#include <asm/offsets.h> 28#include <asm/asm-offsets.h>
29#include <asm/pal.h> 29#include <asm/pal.h>
30#include <asm/pgtable.h> 30#include <asm/pgtable.h>
31#include <asm/processor.h> 31#include <asm/processor.h>
diff --git a/arch/ia64/kernel/ivt.S b/arch/ia64/kernel/ivt.S
index 3bb3a13c40..c13ca0d49c 100644
--- a/arch/ia64/kernel/ivt.S
+++ b/arch/ia64/kernel/ivt.S
@@ -44,7 +44,7 @@
44#include <asm/break.h> 44#include <asm/break.h>
45#include <asm/ia32.h> 45#include <asm/ia32.h>
46#include <asm/kregs.h> 46#include <asm/kregs.h>
47#include <asm/offsets.h> 47#include <asm/asm-offsets.h>
48#include <asm/pgtable.h> 48#include <asm/pgtable.h>
49#include <asm/processor.h> 49#include <asm/processor.h>
50#include <asm/ptrace.h> 50#include <asm/ptrace.h>
@@ -69,7 +69,6 @@
69# define DBG_FAULT(i) 69# define DBG_FAULT(i)
70#endif 70#endif
71 71
72#define MINSTATE_VIRT /* needed by minstate.h */
73#include "minstate.h" 72#include "minstate.h"
74 73
75#define FAULT(n) \ 74#define FAULT(n) \
diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
index 4ebbf39743..6dc726ad71 100644
--- a/arch/ia64/kernel/mca.c
+++ b/arch/ia64/kernel/mca.c
@@ -48,6 +48,9 @@
48 * Delete dead variables and functions. 48 * Delete dead variables and functions.
49 * Reorder to remove the need for forward declarations and to consolidate 49 * Reorder to remove the need for forward declarations and to consolidate
50 * related code. 50 * related code.
51 *
52 * 2005-08-12 Keith Owens <kaos@sgi.com>
53 * Convert MCA/INIT handlers to use per event stacks and SAL/OS state.
51 */ 54 */
52#include <linux/config.h> 55#include <linux/config.h>
53#include <linux/types.h> 56#include <linux/types.h>
@@ -77,6 +80,8 @@
77#include <asm/irq.h> 80#include <asm/irq.h>
78#include <asm/hw_irq.h> 81#include <asm/hw_irq.h>
79 82
83#include "entry.h"
84
80#if defined(IA64_MCA_DEBUG_INFO) 85#if defined(IA64_MCA_DEBUG_INFO)
81# define IA64_MCA_DEBUG(fmt...) printk(fmt) 86# define IA64_MCA_DEBUG(fmt...) printk(fmt)
82#else 87#else
@@ -84,9 +89,7 @@
84#endif 89#endif
85 90
86/* Used by mca_asm.S */ 91/* Used by mca_asm.S */
87ia64_mca_sal_to_os_state_t ia64_sal_to_os_handoff_state; 92u32 ia64_mca_serialize;
88ia64_mca_os_to_sal_state_t ia64_os_to_sal_handoff_state;
89u64 ia64_mca_serialize;
90DEFINE_PER_CPU(u64, ia64_mca_data); /* == __per_cpu_mca[smp_processor_id()] */ 93DEFINE_PER_CPU(u64, ia64_mca_data); /* == __per_cpu_mca[smp_processor_id()] */
91DEFINE_PER_CPU(u64, ia64_mca_per_cpu_pte); /* PTE to map per-CPU area */ 94DEFINE_PER_CPU(u64, ia64_mca_per_cpu_pte); /* PTE to map per-CPU area */
92DEFINE_PER_CPU(u64, ia64_mca_pal_pte); /* PTE to map PAL code */ 95DEFINE_PER_CPU(u64, ia64_mca_pal_pte); /* PTE to map PAL code */
@@ -95,8 +98,10 @@ DEFINE_PER_CPU(u64, ia64_mca_pal_base); /* vaddr PAL code granule */
95unsigned long __per_cpu_mca[NR_CPUS]; 98unsigned long __per_cpu_mca[NR_CPUS];
96 99
97/* In mca_asm.S */ 100/* In mca_asm.S */
98extern void ia64_monarch_init_handler (void); 101extern void ia64_os_init_dispatch_monarch (void);
99extern void ia64_slave_init_handler (void); 102extern void ia64_os_init_dispatch_slave (void);
103
104static int monarch_cpu = -1;
100 105
101static ia64_mc_info_t ia64_mc_info; 106static ia64_mc_info_t ia64_mc_info;
102 107
@@ -234,7 +239,8 @@ ia64_log_get(int sal_info_type, u8 **buffer, int irq_safe)
234 * This function retrieves a specified error record type from SAL 239 * This function retrieves a specified error record type from SAL
235 * and wakes up any processes waiting for error records. 240 * and wakes up any processes waiting for error records.
236 * 241 *
237 * Inputs : sal_info_type (Type of error record MCA/CMC/CPE/INIT) 242 * Inputs : sal_info_type (Type of error record MCA/CMC/CPE)
243 * FIXME: remove MCA and irq_safe.
238 */ 244 */
239static void 245static void
240ia64_mca_log_sal_error_record(int sal_info_type) 246ia64_mca_log_sal_error_record(int sal_info_type)
@@ -242,7 +248,7 @@ ia64_mca_log_sal_error_record(int sal_info_type)
242 u8 *buffer; 248 u8 *buffer;
243 sal_log_record_header_t *rh; 249 sal_log_record_header_t *rh;
244 u64 size; 250 u64 size;
245 int irq_safe = sal_info_type != SAL_INFO_TYPE_MCA && sal_info_type != SAL_INFO_TYPE_INIT; 251 int irq_safe = sal_info_type != SAL_INFO_TYPE_MCA;
246#ifdef IA64_MCA_DEBUG_INFO 252#ifdef IA64_MCA_DEBUG_INFO
247 static const char * const rec_name[] = { "MCA", "INIT", "CMC", "CPE" }; 253 static const char * const rec_name[] = { "MCA", "INIT", "CMC", "CPE" };
248#endif 254#endif
@@ -330,191 +336,6 @@ ia64_mca_cpe_int_handler (int cpe_irq, void *arg, struct pt_regs *ptregs)
330 336
331#endif /* CONFIG_ACPI */ 337#endif /* CONFIG_ACPI */
332 338
333static void
334show_min_state (pal_min_state_area_t *minstate)
335{
336 u64 iip = minstate->pmsa_iip + ((struct ia64_psr *)(&minstate->pmsa_ipsr))->ri;
337 u64 xip = minstate->pmsa_xip + ((struct ia64_psr *)(&minstate->pmsa_xpsr))->ri;
338
339 printk("NaT bits\t%016lx\n", minstate->pmsa_nat_bits);
340 printk("pr\t\t%016lx\n", minstate->pmsa_pr);
341 printk("b0\t\t%016lx ", minstate->pmsa_br0); print_symbol("%s\n", minstate->pmsa_br0);
342 printk("ar.rsc\t\t%016lx\n", minstate->pmsa_rsc);
343 printk("cr.iip\t\t%016lx ", iip); print_symbol("%s\n", iip);
344 printk("cr.ipsr\t\t%016lx\n", minstate->pmsa_ipsr);
345 printk("cr.ifs\t\t%016lx\n", minstate->pmsa_ifs);
346 printk("xip\t\t%016lx ", xip); print_symbol("%s\n", xip);
347 printk("xpsr\t\t%016lx\n", minstate->pmsa_xpsr);
348 printk("xfs\t\t%016lx\n", minstate->pmsa_xfs);
349 printk("b1\t\t%016lx ", minstate->pmsa_br1);
350 print_symbol("%s\n", minstate->pmsa_br1);
351
352 printk("\nstatic registers r0-r15:\n");
353 printk(" r0- 3 %016lx %016lx %016lx %016lx\n",
354 0UL, minstate->pmsa_gr[0], minstate->pmsa_gr[1], minstate->pmsa_gr[2]);
355 printk(" r4- 7 %016lx %016lx %016lx %016lx\n",
356 minstate->pmsa_gr[3], minstate->pmsa_gr[4],
357 minstate->pmsa_gr[5], minstate->pmsa_gr[6]);
358 printk(" r8-11 %016lx %016lx %016lx %016lx\n",
359 minstate->pmsa_gr[7], minstate->pmsa_gr[8],
360 minstate->pmsa_gr[9], minstate->pmsa_gr[10]);
361 printk("r12-15 %016lx %016lx %016lx %016lx\n",
362 minstate->pmsa_gr[11], minstate->pmsa_gr[12],
363 minstate->pmsa_gr[13], minstate->pmsa_gr[14]);
364
365 printk("\nbank 0:\n");
366 printk("r16-19 %016lx %016lx %016lx %016lx\n",
367 minstate->pmsa_bank0_gr[0], minstate->pmsa_bank0_gr[1],
368 minstate->pmsa_bank0_gr[2], minstate->pmsa_bank0_gr[3]);
369 printk("r20-23 %016lx %016lx %016lx %016lx\n",
370 minstate->pmsa_bank0_gr[4], minstate->pmsa_bank0_gr[5],
371 minstate->pmsa_bank0_gr[6], minstate->pmsa_bank0_gr[7]);
372 printk("r24-27 %016lx %016lx %016lx %016lx\n",
373 minstate->pmsa_bank0_gr[8], minstate->pmsa_bank0_gr[9],
374 minstate->pmsa_bank0_gr[10], minstate->pmsa_bank0_gr[11]);
375 printk("r28-31 %016lx %016lx %016lx %016lx\n",
376 minstate->pmsa_bank0_gr[12], minstate->pmsa_bank0_gr[13],
377 minstate->pmsa_bank0_gr[14], minstate->pmsa_bank0_gr[15]);
378
379 printk("\nbank 1:\n");
380 printk("r16-19 %016lx %016lx %016lx %016lx\n",
381 minstate->pmsa_bank1_gr[0], minstate->pmsa_bank1_gr[1],
382 minstate->pmsa_bank1_gr[2], minstate->pmsa_bank1_gr[3]);
383 printk("r20-23 %016lx %016lx %016lx %016lx\n",
384 minstate->pmsa_bank1_gr[4], minstate->pmsa_bank1_gr[5],
385 minstate->pmsa_bank1_gr[6], minstate->pmsa_bank1_gr[7]);
386 printk("r24-27 %016lx %016lx %016lx %016lx\n",
387 minstate->pmsa_bank1_gr[8], minstate->pmsa_bank1_gr[9],
388 minstate->pmsa_bank1_gr[10], minstate->pmsa_bank1_gr[11]);
389 printk("r28-31 %016lx %016lx %016lx %016lx\n",
390 minstate->pmsa_bank1_gr[12], minstate->pmsa_bank1_gr[13],
391 minstate->pmsa_bank1_gr[14], minstate->pmsa_bank1_gr[15]);
392}
393
394static void
395fetch_min_state (pal_min_state_area_t *ms, struct pt_regs *pt, struct switch_stack *sw)
396{
397 u64 *dst_banked, *src_banked, bit, shift, nat_bits;
398 int i;
399
400 /*
401 * First, update the pt-regs and switch-stack structures with the contents stored
402 * in the min-state area:
403 */
404 if (((struct ia64_psr *) &ms->pmsa_ipsr)->ic == 0) {
405 pt->cr_ipsr = ms->pmsa_xpsr;
406 pt->cr_iip = ms->pmsa_xip;
407 pt->cr_ifs = ms->pmsa_xfs;
408 } else {
409 pt->cr_ipsr = ms->pmsa_ipsr;
410 pt->cr_iip = ms->pmsa_iip;
411 pt->cr_ifs = ms->pmsa_ifs;
412 }
413 pt->ar_rsc = ms->pmsa_rsc;
414 pt->pr = ms->pmsa_pr;
415 pt->r1 = ms->pmsa_gr[0];
416 pt->r2 = ms->pmsa_gr[1];
417 pt->r3 = ms->pmsa_gr[2];
418 sw->r4 = ms->pmsa_gr[3];
419 sw->r5 = ms->pmsa_gr[4];
420 sw->r6 = ms->pmsa_gr[5];
421 sw->r7 = ms->pmsa_gr[6];
422 pt->r8 = ms->pmsa_gr[7];
423 pt->r9 = ms->pmsa_gr[8];
424 pt->r10 = ms->pmsa_gr[9];
425 pt->r11 = ms->pmsa_gr[10];
426 pt->r12 = ms->pmsa_gr[11];
427 pt->r13 = ms->pmsa_gr[12];
428 pt->r14 = ms->pmsa_gr[13];
429 pt->r15 = ms->pmsa_gr[14];
430 dst_banked = &pt->r16; /* r16-r31 are contiguous in struct pt_regs */
431 src_banked = ms->pmsa_bank1_gr;
432 for (i = 0; i < 16; ++i)
433 dst_banked[i] = src_banked[i];
434 pt->b0 = ms->pmsa_br0;
435 sw->b1 = ms->pmsa_br1;
436
437 /* construct the NaT bits for the pt-regs structure: */
438# define PUT_NAT_BIT(dst, addr) \
439 do { \
440 bit = nat_bits & 1; nat_bits >>= 1; \
441 shift = ((unsigned long) addr >> 3) & 0x3f; \
442 dst = ((dst) & ~(1UL << shift)) | (bit << shift); \
443 } while (0)
444
445 /* Rotate the saved NaT bits such that bit 0 corresponds to pmsa_gr[0]: */
446 shift = ((unsigned long) &ms->pmsa_gr[0] >> 3) & 0x3f;
447 nat_bits = (ms->pmsa_nat_bits >> shift) | (ms->pmsa_nat_bits << (64 - shift));
448
449 PUT_NAT_BIT(sw->caller_unat, &pt->r1);
450 PUT_NAT_BIT(sw->caller_unat, &pt->r2);
451 PUT_NAT_BIT(sw->caller_unat, &pt->r3);
452 PUT_NAT_BIT(sw->ar_unat, &sw->r4);
453 PUT_NAT_BIT(sw->ar_unat, &sw->r5);
454 PUT_NAT_BIT(sw->ar_unat, &sw->r6);
455 PUT_NAT_BIT(sw->ar_unat, &sw->r7);
456 PUT_NAT_BIT(sw->caller_unat, &pt->r8); PUT_NAT_BIT(sw->caller_unat, &pt->r9);
457 PUT_NAT_BIT(sw->caller_unat, &pt->r10); PUT_NAT_BIT(sw->caller_unat, &pt->r11);
458 PUT_NAT_BIT(sw->caller_unat, &pt->r12); PUT_NAT_BIT(sw->caller_unat, &pt->r13);
459 PUT_NAT_BIT(sw->caller_unat, &pt->r14); PUT_NAT_BIT(sw->caller_unat, &pt->r15);
460 nat_bits >>= 16; /* skip over bank0 NaT bits */
461 PUT_NAT_BIT(sw->caller_unat, &pt->r16); PUT_NAT_BIT(sw->caller_unat, &pt->r17);
462 PUT_NAT_BIT(sw->caller_unat, &pt->r18); PUT_NAT_BIT(sw->caller_unat, &pt->r19);
463 PUT_NAT_BIT(sw->caller_unat, &pt->r20); PUT_NAT_BIT(sw->caller_unat, &pt->r21);
464 PUT_NAT_BIT(sw->caller_unat, &pt->r22); PUT_NAT_BIT(sw->caller_unat, &pt->r23);
465 PUT_NAT_BIT(sw->caller_unat, &pt->r24); PUT_NAT_BIT(sw->caller_unat, &pt->r25);
466 PUT_NAT_BIT(sw->caller_unat, &pt->r26); PUT_NAT_BIT(sw->caller_unat, &pt->r27);
467 PUT_NAT_BIT(sw->caller_unat, &pt->r28); PUT_NAT_BIT(sw->caller_unat, &pt->r29);
468 PUT_NAT_BIT(sw->caller_unat, &pt->r30); PUT_NAT_BIT(sw->caller_unat, &pt->r31);
469}
470
471static void
472init_handler_platform (pal_min_state_area_t *ms,
473 struct pt_regs *pt, struct switch_stack *sw)
474{
475 struct unw_frame_info info;
476
477 /* if a kernel debugger is available call it here else just dump the registers */
478
479 /*
480 * Wait for a bit. On some machines (e.g., HP's zx2000 and zx6000, INIT can be
481 * generated via the BMC's command-line interface, but since the console is on the
482 * same serial line, the user will need some time to switch out of the BMC before
483 * the dump begins.
484 */
485 printk("Delaying for 5 seconds...\n");
486 udelay(5*1000000);
487 show_min_state(ms);
488
489 printk("Backtrace of current task (pid %d, %s)\n", current->pid, current->comm);
490 fetch_min_state(ms, pt, sw);
491 unw_init_from_interruption(&info, current, pt, sw);
492 ia64_do_show_stack(&info, NULL);
493
494#ifdef CONFIG_SMP
495 /* read_trylock() would be handy... */
496 if (!tasklist_lock.write_lock)
497 read_lock(&tasklist_lock);
498#endif
499 {
500 struct task_struct *g, *t;
501 do_each_thread (g, t) {
502 if (t == current)
503 continue;
504
505 printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm);
506 show_stack(t, NULL);
507 } while_each_thread (g, t);
508 }
509#ifdef CONFIG_SMP
510 if (!tasklist_lock.write_lock)
511 read_unlock(&tasklist_lock);
512#endif
513
514 printk("\nINIT dump complete. Please reboot now.\n");
515 while (1); /* hang city if no debugger */
516}
517
518#ifdef CONFIG_ACPI 339#ifdef CONFIG_ACPI
519/* 340/*
520 * ia64_mca_register_cpev 341 * ia64_mca_register_cpev
@@ -657,42 +478,6 @@ ia64_mca_cmc_vector_enable_keventd(void *unused)
657} 478}
658 479
659/* 480/*
660 * ia64_mca_wakeup_ipi_wait
661 *
662 * Wait for the inter-cpu interrupt to be sent by the
663 * monarch processor once it is done with handling the
664 * MCA.
665 *
666 * Inputs : None
667 * Outputs : None
668 */
669static void
670ia64_mca_wakeup_ipi_wait(void)
671{
672 int irr_num = (IA64_MCA_WAKEUP_VECTOR >> 6);
673 int irr_bit = (IA64_MCA_WAKEUP_VECTOR & 0x3f);
674 u64 irr = 0;
675
676 do {
677 switch(irr_num) {
678 case 0:
679 irr = ia64_getreg(_IA64_REG_CR_IRR0);
680 break;
681 case 1:
682 irr = ia64_getreg(_IA64_REG_CR_IRR1);
683 break;
684 case 2:
685 irr = ia64_getreg(_IA64_REG_CR_IRR2);
686 break;
687 case 3:
688 irr = ia64_getreg(_IA64_REG_CR_IRR3);
689 break;
690 }
691 cpu_relax();
692 } while (!(irr & (1UL << irr_bit))) ;
693}
694
695/*
696 * ia64_mca_wakeup 481 * ia64_mca_wakeup
697 * 482 *
698 * Send an inter-cpu interrupt to wake-up a particular cpu 483 * Send an inter-cpu interrupt to wake-up a particular cpu
@@ -757,11 +542,9 @@ ia64_mca_rendez_int_handler(int rendez_irq, void *arg, struct pt_regs *ptregs)
757 */ 542 */
758 ia64_sal_mc_rendez(); 543 ia64_sal_mc_rendez();
759 544
760 /* Wait for the wakeup IPI from the monarch 545 /* Wait for the monarch cpu to exit. */
761 * This waiting is done by polling on the wakeup-interrupt 546 while (monarch_cpu != -1)
762 * vector bit in the processor's IRRs 547 cpu_relax(); /* spin until monarch leaves */
763 */
764 ia64_mca_wakeup_ipi_wait();
765 548
766 /* Enable all interrupts */ 549 /* Enable all interrupts */
767 local_irq_restore(flags); 550 local_irq_restore(flags);
@@ -789,53 +572,13 @@ ia64_mca_wakeup_int_handler(int wakeup_irq, void *arg, struct pt_regs *ptregs)
789 return IRQ_HANDLED; 572 return IRQ_HANDLED;
790} 573}
791 574
792/*
793 * ia64_return_to_sal_check
794 *
795 * This is function called before going back from the OS_MCA handler
796 * to the OS_MCA dispatch code which finally takes the control back
797 * to the SAL.
798 * The main purpose of this routine is to setup the OS_MCA to SAL
799 * return state which can be used by the OS_MCA dispatch code
800 * just before going back to SAL.
801 *
802 * Inputs : None
803 * Outputs : None
804 */
805
806static void
807ia64_return_to_sal_check(int recover)
808{
809
810 /* Copy over some relevant stuff from the sal_to_os_mca_handoff
811 * so that it can be used at the time of os_mca_to_sal_handoff
812 */
813 ia64_os_to_sal_handoff_state.imots_sal_gp =
814 ia64_sal_to_os_handoff_state.imsto_sal_gp;
815
816 ia64_os_to_sal_handoff_state.imots_sal_check_ra =
817 ia64_sal_to_os_handoff_state.imsto_sal_check_ra;
818
819 if (recover)
820 ia64_os_to_sal_handoff_state.imots_os_status = IA64_MCA_CORRECTED;
821 else
822 ia64_os_to_sal_handoff_state.imots_os_status = IA64_MCA_COLD_BOOT;
823
824 /* Default = tell SAL to return to same context */
825 ia64_os_to_sal_handoff_state.imots_context = IA64_MCA_SAME_CONTEXT;
826
827 ia64_os_to_sal_handoff_state.imots_new_min_state =
828 (u64 *)ia64_sal_to_os_handoff_state.pal_min_state;
829
830}
831
832/* Function pointer for extra MCA recovery */ 575/* Function pointer for extra MCA recovery */
833int (*ia64_mca_ucmc_extension) 576int (*ia64_mca_ucmc_extension)
834 (void*,ia64_mca_sal_to_os_state_t*,ia64_mca_os_to_sal_state_t*) 577 (void*,struct ia64_sal_os_state*)
835 = NULL; 578 = NULL;
836 579
837int 580int
838ia64_reg_MCA_extension(void *fn) 581ia64_reg_MCA_extension(int (*fn)(void *, struct ia64_sal_os_state *))
839{ 582{
840 if (ia64_mca_ucmc_extension) 583 if (ia64_mca_ucmc_extension)
841 return 1; 584 return 1;
@@ -854,8 +597,321 @@ ia64_unreg_MCA_extension(void)
854EXPORT_SYMBOL(ia64_reg_MCA_extension); 597EXPORT_SYMBOL(ia64_reg_MCA_extension);
855EXPORT_SYMBOL(ia64_unreg_MCA_extension); 598EXPORT_SYMBOL(ia64_unreg_MCA_extension);
856 599
600
601static inline void
602copy_reg(const u64 *fr, u64 fnat, u64 *tr, u64 *tnat)
603{
604 u64 fslot, tslot, nat;
605 *tr = *fr;
606 fslot = ((unsigned long)fr >> 3) & 63;
607 tslot = ((unsigned long)tr >> 3) & 63;
608 *tnat &= ~(1UL << tslot);
609 nat = (fnat >> fslot) & 1;
610 *tnat |= (nat << tslot);
611}
612
613/* On entry to this routine, we are running on the per cpu stack, see
614 * mca_asm.h. The original stack has not been touched by this event. Some of
615 * the original stack's registers will be in the RBS on this stack. This stack
616 * also contains a partial pt_regs and switch_stack, the rest of the data is in
617 * PAL minstate.
618 *
619 * The first thing to do is modify the original stack to look like a blocked
620 * task so we can run backtrace on the original task. Also mark the per cpu
621 * stack as current to ensure that we use the correct task state, it also means
622 * that we can do backtrace on the MCA/INIT handler code itself.
623 */
624
625static task_t *
626ia64_mca_modify_original_stack(struct pt_regs *regs,
627 const struct switch_stack *sw,
628 struct ia64_sal_os_state *sos,
629 const char *type)
630{
631 char *p, comm[sizeof(current->comm)];
632 ia64_va va;
633 extern char ia64_leave_kernel[]; /* Need asm address, not function descriptor */
634 const pal_min_state_area_t *ms = sos->pal_min_state;
635 task_t *previous_current;
636 struct pt_regs *old_regs;
637 struct switch_stack *old_sw;
638 unsigned size = sizeof(struct pt_regs) +
639 sizeof(struct switch_stack) + 16;
640 u64 *old_bspstore, *old_bsp;
641 u64 *new_bspstore, *new_bsp;
642 u64 old_unat, old_rnat, new_rnat, nat;
643 u64 slots, loadrs = regs->loadrs;
644 u64 r12 = ms->pmsa_gr[12-1], r13 = ms->pmsa_gr[13-1];
645 u64 ar_bspstore = regs->ar_bspstore;
646 u64 ar_bsp = regs->ar_bspstore + (loadrs >> 16);
647 const u64 *bank;
648 const char *msg;
649 int cpu = smp_processor_id();
650
651 previous_current = curr_task(cpu);
652 set_curr_task(cpu, current);
653 if ((p = strchr(current->comm, ' ')))
654 *p = '\0';
655
656 /* Best effort attempt to cope with MCA/INIT delivered while in
657 * physical mode.
658 */
659 regs->cr_ipsr = ms->pmsa_ipsr;
660 if (ia64_psr(regs)->dt == 0) {
661 va.l = r12;
662 if (va.f.reg == 0) {
663 va.f.reg = 7;
664 r12 = va.l;
665 }
666 va.l = r13;
667 if (va.f.reg == 0) {
668 va.f.reg = 7;
669 r13 = va.l;
670 }
671 }
672 if (ia64_psr(regs)->rt == 0) {
673 va.l = ar_bspstore;
674 if (va.f.reg == 0) {
675 va.f.reg = 7;
676 ar_bspstore = va.l;
677 }
678 va.l = ar_bsp;
679 if (va.f.reg == 0) {
680 va.f.reg = 7;
681 ar_bsp = va.l;
682 }
683 }
684
685 /* mca_asm.S ia64_old_stack() cannot assume that the dirty registers
686 * have been copied to the old stack, the old stack may fail the
687 * validation tests below. So ia64_old_stack() must restore the dirty
688 * registers from the new stack. The old and new bspstore probably
689 * have different alignments, so loadrs calculated on the old bsp
690 * cannot be used to restore from the new bsp. Calculate a suitable
691 * loadrs for the new stack and save it in the new pt_regs, where
692 * ia64_old_stack() can get it.
693 */
694 old_bspstore = (u64 *)ar_bspstore;
695 old_bsp = (u64 *)ar_bsp;
696 slots = ia64_rse_num_regs(old_bspstore, old_bsp);
697 new_bspstore = (u64 *)((u64)current + IA64_RBS_OFFSET);
698 new_bsp = ia64_rse_skip_regs(new_bspstore, slots);
699 regs->loadrs = (new_bsp - new_bspstore) * 8 << 16;
700
701 /* Verify the previous stack state before we change it */
702 if (user_mode(regs)) {
703 msg = "occurred in user space";
704 goto no_mod;
705 }
706 if (r13 != sos->prev_IA64_KR_CURRENT) {
707 msg = "inconsistent previous current and r13";
708 goto no_mod;
709 }
710 if ((r12 - r13) >= KERNEL_STACK_SIZE) {
711 msg = "inconsistent r12 and r13";
712 goto no_mod;
713 }
714 if ((ar_bspstore - r13) >= KERNEL_STACK_SIZE) {
715 msg = "inconsistent ar.bspstore and r13";
716 goto no_mod;
717 }
718 va.p = old_bspstore;
719 if (va.f.reg < 5) {
720 msg = "old_bspstore is in the wrong region";
721 goto no_mod;
722 }
723 if ((ar_bsp - r13) >= KERNEL_STACK_SIZE) {
724 msg = "inconsistent ar.bsp and r13";
725 goto no_mod;
726 }
727 size += (ia64_rse_skip_regs(old_bspstore, slots) - old_bspstore) * 8;
728 if (ar_bspstore + size > r12) {
729 msg = "no room for blocked state";
730 goto no_mod;
731 }
732
733 /* Change the comm field on the MCA/INT task to include the pid that
734 * was interrupted, it makes for easier debugging. If that pid was 0
735 * (swapper or nested MCA/INIT) then use the start of the previous comm
736 * field suffixed with its cpu.
737 */
738 if (previous_current->pid)
739 snprintf(comm, sizeof(comm), "%s %d",
740 current->comm, previous_current->pid);
741 else {
742 int l;
743 if ((p = strchr(previous_current->comm, ' ')))
744 l = p - previous_current->comm;
745 else
746 l = strlen(previous_current->comm);
747 snprintf(comm, sizeof(comm), "%s %*s %d",
748 current->comm, l, previous_current->comm,
749 previous_current->thread_info->cpu);
750 }
751 memcpy(current->comm, comm, sizeof(current->comm));
752
753 /* Make the original task look blocked. First stack a struct pt_regs,
754 * describing the state at the time of interrupt. mca_asm.S built a
755 * partial pt_regs, copy it and fill in the blanks using minstate.
756 */
757 p = (char *)r12 - sizeof(*regs);
758 old_regs = (struct pt_regs *)p;
759 memcpy(old_regs, regs, sizeof(*regs));
760 /* If ipsr.ic then use pmsa_{iip,ipsr,ifs}, else use
761 * pmsa_{xip,xpsr,xfs}
762 */
763 if (ia64_psr(regs)->ic) {
764 old_regs->cr_iip = ms->pmsa_iip;
765 old_regs->cr_ipsr = ms->pmsa_ipsr;
766 old_regs->cr_ifs = ms->pmsa_ifs;
767 } else {
768 old_regs->cr_iip = ms->pmsa_xip;
769 old_regs->cr_ipsr = ms->pmsa_xpsr;
770 old_regs->cr_ifs = ms->pmsa_xfs;
771 }
772 old_regs->pr = ms->pmsa_pr;
773 old_regs->b0 = ms->pmsa_br0;
774 old_regs->loadrs = loadrs;
775 old_regs->ar_rsc = ms->pmsa_rsc;
776 old_unat = old_regs->ar_unat;
777 copy_reg(&ms->pmsa_gr[1-1], ms->pmsa_nat_bits, &old_regs->r1, &old_unat);
778 copy_reg(&ms->pmsa_gr[2-1], ms->pmsa_nat_bits, &old_regs->r2, &old_unat);
779 copy_reg(&ms->pmsa_gr[3-1], ms->pmsa_nat_bits, &old_regs->r3, &old_unat);
780 copy_reg(&ms->pmsa_gr[8-1], ms->pmsa_nat_bits, &old_regs->r8, &old_unat);
781 copy_reg(&ms->pmsa_gr[9-1], ms->pmsa_nat_bits, &old_regs->r9, &old_unat);
782 copy_reg(&ms->pmsa_gr[10-1], ms->pmsa_nat_bits, &old_regs->r10, &old_unat);
783 copy_reg(&ms->pmsa_gr[11-1], ms->pmsa_nat_bits, &old_regs->r11, &old_unat);
784 copy_reg(&ms->pmsa_gr[12-1], ms->pmsa_nat_bits, &old_regs->r12, &old_unat);
785 copy_reg(&ms->pmsa_gr[13-1], ms->pmsa_nat_bits, &old_regs->r13, &old_unat);
786 copy_reg(&ms->pmsa_gr[14-1], ms->pmsa_nat_bits, &old_regs->r14, &old_unat);
787 copy_reg(&ms->pmsa_gr[15-1], ms->pmsa_nat_bits, &old_regs->r15, &old_unat);
788 if (ia64_psr(old_regs)->bn)
789 bank = ms->pmsa_bank1_gr;
790 else
791 bank = ms->pmsa_bank0_gr;
792 copy_reg(&bank[16-16], ms->pmsa_nat_bits, &old_regs->r16, &old_unat);
793 copy_reg(&bank[17-16], ms->pmsa_nat_bits, &old_regs->r17, &old_unat);
794 copy_reg(&bank[18-16], ms->pmsa_nat_bits, &old_regs->r18, &old_unat);
795 copy_reg(&bank[19-16], ms->pmsa_nat_bits, &old_regs->r19, &old_unat);
796 copy_reg(&bank[20-16], ms->pmsa_nat_bits, &old_regs->r20, &old_unat);
797 copy_reg(&bank[21-16], ms->pmsa_nat_bits, &old_regs->r21, &old_unat);
798 copy_reg(&bank[22-16], ms->pmsa_nat_bits, &old_regs->r22, &old_unat);
799 copy_reg(&bank[23-16], ms->pmsa_nat_bits, &old_regs->r23, &old_unat);
800 copy_reg(&bank[24-16], ms->pmsa_nat_bits, &old_regs->r24, &old_unat);
801 copy_reg(&bank[25-16], ms->pmsa_nat_bits, &old_regs->r25, &old_unat);
802 copy_reg(&bank[26-16], ms->pmsa_nat_bits, &old_regs->r26, &old_unat);
803 copy_reg(&bank[27-16], ms->pmsa_nat_bits, &old_regs->r27, &old_unat);
804 copy_reg(&bank[28-16], ms->pmsa_nat_bits, &old_regs->r28, &old_unat);
805 copy_reg(&bank[29-16], ms->pmsa_nat_bits, &old_regs->r29, &old_unat);
806 copy_reg(&bank[30-16], ms->pmsa_nat_bits, &old_regs->r30, &old_unat);
807 copy_reg(&bank[31-16], ms->pmsa_nat_bits, &old_regs->r31, &old_unat);
808
809 /* Next stack a struct switch_stack. mca_asm.S built a partial
810 * switch_stack, copy it and fill in the blanks using pt_regs and
811 * minstate.
812 *
813 * In the synthesized switch_stack, b0 points to ia64_leave_kernel,
814 * ar.pfs is set to 0.
815 *
816 * unwind.c::unw_unwind() does special processing for interrupt frames.
817 * It checks if the PRED_NON_SYSCALL predicate is set, if the predicate
818 * is clear then unw_unwind() does _not_ adjust bsp over pt_regs. Not
819 * that this is documented, of course. Set PRED_NON_SYSCALL in the
820 * switch_stack on the original stack so it will unwind correctly when
821 * unwind.c reads pt_regs.
822 *
823 * thread.ksp is updated to point to the synthesized switch_stack.
824 */
825 p -= sizeof(struct switch_stack);
826 old_sw = (struct switch_stack *)p;
827 memcpy(old_sw, sw, sizeof(*sw));
828 old_sw->caller_unat = old_unat;
829 old_sw->ar_fpsr = old_regs->ar_fpsr;
830 copy_reg(&ms->pmsa_gr[4-1], ms->pmsa_nat_bits, &old_sw->r4, &old_unat);
831 copy_reg(&ms->pmsa_gr[5-1], ms->pmsa_nat_bits, &old_sw->r5, &old_unat);
832 copy_reg(&ms->pmsa_gr[6-1], ms->pmsa_nat_bits, &old_sw->r6, &old_unat);
833 copy_reg(&ms->pmsa_gr[7-1], ms->pmsa_nat_bits, &old_sw->r7, &old_unat);
834 old_sw->b0 = (u64)ia64_leave_kernel;
835 old_sw->b1 = ms->pmsa_br1;
836 old_sw->ar_pfs = 0;
837 old_sw->ar_unat = old_unat;
838 old_sw->pr = old_regs->pr | (1UL << PRED_NON_SYSCALL);
839 previous_current->thread.ksp = (u64)p - 16;
840
841 /* Finally copy the original stack's registers back to its RBS.
842 * Registers from ar.bspstore through ar.bsp at the time of the event
843 * are in the current RBS, copy them back to the original stack. The
844 * copy must be done register by register because the original bspstore
845 * and the current one have different alignments, so the saved RNAT
846 * data occurs at different places.
847 *
848 * mca_asm does cover, so the old_bsp already includes all registers at
849 * the time of MCA/INIT. It also does flushrs, so all registers before
850 * this function have been written to backing store on the MCA/INIT
851 * stack.
852 */
853 new_rnat = ia64_get_rnat(ia64_rse_rnat_addr(new_bspstore));
854 old_rnat = regs->ar_rnat;
855 while (slots--) {
856 if (ia64_rse_is_rnat_slot(new_bspstore)) {
857 new_rnat = ia64_get_rnat(new_bspstore++);
858 }
859 if (ia64_rse_is_rnat_slot(old_bspstore)) {
860 *old_bspstore++ = old_rnat;
861 old_rnat = 0;
862 }
863 nat = (new_rnat >> ia64_rse_slot_num(new_bspstore)) & 1UL;
864 old_rnat &= ~(1UL << ia64_rse_slot_num(old_bspstore));
865 old_rnat |= (nat << ia64_rse_slot_num(old_bspstore));
866 *old_bspstore++ = *new_bspstore++;
867 }
868 old_sw->ar_bspstore = (unsigned long)old_bspstore;
869 old_sw->ar_rnat = old_rnat;
870
871 sos->prev_task = previous_current;
872 return previous_current;
873
874no_mod:
875 printk(KERN_INFO "cpu %d, %s %s, original stack not modified\n",
876 smp_processor_id(), type, msg);
877 return previous_current;
878}
879
880/* The monarch/slave interaction is based on monarch_cpu and requires that all
881 * slaves have entered rendezvous before the monarch leaves. If any cpu has
882 * not entered rendezvous yet then wait a bit. The assumption is that any
883 * slave that has not rendezvoused after a reasonable time is never going to do
884 * so. In this context, slave includes cpus that respond to the MCA rendezvous
885 * interrupt, as well as cpus that receive the INIT slave event.
886 */
887
888static void
889ia64_wait_for_slaves(int monarch)
890{
891 int c, wait = 0;
892 for_each_online_cpu(c) {
893 if (c == monarch)
894 continue;
895 if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) {
896 udelay(1000); /* short wait first */
897 wait = 1;
898 break;
899 }
900 }
901 if (!wait)
902 return;
903 for_each_online_cpu(c) {
904 if (c == monarch)
905 continue;
906 if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) {
907 udelay(5*1000000); /* wait 5 seconds for slaves (arbitrary) */
908 break;
909 }
910 }
911}
912
857/* 913/*
858 * ia64_mca_ucmc_handler 914 * ia64_mca_handler
859 * 915 *
860 * This is uncorrectable machine check handler called from OS_MCA 916 * This is uncorrectable machine check handler called from OS_MCA
861 * dispatch code which is in turn called from SAL_CHECK(). 917 * dispatch code which is in turn called from SAL_CHECK().
@@ -866,16 +922,28 @@ EXPORT_SYMBOL(ia64_unreg_MCA_extension);
866 * further MCA logging is enabled by clearing logs. 922 * further MCA logging is enabled by clearing logs.
867 * Monarch also has the duty of sending wakeup-IPIs to pull the 923 * Monarch also has the duty of sending wakeup-IPIs to pull the
868 * slave processors out of rendezvous spinloop. 924 * slave processors out of rendezvous spinloop.
869 *
870 * Inputs : None
871 * Outputs : None
872 */ 925 */
873void 926void
874ia64_mca_ucmc_handler(void) 927ia64_mca_handler(struct pt_regs *regs, struct switch_stack *sw,
928 struct ia64_sal_os_state *sos)
875{ 929{
876 pal_processor_state_info_t *psp = (pal_processor_state_info_t *) 930 pal_processor_state_info_t *psp = (pal_processor_state_info_t *)
877 &ia64_sal_to_os_handoff_state.proc_state_param; 931 &sos->proc_state_param;
878 int recover; 932 int recover, cpu = smp_processor_id();
933 task_t *previous_current;
934
935 oops_in_progress = 1; /* FIXME: make printk NMI/MCA/INIT safe */
936 previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "MCA");
937 monarch_cpu = cpu;
938 ia64_wait_for_slaves(cpu);
939
940 /* Wakeup all the processors which are spinning in the rendezvous loop.
941 * They will leave SAL, then spin in the OS with interrupts disabled
942 * until this monarch cpu leaves the MCA handler. That gets control
943 * back to the OS so we can backtrace the other cpus, backtrace when
944 * spinning in SAL does not work.
945 */
946 ia64_mca_wakeup_all();
879 947
880 /* Get the MCA error record and log it */ 948 /* Get the MCA error record and log it */
881 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA); 949 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA);
@@ -883,25 +951,20 @@ ia64_mca_ucmc_handler(void)
883 /* TLB error is only exist in this SAL error record */ 951 /* TLB error is only exist in this SAL error record */
884 recover = (psp->tc && !(psp->cc || psp->bc || psp->rc || psp->uc)) 952 recover = (psp->tc && !(psp->cc || psp->bc || psp->rc || psp->uc))
885 /* other error recovery */ 953 /* other error recovery */
886 || (ia64_mca_ucmc_extension 954 || (ia64_mca_ucmc_extension
887 && ia64_mca_ucmc_extension( 955 && ia64_mca_ucmc_extension(
888 IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA), 956 IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA),
889 &ia64_sal_to_os_handoff_state, 957 sos));
890 &ia64_os_to_sal_handoff_state));
891 958
892 if (recover) { 959 if (recover) {
893 sal_log_record_header_t *rh = IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA); 960 sal_log_record_header_t *rh = IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA);
894 rh->severity = sal_log_severity_corrected; 961 rh->severity = sal_log_severity_corrected;
895 ia64_sal_clear_state_info(SAL_INFO_TYPE_MCA); 962 ia64_sal_clear_state_info(SAL_INFO_TYPE_MCA);
963 sos->os_status = IA64_MCA_CORRECTED;
896 } 964 }
897 /*
898 * Wakeup all the processors which are spinning in the rendezvous
899 * loop.
900 */
901 ia64_mca_wakeup_all();
902 965
903 /* Return to SAL */ 966 set_curr_task(cpu, previous_current);
904 ia64_return_to_sal_check(recover); 967 monarch_cpu = -1;
905} 968}
906 969
907static DECLARE_WORK(cmc_disable_work, ia64_mca_cmc_vector_disable_keventd, NULL); 970static DECLARE_WORK(cmc_disable_work, ia64_mca_cmc_vector_disable_keventd, NULL);
@@ -1125,34 +1188,114 @@ ia64_mca_cpe_poll (unsigned long dummy)
1125/* 1188/*
1126 * C portion of the OS INIT handler 1189 * C portion of the OS INIT handler
1127 * 1190 *
1128 * Called from ia64_monarch_init_handler 1191 * Called from ia64_os_init_dispatch
1129 *
1130 * Inputs: pointer to pt_regs where processor info was saved.
1131 * 1192 *
1132 * Returns: 1193 * Inputs: pointer to pt_regs where processor info was saved. SAL/OS state for
1133 * 0 if SAL must warm boot the System 1194 * this event. This code is used for both monarch and slave INIT events, see
1134 * 1 if SAL must return to interrupted context using PAL_MC_RESUME 1195 * sos->monarch.
1135 * 1196 *
1197 * All INIT events switch to the INIT stack and change the previous process to
1198 * blocked status. If one of the INIT events is the monarch then we are
1199 * probably processing the nmi button/command. Use the monarch cpu to dump all
1200 * the processes. The slave INIT events all spin until the monarch cpu
1201 * returns. We can also get INIT slave events for MCA, in which case the MCA
1202 * process is the monarch.
1136 */ 1203 */
1204
1137void 1205void
1138ia64_init_handler (struct pt_regs *pt, struct switch_stack *sw) 1206ia64_init_handler(struct pt_regs *regs, struct switch_stack *sw,
1207 struct ia64_sal_os_state *sos)
1139{ 1208{
1140 pal_min_state_area_t *ms; 1209 static atomic_t slaves;
1210 static atomic_t monarchs;
1211 task_t *previous_current;
1212 int cpu = smp_processor_id(), c;
1213 struct task_struct *g, *t;
1141 1214
1142 oops_in_progress = 1; /* avoid deadlock in printk, but it makes recovery dodgy */ 1215 oops_in_progress = 1; /* FIXME: make printk NMI/MCA/INIT safe */
1143 console_loglevel = 15; /* make sure printks make it to console */ 1216 console_loglevel = 15; /* make sure printks make it to console */
1144 1217
1145 printk(KERN_INFO "Entered OS INIT handler. PSP=%lx\n", 1218 printk(KERN_INFO "Entered OS INIT handler. PSP=%lx cpu=%d monarch=%ld\n",
1146 ia64_sal_to_os_handoff_state.proc_state_param); 1219 sos->proc_state_param, cpu, sos->monarch);
1220 salinfo_log_wakeup(SAL_INFO_TYPE_INIT, NULL, 0, 0);
1147 1221
1148 /* 1222 previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "INIT");
1149 * Address of minstate area provided by PAL is physical, 1223 sos->os_status = IA64_INIT_RESUME;
1150 * uncacheable (bit 63 set). Convert to Linux virtual 1224
1151 * address in region 6. 1225 /* FIXME: Workaround for broken proms that drive all INIT events as
1226 * slaves. The last slave that enters is promoted to be a monarch.
1227 * Remove this code in September 2006, that gives platforms a year to
1228 * fix their proms and get their customers updated.
1152 */ 1229 */
1153 ms = (pal_min_state_area_t *)(ia64_sal_to_os_handoff_state.pal_min_state | (6ul<<61)); 1230 if (!sos->monarch && atomic_add_return(1, &slaves) == num_online_cpus()) {
1231 printk(KERN_WARNING "%s: Promoting cpu %d to monarch.\n",
1232 __FUNCTION__, cpu);
1233 atomic_dec(&slaves);
1234 sos->monarch = 1;
1235 }
1236
1237 /* FIXME: Workaround for broken proms that drive all INIT events as
1238 * monarchs. Second and subsequent monarchs are demoted to slaves.
1239 * Remove this code in September 2006, that gives platforms a year to
1240 * fix their proms and get their customers updated.
1241 */
1242 if (sos->monarch && atomic_add_return(1, &monarchs) > 1) {
1243 printk(KERN_WARNING "%s: Demoting cpu %d to slave.\n",
1244 __FUNCTION__, cpu);
1245 atomic_dec(&monarchs);
1246 sos->monarch = 0;
1247 }
1154 1248
1155 init_handler_platform(ms, pt, sw); /* call platform specific routines */ 1249 if (!sos->monarch) {
1250 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_INIT;
1251 while (monarch_cpu == -1)
1252 cpu_relax(); /* spin until monarch enters */
1253 while (monarch_cpu != -1)
1254 cpu_relax(); /* spin until monarch leaves */
1255 printk("Slave on cpu %d returning to normal service.\n", cpu);
1256 set_curr_task(cpu, previous_current);
1257 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
1258 atomic_dec(&slaves);
1259 return;
1260 }
1261
1262 monarch_cpu = cpu;
1263
1264 /*
1265 * Wait for a bit. On some machines (e.g., HP's zx2000 and zx6000, INIT can be
1266 * generated via the BMC's command-line interface, but since the console is on the
1267 * same serial line, the user will need some time to switch out of the BMC before
1268 * the dump begins.
1269 */
1270 printk("Delaying for 5 seconds...\n");
1271 udelay(5*1000000);
1272 ia64_wait_for_slaves(cpu);
1273 printk(KERN_ERR "Processes interrupted by INIT -");
1274 for_each_online_cpu(c) {
1275 struct ia64_sal_os_state *s;
1276 t = __va(__per_cpu_mca[c] + IA64_MCA_CPU_INIT_STACK_OFFSET);
1277 s = (struct ia64_sal_os_state *)((char *)t + MCA_SOS_OFFSET);
1278 g = s->prev_task;
1279 if (g) {
1280 if (g->pid)
1281 printk(" %d", g->pid);
1282 else
1283 printk(" %d (cpu %d task 0x%p)", g->pid, task_cpu(g), g);
1284 }
1285 }
1286 printk("\n\n");
1287 if (read_trylock(&tasklist_lock)) {
1288 do_each_thread (g, t) {
1289 printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm);
1290 show_stack(t, NULL);
1291 } while_each_thread (g, t);
1292 read_unlock(&tasklist_lock);
1293 }
1294 printk("\nINIT dump complete. Monarch on cpu %d returning to normal service.\n", cpu);
1295 atomic_dec(&monarchs);
1296 set_curr_task(cpu, previous_current);
1297 monarch_cpu = -1;
1298 return;
1156} 1299}
1157 1300
1158static int __init 1301static int __init
@@ -1202,6 +1345,34 @@ static struct irqaction mca_cpep_irqaction = {
1202}; 1345};
1203#endif /* CONFIG_ACPI */ 1346#endif /* CONFIG_ACPI */
1204 1347
1348/* Minimal format of the MCA/INIT stacks. The pseudo processes that run on
1349 * these stacks can never sleep, they cannot return from the kernel to user
1350 * space, they do not appear in a normal ps listing. So there is no need to
1351 * format most of the fields.
1352 */
1353
1354static void
1355format_mca_init_stack(void *mca_data, unsigned long offset,
1356 const char *type, int cpu)
1357{
1358 struct task_struct *p = (struct task_struct *)((char *)mca_data + offset);
1359 struct thread_info *ti;
1360 memset(p, 0, KERNEL_STACK_SIZE);
1361 ti = (struct thread_info *)((char *)p + IA64_TASK_SIZE);
1362 ti->flags = _TIF_MCA_INIT;
1363 ti->preempt_count = 1;
1364 ti->task = p;
1365 ti->cpu = cpu;
1366 p->thread_info = ti;
1367 p->state = TASK_UNINTERRUPTIBLE;
1368 __set_bit(cpu, &p->cpus_allowed);
1369 INIT_LIST_HEAD(&p->tasks);
1370 p->parent = p->real_parent = p->group_leader = p;
1371 INIT_LIST_HEAD(&p->children);
1372 INIT_LIST_HEAD(&p->sibling);
1373 strncpy(p->comm, type, sizeof(p->comm)-1);
1374}
1375
1205/* Do per-CPU MCA-related initialization. */ 1376/* Do per-CPU MCA-related initialization. */
1206 1377
1207void __devinit 1378void __devinit
@@ -1214,19 +1385,28 @@ ia64_mca_cpu_init(void *cpu_data)
1214 int cpu; 1385 int cpu;
1215 1386
1216 mca_data = alloc_bootmem(sizeof(struct ia64_mca_cpu) 1387 mca_data = alloc_bootmem(sizeof(struct ia64_mca_cpu)
1217 * NR_CPUS); 1388 * NR_CPUS + KERNEL_STACK_SIZE);
1389 mca_data = (void *)(((unsigned long)mca_data +
1390 KERNEL_STACK_SIZE - 1) &
1391 (-KERNEL_STACK_SIZE));
1218 for (cpu = 0; cpu < NR_CPUS; cpu++) { 1392 for (cpu = 0; cpu < NR_CPUS; cpu++) {
1393 format_mca_init_stack(mca_data,
1394 offsetof(struct ia64_mca_cpu, mca_stack),
1395 "MCA", cpu);
1396 format_mca_init_stack(mca_data,
1397 offsetof(struct ia64_mca_cpu, init_stack),
1398 "INIT", cpu);
1219 __per_cpu_mca[cpu] = __pa(mca_data); 1399 __per_cpu_mca[cpu] = __pa(mca_data);
1220 mca_data += sizeof(struct ia64_mca_cpu); 1400 mca_data += sizeof(struct ia64_mca_cpu);
1221 } 1401 }
1222 } 1402 }
1223 1403
1224 /* 1404 /*
1225 * The MCA info structure was allocated earlier and its 1405 * The MCA info structure was allocated earlier and its
1226 * physical address saved in __per_cpu_mca[cpu]. Copy that 1406 * physical address saved in __per_cpu_mca[cpu]. Copy that
1227 * address * to ia64_mca_data so we can access it as a per-CPU 1407 * address * to ia64_mca_data so we can access it as a per-CPU
1228 * variable. 1408 * variable.
1229 */ 1409 */
1230 __get_cpu_var(ia64_mca_data) = __per_cpu_mca[smp_processor_id()]; 1410 __get_cpu_var(ia64_mca_data) = __per_cpu_mca[smp_processor_id()];
1231 1411
1232 /* 1412 /*
@@ -1236,11 +1416,11 @@ ia64_mca_cpu_init(void *cpu_data)
1236 __get_cpu_var(ia64_mca_per_cpu_pte) = 1416 __get_cpu_var(ia64_mca_per_cpu_pte) =
1237 pte_val(mk_pte_phys(__pa(cpu_data), PAGE_KERNEL)); 1417 pte_val(mk_pte_phys(__pa(cpu_data), PAGE_KERNEL));
1238 1418
1239 /* 1419 /*
1240 * Also, stash away a copy of the PAL address and the PTE 1420 * Also, stash away a copy of the PAL address and the PTE
1241 * needed to map it. 1421 * needed to map it.
1242 */ 1422 */
1243 pal_vaddr = efi_get_pal_addr(); 1423 pal_vaddr = efi_get_pal_addr();
1244 if (!pal_vaddr) 1424 if (!pal_vaddr)
1245 return; 1425 return;
1246 __get_cpu_var(ia64_mca_pal_base) = 1426 __get_cpu_var(ia64_mca_pal_base) =
@@ -1272,8 +1452,8 @@ ia64_mca_cpu_init(void *cpu_data)
1272void __init 1452void __init
1273ia64_mca_init(void) 1453ia64_mca_init(void)
1274{ 1454{
1275 ia64_fptr_t *mon_init_ptr = (ia64_fptr_t *)ia64_monarch_init_handler; 1455 ia64_fptr_t *init_hldlr_ptr_monarch = (ia64_fptr_t *)ia64_os_init_dispatch_monarch;
1276 ia64_fptr_t *slave_init_ptr = (ia64_fptr_t *)ia64_slave_init_handler; 1456 ia64_fptr_t *init_hldlr_ptr_slave = (ia64_fptr_t *)ia64_os_init_dispatch_slave;
1277 ia64_fptr_t *mca_hldlr_ptr = (ia64_fptr_t *)ia64_os_mca_dispatch; 1457 ia64_fptr_t *mca_hldlr_ptr = (ia64_fptr_t *)ia64_os_mca_dispatch;
1278 int i; 1458 int i;
1279 s64 rc; 1459 s64 rc;
@@ -1351,9 +1531,9 @@ ia64_mca_init(void)
1351 * XXX - disable SAL checksum by setting size to 0, should be 1531 * XXX - disable SAL checksum by setting size to 0, should be
1352 * size of the actual init handler in mca_asm.S. 1532 * size of the actual init handler in mca_asm.S.
1353 */ 1533 */
1354 ia64_mc_info.imi_monarch_init_handler = ia64_tpa(mon_init_ptr->fp); 1534 ia64_mc_info.imi_monarch_init_handler = ia64_tpa(init_hldlr_ptr_monarch->fp);
1355 ia64_mc_info.imi_monarch_init_handler_size = 0; 1535 ia64_mc_info.imi_monarch_init_handler_size = 0;
1356 ia64_mc_info.imi_slave_init_handler = ia64_tpa(slave_init_ptr->fp); 1536 ia64_mc_info.imi_slave_init_handler = ia64_tpa(init_hldlr_ptr_slave->fp);
1357 ia64_mc_info.imi_slave_init_handler_size = 0; 1537 ia64_mc_info.imi_slave_init_handler_size = 0;
1358 1538
1359 IA64_MCA_DEBUG("%s: OS INIT handler at %lx\n", __FUNCTION__, 1539 IA64_MCA_DEBUG("%s: OS INIT handler at %lx\n", __FUNCTION__,
diff --git a/arch/ia64/kernel/mca_asm.S b/arch/ia64/kernel/mca_asm.S
index ef3fd7265b..499a065f4e 100644
--- a/arch/ia64/kernel/mca_asm.S
+++ b/arch/ia64/kernel/mca_asm.S
@@ -16,6 +16,9 @@
16// 04/11/12 Russ Anderson <rja@sgi.com> 16// 04/11/12 Russ Anderson <rja@sgi.com>
17// Added per cpu MCA/INIT stack save areas. 17// Added per cpu MCA/INIT stack save areas.
18// 18//
19// 12/08/05 Keith Owens <kaos@sgi.com>
20// Use per cpu MCA/INIT stacks for all data.
21//
19#include <linux/config.h> 22#include <linux/config.h>
20#include <linux/threads.h> 23#include <linux/threads.h>
21 24
@@ -25,96 +28,23 @@
25#include <asm/mca_asm.h> 28#include <asm/mca_asm.h>
26#include <asm/mca.h> 29#include <asm/mca.h>
27 30
28/* 31#include "entry.h"
29 * When we get a machine check, the kernel stack pointer is no longer
30 * valid, so we need to set a new stack pointer.
31 */
32#define MINSTATE_PHYS /* Make sure stack access is physical for MINSTATE */
33
34/*
35 * Needed for return context to SAL
36 */
37#define IA64_MCA_SAME_CONTEXT 0
38#define IA64_MCA_COLD_BOOT -2
39
40#include "minstate.h"
41
42/*
43 * SAL_TO_OS_MCA_HANDOFF_STATE (SAL 3.0 spec)
44 * 1. GR1 = OS GP
45 * 2. GR8 = PAL_PROC physical address
46 * 3. GR9 = SAL_PROC physical address
47 * 4. GR10 = SAL GP (physical)
48 * 5. GR11 = Rendez state
49 * 6. GR12 = Return address to location within SAL_CHECK
50 */
51#define SAL_TO_OS_MCA_HANDOFF_STATE_SAVE(_tmp) \
52 LOAD_PHYSICAL(p0, _tmp, ia64_sal_to_os_handoff_state);; \
53 st8 [_tmp]=r1,0x08;; \
54 st8 [_tmp]=r8,0x08;; \
55 st8 [_tmp]=r9,0x08;; \
56 st8 [_tmp]=r10,0x08;; \
57 st8 [_tmp]=r11,0x08;; \
58 st8 [_tmp]=r12,0x08;; \
59 st8 [_tmp]=r17,0x08;; \
60 st8 [_tmp]=r18,0x08
61
62/*
63 * OS_MCA_TO_SAL_HANDOFF_STATE (SAL 3.0 spec)
64 * (p6) is executed if we never entered virtual mode (TLB error)
65 * (p7) is executed if we entered virtual mode as expected (normal case)
66 * 1. GR8 = OS_MCA return status
67 * 2. GR9 = SAL GP (physical)
68 * 3. GR10 = 0/1 returning same/new context
69 * 4. GR22 = New min state save area pointer
70 * returns ptr to SAL rtn save loc in _tmp
71 */
72#define OS_MCA_TO_SAL_HANDOFF_STATE_RESTORE(_tmp) \
73 movl _tmp=ia64_os_to_sal_handoff_state;; \
74 DATA_VA_TO_PA(_tmp);; \
75 ld8 r8=[_tmp],0x08;; \
76 ld8 r9=[_tmp],0x08;; \
77 ld8 r10=[_tmp],0x08;; \
78 ld8 r22=[_tmp],0x08;;
79 // now _tmp is pointing to SAL rtn save location
80
81/*
82 * COLD_BOOT_HANDOFF_STATE() sets ia64_mca_os_to_sal_state
83 * imots_os_status=IA64_MCA_COLD_BOOT
84 * imots_sal_gp=SAL GP
85 * imots_context=IA64_MCA_SAME_CONTEXT
86 * imots_new_min_state=Min state save area pointer
87 * imots_sal_check_ra=Return address to location within SAL_CHECK
88 *
89 */
90#define COLD_BOOT_HANDOFF_STATE(sal_to_os_handoff,os_to_sal_handoff,tmp)\
91 movl tmp=IA64_MCA_COLD_BOOT; \
92 movl sal_to_os_handoff=__pa(ia64_sal_to_os_handoff_state); \
93 movl os_to_sal_handoff=__pa(ia64_os_to_sal_handoff_state);; \
94 st8 [os_to_sal_handoff]=tmp,8;; \
95 ld8 tmp=[sal_to_os_handoff],48;; \
96 st8 [os_to_sal_handoff]=tmp,8;; \
97 movl tmp=IA64_MCA_SAME_CONTEXT;; \
98 st8 [os_to_sal_handoff]=tmp,8;; \
99 ld8 tmp=[sal_to_os_handoff],-8;; \
100 st8 [os_to_sal_handoff]=tmp,8;; \
101 ld8 tmp=[sal_to_os_handoff];; \
102 st8 [os_to_sal_handoff]=tmp;;
103 32
104#define GET_IA64_MCA_DATA(reg) \ 33#define GET_IA64_MCA_DATA(reg) \
105 GET_THIS_PADDR(reg, ia64_mca_data) \ 34 GET_THIS_PADDR(reg, ia64_mca_data) \
106 ;; \ 35 ;; \
107 ld8 reg=[reg] 36 ld8 reg=[reg]
108 37
109 .global ia64_os_mca_dispatch
110 .global ia64_os_mca_dispatch_end
111 .global ia64_sal_to_os_handoff_state
112 .global ia64_os_to_sal_handoff_state
113 .global ia64_do_tlb_purge 38 .global ia64_do_tlb_purge
39 .global ia64_os_mca_dispatch
40 .global ia64_os_init_dispatch_monarch
41 .global ia64_os_init_dispatch_slave
114 42
115 .text 43 .text
116 .align 16 44 .align 16
117 45
46//StartMain////////////////////////////////////////////////////////////////////
47
118/* 48/*
119 * Just the TLB purge part is moved to a separate function 49 * Just the TLB purge part is moved to a separate function
120 * so we can re-use the code for cpu hotplug code as well 50 * so we can re-use the code for cpu hotplug code as well
@@ -207,34 +137,31 @@ ia64_do_tlb_purge:
207 br.sptk.many b1 137 br.sptk.many b1
208 ;; 138 ;;
209 139
210ia64_os_mca_dispatch: 140//EndMain//////////////////////////////////////////////////////////////////////
141
142//StartMain////////////////////////////////////////////////////////////////////
211 143
144ia64_os_mca_dispatch:
212 // Serialize all MCA processing 145 // Serialize all MCA processing
213 mov r3=1;; 146 mov r3=1;;
214 LOAD_PHYSICAL(p0,r2,ia64_mca_serialize);; 147 LOAD_PHYSICAL(p0,r2,ia64_mca_serialize);;
215ia64_os_mca_spin: 148ia64_os_mca_spin:
216 xchg8 r4=[r2],r3;; 149 xchg4 r4=[r2],r3;;
217 cmp.ne p6,p0=r4,r0 150 cmp.ne p6,p0=r4,r0
218(p6) br ia64_os_mca_spin 151(p6) br ia64_os_mca_spin
219 152
220 // Save the SAL to OS MCA handoff state as defined 153 mov r3=IA64_MCA_CPU_MCA_STACK_OFFSET // use the MCA stack
221 // by SAL SPEC 3.0 154 LOAD_PHYSICAL(p0,r2,1f) // return address
222 // NOTE : The order in which the state gets saved 155 mov r19=1 // All MCA events are treated as monarch (for now)
223 // is dependent on the way the C-structure 156 br.sptk ia64_state_save // save the state that is not in minstate
224 // for ia64_mca_sal_to_os_state_t has been 1571:
225 // defined in include/asm/mca.h
226 SAL_TO_OS_MCA_HANDOFF_STATE_SAVE(r2)
227 ;;
228
229 // LOG PROCESSOR STATE INFO FROM HERE ON..
230begin_os_mca_dump:
231 br ia64_os_mca_proc_state_dump;;
232 158
233ia64_os_mca_done_dump: 159 GET_IA64_MCA_DATA(r2)
234 160 // Using MCA stack, struct ia64_sal_os_state, variable proc_state_param
235 LOAD_PHYSICAL(p0,r16,ia64_sal_to_os_handoff_state+56) 161 ;;
162 add r3=IA64_MCA_CPU_MCA_STACK_OFFSET+MCA_SOS_OFFSET+IA64_SAL_OS_STATE_PROC_STATE_PARAM_OFFSET, r2
236 ;; 163 ;;
237 ld8 r18=[r16] // Get processor state parameter on existing PALE_CHECK. 164 ld8 r18=[r3] // Get processor state parameter on existing PALE_CHECK.
238 ;; 165 ;;
239 tbit.nz p6,p7=r18,60 166 tbit.nz p6,p7=r18,60
240(p7) br.spnt done_tlb_purge_and_reload 167(p7) br.spnt done_tlb_purge_and_reload
@@ -323,624 +250,775 @@ ia64_reload_tr:
323 itr.d dtr[r20]=r16 250 itr.d dtr[r20]=r16
324 ;; 251 ;;
325 srlz.d 252 srlz.d
326 ;;
327 br.sptk.many done_tlb_purge_and_reload
328err:
329 COLD_BOOT_HANDOFF_STATE(r20,r21,r22)
330 br.sptk.many ia64_os_mca_done_restore
331 253
332done_tlb_purge_and_reload: 254done_tlb_purge_and_reload:
333 255
334 // Setup new stack frame for OS_MCA handling 256 // switch to per cpu MCA stack
335 GET_IA64_MCA_DATA(r2) 257 mov r3=IA64_MCA_CPU_MCA_STACK_OFFSET // use the MCA stack
336 ;; 258 LOAD_PHYSICAL(p0,r2,1f) // return address
337 add r3 = IA64_MCA_CPU_STACKFRAME_OFFSET, r2 259 br.sptk ia64_new_stack
338 add r2 = IA64_MCA_CPU_RBSTORE_OFFSET, r2 2601:
339 ;; 261
340 rse_switch_context(r6,r3,r2);; // RSC management in this new context 262 // everything saved, now we can set the kernel registers
263 mov r3=IA64_MCA_CPU_MCA_STACK_OFFSET // use the MCA stack
264 LOAD_PHYSICAL(p0,r2,1f) // return address
265 br.sptk ia64_set_kernel_registers
2661:
341 267
268 // This must be done in physical mode
342 GET_IA64_MCA_DATA(r2) 269 GET_IA64_MCA_DATA(r2)
343 ;; 270 ;;
344 add r2 = IA64_MCA_CPU_STACK_OFFSET+IA64_MCA_STACK_SIZE-16, r2 271 mov r7=r2
345 ;;
346 mov r12=r2 // establish new stack-pointer
347 272
348 // Enter virtual mode from physical mode 273 // Enter virtual mode from physical mode
349 VIRTUAL_MODE_ENTER(r2, r3, ia64_os_mca_virtual_begin, r4) 274 VIRTUAL_MODE_ENTER(r2, r3, ia64_os_mca_virtual_begin, r4)
350ia64_os_mca_virtual_begin: 275
276 // This code returns to SAL via SOS r2, in general SAL has no unwind
277 // data. To get a clean termination when backtracing the C MCA/INIT
278 // handler, set a dummy return address of 0 in this routine. That
279 // requires that ia64_os_mca_virtual_begin be a global function.
280ENTRY(ia64_os_mca_virtual_begin)
281 .prologue
282 .save rp,r0
283 .body
284
285 mov ar.rsc=3 // set eager mode for C handler
286 mov r2=r7 // see GET_IA64_MCA_DATA above
287 ;;
351 288
352 // Call virtual mode handler 289 // Call virtual mode handler
353 movl r2=ia64_mca_ucmc_handler;; 290 alloc r14=ar.pfs,0,0,3,0
354 mov b6=r2;; 291 ;;
355 br.call.sptk.many b0=b6;; 292 DATA_PA_TO_VA(r2,r7)
356.ret0: 293 ;;
294 add out0=IA64_MCA_CPU_MCA_STACK_OFFSET+MCA_PT_REGS_OFFSET, r2
295 add out1=IA64_MCA_CPU_MCA_STACK_OFFSET+MCA_SWITCH_STACK_OFFSET, r2
296 add out2=IA64_MCA_CPU_MCA_STACK_OFFSET+MCA_SOS_OFFSET, r2
297 br.call.sptk.many b0=ia64_mca_handler
298
357 // Revert back to physical mode before going back to SAL 299 // Revert back to physical mode before going back to SAL
358 PHYSICAL_MODE_ENTER(r2, r3, ia64_os_mca_virtual_end, r4) 300 PHYSICAL_MODE_ENTER(r2, r3, ia64_os_mca_virtual_end, r4)
359ia64_os_mca_virtual_end: 301ia64_os_mca_virtual_end:
360 302
361 // restore the original stack frame here 303END(ia64_os_mca_virtual_begin)
304
305 // switch back to previous stack
306 alloc r14=ar.pfs,0,0,0,0 // remove the MCA handler frame
307 mov r3=IA64_MCA_CPU_MCA_STACK_OFFSET // use the MCA stack
308 LOAD_PHYSICAL(p0,r2,1f) // return address
309 br.sptk ia64_old_stack
3101:
311
312 mov r3=IA64_MCA_CPU_MCA_STACK_OFFSET // use the MCA stack
313 LOAD_PHYSICAL(p0,r2,1f) // return address
314 br.sptk ia64_state_restore // restore the SAL state
3151:
316
317 mov b0=r12 // SAL_CHECK return address
318
319 // release lock
320 LOAD_PHYSICAL(p0,r3,ia64_mca_serialize);;
321 st4.rel [r3]=r0
322
323 br b0
324
325//EndMain//////////////////////////////////////////////////////////////////////
326
327//StartMain////////////////////////////////////////////////////////////////////
328
329//
330// SAL to OS entry point for INIT on all processors. This has been defined for
331// registration purposes with SAL as a part of ia64_mca_init. Monarch and
332// slave INIT have identical processing, except for the value of the
333// sos->monarch flag in r19.
334//
335
336ia64_os_init_dispatch_monarch:
337 mov r19=1 // Bow, bow, ye lower middle classes!
338 br.sptk ia64_os_init_dispatch
339
340ia64_os_init_dispatch_slave:
341 mov r19=0 // <igor>yeth, mathter</igor>
342
343ia64_os_init_dispatch:
344
345 mov r3=IA64_MCA_CPU_INIT_STACK_OFFSET // use the INIT stack
346 LOAD_PHYSICAL(p0,r2,1f) // return address
347 br.sptk ia64_state_save // save the state that is not in minstate
3481:
349
350 // switch to per cpu INIT stack
351 mov r3=IA64_MCA_CPU_INIT_STACK_OFFSET // use the INIT stack
352 LOAD_PHYSICAL(p0,r2,1f) // return address
353 br.sptk ia64_new_stack
3541:
355
356 // everything saved, now we can set the kernel registers
357 mov r3=IA64_MCA_CPU_INIT_STACK_OFFSET // use the INIT stack
358 LOAD_PHYSICAL(p0,r2,1f) // return address
359 br.sptk ia64_set_kernel_registers
3601:
361
362 // This must be done in physical mode
362 GET_IA64_MCA_DATA(r2) 363 GET_IA64_MCA_DATA(r2)
363 ;; 364 ;;
364 add r2 = IA64_MCA_CPU_STACKFRAME_OFFSET, r2 365 mov r7=r2
365 ;; 366
366 movl r4=IA64_PSR_MC 367 // Enter virtual mode from physical mode
368 VIRTUAL_MODE_ENTER(r2, r3, ia64_os_init_virtual_begin, r4)
369
370 // This code returns to SAL via SOS r2, in general SAL has no unwind
371 // data. To get a clean termination when backtracing the C MCA/INIT
372 // handler, set a dummy return address of 0 in this routine. That
373 // requires that ia64_os_init_virtual_begin be a global function.
374ENTRY(ia64_os_init_virtual_begin)
375 .prologue
376 .save rp,r0
377 .body
378
379 mov ar.rsc=3 // set eager mode for C handler
380 mov r2=r7 // see GET_IA64_MCA_DATA above
367 ;; 381 ;;
368 rse_return_context(r4,r3,r2) // switch from interrupt context for RSE
369 382
370 // let us restore all the registers from our PSI structure 383 // Call virtual mode handler
371 mov r8=gp 384 alloc r14=ar.pfs,0,0,3,0
385 ;;
386 DATA_PA_TO_VA(r2,r7)
372 ;; 387 ;;
373begin_os_mca_restore: 388 add out0=IA64_MCA_CPU_INIT_STACK_OFFSET+MCA_PT_REGS_OFFSET, r2
374 br ia64_os_mca_proc_state_restore;; 389 add out1=IA64_MCA_CPU_INIT_STACK_OFFSET+MCA_SWITCH_STACK_OFFSET, r2
390 add out2=IA64_MCA_CPU_INIT_STACK_OFFSET+MCA_SOS_OFFSET, r2
391 br.call.sptk.many b0=ia64_init_handler
375 392
376ia64_os_mca_done_restore: 393 // Revert back to physical mode before going back to SAL
377 OS_MCA_TO_SAL_HANDOFF_STATE_RESTORE(r2);; 394 PHYSICAL_MODE_ENTER(r2, r3, ia64_os_init_virtual_end, r4)
378 // branch back to SALE_CHECK 395ia64_os_init_virtual_end:
379 ld8 r3=[r2];;
380 mov b0=r3;; // SAL_CHECK return address
381 396
382 // release lock 397END(ia64_os_init_virtual_begin)
383 movl r3=ia64_mca_serialize;; 398
384 DATA_VA_TO_PA(r3);; 399 mov r3=IA64_MCA_CPU_INIT_STACK_OFFSET // use the INIT stack
385 st8.rel [r3]=r0 400 LOAD_PHYSICAL(p0,r2,1f) // return address
401 br.sptk ia64_state_restore // restore the SAL state
4021:
386 403
404 // switch back to previous stack
405 alloc r14=ar.pfs,0,0,0,0 // remove the INIT handler frame
406 mov r3=IA64_MCA_CPU_INIT_STACK_OFFSET // use the INIT stack
407 LOAD_PHYSICAL(p0,r2,1f) // return address
408 br.sptk ia64_old_stack
4091:
410
411 mov b0=r12 // SAL_CHECK return address
387 br b0 412 br b0
388 ;; 413
389ia64_os_mca_dispatch_end:
390//EndMain////////////////////////////////////////////////////////////////////// 414//EndMain//////////////////////////////////////////////////////////////////////
391 415
416// common defines for the stubs
417#define ms r4
418#define regs r5
419#define temp1 r2 /* careful, it overlaps with input registers */
420#define temp2 r3 /* careful, it overlaps with input registers */
421#define temp3 r7
422#define temp4 r14
423
392 424
393//++ 425//++
394// Name: 426// Name:
395// ia64_os_mca_proc_state_dump() 427// ia64_state_save()
396// 428//
397// Stub Description: 429// Stub Description:
398// 430//
399// This stub dumps the processor state during MCHK to a data area 431// Save the state that is not in minstate. This is sensitive to the layout of
432// struct ia64_sal_os_state in mca.h.
433//
434// r2 contains the return address, r3 contains either
435// IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
436//
437// The OS to SAL section of struct ia64_sal_os_state is set to a default
438// value of cold boot (MCA) or warm boot (INIT) and return to the same
439// context. ia64_sal_os_state is also used to hold some registers that
440// need to be saved and restored across the stack switches.
441//
442// Most input registers to this stub come from PAL/SAL
443// r1 os gp, physical
444// r8 pal_proc entry point
445// r9 sal_proc entry point
446// r10 sal gp
447// r11 MCA - rendevzous state, INIT - reason code
448// r12 sal return address
449// r17 pal min_state
450// r18 processor state parameter
451// r19 monarch flag, set by the caller of this routine
452//
453// In addition to the SAL to OS state, this routine saves all the
454// registers that appear in struct pt_regs and struct switch_stack,
455// excluding those that are already in the PAL minstate area. This
456// results in a partial pt_regs and switch_stack, the C code copies the
457// remaining registers from PAL minstate to pt_regs and switch_stack. The
458// resulting structures contain all the state of the original process when
459// MCA/INIT occurred.
400// 460//
401//-- 461//--
402 462
403ia64_os_mca_proc_state_dump: 463ia64_state_save:
404// Save bank 1 GRs 16-31 which will be used by c-language code when we switch 464 add regs=MCA_SOS_OFFSET, r3
405// to virtual addressing mode. 465 add ms=MCA_SOS_OFFSET+8, r3
406 GET_IA64_MCA_DATA(r2) 466 mov b0=r2 // save return address
467 cmp.eq p1,p2=IA64_MCA_CPU_MCA_STACK_OFFSET, r3
468 ;;
469 GET_IA64_MCA_DATA(temp2)
470 ;;
471 add temp1=temp2, regs // struct ia64_sal_os_state on MCA or INIT stack
472 add temp2=temp2, ms // struct ia64_sal_os_state+8 on MCA or INIT stack
473 ;;
474 mov regs=temp1 // save the start of sos
475 st8 [temp1]=r1,16 // os_gp
476 st8 [temp2]=r8,16 // pal_proc
477 ;;
478 st8 [temp1]=r9,16 // sal_proc
479 st8 [temp2]=r11,16 // rv_rc
480 mov r11=cr.iipa
481 ;;
482 st8 [temp1]=r18,16 // proc_state_param
483 st8 [temp2]=r19,16 // monarch
484 mov r6=IA64_KR(CURRENT)
485 ;;
486 st8 [temp1]=r12,16 // sal_ra
487 st8 [temp2]=r10,16 // sal_gp
488 mov r12=cr.isr
489 ;;
490 st8 [temp1]=r17,16 // pal_min_state
491 st8 [temp2]=r6,16 // prev_IA64_KR_CURRENT
492 mov r6=cr.ifa
493 ;;
494 st8 [temp1]=r0,16 // prev_task, starts off as NULL
495 st8 [temp2]=r12,16 // cr.isr
496 mov r12=cr.itir
497 ;;
498 st8 [temp1]=r6,16 // cr.ifa
499 st8 [temp2]=r12,16 // cr.itir
500 mov r12=cr.iim
501 ;;
502 st8 [temp1]=r11,16 // cr.iipa
503 st8 [temp2]=r12,16 // cr.iim
504 mov r6=cr.iha
505(p1) mov r12=IA64_MCA_COLD_BOOT
506(p2) mov r12=IA64_INIT_WARM_BOOT
507 ;;
508 st8 [temp1]=r6,16 // cr.iha
509 st8 [temp2]=r12 // os_status, default is cold boot
510 mov r6=IA64_MCA_SAME_CONTEXT
511 ;;
512 st8 [temp1]=r6 // context, default is same context
513
514 // Save the pt_regs data that is not in minstate. The previous code
515 // left regs at sos.
516 add regs=MCA_PT_REGS_OFFSET-MCA_SOS_OFFSET, regs
517 ;;
518 add temp1=PT(B6), regs
519 mov temp3=b6
520 mov temp4=b7
521 add temp2=PT(B7), regs
522 ;;
523 st8 [temp1]=temp3,PT(AR_CSD)-PT(B6) // save b6
524 st8 [temp2]=temp4,PT(AR_SSD)-PT(B7) // save b7
525 mov temp3=ar.csd
526 mov temp4=ar.ssd
527 cover // must be last in group
407 ;; 528 ;;
408 add r2 = IA64_MCA_CPU_PROC_STATE_DUMP_OFFSET, r2 529 st8 [temp1]=temp3,PT(AR_UNAT)-PT(AR_CSD) // save ar.csd
409 ;; 530 st8 [temp2]=temp4,PT(AR_PFS)-PT(AR_SSD) // save ar.ssd
410// save ar.NaT 531 mov temp3=ar.unat
411 mov r5=ar.unat // ar.unat 532 mov temp4=ar.pfs
412 533 ;;
413// save banked GRs 16-31 along with NaT bits 534 st8 [temp1]=temp3,PT(AR_RNAT)-PT(AR_UNAT) // save ar.unat
414 bsw.1;; 535 st8 [temp2]=temp4,PT(AR_BSPSTORE)-PT(AR_PFS) // save ar.pfs
415 st8.spill [r2]=r16,8;; 536 mov temp3=ar.rnat
416 st8.spill [r2]=r17,8;; 537 mov temp4=ar.bspstore
417 st8.spill [r2]=r18,8;; 538 ;;
418 st8.spill [r2]=r19,8;; 539 st8 [temp1]=temp3,PT(LOADRS)-PT(AR_RNAT) // save ar.rnat
419 st8.spill [r2]=r20,8;; 540 st8 [temp2]=temp4,PT(AR_FPSR)-PT(AR_BSPSTORE) // save ar.bspstore
420 st8.spill [r2]=r21,8;; 541 mov temp3=ar.bsp
421 st8.spill [r2]=r22,8;; 542 ;;
422 st8.spill [r2]=r23,8;; 543 sub temp3=temp3, temp4 // ar.bsp - ar.bspstore
423 st8.spill [r2]=r24,8;; 544 mov temp4=ar.fpsr
424 st8.spill [r2]=r25,8;; 545 ;;
425 st8.spill [r2]=r26,8;; 546 shl temp3=temp3,16 // compute ar.rsc to be used for "loadrs"
426 st8.spill [r2]=r27,8;; 547 ;;
427 st8.spill [r2]=r28,8;; 548 st8 [temp1]=temp3,PT(AR_CCV)-PT(LOADRS) // save loadrs
428 st8.spill [r2]=r29,8;; 549 st8 [temp2]=temp4,PT(F6)-PT(AR_FPSR) // save ar.fpsr
429 st8.spill [r2]=r30,8;; 550 mov temp3=ar.ccv
430 st8.spill [r2]=r31,8;; 551 ;;
431 552 st8 [temp1]=temp3,PT(F7)-PT(AR_CCV) // save ar.ccv
432 mov r4=ar.unat;; 553 stf.spill [temp2]=f6,PT(F8)-PT(F6)
433 st8 [r2]=r4,8 // save User NaT bits for r16-r31 554 ;;
434 mov ar.unat=r5 // restore original unat 555 stf.spill [temp1]=f7,PT(F9)-PT(F7)
435 bsw.0;; 556 stf.spill [temp2]=f8,PT(F10)-PT(F8)
436 557 ;;
437//save BRs 558 stf.spill [temp1]=f9,PT(F11)-PT(F9)
438 add r4=8,r2 // duplicate r2 in r4 559 stf.spill [temp2]=f10
439 add r6=2*8,r2 // duplicate r2 in r4 560 ;;
440 561 stf.spill [temp1]=f11
441 mov r3=b0 562
442 mov r5=b1 563 // Save the switch_stack data that is not in minstate nor pt_regs. The
443 mov r7=b2;; 564 // previous code left regs at pt_regs.
444 st8 [r2]=r3,3*8 565 add regs=MCA_SWITCH_STACK_OFFSET-MCA_PT_REGS_OFFSET, regs
445 st8 [r4]=r5,3*8 566 ;;
446 st8 [r6]=r7,3*8;; 567 add temp1=SW(F2), regs
447 568 add temp2=SW(F3), regs
448 mov r3=b3 569 ;;
449 mov r5=b4 570 stf.spill [temp1]=f2,32
450 mov r7=b5;; 571 stf.spill [temp2]=f3,32
451 st8 [r2]=r3,3*8 572 ;;
452 st8 [r4]=r5,3*8 573 stf.spill [temp1]=f4,32
453 st8 [r6]=r7,3*8;; 574 stf.spill [temp2]=f5,32
454 575 ;;
455 mov r3=b6 576 stf.spill [temp1]=f12,32
456 mov r5=b7;; 577 stf.spill [temp2]=f13,32
457 st8 [r2]=r3,2*8 578 ;;
458 st8 [r4]=r5,2*8;; 579 stf.spill [temp1]=f14,32
459 580 stf.spill [temp2]=f15,32
460cSaveCRs: 581 ;;
461// save CRs 582 stf.spill [temp1]=f16,32
462 add r4=8,r2 // duplicate r2 in r4 583 stf.spill [temp2]=f17,32
463 add r6=2*8,r2 // duplicate r2 in r4 584 ;;
464 585 stf.spill [temp1]=f18,32
465 mov r3=cr.dcr 586 stf.spill [temp2]=f19,32
466 mov r5=cr.itm 587 ;;
467 mov r7=cr.iva;; 588 stf.spill [temp1]=f20,32
468 589 stf.spill [temp2]=f21,32
469 st8 [r2]=r3,8*8 590 ;;
470 st8 [r4]=r5,3*8 591 stf.spill [temp1]=f22,32
471 st8 [r6]=r7,3*8;; // 48 byte rements 592 stf.spill [temp2]=f23,32
472 593 ;;
473 mov r3=cr.pta;; 594 stf.spill [temp1]=f24,32
474 st8 [r2]=r3,8*8;; // 64 byte rements 595 stf.spill [temp2]=f25,32
475 596 ;;
476// if PSR.ic=0, reading interruption registers causes an illegal operation fault 597 stf.spill [temp1]=f26,32
477 mov r3=psr;; 598 stf.spill [temp2]=f27,32
478 tbit.nz.unc p6,p0=r3,PSR_IC;; // PSI Valid Log bit pos. test 599 ;;
479(p6) st8 [r2]=r0,9*8+160 // increment by 232 byte inc. 600 stf.spill [temp1]=f28,32
480begin_skip_intr_regs: 601 stf.spill [temp2]=f29,32
481(p6) br SkipIntrRegs;; 602 ;;
482 603 stf.spill [temp1]=f30,SW(B2)-SW(F30)
483 add r4=8,r2 // duplicate r2 in r4 604 stf.spill [temp2]=f31,SW(B3)-SW(F31)
484 add r6=2*8,r2 // duplicate r2 in r6 605 mov temp3=b2
485 606 mov temp4=b3
486 mov r3=cr.ipsr 607 ;;
487 mov r5=cr.isr 608 st8 [temp1]=temp3,16 // save b2
488 mov r7=r0;; 609 st8 [temp2]=temp4,16 // save b3
489 st8 [r2]=r3,3*8 610 mov temp3=b4
490 st8 [r4]=r5,3*8 611 mov temp4=b5
491 st8 [r6]=r7,3*8;; 612 ;;
492 613 st8 [temp1]=temp3,SW(AR_LC)-SW(B4) // save b4
493 mov r3=cr.iip 614 st8 [temp2]=temp4 // save b5
494 mov r5=cr.ifa 615 mov temp3=ar.lc
495 mov r7=cr.itir;; 616 ;;
496 st8 [r2]=r3,3*8 617 st8 [temp1]=temp3 // save ar.lc
497 st8 [r4]=r5,3*8 618
498 st8 [r6]=r7,3*8;; 619 // FIXME: Some proms are incorrectly accessing the minstate area as
499 620 // cached data. The C code uses region 6, uncached virtual. Ensure
500 mov r3=cr.iipa 621 // that there is no cache data lying around for the first 1K of the
501 mov r5=cr.ifs 622 // minstate area.
502 mov r7=cr.iim;; 623 // Remove this code in September 2006, that gives platforms a year to
503 st8 [r2]=r3,3*8 624 // fix their proms and get their customers updated.
504 st8 [r4]=r5,3*8 625
505 st8 [r6]=r7,3*8;; 626 add r1=32*1,r17
506 627 add r2=32*2,r17
507 mov r3=cr25;; // cr.iha 628 add r3=32*3,r17
508 st8 [r2]=r3,160;; // 160 byte rement 629 add r4=32*4,r17
509 630 add r5=32*5,r17
510SkipIntrRegs: 631 add r6=32*6,r17
511 st8 [r2]=r0,152;; // another 152 byte . 632 add r7=32*7,r17
512 633 ;;
513 add r4=8,r2 // duplicate r2 in r4 634 fc r17
514 add r6=2*8,r2 // duplicate r2 in r6 635 fc r1
515 636 fc r2
516 mov r3=cr.lid 637 fc r3
517// mov r5=cr.ivr // cr.ivr, don't read it 638 fc r4
518 mov r7=cr.tpr;; 639 fc r5
519 st8 [r2]=r3,3*8 640 fc r6
520 st8 [r4]=r5,3*8 641 fc r7
521 st8 [r6]=r7,3*8;; 642 add r17=32*8,r17
522 643 add r1=32*8,r1
523 mov r3=r0 // cr.eoi => cr67 644 add r2=32*8,r2
524 mov r5=r0 // cr.irr0 => cr68 645 add r3=32*8,r3
525 mov r7=r0;; // cr.irr1 => cr69 646 add r4=32*8,r4
526 st8 [r2]=r3,3*8 647 add r5=32*8,r5
527 st8 [r4]=r5,3*8 648 add r6=32*8,r6
528 st8 [r6]=r7,3*8;; 649 add r7=32*8,r7
529 650 ;;
530 mov r3=r0 // cr.irr2 => cr70 651 fc r17
531 mov r5=r0 // cr.irr3 => cr71 652 fc r1
532 mov r7=cr.itv;; 653 fc r2
533 st8 [r2]=r3,3*8 654 fc r3
534 st8 [r4]=r5,3*8 655 fc r4
535 st8 [r6]=r7,3*8;; 656 fc r5
536 657 fc r6
537 mov r3=cr.pmv 658 fc r7
538 mov r5=cr.cmcv;; 659 add r17=32*8,r17
539 st8 [r2]=r3,7*8 660 add r1=32*8,r1
540 st8 [r4]=r5,7*8;; 661 add r2=32*8,r2
541 662 add r3=32*8,r3
542 mov r3=r0 // cr.lrr0 => cr80 663 add r4=32*8,r4
543 mov r5=r0;; // cr.lrr1 => cr81 664 add r5=32*8,r5
544 st8 [r2]=r3,23*8 665 add r6=32*8,r6
545 st8 [r4]=r5,23*8;; 666 add r7=32*8,r7
546 667 ;;
547 adds r2=25*8,r2;; 668 fc r17
548 669 fc r1
549cSaveARs: 670 fc r2
550// save ARs 671 fc r3
551 add r4=8,r2 // duplicate r2 in r4 672 fc r4
552 add r6=2*8,r2 // duplicate r2 in r6 673 fc r5
553 674 fc r6
554 mov r3=ar.k0 675 fc r7
555 mov r5=ar.k1 676 add r17=32*8,r17
556 mov r7=ar.k2;; 677 add r1=32*8,r1
557 st8 [r2]=r3,3*8 678 add r2=32*8,r2
558 st8 [r4]=r5,3*8 679 add r3=32*8,r3
559 st8 [r6]=r7,3*8;; 680 add r4=32*8,r4
560 681 add r5=32*8,r5
561 mov r3=ar.k3 682 add r6=32*8,r6
562 mov r5=ar.k4 683 add r7=32*8,r7
563 mov r7=ar.k5;; 684 ;;
564 st8 [r2]=r3,3*8 685 fc r17
565 st8 [r4]=r5,3*8 686 fc r1
566 st8 [r6]=r7,3*8;; 687 fc r2
567 688 fc r3
568 mov r3=ar.k6 689 fc r4
569 mov r5=ar.k7 690 fc r5
570 mov r7=r0;; // ar.kr8 691 fc r6
571 st8 [r2]=r3,10*8 692 fc r7
572 st8 [r4]=r5,10*8 693
573 st8 [r6]=r7,10*8;; // rement by 72 bytes 694 br.sptk b0
574
575 mov r3=ar.rsc
576 mov ar.rsc=r0 // put RSE in enforced lazy mode
577 mov r5=ar.bsp
578 ;;
579 mov r7=ar.bspstore;;
580 st8 [r2]=r3,3*8
581 st8 [r4]=r5,3*8
582 st8 [r6]=r7,3*8;;
583
584 mov r3=ar.rnat;;
585 st8 [r2]=r3,8*13 // increment by 13x8 bytes
586
587 mov r3=ar.ccv;;
588 st8 [r2]=r3,8*4
589
590 mov r3=ar.unat;;
591 st8 [r2]=r3,8*4
592
593 mov r3=ar.fpsr;;
594 st8 [r2]=r3,8*4
595
596 mov r3=ar.itc;;
597 st8 [r2]=r3,160 // 160
598
599 mov r3=ar.pfs;;
600 st8 [r2]=r3,8
601
602 mov r3=ar.lc;;
603 st8 [r2]=r3,8
604
605 mov r3=ar.ec;;
606 st8 [r2]=r3
607 add r2=8*62,r2 //padding
608
609// save RRs
610 mov ar.lc=0x08-1
611 movl r4=0x00;;
612
613cStRR:
614 dep.z r5=r4,61,3;;
615 mov r3=rr[r5];;
616 st8 [r2]=r3,8
617 add r4=1,r4
618 br.cloop.sptk.few cStRR
619 ;;
620end_os_mca_dump:
621 br ia64_os_mca_done_dump;;
622 695
623//EndStub////////////////////////////////////////////////////////////////////// 696//EndStub//////////////////////////////////////////////////////////////////////
624 697
625 698
626//++ 699//++
627// Name: 700// Name:
628// ia64_os_mca_proc_state_restore() 701// ia64_state_restore()
629// 702//
630// Stub Description: 703// Stub Description:
631// 704//
632// This is a stub to restore the saved processor state during MCHK 705// Restore the SAL/OS state. This is sensitive to the layout of struct
706// ia64_sal_os_state in mca.h.
707//
708// r2 contains the return address, r3 contains either
709// IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
710//
711// In addition to the SAL to OS state, this routine restores all the
712// registers that appear in struct pt_regs and struct switch_stack,
713// excluding those in the PAL minstate area.
633// 714//
634//-- 715//--
635 716
636ia64_os_mca_proc_state_restore: 717ia64_state_restore:
718 // Restore the switch_stack data that is not in minstate nor pt_regs.
719 add regs=MCA_SWITCH_STACK_OFFSET, r3
720 mov b0=r2 // save return address
721 ;;
722 GET_IA64_MCA_DATA(temp2)
723 ;;
724 add regs=temp2, regs
725 ;;
726 add temp1=SW(F2), regs
727 add temp2=SW(F3), regs
728 ;;
729 ldf.fill f2=[temp1],32
730 ldf.fill f3=[temp2],32
731 ;;
732 ldf.fill f4=[temp1],32
733 ldf.fill f5=[temp2],32
734 ;;
735 ldf.fill f12=[temp1],32
736 ldf.fill f13=[temp2],32
737 ;;
738 ldf.fill f14=[temp1],32
739 ldf.fill f15=[temp2],32
740 ;;
741 ldf.fill f16=[temp1],32
742 ldf.fill f17=[temp2],32
743 ;;
744 ldf.fill f18=[temp1],32
745 ldf.fill f19=[temp2],32
746 ;;
747 ldf.fill f20=[temp1],32
748 ldf.fill f21=[temp2],32
749 ;;
750 ldf.fill f22=[temp1],32
751 ldf.fill f23=[temp2],32
752 ;;
753 ldf.fill f24=[temp1],32
754 ldf.fill f25=[temp2],32
755 ;;
756 ldf.fill f26=[temp1],32
757 ldf.fill f27=[temp2],32
758 ;;
759 ldf.fill f28=[temp1],32
760 ldf.fill f29=[temp2],32
761 ;;
762 ldf.fill f30=[temp1],SW(B2)-SW(F30)
763 ldf.fill f31=[temp2],SW(B3)-SW(F31)
764 ;;
765 ld8 temp3=[temp1],16 // restore b2
766 ld8 temp4=[temp2],16 // restore b3
767 ;;
768 mov b2=temp3
769 mov b3=temp4
770 ld8 temp3=[temp1],SW(AR_LC)-SW(B4) // restore b4
771 ld8 temp4=[temp2] // restore b5
772 ;;
773 mov b4=temp3
774 mov b5=temp4
775 ld8 temp3=[temp1] // restore ar.lc
776 ;;
777 mov ar.lc=temp3
637 778
638// Restore bank1 GR16-31 779 // Restore the pt_regs data that is not in minstate. The previous code
639 GET_IA64_MCA_DATA(r2) 780 // left regs at switch_stack.
781 add regs=MCA_PT_REGS_OFFSET-MCA_SWITCH_STACK_OFFSET, regs
782 ;;
783 add temp1=PT(B6), regs
784 add temp2=PT(B7), regs
785 ;;
786 ld8 temp3=[temp1],PT(AR_CSD)-PT(B6) // restore b6
787 ld8 temp4=[temp2],PT(AR_SSD)-PT(B7) // restore b7
788 ;;
789 mov b6=temp3
790 mov b7=temp4
791 ld8 temp3=[temp1],PT(AR_UNAT)-PT(AR_CSD) // restore ar.csd
792 ld8 temp4=[temp2],PT(AR_PFS)-PT(AR_SSD) // restore ar.ssd
793 ;;
794 mov ar.csd=temp3
795 mov ar.ssd=temp4
796 ld8 temp3=[temp1] // restore ar.unat
797 add temp1=PT(AR_CCV)-PT(AR_UNAT), temp1
798 ld8 temp4=[temp2],PT(AR_FPSR)-PT(AR_PFS) // restore ar.pfs
799 ;;
800 mov ar.unat=temp3
801 mov ar.pfs=temp4
802 // ar.rnat, ar.bspstore, loadrs are restore in ia64_old_stack.
803 ld8 temp3=[temp1],PT(F6)-PT(AR_CCV) // restore ar.ccv
804 ld8 temp4=[temp2],PT(F7)-PT(AR_FPSR) // restore ar.fpsr
805 ;;
806 mov ar.ccv=temp3
807 mov ar.fpsr=temp4
808 ldf.fill f6=[temp1],PT(F8)-PT(F6)
809 ldf.fill f7=[temp2],PT(F9)-PT(F7)
810 ;;
811 ldf.fill f8=[temp1],PT(F10)-PT(F8)
812 ldf.fill f9=[temp2],PT(F11)-PT(F9)
813 ;;
814 ldf.fill f10=[temp1]
815 ldf.fill f11=[temp2]
816
817 // Restore the SAL to OS state. The previous code left regs at pt_regs.
818 add regs=MCA_SOS_OFFSET-MCA_PT_REGS_OFFSET, regs
640 ;; 819 ;;
641 add r2 = IA64_MCA_CPU_PROC_STATE_DUMP_OFFSET, r2 820 add temp1=IA64_SAL_OS_STATE_COMMON_OFFSET, regs
642 821 add temp2=IA64_SAL_OS_STATE_COMMON_OFFSET+8, regs
643restore_GRs: // restore bank-1 GRs 16-31 822 ;;
644 bsw.1;; 823 ld8 r12=[temp1],16 // sal_ra
645 add r3=16*8,r2;; // to get to NaT of GR 16-31 824 ld8 r9=[temp2],16 // sal_gp
646 ld8 r3=[r3];; 825 ;;
647 mov ar.unat=r3;; // first restore NaT 826 ld8 r22=[temp1],24 // pal_min_state, virtual. skip prev_task
648 827 ld8 r21=[temp2],16 // prev_IA64_KR_CURRENT
649 ld8.fill r16=[r2],8;; 828 ;;
650 ld8.fill r17=[r2],8;; 829 ld8 temp3=[temp1],16 // cr.isr
651 ld8.fill r18=[r2],8;; 830 ld8 temp4=[temp2],16 // cr.ifa
652 ld8.fill r19=[r2],8;; 831 ;;
653 ld8.fill r20=[r2],8;; 832 mov cr.isr=temp3
654 ld8.fill r21=[r2],8;; 833 mov cr.ifa=temp4
655 ld8.fill r22=[r2],8;; 834 ld8 temp3=[temp1],16 // cr.itir
656 ld8.fill r23=[r2],8;; 835 ld8 temp4=[temp2],16 // cr.iipa
657 ld8.fill r24=[r2],8;; 836 ;;
658 ld8.fill r25=[r2],8;; 837 mov cr.itir=temp3
659 ld8.fill r26=[r2],8;; 838 mov cr.iipa=temp4
660 ld8.fill r27=[r2],8;; 839 ld8 temp3=[temp1],16 // cr.iim
661 ld8.fill r28=[r2],8;; 840 ld8 temp4=[temp2],16 // cr.iha
662 ld8.fill r29=[r2],8;; 841 ;;
663 ld8.fill r30=[r2],8;; 842 mov cr.iim=temp3
664 ld8.fill r31=[r2],8;; 843 mov cr.iha=temp4
665 844 dep r22=0,r22,62,2 // pal_min_state, physical, uncached
666 ld8 r3=[r2],8;; // increment to skip NaT 845 mov IA64_KR(CURRENT)=r21
667 bsw.0;; 846 ld8 r8=[temp1] // os_status
668 847 ld8 r10=[temp2] // context
669restore_BRs: 848
670 add r4=8,r2 // duplicate r2 in r4 849 br.sptk b0
671 add r6=2*8,r2;; // duplicate r2 in r4
672
673 ld8 r3=[r2],3*8
674 ld8 r5=[r4],3*8
675 ld8 r7=[r6],3*8;;
676 mov b0=r3
677 mov b1=r5
678 mov b2=r7;;
679
680 ld8 r3=[r2],3*8
681 ld8 r5=[r4],3*8
682 ld8 r7=[r6],3*8;;
683 mov b3=r3
684 mov b4=r5
685 mov b5=r7;;
686
687 ld8 r3=[r2],2*8
688 ld8 r5=[r4],2*8;;
689 mov b6=r3
690 mov b7=r5;;
691
692restore_CRs:
693 add r4=8,r2 // duplicate r2 in r4
694 add r6=2*8,r2;; // duplicate r2 in r4
695
696 ld8 r3=[r2],8*8
697 ld8 r5=[r4],3*8
698 ld8 r7=[r6],3*8;; // 48 byte increments
699 mov cr.dcr=r3
700 mov cr.itm=r5
701 mov cr.iva=r7;;
702
703 ld8 r3=[r2],8*8;; // 64 byte increments
704// mov cr.pta=r3
705
706
707// if PSR.ic=1, reading interruption registers causes an illegal operation fault
708 mov r3=psr;;
709 tbit.nz.unc p6,p0=r3,PSR_IC;; // PSI Valid Log bit pos. test
710(p6) st8 [r2]=r0,9*8+160 // increment by 232 byte inc.
711
712begin_rskip_intr_regs:
713(p6) br rSkipIntrRegs;;
714
715 add r4=8,r2 // duplicate r2 in r4
716 add r6=2*8,r2;; // duplicate r2 in r4
717
718 ld8 r3=[r2],3*8
719 ld8 r5=[r4],3*8
720 ld8 r7=[r6],3*8;;
721 mov cr.ipsr=r3
722// mov cr.isr=r5 // cr.isr is read only
723
724 ld8 r3=[r2],3*8
725 ld8 r5=[r4],3*8
726 ld8 r7=[r6],3*8;;
727 mov cr.iip=r3
728 mov cr.ifa=r5
729 mov cr.itir=r7;;
730
731 ld8 r3=[r2],3*8
732 ld8 r5=[r4],3*8
733 ld8 r7=[r6],3*8;;
734 mov cr.iipa=r3
735 mov cr.ifs=r5
736 mov cr.iim=r7
737
738 ld8 r3=[r2],160;; // 160 byte increment
739 mov cr.iha=r3
740
741rSkipIntrRegs:
742 ld8 r3=[r2],152;; // another 152 byte inc.
743
744 add r4=8,r2 // duplicate r2 in r4
745 add r6=2*8,r2;; // duplicate r2 in r6
746
747 ld8 r3=[r2],8*3
748 ld8 r5=[r4],8*3
749 ld8 r7=[r6],8*3;;
750 mov cr.lid=r3
751// mov cr.ivr=r5 // cr.ivr is read only
752 mov cr.tpr=r7;;
753
754 ld8 r3=[r2],8*3
755 ld8 r5=[r4],8*3
756 ld8 r7=[r6],8*3;;
757// mov cr.eoi=r3
758// mov cr.irr0=r5 // cr.irr0 is read only
759// mov cr.irr1=r7;; // cr.irr1 is read only
760
761 ld8 r3=[r2],8*3
762 ld8 r5=[r4],8*3
763 ld8 r7=[r6],8*3;;
764// mov cr.irr2=r3 // cr.irr2 is read only
765// mov cr.irr3=r5 // cr.irr3 is read only
766 mov cr.itv=r7;;
767
768 ld8 r3=[r2],8*7
769 ld8 r5=[r4],8*7;;
770 mov cr.pmv=r3
771 mov cr.cmcv=r5;;
772
773 ld8 r3=[r2],8*23
774 ld8 r5=[r4],8*23;;
775 adds r2=8*23,r2
776 adds r4=8*23,r4;;
777// mov cr.lrr0=r3
778// mov cr.lrr1=r5
779
780 adds r2=8*2,r2;;
781
782restore_ARs:
783 add r4=8,r2 // duplicate r2 in r4
784 add r6=2*8,r2;; // duplicate r2 in r4
785
786 ld8 r3=[r2],3*8
787 ld8 r5=[r4],3*8
788 ld8 r7=[r6],3*8;;
789 mov ar.k0=r3
790 mov ar.k1=r5
791 mov ar.k2=r7;;
792
793 ld8 r3=[r2],3*8
794 ld8 r5=[r4],3*8
795 ld8 r7=[r6],3*8;;
796 mov ar.k3=r3
797 mov ar.k4=r5
798 mov ar.k5=r7;;
799
800 ld8 r3=[r2],10*8
801 ld8 r5=[r4],10*8
802 ld8 r7=[r6],10*8;;
803 mov ar.k6=r3
804 mov ar.k7=r5
805 ;;
806
807 ld8 r3=[r2],3*8
808 ld8 r5=[r4],3*8
809 ld8 r7=[r6],3*8;;
810// mov ar.rsc=r3
811// mov ar.bsp=r5 // ar.bsp is read only
812 mov ar.rsc=r0 // make sure that RSE is in enforced lazy mode
813 ;;
814 mov ar.bspstore=r7;;
815
816 ld8 r9=[r2],8*13;;
817 mov ar.rnat=r9
818
819 mov ar.rsc=r3
820 ld8 r3=[r2],8*4;;
821 mov ar.ccv=r3
822
823 ld8 r3=[r2],8*4;;
824 mov ar.unat=r3
825
826 ld8 r3=[r2],8*4;;
827 mov ar.fpsr=r3
828
829 ld8 r3=[r2],160;; // 160
830// mov ar.itc=r3
831
832 ld8 r3=[r2],8;;
833 mov ar.pfs=r3
834
835 ld8 r3=[r2],8;;
836 mov ar.lc=r3
837
838 ld8 r3=[r2];;
839 mov ar.ec=r3
840 add r2=8*62,r2;; // padding
841
842restore_RRs:
843 mov r5=ar.lc
844 mov ar.lc=0x08-1
845 movl r4=0x00;;
846cStRRr:
847 dep.z r7=r4,61,3
848 ld8 r3=[r2],8;;
849 mov rr[r7]=r3 // what are its access previledges?
850 add r4=1,r4
851 br.cloop.sptk.few cStRRr
852 ;;
853 mov ar.lc=r5
854 ;;
855end_os_mca_restore:
856 br ia64_os_mca_done_restore;;
857 850
858//EndStub////////////////////////////////////////////////////////////////////// 851//EndStub//////////////////////////////////////////////////////////////////////
859 852
860 853
861// ok, the issue here is that we need to save state information so 854//++
862// it can be useable by the kernel debugger and show regs routines. 855// Name:
863// In order to do this, our best bet is save the current state (plus 856// ia64_new_stack()
864// the state information obtain from the MIN_STATE_AREA) into a pt_regs
865// format. This way we can pass it on in a useable format.
866// 857//
867 858// Stub Description:
868// 859//
869// SAL to OS entry point for INIT on the monarch processor 860// Switch to the MCA/INIT stack.
870// This has been defined for registration purposes with SAL
871// as a part of ia64_mca_init.
872// 861//
873// When we get here, the following registers have been 862// r2 contains the return address, r3 contains either
874// set by the SAL for our use 863// IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
875// 864//
876// 1. GR1 = OS INIT GP 865// On entry RBS is still on the original stack, this routine switches RBS
877// 2. GR8 = PAL_PROC physical address 866// to use the MCA/INIT stack.
878// 3. GR9 = SAL_PROC physical address
879// 4. GR10 = SAL GP (physical)
880// 5. GR11 = Init Reason
881// 0 = Received INIT for event other than crash dump switch
882// 1 = Received wakeup at the end of an OS_MCA corrected machine check
883// 2 = Received INIT dude to CrashDump switch assertion
884// 867//
885// 6. GR12 = Return address to location within SAL_INIT procedure 868// On entry, sos->pal_min_state is physical, on exit it is virtual.
886 869//
870//--
887 871
888GLOBAL_ENTRY(ia64_monarch_init_handler) 872ia64_new_stack:
889 .prologue 873 add regs=MCA_PT_REGS_OFFSET, r3
890 // stash the information the SAL passed to os 874 add temp2=MCA_SOS_OFFSET+IA64_SAL_OS_STATE_PAL_MIN_STATE_OFFSET, r3
891 SAL_TO_OS_MCA_HANDOFF_STATE_SAVE(r2) 875 mov b0=r2 // save return address
876 GET_IA64_MCA_DATA(temp1)
877 invala
892 ;; 878 ;;
893 SAVE_MIN_WITH_COVER 879 add temp2=temp2, temp1 // struct ia64_sal_os_state.pal_min_state on MCA or INIT stack
880 add regs=regs, temp1 // struct pt_regs on MCA or INIT stack
894 ;; 881 ;;
895 mov r8=cr.ifa 882 // Address of minstate area provided by PAL is physical, uncacheable.
896 mov r9=cr.isr 883 // Convert to Linux virtual address in region 6 for C code.
897 adds r3=8,r2 // set up second base pointer 884 ld8 ms=[temp2] // pal_min_state, physical
898 ;; 885 ;;
899 SAVE_REST 886 dep temp1=-1,ms,62,2 // set region 6
900 887 mov temp3=IA64_RBS_OFFSET-MCA_PT_REGS_OFFSET
901// ok, enough should be saved at this point to be dangerous, and supply 888 ;;
902// information for a dump 889 st8 [temp2]=temp1 // pal_min_state, virtual
903// We need to switch to Virtual mode before hitting the C functions.
904 890
905 movl r2=IA64_PSR_IT|IA64_PSR_IC|IA64_PSR_DT|IA64_PSR_RT|IA64_PSR_DFH|IA64_PSR_BN 891 add temp4=temp3, regs // start of bspstore on new stack
906 mov r3=psr // get the current psr, minimum enabled at this point
907 ;; 892 ;;
908 or r2=r2,r3 893 mov ar.bspstore=temp4 // switch RBS to MCA/INIT stack
909 ;; 894 ;;
910 movl r3=IVirtual_Switch 895 flushrs // must be first in group
896 br.sptk b0
897
898//EndStub//////////////////////////////////////////////////////////////////////
899
900
901//++
902// Name:
903// ia64_old_stack()
904//
905// Stub Description:
906//
907// Switch to the old stack.
908//
909// r2 contains the return address, r3 contains either
910// IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
911//
912// On entry, pal_min_state is virtual, on exit it is physical.
913//
914// On entry RBS is on the MCA/INIT stack, this routine switches RBS
915// back to the previous stack.
916//
917// The psr is set to all zeroes. SAL return requires either all zeroes or
918// just psr.mc set. Leaving psr.mc off allows INIT to be issued if this
919// code does not perform correctly.
920//
921// The dirty registers at the time of the event were flushed to the
922// MCA/INIT stack in ia64_pt_regs_save(). Restore the dirty registers
923// before reverting to the previous bspstore.
924//--
925
926ia64_old_stack:
927 add regs=MCA_PT_REGS_OFFSET, r3
928 mov b0=r2 // save return address
929 GET_IA64_MCA_DATA(temp2)
930 LOAD_PHYSICAL(p0,temp1,1f)
911 ;; 931 ;;
912 mov cr.iip=r3 // short return to set the appropriate bits 932 mov cr.ipsr=r0
913 mov cr.ipsr=r2 // need to do an rfi to set appropriate bits 933 mov cr.ifs=r0
934 mov cr.iip=temp1
914 ;; 935 ;;
936 invala
915 rfi 937 rfi
9381:
939
940 add regs=regs, temp2 // struct pt_regs on MCA or INIT stack
916 ;; 941 ;;
917IVirtual_Switch: 942 add temp1=PT(LOADRS), regs
918 //
919 // We should now be running virtual
920 //
921 // Let's call the C handler to get the rest of the state info
922 //
923 alloc r14=ar.pfs,0,0,2,0 // now it's safe (must be first in insn group!)
924 ;; 943 ;;
925 adds out0=16,sp // out0 = pointer to pt_regs 944 ld8 temp2=[temp1],PT(AR_BSPSTORE)-PT(LOADRS) // restore loadrs
926 ;; 945 ;;
927 DO_SAVE_SWITCH_STACK 946 ld8 temp3=[temp1],PT(AR_RNAT)-PT(AR_BSPSTORE) // restore ar.bspstore
928 .body 947 mov ar.rsc=temp2
929 adds out1=16,sp // out0 = pointer to switch_stack 948 ;;
949 loadrs
950 ld8 temp4=[temp1] // restore ar.rnat
951 ;;
952 mov ar.bspstore=temp3 // back to old stack
953 ;;
954 mov ar.rnat=temp4
955 ;;
956
957 br.sptk b0
930 958
931 br.call.sptk.many rp=ia64_init_handler 959//EndStub//////////////////////////////////////////////////////////////////////
932.ret1:
933 960
934return_from_init:
935 br.sptk return_from_init
936END(ia64_monarch_init_handler)
937 961
962//++
963// Name:
964// ia64_set_kernel_registers()
938// 965//
939// SAL to OS entry point for INIT on the slave processor 966// Stub Description:
940// This has been defined for registration purposes with SAL 967//
941// as a part of ia64_mca_init. 968// Set the registers that are required by the C code in order to run on an
969// MCA/INIT stack.
970//
971// r2 contains the return address, r3 contains either
972// IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
942// 973//
974//--
975
976ia64_set_kernel_registers:
977 add temp3=MCA_SP_OFFSET, r3
978 add temp4=MCA_SOS_OFFSET+IA64_SAL_OS_STATE_OS_GP_OFFSET, r3
979 mov b0=r2 // save return address
980 GET_IA64_MCA_DATA(temp1)
981 ;;
982 add temp4=temp4, temp1 // &struct ia64_sal_os_state.os_gp
983 add r12=temp1, temp3 // kernel stack pointer on MCA/INIT stack
984 add r13=temp1, r3 // set current to start of MCA/INIT stack
985 ;;
986 ld8 r1=[temp4] // OS GP from SAL OS state
987 ;;
988 DATA_PA_TO_VA(r1,temp1)
989 DATA_PA_TO_VA(r12,temp2)
990 DATA_PA_TO_VA(r13,temp3)
991 ;;
992 mov IA64_KR(CURRENT)=r13
993
994 // FIXME: do I need to wire IA64_KR_CURRENT_STACK and IA64_TR_CURRENT_STACK?
995
996 br.sptk b0
997
998//EndStub//////////////////////////////////////////////////////////////////////
999
1000#undef ms
1001#undef regs
1002#undef temp1
1003#undef temp2
1004#undef temp3
1005#undef temp4
1006
943 1007
944GLOBAL_ENTRY(ia64_slave_init_handler) 1008// Support function for mca.c, it is here to avoid using inline asm. Given the
9451: br.sptk 1b 1009// address of an rnat slot, if that address is below the current ar.bspstore
946END(ia64_slave_init_handler) 1010// then return the contents of that slot, otherwise return the contents of
1011// ar.rnat.
1012GLOBAL_ENTRY(ia64_get_rnat)
1013 alloc r14=ar.pfs,1,0,0,0
1014 mov ar.rsc=0
1015 ;;
1016 mov r14=ar.bspstore
1017 ;;
1018 cmp.lt p6,p7=in0,r14
1019 ;;
1020(p6) ld8 r8=[in0]
1021(p7) mov r8=ar.rnat
1022 mov ar.rsc=3
1023 br.ret.sptk.many rp
1024END(ia64_get_rnat)
diff --git a/arch/ia64/kernel/mca_drv.c b/arch/ia64/kernel/mca_drv.c
index abc0113a82..6e683745af 100644
--- a/arch/ia64/kernel/mca_drv.c
+++ b/arch/ia64/kernel/mca_drv.c
@@ -4,6 +4,8 @@
4 * 4 *
5 * Copyright (C) 2004 FUJITSU LIMITED 5 * Copyright (C) 2004 FUJITSU LIMITED
6 * Copyright (C) Hidetoshi Seto (seto.hidetoshi@jp.fujitsu.com) 6 * Copyright (C) Hidetoshi Seto (seto.hidetoshi@jp.fujitsu.com)
7 * Copyright (C) 2005 Silicon Graphics, Inc
8 * Copyright (C) 2005 Keith Owens <kaos@sgi.com>
7 */ 9 */
8#include <linux/config.h> 10#include <linux/config.h>
9#include <linux/types.h> 11#include <linux/types.h>
@@ -38,10 +40,6 @@
38/* max size of SAL error record (default) */ 40/* max size of SAL error record (default) */
39static int sal_rec_max = 10000; 41static int sal_rec_max = 10000;
40 42
41/* from mca.c */
42static ia64_mca_sal_to_os_state_t *sal_to_os_handoff_state;
43static ia64_mca_os_to_sal_state_t *os_to_sal_handoff_state;
44
45/* from mca_drv_asm.S */ 43/* from mca_drv_asm.S */
46extern void *mca_handler_bhhook(void); 44extern void *mca_handler_bhhook(void);
47 45
@@ -316,7 +314,8 @@ init_record_index_pools(void)
316 */ 314 */
317 315
318static mca_type_t 316static mca_type_t
319is_mca_global(peidx_table_t *peidx, pal_bus_check_info_t *pbci) 317is_mca_global(peidx_table_t *peidx, pal_bus_check_info_t *pbci,
318 struct ia64_sal_os_state *sos)
320{ 319{
321 pal_processor_state_info_t *psp = (pal_processor_state_info_t*)peidx_psp(peidx); 320 pal_processor_state_info_t *psp = (pal_processor_state_info_t*)peidx_psp(peidx);
322 321
@@ -327,7 +326,7 @@ is_mca_global(peidx_table_t *peidx, pal_bus_check_info_t *pbci)
327 * Therefore it is local MCA when rendezvous has not been requested. 326 * Therefore it is local MCA when rendezvous has not been requested.
328 * Failed to rendezvous, the system must be down. 327 * Failed to rendezvous, the system must be down.
329 */ 328 */
330 switch (sal_to_os_handoff_state->imsto_rendez_state) { 329 switch (sos->rv_rc) {
331 case -1: /* SAL rendezvous unsuccessful */ 330 case -1: /* SAL rendezvous unsuccessful */
332 return MCA_IS_GLOBAL; 331 return MCA_IS_GLOBAL;
333 case 0: /* SAL rendezvous not required */ 332 case 0: /* SAL rendezvous not required */
@@ -388,7 +387,8 @@ is_mca_global(peidx_table_t *peidx, pal_bus_check_info_t *pbci)
388 */ 387 */
389 388
390static int 389static int
391recover_from_read_error(slidx_table_t *slidx, peidx_table_t *peidx, pal_bus_check_info_t *pbci) 390recover_from_read_error(slidx_table_t *slidx, peidx_table_t *peidx, pal_bus_check_info_t *pbci,
391 struct ia64_sal_os_state *sos)
392{ 392{
393 sal_log_mod_error_info_t *smei; 393 sal_log_mod_error_info_t *smei;
394 pal_min_state_area_t *pmsa; 394 pal_min_state_area_t *pmsa;
@@ -426,7 +426,7 @@ recover_from_read_error(slidx_table_t *slidx, peidx_table_t *peidx, pal_bus_chec
426 * setup for resume to bottom half of MCA, 426 * setup for resume to bottom half of MCA,
427 * "mca_handler_bhhook" 427 * "mca_handler_bhhook"
428 */ 428 */
429 pmsa = (pal_min_state_area_t *)(sal_to_os_handoff_state->pal_min_state | (6ul<<61)); 429 pmsa = sos->pal_min_state;
430 /* pass to bhhook as 1st argument (gr8) */ 430 /* pass to bhhook as 1st argument (gr8) */
431 pmsa->pmsa_gr[8-1] = smei->target_identifier; 431 pmsa->pmsa_gr[8-1] = smei->target_identifier;
432 /* set interrupted return address (but no use) */ 432 /* set interrupted return address (but no use) */
@@ -459,7 +459,8 @@ recover_from_read_error(slidx_table_t *slidx, peidx_table_t *peidx, pal_bus_chec
459 */ 459 */
460 460
461static int 461static int
462recover_from_platform_error(slidx_table_t *slidx, peidx_table_t *peidx, pal_bus_check_info_t *pbci) 462recover_from_platform_error(slidx_table_t *slidx, peidx_table_t *peidx, pal_bus_check_info_t *pbci,
463 struct ia64_sal_os_state *sos)
463{ 464{
464 int status = 0; 465 int status = 0;
465 pal_processor_state_info_t *psp = (pal_processor_state_info_t*)peidx_psp(peidx); 466 pal_processor_state_info_t *psp = (pal_processor_state_info_t*)peidx_psp(peidx);
@@ -469,7 +470,7 @@ recover_from_platform_error(slidx_table_t *slidx, peidx_table_t *peidx, pal_bus_
469 case 1: /* partial read */ 470 case 1: /* partial read */
470 case 3: /* full line(cpu) read */ 471 case 3: /* full line(cpu) read */
471 case 9: /* I/O space read */ 472 case 9: /* I/O space read */
472 status = recover_from_read_error(slidx, peidx, pbci); 473 status = recover_from_read_error(slidx, peidx, pbci, sos);
473 break; 474 break;
474 case 0: /* unknown */ 475 case 0: /* unknown */
475 case 2: /* partial write */ 476 case 2: /* partial write */
@@ -508,7 +509,8 @@ recover_from_platform_error(slidx_table_t *slidx, peidx_table_t *peidx, pal_bus_
508 */ 509 */
509 510
510static int 511static int
511recover_from_processor_error(int platform, slidx_table_t *slidx, peidx_table_t *peidx, pal_bus_check_info_t *pbci) 512recover_from_processor_error(int platform, slidx_table_t *slidx, peidx_table_t *peidx, pal_bus_check_info_t *pbci,
513 struct ia64_sal_os_state *sos)
512{ 514{
513 pal_processor_state_info_t *psp = (pal_processor_state_info_t*)peidx_psp(peidx); 515 pal_processor_state_info_t *psp = (pal_processor_state_info_t*)peidx_psp(peidx);
514 516
@@ -545,7 +547,7 @@ recover_from_processor_error(int platform, slidx_table_t *slidx, peidx_table_t *
545 * This means "there are some platform errors". 547 * This means "there are some platform errors".
546 */ 548 */
547 if (platform) 549 if (platform)
548 return recover_from_platform_error(slidx, peidx, pbci); 550 return recover_from_platform_error(slidx, peidx, pbci, sos);
549 /* 551 /*
550 * On account of strange SAL error record, we cannot recover. 552 * On account of strange SAL error record, we cannot recover.
551 */ 553 */
@@ -562,8 +564,7 @@ recover_from_processor_error(int platform, slidx_table_t *slidx, peidx_table_t *
562 564
563static int 565static int
564mca_try_to_recover(void *rec, 566mca_try_to_recover(void *rec,
565 ia64_mca_sal_to_os_state_t *sal_to_os_state, 567 struct ia64_sal_os_state *sos)
566 ia64_mca_os_to_sal_state_t *os_to_sal_state)
567{ 568{
568 int platform_err; 569 int platform_err;
569 int n_proc_err; 570 int n_proc_err;
@@ -571,10 +572,6 @@ mca_try_to_recover(void *rec,
571 peidx_table_t peidx; 572 peidx_table_t peidx;
572 pal_bus_check_info_t pbci; 573 pal_bus_check_info_t pbci;
573 574
574 /* handoff state from/to mca.c */
575 sal_to_os_handoff_state = sal_to_os_state;
576 os_to_sal_handoff_state = os_to_sal_state;
577
578 /* Make index of SAL error record */ 575 /* Make index of SAL error record */
579 platform_err = mca_make_slidx(rec, &slidx); 576 platform_err = mca_make_slidx(rec, &slidx);
580 577
@@ -597,11 +594,11 @@ mca_try_to_recover(void *rec,
597 *((u64*)&pbci) = peidx_check_info(&peidx, bus_check, 0); 594 *((u64*)&pbci) = peidx_check_info(&peidx, bus_check, 0);
598 595
599 /* Check whether MCA is global or not */ 596 /* Check whether MCA is global or not */
600 if (is_mca_global(&peidx, &pbci)) 597 if (is_mca_global(&peidx, &pbci, sos))
601 return 0; 598 return 0;
602 599
603 /* Try to recover a processor error */ 600 /* Try to recover a processor error */
604 return recover_from_processor_error(platform_err, &slidx, &peidx, &pbci); 601 return recover_from_processor_error(platform_err, &slidx, &peidx, &pbci, sos);
605} 602}
606 603
607/* 604/*
diff --git a/arch/ia64/kernel/minstate.h b/arch/ia64/kernel/minstate.h
index f6d8a010d9..85ed54179a 100644
--- a/arch/ia64/kernel/minstate.h
+++ b/arch/ia64/kernel/minstate.h
@@ -5,73 +5,6 @@
5#include "entry.h" 5#include "entry.h"
6 6
7/* 7/*
8 * For ivt.s we want to access the stack virtually so we don't have to disable translation
9 * on interrupts.
10 *
11 * On entry:
12 * r1: pointer to current task (ar.k6)
13 */
14#define MINSTATE_START_SAVE_MIN_VIRT \
15(pUStk) mov ar.rsc=0; /* set enforced lazy mode, pl 0, little-endian, loadrs=0 */ \
16 ;; \
17(pUStk) mov.m r24=ar.rnat; \
18(pUStk) addl r22=IA64_RBS_OFFSET,r1; /* compute base of RBS */ \
19(pKStk) mov r1=sp; /* get sp */ \
20 ;; \
21(pUStk) lfetch.fault.excl.nt1 [r22]; \
22(pUStk) addl r1=IA64_STK_OFFSET-IA64_PT_REGS_SIZE,r1; /* compute base of memory stack */ \
23(pUStk) mov r23=ar.bspstore; /* save ar.bspstore */ \
24 ;; \
25(pUStk) mov ar.bspstore=r22; /* switch to kernel RBS */ \
26(pKStk) addl r1=-IA64_PT_REGS_SIZE,r1; /* if in kernel mode, use sp (r12) */ \
27 ;; \
28(pUStk) mov r18=ar.bsp; \
29(pUStk) mov ar.rsc=0x3; /* set eager mode, pl 0, little-endian, loadrs=0 */
30
31#define MINSTATE_END_SAVE_MIN_VIRT \
32 bsw.1; /* switch back to bank 1 (must be last in insn group) */ \
33 ;;
34
35/*
36 * For mca_asm.S we want to access the stack physically since the state is saved before we
37 * go virtual and don't want to destroy the iip or ipsr.
38 */
39#define MINSTATE_START_SAVE_MIN_PHYS \
40(pKStk) mov r3=IA64_KR(PER_CPU_DATA);; \
41(pKStk) addl r3=THIS_CPU(ia64_mca_data),r3;; \
42(pKStk) ld8 r3 = [r3];; \
43(pKStk) addl r3=IA64_MCA_CPU_INIT_STACK_OFFSET,r3;; \
44(pKStk) addl r1=IA64_STK_OFFSET-IA64_PT_REGS_SIZE,r3; \
45(pUStk) mov ar.rsc=0; /* set enforced lazy mode, pl 0, little-endian, loadrs=0 */ \
46(pUStk) addl r22=IA64_RBS_OFFSET,r1; /* compute base of register backing store */ \
47 ;; \
48(pUStk) mov r24=ar.rnat; \
49(pUStk) addl r1=IA64_STK_OFFSET-IA64_PT_REGS_SIZE,r1; /* compute base of memory stack */ \
50(pUStk) mov r23=ar.bspstore; /* save ar.bspstore */ \
51(pUStk) dep r22=-1,r22,61,3; /* compute kernel virtual addr of RBS */ \
52 ;; \
53(pUStk) mov ar.bspstore=r22; /* switch to kernel RBS */ \
54 ;; \
55(pUStk) mov r18=ar.bsp; \
56(pUStk) mov ar.rsc=0x3; /* set eager mode, pl 0, little-endian, loadrs=0 */ \
57
58#define MINSTATE_END_SAVE_MIN_PHYS \
59 dep r12=-1,r12,61,3; /* make sp a kernel virtual address */ \
60 ;;
61
62#ifdef MINSTATE_VIRT
63# define MINSTATE_GET_CURRENT(reg) mov reg=IA64_KR(CURRENT)
64# define MINSTATE_START_SAVE_MIN MINSTATE_START_SAVE_MIN_VIRT
65# define MINSTATE_END_SAVE_MIN MINSTATE_END_SAVE_MIN_VIRT
66#endif
67
68#ifdef MINSTATE_PHYS
69# define MINSTATE_GET_CURRENT(reg) mov reg=IA64_KR(CURRENT);; tpa reg=reg
70# define MINSTATE_START_SAVE_MIN MINSTATE_START_SAVE_MIN_PHYS
71# define MINSTATE_END_SAVE_MIN MINSTATE_END_SAVE_MIN_PHYS
72#endif
73
74/*
75 * DO_SAVE_MIN switches to the kernel stacks (if necessary) and saves 8 * DO_SAVE_MIN switches to the kernel stacks (if necessary) and saves
76 * the minimum state necessary that allows us to turn psr.ic back 9 * the minimum state necessary that allows us to turn psr.ic back
77 * on. 10 * on.
@@ -97,7 +30,7 @@
97 * we can pass interruption state as arguments to a handler. 30 * we can pass interruption state as arguments to a handler.
98 */ 31 */
99#define DO_SAVE_MIN(COVER,SAVE_IFS,EXTRA) \ 32#define DO_SAVE_MIN(COVER,SAVE_IFS,EXTRA) \
100 MINSTATE_GET_CURRENT(r16); /* M (or M;;I) */ \ 33 mov r16=IA64_KR(CURRENT); /* M */ \
101 mov r27=ar.rsc; /* M */ \ 34 mov r27=ar.rsc; /* M */ \
102 mov r20=r1; /* A */ \ 35 mov r20=r1; /* A */ \
103 mov r25=ar.unat; /* M */ \ 36 mov r25=ar.unat; /* M */ \
@@ -118,7 +51,21 @@
118 SAVE_IFS; \ 51 SAVE_IFS; \
119 cmp.eq pKStk,pUStk=r0,r17; /* are we in kernel mode already? */ \ 52 cmp.eq pKStk,pUStk=r0,r17; /* are we in kernel mode already? */ \
120 ;; \ 53 ;; \
121 MINSTATE_START_SAVE_MIN \ 54(pUStk) mov ar.rsc=0; /* set enforced lazy mode, pl 0, little-endian, loadrs=0 */ \
55 ;; \
56(pUStk) mov.m r24=ar.rnat; \
57(pUStk) addl r22=IA64_RBS_OFFSET,r1; /* compute base of RBS */ \
58(pKStk) mov r1=sp; /* get sp */ \
59 ;; \
60(pUStk) lfetch.fault.excl.nt1 [r22]; \
61(pUStk) addl r1=IA64_STK_OFFSET-IA64_PT_REGS_SIZE,r1; /* compute base of memory stack */ \
62(pUStk) mov r23=ar.bspstore; /* save ar.bspstore */ \
63 ;; \
64(pUStk) mov ar.bspstore=r22; /* switch to kernel RBS */ \
65(pKStk) addl r1=-IA64_PT_REGS_SIZE,r1; /* if in kernel mode, use sp (r12) */ \
66 ;; \
67(pUStk) mov r18=ar.bsp; \
68(pUStk) mov ar.rsc=0x3; /* set eager mode, pl 0, little-endian, loadrs=0 */ \
122 adds r17=2*L1_CACHE_BYTES,r1; /* really: biggest cache-line size */ \ 69 adds r17=2*L1_CACHE_BYTES,r1; /* really: biggest cache-line size */ \
123 adds r16=PT(CR_IPSR),r1; \ 70 adds r16=PT(CR_IPSR),r1; \
124 ;; \ 71 ;; \
@@ -181,7 +128,8 @@
181 EXTRA; \ 128 EXTRA; \
182 movl r1=__gp; /* establish kernel global pointer */ \ 129 movl r1=__gp; /* establish kernel global pointer */ \
183 ;; \ 130 ;; \
184 MINSTATE_END_SAVE_MIN 131 bsw.1; /* switch back to bank 1 (must be last in insn group) */ \
132 ;;
185 133
186/* 134/*
187 * SAVE_REST saves the remainder of pt_regs (with psr.ic on). 135 * SAVE_REST saves the remainder of pt_regs (with psr.ic on).
diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
index 25e7c83445..89faa603c6 100644
--- a/arch/ia64/kernel/palinfo.c
+++ b/arch/ia64/kernel/palinfo.c
@@ -307,11 +307,9 @@ vm_info(char *page)
307 307
308 if ((status = ia64_pal_vm_summary(&vm_info_1, &vm_info_2)) !=0) { 308 if ((status = ia64_pal_vm_summary(&vm_info_1, &vm_info_2)) !=0) {
309 printk(KERN_ERR "ia64_pal_vm_summary=%ld\n", status); 309 printk(KERN_ERR "ia64_pal_vm_summary=%ld\n", status);
310 return 0; 310 } else {
311 }
312 311
313 312 p += sprintf(p,
314 p += sprintf(p,
315 "Physical Address Space : %d bits\n" 313 "Physical Address Space : %d bits\n"
316 "Virtual Address Space : %d bits\n" 314 "Virtual Address Space : %d bits\n"
317 "Protection Key Registers(PKR) : %d\n" 315 "Protection Key Registers(PKR) : %d\n"
@@ -319,92 +317,99 @@ vm_info(char *page)
319 "Hash Tag ID : 0x%x\n" 317 "Hash Tag ID : 0x%x\n"
320 "Size of RR.rid : %d\n", 318 "Size of RR.rid : %d\n",
321 vm_info_1.pal_vm_info_1_s.phys_add_size, 319 vm_info_1.pal_vm_info_1_s.phys_add_size,
322 vm_info_2.pal_vm_info_2_s.impl_va_msb+1, vm_info_1.pal_vm_info_1_s.max_pkr+1, 320 vm_info_2.pal_vm_info_2_s.impl_va_msb+1,
323 vm_info_1.pal_vm_info_1_s.key_size, vm_info_1.pal_vm_info_1_s.hash_tag_id, 321 vm_info_1.pal_vm_info_1_s.max_pkr+1,
322 vm_info_1.pal_vm_info_1_s.key_size,
323 vm_info_1.pal_vm_info_1_s.hash_tag_id,
324 vm_info_2.pal_vm_info_2_s.rid_size); 324 vm_info_2.pal_vm_info_2_s.rid_size);
325 }
325 326
326 if (ia64_pal_mem_attrib(&attrib) != 0) 327 if (ia64_pal_mem_attrib(&attrib) == 0) {
327 return 0; 328 p += sprintf(p, "Supported memory attributes : ");
328 329 sep = "";
329 p += sprintf(p, "Supported memory attributes : "); 330 for (i = 0; i < 8; i++) {
330 sep = ""; 331 if (attrib & (1 << i)) {
331 for (i = 0; i < 8; i++) { 332 p += sprintf(p, "%s%s", sep, mem_attrib[i]);
332 if (attrib & (1 << i)) { 333 sep = ", ";
333 p += sprintf(p, "%s%s", sep, mem_attrib[i]); 334 }
334 sep = ", ";
335 } 335 }
336 p += sprintf(p, "\n");
336 } 337 }
337 p += sprintf(p, "\n");
338 338
339 if ((status = ia64_pal_vm_page_size(&tr_pages, &vw_pages)) !=0) { 339 if ((status = ia64_pal_vm_page_size(&tr_pages, &vw_pages)) !=0) {
340 printk(KERN_ERR "ia64_pal_vm_page_size=%ld\n", status); 340 printk(KERN_ERR "ia64_pal_vm_page_size=%ld\n", status);
341 return 0; 341 } else {
342 }
343
344 p += sprintf(p,
345 "\nTLB walker : %simplemented\n"
346 "Number of DTR : %d\n"
347 "Number of ITR : %d\n"
348 "TLB insertable page sizes : ",
349 vm_info_1.pal_vm_info_1_s.vw ? "" : "not ",
350 vm_info_1.pal_vm_info_1_s.max_dtr_entry+1,
351 vm_info_1.pal_vm_info_1_s.max_itr_entry+1);
352 342
343 p += sprintf(p,
344 "\nTLB walker : %simplemented\n"
345 "Number of DTR : %d\n"
346 "Number of ITR : %d\n"
347 "TLB insertable page sizes : ",
348 vm_info_1.pal_vm_info_1_s.vw ? "" : "not ",
349 vm_info_1.pal_vm_info_1_s.max_dtr_entry+1,
350 vm_info_1.pal_vm_info_1_s.max_itr_entry+1);
353 351
354 p = bitvector_process(p, tr_pages);
355 352
356 p += sprintf(p, "\nTLB purgeable page sizes : "); 353 p = bitvector_process(p, tr_pages);
357 354
358 p = bitvector_process(p, vw_pages); 355 p += sprintf(p, "\nTLB purgeable page sizes : ");
359 356
357 p = bitvector_process(p, vw_pages);
358 }
360 if ((status=ia64_get_ptce(&ptce)) != 0) { 359 if ((status=ia64_get_ptce(&ptce)) != 0) {
361 printk(KERN_ERR "ia64_get_ptce=%ld\n", status); 360 printk(KERN_ERR "ia64_get_ptce=%ld\n", status);
362 return 0; 361 } else {
363 } 362 p += sprintf(p,
364
365 p += sprintf(p,
366 "\nPurge base address : 0x%016lx\n" 363 "\nPurge base address : 0x%016lx\n"
367 "Purge outer loop count : %d\n" 364 "Purge outer loop count : %d\n"
368 "Purge inner loop count : %d\n" 365 "Purge inner loop count : %d\n"
369 "Purge outer loop stride : %d\n" 366 "Purge outer loop stride : %d\n"
370 "Purge inner loop stride : %d\n", 367 "Purge inner loop stride : %d\n",
371 ptce.base, ptce.count[0], ptce.count[1], ptce.stride[0], ptce.stride[1]); 368 ptce.base, ptce.count[0], ptce.count[1],
369 ptce.stride[0], ptce.stride[1]);
372 370
373 p += sprintf(p, 371 p += sprintf(p,
374 "TC Levels : %d\n" 372 "TC Levels : %d\n"
375 "Unique TC(s) : %d\n", 373 "Unique TC(s) : %d\n",
376 vm_info_1.pal_vm_info_1_s.num_tc_levels, 374 vm_info_1.pal_vm_info_1_s.num_tc_levels,
377 vm_info_1.pal_vm_info_1_s.max_unique_tcs); 375 vm_info_1.pal_vm_info_1_s.max_unique_tcs);
378 376
379 for(i=0; i < vm_info_1.pal_vm_info_1_s.num_tc_levels; i++) { 377 for(i=0; i < vm_info_1.pal_vm_info_1_s.num_tc_levels; i++) {
380 for (j=2; j>0 ; j--) { 378 for (j=2; j>0 ; j--) {
381 tc_pages = 0; /* just in case */ 379 tc_pages = 0; /* just in case */
382 380
383 381
384 /* even without unification, some levels may not be present */ 382 /* even without unification, some levels may not be present */
385 if ((status=ia64_pal_vm_info(i,j, &tc_info, &tc_pages)) != 0) { 383 if ((status=ia64_pal_vm_info(i,j, &tc_info, &tc_pages)) != 0) {
386 continue; 384 continue;
387 } 385 }
388 386
389 p += sprintf(p, 387 p += sprintf(p,
390 "\n%s Translation Cache Level %d:\n" 388 "\n%s Translation Cache Level %d:\n"
391 "\tHash sets : %d\n" 389 "\tHash sets : %d\n"
392 "\tAssociativity : %d\n" 390 "\tAssociativity : %d\n"
393 "\tNumber of entries : %d\n" 391 "\tNumber of entries : %d\n"
394 "\tFlags : ", 392 "\tFlags : ",
395 cache_types[j+tc_info.tc_unified], i+1, tc_info.tc_num_sets, 393 cache_types[j+tc_info.tc_unified], i+1,
396 tc_info.tc_associativity, tc_info.tc_num_entries); 394 tc_info.tc_num_sets,
395 tc_info.tc_associativity,
396 tc_info.tc_num_entries);
397 397
398 if (tc_info.tc_pf) p += sprintf(p, "PreferredPageSizeOptimized "); 398 if (tc_info.tc_pf)
399 if (tc_info.tc_unified) p += sprintf(p, "Unified "); 399 p += sprintf(p, "PreferredPageSizeOptimized ");
400 if (tc_info.tc_reduce_tr) p += sprintf(p, "TCReduction"); 400 if (tc_info.tc_unified)
401 p += sprintf(p, "Unified ");
402 if (tc_info.tc_reduce_tr)
403 p += sprintf(p, "TCReduction");
401 404
402 p += sprintf(p, "\n\tSupported page sizes: "); 405 p += sprintf(p, "\n\tSupported page sizes: ");
403 406
404 p = bitvector_process(p, tc_pages); 407 p = bitvector_process(p, tc_pages);
405 408
406 /* when unified date (j=2) is enough */ 409 /* when unified date (j=2) is enough */
407 if (tc_info.tc_unified) break; 410 if (tc_info.tc_unified)
411 break;
412 }
408 } 413 }
409 } 414 }
410 p += sprintf(p, "\n"); 415 p += sprintf(p, "\n");
@@ -440,14 +445,14 @@ register_info(char *page)
440 p += sprintf(p, "\n"); 445 p += sprintf(p, "\n");
441 } 446 }
442 447
443 if (ia64_pal_rse_info(&phys_stacked, &hints) != 0) return 0; 448 if (ia64_pal_rse_info(&phys_stacked, &hints) == 0) {
444 449
445 p += sprintf(p, 450 p += sprintf(p,
446 "RSE stacked physical registers : %ld\n" 451 "RSE stacked physical registers : %ld\n"
447 "RSE load/store hints : %ld (%s)\n", 452 "RSE load/store hints : %ld (%s)\n",
448 phys_stacked, hints.ph_data, 453 phys_stacked, hints.ph_data,
449 hints.ph_data < RSE_HINTS_COUNT ? rse_hints[hints.ph_data]: "(??)"); 454 hints.ph_data < RSE_HINTS_COUNT ? rse_hints[hints.ph_data]: "(??)");
450 455 }
451 if (ia64_pal_debug_info(&iregs, &dregs)) 456 if (ia64_pal_debug_info(&iregs, &dregs))
452 return 0; 457 return 0;
453 458
diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c
index f1201ac8a1..1650353e3f 100644
--- a/arch/ia64/kernel/perfmon.c
+++ b/arch/ia64/kernel/perfmon.c
@@ -38,6 +38,7 @@
38#include <linux/pagemap.h> 38#include <linux/pagemap.h>
39#include <linux/mount.h> 39#include <linux/mount.h>
40#include <linux/bitops.h> 40#include <linux/bitops.h>
41#include <linux/rcupdate.h>
41 42
42#include <asm/errno.h> 43#include <asm/errno.h>
43#include <asm/intrinsics.h> 44#include <asm/intrinsics.h>
@@ -496,7 +497,7 @@ typedef struct {
496static pfm_stats_t pfm_stats[NR_CPUS]; 497static pfm_stats_t pfm_stats[NR_CPUS];
497static pfm_session_t pfm_sessions; /* global sessions information */ 498static pfm_session_t pfm_sessions; /* global sessions information */
498 499
499static spinlock_t pfm_alt_install_check = SPIN_LOCK_UNLOCKED; 500static DEFINE_SPINLOCK(pfm_alt_install_check);
500static pfm_intr_handler_desc_t *pfm_alt_intr_handler; 501static pfm_intr_handler_desc_t *pfm_alt_intr_handler;
501 502
502static struct proc_dir_entry *perfmon_dir; 503static struct proc_dir_entry *perfmon_dir;
@@ -2217,15 +2218,17 @@ static void
2217pfm_free_fd(int fd, struct file *file) 2218pfm_free_fd(int fd, struct file *file)
2218{ 2219{
2219 struct files_struct *files = current->files; 2220 struct files_struct *files = current->files;
2221 struct fdtable *fdt = files_fdtable(files);
2220 2222
2221 /* 2223 /*
2222 * there ie no fd_uninstall(), so we do it here 2224 * there ie no fd_uninstall(), so we do it here
2223 */ 2225 */
2224 spin_lock(&files->file_lock); 2226 spin_lock(&files->file_lock);
2225 files->fd[fd] = NULL; 2227 rcu_assign_pointer(fdt->fd[fd], NULL);
2226 spin_unlock(&files->file_lock); 2228 spin_unlock(&files->file_lock);
2227 2229
2228 if (file) put_filp(file); 2230 if (file)
2231 put_filp(file);
2229 put_unused_fd(fd); 2232 put_unused_fd(fd);
2230} 2233}
2231 2234
diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
index 6f0cc7a663..ca68e6e44a 100644
--- a/arch/ia64/kernel/salinfo.c
+++ b/arch/ia64/kernel/salinfo.c
@@ -22,6 +22,11 @@
22 * 22 *
23 * Dec 5 2004 kaos@sgi.com 23 * Dec 5 2004 kaos@sgi.com
24 * Standardize which records are cleared automatically. 24 * Standardize which records are cleared automatically.
25 *
26 * Aug 18 2005 kaos@sgi.com
27 * mca.c may not pass a buffer, a NULL buffer just indicates that a new
28 * record is available in SAL.
29 * Replace some NR_CPUS by cpus_online, for hotplug cpu.
25 */ 30 */
26 31
27#include <linux/types.h> 32#include <linux/types.h>
@@ -193,7 +198,7 @@ shift1_data_saved (struct salinfo_data *data, int shift)
193 * The buffer passed from mca.c points to the output from ia64_log_get. This is 198 * The buffer passed from mca.c points to the output from ia64_log_get. This is
194 * a persistent buffer but its contents can change between the interrupt and 199 * a persistent buffer but its contents can change between the interrupt and
195 * when user space processes the record. Save the record id to identify 200 * when user space processes the record. Save the record id to identify
196 * changes. 201 * changes. If the buffer is NULL then just update the bitmap.
197 */ 202 */
198void 203void
199salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe) 204salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe)
@@ -206,27 +211,29 @@ salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe)
206 211
207 BUG_ON(type >= ARRAY_SIZE(salinfo_log_name)); 212 BUG_ON(type >= ARRAY_SIZE(salinfo_log_name));
208 213
209 if (irqsafe) 214 if (buffer) {
210 spin_lock_irqsave(&data_saved_lock, flags); 215 if (irqsafe)
211 for (i = 0, data_saved = data->data_saved; i < saved_size; ++i, ++data_saved) { 216 spin_lock_irqsave(&data_saved_lock, flags);
212 if (!data_saved->buffer) 217 for (i = 0, data_saved = data->data_saved; i < saved_size; ++i, ++data_saved) {
213 break; 218 if (!data_saved->buffer)
214 } 219 break;
215 if (i == saved_size) { 220 }
216 if (!data->saved_num) { 221 if (i == saved_size) {
217 shift1_data_saved(data, 0); 222 if (!data->saved_num) {
218 data_saved = data->data_saved + saved_size - 1; 223 shift1_data_saved(data, 0);
219 } else 224 data_saved = data->data_saved + saved_size - 1;
220 data_saved = NULL; 225 } else
221 } 226 data_saved = NULL;
222 if (data_saved) { 227 }
223 data_saved->cpu = smp_processor_id(); 228 if (data_saved) {
224 data_saved->id = ((sal_log_record_header_t *)buffer)->id; 229 data_saved->cpu = smp_processor_id();
225 data_saved->size = size; 230 data_saved->id = ((sal_log_record_header_t *)buffer)->id;
226 data_saved->buffer = buffer; 231 data_saved->size = size;
232 data_saved->buffer = buffer;
233 }
234 if (irqsafe)
235 spin_unlock_irqrestore(&data_saved_lock, flags);
227 } 236 }
228 if (irqsafe)
229 spin_unlock_irqrestore(&data_saved_lock, flags);
230 237
231 if (!test_and_set_bit(smp_processor_id(), &data->cpu_event)) { 238 if (!test_and_set_bit(smp_processor_id(), &data->cpu_event)) {
232 if (irqsafe) 239 if (irqsafe)
@@ -244,7 +251,7 @@ salinfo_timeout_check(struct salinfo_data *data)
244 int i; 251 int i;
245 if (!data->open) 252 if (!data->open)
246 return; 253 return;
247 for (i = 0; i < NR_CPUS; ++i) { 254 for_each_online_cpu(i) {
248 if (test_bit(i, &data->cpu_event)) { 255 if (test_bit(i, &data->cpu_event)) {
249 /* double up() is not a problem, user space will see no 256 /* double up() is not a problem, user space will see no
250 * records for the additional "events". 257 * records for the additional "events".
@@ -291,7 +298,7 @@ retry:
291 298
292 n = data->cpu_check; 299 n = data->cpu_check;
293 for (i = 0; i < NR_CPUS; i++) { 300 for (i = 0; i < NR_CPUS; i++) {
294 if (test_bit(n, &data->cpu_event)) { 301 if (test_bit(n, &data->cpu_event) && cpu_online(n)) {
295 cpu = n; 302 cpu = n;
296 break; 303 break;
297 } 304 }
@@ -585,11 +592,10 @@ salinfo_init(void)
585 592
586 /* we missed any events before now */ 593 /* we missed any events before now */
587 online = 0; 594 online = 0;
588 for (j = 0; j < NR_CPUS; j++) 595 for_each_online_cpu(j) {
589 if (cpu_online(j)) { 596 set_bit(j, &data->cpu_event);
590 set_bit(j, &data->cpu_event); 597 ++online;
591 ++online; 598 }
592 }
593 sema_init(&data->sem, online); 599 sema_init(&data->sem, online);
594 600
595 *sdir++ = dir; 601 *sdir++ = dir;
diff --git a/arch/ia64/kernel/unwind.c b/arch/ia64/kernel/unwind.c
index 3288be47bc..93d5a3b41f 100644
--- a/arch/ia64/kernel/unwind.c
+++ b/arch/ia64/kernel/unwind.c
@@ -2020,28 +2020,6 @@ init_frame_info (struct unw_frame_info *info, struct task_struct *t,
2020} 2020}
2021 2021
2022void 2022void
2023unw_init_from_interruption (struct unw_frame_info *info, struct task_struct *t,
2024 struct pt_regs *pt, struct switch_stack *sw)
2025{
2026 unsigned long sof;
2027
2028 init_frame_info(info, t, sw, pt->r12);
2029 info->cfm_loc = &pt->cr_ifs;
2030 info->unat_loc = &pt->ar_unat;
2031 info->pfs_loc = &pt->ar_pfs;
2032 sof = *info->cfm_loc & 0x7f;
2033 info->bsp = (unsigned long) ia64_rse_skip_regs((unsigned long *) info->regstk.top, -sof);
2034 info->ip = pt->cr_iip + ia64_psr(pt)->ri;
2035 info->pt = (unsigned long) pt;
2036 UNW_DPRINT(3, "unwind.%s:\n"
2037 " bsp 0x%lx\n"
2038 " sof 0x%lx\n"
2039 " ip 0x%lx\n",
2040 __FUNCTION__, info->bsp, sof, info->ip);
2041 find_save_locs(info);
2042}
2043
2044void
2045unw_init_frame_info (struct unw_frame_info *info, struct task_struct *t, struct switch_stack *sw) 2023unw_init_frame_info (struct unw_frame_info *info, struct task_struct *t, struct switch_stack *sw)
2046{ 2024{
2047 unsigned long sol; 2025 unsigned long sol;
diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
index 65f9958db9..1281c609ee 100644
--- a/arch/ia64/mm/init.c
+++ b/arch/ia64/mm/init.c
@@ -382,13 +382,22 @@ ia64_mmu_init (void *my_cpu_data)
382 382
383 if (impl_va_bits < 51 || impl_va_bits > 61) 383 if (impl_va_bits < 51 || impl_va_bits > 61)
384 panic("CPU has bogus IMPL_VA_MSB value of %lu!\n", impl_va_bits - 1); 384 panic("CPU has bogus IMPL_VA_MSB value of %lu!\n", impl_va_bits - 1);
385 /*
386 * mapped_space_bits - PAGE_SHIFT is the total number of ptes we need,
387 * which must fit into "vmlpt_bits - pte_bits" slots. Second half of
388 * the test makes sure that our mapped space doesn't overlap the
389 * unimplemented hole in the middle of the region.
390 */
391 if ((mapped_space_bits - PAGE_SHIFT > vmlpt_bits - pte_bits) ||
392 (mapped_space_bits > impl_va_bits - 1))
393 panic("Cannot build a big enough virtual-linear page table"
394 " to cover mapped address space.\n"
395 " Try using a smaller page size.\n");
396
385 397
386 /* place the VMLPT at the end of each page-table mapped region: */ 398 /* place the VMLPT at the end of each page-table mapped region: */
387 pta = POW2(61) - POW2(vmlpt_bits); 399 pta = POW2(61) - POW2(vmlpt_bits);
388 400
389 if (POW2(mapped_space_bits) >= pta)
390 panic("mm/init: overlap between virtually mapped linear page table and "
391 "mapped kernel space!");
392 /* 401 /*
393 * Set the (virtually mapped linear) page table address. Bit 402 * Set the (virtually mapped linear) page table address. Bit
394 * 8 selects between the short and long format, bits 2-7 the 403 * 8 selects between the short and long format, bits 2-7 the
diff --git a/arch/ia64/sn/kernel/setup.c b/arch/ia64/sn/kernel/setup.c
index 14908ad7db..6f8c588371 100644
--- a/arch/ia64/sn/kernel/setup.c
+++ b/arch/ia64/sn/kernel/setup.c
@@ -49,6 +49,7 @@
49#include <asm/sn/clksupport.h> 49#include <asm/sn/clksupport.h>
50#include <asm/sn/sn_sal.h> 50#include <asm/sn/sn_sal.h>
51#include <asm/sn/geo.h> 51#include <asm/sn/geo.h>
52#include <asm/sn/sn_feature_sets.h>
52#include "xtalk/xwidgetdev.h" 53#include "xtalk/xwidgetdev.h"
53#include "xtalk/hubdev.h" 54#include "xtalk/hubdev.h"
54#include <asm/sn/klconfig.h> 55#include <asm/sn/klconfig.h>
@@ -97,6 +98,7 @@ EXPORT_SYMBOL(sn_region_size);
97int sn_prom_type; /* 0=hardware, 1=medusa/realprom, 2=medusa/fakeprom */ 98int sn_prom_type; /* 0=hardware, 1=medusa/realprom, 2=medusa/fakeprom */
98 99
99short physical_node_map[MAX_PHYSNODE_ID]; 100short physical_node_map[MAX_PHYSNODE_ID];
101static unsigned long sn_prom_features[MAX_PROM_FEATURE_SETS];
100 102
101EXPORT_SYMBOL(physical_node_map); 103EXPORT_SYMBOL(physical_node_map);
102 104
@@ -271,7 +273,10 @@ void __init sn_setup(char **cmdline_p)
271 u32 version = sn_sal_rev(); 273 u32 version = sn_sal_rev();
272 extern void sn_cpu_init(void); 274 extern void sn_cpu_init(void);
273 275
274 ia64_sn_plat_set_error_handling_features(); 276 ia64_sn_plat_set_error_handling_features(); // obsolete
277 ia64_sn_set_os_feature(OSF_MCA_SLV_TO_OS_INIT_SLV);
278 ia64_sn_set_os_feature(OSF_FEAT_LOG_SBES);
279
275 280
276#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE) 281#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
277 /* 282 /*
@@ -314,16 +319,6 @@ void __init sn_setup(char **cmdline_p)
314 319
315 printk("SGI SAL version %x.%02x\n", version >> 8, version & 0x00FF); 320 printk("SGI SAL version %x.%02x\n", version >> 8, version & 0x00FF);
316 321
317 /*
318 * Confirm the SAL we're running on is recent enough...
319 */
320 if (version < SN_SAL_MIN_VERSION) {
321 printk(KERN_ERR "This kernel needs SGI SAL version >= "
322 "%x.%02x\n", SN_SAL_MIN_VERSION >> 8,
323 SN_SAL_MIN_VERSION & 0x00FF);
324 panic("PROM version too old\n");
325 }
326
327 master_nasid = boot_get_nasid(); 322 master_nasid = boot_get_nasid();
328 323
329 status = 324 status =
@@ -480,6 +475,10 @@ void __init sn_cpu_init(void)
480 if (nodepdaindr[0] == NULL) 475 if (nodepdaindr[0] == NULL)
481 return; 476 return;
482 477
478 for (i = 0; i < MAX_PROM_FEATURE_SETS; i++)
479 if (ia64_sn_get_prom_feature_set(i, &sn_prom_features[i]) != 0)
480 break;
481
483 cpuid = smp_processor_id(); 482 cpuid = smp_processor_id();
484 cpuphyid = get_sapicid(); 483 cpuphyid = get_sapicid();
485 484
@@ -651,3 +650,12 @@ nasid_slice_to_cpuid(int nasid, int slice)
651 650
652 return -1; 651 return -1;
653} 652}
653
654int sn_prom_feature_available(int id)
655{
656 if (id >= BITS_PER_LONG * MAX_PROM_FEATURE_SETS)
657 return 0;
658 return test_bit(id, sn_prom_features);
659}
660EXPORT_SYMBOL(sn_prom_feature_available);
661
diff --git a/arch/ia64/sn/kernel/xpnet.c b/arch/ia64/sn/kernel/xpnet.c
index d0c2c114a4..e5c6d3c0a8 100644
--- a/arch/ia64/sn/kernel/xpnet.c
+++ b/arch/ia64/sn/kernel/xpnet.c
@@ -130,7 +130,7 @@ struct net_device *xpnet_device;
130 */ 130 */
131static u64 xpnet_broadcast_partitions; 131static u64 xpnet_broadcast_partitions;
132/* protect above */ 132/* protect above */
133static spinlock_t xpnet_broadcast_lock = SPIN_LOCK_UNLOCKED; 133static DEFINE_SPINLOCK(xpnet_broadcast_lock);
134 134
135/* 135/*
136 * Since the Block Transfer Engine (BTE) is being used for the transfer 136 * Since the Block Transfer Engine (BTE) is being used for the transfer
diff --git a/arch/m32r/Kconfig b/arch/m32r/Kconfig
index 7622d4ec5f..1ef3987ebc 100644
--- a/arch/m32r/Kconfig
+++ b/arch/m32r/Kconfig
@@ -242,8 +242,8 @@ config SMP
242 Y to "Enhanced Real Time Clock Support", below. The "Advanced Power 242 Y to "Enhanced Real Time Clock Support", below. The "Advanced Power
243 Management" code will be disabled if you say Y here. 243 Management" code will be disabled if you say Y here.
244 244
245 See also the <file:Documentation/smp.tex>, 245 See also the <file:Documentation/smp.txt>,
246 <file:Documentation/smp.txt> and the SMP-HOWTO available at 246 and the SMP-HOWTO available at
247 <http://www.linuxdoc.org/docs.html#howto>. 247 <http://www.linuxdoc.org/docs.html#howto>.
248 248
249 If you don't know what to do here, say N. 249 If you don't know what to do here, say N.
diff --git a/arch/m32r/kernel/asm-offsets.c b/arch/m32r/kernel/asm-offsets.c
new file mode 100644
index 0000000000..9e263112a6
--- /dev/null
+++ b/arch/m32r/kernel/asm-offsets.c
@@ -0,0 +1 @@
/* Dummy asm-offsets.c file. Required by kbuild and ready to be used - hint! */
diff --git a/arch/m32r/kernel/smp.c b/arch/m32r/kernel/smp.c
index 48b187f2d2..a4576ac7e8 100644
--- a/arch/m32r/kernel/smp.c
+++ b/arch/m32r/kernel/smp.c
@@ -892,7 +892,6 @@ unsigned long send_IPI_mask_phys(cpumask_t physid_mask, int ipi_num,
892 int try) 892 int try)
893{ 893{
894 spinlock_t *ipilock; 894 spinlock_t *ipilock;
895 unsigned long flags = 0;
896 volatile unsigned long *ipicr_addr; 895 volatile unsigned long *ipicr_addr;
897 unsigned long ipicr_val; 896 unsigned long ipicr_val;
898 unsigned long my_physid_mask; 897 unsigned long my_physid_mask;
@@ -916,50 +915,27 @@ unsigned long send_IPI_mask_phys(cpumask_t physid_mask, int ipi_num,
916 * write IPICRi (send IPIi) 915 * write IPICRi (send IPIi)
917 * unlock ipi_lock[i] 916 * unlock ipi_lock[i]
918 */ 917 */
918 spin_lock(ipilock);
919 __asm__ __volatile__ ( 919 __asm__ __volatile__ (
920 ";; LOCK ipi_lock[i] \n\t" 920 ";; CHECK IPICRi == 0 \n\t"
921 ".fillinsn \n" 921 ".fillinsn \n"
922 "1: \n\t" 922 "1: \n\t"
923 "mvfc %1, psw \n\t" 923 "ld %0, @%1 \n\t"
924 "clrpsw #0x40 -> nop \n\t" 924 "and %0, %4 \n\t"
925 DCACHE_CLEAR("r4", "r5", "%2") 925 "beqz %0, 2f \n\t"
926 "lock r4, @%2 \n\t" 926 "bnez %3, 3f \n\t"
927 "addi r4, #-1 \n\t"
928 "unlock r4, @%2 \n\t"
929 "mvtc %1, psw \n\t"
930 "bnez r4, 2f \n\t"
931 LOCK_SECTION_START(".balign 4 \n\t")
932 ".fillinsn \n"
933 "2: \n\t"
934 "ld r4, @%2 \n\t"
935 "blez r4, 2b \n\t"
936 "bra 1b \n\t" 927 "bra 1b \n\t"
937 LOCK_SECTION_END
938 ";; CHECK IPICRi == 0 \n\t"
939 ".fillinsn \n"
940 "3: \n\t"
941 "ld %0, @%3 \n\t"
942 "and %0, %6 \n\t"
943 "beqz %0, 4f \n\t"
944 "bnez %5, 5f \n\t"
945 "bra 3b \n\t"
946 ";; WRITE IPICRi (send IPIi) \n\t" 928 ";; WRITE IPICRi (send IPIi) \n\t"
947 ".fillinsn \n" 929 ".fillinsn \n"
948 "4: \n\t" 930 "2: \n\t"
949 "st %4, @%3 \n\t" 931 "st %2, @%1 \n\t"
950 ";; UNLOCK ipi_lock[i] \n\t"
951 ".fillinsn \n" 932 ".fillinsn \n"
952 "5: \n\t" 933 "3: \n\t"
953 "ldi r4, #1 \n\t"
954 "st r4, @%2 \n\t"
955 : "=&r"(ipicr_val) 934 : "=&r"(ipicr_val)
956 : "r"(flags), "r"(&ipilock->slock), "r"(ipicr_addr), 935 : "r"(ipicr_addr), "r"(mask), "r"(try), "r"(my_physid_mask)
957 "r"(mask), "r"(try), "r"(my_physid_mask) 936 : "memory"
958 : "memory", "r4"
959#ifdef CONFIG_CHIP_M32700_TS1
960 , "r5"
961#endif /* CONFIG_CHIP_M32700_TS1 */
962 ); 937 );
938 spin_unlock(ipilock);
963 939
964 return ipicr_val; 940 return ipicr_val;
965} 941}
diff --git a/arch/m68k/Makefile b/arch/m68k/Makefile
index 466e7407af..34d826d10f 100644
--- a/arch/m68k/Makefile
+++ b/arch/m68k/Makefile
@@ -113,14 +113,5 @@ else
113 bzip2 -1c vmlinux >vmlinux.bz2 113 bzip2 -1c vmlinux >vmlinux.bz2
114endif 114endif
115 115
116prepare: include/asm-$(ARCH)/offsets.h
117CLEAN_FILES += include/asm-$(ARCH)/offsets.h
118
119arch/$(ARCH)/kernel/asm-offsets.s: include/asm include/linux/version.h \
120 include/config/MARKER
121
122include/asm-$(ARCH)/offsets.h: arch/$(ARCH)/kernel/asm-offsets.s
123 $(call filechk,gen-asm-offsets)
124
125archclean: 116archclean:
126 rm -f vmlinux.gz vmlinux.bz2 117 rm -f vmlinux.gz vmlinux.bz2
diff --git a/arch/m68k/amiga/amisound.c b/arch/m68k/amiga/amisound.c
index cb5d936304..bd5d134e9f 100644
--- a/arch/m68k/amiga/amisound.c
+++ b/arch/m68k/amiga/amisound.c
@@ -63,7 +63,7 @@ void __init amiga_init_sound(void)
63} 63}
64 64
65static void nosound( unsigned long ignored ); 65static void nosound( unsigned long ignored );
66static struct timer_list sound_timer = TIMER_INITIALIZER(nosound, 0, 0); 66static DEFINE_TIMER(sound_timer, nosound, 0, 0);
67 67
68void amiga_mksound( unsigned int hz, unsigned int ticks ) 68void amiga_mksound( unsigned int hz, unsigned int ticks )
69{ 69{
diff --git a/arch/m68k/fpsp040/skeleton.S b/arch/m68k/fpsp040/skeleton.S
index dbc1255a5e..9571a21d6a 100644
--- a/arch/m68k/fpsp040/skeleton.S
+++ b/arch/m68k/fpsp040/skeleton.S
@@ -40,7 +40,7 @@
40 40
41#include <linux/linkage.h> 41#include <linux/linkage.h>
42#include <asm/entry.h> 42#include <asm/entry.h>
43#include <asm/offsets.h> 43#include <asm/asm-offsets.h>
44 44
45|SKELETON idnt 2,1 | Motorola 040 Floating Point Software Package 45|SKELETON idnt 2,1 | Motorola 040 Floating Point Software Package
46 46
diff --git a/arch/m68k/ifpsp060/iskeleton.S b/arch/m68k/ifpsp060/iskeleton.S
index 803a6ecdda..4ba2c74da9 100644
--- a/arch/m68k/ifpsp060/iskeleton.S
+++ b/arch/m68k/ifpsp060/iskeleton.S
@@ -36,7 +36,7 @@
36 36
37#include <linux/linkage.h> 37#include <linux/linkage.h>
38#include <asm/entry.h> 38#include <asm/entry.h>
39#include <asm/offsets.h> 39#include <asm/asm-offsets.h>
40 40
41 41
42|################################ 42|################################
diff --git a/arch/m68k/kernel/entry.S b/arch/m68k/kernel/entry.S
index e964015a31..23ca60a455 100644
--- a/arch/m68k/kernel/entry.S
+++ b/arch/m68k/kernel/entry.S
@@ -42,7 +42,7 @@
42#include <asm/traps.h> 42#include <asm/traps.h>
43#include <asm/unistd.h> 43#include <asm/unistd.h>
44 44
45#include <asm/offsets.h> 45#include <asm/asm-offsets.h>
46 46
47.globl system_call, buserr, trap 47.globl system_call, buserr, trap
48.globl resume, ret_from_exception 48.globl resume, ret_from_exception
diff --git a/arch/m68k/kernel/head.S b/arch/m68k/kernel/head.S
index 7cd6de17c2..d4336d846d 100644
--- a/arch/m68k/kernel/head.S
+++ b/arch/m68k/kernel/head.S
@@ -263,7 +263,7 @@
263#include <asm/entry.h> 263#include <asm/entry.h>
264#include <asm/pgtable.h> 264#include <asm/pgtable.h>
265#include <asm/page.h> 265#include <asm/page.h>
266#include <asm/offsets.h> 266#include <asm/asm-offsets.h>
267 267
268#ifdef CONFIG_MAC 268#ifdef CONFIG_MAC
269 269
diff --git a/arch/m68k/mac/macboing.c b/arch/m68k/mac/macboing.c
index 44c5cd2ad6..8f0640847a 100644
--- a/arch/m68k/mac/macboing.c
+++ b/arch/m68k/mac/macboing.c
@@ -56,8 +56,7 @@ static void ( *mac_special_bell )( unsigned int, unsigned int, unsigned int );
56/* 56/*
57 * our timer to start/continue/stop the bell 57 * our timer to start/continue/stop the bell
58 */ 58 */
59static struct timer_list mac_sound_timer = 59static DEFINE_TIMER(mac_sound_timer, mac_nosound, 0, 0);
60 TIMER_INITIALIZER(mac_nosound, 0, 0);
61 60
62/* 61/*
63 * Sort of initialize the sound chip (called from mac_mksound on the first 62 * Sort of initialize the sound chip (called from mac_mksound on the first
diff --git a/arch/m68k/math-emu/fp_emu.h b/arch/m68k/math-emu/fp_emu.h
index 1d6edc975d..c1ecfef788 100644
--- a/arch/m68k/math-emu/fp_emu.h
+++ b/arch/m68k/math-emu/fp_emu.h
@@ -39,7 +39,7 @@
39#define _FP_EMU_H 39#define _FP_EMU_H
40 40
41#ifdef __ASSEMBLY__ 41#ifdef __ASSEMBLY__
42#include <asm/offsets.h> 42#include <asm/asm-offsets.h>
43#endif 43#endif
44#include <asm/math-emu.h> 44#include <asm/math-emu.h>
45 45
diff --git a/arch/m68knommu/Makefile b/arch/m68knommu/Makefile
index 7ce5e55b24..b8fdf191b8 100644
--- a/arch/m68knommu/Makefile
+++ b/arch/m68knommu/Makefile
@@ -102,21 +102,11 @@ CFLAGS += -DUTS_SYSNAME=\"uClinux\"
102 102
103head-y := arch/m68knommu/platform/$(cpuclass-y)/head.o 103head-y := arch/m68knommu/platform/$(cpuclass-y)/head.o
104 104
105CLEAN_FILES := include/asm-$(ARCH)/asm-offsets.h \
106 arch/$(ARCH)/kernel/asm-offsets.s
107
108core-y += arch/m68knommu/kernel/ \ 105core-y += arch/m68knommu/kernel/ \
109 arch/m68knommu/mm/ \ 106 arch/m68knommu/mm/ \
110 $(CLASSDIR) \ 107 $(CLASSDIR) \
111 arch/m68knommu/platform/$(PLATFORM)/ 108 arch/m68knommu/platform/$(PLATFORM)/
112libs-y += arch/m68knommu/lib/ 109libs-y += arch/m68knommu/lib/
113 110
114prepare: include/asm-$(ARCH)/asm-offsets.h
115
116archclean: 111archclean:
117 $(Q)$(MAKE) $(clean)=arch/m68knommu/boot 112 $(Q)$(MAKE) $(clean)=arch/m68knommu/boot
118
119include/asm-$(ARCH)/asm-offsets.h: arch/$(ARCH)/kernel/asm-offsets.s \
120 include/asm include/linux/version.h \
121 include/config/MARKER
122 $(call filechk,gen-asm-offsets)
diff --git a/arch/m68knommu/platform/68360/head-ram.S b/arch/m68knommu/platform/68360/head-ram.S
new file mode 100644
index 0000000000..a5c639a51e
--- /dev/null
+++ b/arch/m68knommu/platform/68360/head-ram.S
@@ -0,0 +1,408 @@
1/* arch/m68knommu/platform/68360/head-ram.S
2 *
3 * Startup code for Motorola 68360
4 *
5 * Copyright 2001 (C) SED Systems, a Division of Calian Ltd.
6 * Based on: arch/m68knommu/platform/68328/pilot/crt0_rom.S
7 * Based on: arch/m68knommu/platform/68360/uCquicc/crt0_rom.S, 2.0.38.1.pre7
8 * uClinux Kernel
9 * Copyright (C) Michael Leslie <mleslie@lineo.com>
10 * Based on: arch/m68knommu/platform/68EZ328/ucsimm/crt0_rom.S
11 * Copyright (C) 1998 D. Jeff Dionne <jeff@uclinux.org>,
12 *
13 */
14#define ASSEMBLY
15#include <linux/config.h>
16
17.global _stext
18.global _start
19
20.global _rambase
21.global __ramvec
22.global _ramvec
23.global _ramstart
24.global _ramend
25
26.global _quicc_base
27.global _periph_base
28
29#define REGB 0x1000
30#define PEPAR (_dprbase + REGB + 0x0016)
31#define GMR (_dprbase + REGB + 0x0040)
32#define OR0 (_dprbase + REGB + 0x0054)
33#define BR0 (_dprbase + REGB + 0x0050)
34#define OR1 (_dprbase + REGB + 0x0064)
35#define BR1 (_dprbase + REGB + 0x0060)
36#define OR4 (_dprbase + REGB + 0x0094)
37#define BR4 (_dprbase + REGB + 0x0090)
38#define OR6 (_dprbase + REGB + 0x00b4)
39#define BR6 (_dprbase + REGB + 0x00b0)
40#define OR7 (_dprbase + REGB + 0x00c4)
41#define BR7 (_dprbase + REGB + 0x00c0)
42
43#define MCR (_dprbase + REGB + 0x0000)
44#define AVR (_dprbase + REGB + 0x0008)
45
46#define SYPCR (_dprbase + REGB + 0x0022)
47
48#define PLLCR (_dprbase + REGB + 0x0010)
49#define CLKOCR (_dprbase + REGB + 0x000C)
50#define CDVCR (_dprbase + REGB + 0x0014)
51
52#define BKAR (_dprbase + REGB + 0x0030)
53#define BKCR (_dprbase + REGB + 0x0034)
54#define SWIV (_dprbase + REGB + 0x0023)
55#define PICR (_dprbase + REGB + 0x0026)
56#define PITR (_dprbase + REGB + 0x002A)
57
58/* Define for all memory configuration */
59#define MCU_SIM_GMR 0x00000000
60#define SIM_OR_MASK 0x0fffffff
61
62/* Defines for chip select zero - the flash */
63#define SIM_OR0_MASK 0x20000002
64#define SIM_BR0_MASK 0x00000001
65
66
67/* Defines for chip select one - the RAM */
68#define SIM_OR1_MASK 0x10000000
69#define SIM_BR1_MASK 0x00000001
70
71#define MCU_SIM_MBAR_ADRS 0x0003ff00
72#define MCU_SIM_MBAR_BA_MASK 0xfffff000
73#define MCU_SIM_MBAR_AS_MASK 0x00000001
74
75#define MCU_SIM_PEPAR 0x00B4
76
77#define MCU_DISABLE_INTRPTS 0x2700
78#define MCU_SIM_AVR 0x00
79
80#define MCU_SIM_MCR 0x00005cff
81
82#define MCU_SIM_CLKOCR 0x00
83#define MCU_SIM_PLLCR 0x8000
84#define MCU_SIM_CDVCR 0x0000
85
86#define MCU_SIM_SYPCR 0x0000
87#define MCU_SIM_SWIV 0x00
88#define MCU_SIM_PICR 0x0000
89#define MCU_SIM_PITR 0x0000
90
91
92#include <asm/m68360_regs.h>
93
94
95/*
96 * By the time this RAM specific code begins to execute, DPRAM
97 * and DRAM should already be mapped and accessible.
98 */
99
100 .text
101_start:
102_stext:
103 nop
104 ori.w #MCU_DISABLE_INTRPTS, %sr /* disable interrupts: */
105 /* We should not need to setup the boot stack the reset should do it. */
106 movea.l #__ramend, %sp /*set up stack at the end of DRAM:*/
107
108set_mbar_register:
109 moveq.l #0x07, %d1 /* Setup MBAR */
110 movec %d1, %dfc
111
112 lea.l MCU_SIM_MBAR_ADRS, %a0
113 move.l #_dprbase, %d0
114 andi.l #MCU_SIM_MBAR_BA_MASK, %d0
115 ori.l #MCU_SIM_MBAR_AS_MASK, %d0
116 moves.l %d0, %a0@
117
118 moveq.l #0x05, %d1
119 movec.l %d1, %dfc
120
121 /* Now we can begin to access registers in DPRAM */
122
123set_sim_mcr:
124 /* Set Module Configuration Register */
125 move.l #MCU_SIM_MCR, MCR
126
127 /* to do: Determine cause of reset */
128
129 /*
130 * configure system clock MC68360 p. 6-40
131 * (value +1)*osc/128 = system clock
132 */
133set_sim_clock:
134 move.w #MCU_SIM_PLLCR, PLLCR
135 move.b #MCU_SIM_CLKOCR, CLKOCR
136 move.w #MCU_SIM_CDVCR, CDVCR
137
138 /* Wait for the PLL to settle */
139 move.w #16384, %d0
140pll_settle_wait:
141 subi.w #1, %d0
142 bne pll_settle_wait
143
144 /* Setup the system protection register, and watchdog timer register */
145 move.b #MCU_SIM_SWIV, SWIV
146 move.w #MCU_SIM_PICR, PICR
147 move.w #MCU_SIM_PITR, PITR
148 move.w #MCU_SIM_SYPCR, SYPCR
149
150 /* Clear DPRAM - system + parameter */
151 movea.l #_dprbase, %a0
152 movea.l #_dprbase+0x2000, %a1
153
154 /* Copy 0 to %a0 until %a0 == %a1 */
155clear_dpram:
156 movel #0, %a0@+
157 cmpal %a0, %a1
158 bhi clear_dpram
159
160configure_memory_controller:
161 /* Set up Global Memory Register (GMR) */
162 move.l #MCU_SIM_GMR, %d0
163 move.l %d0, GMR
164
165configure_chip_select_0:
166 move.l #__ramend, %d0
167 subi.l #__ramstart, %d0
168 subq.l #0x01, %d0
169 eori.l #SIM_OR_MASK, %d0
170 ori.l #SIM_OR0_MASK, %d0
171 move.l %d0, OR0
172
173 move.l #__ramstart, %d0
174 ori.l #SIM_BR0_MASK, %d0
175 move.l %d0, BR0
176
177configure_chip_select_1:
178 move.l #__rom_end, %d0
179 subi.l #__rom_start, %d0
180 subq.l #0x01, %d0
181 eori.l #SIM_OR_MASK, %d0
182 ori.l #SIM_OR1_MASK, %d0
183 move.l %d0, OR1
184
185 move.l #__rom_start, %d0
186 ori.l #SIM_BR1_MASK, %d0
187 move.l %d0, BR1
188
189 move.w #MCU_SIM_PEPAR, PEPAR
190
191 /* point to vector table: */
192 move.l #_romvec, %a0
193 move.l #_ramvec, %a1
194copy_vectors:
195 move.l %a0@, %d0
196 move.l %d0, %a1@
197 move.l %a0@, %a1@
198 addq.l #0x04, %a0
199 addq.l #0x04, %a1
200 cmp.l #_start, %a0
201 blt copy_vectors
202
203 move.l #_ramvec, %a1
204 movec %a1, %vbr
205
206
207 /* Copy data segment from ROM to RAM */
208 moveal #_stext, %a0
209 moveal #_sdata, %a1
210 moveal #_edata, %a2
211
212 /* Copy %a0 to %a1 until %a1 == %a2 */
213LD1:
214 move.l %a0@, %d0
215 addq.l #0x04, %a0
216 move.l %d0, %a1@
217 addq.l #0x04, %a1
218 cmp.l #_edata, %a1
219 blt LD1
220
221 moveal #_sbss, %a0
222 moveal #_ebss, %a1
223
224 /* Copy 0 to %a0 until %a0 == %a1 */
225L1:
226 movel #0, %a0@+
227 cmpal %a0, %a1
228 bhi L1
229
230load_quicc:
231 move.l #_dprbase, _quicc_base
232
233store_ram_size:
234 /* Set ram size information */
235 move.l #_sdata, _rambase
236 move.l #_ebss, _ramstart
237 move.l #__ramend, %d0
238 sub.l #0x1000, %d0 /* Reserve 4K for stack space.*/
239 move.l %d0, _ramend /* Different from __ramend.*/
240
241store_flash_size:
242 /* Set rom size information */
243 move.l #__rom_end, %d0
244 sub.l #__rom_start, %d0
245 move.l %d0, rom_length
246
247 pea 0
248 pea env
249 pea %sp@(4)
250 pea 0
251
252 lea init_thread_union, %a2
253 lea 0x2000(%a2), %sp
254
255lp:
256 jsr start_kernel
257
258_exit:
259 jmp _exit
260
261
262 .data
263 .align 4
264env:
265 .long 0
266_quicc_base:
267 .long 0
268_periph_base:
269 .long 0
270_ramvec:
271 .long 0
272_rambase:
273 .long 0
274_ramstart:
275 .long 0
276_ramend:
277 .long 0
278_dprbase:
279 .long 0xffffe000
280
281 .text
282
283 /*
284 * These are the exception vectors at boot up, they are copied into RAM
285 * and then overwritten as needed.
286 */
287
288.section ".data.initvect","awx"
289 .long __ramend /* Reset: Initial Stack Pointer - 0. */
290 .long _start /* Reset: Initial Program Counter - 1. */
291 .long buserr /* Bus Error - 2. */
292 .long trap /* Address Error - 3. */
293 .long trap /* Illegal Instruction - 4. */
294 .long trap /* Divide by zero - 5. */
295 .long trap /* CHK, CHK2 Instructions - 6. */
296 .long trap /* TRAPcc, TRAPV Instructions - 7. */
297 .long trap /* Privilege Violation - 8. */
298 .long trap /* Trace - 9. */
299 .long trap /* Line 1010 Emulator - 10. */
300 .long trap /* Line 1111 Emualtor - 11. */
301 .long trap /* Harware Breakpoint - 12. */
302 .long trap /* (Reserved for Coprocessor Protocol Violation)- 13. */
303 .long trap /* Format Error - 14. */
304 .long trap /* Uninitialized Interrupt - 15. */
305 .long trap /* (Unassigned, Reserver) - 16. */
306 .long trap /* (Unassigned, Reserver) - 17. */
307 .long trap /* (Unassigned, Reserver) - 18. */
308 .long trap /* (Unassigned, Reserver) - 19. */
309 .long trap /* (Unassigned, Reserver) - 20. */
310 .long trap /* (Unassigned, Reserver) - 21. */
311 .long trap /* (Unassigned, Reserver) - 22. */
312 .long trap /* (Unassigned, Reserver) - 23. */
313 .long trap /* Spurious Interrupt - 24. */
314 .long trap /* Level 1 Interrupt Autovector - 25. */
315 .long trap /* Level 2 Interrupt Autovector - 26. */
316 .long trap /* Level 3 Interrupt Autovector - 27. */
317 .long trap /* Level 4 Interrupt Autovector - 28. */
318 .long trap /* Level 5 Interrupt Autovector - 29. */
319 .long trap /* Level 6 Interrupt Autovector - 30. */
320 .long trap /* Level 7 Interrupt Autovector - 31. */
321 .long system_call /* Trap Instruction Vectors 0 - 32. */
322 .long trap /* Trap Instruction Vectors 1 - 33. */
323 .long trap /* Trap Instruction Vectors 2 - 34. */
324 .long trap /* Trap Instruction Vectors 3 - 35. */
325 .long trap /* Trap Instruction Vectors 4 - 36. */
326 .long trap /* Trap Instruction Vectors 5 - 37. */
327 .long trap /* Trap Instruction Vectors 6 - 38. */
328 .long trap /* Trap Instruction Vectors 7 - 39. */
329 .long trap /* Trap Instruction Vectors 8 - 40. */
330 .long trap /* Trap Instruction Vectors 9 - 41. */
331 .long trap /* Trap Instruction Vectors 10 - 42. */
332 .long trap /* Trap Instruction Vectors 11 - 43. */
333 .long trap /* Trap Instruction Vectors 12 - 44. */
334 .long trap /* Trap Instruction Vectors 13 - 45. */
335 .long trap /* Trap Instruction Vectors 14 - 46. */
336 .long trap /* Trap Instruction Vectors 15 - 47. */
337 .long 0 /* (Reserved for Coprocessor) - 48. */
338 .long 0 /* (Reserved for Coprocessor) - 49. */
339 .long 0 /* (Reserved for Coprocessor) - 50. */
340 .long 0 /* (Reserved for Coprocessor) - 51. */
341 .long 0 /* (Reserved for Coprocessor) - 52. */
342 .long 0 /* (Reserved for Coprocessor) - 53. */
343 .long 0 /* (Reserved for Coprocessor) - 54. */
344 .long 0 /* (Reserved for Coprocessor) - 55. */
345 .long 0 /* (Reserved for Coprocessor) - 56. */
346 .long 0 /* (Reserved for Coprocessor) - 57. */
347 .long 0 /* (Reserved for Coprocessor) - 58. */
348 .long 0 /* (Unassigned, Reserved) - 59. */
349 .long 0 /* (Unassigned, Reserved) - 60. */
350 .long 0 /* (Unassigned, Reserved) - 61. */
351 .long 0 /* (Unassigned, Reserved) - 62. */
352 .long 0 /* (Unassigned, Reserved) - 63. */
353 /* The assignment of these vectors to the CPM is */
354 /* dependent on the configuration of the CPM vba */
355 /* fields. */
356 .long 0 /* (User-Defined Vectors 1) CPM Error - 64. */
357 .long 0 /* (User-Defined Vectors 2) CPM Parallel IO PC11- 65. */
358 .long 0 /* (User-Defined Vectors 3) CPM Parallel IO PC10- 66. */
359 .long 0 /* (User-Defined Vectors 4) CPM SMC2 / PIP - 67. */
360 .long 0 /* (User-Defined Vectors 5) CPM SMC1 - 68. */
361 .long 0 /* (User-Defined Vectors 6) CPM SPI - 69. */
362 .long 0 /* (User-Defined Vectors 7) CPM Parallel IO PC9 - 70. */
363 .long 0 /* (User-Defined Vectors 8) CPM Timer 4 - 71. */
364 .long 0 /* (User-Defined Vectors 9) CPM Reserved - 72. */
365 .long 0 /* (User-Defined Vectors 10) CPM Parallel IO PC8- 73. */
366 .long 0 /* (User-Defined Vectors 11) CPM Parallel IO PC7- 74. */
367 .long 0 /* (User-Defined Vectors 12) CPM Parallel IO PC6- 75. */
368 .long 0 /* (User-Defined Vectors 13) CPM Timer 3 - 76. */
369 .long 0 /* (User-Defined Vectors 14) CPM Reserved - 77. */
370 .long 0 /* (User-Defined Vectors 15) CPM Parallel IO PC5- 78. */
371 .long 0 /* (User-Defined Vectors 16) CPM Parallel IO PC4- 79. */
372 .long 0 /* (User-Defined Vectors 17) CPM Reserved - 80. */
373 .long 0 /* (User-Defined Vectors 18) CPM RISC Timer Tbl - 81. */
374 .long 0 /* (User-Defined Vectors 19) CPM Timer 2 - 82. */
375 .long 0 /* (User-Defined Vectors 21) CPM Reserved - 83. */
376 .long 0 /* (User-Defined Vectors 22) CPM IDMA2 - 84. */
377 .long 0 /* (User-Defined Vectors 23) CPM IDMA1 - 85. */
378 .long 0 /* (User-Defined Vectors 24) CPM SDMA Bus Err - 86. */
379 .long 0 /* (User-Defined Vectors 25) CPM Parallel IO PC3- 87. */
380 .long 0 /* (User-Defined Vectors 26) CPM Parallel IO PC2- 88. */
381 .long 0 /* (User-Defined Vectors 27) CPM Timer 1 - 89. */
382 .long 0 /* (User-Defined Vectors 28) CPM Parallel IO PC1- 90. */
383 .long 0 /* (User-Defined Vectors 29) CPM SCC 4 - 91. */
384 .long 0 /* (User-Defined Vectors 30) CPM SCC 3 - 92. */
385 .long 0 /* (User-Defined Vectors 31) CPM SCC 2 - 93. */
386 .long 0 /* (User-Defined Vectors 32) CPM SCC 1 - 94. */
387 .long 0 /* (User-Defined Vectors 33) CPM Parallel IO PC0- 95. */
388 /* I don't think anything uses the vectors after here. */
389 .long 0 /* (User-Defined Vectors 34) - 96. */
390 .long 0,0,0,0,0 /* (User-Defined Vectors 35 - 39). */
391 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 40 - 49). */
392 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 50 - 59). */
393 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 60 - 69). */
394 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 70 - 79). */
395 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 80 - 89). */
396 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 90 - 99). */
397 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 100 - 109). */
398 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 110 - 119). */
399 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 120 - 129). */
400 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 130 - 139). */
401 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 140 - 149). */
402 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 150 - 159). */
403 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 160 - 169). */
404 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 170 - 179). */
405 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 180 - 189). */
406 .long 0,0,0 /* (User-Defined Vectors 190 - 192). */
407.text
408ignore: rte
diff --git a/arch/m68knommu/platform/68360/head-rom.S b/arch/m68knommu/platform/68360/head-rom.S
new file mode 100644
index 0000000000..0da357a4cf
--- /dev/null
+++ b/arch/m68knommu/platform/68360/head-rom.S
@@ -0,0 +1,420 @@
1/* arch/m68knommu/platform/68360/head-rom.S
2 *
3 * Startup code for Motorola 68360
4 *
5 * Copyright (C) SED Systems, a Division of Calian Ltd.
6 * Based on: arch/m68knommu/platform/68328/pilot/crt0_rom.S
7 * Based on: arch/m68knommu/platform/68360/uCquicc/crt0_rom.S, 2.0.38.1.pre7
8 * uClinux Kernel
9 * Copyright (C) Michael Leslie <mleslie@lineo.com>
10 * Based on: arch/m68knommu/platform/68EZ328/ucsimm/crt0_rom.S
11 * Copyright (C) 1998 D. Jeff Dionne <jeff@uclinux.org>,
12 *
13 */
14#include <linux/config.h>
15
16.global _stext
17.global _sbss
18.global _start
19
20.global _rambase
21.global __ramvec
22.global _ramvec
23.global _ramstart
24.global _ramend
25
26.global _quicc_base
27.global _periph_base
28
29#define REGB 0x1000
30#define PEPAR (_dprbase + REGB + 0x0016)
31#define GMR (_dprbase + REGB + 0x0040)
32#define OR0 (_dprbase + REGB + 0x0054)
33#define BR0 (_dprbase + REGB + 0x0050)
34
35#define OR1 (_dprbase + REGB + 0x0064)
36#define BR1 (_dprbase + REGB + 0x0060)
37
38#define OR2 (_dprbase + REGB + 0x0074)
39#define BR2 (_dprbase + REGB + 0x0070)
40
41#define OR3 (_dprbase + REGB + 0x0084)
42#define BR3 (_dprbase + REGB + 0x0080)
43
44#define OR4 (_dprbase + REGB + 0x0094)
45#define BR4 (_dprbase + REGB + 0x0090)
46
47#define OR5 (_dprbase + REGB + 0x00A4)
48#define BR5 (_dprbase + REGB + 0x00A0)
49
50#define OR6 (_dprbase + REGB + 0x00b4)
51#define BR6 (_dprbase + REGB + 0x00b0)
52
53#define OR7 (_dprbase + REGB + 0x00c4)
54#define BR7 (_dprbase + REGB + 0x00c0)
55
56#define MCR (_dprbase + REGB + 0x0000)
57#define AVR (_dprbase + REGB + 0x0008)
58
59#define SYPCR (_dprbase + REGB + 0x0022)
60
61#define PLLCR (_dprbase + REGB + 0x0010)
62#define CLKOCR (_dprbase + REGB + 0x000C)
63#define CDVCR (_dprbase + REGB + 0x0014)
64
65#define BKAR (_dprbase + REGB + 0x0030)
66#define BKCR (_dprbase + REGB + 0x0034)
67#define SWIV (_dprbase + REGB + 0x0023)
68#define PICR (_dprbase + REGB + 0x0026)
69#define PITR (_dprbase + REGB + 0x002A)
70
71/* Define for all memory configuration */
72#define MCU_SIM_GMR 0x00000000
73#define SIM_OR_MASK 0x0fffffff
74
75/* Defines for chip select zero - the flash */
76#define SIM_OR0_MASK 0x20000000
77#define SIM_BR0_MASK 0x00000001
78
79/* Defines for chip select one - the RAM */
80#define SIM_OR1_MASK 0x10000000
81#define SIM_BR1_MASK 0x00000001
82
83#define MCU_SIM_MBAR_ADRS 0x0003ff00
84#define MCU_SIM_MBAR_BA_MASK 0xfffff000
85#define MCU_SIM_MBAR_AS_MASK 0x00000001
86
87#define MCU_SIM_PEPAR 0x00B4
88
89#define MCU_DISABLE_INTRPTS 0x2700
90#define MCU_SIM_AVR 0x00
91
92#define MCU_SIM_MCR 0x00005cff
93
94#define MCU_SIM_CLKOCR 0x00
95#define MCU_SIM_PLLCR 0x8000
96#define MCU_SIM_CDVCR 0x0000
97
98#define MCU_SIM_SYPCR 0x0000
99#define MCU_SIM_SWIV 0x00
100#define MCU_SIM_PICR 0x0000
101#define MCU_SIM_PITR 0x0000
102
103
104#include <asm/m68360_regs.h>
105
106
107/*
108 * By the time this RAM specific code begins to execute, DPRAM
109 * and DRAM should already be mapped and accessible.
110 */
111
112 .text
113_start:
114_stext:
115 nop
116 ori.w #MCU_DISABLE_INTRPTS, %sr /* disable interrupts: */
117 /* We should not need to setup the boot stack the reset should do it. */
118 movea.l #__ramend, %sp /* set up stack at the end of DRAM:*/
119
120
121set_mbar_register:
122 moveq.l #0x07, %d1 /* Setup MBAR */
123 movec %d1, %dfc
124
125 lea.l MCU_SIM_MBAR_ADRS, %a0
126 move.l #_dprbase, %d0
127 andi.l #MCU_SIM_MBAR_BA_MASK, %d0
128 ori.l #MCU_SIM_MBAR_AS_MASK, %d0
129 moves.l %d0, %a0@
130
131 moveq.l #0x05, %d1
132 movec.l %d1, %dfc
133
134 /* Now we can begin to access registers in DPRAM */
135
136set_sim_mcr:
137 /* Set Module Configuration Register */
138 move.l #MCU_SIM_MCR, MCR
139
140 /* to do: Determine cause of reset */
141
142 /*
143 * configure system clock MC68360 p. 6-40
144 * (value +1)*osc/128 = system clock
145 * or
146 * (value + 1)*osc = system clock
147 * You do not need to divide the oscillator by 128 unless you want to.
148 */
149set_sim_clock:
150 move.w #MCU_SIM_PLLCR, PLLCR
151 move.b #MCU_SIM_CLKOCR, CLKOCR
152 move.w #MCU_SIM_CDVCR, CDVCR
153
154 /* Wait for the PLL to settle */
155 move.w #16384, %d0
156pll_settle_wait:
157 subi.w #1, %d0
158 bne pll_settle_wait
159
160 /* Setup the system protection register, and watchdog timer register */
161 move.b #MCU_SIM_SWIV, SWIV
162 move.w #MCU_SIM_PICR, PICR
163 move.w #MCU_SIM_PITR, PITR
164 move.w #MCU_SIM_SYPCR, SYPCR
165
166 /* Clear DPRAM - system + parameter */
167 movea.l #_dprbase, %a0
168 movea.l #_dprbase+0x2000, %a1
169
170 /* Copy 0 to %a0 until %a0 == %a1 */
171clear_dpram:
172 movel #0, %a0@+
173 cmpal %a0, %a1
174 bhi clear_dpram
175
176configure_memory_controller:
177 /* Set up Global Memory Register (GMR) */
178 move.l #MCU_SIM_GMR, %d0
179 move.l %d0, GMR
180
181configure_chip_select_0:
182 move.l #0x00400000, %d0
183 subq.l #0x01, %d0
184 eori.l #SIM_OR_MASK, %d0
185 ori.l #SIM_OR0_MASK, %d0
186 move.l %d0, OR0
187
188 move.l #__rom_start, %d0
189 ori.l #SIM_BR0_MASK, %d0
190 move.l %d0, BR0
191
192 move.l #0x0, BR1
193 move.l #0x0, BR2
194 move.l #0x0, BR3
195 move.l #0x0, BR4
196 move.l #0x0, BR5
197 move.l #0x0, BR6
198 move.l #0x0, BR7
199
200 move.w #MCU_SIM_PEPAR, PEPAR
201
202 /* point to vector table: */
203 move.l #_romvec, %a0
204 move.l #_ramvec, %a1
205copy_vectors:
206 move.l %a0@, %d0
207 move.l %d0, %a1@
208 move.l %a0@, %a1@
209 addq.l #0x04, %a0
210 addq.l #0x04, %a1
211 cmp.l #_start, %a0
212 blt copy_vectors
213
214 move.l #_ramvec, %a1
215 movec %a1, %vbr
216
217
218 /* Copy data segment from ROM to RAM */
219 moveal #_etext, %a0
220 moveal #_sdata, %a1
221 moveal #_edata, %a2
222
223 /* Copy %a0 to %a1 until %a1 == %a2 */
224LD1:
225 move.l %a0@, %d0
226 addq.l #0x04, %a0
227 move.l %d0, %a1@
228 addq.l #0x04, %a1
229 cmp.l #_edata, %a1
230 blt LD1
231
232 moveal #_sbss, %a0
233 moveal #_ebss, %a1
234
235 /* Copy 0 to %a0 until %a0 == %a1 */
236L1:
237 movel #0, %a0@+
238 cmpal %a0, %a1
239 bhi L1
240
241load_quicc:
242 move.l #_dprbase, _quicc_base
243
244store_ram_size:
245 /* Set ram size information */
246 move.l #_sdata, _rambase
247 move.l #_ebss, _ramstart
248 move.l #__ramend, %d0
249 sub.l #0x1000, %d0 /* Reserve 4K for stack space.*/
250 move.l %d0, _ramend /* Different from __ramend.*/
251
252store_flash_size:
253 /* Set rom size information */
254 move.l #__rom_end, %d0
255 sub.l #__rom_start, %d0
256 move.l %d0, rom_length
257
258 pea 0
259 pea env
260 pea %sp@(4)
261 pea 0
262
263 lea init_thread_union, %a2
264 lea 0x2000(%a2), %sp
265
266lp:
267 jsr start_kernel
268
269_exit:
270 jmp _exit
271
272
273 .data
274 .align 4
275env:
276 .long 0
277_quicc_base:
278 .long 0
279_periph_base:
280 .long 0
281_ramvec:
282 .long 0
283_rambase:
284 .long 0
285_ramstart:
286 .long 0
287_ramend:
288 .long 0
289_dprbase:
290 .long 0xffffe000
291
292
293 .text
294
295 /*
296 * These are the exception vectors at boot up, they are copied into RAM
297 * and then overwritten as needed.
298 */
299
300.section ".data.initvect","awx"
301 .long __ramend /* Reset: Initial Stack Pointer - 0. */
302 .long _start /* Reset: Initial Program Counter - 1. */
303 .long buserr /* Bus Error - 2. */
304 .long trap /* Address Error - 3. */
305 .long trap /* Illegal Instruction - 4. */
306 .long trap /* Divide by zero - 5. */
307 .long trap /* CHK, CHK2 Instructions - 6. */
308 .long trap /* TRAPcc, TRAPV Instructions - 7. */
309 .long trap /* Privilege Violation - 8. */
310 .long trap /* Trace - 9. */
311 .long trap /* Line 1010 Emulator - 10. */
312 .long trap /* Line 1111 Emualtor - 11. */
313 .long trap /* Harware Breakpoint - 12. */
314 .long trap /* (Reserved for Coprocessor Protocol Violation)- 13. */
315 .long trap /* Format Error - 14. */
316 .long trap /* Uninitialized Interrupt - 15. */
317 .long trap /* (Unassigned, Reserver) - 16. */
318 .long trap /* (Unassigned, Reserver) - 17. */
319 .long trap /* (Unassigned, Reserver) - 18. */
320 .long trap /* (Unassigned, Reserver) - 19. */
321 .long trap /* (Unassigned, Reserver) - 20. */
322 .long trap /* (Unassigned, Reserver) - 21. */
323 .long trap /* (Unassigned, Reserver) - 22. */
324 .long trap /* (Unassigned, Reserver) - 23. */
325 .long trap /* Spurious Interrupt - 24. */
326 .long trap /* Level 1 Interrupt Autovector - 25. */
327 .long trap /* Level 2 Interrupt Autovector - 26. */
328 .long trap /* Level 3 Interrupt Autovector - 27. */
329 .long trap /* Level 4 Interrupt Autovector - 28. */
330 .long trap /* Level 5 Interrupt Autovector - 29. */
331 .long trap /* Level 6 Interrupt Autovector - 30. */
332 .long trap /* Level 7 Interrupt Autovector - 31. */
333 .long system_call /* Trap Instruction Vectors 0 - 32. */
334 .long trap /* Trap Instruction Vectors 1 - 33. */
335 .long trap /* Trap Instruction Vectors 2 - 34. */
336 .long trap /* Trap Instruction Vectors 3 - 35. */
337 .long trap /* Trap Instruction Vectors 4 - 36. */
338 .long trap /* Trap Instruction Vectors 5 - 37. */
339 .long trap /* Trap Instruction Vectors 6 - 38. */
340 .long trap /* Trap Instruction Vectors 7 - 39. */
341 .long trap /* Trap Instruction Vectors 8 - 40. */
342 .long trap /* Trap Instruction Vectors 9 - 41. */
343 .long trap /* Trap Instruction Vectors 10 - 42. */
344 .long trap /* Trap Instruction Vectors 11 - 43. */
345 .long trap /* Trap Instruction Vectors 12 - 44. */
346 .long trap /* Trap Instruction Vectors 13 - 45. */
347 .long trap /* Trap Instruction Vectors 14 - 46. */
348 .long trap /* Trap Instruction Vectors 15 - 47. */
349 .long 0 /* (Reserved for Coprocessor) - 48. */
350 .long 0 /* (Reserved for Coprocessor) - 49. */
351 .long 0 /* (Reserved for Coprocessor) - 50. */
352 .long 0 /* (Reserved for Coprocessor) - 51. */
353 .long 0 /* (Reserved for Coprocessor) - 52. */
354 .long 0 /* (Reserved for Coprocessor) - 53. */
355 .long 0 /* (Reserved for Coprocessor) - 54. */
356 .long 0 /* (Reserved for Coprocessor) - 55. */
357 .long 0 /* (Reserved for Coprocessor) - 56. */
358 .long 0 /* (Reserved for Coprocessor) - 57. */
359 .long 0 /* (Reserved for Coprocessor) - 58. */
360 .long 0 /* (Unassigned, Reserved) - 59. */
361 .long 0 /* (Unassigned, Reserved) - 60. */
362 .long 0 /* (Unassigned, Reserved) - 61. */
363 .long 0 /* (Unassigned, Reserved) - 62. */
364 .long 0 /* (Unassigned, Reserved) - 63. */
365 /* The assignment of these vectors to the CPM is */
366 /* dependent on the configuration of the CPM vba */
367 /* fields. */
368 .long 0 /* (User-Defined Vectors 1) CPM Error - 64. */
369 .long 0 /* (User-Defined Vectors 2) CPM Parallel IO PC11- 65. */
370 .long 0 /* (User-Defined Vectors 3) CPM Parallel IO PC10- 66. */
371 .long 0 /* (User-Defined Vectors 4) CPM SMC2 / PIP - 67. */
372 .long 0 /* (User-Defined Vectors 5) CPM SMC1 - 68. */
373 .long 0 /* (User-Defined Vectors 6) CPM SPI - 69. */
374 .long 0 /* (User-Defined Vectors 7) CPM Parallel IO PC9 - 70. */
375 .long 0 /* (User-Defined Vectors 8) CPM Timer 4 - 71. */
376 .long 0 /* (User-Defined Vectors 9) CPM Reserved - 72. */
377 .long 0 /* (User-Defined Vectors 10) CPM Parallel IO PC8- 73. */
378 .long 0 /* (User-Defined Vectors 11) CPM Parallel IO PC7- 74. */
379 .long 0 /* (User-Defined Vectors 12) CPM Parallel IO PC6- 75. */
380 .long 0 /* (User-Defined Vectors 13) CPM Timer 3 - 76. */
381 .long 0 /* (User-Defined Vectors 14) CPM Reserved - 77. */
382 .long 0 /* (User-Defined Vectors 15) CPM Parallel IO PC5- 78. */
383 .long 0 /* (User-Defined Vectors 16) CPM Parallel IO PC4- 79. */
384 .long 0 /* (User-Defined Vectors 17) CPM Reserved - 80. */
385 .long 0 /* (User-Defined Vectors 18) CPM RISC Timer Tbl - 81. */
386 .long 0 /* (User-Defined Vectors 19) CPM Timer 2 - 82. */
387 .long 0 /* (User-Defined Vectors 21) CPM Reserved - 83. */
388 .long 0 /* (User-Defined Vectors 22) CPM IDMA2 - 84. */
389 .long 0 /* (User-Defined Vectors 23) CPM IDMA1 - 85. */
390 .long 0 /* (User-Defined Vectors 24) CPM SDMA Bus Err - 86. */
391 .long 0 /* (User-Defined Vectors 25) CPM Parallel IO PC3- 87. */
392 .long 0 /* (User-Defined Vectors 26) CPM Parallel IO PC2- 88. */
393 .long 0 /* (User-Defined Vectors 27) CPM Timer 1 - 89. */
394 .long 0 /* (User-Defined Vectors 28) CPM Parallel IO PC1- 90. */
395 .long 0 /* (User-Defined Vectors 29) CPM SCC 4 - 91. */
396 .long 0 /* (User-Defined Vectors 30) CPM SCC 3 - 92. */
397 .long 0 /* (User-Defined Vectors 31) CPM SCC 2 - 93. */
398 .long 0 /* (User-Defined Vectors 32) CPM SCC 1 - 94. */
399 .long 0 /* (User-Defined Vectors 33) CPM Parallel IO PC0- 95. */
400 /* I don't think anything uses the vectors after here. */
401 .long 0 /* (User-Defined Vectors 34) - 96. */
402 .long 0,0,0,0,0 /* (User-Defined Vectors 35 - 39). */
403 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 40 - 49). */
404 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 50 - 59). */
405 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 60 - 69). */
406 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 70 - 79). */
407 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 80 - 89). */
408 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 90 - 99). */
409 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 100 - 109). */
410 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 110 - 119). */
411 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 120 - 129). */
412 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 130 - 139). */
413 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 140 - 149). */
414 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 150 - 159). */
415 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 160 - 169). */
416 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 170 - 179). */
417 .long 0,0,0,0,0,0,0,0,0,0 /* (User-Defined Vectors 180 - 189). */
418 .long 0,0,0 /* (User-Defined Vectors 190 - 192). */
419.text
420ignore: rte
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 8d76eb1ff2..0eb71ac303 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -154,6 +154,13 @@ config TANBAC_TB0226
154 The TANBAC Mbase(TB0226) is a MIPS-based platform manufactured by TANBAC. 154 The TANBAC Mbase(TB0226) is a MIPS-based platform manufactured by TANBAC.
155 Please refer to <http://www.tanbac.co.jp/> about Mbase. 155 Please refer to <http://www.tanbac.co.jp/> about Mbase.
156 156
157config TANBAC_TB0287
158 bool "Support for TANBAC Mini-ITX DIMM base(TB0287)"
159 depends on TANBAC_TB022X
160 help
161 The TANBAC Mini-ITX DIMM base(TB0287) is a MIPS-based platform manufactured by TANBAC.
162 Please refer to <http://www.tanbac.co.jp/> about Mini-ITX DIMM base.
163
157config VICTOR_MPC30X 164config VICTOR_MPC30X
158 bool "Support for Victor MP-C303/304" 165 bool "Support for Victor MP-C303/304"
159 depends on MACH_VR41XX 166 depends on MACH_VR41XX
diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index b0fdaee8d8..346e803f15 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -720,38 +720,7 @@ archclean:
720 @$(MAKE) $(clean)=arch/mips/boot 720 @$(MAKE) $(clean)=arch/mips/boot
721 @$(MAKE) $(clean)=arch/mips/lasat 721 @$(MAKE) $(clean)=arch/mips/lasat
722 722
723# Generate <asm/offset.h 723
724# 724CLEAN_FILES += vmlinux.32 \
725# The default rule is suffering from funny problems on MIPS so we using our
726# own ...
727#
728# ---------------------------------------------------------------------------
729
730define filechk_gen-asm-offset.h
731 (set -e; \
732 echo "#ifndef _ASM_OFFSET_H"; \
733 echo "#define _ASM_OFFSET_H"; \
734 echo "/*"; \
735 echo " * DO NOT MODIFY."; \
736 echo " *"; \
737 echo " * This file was generated by arch/$(ARCH)/Makefile"; \
738 echo " *"; \
739 echo " */"; \
740 echo ""; \
741 sed -ne "/^@@@/s///p"; \
742 echo "#endif /* _ASM_OFFSET_H */" )
743endef
744
745prepare: include/asm-$(ARCH)/offset.h
746
747arch/$(ARCH)/kernel/offset.s: include/asm include/linux/version.h \
748 include/config/MARKER
749
750include/asm-$(ARCH)/offset.h: arch/$(ARCH)/kernel/offset.s
751 $(call filechk,gen-asm-offset.h)
752
753CLEAN_FILES += include/asm-$(ARCH)/offset.h.tmp \
754 include/asm-$(ARCH)/offset.h \
755 vmlinux.32 \
756 vmlinux.64 \ 725 vmlinux.64 \
757 vmlinux.ecoff 726 vmlinux.ecoff
diff --git a/arch/mips/configs/tb0287_defconfig b/arch/mips/configs/tb0287_defconfig
new file mode 100644
index 0000000000..17b9f2f65b
--- /dev/null
+++ b/arch/mips/configs/tb0287_defconfig
@@ -0,0 +1,1041 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.13-mm1
4# Thu Sep 1 22:58:34 2005
5#
6CONFIG_MIPS=y
7
8#
9# Code maturity level options
10#
11CONFIG_EXPERIMENTAL=y
12CONFIG_CLEAN_COMPILE=y
13CONFIG_BROKEN_ON_SMP=y
14CONFIG_INIT_ENV_ARG_LIMIT=32
15
16#
17# General setup
18#
19CONFIG_LOCALVERSION=""
20CONFIG_LOCALVERSION_AUTO=y
21CONFIG_SWAP=y
22CONFIG_SYSVIPC=y
23# CONFIG_POSIX_MQUEUE is not set
24# CONFIG_BSD_PROCESS_ACCT is not set
25CONFIG_SYSCTL=y
26# CONFIG_AUDIT is not set
27# CONFIG_HOTPLUG is not set
28CONFIG_KOBJECT_UEVENT=y
29# CONFIG_IKCONFIG is not set
30CONFIG_INITRAMFS_SOURCE=""
31CONFIG_EMBEDDED=y
32CONFIG_KALLSYMS=y
33# CONFIG_KALLSYMS_EXTRA_PASS is not set
34CONFIG_PRINTK=y
35CONFIG_BUG=y
36CONFIG_BASE_FULL=y
37CONFIG_FUTEX=y
38CONFIG_EPOLL=y
39# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
40CONFIG_SHMEM=y
41CONFIG_CC_ALIGN_FUNCTIONS=0
42CONFIG_CC_ALIGN_LABELS=0
43CONFIG_CC_ALIGN_LOOPS=0
44CONFIG_CC_ALIGN_JUMPS=0
45# CONFIG_TINY_SHMEM is not set
46CONFIG_BASE_SMALL=0
47
48#
49# Loadable module support
50#
51CONFIG_MODULES=y
52CONFIG_MODULE_UNLOAD=y
53# CONFIG_MODULE_FORCE_UNLOAD is not set
54CONFIG_OBSOLETE_MODPARM=y
55CONFIG_MODVERSIONS=y
56CONFIG_MODULE_SRCVERSION_ALL=y
57CONFIG_KMOD=y
58CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
59CONFIG_SYS_SUPPORTS_64BIT_KERNEL=y
60CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
61CONFIG_CPU_SUPPORTS_64BIT_KERNEL=y
62
63#
64# Kernel type
65#
66CONFIG_32BIT=y
67# CONFIG_64BIT is not set
68
69#
70# Machine selection
71#
72# CONFIG_MACH_JAZZ is not set
73CONFIG_MACH_VR41XX=y
74# CONFIG_NEC_CMBVR4133 is not set
75# CONFIG_CASIO_E55 is not set
76# CONFIG_IBM_WORKPAD is not set
77CONFIG_TANBAC_TB022X=y
78# CONFIG_TANBAC_TB0226 is not set
79CONFIG_TANBAC_TB0287=y
80# CONFIG_VICTOR_MPC30X is not set
81# CONFIG_ZAO_CAPCELLA is not set
82CONFIG_PCI_VR41XX=y
83# CONFIG_VRC4173 is not set
84# CONFIG_TOSHIBA_JMR3927 is not set
85# CONFIG_MIPS_COBALT is not set
86# CONFIG_MACH_DECSTATION is not set
87# CONFIG_MIPS_EV64120 is not set
88# CONFIG_MIPS_EV96100 is not set
89# CONFIG_MIPS_IVR is not set
90# CONFIG_LASAT is not set
91# CONFIG_MIPS_ITE8172 is not set
92# CONFIG_MIPS_ATLAS is not set
93# CONFIG_MIPS_MALTA is not set
94# CONFIG_MIPS_SEAD is not set
95# CONFIG_MOMENCO_OCELOT is not set
96# CONFIG_MOMENCO_OCELOT_G is not set
97# CONFIG_MOMENCO_OCELOT_C is not set
98# CONFIG_MOMENCO_OCELOT_3 is not set
99# CONFIG_MOMENCO_JAGUAR_ATX is not set
100# CONFIG_PMC_YOSEMITE is not set
101# CONFIG_DDB5074 is not set
102# CONFIG_DDB5476 is not set
103# CONFIG_DDB5477 is not set
104# CONFIG_QEMU is not set
105# CONFIG_SGI_IP22 is not set
106# CONFIG_SGI_IP27 is not set
107# CONFIG_SGI_IP32 is not set
108# CONFIG_SOC_AU1X00 is not set
109# CONFIG_SIBYTE_SB1xxx_SOC is not set
110# CONFIG_SNI_RM200_PCI is not set
111# CONFIG_TOSHIBA_RBTX4927 is not set
112CONFIG_RWSEM_GENERIC_SPINLOCK=y
113CONFIG_GENERIC_CALIBRATE_DELAY=y
114CONFIG_HAVE_DEC_LOCK=y
115CONFIG_DMA_NONCOHERENT=y
116CONFIG_DMA_NEED_PCI_MAP_STATE=y
117CONFIG_CPU_LITTLE_ENDIAN=y
118CONFIG_IRQ_CPU=y
119CONFIG_MIPS_L1_CACHE_SHIFT=5
120
121#
122# CPU selection
123#
124# CONFIG_CPU_MIPS32 is not set
125# CONFIG_CPU_MIPS64 is not set
126# CONFIG_CPU_R3000 is not set
127# CONFIG_CPU_TX39XX is not set
128CONFIG_CPU_VR41XX=y
129# CONFIG_CPU_R4300 is not set
130# CONFIG_CPU_R4X00 is not set
131# CONFIG_CPU_TX49XX is not set
132# CONFIG_CPU_R5000 is not set
133# CONFIG_CPU_R5432 is not set
134# CONFIG_CPU_R6000 is not set
135# CONFIG_CPU_NEVADA is not set
136# CONFIG_CPU_R8000 is not set
137# CONFIG_CPU_R10000 is not set
138# CONFIG_CPU_RM7000 is not set
139# CONFIG_CPU_RM9000 is not set
140# CONFIG_CPU_SB1 is not set
141CONFIG_PAGE_SIZE_4KB=y
142# CONFIG_PAGE_SIZE_8KB is not set
143# CONFIG_PAGE_SIZE_16KB is not set
144# CONFIG_PAGE_SIZE_64KB is not set
145# CONFIG_CPU_ADVANCED is not set
146CONFIG_CPU_HAS_SYNC=y
147CONFIG_ARCH_FLATMEM_ENABLE=y
148CONFIG_SELECT_MEMORY_MODEL=y
149CONFIG_FLATMEM_MANUAL=y
150# CONFIG_DISCONTIGMEM_MANUAL is not set
151# CONFIG_SPARSEMEM_MANUAL is not set
152CONFIG_FLATMEM=y
153CONFIG_FLAT_NODE_MEM_MAP=y
154# CONFIG_SPARSEMEM_STATIC is not set
155# CONFIG_PREEMPT is not set
156
157#
158# Bus options (PCI, PCMCIA, EISA, ISA, TC)
159#
160CONFIG_HW_HAS_PCI=y
161CONFIG_PCI=y
162# CONFIG_PCI_LEGACY_PROC is not set
163CONFIG_MMU=y
164
165#
166# PCCARD (PCMCIA/CardBus) support
167#
168# CONFIG_PCCARD is not set
169
170#
171# PCI Hotplug Support
172#
173# CONFIG_HOTPLUG_PCI is not set
174
175#
176# Executable file formats
177#
178CONFIG_BINFMT_ELF=y
179# CONFIG_BINFMT_MISC is not set
180CONFIG_TRAD_SIGNALS=y
181
182#
183# Networking
184#
185CONFIG_NET=y
186
187#
188# Networking options
189#
190CONFIG_PACKET=y
191# CONFIG_PACKET_MMAP is not set
192CONFIG_UNIX=y
193CONFIG_XFRM=y
194CONFIG_XFRM_USER=m
195# CONFIG_NET_KEY is not set
196CONFIG_INET=y
197CONFIG_IP_MULTICAST=y
198CONFIG_IP_ADVANCED_ROUTER=y
199CONFIG_ASK_IP_FIB_HASH=y
200# CONFIG_IP_FIB_TRIE is not set
201CONFIG_IP_FIB_HASH=y
202CONFIG_IP_MULTIPLE_TABLES=y
203CONFIG_IP_ROUTE_MULTIPATH=y
204# CONFIG_IP_ROUTE_MULTIPATH_CACHED is not set
205CONFIG_IP_ROUTE_VERBOSE=y
206CONFIG_IP_PNP=y
207# CONFIG_IP_PNP_DHCP is not set
208CONFIG_IP_PNP_BOOTP=y
209# CONFIG_IP_PNP_RARP is not set
210CONFIG_NET_IPIP=m
211CONFIG_NET_IPGRE=m
212# CONFIG_NET_IPGRE_BROADCAST is not set
213# CONFIG_IP_MROUTE is not set
214# CONFIG_ARPD is not set
215CONFIG_SYN_COOKIES=y
216# CONFIG_INET_AH is not set
217# CONFIG_INET_ESP is not set
218# CONFIG_INET_IPCOMP is not set
219CONFIG_INET_TUNNEL=m
220CONFIG_INET_DIAG=y
221CONFIG_INET_TCP_DIAG=y
222CONFIG_TCP_CONG_ADVANCED=y
223
224#
225# TCP congestion control
226#
227CONFIG_TCP_CONG_BIC=y
228CONFIG_TCP_CONG_WESTWOOD=m
229CONFIG_TCP_CONG_HTCP=m
230# CONFIG_TCP_CONG_HSTCP is not set
231# CONFIG_TCP_CONG_HYBLA is not set
232# CONFIG_TCP_CONG_VEGAS is not set
233# CONFIG_TCP_CONG_SCALABLE is not set
234# CONFIG_IPV6 is not set
235# CONFIG_NETFILTER is not set
236
237#
238# DCCP Configuration (EXPERIMENTAL)
239#
240# CONFIG_IP_DCCP is not set
241
242#
243# SCTP Configuration (EXPERIMENTAL)
244#
245# CONFIG_IP_SCTP is not set
246# CONFIG_ATM is not set
247# CONFIG_BRIDGE is not set
248# CONFIG_VLAN_8021Q is not set
249# CONFIG_DECNET is not set
250# CONFIG_LLC2 is not set
251# CONFIG_IPX is not set
252# CONFIG_ATALK is not set
253# CONFIG_X25 is not set
254# CONFIG_LAPB is not set
255# CONFIG_NET_DIVERT is not set
256# CONFIG_ECONET is not set
257# CONFIG_WAN_ROUTER is not set
258# CONFIG_NET_SCHED is not set
259# CONFIG_NET_CLS_ROUTE is not set
260
261#
262# Network testing
263#
264# CONFIG_NET_PKTGEN is not set
265# CONFIG_NETFILTER_NETLINK is not set
266# CONFIG_HAMRADIO is not set
267# CONFIG_IRDA is not set
268# CONFIG_BT is not set
269# CONFIG_IEEE80211 is not set
270
271#
272# Device Drivers
273#
274
275#
276# Generic Driver Options
277#
278CONFIG_STANDALONE=y
279CONFIG_PREVENT_FIRMWARE_BUILD=y
280# CONFIG_FW_LOADER is not set
281
282#
283# Memory Technology Devices (MTD)
284#
285# CONFIG_MTD is not set
286
287#
288# Parallel port support
289#
290# CONFIG_PARPORT is not set
291
292#
293# Plug and Play support
294#
295
296#
297# Block devices
298#
299# CONFIG_BLK_DEV_FD is not set
300# CONFIG_BLK_CPQ_DA is not set
301# CONFIG_BLK_CPQ_CISS_DA is not set
302# CONFIG_BLK_DEV_DAC960 is not set
303# CONFIG_BLK_DEV_UMEM is not set
304# CONFIG_BLK_DEV_COW_COMMON is not set
305CONFIG_BLK_DEV_LOOP=m
306# CONFIG_BLK_DEV_CRYPTOLOOP is not set
307CONFIG_BLK_DEV_NBD=m
308# CONFIG_BLK_DEV_SX8 is not set
309# CONFIG_BLK_DEV_UB is not set
310CONFIG_BLK_DEV_RAM=y
311CONFIG_BLK_DEV_RAM_COUNT=16
312CONFIG_BLK_DEV_RAM_SIZE=4096
313# CONFIG_BLK_DEV_INITRD is not set
314# CONFIG_LBD is not set
315# CONFIG_CDROM_PKTCDVD is not set
316
317#
318# IO Schedulers
319#
320CONFIG_IOSCHED_NOOP=y
321CONFIG_IOSCHED_AS=y
322CONFIG_IOSCHED_DEADLINE=y
323CONFIG_IOSCHED_CFQ=y
324# CONFIG_ATA_OVER_ETH is not set
325
326#
327# ATA/ATAPI/MFM/RLL support
328#
329CONFIG_IDE=y
330CONFIG_BLK_DEV_IDE=y
331
332#
333# Please see Documentation/ide.txt for help/info on IDE drives
334#
335# CONFIG_BLK_DEV_IDE_SATA is not set
336CONFIG_BLK_DEV_IDEDISK=y
337# CONFIG_IDEDISK_MULTI_MODE is not set
338# CONFIG_BLK_DEV_IDECD is not set
339# CONFIG_BLK_DEV_IDETAPE is not set
340# CONFIG_BLK_DEV_IDEFLOPPY is not set
341# CONFIG_BLK_DEV_IDESCSI is not set
342# CONFIG_IDE_TASK_IOCTL is not set
343
344#
345# IDE chipset support/bugfixes
346#
347CONFIG_IDE_GENERIC=y
348CONFIG_BLK_DEV_IDEPCI=y
349# CONFIG_IDEPCI_SHARE_IRQ is not set
350# CONFIG_BLK_DEV_OFFBOARD is not set
351# CONFIG_BLK_DEV_GENERIC is not set
352# CONFIG_BLK_DEV_OPTI621 is not set
353CONFIG_BLK_DEV_IDEDMA_PCI=y
354# CONFIG_BLK_DEV_IDEDMA_FORCED is not set
355# CONFIG_IDEDMA_PCI_AUTO is not set
356# CONFIG_BLK_DEV_AEC62XX is not set
357# CONFIG_BLK_DEV_ALI15X3 is not set
358# CONFIG_BLK_DEV_AMD74XX is not set
359# CONFIG_BLK_DEV_CMD64X is not set
360# CONFIG_BLK_DEV_TRIFLEX is not set
361# CONFIG_BLK_DEV_CY82C693 is not set
362# CONFIG_BLK_DEV_CS5520 is not set
363# CONFIG_BLK_DEV_CS5530 is not set
364# CONFIG_BLK_DEV_HPT34X is not set
365# CONFIG_BLK_DEV_HPT366 is not set
366# CONFIG_BLK_DEV_SC1200 is not set
367# CONFIG_BLK_DEV_PIIX is not set
368# CONFIG_BLK_DEV_IT821X is not set
369# CONFIG_BLK_DEV_NS87415 is not set
370# CONFIG_BLK_DEV_PDC202XX_OLD is not set
371# CONFIG_BLK_DEV_PDC202XX_NEW is not set
372# CONFIG_BLK_DEV_SVWKS is not set
373CONFIG_BLK_DEV_SIIMAGE=y
374# CONFIG_BLK_DEV_SLC90E66 is not set
375# CONFIG_BLK_DEV_TRM290 is not set
376# CONFIG_BLK_DEV_VIA82CXXX is not set
377# CONFIG_IDE_ARM is not set
378CONFIG_BLK_DEV_IDEDMA=y
379# CONFIG_IDEDMA_IVB is not set
380# CONFIG_IDEDMA_AUTO is not set
381# CONFIG_BLK_DEV_HD is not set
382
383#
384# SCSI device support
385#
386# CONFIG_RAID_ATTRS is not set
387CONFIG_SCSI=y
388CONFIG_SCSI_PROC_FS=y
389
390#
391# SCSI support type (disk, tape, CD-ROM)
392#
393CONFIG_BLK_DEV_SD=y
394# CONFIG_CHR_DEV_ST is not set
395# CONFIG_CHR_DEV_OSST is not set
396# CONFIG_BLK_DEV_SR is not set
397# CONFIG_CHR_DEV_SG is not set
398# CONFIG_CHR_DEV_SCH is not set
399
400#
401# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
402#
403# CONFIG_SCSI_MULTI_LUN is not set
404# CONFIG_SCSI_CONSTANTS is not set
405# CONFIG_SCSI_LOGGING is not set
406
407#
408# SCSI Transport Attributes
409#
410# CONFIG_SCSI_SPI_ATTRS is not set
411# CONFIG_SCSI_FC_ATTRS is not set
412# CONFIG_SCSI_ISCSI_ATTRS is not set
413
414#
415# SCSI low-level drivers
416#
417# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
418# CONFIG_SCSI_3W_9XXX is not set
419# CONFIG_SCSI_ARCMSR is not set
420# CONFIG_SCSI_ACARD is not set
421# CONFIG_SCSI_AACRAID is not set
422# CONFIG_SCSI_AIC7XXX is not set
423# CONFIG_SCSI_AIC7XXX_OLD is not set
424# CONFIG_SCSI_AIC79XX is not set
425# CONFIG_SCSI_DPT_I2O is not set
426# CONFIG_MEGARAID_NEWGEN is not set
427# CONFIG_MEGARAID_LEGACY is not set
428# CONFIG_SCSI_SATA is not set
429# CONFIG_SCSI_BUSLOGIC is not set
430# CONFIG_SCSI_DMX3191D is not set
431# CONFIG_SCSI_EATA is not set
432# CONFIG_SCSI_FUTURE_DOMAIN is not set
433# CONFIG_SCSI_GDTH is not set
434# CONFIG_SCSI_IPS is not set
435# CONFIG_SCSI_INITIO is not set
436# CONFIG_SCSI_INIA100 is not set
437# CONFIG_SCSI_SYM53C8XX_2 is not set
438# CONFIG_SCSI_IPR is not set
439# CONFIG_SCSI_QLOGIC_FC is not set
440# CONFIG_SCSI_QLOGIC_1280 is not set
441CONFIG_SCSI_QLA2XXX=y
442# CONFIG_SCSI_QLA21XX is not set
443# CONFIG_SCSI_QLA22XX is not set
444# CONFIG_SCSI_QLA2300 is not set
445# CONFIG_SCSI_QLA2322 is not set
446# CONFIG_SCSI_QLA6312 is not set
447# CONFIG_SCSI_QLA24XX is not set
448# CONFIG_SCSI_LPFC is not set
449# CONFIG_SCSI_DC395x is not set
450# CONFIG_SCSI_DC390T is not set
451# CONFIG_SCSI_NSP32 is not set
452# CONFIG_SCSI_DEBUG is not set
453
454#
455# Multi-device support (RAID and LVM)
456#
457# CONFIG_MD is not set
458
459#
460# Fusion MPT device support
461#
462# CONFIG_FUSION is not set
463# CONFIG_FUSION_SPI is not set
464# CONFIG_FUSION_FC is not set
465
466#
467# IEEE 1394 (FireWire) support
468#
469CONFIG_IEEE1394=m
470
471#
472# Subsystem Options
473#
474# CONFIG_IEEE1394_VERBOSEDEBUG is not set
475# CONFIG_IEEE1394_OUI_DB is not set
476CONFIG_IEEE1394_EXTRA_CONFIG_ROMS=y
477CONFIG_IEEE1394_CONFIG_ROM_IP1394=y
478# CONFIG_IEEE1394_EXPORT_FULL_API is not set
479
480#
481# Device Drivers
482#
483
484#
485# Texas Instruments PCILynx requires I2C
486#
487CONFIG_IEEE1394_OHCI1394=m
488
489#
490# Protocol Drivers
491#
492CONFIG_IEEE1394_VIDEO1394=m
493CONFIG_IEEE1394_SBP2=m
494# CONFIG_IEEE1394_SBP2_PHYS_DMA is not set
495CONFIG_IEEE1394_ETH1394=m
496CONFIG_IEEE1394_DV1394=m
497CONFIG_IEEE1394_RAWIO=m
498CONFIG_IEEE1394_CMP=m
499CONFIG_IEEE1394_AMDTP=m
500
501#
502# I2O device support
503#
504# CONFIG_I2O is not set
505
506#
507# Network device support
508#
509CONFIG_NETDEVICES=y
510CONFIG_DUMMY=m
511# CONFIG_BONDING is not set
512# CONFIG_EQUALIZER is not set
513# CONFIG_TUN is not set
514
515#
516# ARCnet devices
517#
518# CONFIG_ARCNET is not set
519
520#
521# PHY device support
522#
523# CONFIG_PHYLIB is not set
524
525#
526# Ethernet (10 or 100Mbit)
527#
528CONFIG_NET_ETHERNET=y
529CONFIG_MII=y
530# CONFIG_HAPPYMEAL is not set
531# CONFIG_SUNGEM is not set
532# CONFIG_NET_VENDOR_3COM is not set
533
534#
535# Tulip family network device support
536#
537# CONFIG_NET_TULIP is not set
538# CONFIG_HP100 is not set
539# CONFIG_NET_PCI is not set
540
541#
542# Ethernet (1000 Mbit)
543#
544# CONFIG_ACENIC is not set
545# CONFIG_DL2K is not set
546# CONFIG_E1000 is not set
547# CONFIG_NS83820 is not set
548# CONFIG_HAMACHI is not set
549# CONFIG_YELLOWFIN is not set
550CONFIG_R8169=y
551# CONFIG_R8169_NAPI is not set
552# CONFIG_SIS190 is not set
553# CONFIG_SKGE is not set
554# CONFIG_SKY2 is not set
555# CONFIG_SK98LIN is not set
556# CONFIG_TIGON3 is not set
557# CONFIG_BNX2 is not set
558
559#
560# Ethernet (10000 Mbit)
561#
562# CONFIG_CHELSIO_T1 is not set
563# CONFIG_IXGB is not set
564# CONFIG_S2IO is not set
565
566#
567# Token Ring devices
568#
569# CONFIG_TR is not set
570
571#
572# Wireless LAN (non-hamradio)
573#
574# CONFIG_NET_RADIO is not set
575
576#
577# Wan interfaces
578#
579# CONFIG_WAN is not set
580# CONFIG_FDDI is not set
581# CONFIG_HIPPI is not set
582# CONFIG_PPP is not set
583# CONFIG_SLIP is not set
584# CONFIG_NET_FC is not set
585# CONFIG_SHAPER is not set
586# CONFIG_NETCONSOLE is not set
587# CONFIG_KGDBOE is not set
588# CONFIG_NETPOLL is not set
589# CONFIG_NETPOLL_RX is not set
590# CONFIG_NETPOLL_TRAP is not set
591# CONFIG_NET_POLL_CONTROLLER is not set
592
593#
594# ISDN subsystem
595#
596# CONFIG_ISDN is not set
597
598#
599# Telephony Support
600#
601# CONFIG_PHONE is not set
602
603#
604# Input device support
605#
606CONFIG_INPUT=y
607
608#
609# Userland interfaces
610#
611# CONFIG_INPUT_MOUSEDEV is not set
612# CONFIG_INPUT_JOYDEV is not set
613# CONFIG_INPUT_TSDEV is not set
614# CONFIG_INPUT_EVDEV is not set
615# CONFIG_INPUT_EVBUG is not set
616
617#
618# Input Device Drivers
619#
620# CONFIG_INPUT_KEYBOARD is not set
621# CONFIG_INPUT_MOUSE is not set
622# CONFIG_INPUT_JOYSTICK is not set
623# CONFIG_INPUT_TOUCHSCREEN is not set
624# CONFIG_INPUT_MISC is not set
625
626#
627# Hardware I/O ports
628#
629# CONFIG_SERIO is not set
630# CONFIG_GAMEPORT is not set
631
632#
633# Character devices
634#
635CONFIG_VT=y
636CONFIG_VT_CONSOLE=y
637CONFIG_HW_CONSOLE=y
638# CONFIG_SERIAL_NONSTANDARD is not set
639
640#
641# Serial drivers
642#
643# CONFIG_SERIAL_8250 is not set
644
645#
646# Non-8250 serial port support
647#
648CONFIG_SERIAL_CORE=y
649CONFIG_SERIAL_CORE_CONSOLE=y
650CONFIG_SERIAL_VR41XX=y
651CONFIG_SERIAL_VR41XX_CONSOLE=y
652# CONFIG_SERIAL_JSM is not set
653CONFIG_UNIX98_PTYS=y
654CONFIG_LEGACY_PTYS=y
655CONFIG_LEGACY_PTY_COUNT=256
656
657#
658# IPMI
659#
660# CONFIG_IPMI_HANDLER is not set
661
662#
663# Watchdog Cards
664#
665# CONFIG_WATCHDOG is not set
666# CONFIG_RTC is not set
667# CONFIG_GEN_RTC is not set
668# CONFIG_RTC_VR41XX is not set
669# CONFIG_DTLK is not set
670# CONFIG_R3964 is not set
671# CONFIG_APPLICOM is not set
672# CONFIG_TANBAC_TB0219 is not set
673
674#
675# Ftape, the floppy tape device driver
676#
677# CONFIG_DRM is not set
678CONFIG_GPIO_VR41XX=y
679# CONFIG_RAW_DRIVER is not set
680
681#
682# TPM devices
683#
684# CONFIG_TCG_TPM is not set
685
686#
687# I2C support
688#
689# CONFIG_I2C is not set
690
691#
692# Dallas's 1-wire bus
693#
694# CONFIG_W1 is not set
695
696#
697# Hardware Monitoring support
698#
699# CONFIG_HWMON is not set
700# CONFIG_HWMON_VID is not set
701
702#
703# Misc devices
704#
705
706#
707# Multimedia Capabilities Port drivers
708#
709
710#
711# Multimedia devices
712#
713# CONFIG_VIDEO_DEV is not set
714
715#
716# Digital Video Broadcasting Devices
717#
718# CONFIG_DVB is not set
719
720#
721# Graphics support
722#
723# CONFIG_FB is not set
724
725#
726# Console display driver support
727#
728# CONFIG_VGA_CONSOLE is not set
729CONFIG_DUMMY_CONSOLE=y
730
731#
732# Speakup console speech
733#
734# CONFIG_SPEAKUP is not set
735
736#
737# Sound
738#
739# CONFIG_SOUND is not set
740
741#
742# USB support
743#
744CONFIG_USB_ARCH_HAS_HCD=y
745CONFIG_USB_ARCH_HAS_OHCI=y
746CONFIG_USB=m
747# CONFIG_USB_DEBUG is not set
748
749#
750# Miscellaneous USB options
751#
752# CONFIG_USB_DEVICEFS is not set
753# CONFIG_USB_BANDWIDTH is not set
754# CONFIG_USB_DYNAMIC_MINORS is not set
755# CONFIG_USB_OTG is not set
756
757#
758# USB Host Controller Drivers
759#
760CONFIG_USB_EHCI_HCD=m
761# CONFIG_USB_EHCI_SPLIT_ISO is not set
762# CONFIG_USB_EHCI_ROOT_HUB_TT is not set
763# CONFIG_USB_ISP116X_HCD is not set
764CONFIG_USB_OHCI_HCD=m
765# CONFIG_USB_OHCI_BIG_ENDIAN is not set
766CONFIG_USB_OHCI_LITTLE_ENDIAN=y
767# CONFIG_USB_UHCI_HCD is not set
768# CONFIG_USB_SL811_HCD is not set
769
770#
771# USB Device Class drivers
772#
773# CONFIG_USB_BLUETOOTH_TTY is not set
774# CONFIG_USB_ACM is not set
775# CONFIG_USB_PRINTER is not set
776
777#
778# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support' may also be needed; see USB_STORAGE Help for more information
779#
780CONFIG_USB_STORAGE=m
781# CONFIG_USB_STORAGE_DEBUG is not set
782# CONFIG_USB_STORAGE_DATAFAB is not set
783# CONFIG_USB_STORAGE_FREECOM is not set
784# CONFIG_USB_STORAGE_ISD200 is not set
785# CONFIG_USB_STORAGE_DPCM is not set
786# CONFIG_USB_STORAGE_USBAT is not set
787# CONFIG_USB_STORAGE_SDDR09 is not set
788# CONFIG_USB_STORAGE_SDDR55 is not set
789# CONFIG_USB_STORAGE_JUMPSHOT is not set
790
791#
792# USB Input Devices
793#
794CONFIG_USB_HID=m
795CONFIG_USB_HIDINPUT=y
796# CONFIG_HID_FF is not set
797# CONFIG_USB_HIDDEV is not set
798
799#
800# USB HID Boot Protocol drivers
801#
802# CONFIG_USB_KBD is not set
803# CONFIG_USB_MOUSE is not set
804# CONFIG_USB_AIPTEK is not set
805# CONFIG_USB_WACOM is not set
806# CONFIG_USB_ACECAD is not set
807# CONFIG_USB_KBTAB is not set
808# CONFIG_USB_POWERMATE is not set
809# CONFIG_USB_MTOUCH is not set
810# CONFIG_USB_ITMTOUCH is not set
811# CONFIG_USB_EGALAX is not set
812# CONFIG_USB_YEALINK is not set
813# CONFIG_USB_XPAD is not set
814# CONFIG_USB_ATI_REMOTE is not set
815# CONFIG_USB_KEYSPAN_REMOTE is not set
816# CONFIG_USB_APPLETOUCH is not set
817
818#
819# USB Imaging devices
820#
821# CONFIG_USB_MDC800 is not set
822# CONFIG_USB_MICROTEK is not set
823
824#
825# USB Multimedia devices
826#
827# CONFIG_USB_DABUSB is not set
828
829#
830# Video4Linux support is needed for USB Multimedia device support
831#
832
833#
834# USB Network Adapters
835#
836# CONFIG_USB_CATC is not set
837# CONFIG_USB_KAWETH is not set
838# CONFIG_USB_PEGASUS is not set
839# CONFIG_USB_RTL8150 is not set
840# CONFIG_USB_USBNET is not set
841CONFIG_USB_MON=y
842
843#
844# USB port drivers
845#
846
847#
848# USB Serial Converter support
849#
850# CONFIG_USB_SERIAL is not set
851
852#
853# USB Miscellaneous drivers
854#
855# CONFIG_USB_EMI62 is not set
856# CONFIG_USB_EMI26 is not set
857# CONFIG_USB_AUERSWALD is not set
858# CONFIG_USB_RIO500 is not set
859# CONFIG_USB_LEGOTOWER is not set
860# CONFIG_USB_LCD is not set
861# CONFIG_USB_LED is not set
862# CONFIG_USB_CYTHERM is not set
863# CONFIG_USB_GOTEMP is not set
864# CONFIG_USB_PHIDGETKIT is not set
865# CONFIG_USB_PHIDGETSERVO is not set
866# CONFIG_USB_IDMOUSE is not set
867# CONFIG_USB_SISUSBVGA is not set
868# CONFIG_USB_LD is not set
869
870#
871# USB DSL modem support
872#
873
874#
875# USB Gadget Support
876#
877# CONFIG_USB_GADGET is not set
878
879#
880# MMC/SD Card support
881#
882# CONFIG_MMC is not set
883
884#
885# InfiniBand support
886#
887# CONFIG_INFINIBAND is not set
888
889#
890# SN Devices
891#
892
893#
894# Distributed Lock Manager
895#
896# CONFIG_DLM 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
904# CONFIG_EXT3_FS is not set
905# CONFIG_REISER4_FS is not set
906# CONFIG_REISERFS_FS is not set
907# CONFIG_JFS_FS is not set
908# CONFIG_FS_POSIX_ACL is not set
909
910#
911# XFS support
912#
913CONFIG_XFS_FS=y
914# CONFIG_XFS_RT is not set
915CONFIG_XFS_QUOTA=y
916# CONFIG_XFS_SECURITY is not set
917CONFIG_XFS_POSIX_ACL=y
918# CONFIG_OCFS2_FS is not set
919# CONFIG_MINIX_FS is not set
920CONFIG_ROMFS_FS=m
921CONFIG_INOTIFY=y
922# CONFIG_QUOTA is not set
923CONFIG_QUOTACTL=y
924# CONFIG_DNOTIFY is not set
925# CONFIG_AUTOFS_FS is not set
926CONFIG_AUTOFS4_FS=y
927# CONFIG_FUSE_FS is not set
928
929#
930# CD-ROM/DVD Filesystems
931#
932# CONFIG_ISO9660_FS is not set
933# CONFIG_UDF_FS is not set
934
935#
936# DOS/FAT/NT Filesystems
937#
938# CONFIG_MSDOS_FS is not set
939# CONFIG_VFAT_FS is not set
940# CONFIG_NTFS_FS is not set
941
942#
943# Pseudo filesystems
944#
945CONFIG_PROC_FS=y
946CONFIG_PROC_KCORE=y
947CONFIG_SYSFS=y
948CONFIG_TMPFS=y
949# CONFIG_HUGETLB_PAGE is not set
950CONFIG_RAMFS=y
951# CONFIG_CONFIGFS_FS is not set
952# CONFIG_RELAYFS_FS is not set
953
954#
955# Miscellaneous filesystems
956#
957# CONFIG_ADFS_FS is not set
958# CONFIG_AFFS_FS is not set
959# CONFIG_ASFS_FS is not set
960# CONFIG_HFS_FS is not set
961# CONFIG_HFSPLUS_FS is not set
962# CONFIG_BEFS_FS is not set
963# CONFIG_BFS_FS is not set
964# CONFIG_EFS_FS is not set
965CONFIG_CRAMFS=m
966# CONFIG_VXFS_FS is not set
967# CONFIG_HPFS_FS is not set
968# CONFIG_QNX4FS_FS is not set
969# CONFIG_SYSV_FS is not set
970# CONFIG_UFS_FS is not set
971
972#
973# Network File Systems
974#
975CONFIG_NFS_FS=y
976CONFIG_NFS_V3=y
977# CONFIG_NFS_V3_ACL is not set
978# CONFIG_NFS_V4 is not set
979# CONFIG_NFS_DIRECTIO is not set
980# CONFIG_NFSD is not set
981CONFIG_ROOT_NFS=y
982CONFIG_LOCKD=y
983CONFIG_LOCKD_V4=y
984CONFIG_NFS_COMMON=y
985CONFIG_SUNRPC=y
986# CONFIG_RPCSEC_GSS_KRB5 is not set
987# CONFIG_RPCSEC_GSS_SPKM3 is not set
988# CONFIG_SMB_FS is not set
989# CONFIG_CIFS is not set
990# CONFIG_NCP_FS is not set
991# CONFIG_CODA_FS is not set
992# CONFIG_AFS_FS is not set
993# CONFIG_9P_FS is not set
994
995#
996# Partition Types
997#
998# CONFIG_PARTITION_ADVANCED is not set
999CONFIG_MSDOS_PARTITION=y
1000
1001#
1002# Native Language Support
1003#
1004# CONFIG_NLS is not set
1005
1006#
1007# Kernel hacking
1008#
1009# CONFIG_PRINTK_TIME is not set
1010# CONFIG_DEBUG_KERNEL is not set
1011CONFIG_LOG_BUF_SHIFT=14
1012CONFIG_CROSSCOMPILE=y
1013CONFIG_CMDLINE="mem=64M console=ttyVR0,115200 ip=any root=/dev/nfs"
1014
1015#
1016# Security options
1017#
1018CONFIG_KEYS=y
1019CONFIG_KEYS_DEBUG_PROC_KEYS=y
1020# CONFIG_SECURITY is not set
1021
1022#
1023# Cryptographic options
1024#
1025# CONFIG_CRYPTO is not set
1026
1027#
1028# Hardware crypto devices
1029#
1030
1031#
1032# Library routines
1033#
1034# CONFIG_CRC_CCITT is not set
1035# CONFIG_CRC16 is not set
1036CONFIG_CRC32=y
1037# CONFIG_LIBCRC32C is not set
1038CONFIG_ZLIB_INFLATE=m
1039CONFIG_GENERIC_HARDIRQS=y
1040CONFIG_GENERIC_IRQ_PROBE=y
1041CONFIG_ISA_DMA_API=y
diff --git a/arch/mips/kernel/offset.c b/arch/mips/kernel/asm-offsets.c
index 2c11abb5a4..2c11abb5a4 100644
--- a/arch/mips/kernel/offset.c
+++ b/arch/mips/kernel/asm-offsets.c
diff --git a/arch/mips/kernel/genrtc.c b/arch/mips/kernel/genrtc.c
index 288bf51ad4..71416e7bbb 100644
--- a/arch/mips/kernel/genrtc.c
+++ b/arch/mips/kernel/genrtc.c
@@ -14,7 +14,7 @@
14#include <asm/rtc.h> 14#include <asm/rtc.h>
15#include <asm/time.h> 15#include <asm/time.h>
16 16
17static spinlock_t mips_rtc_lock = SPIN_LOCK_UNLOCKED; 17static DEFINE_SPINLOCK(mips_rtc_lock);
18 18
19unsigned int get_rtc_time(struct rtc_time *time) 19unsigned int get_rtc_time(struct rtc_time *time)
20{ 20{
diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
index 7eec7568bf..447759201d 100644
--- a/arch/mips/kernel/i8259.c
+++ b/arch/mips/kernel/i8259.c
@@ -31,7 +31,7 @@ void disable_8259A_irq(unsigned int irq);
31 * moves to arch independent land 31 * moves to arch independent land
32 */ 32 */
33 33
34spinlock_t i8259A_lock = SPIN_LOCK_UNLOCKED; 34spinlock_t DEFINE_SPINLOCK(i8259A_lock);
35 35
36static void end_8259A_irq (unsigned int irq) 36static void end_8259A_irq (unsigned int irq)
37{ 37{
diff --git a/arch/mips/kernel/irixioctl.c b/arch/mips/kernel/irixioctl.c
index 4cd3d38a22..3cdc22346f 100644
--- a/arch/mips/kernel/irixioctl.c
+++ b/arch/mips/kernel/irixioctl.c
@@ -14,6 +14,7 @@
14#include <linux/syscalls.h> 14#include <linux/syscalls.h>
15#include <linux/tty.h> 15#include <linux/tty.h>
16#include <linux/file.h> 16#include <linux/file.h>
17#include <linux/rcupdate.h>
17 18
18#include <asm/uaccess.h> 19#include <asm/uaccess.h>
19#include <asm/ioctl.h> 20#include <asm/ioctl.h>
@@ -33,7 +34,7 @@ static struct tty_struct *get_tty(int fd)
33 struct file *filp; 34 struct file *filp;
34 struct tty_struct *ttyp = NULL; 35 struct tty_struct *ttyp = NULL;
35 36
36 spin_lock(&current->files->file_lock); 37 rcu_read_lock();
37 filp = fcheck(fd); 38 filp = fcheck(fd);
38 if(filp && filp->private_data) { 39 if(filp && filp->private_data) {
39 ttyp = (struct tty_struct *) filp->private_data; 40 ttyp = (struct tty_struct *) filp->private_data;
@@ -41,7 +42,7 @@ static struct tty_struct *get_tty(int fd)
41 if(ttyp->magic != TTY_MAGIC) 42 if(ttyp->magic != TTY_MAGIC)
42 ttyp =NULL; 43 ttyp =NULL;
43 } 44 }
44 spin_unlock(&current->files->file_lock); 45 rcu_read_unlock();
45 return ttyp; 46 return ttyp;
46} 47}
47 48
diff --git a/arch/mips/kernel/irixsig.c b/arch/mips/kernel/irixsig.c
index 4c114ae217..eff89322ba 100644
--- a/arch/mips/kernel/irixsig.c
+++ b/arch/mips/kernel/irixsig.c
@@ -440,18 +440,6 @@ struct irix5_siginfo {
440 } stuff; 440 } stuff;
441}; 441};
442 442
443static inline unsigned long timespectojiffies(struct timespec *value)
444{
445 unsigned long sec = (unsigned) value->tv_sec;
446 long nsec = value->tv_nsec;
447
448 if (sec > (LONG_MAX / HZ))
449 return LONG_MAX;
450 nsec += 1000000000L / HZ - 1;
451 nsec /= 1000000000L / HZ;
452 return HZ * sec + nsec;
453}
454
455asmlinkage int irix_sigpoll_sys(unsigned long *set, struct irix5_siginfo *info, 443asmlinkage int irix_sigpoll_sys(unsigned long *set, struct irix5_siginfo *info,
456 struct timespec *tp) 444 struct timespec *tp)
457{ 445{
@@ -489,14 +477,13 @@ asmlinkage int irix_sigpoll_sys(unsigned long *set, struct irix5_siginfo *info,
489 error = -EINVAL; 477 error = -EINVAL;
490 goto out; 478 goto out;
491 } 479 }
492 expire = timespectojiffies(tp)+(tp->tv_sec||tp->tv_nsec); 480 expire = timespec_to_jiffies(tp) + (tp->tv_sec||tp->tv_nsec);
493 } 481 }
494 482
495 while(1) { 483 while(1) {
496 long tmp = 0; 484 long tmp = 0;
497 485
498 current->state = TASK_INTERRUPTIBLE; 486 expire = schedule_timeout_interruptible(expire);
499 expire = schedule_timeout(expire);
500 487
501 for (i=0; i<=4; i++) 488 for (i=0; i<=4; i++)
502 tmp |= (current->pending.signal.sig[i] & kset.sig[i]); 489 tmp |= (current->pending.signal.sig[i] & kset.sig[i]);
diff --git a/arch/mips/kernel/r2300_fpu.S b/arch/mips/kernel/r2300_fpu.S
index f83c31f720..ac68e68339 100644
--- a/arch/mips/kernel/r2300_fpu.S
+++ b/arch/mips/kernel/r2300_fpu.S
@@ -15,7 +15,7 @@
15#include <asm/errno.h> 15#include <asm/errno.h>
16#include <asm/fpregdef.h> 16#include <asm/fpregdef.h>
17#include <asm/mipsregs.h> 17#include <asm/mipsregs.h>
18#include <asm/offset.h> 18#include <asm/asm-offsets.h>
19#include <asm/regdef.h> 19#include <asm/regdef.h>
20 20
21#define EX(a,b) \ 21#define EX(a,b) \
diff --git a/arch/mips/kernel/r2300_switch.S b/arch/mips/kernel/r2300_switch.S
index f10019640e..0d9c4a32a9 100644
--- a/arch/mips/kernel/r2300_switch.S
+++ b/arch/mips/kernel/r2300_switch.S
@@ -15,7 +15,7 @@
15#include <asm/cachectl.h> 15#include <asm/cachectl.h>
16#include <asm/fpregdef.h> 16#include <asm/fpregdef.h>
17#include <asm/mipsregs.h> 17#include <asm/mipsregs.h>
18#include <asm/offset.h> 18#include <asm/asm-offsets.h>
19#include <asm/page.h> 19#include <asm/page.h>
20#include <asm/regdef.h> 20#include <asm/regdef.h>
21#include <asm/stackframe.h> 21#include <asm/stackframe.h>
diff --git a/arch/mips/kernel/r4k_fpu.S b/arch/mips/kernel/r4k_fpu.S
index aba665bcb3..1a14c6b188 100644
--- a/arch/mips/kernel/r4k_fpu.S
+++ b/arch/mips/kernel/r4k_fpu.S
@@ -17,7 +17,7 @@
17#include <asm/errno.h> 17#include <asm/errno.h>
18#include <asm/fpregdef.h> 18#include <asm/fpregdef.h>
19#include <asm/mipsregs.h> 19#include <asm/mipsregs.h>
20#include <asm/offset.h> 20#include <asm/asm-offsets.h>
21#include <asm/regdef.h> 21#include <asm/regdef.h>
22 22
23 .macro EX insn, reg, src 23 .macro EX insn, reg, src
diff --git a/arch/mips/kernel/r4k_switch.S b/arch/mips/kernel/r4k_switch.S
index e02b7722cc..d2afbd19a9 100644
--- a/arch/mips/kernel/r4k_switch.S
+++ b/arch/mips/kernel/r4k_switch.S
@@ -15,7 +15,7 @@
15#include <asm/cachectl.h> 15#include <asm/cachectl.h>
16#include <asm/fpregdef.h> 16#include <asm/fpregdef.h>
17#include <asm/mipsregs.h> 17#include <asm/mipsregs.h>
18#include <asm/offset.h> 18#include <asm/asm-offsets.h>
19#include <asm/page.h> 19#include <asm/page.h>
20#include <asm/pgtable-bits.h> 20#include <asm/pgtable-bits.h>
21#include <asm/regdef.h> 21#include <asm/regdef.h>
diff --git a/arch/mips/kernel/r6000_fpu.S b/arch/mips/kernel/r6000_fpu.S
index d8d3b13fe5..43cda53f5a 100644
--- a/arch/mips/kernel/r6000_fpu.S
+++ b/arch/mips/kernel/r6000_fpu.S
@@ -13,7 +13,7 @@
13#include <asm/asm.h> 13#include <asm/asm.h>
14#include <asm/fpregdef.h> 14#include <asm/fpregdef.h>
15#include <asm/mipsregs.h> 15#include <asm/mipsregs.h>
16#include <asm/offset.h> 16#include <asm/asm-offsets.h>
17#include <asm/regdef.h> 17#include <asm/regdef.h>
18 18
19 .set noreorder 19 .set noreorder
diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
index 344f2e29eb..17b5030fb6 100644
--- a/arch/mips/kernel/scall32-o32.S
+++ b/arch/mips/kernel/scall32-o32.S
@@ -19,7 +19,7 @@
19#include <asm/thread_info.h> 19#include <asm/thread_info.h>
20#include <asm/unistd.h> 20#include <asm/unistd.h>
21#include <asm/war.h> 21#include <asm/war.h>
22#include <asm/offset.h> 22#include <asm/asm-offsets.h>
23 23
24/* Highest syscall used of any syscall flavour */ 24/* Highest syscall used of any syscall flavour */
25#define MAX_SYSCALL_NO __NR_O32_Linux + __NR_O32_Linux_syscalls 25#define MAX_SYSCALL_NO __NR_O32_Linux + __NR_O32_Linux_syscalls
diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
index 32efb88816..ffb22a2068 100644
--- a/arch/mips/kernel/scall64-64.S
+++ b/arch/mips/kernel/scall64-64.S
@@ -14,7 +14,7 @@
14#include <asm/mipsregs.h> 14#include <asm/mipsregs.h>
15#include <asm/regdef.h> 15#include <asm/regdef.h>
16#include <asm/stackframe.h> 16#include <asm/stackframe.h>
17#include <asm/offset.h> 17#include <asm/asm-offsets.h>
18#include <asm/sysmips.h> 18#include <asm/sysmips.h>
19#include <asm/thread_info.h> 19#include <asm/thread_info.h>
20#include <asm/unistd.h> 20#include <asm/unistd.h>
diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c
index ae2a1312d4..21e3e13a4b 100644
--- a/arch/mips/kernel/syscall.c
+++ b/arch/mips/kernel/syscall.c
@@ -31,7 +31,7 @@
31#include <asm/cachectl.h> 31#include <asm/cachectl.h>
32#include <asm/cacheflush.h> 32#include <asm/cacheflush.h>
33#include <asm/ipc.h> 33#include <asm/ipc.h>
34#include <asm/offset.h> 34#include <asm/asm-offsets.h>
35#include <asm/signal.h> 35#include <asm/signal.h>
36#include <asm/sim.h> 36#include <asm/sim.h>
37#include <asm/shmparam.h> 37#include <asm/shmparam.h>
diff --git a/arch/mips/kernel/sysirix.c b/arch/mips/kernel/sysirix.c
index b465954627..4de155699c 100644
--- a/arch/mips/kernel/sysirix.c
+++ b/arch/mips/kernel/sysirix.c
@@ -1032,8 +1032,7 @@ bad:
1032 1032
1033asmlinkage int irix_sginap(int ticks) 1033asmlinkage int irix_sginap(int ticks)
1034{ 1034{
1035 current->state = TASK_INTERRUPTIBLE; 1035 schedule_timeout_interruptible(ticks);
1036 schedule_timeout(ticks);
1037 return 0; 1036 return 0;
1038} 1037}
1039 1038
diff --git a/arch/mips/lib-32/memset.S b/arch/mips/lib-32/memset.S
index ad9ff4071c..1981485bd4 100644
--- a/arch/mips/lib-32/memset.S
+++ b/arch/mips/lib-32/memset.S
@@ -7,7 +7,7 @@
7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc. 7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8 */ 8 */
9#include <asm/asm.h> 9#include <asm/asm.h>
10#include <asm/offset.h> 10#include <asm/asm-offsets.h>
11#include <asm/regdef.h> 11#include <asm/regdef.h>
12 12
13#define EX(insn,reg,addr,handler) \ 13#define EX(insn,reg,addr,handler) \
diff --git a/arch/mips/lib-64/memset.S b/arch/mips/lib-64/memset.S
index 242f1976cf..e2c42c8511 100644
--- a/arch/mips/lib-64/memset.S
+++ b/arch/mips/lib-64/memset.S
@@ -7,7 +7,7 @@
7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc. 7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8 */ 8 */
9#include <asm/asm.h> 9#include <asm/asm.h>
10#include <asm/offset.h> 10#include <asm/asm-offsets.h>
11#include <asm/regdef.h> 11#include <asm/regdef.h>
12 12
13#define EX(insn,reg,addr,handler) \ 13#define EX(insn,reg,addr,handler) \
diff --git a/arch/mips/lib/dec_and_lock.c b/arch/mips/lib/dec_and_lock.c
index e44e9579bd..fd82c84a93 100644
--- a/arch/mips/lib/dec_and_lock.c
+++ b/arch/mips/lib/dec_and_lock.c
@@ -20,14 +20,7 @@
20 * has a cmpxchg, and where atomic->value is an int holding 20 * has a cmpxchg, and where atomic->value is an int holding
21 * the value of the atomic (i.e. the high bits aren't used 21 * the value of the atomic (i.e. the high bits aren't used
22 * for a lock or anything like that). 22 * for a lock or anything like that).
23 *
24 * N.B. ATOMIC_DEC_AND_LOCK gets defined in include/linux/spinlock.h
25 * if spinlocks are empty and thus atomic_dec_and_lock is defined
26 * to be atomic_dec_and_test - in that case we don't need it
27 * defined here as well.
28 */ 23 */
29
30#ifndef ATOMIC_DEC_AND_LOCK
31int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock) 24int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
32{ 25{
33 int counter; 26 int counter;
@@ -52,4 +45,3 @@ int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
52} 45}
53 46
54EXPORT_SYMBOL(_atomic_dec_and_lock); 47EXPORT_SYMBOL(_atomic_dec_and_lock);
55#endif /* ATOMIC_DEC_AND_LOCK */
diff --git a/arch/mips/lib/memcpy.S b/arch/mips/lib/memcpy.S
index 90ee8d4326..a78865f765 100644
--- a/arch/mips/lib/memcpy.S
+++ b/arch/mips/lib/memcpy.S
@@ -14,7 +14,7 @@
14 */ 14 */
15#include <linux/config.h> 15#include <linux/config.h>
16#include <asm/asm.h> 16#include <asm/asm.h>
17#include <asm/offset.h> 17#include <asm/asm-offsets.h>
18#include <asm/regdef.h> 18#include <asm/regdef.h>
19 19
20#define dst a0 20#define dst a0
diff --git a/arch/mips/lib/strlen_user.S b/arch/mips/lib/strlen_user.S
index 07660e86c9..eca558d83a 100644
--- a/arch/mips/lib/strlen_user.S
+++ b/arch/mips/lib/strlen_user.S
@@ -7,7 +7,7 @@
7 * Copyright (c) 1999 Silicon Graphics, Inc. 7 * Copyright (c) 1999 Silicon Graphics, Inc.
8 */ 8 */
9#include <asm/asm.h> 9#include <asm/asm.h>
10#include <asm/offset.h> 10#include <asm/asm-offsets.h>
11#include <asm/regdef.h> 11#include <asm/regdef.h>
12 12
13#define EX(insn,reg,addr,handler) \ 13#define EX(insn,reg,addr,handler) \
diff --git a/arch/mips/lib/strncpy_user.S b/arch/mips/lib/strncpy_user.S
index 14bed17c16..d16c76fbfa 100644
--- a/arch/mips/lib/strncpy_user.S
+++ b/arch/mips/lib/strncpy_user.S
@@ -7,7 +7,7 @@
7 */ 7 */
8#include <linux/errno.h> 8#include <linux/errno.h>
9#include <asm/asm.h> 9#include <asm/asm.h>
10#include <asm/offset.h> 10#include <asm/asm-offsets.h>
11#include <asm/regdef.h> 11#include <asm/regdef.h>
12 12
13#define EX(insn,reg,addr,handler) \ 13#define EX(insn,reg,addr,handler) \
diff --git a/arch/mips/lib/strnlen_user.S b/arch/mips/lib/strnlen_user.S
index 6e7a8eed4d..c0ea15194a 100644
--- a/arch/mips/lib/strnlen_user.S
+++ b/arch/mips/lib/strnlen_user.S
@@ -7,7 +7,7 @@
7 * Copyright (c) 1999 Silicon Graphics, Inc. 7 * Copyright (c) 1999 Silicon Graphics, Inc.
8 */ 8 */
9#include <asm/asm.h> 9#include <asm/asm.h>
10#include <asm/offset.h> 10#include <asm/asm-offsets.h>
11#include <asm/regdef.h> 11#include <asm/regdef.h>
12 12
13#define EX(insn,reg,addr,handler) \ 13#define EX(insn,reg,addr,handler) \
diff --git a/arch/mips/pci/Makefile b/arch/mips/pci/Makefile
index c53e4cb359..83d81c9cdc 100644
--- a/arch/mips/pci/Makefile
+++ b/arch/mips/pci/Makefile
@@ -48,6 +48,7 @@ obj-$(CONFIG_SIBYTE_SB1250) += fixup-sb1250.o pci-sb1250.o
48obj-$(CONFIG_SNI_RM200_PCI) += fixup-sni.o ops-sni.o 48obj-$(CONFIG_SNI_RM200_PCI) += fixup-sni.o ops-sni.o
49obj-$(CONFIG_TANBAC_TB0219) += fixup-tb0219.o 49obj-$(CONFIG_TANBAC_TB0219) += fixup-tb0219.o
50obj-$(CONFIG_TANBAC_TB0226) += fixup-tb0226.o 50obj-$(CONFIG_TANBAC_TB0226) += fixup-tb0226.o
51obj-$(CONFIG_TANBAC_TB0287) += fixup-tb0287.o
51obj-$(CONFIG_TOSHIBA_JMR3927) += fixup-jmr3927.o pci-jmr3927.o 52obj-$(CONFIG_TOSHIBA_JMR3927) += fixup-jmr3927.o pci-jmr3927.o
52obj-$(CONFIG_TOSHIBA_RBTX4927) += fixup-rbtx4927.o ops-tx4927.o 53obj-$(CONFIG_TOSHIBA_RBTX4927) += fixup-rbtx4927.o ops-tx4927.o
53obj-$(CONFIG_VICTOR_MPC30X) += fixup-mpc30x.o 54obj-$(CONFIG_VICTOR_MPC30X) += fixup-mpc30x.o
diff --git a/arch/mips/pci/fixup-tb0287.c b/arch/mips/pci/fixup-tb0287.c
new file mode 100644
index 0000000000..8436d7f1fd
--- /dev/null
+++ b/arch/mips/pci/fixup-tb0287.c
@@ -0,0 +1,65 @@
1/*
2 * fixup-tb0287.c, The TANBAC TB0287 specific PCI fixups.
3 *
4 * Copyright (C) 2005 Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
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/pci.h>
22
23#include <asm/vr41xx/tb0287.h>
24
25int __init pcibios_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
26{
27 unsigned char bus;
28 int irq = -1;
29
30 bus = dev->bus->number;
31 if (bus == 0) {
32 switch (slot) {
33 case 16:
34 irq = TB0287_SM501_IRQ;
35 break;
36 case 17:
37 irq = TB0287_SIL680A_IRQ;
38 break;
39 default:
40 break;
41 }
42 } else if (bus == 1) {
43 switch (PCI_SLOT(dev->devfn)) {
44 case 0:
45 irq = TB0287_PCI_SLOT_IRQ;
46 break;
47 case 2:
48 case 3:
49 irq = TB0287_RTL8110_IRQ;
50 break;
51 default:
52 break;
53 }
54 } else if (bus > 1) {
55 irq = TB0287_PCI_SLOT_IRQ;
56 }
57
58 return irq;
59}
60
61/* Do platform specific device initialization at pci_enable_device() time */
62int pcibios_plat_dev_init(struct pci_dev *dev)
63{
64 return 0;
65}
diff --git a/arch/parisc/Makefile b/arch/parisc/Makefile
index 0403d2fcb8..3b339b1cce 100644
--- a/arch/parisc/Makefile
+++ b/arch/parisc/Makefile
@@ -100,15 +100,7 @@ kernel_install: vmlinux
100 100
101install: kernel_install modules_install 101install: kernel_install modules_install
102 102
103prepare: include/asm-parisc/offsets.h 103CLEAN_FILES += lifimage
104
105arch/parisc/kernel/asm-offsets.s: include/asm include/linux/version.h \
106 include/config/MARKER
107
108include/asm-parisc/offsets.h: arch/parisc/kernel/asm-offsets.s
109 $(call filechk,gen-asm-offsets)
110
111CLEAN_FILES += lifimage include/asm-parisc/offsets.h
112MRPROPER_FILES += palo.conf 104MRPROPER_FILES += palo.conf
113 105
114define archhelp 106define archhelp
diff --git a/arch/parisc/hpux/gate.S b/arch/parisc/hpux/gate.S
index 2680a1c0fa..aaaf3306c0 100644
--- a/arch/parisc/hpux/gate.S
+++ b/arch/parisc/hpux/gate.S
@@ -9,7 +9,7 @@
9 */ 9 */
10 10
11#include <asm/assembly.h> 11#include <asm/assembly.h>
12#include <asm/offsets.h> 12#include <asm/asm-offsets.h>
13#include <asm/unistd.h> 13#include <asm/unistd.h>
14#include <asm/errno.h> 14#include <asm/errno.h>
15 15
diff --git a/arch/parisc/hpux/wrappers.S b/arch/parisc/hpux/wrappers.S
index 1aa936dfe1..0b0c3a66b1 100644
--- a/arch/parisc/hpux/wrappers.S
+++ b/arch/parisc/hpux/wrappers.S
@@ -24,7 +24,7 @@
24#warning PA64 support needs more work...did first cut 24#warning PA64 support needs more work...did first cut
25#endif 25#endif
26 26
27#include <asm/offsets.h> 27#include <asm/asm-offsets.h>
28#include <asm/assembly.h> 28#include <asm/assembly.h>
29#include <asm/signal.h> 29#include <asm/signal.h>
30 30
diff --git a/arch/parisc/kernel/entry.S b/arch/parisc/kernel/entry.S
index ee58d37dbb..be0f07f2fa 100644
--- a/arch/parisc/kernel/entry.S
+++ b/arch/parisc/kernel/entry.S
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include <linux/config.h> 25#include <linux/config.h>
26#include <asm/offsets.h> 26#include <asm/asm-offsets.h>
27 27
28/* we have the following possibilities to act on an interruption: 28/* we have the following possibilities to act on an interruption:
29 * - handle in assembly and use shadowed registers only 29 * - handle in assembly and use shadowed registers only
diff --git a/arch/parisc/kernel/head.S b/arch/parisc/kernel/head.S
index ddf7e914f1..28405edf84 100644
--- a/arch/parisc/kernel/head.S
+++ b/arch/parisc/kernel/head.S
@@ -14,7 +14,7 @@
14 14
15#include <linux/autoconf.h> /* for CONFIG_SMP */ 15#include <linux/autoconf.h> /* for CONFIG_SMP */
16 16
17#include <asm/offsets.h> 17#include <asm/asm-offsets.h>
18#include <asm/psw.h> 18#include <asm/psw.h>
19#include <asm/pdc.h> 19#include <asm/pdc.h>
20 20
diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c
index 4fc04501d5..46b7593851 100644
--- a/arch/parisc/kernel/process.c
+++ b/arch/parisc/kernel/process.c
@@ -47,7 +47,7 @@
47#include <linux/kallsyms.h> 47#include <linux/kallsyms.h>
48 48
49#include <asm/io.h> 49#include <asm/io.h>
50#include <asm/offsets.h> 50#include <asm/asm-offsets.h>
51#include <asm/pdc.h> 51#include <asm/pdc.h>
52#include <asm/pdc_chassis.h> 52#include <asm/pdc_chassis.h>
53#include <asm/pgalloc.h> 53#include <asm/pgalloc.h>
diff --git a/arch/parisc/kernel/ptrace.c b/arch/parisc/kernel/ptrace.c
index c07db9dff7..f3428e5e86 100644
--- a/arch/parisc/kernel/ptrace.c
+++ b/arch/parisc/kernel/ptrace.c
@@ -23,7 +23,7 @@
23#include <asm/pgtable.h> 23#include <asm/pgtable.h>
24#include <asm/system.h> 24#include <asm/system.h>
25#include <asm/processor.h> 25#include <asm/processor.h>
26#include <asm/offsets.h> 26#include <asm/asm-offsets.h>
27 27
28/* PSW bits we allow the debugger to modify */ 28/* PSW bits we allow the debugger to modify */
29#define USER_PSW_BITS (PSW_N | PSW_V | PSW_CB) 29#define USER_PSW_BITS (PSW_N | PSW_V | PSW_CB)
diff --git a/arch/parisc/kernel/signal.c b/arch/parisc/kernel/signal.c
index 55d71c15e1..0224651fd8 100644
--- a/arch/parisc/kernel/signal.c
+++ b/arch/parisc/kernel/signal.c
@@ -32,7 +32,7 @@
32#include <asm/uaccess.h> 32#include <asm/uaccess.h>
33#include <asm/pgalloc.h> 33#include <asm/pgalloc.h>
34#include <asm/cacheflush.h> 34#include <asm/cacheflush.h>
35#include <asm/offsets.h> 35#include <asm/asm-offsets.h>
36 36
37#ifdef CONFIG_COMPAT 37#ifdef CONFIG_COMPAT
38#include <linux/compat.h> 38#include <linux/compat.h>
diff --git a/arch/parisc/kernel/syscall.S b/arch/parisc/kernel/syscall.S
index 32ea701f4d..8c7a7185cd 100644
--- a/arch/parisc/kernel/syscall.S
+++ b/arch/parisc/kernel/syscall.S
@@ -7,7 +7,7 @@
7 * sorry about the wall, puffin.. 7 * sorry about the wall, puffin..
8 */ 8 */
9 9
10#include <asm/offsets.h> 10#include <asm/asm-offsets.h>
11#include <asm/unistd.h> 11#include <asm/unistd.h>
12#include <asm/errno.h> 12#include <asm/errno.h>
13#include <asm/psw.h> 13#include <asm/psw.h>
diff --git a/arch/parisc/lib/Makefile b/arch/parisc/lib/Makefile
index 7bf7056762..5f2e6904d1 100644
--- a/arch/parisc/lib/Makefile
+++ b/arch/parisc/lib/Makefile
@@ -5,5 +5,3 @@
5lib-y := lusercopy.o bitops.o checksum.o io.o memset.o fixup.o memcpy.o 5lib-y := lusercopy.o bitops.o checksum.o io.o memset.o fixup.o memcpy.o
6 6
7obj-y := iomap.o 7obj-y := iomap.o
8
9lib-$(CONFIG_SMP) += debuglocks.o
diff --git a/arch/parisc/lib/bitops.c b/arch/parisc/lib/bitops.c
index 2de182f6fe..90f400b102 100644
--- a/arch/parisc/lib/bitops.c
+++ b/arch/parisc/lib/bitops.c
@@ -13,8 +13,8 @@
13#include <asm/atomic.h> 13#include <asm/atomic.h>
14 14
15#ifdef CONFIG_SMP 15#ifdef CONFIG_SMP
16spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned = { 16raw_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned = {
17 [0 ... (ATOMIC_HASH_SIZE-1)] = SPIN_LOCK_UNLOCKED 17 [0 ... (ATOMIC_HASH_SIZE-1)] = __RAW_SPIN_LOCK_UNLOCKED
18}; 18};
19#endif 19#endif
20 20
diff --git a/arch/parisc/lib/debuglocks.c b/arch/parisc/lib/debuglocks.c
deleted file mode 100644
index 1b33fe6e5b..0000000000
--- a/arch/parisc/lib/debuglocks.c
+++ /dev/null
@@ -1,277 +0,0 @@
1/*
2 * Debugging versions of SMP locking primitives.
3 *
4 * Copyright (C) 2004 Thibaut VARENE <varenet@parisc-linux.org>
5 *
6 * Some code stollen from alpha & sparc64 ;)
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 * We use pdc_printf() throughout the file for all output messages, to avoid
23 * losing messages because of disabled interrupts. Since we're using these
24 * messages for debugging purposes, it makes sense not to send them to the
25 * linux console.
26 */
27
28
29#include <linux/config.h>
30#include <linux/kernel.h>
31#include <linux/sched.h>
32#include <linux/spinlock.h>
33#include <linux/hardirq.h> /* in_interrupt() */
34#include <asm/system.h>
35#include <asm/hardirq.h> /* in_interrupt() */
36#include <asm/pdc.h>
37
38#undef INIT_STUCK
39#define INIT_STUCK 1L << 30
40
41#ifdef CONFIG_DEBUG_SPINLOCK
42
43
44void _dbg_spin_lock(spinlock_t * lock, const char *base_file, int line_no)
45{
46 volatile unsigned int *a;
47 long stuck = INIT_STUCK;
48 void *inline_pc = __builtin_return_address(0);
49 unsigned long started = jiffies;
50 int printed = 0;
51 int cpu = smp_processor_id();
52
53try_again:
54
55 /* Do the actual locking */
56 /* <T-Bone> ggg: we can't get stuck on the outter loop?
57 * <ggg> T-Bone: We can hit the outer loop
58 * alot if multiple CPUs are constantly racing for a lock
59 * and the backplane is NOT fair about which CPU sees
60 * the update first. But it won't hang since every failed
61 * attempt will drop us back into the inner loop and
62 * decrement `stuck'.
63 * <ggg> K-class and some of the others are NOT fair in the HW
64 * implementation so we could see false positives.
65 * But fixing the lock contention is easier than
66 * fixing the HW to be fair.
67 * <tausq> __ldcw() returns 1 if we get the lock; otherwise we
68 * spin until the value of the lock changes, or we time out.
69 */
70 mb();
71 a = __ldcw_align(lock);
72 while (stuck && (__ldcw(a) == 0))
73 while ((*a == 0) && --stuck);
74 mb();
75
76 if (unlikely(stuck <= 0)) {
77 pdc_printf(
78 "%s:%d: spin_lock(%s/%p) stuck in %s at %p(%d)"
79 " owned by %s:%d in %s at %p(%d)\n",
80 base_file, line_no, lock->module, lock,
81 current->comm, inline_pc, cpu,
82 lock->bfile, lock->bline, lock->task->comm,
83 lock->previous, lock->oncpu);
84 stuck = INIT_STUCK;
85 printed = 1;
86 goto try_again;
87 }
88
89 /* Exiting. Got the lock. */
90 lock->oncpu = cpu;
91 lock->previous = inline_pc;
92 lock->task = current;
93 lock->bfile = (char *)base_file;
94 lock->bline = line_no;
95
96 if (unlikely(printed)) {
97 pdc_printf(
98 "%s:%d: spin_lock grabbed in %s at %p(%d) %ld ticks\n",
99 base_file, line_no, current->comm, inline_pc,
100 cpu, jiffies - started);
101 }
102}
103
104void _dbg_spin_unlock(spinlock_t * lock, const char *base_file, int line_no)
105{
106 CHECK_LOCK(lock);
107 volatile unsigned int *a;
108 mb();
109 a = __ldcw_align(lock);
110 if (unlikely((*a != 0) && lock->babble)) {
111 lock->babble--;
112 pdc_printf(
113 "%s:%d: spin_unlock(%s:%p) not locked\n",
114 base_file, line_no, lock->module, lock);
115 }
116 *a = 1;
117 mb();
118}
119
120int _dbg_spin_trylock(spinlock_t * lock, const char *base_file, int line_no)
121{
122 int ret;
123 volatile unsigned int *a;
124 mb();
125 a = __ldcw_align(lock);
126 ret = (__ldcw(a) != 0);
127 mb();
128 if (ret) {
129 lock->oncpu = smp_processor_id();
130 lock->previous = __builtin_return_address(0);
131 lock->task = current;
132 } else {
133 lock->bfile = (char *)base_file;
134 lock->bline = line_no;
135 }
136 return ret;
137}
138
139#endif /* CONFIG_DEBUG_SPINLOCK */
140
141#ifdef CONFIG_DEBUG_RWLOCK
142
143/* Interrupts trouble detailed explanation, thx Grant:
144 *
145 * o writer (wants to modify data) attempts to acquire the rwlock
146 * o He gets the write lock.
147 * o Interupts are still enabled, we take an interrupt with the
148 * write still holding the lock.
149 * o interrupt handler tries to acquire the rwlock for read.
150 * o deadlock since the writer can't release it at this point.
151 *
152 * In general, any use of spinlocks that competes between "base"
153 * level and interrupt level code will risk deadlock. Interrupts
154 * need to be disabled in the base level routines to avoid it.
155 * Or more precisely, only the IRQ the base level routine
156 * is competing with for the lock. But it's more efficient/faster
157 * to just disable all interrupts on that CPU to guarantee
158 * once it gets the lock it can release it quickly too.
159 */
160
161void _dbg_write_lock(rwlock_t *rw, const char *bfile, int bline)
162{
163 void *inline_pc = __builtin_return_address(0);
164 unsigned long started = jiffies;
165 long stuck = INIT_STUCK;
166 int printed = 0;
167 int cpu = smp_processor_id();
168
169 if(unlikely(in_interrupt())) { /* acquiring write lock in interrupt context, bad idea */
170 pdc_printf("write_lock caller: %s:%d, IRQs enabled,\n", bfile, bline);
171 BUG();
172 }
173
174 /* Note: if interrupts are disabled (which is most likely), the printk
175 will never show on the console. We might need a polling method to flush
176 the dmesg buffer anyhow. */
177
178retry:
179 _raw_spin_lock(&rw->lock);
180
181 if(rw->counter != 0) {
182 /* this basically never happens */
183 _raw_spin_unlock(&rw->lock);
184
185 stuck--;
186 if ((unlikely(stuck <= 0)) && (rw->counter < 0)) {
187 pdc_printf(
188 "%s:%d: write_lock stuck on writer"
189 " in %s at %p(%d) %ld ticks\n",
190 bfile, bline, current->comm, inline_pc,
191 cpu, jiffies - started);
192 stuck = INIT_STUCK;
193 printed = 1;
194 }
195 else if (unlikely(stuck <= 0)) {
196 pdc_printf(
197 "%s:%d: write_lock stuck on reader"
198 " in %s at %p(%d) %ld ticks\n",
199 bfile, bline, current->comm, inline_pc,
200 cpu, jiffies - started);
201 stuck = INIT_STUCK;
202 printed = 1;
203 }
204
205 while(rw->counter != 0);
206
207 goto retry;
208 }
209
210 /* got it. now leave without unlocking */
211 rw->counter = -1; /* remember we are locked */
212
213 if (unlikely(printed)) {
214 pdc_printf(
215 "%s:%d: write_lock grabbed in %s at %p(%d) %ld ticks\n",
216 bfile, bline, current->comm, inline_pc,
217 cpu, jiffies - started);
218 }
219}
220
221int _dbg_write_trylock(rwlock_t *rw, const char *bfile, int bline)
222{
223#if 0
224 void *inline_pc = __builtin_return_address(0);
225 int cpu = smp_processor_id();
226#endif
227
228 if(unlikely(in_interrupt())) { /* acquiring write lock in interrupt context, bad idea */
229 pdc_printf("write_lock caller: %s:%d, IRQs enabled,\n", bfile, bline);
230 BUG();
231 }
232
233 /* Note: if interrupts are disabled (which is most likely), the printk
234 will never show on the console. We might need a polling method to flush
235 the dmesg buffer anyhow. */
236
237 _raw_spin_lock(&rw->lock);
238
239 if(rw->counter != 0) {
240 /* this basically never happens */
241 _raw_spin_unlock(&rw->lock);
242 return 0;
243 }
244
245 /* got it. now leave without unlocking */
246 rw->counter = -1; /* remember we are locked */
247#if 0
248 pdc_printf("%s:%d: try write_lock grabbed in %s at %p(%d)\n",
249 bfile, bline, current->comm, inline_pc, cpu);
250#endif
251 return 1;
252}
253
254void _dbg_read_lock(rwlock_t * rw, const char *bfile, int bline)
255{
256#if 0
257 void *inline_pc = __builtin_return_address(0);
258 unsigned long started = jiffies;
259 int cpu = smp_processor_id();
260#endif
261 unsigned long flags;
262
263 local_irq_save(flags);
264 _raw_spin_lock(&rw->lock);
265
266 rw->counter++;
267#if 0
268 pdc_printf(
269 "%s:%d: read_lock grabbed in %s at %p(%d) %ld ticks\n",
270 bfile, bline, current->comm, inline_pc,
271 cpu, jiffies - started);
272#endif
273 _raw_spin_unlock(&rw->lock);
274 local_irq_restore(flags);
275}
276
277#endif /* CONFIG_DEBUG_RWLOCK */
diff --git a/arch/parisc/lib/fixup.S b/arch/parisc/lib/fixup.S
index 134f0cd240..1b91612ed9 100644
--- a/arch/parisc/lib/fixup.S
+++ b/arch/parisc/lib/fixup.S
@@ -20,7 +20,7 @@
20 * Fixup routines for kernel exception handling. 20 * Fixup routines for kernel exception handling.
21 */ 21 */
22#include <linux/config.h> 22#include <linux/config.h>
23#include <asm/offsets.h> 23#include <asm/asm-offsets.h>
24#include <asm/assembly.h> 24#include <asm/assembly.h>
25#include <asm/errno.h> 25#include <asm/errno.h>
26 26
diff --git a/arch/ppc/8xx_io/cs4218_tdm.c b/arch/ppc/8xx_io/cs4218_tdm.c
index 89fe0ceeaa..2ca9ec7ec3 100644
--- a/arch/ppc/8xx_io/cs4218_tdm.c
+++ b/arch/ppc/8xx_io/cs4218_tdm.c
@@ -1380,7 +1380,7 @@ static void cs_nosound(unsigned long xx)
1380 spin_unlock_irqrestore(&cs4218_lock, flags); 1380 spin_unlock_irqrestore(&cs4218_lock, flags);
1381} 1381}
1382 1382
1383static struct timer_list beep_timer = TIMER_INITIALIZER(cs_nosound, 0, 0); 1383static DEFINE_TIMER(beep_timer, cs_nosound, 0, 0);
1384}; 1384};
1385 1385
1386static void cs_mksound(unsigned int hz, unsigned int ticks) 1386static void cs_mksound(unsigned int hz, unsigned int ticks)
diff --git a/arch/ppc/Kconfig b/arch/ppc/Kconfig
index 6ab7e5ea5f..347ea28414 100644
--- a/arch/ppc/Kconfig
+++ b/arch/ppc/Kconfig
@@ -265,6 +265,15 @@ config PPC601_SYNC_FIX
265 265
266 If in doubt, say Y here. 266 If in doubt, say Y here.
267 267
268config HOTPLUG_CPU
269 bool "Support for enabling/disabling CPUs"
270 depends on SMP && HOTPLUG && EXPERIMENTAL && PPC_PMAC
271 ---help---
272 Say Y here to be able to disable and re-enable individual
273 CPUs at runtime on SMP machines.
274
275 Say N if you are unsure.
276
268source arch/ppc/platforms/4xx/Kconfig 277source arch/ppc/platforms/4xx/Kconfig
269source arch/ppc/platforms/85xx/Kconfig 278source arch/ppc/platforms/85xx/Kconfig
270 279
@@ -499,11 +508,6 @@ config WINCEPT
499 MPC821 PowerPC, introduced in 1998 and designed to be used in 508 MPC821 PowerPC, introduced in 1998 and designed to be used in
500 thin-client machines. Say Y to support it directly. 509 thin-client machines. Say Y to support it directly.
501 510
502 Be aware that PCI buses can only function when SYS board is plugged
503 into the PIB (Platform IO Board) board from Freescale which provide
504 3 PCI slots. The PIBs PCI initialization is the bootloader's
505 responsiblilty.
506
507endchoice 511endchoice
508 512
509choice 513choice
@@ -680,6 +684,11 @@ config MPC834x_SYS
680 help 684 help
681 This option enables support for the MPC 834x SYS evaluation board. 685 This option enables support for the MPC 834x SYS evaluation board.
682 686
687 Be aware that PCI buses can only function when SYS board is plugged
688 into the PIB (Platform IO Board) board from Freescale which provide
689 3 PCI slots. The PIBs PCI initialization is the bootloader's
690 responsiblilty.
691
683config EV64360 692config EV64360
684 bool "Marvell-EV64360BP" 693 bool "Marvell-EV64360BP"
685 help 694 help
diff --git a/arch/ppc/Makefile b/arch/ppc/Makefile
index d1b6e6dcb5..16e2675f32 100644
--- a/arch/ppc/Makefile
+++ b/arch/ppc/Makefile
@@ -21,13 +21,14 @@ CC := $(CC) -m32
21endif 21endif
22 22
23LDFLAGS_vmlinux := -Ttext $(KERNELLOAD) -Bstatic 23LDFLAGS_vmlinux := -Ttext $(KERNELLOAD) -Bstatic
24CPPFLAGS += -Iarch/$(ARCH) -Iinclude3 24# The -Iarch/$(ARCH)/include is temporary while we are merging
25CPPFLAGS += -Iarch/$(ARCH) -Iarch/$(ARCH)/include
25AFLAGS += -Iarch/$(ARCH) 26AFLAGS += -Iarch/$(ARCH)
26CFLAGS += -Iarch/$(ARCH) -msoft-float -pipe \ 27CFLAGS += -Iarch/$(ARCH) -msoft-float -pipe \
27 -ffixed-r2 -mmultiple 28 -ffixed-r2 -mmultiple
28CPP = $(CC) -E $(CFLAGS) 29CPP = $(CC) -E $(CFLAGS)
29# Temporary hack until we have migrated to asm-powerpc 30# Temporary hack until we have migrated to asm-powerpc
30LINUXINCLUDE += -Iinclude3 31LINUXINCLUDE += -Iarch/$(ARCH)/include
31 32
32CHECKFLAGS += -D__powerpc__ 33CHECKFLAGS += -D__powerpc__
33 34
@@ -103,21 +104,16 @@ endef
103 104
104archclean: 105archclean:
105 $(Q)$(MAKE) $(clean)=arch/ppc/boot 106 $(Q)$(MAKE) $(clean)=arch/ppc/boot
106 $(Q)rm -rf include3 107 # Temporary hack until we have migrated to asm-powerpc
108 $(Q)rm -rf arch/$(ARCH)/include
107 109
108prepare: include/asm-$(ARCH)/offsets.h checkbin 110archprepare: checkbin
109
110arch/$(ARCH)/kernel/asm-offsets.s: include/asm include/linux/version.h \
111 include/config/MARKER
112
113include/asm-$(ARCH)/offsets.h: arch/$(ARCH)/kernel/asm-offsets.s
114 $(call filechk,gen-asm-offsets)
115 111
116# Temporary hack until we have migrated to asm-powerpc 112# Temporary hack until we have migrated to asm-powerpc
117include/asm: include3/asm 113include/asm: arch/$(ARCH)/include/asm
118include3/asm: 114arch/$(ARCH)/include/asm:
119 $(Q)if [ ! -d include3 ]; then mkdir -p include3; fi 115 $(Q)if [ ! -d arch/$(ARCH)/include ]; then mkdir -p arch/$(ARCH)/include; fi
120 $(Q)ln -fsn $(srctree)/include/asm-powerpc include3/asm 116 $(Q)ln -fsn $(srctree)/include/asm-powerpc arch/$(ARCH)/include/asm
121 117
122# Use the file '.tmp_gas_check' for binutils tests, as gas won't output 118# Use the file '.tmp_gas_check' for binutils tests, as gas won't output
123# to stdout and these checks are run even on install targets. 119# to stdout and these checks are run even on install targets.
@@ -143,7 +139,5 @@ checkbin:
143 false ; \ 139 false ; \
144 fi 140 fi
145 141
146CLEAN_FILES += include/asm-$(ARCH)/offsets.h \ 142CLEAN_FILES += $(TOUT)
147 arch/$(ARCH)/kernel/asm-offsets.s \
148 $(TOUT)
149 143
diff --git a/arch/ppc/boot/common/ns16550.c b/arch/ppc/boot/common/ns16550.c
index 9017c547a6..26818bbb6c 100644
--- a/arch/ppc/boot/common/ns16550.c
+++ b/arch/ppc/boot/common/ns16550.c
@@ -23,7 +23,7 @@ static int shift;
23 23
24unsigned long serial_init(int chan, void *ignored) 24unsigned long serial_init(int chan, void *ignored)
25{ 25{
26 unsigned long com_port; 26 unsigned long com_port, base_baud;
27 unsigned char lcr, dlm; 27 unsigned char lcr, dlm;
28 28
29 /* We need to find out which type io we're expecting. If it's 29 /* We need to find out which type io we're expecting. If it's
@@ -43,6 +43,8 @@ unsigned long serial_init(int chan, void *ignored)
43 43
44 /* How far apart the registers are. */ 44 /* How far apart the registers are. */
45 shift = rs_table[chan].iomem_reg_shift; 45 shift = rs_table[chan].iomem_reg_shift;
46 /* Base baud.. */
47 base_baud = rs_table[chan].baud_base;
46 48
47 /* save the LCR */ 49 /* save the LCR */
48 lcr = inb(com_port + (UART_LCR << shift)); 50 lcr = inb(com_port + (UART_LCR << shift));
@@ -62,9 +64,9 @@ unsigned long serial_init(int chan, void *ignored)
62 else { 64 else {
63 /* Input clock. */ 65 /* Input clock. */
64 outb(com_port + (UART_DLL << shift), 66 outb(com_port + (UART_DLL << shift),
65 (BASE_BAUD / SERIAL_BAUD) & 0xFF); 67 (base_baud / SERIAL_BAUD) & 0xFF);
66 outb(com_port + (UART_DLM << shift), 68 outb(com_port + (UART_DLM << shift),
67 (BASE_BAUD / SERIAL_BAUD) >> 8); 69 (base_baud / SERIAL_BAUD) >> 8);
68 /* 8 data, 1 stop, no parity */ 70 /* 8 data, 1 stop, no parity */
69 outb(com_port + (UART_LCR << shift), 0x03); 71 outb(com_port + (UART_LCR << shift), 0x03);
70 /* RTS/DTR */ 72 /* RTS/DTR */
diff --git a/arch/ppc/boot/common/util.S b/arch/ppc/boot/common/util.S
index 47e641455b..c96c9f8052 100644
--- a/arch/ppc/boot/common/util.S
+++ b/arch/ppc/boot/common/util.S
@@ -252,7 +252,7 @@ _GLOBAL(flush_instruction_cache)
2521: dcbf r0,r3 # Flush the data cache 2521: dcbf r0,r3 # Flush the data cache
253 icbi r0,r3 # Invalidate the instruction cache 253 icbi r0,r3 # Invalidate the instruction cache
254 addi r3,r3,0x10 # Increment by one cache line 254 addi r3,r3,0x10 # Increment by one cache line
255 cmplwi cr0,r3,r4 # Are we at the end yet? 255 cmplw cr0,r3,r4 # Are we at the end yet?
256 blt 1b # No, keep flushing and invalidating 256 blt 1b # No, keep flushing and invalidating
257#else 257#else
258 /* Enable, invalidate and then disable the L1 icache/dcache. */ 258 /* Enable, invalidate and then disable the L1 icache/dcache. */
diff --git a/arch/ppc/kernel/Makefile b/arch/ppc/kernel/Makefile
index b1457a8a9c..1fb92f16ac 100644
--- a/arch/ppc/kernel/Makefile
+++ b/arch/ppc/kernel/Makefile
@@ -15,8 +15,9 @@ extra-y += vmlinux.lds
15obj-y := entry.o traps.o irq.o idle.o time.o misc.o \ 15obj-y := entry.o traps.o irq.o idle.o time.o misc.o \
16 process.o signal.o ptrace.o align.o \ 16 process.o signal.o ptrace.o align.o \
17 semaphore.o syscalls.o setup.o \ 17 semaphore.o syscalls.o setup.o \
18 cputable.o ppc_htab.o perfmon.o 18 cputable.o ppc_htab.o
19obj-$(CONFIG_6xx) += l2cr.o cpu_setup_6xx.o 19obj-$(CONFIG_6xx) += l2cr.o cpu_setup_6xx.o
20obj-$(CONFIG_E500) += perfmon.o
20obj-$(CONFIG_SOFTWARE_SUSPEND) += swsusp.o 21obj-$(CONFIG_SOFTWARE_SUSPEND) += swsusp.o
21obj-$(CONFIG_POWER4) += cpu_setup_power4.o 22obj-$(CONFIG_POWER4) += cpu_setup_power4.o
22obj-$(CONFIG_MODULES) += module.o ppc_ksyms.o 23obj-$(CONFIG_MODULES) += module.o ppc_ksyms.o
diff --git a/arch/ppc/kernel/cpu_setup_6xx.S b/arch/ppc/kernel/cpu_setup_6xx.S
index bd037caa40..ba396438ed 100644
--- a/arch/ppc/kernel/cpu_setup_6xx.S
+++ b/arch/ppc/kernel/cpu_setup_6xx.S
@@ -12,10 +12,9 @@
12#include <linux/config.h> 12#include <linux/config.h>
13#include <asm/processor.h> 13#include <asm/processor.h>
14#include <asm/page.h> 14#include <asm/page.h>
15#include <asm/ppc_asm.h>
16#include <asm/cputable.h> 15#include <asm/cputable.h>
17#include <asm/ppc_asm.h> 16#include <asm/ppc_asm.h>
18#include <asm/offsets.h> 17#include <asm/asm-offsets.h>
19#include <asm/cache.h> 18#include <asm/cache.h>
20 19
21_GLOBAL(__setup_cpu_601) 20_GLOBAL(__setup_cpu_601)
diff --git a/arch/ppc/kernel/cpu_setup_power4.S b/arch/ppc/kernel/cpu_setup_power4.S
index f2ea1a990f..7e4fbb6537 100644
--- a/arch/ppc/kernel/cpu_setup_power4.S
+++ b/arch/ppc/kernel/cpu_setup_power4.S
@@ -14,8 +14,7 @@
14#include <asm/page.h> 14#include <asm/page.h>
15#include <asm/ppc_asm.h> 15#include <asm/ppc_asm.h>
16#include <asm/cputable.h> 16#include <asm/cputable.h>
17#include <asm/ppc_asm.h> 17#include <asm/asm-offsets.h>
18#include <asm/offsets.h>
19#include <asm/cache.h> 18#include <asm/cache.h>
20 19
21_GLOBAL(__970_cpu_preinit) 20_GLOBAL(__970_cpu_preinit)
diff --git a/arch/ppc/kernel/dma-mapping.c b/arch/ppc/kernel/dma-mapping.c
index e0c631cf96..b566d98280 100644
--- a/arch/ppc/kernel/dma-mapping.c
+++ b/arch/ppc/kernel/dma-mapping.c
@@ -393,7 +393,7 @@ EXPORT_SYMBOL(__dma_sync);
393 * __dma_sync_page() implementation for systems using highmem. 393 * __dma_sync_page() implementation for systems using highmem.
394 * In this case, each page of a buffer must be kmapped/kunmapped 394 * In this case, each page of a buffer must be kmapped/kunmapped
395 * in order to have a virtual address for __dma_sync(). This must 395 * in order to have a virtual address for __dma_sync(). This must
396 * not sleep so kmap_atmomic()/kunmap_atomic() are used. 396 * not sleep so kmap_atomic()/kunmap_atomic() are used.
397 * 397 *
398 * Note: yes, it is possible and correct to have a buffer extend 398 * Note: yes, it is possible and correct to have a buffer extend
399 * beyond the first page. 399 * beyond the first page.
diff --git a/arch/ppc/kernel/entry.S b/arch/ppc/kernel/entry.S
index cb83045e2e..03d4886869 100644
--- a/arch/ppc/kernel/entry.S
+++ b/arch/ppc/kernel/entry.S
@@ -29,7 +29,7 @@
29#include <asm/cputable.h> 29#include <asm/cputable.h>
30#include <asm/thread_info.h> 30#include <asm/thread_info.h>
31#include <asm/ppc_asm.h> 31#include <asm/ppc_asm.h>
32#include <asm/offsets.h> 32#include <asm/asm-offsets.h>
33#include <asm/unistd.h> 33#include <asm/unistd.h>
34 34
35#undef SHOW_SYSCALLS 35#undef SHOW_SYSCALLS
diff --git a/arch/ppc/kernel/fpu.S b/arch/ppc/kernel/fpu.S
index 6189b26f64..665d7d3430 100644
--- a/arch/ppc/kernel/fpu.S
+++ b/arch/ppc/kernel/fpu.S
@@ -18,7 +18,7 @@
18#include <asm/cache.h> 18#include <asm/cache.h>
19#include <asm/thread_info.h> 19#include <asm/thread_info.h>
20#include <asm/ppc_asm.h> 20#include <asm/ppc_asm.h>
21#include <asm/offsets.h> 21#include <asm/asm-offsets.h>
22 22
23/* 23/*
24 * This task wants to use the FPU now. 24 * This task wants to use the FPU now.
diff --git a/arch/ppc/kernel/head.S b/arch/ppc/kernel/head.S
index a931d77371..1960fb8c25 100644
--- a/arch/ppc/kernel/head.S
+++ b/arch/ppc/kernel/head.S
@@ -31,7 +31,7 @@
31#include <asm/cache.h> 31#include <asm/cache.h>
32#include <asm/thread_info.h> 32#include <asm/thread_info.h>
33#include <asm/ppc_asm.h> 33#include <asm/ppc_asm.h>
34#include <asm/offsets.h> 34#include <asm/asm-offsets.h>
35 35
36#ifdef CONFIG_APUS 36#ifdef CONFIG_APUS
37#include <asm/amigappc.h> 37#include <asm/amigappc.h>
@@ -1023,23 +1023,21 @@ __secondary_start_gemini:
1023 andc r4,r4,r3 1023 andc r4,r4,r3
1024 mtspr SPRN_HID0,r4 1024 mtspr SPRN_HID0,r4
1025 sync 1025 sync
1026 bl gemini_prom_init
1027 b __secondary_start 1026 b __secondary_start
1028#endif /* CONFIG_GEMINI */ 1027#endif /* CONFIG_GEMINI */
1029 .globl __secondary_start_psurge 1028
1030__secondary_start_psurge: 1029 .globl __secondary_start_pmac_0
1031 li r24,1 /* cpu # */ 1030__secondary_start_pmac_0:
1032 b __secondary_start_psurge99 1031 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1033 .globl __secondary_start_psurge2 1032 li r24,0
1034__secondary_start_psurge2: 1033 b 1f
1035 li r24,2 /* cpu # */ 1034 li r24,1
1036 b __secondary_start_psurge99 1035 b 1f
1037 .globl __secondary_start_psurge3 1036 li r24,2
1038__secondary_start_psurge3: 1037 b 1f
1039 li r24,3 /* cpu # */ 1038 li r24,3
1040 b __secondary_start_psurge99 10391:
1041__secondary_start_psurge99: 1040 /* on powersurge, we come in here with IR=0 and DR=1, and DBAT 0
1042 /* we come in here with IR=0 and DR=1, and DBAT 0
1043 set to map the 0xf0000000 - 0xffffffff region */ 1041 set to map the 0xf0000000 - 0xffffffff region */
1044 mfmsr r0 1042 mfmsr r0
1045 rlwinm r0,r0,0,28,26 /* clear DR (0x10) */ 1043 rlwinm r0,r0,0,28,26 /* clear DR (0x10) */
diff --git a/arch/ppc/kernel/head_44x.S b/arch/ppc/kernel/head_44x.S
index 9e68e32edb..599245b040 100644
--- a/arch/ppc/kernel/head_44x.S
+++ b/arch/ppc/kernel/head_44x.S
@@ -40,7 +40,7 @@
40#include <asm/cputable.h> 40#include <asm/cputable.h>
41#include <asm/thread_info.h> 41#include <asm/thread_info.h>
42#include <asm/ppc_asm.h> 42#include <asm/ppc_asm.h>
43#include <asm/offsets.h> 43#include <asm/asm-offsets.h>
44#include "head_booke.h" 44#include "head_booke.h"
45 45
46 46
diff --git a/arch/ppc/kernel/head_4xx.S b/arch/ppc/kernel/head_4xx.S
index ca9518b96c..8562b807b3 100644
--- a/arch/ppc/kernel/head_4xx.S
+++ b/arch/ppc/kernel/head_4xx.S
@@ -40,7 +40,7 @@
40#include <asm/cputable.h> 40#include <asm/cputable.h>
41#include <asm/thread_info.h> 41#include <asm/thread_info.h>
42#include <asm/ppc_asm.h> 42#include <asm/ppc_asm.h>
43#include <asm/offsets.h> 43#include <asm/asm-offsets.h>
44 44
45/* As with the other PowerPC ports, it is expected that when code 45/* As with the other PowerPC ports, it is expected that when code
46 * execution begins here, the following registers contain valid, yet 46 * execution begins here, the following registers contain valid, yet
diff --git a/arch/ppc/kernel/head_8xx.S b/arch/ppc/kernel/head_8xx.S
index eb18cadb37..cb1a3a54a0 100644
--- a/arch/ppc/kernel/head_8xx.S
+++ b/arch/ppc/kernel/head_8xx.S
@@ -30,7 +30,7 @@
30#include <asm/cputable.h> 30#include <asm/cputable.h>
31#include <asm/thread_info.h> 31#include <asm/thread_info.h>
32#include <asm/ppc_asm.h> 32#include <asm/ppc_asm.h>
33#include <asm/offsets.h> 33#include <asm/asm-offsets.h>
34 34
35/* Macro to make the code more readable. */ 35/* Macro to make the code more readable. */
36#ifdef CONFIG_8xx_CPU6 36#ifdef CONFIG_8xx_CPU6
diff --git a/arch/ppc/kernel/head_fsl_booke.S b/arch/ppc/kernel/head_fsl_booke.S
index 4028f4c7d9..8e52e84083 100644
--- a/arch/ppc/kernel/head_fsl_booke.S
+++ b/arch/ppc/kernel/head_fsl_booke.S
@@ -41,7 +41,7 @@
41#include <asm/cputable.h> 41#include <asm/cputable.h>
42#include <asm/thread_info.h> 42#include <asm/thread_info.h>
43#include <asm/ppc_asm.h> 43#include <asm/ppc_asm.h>
44#include <asm/offsets.h> 44#include <asm/asm-offsets.h>
45#include "head_booke.h" 45#include "head_booke.h"
46 46
47/* As with the other PowerPC ports, it is expected that when code 47/* As with the other PowerPC ports, it is expected that when code
diff --git a/arch/ppc/kernel/idle.c b/arch/ppc/kernel/idle.c
index 53547b6de4..fba29c876b 100644
--- a/arch/ppc/kernel/idle.c
+++ b/arch/ppc/kernel/idle.c
@@ -22,6 +22,7 @@
22#include <linux/ptrace.h> 22#include <linux/ptrace.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/sysctl.h> 24#include <linux/sysctl.h>
25#include <linux/cpu.h>
25 26
26#include <asm/pgtable.h> 27#include <asm/pgtable.h>
27#include <asm/uaccess.h> 28#include <asm/uaccess.h>
@@ -35,6 +36,7 @@
35void default_idle(void) 36void default_idle(void)
36{ 37{
37 void (*powersave)(void); 38 void (*powersave)(void);
39 int cpu = smp_processor_id();
38 40
39 powersave = ppc_md.power_save; 41 powersave = ppc_md.power_save;
40 42
@@ -44,7 +46,7 @@ void default_idle(void)
44#ifdef CONFIG_SMP 46#ifdef CONFIG_SMP
45 else { 47 else {
46 set_thread_flag(TIF_POLLING_NRFLAG); 48 set_thread_flag(TIF_POLLING_NRFLAG);
47 while (!need_resched()) 49 while (!need_resched() && !cpu_is_offline(cpu))
48 barrier(); 50 barrier();
49 clear_thread_flag(TIF_POLLING_NRFLAG); 51 clear_thread_flag(TIF_POLLING_NRFLAG);
50 } 52 }
@@ -52,6 +54,8 @@ void default_idle(void)
52 } 54 }
53 if (need_resched()) 55 if (need_resched())
54 schedule(); 56 schedule();
57 if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING)
58 cpu_die();
55} 59}
56 60
57/* 61/*
diff --git a/arch/ppc/kernel/idle_6xx.S b/arch/ppc/kernel/idle_6xx.S
index 25d009c75f..1a2194cf68 100644
--- a/arch/ppc/kernel/idle_6xx.S
+++ b/arch/ppc/kernel/idle_6xx.S
@@ -20,7 +20,7 @@
20#include <asm/cputable.h> 20#include <asm/cputable.h>
21#include <asm/thread_info.h> 21#include <asm/thread_info.h>
22#include <asm/ppc_asm.h> 22#include <asm/ppc_asm.h>
23#include <asm/offsets.h> 23#include <asm/asm-offsets.h>
24 24
25#undef DEBUG 25#undef DEBUG
26 26
diff --git a/arch/ppc/kernel/idle_power4.S b/arch/ppc/kernel/idle_power4.S
index 73a58ff039..cc0d535365 100644
--- a/arch/ppc/kernel/idle_power4.S
+++ b/arch/ppc/kernel/idle_power4.S
@@ -20,7 +20,7 @@
20#include <asm/cputable.h> 20#include <asm/cputable.h>
21#include <asm/thread_info.h> 21#include <asm/thread_info.h>
22#include <asm/ppc_asm.h> 22#include <asm/ppc_asm.h>
23#include <asm/offsets.h> 23#include <asm/asm-offsets.h>
24 24
25#undef DEBUG 25#undef DEBUG
26 26
diff --git a/arch/ppc/kernel/misc.S b/arch/ppc/kernel/misc.S
index ce71b4a015..90d917d2e8 100644
--- a/arch/ppc/kernel/misc.S
+++ b/arch/ppc/kernel/misc.S
@@ -23,7 +23,7 @@
23#include <asm/mmu.h> 23#include <asm/mmu.h>
24#include <asm/ppc_asm.h> 24#include <asm/ppc_asm.h>
25#include <asm/thread_info.h> 25#include <asm/thread_info.h>
26#include <asm/offsets.h> 26#include <asm/asm-offsets.h>
27 27
28 .text 28 .text
29 29
diff --git a/arch/ppc/kernel/smp.c b/arch/ppc/kernel/smp.c
index e70b587b9e..726fe7ce17 100644
--- a/arch/ppc/kernel/smp.c
+++ b/arch/ppc/kernel/smp.c
@@ -45,6 +45,7 @@ cpumask_t cpu_online_map;
45cpumask_t cpu_possible_map; 45cpumask_t cpu_possible_map;
46int smp_hw_index[NR_CPUS]; 46int smp_hw_index[NR_CPUS];
47struct thread_info *secondary_ti; 47struct thread_info *secondary_ti;
48static struct task_struct *idle_tasks[NR_CPUS];
48 49
49EXPORT_SYMBOL(cpu_online_map); 50EXPORT_SYMBOL(cpu_online_map);
50EXPORT_SYMBOL(cpu_possible_map); 51EXPORT_SYMBOL(cpu_possible_map);
@@ -286,7 +287,8 @@ static void __devinit smp_store_cpu_info(int id)
286 287
287void __init smp_prepare_cpus(unsigned int max_cpus) 288void __init smp_prepare_cpus(unsigned int max_cpus)
288{ 289{
289 int num_cpus, i; 290 int num_cpus, i, cpu;
291 struct task_struct *p;
290 292
291 /* Fixup boot cpu */ 293 /* Fixup boot cpu */
292 smp_store_cpu_info(smp_processor_id()); 294 smp_store_cpu_info(smp_processor_id());
@@ -308,6 +310,17 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
308 310
309 if (smp_ops->space_timers) 311 if (smp_ops->space_timers)
310 smp_ops->space_timers(num_cpus); 312 smp_ops->space_timers(num_cpus);
313
314 for_each_cpu(cpu) {
315 if (cpu == smp_processor_id())
316 continue;
317 /* create a process for the processor */
318 p = fork_idle(cpu);
319 if (IS_ERR(p))
320 panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p));
321 p->thread_info->cpu = cpu;
322 idle_tasks[cpu] = p;
323 }
311} 324}
312 325
313void __devinit smp_prepare_boot_cpu(void) 326void __devinit smp_prepare_boot_cpu(void)
@@ -334,12 +347,17 @@ int __devinit start_secondary(void *unused)
334 set_dec(tb_ticks_per_jiffy); 347 set_dec(tb_ticks_per_jiffy);
335 cpu_callin_map[cpu] = 1; 348 cpu_callin_map[cpu] = 1;
336 349
337 printk("CPU %i done callin...\n", cpu); 350 printk("CPU %d done callin...\n", cpu);
338 smp_ops->setup_cpu(cpu); 351 smp_ops->setup_cpu(cpu);
339 printk("CPU %i done setup...\n", cpu); 352 printk("CPU %d done setup...\n", cpu);
340 local_irq_enable();
341 smp_ops->take_timebase(); 353 smp_ops->take_timebase();
342 printk("CPU %i done timebase take...\n", cpu); 354 printk("CPU %d done timebase take...\n", cpu);
355
356 spin_lock(&call_lock);
357 cpu_set(cpu, cpu_online_map);
358 spin_unlock(&call_lock);
359
360 local_irq_enable();
343 361
344 cpu_idle(); 362 cpu_idle();
345 return 0; 363 return 0;
@@ -347,17 +365,11 @@ int __devinit start_secondary(void *unused)
347 365
348int __cpu_up(unsigned int cpu) 366int __cpu_up(unsigned int cpu)
349{ 367{
350 struct task_struct *p;
351 char buf[32]; 368 char buf[32];
352 int c; 369 int c;
353 370
354 /* create a process for the processor */ 371 secondary_ti = idle_tasks[cpu]->thread_info;
355 /* only regs.msr is actually used, and 0 is OK for it */ 372 mb();
356 p = fork_idle(cpu);
357 if (IS_ERR(p))
358 panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p));
359 secondary_ti = p->thread_info;
360 p->thread_info->cpu = cpu;
361 373
362 /* 374 /*
363 * There was a cache flush loop here to flush the cache 375 * There was a cache flush loop here to flush the cache
@@ -389,7 +401,11 @@ int __cpu_up(unsigned int cpu)
389 printk("Processor %d found.\n", cpu); 401 printk("Processor %d found.\n", cpu);
390 402
391 smp_ops->give_timebase(); 403 smp_ops->give_timebase();
392 cpu_set(cpu, cpu_online_map); 404
405 /* Wait until cpu puts itself in the online map */
406 while (!cpu_online(cpu))
407 cpu_relax();
408
393 return 0; 409 return 0;
394} 410}
395 411
diff --git a/arch/ppc/kernel/swsusp.S b/arch/ppc/kernel/swsusp.S
index 55148bb88d..69773cc1a8 100644
--- a/arch/ppc/kernel/swsusp.S
+++ b/arch/ppc/kernel/swsusp.S
@@ -5,7 +5,7 @@
5#include <asm/cputable.h> 5#include <asm/cputable.h>
6#include <asm/thread_info.h> 6#include <asm/thread_info.h>
7#include <asm/ppc_asm.h> 7#include <asm/ppc_asm.h>
8#include <asm/offsets.h> 8#include <asm/asm-offsets.h>
9 9
10 10
11/* 11/*
diff --git a/arch/ppc/kernel/traps.c b/arch/ppc/kernel/traps.c
index d87423d100..961ede87be 100644
--- a/arch/ppc/kernel/traps.c
+++ b/arch/ppc/kernel/traps.c
@@ -118,6 +118,28 @@ void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
118 info.si_code = code; 118 info.si_code = code;
119 info.si_addr = (void __user *) addr; 119 info.si_addr = (void __user *) addr;
120 force_sig_info(signr, &info, current); 120 force_sig_info(signr, &info, current);
121
122 /*
123 * Init gets no signals that it doesn't have a handler for.
124 * That's all very well, but if it has caused a synchronous
125 * exception and we ignore the resulting signal, it will just
126 * generate the same exception over and over again and we get
127 * nowhere. Better to kill it and let the kernel panic.
128 */
129 if (current->pid == 1) {
130 __sighandler_t handler;
131
132 spin_lock_irq(&current->sighand->siglock);
133 handler = current->sighand->action[signr-1].sa.sa_handler;
134 spin_unlock_irq(&current->sighand->siglock);
135 if (handler == SIG_DFL) {
136 /* init has generated a synchronous exception
137 and it doesn't have a handler for the signal */
138 printk(KERN_CRIT "init has generated signal %d "
139 "but has no handler for it\n", signr);
140 do_exit(signr);
141 }
142 }
121} 143}
122 144
123/* 145/*
@@ -849,10 +871,12 @@ void AltivecAssistException(struct pt_regs *regs)
849} 871}
850#endif /* CONFIG_ALTIVEC */ 872#endif /* CONFIG_ALTIVEC */
851 873
874#ifdef CONFIG_E500
852void PerformanceMonitorException(struct pt_regs *regs) 875void PerformanceMonitorException(struct pt_regs *regs)
853{ 876{
854 perf_irq(regs); 877 perf_irq(regs);
855} 878}
879#endif
856 880
857#ifdef CONFIG_FSL_BOOKE 881#ifdef CONFIG_FSL_BOOKE
858void CacheLockingException(struct pt_regs *regs, unsigned long address, 882void CacheLockingException(struct pt_regs *regs, unsigned long address,
diff --git a/arch/ppc/lib/Makefile b/arch/ppc/lib/Makefile
index 1c380e67d4..f1e1fb4144 100644
--- a/arch/ppc/lib/Makefile
+++ b/arch/ppc/lib/Makefile
@@ -4,6 +4,5 @@
4 4
5obj-y := checksum.o string.o strcase.o dec_and_lock.o div64.o 5obj-y := checksum.o string.o strcase.o dec_and_lock.o div64.o
6 6
7obj-$(CONFIG_SMP) += locks.o
8obj-$(CONFIG_8xx) += rheap.o 7obj-$(CONFIG_8xx) += rheap.o
9obj-$(CONFIG_CPM2) += rheap.o 8obj-$(CONFIG_CPM2) += rheap.o
diff --git a/arch/ppc/lib/dec_and_lock.c b/arch/ppc/lib/dec_and_lock.c
index 4ee888070d..b18f0d9a00 100644
--- a/arch/ppc/lib/dec_and_lock.c
+++ b/arch/ppc/lib/dec_and_lock.c
@@ -11,14 +11,7 @@
11 * has a cmpxchg, and where atomic->value is an int holding 11 * has a cmpxchg, and where atomic->value is an int holding
12 * the value of the atomic (i.e. the high bits aren't used 12 * the value of the atomic (i.e. the high bits aren't used
13 * for a lock or anything like that). 13 * for a lock or anything like that).
14 *
15 * N.B. ATOMIC_DEC_AND_LOCK gets defined in include/linux/spinlock.h
16 * if spinlocks are empty and thus atomic_dec_and_lock is defined
17 * to be atomic_dec_and_test - in that case we don't need it
18 * defined here as well.
19 */ 14 */
20
21#ifndef ATOMIC_DEC_AND_LOCK
22int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock) 15int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
23{ 16{
24 int counter; 17 int counter;
@@ -43,4 +36,3 @@ int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
43} 36}
44 37
45EXPORT_SYMBOL(_atomic_dec_and_lock); 38EXPORT_SYMBOL(_atomic_dec_and_lock);
46#endif /* ATOMIC_DEC_AND_LOCK */
diff --git a/arch/ppc/mm/fault.c b/arch/ppc/mm/fault.c
index 57d9930843..ee5e9f25ba 100644
--- a/arch/ppc/mm/fault.c
+++ b/arch/ppc/mm/fault.c
@@ -278,11 +278,7 @@ bad_area:
278 278
279 /* User mode accesses cause a SIGSEGV */ 279 /* User mode accesses cause a SIGSEGV */
280 if (user_mode(regs)) { 280 if (user_mode(regs)) {
281 info.si_signo = SIGSEGV; 281 _exception(SIGSEGV, regs, code, address);
282 info.si_errno = 0;
283 info.si_code = code;
284 info.si_addr = (void __user *) address;
285 force_sig_info(SIGSEGV, &info, current);
286 return 0; 282 return 0;
287 } 283 }
288 284
diff --git a/arch/ppc/mm/hashtable.S b/arch/ppc/mm/hashtable.S
index ab83132a7e..3ec87c9134 100644
--- a/arch/ppc/mm/hashtable.S
+++ b/arch/ppc/mm/hashtable.S
@@ -30,7 +30,7 @@
30#include <asm/cputable.h> 30#include <asm/cputable.h>
31#include <asm/ppc_asm.h> 31#include <asm/ppc_asm.h>
32#include <asm/thread_info.h> 32#include <asm/thread_info.h>
33#include <asm/offsets.h> 33#include <asm/asm-offsets.h>
34 34
35#ifdef CONFIG_SMP 35#ifdef CONFIG_SMP
36 .comm mmu_hash_lock,4 36 .comm mmu_hash_lock,4
diff --git a/arch/ppc/platforms/4xx/ebony.c b/arch/ppc/platforms/4xx/ebony.c
index 0fd3442f51..d6b2b1965d 100644
--- a/arch/ppc/platforms/4xx/ebony.c
+++ b/arch/ppc/platforms/4xx/ebony.c
@@ -91,15 +91,10 @@ ebony_calibrate_decr(void)
91 * on Rev. C silicon then errata forces us to 91 * on Rev. C silicon then errata forces us to
92 * use the internal clock. 92 * use the internal clock.
93 */ 93 */
94 switch (PVR_REV(mfspr(SPRN_PVR))) { 94 if (strcmp(cur_cpu_spec[0]->cpu_name, "440GP Rev. B") == 0)
95 case PVR_REV(PVR_440GP_RB): 95 freq = EBONY_440GP_RB_SYSCLK;
96 freq = EBONY_440GP_RB_SYSCLK; 96 else
97 break; 97 freq = EBONY_440GP_RC_SYSCLK;
98 case PVR_REV(PVR_440GP_RC1):
99 default:
100 freq = EBONY_440GP_RC_SYSCLK;
101 break;
102 }
103 98
104 ibm44x_calibrate_decr(freq); 99 ibm44x_calibrate_decr(freq);
105} 100}
diff --git a/arch/ppc/platforms/hdpu.c b/arch/ppc/platforms/hdpu.c
index b659d7b3d7..ff37968601 100644
--- a/arch/ppc/platforms/hdpu.c
+++ b/arch/ppc/platforms/hdpu.c
@@ -58,7 +58,7 @@ static void parse_bootinfo(unsigned long r3,
58static void hdpu_set_l1pe(void); 58static void hdpu_set_l1pe(void);
59static void hdpu_cpustate_set(unsigned char new_state); 59static void hdpu_cpustate_set(unsigned char new_state);
60#ifdef CONFIG_SMP 60#ifdef CONFIG_SMP
61static spinlock_t timebase_lock = SPIN_LOCK_UNLOCKED; 61static DEFINE_SPINLOCK(timebase_lock);
62static unsigned int timebase_upper = 0, timebase_lower = 0; 62static unsigned int timebase_upper = 0, timebase_lower = 0;
63extern int smp_tb_synchronized; 63extern int smp_tb_synchronized;
64 64
diff --git a/arch/ppc/platforms/pmac_sleep.S b/arch/ppc/platforms/pmac_sleep.S
index 016a746491..88419c77ac 100644
--- a/arch/ppc/platforms/pmac_sleep.S
+++ b/arch/ppc/platforms/pmac_sleep.S
@@ -17,7 +17,7 @@
17#include <asm/cputable.h> 17#include <asm/cputable.h>
18#include <asm/cache.h> 18#include <asm/cache.h>
19#include <asm/thread_info.h> 19#include <asm/thread_info.h>
20#include <asm/offsets.h> 20#include <asm/asm-offsets.h>
21 21
22#define MAGIC 0x4c617273 /* 'Lars' */ 22#define MAGIC 0x4c617273 /* 'Lars' */
23 23
@@ -161,6 +161,8 @@ _GLOBAL(low_sleep_handler)
161 addi r3,r3,sleep_storage@l 161 addi r3,r3,sleep_storage@l
162 stw r5,0(r3) 162 stw r5,0(r3)
163 163
164 .globl low_cpu_die
165low_cpu_die:
164 /* Flush & disable all caches */ 166 /* Flush & disable all caches */
165 bl flush_disable_caches 167 bl flush_disable_caches
166 168
diff --git a/arch/ppc/platforms/pmac_smp.c b/arch/ppc/platforms/pmac_smp.c
index 8e049dab4e..794a23994b 100644
--- a/arch/ppc/platforms/pmac_smp.c
+++ b/arch/ppc/platforms/pmac_smp.c
@@ -33,6 +33,7 @@
33#include <linux/spinlock.h> 33#include <linux/spinlock.h>
34#include <linux/errno.h> 34#include <linux/errno.h>
35#include <linux/hardirq.h> 35#include <linux/hardirq.h>
36#include <linux/cpu.h>
36 37
37#include <asm/ptrace.h> 38#include <asm/ptrace.h>
38#include <asm/atomic.h> 39#include <asm/atomic.h>
@@ -55,9 +56,7 @@
55 * Powersurge (old powermac SMP) support. 56 * Powersurge (old powermac SMP) support.
56 */ 57 */
57 58
58extern void __secondary_start_psurge(void); 59extern void __secondary_start_pmac_0(void);
59extern void __secondary_start_psurge2(void); /* Temporary horrible hack */
60extern void __secondary_start_psurge3(void); /* Temporary horrible hack */
61 60
62/* Addresses for powersurge registers */ 61/* Addresses for powersurge registers */
63#define HAMMERHEAD_BASE 0xf8000000 62#define HAMMERHEAD_BASE 0xf8000000
@@ -119,7 +118,7 @@ static volatile int sec_tb_reset = 0;
119static unsigned int pri_tb_hi, pri_tb_lo; 118static unsigned int pri_tb_hi, pri_tb_lo;
120static unsigned int pri_tb_stamp; 119static unsigned int pri_tb_stamp;
121 120
122static void __init core99_init_caches(int cpu) 121static void __devinit core99_init_caches(int cpu)
123{ 122{
124 if (!cpu_has_feature(CPU_FTR_L2CR)) 123 if (!cpu_has_feature(CPU_FTR_L2CR))
125 return; 124 return;
@@ -346,7 +345,7 @@ static int __init smp_psurge_probe(void)
346 345
347static void __init smp_psurge_kick_cpu(int nr) 346static void __init smp_psurge_kick_cpu(int nr)
348{ 347{
349 void (*start)(void) = __secondary_start_psurge; 348 unsigned long start = __pa(__secondary_start_pmac_0) + nr * 8;
350 unsigned long a; 349 unsigned long a;
351 350
352 /* may need to flush here if secondary bats aren't setup */ 351 /* may need to flush here if secondary bats aren't setup */
@@ -356,17 +355,7 @@ static void __init smp_psurge_kick_cpu(int nr)
356 355
357 if (ppc_md.progress) ppc_md.progress("smp_psurge_kick_cpu", 0x353); 356 if (ppc_md.progress) ppc_md.progress("smp_psurge_kick_cpu", 0x353);
358 357
359 /* setup entry point of secondary processor */ 358 out_be32(psurge_start, start);
360 switch (nr) {
361 case 2:
362 start = __secondary_start_psurge2;
363 break;
364 case 3:
365 start = __secondary_start_psurge3;
366 break;
367 }
368
369 out_be32(psurge_start, __pa(start));
370 mb(); 359 mb();
371 360
372 psurge_set_ipi(nr); 361 psurge_set_ipi(nr);
@@ -500,14 +489,14 @@ static int __init smp_core99_probe(void)
500 return ncpus; 489 return ncpus;
501} 490}
502 491
503static void __init smp_core99_kick_cpu(int nr) 492static void __devinit smp_core99_kick_cpu(int nr)
504{ 493{
505 unsigned long save_vector, new_vector; 494 unsigned long save_vector, new_vector;
506 unsigned long flags; 495 unsigned long flags;
507 496
508 volatile unsigned long *vector 497 volatile unsigned long *vector
509 = ((volatile unsigned long *)(KERNELBASE+0x100)); 498 = ((volatile unsigned long *)(KERNELBASE+0x100));
510 if (nr < 1 || nr > 3) 499 if (nr < 0 || nr > 3)
511 return; 500 return;
512 if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu", 0x346); 501 if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu", 0x346);
513 502
@@ -518,19 +507,9 @@ static void __init smp_core99_kick_cpu(int nr)
518 save_vector = *vector; 507 save_vector = *vector;
519 508
520 /* Setup fake reset vector that does 509 /* Setup fake reset vector that does
521 * b __secondary_start_psurge - KERNELBASE 510 * b __secondary_start_pmac_0 + nr*8 - KERNELBASE
522 */ 511 */
523 switch(nr) { 512 new_vector = (unsigned long) __secondary_start_pmac_0 + nr * 8;
524 case 1:
525 new_vector = (unsigned long)__secondary_start_psurge;
526 break;
527 case 2:
528 new_vector = (unsigned long)__secondary_start_psurge2;
529 break;
530 case 3:
531 new_vector = (unsigned long)__secondary_start_psurge3;
532 break;
533 }
534 *vector = 0x48000002 + new_vector - KERNELBASE; 513 *vector = 0x48000002 + new_vector - KERNELBASE;
535 514
536 /* flush data cache and inval instruction cache */ 515 /* flush data cache and inval instruction cache */
@@ -554,7 +533,7 @@ static void __init smp_core99_kick_cpu(int nr)
554 if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu done", 0x347); 533 if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu done", 0x347);
555} 534}
556 535
557static void __init smp_core99_setup_cpu(int cpu_nr) 536static void __devinit smp_core99_setup_cpu(int cpu_nr)
558{ 537{
559 /* Setup L2/L3 */ 538 /* Setup L2/L3 */
560 if (cpu_nr != 0) 539 if (cpu_nr != 0)
@@ -668,3 +647,47 @@ struct smp_ops_t core99_smp_ops __pmacdata = {
668 .give_timebase = smp_core99_give_timebase, 647 .give_timebase = smp_core99_give_timebase,
669 .take_timebase = smp_core99_take_timebase, 648 .take_timebase = smp_core99_take_timebase,
670}; 649};
650
651#ifdef CONFIG_HOTPLUG_CPU
652
653int __cpu_disable(void)
654{
655 cpu_clear(smp_processor_id(), cpu_online_map);
656
657 /* XXX reset cpu affinity here */
658 openpic_set_priority(0xf);
659 asm volatile("mtdec %0" : : "r" (0x7fffffff));
660 mb();
661 udelay(20);
662 asm volatile("mtdec %0" : : "r" (0x7fffffff));
663 return 0;
664}
665
666extern void low_cpu_die(void) __attribute__((noreturn)); /* in pmac_sleep.S */
667static int cpu_dead[NR_CPUS];
668
669void cpu_die(void)
670{
671 local_irq_disable();
672 cpu_dead[smp_processor_id()] = 1;
673 mb();
674 low_cpu_die();
675}
676
677void __cpu_die(unsigned int cpu)
678{
679 int timeout;
680
681 timeout = 1000;
682 while (!cpu_dead[cpu]) {
683 if (--timeout == 0) {
684 printk("CPU %u refused to die!\n", cpu);
685 break;
686 }
687 msleep(1);
688 }
689 cpu_callin_map[cpu] = 0;
690 cpu_dead[cpu] = 0;
691}
692
693#endif
diff --git a/arch/ppc/syslib/cpc700_pic.c b/arch/ppc/syslib/cpc700_pic.c
index 7747098075..75fe8eb106 100644
--- a/arch/ppc/syslib/cpc700_pic.c
+++ b/arch/ppc/syslib/cpc700_pic.c
@@ -90,14 +90,10 @@ cpc700_mask_and_ack_irq(unsigned int irq)
90} 90}
91 91
92static struct hw_interrupt_type cpc700_pic = { 92static struct hw_interrupt_type cpc700_pic = {
93 "CPC700 PIC", 93 .typename = "CPC700 PIC",
94 NULL, 94 .enable = cpc700_unmask_irq,
95 NULL, 95 .disable = cpc700_mask_irq,
96 cpc700_unmask_irq, 96 .ack = cpc700_mask_and_ack_irq,
97 cpc700_mask_irq,
98 cpc700_mask_and_ack_irq,
99 NULL,
100 NULL
101}; 97};
102 98
103__init static void 99__init static void
diff --git a/arch/ppc/syslib/i8259.c b/arch/ppc/syslib/i8259.c
index b9391e6501..5c7908c20e 100644
--- a/arch/ppc/syslib/i8259.c
+++ b/arch/ppc/syslib/i8259.c
@@ -129,14 +129,11 @@ static void i8259_end_irq(unsigned int irq)
129} 129}
130 130
131struct hw_interrupt_type i8259_pic = { 131struct hw_interrupt_type i8259_pic = {
132 " i8259 ", 132 .typename = " i8259 ",
133 NULL, 133 .enable = i8259_unmask_irq,
134 NULL, 134 .disable = i8259_mask_irq,
135 i8259_unmask_irq, 135 .ack = i8259_mask_and_ack_irq,
136 i8259_mask_irq, 136 .end = i8259_end_irq,
137 i8259_mask_and_ack_irq,
138 i8259_end_irq,
139 NULL
140}; 137};
141 138
142static struct resource pic1_iores = { 139static struct resource pic1_iores = {
diff --git a/arch/ppc/syslib/ibm440gx_common.c b/arch/ppc/syslib/ibm440gx_common.c
index d4776af6a3..0bb919859b 100644
--- a/arch/ppc/syslib/ibm440gx_common.c
+++ b/arch/ppc/syslib/ibm440gx_common.c
@@ -236,9 +236,10 @@ void __init ibm440gx_l2c_setup(struct ibm44x_clocks* p)
236 /* Disable L2C on rev.A, rev.B and 800MHz version of rev.C, 236 /* Disable L2C on rev.A, rev.B and 800MHz version of rev.C,
237 enable it on all other revisions 237 enable it on all other revisions
238 */ 238 */
239 u32 pvr = mfspr(SPRN_PVR); 239 if (strcmp(cur_cpu_spec[0]->cpu_name, "440GX Rev. A") == 0 ||
240 if (pvr == PVR_440GX_RA || pvr == PVR_440GX_RB || 240 strcmp(cur_cpu_spec[0]->cpu_name, "440GX Rev. B") == 0
241 (pvr == PVR_440GX_RC && p->cpu > 667000000)) 241 || (strcmp(cur_cpu_spec[0]->cpu_name, "440GX Rev. C")
242 == 0 && p->cpu > 667000000))
242 ibm440gx_l2c_disable(); 243 ibm440gx_l2c_disable();
243 else 244 else
244 ibm440gx_l2c_enable(); 245 ibm440gx_l2c_enable();
diff --git a/arch/ppc/syslib/mv64x60.c b/arch/ppc/syslib/mv64x60.c
index 6262b11f36..839f887282 100644
--- a/arch/ppc/syslib/mv64x60.c
+++ b/arch/ppc/syslib/mv64x60.c
@@ -31,7 +31,7 @@
31 31
32 32
33u8 mv64x60_pci_exclude_bridge = 1; 33u8 mv64x60_pci_exclude_bridge = 1;
34spinlock_t mv64x60_lock = SPIN_LOCK_UNLOCKED; 34DEFINE_SPINLOCK(mv64x60_lock);
35 35
36static phys_addr_t mv64x60_bridge_pbase; 36static phys_addr_t mv64x60_bridge_pbase;
37static void *mv64x60_bridge_vbase; 37static void *mv64x60_bridge_vbase;
diff --git a/arch/ppc/syslib/open_pic2.c b/arch/ppc/syslib/open_pic2.c
index 7e272c51a4..2e0ea92144 100644
--- a/arch/ppc/syslib/open_pic2.c
+++ b/arch/ppc/syslib/open_pic2.c
@@ -82,13 +82,11 @@ static void openpic2_end_irq(unsigned int irq_nr);
82static void openpic2_ack_irq(unsigned int irq_nr); 82static void openpic2_ack_irq(unsigned int irq_nr);
83 83
84struct hw_interrupt_type open_pic2 = { 84struct hw_interrupt_type open_pic2 = {
85 " OpenPIC2 ", 85 .typename = " OpenPIC2 ",
86 NULL, 86 .enable = openpic2_enable_irq,
87 NULL, 87 .disable = openpic2_disable_irq,
88 openpic2_enable_irq, 88 .ack = openpic2_ack_irq,
89 openpic2_disable_irq, 89 .end = openpic2_end_irq,
90 openpic2_ack_irq,
91 openpic2_end_irq,
92}; 90};
93 91
94/* 92/*
diff --git a/arch/ppc/syslib/ppc403_pic.c b/arch/ppc/syslib/ppc403_pic.c
index 06cb0af2a5..ce4d1deb86 100644
--- a/arch/ppc/syslib/ppc403_pic.c
+++ b/arch/ppc/syslib/ppc403_pic.c
@@ -34,13 +34,10 @@ static void ppc403_aic_disable(unsigned int irq);
34static void ppc403_aic_disable_and_ack(unsigned int irq); 34static void ppc403_aic_disable_and_ack(unsigned int irq);
35 35
36static struct hw_interrupt_type ppc403_aic = { 36static struct hw_interrupt_type ppc403_aic = {
37 "403GC AIC", 37 .typename = "403GC AIC",
38 NULL, 38 .enable = ppc403_aic_enable,
39 NULL, 39 .disable = ppc403_aic_disable,
40 ppc403_aic_enable, 40 .ack = ppc403_aic_disable_and_ack,
41 ppc403_aic_disable,
42 ppc403_aic_disable_and_ack,
43 0
44}; 41};
45 42
46int 43int
diff --git a/arch/ppc/syslib/qspan_pci.c b/arch/ppc/syslib/qspan_pci.c
index 57f4ed5e5a..0970b5d303 100644
--- a/arch/ppc/syslib/qspan_pci.c
+++ b/arch/ppc/syslib/qspan_pci.c
@@ -94,7 +94,7 @@
94#define mk_config_type1(bus, dev, offset) \ 94#define mk_config_type1(bus, dev, offset) \
95 mk_config_addr(bus, dev, offset) | 1; 95 mk_config_addr(bus, dev, offset) | 1;
96 96
97static spinlock_t pcibios_lock = SPIN_LOCK_UNLOCKED; 97static DEFINE_SPINLOCK(pcibios_lock);
98 98
99int qspan_pcibios_read_config_byte(unsigned char bus, unsigned char dev_fn, 99int qspan_pcibios_read_config_byte(unsigned char bus, unsigned char dev_fn,
100 unsigned char offset, unsigned char *val) 100 unsigned char offset, unsigned char *val)
diff --git a/arch/ppc/syslib/xilinx_pic.c b/arch/ppc/syslib/xilinx_pic.c
index e0bd66f084..2cbcad278c 100644
--- a/arch/ppc/syslib/xilinx_pic.c
+++ b/arch/ppc/syslib/xilinx_pic.c
@@ -79,14 +79,11 @@ xilinx_intc_end(unsigned int irq)
79} 79}
80 80
81static struct hw_interrupt_type xilinx_intc = { 81static struct hw_interrupt_type xilinx_intc = {
82 "Xilinx Interrupt Controller", 82 .typename = "Xilinx Interrupt Controller",
83 NULL, 83 .enable = xilinx_intc_enable,
84 NULL, 84 .disable = xilinx_intc_disable,
85 xilinx_intc_enable, 85 .ack = xilinx_intc_disable_and_ack,
86 xilinx_intc_disable, 86 .end = xilinx_intc_end,
87 xilinx_intc_disable_and_ack,
88 xilinx_intc_end,
89 0
90}; 87};
91 88
92int 89int
diff --git a/arch/ppc64/Makefile b/arch/ppc64/Makefile
index a91daa324e..17d2c1eac3 100644
--- a/arch/ppc64/Makefile
+++ b/arch/ppc64/Makefile
@@ -56,7 +56,7 @@ LDFLAGS_vmlinux := -Bstatic -e $(KERNELLOAD) -Ttext $(KERNELLOAD)
56CFLAGS += -msoft-float -pipe -mminimal-toc -mtraceback=none \ 56CFLAGS += -msoft-float -pipe -mminimal-toc -mtraceback=none \
57 -mcall-aixdesc 57 -mcall-aixdesc
58# Temporary hack until we have migrated to asm-powerpc 58# Temporary hack until we have migrated to asm-powerpc
59CPPFLAGS += -Iinclude3 59CPPFLAGS += -Iarch/$(ARCH)/include
60 60
61GCC_VERSION := $(call cc-version) 61GCC_VERSION := $(call cc-version)
62GCC_BROKEN_VEC := $(shell if [ $(GCC_VERSION) -lt 0400 ] ; then echo "y"; fi ;) 62GCC_BROKEN_VEC := $(shell if [ $(GCC_VERSION) -lt 0400 ] ; then echo "y"; fi ;)
@@ -115,21 +115,15 @@ all: $(KBUILD_IMAGE)
115 115
116archclean: 116archclean:
117 $(Q)$(MAKE) $(clean)=$(boot) 117 $(Q)$(MAKE) $(clean)=$(boot)
118 $(Q)rm -rf include3 118 # Temporary hack until we have migrated to asm-powerpc
119 $(Q)rm -rf arch/$(ARCH)/include
119 120
120prepare: include/asm-ppc64/offsets.h
121
122arch/ppc64/kernel/asm-offsets.s: include/asm include/linux/version.h \
123 include/config/MARKER
124
125include/asm-ppc64/offsets.h: arch/ppc64/kernel/asm-offsets.s
126 $(call filechk,gen-asm-offsets)
127 121
128# Temporary hack until we have migrated to asm-powerpc 122# Temporary hack until we have migrated to asm-powerpc
129include/asm: include3/asm 123include/asm: arch/$(ARCH)/include/asm
130include3/asm: 124arch/$(ARCH)/include/asm:
131 $(Q)if [ ! -d include3 ]; then mkdir -p include3; fi; 125 $(Q)if [ ! -d arch/$(ARCH)/include ]; then mkdir -p arch/$(ARCH)/include; fi
132 $(Q)ln -fsn $(srctree)/include/asm-powerpc include3/asm 126 $(Q)ln -fsn $(srctree)/include/asm-powerpc arch/$(ARCH)/include/asm
133 127
134define archhelp 128define archhelp
135 echo ' zImage.vmode - Compressed kernel image (arch/$(ARCH)/boot/zImage.vmode)' 129 echo ' zImage.vmode - Compressed kernel image (arch/$(ARCH)/boot/zImage.vmode)'
@@ -139,5 +133,3 @@ define archhelp
139 echo ' zImage - zImage for pSeries machines' 133 echo ' zImage - zImage for pSeries machines'
140 echo ' zImage.initrd - zImage with initrd for pSeries machines' 134 echo ' zImage.initrd - zImage with initrd for pSeries machines'
141endef 135endef
142
143CLEAN_FILES += include/asm-ppc64/offsets.h
diff --git a/arch/ppc64/kernel/cpu_setup_power4.S b/arch/ppc64/kernel/cpu_setup_power4.S
index 0482c063c2..1fb673c511 100644
--- a/arch/ppc64/kernel/cpu_setup_power4.S
+++ b/arch/ppc64/kernel/cpu_setup_power4.S
@@ -12,10 +12,9 @@
12#include <linux/config.h> 12#include <linux/config.h>
13#include <asm/processor.h> 13#include <asm/processor.h>
14#include <asm/page.h> 14#include <asm/page.h>
15#include <asm/ppc_asm.h>
16#include <asm/cputable.h> 15#include <asm/cputable.h>
17#include <asm/ppc_asm.h> 16#include <asm/ppc_asm.h>
18#include <asm/offsets.h> 17#include <asm/asm-offsets.h>
19#include <asm/cache.h> 18#include <asm/cache.h>
20 19
21_GLOBAL(__970_cpu_preinit) 20_GLOBAL(__970_cpu_preinit)
diff --git a/arch/ppc64/kernel/entry.S b/arch/ppc64/kernel/entry.S
index bf99b4a92f..d133a49cdf 100644
--- a/arch/ppc64/kernel/entry.S
+++ b/arch/ppc64/kernel/entry.S
@@ -28,7 +28,7 @@
28#include <asm/mmu.h> 28#include <asm/mmu.h>
29#include <asm/thread_info.h> 29#include <asm/thread_info.h>
30#include <asm/ppc_asm.h> 30#include <asm/ppc_asm.h>
31#include <asm/offsets.h> 31#include <asm/asm-offsets.h>
32#include <asm/cputable.h> 32#include <asm/cputable.h>
33 33
34#ifdef CONFIG_PPC_ISERIES 34#ifdef CONFIG_PPC_ISERIES
diff --git a/arch/ppc64/kernel/head.S b/arch/ppc64/kernel/head.S
index b436206e31..58c314738c 100644
--- a/arch/ppc64/kernel/head.S
+++ b/arch/ppc64/kernel/head.S
@@ -30,7 +30,7 @@
30#include <asm/mmu.h> 30#include <asm/mmu.h>
31#include <asm/systemcfg.h> 31#include <asm/systemcfg.h>
32#include <asm/ppc_asm.h> 32#include <asm/ppc_asm.h>
33#include <asm/offsets.h> 33#include <asm/asm-offsets.h>
34#include <asm/bug.h> 34#include <asm/bug.h>
35#include <asm/cputable.h> 35#include <asm/cputable.h>
36#include <asm/setup.h> 36#include <asm/setup.h>
diff --git a/arch/ppc64/kernel/iSeries_pci.c b/arch/ppc64/kernel/iSeries_pci.c
index 356e4fd9a9..fbc273c32b 100644
--- a/arch/ppc64/kernel/iSeries_pci.c
+++ b/arch/ppc64/kernel/iSeries_pci.c
@@ -252,7 +252,7 @@ unsigned long __init find_and_init_phbs(void)
252 phb = (struct pci_controller *)kmalloc(sizeof(struct pci_controller), GFP_KERNEL); 252 phb = (struct pci_controller *)kmalloc(sizeof(struct pci_controller), GFP_KERNEL);
253 if (phb == NULL) 253 if (phb == NULL)
254 return -ENOMEM; 254 return -ENOMEM;
255 pci_setup_pci_controller(phb); 255 pci_setup_pci_controller(phb);
256 256
257 phb->pci_mem_offset = phb->local_number = bus; 257 phb->pci_mem_offset = phb->local_number = bus;
258 phb->first_busno = bus; 258 phb->first_busno = bus;
diff --git a/arch/ppc64/kernel/idle_power4.S b/arch/ppc64/kernel/idle_power4.S
index 97e4a26550..ca02afe2a7 100644
--- a/arch/ppc64/kernel/idle_power4.S
+++ b/arch/ppc64/kernel/idle_power4.S
@@ -20,7 +20,7 @@
20#include <asm/cputable.h> 20#include <asm/cputable.h>
21#include <asm/thread_info.h> 21#include <asm/thread_info.h>
22#include <asm/ppc_asm.h> 22#include <asm/ppc_asm.h>
23#include <asm/offsets.h> 23#include <asm/asm-offsets.h>
24 24
25#undef DEBUG 25#undef DEBUG
26 26
diff --git a/arch/ppc64/kernel/maple_pci.c b/arch/ppc64/kernel/maple_pci.c
index 5a8b4d8c2d..1d297e0edf 100644
--- a/arch/ppc64/kernel/maple_pci.c
+++ b/arch/ppc64/kernel/maple_pci.c
@@ -283,7 +283,7 @@ static void __init setup_u3_agp(struct pci_controller* hose)
283 * the reg address cell, we shall fix that by killing struct 283 * the reg address cell, we shall fix that by killing struct
284 * reg_property and using some accessor functions instead 284 * reg_property and using some accessor functions instead
285 */ 285 */
286 hose->first_busno = 0xf0; 286 hose->first_busno = 0xf0;
287 hose->last_busno = 0xff; 287 hose->last_busno = 0xff;
288 hose->ops = &u3_agp_pci_ops; 288 hose->ops = &u3_agp_pci_ops;
289 hose->cfg_addr = ioremap(0xf0000000 + 0x800000, 0x1000); 289 hose->cfg_addr = ioremap(0xf0000000 + 0x800000, 0x1000);
@@ -315,24 +315,24 @@ static int __init add_bridge(struct device_node *dev)
315 char* disp_name; 315 char* disp_name;
316 int *bus_range; 316 int *bus_range;
317 int primary = 1; 317 int primary = 1;
318 struct property *of_prop; 318 struct property *of_prop;
319 319
320 DBG("Adding PCI host bridge %s\n", dev->full_name); 320 DBG("Adding PCI host bridge %s\n", dev->full_name);
321 321
322 bus_range = (int *) get_property(dev, "bus-range", &len); 322 bus_range = (int *) get_property(dev, "bus-range", &len);
323 if (bus_range == NULL || len < 2 * sizeof(int)) { 323 if (bus_range == NULL || len < 2 * sizeof(int)) {
324 printk(KERN_WARNING "Can't get bus-range for %s, assume bus 0\n", 324 printk(KERN_WARNING "Can't get bus-range for %s, assume bus 0\n",
325 dev->full_name); 325 dev->full_name);
326 } 326 }
327 327
328 hose = alloc_bootmem(sizeof(struct pci_controller)); 328 hose = alloc_bootmem(sizeof(struct pci_controller));
329 if (hose == NULL) 329 if (hose == NULL)
330 return -ENOMEM; 330 return -ENOMEM;
331 pci_setup_pci_controller(hose); 331 pci_setup_pci_controller(hose);
332 332
333 hose->arch_data = dev; 333 hose->arch_data = dev;
334 hose->first_busno = bus_range ? bus_range[0] : 0; 334 hose->first_busno = bus_range ? bus_range[0] : 0;
335 hose->last_busno = bus_range ? bus_range[1] : 0xff; 335 hose->last_busno = bus_range ? bus_range[1] : 0xff;
336 336
337 of_prop = alloc_bootmem(sizeof(struct property) + 337 of_prop = alloc_bootmem(sizeof(struct property) +
338 sizeof(hose->global_number)); 338 sizeof(hose->global_number));
@@ -346,25 +346,25 @@ static int __init add_bridge(struct device_node *dev)
346 } 346 }
347 347
348 disp_name = NULL; 348 disp_name = NULL;
349 if (device_is_compatible(dev, "u3-agp")) { 349 if (device_is_compatible(dev, "u3-agp")) {
350 setup_u3_agp(hose); 350 setup_u3_agp(hose);
351 disp_name = "U3-AGP"; 351 disp_name = "U3-AGP";
352 primary = 0; 352 primary = 0;
353 } else if (device_is_compatible(dev, "u3-ht")) { 353 } else if (device_is_compatible(dev, "u3-ht")) {
354 setup_u3_ht(hose); 354 setup_u3_ht(hose);
355 disp_name = "U3-HT"; 355 disp_name = "U3-HT";
356 primary = 1; 356 primary = 1;
357 } 357 }
358 printk(KERN_INFO "Found %s PCI host bridge. Firmware bus number: %d->%d\n", 358 printk(KERN_INFO "Found %s PCI host bridge. Firmware bus number: %d->%d\n",
359 disp_name, hose->first_busno, hose->last_busno); 359 disp_name, hose->first_busno, hose->last_busno);
360 360
361 /* Interpret the "ranges" property */ 361 /* Interpret the "ranges" property */
362 /* This also maps the I/O region and sets isa_io/mem_base */ 362 /* This also maps the I/O region and sets isa_io/mem_base */
363 pci_process_bridge_OF_ranges(hose, dev); 363 pci_process_bridge_OF_ranges(hose, dev);
364 pci_setup_phb_io(hose, primary); 364 pci_setup_phb_io(hose, primary);
365 365
366 /* Fixup "bus-range" OF property */ 366 /* Fixup "bus-range" OF property */
367 fixup_bus_range(dev); 367 fixup_bus_range(dev);
368 368
369 return 0; 369 return 0;
370} 370}
diff --git a/arch/ppc64/kernel/misc.S b/arch/ppc64/kernel/misc.S
index c047663eb4..e7241ad80a 100644
--- a/arch/ppc64/kernel/misc.S
+++ b/arch/ppc64/kernel/misc.S
@@ -26,7 +26,7 @@
26#include <asm/page.h> 26#include <asm/page.h>
27#include <asm/cache.h> 27#include <asm/cache.h>
28#include <asm/ppc_asm.h> 28#include <asm/ppc_asm.h>
29#include <asm/offsets.h> 29#include <asm/asm-offsets.h>
30#include <asm/cputable.h> 30#include <asm/cputable.h>
31 31
32 .text 32 .text
diff --git a/arch/ppc64/kernel/pSeries_setup.c b/arch/ppc64/kernel/pSeries_setup.c
index 9490b6c5b1..bfadccc7b8 100644
--- a/arch/ppc64/kernel/pSeries_setup.c
+++ b/arch/ppc64/kernel/pSeries_setup.c
@@ -590,6 +590,13 @@ static int pseries_shared_idle(void)
590 return 0; 590 return 0;
591} 591}
592 592
593static int pSeries_pci_probe_mode(struct pci_bus *bus)
594{
595 if (systemcfg->platform & PLATFORM_LPAR)
596 return PCI_PROBE_DEVTREE;
597 return PCI_PROBE_NORMAL;
598}
599
593struct machdep_calls __initdata pSeries_md = { 600struct machdep_calls __initdata pSeries_md = {
594 .probe = pSeries_probe, 601 .probe = pSeries_probe,
595 .setup_arch = pSeries_setup_arch, 602 .setup_arch = pSeries_setup_arch,
@@ -597,6 +604,7 @@ struct machdep_calls __initdata pSeries_md = {
597 .get_cpuinfo = pSeries_get_cpuinfo, 604 .get_cpuinfo = pSeries_get_cpuinfo,
598 .log_error = pSeries_log_error, 605 .log_error = pSeries_log_error,
599 .pcibios_fixup = pSeries_final_fixup, 606 .pcibios_fixup = pSeries_final_fixup,
607 .pci_probe_mode = pSeries_pci_probe_mode,
600 .irq_bus_setup = pSeries_irq_bus_setup, 608 .irq_bus_setup = pSeries_irq_bus_setup,
601 .restart = rtas_restart, 609 .restart = rtas_restart,
602 .power_off = rtas_power_off, 610 .power_off = rtas_power_off,
diff --git a/arch/ppc64/kernel/pSeries_smp.c b/arch/ppc64/kernel/pSeries_smp.c
index 79c7f32236..d2c7e2c473 100644
--- a/arch/ppc64/kernel/pSeries_smp.c
+++ b/arch/ppc64/kernel/pSeries_smp.c
@@ -272,6 +272,7 @@ static inline int __devinit smp_startup_cpu(unsigned int lcpu)
272 unsigned long start_here = __pa((u32)*((unsigned long *) 272 unsigned long start_here = __pa((u32)*((unsigned long *)
273 pSeries_secondary_smp_init)); 273 pSeries_secondary_smp_init));
274 unsigned int pcpu; 274 unsigned int pcpu;
275 int start_cpu;
275 276
276 if (cpu_isset(lcpu, of_spin_map)) 277 if (cpu_isset(lcpu, of_spin_map))
277 /* Already started by OF and sitting in spin loop */ 278 /* Already started by OF and sitting in spin loop */
@@ -282,12 +283,20 @@ static inline int __devinit smp_startup_cpu(unsigned int lcpu)
282 /* Fixup atomic count: it exited inside IRQ handler. */ 283 /* Fixup atomic count: it exited inside IRQ handler. */
283 paca[lcpu].__current->thread_info->preempt_count = 0; 284 paca[lcpu].__current->thread_info->preempt_count = 0;
284 285
285 status = rtas_call(rtas_token("start-cpu"), 3, 1, NULL, 286 /*
286 pcpu, start_here, lcpu); 287 * If the RTAS start-cpu token does not exist then presume the
288 * cpu is already spinning.
289 */
290 start_cpu = rtas_token("start-cpu");
291 if (start_cpu == RTAS_UNKNOWN_SERVICE)
292 return 1;
293
294 status = rtas_call(start_cpu, 3, 1, NULL, pcpu, start_here, lcpu);
287 if (status != 0) { 295 if (status != 0) {
288 printk(KERN_ERR "start-cpu failed: %i\n", status); 296 printk(KERN_ERR "start-cpu failed: %i\n", status);
289 return 0; 297 return 0;
290 } 298 }
299
291 return 1; 300 return 1;
292} 301}
293 302
diff --git a/arch/ppc64/kernel/pci.c b/arch/ppc64/kernel/pci.c
index 8447dcc2c2..861138ad09 100644
--- a/arch/ppc64/kernel/pci.c
+++ b/arch/ppc64/kernel/pci.c
@@ -51,6 +51,10 @@ unsigned long io_page_mask;
51 51
52EXPORT_SYMBOL(io_page_mask); 52EXPORT_SYMBOL(io_page_mask);
53 53
54#ifdef CONFIG_PPC_MULTIPLATFORM
55static void fixup_resource(struct resource *res, struct pci_dev *dev);
56static void do_bus_setup(struct pci_bus *bus);
57#endif
54 58
55unsigned int pcibios_assign_all_busses(void) 59unsigned int pcibios_assign_all_busses(void)
56{ 60{
@@ -225,10 +229,287 @@ static void __init pcibios_claim_of_setup(void)
225} 229}
226#endif 230#endif
227 231
232#ifdef CONFIG_PPC_MULTIPLATFORM
233static u32 get_int_prop(struct device_node *np, const char *name, u32 def)
234{
235 u32 *prop;
236 int len;
237
238 prop = (u32 *) get_property(np, name, &len);
239 if (prop && len >= 4)
240 return *prop;
241 return def;
242}
243
244static unsigned int pci_parse_of_flags(u32 addr0)
245{
246 unsigned int flags = 0;
247
248 if (addr0 & 0x02000000) {
249 flags |= IORESOURCE_MEM;
250 if (addr0 & 0x40000000)
251 flags |= IORESOURCE_PREFETCH;
252 } else if (addr0 & 0x01000000)
253 flags |= IORESOURCE_IO;
254 return flags;
255}
256
257#define GET_64BIT(prop, i) ((((u64) (prop)[(i)]) << 32) | (prop)[(i)+1])
258
259static void pci_parse_of_addrs(struct device_node *node, struct pci_dev *dev)
260{
261 u64 base, size;
262 unsigned int flags;
263 struct resource *res;
264 u32 *addrs, i;
265 int proplen;
266
267 addrs = (u32 *) get_property(node, "assigned-addresses", &proplen);
268 if (!addrs)
269 return;
270 for (; proplen >= 20; proplen -= 20, addrs += 5) {
271 flags = pci_parse_of_flags(addrs[0]);
272 if (!flags)
273 continue;
274 base = GET_64BIT(addrs, 1);
275 size = GET_64BIT(addrs, 3);
276 if (!size)
277 continue;
278 i = addrs[0] & 0xff;
279 if (PCI_BASE_ADDRESS_0 <= i && i <= PCI_BASE_ADDRESS_5) {
280 res = &dev->resource[(i - PCI_BASE_ADDRESS_0) >> 2];
281 } else if (i == dev->rom_base_reg) {
282 res = &dev->resource[PCI_ROM_RESOURCE];
283 flags |= IORESOURCE_READONLY | IORESOURCE_CACHEABLE;
284 } else {
285 printk(KERN_ERR "PCI: bad cfg reg num 0x%x\n", i);
286 continue;
287 }
288 res->start = base;
289 res->end = base + size - 1;
290 res->flags = flags;
291 res->name = pci_name(dev);
292 fixup_resource(res, dev);
293 }
294}
295
296static struct pci_dev *of_create_pci_dev(struct device_node *node,
297 struct pci_bus *bus, int devfn)
298{
299 struct pci_dev *dev;
300 const char *type;
301
302 dev = kmalloc(sizeof(struct pci_dev), GFP_KERNEL);
303 if (!dev)
304 return NULL;
305 type = get_property(node, "device_type", NULL);
306 if (type == NULL)
307 type = "";
308
309 memset(dev, 0, sizeof(struct pci_dev));
310 dev->bus = bus;
311 dev->sysdata = node;
312 dev->dev.parent = bus->bridge;
313 dev->dev.bus = &pci_bus_type;
314 dev->devfn = devfn;
315 dev->multifunction = 0; /* maybe a lie? */
316
317 dev->vendor = get_int_prop(node, "vendor-id", 0xffff);
318 dev->device = get_int_prop(node, "device-id", 0xffff);
319 dev->subsystem_vendor = get_int_prop(node, "subsystem-vendor-id", 0);
320 dev->subsystem_device = get_int_prop(node, "subsystem-id", 0);
321
322 dev->cfg_size = 256; /*pci_cfg_space_size(dev);*/
323
324 sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus),
325 dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
326 dev->class = get_int_prop(node, "class-code", 0);
327
328 dev->current_state = 4; /* unknown power state */
329
330 if (!strcmp(type, "pci")) {
331 /* a PCI-PCI bridge */
332 dev->hdr_type = PCI_HEADER_TYPE_BRIDGE;
333 dev->rom_base_reg = PCI_ROM_ADDRESS1;
334 } else if (!strcmp(type, "cardbus")) {
335 dev->hdr_type = PCI_HEADER_TYPE_CARDBUS;
336 } else {
337 dev->hdr_type = PCI_HEADER_TYPE_NORMAL;
338 dev->rom_base_reg = PCI_ROM_ADDRESS;
339 dev->irq = NO_IRQ;
340 if (node->n_intrs > 0) {
341 dev->irq = node->intrs[0].line;
342 pci_write_config_byte(dev, PCI_INTERRUPT_LINE,
343 dev->irq);
344 }
345 }
346
347 pci_parse_of_addrs(node, dev);
348
349 pci_device_add(dev, bus);
350
351 /* XXX pci_scan_msi_device(dev); */
352
353 return dev;
354}
355
356static void of_scan_pci_bridge(struct device_node *node, struct pci_dev *dev);
357
358static void __devinit of_scan_bus(struct device_node *node,
359 struct pci_bus *bus)
360{
361 struct device_node *child = NULL;
362 u32 *reg;
363 int reglen, devfn;
364 struct pci_dev *dev;
365
366 while ((child = of_get_next_child(node, child)) != NULL) {
367 reg = (u32 *) get_property(child, "reg", &reglen);
368 if (reg == NULL || reglen < 20)
369 continue;
370 devfn = (reg[0] >> 8) & 0xff;
371 /* create a new pci_dev for this device */
372 dev = of_create_pci_dev(child, bus, devfn);
373 if (!dev)
374 continue;
375 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
376 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
377 of_scan_pci_bridge(child, dev);
378 }
379
380 do_bus_setup(bus);
381}
382
383static void __devinit of_scan_pci_bridge(struct device_node *node,
384 struct pci_dev *dev)
385{
386 struct pci_bus *bus;
387 u32 *busrange, *ranges;
388 int len, i, mode;
389 struct resource *res;
390 unsigned int flags;
391 u64 size;
392
393 /* parse bus-range property */
394 busrange = (u32 *) get_property(node, "bus-range", &len);
395 if (busrange == NULL || len != 8) {
396 printk(KERN_ERR "Can't get bus-range for PCI-PCI bridge %s\n",
397 node->full_name);
398 return;
399 }
400 ranges = (u32 *) get_property(node, "ranges", &len);
401 if (ranges == NULL) {
402 printk(KERN_ERR "Can't get ranges for PCI-PCI bridge %s\n",
403 node->full_name);
404 return;
405 }
406
407 bus = pci_add_new_bus(dev->bus, dev, busrange[0]);
408 if (!bus) {
409 printk(KERN_ERR "Failed to create pci bus for %s\n",
410 node->full_name);
411 return;
412 }
413
414 bus->primary = dev->bus->number;
415 bus->subordinate = busrange[1];
416 bus->bridge_ctl = 0;
417 bus->sysdata = node;
418
419 /* parse ranges property */
420 /* PCI #address-cells == 3 and #size-cells == 2 always */
421 res = &dev->resource[PCI_BRIDGE_RESOURCES];
422 for (i = 0; i < PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES; ++i) {
423 res->flags = 0;
424 bus->resource[i] = res;
425 ++res;
426 }
427 i = 1;
428 for (; len >= 32; len -= 32, ranges += 8) {
429 flags = pci_parse_of_flags(ranges[0]);
430 size = GET_64BIT(ranges, 6);
431 if (flags == 0 || size == 0)
432 continue;
433 if (flags & IORESOURCE_IO) {
434 res = bus->resource[0];
435 if (res->flags) {
436 printk(KERN_ERR "PCI: ignoring extra I/O range"
437 " for bridge %s\n", node->full_name);
438 continue;
439 }
440 } else {
441 if (i >= PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES) {
442 printk(KERN_ERR "PCI: too many memory ranges"
443 " for bridge %s\n", node->full_name);
444 continue;
445 }
446 res = bus->resource[i];
447 ++i;
448 }
449 res->start = GET_64BIT(ranges, 1);
450 res->end = res->start + size - 1;
451 res->flags = flags;
452 fixup_resource(res, dev);
453 }
454 sprintf(bus->name, "PCI Bus %04x:%02x", pci_domain_nr(bus),
455 bus->number);
456
457 mode = PCI_PROBE_NORMAL;
458 if (ppc_md.pci_probe_mode)
459 mode = ppc_md.pci_probe_mode(bus);
460 if (mode == PCI_PROBE_DEVTREE)
461 of_scan_bus(node, bus);
462 else if (mode == PCI_PROBE_NORMAL)
463 pci_scan_child_bus(bus);
464}
465#endif /* CONFIG_PPC_MULTIPLATFORM */
466
467static void __devinit scan_phb(struct pci_controller *hose)
468{
469 struct pci_bus *bus;
470 struct device_node *node = hose->arch_data;
471 int i, mode;
472 struct resource *res;
473
474 bus = pci_create_bus(NULL, hose->first_busno, hose->ops, node);
475 if (bus == NULL) {
476 printk(KERN_ERR "Failed to create bus for PCI domain %04x\n",
477 hose->global_number);
478 return;
479 }
480 bus->secondary = hose->first_busno;
481 hose->bus = bus;
482
483 bus->resource[0] = res = &hose->io_resource;
484 if (res->flags && request_resource(&ioport_resource, res))
485 printk(KERN_ERR "Failed to request PCI IO region "
486 "on PCI domain %04x\n", hose->global_number);
487
488 for (i = 0; i < 3; ++i) {
489 res = &hose->mem_resources[i];
490 bus->resource[i+1] = res;
491 if (res->flags && request_resource(&iomem_resource, res))
492 printk(KERN_ERR "Failed to request PCI memory region "
493 "on PCI domain %04x\n", hose->global_number);
494 }
495
496 mode = PCI_PROBE_NORMAL;
497#ifdef CONFIG_PPC_MULTIPLATFORM
498 if (ppc_md.pci_probe_mode)
499 mode = ppc_md.pci_probe_mode(bus);
500 if (mode == PCI_PROBE_DEVTREE) {
501 bus->subordinate = hose->last_busno;
502 of_scan_bus(node, bus);
503 }
504#endif /* CONFIG_PPC_MULTIPLATFORM */
505 if (mode == PCI_PROBE_NORMAL)
506 hose->last_busno = bus->subordinate = pci_scan_child_bus(bus);
507 pci_bus_add_devices(bus);
508}
509
228static int __init pcibios_init(void) 510static int __init pcibios_init(void)
229{ 511{
230 struct pci_controller *hose, *tmp; 512 struct pci_controller *hose, *tmp;
231 struct pci_bus *bus;
232 513
233 /* For now, override phys_mem_access_prot. If we need it, 514 /* For now, override phys_mem_access_prot. If we need it,
234 * later, we may move that initialization to each ppc_md 515 * later, we may move that initialization to each ppc_md
@@ -242,13 +523,8 @@ static int __init pcibios_init(void)
242 printk("PCI: Probing PCI hardware\n"); 523 printk("PCI: Probing PCI hardware\n");
243 524
244 /* Scan all of the recorded PCI controllers. */ 525 /* Scan all of the recorded PCI controllers. */
245 list_for_each_entry_safe(hose, tmp, &hose_list, list_node) { 526 list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
246 hose->last_busno = 0xff; 527 scan_phb(hose);
247 bus = pci_scan_bus(hose->first_busno, hose->ops,
248 hose->arch_data);
249 hose->bus = bus;
250 hose->last_busno = bus->subordinate;
251 }
252 528
253#ifndef CONFIG_PPC_ISERIES 529#ifndef CONFIG_PPC_ISERIES
254 if (pci_probe_only) 530 if (pci_probe_only)
@@ -820,120 +1096,89 @@ void phbs_remap_io(void)
820/* 1096/*
821 * ppc64 can have multifunction devices that do not respond to function 0. 1097 * ppc64 can have multifunction devices that do not respond to function 0.
822 * In this case we must scan all functions. 1098 * In this case we must scan all functions.
1099 * XXX this can go now, we use the OF device tree in all the
1100 * cases that caused problems. -- paulus
823 */ 1101 */
824int pcibios_scan_all_fns(struct pci_bus *bus, int devfn) 1102int pcibios_scan_all_fns(struct pci_bus *bus, int devfn)
825{ 1103{
826 struct device_node *busdn, *dn;
827
828 if (bus->self)
829 busdn = pci_device_to_OF_node(bus->self);
830 else
831 busdn = bus->sysdata; /* must be a phb */
832
833 if (busdn == NULL)
834 return 0;
835
836 /*
837 * Check to see if there is any of the 8 functions are in the
838 * device tree. If they are then we need to scan all the
839 * functions of this slot.
840 */
841 for (dn = busdn->child; dn; dn = dn->sibling) {
842 struct pci_dn *pdn = dn->data;
843 if (pdn && (pdn->devfn >> 3) == (devfn >> 3))
844 return 1;
845 }
846
847 return 0; 1104 return 0;
848} 1105}
849 1106
1107static void __devinit fixup_resource(struct resource *res, struct pci_dev *dev)
1108{
1109 struct pci_controller *hose = pci_bus_to_host(dev->bus);
1110 unsigned long start, end, mask, offset;
1111
1112 if (res->flags & IORESOURCE_IO) {
1113 offset = (unsigned long)hose->io_base_virt - pci_io_base;
1114
1115 start = res->start += offset;
1116 end = res->end += offset;
1117
1118 /* Need to allow IO access to pages that are in the
1119 ISA range */
1120 if (start < MAX_ISA_PORT) {
1121 if (end > MAX_ISA_PORT)
1122 end = MAX_ISA_PORT;
1123
1124 start >>= PAGE_SHIFT;
1125 end >>= PAGE_SHIFT;
1126
1127 /* get the range of pages for the map */
1128 mask = ((1 << (end+1)) - 1) ^ ((1 << start) - 1);
1129 io_page_mask |= mask;
1130 }
1131 } else if (res->flags & IORESOURCE_MEM) {
1132 res->start += hose->pci_mem_offset;
1133 res->end += hose->pci_mem_offset;
1134 }
1135}
850 1136
851void __devinit pcibios_fixup_device_resources(struct pci_dev *dev, 1137void __devinit pcibios_fixup_device_resources(struct pci_dev *dev,
852 struct pci_bus *bus) 1138 struct pci_bus *bus)
853{ 1139{
854 /* Update device resources. */ 1140 /* Update device resources. */
855 struct pci_controller *hose = pci_bus_to_host(bus);
856 int i; 1141 int i;
857 1142
858 for (i = 0; i < PCI_NUM_RESOURCES; i++) { 1143 for (i = 0; i < PCI_NUM_RESOURCES; i++)
859 if (dev->resource[i].flags & IORESOURCE_IO) { 1144 if (dev->resource[i].flags)
860 unsigned long offset = (unsigned long)hose->io_base_virt 1145 fixup_resource(&dev->resource[i], dev);
861 - pci_io_base;
862 unsigned long start, end, mask;
863
864 start = dev->resource[i].start += offset;
865 end = dev->resource[i].end += offset;
866
867 /* Need to allow IO access to pages that are in the
868 ISA range */
869 if (start < MAX_ISA_PORT) {
870 if (end > MAX_ISA_PORT)
871 end = MAX_ISA_PORT;
872
873 start >>= PAGE_SHIFT;
874 end >>= PAGE_SHIFT;
875
876 /* get the range of pages for the map */
877 mask = ((1 << (end+1))-1) ^ ((1 << start)-1);
878 io_page_mask |= mask;
879 }
880 }
881 else if (dev->resource[i].flags & IORESOURCE_MEM) {
882 dev->resource[i].start += hose->pci_mem_offset;
883 dev->resource[i].end += hose->pci_mem_offset;
884 }
885 }
886} 1146}
887EXPORT_SYMBOL(pcibios_fixup_device_resources); 1147EXPORT_SYMBOL(pcibios_fixup_device_resources);
888 1148
889void __devinit pcibios_fixup_bus(struct pci_bus *bus) 1149static void __devinit do_bus_setup(struct pci_bus *bus)
890{ 1150{
891 struct pci_controller *hose = pci_bus_to_host(bus); 1151 struct pci_dev *dev;
892 struct pci_dev *dev = bus->self;
893 struct resource *res;
894 int i;
895 1152
896 if (!dev) { 1153 ppc_md.iommu_bus_setup(bus);
897 /* Root bus. */
898 1154
899 hose->bus = bus; 1155 list_for_each_entry(dev, &bus->devices, bus_list)
900 bus->resource[0] = res = &hose->io_resource; 1156 ppc_md.iommu_dev_setup(dev);
901 1157
902 if (res->flags && request_resource(&ioport_resource, res)) 1158 if (ppc_md.irq_bus_setup)
903 printk(KERN_ERR "Failed to request IO on " 1159 ppc_md.irq_bus_setup(bus);
904 "PCI domain %d\n", pci_domain_nr(bus)); 1160}
905 1161
906 for (i = 0; i < 3; ++i) { 1162void __devinit pcibios_fixup_bus(struct pci_bus *bus)
907 res = &hose->mem_resources[i]; 1163{
908 bus->resource[i+1] = res; 1164 struct pci_dev *dev = bus->self;
909 if (res->flags && request_resource(&iomem_resource, res)) 1165
910 printk(KERN_ERR "Failed to request MEM on " 1166 if (dev && pci_probe_only &&
911 "PCI domain %d\n", 1167 (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
912 pci_domain_nr(bus));
913 }
914 } else if (pci_probe_only &&
915 (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
916 /* This is a subordinate bridge */ 1168 /* This is a subordinate bridge */
917 1169
918 pci_read_bridge_bases(bus); 1170 pci_read_bridge_bases(bus);
919 pcibios_fixup_device_resources(dev, bus); 1171 pcibios_fixup_device_resources(dev, bus);
920 } 1172 }
921 1173
922 ppc_md.iommu_bus_setup(bus); 1174 do_bus_setup(bus);
923
924 list_for_each_entry(dev, &bus->devices, bus_list)
925 ppc_md.iommu_dev_setup(dev);
926
927 if (ppc_md.irq_bus_setup)
928 ppc_md.irq_bus_setup(bus);
929 1175
930 if (!pci_probe_only) 1176 if (!pci_probe_only)
931 return; 1177 return;
932 1178
933 list_for_each_entry(dev, &bus->devices, bus_list) { 1179 list_for_each_entry(dev, &bus->devices, bus_list)
934 if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI) 1180 if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI)
935 pcibios_fixup_device_resources(dev, bus); 1181 pcibios_fixup_device_resources(dev, bus);
936 }
937} 1182}
938EXPORT_SYMBOL(pcibios_fixup_bus); 1183EXPORT_SYMBOL(pcibios_fixup_bus);
939 1184
diff --git a/arch/ppc64/kernel/pmac_pci.c b/arch/ppc64/kernel/pmac_pci.c
index d37bff2d7d..dc40a0cad0 100644
--- a/arch/ppc64/kernel/pmac_pci.c
+++ b/arch/ppc64/kernel/pmac_pci.c
@@ -388,7 +388,7 @@ static void __init setup_u3_agp(struct pci_controller* hose)
388 * the reg address cell, we shall fix that by killing struct 388 * the reg address cell, we shall fix that by killing struct
389 * reg_property and using some accessor functions instead 389 * reg_property and using some accessor functions instead
390 */ 390 */
391 hose->first_busno = 0xf0; 391 hose->first_busno = 0xf0;
392 hose->last_busno = 0xff; 392 hose->last_busno = 0xff;
393 has_uninorth = 1; 393 has_uninorth = 1;
394 hose->ops = &macrisc_pci_ops; 394 hose->ops = &macrisc_pci_ops;
@@ -473,7 +473,7 @@ static void __init setup_u3_ht(struct pci_controller* hose)
473 continue; 473 continue;
474 } 474 }
475 cur++; 475 cur++;
476 DBG("U3/HT: hole, %d end at %08lx, %d start at %08lx\n", 476 DBG("U3/HT: hole, %d end at %08lx, %d start at %08lx\n",
477 cur-1, res->start - 1, cur, res->end + 1); 477 cur-1, res->start - 1, cur, res->end + 1);
478 hose->mem_resources[cur].name = np->full_name; 478 hose->mem_resources[cur].name = np->full_name;
479 hose->mem_resources[cur].flags = IORESOURCE_MEM; 479 hose->mem_resources[cur].flags = IORESOURCE_MEM;
@@ -603,24 +603,24 @@ static int __init add_bridge(struct device_node *dev)
603 char* disp_name; 603 char* disp_name;
604 int *bus_range; 604 int *bus_range;
605 int primary = 1; 605 int primary = 1;
606 struct property *of_prop; 606 struct property *of_prop;
607 607
608 DBG("Adding PCI host bridge %s\n", dev->full_name); 608 DBG("Adding PCI host bridge %s\n", dev->full_name);
609 609
610 bus_range = (int *) get_property(dev, "bus-range", &len); 610 bus_range = (int *) get_property(dev, "bus-range", &len);
611 if (bus_range == NULL || len < 2 * sizeof(int)) { 611 if (bus_range == NULL || len < 2 * sizeof(int)) {
612 printk(KERN_WARNING "Can't get bus-range for %s, assume bus 0\n", 612 printk(KERN_WARNING "Can't get bus-range for %s, assume bus 0\n",
613 dev->full_name); 613 dev->full_name);
614 } 614 }
615 615
616 hose = alloc_bootmem(sizeof(struct pci_controller)); 616 hose = alloc_bootmem(sizeof(struct pci_controller));
617 if (hose == NULL) 617 if (hose == NULL)
618 return -ENOMEM; 618 return -ENOMEM;
619 pci_setup_pci_controller(hose); 619 pci_setup_pci_controller(hose);
620 620
621 hose->arch_data = dev; 621 hose->arch_data = dev;
622 hose->first_busno = bus_range ? bus_range[0] : 0; 622 hose->first_busno = bus_range ? bus_range[0] : 0;
623 hose->last_busno = bus_range ? bus_range[1] : 0xff; 623 hose->last_busno = bus_range ? bus_range[1] : 0xff;
624 624
625 of_prop = alloc_bootmem(sizeof(struct property) + 625 of_prop = alloc_bootmem(sizeof(struct property) +
626 sizeof(hose->global_number)); 626 sizeof(hose->global_number));
@@ -634,24 +634,24 @@ static int __init add_bridge(struct device_node *dev)
634 } 634 }
635 635
636 disp_name = NULL; 636 disp_name = NULL;
637 if (device_is_compatible(dev, "u3-agp")) { 637 if (device_is_compatible(dev, "u3-agp")) {
638 setup_u3_agp(hose); 638 setup_u3_agp(hose);
639 disp_name = "U3-AGP"; 639 disp_name = "U3-AGP";
640 primary = 0; 640 primary = 0;
641 } else if (device_is_compatible(dev, "u3-ht")) { 641 } else if (device_is_compatible(dev, "u3-ht")) {
642 setup_u3_ht(hose); 642 setup_u3_ht(hose);
643 disp_name = "U3-HT"; 643 disp_name = "U3-HT";
644 primary = 1; 644 primary = 1;
645 } 645 }
646 printk(KERN_INFO "Found %s PCI host bridge. Firmware bus number: %d->%d\n", 646 printk(KERN_INFO "Found %s PCI host bridge. Firmware bus number: %d->%d\n",
647 disp_name, hose->first_busno, hose->last_busno); 647 disp_name, hose->first_busno, hose->last_busno);
648 648
649 /* Interpret the "ranges" property */ 649 /* Interpret the "ranges" property */
650 /* This also maps the I/O region and sets isa_io/mem_base */ 650 /* This also maps the I/O region and sets isa_io/mem_base */
651 pmac_process_bridge_OF_ranges(hose, dev, primary); 651 pmac_process_bridge_OF_ranges(hose, dev, primary);
652 652
653 /* Fixup "bus-range" OF property */ 653 /* Fixup "bus-range" OF property */
654 fixup_bus_range(dev); 654 fixup_bus_range(dev);
655 655
656 return 0; 656 return 0;
657} 657}
diff --git a/arch/ppc64/kernel/pmac_setup.c b/arch/ppc64/kernel/pmac_setup.c
index e7f695dcd8..325426c7be 100644
--- a/arch/ppc64/kernel/pmac_setup.c
+++ b/arch/ppc64/kernel/pmac_setup.c
@@ -477,6 +477,18 @@ static int __init pmac_probe(int platform)
477 return 1; 477 return 1;
478} 478}
479 479
480static int pmac_probe_mode(struct pci_bus *bus)
481{
482 struct device_node *node = bus->sysdata;
483
484 /* We need to use normal PCI probing for the AGP bus,
485 since the device for the AGP bridge isn't in the tree. */
486 if (bus->self == NULL && device_is_compatible(node, "u3-agp"))
487 return PCI_PROBE_NORMAL;
488
489 return PCI_PROBE_DEVTREE;
490}
491
480struct machdep_calls __initdata pmac_md = { 492struct machdep_calls __initdata pmac_md = {
481#ifdef CONFIG_HOTPLUG_CPU 493#ifdef CONFIG_HOTPLUG_CPU
482 .cpu_die = generic_mach_cpu_die, 494 .cpu_die = generic_mach_cpu_die,
@@ -488,6 +500,7 @@ struct machdep_calls __initdata pmac_md = {
488 .init_IRQ = pmac_init_IRQ, 500 .init_IRQ = pmac_init_IRQ,
489 .get_irq = mpic_get_irq, 501 .get_irq = mpic_get_irq,
490 .pcibios_fixup = pmac_pcibios_fixup, 502 .pcibios_fixup = pmac_pcibios_fixup,
503 .pci_probe_mode = pmac_probe_mode,
491 .restart = pmac_restart, 504 .restart = pmac_restart,
492 .power_off = pmac_power_off, 505 .power_off = pmac_power_off,
493 .halt = pmac_halt, 506 .halt = pmac_halt,
diff --git a/arch/ppc64/kernel/pmc.c b/arch/ppc64/kernel/pmc.c
index cdfec7438d..63d9481c3e 100644
--- a/arch/ppc64/kernel/pmc.c
+++ b/arch/ppc64/kernel/pmc.c
@@ -26,7 +26,7 @@ static void dummy_perf(struct pt_regs *regs)
26 mtspr(SPRN_MMCR0, mmcr0); 26 mtspr(SPRN_MMCR0, mmcr0);
27} 27}
28 28
29static spinlock_t pmc_owner_lock = SPIN_LOCK_UNLOCKED; 29static DEFINE_SPINLOCK(pmc_owner_lock);
30static void *pmc_owner_caller; /* mostly for debugging */ 30static void *pmc_owner_caller; /* mostly for debugging */
31perf_irq_t perf_irq = dummy_perf; 31perf_irq_t perf_irq = dummy_perf;
32 32
diff --git a/arch/ppc64/kernel/process.c b/arch/ppc64/kernel/process.c
index 7a7e027653..887005358e 100644
--- a/arch/ppc64/kernel/process.c
+++ b/arch/ppc64/kernel/process.c
@@ -54,6 +54,7 @@
54#include <asm/sections.h> 54#include <asm/sections.h>
55#include <asm/tlbflush.h> 55#include <asm/tlbflush.h>
56#include <asm/time.h> 56#include <asm/time.h>
57#include <asm/plpar_wrappers.h>
57 58
58#ifndef CONFIG_SMP 59#ifndef CONFIG_SMP
59struct task_struct *last_task_used_math = NULL; 60struct task_struct *last_task_used_math = NULL;
@@ -163,7 +164,30 @@ int dump_task_altivec(struct pt_regs *regs, elf_vrregset_t *vrregs)
163 164
164#endif /* CONFIG_ALTIVEC */ 165#endif /* CONFIG_ALTIVEC */
165 166
167static void set_dabr_spr(unsigned long val)
168{
169 mtspr(SPRN_DABR, val);
170}
171
172int set_dabr(unsigned long dabr)
173{
174 int ret = 0;
175
176 if (firmware_has_feature(FW_FEATURE_XDABR)) {
177 /* We want to catch accesses from kernel and userspace */
178 unsigned long flags = H_DABRX_KERNEL|H_DABRX_USER;
179 ret = plpar_set_xdabr(dabr, flags);
180 } else if (firmware_has_feature(FW_FEATURE_DABR)) {
181 ret = plpar_set_dabr(dabr);
182 } else {
183 set_dabr_spr(dabr);
184 }
185
186 return ret;
187}
188
166DEFINE_PER_CPU(struct cpu_usage, cpu_usage_array); 189DEFINE_PER_CPU(struct cpu_usage, cpu_usage_array);
190static DEFINE_PER_CPU(unsigned long, current_dabr);
167 191
168struct task_struct *__switch_to(struct task_struct *prev, 192struct task_struct *__switch_to(struct task_struct *prev,
169 struct task_struct *new) 193 struct task_struct *new)
@@ -198,6 +222,11 @@ struct task_struct *__switch_to(struct task_struct *prev,
198 new->thread.regs->msr |= MSR_VEC; 222 new->thread.regs->msr |= MSR_VEC;
199#endif /* CONFIG_ALTIVEC */ 223#endif /* CONFIG_ALTIVEC */
200 224
225 if (unlikely(__get_cpu_var(current_dabr) != new->thread.dabr)) {
226 set_dabr(new->thread.dabr);
227 __get_cpu_var(current_dabr) = new->thread.dabr;
228 }
229
201 flush_tlb_pending(); 230 flush_tlb_pending();
202 231
203 new_thread = &new->thread; 232 new_thread = &new->thread;
@@ -334,6 +363,11 @@ void flush_thread(void)
334 last_task_used_altivec = NULL; 363 last_task_used_altivec = NULL;
335#endif /* CONFIG_ALTIVEC */ 364#endif /* CONFIG_ALTIVEC */
336#endif /* CONFIG_SMP */ 365#endif /* CONFIG_SMP */
366
367 if (current->thread.dabr) {
368 current->thread.dabr = 0;
369 set_dabr(0);
370 }
337} 371}
338 372
339void 373void
diff --git a/arch/ppc64/kernel/ptrace.c b/arch/ppc64/kernel/ptrace.c
index 2993f108d9..85ed3188a9 100644
--- a/arch/ppc64/kernel/ptrace.c
+++ b/arch/ppc64/kernel/ptrace.c
@@ -17,6 +17,7 @@
17 * this archive for more details. 17 * this archive for more details.
18 */ 18 */
19 19
20#include <linux/config.h>
20#include <linux/kernel.h> 21#include <linux/kernel.h>
21#include <linux/sched.h> 22#include <linux/sched.h>
22#include <linux/mm.h> 23#include <linux/mm.h>
@@ -206,6 +207,19 @@ int sys_ptrace(long request, long pid, long addr, long data)
206 break; 207 break;
207 } 208 }
208 209
210 case PTRACE_GET_DEBUGREG: {
211 ret = -EINVAL;
212 /* We only support one DABR and no IABRS at the moment */
213 if (addr > 0)
214 break;
215 ret = put_user(child->thread.dabr,
216 (unsigned long __user *)data);
217 break;
218 }
219
220 case PTRACE_SET_DEBUGREG:
221 ret = ptrace_set_debugreg(child, addr, data);
222
209 case PTRACE_DETACH: 223 case PTRACE_DETACH:
210 ret = ptrace_detach(child, data); 224 ret = ptrace_detach(child, data);
211 break; 225 break;
@@ -274,6 +288,20 @@ int sys_ptrace(long request, long pid, long addr, long data)
274 break; 288 break;
275 } 289 }
276 290
291#ifdef CONFIG_ALTIVEC
292 case PTRACE_GETVRREGS:
293 /* Get the child altivec register state. */
294 flush_altivec_to_thread(child);
295 ret = get_vrregs((unsigned long __user *)data, child);
296 break;
297
298 case PTRACE_SETVRREGS:
299 /* Set the child altivec register state. */
300 flush_altivec_to_thread(child);
301 ret = set_vrregs(child, (unsigned long __user *)data);
302 break;
303#endif
304
277 default: 305 default:
278 ret = ptrace_request(child, request, addr, data); 306 ret = ptrace_request(child, request, addr, data);
279 break; 307 break;
diff --git a/arch/ppc64/kernel/ptrace32.c b/arch/ppc64/kernel/ptrace32.c
index 16436426c7..fb8c22d608 100644
--- a/arch/ppc64/kernel/ptrace32.c
+++ b/arch/ppc64/kernel/ptrace32.c
@@ -17,6 +17,7 @@
17 * this archive for more details. 17 * this archive for more details.
18 */ 18 */
19 19
20#include <linux/config.h>
20#include <linux/kernel.h> 21#include <linux/kernel.h>
21#include <linux/sched.h> 22#include <linux/sched.h>
22#include <linux/mm.h> 23#include <linux/mm.h>
@@ -337,6 +338,19 @@ int sys32_ptrace(long request, long pid, unsigned long addr, unsigned long data)
337 break; 338 break;
338 } 339 }
339 340
341 case PTRACE_GET_DEBUGREG: {
342 ret = -EINVAL;
343 /* We only support one DABR and no IABRS at the moment */
344 if (addr > 0)
345 break;
346 ret = put_user(child->thread.dabr, (u32 __user *)data);
347 break;
348 }
349
350 case PTRACE_SET_DEBUGREG:
351 ret = ptrace_set_debugreg(child, addr, data);
352 break;
353
340 case PTRACE_DETACH: 354 case PTRACE_DETACH:
341 ret = ptrace_detach(child, data); 355 ret = ptrace_detach(child, data);
342 break; 356 break;
@@ -405,9 +419,23 @@ int sys32_ptrace(long request, long pid, unsigned long addr, unsigned long data)
405 break; 419 break;
406 } 420 }
407 421
408 case PTRACE_GETEVENTMSG: 422 case PTRACE_GETEVENTMSG:
409 ret = put_user(child->ptrace_message, (unsigned int __user *) data); 423 ret = put_user(child->ptrace_message, (unsigned int __user *) data);
410 break; 424 break;
425
426#ifdef CONFIG_ALTIVEC
427 case PTRACE_GETVRREGS:
428 /* Get the child altivec register state. */
429 flush_altivec_to_thread(child);
430 ret = get_vrregs((unsigned long __user *)data, child);
431 break;
432
433 case PTRACE_SETVRREGS:
434 /* Set the child altivec register state. */
435 flush_altivec_to_thread(child);
436 ret = set_vrregs(child, (unsigned long __user *)data);
437 break;
438#endif
411 439
412 default: 440 default:
413 ret = ptrace_request(child, request, addr, data); 441 ret = ptrace_request(child, request, addr, data);
diff --git a/arch/ppc64/kernel/ras.c b/arch/ppc64/kernel/ras.c
index 3c00f7bfc1..41b97dc9cc 100644
--- a/arch/ppc64/kernel/ras.c
+++ b/arch/ppc64/kernel/ras.c
@@ -59,8 +59,6 @@ char mce_data_buf[RTAS_ERROR_LOG_MAX]
59/* This is true if we are using the firmware NMI handler (typically LPAR) */ 59/* This is true if we are using the firmware NMI handler (typically LPAR) */
60extern int fwnmi_active; 60extern int fwnmi_active;
61 61
62extern void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr);
63
64static int ras_get_sensor_state_token; 62static int ras_get_sensor_state_token;
65static int ras_check_exception_token; 63static int ras_check_exception_token;
66 64
diff --git a/arch/ppc64/kernel/setup.c b/arch/ppc64/kernel/setup.c
index bfa8791c98..5ac48bd648 100644
--- a/arch/ppc64/kernel/setup.c
+++ b/arch/ppc64/kernel/setup.c
@@ -1064,8 +1064,6 @@ void __init setup_arch(char **cmdline_p)
1064#define PPC64_LINUX_FUNCTION 0x0f000000 1064#define PPC64_LINUX_FUNCTION 0x0f000000
1065#define PPC64_IPL_MESSAGE 0xc0000000 1065#define PPC64_IPL_MESSAGE 0xc0000000
1066#define PPC64_TERM_MESSAGE 0xb0000000 1066#define PPC64_TERM_MESSAGE 0xb0000000
1067#define PPC64_ATTN_MESSAGE 0xa0000000
1068#define PPC64_DUMP_MESSAGE 0xd0000000
1069 1067
1070static void ppc64_do_msg(unsigned int src, const char *msg) 1068static void ppc64_do_msg(unsigned int src, const char *msg)
1071{ 1069{
@@ -1093,20 +1091,6 @@ void ppc64_terminate_msg(unsigned int src, const char *msg)
1093 printk("[terminate]%04x %s\n", src, msg); 1091 printk("[terminate]%04x %s\n", src, msg);
1094} 1092}
1095 1093
1096/* Print something that needs attention (device error, etc) */
1097void ppc64_attention_msg(unsigned int src, const char *msg)
1098{
1099 ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_ATTN_MESSAGE|src, msg);
1100 printk("[attention]%04x %s\n", src, msg);
1101}
1102
1103/* Print a dump progress message. */
1104void ppc64_dump_msg(unsigned int src, const char *msg)
1105{
1106 ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_DUMP_MESSAGE|src, msg);
1107 printk("[dump]%04x %s\n", src, msg);
1108}
1109
1110/* This should only be called on processor 0 during calibrate decr */ 1094/* This should only be called on processor 0 during calibrate decr */
1111void __init setup_default_decr(void) 1095void __init setup_default_decr(void)
1112{ 1096{
diff --git a/arch/ppc64/kernel/signal.c b/arch/ppc64/kernel/signal.c
index 49a79a55c3..347112cca3 100644
--- a/arch/ppc64/kernel/signal.c
+++ b/arch/ppc64/kernel/signal.c
@@ -550,6 +550,15 @@ int do_signal(sigset_t *oldset, struct pt_regs *regs)
550 /* Whee! Actually deliver the signal. */ 550 /* Whee! Actually deliver the signal. */
551 if (TRAP(regs) == 0x0C00) 551 if (TRAP(regs) == 0x0C00)
552 syscall_restart(regs, &ka); 552 syscall_restart(regs, &ka);
553
554 /*
555 * Reenable the DABR before delivering the signal to
556 * user space. The DABR will have been cleared if it
557 * triggered inside the kernel.
558 */
559 if (current->thread.dabr)
560 set_dabr(current->thread.dabr);
561
553 return handle_signal(signr, &ka, &info, oldset, regs); 562 return handle_signal(signr, &ka, &info, oldset, regs);
554 } 563 }
555 564
diff --git a/arch/ppc64/kernel/signal32.c b/arch/ppc64/kernel/signal32.c
index 46f4d6cc7f..a8b7a5a56b 100644
--- a/arch/ppc64/kernel/signal32.c
+++ b/arch/ppc64/kernel/signal32.c
@@ -970,6 +970,14 @@ int do_signal32(sigset_t *oldset, struct pt_regs *regs)
970 newsp = regs->gpr[1]; 970 newsp = regs->gpr[1];
971 newsp &= ~0xfUL; 971 newsp &= ~0xfUL;
972 972
973 /*
974 * Reenable the DABR before delivering the signal to
975 * user space. The DABR will have been cleared if it
976 * triggered inside the kernel.
977 */
978 if (current->thread.dabr)
979 set_dabr(current->thread.dabr);
980
973 /* Whee! Actually deliver the signal. */ 981 /* Whee! Actually deliver the signal. */
974 if (ka.sa.sa_flags & SA_SIGINFO) 982 if (ka.sa.sa_flags & SA_SIGINFO)
975 ret = handle_rt_signal32(signr, &ka, &info, oldset, regs, newsp); 983 ret = handle_rt_signal32(signr, &ka, &info, oldset, regs, newsp);
diff --git a/arch/ppc64/kernel/vdso32/cacheflush.S b/arch/ppc64/kernel/vdso32/cacheflush.S
index 0ed7ea7217..c8db993574 100644
--- a/arch/ppc64/kernel/vdso32/cacheflush.S
+++ b/arch/ppc64/kernel/vdso32/cacheflush.S
@@ -13,7 +13,7 @@
13#include <asm/processor.h> 13#include <asm/processor.h>
14#include <asm/ppc_asm.h> 14#include <asm/ppc_asm.h>
15#include <asm/vdso.h> 15#include <asm/vdso.h>
16#include <asm/offsets.h> 16#include <asm/asm-offsets.h>
17 17
18 .text 18 .text
19 19
diff --git a/arch/ppc64/kernel/vdso32/datapage.S b/arch/ppc64/kernel/vdso32/datapage.S
index 29b6bd32e1..4f4eb0be39 100644
--- a/arch/ppc64/kernel/vdso32/datapage.S
+++ b/arch/ppc64/kernel/vdso32/datapage.S
@@ -12,7 +12,7 @@
12#include <linux/config.h> 12#include <linux/config.h>
13#include <asm/processor.h> 13#include <asm/processor.h>
14#include <asm/ppc_asm.h> 14#include <asm/ppc_asm.h>
15#include <asm/offsets.h> 15#include <asm/asm-offsets.h>
16#include <asm/unistd.h> 16#include <asm/unistd.h>
17#include <asm/vdso.h> 17#include <asm/vdso.h>
18 18
diff --git a/arch/ppc64/kernel/vdso32/gettimeofday.S b/arch/ppc64/kernel/vdso32/gettimeofday.S
index 2b48bf1fb1..07f1c1c650 100644
--- a/arch/ppc64/kernel/vdso32/gettimeofday.S
+++ b/arch/ppc64/kernel/vdso32/gettimeofday.S
@@ -13,7 +13,7 @@
13#include <asm/processor.h> 13#include <asm/processor.h>
14#include <asm/ppc_asm.h> 14#include <asm/ppc_asm.h>
15#include <asm/vdso.h> 15#include <asm/vdso.h>
16#include <asm/offsets.h> 16#include <asm/asm-offsets.h>
17#include <asm/unistd.h> 17#include <asm/unistd.h>
18 18
19 .text 19 .text
diff --git a/arch/ppc64/kernel/vdso64/cacheflush.S b/arch/ppc64/kernel/vdso64/cacheflush.S
index e0725b7b70..d4a0ad28d5 100644
--- a/arch/ppc64/kernel/vdso64/cacheflush.S
+++ b/arch/ppc64/kernel/vdso64/cacheflush.S
@@ -13,7 +13,7 @@
13#include <asm/processor.h> 13#include <asm/processor.h>
14#include <asm/ppc_asm.h> 14#include <asm/ppc_asm.h>
15#include <asm/vdso.h> 15#include <asm/vdso.h>
16#include <asm/offsets.h> 16#include <asm/asm-offsets.h>
17 17
18 .text 18 .text
19 19
diff --git a/arch/ppc64/kernel/vdso64/datapage.S b/arch/ppc64/kernel/vdso64/datapage.S
index 18afd971c9..ed6e599ae8 100644
--- a/arch/ppc64/kernel/vdso64/datapage.S
+++ b/arch/ppc64/kernel/vdso64/datapage.S
@@ -12,7 +12,7 @@
12#include <linux/config.h> 12#include <linux/config.h>
13#include <asm/processor.h> 13#include <asm/processor.h>
14#include <asm/ppc_asm.h> 14#include <asm/ppc_asm.h>
15#include <asm/offsets.h> 15#include <asm/asm-offsets.h>
16#include <asm/unistd.h> 16#include <asm/unistd.h>
17#include <asm/vdso.h> 17#include <asm/vdso.h>
18 18
diff --git a/arch/ppc64/kernel/vdso64/gettimeofday.S b/arch/ppc64/kernel/vdso64/gettimeofday.S
index ed3f970ff0..f6df802857 100644
--- a/arch/ppc64/kernel/vdso64/gettimeofday.S
+++ b/arch/ppc64/kernel/vdso64/gettimeofday.S
@@ -14,7 +14,7 @@
14#include <asm/processor.h> 14#include <asm/processor.h>
15#include <asm/ppc_asm.h> 15#include <asm/ppc_asm.h>
16#include <asm/vdso.h> 16#include <asm/vdso.h>
17#include <asm/offsets.h> 17#include <asm/asm-offsets.h>
18 18
19 .text 19 .text
20/* 20/*
diff --git a/arch/ppc64/kernel/xics.c b/arch/ppc64/kernel/xics.c
index d9dc6f28d0..daf93885dc 100644
--- a/arch/ppc64/kernel/xics.c
+++ b/arch/ppc64/kernel/xics.c
@@ -38,7 +38,7 @@ static void xics_mask_and_ack_irq(unsigned int irq);
38static void xics_end_irq(unsigned int irq); 38static void xics_end_irq(unsigned int irq);
39static void xics_set_affinity(unsigned int irq_nr, cpumask_t cpumask); 39static void xics_set_affinity(unsigned int irq_nr, cpumask_t cpumask);
40 40
41struct hw_interrupt_type xics_pic = { 41static struct hw_interrupt_type xics_pic = {
42 .typename = " XICS ", 42 .typename = " XICS ",
43 .startup = xics_startup, 43 .startup = xics_startup,
44 .enable = xics_enable_irq, 44 .enable = xics_enable_irq,
@@ -48,7 +48,7 @@ struct hw_interrupt_type xics_pic = {
48 .set_affinity = xics_set_affinity 48 .set_affinity = xics_set_affinity
49}; 49};
50 50
51struct hw_interrupt_type xics_8259_pic = { 51static struct hw_interrupt_type xics_8259_pic = {
52 .typename = " XICS/8259", 52 .typename = " XICS/8259",
53 .ack = xics_mask_and_ack_irq, 53 .ack = xics_mask_and_ack_irq,
54}; 54};
@@ -89,9 +89,8 @@ static struct xics_ipl __iomem *xics_per_cpu[NR_CPUS];
89static int xics_irq_8259_cascade = 0; 89static int xics_irq_8259_cascade = 0;
90static int xics_irq_8259_cascade_real = 0; 90static int xics_irq_8259_cascade_real = 0;
91static unsigned int default_server = 0xFF; 91static unsigned int default_server = 0xFF;
92/* also referenced in smp.c... */ 92static unsigned int default_distrib_server = 0;
93unsigned int default_distrib_server = 0; 93static unsigned int interrupt_server_size = 8;
94unsigned int interrupt_server_size = 8;
95 94
96/* 95/*
97 * XICS only has a single IPI, so encode the messages per CPU 96 * XICS only has a single IPI, so encode the messages per CPU
@@ -99,10 +98,10 @@ unsigned int interrupt_server_size = 8;
99struct xics_ipi_struct xics_ipi_message[NR_CPUS] __cacheline_aligned; 98struct xics_ipi_struct xics_ipi_message[NR_CPUS] __cacheline_aligned;
100 99
101/* RTAS service tokens */ 100/* RTAS service tokens */
102int ibm_get_xive; 101static int ibm_get_xive;
103int ibm_set_xive; 102static int ibm_set_xive;
104int ibm_int_on; 103static int ibm_int_on;
105int ibm_int_off; 104static int ibm_int_off;
106 105
107typedef struct { 106typedef struct {
108 int (*xirr_info_get)(int cpu); 107 int (*xirr_info_get)(int cpu);
@@ -284,16 +283,17 @@ static void xics_enable_irq(unsigned int virq)
284 call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq, server, 283 call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq, server,
285 DEFAULT_PRIORITY); 284 DEFAULT_PRIORITY);
286 if (call_status != 0) { 285 if (call_status != 0) {
287 printk(KERN_ERR "xics_enable_irq: irq=%d: ibm_set_xive " 286 printk(KERN_ERR "xics_enable_irq: irq=%u: ibm_set_xive "
288 "returned %x\n", irq, call_status); 287 "returned %d\n", irq, call_status);
288 printk("set_xive %x, server %x\n", ibm_set_xive, server);
289 return; 289 return;
290 } 290 }
291 291
292 /* Now unmask the interrupt (often a no-op) */ 292 /* Now unmask the interrupt (often a no-op) */
293 call_status = rtas_call(ibm_int_on, 1, 1, NULL, irq); 293 call_status = rtas_call(ibm_int_on, 1, 1, NULL, irq);
294 if (call_status != 0) { 294 if (call_status != 0) {
295 printk(KERN_ERR "xics_enable_irq: irq=%d: ibm_int_on " 295 printk(KERN_ERR "xics_enable_irq: irq=%u: ibm_int_on "
296 "returned %x\n", irq, call_status); 296 "returned %d\n", irq, call_status);
297 return; 297 return;
298 } 298 }
299} 299}
@@ -308,8 +308,8 @@ static void xics_disable_real_irq(unsigned int irq)
308 308
309 call_status = rtas_call(ibm_int_off, 1, 1, NULL, irq); 309 call_status = rtas_call(ibm_int_off, 1, 1, NULL, irq);
310 if (call_status != 0) { 310 if (call_status != 0) {
311 printk(KERN_ERR "xics_disable_real_irq: irq=%d: " 311 printk(KERN_ERR "xics_disable_real_irq: irq=%u: "
312 "ibm_int_off returned %x\n", irq, call_status); 312 "ibm_int_off returned %d\n", irq, call_status);
313 return; 313 return;
314 } 314 }
315 315
@@ -317,8 +317,8 @@ static void xics_disable_real_irq(unsigned int irq)
317 /* Have to set XIVE to 0xff to be able to remove a slot */ 317 /* Have to set XIVE to 0xff to be able to remove a slot */
318 call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq, server, 0xff); 318 call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq, server, 0xff);
319 if (call_status != 0) { 319 if (call_status != 0) {
320 printk(KERN_ERR "xics_disable_irq: irq=%d: ibm_set_xive(0xff)" 320 printk(KERN_ERR "xics_disable_irq: irq=%u: ibm_set_xive(0xff)"
321 " returned %x\n", irq, call_status); 321 " returned %d\n", irq, call_status);
322 return; 322 return;
323 } 323 }
324} 324}
@@ -380,7 +380,7 @@ int xics_get_irq(struct pt_regs *regs)
380 if (irq == NO_IRQ) 380 if (irq == NO_IRQ)
381 irq = real_irq_to_virt_slowpath(vec); 381 irq = real_irq_to_virt_slowpath(vec);
382 if (irq == NO_IRQ) { 382 if (irq == NO_IRQ) {
383 printk(KERN_ERR "Interrupt %d (real) is invalid," 383 printk(KERN_ERR "Interrupt %u (real) is invalid,"
384 " disabling it.\n", vec); 384 " disabling it.\n", vec);
385 xics_disable_real_irq(vec); 385 xics_disable_real_irq(vec);
386 } else 386 } else
@@ -622,7 +622,7 @@ static void xics_set_affinity(unsigned int virq, cpumask_t cpumask)
622 status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq); 622 status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
623 623
624 if (status) { 624 if (status) {
625 printk(KERN_ERR "xics_set_affinity: irq=%d ibm,get-xive " 625 printk(KERN_ERR "xics_set_affinity: irq=%u ibm,get-xive "
626 "returns %d\n", irq, status); 626 "returns %d\n", irq, status);
627 return; 627 return;
628 } 628 }
@@ -641,7 +641,7 @@ static void xics_set_affinity(unsigned int virq, cpumask_t cpumask)
641 irq, newmask, xics_status[1]); 641 irq, newmask, xics_status[1]);
642 642
643 if (status) { 643 if (status) {
644 printk(KERN_ERR "xics_set_affinity: irq=%d ibm,set-xive " 644 printk(KERN_ERR "xics_set_affinity: irq=%u ibm,set-xive "
645 "returns %d\n", irq, status); 645 "returns %d\n", irq, status);
646 return; 646 return;
647 } 647 }
@@ -720,7 +720,7 @@ void xics_migrate_irqs_away(void)
720 720
721 status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq); 721 status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq);
722 if (status) { 722 if (status) {
723 printk(KERN_ERR "migrate_irqs_away: irq=%d " 723 printk(KERN_ERR "migrate_irqs_away: irq=%u "
724 "ibm,get-xive returns %d\n", 724 "ibm,get-xive returns %d\n",
725 virq, status); 725 virq, status);
726 goto unlock; 726 goto unlock;
@@ -734,7 +734,7 @@ void xics_migrate_irqs_away(void)
734 if (xics_status[0] != get_hard_smp_processor_id(cpu)) 734 if (xics_status[0] != get_hard_smp_processor_id(cpu))
735 goto unlock; 735 goto unlock;
736 736
737 printk(KERN_WARNING "IRQ %d affinity broken off cpu %u\n", 737 printk(KERN_WARNING "IRQ %u affinity broken off cpu %u\n",
738 virq, cpu); 738 virq, cpu);
739 739
740 /* Reset affinity to all cpus */ 740 /* Reset affinity to all cpus */
diff --git a/arch/ppc64/lib/dec_and_lock.c b/arch/ppc64/lib/dec_and_lock.c
index 6e8d859170..7b9d4da5cf 100644
--- a/arch/ppc64/lib/dec_and_lock.c
+++ b/arch/ppc64/lib/dec_and_lock.c
@@ -20,14 +20,7 @@
20 * has a cmpxchg, and where atomic->value is an int holding 20 * has a cmpxchg, and where atomic->value is an int holding
21 * the value of the atomic (i.e. the high bits aren't used 21 * the value of the atomic (i.e. the high bits aren't used
22 * for a lock or anything like that). 22 * for a lock or anything like that).
23 *
24 * N.B. ATOMIC_DEC_AND_LOCK gets defined in include/linux/spinlock.h
25 * if spinlocks are empty and thus atomic_dec_and_lock is defined
26 * to be atomic_dec_and_test - in that case we don't need it
27 * defined here as well.
28 */ 23 */
29
30#ifndef ATOMIC_DEC_AND_LOCK
31int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock) 24int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
32{ 25{
33 int counter; 26 int counter;
@@ -52,4 +45,3 @@ int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
52} 45}
53 46
54EXPORT_SYMBOL(_atomic_dec_and_lock); 47EXPORT_SYMBOL(_atomic_dec_and_lock);
55#endif /* ATOMIC_DEC_AND_LOCK */
diff --git a/arch/ppc64/lib/locks.c b/arch/ppc64/lib/locks.c
index ef70ef91ab..033643ab69 100644
--- a/arch/ppc64/lib/locks.c
+++ b/arch/ppc64/lib/locks.c
@@ -23,12 +23,12 @@
23/* waiting for a spinlock... */ 23/* waiting for a spinlock... */
24#if defined(CONFIG_PPC_SPLPAR) || defined(CONFIG_PPC_ISERIES) 24#if defined(CONFIG_PPC_SPLPAR) || defined(CONFIG_PPC_ISERIES)
25 25
26void __spin_yield(spinlock_t *lock) 26void __spin_yield(raw_spinlock_t *lock)
27{ 27{
28 unsigned int lock_value, holder_cpu, yield_count; 28 unsigned int lock_value, holder_cpu, yield_count;
29 struct paca_struct *holder_paca; 29 struct paca_struct *holder_paca;
30 30
31 lock_value = lock->lock; 31 lock_value = lock->slock;
32 if (lock_value == 0) 32 if (lock_value == 0)
33 return; 33 return;
34 holder_cpu = lock_value & 0xffff; 34 holder_cpu = lock_value & 0xffff;
@@ -38,7 +38,7 @@ void __spin_yield(spinlock_t *lock)
38 if ((yield_count & 1) == 0) 38 if ((yield_count & 1) == 0)
39 return; /* virtual cpu is currently running */ 39 return; /* virtual cpu is currently running */
40 rmb(); 40 rmb();
41 if (lock->lock != lock_value) 41 if (lock->slock != lock_value)
42 return; /* something has changed */ 42 return; /* something has changed */
43#ifdef CONFIG_PPC_ISERIES 43#ifdef CONFIG_PPC_ISERIES
44 HvCall2(HvCallBaseYieldProcessor, HvCall_YieldToProc, 44 HvCall2(HvCallBaseYieldProcessor, HvCall_YieldToProc,
@@ -54,7 +54,7 @@ void __spin_yield(spinlock_t *lock)
54 * This turns out to be the same for read and write locks, since 54 * This turns out to be the same for read and write locks, since
55 * we only know the holder if it is write-locked. 55 * we only know the holder if it is write-locked.
56 */ 56 */
57void __rw_yield(rwlock_t *rw) 57void __rw_yield(raw_rwlock_t *rw)
58{ 58{
59 int lock_value; 59 int lock_value;
60 unsigned int holder_cpu, yield_count; 60 unsigned int holder_cpu, yield_count;
@@ -82,9 +82,9 @@ void __rw_yield(rwlock_t *rw)
82} 82}
83#endif 83#endif
84 84
85void spin_unlock_wait(spinlock_t *lock) 85void __raw_spin_unlock_wait(raw_spinlock_t *lock)
86{ 86{
87 while (lock->lock) { 87 while (lock->slock) {
88 HMT_low(); 88 HMT_low();
89 if (SHARED_PROCESSOR) 89 if (SHARED_PROCESSOR)
90 __spin_yield(lock); 90 __spin_yield(lock);
@@ -92,4 +92,4 @@ void spin_unlock_wait(spinlock_t *lock)
92 HMT_medium(); 92 HMT_medium();
93} 93}
94 94
95EXPORT_SYMBOL(spin_unlock_wait); 95EXPORT_SYMBOL(__raw_spin_unlock_wait);
diff --git a/arch/ppc64/mm/fault.c b/arch/ppc64/mm/fault.c
index 772f0714a5..7fbc68bbb7 100644
--- a/arch/ppc64/mm/fault.c
+++ b/arch/ppc64/mm/fault.c
@@ -77,6 +77,28 @@ static int store_updates_sp(struct pt_regs *regs)
77 return 0; 77 return 0;
78} 78}
79 79
80static void do_dabr(struct pt_regs *regs, unsigned long error_code)
81{
82 siginfo_t info;
83
84 if (notify_die(DIE_DABR_MATCH, "dabr_match", regs, error_code,
85 11, SIGSEGV) == NOTIFY_STOP)
86 return;
87
88 if (debugger_dabr_match(regs))
89 return;
90
91 /* Clear the DABR */
92 set_dabr(0);
93
94 /* Deliver the signal to userspace */
95 info.si_signo = SIGTRAP;
96 info.si_errno = 0;
97 info.si_code = TRAP_HWBKPT;
98 info.si_addr = (void __user *)regs->nip;
99 force_sig_info(SIGTRAP, &info, current);
100}
101
80/* 102/*
81 * The error_code parameter is 103 * The error_code parameter is
82 * - DSISR for a non-SLB data access fault, 104 * - DSISR for a non-SLB data access fault,
@@ -111,12 +133,9 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
111 if (!user_mode(regs) && (address >= TASK_SIZE)) 133 if (!user_mode(regs) && (address >= TASK_SIZE))
112 return SIGSEGV; 134 return SIGSEGV;
113 135
114 if (error_code & DSISR_DABRMATCH) { 136 if (error_code & DSISR_DABRMATCH) {
115 if (notify_die(DIE_DABR_MATCH, "dabr_match", regs, error_code, 137 do_dabr(regs, error_code);
116 11, SIGSEGV) == NOTIFY_STOP) 138 return 0;
117 return 0;
118 if (debugger_dabr_match(regs))
119 return 0;
120 } 139 }
121 140
122 if (in_atomic() || mm == NULL) { 141 if (in_atomic() || mm == NULL) {
diff --git a/arch/ppc64/mm/hash_low.S b/arch/ppc64/mm/hash_low.S
index 35eb49e1b8..ee5a5d36bf 100644
--- a/arch/ppc64/mm/hash_low.S
+++ b/arch/ppc64/mm/hash_low.S
@@ -16,7 +16,7 @@
16#include <asm/page.h> 16#include <asm/page.h>
17#include <asm/types.h> 17#include <asm/types.h>
18#include <asm/ppc_asm.h> 18#include <asm/ppc_asm.h>
19#include <asm/offsets.h> 19#include <asm/asm-offsets.h>
20#include <asm/cputable.h> 20#include <asm/cputable.h>
21 21
22 .text 22 .text
diff --git a/arch/ppc64/mm/slb_low.S b/arch/ppc64/mm/slb_low.S
index 698d6b9ed6..a3a03da503 100644
--- a/arch/ppc64/mm/slb_low.S
+++ b/arch/ppc64/mm/slb_low.S
@@ -21,7 +21,7 @@
21#include <asm/page.h> 21#include <asm/page.h>
22#include <asm/mmu.h> 22#include <asm/mmu.h>
23#include <asm/ppc_asm.h> 23#include <asm/ppc_asm.h>
24#include <asm/offsets.h> 24#include <asm/asm-offsets.h>
25#include <asm/cputable.h> 25#include <asm/cputable.h>
26 26
27/* void slb_allocate(unsigned long ea); 27/* void slb_allocate(unsigned long ea);
diff --git a/arch/ppc64/xmon/privinst.h b/arch/ppc64/xmon/privinst.h
index 183c3e4002..02eb40dac0 100644
--- a/arch/ppc64/xmon/privinst.h
+++ b/arch/ppc64/xmon/privinst.h
@@ -46,7 +46,6 @@ GSETSPR(287, pvr)
46GSETSPR(1008, hid0) 46GSETSPR(1008, hid0)
47GSETSPR(1009, hid1) 47GSETSPR(1009, hid1)
48GSETSPR(1010, iabr) 48GSETSPR(1010, iabr)
49GSETSPR(1013, dabr)
50GSETSPR(1023, pir) 49GSETSPR(1023, pir)
51 50
52static inline void store_inst(void *p) 51static inline void store_inst(void *p)
diff --git a/arch/ppc64/xmon/xmon.c b/arch/ppc64/xmon/xmon.c
index 45908b10ac..74e63a886a 100644
--- a/arch/ppc64/xmon/xmon.c
+++ b/arch/ppc64/xmon/xmon.c
@@ -586,6 +586,8 @@ int xmon_dabr_match(struct pt_regs *regs)
586{ 586{
587 if ((regs->msr & (MSR_IR|MSR_PR|MSR_SF)) != (MSR_IR|MSR_SF)) 587 if ((regs->msr & (MSR_IR|MSR_PR|MSR_SF)) != (MSR_IR|MSR_SF))
588 return 0; 588 return 0;
589 if (dabr.enabled == 0)
590 return 0;
589 xmon_core(regs, 0); 591 xmon_core(regs, 0);
590 return 1; 592 return 1;
591} 593}
@@ -628,20 +630,6 @@ int xmon_fault_handler(struct pt_regs *regs)
628 return 0; 630 return 0;
629} 631}
630 632
631/* On systems with a hypervisor, we can't set the DABR
632 (data address breakpoint register) directly. */
633static void set_controlled_dabr(unsigned long val)
634{
635#ifdef CONFIG_PPC_PSERIES
636 if (systemcfg->platform == PLATFORM_PSERIES_LPAR) {
637 int rc = plpar_hcall_norets(H_SET_DABR, val);
638 if (rc != H_Success)
639 xmon_printf("Warning: setting DABR failed (%d)\n", rc);
640 } else
641#endif
642 set_dabr(val);
643}
644
645static struct bpt *at_breakpoint(unsigned long pc) 633static struct bpt *at_breakpoint(unsigned long pc)
646{ 634{
647 int i; 635 int i;
@@ -728,7 +716,7 @@ static void insert_bpts(void)
728static void insert_cpu_bpts(void) 716static void insert_cpu_bpts(void)
729{ 717{
730 if (dabr.enabled) 718 if (dabr.enabled)
731 set_controlled_dabr(dabr.address | (dabr.enabled & 7)); 719 set_dabr(dabr.address | (dabr.enabled & 7));
732 if (iabr && cpu_has_feature(CPU_FTR_IABR)) 720 if (iabr && cpu_has_feature(CPU_FTR_IABR))
733 set_iabr(iabr->address 721 set_iabr(iabr->address
734 | (iabr->enabled & (BP_IABR|BP_IABR_TE))); 722 | (iabr->enabled & (BP_IABR|BP_IABR_TE)));
@@ -756,7 +744,7 @@ static void remove_bpts(void)
756 744
757static void remove_cpu_bpts(void) 745static void remove_cpu_bpts(void)
758{ 746{
759 set_controlled_dabr(0); 747 set_dabr(0);
760 if (cpu_has_feature(CPU_FTR_IABR)) 748 if (cpu_has_feature(CPU_FTR_IABR))
761 set_iabr(0); 749 set_iabr(0);
762} 750}
diff --git a/arch/s390/Makefile b/arch/s390/Makefile
index c1ea6bcb77..98db30481d 100644
--- a/arch/s390/Makefile
+++ b/arch/s390/Makefile
@@ -102,16 +102,6 @@ image: vmlinux
102archclean: 102archclean:
103 $(Q)$(MAKE) $(clean)=$(boot) 103 $(Q)$(MAKE) $(clean)=$(boot)
104 104
105prepare: include/asm-$(ARCH)/offsets.h
106
107arch/$(ARCH)/kernel/asm-offsets.s: include/asm include/linux/version.h \
108 include/config/MARKER
109
110include/asm-$(ARCH)/offsets.h: arch/$(ARCH)/kernel/asm-offsets.s
111 $(call filechk,gen-asm-offsets)
112
113CLEAN_FILES += include/asm-$(ARCH)/offsets.h
114
115# Don't use tabs in echo arguments 105# Don't use tabs in echo arguments
116define archhelp 106define archhelp
117 echo '* image - Kernel image for IPL ($(boot)/image)' 107 echo '* image - Kernel image for IPL ($(boot)/image)'
diff --git a/arch/s390/kernel/compat_linux.c b/arch/s390/kernel/compat_linux.c
index 18610cea03..ed877d0f27 100644
--- a/arch/s390/kernel/compat_linux.c
+++ b/arch/s390/kernel/compat_linux.c
@@ -678,7 +678,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd, compat_off_t *offset, size
678 ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count); 678 ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
679 set_fs(old_fs); 679 set_fs(old_fs);
680 680
681 if (!ret && offset && put_user(of, offset)) 681 if (offset && put_user(of, offset))
682 return -EFAULT; 682 return -EFAULT;
683 683
684 return ret; 684 return ret;
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index cbe7d6a2d0..58fc7fbcb4 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -18,7 +18,7 @@
18#include <asm/errno.h> 18#include <asm/errno.h>
19#include <asm/ptrace.h> 19#include <asm/ptrace.h>
20#include <asm/thread_info.h> 20#include <asm/thread_info.h>
21#include <asm/offsets.h> 21#include <asm/asm-offsets.h>
22#include <asm/unistd.h> 22#include <asm/unistd.h>
23#include <asm/page.h> 23#include <asm/page.h>
24 24
diff --git a/arch/s390/kernel/entry64.S b/arch/s390/kernel/entry64.S
index fb77b72ab2..d0c9ffaa25 100644
--- a/arch/s390/kernel/entry64.S
+++ b/arch/s390/kernel/entry64.S
@@ -18,7 +18,7 @@
18#include <asm/errno.h> 18#include <asm/errno.h>
19#include <asm/ptrace.h> 19#include <asm/ptrace.h>
20#include <asm/thread_info.h> 20#include <asm/thread_info.h>
21#include <asm/offsets.h> 21#include <asm/asm-offsets.h>
22#include <asm/unistd.h> 22#include <asm/unistd.h>
23#include <asm/page.h> 23#include <asm/page.h>
24 24
diff --git a/arch/s390/kernel/head.S b/arch/s390/kernel/head.S
index 2710e66fef..55654b6e16 100644
--- a/arch/s390/kernel/head.S
+++ b/arch/s390/kernel/head.S
@@ -30,7 +30,7 @@
30#include <linux/config.h> 30#include <linux/config.h>
31#include <asm/setup.h> 31#include <asm/setup.h>
32#include <asm/lowcore.h> 32#include <asm/lowcore.h>
33#include <asm/offsets.h> 33#include <asm/asm-offsets.h>
34#include <asm/thread_info.h> 34#include <asm/thread_info.h>
35#include <asm/page.h> 35#include <asm/page.h>
36 36
diff --git a/arch/s390/kernel/head64.S b/arch/s390/kernel/head64.S
index 9a8263a153..c9ff0404c8 100644
--- a/arch/s390/kernel/head64.S
+++ b/arch/s390/kernel/head64.S
@@ -30,7 +30,7 @@
30#include <linux/config.h> 30#include <linux/config.h>
31#include <asm/setup.h> 31#include <asm/setup.h>
32#include <asm/lowcore.h> 32#include <asm/lowcore.h>
33#include <asm/offsets.h> 33#include <asm/asm-offsets.h>
34#include <asm/thread_info.h> 34#include <asm/thread_info.h>
35#include <asm/page.h> 35#include <asm/page.h>
36 36
diff --git a/arch/s390/lib/spinlock.c b/arch/s390/lib/spinlock.c
index 888b5596c1..2dc14e9c83 100644
--- a/arch/s390/lib/spinlock.c
+++ b/arch/s390/lib/spinlock.c
@@ -36,7 +36,7 @@ _diag44(void)
36} 36}
37 37
38void 38void
39_raw_spin_lock_wait(spinlock_t *lp, unsigned int pc) 39_raw_spin_lock_wait(raw_spinlock_t *lp, unsigned int pc)
40{ 40{
41 int count = spin_retry; 41 int count = spin_retry;
42 42
@@ -53,7 +53,7 @@ _raw_spin_lock_wait(spinlock_t *lp, unsigned int pc)
53EXPORT_SYMBOL(_raw_spin_lock_wait); 53EXPORT_SYMBOL(_raw_spin_lock_wait);
54 54
55int 55int
56_raw_spin_trylock_retry(spinlock_t *lp, unsigned int pc) 56_raw_spin_trylock_retry(raw_spinlock_t *lp, unsigned int pc)
57{ 57{
58 int count = spin_retry; 58 int count = spin_retry;
59 59
@@ -67,7 +67,7 @@ _raw_spin_trylock_retry(spinlock_t *lp, unsigned int pc)
67EXPORT_SYMBOL(_raw_spin_trylock_retry); 67EXPORT_SYMBOL(_raw_spin_trylock_retry);
68 68
69void 69void
70_raw_read_lock_wait(rwlock_t *rw) 70_raw_read_lock_wait(raw_rwlock_t *rw)
71{ 71{
72 unsigned int old; 72 unsigned int old;
73 int count = spin_retry; 73 int count = spin_retry;
@@ -86,7 +86,7 @@ _raw_read_lock_wait(rwlock_t *rw)
86EXPORT_SYMBOL(_raw_read_lock_wait); 86EXPORT_SYMBOL(_raw_read_lock_wait);
87 87
88int 88int
89_raw_read_trylock_retry(rwlock_t *rw) 89_raw_read_trylock_retry(raw_rwlock_t *rw)
90{ 90{
91 unsigned int old; 91 unsigned int old;
92 int count = spin_retry; 92 int count = spin_retry;
@@ -102,7 +102,7 @@ _raw_read_trylock_retry(rwlock_t *rw)
102EXPORT_SYMBOL(_raw_read_trylock_retry); 102EXPORT_SYMBOL(_raw_read_trylock_retry);
103 103
104void 104void
105_raw_write_lock_wait(rwlock_t *rw) 105_raw_write_lock_wait(raw_rwlock_t *rw)
106{ 106{
107 int count = spin_retry; 107 int count = spin_retry;
108 108
@@ -119,7 +119,7 @@ _raw_write_lock_wait(rwlock_t *rw)
119EXPORT_SYMBOL(_raw_write_lock_wait); 119EXPORT_SYMBOL(_raw_write_lock_wait);
120 120
121int 121int
122_raw_write_trylock_retry(rwlock_t *rw) 122_raw_write_trylock_retry(raw_rwlock_t *rw)
123{ 123{
124 int count = spin_retry; 124 int count = spin_retry;
125 125
diff --git a/arch/s390/lib/uaccess.S b/arch/s390/lib/uaccess.S
index e8029ef42e..88fc94fe64 100644
--- a/arch/s390/lib/uaccess.S
+++ b/arch/s390/lib/uaccess.S
@@ -11,7 +11,7 @@
11 11
12#include <linux/errno.h> 12#include <linux/errno.h>
13#include <asm/lowcore.h> 13#include <asm/lowcore.h>
14#include <asm/offsets.h> 14#include <asm/asm-offsets.h>
15 15
16 .text 16 .text
17 .align 4 17 .align 4
diff --git a/arch/s390/lib/uaccess64.S b/arch/s390/lib/uaccess64.S
index 0ca56972f4..50219786fc 100644
--- a/arch/s390/lib/uaccess64.S
+++ b/arch/s390/lib/uaccess64.S
@@ -11,7 +11,7 @@
11 11
12#include <linux/errno.h> 12#include <linux/errno.h>
13#include <asm/lowcore.h> 13#include <asm/lowcore.h>
14#include <asm/offsets.h> 14#include <asm/asm-offsets.h>
15 15
16 .text 16 .text
17 .align 4 17 .align 4
diff --git a/arch/sh/Makefile b/arch/sh/Makefile
index b5635635b5..4a3049080b 100644
--- a/arch/sh/Makefile
+++ b/arch/sh/Makefile
@@ -152,10 +152,10 @@ endif
152 @touch $@ 152 @touch $@
153 153
154 154
155prepare: maketools include/asm-sh/.cpu include/asm-sh/.mach 155archprepare: maketools include/asm-sh/.cpu include/asm-sh/.mach
156 156
157.PHONY: maketools FORCE 157.PHONY: maketools FORCE
158maketools: include/asm-sh/asm-offsets.h include/linux/version.h FORCE 158maketools: include/linux/version.h FORCE
159 $(Q)$(MAKE) $(build)=arch/sh/tools include/asm-sh/machtypes.h 159 $(Q)$(MAKE) $(build)=arch/sh/tools include/asm-sh/machtypes.h
160 160
161all: zImage 161all: zImage
@@ -168,14 +168,7 @@ compressed: zImage
168archclean: 168archclean:
169 $(Q)$(MAKE) $(clean)=$(boot) 169 $(Q)$(MAKE) $(clean)=$(boot)
170 170
171CLEAN_FILES += include/asm-sh/machtypes.h include/asm-sh/asm-offsets.h 171CLEAN_FILES += include/asm-sh/machtypes.h
172
173arch/sh/kernel/asm-offsets.s: include/asm include/linux/version.h \
174 include/asm-sh/.cpu include/asm-sh/.mach
175
176include/asm-sh/asm-offsets.h: arch/sh/kernel/asm-offsets.s
177 $(call filechk,gen-asm-offsets)
178
179 172
180define archhelp 173define archhelp
181 @echo ' zImage - Compressed kernel image (arch/sh/boot/zImage)' 174 @echo ' zImage - Compressed kernel image (arch/sh/boot/zImage)'
diff --git a/arch/sh/boards/adx/irq_maskreg.c b/arch/sh/boards/adx/irq_maskreg.c
index ca91bb0f1f..c0973f8d57 100644
--- a/arch/sh/boards/adx/irq_maskreg.c
+++ b/arch/sh/boards/adx/irq_maskreg.c
@@ -37,13 +37,13 @@ static void end_maskreg_irq(unsigned int irq);
37 37
38/* hw_interrupt_type */ 38/* hw_interrupt_type */
39static struct hw_interrupt_type maskreg_irq_type = { 39static struct hw_interrupt_type maskreg_irq_type = {
40 " Mask Register", 40 .typename = " Mask Register",
41 startup_maskreg_irq, 41 .startup = startup_maskreg_irq,
42 shutdown_maskreg_irq, 42 .shutdown = shutdown_maskreg_irq,
43 enable_maskreg_irq, 43 .enable = enable_maskreg_irq,
44 disable_maskreg_irq, 44 .disable = disable_maskreg_irq,
45 mask_and_ack_maskreg, 45 .ack = mask_and_ack_maskreg,
46 end_maskreg_irq 46 .end = end_maskreg_irq
47}; 47};
48 48
49/* actual implementatin */ 49/* actual implementatin */
diff --git a/arch/sh/boards/bigsur/io.c b/arch/sh/boards/bigsur/io.c
index 697144de74..a9fde781b2 100644
--- a/arch/sh/boards/bigsur/io.c
+++ b/arch/sh/boards/bigsur/io.c
@@ -37,10 +37,6 @@ static u8 bigsur_iomap_lo_shift[BIGSUR_IOMAP_LO_NMAP];
37static u32 bigsur_iomap_hi[BIGSUR_IOMAP_HI_NMAP]; 37static u32 bigsur_iomap_hi[BIGSUR_IOMAP_HI_NMAP];
38static u8 bigsur_iomap_hi_shift[BIGSUR_IOMAP_HI_NMAP]; 38static u8 bigsur_iomap_hi_shift[BIGSUR_IOMAP_HI_NMAP];
39 39
40#ifndef MAX
41#define MAX(a,b) ((a)>(b)?(a):(b))
42#endif
43
44void bigsur_port_map(u32 baseport, u32 nports, u32 addr, u8 shift) 40void bigsur_port_map(u32 baseport, u32 nports, u32 addr, u8 shift)
45{ 41{
46 u32 port, endport = baseport + nports; 42 u32 port, endport = baseport + nports;
@@ -57,7 +53,7 @@ void bigsur_port_map(u32 baseport, u32 nports, u32 addr, u8 shift)
57 addr += (1<<(BIGSUR_IOMAP_LO_SHIFT)); 53 addr += (1<<(BIGSUR_IOMAP_LO_SHIFT));
58 } 54 }
59 55
60 for (port = MAX(baseport, BIGSUR_IOMAP_LO_THRESH) ; 56 for (port = max_t(u32, baseport, BIGSUR_IOMAP_LO_THRESH);
61 port < endport && port < BIGSUR_IOMAP_HI_THRESH ; 57 port < endport && port < BIGSUR_IOMAP_HI_THRESH ;
62 port += (1<<BIGSUR_IOMAP_HI_SHIFT)) { 58 port += (1<<BIGSUR_IOMAP_HI_SHIFT)) {
63 pr_debug(" maphi[0x%x] = 0x%08x\n", port, addr); 59 pr_debug(" maphi[0x%x] = 0x%08x\n", port, addr);
@@ -80,7 +76,7 @@ void bigsur_port_unmap(u32 baseport, u32 nports)
80 bigsur_iomap_lo[port>>BIGSUR_IOMAP_LO_SHIFT] = 0; 76 bigsur_iomap_lo[port>>BIGSUR_IOMAP_LO_SHIFT] = 0;
81 } 77 }
82 78
83 for (port = MAX(baseport, BIGSUR_IOMAP_LO_THRESH) ; 79 for (port = max_t(u32, baseport, BIGSUR_IOMAP_LO_THRESH);
84 port < endport && port < BIGSUR_IOMAP_HI_THRESH ; 80 port < endport && port < BIGSUR_IOMAP_HI_THRESH ;
85 port += (1<<BIGSUR_IOMAP_HI_SHIFT)) { 81 port += (1<<BIGSUR_IOMAP_HI_SHIFT)) {
86 bigsur_iomap_hi[port>>BIGSUR_IOMAP_HI_SHIFT] = 0; 82 bigsur_iomap_hi[port>>BIGSUR_IOMAP_HI_SHIFT] = 0;
diff --git a/arch/sh/boards/bigsur/irq.c b/arch/sh/boards/bigsur/irq.c
index c188fc32dc..6ddbcc7724 100644
--- a/arch/sh/boards/bigsur/irq.c
+++ b/arch/sh/boards/bigsur/irq.c
@@ -228,23 +228,23 @@ static void shutdown_bigsur_irq(unsigned int irq)
228 228
229/* Define the IRQ structures for the L1 and L2 IRQ types */ 229/* Define the IRQ structures for the L1 and L2 IRQ types */
230static struct hw_interrupt_type bigsur_l1irq_type = { 230static struct hw_interrupt_type bigsur_l1irq_type = {
231 "BigSur-CPLD-Level1-IRQ", 231 .typename = "BigSur-CPLD-Level1-IRQ",
232 startup_bigsur_irq, 232 .startup = startup_bigsur_irq,
233 shutdown_bigsur_irq, 233 .shutdown = shutdown_bigsur_irq,
234 enable_bigsur_l1irq, 234 .enable = enable_bigsur_l1irq,
235 disable_bigsur_l1irq, 235 .disable = disable_bigsur_l1irq,
236 mask_and_ack_bigsur, 236 .ack = mask_and_ack_bigsur,
237 end_bigsur_irq 237 .end = end_bigsur_irq
238}; 238};
239 239
240static struct hw_interrupt_type bigsur_l2irq_type = { 240static struct hw_interrupt_type bigsur_l2irq_type = {
241 "BigSur-CPLD-Level2-IRQ", 241 .typename = "BigSur-CPLD-Level2-IRQ",
242 startup_bigsur_irq, 242 .startup = startup_bigsur_irq,
243 shutdown_bigsur_irq, 243 .shutdown =shutdown_bigsur_irq,
244 enable_bigsur_l2irq, 244 .enable = enable_bigsur_l2irq,
245 disable_bigsur_l2irq, 245 .disable = disable_bigsur_l2irq,
246 mask_and_ack_bigsur, 246 .ack = mask_and_ack_bigsur,
247 end_bigsur_irq 247 .end = end_bigsur_irq
248}; 248};
249 249
250 250
diff --git a/arch/sh/boards/cqreek/irq.c b/arch/sh/boards/cqreek/irq.c
index fa6cfe5a20..d1da0d8445 100644
--- a/arch/sh/boards/cqreek/irq.c
+++ b/arch/sh/boards/cqreek/irq.c
@@ -83,13 +83,13 @@ static void shutdown_cqreek_irq(unsigned int irq)
83} 83}
84 84
85static struct hw_interrupt_type cqreek_irq_type = { 85static struct hw_interrupt_type cqreek_irq_type = {
86 "CqREEK-IRQ", 86 .typename = "CqREEK-IRQ",
87 startup_cqreek_irq, 87 .startup = startup_cqreek_irq,
88 shutdown_cqreek_irq, 88 .shutdown = shutdown_cqreek_irq,
89 enable_cqreek_irq, 89 .enable = enable_cqreek_irq,
90 disable_cqreek_irq, 90 .disable = disable_cqreek_irq,
91 mask_and_ack_cqreek, 91 .ack = mask_and_ack_cqreek,
92 end_cqreek_irq 92 .end = end_cqreek_irq
93}; 93};
94 94
95int cqreek_has_ide, cqreek_has_isa; 95int cqreek_has_ide, cqreek_has_isa;
diff --git a/arch/sh/boards/harp/irq.c b/arch/sh/boards/harp/irq.c
index acd5848997..52d0ba3903 100644
--- a/arch/sh/boards/harp/irq.c
+++ b/arch/sh/boards/harp/irq.c
@@ -39,13 +39,13 @@ static unsigned int startup_harp_irq(unsigned int irq)
39} 39}
40 40
41static struct hw_interrupt_type harp_irq_type = { 41static struct hw_interrupt_type harp_irq_type = {
42 "Harp-IRQ", 42 .typename = "Harp-IRQ",
43 startup_harp_irq, 43 .startup = startup_harp_irq,
44 shutdown_harp_irq, 44 .shutdown = shutdown_harp_irq,
45 enable_harp_irq, 45 .enable = enable_harp_irq,
46 disable_harp_irq, 46 .disable = disable_harp_irq,
47 mask_and_ack_harp, 47 .ack = mask_and_ack_harp,
48 end_harp_irq 48 .end = end_harp_irq
49}; 49};
50 50
51static void disable_harp_irq(unsigned int irq) 51static void disable_harp_irq(unsigned int irq)
diff --git a/arch/sh/boards/overdrive/irq.c b/arch/sh/boards/overdrive/irq.c
index 23adc6be71..715e8feb3a 100644
--- a/arch/sh/boards/overdrive/irq.c
+++ b/arch/sh/boards/overdrive/irq.c
@@ -86,13 +86,13 @@ static unsigned int startup_od_irq(unsigned int irq)
86} 86}
87 87
88static struct hw_interrupt_type od_irq_type = { 88static struct hw_interrupt_type od_irq_type = {
89 "Overdrive-IRQ", 89 .typename = "Overdrive-IRQ",
90 startup_od_irq, 90 .startup = startup_od_irq,
91 shutdown_od_irq, 91 .shutdown = shutdown_od_irq,
92 enable_od_irq, 92 .enable = enable_od_irq,
93 disable_od_irq, 93 .disable = disable_od_irq,
94 mask_and_ack_od, 94 .ack = mask_and_ack_od,
95 end_od_irq 95 .end = end_od_irq
96}; 96};
97 97
98static void disable_od_irq(unsigned int irq) 98static void disable_od_irq(unsigned int irq)
diff --git a/arch/sh/boards/renesas/hs7751rvoip/irq.c b/arch/sh/boards/renesas/hs7751rvoip/irq.c
index a7921f67a3..ed4c5b50ea 100644
--- a/arch/sh/boards/renesas/hs7751rvoip/irq.c
+++ b/arch/sh/boards/renesas/hs7751rvoip/irq.c
@@ -74,13 +74,13 @@ static void end_hs7751rvoip_irq(unsigned int irq)
74} 74}
75 75
76static struct hw_interrupt_type hs7751rvoip_irq_type = { 76static struct hw_interrupt_type hs7751rvoip_irq_type = {
77 "HS7751RVoIP IRQ", 77 .typename = "HS7751RVoIP IRQ",
78 startup_hs7751rvoip_irq, 78 .startup = startup_hs7751rvoip_irq,
79 shutdown_hs7751rvoip_irq, 79 .shutdown = shutdown_hs7751rvoip_irq,
80 enable_hs7751rvoip_irq, 80 .enable = enable_hs7751rvoip_irq,
81 disable_hs7751rvoip_irq, 81 .disable = disable_hs7751rvoip_irq,
82 ack_hs7751rvoip_irq, 82 .ack = ack_hs7751rvoip_irq,
83 end_hs7751rvoip_irq, 83 .end = end_hs7751rvoip_irq,
84}; 84};
85 85
86static void make_hs7751rvoip_irq(unsigned int irq) 86static void make_hs7751rvoip_irq(unsigned int irq)
diff --git a/arch/sh/boards/renesas/rts7751r2d/irq.c b/arch/sh/boards/renesas/rts7751r2d/irq.c
index 95717f4f1e..d36c9374ae 100644
--- a/arch/sh/boards/renesas/rts7751r2d/irq.c
+++ b/arch/sh/boards/renesas/rts7751r2d/irq.c
@@ -88,13 +88,13 @@ static void end_rts7751r2d_irq(unsigned int irq)
88} 88}
89 89
90static struct hw_interrupt_type rts7751r2d_irq_type = { 90static struct hw_interrupt_type rts7751r2d_irq_type = {
91 "RTS7751R2D IRQ", 91 .typename = "RTS7751R2D IRQ",
92 startup_rts7751r2d_irq, 92 .startup = startup_rts7751r2d_irq,
93 shutdown_rts7751r2d_irq, 93 .shutdown = shutdown_rts7751r2d_irq,
94 enable_rts7751r2d_irq, 94 .enable = enable_rts7751r2d_irq,
95 disable_rts7751r2d_irq, 95 .disable = disable_rts7751r2d_irq,
96 ack_rts7751r2d_irq, 96 .ack = ack_rts7751r2d_irq,
97 end_rts7751r2d_irq, 97 .end = end_rts7751r2d_irq,
98}; 98};
99 99
100static void make_rts7751r2d_irq(unsigned int irq) 100static void make_rts7751r2d_irq(unsigned int irq)
diff --git a/arch/sh/boards/renesas/systemh/irq.c b/arch/sh/boards/renesas/systemh/irq.c
index 5675a4134e..7a2eb10edb 100644
--- a/arch/sh/boards/renesas/systemh/irq.c
+++ b/arch/sh/boards/renesas/systemh/irq.c
@@ -35,13 +35,13 @@ static void end_systemh_irq(unsigned int irq);
35 35
36/* hw_interrupt_type */ 36/* hw_interrupt_type */
37static struct hw_interrupt_type systemh_irq_type = { 37static struct hw_interrupt_type systemh_irq_type = {
38 " SystemH Register", 38 .typename = " SystemH Register",
39 startup_systemh_irq, 39 .startup = startup_systemh_irq,
40 shutdown_systemh_irq, 40 .shutdown = shutdown_systemh_irq,
41 enable_systemh_irq, 41 .enable = enable_systemh_irq,
42 disable_systemh_irq, 42 .disable = disable_systemh_irq,
43 mask_and_ack_systemh, 43 .ack = mask_and_ack_systemh,
44 end_systemh_irq 44 .end = end_systemh_irq
45}; 45};
46 46
47static unsigned int startup_systemh_irq(unsigned int irq) 47static unsigned int startup_systemh_irq(unsigned int irq)
diff --git a/arch/sh/boards/superh/microdev/irq.c b/arch/sh/boards/superh/microdev/irq.c
index 1298883eca..1395c1e65d 100644
--- a/arch/sh/boards/superh/microdev/irq.c
+++ b/arch/sh/boards/superh/microdev/irq.c
@@ -83,13 +83,13 @@ static unsigned int startup_microdev_irq(unsigned int irq)
83} 83}
84 84
85static struct hw_interrupt_type microdev_irq_type = { 85static struct hw_interrupt_type microdev_irq_type = {
86 "MicroDev-IRQ", 86 .typename = "MicroDev-IRQ",
87 startup_microdev_irq, 87 .startup = startup_microdev_irq,
88 shutdown_microdev_irq, 88 .shutdown = shutdown_microdev_irq,
89 enable_microdev_irq, 89 .enable = enable_microdev_irq,
90 disable_microdev_irq, 90 .disable = disable_microdev_irq,
91 mask_and_ack_microdev, 91 .ack = mask_and_ack_microdev,
92 end_microdev_irq 92 .end = end_microdev_irq
93}; 93};
94 94
95static void disable_microdev_irq(unsigned int irq) 95static void disable_microdev_irq(unsigned int irq)
diff --git a/arch/sh/cchips/hd6446x/hd64465/io.c b/arch/sh/cchips/hd6446x/hd64465/io.c
index 99ac709c55..84cb142def 100644
--- a/arch/sh/cchips/hd6446x/hd64465/io.c
+++ b/arch/sh/cchips/hd6446x/hd64465/io.c
@@ -48,10 +48,6 @@ static unsigned char hd64465_iomap_lo_shift[HD64465_IOMAP_LO_NMAP];
48static unsigned long hd64465_iomap_hi[HD64465_IOMAP_HI_NMAP]; 48static unsigned long hd64465_iomap_hi[HD64465_IOMAP_HI_NMAP];
49static unsigned char hd64465_iomap_hi_shift[HD64465_IOMAP_HI_NMAP]; 49static unsigned char hd64465_iomap_hi_shift[HD64465_IOMAP_HI_NMAP];
50 50
51#ifndef MAX
52#define MAX(a,b) ((a)>(b)?(a):(b))
53#endif
54
55#define PORT2ADDR(x) (sh_mv.mv_isa_port2addr(x)) 51#define PORT2ADDR(x) (sh_mv.mv_isa_port2addr(x))
56 52
57void hd64465_port_map(unsigned short baseport, unsigned int nports, 53void hd64465_port_map(unsigned short baseport, unsigned int nports,
@@ -71,7 +67,7 @@ void hd64465_port_map(unsigned short baseport, unsigned int nports,
71 addr += (1<<(HD64465_IOMAP_LO_SHIFT)); 67 addr += (1<<(HD64465_IOMAP_LO_SHIFT));
72 } 68 }
73 69
74 for (port = MAX(baseport, HD64465_IOMAP_LO_THRESH) ; 70 for (port = max_t(unsigned int, baseport, HD64465_IOMAP_LO_THRESH);
75 port < endport && port < HD64465_IOMAP_HI_THRESH ; 71 port < endport && port < HD64465_IOMAP_HI_THRESH ;
76 port += (1<<HD64465_IOMAP_HI_SHIFT)) { 72 port += (1<<HD64465_IOMAP_HI_SHIFT)) {
77 DPRINTK(" maphi[0x%x] = 0x%08lx\n", port, addr); 73 DPRINTK(" maphi[0x%x] = 0x%08lx\n", port, addr);
@@ -95,7 +91,7 @@ void hd64465_port_unmap(unsigned short baseport, unsigned int nports)
95 hd64465_iomap_lo[port>>HD64465_IOMAP_LO_SHIFT] = 0; 91 hd64465_iomap_lo[port>>HD64465_IOMAP_LO_SHIFT] = 0;
96 } 92 }
97 93
98 for (port = MAX(baseport, HD64465_IOMAP_LO_THRESH) ; 94 for (port = max_t(unsigned int, baseport, HD64465_IOMAP_LO_THRESH);
99 port < endport && port < HD64465_IOMAP_HI_THRESH ; 95 port < endport && port < HD64465_IOMAP_HI_THRESH ;
100 port += (1<<HD64465_IOMAP_HI_SHIFT)) { 96 port += (1<<HD64465_IOMAP_HI_SHIFT)) {
101 hd64465_iomap_hi[port>>HD64465_IOMAP_HI_SHIFT] = 0; 97 hd64465_iomap_hi[port>>HD64465_IOMAP_HI_SHIFT] = 0;
diff --git a/arch/sh/cchips/voyagergx/irq.c b/arch/sh/cchips/voyagergx/irq.c
index 3079234cb6..1b6ac523b4 100644
--- a/arch/sh/cchips/voyagergx/irq.c
+++ b/arch/sh/cchips/voyagergx/irq.c
@@ -87,13 +87,13 @@ static void shutdown_voyagergx_irq(unsigned int irq)
87} 87}
88 88
89static struct hw_interrupt_type voyagergx_irq_type = { 89static struct hw_interrupt_type voyagergx_irq_type = {
90 "VOYAGERGX-IRQ", 90 .typename = "VOYAGERGX-IRQ",
91 startup_voyagergx_irq, 91 .startup = startup_voyagergx_irq,
92 shutdown_voyagergx_irq, 92 .shutdown = shutdown_voyagergx_irq,
93 enable_voyagergx_irq, 93 .enable = enable_voyagergx_irq,
94 disable_voyagergx_irq, 94 .disable = disable_voyagergx_irq,
95 mask_and_ack_voyagergx, 95 .ack = mask_and_ack_voyagergx,
96 end_voyagergx_irq, 96 .end = end_voyagergx_irq,
97}; 97};
98 98
99static irqreturn_t voyagergx_interrupt(int irq, void *dev_id, struct pt_regs *regs) 99static irqreturn_t voyagergx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
diff --git a/arch/sh/kernel/cpu/irq_imask.c b/arch/sh/kernel/cpu/irq_imask.c
index f76901e732..a963d00a97 100644
--- a/arch/sh/kernel/cpu/irq_imask.c
+++ b/arch/sh/kernel/cpu/irq_imask.c
@@ -46,13 +46,13 @@ static unsigned int startup_imask_irq(unsigned int irq)
46} 46}
47 47
48static struct hw_interrupt_type imask_irq_type = { 48static struct hw_interrupt_type imask_irq_type = {
49 "SR.IMASK", 49 .typename = "SR.IMASK",
50 startup_imask_irq, 50 .startup = startup_imask_irq,
51 shutdown_imask_irq, 51 .shutdown = shutdown_imask_irq,
52 enable_imask_irq, 52 .enable = enable_imask_irq,
53 disable_imask_irq, 53 .disable = disable_imask_irq,
54 mask_and_ack_imask, 54 .ack = mask_and_ack_imask,
55 end_imask_irq 55 .end = end_imask_irq
56}; 56};
57 57
58void static inline set_interrupt_registers(int ip) 58void static inline set_interrupt_registers(int ip)
diff --git a/arch/sh/kernel/cpu/irq_ipr.c b/arch/sh/kernel/cpu/irq_ipr.c
index 7ea3d2d030..71f9209613 100644
--- a/arch/sh/kernel/cpu/irq_ipr.c
+++ b/arch/sh/kernel/cpu/irq_ipr.c
@@ -48,13 +48,13 @@ static unsigned int startup_ipr_irq(unsigned int irq)
48} 48}
49 49
50static struct hw_interrupt_type ipr_irq_type = { 50static struct hw_interrupt_type ipr_irq_type = {
51 "IPR-IRQ", 51 .typename = "IPR-IRQ",
52 startup_ipr_irq, 52 .startup = startup_ipr_irq,
53 shutdown_ipr_irq, 53 .shutdown = shutdown_ipr_irq,
54 enable_ipr_irq, 54 .enable = enable_ipr_irq,
55 disable_ipr_irq, 55 .disable = disable_ipr_irq,
56 mask_and_ack_ipr, 56 .ack = mask_and_ack_ipr,
57 end_ipr_irq 57 .end = end_ipr_irq
58}; 58};
59 59
60static void disable_ipr_irq(unsigned int irq) 60static void disable_ipr_irq(unsigned int irq)
@@ -142,13 +142,13 @@ static unsigned int startup_pint_irq(unsigned int irq)
142} 142}
143 143
144static struct hw_interrupt_type pint_irq_type = { 144static struct hw_interrupt_type pint_irq_type = {
145 "PINT-IRQ", 145 .typename = "PINT-IRQ",
146 startup_pint_irq, 146 .startup = startup_pint_irq,
147 shutdown_pint_irq, 147 .shutdown = shutdown_pint_irq,
148 enable_pint_irq, 148 .enable = enable_pint_irq,
149 disable_pint_irq, 149 .disable = disable_pint_irq,
150 mask_and_ack_pint, 150 .ack = mask_and_ack_pint,
151 end_pint_irq 151 .end = end_pint_irq
152}; 152};
153 153
154static void disable_pint_irq(unsigned int irq) 154static void disable_pint_irq(unsigned int irq)
diff --git a/arch/sh/kernel/cpu/sh4/irq_intc2.c b/arch/sh/kernel/cpu/sh4/irq_intc2.c
index 099ebbf897..f6b16ba019 100644
--- a/arch/sh/kernel/cpu/sh4/irq_intc2.c
+++ b/arch/sh/kernel/cpu/sh4/irq_intc2.c
@@ -48,13 +48,13 @@ static unsigned int startup_intc2_irq(unsigned int irq)
48} 48}
49 49
50static struct hw_interrupt_type intc2_irq_type = { 50static struct hw_interrupt_type intc2_irq_type = {
51 "INTC2-IRQ", 51 .typename = "INTC2-IRQ",
52 startup_intc2_irq, 52 .startup = startup_intc2_irq,
53 shutdown_intc2_irq, 53 .shutdown = shutdown_intc2_irq,
54 enable_intc2_irq, 54 .enable = enable_intc2_irq,
55 disable_intc2_irq, 55 .disable = disable_intc2_irq,
56 mask_and_ack_intc2, 56 .ack = mask_and_ack_intc2,
57 end_intc2_irq 57 .end = end_intc2_irq
58}; 58};
59 59
60static void disable_intc2_irq(unsigned int irq) 60static void disable_intc2_irq(unsigned int irq)
diff --git a/arch/sh64/Makefile b/arch/sh64/Makefile
index b4fd8e13fe..8ca57ffa2b 100644
--- a/arch/sh64/Makefile
+++ b/arch/sh64/Makefile
@@ -73,11 +73,7 @@ compressed: zImage
73archclean: 73archclean:
74 $(Q)$(MAKE) $(clean)=$(boot) 74 $(Q)$(MAKE) $(clean)=$(boot)
75 75
76prepare: include/asm-$(ARCH)/asm-offsets.h arch/$(ARCH)/lib/syscalltab.h 76archprepare: arch/$(ARCH)/lib/syscalltab.h
77
78include/asm-$(ARCH)/asm-offsets.h: arch/$(ARCH)/kernel/asm-offsets.s \
79 include/asm include/linux/version.h
80 $(call filechk,gen-asm-offsets)
81 77
82define filechk_gen-syscalltab 78define filechk_gen-syscalltab
83 (set -e; \ 79 (set -e; \
@@ -108,7 +104,7 @@ endef
108arch/$(ARCH)/lib/syscalltab.h: arch/sh64/kernel/syscalls.S 104arch/$(ARCH)/lib/syscalltab.h: arch/sh64/kernel/syscalls.S
109 $(call filechk,gen-syscalltab) 105 $(call filechk,gen-syscalltab)
110 106
111CLEAN_FILES += include/asm-$(ARCH)/asm-offsets.h arch/$(ARCH)/lib/syscalltab.h 107CLEAN_FILES += arch/$(ARCH)/lib/syscalltab.h
112 108
113define archhelp 109define archhelp
114 @echo ' zImage - Compressed kernel image (arch/sh64/boot/zImage)' 110 @echo ' zImage - Compressed kernel image (arch/sh64/boot/zImage)'
diff --git a/arch/sh64/kernel/irq_intc.c b/arch/sh64/kernel/irq_intc.c
index 43f88f3a78..fc99bf4e36 100644
--- a/arch/sh64/kernel/irq_intc.c
+++ b/arch/sh64/kernel/irq_intc.c
@@ -107,13 +107,13 @@ static void mask_and_ack_intc(unsigned int);
107static void end_intc_irq(unsigned int irq); 107static void end_intc_irq(unsigned int irq);
108 108
109static struct hw_interrupt_type intc_irq_type = { 109static struct hw_interrupt_type intc_irq_type = {
110 "INTC", 110 .typename = "INTC",
111 startup_intc_irq, 111 .startup = startup_intc_irq,
112 shutdown_intc_irq, 112 .shutdown = shutdown_intc_irq,
113 enable_intc_irq, 113 .enable = enable_intc_irq,
114 disable_intc_irq, 114 .disable = disable_intc_irq,
115 mask_and_ack_intc, 115 .ack = mask_and_ack_intc,
116 end_intc_irq 116 .end = end_intc_irq
117}; 117};
118 118
119static int irlm; /* IRL mode */ 119static int irlm; /* IRL mode */
diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
index 7b3bbaf083..dea48f6cff 100644
--- a/arch/sparc/Makefile
+++ b/arch/sparc/Makefile
@@ -59,17 +59,7 @@ image tftpboot.img: vmlinux
59archclean: 59archclean:
60 $(Q)$(MAKE) $(clean)=$(boot) 60 $(Q)$(MAKE) $(clean)=$(boot)
61 61
62prepare: include/asm-$(ARCH)/asm_offsets.h 62CLEAN_FILES += arch/$(ARCH)/boot/System.map
63
64arch/$(ARCH)/kernel/asm-offsets.s: include/asm include/linux/version.h \
65 include/config/MARKER
66
67include/asm-$(ARCH)/asm_offsets.h: arch/$(ARCH)/kernel/asm-offsets.s
68 $(call filechk,gen-asm-offsets)
69
70CLEAN_FILES += include/asm-$(ARCH)/asm_offsets.h \
71 arch/$(ARCH)/kernel/asm-offsets.s \
72 arch/$(ARCH)/boot/System.map
73 63
74# Don't use tabs in echo arguments. 64# Don't use tabs in echo arguments.
75define archhelp 65define archhelp
diff --git a/arch/sparc/kernel/entry.S b/arch/sparc/kernel/entry.S
index b448166f5d..03ecb4e461 100644
--- a/arch/sparc/kernel/entry.S
+++ b/arch/sparc/kernel/entry.S
@@ -17,7 +17,7 @@
17#include <asm/kgdb.h> 17#include <asm/kgdb.h>
18#include <asm/contregs.h> 18#include <asm/contregs.h>
19#include <asm/ptrace.h> 19#include <asm/ptrace.h>
20#include <asm/asm_offsets.h> 20#include <asm/asm-offsets.h>
21#include <asm/psr.h> 21#include <asm/psr.h>
22#include <asm/vaddrs.h> 22#include <asm/vaddrs.h>
23#include <asm/memreg.h> 23#include <asm/memreg.h>
diff --git a/arch/sparc/kernel/sclow.S b/arch/sparc/kernel/sclow.S
index 3a867fc199..136e37c53d 100644
--- a/arch/sparc/kernel/sclow.S
+++ b/arch/sparc/kernel/sclow.S
@@ -7,7 +7,7 @@
7 */ 7 */
8 8
9#include <asm/ptrace.h> 9#include <asm/ptrace.h>
10#include <asm/asm_offsets.h> 10#include <asm/asm-offsets.h>
11#include <asm/errno.h> 11#include <asm/errno.h>
12#include <asm/winmacro.h> 12#include <asm/winmacro.h>
13#include <asm/thread_info.h> 13#include <asm/thread_info.h>
diff --git a/arch/sparc/kernel/sparc_ksyms.c b/arch/sparc/kernel/sparc_ksyms.c
index 5d974a2b73..f848093336 100644
--- a/arch/sparc/kernel/sparc_ksyms.c
+++ b/arch/sparc/kernel/sparc_ksyms.c
@@ -114,17 +114,7 @@ DOT_ALIAS2(unsigned, urem, unsigned, unsigned)
114/* used by various drivers */ 114/* used by various drivers */
115EXPORT_SYMBOL(sparc_cpu_model); 115EXPORT_SYMBOL(sparc_cpu_model);
116EXPORT_SYMBOL(kernel_thread); 116EXPORT_SYMBOL(kernel_thread);
117#ifdef CONFIG_DEBUG_SPINLOCK
118#ifdef CONFIG_SMP 117#ifdef CONFIG_SMP
119EXPORT_SYMBOL(_do_spin_lock);
120EXPORT_SYMBOL(_do_spin_unlock);
121EXPORT_SYMBOL(_spin_trylock);
122EXPORT_SYMBOL(_do_read_lock);
123EXPORT_SYMBOL(_do_read_unlock);
124EXPORT_SYMBOL(_do_write_lock);
125EXPORT_SYMBOL(_do_write_unlock);
126#endif
127#else
128// XXX find what uses (or used) these. 118// XXX find what uses (or used) these.
129EXPORT_SYMBOL(___rw_read_enter); 119EXPORT_SYMBOL(___rw_read_enter);
130EXPORT_SYMBOL(___rw_read_exit); 120EXPORT_SYMBOL(___rw_read_exit);
diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
index 2296ff9dc4..fa50069460 100644
--- a/arch/sparc/lib/Makefile
+++ b/arch/sparc/lib/Makefile
@@ -9,5 +9,3 @@ lib-y := mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o memcpy.o memset.o \
9 strncpy_from_user.o divdi3.o udivdi3.o strlen_user.o \ 9 strncpy_from_user.o divdi3.o udivdi3.o strlen_user.o \
10 copy_user.o locks.o atomic.o atomic32.o bitops.o \ 10 copy_user.o locks.o atomic.o atomic32.o bitops.o \
11 lshrdi3.o ashldi3.o rwsem.o muldi3.o bitext.o 11 lshrdi3.o ashldi3.o rwsem.o muldi3.o bitext.o
12
13lib-$(CONFIG_DEBUG_SPINLOCK) += debuglocks.o
diff --git a/arch/sparc/lib/atomic32.c b/arch/sparc/lib/atomic32.c
index 19724c5800..2e64e8c3e8 100644
--- a/arch/sparc/lib/atomic32.c
+++ b/arch/sparc/lib/atomic32.c
@@ -20,7 +20,7 @@ spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] = {
20 20
21#else /* SMP */ 21#else /* SMP */
22 22
23static spinlock_t dummy = SPIN_LOCK_UNLOCKED; 23static DEFINE_SPINLOCK(dummy);
24#define ATOMIC_HASH_SIZE 1 24#define ATOMIC_HASH_SIZE 1
25#define ATOMIC_HASH(a) (&dummy) 25#define ATOMIC_HASH(a) (&dummy)
26 26
diff --git a/arch/sparc/lib/debuglocks.c b/arch/sparc/lib/debuglocks.c
deleted file mode 100644
index fb18235278..0000000000
--- a/arch/sparc/lib/debuglocks.c
+++ /dev/null
@@ -1,202 +0,0 @@
1/* $Id: debuglocks.c,v 1.11 2001/09/20 00:35:31 davem Exp $
2 * debuglocks.c: Debugging versions of SMP locking primitives.
3 *
4 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1998-99 Anton Blanchard (anton@progsoc.uts.edu.au)
6 */
7
8#include <linux/kernel.h>
9#include <linux/sched.h>
10#include <linux/threads.h> /* For NR_CPUS */
11#include <linux/spinlock.h>
12#include <asm/psr.h>
13#include <asm/system.h>
14
15#ifdef CONFIG_SMP
16
17/* Some notes on how these debugging routines work. When a lock is acquired
18 * an extra debugging member lock->owner_pc is set to the caller of the lock
19 * acquisition routine. Right before releasing a lock, the debugging program
20 * counter is cleared to zero.
21 *
22 * Furthermore, since PC's are 4 byte aligned on Sparc, we stuff the CPU
23 * number of the owner in the lowest two bits.
24 */
25
26#define STORE_CALLER(A) __asm__ __volatile__("mov %%i7, %0" : "=r" (A));
27
28static inline void show(char *str, spinlock_t *lock, unsigned long caller)
29{
30 int cpu = smp_processor_id();
31
32 printk("%s(%p) CPU#%d stuck at %08lx, owner PC(%08lx):CPU(%lx)\n",str,
33 lock, cpu, caller, lock->owner_pc & ~3, lock->owner_pc & 3);
34}
35
36static inline void show_read(char *str, rwlock_t *lock, unsigned long caller)
37{
38 int cpu = smp_processor_id();
39
40 printk("%s(%p) CPU#%d stuck at %08lx, owner PC(%08lx):CPU(%lx)\n", str,
41 lock, cpu, caller, lock->owner_pc & ~3, lock->owner_pc & 3);
42}
43
44static inline void show_write(char *str, rwlock_t *lock, unsigned long caller)
45{
46 int cpu = smp_processor_id();
47 int i;
48
49 printk("%s(%p) CPU#%d stuck at %08lx, owner PC(%08lx):CPU(%lx)", str,
50 lock, cpu, caller, lock->owner_pc & ~3, lock->owner_pc & 3);
51
52 for(i = 0; i < NR_CPUS; i++)
53 printk(" reader[%d]=%08lx", i, lock->reader_pc[i]);
54
55 printk("\n");
56}
57
58#undef INIT_STUCK
59#define INIT_STUCK 100000000
60
61void _do_spin_lock(spinlock_t *lock, char *str)
62{
63 unsigned long caller;
64 unsigned long val;
65 int cpu = smp_processor_id();
66 int stuck = INIT_STUCK;
67
68 STORE_CALLER(caller);
69
70again:
71 __asm__ __volatile__("ldstub [%1], %0" : "=r" (val) : "r" (&(lock->lock)));
72 if(val) {
73 while(lock->lock) {
74 if (!--stuck) {
75 show(str, lock, caller);
76 stuck = INIT_STUCK;
77 }
78 barrier();
79 }
80 goto again;
81 }
82 lock->owner_pc = (cpu & 3) | (caller & ~3);
83}
84
85int _spin_trylock(spinlock_t *lock)
86{
87 unsigned long val;
88 unsigned long caller;
89 int cpu = smp_processor_id();
90
91 STORE_CALLER(caller);
92
93 __asm__ __volatile__("ldstub [%1], %0" : "=r" (val) : "r" (&(lock->lock)));
94 if(!val) {
95 /* We got it, record our identity for debugging. */
96 lock->owner_pc = (cpu & 3) | (caller & ~3);
97 }
98 return val == 0;
99}
100
101void _do_spin_unlock(spinlock_t *lock)
102{
103 lock->owner_pc = 0;
104 barrier();
105 lock->lock = 0;
106}
107
108void _do_read_lock(rwlock_t *rw, char *str)
109{
110 unsigned long caller;
111 unsigned long val;
112 int cpu = smp_processor_id();
113 int stuck = INIT_STUCK;
114
115 STORE_CALLER(caller);
116
117wlock_again:
118 __asm__ __volatile__("ldstub [%1 + 3], %0" : "=r" (val) : "r" (&(rw->lock)));
119 if(val) {
120 while(rw->lock & 0xff) {
121 if (!--stuck) {
122 show_read(str, rw, caller);
123 stuck = INIT_STUCK;
124 }
125 barrier();
126 }
127 goto wlock_again;
128 }
129
130 rw->reader_pc[cpu] = caller;
131 barrier();
132 rw->lock++;
133}
134
135void _do_read_unlock(rwlock_t *rw, char *str)
136{
137 unsigned long caller;
138 unsigned long val;
139 int cpu = smp_processor_id();
140 int stuck = INIT_STUCK;
141
142 STORE_CALLER(caller);
143
144wlock_again:
145 __asm__ __volatile__("ldstub [%1 + 3], %0" : "=r" (val) : "r" (&(rw->lock)));
146 if(val) {
147 while(rw->lock & 0xff) {
148 if (!--stuck) {
149 show_read(str, rw, caller);
150 stuck = INIT_STUCK;
151 }
152 barrier();
153 }
154 goto wlock_again;
155 }
156
157 rw->reader_pc[cpu] = 0;
158 barrier();
159 rw->lock -= 0x1ff;
160}
161
162void _do_write_lock(rwlock_t *rw, char *str)
163{
164 unsigned long caller;
165 unsigned long val;
166 int cpu = smp_processor_id();
167 int stuck = INIT_STUCK;
168
169 STORE_CALLER(caller);
170
171wlock_again:
172 __asm__ __volatile__("ldstub [%1 + 3], %0" : "=r" (val) : "r" (&(rw->lock)));
173 if(val) {
174wlock_wait:
175 while(rw->lock) {
176 if (!--stuck) {
177 show_write(str, rw, caller);
178 stuck = INIT_STUCK;
179 }
180 barrier();
181 }
182 goto wlock_again;
183 }
184
185 if (rw->lock & ~0xff) {
186 *(((unsigned char *)&rw->lock)+3) = 0;
187 barrier();
188 goto wlock_wait;
189 }
190
191 barrier();
192 rw->owner_pc = (cpu & 3) | (caller & ~3);
193}
194
195void _do_write_unlock(rwlock_t *rw)
196{
197 rw->owner_pc = 0;
198 barrier();
199 rw->lock = 0;
200}
201
202#endif /* SMP */
diff --git a/arch/sparc/mm/hypersparc.S b/arch/sparc/mm/hypersparc.S
index 54b8e764b0..a231cca372 100644
--- a/arch/sparc/mm/hypersparc.S
+++ b/arch/sparc/mm/hypersparc.S
@@ -6,7 +6,7 @@
6 6
7#include <asm/ptrace.h> 7#include <asm/ptrace.h>
8#include <asm/psr.h> 8#include <asm/psr.h>
9#include <asm/asm_offsets.h> 9#include <asm/asm-offsets.h>
10#include <asm/asi.h> 10#include <asm/asi.h>
11#include <asm/page.h> 11#include <asm/page.h>
12#include <asm/pgtsrmmu.h> 12#include <asm/pgtsrmmu.h>
diff --git a/arch/sparc/mm/swift.S b/arch/sparc/mm/swift.S
index 2dcaa5ac1a..cd90f3fdc4 100644
--- a/arch/sparc/mm/swift.S
+++ b/arch/sparc/mm/swift.S
@@ -9,7 +9,7 @@
9#include <asm/asi.h> 9#include <asm/asi.h>
10#include <asm/page.h> 10#include <asm/page.h>
11#include <asm/pgtsrmmu.h> 11#include <asm/pgtsrmmu.h>
12#include <asm/asm_offsets.h> 12#include <asm/asm-offsets.h>
13 13
14 .text 14 .text
15 .align 4 15 .align 4
diff --git a/arch/sparc/mm/tsunami.S b/arch/sparc/mm/tsunami.S
index 8acd1787fd..697af61759 100644
--- a/arch/sparc/mm/tsunami.S
+++ b/arch/sparc/mm/tsunami.S
@@ -6,7 +6,7 @@
6 6
7#include <linux/config.h> 7#include <linux/config.h>
8#include <asm/ptrace.h> 8#include <asm/ptrace.h>
9#include <asm/asm_offsets.h> 9#include <asm/asm-offsets.h>
10#include <asm/psr.h> 10#include <asm/psr.h>
11#include <asm/asi.h> 11#include <asm/asi.h>
12#include <asm/page.h> 12#include <asm/page.h>
diff --git a/arch/sparc/mm/viking.S b/arch/sparc/mm/viking.S
index f58712d26b..3cbd6de18d 100644
--- a/arch/sparc/mm/viking.S
+++ b/arch/sparc/mm/viking.S
@@ -9,7 +9,7 @@
9#include <linux/config.h> 9#include <linux/config.h>
10#include <asm/ptrace.h> 10#include <asm/ptrace.h>
11#include <asm/psr.h> 11#include <asm/psr.h>
12#include <asm/asm_offsets.h> 12#include <asm/asm-offsets.h>
13#include <asm/asi.h> 13#include <asm/asi.h>
14#include <asm/mxcc.h> 14#include <asm/mxcc.h>
15#include <asm/page.h> 15#include <asm/page.h>
diff --git a/arch/sparc64/kernel/asm-offsets.c b/arch/sparc64/kernel/asm-offsets.c
new file mode 100644
index 0000000000..9e263112a6
--- /dev/null
+++ b/arch/sparc64/kernel/asm-offsets.c
@@ -0,0 +1 @@
/* Dummy asm-offsets.c file. Required by kbuild and ready to be used - hint! */
diff --git a/arch/sparc64/kernel/process.c b/arch/sparc64/kernel/process.c
index 6625543412..7d10b03970 100644
--- a/arch/sparc64/kernel/process.c
+++ b/arch/sparc64/kernel/process.c
@@ -607,11 +607,6 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
607 struct thread_info *t = p->thread_info; 607 struct thread_info *t = p->thread_info;
608 char *child_trap_frame; 608 char *child_trap_frame;
609 609
610#ifdef CONFIG_DEBUG_SPINLOCK
611 p->thread.smp_lock_count = 0;
612 p->thread.smp_lock_pc = 0;
613#endif
614
615 /* Calculate offset to stack_frame & pt_regs */ 610 /* Calculate offset to stack_frame & pt_regs */
616 child_trap_frame = ((char *)t) + (THREAD_SIZE - (TRACEREG_SZ+STACKFRAME_SZ)); 611 child_trap_frame = ((char *)t) + (THREAD_SIZE - (TRACEREG_SZ+STACKFRAME_SZ));
617 memcpy(child_trap_frame, (((struct sparc_stackf *)regs)-1), (TRACEREG_SZ+STACKFRAME_SZ)); 612 memcpy(child_trap_frame, (((struct sparc_stackf *)regs)-1), (TRACEREG_SZ+STACKFRAME_SZ));
diff --git a/arch/sparc64/kernel/sparc64_ksyms.c b/arch/sparc64/kernel/sparc64_ksyms.c
index 7d9a0f6c43..cbb5e59824 100644
--- a/arch/sparc64/kernel/sparc64_ksyms.c
+++ b/arch/sparc64/kernel/sparc64_ksyms.c
@@ -115,17 +115,12 @@ EXPORT_PER_CPU_SYMBOL(__cpu_data);
115 115
116/* used by various drivers */ 116/* used by various drivers */
117#ifdef CONFIG_SMP 117#ifdef CONFIG_SMP
118#ifndef CONFIG_DEBUG_SPINLOCK
119/* Out of line rw-locking implementation. */ 118/* Out of line rw-locking implementation. */
120EXPORT_SYMBOL(__read_lock); 119EXPORT_SYMBOL(__read_lock);
121EXPORT_SYMBOL(__read_unlock); 120EXPORT_SYMBOL(__read_unlock);
122EXPORT_SYMBOL(__write_lock); 121EXPORT_SYMBOL(__write_lock);
123EXPORT_SYMBOL(__write_unlock); 122EXPORT_SYMBOL(__write_unlock);
124EXPORT_SYMBOL(__write_trylock); 123EXPORT_SYMBOL(__write_trylock);
125/* Out of line spin-locking implementation. */
126EXPORT_SYMBOL(_raw_spin_lock);
127EXPORT_SYMBOL(_raw_spin_lock_flags);
128#endif
129 124
130/* Hard IRQ locking */ 125/* Hard IRQ locking */
131EXPORT_SYMBOL(synchronize_irq); 126EXPORT_SYMBOL(synchronize_irq);
diff --git a/arch/sparc64/lib/Makefile b/arch/sparc64/lib/Makefile
index 40dbeec7e5..d968aebe83 100644
--- a/arch/sparc64/lib/Makefile
+++ b/arch/sparc64/lib/Makefile
@@ -14,7 +14,6 @@ lib-y := PeeCeeI.o copy_page.o clear_page.o strlen.o strncmp.o \
14 copy_in_user.o user_fixup.o memmove.o \ 14 copy_in_user.o user_fixup.o memmove.o \
15 mcount.o ipcsum.o rwsem.o xor.o find_bit.o delay.o 15 mcount.o ipcsum.o rwsem.o xor.o find_bit.o delay.o
16 16
17lib-$(CONFIG_DEBUG_SPINLOCK) += debuglocks.o
18lib-$(CONFIG_HAVE_DEC_LOCK) += dec_and_lock.o 17lib-$(CONFIG_HAVE_DEC_LOCK) += dec_and_lock.o
19 18
20obj-y += iomap.o 19obj-y += iomap.o
diff --git a/arch/sparc64/lib/debuglocks.c b/arch/sparc64/lib/debuglocks.c
deleted file mode 100644
index f5f0b5586f..0000000000
--- a/arch/sparc64/lib/debuglocks.c
+++ /dev/null
@@ -1,366 +0,0 @@
1/* $Id: debuglocks.c,v 1.9 2001/11/17 00:10:48 davem Exp $
2 * debuglocks.c: Debugging versions of SMP locking primitives.
3 *
4 * Copyright (C) 1998 David S. Miller (davem@redhat.com)
5 */
6
7#include <linux/config.h>
8#include <linux/kernel.h>
9#include <linux/sched.h>
10#include <linux/spinlock.h>
11#include <asm/system.h>
12
13#ifdef CONFIG_SMP
14
15static inline void show (char *str, spinlock_t *lock, unsigned long caller)
16{
17 int cpu = smp_processor_id();
18
19 printk("%s(%p) CPU#%d stuck at %08x, owner PC(%08x):CPU(%x)\n",
20 str, lock, cpu, (unsigned int) caller,
21 lock->owner_pc, lock->owner_cpu);
22}
23
24static inline void show_read (char *str, rwlock_t *lock, unsigned long caller)
25{
26 int cpu = smp_processor_id();
27
28 printk("%s(%p) CPU#%d stuck at %08x, writer PC(%08x):CPU(%x)\n",
29 str, lock, cpu, (unsigned int) caller,
30 lock->writer_pc, lock->writer_cpu);
31}
32
33static inline void show_write (char *str, rwlock_t *lock, unsigned long caller)
34{
35 int cpu = smp_processor_id();
36 int i;
37
38 printk("%s(%p) CPU#%d stuck at %08x\n",
39 str, lock, cpu, (unsigned int) caller);
40 printk("Writer: PC(%08x):CPU(%x)\n",
41 lock->writer_pc, lock->writer_cpu);
42 printk("Readers:");
43 for (i = 0; i < NR_CPUS; i++)
44 if (lock->reader_pc[i])
45 printk(" %d[%08x]", i, lock->reader_pc[i]);
46 printk("\n");
47}
48
49#undef INIT_STUCK
50#define INIT_STUCK 100000000
51
52void _do_spin_lock(spinlock_t *lock, char *str, unsigned long caller)
53{
54 unsigned long val;
55 int stuck = INIT_STUCK;
56 int cpu = get_cpu();
57 int shown = 0;
58
59again:
60 __asm__ __volatile__("ldstub [%1], %0"
61 : "=r" (val)
62 : "r" (&(lock->lock))
63 : "memory");
64 membar_storeload_storestore();
65 if (val) {
66 while (lock->lock) {
67 if (!--stuck) {
68 if (shown++ <= 2)
69 show(str, lock, caller);
70 stuck = INIT_STUCK;
71 }
72 rmb();
73 }
74 goto again;
75 }
76 lock->owner_pc = ((unsigned int)caller);
77 lock->owner_cpu = cpu;
78 current->thread.smp_lock_count++;
79 current->thread.smp_lock_pc = ((unsigned int)caller);
80
81 put_cpu();
82}
83
84int _do_spin_trylock(spinlock_t *lock, unsigned long caller)
85{
86 unsigned long val;
87 int cpu = get_cpu();
88
89 __asm__ __volatile__("ldstub [%1], %0"
90 : "=r" (val)
91 : "r" (&(lock->lock))
92 : "memory");
93 membar_storeload_storestore();
94 if (!val) {
95 lock->owner_pc = ((unsigned int)caller);
96 lock->owner_cpu = cpu;
97 current->thread.smp_lock_count++;
98 current->thread.smp_lock_pc = ((unsigned int)caller);
99 }
100
101 put_cpu();
102
103 return val == 0;
104}
105
106void _do_spin_unlock(spinlock_t *lock)
107{
108 lock->owner_pc = 0;
109 lock->owner_cpu = NO_PROC_ID;
110 membar_storestore_loadstore();
111 lock->lock = 0;
112 current->thread.smp_lock_count--;
113}
114
115/* Keep INIT_STUCK the same... */
116
117void _do_read_lock(rwlock_t *rw, char *str, unsigned long caller)
118{
119 unsigned long val;
120 int stuck = INIT_STUCK;
121 int cpu = get_cpu();
122 int shown = 0;
123
124wlock_again:
125 /* Wait for any writer to go away. */
126 while (((long)(rw->lock)) < 0) {
127 if (!--stuck) {
128 if (shown++ <= 2)
129 show_read(str, rw, caller);
130 stuck = INIT_STUCK;
131 }
132 rmb();
133 }
134 /* Try once to increment the counter. */
135 __asm__ __volatile__(
136" ldx [%0], %%g1\n"
137" brlz,a,pn %%g1, 2f\n"
138" mov 1, %0\n"
139" add %%g1, 1, %%g7\n"
140" casx [%0], %%g1, %%g7\n"
141" sub %%g1, %%g7, %0\n"
142"2:" : "=r" (val)
143 : "0" (&(rw->lock))
144 : "g1", "g7", "memory");
145 membar_storeload_storestore();
146 if (val)
147 goto wlock_again;
148 rw->reader_pc[cpu] = ((unsigned int)caller);
149 current->thread.smp_lock_count++;
150 current->thread.smp_lock_pc = ((unsigned int)caller);
151
152 put_cpu();
153}
154
155void _do_read_unlock(rwlock_t *rw, char *str, unsigned long caller)
156{
157 unsigned long val;
158 int stuck = INIT_STUCK;
159 int cpu = get_cpu();
160 int shown = 0;
161
162 /* Drop our identity _first_. */
163 rw->reader_pc[cpu] = 0;
164 current->thread.smp_lock_count--;
165runlock_again:
166 /* Spin trying to decrement the counter using casx. */
167 __asm__ __volatile__(
168" membar #StoreLoad | #LoadLoad\n"
169" ldx [%0], %%g1\n"
170" sub %%g1, 1, %%g7\n"
171" casx [%0], %%g1, %%g7\n"
172" membar #StoreLoad | #StoreStore\n"
173" sub %%g1, %%g7, %0\n"
174 : "=r" (val)
175 : "0" (&(rw->lock))
176 : "g1", "g7", "memory");
177 if (val) {
178 if (!--stuck) {
179 if (shown++ <= 2)
180 show_read(str, rw, caller);
181 stuck = INIT_STUCK;
182 }
183 goto runlock_again;
184 }
185
186 put_cpu();
187}
188
189void _do_write_lock(rwlock_t *rw, char *str, unsigned long caller)
190{
191 unsigned long val;
192 int stuck = INIT_STUCK;
193 int cpu = get_cpu();
194 int shown = 0;
195
196wlock_again:
197 /* Spin while there is another writer. */
198 while (((long)rw->lock) < 0) {
199 if (!--stuck) {
200 if (shown++ <= 2)
201 show_write(str, rw, caller);
202 stuck = INIT_STUCK;
203 }
204 rmb();
205 }
206
207 /* Try to acuire the write bit. */
208 __asm__ __volatile__(
209" mov 1, %%g3\n"
210" sllx %%g3, 63, %%g3\n"
211" ldx [%0], %%g1\n"
212" brlz,pn %%g1, 1f\n"
213" or %%g1, %%g3, %%g7\n"
214" casx [%0], %%g1, %%g7\n"
215" membar #StoreLoad | #StoreStore\n"
216" ba,pt %%xcc, 2f\n"
217" sub %%g1, %%g7, %0\n"
218"1: mov 1, %0\n"
219"2:" : "=r" (val)
220 : "0" (&(rw->lock))
221 : "g3", "g1", "g7", "memory");
222 if (val) {
223 /* We couldn't get the write bit. */
224 if (!--stuck) {
225 if (shown++ <= 2)
226 show_write(str, rw, caller);
227 stuck = INIT_STUCK;
228 }
229 goto wlock_again;
230 }
231 if ((rw->lock & ((1UL<<63)-1UL)) != 0UL) {
232 /* Readers still around, drop the write
233 * lock, spin, and try again.
234 */
235 if (!--stuck) {
236 if (shown++ <= 2)
237 show_write(str, rw, caller);
238 stuck = INIT_STUCK;
239 }
240 __asm__ __volatile__(
241" mov 1, %%g3\n"
242" sllx %%g3, 63, %%g3\n"
243"1: ldx [%0], %%g1\n"
244" andn %%g1, %%g3, %%g7\n"
245" casx [%0], %%g1, %%g7\n"
246" cmp %%g1, %%g7\n"
247" membar #StoreLoad | #StoreStore\n"
248" bne,pn %%xcc, 1b\n"
249" nop"
250 : /* no outputs */
251 : "r" (&(rw->lock))
252 : "g3", "g1", "g7", "cc", "memory");
253 while(rw->lock != 0) {
254 if (!--stuck) {
255 if (shown++ <= 2)
256 show_write(str, rw, caller);
257 stuck = INIT_STUCK;
258 }
259 rmb();
260 }
261 goto wlock_again;
262 }
263
264 /* We have it, say who we are. */
265 rw->writer_pc = ((unsigned int)caller);
266 rw->writer_cpu = cpu;
267 current->thread.smp_lock_count++;
268 current->thread.smp_lock_pc = ((unsigned int)caller);
269
270 put_cpu();
271}
272
273void _do_write_unlock(rwlock_t *rw, unsigned long caller)
274{
275 unsigned long val;
276 int stuck = INIT_STUCK;
277 int shown = 0;
278
279 /* Drop our identity _first_ */
280 rw->writer_pc = 0;
281 rw->writer_cpu = NO_PROC_ID;
282 current->thread.smp_lock_count--;
283wlock_again:
284 __asm__ __volatile__(
285" membar #StoreLoad | #LoadLoad\n"
286" mov 1, %%g3\n"
287" sllx %%g3, 63, %%g3\n"
288" ldx [%0], %%g1\n"
289" andn %%g1, %%g3, %%g7\n"
290" casx [%0], %%g1, %%g7\n"
291" membar #StoreLoad | #StoreStore\n"
292" sub %%g1, %%g7, %0\n"
293 : "=r" (val)
294 : "0" (&(rw->lock))
295 : "g3", "g1", "g7", "memory");
296 if (val) {
297 if (!--stuck) {
298 if (shown++ <= 2)
299 show_write("write_unlock", rw, caller);
300 stuck = INIT_STUCK;
301 }
302 goto wlock_again;
303 }
304}
305
306int _do_write_trylock(rwlock_t *rw, char *str, unsigned long caller)
307{
308 unsigned long val;
309 int cpu = get_cpu();
310
311 /* Try to acuire the write bit. */
312 __asm__ __volatile__(
313" mov 1, %%g3\n"
314" sllx %%g3, 63, %%g3\n"
315" ldx [%0], %%g1\n"
316" brlz,pn %%g1, 1f\n"
317" or %%g1, %%g3, %%g7\n"
318" casx [%0], %%g1, %%g7\n"
319" membar #StoreLoad | #StoreStore\n"
320" ba,pt %%xcc, 2f\n"
321" sub %%g1, %%g7, %0\n"
322"1: mov 1, %0\n"
323"2:" : "=r" (val)
324 : "0" (&(rw->lock))
325 : "g3", "g1", "g7", "memory");
326
327 if (val) {
328 put_cpu();
329 return 0;
330 }
331
332 if ((rw->lock & ((1UL<<63)-1UL)) != 0UL) {
333 /* Readers still around, drop the write
334 * lock, return failure.
335 */
336 __asm__ __volatile__(
337" mov 1, %%g3\n"
338" sllx %%g3, 63, %%g3\n"
339"1: ldx [%0], %%g1\n"
340" andn %%g1, %%g3, %%g7\n"
341" casx [%0], %%g1, %%g7\n"
342" cmp %%g1, %%g7\n"
343" membar #StoreLoad | #StoreStore\n"
344" bne,pn %%xcc, 1b\n"
345" nop"
346 : /* no outputs */
347 : "r" (&(rw->lock))
348 : "g3", "g1", "g7", "cc", "memory");
349
350 put_cpu();
351
352 return 0;
353 }
354
355 /* We have it, say who we are. */
356 rw->writer_pc = ((unsigned int)caller);
357 rw->writer_cpu = cpu;
358 current->thread.smp_lock_count++;
359 current->thread.smp_lock_pc = ((unsigned int)caller);
360
361 put_cpu();
362
363 return 1;
364}
365
366#endif /* CONFIG_SMP */
diff --git a/arch/sparc64/solaris/ioctl.c b/arch/sparc64/solaris/ioctl.c
index cac0a1cf00..be0a054e3e 100644
--- a/arch/sparc64/solaris/ioctl.c
+++ b/arch/sparc64/solaris/ioctl.c
@@ -24,6 +24,7 @@
24#include <linux/netdevice.h> 24#include <linux/netdevice.h>
25#include <linux/mtio.h> 25#include <linux/mtio.h>
26#include <linux/time.h> 26#include <linux/time.h>
27#include <linux/rcupdate.h>
27#include <linux/compat.h> 28#include <linux/compat.h>
28 29
29#include <net/sock.h> 30#include <net/sock.h>
@@ -293,16 +294,18 @@ static struct module_info {
293static inline int solaris_sockmod(unsigned int fd, unsigned int cmd, u32 arg) 294static inline int solaris_sockmod(unsigned int fd, unsigned int cmd, u32 arg)
294{ 295{
295 struct inode *ino; 296 struct inode *ino;
297 struct fdtable *fdt;
296 /* I wonder which of these tests are superfluous... --patrik */ 298 /* I wonder which of these tests are superfluous... --patrik */
297 spin_lock(&current->files->file_lock); 299 rcu_read_lock();
298 if (! current->files->fd[fd] || 300 fdt = files_fdtable(current->files);
299 ! current->files->fd[fd]->f_dentry || 301 if (! fdt->fd[fd] ||
300 ! (ino = current->files->fd[fd]->f_dentry->d_inode) || 302 ! fdt->fd[fd]->f_dentry ||
303 ! (ino = fdt->fd[fd]->f_dentry->d_inode) ||
301 ! S_ISSOCK(ino->i_mode)) { 304 ! S_ISSOCK(ino->i_mode)) {
302 spin_unlock(&current->files->file_lock); 305 rcu_read_unlock();
303 return TBADF; 306 return TBADF;
304 } 307 }
305 spin_unlock(&current->files->file_lock); 308 rcu_read_unlock();
306 309
307 switch (cmd & 0xff) { 310 switch (cmd & 0xff) {
308 case 109: /* SI_SOCKPARAMS */ 311 case 109: /* SI_SOCKPARAMS */
diff --git a/arch/sparc64/solaris/timod.c b/arch/sparc64/solaris/timod.c
index 022c80f433..aaad29c35c 100644
--- a/arch/sparc64/solaris/timod.c
+++ b/arch/sparc64/solaris/timod.c
@@ -143,9 +143,11 @@ static struct T_primsg *timod_mkctl(int size)
143static void timod_wake_socket(unsigned int fd) 143static void timod_wake_socket(unsigned int fd)
144{ 144{
145 struct socket *sock; 145 struct socket *sock;
146 struct fdtable *fdt;
146 147
147 SOLD("wakeing socket"); 148 SOLD("wakeing socket");
148 sock = SOCKET_I(current->files->fd[fd]->f_dentry->d_inode); 149 fdt = files_fdtable(current->files);
150 sock = SOCKET_I(fdt->fd[fd]->f_dentry->d_inode);
149 wake_up_interruptible(&sock->wait); 151 wake_up_interruptible(&sock->wait);
150 read_lock(&sock->sk->sk_callback_lock); 152 read_lock(&sock->sk->sk_callback_lock);
151 if (sock->fasync_list && !test_bit(SOCK_ASYNC_WAITDATA, &sock->flags)) 153 if (sock->fasync_list && !test_bit(SOCK_ASYNC_WAITDATA, &sock->flags))
@@ -157,9 +159,11 @@ static void timod_wake_socket(unsigned int fd)
157static void timod_queue(unsigned int fd, struct T_primsg *it) 159static void timod_queue(unsigned int fd, struct T_primsg *it)
158{ 160{
159 struct sol_socket_struct *sock; 161 struct sol_socket_struct *sock;
162 struct fdtable *fdt;
160 163
161 SOLD("queuing primsg"); 164 SOLD("queuing primsg");
162 sock = (struct sol_socket_struct *)current->files->fd[fd]->private_data; 165 fdt = files_fdtable(current->files);
166 sock = (struct sol_socket_struct *)fdt->fd[fd]->private_data;
163 it->next = sock->pfirst; 167 it->next = sock->pfirst;
164 sock->pfirst = it; 168 sock->pfirst = it;
165 if (!sock->plast) 169 if (!sock->plast)
@@ -171,9 +175,11 @@ static void timod_queue(unsigned int fd, struct T_primsg *it)
171static void timod_queue_end(unsigned int fd, struct T_primsg *it) 175static void timod_queue_end(unsigned int fd, struct T_primsg *it)
172{ 176{
173 struct sol_socket_struct *sock; 177 struct sol_socket_struct *sock;
178 struct fdtable *fdt;
174 179
175 SOLD("queuing primsg at end"); 180 SOLD("queuing primsg at end");
176 sock = (struct sol_socket_struct *)current->files->fd[fd]->private_data; 181 fdt = files_fdtable(current->files);
182 sock = (struct sol_socket_struct *)fdt->fd[fd]->private_data;
177 it->next = NULL; 183 it->next = NULL;
178 if (sock->plast) 184 if (sock->plast)
179 sock->plast->next = it; 185 sock->plast->next = it;
@@ -344,6 +350,7 @@ int timod_putmsg(unsigned int fd, char __user *ctl_buf, int ctl_len,
344 char *buf; 350 char *buf;
345 struct file *filp; 351 struct file *filp;
346 struct inode *ino; 352 struct inode *ino;
353 struct fdtable *fdt;
347 struct sol_socket_struct *sock; 354 struct sol_socket_struct *sock;
348 mm_segment_t old_fs = get_fs(); 355 mm_segment_t old_fs = get_fs();
349 long args[6]; 356 long args[6];
@@ -351,7 +358,9 @@ int timod_putmsg(unsigned int fd, char __user *ctl_buf, int ctl_len,
351 (int (*)(int, unsigned long __user *))SYS(socketcall); 358 (int (*)(int, unsigned long __user *))SYS(socketcall);
352 int (*sys_sendto)(int, void __user *, size_t, unsigned, struct sockaddr __user *, int) = 359 int (*sys_sendto)(int, void __user *, size_t, unsigned, struct sockaddr __user *, int) =
353 (int (*)(int, void __user *, size_t, unsigned, struct sockaddr __user *, int))SYS(sendto); 360 (int (*)(int, void __user *, size_t, unsigned, struct sockaddr __user *, int))SYS(sendto);
354 filp = current->files->fd[fd]; 361
362 fdt = files_fdtable(current->files);
363 filp = fdt->fd[fd];
355 ino = filp->f_dentry->d_inode; 364 ino = filp->f_dentry->d_inode;
356 sock = (struct sol_socket_struct *)filp->private_data; 365 sock = (struct sol_socket_struct *)filp->private_data;
357 SOLD("entry"); 366 SOLD("entry");
@@ -620,6 +629,7 @@ int timod_getmsg(unsigned int fd, char __user *ctl_buf, int ctl_maxlen, s32 __us
620 int oldflags; 629 int oldflags;
621 struct file *filp; 630 struct file *filp;
622 struct inode *ino; 631 struct inode *ino;
632 struct fdtable *fdt;
623 struct sol_socket_struct *sock; 633 struct sol_socket_struct *sock;
624 struct T_unitdata_ind udi; 634 struct T_unitdata_ind udi;
625 mm_segment_t old_fs = get_fs(); 635 mm_segment_t old_fs = get_fs();
@@ -632,7 +642,8 @@ int timod_getmsg(unsigned int fd, char __user *ctl_buf, int ctl_maxlen, s32 __us
632 642
633 SOLD("entry"); 643 SOLD("entry");
634 SOLDD(("%u %p %d %p %p %d %p %d\n", fd, ctl_buf, ctl_maxlen, ctl_len, data_buf, data_maxlen, data_len, *flags_p)); 644 SOLDD(("%u %p %d %p %p %d %p %d\n", fd, ctl_buf, ctl_maxlen, ctl_len, data_buf, data_maxlen, data_len, *flags_p));
635 filp = current->files->fd[fd]; 645 fdt = files_fdtable(current->files);
646 filp = fdt->fd[fd];
636 ino = filp->f_dentry->d_inode; 647 ino = filp->f_dentry->d_inode;
637 sock = (struct sol_socket_struct *)filp->private_data; 648 sock = (struct sol_socket_struct *)filp->private_data;
638 SOLDD(("%p %p\n", sock->pfirst, sock->pfirst ? sock->pfirst->next : NULL)); 649 SOLDD(("%p %p\n", sock->pfirst, sock->pfirst ? sock->pfirst->next : NULL));
@@ -844,12 +855,14 @@ asmlinkage int solaris_getmsg(unsigned int fd, u32 arg1, u32 arg2, u32 arg3)
844 int __user *flgptr; 855 int __user *flgptr;
845 int flags; 856 int flags;
846 int error = -EBADF; 857 int error = -EBADF;
858 struct fdtable *fdt;
847 859
848 SOLD("entry"); 860 SOLD("entry");
849 lock_kernel(); 861 lock_kernel();
850 if(fd >= NR_OPEN) goto out; 862 if(fd >= NR_OPEN) goto out;
851 863
852 filp = current->files->fd[fd]; 864 fdt = files_fdtable(current->files);
865 filp = fdt->fd[fd];
853 if(!filp) goto out; 866 if(!filp) goto out;
854 867
855 ino = filp->f_dentry->d_inode; 868 ino = filp->f_dentry->d_inode;
@@ -910,12 +923,14 @@ asmlinkage int solaris_putmsg(unsigned int fd, u32 arg1, u32 arg2, u32 arg3)
910 struct strbuf ctl, dat; 923 struct strbuf ctl, dat;
911 int flags = (int) arg3; 924 int flags = (int) arg3;
912 int error = -EBADF; 925 int error = -EBADF;
926 struct fdtable *fdt;
913 927
914 SOLD("entry"); 928 SOLD("entry");
915 lock_kernel(); 929 lock_kernel();
916 if(fd >= NR_OPEN) goto out; 930 if(fd >= NR_OPEN) goto out;
917 931
918 filp = current->files->fd[fd]; 932 fdt = files_fdtable(current->files);
933 filp = fdt->fd[fd];
919 if(!filp) goto out; 934 if(!filp) goto out;
920 935
921 ino = filp->f_dentry->d_inode; 936 ino = filp->f_dentry->d_inode;
diff --git a/arch/um/Makefile b/arch/um/Makefile
index b15f6048ca..ce987266da 100644
--- a/arch/um/Makefile
+++ b/arch/um/Makefile
@@ -103,12 +103,11 @@ endef
103 103
104ifneq ($(KBUILD_SRC),) 104ifneq ($(KBUILD_SRC),)
105$(shell mkdir -p $(ARCH_DIR) && ln -fsn $(srctree)/$(ARCH_DIR)/Kconfig.$(SUBARCH) $(ARCH_DIR)/Kconfig.arch) 105$(shell mkdir -p $(ARCH_DIR) && ln -fsn $(srctree)/$(ARCH_DIR)/Kconfig.$(SUBARCH) $(ARCH_DIR)/Kconfig.arch)
106CLEAN_FILES += $(ARCH_DIR)/Kconfig.arch
107else 106else
108$(shell cd $(ARCH_DIR) && ln -sf Kconfig.$(SUBARCH) Kconfig.arch) 107$(shell cd $(ARCH_DIR) && ln -sf Kconfig.$(SUBARCH) Kconfig.arch)
109endif 108endif
110 109
111prepare: $(ARCH_SYMLINKS) $(SYS_HEADERS) $(GEN_HEADERS) 110archprepare: $(ARCH_SYMLINKS) $(SYS_HEADERS) $(GEN_HEADERS)
112 111
113LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static 112LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
114LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib 113LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib
@@ -144,14 +143,14 @@ endef
144#TT or skas makefiles and don't clean skas_ptregs.h. 143#TT or skas makefiles and don't clean skas_ptregs.h.
145CLEAN_FILES += linux x.i gmon.out $(ARCH_DIR)/include/uml-config.h \ 144CLEAN_FILES += linux x.i gmon.out $(ARCH_DIR)/include/uml-config.h \
146 $(GEN_HEADERS) $(ARCH_DIR)/include/skas_ptregs.h \ 145 $(GEN_HEADERS) $(ARCH_DIR)/include/skas_ptregs.h \
147 $(ARCH_DIR)/include/user_constants.h 146 $(ARCH_DIR)/include/user_constants.h $(ARCH_DIR)/Kconfig.arch
148 147
149MRPROPER_FILES += $(SYMLINK_HEADERS) $(ARCH_SYMLINKS) \ 148MRPROPER_FILES += $(SYMLINK_HEADERS) $(ARCH_SYMLINKS) \
150 $(addprefix $(ARCH_DIR)/kernel/,$(KERN_SYMLINKS)) $(ARCH_DIR)/os \ 149 $(addprefix $(ARCH_DIR)/kernel/,$(KERN_SYMLINKS)) $(ARCH_DIR)/os
151 $(ARCH_DIR)/Kconfig.arch
152 150
153archclean: 151archclean:
154 $(Q)$(MAKE) $(clean)=$(ARCH_DIR)/util 152 $(Q)$(MAKE) $(clean)=$(ARCH_DIR)/util
153 $(Q)$(MAKE) $(clean)=$(ARCH_DIR)/os-$(OS)/util
155 @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \ 154 @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
156 -o -name '*.gcov' \) -type f -print | xargs rm -f 155 -o -name '*.gcov' \) -type f -print | xargs rm -f
157 156
@@ -197,6 +196,22 @@ define filechk_umlconfig
197 sed 's/ CONFIG/ UML_CONFIG/' 196 sed 's/ CONFIG/ UML_CONFIG/'
198endef 197endef
199 198
199define filechk_gen-asm-offsets
200 (set -e; \
201 echo "#ifndef __ASM_OFFSETS_H__"; \
202 echo "#define __ASM_OFFSETS_H__"; \
203 echo "/*"; \
204 echo " * DO NOT MODIFY."; \
205 echo " *"; \
206 echo " * This file was generated by arch/$(ARCH)/Makefile"; \
207 echo " *"; \
208 echo " */"; \
209 echo ""; \
210 sed -ne "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"; \
211 echo ""; \
212 echo "#endif" )
213endef
214
200$(ARCH_DIR)/include/uml-config.h : include/linux/autoconf.h 215$(ARCH_DIR)/include/uml-config.h : include/linux/autoconf.h
201 $(call filechk,umlconfig) 216 $(call filechk,umlconfig)
202 217
diff --git a/arch/um/include/mem.h b/arch/um/include/mem.h
index 99d3ad4a03..e8ff0d8fa6 100644
--- a/arch/um/include/mem.h
+++ b/arch/um/include/mem.h
@@ -13,7 +13,17 @@ extern int physmem_subst_mapping(void *virt, int fd, __u64 offset, int w);
13extern int is_remapped(void *virt); 13extern int is_remapped(void *virt);
14extern int physmem_remove_mapping(void *virt); 14extern int physmem_remove_mapping(void *virt);
15extern void physmem_forget_descriptor(int fd); 15extern void physmem_forget_descriptor(int fd);
16extern unsigned long to_phys(void *virt); 16
17extern unsigned long uml_physmem;
18static inline unsigned long to_phys(void *virt)
19{
20 return(((unsigned long) virt) - uml_physmem);
21}
22
23static inline void *to_virt(unsigned long phys)
24{
25 return((void *) uml_physmem + phys);
26}
17 27
18#endif 28#endif
19 29
diff --git a/arch/um/kernel/asm-offsets.c b/arch/um/kernel/asm-offsets.c
new file mode 100644
index 0000000000..c13a64a288
--- /dev/null
+++ b/arch/um/kernel/asm-offsets.c
@@ -0,0 +1 @@
/* Dummy file to make kbuild happy - unused! */
diff --git a/arch/um/kernel/dyn.lds.S b/arch/um/kernel/dyn.lds.S
index 3942a5f245..2517ecb8bf 100644
--- a/arch/um/kernel/dyn.lds.S
+++ b/arch/um/kernel/dyn.lds.S
@@ -146,37 +146,8 @@ SECTIONS
146 } 146 }
147 _end = .; 147 _end = .;
148 PROVIDE (end = .); 148 PROVIDE (end = .);
149 /* Stabs debugging sections. */ 149
150 .stab 0 : { *(.stab) } 150 STABS_DEBUG
151 .stabstr 0 : { *(.stabstr) } 151
152 .stab.excl 0 : { *(.stab.excl) } 152 DWARF_DEBUG
153 .stab.exclstr 0 : { *(.stab.exclstr) }
154 .stab.index 0 : { *(.stab.index) }
155 .stab.indexstr 0 : { *(.stab.indexstr) }
156 .comment 0 : { *(.comment) }
157 /* DWARF debug sections.
158 Symbols in the DWARF debugging sections are relative to the beginning
159 of the section so we begin them at 0. */
160 /* DWARF 1 */
161 .debug 0 : { *(.debug) }
162 .line 0 : { *(.line) }
163 /* GNU DWARF 1 extensions */
164 .debug_srcinfo 0 : { *(.debug_srcinfo) }
165 .debug_sfnames 0 : { *(.debug_sfnames) }
166 /* DWARF 1.1 and DWARF 2 */
167 .debug_aranges 0 : { *(.debug_aranges) }
168 .debug_pubnames 0 : { *(.debug_pubnames) }
169 /* DWARF 2 */
170 .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
171 .debug_abbrev 0 : { *(.debug_abbrev) }
172 .debug_line 0 : { *(.debug_line) }
173 .debug_frame 0 : { *(.debug_frame) }
174 .debug_str 0 : { *(.debug_str) }
175 .debug_loc 0 : { *(.debug_loc) }
176 .debug_macinfo 0 : { *(.debug_macinfo) }
177 /* SGI/MIPS DWARF 2 extensions */
178 .debug_weaknames 0 : { *(.debug_weaknames) }
179 .debug_funcnames 0 : { *(.debug_funcnames) }
180 .debug_typenames 0 : { *(.debug_typenames) }
181 .debug_varnames 0 : { *(.debug_varnames) }
182} 153}
diff --git a/arch/um/kernel/ksyms.c b/arch/um/kernel/ksyms.c
index 32d3076dd2..a97a72e516 100644
--- a/arch/um/kernel/ksyms.c
+++ b/arch/um/kernel/ksyms.c
@@ -34,14 +34,9 @@ EXPORT_SYMBOL(host_task_size);
34EXPORT_SYMBOL(arch_validate); 34EXPORT_SYMBOL(arch_validate);
35EXPORT_SYMBOL(get_kmem_end); 35EXPORT_SYMBOL(get_kmem_end);
36 36
37EXPORT_SYMBOL(page_to_phys);
38EXPORT_SYMBOL(phys_to_page);
39EXPORT_SYMBOL(high_physmem); 37EXPORT_SYMBOL(high_physmem);
40EXPORT_SYMBOL(empty_zero_page); 38EXPORT_SYMBOL(empty_zero_page);
41EXPORT_SYMBOL(um_virt_to_phys); 39EXPORT_SYMBOL(um_virt_to_phys);
42EXPORT_SYMBOL(__virt_to_page);
43EXPORT_SYMBOL(to_phys);
44EXPORT_SYMBOL(to_virt);
45EXPORT_SYMBOL(mode_tt); 40EXPORT_SYMBOL(mode_tt);
46EXPORT_SYMBOL(handle_page_fault); 41EXPORT_SYMBOL(handle_page_fault);
47EXPORT_SYMBOL(find_iomem); 42EXPORT_SYMBOL(find_iomem);
diff --git a/arch/um/kernel/physmem.c b/arch/um/kernel/physmem.c
index a24e3b7f4b..ea670fcc8a 100644
--- a/arch/um/kernel/physmem.c
+++ b/arch/um/kernel/physmem.c
@@ -248,16 +248,6 @@ unsigned long high_physmem;
248 248
249extern unsigned long physmem_size; 249extern unsigned long physmem_size;
250 250
251void *to_virt(unsigned long phys)
252{
253 return((void *) uml_physmem + phys);
254}
255
256unsigned long to_phys(void *virt)
257{
258 return(((unsigned long) virt) - uml_physmem);
259}
260
261int init_maps(unsigned long physmem, unsigned long iomem, unsigned long highmem) 251int init_maps(unsigned long physmem, unsigned long iomem, unsigned long highmem)
262{ 252{
263 struct page *p, *map; 253 struct page *p, *map;
@@ -298,31 +288,6 @@ int init_maps(unsigned long physmem, unsigned long iomem, unsigned long highmem)
298 return(0); 288 return(0);
299} 289}
300 290
301struct page *phys_to_page(const unsigned long phys)
302{
303 return(&mem_map[phys >> PAGE_SHIFT]);
304}
305
306struct page *__virt_to_page(const unsigned long virt)
307{
308 return(&mem_map[__pa(virt) >> PAGE_SHIFT]);
309}
310
311phys_t page_to_phys(struct page *page)
312{
313 return((page - mem_map) << PAGE_SHIFT);
314}
315
316pte_t mk_pte(struct page *page, pgprot_t pgprot)
317{
318 pte_t pte;
319
320 pte_set_val(pte, page_to_phys(page), pgprot);
321 if(pte_present(pte))
322 pte_mknewprot(pte_mknewpage(pte));
323 return(pte);
324}
325
326/* Changed during early boot */ 291/* Changed during early boot */
327static unsigned long kmem_top = 0; 292static unsigned long kmem_top = 0;
328 293
diff --git a/arch/um/kernel/trap_kern.c b/arch/um/kernel/trap_kern.c
index b5fc89fe9e..87cc6fd76c 100644
--- a/arch/um/kernel/trap_kern.c
+++ b/arch/um/kernel/trap_kern.c
@@ -57,7 +57,8 @@ good_area:
57 if(is_write && !(vma->vm_flags & VM_WRITE)) 57 if(is_write && !(vma->vm_flags & VM_WRITE))
58 goto out; 58 goto out;
59 59
60 if(!(vma->vm_flags & (VM_READ | VM_EXEC))) 60 /* Don't require VM_READ|VM_EXEC for write faults! */
61 if(!is_write && !(vma->vm_flags & (VM_READ | VM_EXEC)))
61 goto out; 62 goto out;
62 63
63 do { 64 do {
@@ -84,8 +85,7 @@ survive:
84 pte = pte_offset_kernel(pmd, address); 85 pte = pte_offset_kernel(pmd, address);
85 } while(!pte_present(*pte)); 86 } while(!pte_present(*pte));
86 err = 0; 87 err = 0;
87 *pte = pte_mkyoung(*pte); 88 WARN_ON(!pte_young(*pte) || (is_write && !pte_dirty(*pte)));
88 if(pte_write(*pte)) *pte = pte_mkdirty(*pte);
89 flush_tlb_page(vma, address); 89 flush_tlb_page(vma, address);
90out: 90out:
91 up_read(&mm->mmap_sem); 91 up_read(&mm->mmap_sem);
diff --git a/arch/um/kernel/uml.lds.S b/arch/um/kernel/uml.lds.S
index b03326d391..af11915ce0 100644
--- a/arch/um/kernel/uml.lds.S
+++ b/arch/um/kernel/uml.lds.S
@@ -93,14 +93,10 @@ SECTIONS
93 *(.bss) 93 *(.bss)
94 *(COMMON) 94 *(COMMON)
95 } 95 }
96 _end = . ; 96 _end = .;
97 PROVIDE (end = .); 97 PROVIDE (end = .);
98 /* Stabs debugging sections. */ 98
99 .stab 0 : { *(.stab) } 99 STABS_DEBUG
100 .stabstr 0 : { *(.stabstr) } 100
101 .stab.excl 0 : { *(.stab.excl) } 101 DWARF_DEBUG
102 .stab.exclstr 0 : { *(.stab.exclstr) }
103 .stab.index 0 : { *(.stab.index) }
104 .stab.indexstr 0 : { *(.stab.indexstr) }
105 .comment 0 : { *(.comment) }
106} 102}
diff --git a/arch/v850/Makefile b/arch/v850/Makefile
index bf38ca0ad7..8be9aacb20 100644
--- a/arch/v850/Makefile
+++ b/arch/v850/Makefile
@@ -51,16 +51,4 @@ root_fs_image_force: $(ROOT_FS_IMAGE)
51 $(OBJCOPY) $(OBJCOPY_FLAGS_BLOB) --rename-section .data=.root,alloc,load,readonly,data,contents $< root_fs_image.o 51 $(OBJCOPY) $(OBJCOPY_FLAGS_BLOB) --rename-section .data=.root,alloc,load,readonly,data,contents $< root_fs_image.o
52endif 52endif
53 53
54 54CLEAN_FILES += root_fs_image.o
55prepare: include/asm-$(ARCH)/asm-consts.h
56
57# Generate constants from C code for use by asm files
58arch/$(ARCH)/kernel/asm-consts.s: include/asm include/linux/version.h \
59 include/config/MARKER
60
61include/asm-$(ARCH)/asm-consts.h: arch/$(ARCH)/kernel/asm-consts.s
62 $(call filechk,gen-asm-offsets)
63
64CLEAN_FILES += include/asm-$(ARCH)/asm-consts.h \
65 arch/$(ARCH)/kernel/asm-consts.s \
66 root_fs_image.o
diff --git a/arch/v850/kernel/asm-consts.c b/arch/v850/kernel/asm-offsets.c
index 24f2913690..24f2913690 100644
--- a/arch/v850/kernel/asm-consts.c
+++ b/arch/v850/kernel/asm-offsets.c
diff --git a/arch/v850/kernel/entry.S b/arch/v850/kernel/entry.S
index 895e27b1d8..d991e4547d 100644
--- a/arch/v850/kernel/entry.S
+++ b/arch/v850/kernel/entry.S
@@ -22,7 +22,7 @@
22#include <asm/irq.h> 22#include <asm/irq.h>
23#include <asm/errno.h> 23#include <asm/errno.h>
24 24
25#include <asm/asm-consts.h> 25#include <asm/asm-offsets.h>
26 26
27 27
28/* Make a slightly more convenient alias for C_SYMBOL_NAME. */ 28/* Make a slightly more convenient alias for C_SYMBOL_NAME. */
diff --git a/arch/v850/kernel/irq.c b/arch/v850/kernel/irq.c
index 336cbf21dc..9e85969ba9 100644
--- a/arch/v850/kernel/irq.c
+++ b/arch/v850/kernel/irq.c
@@ -67,13 +67,13 @@ static void ack_none(unsigned int irq)
67#define end_none enable_none 67#define end_none enable_none
68 68
69struct hw_interrupt_type no_irq_type = { 69struct hw_interrupt_type no_irq_type = {
70 "none", 70 .typename = "none",
71 startup_none, 71 .startup = startup_none,
72 shutdown_none, 72 .shutdown = shutdown_none,
73 enable_none, 73 .enable = enable_none,
74 disable_none, 74 .disable = disable_none,
75 ack_none, 75 .ack = ack_none,
76 end_none 76 .end = end_none
77}; 77};
78 78
79volatile unsigned long irq_err_count, spurious_count; 79volatile unsigned long irq_err_count, spurious_count;
diff --git a/arch/v850/kernel/setup.c b/arch/v850/kernel/setup.c
index abd48409dc..62bdb8d29f 100644
--- a/arch/v850/kernel/setup.c
+++ b/arch/v850/kernel/setup.c
@@ -138,13 +138,13 @@ static void nmi_end (unsigned irq)
138} 138}
139 139
140static struct hw_interrupt_type nmi_irq_type = { 140static struct hw_interrupt_type nmi_irq_type = {
141 "NMI", 141 .typename = "NMI",
142 irq_zero, /* startup */ 142 .startup = irq_zero, /* startup */
143 irq_nop, /* shutdown */ 143 .shutdown = irq_nop, /* shutdown */
144 irq_nop, /* enable */ 144 .enable = irq_nop, /* enable */
145 irq_nop, /* disable */ 145 .disable = irq_nop, /* disable */
146 irq_nop, /* ack */ 146 .ack = irq_nop, /* ack */
147 nmi_end, /* end */ 147 .end = nmi_end, /* end */
148}; 148};
149 149
150void __init init_IRQ (void) 150void __init init_IRQ (void)
diff --git a/arch/v850/kernel/sim.c b/arch/v850/kernel/sim.c
index e2cc5580fa..17049aaa8f 100644
--- a/arch/v850/kernel/sim.c
+++ b/arch/v850/kernel/sim.c
@@ -73,13 +73,13 @@ static void irq_nop (unsigned irq) { }
73static unsigned irq_zero (unsigned irq) { return 0; } 73static unsigned irq_zero (unsigned irq) { return 0; }
74 74
75static struct hw_interrupt_type sim_irq_type = { 75static struct hw_interrupt_type sim_irq_type = {
76 "IRQ", 76 .typename = "IRQ",
77 irq_zero, /* startup */ 77 .startup = irq_zero, /* startup */
78 irq_nop, /* shutdown */ 78 .shutdown = irq_nop, /* shutdown */
79 irq_nop, /* enable */ 79 .enable = irq_nop, /* enable */
80 irq_nop, /* disable */ 80 .disable = irq_nop, /* disable */
81 irq_nop, /* ack */ 81 .ack = irq_nop, /* ack */
82 irq_nop, /* end */ 82 .end = irq_nop, /* end */
83}; 83};
84 84
85void __init mach_init_irqs (void) 85void __init mach_init_irqs (void)
diff --git a/arch/x86_64/Makefile b/arch/x86_64/Makefile
index 4c6ed96d5f..a9cd42e618 100644
--- a/arch/x86_64/Makefile
+++ b/arch/x86_64/Makefile
@@ -86,16 +86,6 @@ install fdimage fdimage144 fdimage288: vmlinux
86archclean: 86archclean:
87 $(Q)$(MAKE) $(clean)=$(boot) 87 $(Q)$(MAKE) $(clean)=$(boot)
88 88
89prepare: include/asm-$(ARCH)/offset.h
90
91arch/$(ARCH)/kernel/asm-offsets.s: include/asm include/linux/version.h \
92 include/config/MARKER
93
94include/asm-$(ARCH)/offset.h: arch/$(ARCH)/kernel/asm-offsets.s
95 $(call filechk,gen-asm-offsets)
96
97CLEAN_FILES += include/asm-$(ARCH)/offset.h
98
99define archhelp 89define archhelp
100 echo '* bzImage - Compressed kernel image (arch/$(ARCH)/boot/bzImage)' 90 echo '* bzImage - Compressed kernel image (arch/$(ARCH)/boot/bzImage)'
101 echo ' install - Install kernel using' 91 echo ' install - Install kernel using'
diff --git a/arch/x86_64/boot/Makefile b/arch/x86_64/boot/Makefile
index f4399c701b..18c6e915d6 100644
--- a/arch/x86_64/boot/Makefile
+++ b/arch/x86_64/boot/Makefile
@@ -46,7 +46,7 @@ cmd_image = $(obj)/tools/build $(BUILDFLAGS) $(obj)/bootsect $(obj)/setup \
46$(obj)/bzImage: $(obj)/bootsect $(obj)/setup \ 46$(obj)/bzImage: $(obj)/bootsect $(obj)/setup \
47 $(obj)/vmlinux.bin $(obj)/tools/build FORCE 47 $(obj)/vmlinux.bin $(obj)/tools/build FORCE
48 $(call if_changed,image) 48 $(call if_changed,image)
49 @echo 'Kernel: $@ is ready' 49 @echo 'Kernel: $@ is ready' ' (#'`cat .version`')'
50 50
51$(obj)/vmlinux.bin: $(obj)/compressed/vmlinux FORCE 51$(obj)/vmlinux.bin: $(obj)/compressed/vmlinux FORCE
52 $(call if_changed,objcopy) 52 $(call if_changed,objcopy)
diff --git a/arch/x86_64/boot/compressed/misc.c b/arch/x86_64/boot/compressed/misc.c
index b38d5b8b5f..0e10fd84c7 100644
--- a/arch/x86_64/boot/compressed/misc.c
+++ b/arch/x86_64/boot/compressed/misc.c
@@ -83,7 +83,7 @@ static unsigned char *real_mode; /* Pointer to real-mode data */
83#endif 83#endif
84#define SCREEN_INFO (*(struct screen_info *)(real_mode+0)) 84#define SCREEN_INFO (*(struct screen_info *)(real_mode+0))
85 85
86extern char input_data[]; 86extern unsigned char input_data[];
87extern int input_len; 87extern int input_len;
88 88
89static long bytes_out = 0; 89static long bytes_out = 0;
@@ -288,7 +288,7 @@ void setup_normal_output_buffer(void)
288#else 288#else
289 if ((ALT_MEM_K > EXT_MEM_K ? ALT_MEM_K : EXT_MEM_K) < 1024) error("Less than 2MB of memory"); 289 if ((ALT_MEM_K > EXT_MEM_K ? ALT_MEM_K : EXT_MEM_K) < 1024) error("Less than 2MB of memory");
290#endif 290#endif
291 output_data = (char *)__PHYSICAL_START; /* Normally Points to 1M */ 291 output_data = (unsigned char *)__PHYSICAL_START; /* Normally Points to 1M */
292 free_mem_end_ptr = (long)real_mode; 292 free_mem_end_ptr = (long)real_mode;
293} 293}
294 294
@@ -305,7 +305,7 @@ void setup_output_buffer_if_we_run_high(struct moveparams *mv)
305#else 305#else
306 if ((ALT_MEM_K > EXT_MEM_K ? ALT_MEM_K : EXT_MEM_K) < (3*1024)) error("Less than 4MB of memory"); 306 if ((ALT_MEM_K > EXT_MEM_K ? ALT_MEM_K : EXT_MEM_K) < (3*1024)) error("Less than 4MB of memory");
307#endif 307#endif
308 mv->low_buffer_start = output_data = (char *)LOW_BUFFER_START; 308 mv->low_buffer_start = output_data = (unsigned char *)LOW_BUFFER_START;
309 low_buffer_end = ((unsigned int)real_mode > LOW_BUFFER_MAX 309 low_buffer_end = ((unsigned int)real_mode > LOW_BUFFER_MAX
310 ? LOW_BUFFER_MAX : (unsigned int)real_mode) & ~0xfff; 310 ? LOW_BUFFER_MAX : (unsigned int)real_mode) & ~0xfff;
311 low_buffer_size = low_buffer_end - LOW_BUFFER_START; 311 low_buffer_size = low_buffer_end - LOW_BUFFER_START;
diff --git a/arch/x86_64/defconfig b/arch/x86_64/defconfig
index bf57e2362b..f8db7e500f 100644
--- a/arch/x86_64/defconfig
+++ b/arch/x86_64/defconfig
@@ -1,11 +1,12 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.13-rc6-git3 3# Linux kernel version: 2.6.13-git11
4# Fri Aug 12 16:40:34 2005 4# Mon Sep 12 16:16:16 2005
5# 5#
6CONFIG_X86_64=y 6CONFIG_X86_64=y
7CONFIG_64BIT=y 7CONFIG_64BIT=y
8CONFIG_X86=y 8CONFIG_X86=y
9CONFIG_SEMAPHORE_SLEEPERS=y
9CONFIG_MMU=y 10CONFIG_MMU=y
10CONFIG_RWSEM_GENERIC_SPINLOCK=y 11CONFIG_RWSEM_GENERIC_SPINLOCK=y
11CONFIG_GENERIC_CALIBRATE_DELAY=y 12CONFIG_GENERIC_CALIBRATE_DELAY=y
@@ -13,6 +14,7 @@ CONFIG_X86_CMPXCHG=y
13CONFIG_EARLY_PRINTK=y 14CONFIG_EARLY_PRINTK=y
14CONFIG_GENERIC_ISA_DMA=y 15CONFIG_GENERIC_ISA_DMA=y
15CONFIG_GENERIC_IOMAP=y 16CONFIG_GENERIC_IOMAP=y
17CONFIG_ARCH_MAY_HAVE_PC_FDC=y
16 18
17# 19#
18# Code maturity level options 20# Code maturity level options
@@ -26,6 +28,7 @@ CONFIG_INIT_ENV_ARG_LIMIT=32
26# General setup 28# General setup
27# 29#
28CONFIG_LOCALVERSION="" 30CONFIG_LOCALVERSION=""
31CONFIG_LOCALVERSION_AUTO=y
29CONFIG_SWAP=y 32CONFIG_SWAP=y
30CONFIG_SYSVIPC=y 33CONFIG_SYSVIPC=y
31CONFIG_POSIX_MQUEUE=y 34CONFIG_POSIX_MQUEUE=y
@@ -37,6 +40,7 @@ CONFIG_KOBJECT_UEVENT=y
37CONFIG_IKCONFIG=y 40CONFIG_IKCONFIG=y
38CONFIG_IKCONFIG_PROC=y 41CONFIG_IKCONFIG_PROC=y
39# CONFIG_CPUSETS is not set 42# CONFIG_CPUSETS is not set
43CONFIG_INITRAMFS_SOURCE=""
40# CONFIG_EMBEDDED is not set 44# CONFIG_EMBEDDED is not set
41CONFIG_KALLSYMS=y 45CONFIG_KALLSYMS=y
42CONFIG_KALLSYMS_ALL=y 46CONFIG_KALLSYMS_ALL=y
@@ -102,6 +106,7 @@ CONFIG_DISCONTIGMEM_MANUAL=y
102CONFIG_DISCONTIGMEM=y 106CONFIG_DISCONTIGMEM=y
103CONFIG_FLAT_NODE_MEM_MAP=y 107CONFIG_FLAT_NODE_MEM_MAP=y
104CONFIG_NEED_MULTIPLE_NODES=y 108CONFIG_NEED_MULTIPLE_NODES=y
109# CONFIG_SPARSEMEM_STATIC is not set
105CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID=y 110CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID=y
106CONFIG_HAVE_DEC_LOCK=y 111CONFIG_HAVE_DEC_LOCK=y
107CONFIG_NR_CPUS=32 112CONFIG_NR_CPUS=32
@@ -122,6 +127,7 @@ CONFIG_HZ=250
122CONFIG_GENERIC_HARDIRQS=y 127CONFIG_GENERIC_HARDIRQS=y
123CONFIG_GENERIC_IRQ_PROBE=y 128CONFIG_GENERIC_IRQ_PROBE=y
124CONFIG_ISA_DMA_API=y 129CONFIG_ISA_DMA_API=y
130CONFIG_GENERIC_PENDING_IRQ=y
125 131
126# 132#
127# Power management options 133# Power management options
@@ -194,7 +200,6 @@ CONFIG_UNORDERED_IO=y
194# CONFIG_PCIEPORTBUS is not set 200# CONFIG_PCIEPORTBUS is not set
195CONFIG_PCI_MSI=y 201CONFIG_PCI_MSI=y
196# CONFIG_PCI_LEGACY_PROC is not set 202# CONFIG_PCI_LEGACY_PROC is not set
197# CONFIG_PCI_NAMES is not set
198# CONFIG_PCI_DEBUG is not set 203# CONFIG_PCI_DEBUG is not set
199 204
200# 205#
@@ -234,7 +239,10 @@ CONFIG_INET=y
234CONFIG_IP_MULTICAST=y 239CONFIG_IP_MULTICAST=y
235# CONFIG_IP_ADVANCED_ROUTER is not set 240# CONFIG_IP_ADVANCED_ROUTER is not set
236CONFIG_IP_FIB_HASH=y 241CONFIG_IP_FIB_HASH=y
237# CONFIG_IP_PNP is not set 242CONFIG_IP_PNP=y
243CONFIG_IP_PNP_DHCP=y
244# CONFIG_IP_PNP_BOOTP is not set
245# CONFIG_IP_PNP_RARP is not set
238# CONFIG_NET_IPIP is not set 246# CONFIG_NET_IPIP is not set
239# CONFIG_NET_IPGRE is not set 247# CONFIG_NET_IPGRE is not set
240# CONFIG_IP_MROUTE is not set 248# CONFIG_IP_MROUTE is not set
@@ -244,8 +252,8 @@ CONFIG_IP_FIB_HASH=y
244# CONFIG_INET_ESP is not set 252# CONFIG_INET_ESP is not set
245# CONFIG_INET_IPCOMP is not set 253# CONFIG_INET_IPCOMP is not set
246# CONFIG_INET_TUNNEL is not set 254# CONFIG_INET_TUNNEL is not set
247CONFIG_IP_TCPDIAG=y 255CONFIG_INET_DIAG=y
248CONFIG_IP_TCPDIAG_IPV6=y 256CONFIG_INET_TCP_DIAG=y
249# CONFIG_TCP_CONG_ADVANCED is not set 257# CONFIG_TCP_CONG_ADVANCED is not set
250CONFIG_TCP_CONG_BIC=y 258CONFIG_TCP_CONG_BIC=y
251CONFIG_IPV6=y 259CONFIG_IPV6=y
@@ -258,6 +266,11 @@ CONFIG_IPV6=y
258# CONFIG_NETFILTER is not set 266# CONFIG_NETFILTER is not set
259 267
260# 268#
269# DCCP Configuration (EXPERIMENTAL)
270#
271# CONFIG_IP_DCCP is not set
272
273#
261# SCTP Configuration (EXPERIMENTAL) 274# SCTP Configuration (EXPERIMENTAL)
262# 275#
263# CONFIG_IP_SCTP is not set 276# CONFIG_IP_SCTP is not set
@@ -280,9 +293,11 @@ CONFIG_IPV6=y
280# Network testing 293# Network testing
281# 294#
282# CONFIG_NET_PKTGEN is not set 295# CONFIG_NET_PKTGEN is not set
296# CONFIG_NETFILTER_NETLINK is not set
283# CONFIG_HAMRADIO is not set 297# CONFIG_HAMRADIO is not set
284# CONFIG_IRDA is not set 298# CONFIG_IRDA is not set
285# CONFIG_BT is not set 299# CONFIG_BT is not set
300# CONFIG_IEEE80211 is not set
286 301
287# 302#
288# Device Drivers 303# Device Drivers
@@ -329,7 +344,6 @@ CONFIG_BLK_DEV_RAM=y
329CONFIG_BLK_DEV_RAM_COUNT=16 344CONFIG_BLK_DEV_RAM_COUNT=16
330CONFIG_BLK_DEV_RAM_SIZE=4096 345CONFIG_BLK_DEV_RAM_SIZE=4096
331CONFIG_BLK_DEV_INITRD=y 346CONFIG_BLK_DEV_INITRD=y
332CONFIG_INITRAMFS_SOURCE=""
333CONFIG_LBD=y 347CONFIG_LBD=y
334# CONFIG_CDROM_PKTCDVD is not set 348# CONFIG_CDROM_PKTCDVD is not set
335 349
@@ -409,6 +423,7 @@ CONFIG_IDEDMA_AUTO=y
409# 423#
410# SCSI device support 424# SCSI device support
411# 425#
426# CONFIG_RAID_ATTRS is not set
412CONFIG_SCSI=y 427CONFIG_SCSI=y
413# CONFIG_SCSI_PROC_FS is not set 428# CONFIG_SCSI_PROC_FS is not set
414 429
@@ -432,7 +447,7 @@ CONFIG_BLK_DEV_SD=y
432# 447#
433# SCSI Transport Attributes 448# SCSI Transport Attributes
434# 449#
435# CONFIG_SCSI_SPI_ATTRS is not set 450CONFIG_SCSI_SPI_ATTRS=y
436# CONFIG_SCSI_FC_ATTRS is not set 451# CONFIG_SCSI_FC_ATTRS is not set
437# CONFIG_SCSI_ISCSI_ATTRS is not set 452# CONFIG_SCSI_ISCSI_ATTRS is not set
438 453
@@ -458,6 +473,7 @@ CONFIG_SCSI_SATA=y
458# CONFIG_SCSI_SATA_AHCI is not set 473# CONFIG_SCSI_SATA_AHCI is not set
459# CONFIG_SCSI_SATA_SVW is not set 474# CONFIG_SCSI_SATA_SVW is not set
460CONFIG_SCSI_ATA_PIIX=y 475CONFIG_SCSI_ATA_PIIX=y
476# CONFIG_SCSI_SATA_MV is not set
461# CONFIG_SCSI_SATA_NV is not set 477# CONFIG_SCSI_SATA_NV is not set
462# CONFIG_SCSI_SATA_PROMISE is not set 478# CONFIG_SCSI_SATA_PROMISE is not set
463# CONFIG_SCSI_SATA_QSTOR is not set 479# CONFIG_SCSI_SATA_QSTOR is not set
@@ -537,6 +553,11 @@ CONFIG_TUN=y
537# CONFIG_ARCNET is not set 553# CONFIG_ARCNET is not set
538 554
539# 555#
556# PHY device support
557#
558# CONFIG_PHYLIB is not set
559
560#
540# Ethernet (10 or 100Mbit) 561# Ethernet (10 or 100Mbit)
541# 562#
542CONFIG_NET_ETHERNET=y 563CONFIG_NET_ETHERNET=y
@@ -586,6 +607,7 @@ CONFIG_E1000=y
586# CONFIG_HAMACHI is not set 607# CONFIG_HAMACHI is not set
587# CONFIG_YELLOWFIN is not set 608# CONFIG_YELLOWFIN is not set
588# CONFIG_R8169 is not set 609# CONFIG_R8169 is not set
610# CONFIG_SIS190 is not set
589# CONFIG_SKGE is not set 611# CONFIG_SKGE is not set
590# CONFIG_SK98LIN is not set 612# CONFIG_SK98LIN is not set
591# CONFIG_VIA_VELOCITY is not set 613# CONFIG_VIA_VELOCITY is not set
@@ -595,6 +617,7 @@ CONFIG_TIGON3=y
595# 617#
596# Ethernet (10000 Mbit) 618# Ethernet (10000 Mbit)
597# 619#
620# CONFIG_CHELSIO_T1 is not set
598# CONFIG_IXGB is not set 621# CONFIG_IXGB is not set
599CONFIG_S2IO=m 622CONFIG_S2IO=m
600# CONFIG_S2IO_NAPI is not set 623# CONFIG_S2IO_NAPI is not set
@@ -749,7 +772,6 @@ CONFIG_MAX_RAW_DEVS=256
749# I2C support 772# I2C support
750# 773#
751# CONFIG_I2C is not set 774# CONFIG_I2C is not set
752# CONFIG_I2C_SENSOR is not set
753 775
754# 776#
755# Dallas's 1-wire bus 777# Dallas's 1-wire bus
@@ -760,6 +782,7 @@ CONFIG_MAX_RAW_DEVS=256
760# Hardware Monitoring support 782# Hardware Monitoring support
761# 783#
762CONFIG_HWMON=y 784CONFIG_HWMON=y
785# CONFIG_HWMON_VID is not set
763# CONFIG_HWMON_DEBUG_CHIP is not set 786# CONFIG_HWMON_DEBUG_CHIP is not set
764 787
765# 788#
@@ -768,6 +791,10 @@ CONFIG_HWMON=y
768# CONFIG_IBM_ASM is not set 791# CONFIG_IBM_ASM is not set
769 792
770# 793#
794# Multimedia Capabilities Port drivers
795#
796
797#
771# Multimedia devices 798# Multimedia devices
772# 799#
773# CONFIG_VIDEO_DEV is not set 800# CONFIG_VIDEO_DEV is not set
@@ -858,9 +885,8 @@ CONFIG_USB_UHCI_HCD=y
858# 885#
859# USB Device Class drivers 886# USB Device Class drivers
860# 887#
861# CONFIG_USB_AUDIO is not set 888# CONFIG_OBSOLETE_OSS_USB_DRIVER is not set
862# CONFIG_USB_BLUETOOTH_TTY is not set 889# CONFIG_USB_BLUETOOTH_TTY is not set
863# CONFIG_USB_MIDI is not set
864# CONFIG_USB_ACM is not set 890# CONFIG_USB_ACM is not set
865CONFIG_USB_PRINTER=y 891CONFIG_USB_PRINTER=y
866 892
@@ -877,6 +903,7 @@ CONFIG_USB_STORAGE=y
877# CONFIG_USB_STORAGE_SDDR09 is not set 903# CONFIG_USB_STORAGE_SDDR09 is not set
878# CONFIG_USB_STORAGE_SDDR55 is not set 904# CONFIG_USB_STORAGE_SDDR55 is not set
879# CONFIG_USB_STORAGE_JUMPSHOT is not set 905# CONFIG_USB_STORAGE_JUMPSHOT is not set
906# CONFIG_USB_STORAGE_ONETOUCH is not set
880 907
881# 908#
882# USB Input Devices 909# USB Input Devices
@@ -893,6 +920,7 @@ CONFIG_USB_HIDINPUT=y
893# CONFIG_USB_MTOUCH is not set 920# CONFIG_USB_MTOUCH is not set
894# CONFIG_USB_ITMTOUCH is not set 921# CONFIG_USB_ITMTOUCH is not set
895# CONFIG_USB_EGALAX is not set 922# CONFIG_USB_EGALAX is not set
923# CONFIG_USB_YEALINK is not set
896# CONFIG_USB_XPAD is not set 924# CONFIG_USB_XPAD is not set
897# CONFIG_USB_ATI_REMOTE is not set 925# CONFIG_USB_ATI_REMOTE is not set
898# CONFIG_USB_KEYSPAN_REMOTE is not set 926# CONFIG_USB_KEYSPAN_REMOTE is not set
@@ -976,6 +1004,8 @@ CONFIG_USB_MON=y
976# Firmware Drivers 1004# Firmware Drivers
977# 1005#
978# CONFIG_EDD is not set 1006# CONFIG_EDD is not set
1007# CONFIG_DELL_RBU is not set
1008CONFIG_DCDBAS=m
979 1009
980# 1010#
981# File systems 1011# File systems
@@ -1000,10 +1030,6 @@ CONFIG_REISERFS_FS_POSIX_ACL=y
1000# CONFIG_REISERFS_FS_SECURITY is not set 1030# CONFIG_REISERFS_FS_SECURITY is not set
1001# CONFIG_JFS_FS is not set 1031# CONFIG_JFS_FS is not set
1002CONFIG_FS_POSIX_ACL=y 1032CONFIG_FS_POSIX_ACL=y
1003
1004#
1005# XFS support
1006#
1007# CONFIG_XFS_FS is not set 1033# CONFIG_XFS_FS is not set
1008# CONFIG_MINIX_FS is not set 1034# CONFIG_MINIX_FS is not set
1009# CONFIG_ROMFS_FS is not set 1035# CONFIG_ROMFS_FS is not set
@@ -1012,6 +1038,7 @@ CONFIG_INOTIFY=y
1012CONFIG_DNOTIFY=y 1038CONFIG_DNOTIFY=y
1013CONFIG_AUTOFS_FS=y 1039CONFIG_AUTOFS_FS=y
1014# CONFIG_AUTOFS4_FS is not set 1040# CONFIG_AUTOFS4_FS is not set
1041# CONFIG_FUSE_FS is not set
1015 1042
1016# 1043#
1017# CD-ROM/DVD Filesystems 1044# CD-ROM/DVD Filesystems
@@ -1037,12 +1064,11 @@ CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
1037CONFIG_PROC_FS=y 1064CONFIG_PROC_FS=y
1038CONFIG_PROC_KCORE=y 1065CONFIG_PROC_KCORE=y
1039CONFIG_SYSFS=y 1066CONFIG_SYSFS=y
1040# CONFIG_DEVPTS_FS_XATTR is not set
1041CONFIG_TMPFS=y 1067CONFIG_TMPFS=y
1042# CONFIG_TMPFS_XATTR is not set
1043CONFIG_HUGETLBFS=y 1068CONFIG_HUGETLBFS=y
1044CONFIG_HUGETLB_PAGE=y 1069CONFIG_HUGETLB_PAGE=y
1045CONFIG_RAMFS=y 1070CONFIG_RAMFS=y
1071# CONFIG_RELAYFS_FS is not set
1046 1072
1047# 1073#
1048# Miscellaneous filesystems 1074# Miscellaneous filesystems
@@ -1074,6 +1100,7 @@ CONFIG_NFSD_V3=y
1074# CONFIG_NFSD_V3_ACL is not set 1100# CONFIG_NFSD_V3_ACL is not set
1075# CONFIG_NFSD_V4 is not set 1101# CONFIG_NFSD_V4 is not set
1076CONFIG_NFSD_TCP=y 1102CONFIG_NFSD_TCP=y
1103CONFIG_ROOT_NFS=y
1077CONFIG_LOCKD=y 1104CONFIG_LOCKD=y
1078CONFIG_LOCKD_V4=y 1105CONFIG_LOCKD_V4=y
1079CONFIG_EXPORTFS=y 1106CONFIG_EXPORTFS=y
@@ -1086,6 +1113,7 @@ CONFIG_SUNRPC=y
1086# CONFIG_NCP_FS is not set 1113# CONFIG_NCP_FS is not set
1087# CONFIG_CODA_FS is not set 1114# CONFIG_CODA_FS is not set
1088# CONFIG_AFS_FS is not set 1115# CONFIG_AFS_FS is not set
1116# CONFIG_9P_FS is not set
1089 1117
1090# 1118#
1091# Partition Types 1119# Partition Types
@@ -1150,6 +1178,7 @@ CONFIG_OPROFILE=y
1150CONFIG_DEBUG_KERNEL=y 1178CONFIG_DEBUG_KERNEL=y
1151CONFIG_MAGIC_SYSRQ=y 1179CONFIG_MAGIC_SYSRQ=y
1152CONFIG_LOG_BUF_SHIFT=18 1180CONFIG_LOG_BUF_SHIFT=18
1181CONFIG_DETECT_SOFTLOCKUP=y
1153# CONFIG_SCHEDSTATS is not set 1182# CONFIG_SCHEDSTATS is not set
1154# CONFIG_DEBUG_SLAB is not set 1183# CONFIG_DEBUG_SLAB is not set
1155# CONFIG_DEBUG_SPINLOCK is not set 1184# CONFIG_DEBUG_SPINLOCK is not set
@@ -1157,6 +1186,7 @@ CONFIG_LOG_BUF_SHIFT=18
1157# CONFIG_DEBUG_KOBJECT is not set 1186# CONFIG_DEBUG_KOBJECT is not set
1158# CONFIG_DEBUG_INFO is not set 1187# CONFIG_DEBUG_INFO is not set
1159CONFIG_DEBUG_FS=y 1188CONFIG_DEBUG_FS=y
1189# CONFIG_FRAME_POINTER is not set
1160CONFIG_INIT_DEBUG=y 1190CONFIG_INIT_DEBUG=y
1161# CONFIG_IOMMU_DEBUG is not set 1191# CONFIG_IOMMU_DEBUG is not set
1162CONFIG_KPROBES=y 1192CONFIG_KPROBES=y
@@ -1180,5 +1210,6 @@ CONFIG_KPROBES=y
1180# Library routines 1210# Library routines
1181# 1211#
1182# CONFIG_CRC_CCITT is not set 1212# CONFIG_CRC_CCITT is not set
1213# CONFIG_CRC16 is not set
1183CONFIG_CRC32=y 1214CONFIG_CRC32=y
1184# CONFIG_LIBCRC32C is not set 1215# CONFIG_LIBCRC32C is not set
diff --git a/arch/x86_64/ia32/ia32_ioctl.c b/arch/x86_64/ia32/ia32_ioctl.c
index d259f8a6f8..419758f19c 100644
--- a/arch/x86_64/ia32/ia32_ioctl.c
+++ b/arch/x86_64/ia32/ia32_ioctl.c
@@ -24,17 +24,26 @@
24static int tiocgdev(unsigned fd, unsigned cmd, unsigned int __user *ptr) 24static int tiocgdev(unsigned fd, unsigned cmd, unsigned int __user *ptr)
25{ 25{
26 26
27 struct file *file = fget(fd); 27 struct file *file;
28 struct tty_struct *real_tty; 28 struct tty_struct *real_tty;
29 int fput_needed, ret;
29 30
31 file = fget_light(fd, &fput_needed);
30 if (!file) 32 if (!file)
31 return -EBADF; 33 return -EBADF;
34
35 ret = -EINVAL;
32 if (file->f_op->ioctl != tty_ioctl) 36 if (file->f_op->ioctl != tty_ioctl)
33 return -EINVAL; 37 goto out;
34 real_tty = (struct tty_struct *)file->private_data; 38 real_tty = (struct tty_struct *)file->private_data;
35 if (!real_tty) 39 if (!real_tty)
36 return -EINVAL; 40 goto out;
37 return put_user(new_encode_dev(tty_devnum(real_tty)), ptr); 41
42 ret = put_user(new_encode_dev(tty_devnum(real_tty)), ptr);
43
44out:
45 fput_light(file, fput_needed);
46 return ret;
38} 47}
39 48
40#define RTC_IRQP_READ32 _IOR('p', 0x0b, unsigned int) /* Read IRQ rate */ 49#define RTC_IRQP_READ32 _IOR('p', 0x0b, unsigned int) /* Read IRQ rate */
diff --git a/arch/x86_64/ia32/ia32entry.S b/arch/x86_64/ia32/ia32entry.S
index f174083d55..e0eb0c712f 100644
--- a/arch/x86_64/ia32/ia32entry.S
+++ b/arch/x86_64/ia32/ia32entry.S
@@ -6,7 +6,7 @@
6 6
7#include <asm/dwarf2.h> 7#include <asm/dwarf2.h>
8#include <asm/calling.h> 8#include <asm/calling.h>
9#include <asm/offset.h> 9#include <asm/asm-offsets.h>
10#include <asm/current.h> 10#include <asm/current.h>
11#include <asm/errno.h> 11#include <asm/errno.h>
12#include <asm/ia32_unistd.h> 12#include <asm/ia32_unistd.h>
@@ -55,20 +55,34 @@
55 * with the int 0x80 path. 55 * with the int 0x80 path.
56 */ 56 */
57ENTRY(ia32_sysenter_target) 57ENTRY(ia32_sysenter_target)
58 CFI_STARTPROC 58 CFI_STARTPROC simple
59 CFI_DEF_CFA rsp,0
60 CFI_REGISTER rsp,rbp
59 swapgs 61 swapgs
60 movq %gs:pda_kernelstack, %rsp 62 movq %gs:pda_kernelstack, %rsp
61 addq $(PDA_STACKOFFSET),%rsp 63 addq $(PDA_STACKOFFSET),%rsp
62 sti 64 sti
63 movl %ebp,%ebp /* zero extension */ 65 movl %ebp,%ebp /* zero extension */
64 pushq $__USER32_DS 66 pushq $__USER32_DS
67 CFI_ADJUST_CFA_OFFSET 8
68 /*CFI_REL_OFFSET ss,0*/
65 pushq %rbp 69 pushq %rbp
70 CFI_ADJUST_CFA_OFFSET 8
71 CFI_REL_OFFSET rsp,0
66 pushfq 72 pushfq
73 CFI_ADJUST_CFA_OFFSET 8
74 /*CFI_REL_OFFSET rflags,0*/
67 movl $VSYSCALL32_SYSEXIT, %r10d 75 movl $VSYSCALL32_SYSEXIT, %r10d
76 CFI_REGISTER rip,r10
68 pushq $__USER32_CS 77 pushq $__USER32_CS
78 CFI_ADJUST_CFA_OFFSET 8
79 /*CFI_REL_OFFSET cs,0*/
69 movl %eax, %eax 80 movl %eax, %eax
70 pushq %r10 81 pushq %r10
82 CFI_ADJUST_CFA_OFFSET 8
83 CFI_REL_OFFSET rip,0
71 pushq %rax 84 pushq %rax
85 CFI_ADJUST_CFA_OFFSET 8
72 cld 86 cld
73 SAVE_ARGS 0,0,1 87 SAVE_ARGS 0,0,1
74 /* no need to do an access_ok check here because rbp has been 88 /* no need to do an access_ok check here because rbp has been
@@ -79,6 +93,7 @@ ENTRY(ia32_sysenter_target)
79 .previous 93 .previous
80 GET_THREAD_INFO(%r10) 94 GET_THREAD_INFO(%r10)
81 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10) 95 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
96 CFI_REMEMBER_STATE
82 jnz sysenter_tracesys 97 jnz sysenter_tracesys
83sysenter_do_call: 98sysenter_do_call:
84 cmpl $(IA32_NR_syscalls),%eax 99 cmpl $(IA32_NR_syscalls),%eax
@@ -94,14 +109,20 @@ sysenter_do_call:
94 andl $~0x200,EFLAGS-R11(%rsp) 109 andl $~0x200,EFLAGS-R11(%rsp)
95 RESTORE_ARGS 1,24,1,1,1,1 110 RESTORE_ARGS 1,24,1,1,1,1
96 popfq 111 popfq
112 CFI_ADJUST_CFA_OFFSET -8
113 /*CFI_RESTORE rflags*/
97 popq %rcx /* User %esp */ 114 popq %rcx /* User %esp */
115 CFI_ADJUST_CFA_OFFSET -8
116 CFI_REGISTER rsp,rcx
98 movl $VSYSCALL32_SYSEXIT,%edx /* User %eip */ 117 movl $VSYSCALL32_SYSEXIT,%edx /* User %eip */
118 CFI_REGISTER rip,rdx
99 swapgs 119 swapgs
100 sti /* sti only takes effect after the next instruction */ 120 sti /* sti only takes effect after the next instruction */
101 /* sysexit */ 121 /* sysexit */
102 .byte 0xf, 0x35 122 .byte 0xf, 0x35
103 123
104sysenter_tracesys: 124sysenter_tracesys:
125 CFI_RESTORE_STATE
105 SAVE_REST 126 SAVE_REST
106 CLEAR_RREGS 127 CLEAR_RREGS
107 movq $-ENOSYS,RAX(%rsp) /* really needed? */ 128 movq $-ENOSYS,RAX(%rsp) /* really needed? */
@@ -140,21 +161,28 @@ sysenter_tracesys:
140 * with the int 0x80 path. 161 * with the int 0x80 path.
141 */ 162 */
142ENTRY(ia32_cstar_target) 163ENTRY(ia32_cstar_target)
143 CFI_STARTPROC 164 CFI_STARTPROC simple
165 CFI_DEF_CFA rsp,0
166 CFI_REGISTER rip,rcx
167 /*CFI_REGISTER rflags,r11*/
144 swapgs 168 swapgs
145 movl %esp,%r8d 169 movl %esp,%r8d
170 CFI_REGISTER rsp,r8
146 movq %gs:pda_kernelstack,%rsp 171 movq %gs:pda_kernelstack,%rsp
147 sti 172 sti
148 SAVE_ARGS 8,1,1 173 SAVE_ARGS 8,1,1
149 movl %eax,%eax /* zero extension */ 174 movl %eax,%eax /* zero extension */
150 movq %rax,ORIG_RAX-ARGOFFSET(%rsp) 175 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
151 movq %rcx,RIP-ARGOFFSET(%rsp) 176 movq %rcx,RIP-ARGOFFSET(%rsp)
177 CFI_REL_OFFSET rip,RIP-ARGOFFSET
152 movq %rbp,RCX-ARGOFFSET(%rsp) /* this lies slightly to ptrace */ 178 movq %rbp,RCX-ARGOFFSET(%rsp) /* this lies slightly to ptrace */
153 movl %ebp,%ecx 179 movl %ebp,%ecx
154 movq $__USER32_CS,CS-ARGOFFSET(%rsp) 180 movq $__USER32_CS,CS-ARGOFFSET(%rsp)
155 movq $__USER32_DS,SS-ARGOFFSET(%rsp) 181 movq $__USER32_DS,SS-ARGOFFSET(%rsp)
156 movq %r11,EFLAGS-ARGOFFSET(%rsp) 182 movq %r11,EFLAGS-ARGOFFSET(%rsp)
183 /*CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
157 movq %r8,RSP-ARGOFFSET(%rsp) 184 movq %r8,RSP-ARGOFFSET(%rsp)
185 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
158 /* no need to do an access_ok check here because r8 has been 186 /* no need to do an access_ok check here because r8 has been
159 32bit zero extended */ 187 32bit zero extended */
160 /* hardware stack frame is complete now */ 188 /* hardware stack frame is complete now */
@@ -164,6 +192,7 @@ ENTRY(ia32_cstar_target)
164 .previous 192 .previous
165 GET_THREAD_INFO(%r10) 193 GET_THREAD_INFO(%r10)
166 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10) 194 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
195 CFI_REMEMBER_STATE
167 jnz cstar_tracesys 196 jnz cstar_tracesys
168cstar_do_call: 197cstar_do_call:
169 cmpl $IA32_NR_syscalls,%eax 198 cmpl $IA32_NR_syscalls,%eax
@@ -177,12 +206,16 @@ cstar_do_call:
177 jnz int_ret_from_sys_call 206 jnz int_ret_from_sys_call
178 RESTORE_ARGS 1,-ARG_SKIP,1,1,1 207 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
179 movl RIP-ARGOFFSET(%rsp),%ecx 208 movl RIP-ARGOFFSET(%rsp),%ecx
209 CFI_REGISTER rip,rcx
180 movl EFLAGS-ARGOFFSET(%rsp),%r11d 210 movl EFLAGS-ARGOFFSET(%rsp),%r11d
211 /*CFI_REGISTER rflags,r11*/
181 movl RSP-ARGOFFSET(%rsp),%esp 212 movl RSP-ARGOFFSET(%rsp),%esp
213 CFI_RESTORE rsp
182 swapgs 214 swapgs
183 sysretl 215 sysretl
184 216
185cstar_tracesys: 217cstar_tracesys:
218 CFI_RESTORE_STATE
186 SAVE_REST 219 SAVE_REST
187 CLEAR_RREGS 220 CLEAR_RREGS
188 movq $-ENOSYS,RAX(%rsp) /* really needed? */ 221 movq $-ENOSYS,RAX(%rsp) /* really needed? */
@@ -226,11 +259,18 @@ ia32_badarg:
226 */ 259 */
227 260
228ENTRY(ia32_syscall) 261ENTRY(ia32_syscall)
229 CFI_STARTPROC 262 CFI_STARTPROC simple
263 CFI_DEF_CFA rsp,SS+8-RIP
264 /*CFI_REL_OFFSET ss,SS-RIP*/
265 CFI_REL_OFFSET rsp,RSP-RIP
266 /*CFI_REL_OFFSET rflags,EFLAGS-RIP*/
267 /*CFI_REL_OFFSET cs,CS-RIP*/
268 CFI_REL_OFFSET rip,RIP-RIP
230 swapgs 269 swapgs
231 sti 270 sti
232 movl %eax,%eax 271 movl %eax,%eax
233 pushq %rax 272 pushq %rax
273 CFI_ADJUST_CFA_OFFSET 8
234 cld 274 cld
235 /* note the registers are not zero extended to the sf. 275 /* note the registers are not zero extended to the sf.
236 this could be a problem. */ 276 this could be a problem. */
@@ -278,6 +318,8 @@ quiet_ni_syscall:
278 jmp ia32_ptregs_common 318 jmp ia32_ptregs_common
279 .endm 319 .endm
280 320
321 CFI_STARTPROC
322
281 PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn, %rdi 323 PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn, %rdi
282 PTREGSCALL stub32_sigreturn, sys32_sigreturn, %rdi 324 PTREGSCALL stub32_sigreturn, sys32_sigreturn, %rdi
283 PTREGSCALL stub32_sigaltstack, sys32_sigaltstack, %rdx 325 PTREGSCALL stub32_sigaltstack, sys32_sigaltstack, %rdx
@@ -290,8 +332,9 @@ quiet_ni_syscall:
290 PTREGSCALL stub32_rt_sigsuspend, sys_rt_sigsuspend, %rdx 332 PTREGSCALL stub32_rt_sigsuspend, sys_rt_sigsuspend, %rdx
291 333
292ENTRY(ia32_ptregs_common) 334ENTRY(ia32_ptregs_common)
293 CFI_STARTPROC
294 popq %r11 335 popq %r11
336 CFI_ADJUST_CFA_OFFSET -8
337 CFI_REGISTER rip, r11
295 SAVE_REST 338 SAVE_REST
296 call *%rax 339 call *%rax
297 RESTORE_REST 340 RESTORE_REST
diff --git a/arch/x86_64/ia32/sys_ia32.c b/arch/x86_64/ia32/sys_ia32.c
index 04d80406ce..5389df610e 100644
--- a/arch/x86_64/ia32/sys_ia32.c
+++ b/arch/x86_64/ia32/sys_ia32.c
@@ -751,7 +751,7 @@ sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count)
751 ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count); 751 ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
752 set_fs(old_fs); 752 set_fs(old_fs);
753 753
754 if (!ret && offset && put_user(of, offset)) 754 if (offset && put_user(of, offset))
755 return -EFAULT; 755 return -EFAULT;
756 756
757 return ret; 757 return ret;
diff --git a/arch/x86_64/ia32/vsyscall-syscall.S b/arch/x86_64/ia32/vsyscall-syscall.S
index e2aaf3de8a..b024965bb6 100644
--- a/arch/x86_64/ia32/vsyscall-syscall.S
+++ b/arch/x86_64/ia32/vsyscall-syscall.S
@@ -3,7 +3,7 @@
3 */ 3 */
4 4
5#include <asm/ia32_unistd.h> 5#include <asm/ia32_unistd.h>
6#include <asm/offset.h> 6#include <asm/asm-offsets.h>
7#include <asm/segment.h> 7#include <asm/segment.h>
8 8
9 .text 9 .text
diff --git a/arch/x86_64/ia32/vsyscall-sysenter.S b/arch/x86_64/ia32/vsyscall-sysenter.S
index 8fb8e0ff3a..71f3de586b 100644
--- a/arch/x86_64/ia32/vsyscall-sysenter.S
+++ b/arch/x86_64/ia32/vsyscall-sysenter.S
@@ -3,7 +3,7 @@
3 */ 3 */
4 4
5#include <asm/ia32_unistd.h> 5#include <asm/ia32_unistd.h>
6#include <asm/offset.h> 6#include <asm/asm-offsets.h>
7 7
8 .text 8 .text
9 .section .text.vsyscall,"ax" 9 .section .text.vsyscall,"ax"
diff --git a/arch/x86_64/kernel/Makefile b/arch/x86_64/kernel/Makefile
index 1579bdd0ad..bcdd0a805f 100644
--- a/arch/x86_64/kernel/Makefile
+++ b/arch/x86_64/kernel/Makefile
@@ -46,3 +46,4 @@ microcode-$(subst m,y,$(CONFIG_MICROCODE)) += ../../i386/kernel/microcode.o
46intel_cacheinfo-y += ../../i386/kernel/cpu/intel_cacheinfo.o 46intel_cacheinfo-y += ../../i386/kernel/cpu/intel_cacheinfo.o
47quirks-y += ../../i386/kernel/quirks.o 47quirks-y += ../../i386/kernel/quirks.o
48i8237-y += ../../i386/kernel/i8237.o 48i8237-y += ../../i386/kernel/i8237.o
49msr-$(subst m,y,$(CONFIG_X86_MSR)) += ../../i386/kernel/msr.o
diff --git a/arch/x86_64/kernel/acpi/sleep.c b/arch/x86_64/kernel/acpi/sleep.c
index 148f6f7ea3..867a0ebee1 100644
--- a/arch/x86_64/kernel/acpi/sleep.c
+++ b/arch/x86_64/kernel/acpi/sleep.c
@@ -34,7 +34,6 @@
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/pci.h> 35#include <linux/pci.h>
36#include <linux/bootmem.h> 36#include <linux/bootmem.h>
37#include <linux/irq.h>
38#include <linux/acpi.h> 37#include <linux/acpi.h>
39#include <asm/mpspec.h> 38#include <asm/mpspec.h>
40#include <asm/io.h> 39#include <asm/io.h>
diff --git a/arch/x86_64/kernel/aperture.c b/arch/x86_64/kernel/aperture.c
index c9a6b812e9..962ad4823b 100644
--- a/arch/x86_64/kernel/aperture.c
+++ b/arch/x86_64/kernel/aperture.c
@@ -245,6 +245,8 @@ void __init iommu_hole_init(void)
245 245
246 if (aper_alloc) { 246 if (aper_alloc) {
247 /* Got the aperture from the AGP bridge */ 247 /* Got the aperture from the AGP bridge */
248 } else if (swiotlb && !valid_agp) {
249 /* Do nothing */
248 } else if ((!no_iommu && end_pfn >= 0xffffffff>>PAGE_SHIFT) || 250 } else if ((!no_iommu && end_pfn >= 0xffffffff>>PAGE_SHIFT) ||
249 force_iommu || 251 force_iommu ||
250 valid_agp || 252 valid_agp ||
diff --git a/arch/x86_64/kernel/apic.c b/arch/x86_64/kernel/apic.c
index 375d369570..b6e7715d87 100644
--- a/arch/x86_64/kernel/apic.c
+++ b/arch/x86_64/kernel/apic.c
@@ -18,7 +18,6 @@
18#include <linux/init.h> 18#include <linux/init.h>
19 19
20#include <linux/mm.h> 20#include <linux/mm.h>
21#include <linux/irq.h>
22#include <linux/delay.h> 21#include <linux/delay.h>
23#include <linux/bootmem.h> 22#include <linux/bootmem.h>
24#include <linux/smp_lock.h> 23#include <linux/smp_lock.h>
@@ -109,11 +108,8 @@ void clear_local_APIC(void)
109 if (maxlvt >= 4) 108 if (maxlvt >= 4)
110 apic_write_around(APIC_LVTPC, APIC_LVT_MASKED); 109 apic_write_around(APIC_LVTPC, APIC_LVT_MASKED);
111 v = GET_APIC_VERSION(apic_read(APIC_LVR)); 110 v = GET_APIC_VERSION(apic_read(APIC_LVR));
112 if (APIC_INTEGRATED(v)) { /* !82489DX */ 111 apic_write(APIC_ESR, 0);
113 if (maxlvt > 3) /* Due to Pentium errata 3AP and 11AP. */ 112 apic_read(APIC_ESR);
114 apic_write(APIC_ESR, 0);
115 apic_read(APIC_ESR);
116 }
117} 113}
118 114
119void __init connect_bsp_APIC(void) 115void __init connect_bsp_APIC(void)
@@ -316,8 +312,6 @@ void __init init_bsp_APIC(void)
316 */ 312 */
317 apic_write_around(APIC_LVT0, APIC_DM_EXTINT); 313 apic_write_around(APIC_LVT0, APIC_DM_EXTINT);
318 value = APIC_DM_NMI; 314 value = APIC_DM_NMI;
319 if (!APIC_INTEGRATED(ver)) /* 82489DX */
320 value |= APIC_LVT_LEVEL_TRIGGER;
321 apic_write_around(APIC_LVT1, value); 315 apic_write_around(APIC_LVT1, value);
322} 316}
323 317
@@ -325,14 +319,6 @@ void __cpuinit setup_local_APIC (void)
325{ 319{
326 unsigned int value, ver, maxlvt; 320 unsigned int value, ver, maxlvt;
327 321
328 /* Pound the ESR really hard over the head with a big hammer - mbligh */
329 if (esr_disable) {
330 apic_write(APIC_ESR, 0);
331 apic_write(APIC_ESR, 0);
332 apic_write(APIC_ESR, 0);
333 apic_write(APIC_ESR, 0);
334 }
335
336 value = apic_read(APIC_LVR); 322 value = apic_read(APIC_LVR);
337 ver = GET_APIC_VERSION(value); 323 ver = GET_APIC_VERSION(value);
338 324
@@ -430,15 +416,11 @@ void __cpuinit setup_local_APIC (void)
430 value = APIC_DM_NMI; 416 value = APIC_DM_NMI;
431 else 417 else
432 value = APIC_DM_NMI | APIC_LVT_MASKED; 418 value = APIC_DM_NMI | APIC_LVT_MASKED;
433 if (!APIC_INTEGRATED(ver)) /* 82489DX */
434 value |= APIC_LVT_LEVEL_TRIGGER;
435 apic_write_around(APIC_LVT1, value); 419 apic_write_around(APIC_LVT1, value);
436 420
437 if (APIC_INTEGRATED(ver) && !esr_disable) { /* !82489DX */ 421 {
438 unsigned oldvalue; 422 unsigned oldvalue;
439 maxlvt = get_maxlvt(); 423 maxlvt = get_maxlvt();
440 if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */
441 apic_write(APIC_ESR, 0);
442 oldvalue = apic_read(APIC_ESR); 424 oldvalue = apic_read(APIC_ESR);
443 value = ERROR_APIC_VECTOR; // enables sending errors 425 value = ERROR_APIC_VECTOR; // enables sending errors
444 apic_write_around(APIC_LVTERR, value); 426 apic_write_around(APIC_LVTERR, value);
@@ -452,17 +434,6 @@ void __cpuinit setup_local_APIC (void)
452 apic_printk(APIC_VERBOSE, 434 apic_printk(APIC_VERBOSE,
453 "ESR value after enabling vector: %08x, after %08x\n", 435 "ESR value after enabling vector: %08x, after %08x\n",
454 oldvalue, value); 436 oldvalue, value);
455 } else {
456 if (esr_disable)
457 /*
458 * Something untraceble is creating bad interrupts on
459 * secondary quads ... for the moment, just leave the
460 * ESR disabled - we can't do anything useful with the
461 * errors anyway - mbligh
462 */
463 apic_printk(APIC_DEBUG, "Leaving ESR disabled.\n");
464 else
465 apic_printk(APIC_DEBUG, "No ESR for 82489DX.\n");
466 } 437 }
467 438
468 nmi_watchdog_default(); 439 nmi_watchdog_default();
@@ -650,8 +621,7 @@ void __init init_apic_mappings(void)
650 * Fetch the APIC ID of the BSP in case we have a 621 * Fetch the APIC ID of the BSP in case we have a
651 * default configuration (or the MP table is broken). 622 * default configuration (or the MP table is broken).
652 */ 623 */
653 if (boot_cpu_id == -1U) 624 boot_cpu_id = GET_APIC_ID(apic_read(APIC_ID));
654 boot_cpu_id = GET_APIC_ID(apic_read(APIC_ID));
655 625
656#ifdef CONFIG_X86_IO_APIC 626#ifdef CONFIG_X86_IO_APIC
657 { 627 {
@@ -693,8 +663,6 @@ static void __setup_APIC_LVTT(unsigned int clocks)
693 663
694 ver = GET_APIC_VERSION(apic_read(APIC_LVR)); 664 ver = GET_APIC_VERSION(apic_read(APIC_LVR));
695 lvtt_value = APIC_LVT_TIMER_PERIODIC | LOCAL_TIMER_VECTOR; 665 lvtt_value = APIC_LVT_TIMER_PERIODIC | LOCAL_TIMER_VECTOR;
696 if (!APIC_INTEGRATED(ver))
697 lvtt_value |= SET_APIC_TIMER_BASE(APIC_TIMER_BASE_DIV);
698 apic_write_around(APIC_LVTT, lvtt_value); 666 apic_write_around(APIC_LVTT, lvtt_value);
699 667
700 /* 668 /*
@@ -1081,7 +1049,7 @@ int __init APIC_init_uniprocessor (void)
1081 1049
1082 connect_bsp_APIC(); 1050 connect_bsp_APIC();
1083 1051
1084 phys_cpu_present_map = physid_mask_of_physid(0); 1052 phys_cpu_present_map = physid_mask_of_physid(boot_cpu_id);
1085 apic_write_around(APIC_ID, boot_cpu_id); 1053 apic_write_around(APIC_ID, boot_cpu_id);
1086 1054
1087 setup_local_APIC(); 1055 setup_local_APIC();
diff --git a/arch/x86_64/kernel/asm-offsets.c b/arch/x86_64/kernel/asm-offsets.c
index 35b4c3fcbb..aaa6d38335 100644
--- a/arch/x86_64/kernel/asm-offsets.c
+++ b/arch/x86_64/kernel/asm-offsets.c
@@ -39,7 +39,6 @@ int main(void)
39 ENTRY(kernelstack); 39 ENTRY(kernelstack);
40 ENTRY(oldrsp); 40 ENTRY(oldrsp);
41 ENTRY(pcurrent); 41 ENTRY(pcurrent);
42 ENTRY(irqrsp);
43 ENTRY(irqcount); 42 ENTRY(irqcount);
44 ENTRY(cpunumber); 43 ENTRY(cpunumber);
45 ENTRY(irqstackptr); 44 ENTRY(irqstackptr);
diff --git a/arch/x86_64/kernel/crash.c b/arch/x86_64/kernel/crash.c
index d7fa424850..535e044660 100644
--- a/arch/x86_64/kernel/crash.c
+++ b/arch/x86_64/kernel/crash.c
@@ -11,7 +11,6 @@
11#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/smp.h> 13#include <linux/smp.h>
14#include <linux/irq.h>
15#include <linux/reboot.h> 14#include <linux/reboot.h>
16#include <linux/kexec.h> 15#include <linux/kexec.h>
17 16
diff --git a/arch/x86_64/kernel/e820.c b/arch/x86_64/kernel/e820.c
index 116ac5f53d..eb7929eea7 100644
--- a/arch/x86_64/kernel/e820.c
+++ b/arch/x86_64/kernel/e820.c
@@ -131,7 +131,7 @@ void __init e820_bootmem_free(pg_data_t *pgdat, unsigned long start,unsigned lon
131 131
132 if (ei->type != E820_RAM || 132 if (ei->type != E820_RAM ||
133 ei->addr+ei->size <= start || 133 ei->addr+ei->size <= start ||
134 ei->addr > end) 134 ei->addr >= end)
135 continue; 135 continue;
136 136
137 addr = round_up(ei->addr, PAGE_SIZE); 137 addr = round_up(ei->addr, PAGE_SIZE);
@@ -567,7 +567,7 @@ unsigned long pci_mem_start = 0xaeedbabe;
567 */ 567 */
568__init void e820_setup_gap(void) 568__init void e820_setup_gap(void)
569{ 569{
570 unsigned long gapstart, gapsize; 570 unsigned long gapstart, gapsize, round;
571 unsigned long last; 571 unsigned long last;
572 int i; 572 int i;
573 int found = 0; 573 int found = 0;
@@ -604,14 +604,14 @@ __init void e820_setup_gap(void)
604 } 604 }
605 605
606 /* 606 /*
607 * Start allocating dynamic PCI memory a bit into the gap, 607 * See how much we want to round up: start off with
608 * aligned up to the nearest megabyte. 608 * rounding to the next 1MB area.
609 *
610 * Question: should we try to pad it up a bit (do something
611 * like " + (gapsize >> 3)" in there too?). We now have the
612 * technology.
613 */ 609 */
614 pci_mem_start = (gapstart + 0xfffff) & ~0xfffff; 610 round = 0x100000;
611 while ((gapsize >> 4) > round)
612 round += round;
613 /* Fun with two's complement */
614 pci_mem_start = (gapstart + round) & -round;
615 615
616 printk(KERN_INFO "Allocating PCI resources starting at %lx (gap: %lx:%lx)\n", 616 printk(KERN_INFO "Allocating PCI resources starting at %lx (gap: %lx:%lx)\n",
617 pci_mem_start, gapstart, gapsize); 617 pci_mem_start, gapstart, gapsize);
diff --git a/arch/x86_64/kernel/early_printk.c b/arch/x86_64/kernel/early_printk.c
index 9631c747c5..9cd968dd0f 100644
--- a/arch/x86_64/kernel/early_printk.c
+++ b/arch/x86_64/kernel/early_printk.c
@@ -5,6 +5,7 @@
5#include <linux/tty.h> 5#include <linux/tty.h>
6#include <asm/io.h> 6#include <asm/io.h>
7#include <asm/processor.h> 7#include <asm/processor.h>
8#include <asm/fcntl.h>
8 9
9/* Simple VGA output */ 10/* Simple VGA output */
10 11
@@ -158,6 +159,47 @@ static struct console early_serial_console = {
158 .index = -1, 159 .index = -1,
159}; 160};
160 161
162/* Console interface to a host file on AMD's SimNow! */
163
164static int simnow_fd;
165
166enum {
167 MAGIC1 = 0xBACCD00A,
168 MAGIC2 = 0xCA110000,
169 XOPEN = 5,
170 XWRITE = 4,
171};
172
173static noinline long simnow(long cmd, long a, long b, long c)
174{
175 long ret;
176 asm volatile("cpuid" :
177 "=a" (ret) :
178 "b" (a), "c" (b), "d" (c), "0" (MAGIC1), "D" (cmd + MAGIC2));
179 return ret;
180}
181
182void __init simnow_init(char *str)
183{
184 char *fn = "klog";
185 if (*str == '=')
186 fn = ++str;
187 /* error ignored */
188 simnow_fd = simnow(XOPEN, (unsigned long)fn, O_WRONLY|O_APPEND|O_CREAT, 0644);
189}
190
191static void simnow_write(struct console *con, const char *s, unsigned n)
192{
193 simnow(XWRITE, simnow_fd, (unsigned long)s, n);
194}
195
196static struct console simnow_console = {
197 .name = "simnow",
198 .write = simnow_write,
199 .flags = CON_PRINTBUFFER,
200 .index = -1,
201};
202
161/* Direct interface for emergencies */ 203/* Direct interface for emergencies */
162struct console *early_console = &early_vga_console; 204struct console *early_console = &early_vga_console;
163static int early_console_initialized = 0; 205static int early_console_initialized = 0;
@@ -205,6 +247,10 @@ int __init setup_early_printk(char *opt)
205 max_xpos = SCREEN_INFO.orig_video_cols; 247 max_xpos = SCREEN_INFO.orig_video_cols;
206 max_ypos = SCREEN_INFO.orig_video_lines; 248 max_ypos = SCREEN_INFO.orig_video_lines;
207 early_console = &early_vga_console; 249 early_console = &early_vga_console;
250 } else if (!strncmp(buf, "simnow", 6)) {
251 simnow_init(buf + 6);
252 early_console = &simnow_console;
253 keep_early = 1;
208 } 254 }
209 early_console_initialized = 1; 255 early_console_initialized = 1;
210 register_console(early_console); 256 register_console(early_console);
diff --git a/arch/x86_64/kernel/entry.S b/arch/x86_64/kernel/entry.S
index be51dbe1f7..7937971d18 100644
--- a/arch/x86_64/kernel/entry.S
+++ b/arch/x86_64/kernel/entry.S
@@ -36,7 +36,7 @@
36#include <asm/errno.h> 36#include <asm/errno.h>
37#include <asm/dwarf2.h> 37#include <asm/dwarf2.h>
38#include <asm/calling.h> 38#include <asm/calling.h>
39#include <asm/offset.h> 39#include <asm/asm-offsets.h>
40#include <asm/msr.h> 40#include <asm/msr.h>
41#include <asm/unistd.h> 41#include <asm/unistd.h>
42#include <asm/thread_info.h> 42#include <asm/thread_info.h>
@@ -79,16 +79,19 @@
79 xorl %eax, %eax 79 xorl %eax, %eax
80 pushq %rax /* ss */ 80 pushq %rax /* ss */
81 CFI_ADJUST_CFA_OFFSET 8 81 CFI_ADJUST_CFA_OFFSET 8
82 /*CFI_REL_OFFSET ss,0*/
82 pushq %rax /* rsp */ 83 pushq %rax /* rsp */
83 CFI_ADJUST_CFA_OFFSET 8 84 CFI_ADJUST_CFA_OFFSET 8
84 CFI_OFFSET rip,0 85 CFI_REL_OFFSET rsp,0
85 pushq $(1<<9) /* eflags - interrupts on */ 86 pushq $(1<<9) /* eflags - interrupts on */
86 CFI_ADJUST_CFA_OFFSET 8 87 CFI_ADJUST_CFA_OFFSET 8
88 /*CFI_REL_OFFSET rflags,0*/
87 pushq $__KERNEL_CS /* cs */ 89 pushq $__KERNEL_CS /* cs */
88 CFI_ADJUST_CFA_OFFSET 8 90 CFI_ADJUST_CFA_OFFSET 8
91 /*CFI_REL_OFFSET cs,0*/
89 pushq \child_rip /* rip */ 92 pushq \child_rip /* rip */
90 CFI_ADJUST_CFA_OFFSET 8 93 CFI_ADJUST_CFA_OFFSET 8
91 CFI_OFFSET rip,0 94 CFI_REL_OFFSET rip,0
92 pushq %rax /* orig rax */ 95 pushq %rax /* orig rax */
93 CFI_ADJUST_CFA_OFFSET 8 96 CFI_ADJUST_CFA_OFFSET 8
94 .endm 97 .endm
@@ -98,32 +101,39 @@
98 CFI_ADJUST_CFA_OFFSET -(6*8) 101 CFI_ADJUST_CFA_OFFSET -(6*8)
99 .endm 102 .endm
100 103
101 .macro CFI_DEFAULT_STACK 104 .macro CFI_DEFAULT_STACK start=1
102 CFI_ADJUST_CFA_OFFSET (SS) 105 .if \start
103 CFI_OFFSET r15,R15-SS 106 CFI_STARTPROC simple
104 CFI_OFFSET r14,R14-SS 107 CFI_DEF_CFA rsp,SS+8
105 CFI_OFFSET r13,R13-SS 108 .else
106 CFI_OFFSET r12,R12-SS 109 CFI_DEF_CFA_OFFSET SS+8
107 CFI_OFFSET rbp,RBP-SS 110 .endif
108 CFI_OFFSET rbx,RBX-SS 111 CFI_REL_OFFSET r15,R15
109 CFI_OFFSET r11,R11-SS 112 CFI_REL_OFFSET r14,R14
110 CFI_OFFSET r10,R10-SS 113 CFI_REL_OFFSET r13,R13
111 CFI_OFFSET r9,R9-SS 114 CFI_REL_OFFSET r12,R12
112 CFI_OFFSET r8,R8-SS 115 CFI_REL_OFFSET rbp,RBP
113 CFI_OFFSET rax,RAX-SS 116 CFI_REL_OFFSET rbx,RBX
114 CFI_OFFSET rcx,RCX-SS 117 CFI_REL_OFFSET r11,R11
115 CFI_OFFSET rdx,RDX-SS 118 CFI_REL_OFFSET r10,R10
116 CFI_OFFSET rsi,RSI-SS 119 CFI_REL_OFFSET r9,R9
117 CFI_OFFSET rdi,RDI-SS 120 CFI_REL_OFFSET r8,R8
118 CFI_OFFSET rsp,RSP-SS 121 CFI_REL_OFFSET rax,RAX
119 CFI_OFFSET rip,RIP-SS 122 CFI_REL_OFFSET rcx,RCX
123 CFI_REL_OFFSET rdx,RDX
124 CFI_REL_OFFSET rsi,RSI
125 CFI_REL_OFFSET rdi,RDI
126 CFI_REL_OFFSET rip,RIP
127 /*CFI_REL_OFFSET cs,CS*/
128 /*CFI_REL_OFFSET rflags,EFLAGS*/
129 CFI_REL_OFFSET rsp,RSP
130 /*CFI_REL_OFFSET ss,SS*/
120 .endm 131 .endm
121/* 132/*
122 * A newly forked process directly context switches into this. 133 * A newly forked process directly context switches into this.
123 */ 134 */
124/* rdi: prev */ 135/* rdi: prev */
125ENTRY(ret_from_fork) 136ENTRY(ret_from_fork)
126 CFI_STARTPROC
127 CFI_DEFAULT_STACK 137 CFI_DEFAULT_STACK
128 call schedule_tail 138 call schedule_tail
129 GET_THREAD_INFO(%rcx) 139 GET_THREAD_INFO(%rcx)
@@ -172,16 +182,21 @@ rff_trace:
172 */ 182 */
173 183
174ENTRY(system_call) 184ENTRY(system_call)
175 CFI_STARTPROC 185 CFI_STARTPROC simple
186 CFI_DEF_CFA rsp,0
187 CFI_REGISTER rip,rcx
188 /*CFI_REGISTER rflags,r11*/
176 swapgs 189 swapgs
177 movq %rsp,%gs:pda_oldrsp 190 movq %rsp,%gs:pda_oldrsp
178 movq %gs:pda_kernelstack,%rsp 191 movq %gs:pda_kernelstack,%rsp
179 sti 192 sti
180 SAVE_ARGS 8,1 193 SAVE_ARGS 8,1
181 movq %rax,ORIG_RAX-ARGOFFSET(%rsp) 194 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
182 movq %rcx,RIP-ARGOFFSET(%rsp) 195 movq %rcx,RIP-ARGOFFSET(%rsp)
196 CFI_REL_OFFSET rip,RIP-ARGOFFSET
183 GET_THREAD_INFO(%rcx) 197 GET_THREAD_INFO(%rcx)
184 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%rcx) 198 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%rcx)
199 CFI_REMEMBER_STATE
185 jnz tracesys 200 jnz tracesys
186 cmpq $__NR_syscall_max,%rax 201 cmpq $__NR_syscall_max,%rax
187 ja badsys 202 ja badsys
@@ -201,9 +216,12 @@ sysret_check:
201 cli 216 cli
202 movl threadinfo_flags(%rcx),%edx 217 movl threadinfo_flags(%rcx),%edx
203 andl %edi,%edx 218 andl %edi,%edx
219 CFI_REMEMBER_STATE
204 jnz sysret_careful 220 jnz sysret_careful
205 movq RIP-ARGOFFSET(%rsp),%rcx 221 movq RIP-ARGOFFSET(%rsp),%rcx
222 CFI_REGISTER rip,rcx
206 RESTORE_ARGS 0,-ARG_SKIP,1 223 RESTORE_ARGS 0,-ARG_SKIP,1
224 /*CFI_REGISTER rflags,r11*/
207 movq %gs:pda_oldrsp,%rsp 225 movq %gs:pda_oldrsp,%rsp
208 swapgs 226 swapgs
209 sysretq 227 sysretq
@@ -211,12 +229,15 @@ sysret_check:
211 /* Handle reschedules */ 229 /* Handle reschedules */
212 /* edx: work, edi: workmask */ 230 /* edx: work, edi: workmask */
213sysret_careful: 231sysret_careful:
232 CFI_RESTORE_STATE
214 bt $TIF_NEED_RESCHED,%edx 233 bt $TIF_NEED_RESCHED,%edx
215 jnc sysret_signal 234 jnc sysret_signal
216 sti 235 sti
217 pushq %rdi 236 pushq %rdi
237 CFI_ADJUST_CFA_OFFSET 8
218 call schedule 238 call schedule
219 popq %rdi 239 popq %rdi
240 CFI_ADJUST_CFA_OFFSET -8
220 jmp sysret_check 241 jmp sysret_check
221 242
222 /* Handle a signal */ 243 /* Handle a signal */
@@ -234,8 +255,13 @@ sysret_signal:
2341: movl $_TIF_NEED_RESCHED,%edi 2551: movl $_TIF_NEED_RESCHED,%edi
235 jmp sysret_check 256 jmp sysret_check
236 257
258badsys:
259 movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
260 jmp ret_from_sys_call
261
237 /* Do syscall tracing */ 262 /* Do syscall tracing */
238tracesys: 263tracesys:
264 CFI_RESTORE_STATE
239 SAVE_REST 265 SAVE_REST
240 movq $-ENOSYS,RAX(%rsp) 266 movq $-ENOSYS,RAX(%rsp)
241 FIXUP_TOP_OF_STACK %rdi 267 FIXUP_TOP_OF_STACK %rdi
@@ -254,16 +280,29 @@ tracesys:
254 RESTORE_TOP_OF_STACK %rbx 280 RESTORE_TOP_OF_STACK %rbx
255 RESTORE_REST 281 RESTORE_REST
256 jmp ret_from_sys_call 282 jmp ret_from_sys_call
283 CFI_ENDPROC
257 284
258badsys:
259 movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
260 jmp ret_from_sys_call
261
262/* 285/*
263 * Syscall return path ending with IRET. 286 * Syscall return path ending with IRET.
264 * Has correct top of stack, but partial stack frame. 287 * Has correct top of stack, but partial stack frame.
265 */ 288 */
266ENTRY(int_ret_from_sys_call) 289ENTRY(int_ret_from_sys_call)
290 CFI_STARTPROC simple
291 CFI_DEF_CFA rsp,SS+8-ARGOFFSET
292 /*CFI_REL_OFFSET ss,SS-ARGOFFSET*/
293 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
294 /*CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
295 /*CFI_REL_OFFSET cs,CS-ARGOFFSET*/
296 CFI_REL_OFFSET rip,RIP-ARGOFFSET
297 CFI_REL_OFFSET rdx,RDX-ARGOFFSET
298 CFI_REL_OFFSET rcx,RCX-ARGOFFSET
299 CFI_REL_OFFSET rax,RAX-ARGOFFSET
300 CFI_REL_OFFSET rdi,RDI-ARGOFFSET
301 CFI_REL_OFFSET rsi,RSI-ARGOFFSET
302 CFI_REL_OFFSET r8,R8-ARGOFFSET
303 CFI_REL_OFFSET r9,R9-ARGOFFSET
304 CFI_REL_OFFSET r10,R10-ARGOFFSET
305 CFI_REL_OFFSET r11,R11-ARGOFFSET
267 cli 306 cli
268 testl $3,CS-ARGOFFSET(%rsp) 307 testl $3,CS-ARGOFFSET(%rsp)
269 je retint_restore_args 308 je retint_restore_args
@@ -284,8 +323,10 @@ int_careful:
284 jnc int_very_careful 323 jnc int_very_careful
285 sti 324 sti
286 pushq %rdi 325 pushq %rdi
326 CFI_ADJUST_CFA_OFFSET 8
287 call schedule 327 call schedule
288 popq %rdi 328 popq %rdi
329 CFI_ADJUST_CFA_OFFSET -8
289 cli 330 cli
290 jmp int_with_check 331 jmp int_with_check
291 332
@@ -297,9 +338,11 @@ int_very_careful:
297 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP),%edx 338 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP),%edx
298 jz int_signal 339 jz int_signal
299 pushq %rdi 340 pushq %rdi
341 CFI_ADJUST_CFA_OFFSET 8
300 leaq 8(%rsp),%rdi # &ptregs -> arg1 342 leaq 8(%rsp),%rdi # &ptregs -> arg1
301 call syscall_trace_leave 343 call syscall_trace_leave
302 popq %rdi 344 popq %rdi
345 CFI_ADJUST_CFA_OFFSET -8
303 andl $~(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP),%edi 346 andl $~(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP),%edi
304 cli 347 cli
305 jmp int_restore_rest 348 jmp int_restore_rest
@@ -329,6 +372,8 @@ int_restore_rest:
329 jmp ptregscall_common 372 jmp ptregscall_common
330 .endm 373 .endm
331 374
375 CFI_STARTPROC
376
332 PTREGSCALL stub_clone, sys_clone, %r8 377 PTREGSCALL stub_clone, sys_clone, %r8
333 PTREGSCALL stub_fork, sys_fork, %rdi 378 PTREGSCALL stub_fork, sys_fork, %rdi
334 PTREGSCALL stub_vfork, sys_vfork, %rdi 379 PTREGSCALL stub_vfork, sys_vfork, %rdi
@@ -337,40 +382,49 @@ int_restore_rest:
337 PTREGSCALL stub_iopl, sys_iopl, %rsi 382 PTREGSCALL stub_iopl, sys_iopl, %rsi
338 383
339ENTRY(ptregscall_common) 384ENTRY(ptregscall_common)
340 CFI_STARTPROC
341 popq %r11 385 popq %r11
342 CFI_ADJUST_CFA_OFFSET -8 386 CFI_ADJUST_CFA_OFFSET -8
387 CFI_REGISTER rip, r11
343 SAVE_REST 388 SAVE_REST
344 movq %r11, %r15 389 movq %r11, %r15
390 CFI_REGISTER rip, r15
345 FIXUP_TOP_OF_STACK %r11 391 FIXUP_TOP_OF_STACK %r11
346 call *%rax 392 call *%rax
347 RESTORE_TOP_OF_STACK %r11 393 RESTORE_TOP_OF_STACK %r11
348 movq %r15, %r11 394 movq %r15, %r11
395 CFI_REGISTER rip, r11
349 RESTORE_REST 396 RESTORE_REST
350 pushq %r11 397 pushq %r11
351 CFI_ADJUST_CFA_OFFSET 8 398 CFI_ADJUST_CFA_OFFSET 8
399 CFI_REL_OFFSET rip, 0
352 ret 400 ret
353 CFI_ENDPROC 401 CFI_ENDPROC
354 402
355ENTRY(stub_execve) 403ENTRY(stub_execve)
356 CFI_STARTPROC 404 CFI_STARTPROC
357 popq %r11 405 popq %r11
358 CFI_ADJUST_CFA_OFFSET -8 406 CFI_ADJUST_CFA_OFFSET -8
407 CFI_REGISTER rip, r11
359 SAVE_REST 408 SAVE_REST
360 movq %r11, %r15 409 movq %r11, %r15
410 CFI_REGISTER rip, r15
361 FIXUP_TOP_OF_STACK %r11 411 FIXUP_TOP_OF_STACK %r11
362 call sys_execve 412 call sys_execve
363 GET_THREAD_INFO(%rcx) 413 GET_THREAD_INFO(%rcx)
364 bt $TIF_IA32,threadinfo_flags(%rcx) 414 bt $TIF_IA32,threadinfo_flags(%rcx)
415 CFI_REMEMBER_STATE
365 jc exec_32bit 416 jc exec_32bit
366 RESTORE_TOP_OF_STACK %r11 417 RESTORE_TOP_OF_STACK %r11
367 movq %r15, %r11 418 movq %r15, %r11
419 CFI_REGISTER rip, r11
368 RESTORE_REST 420 RESTORE_REST
369 push %r11 421 pushq %r11
422 CFI_ADJUST_CFA_OFFSET 8
423 CFI_REL_OFFSET rip, 0
370 ret 424 ret
371 425
372exec_32bit: 426exec_32bit:
373 CFI_ADJUST_CFA_OFFSET REST_SKIP 427 CFI_RESTORE_STATE
374 movq %rax,RAX(%rsp) 428 movq %rax,RAX(%rsp)
375 RESTORE_REST 429 RESTORE_REST
376 jmp int_ret_from_sys_call 430 jmp int_ret_from_sys_call
@@ -382,7 +436,8 @@ exec_32bit:
382 */ 436 */
383ENTRY(stub_rt_sigreturn) 437ENTRY(stub_rt_sigreturn)
384 CFI_STARTPROC 438 CFI_STARTPROC
385 addq $8, %rsp 439 addq $8, %rsp
440 CFI_ADJUST_CFA_OFFSET -8
386 SAVE_REST 441 SAVE_REST
387 movq %rsp,%rdi 442 movq %rsp,%rdi
388 FIXUP_TOP_OF_STACK %r11 443 FIXUP_TOP_OF_STACK %r11
@@ -392,6 +447,25 @@ ENTRY(stub_rt_sigreturn)
392 jmp int_ret_from_sys_call 447 jmp int_ret_from_sys_call
393 CFI_ENDPROC 448 CFI_ENDPROC
394 449
450/*
451 * initial frame state for interrupts and exceptions
452 */
453 .macro _frame ref
454 CFI_STARTPROC simple
455 CFI_DEF_CFA rsp,SS+8-\ref
456 /*CFI_REL_OFFSET ss,SS-\ref*/
457 CFI_REL_OFFSET rsp,RSP-\ref
458 /*CFI_REL_OFFSET rflags,EFLAGS-\ref*/
459 /*CFI_REL_OFFSET cs,CS-\ref*/
460 CFI_REL_OFFSET rip,RIP-\ref
461 .endm
462
463/* initial frame state for interrupts (and exceptions without error code) */
464#define INTR_FRAME _frame RIP
465/* initial frame state for exceptions with error code (and interrupts with
466 vector already pushed) */
467#define XCPT_FRAME _frame ORIG_RAX
468
395/* 469/*
396 * Interrupt entry/exit. 470 * Interrupt entry/exit.
397 * 471 *
@@ -402,10 +476,6 @@ ENTRY(stub_rt_sigreturn)
402 476
403/* 0(%rsp): interrupt number */ 477/* 0(%rsp): interrupt number */
404 .macro interrupt func 478 .macro interrupt func
405 CFI_STARTPROC simple
406 CFI_DEF_CFA rsp,(SS-RDI)
407 CFI_REL_OFFSET rsp,(RSP-ORIG_RAX)
408 CFI_REL_OFFSET rip,(RIP-ORIG_RAX)
409 cld 479 cld
410#ifdef CONFIG_DEBUG_INFO 480#ifdef CONFIG_DEBUG_INFO
411 SAVE_ALL 481 SAVE_ALL
@@ -425,23 +495,27 @@ ENTRY(stub_rt_sigreturn)
425 swapgs 495 swapgs
4261: incl %gs:pda_irqcount # RED-PEN should check preempt count 4961: incl %gs:pda_irqcount # RED-PEN should check preempt count
427 movq %gs:pda_irqstackptr,%rax 497 movq %gs:pda_irqstackptr,%rax
428 cmoveq %rax,%rsp 498 cmoveq %rax,%rsp /*todo This needs CFI annotation! */
429 pushq %rdi # save old stack 499 pushq %rdi # save old stack
500 CFI_ADJUST_CFA_OFFSET 8
430 call \func 501 call \func
431 .endm 502 .endm
432 503
433ENTRY(common_interrupt) 504ENTRY(common_interrupt)
505 XCPT_FRAME
434 interrupt do_IRQ 506 interrupt do_IRQ
435 /* 0(%rsp): oldrsp-ARGOFFSET */ 507 /* 0(%rsp): oldrsp-ARGOFFSET */
436ret_from_intr: 508ret_from_intr:
437 popq %rdi 509 popq %rdi
510 CFI_ADJUST_CFA_OFFSET -8
438 cli 511 cli
439 decl %gs:pda_irqcount 512 decl %gs:pda_irqcount
440#ifdef CONFIG_DEBUG_INFO 513#ifdef CONFIG_DEBUG_INFO
441 movq RBP(%rdi),%rbp 514 movq RBP(%rdi),%rbp
515 CFI_DEF_CFA_REGISTER rsp
442#endif 516#endif
443 leaq ARGOFFSET(%rdi),%rsp 517 leaq ARGOFFSET(%rdi),%rsp /*todo This needs CFI annotation! */
444exit_intr: 518exit_intr:
445 GET_THREAD_INFO(%rcx) 519 GET_THREAD_INFO(%rcx)
446 testl $3,CS-ARGOFFSET(%rsp) 520 testl $3,CS-ARGOFFSET(%rsp)
447 je retint_kernel 521 je retint_kernel
@@ -453,9 +527,10 @@ exit_intr:
453 */ 527 */
454retint_with_reschedule: 528retint_with_reschedule:
455 movl $_TIF_WORK_MASK,%edi 529 movl $_TIF_WORK_MASK,%edi
456retint_check: 530retint_check:
457 movl threadinfo_flags(%rcx),%edx 531 movl threadinfo_flags(%rcx),%edx
458 andl %edi,%edx 532 andl %edi,%edx
533 CFI_REMEMBER_STATE
459 jnz retint_careful 534 jnz retint_careful
460retint_swapgs: 535retint_swapgs:
461 swapgs 536 swapgs
@@ -476,14 +551,17 @@ bad_iret:
476 jmp do_exit 551 jmp do_exit
477 .previous 552 .previous
478 553
479 /* edi: workmask, edx: work */ 554 /* edi: workmask, edx: work */
480retint_careful: 555retint_careful:
556 CFI_RESTORE_STATE
481 bt $TIF_NEED_RESCHED,%edx 557 bt $TIF_NEED_RESCHED,%edx
482 jnc retint_signal 558 jnc retint_signal
483 sti 559 sti
484 pushq %rdi 560 pushq %rdi
561 CFI_ADJUST_CFA_OFFSET 8
485 call schedule 562 call schedule
486 popq %rdi 563 popq %rdi
564 CFI_ADJUST_CFA_OFFSET -8
487 GET_THREAD_INFO(%rcx) 565 GET_THREAD_INFO(%rcx)
488 cli 566 cli
489 jmp retint_check 567 jmp retint_check
@@ -523,7 +601,9 @@ retint_kernel:
523 * APIC interrupts. 601 * APIC interrupts.
524 */ 602 */
525 .macro apicinterrupt num,func 603 .macro apicinterrupt num,func
604 INTR_FRAME
526 pushq $\num-256 605 pushq $\num-256
606 CFI_ADJUST_CFA_OFFSET 8
527 interrupt \func 607 interrupt \func
528 jmp ret_from_intr 608 jmp ret_from_intr
529 CFI_ENDPROC 609 CFI_ENDPROC
@@ -536,8 +616,19 @@ ENTRY(thermal_interrupt)
536ENTRY(reschedule_interrupt) 616ENTRY(reschedule_interrupt)
537 apicinterrupt RESCHEDULE_VECTOR,smp_reschedule_interrupt 617 apicinterrupt RESCHEDULE_VECTOR,smp_reschedule_interrupt
538 618
539ENTRY(invalidate_interrupt) 619 .macro INVALIDATE_ENTRY num
540 apicinterrupt INVALIDATE_TLB_VECTOR,smp_invalidate_interrupt 620ENTRY(invalidate_interrupt\num)
621 apicinterrupt INVALIDATE_TLB_VECTOR_START+\num,smp_invalidate_interrupt
622 .endm
623
624 INVALIDATE_ENTRY 0
625 INVALIDATE_ENTRY 1
626 INVALIDATE_ENTRY 2
627 INVALIDATE_ENTRY 3
628 INVALIDATE_ENTRY 4
629 INVALIDATE_ENTRY 5
630 INVALIDATE_ENTRY 6
631 INVALIDATE_ENTRY 7
541 632
542ENTRY(call_function_interrupt) 633ENTRY(call_function_interrupt)
543 apicinterrupt CALL_FUNCTION_VECTOR,smp_call_function_interrupt 634 apicinterrupt CALL_FUNCTION_VECTOR,smp_call_function_interrupt
@@ -558,16 +649,23 @@ ENTRY(spurious_interrupt)
558 * Exception entry points. 649 * Exception entry points.
559 */ 650 */
560 .macro zeroentry sym 651 .macro zeroentry sym
652 INTR_FRAME
561 pushq $0 /* push error code/oldrax */ 653 pushq $0 /* push error code/oldrax */
654 CFI_ADJUST_CFA_OFFSET 8
562 pushq %rax /* push real oldrax to the rdi slot */ 655 pushq %rax /* push real oldrax to the rdi slot */
656 CFI_ADJUST_CFA_OFFSET 8
563 leaq \sym(%rip),%rax 657 leaq \sym(%rip),%rax
564 jmp error_entry 658 jmp error_entry
659 CFI_ENDPROC
565 .endm 660 .endm
566 661
567 .macro errorentry sym 662 .macro errorentry sym
663 XCPT_FRAME
568 pushq %rax 664 pushq %rax
665 CFI_ADJUST_CFA_OFFSET 8
569 leaq \sym(%rip),%rax 666 leaq \sym(%rip),%rax
570 jmp error_entry 667 jmp error_entry
668 CFI_ENDPROC
571 .endm 669 .endm
572 670
573 /* error code is on the stack already */ 671 /* error code is on the stack already */
@@ -594,10 +692,7 @@ ENTRY(spurious_interrupt)
594 * and the exception handler in %rax. 692 * and the exception handler in %rax.
595 */ 693 */
596ENTRY(error_entry) 694ENTRY(error_entry)
597 CFI_STARTPROC simple 695 _frame RDI
598 CFI_DEF_CFA rsp,(SS-RDI)
599 CFI_REL_OFFSET rsp,(RSP-RDI)
600 CFI_REL_OFFSET rip,(RIP-RDI)
601 /* rdi slot contains rax, oldrax contains error code */ 696 /* rdi slot contains rax, oldrax contains error code */
602 cld 697 cld
603 subq $14*8,%rsp 698 subq $14*8,%rsp
@@ -679,7 +774,9 @@ error_kernelspace:
679 /* Reload gs selector with exception handling */ 774 /* Reload gs selector with exception handling */
680 /* edi: new selector */ 775 /* edi: new selector */
681ENTRY(load_gs_index) 776ENTRY(load_gs_index)
777 CFI_STARTPROC
682 pushf 778 pushf
779 CFI_ADJUST_CFA_OFFSET 8
683 cli 780 cli
684 swapgs 781 swapgs
685gs_change: 782gs_change:
@@ -687,7 +784,9 @@ gs_change:
6872: mfence /* workaround */ 7842: mfence /* workaround */
688 swapgs 785 swapgs
689 popf 786 popf
787 CFI_ADJUST_CFA_OFFSET -8
690 ret 788 ret
789 CFI_ENDPROC
691 790
692 .section __ex_table,"a" 791 .section __ex_table,"a"
693 .align 8 792 .align 8
@@ -799,7 +898,7 @@ ENTRY(device_not_available)
799 898
800 /* runs on exception stack */ 899 /* runs on exception stack */
801KPROBE_ENTRY(debug) 900KPROBE_ENTRY(debug)
802 CFI_STARTPROC 901 INTR_FRAME
803 pushq $0 902 pushq $0
804 CFI_ADJUST_CFA_OFFSET 8 903 CFI_ADJUST_CFA_OFFSET 8
805 paranoidentry do_debug 904 paranoidentry do_debug
@@ -809,9 +908,9 @@ KPROBE_ENTRY(debug)
809 908
810 /* runs on exception stack */ 909 /* runs on exception stack */
811ENTRY(nmi) 910ENTRY(nmi)
812 CFI_STARTPROC 911 INTR_FRAME
813 pushq $-1 912 pushq $-1
814 CFI_ADJUST_CFA_OFFSET 8 913 CFI_ADJUST_CFA_OFFSET 8
815 paranoidentry do_nmi 914 paranoidentry do_nmi
816 /* 915 /*
817 * "Paranoid" exit path from exception stack. 916 * "Paranoid" exit path from exception stack.
@@ -877,7 +976,7 @@ ENTRY(reserved)
877 976
878 /* runs on exception stack */ 977 /* runs on exception stack */
879ENTRY(double_fault) 978ENTRY(double_fault)
880 CFI_STARTPROC 979 XCPT_FRAME
881 paranoidentry do_double_fault 980 paranoidentry do_double_fault
882 jmp paranoid_exit 981 jmp paranoid_exit
883 CFI_ENDPROC 982 CFI_ENDPROC
@@ -890,7 +989,7 @@ ENTRY(segment_not_present)
890 989
891 /* runs on exception stack */ 990 /* runs on exception stack */
892ENTRY(stack_segment) 991ENTRY(stack_segment)
893 CFI_STARTPROC 992 XCPT_FRAME
894 paranoidentry do_stack_segment 993 paranoidentry do_stack_segment
895 jmp paranoid_exit 994 jmp paranoid_exit
896 CFI_ENDPROC 995 CFI_ENDPROC
@@ -911,7 +1010,7 @@ ENTRY(spurious_interrupt_bug)
911#ifdef CONFIG_X86_MCE 1010#ifdef CONFIG_X86_MCE
912 /* runs on exception stack */ 1011 /* runs on exception stack */
913ENTRY(machine_check) 1012ENTRY(machine_check)
914 CFI_STARTPROC 1013 INTR_FRAME
915 pushq $0 1014 pushq $0
916 CFI_ADJUST_CFA_OFFSET 8 1015 CFI_ADJUST_CFA_OFFSET 8
917 paranoidentry do_machine_check 1016 paranoidentry do_machine_check
@@ -923,14 +1022,19 @@ ENTRY(call_debug)
923 zeroentry do_call_debug 1022 zeroentry do_call_debug
924 1023
925ENTRY(call_softirq) 1024ENTRY(call_softirq)
1025 CFI_STARTPROC
926 movq %gs:pda_irqstackptr,%rax 1026 movq %gs:pda_irqstackptr,%rax
927 pushq %r15 1027 pushq %r15
1028 CFI_ADJUST_CFA_OFFSET 8
928 movq %rsp,%r15 1029 movq %rsp,%r15
1030 CFI_DEF_CFA_REGISTER r15
929 incl %gs:pda_irqcount 1031 incl %gs:pda_irqcount
930 cmove %rax,%rsp 1032 cmove %rax,%rsp
931 call __do_softirq 1033 call __do_softirq
932 movq %r15,%rsp 1034 movq %r15,%rsp
1035 CFI_DEF_CFA_REGISTER rsp
933 decl %gs:pda_irqcount 1036 decl %gs:pda_irqcount
934 popq %r15 1037 popq %r15
1038 CFI_ADJUST_CFA_OFFSET -8
935 ret 1039 ret
936 1040 CFI_ENDPROC
diff --git a/arch/x86_64/kernel/genapic.c b/arch/x86_64/kernel/genapic.c
index b1c144f731..7a64ea1817 100644
--- a/arch/x86_64/kernel/genapic.c
+++ b/arch/x86_64/kernel/genapic.c
@@ -45,7 +45,7 @@ void __init clustered_apic_check(void)
45 u8 clusters, max_cluster; 45 u8 clusters, max_cluster;
46 u8 id; 46 u8 id;
47 u8 cluster_cnt[NUM_APIC_CLUSTERS]; 47 u8 cluster_cnt[NUM_APIC_CLUSTERS];
48 int num_cpus = 0; 48 int max_apic = 0;
49 49
50#if defined(CONFIG_ACPI) 50#if defined(CONFIG_ACPI)
51 /* 51 /*
@@ -64,14 +64,15 @@ void __init clustered_apic_check(void)
64 id = bios_cpu_apicid[i]; 64 id = bios_cpu_apicid[i];
65 if (id == BAD_APICID) 65 if (id == BAD_APICID)
66 continue; 66 continue;
67 num_cpus++; 67 if (id > max_apic)
68 max_apic = id;
68 cluster_cnt[APIC_CLUSTERID(id)]++; 69 cluster_cnt[APIC_CLUSTERID(id)]++;
69 } 70 }
70 71
71 /* Don't use clustered mode on AMD platforms. */ 72 /* Don't use clustered mode on AMD platforms. */
72 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) { 73 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
73 genapic = &apic_physflat; 74 genapic = &apic_physflat;
74#ifndef CONFIG_CPU_HOTPLUG 75#ifndef CONFIG_HOTPLUG_CPU
75 /* In the CPU hotplug case we cannot use broadcast mode 76 /* In the CPU hotplug case we cannot use broadcast mode
76 because that opens a race when a CPU is removed. 77 because that opens a race when a CPU is removed.
77 Stay at physflat mode in this case. 78 Stay at physflat mode in this case.
@@ -79,7 +80,7 @@ void __init clustered_apic_check(void)
79 we have ACPI platform support for CPU hotplug 80 we have ACPI platform support for CPU hotplug
80 we should detect hotplug capablity from ACPI tables and 81 we should detect hotplug capablity from ACPI tables and
81 only do this when really needed. -AK */ 82 only do this when really needed. -AK */
82 if (num_cpus <= 8) 83 if (max_apic <= 8)
83 genapic = &apic_flat; 84 genapic = &apic_flat;
84#endif 85#endif
85 goto print; 86 goto print;
@@ -103,9 +104,14 @@ void __init clustered_apic_check(void)
103 * (We don't use lowest priority delivery + HW APIC IRQ steering, so 104 * (We don't use lowest priority delivery + HW APIC IRQ steering, so
104 * can ignore the clustered logical case and go straight to physical.) 105 * can ignore the clustered logical case and go straight to physical.)
105 */ 106 */
106 if (clusters <= 1 && max_cluster <= 8 && cluster_cnt[0] == max_cluster) 107 if (clusters <= 1 && max_cluster <= 8 && cluster_cnt[0] == max_cluster) {
108#ifdef CONFIG_HOTPLUG_CPU
109 /* Don't use APIC shortcuts in CPU hotplug to avoid races */
110 genapic = &apic_physflat;
111#else
107 genapic = &apic_flat; 112 genapic = &apic_flat;
108 else 113#endif
114 } else
109 genapic = &apic_cluster; 115 genapic = &apic_cluster;
110 116
111print: 117print:
diff --git a/arch/x86_64/kernel/genapic_cluster.c b/arch/x86_64/kernel/genapic_cluster.c
index f6523dd1bc..a472d62f89 100644
--- a/arch/x86_64/kernel/genapic_cluster.c
+++ b/arch/x86_64/kernel/genapic_cluster.c
@@ -51,10 +51,10 @@ static void cluster_init_apic_ldr(void)
51 count = 3; 51 count = 3;
52 id = my_cluster | (1UL << count); 52 id = my_cluster | (1UL << count);
53 x86_cpu_to_log_apicid[smp_processor_id()] = id; 53 x86_cpu_to_log_apicid[smp_processor_id()] = id;
54 apic_write_around(APIC_DFR, APIC_DFR_CLUSTER); 54 apic_write(APIC_DFR, APIC_DFR_CLUSTER);
55 val = apic_read(APIC_LDR) & ~APIC_LDR_MASK; 55 val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
56 val |= SET_APIC_LOGICAL_ID(id); 56 val |= SET_APIC_LOGICAL_ID(id);
57 apic_write_around(APIC_LDR, val); 57 apic_write(APIC_LDR, val);
58} 58}
59 59
60/* Start with all IRQs pointing to boot CPU. IRQ balancing will shift them. */ 60/* Start with all IRQs pointing to boot CPU. IRQ balancing will shift them. */
diff --git a/arch/x86_64/kernel/genapic_flat.c b/arch/x86_64/kernel/genapic_flat.c
index adc96282a9..9da3edb799 100644
--- a/arch/x86_64/kernel/genapic_flat.c
+++ b/arch/x86_64/kernel/genapic_flat.c
@@ -38,10 +38,10 @@ static void flat_init_apic_ldr(void)
38 num = smp_processor_id(); 38 num = smp_processor_id();
39 id = 1UL << num; 39 id = 1UL << num;
40 x86_cpu_to_log_apicid[num] = id; 40 x86_cpu_to_log_apicid[num] = id;
41 apic_write_around(APIC_DFR, APIC_DFR_FLAT); 41 apic_write(APIC_DFR, APIC_DFR_FLAT);
42 val = apic_read(APIC_LDR) & ~APIC_LDR_MASK; 42 val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
43 val |= SET_APIC_LOGICAL_ID(id); 43 val |= SET_APIC_LOGICAL_ID(id);
44 apic_write_around(APIC_LDR, val); 44 apic_write(APIC_LDR, val);
45} 45}
46 46
47static void flat_send_IPI_mask(cpumask_t cpumask, int vector) 47static void flat_send_IPI_mask(cpumask_t cpumask, int vector)
@@ -62,7 +62,7 @@ static void flat_send_IPI_mask(cpumask_t cpumask, int vector)
62 * prepare target chip field 62 * prepare target chip field
63 */ 63 */
64 cfg = __prepare_ICR2(mask); 64 cfg = __prepare_ICR2(mask);
65 apic_write_around(APIC_ICR2, cfg); 65 apic_write(APIC_ICR2, cfg);
66 66
67 /* 67 /*
68 * program the ICR 68 * program the ICR
@@ -72,14 +72,24 @@ static void flat_send_IPI_mask(cpumask_t cpumask, int vector)
72 /* 72 /*
73 * Send the IPI. The write to APIC_ICR fires this off. 73 * Send the IPI. The write to APIC_ICR fires this off.
74 */ 74 */
75 apic_write_around(APIC_ICR, cfg); 75 apic_write(APIC_ICR, cfg);
76 local_irq_restore(flags); 76 local_irq_restore(flags);
77} 77}
78 78
79static void flat_send_IPI_allbutself(int vector) 79static void flat_send_IPI_allbutself(int vector)
80{ 80{
81#ifndef CONFIG_HOTPLUG_CPU
81 if (((num_online_cpus()) - 1) >= 1) 82 if (((num_online_cpus()) - 1) >= 1)
82 __send_IPI_shortcut(APIC_DEST_ALLBUT, vector,APIC_DEST_LOGICAL); 83 __send_IPI_shortcut(APIC_DEST_ALLBUT, vector,APIC_DEST_LOGICAL);
84#else
85 cpumask_t allbutme = cpu_online_map;
86 int me = get_cpu(); /* Ensure we are not preempted when we clear */
87 cpu_clear(me, allbutme);
88
89 if (!cpus_empty(allbutme))
90 flat_send_IPI_mask(allbutme, vector);
91 put_cpu();
92#endif
83} 93}
84 94
85static void flat_send_IPI_all(int vector) 95static void flat_send_IPI_all(int vector)
@@ -167,9 +177,9 @@ static unsigned int physflat_cpu_mask_to_apicid(cpumask_t cpumask)
167 177
168struct genapic apic_physflat = { 178struct genapic apic_physflat = {
169 .name = "physical flat", 179 .name = "physical flat",
170 .int_delivery_mode = dest_LowestPrio, 180 .int_delivery_mode = dest_Fixed,
171 .int_dest_mode = (APIC_DEST_PHYSICAL != 0), 181 .int_dest_mode = (APIC_DEST_PHYSICAL != 0),
172 .int_delivery_dest = APIC_DEST_PHYSICAL | APIC_DM_LOWEST, 182 .int_delivery_dest = APIC_DEST_PHYSICAL | APIC_DM_FIXED,
173 .target_cpus = physflat_target_cpus, 183 .target_cpus = physflat_target_cpus,
174 .apic_id_registered = flat_apic_id_registered, 184 .apic_id_registered = flat_apic_id_registered,
175 .init_apic_ldr = flat_init_apic_ldr,/*not needed, but shouldn't hurt*/ 185 .init_apic_ldr = flat_init_apic_ldr,/*not needed, but shouldn't hurt*/
diff --git a/arch/x86_64/kernel/head.S b/arch/x86_64/kernel/head.S
index 98ff5eb32b..4592bf21fc 100644
--- a/arch/x86_64/kernel/head.S
+++ b/arch/x86_64/kernel/head.S
@@ -270,7 +270,7 @@ ENTRY(level3_kernel_pgt)
270.org 0x4000 270.org 0x4000
271ENTRY(level2_ident_pgt) 271ENTRY(level2_ident_pgt)
272 /* 40MB for bootup. */ 272 /* 40MB for bootup. */
273 .quad 0x0000000000000283 273 .quad 0x0000000000000183
274 .quad 0x0000000000200183 274 .quad 0x0000000000200183
275 .quad 0x0000000000400183 275 .quad 0x0000000000400183
276 .quad 0x0000000000600183 276 .quad 0x0000000000600183
diff --git a/arch/x86_64/kernel/i8259.c b/arch/x86_64/kernel/i8259.c
index a891690951..b2a238b5a1 100644
--- a/arch/x86_64/kernel/i8259.c
+++ b/arch/x86_64/kernel/i8259.c
@@ -18,15 +18,12 @@
18#include <asm/atomic.h> 18#include <asm/atomic.h>
19#include <asm/system.h> 19#include <asm/system.h>
20#include <asm/io.h> 20#include <asm/io.h>
21#include <asm/irq.h>
22#include <asm/hw_irq.h> 21#include <asm/hw_irq.h>
23#include <asm/pgtable.h> 22#include <asm/pgtable.h>
24#include <asm/delay.h> 23#include <asm/delay.h>
25#include <asm/desc.h> 24#include <asm/desc.h>
26#include <asm/apic.h> 25#include <asm/apic.h>
27 26
28#include <linux/irq.h>
29
30/* 27/*
31 * Common place to define all x86 IRQ vectors 28 * Common place to define all x86 IRQ vectors
32 * 29 *
@@ -486,7 +483,14 @@ void spurious_interrupt(void);
486void error_interrupt(void); 483void error_interrupt(void);
487void reschedule_interrupt(void); 484void reschedule_interrupt(void);
488void call_function_interrupt(void); 485void call_function_interrupt(void);
489void invalidate_interrupt(void); 486void invalidate_interrupt0(void);
487void invalidate_interrupt1(void);
488void invalidate_interrupt2(void);
489void invalidate_interrupt3(void);
490void invalidate_interrupt4(void);
491void invalidate_interrupt5(void);
492void invalidate_interrupt6(void);
493void invalidate_interrupt7(void);
490void thermal_interrupt(void); 494void thermal_interrupt(void);
491void i8254_timer_resume(void); 495void i8254_timer_resume(void);
492 496
@@ -562,8 +566,15 @@ void __init init_IRQ(void)
562 */ 566 */
563 set_intr_gate(RESCHEDULE_VECTOR, reschedule_interrupt); 567 set_intr_gate(RESCHEDULE_VECTOR, reschedule_interrupt);
564 568
565 /* IPI for invalidation */ 569 /* IPIs for invalidation */
566 set_intr_gate(INVALIDATE_TLB_VECTOR, invalidate_interrupt); 570 set_intr_gate(INVALIDATE_TLB_VECTOR_START+0, invalidate_interrupt0);
571 set_intr_gate(INVALIDATE_TLB_VECTOR_START+1, invalidate_interrupt1);
572 set_intr_gate(INVALIDATE_TLB_VECTOR_START+2, invalidate_interrupt2);
573 set_intr_gate(INVALIDATE_TLB_VECTOR_START+3, invalidate_interrupt3);
574 set_intr_gate(INVALIDATE_TLB_VECTOR_START+4, invalidate_interrupt4);
575 set_intr_gate(INVALIDATE_TLB_VECTOR_START+5, invalidate_interrupt5);
576 set_intr_gate(INVALIDATE_TLB_VECTOR_START+6, invalidate_interrupt6);
577 set_intr_gate(INVALIDATE_TLB_VECTOR_START+7, invalidate_interrupt7);
567 578
568 /* IPI for generic function call */ 579 /* IPI for generic function call */
569 set_intr_gate(CALL_FUNCTION_VECTOR, call_function_interrupt); 580 set_intr_gate(CALL_FUNCTION_VECTOR, call_function_interrupt);
diff --git a/arch/x86_64/kernel/init_task.c b/arch/x86_64/kernel/init_task.c
index c4dc914911..e0ba5c1043 100644
--- a/arch/x86_64/kernel/init_task.c
+++ b/arch/x86_64/kernel/init_task.c
@@ -44,6 +44,6 @@ EXPORT_SYMBOL(init_task);
44 * section. Since TSS's are completely CPU-local, we want them 44 * section. Since TSS's are completely CPU-local, we want them
45 * on exact cacheline boundaries, to eliminate cacheline ping-pong. 45 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
46 */ 46 */
47DEFINE_PER_CPU(struct tss_struct, init_tss) ____cacheline_maxaligned_in_smp; 47DEFINE_PER_CPU(struct tss_struct, init_tss) ____cacheline_maxaligned_in_smp = INIT_TSS;
48 48
49#define ALIGN_TO_4K __attribute__((section(".data.init_task"))) 49#define ALIGN_TO_4K __attribute__((section(".data.init_task")))
diff --git a/arch/x86_64/kernel/io_apic.c b/arch/x86_64/kernel/io_apic.c
index 5f1529be12..522944a000 100644
--- a/arch/x86_64/kernel/io_apic.c
+++ b/arch/x86_64/kernel/io_apic.c
@@ -21,7 +21,6 @@
21 */ 21 */
22 22
23#include <linux/mm.h> 23#include <linux/mm.h>
24#include <linux/irq.h>
25#include <linux/interrupt.h> 24#include <linux/interrupt.h>
26#include <linux/init.h> 25#include <linux/init.h>
27#include <linux/delay.h> 26#include <linux/delay.h>
@@ -45,6 +44,8 @@ int sis_apic_bug; /* not actually supported, dummy for compile */
45 44
46static int no_timer_check; 45static int no_timer_check;
47 46
47int disable_timer_pin_1 __initdata;
48
48static DEFINE_SPINLOCK(ioapic_lock); 49static DEFINE_SPINLOCK(ioapic_lock);
49 50
50/* 51/*
@@ -298,6 +299,15 @@ void __init check_ioapic(void)
298#endif 299#endif
299 /* RED-PEN skip them on mptables too? */ 300 /* RED-PEN skip them on mptables too? */
300 return; 301 return;
302 case PCI_VENDOR_ID_ATI:
303 /* All timer interrupts on atiixp
304 are doubled. Disable one. */
305 if (disable_timer_pin_1 == 0) {
306 disable_timer_pin_1 = 1;
307 printk(KERN_INFO
308 "ATI board detected. Disabling timer pin 1.\n");
309 }
310 return;
301 } 311 }
302 312
303 /* No multi-function device? */ 313 /* No multi-function device? */
@@ -1022,13 +1032,11 @@ void __apicdebuginit print_local_APIC(void * dummy)
1022 v = apic_read(APIC_TASKPRI); 1032 v = apic_read(APIC_TASKPRI);
1023 printk(KERN_DEBUG "... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK); 1033 printk(KERN_DEBUG "... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK);
1024 1034
1025 if (APIC_INTEGRATED(ver)) { /* !82489DX */ 1035 v = apic_read(APIC_ARBPRI);
1026 v = apic_read(APIC_ARBPRI); 1036 printk(KERN_DEBUG "... APIC ARBPRI: %08x (%02x)\n", v,
1027 printk(KERN_DEBUG "... APIC ARBPRI: %08x (%02x)\n", v, 1037 v & APIC_ARBPRI_MASK);
1028 v & APIC_ARBPRI_MASK); 1038 v = apic_read(APIC_PROCPRI);
1029 v = apic_read(APIC_PROCPRI); 1039 printk(KERN_DEBUG "... APIC PROCPRI: %08x\n", v);
1030 printk(KERN_DEBUG "... APIC PROCPRI: %08x\n", v);
1031 }
1032 1040
1033 v = apic_read(APIC_EOI); 1041 v = apic_read(APIC_EOI);
1034 printk(KERN_DEBUG "... APIC EOI: %08x\n", v); 1042 printk(KERN_DEBUG "... APIC EOI: %08x\n", v);
@@ -1048,12 +1056,8 @@ void __apicdebuginit print_local_APIC(void * dummy)
1048 printk(KERN_DEBUG "... APIC IRR field:\n"); 1056 printk(KERN_DEBUG "... APIC IRR field:\n");
1049 print_APIC_bitfield(APIC_IRR); 1057 print_APIC_bitfield(APIC_IRR);
1050 1058
1051 if (APIC_INTEGRATED(ver)) { /* !82489DX */ 1059 v = apic_read(APIC_ESR);
1052 if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */ 1060 printk(KERN_DEBUG "... APIC ESR: %08x\n", v);
1053 apic_write(APIC_ESR, 0);
1054 v = apic_read(APIC_ESR);
1055 printk(KERN_DEBUG "... APIC ESR: %08x\n", v);
1056 }
1057 1061
1058 v = apic_read(APIC_ICR); 1062 v = apic_read(APIC_ICR);
1059 printk(KERN_DEBUG "... APIC ICR: %08x\n", v); 1063 printk(KERN_DEBUG "... APIC ICR: %08x\n", v);
@@ -1665,6 +1669,8 @@ static inline void check_timer(void)
1665 setup_nmi(); 1669 setup_nmi();
1666 enable_8259A_irq(0); 1670 enable_8259A_irq(0);
1667 } 1671 }
1672 if (disable_timer_pin_1 > 0)
1673 clear_IO_APIC_pin(0, pin1);
1668 return; 1674 return;
1669 } 1675 }
1670 clear_IO_APIC_pin(0, pin1); 1676 clear_IO_APIC_pin(0, pin1);
diff --git a/arch/x86_64/kernel/irq.c b/arch/x86_64/kernel/irq.c
index 849a20aec7..d6a04a8320 100644
--- a/arch/x86_64/kernel/irq.c
+++ b/arch/x86_64/kernel/irq.c
@@ -99,7 +99,6 @@ asmlinkage unsigned int do_IRQ(struct pt_regs *regs)
99 unsigned irq = regs->orig_rax & 0xff; 99 unsigned irq = regs->orig_rax & 0xff;
100 100
101 irq_enter(); 101 irq_enter();
102 BUG_ON(irq > 256);
103 102
104 __do_IRQ(irq, regs); 103 __do_IRQ(irq, regs);
105 irq_exit(); 104 irq_exit();
diff --git a/arch/x86_64/kernel/mce.c b/arch/x86_64/kernel/mce.c
index 8aa56736cd..969365c077 100644
--- a/arch/x86_64/kernel/mce.c
+++ b/arch/x86_64/kernel/mce.c
@@ -17,6 +17,7 @@
17#include <linux/fs.h> 17#include <linux/fs.h>
18#include <linux/cpu.h> 18#include <linux/cpu.h>
19#include <linux/percpu.h> 19#include <linux/percpu.h>
20#include <linux/ctype.h>
20#include <asm/processor.h> 21#include <asm/processor.h>
21#include <asm/msr.h> 22#include <asm/msr.h>
22#include <asm/mce.h> 23#include <asm/mce.h>
@@ -56,15 +57,19 @@ void mce_log(struct mce *mce)
56 smp_wmb(); 57 smp_wmb();
57 for (;;) { 58 for (;;) {
58 entry = rcu_dereference(mcelog.next); 59 entry = rcu_dereference(mcelog.next);
59 /* When the buffer fills up discard new entries. Assume 60 for (;;) {
60 that the earlier errors are the more interesting. */ 61 /* When the buffer fills up discard new entries. Assume
61 if (entry >= MCE_LOG_LEN) { 62 that the earlier errors are the more interesting. */
62 set_bit(MCE_OVERFLOW, &mcelog.flags); 63 if (entry >= MCE_LOG_LEN) {
63 return; 64 set_bit(MCE_OVERFLOW, &mcelog.flags);
65 return;
66 }
67 /* Old left over entry. Skip. */
68 if (mcelog.entry[entry].finished) {
69 entry++;
70 continue;
71 }
64 } 72 }
65 /* Old left over entry. Skip. */
66 if (mcelog.entry[entry].finished)
67 continue;
68 smp_rmb(); 73 smp_rmb();
69 next = entry + 1; 74 next = entry + 1;
70 if (cmpxchg(&mcelog.next, entry, next) == entry) 75 if (cmpxchg(&mcelog.next, entry, next) == entry)
@@ -404,9 +409,15 @@ static ssize_t mce_read(struct file *filp, char __user *ubuf, size_t usize, loff
404 } 409 }
405 410
406 err = 0; 411 err = 0;
407 for (i = 0; i < next; i++) { 412 for (i = 0; i < next; i++) {
408 if (!mcelog.entry[i].finished) 413 unsigned long start = jiffies;
409 continue; 414 while (!mcelog.entry[i].finished) {
415 if (!time_before(jiffies, start + 2)) {
416 memset(mcelog.entry + i,0, sizeof(struct mce));
417 continue;
418 }
419 cpu_relax();
420 }
410 smp_rmb(); 421 smp_rmb();
411 err |= copy_to_user(buf, mcelog.entry + i, sizeof(struct mce)); 422 err |= copy_to_user(buf, mcelog.entry + i, sizeof(struct mce));
412 buf += sizeof(struct mce); 423 buf += sizeof(struct mce);
@@ -479,6 +490,7 @@ static int __init mcheck_disable(char *str)
479 490
480/* mce=off disables machine check. Note you can reenable it later 491/* mce=off disables machine check. Note you can reenable it later
481 using sysfs. 492 using sysfs.
493 mce=TOLERANCELEVEL (number, see above)
482 mce=bootlog Log MCEs from before booting. Disabled by default to work 494 mce=bootlog Log MCEs from before booting. Disabled by default to work
483 around buggy BIOS that leave bogus MCEs. */ 495 around buggy BIOS that leave bogus MCEs. */
484static int __init mcheck_enable(char *str) 496static int __init mcheck_enable(char *str)
@@ -489,6 +501,8 @@ static int __init mcheck_enable(char *str)
489 mce_dont_init = 1; 501 mce_dont_init = 1;
490 else if (!strcmp(str, "bootlog")) 502 else if (!strcmp(str, "bootlog"))
491 mce_bootlog = 1; 503 mce_bootlog = 1;
504 else if (isdigit(str[0]))
505 get_option(&str, &tolerant);
492 else 506 else
493 printk("mce= argument %s ignored. Please use /sys", str); 507 printk("mce= argument %s ignored. Please use /sys", str);
494 return 0; 508 return 0;
@@ -501,10 +515,12 @@ __setup("mce", mcheck_enable);
501 * Sysfs support 515 * Sysfs support
502 */ 516 */
503 517
504/* On resume clear all MCE state. Don't want to see leftovers from the BIOS. */ 518/* On resume clear all MCE state. Don't want to see leftovers from the BIOS.
519 Only one CPU is active at this time, the others get readded later using
520 CPU hotplug. */
505static int mce_resume(struct sys_device *dev) 521static int mce_resume(struct sys_device *dev)
506{ 522{
507 on_each_cpu(mce_init, NULL, 1, 1); 523 mce_init(NULL);
508 return 0; 524 return 0;
509} 525}
510 526
diff --git a/arch/x86_64/kernel/mpparse.c b/arch/x86_64/kernel/mpparse.c
index 8d8ed6ae1d..f16d38d09d 100644
--- a/arch/x86_64/kernel/mpparse.c
+++ b/arch/x86_64/kernel/mpparse.c
@@ -14,7 +14,6 @@
14 */ 14 */
15 15
16#include <linux/mm.h> 16#include <linux/mm.h>
17#include <linux/irq.h>
18#include <linux/init.h> 17#include <linux/init.h>
19#include <linux/delay.h> 18#include <linux/delay.h>
20#include <linux/config.h> 19#include <linux/config.h>
@@ -46,8 +45,6 @@ int acpi_found_madt;
46int apic_version [MAX_APICS]; 45int apic_version [MAX_APICS];
47unsigned char mp_bus_id_to_type [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = -1 }; 46unsigned char mp_bus_id_to_type [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = -1 };
48int mp_bus_id_to_pci_bus [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = -1 }; 47int mp_bus_id_to_pci_bus [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = -1 };
49unsigned char pci_bus_to_node [256];
50EXPORT_SYMBOL(pci_bus_to_node);
51 48
52static int mp_current_pci_id = 0; 49static int mp_current_pci_id = 0;
53/* I/O APIC entries */ 50/* I/O APIC entries */
@@ -705,7 +702,7 @@ void __init mp_register_lapic (
705 702
706 processor.mpc_type = MP_PROCESSOR; 703 processor.mpc_type = MP_PROCESSOR;
707 processor.mpc_apicid = id; 704 processor.mpc_apicid = id;
708 processor.mpc_apicver = 0x10; /* TBD: lapic version */ 705 processor.mpc_apicver = GET_APIC_VERSION(apic_read(APIC_LVR));
709 processor.mpc_cpuflag = (enabled ? CPU_ENABLED : 0); 706 processor.mpc_cpuflag = (enabled ? CPU_ENABLED : 0);
710 processor.mpc_cpuflag |= (boot_cpu ? CPU_BOOTPROCESSOR : 0); 707 processor.mpc_cpuflag |= (boot_cpu ? CPU_BOOTPROCESSOR : 0);
711 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) | 708 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
diff --git a/arch/x86_64/kernel/msr.c b/arch/x86_64/kernel/msr.c
deleted file mode 100644
index 598953ab01..0000000000
--- a/arch/x86_64/kernel/msr.c
+++ /dev/null
@@ -1,279 +0,0 @@
1/* ----------------------------------------------------------------------- *
2 *
3 * Copyright 2000 H. Peter Anvin - All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
8 * USA; either version 2 of the License, or (at your option) any later
9 * version; incorporated herein by reference.
10 *
11 * ----------------------------------------------------------------------- */
12
13/*
14 * msr.c
15 *
16 * x86 MSR access device
17 *
18 * This device is accessed by lseek() to the appropriate register number
19 * and then read/write in chunks of 8 bytes. A larger size means multiple
20 * reads or writes of the same register.
21 *
22 * This driver uses /dev/cpu/%d/msr where %d is the minor number, and on
23 * an SMP box will direct the access to CPU %d.
24 */
25
26#include <linux/module.h>
27#include <linux/config.h>
28
29#include <linux/types.h>
30#include <linux/errno.h>
31#include <linux/fcntl.h>
32#include <linux/init.h>
33#include <linux/poll.h>
34#include <linux/smp.h>
35#include <linux/smp_lock.h>
36#include <linux/major.h>
37#include <linux/fs.h>
38
39#include <asm/processor.h>
40#include <asm/msr.h>
41#include <asm/uaccess.h>
42#include <asm/system.h>
43
44/* Note: "err" is handled in a funny way below. Otherwise one version
45 of gcc or another breaks. */
46
47static inline int wrmsr_eio(u32 reg, u32 eax, u32 edx)
48{
49 int err;
50
51 asm volatile ("1: wrmsr\n"
52 "2:\n"
53 ".section .fixup,\"ax\"\n"
54 "3: movl %4,%0\n"
55 " jmp 2b\n"
56 ".previous\n"
57 ".section __ex_table,\"a\"\n"
58 " .align 8\n" " .quad 1b,3b\n" ".previous":"=&bDS" (err)
59 :"a"(eax), "d"(edx), "c"(reg), "i"(-EIO), "0"(0));
60
61 return err;
62}
63
64static inline int rdmsr_eio(u32 reg, u32 *eax, u32 *edx)
65{
66 int err;
67
68 asm volatile ("1: rdmsr\n"
69 "2:\n"
70 ".section .fixup,\"ax\"\n"
71 "3: movl %4,%0\n"
72 " jmp 2b\n"
73 ".previous\n"
74 ".section __ex_table,\"a\"\n"
75 " .align 8\n"
76 " .quad 1b,3b\n"
77 ".previous":"=&bDS" (err), "=a"(*eax), "=d"(*edx)
78 :"c"(reg), "i"(-EIO), "0"(0));
79
80 return err;
81}
82
83#ifdef CONFIG_SMP
84
85struct msr_command {
86 int cpu;
87 int err;
88 u32 reg;
89 u32 data[2];
90};
91
92static void msr_smp_wrmsr(void *cmd_block)
93{
94 struct msr_command *cmd = (struct msr_command *)cmd_block;
95
96 if (cmd->cpu == smp_processor_id())
97 cmd->err = wrmsr_eio(cmd->reg, cmd->data[0], cmd->data[1]);
98}
99
100static void msr_smp_rdmsr(void *cmd_block)
101{
102 struct msr_command *cmd = (struct msr_command *)cmd_block;
103
104 if (cmd->cpu == smp_processor_id())
105 cmd->err = rdmsr_eio(cmd->reg, &cmd->data[0], &cmd->data[1]);
106}
107
108static inline int do_wrmsr(int cpu, u32 reg, u32 eax, u32 edx)
109{
110 struct msr_command cmd;
111 int ret;
112
113 preempt_disable();
114 if (cpu == smp_processor_id()) {
115 ret = wrmsr_eio(reg, eax, edx);
116 } else {
117 cmd.cpu = cpu;
118 cmd.reg = reg;
119 cmd.data[0] = eax;
120 cmd.data[1] = edx;
121
122 smp_call_function(msr_smp_wrmsr, &cmd, 1, 1);
123 ret = cmd.err;
124 }
125 preempt_enable();
126 return ret;
127}
128
129static inline int do_rdmsr(int cpu, u32 reg, u32 * eax, u32 * edx)
130{
131 struct msr_command cmd;
132 int ret;
133
134 preempt_disable();
135 if (cpu == smp_processor_id()) {
136 ret = rdmsr_eio(reg, eax, edx);
137 } else {
138 cmd.cpu = cpu;
139 cmd.reg = reg;
140
141 smp_call_function(msr_smp_rdmsr, &cmd, 1, 1);
142
143 *eax = cmd.data[0];
144 *edx = cmd.data[1];
145
146 ret = cmd.err;
147 }
148 preempt_enable();
149 return ret;
150}
151
152#else /* ! CONFIG_SMP */
153
154static inline int do_wrmsr(int cpu, u32 reg, u32 eax, u32 edx)
155{
156 return wrmsr_eio(reg, eax, edx);
157}
158
159static inline int do_rdmsr(int cpu, u32 reg, u32 *eax, u32 *edx)
160{
161 return rdmsr_eio(reg, eax, edx);
162}
163
164#endif /* ! CONFIG_SMP */
165
166static loff_t msr_seek(struct file *file, loff_t offset, int orig)
167{
168 loff_t ret = -EINVAL;
169
170 lock_kernel();
171 switch (orig) {
172 case 0:
173 file->f_pos = offset;
174 ret = file->f_pos;
175 break;
176 case 1:
177 file->f_pos += offset;
178 ret = file->f_pos;
179 }
180 unlock_kernel();
181 return ret;
182}
183
184static ssize_t msr_read(struct file *file, char __user * buf,
185 size_t count, loff_t * ppos)
186{
187 u32 __user *tmp = (u32 __user *) buf;
188 u32 data[2];
189 size_t rv;
190 u32 reg = *ppos;
191 int cpu = iminor(file->f_dentry->d_inode);
192 int err;
193
194 if (count % 8)
195 return -EINVAL; /* Invalid chunk size */
196
197 for (rv = 0; count; count -= 8) {
198 err = do_rdmsr(cpu, reg, &data[0], &data[1]);
199 if (err)
200 return err;
201 if (copy_to_user(tmp, &data, 8))
202 return -EFAULT;
203 tmp += 2;
204 }
205
206 return ((char __user *)tmp) - buf;
207}
208
209static ssize_t msr_write(struct file *file, const char __user *buf,
210 size_t count, loff_t *ppos)
211{
212 const u32 __user *tmp = (const u32 __user *)buf;
213 u32 data[2];
214 size_t rv;
215 u32 reg = *ppos;
216 int cpu = iminor(file->f_dentry->d_inode);
217 int err;
218
219 if (count % 8)
220 return -EINVAL; /* Invalid chunk size */
221
222 for (rv = 0; count; count -= 8) {
223 if (copy_from_user(&data, tmp, 8))
224 return -EFAULT;
225 err = do_wrmsr(cpu, reg, data[0], data[1]);
226 if (err)
227 return err;
228 tmp += 2;
229 }
230
231 return ((char __user *)tmp) - buf;
232}
233
234static int msr_open(struct inode *inode, struct file *file)
235{
236 unsigned int cpu = iminor(file->f_dentry->d_inode);
237 struct cpuinfo_x86 *c = &(cpu_data)[cpu];
238
239 if (cpu >= NR_CPUS || !cpu_online(cpu))
240 return -ENXIO; /* No such CPU */
241 if (!cpu_has(c, X86_FEATURE_MSR))
242 return -EIO; /* MSR not supported */
243
244 return 0;
245}
246
247/*
248 * File operations we support
249 */
250static struct file_operations msr_fops = {
251 .owner = THIS_MODULE,
252 .llseek = msr_seek,
253 .read = msr_read,
254 .write = msr_write,
255 .open = msr_open,
256};
257
258static int __init msr_init(void)
259{
260 if (register_chrdev(MSR_MAJOR, "cpu/msr", &msr_fops)) {
261 printk(KERN_ERR "msr: unable to get major %d for msr\n",
262 MSR_MAJOR);
263 return -EBUSY;
264 }
265
266 return 0;
267}
268
269static void __exit msr_exit(void)
270{
271 unregister_chrdev(MSR_MAJOR, "cpu/msr");
272}
273
274module_init(msr_init);
275module_exit(msr_exit)
276
277MODULE_AUTHOR("H. Peter Anvin <hpa@zytor.com>");
278MODULE_DESCRIPTION("x86 generic MSR driver");
279MODULE_LICENSE("GPL");
diff --git a/arch/x86_64/kernel/nmi.c b/arch/x86_64/kernel/nmi.c
index caf164959e..4388b8a5ba 100644
--- a/arch/x86_64/kernel/nmi.c
+++ b/arch/x86_64/kernel/nmi.c
@@ -14,7 +14,6 @@
14 14
15#include <linux/config.h> 15#include <linux/config.h>
16#include <linux/mm.h> 16#include <linux/mm.h>
17#include <linux/irq.h>
18#include <linux/delay.h> 17#include <linux/delay.h>
19#include <linux/bootmem.h> 18#include <linux/bootmem.h>
20#include <linux/smp_lock.h> 19#include <linux/smp_lock.h>
@@ -488,8 +487,8 @@ void nmi_watchdog_tick (struct pt_regs * regs, unsigned reason)
488 == NOTIFY_STOP) { 487 == NOTIFY_STOP) {
489 local_set(&__get_cpu_var(alert_counter), 0); 488 local_set(&__get_cpu_var(alert_counter), 0);
490 return; 489 return;
491 } 490 }
492 die_nmi("NMI Watchdog detected LOCKUP on CPU%d", regs); 491 die_nmi("NMI Watchdog detected LOCKUP on CPU %d\n", regs);
493 } 492 }
494 } else { 493 } else {
495 __get_cpu_var(last_irq_sum) = sum; 494 __get_cpu_var(last_irq_sum) = sum;
diff --git a/arch/x86_64/kernel/pci-gart.c b/arch/x86_64/kernel/pci-gart.c
index 57f35c68aa..cf0a0315d5 100644
--- a/arch/x86_64/kernel/pci-gart.c
+++ b/arch/x86_64/kernel/pci-gart.c
@@ -191,11 +191,9 @@ static void *dma_alloc_pages(struct device *dev, unsigned gfp, unsigned order)
191{ 191{
192 struct page *page; 192 struct page *page;
193 int node; 193 int node;
194 if (dev->bus == &pci_bus_type) { 194 if (dev->bus == &pci_bus_type)
195 cpumask_t mask; 195 node = pcibus_to_node(to_pci_dev(dev)->bus);
196 mask = pcibus_to_cpumask(to_pci_dev(dev)->bus); 196 else
197 node = cpu_to_node(first_cpu(mask));
198 } else
199 node = numa_node_id(); 197 node = numa_node_id();
200 page = alloc_pages_node(node, gfp, order); 198 page = alloc_pages_node(node, gfp, order);
201 return page ? page_address(page) : NULL; 199 return page ? page_address(page) : NULL;
diff --git a/arch/x86_64/kernel/process.c b/arch/x86_64/kernel/process.c
index 8661f82ac7..b5a89c0bdf 100644
--- a/arch/x86_64/kernel/process.c
+++ b/arch/x86_64/kernel/process.c
@@ -32,7 +32,6 @@
32#include <linux/a.out.h> 32#include <linux/a.out.h>
33#include <linux/interrupt.h> 33#include <linux/interrupt.h>
34#include <linux/delay.h> 34#include <linux/delay.h>
35#include <linux/irq.h>
36#include <linux/ptrace.h> 35#include <linux/ptrace.h>
37#include <linux/utsname.h> 36#include <linux/utsname.h>
38#include <linux/random.h> 37#include <linux/random.h>
@@ -123,6 +122,7 @@ static void poll_idle (void)
123 : : 122 : :
124 "i" (_TIF_NEED_RESCHED), 123 "i" (_TIF_NEED_RESCHED),
125 "m" (current_thread_info()->flags)); 124 "m" (current_thread_info()->flags));
125 clear_thread_flag(TIF_POLLING_NRFLAG);
126 } else { 126 } else {
127 set_need_resched(); 127 set_need_resched();
128 } 128 }
@@ -271,8 +271,11 @@ void __show_regs(struct pt_regs * regs)
271 271
272 printk("\n"); 272 printk("\n");
273 print_modules(); 273 print_modules();
274 printk("Pid: %d, comm: %.20s %s %s\n", 274 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
275 current->pid, current->comm, print_tainted(), system_utsname.release); 275 current->pid, current->comm, print_tainted(),
276 system_utsname.release,
277 (int)strcspn(system_utsname.version, " "),
278 system_utsname.version);
276 printk("RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->rip); 279 printk("RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->rip);
277 printk_address(regs->rip); 280 printk_address(regs->rip);
278 printk("\nRSP: %04lx:%016lx EFLAGS: %08lx\n", regs->ss, regs->rsp, regs->eflags); 281 printk("\nRSP: %04lx:%016lx EFLAGS: %08lx\n", regs->ss, regs->rsp, regs->eflags);
@@ -483,33 +486,6 @@ out:
483} 486}
484 487
485/* 488/*
486 * This function selects if the context switch from prev to next
487 * has to tweak the TSC disable bit in the cr4.
488 */
489static inline void disable_tsc(struct task_struct *prev_p,
490 struct task_struct *next_p)
491{
492 struct thread_info *prev, *next;
493
494 /*
495 * gcc should eliminate the ->thread_info dereference if
496 * has_secure_computing returns 0 at compile time (SECCOMP=n).
497 */
498 prev = prev_p->thread_info;
499 next = next_p->thread_info;
500
501 if (has_secure_computing(prev) || has_secure_computing(next)) {
502 /* slow path here */
503 if (has_secure_computing(prev) &&
504 !has_secure_computing(next)) {
505 write_cr4(read_cr4() & ~X86_CR4_TSD);
506 } else if (!has_secure_computing(prev) &&
507 has_secure_computing(next))
508 write_cr4(read_cr4() | X86_CR4_TSD);
509 }
510}
511
512/*
513 * This special macro can be used to load a debugging register 489 * This special macro can be used to load a debugging register
514 */ 490 */
515#define loaddebug(thread,r) set_debug(thread->debugreg ## r, r) 491#define loaddebug(thread,r) set_debug(thread->debugreg ## r, r)
@@ -627,8 +603,6 @@ struct task_struct *__switch_to(struct task_struct *prev_p, struct task_struct *
627 } 603 }
628 } 604 }
629 605
630 disable_tsc(prev_p, next_p);
631
632 return prev_p; 606 return prev_p;
633} 607}
634 608
diff --git a/arch/x86_64/kernel/setup.c b/arch/x86_64/kernel/setup.c
index 0511d80879..351d8d64c2 100644
--- a/arch/x86_64/kernel/setup.c
+++ b/arch/x86_64/kernel/setup.c
@@ -336,6 +336,11 @@ static __init void parse_cmdline_early (char ** cmdline_p)
336#endif 336#endif
337#endif 337#endif
338 338
339 if (!memcmp(from, "disable_timer_pin_1", 19))
340 disable_timer_pin_1 = 1;
341 if (!memcmp(from, "enable_timer_pin_1", 18))
342 disable_timer_pin_1 = -1;
343
339 if (!memcmp(from, "nolapic", 7) || 344 if (!memcmp(from, "nolapic", 7) ||
340 !memcmp(from, "disableapic", 11)) 345 !memcmp(from, "disableapic", 11))
341 disable_apic = 1; 346 disable_apic = 1;
@@ -755,6 +760,24 @@ static void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
755 } 760 }
756} 761}
757 762
763#ifdef CONFIG_NUMA
764static int nearby_node(int apicid)
765{
766 int i;
767 for (i = apicid - 1; i >= 0; i--) {
768 int node = apicid_to_node[i];
769 if (node != NUMA_NO_NODE && node_online(node))
770 return node;
771 }
772 for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
773 int node = apicid_to_node[i];
774 if (node != NUMA_NO_NODE && node_online(node))
775 return node;
776 }
777 return first_node(node_online_map); /* Shouldn't happen */
778}
779#endif
780
758/* 781/*
759 * On a AMD dual core setup the lower bits of the APIC id distingush the cores. 782 * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
760 * Assumes number of cores is a power of two. 783 * Assumes number of cores is a power of two.
@@ -763,8 +786,11 @@ static void __init amd_detect_cmp(struct cpuinfo_x86 *c)
763{ 786{
764#ifdef CONFIG_SMP 787#ifdef CONFIG_SMP
765 int cpu = smp_processor_id(); 788 int cpu = smp_processor_id();
766 int node = 0;
767 unsigned bits; 789 unsigned bits;
790#ifdef CONFIG_NUMA
791 int node = 0;
792 unsigned apicid = phys_proc_id[cpu];
793#endif
768 794
769 bits = 0; 795 bits = 0;
770 while ((1 << bits) < c->x86_num_cores) 796 while ((1 << bits) < c->x86_num_cores)
@@ -776,20 +802,32 @@ static void __init amd_detect_cmp(struct cpuinfo_x86 *c)
776 phys_proc_id[cpu] >>= bits; 802 phys_proc_id[cpu] >>= bits;
777 803
778#ifdef CONFIG_NUMA 804#ifdef CONFIG_NUMA
779 /* When an ACPI SRAT table is available use the mappings from SRAT 805 node = phys_proc_id[cpu];
780 instead. */ 806 if (apicid_to_node[apicid] != NUMA_NO_NODE)
781 if (acpi_numa <= 0) { 807 node = apicid_to_node[apicid];
782 node = phys_proc_id[cpu]; 808 if (!node_online(node)) {
783 if (!node_online(node)) 809 /* Two possibilities here:
784 node = first_node(node_online_map); 810 - The CPU is missing memory and no node was created.
785 cpu_to_node[cpu] = node; 811 In that case try picking one from a nearby CPU
786 } else { 812 - The APIC IDs differ from the HyperTransport node IDs
787 node = cpu_to_node[cpu]; 813 which the K8 northbridge parsing fills in.
788 } 814 Assume they are all increased by a constant offset,
815 but in the same order as the HT nodeids.
816 If that doesn't result in a usable node fall back to the
817 path for the previous case. */
818 int ht_nodeid = apicid - (phys_proc_id[0] << bits);
819 if (ht_nodeid >= 0 &&
820 apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
821 node = apicid_to_node[ht_nodeid];
822 /* Pick a nearby node */
823 if (!node_online(node))
824 node = nearby_node(apicid);
825 }
826 cpu_to_node[cpu] = node;
827
828 printk(KERN_INFO "CPU %d(%d) -> Node %d -> Core %d\n",
829 cpu, c->x86_num_cores, node, cpu_core_id[cpu]);
789#endif 830#endif
790
791 printk(KERN_INFO "CPU %d(%d) -> Node %d -> Core %d\n",
792 cpu, c->x86_num_cores, node, cpu_core_id[cpu]);
793#endif 831#endif
794} 832}
795 833
@@ -909,6 +947,25 @@ static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
909 return 1; 947 return 1;
910} 948}
911 949
950static void srat_detect_node(void)
951{
952#ifdef CONFIG_NUMA
953 unsigned apicid, node;
954 int cpu = smp_processor_id();
955
956 /* Don't do the funky fallback heuristics the AMD version employs
957 for now. */
958 apicid = phys_proc_id[cpu];
959 node = apicid_to_node[apicid];
960 if (node == NUMA_NO_NODE)
961 node = 0;
962 cpu_to_node[cpu] = node;
963
964 if (acpi_numa > 0)
965 printk(KERN_INFO "CPU %d -> Node %d\n", cpu, node);
966#endif
967}
968
912static void __cpuinit init_intel(struct cpuinfo_x86 *c) 969static void __cpuinit init_intel(struct cpuinfo_x86 *c)
913{ 970{
914 /* Cache sizes */ 971 /* Cache sizes */
@@ -927,9 +984,11 @@ static void __cpuinit init_intel(struct cpuinfo_x86 *c)
927 if (c->x86 >= 15) 984 if (c->x86 >= 15)
928 set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability); 985 set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
929 c->x86_num_cores = intel_num_cpu_cores(c); 986 c->x86_num_cores = intel_num_cpu_cores(c);
987
988 srat_detect_node();
930} 989}
931 990
932void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c) 991static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
933{ 992{
934 char *v = c->x86_vendor_id; 993 char *v = c->x86_vendor_id;
935 994
diff --git a/arch/x86_64/kernel/setup64.c b/arch/x86_64/kernel/setup64.c
index e3ffcacc8c..bd33be24a3 100644
--- a/arch/x86_64/kernel/setup64.c
+++ b/arch/x86_64/kernel/setup64.c
@@ -94,7 +94,7 @@ void __init setup_per_cpu_areas(void)
94 size = PERCPU_ENOUGH_ROOM; 94 size = PERCPU_ENOUGH_ROOM;
95#endif 95#endif
96 96
97 for (i = 0; i < NR_CPUS; i++) { 97 for_each_cpu_mask (i, cpu_possible_map) {
98 char *ptr; 98 char *ptr;
99 99
100 if (!NODE_DATA(cpu_to_node(i))) { 100 if (!NODE_DATA(cpu_to_node(i))) {
@@ -119,7 +119,6 @@ void pda_init(int cpu)
119 asm volatile("movl %0,%%fs ; movl %0,%%gs" :: "r" (0)); 119 asm volatile("movl %0,%%fs ; movl %0,%%gs" :: "r" (0));
120 wrmsrl(MSR_GS_BASE, cpu_pda + cpu); 120 wrmsrl(MSR_GS_BASE, cpu_pda + cpu);
121 121
122 pda->me = pda;
123 pda->cpunumber = cpu; 122 pda->cpunumber = cpu;
124 pda->irqcount = -1; 123 pda->irqcount = -1;
125 pda->kernelstack = 124 pda->kernelstack =
diff --git a/arch/x86_64/kernel/smp.c b/arch/x86_64/kernel/smp.c
index e5958220d6..9db9dda161 100644
--- a/arch/x86_64/kernel/smp.c
+++ b/arch/x86_64/kernel/smp.c
@@ -12,7 +12,6 @@
12#include <linux/init.h> 12#include <linux/init.h>
13 13
14#include <linux/mm.h> 14#include <linux/mm.h>
15#include <linux/irq.h>
16#include <linux/delay.h> 15#include <linux/delay.h>
17#include <linux/spinlock.h> 16#include <linux/spinlock.h>
18#include <linux/smp_lock.h> 17#include <linux/smp_lock.h>
@@ -29,6 +28,8 @@
29#include <asm/proto.h> 28#include <asm/proto.h>
30#include <asm/apicdef.h> 29#include <asm/apicdef.h>
31 30
31#define __cpuinit __init
32
32/* 33/*
33 * Smarter SMP flushing macros. 34 * Smarter SMP flushing macros.
34 * c/o Linus Torvalds. 35 * c/o Linus Torvalds.
@@ -37,19 +38,41 @@
37 * writing to user space from interrupts. (Its not allowed anyway). 38 * writing to user space from interrupts. (Its not allowed anyway).
38 * 39 *
39 * Optimizations Manfred Spraul <manfred@colorfullife.com> 40 * Optimizations Manfred Spraul <manfred@colorfullife.com>
41 *
42 * More scalable flush, from Andi Kleen
43 *
44 * To avoid global state use 8 different call vectors.
45 * Each CPU uses a specific vector to trigger flushes on other
46 * CPUs. Depending on the received vector the target CPUs look into
47 * the right per cpu variable for the flush data.
48 *
49 * With more than 8 CPUs they are hashed to the 8 available
50 * vectors. The limited global vector space forces us to this right now.
51 * In future when interrupts are split into per CPU domains this could be
52 * fixed, at the cost of triggering multiple IPIs in some cases.
40 */ 53 */
41 54
42static cpumask_t flush_cpumask; 55union smp_flush_state {
43static struct mm_struct * flush_mm; 56 struct {
44static unsigned long flush_va; 57 cpumask_t flush_cpumask;
45static DEFINE_SPINLOCK(tlbstate_lock); 58 struct mm_struct *flush_mm;
59 unsigned long flush_va;
46#define FLUSH_ALL -1ULL 60#define FLUSH_ALL -1ULL
61 spinlock_t tlbstate_lock;
62 };
63 char pad[SMP_CACHE_BYTES];
64} ____cacheline_aligned;
65
66/* State is put into the per CPU data section, but padded
67 to a full cache line because other CPUs can access it and we don't
68 want false sharing in the per cpu data segment. */
69static DEFINE_PER_CPU(union smp_flush_state, flush_state);
47 70
48/* 71/*
49 * We cannot call mmdrop() because we are in interrupt context, 72 * We cannot call mmdrop() because we are in interrupt context,
50 * instead update mm->cpu_vm_mask. 73 * instead update mm->cpu_vm_mask.
51 */ 74 */
52static inline void leave_mm (unsigned long cpu) 75static inline void leave_mm(int cpu)
53{ 76{
54 if (read_pda(mmu_state) == TLBSTATE_OK) 77 if (read_pda(mmu_state) == TLBSTATE_OK)
55 BUG(); 78 BUG();
@@ -101,15 +124,25 @@ static inline void leave_mm (unsigned long cpu)
101 * 124 *
102 * 1) Flush the tlb entries if the cpu uses the mm that's being flushed. 125 * 1) Flush the tlb entries if the cpu uses the mm that's being flushed.
103 * 2) Leave the mm if we are in the lazy tlb mode. 126 * 2) Leave the mm if we are in the lazy tlb mode.
127 *
128 * Interrupts are disabled.
104 */ 129 */
105 130
106asmlinkage void smp_invalidate_interrupt (void) 131asmlinkage void smp_invalidate_interrupt(struct pt_regs *regs)
107{ 132{
108 unsigned long cpu; 133 int cpu;
134 int sender;
135 union smp_flush_state *f;
109 136
110 cpu = get_cpu(); 137 cpu = smp_processor_id();
138 /*
139 * orig_rax contains the interrupt vector - 256.
140 * Use that to determine where the sender put the data.
141 */
142 sender = regs->orig_rax + 256 - INVALIDATE_TLB_VECTOR_START;
143 f = &per_cpu(flush_state, sender);
111 144
112 if (!cpu_isset(cpu, flush_cpumask)) 145 if (!cpu_isset(cpu, f->flush_cpumask))
113 goto out; 146 goto out;
114 /* 147 /*
115 * This was a BUG() but until someone can quote me the 148 * This was a BUG() but until someone can quote me the
@@ -120,64 +153,63 @@ asmlinkage void smp_invalidate_interrupt (void)
120 * BUG(); 153 * BUG();
121 */ 154 */
122 155
123 if (flush_mm == read_pda(active_mm)) { 156 if (f->flush_mm == read_pda(active_mm)) {
124 if (read_pda(mmu_state) == TLBSTATE_OK) { 157 if (read_pda(mmu_state) == TLBSTATE_OK) {
125 if (flush_va == FLUSH_ALL) 158 if (f->flush_va == FLUSH_ALL)
126 local_flush_tlb(); 159 local_flush_tlb();
127 else 160 else
128 __flush_tlb_one(flush_va); 161 __flush_tlb_one(f->flush_va);
129 } else 162 } else
130 leave_mm(cpu); 163 leave_mm(cpu);
131 } 164 }
132out: 165out:
133 ack_APIC_irq(); 166 ack_APIC_irq();
134 cpu_clear(cpu, flush_cpumask); 167 cpu_clear(cpu, f->flush_cpumask);
135 put_cpu_no_resched();
136} 168}
137 169
138static void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm, 170static void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
139 unsigned long va) 171 unsigned long va)
140{ 172{
141 cpumask_t tmp; 173 int sender;
142 /* 174 union smp_flush_state *f;
143 * A couple of (to be removed) sanity checks:
144 *
145 * - we do not send IPIs to not-yet booted CPUs.
146 * - current CPU must not be in mask
147 * - mask must exist :)
148 */
149 BUG_ON(cpus_empty(cpumask));
150 cpus_and(tmp, cpumask, cpu_online_map);
151 BUG_ON(!cpus_equal(tmp, cpumask));
152 BUG_ON(cpu_isset(smp_processor_id(), cpumask));
153 if (!mm)
154 BUG();
155 175
156 /* 176 /* Caller has disabled preemption */
157 * I'm not happy about this global shared spinlock in the 177 sender = smp_processor_id() % NUM_INVALIDATE_TLB_VECTORS;
158 * MM hot path, but we'll see how contended it is. 178 f = &per_cpu(flush_state, sender);
159 * Temporarily this turns IRQs off, so that lockups are 179
160 * detected by the NMI watchdog. 180 /* Could avoid this lock when
161 */ 181 num_online_cpus() <= NUM_INVALIDATE_TLB_VECTORS, but it is
162 spin_lock(&tlbstate_lock); 182 probably not worth checking this for a cache-hot lock. */
163 183 spin_lock(&f->tlbstate_lock);
164 flush_mm = mm; 184
165 flush_va = va; 185 f->flush_mm = mm;
166 cpus_or(flush_cpumask, cpumask, flush_cpumask); 186 f->flush_va = va;
187 cpus_or(f->flush_cpumask, cpumask, f->flush_cpumask);
167 188
168 /* 189 /*
169 * We have to send the IPI only to 190 * We have to send the IPI only to
170 * CPUs affected. 191 * CPUs affected.
171 */ 192 */
172 send_IPI_mask(cpumask, INVALIDATE_TLB_VECTOR); 193 send_IPI_mask(cpumask, INVALIDATE_TLB_VECTOR_START + sender);
194
195 while (!cpus_empty(f->flush_cpumask))
196 cpu_relax();
173 197
174 while (!cpus_empty(flush_cpumask)) 198 f->flush_mm = NULL;
175 mb(); /* nothing. lockup detection does not belong here */; 199 f->flush_va = 0;
200 spin_unlock(&f->tlbstate_lock);
201}
176 202
177 flush_mm = NULL; 203int __cpuinit init_smp_flush(void)
178 flush_va = 0; 204{
179 spin_unlock(&tlbstate_lock); 205 int i;
206 for_each_cpu_mask(i, cpu_possible_map) {
207 spin_lock_init(&per_cpu(flush_state.tlbstate_lock, i));
208 }
209 return 0;
180} 210}
211
212core_initcall(init_smp_flush);
181 213
182void flush_tlb_current_task(void) 214void flush_tlb_current_task(void)
183{ 215{
@@ -295,8 +327,11 @@ void unlock_ipi_call_lock(void)
295/* 327/*
296 * this function sends a 'generic call function' IPI to one other CPU 328 * this function sends a 'generic call function' IPI to one other CPU
297 * in the system. 329 * in the system.
330 *
331 * cpu is a standard Linux logical CPU number.
298 */ 332 */
299static void __smp_call_function_single (int cpu, void (*func) (void *info), void *info, 333static void
334__smp_call_function_single(int cpu, void (*func) (void *info), void *info,
300 int nonatomic, int wait) 335 int nonatomic, int wait)
301{ 336{
302 struct call_data_struct data; 337 struct call_data_struct data;
diff --git a/arch/x86_64/kernel/smpboot.c b/arch/x86_64/kernel/smpboot.c
index 90aeccd151..e12d7baeb3 100644
--- a/arch/x86_64/kernel/smpboot.c
+++ b/arch/x86_64/kernel/smpboot.c
@@ -44,7 +44,6 @@
44#include <linux/mm.h> 44#include <linux/mm.h>
45#include <linux/kernel_stat.h> 45#include <linux/kernel_stat.h>
46#include <linux/smp_lock.h> 46#include <linux/smp_lock.h>
47#include <linux/irq.h>
48#include <linux/bootmem.h> 47#include <linux/bootmem.h>
49#include <linux/thread_info.h> 48#include <linux/thread_info.h>
50#include <linux/module.h> 49#include <linux/module.h>
@@ -58,6 +57,8 @@
58#include <asm/tlbflush.h> 57#include <asm/tlbflush.h>
59#include <asm/proto.h> 58#include <asm/proto.h>
60#include <asm/nmi.h> 59#include <asm/nmi.h>
60#include <asm/irq.h>
61#include <asm/hw_irq.h>
61 62
62/* Number of siblings per CPU package */ 63/* Number of siblings per CPU package */
63int smp_num_siblings = 1; 64int smp_num_siblings = 1;
@@ -413,8 +414,13 @@ void __cpuinit smp_callin(void)
413 414
414 /* 415 /*
415 * Get our bogomips. 416 * Get our bogomips.
417 *
418 * Need to enable IRQs because it can take longer and then
419 * the NMI watchdog might kill us.
416 */ 420 */
421 local_irq_enable();
417 calibrate_delay(); 422 calibrate_delay();
423 local_irq_disable();
418 Dprintk("Stack at about %p\n",&cpuid); 424 Dprintk("Stack at about %p\n",&cpuid);
419 425
420 disable_APIC_timer(); 426 disable_APIC_timer();
@@ -540,8 +546,8 @@ static void inquire_remote_apic(int apicid)
540 */ 546 */
541 apic_wait_icr_idle(); 547 apic_wait_icr_idle();
542 548
543 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(apicid)); 549 apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(apicid));
544 apic_write_around(APIC_ICR, APIC_DM_REMRD | regs[i]); 550 apic_write(APIC_ICR, APIC_DM_REMRD | regs[i]);
545 551
546 timeout = 0; 552 timeout = 0;
547 do { 553 do {
@@ -574,12 +580,12 @@ static int __cpuinit wakeup_secondary_via_INIT(int phys_apicid, unsigned int sta
574 /* 580 /*
575 * Turn INIT on target chip 581 * Turn INIT on target chip
576 */ 582 */
577 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid)); 583 apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
578 584
579 /* 585 /*
580 * Send IPI 586 * Send IPI
581 */ 587 */
582 apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_INT_ASSERT 588 apic_write(APIC_ICR, APIC_INT_LEVELTRIG | APIC_INT_ASSERT
583 | APIC_DM_INIT); 589 | APIC_DM_INIT);
584 590
585 Dprintk("Waiting for send to finish...\n"); 591 Dprintk("Waiting for send to finish...\n");
@@ -595,10 +601,10 @@ static int __cpuinit wakeup_secondary_via_INIT(int phys_apicid, unsigned int sta
595 Dprintk("Deasserting INIT.\n"); 601 Dprintk("Deasserting INIT.\n");
596 602
597 /* Target chip */ 603 /* Target chip */
598 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid)); 604 apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
599 605
600 /* Send IPI */ 606 /* Send IPI */
601 apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_DM_INIT); 607 apic_write(APIC_ICR, APIC_INT_LEVELTRIG | APIC_DM_INIT);
602 608
603 Dprintk("Waiting for send to finish...\n"); 609 Dprintk("Waiting for send to finish...\n");
604 timeout = 0; 610 timeout = 0;
@@ -610,16 +616,7 @@ static int __cpuinit wakeup_secondary_via_INIT(int phys_apicid, unsigned int sta
610 616
611 atomic_set(&init_deasserted, 1); 617 atomic_set(&init_deasserted, 1);
612 618
613 /* 619 num_starts = 2;
614 * Should we send STARTUP IPIs ?
615 *
616 * Determine this based on the APIC version.
617 * If we don't have an integrated APIC, don't send the STARTUP IPIs.
618 */
619 if (APIC_INTEGRATED(apic_version[phys_apicid]))
620 num_starts = 2;
621 else
622 num_starts = 0;
623 620
624 /* 621 /*
625 * Run STARTUP IPI loop. 622 * Run STARTUP IPI loop.
@@ -640,12 +637,11 @@ static int __cpuinit wakeup_secondary_via_INIT(int phys_apicid, unsigned int sta
640 */ 637 */
641 638
642 /* Target chip */ 639 /* Target chip */
643 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid)); 640 apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
644 641
645 /* Boot on the stack */ 642 /* Boot on the stack */
646 /* Kick the second */ 643 /* Kick the second */
647 apic_write_around(APIC_ICR, APIC_DM_STARTUP 644 apic_write(APIC_ICR, APIC_DM_STARTUP | (start_rip >> 12));
648 | (start_rip >> 12));
649 645
650 /* 646 /*
651 * Give the other CPU some time to accept the IPI. 647 * Give the other CPU some time to accept the IPI.
@@ -864,17 +860,6 @@ static __cpuinit void smp_cleanup_boot(void)
864 * Reset trampoline flag 860 * Reset trampoline flag
865 */ 861 */
866 *((volatile int *) phys_to_virt(0x467)) = 0; 862 *((volatile int *) phys_to_virt(0x467)) = 0;
867
868#ifndef CONFIG_HOTPLUG_CPU
869 /*
870 * Free pages reserved for SMP bootup.
871 * When you add hotplug CPU support later remove this
872 * Note there is more work to be done for later CPU bootup.
873 */
874
875 free_page((unsigned long) __va(PAGE_SIZE));
876 free_page((unsigned long) __va(SMP_TRAMPOLINE_BASE));
877#endif
878} 863}
879 864
880/* 865/*
@@ -894,23 +879,6 @@ static __init void disable_smp(void)
894 cpu_set(0, cpu_core_map[0]); 879 cpu_set(0, cpu_core_map[0]);
895} 880}
896 881
897/*
898 * Handle user cpus=... parameter.
899 */
900static __init void enforce_max_cpus(unsigned max_cpus)
901{
902 int i, k;
903 k = 0;
904 for (i = 0; i < NR_CPUS; i++) {
905 if (!cpu_possible(i))
906 continue;
907 if (++k > max_cpus) {
908 cpu_clear(i, cpu_possible_map);
909 cpu_clear(i, cpu_present_map);
910 }
911 }
912}
913
914#ifdef CONFIG_HOTPLUG_CPU 882#ifdef CONFIG_HOTPLUG_CPU
915/* 883/*
916 * cpu_possible_map should be static, it cannot change as cpu's 884 * cpu_possible_map should be static, it cannot change as cpu's
@@ -999,8 +967,6 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
999 current_cpu_data = boot_cpu_data; 967 current_cpu_data = boot_cpu_data;
1000 current_thread_info()->cpu = 0; /* needed? */ 968 current_thread_info()->cpu = 0; /* needed? */
1001 969
1002 enforce_max_cpus(max_cpus);
1003
1004#ifdef CONFIG_HOTPLUG_CPU 970#ifdef CONFIG_HOTPLUG_CPU
1005 prefill_possible_map(); 971 prefill_possible_map();
1006#endif 972#endif
diff --git a/arch/x86_64/kernel/suspend.c b/arch/x86_64/kernel/suspend.c
index 0612640d91..ebb9abf3ce 100644
--- a/arch/x86_64/kernel/suspend.c
+++ b/arch/x86_64/kernel/suspend.c
@@ -8,23 +8,8 @@
8 */ 8 */
9 9
10#include <linux/config.h> 10#include <linux/config.h>
11#include <linux/kernel.h> 11#include <linux/smp.h>
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/types.h>
15#include <linux/spinlock.h>
16#include <linux/poll.h>
17#include <linux/delay.h>
18#include <linux/sysrq.h>
19#include <linux/proc_fs.h>
20#include <linux/irq.h>
21#include <linux/pm.h>
22#include <linux/device.h>
23#include <linux/suspend.h> 12#include <linux/suspend.h>
24#include <asm/uaccess.h>
25#include <asm/acpi.h>
26#include <asm/tlbflush.h>
27#include <asm/io.h>
28#include <asm/proto.h> 13#include <asm/proto.h>
29 14
30struct saved_context saved_context; 15struct saved_context saved_context;
diff --git a/arch/x86_64/kernel/suspend_asm.S b/arch/x86_64/kernel/suspend_asm.S
index 53f8e16595..4d659e97df 100644
--- a/arch/x86_64/kernel/suspend_asm.S
+++ b/arch/x86_64/kernel/suspend_asm.S
@@ -14,7 +14,7 @@
14#include <linux/linkage.h> 14#include <linux/linkage.h>
15#include <asm/segment.h> 15#include <asm/segment.h>
16#include <asm/page.h> 16#include <asm/page.h>
17#include <asm/offset.h> 17#include <asm/asm-offsets.h>
18 18
19ENTRY(swsusp_arch_suspend) 19ENTRY(swsusp_arch_suspend)
20 20
diff --git a/arch/x86_64/kernel/time.c b/arch/x86_64/kernel/time.c
index 7b6abe0582..2373cb8b86 100644
--- a/arch/x86_64/kernel/time.c
+++ b/arch/x86_64/kernel/time.c
@@ -18,7 +18,6 @@
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/mc146818rtc.h> 20#include <linux/mc146818rtc.h>
21#include <linux/irq.h>
22#include <linux/time.h> 21#include <linux/time.h>
23#include <linux/ioport.h> 22#include <linux/ioport.h>
24#include <linux/module.h> 23#include <linux/module.h>
@@ -937,7 +936,6 @@ void __init time_init(void)
937 vxtime.mode = VXTIME_TSC; 936 vxtime.mode = VXTIME_TSC;
938 vxtime.quot = (1000000L << 32) / vxtime_hz; 937 vxtime.quot = (1000000L << 32) / vxtime_hz;
939 vxtime.tsc_quot = (1000L << 32) / cpu_khz; 938 vxtime.tsc_quot = (1000L << 32) / cpu_khz;
940 vxtime.hz = vxtime_hz;
941 rdtscll_sync(&vxtime.last_tsc); 939 rdtscll_sync(&vxtime.last_tsc);
942 setup_irq(0, &irq0); 940 setup_irq(0, &irq0);
943 941
diff --git a/arch/x86_64/kernel/traps.c b/arch/x86_64/kernel/traps.c
index f238d6078a..b5e09e6b55 100644
--- a/arch/x86_64/kernel/traps.c
+++ b/arch/x86_64/kernel/traps.c
@@ -47,9 +47,6 @@
47#include <asm/proto.h> 47#include <asm/proto.h>
48#include <asm/nmi.h> 48#include <asm/nmi.h>
49 49
50#include <linux/irq.h>
51
52
53extern struct gate_struct idt_table[256]; 50extern struct gate_struct idt_table[256];
54 51
55asmlinkage void divide_error(void); 52asmlinkage void divide_error(void);
@@ -324,13 +321,13 @@ void handle_BUG(struct pt_regs *regs)
324 if (__copy_from_user(&f, (struct bug_frame *) regs->rip, 321 if (__copy_from_user(&f, (struct bug_frame *) regs->rip,
325 sizeof(struct bug_frame))) 322 sizeof(struct bug_frame)))
326 return; 323 return;
327 if ((unsigned long)f.filename < __PAGE_OFFSET || 324 if (f.filename >= 0 ||
328 f.ud2[0] != 0x0f || f.ud2[1] != 0x0b) 325 f.ud2[0] != 0x0f || f.ud2[1] != 0x0b)
329 return; 326 return;
330 if (__get_user(tmp, f.filename)) 327 if (__get_user(tmp, (char *)(long)f.filename))
331 f.filename = "unmapped filename"; 328 f.filename = (int)(long)"unmapped filename";
332 printk("----------- [cut here ] --------- [please bite here ] ---------\n"); 329 printk("----------- [cut here ] --------- [please bite here ] ---------\n");
333 printk(KERN_ALERT "Kernel BUG at %.50s:%d\n", f.filename, f.line); 330 printk(KERN_ALERT "Kernel BUG at %.50s:%d\n", (char *)(long)f.filename, f.line);
334} 331}
335 332
336#ifdef CONFIG_BUG 333#ifdef CONFIG_BUG
@@ -343,30 +340,33 @@ void out_of_line_bug(void)
343static DEFINE_SPINLOCK(die_lock); 340static DEFINE_SPINLOCK(die_lock);
344static int die_owner = -1; 341static int die_owner = -1;
345 342
346void oops_begin(void) 343unsigned long oops_begin(void)
347{ 344{
348 int cpu = safe_smp_processor_id(); 345 int cpu = safe_smp_processor_id();
349 /* racy, but better than risking deadlock. */ 346 unsigned long flags;
350 local_irq_disable(); 347
348 /* racy, but better than risking deadlock. */
349 local_irq_save(flags);
351 if (!spin_trylock(&die_lock)) { 350 if (!spin_trylock(&die_lock)) {
352 if (cpu == die_owner) 351 if (cpu == die_owner)
353 /* nested oops. should stop eventually */; 352 /* nested oops. should stop eventually */;
354 else 353 else
355 spin_lock(&die_lock); 354 spin_lock(&die_lock);
356 } 355 }
357 die_owner = cpu; 356 die_owner = cpu;
358 console_verbose(); 357 console_verbose();
359 bust_spinlocks(1); 358 bust_spinlocks(1);
359 return flags;
360} 360}
361 361
362void oops_end(void) 362void oops_end(unsigned long flags)
363{ 363{
364 die_owner = -1; 364 die_owner = -1;
365 bust_spinlocks(0); 365 bust_spinlocks(0);
366 spin_unlock(&die_lock); 366 spin_unlock_irqrestore(&die_lock, flags);
367 if (panic_on_oops) 367 if (panic_on_oops)
368 panic("Oops"); 368 panic("Oops");
369} 369}
370 370
371void __die(const char * str, struct pt_regs * regs, long err) 371void __die(const char * str, struct pt_regs * regs, long err)
372{ 372{
@@ -392,10 +392,11 @@ void __die(const char * str, struct pt_regs * regs, long err)
392 392
393void die(const char * str, struct pt_regs * regs, long err) 393void die(const char * str, struct pt_regs * regs, long err)
394{ 394{
395 oops_begin(); 395 unsigned long flags = oops_begin();
396
396 handle_BUG(regs); 397 handle_BUG(regs);
397 __die(str, regs, err); 398 __die(str, regs, err);
398 oops_end(); 399 oops_end(flags);
399 do_exit(SIGSEGV); 400 do_exit(SIGSEGV);
400} 401}
401static inline void die_if_kernel(const char * str, struct pt_regs * regs, long err) 402static inline void die_if_kernel(const char * str, struct pt_regs * regs, long err)
@@ -406,7 +407,8 @@ static inline void die_if_kernel(const char * str, struct pt_regs * regs, long e
406 407
407void die_nmi(char *str, struct pt_regs *regs) 408void die_nmi(char *str, struct pt_regs *regs)
408{ 409{
409 oops_begin(); 410 unsigned long flags = oops_begin();
411
410 /* 412 /*
411 * We are in trouble anyway, lets at least try 413 * We are in trouble anyway, lets at least try
412 * to get a message out. 414 * to get a message out.
@@ -416,7 +418,7 @@ void die_nmi(char *str, struct pt_regs *regs)
416 if (panic_on_timeout || panic_on_oops) 418 if (panic_on_timeout || panic_on_oops)
417 panic("nmi watchdog"); 419 panic("nmi watchdog");
418 printk("console shuts up ...\n"); 420 printk("console shuts up ...\n");
419 oops_end(); 421 oops_end(flags);
420 do_exit(SIGSEGV); 422 do_exit(SIGSEGV);
421} 423}
422 424
@@ -790,13 +792,16 @@ asmlinkage void do_coprocessor_error(struct pt_regs *regs)
790 */ 792 */
791 cwd = get_fpu_cwd(task); 793 cwd = get_fpu_cwd(task);
792 swd = get_fpu_swd(task); 794 swd = get_fpu_swd(task);
793 switch (((~cwd) & swd & 0x3f) | (swd & 0x240)) { 795 switch (swd & ~cwd & 0x3f) {
794 case 0x000: 796 case 0x000:
795 default: 797 default:
796 break; 798 break;
797 case 0x001: /* Invalid Op */ 799 case 0x001: /* Invalid Op */
798 case 0x041: /* Stack Fault */ 800 /*
799 case 0x241: /* Stack Fault | Direction */ 801 * swd & 0x240 == 0x040: Stack Underflow
802 * swd & 0x240 == 0x240: Stack Overflow
803 * User must clear the SF bit (0x40) if set
804 */
800 info.si_code = FPE_FLTINV; 805 info.si_code = FPE_FLTINV;
801 break; 806 break;
802 case 0x002: /* Denormalize */ 807 case 0x002: /* Denormalize */
diff --git a/arch/x86_64/kernel/vmlinux.lds.S b/arch/x86_64/kernel/vmlinux.lds.S
index d4abb07af5..6dd642cad2 100644
--- a/arch/x86_64/kernel/vmlinux.lds.S
+++ b/arch/x86_64/kernel/vmlinux.lds.S
@@ -194,20 +194,7 @@ SECTIONS
194#endif 194#endif
195 } 195 }
196 196
197 /* DWARF 2 */ 197 STABS_DEBUG
198 .debug_info 0 : { *(.debug_info) } 198
199 .debug_abbrev 0 : { *(.debug_abbrev) } 199 DWARF_DEBUG
200 .debug_line 0 : { *(.debug_line) }
201 .debug_frame 0 : { *(.debug_frame) }
202 .debug_str 0 : { *(.debug_str) }
203 .debug_loc 0 : { *(.debug_loc) }
204 .debug_macinfo 0 : { *(.debug_macinfo) }
205 /* SGI/MIPS DWARF 2 extensions */
206 .debug_weaknames 0 : { *(.debug_weaknames) }
207 .debug_funcnames 0 : { *(.debug_funcnames) }
208 .debug_typenames 0 : { *(.debug_typenames) }
209 .debug_varnames 0 : { *(.debug_varnames) }
210
211
212 .comment 0 : { *(.comment) }
213} 200}
diff --git a/arch/x86_64/kernel/vsyscall.c b/arch/x86_64/kernel/vsyscall.c
index 2e57344259..70a0bd1608 100644
--- a/arch/x86_64/kernel/vsyscall.c
+++ b/arch/x86_64/kernel/vsyscall.c
@@ -107,7 +107,7 @@ static force_inline long time_syscall(long *t)
107 return secs; 107 return secs;
108} 108}
109 109
110static int __vsyscall(0) vgettimeofday(struct timeval * tv, struct timezone * tz) 110int __vsyscall(0) vgettimeofday(struct timeval * tv, struct timezone * tz)
111{ 111{
112 if (unlikely(!__sysctl_vsyscall)) 112 if (unlikely(!__sysctl_vsyscall))
113 return gettimeofday(tv,tz); 113 return gettimeofday(tv,tz);
@@ -120,7 +120,7 @@ static int __vsyscall(0) vgettimeofday(struct timeval * tv, struct timezone * tz
120 120
121/* This will break when the xtime seconds get inaccurate, but that is 121/* This will break when the xtime seconds get inaccurate, but that is
122 * unlikely */ 122 * unlikely */
123static time_t __vsyscall(1) vtime(time_t *t) 123time_t __vsyscall(1) vtime(time_t *t)
124{ 124{
125 if (unlikely(!__sysctl_vsyscall)) 125 if (unlikely(!__sysctl_vsyscall))
126 return time_syscall(t); 126 return time_syscall(t);
@@ -129,12 +129,12 @@ static time_t __vsyscall(1) vtime(time_t *t)
129 return __xtime.tv_sec; 129 return __xtime.tv_sec;
130} 130}
131 131
132static long __vsyscall(2) venosys_0(void) 132long __vsyscall(2) venosys_0(void)
133{ 133{
134 return -ENOSYS; 134 return -ENOSYS;
135} 135}
136 136
137static long __vsyscall(3) venosys_1(void) 137long __vsyscall(3) venosys_1(void)
138{ 138{
139 return -ENOSYS; 139 return -ENOSYS;
140} 140}
diff --git a/arch/x86_64/lib/copy_user.S b/arch/x86_64/lib/copy_user.S
index bd556c8042..dfa358b05c 100644
--- a/arch/x86_64/lib/copy_user.S
+++ b/arch/x86_64/lib/copy_user.S
@@ -7,7 +7,7 @@
7#define FIX_ALIGNMENT 1 7#define FIX_ALIGNMENT 1
8 8
9 #include <asm/current.h> 9 #include <asm/current.h>
10 #include <asm/offset.h> 10 #include <asm/asm-offsets.h>
11 #include <asm/thread_info.h> 11 #include <asm/thread_info.h>
12 #include <asm/cpufeature.h> 12 #include <asm/cpufeature.h>
13 13
diff --git a/arch/x86_64/lib/getuser.S b/arch/x86_64/lib/getuser.S
index f80bafee86..3844d5e885 100644
--- a/arch/x86_64/lib/getuser.S
+++ b/arch/x86_64/lib/getuser.S
@@ -29,7 +29,7 @@
29#include <linux/linkage.h> 29#include <linux/linkage.h>
30#include <asm/page.h> 30#include <asm/page.h>
31#include <asm/errno.h> 31#include <asm/errno.h>
32#include <asm/offset.h> 32#include <asm/asm-offsets.h>
33#include <asm/thread_info.h> 33#include <asm/thread_info.h>
34 34
35 .text 35 .text
diff --git a/arch/x86_64/lib/putuser.S b/arch/x86_64/lib/putuser.S
index 5828b81916..7f5593974e 100644
--- a/arch/x86_64/lib/putuser.S
+++ b/arch/x86_64/lib/putuser.S
@@ -27,7 +27,7 @@
27#include <linux/linkage.h> 27#include <linux/linkage.h>
28#include <asm/page.h> 28#include <asm/page.h>
29#include <asm/errno.h> 29#include <asm/errno.h>
30#include <asm/offset.h> 30#include <asm/asm-offsets.h>
31#include <asm/thread_info.h> 31#include <asm/thread_info.h>
32 32
33 .text 33 .text
diff --git a/arch/x86_64/mm/fault.c b/arch/x86_64/mm/fault.c
index 816732d885..b75b872ec1 100644
--- a/arch/x86_64/mm/fault.c
+++ b/arch/x86_64/mm/fault.c
@@ -221,12 +221,13 @@ int unhandled_signal(struct task_struct *tsk, int sig)
221static noinline void pgtable_bad(unsigned long address, struct pt_regs *regs, 221static noinline void pgtable_bad(unsigned long address, struct pt_regs *regs,
222 unsigned long error_code) 222 unsigned long error_code)
223{ 223{
224 oops_begin(); 224 unsigned long flags = oops_begin();
225
225 printk(KERN_ALERT "%s: Corrupted page table at address %lx\n", 226 printk(KERN_ALERT "%s: Corrupted page table at address %lx\n",
226 current->comm, address); 227 current->comm, address);
227 dump_pagetable(address); 228 dump_pagetable(address);
228 __die("Bad pagetable", regs, error_code); 229 __die("Bad pagetable", regs, error_code);
229 oops_end(); 230 oops_end(flags);
230 do_exit(SIGKILL); 231 do_exit(SIGKILL);
231} 232}
232 233
@@ -304,6 +305,7 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
304 unsigned long address; 305 unsigned long address;
305 const struct exception_table_entry *fixup; 306 const struct exception_table_entry *fixup;
306 int write; 307 int write;
308 unsigned long flags;
307 siginfo_t info; 309 siginfo_t info;
308 310
309#ifdef CONFIG_CHECKING 311#ifdef CONFIG_CHECKING
@@ -521,7 +523,7 @@ no_context:
521 * terminate things with extreme prejudice. 523 * terminate things with extreme prejudice.
522 */ 524 */
523 525
524 oops_begin(); 526 flags = oops_begin();
525 527
526 if (address < PAGE_SIZE) 528 if (address < PAGE_SIZE)
527 printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference"); 529 printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference");
@@ -534,7 +536,7 @@ no_context:
534 __die("Oops", regs, error_code); 536 __die("Oops", regs, error_code);
535 /* Executive summary in case the body of the oops scrolled away */ 537 /* Executive summary in case the body of the oops scrolled away */
536 printk(KERN_EMERG "CR2: %016lx\n", address); 538 printk(KERN_EMERG "CR2: %016lx\n", address);
537 oops_end(); 539 oops_end(flags);
538 do_exit(SIGKILL); 540 do_exit(SIGKILL);
539 541
540/* 542/*
diff --git a/arch/x86_64/mm/init.c b/arch/x86_64/mm/init.c
index aa4a5189ec..e60a1a848d 100644
--- a/arch/x86_64/mm/init.c
+++ b/arch/x86_64/mm/init.c
@@ -57,31 +57,31 @@ DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
57 57
58void show_mem(void) 58void show_mem(void)
59{ 59{
60 int i, total = 0, reserved = 0; 60 long i, total = 0, reserved = 0;
61 int shared = 0, cached = 0; 61 long shared = 0, cached = 0;
62 pg_data_t *pgdat; 62 pg_data_t *pgdat;
63 struct page *page; 63 struct page *page;
64 64
65 printk("Mem-info:\n"); 65 printk(KERN_INFO "Mem-info:\n");
66 show_free_areas(); 66 show_free_areas();
67 printk("Free swap: %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10)); 67 printk(KERN_INFO "Free swap: %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10));
68 68
69 for_each_pgdat(pgdat) { 69 for_each_pgdat(pgdat) {
70 for (i = 0; i < pgdat->node_spanned_pages; ++i) { 70 for (i = 0; i < pgdat->node_spanned_pages; ++i) {
71 page = pfn_to_page(pgdat->node_start_pfn + i); 71 page = pfn_to_page(pgdat->node_start_pfn + i);
72 total++; 72 total++;
73 if (PageReserved(page)) 73 if (PageReserved(page))
74 reserved++; 74 reserved++;
75 else if (PageSwapCache(page)) 75 else if (PageSwapCache(page))
76 cached++; 76 cached++;
77 else if (page_count(page)) 77 else if (page_count(page))
78 shared += page_count(page) - 1; 78 shared += page_count(page) - 1;
79 } 79 }
80 } 80 }
81 printk("%d pages of RAM\n", total); 81 printk(KERN_INFO "%lu pages of RAM\n", total);
82 printk("%d reserved pages\n",reserved); 82 printk(KERN_INFO "%lu reserved pages\n",reserved);
83 printk("%d pages shared\n",shared); 83 printk(KERN_INFO "%lu pages shared\n",shared);
84 printk("%d pages swap cached\n",cached); 84 printk(KERN_INFO "%lu pages swap cached\n",cached);
85} 85}
86 86
87/* References to section boundaries */ 87/* References to section boundaries */
@@ -381,41 +381,14 @@ void __init clear_kernel_mapping(unsigned long address, unsigned long size)
381 __flush_tlb_all(); 381 __flush_tlb_all();
382} 382}
383 383
384static inline int page_is_ram (unsigned long pagenr)
385{
386 int i;
387
388 for (i = 0; i < e820.nr_map; i++) {
389 unsigned long addr, end;
390
391 if (e820.map[i].type != E820_RAM) /* not usable memory */
392 continue;
393 /*
394 * !!!FIXME!!! Some BIOSen report areas as RAM that
395 * are not. Notably the 640->1Mb area. We need a sanity
396 * check here.
397 */
398 addr = (e820.map[i].addr+PAGE_SIZE-1) >> PAGE_SHIFT;
399 end = (e820.map[i].addr+e820.map[i].size) >> PAGE_SHIFT;
400 if ((pagenr >= addr) && (pagenr < end))
401 return 1;
402 }
403 return 0;
404}
405
406extern int swiotlb_force;
407
408static struct kcore_list kcore_mem, kcore_vmalloc, kcore_kernel, kcore_modules, 384static struct kcore_list kcore_mem, kcore_vmalloc, kcore_kernel, kcore_modules,
409 kcore_vsyscall; 385 kcore_vsyscall;
410 386
411void __init mem_init(void) 387void __init mem_init(void)
412{ 388{
413 int codesize, reservedpages, datasize, initsize; 389 long codesize, reservedpages, datasize, initsize;
414 int tmp;
415 390
416#ifdef CONFIG_SWIOTLB 391#ifdef CONFIG_SWIOTLB
417 if (swiotlb_force)
418 swiotlb = 1;
419 if (!iommu_aperture && 392 if (!iommu_aperture &&
420 (end_pfn >= 0xffffffff>>PAGE_SHIFT || force_iommu)) 393 (end_pfn >= 0xffffffff>>PAGE_SHIFT || force_iommu))
421 swiotlb = 1; 394 swiotlb = 1;
@@ -436,25 +409,11 @@ void __init mem_init(void)
436 409
437 /* this will put all low memory onto the freelists */ 410 /* this will put all low memory onto the freelists */
438#ifdef CONFIG_NUMA 411#ifdef CONFIG_NUMA
439 totalram_pages += numa_free_all_bootmem(); 412 totalram_pages = numa_free_all_bootmem();
440 tmp = 0;
441 /* should count reserved pages here for all nodes */
442#else 413#else
443 414 totalram_pages = free_all_bootmem();
444#ifdef CONFIG_FLATMEM
445 max_mapnr = end_pfn;
446 if (!mem_map) BUG();
447#endif
448
449 totalram_pages += free_all_bootmem();
450
451 for (tmp = 0; tmp < end_pfn; tmp++)
452 /*
453 * Only count reserved RAM pages
454 */
455 if (page_is_ram(tmp) && PageReserved(pfn_to_page(tmp)))
456 reservedpages++;
457#endif 415#endif
416 reservedpages = end_pfn - totalram_pages - e820_hole_size(0, end_pfn);
458 417
459 after_bootmem = 1; 418 after_bootmem = 1;
460 419
@@ -471,7 +430,7 @@ void __init mem_init(void)
471 kclist_add(&kcore_vsyscall, (void *)VSYSCALL_START, 430 kclist_add(&kcore_vsyscall, (void *)VSYSCALL_START,
472 VSYSCALL_END - VSYSCALL_START); 431 VSYSCALL_END - VSYSCALL_START);
473 432
474 printk("Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data, %dk init)\n", 433 printk("Memory: %luk/%luk available (%ldk kernel code, %ldk reserved, %ldk data, %ldk init)\n",
475 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10), 434 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
476 end_pfn << (PAGE_SHIFT-10), 435 end_pfn << (PAGE_SHIFT-10),
477 codesize >> 10, 436 codesize >> 10,
diff --git a/arch/x86_64/mm/k8topology.c b/arch/x86_64/mm/k8topology.c
index ec35747aac..65417b040c 100644
--- a/arch/x86_64/mm/k8topology.c
+++ b/arch/x86_64/mm/k8topology.c
@@ -45,10 +45,12 @@ int __init k8_scan_nodes(unsigned long start, unsigned long end)
45 unsigned long prevbase; 45 unsigned long prevbase;
46 struct node nodes[8]; 46 struct node nodes[8];
47 int nodeid, i, nb; 47 int nodeid, i, nb;
48 unsigned char nodeids[8];
48 int found = 0; 49 int found = 0;
49 u32 reg; 50 u32 reg;
50 unsigned numnodes; 51 unsigned numnodes;
51 nodemask_t nodes_parsed; 52 nodemask_t nodes_parsed;
53 unsigned dualcore = 0;
52 54
53 nodes_clear(nodes_parsed); 55 nodes_clear(nodes_parsed);
54 56
@@ -67,11 +69,15 @@ int __init k8_scan_nodes(unsigned long start, unsigned long end)
67 prevbase = 0; 69 prevbase = 0;
68 for (i = 0; i < 8; i++) { 70 for (i = 0; i < 8; i++) {
69 unsigned long base,limit; 71 unsigned long base,limit;
70 72 u32 nodeid;
73
74 /* Undefined before E stepping, but hopefully 0 */
75 dualcore |= ((read_pci_config(0, nb, 3, 0xe8) >> 12) & 3) == 1;
71 base = read_pci_config(0, nb, 1, 0x40 + i*8); 76 base = read_pci_config(0, nb, 1, 0x40 + i*8);
72 limit = read_pci_config(0, nb, 1, 0x44 + i*8); 77 limit = read_pci_config(0, nb, 1, 0x44 + i*8);
73 78
74 nodeid = limit & 7; 79 nodeid = limit & 7;
80 nodeids[i] = nodeid;
75 if ((base & 3) == 0) { 81 if ((base & 3) == 0) {
76 if (i < numnodes) 82 if (i < numnodes)
77 printk("Skipping disabled node %d\n", i); 83 printk("Skipping disabled node %d\n", i);
@@ -157,8 +163,9 @@ int __init k8_scan_nodes(unsigned long start, unsigned long end)
157 163
158 for (i = 0; i < 8; i++) { 164 for (i = 0; i < 8; i++) {
159 if (nodes[i].start != nodes[i].end) { 165 if (nodes[i].start != nodes[i].end) {
160 /* assume 1:1 NODE:CPU */ 166 nodeid = nodeids[i];
161 cpu_to_node[i] = i; 167 apicid_to_node[nodeid << dualcore] = i;
168 apicid_to_node[(nodeid << dualcore) + dualcore] = i;
162 setup_node_bootmem(i, nodes[i].start, nodes[i].end); 169 setup_node_bootmem(i, nodes[i].start, nodes[i].end);
163 } 170 }
164 } 171 }
diff --git a/arch/x86_64/mm/numa.c b/arch/x86_64/mm/numa.c
index 04f7a33e14..80a49d9bd8 100644
--- a/arch/x86_64/mm/numa.c
+++ b/arch/x86_64/mm/numa.c
@@ -28,8 +28,13 @@ bootmem_data_t plat_node_bdata[MAX_NUMNODES];
28int memnode_shift; 28int memnode_shift;
29u8 memnodemap[NODEMAPSIZE]; 29u8 memnodemap[NODEMAPSIZE];
30 30
31unsigned char cpu_to_node[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1] = NUMA_NO_NODE }; 31unsigned char cpu_to_node[NR_CPUS] __read_mostly = {
32cpumask_t node_to_cpumask[MAX_NUMNODES] __read_mostly; 32 [0 ... NR_CPUS-1] = NUMA_NO_NODE
33};
34unsigned char apicid_to_node[MAX_LOCAL_APIC] __cpuinitdata = {
35 [0 ... MAX_LOCAL_APIC-1] = NUMA_NO_NODE
36};
37cpumask_t node_to_cpumask[MAX_NUMNODES] __read_mostly;
33 38
34int numa_off __initdata; 39int numa_off __initdata;
35 40
diff --git a/arch/x86_64/mm/srat.c b/arch/x86_64/mm/srat.c
index 8e3d097a9d..4b2e844c15 100644
--- a/arch/x86_64/mm/srat.c
+++ b/arch/x86_64/mm/srat.c
@@ -20,14 +20,20 @@
20 20
21static struct acpi_table_slit *acpi_slit; 21static struct acpi_table_slit *acpi_slit;
22 22
23/* Internal processor count */
24static unsigned int __initdata num_processors = 0;
25
26static nodemask_t nodes_parsed __initdata; 23static nodemask_t nodes_parsed __initdata;
27static nodemask_t nodes_found __initdata; 24static nodemask_t nodes_found __initdata;
28static struct node nodes[MAX_NUMNODES] __initdata; 25static struct node nodes[MAX_NUMNODES] __initdata;
29static __u8 pxm2node[256] = { [0 ... 255] = 0xff }; 26static __u8 pxm2node[256] = { [0 ... 255] = 0xff };
30 27
28static int node_to_pxm(int n);
29
30int pxm_to_node(int pxm)
31{
32 if ((unsigned)pxm >= 256)
33 return 0;
34 return pxm2node[pxm];
35}
36
31static __init int setup_node(int pxm) 37static __init int setup_node(int pxm)
32{ 38{
33 unsigned node = pxm2node[pxm]; 39 unsigned node = pxm2node[pxm];
@@ -44,14 +50,14 @@ static __init int setup_node(int pxm)
44static __init int conflicting_nodes(unsigned long start, unsigned long end) 50static __init int conflicting_nodes(unsigned long start, unsigned long end)
45{ 51{
46 int i; 52 int i;
47 for_each_online_node(i) { 53 for_each_node_mask(i, nodes_parsed) {
48 struct node *nd = &nodes[i]; 54 struct node *nd = &nodes[i];
49 if (nd->start == nd->end) 55 if (nd->start == nd->end)
50 continue; 56 continue;
51 if (nd->end > start && nd->start < end) 57 if (nd->end > start && nd->start < end)
52 return 1; 58 return i;
53 if (nd->end == end && nd->start == start) 59 if (nd->end == end && nd->start == start)
54 return 1; 60 return i;
55 } 61 }
56 return -1; 62 return -1;
57} 63}
@@ -75,8 +81,11 @@ static __init void cutoff_node(int i, unsigned long start, unsigned long end)
75 81
76static __init void bad_srat(void) 82static __init void bad_srat(void)
77{ 83{
84 int i;
78 printk(KERN_ERR "SRAT: SRAT not used.\n"); 85 printk(KERN_ERR "SRAT: SRAT not used.\n");
79 acpi_numa = -1; 86 acpi_numa = -1;
87 for (i = 0; i < MAX_LOCAL_APIC; i++)
88 apicid_to_node[i] = NUMA_NO_NODE;
80} 89}
81 90
82static __init inline int srat_disabled(void) 91static __init inline int srat_disabled(void)
@@ -104,18 +113,10 @@ acpi_numa_processor_affinity_init(struct acpi_table_processor_affinity *pa)
104 bad_srat(); 113 bad_srat();
105 return; 114 return;
106 } 115 }
107 if (num_processors >= NR_CPUS) { 116 apicid_to_node[pa->apic_id] = node;
108 printk(KERN_ERR "SRAT: Processor #%d (lapic %u) INVALID. (Max ID: %d).\n",
109 num_processors, pa->apic_id, NR_CPUS);
110 bad_srat();
111 return;
112 }
113 cpu_to_node[num_processors] = node;
114 acpi_numa = 1; 117 acpi_numa = 1;
115 printk(KERN_INFO "SRAT: PXM %u -> APIC %u -> CPU %u -> Node %u\n", 118 printk(KERN_INFO "SRAT: PXM %u -> APIC %u -> Node %u\n",
116 pxm, pa->apic_id, num_processors, node); 119 pxm, pa->apic_id, node);
117
118 num_processors++;
119} 120}
120 121
121/* Callback for parsing of the Proximity Domain <-> Memory Area mappings */ 122/* Callback for parsing of the Proximity Domain <-> Memory Area mappings */
@@ -143,10 +144,15 @@ acpi_numa_memory_affinity_init(struct acpi_table_memory_affinity *ma)
143 printk(KERN_INFO "SRAT: hot plug zone found %lx - %lx \n", 144 printk(KERN_INFO "SRAT: hot plug zone found %lx - %lx \n",
144 start, end); 145 start, end);
145 i = conflicting_nodes(start, end); 146 i = conflicting_nodes(start, end);
146 if (i >= 0) { 147 if (i == node) {
148 printk(KERN_WARNING
149 "SRAT: Warning: PXM %d (%lx-%lx) overlaps with itself (%Lx-%Lx)\n",
150 pxm, start, end, nodes[i].start, nodes[i].end);
151 } else if (i >= 0) {
147 printk(KERN_ERR 152 printk(KERN_ERR
148 "SRAT: pxm %d overlap %lx-%lx with node %d(%Lx-%Lx)\n", 153 "SRAT: PXM %d (%lx-%lx) overlaps with PXM %d (%Lx-%Lx)\n",
149 pxm, start, end, i, nodes[i].start, nodes[i].end); 154 pxm, start, end, node_to_pxm(i),
155 nodes[i].start, nodes[i].end);
150 bad_srat(); 156 bad_srat();
151 return; 157 return;
152 } 158 }
@@ -174,6 +180,14 @@ int __init acpi_scan_nodes(unsigned long start, unsigned long end)
174 int i; 180 int i;
175 if (acpi_numa <= 0) 181 if (acpi_numa <= 0)
176 return -1; 182 return -1;
183
184 /* First clean up the node list */
185 for_each_node_mask(i, nodes_parsed) {
186 cutoff_node(i, start, end);
187 if (nodes[i].start == nodes[i].end)
188 node_clear(i, nodes_parsed);
189 }
190
177 memnode_shift = compute_hash_shift(nodes, nodes_weight(nodes_parsed)); 191 memnode_shift = compute_hash_shift(nodes, nodes_weight(nodes_parsed));
178 if (memnode_shift < 0) { 192 if (memnode_shift < 0) {
179 printk(KERN_ERR 193 printk(KERN_ERR
@@ -181,16 +195,10 @@ int __init acpi_scan_nodes(unsigned long start, unsigned long end)
181 bad_srat(); 195 bad_srat();
182 return -1; 196 return -1;
183 } 197 }
184 for (i = 0; i < MAX_NUMNODES; i++) { 198
185 if (!node_isset(i, nodes_parsed)) 199 /* Finally register nodes */
186 continue; 200 for_each_node_mask(i, nodes_parsed)
187 cutoff_node(i, start, end);
188 if (nodes[i].start == nodes[i].end) {
189 node_clear(i, nodes_parsed);
190 continue;
191 }
192 setup_node_bootmem(i, nodes[i].start, nodes[i].end); 201 setup_node_bootmem(i, nodes[i].start, nodes[i].end);
193 }
194 for (i = 0; i < NR_CPUS; i++) { 202 for (i = 0; i < NR_CPUS; i++) {
195 if (cpu_to_node[i] == NUMA_NO_NODE) 203 if (cpu_to_node[i] == NUMA_NO_NODE)
196 continue; 204 continue;
@@ -201,7 +209,7 @@ int __init acpi_scan_nodes(unsigned long start, unsigned long end)
201 return 0; 209 return 0;
202} 210}
203 211
204int node_to_pxm(int n) 212static int node_to_pxm(int n)
205{ 213{
206 int i; 214 int i;
207 if (pxm2node[n] == n) 215 if (pxm2node[n] == n)
diff --git a/arch/x86_64/pci/k8-bus.c b/arch/x86_64/pci/k8-bus.c
index d80c323669..3acf60ded2 100644
--- a/arch/x86_64/pci/k8-bus.c
+++ b/arch/x86_64/pci/k8-bus.c
@@ -58,10 +58,16 @@ fill_mp_bus_to_cpumask(void)
58 for (j = SECONDARY_LDT_BUS_NUMBER(ldtbus); 58 for (j = SECONDARY_LDT_BUS_NUMBER(ldtbus);
59 j <= SUBORDINATE_LDT_BUS_NUMBER(ldtbus); 59 j <= SUBORDINATE_LDT_BUS_NUMBER(ldtbus);
60 j++) { 60 j++) {
61 int node = NODE_ID(nid); 61 struct pci_bus *bus;
62 long node = NODE_ID(nid);
63 /* Algorithm a bit dumb, but
64 it shouldn't matter here */
65 bus = pci_find_bus(0, j);
66 if (!bus)
67 continue;
62 if (!node_online(node)) 68 if (!node_online(node))
63 node = 0; 69 node = 0;
64 pci_bus_to_node[j] = node; 70 bus->sysdata = (void *)node;
65 } 71 }
66 } 72 }
67 } 73 }
diff --git a/arch/x86_64/pci/mmconfig.c b/arch/x86_64/pci/mmconfig.c
index 657e88aa09..a0838c4a94 100644
--- a/arch/x86_64/pci/mmconfig.c
+++ b/arch/x86_64/pci/mmconfig.c
@@ -111,13 +111,6 @@ static int __init pci_mmcfg_init(void)
111 (pci_mmcfg_config[0].base_address == 0)) 111 (pci_mmcfg_config[0].base_address == 0))
112 return 0; 112 return 0;
113 113
114 /* Kludge for now. Don't use mmconfig on AMD systems because
115 those have some busses where mmconfig doesn't work,
116 and we don't parse ACPI MCFG well enough to handle that.
117 Remove when proper handling is added. */
118 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
119 return 0;
120
121 /* RED-PEN i386 doesn't do _nocache right now */ 114 /* RED-PEN i386 doesn't do _nocache right now */
122 pci_mmcfg_virt = kmalloc(sizeof(*pci_mmcfg_virt) * pci_mmcfg_config_num, GFP_KERNEL); 115 pci_mmcfg_virt = kmalloc(sizeof(*pci_mmcfg_virt) * pci_mmcfg_config_num, GFP_KERNEL);
123 if (pci_mmcfg_virt == NULL) { 116 if (pci_mmcfg_virt == NULL) {
diff --git a/arch/xtensa/Makefile b/arch/xtensa/Makefile
index 27847e4ffc..98fac8489a 100644
--- a/arch/xtensa/Makefile
+++ b/arch/xtensa/Makefile
@@ -66,13 +66,7 @@ boot := arch/xtensa/boot
66 66
67archinc := include/asm-xtensa 67archinc := include/asm-xtensa
68 68
69arch/xtensa/kernel/asm-offsets.s: \ 69archprepare: $(archinc)/.platform
70 arch/xtensa/kernel/asm-offsets.c $(archinc)/.platform
71
72include/asm-xtensa/offsets.h: arch/xtensa/kernel/asm-offsets.s
73 $(call filechk,gen-asm-offsets)
74
75prepare: $(archinc)/.platform $(archinc)/offsets.h
76 70
77# Update machine cpu and platform symlinks if something which affects 71# Update machine cpu and platform symlinks if something which affects
78# them changed. 72# them changed.
@@ -94,7 +88,7 @@ bzImage : zImage
94zImage zImage.initrd: vmlinux 88zImage zImage.initrd: vmlinux
95 $(Q)$(MAKE) $(build)=$(boot) $@ 89 $(Q)$(MAKE) $(build)=$(boot) $@
96 90
97CLEAN_FILES += arch/xtensa/vmlinux.lds $(archinc)/offset.h \ 91CLEAN_FILES += arch/xtensa/vmlinux.lds \
98 $(archinc)/platform $(archinc)/xtensa/config \ 92 $(archinc)/platform $(archinc)/xtensa/config \
99 $(archinc)/.platform 93 $(archinc)/.platform
100 94
diff --git a/arch/xtensa/kernel/align.S b/arch/xtensa/kernel/align.S
index 74b1e90ef0..a4956578a2 100644
--- a/arch/xtensa/kernel/align.S
+++ b/arch/xtensa/kernel/align.S
@@ -19,7 +19,7 @@
19#include <asm/ptrace.h> 19#include <asm/ptrace.h>
20#include <asm/ptrace.h> 20#include <asm/ptrace.h>
21#include <asm/current.h> 21#include <asm/current.h>
22#include <asm/offsets.h> 22#include <asm/asm-offsets.h>
23#include <asm/pgtable.h> 23#include <asm/pgtable.h>
24#include <asm/processor.h> 24#include <asm/processor.h>
25#include <asm/page.h> 25#include <asm/page.h>
diff --git a/arch/xtensa/kernel/entry.S b/arch/xtensa/kernel/entry.S
index c64a01f71d..5c018c503d 100644
--- a/arch/xtensa/kernel/entry.S
+++ b/arch/xtensa/kernel/entry.S
@@ -14,7 +14,7 @@
14 */ 14 */
15 15
16#include <linux/linkage.h> 16#include <linux/linkage.h>
17#include <asm/offsets.h> 17#include <asm/asm-offsets.h>
18#include <asm/processor.h> 18#include <asm/processor.h>
19#include <asm/thread_info.h> 19#include <asm/thread_info.h>
20#include <asm/uaccess.h> 20#include <asm/uaccess.h>
diff --git a/arch/xtensa/kernel/process.c b/arch/xtensa/kernel/process.c
index 4099703b14..c83bb0d417 100644
--- a/arch/xtensa/kernel/process.c
+++ b/arch/xtensa/kernel/process.c
@@ -43,7 +43,7 @@
43#include <asm/mmu.h> 43#include <asm/mmu.h>
44#include <asm/irq.h> 44#include <asm/irq.h>
45#include <asm/atomic.h> 45#include <asm/atomic.h>
46#include <asm/offsets.h> 46#include <asm/asm-offsets.h>
47#include <asm/coprocessor.h> 47#include <asm/coprocessor.h>
48 48
49extern void ret_from_fork(void); 49extern void ret_from_fork(void);
diff --git a/arch/xtensa/kernel/vectors.S b/arch/xtensa/kernel/vectors.S
index 81808f0c67..0e74397bfa 100644
--- a/arch/xtensa/kernel/vectors.S
+++ b/arch/xtensa/kernel/vectors.S
@@ -46,7 +46,7 @@
46#include <asm/ptrace.h> 46#include <asm/ptrace.h>
47#include <asm/ptrace.h> 47#include <asm/ptrace.h>
48#include <asm/current.h> 48#include <asm/current.h>
49#include <asm/offsets.h> 49#include <asm/asm-offsets.h>
50#include <asm/pgtable.h> 50#include <asm/pgtable.h>
51#include <asm/processor.h> 51#include <asm/processor.h>
52#include <asm/page.h> 52#include <asm/page.h>
diff --git a/drivers/acorn/block/fd1772.c b/drivers/acorn/block/fd1772.c
index c0a37d98b4..0485423412 100644
--- a/drivers/acorn/block/fd1772.c
+++ b/drivers/acorn/block/fd1772.c
@@ -376,19 +376,15 @@ static void do_fd_request(request_queue_t *);
376 376
377/************************* End of Prototypes **************************/ 377/************************* End of Prototypes **************************/
378 378
379static struct timer_list motor_off_timer = 379static DEFINE_TIMER(motor_off_timer, fd_motor_off_timer, 0, 0);
380 TIMER_INITIALIZER(fd_motor_off_timer, 0, 0);
381 380
382#ifdef TRACKBUFFER 381#ifdef TRACKBUFFER
383static struct timer_list readtrack_timer = 382static DEFINE_TIMER(readtrack_timer, fd_readtrack_check, 0, 0);
384 TIMER_INITIALIZER(fd_readtrack_check, 0, 0);
385#endif 383#endif
386 384
387static struct timer_list timeout_timer = 385static DEFINE_TIMER(timeout_timer, fd_times_out, 0, 0);
388 TIMER_INITIALIZER(fd_times_out, 0, 0);
389 386
390static struct timer_list fd_timer = 387static DEFINE_TIMER(fd_timer, check_change, 0, 0);
391 TIMER_INITIALIZER(check_change, 0, 0);
392 388
393/* DAG: Haven't got a clue what this is? */ 389/* DAG: Haven't got a clue what this is? */
394int stdma_islocked(void) 390int stdma_islocked(void)
diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c
index 7249ba2b7a..aee50b4532 100644
--- a/drivers/acpi/sleep/main.c
+++ b/drivers/acpi/sleep/main.c
@@ -23,7 +23,6 @@ u8 sleep_states[ACPI_S_STATE_COUNT];
23 23
24static struct pm_ops acpi_pm_ops; 24static struct pm_ops acpi_pm_ops;
25 25
26extern void do_suspend_lowlevel_s4bios(void);
27extern void do_suspend_lowlevel(void); 26extern void do_suspend_lowlevel(void);
28 27
29static u32 acpi_suspend_states[] = { 28static u32 acpi_suspend_states[] = {
@@ -98,8 +97,6 @@ static int acpi_pm_enter(suspend_state_t pm_state)
98 case PM_SUSPEND_DISK: 97 case PM_SUSPEND_DISK:
99 if (acpi_pm_ops.pm_disk_mode == PM_DISK_PLATFORM) 98 if (acpi_pm_ops.pm_disk_mode == PM_DISK_PLATFORM)
100 status = acpi_enter_sleep_state(acpi_state); 99 status = acpi_enter_sleep_state(acpi_state);
101 else
102 do_suspend_lowlevel_s4bios();
103 break; 100 break;
104 case PM_SUSPEND_MAX: 101 case PM_SUSPEND_MAX:
105 acpi_power_off(); 102 acpi_power_off();
@@ -206,11 +203,6 @@ static int __init acpi_sleep_init(void)
206 printk(" S%d", i); 203 printk(" S%d", i);
207 } 204 }
208 if (i == ACPI_STATE_S4) { 205 if (i == ACPI_STATE_S4) {
209 if (acpi_gbl_FACS->S4bios_f) {
210 sleep_states[i] = 1;
211 printk(" S4bios");
212 acpi_pm_ops.pm_disk_mode = PM_DISK_FIRMWARE;
213 }
214 if (sleep_states[i]) 206 if (sleep_states[i])
215 acpi_pm_ops.pm_disk_mode = PM_DISK_PLATFORM; 207 acpi_pm_ops.pm_disk_mode = PM_DISK_PLATFORM;
216 } 208 }
diff --git a/drivers/acpi/sleep/poweroff.c b/drivers/acpi/sleep/poweroff.c
index a5f947de87..af7935a95b 100644
--- a/drivers/acpi/sleep/poweroff.c
+++ b/drivers/acpi/sleep/poweroff.c
@@ -21,9 +21,7 @@ int acpi_sleep_prepare(u32 acpi_state)
21{ 21{
22#ifdef CONFIG_ACPI_SLEEP 22#ifdef CONFIG_ACPI_SLEEP
23 /* do we have a wakeup address for S2 and S3? */ 23 /* do we have a wakeup address for S2 and S3? */
24 /* Here, we support only S4BIOS, those we set the wakeup address */ 24 if (acpi_state == ACPI_STATE_S3) {
25 /* S4OS is only supported for now via swsusp.. */
26 if (acpi_state == ACPI_STATE_S3 || acpi_state == ACPI_STATE_S4) {
27 if (!acpi_wakeup_address) { 25 if (!acpi_wakeup_address) {
28 return -EFAULT; 26 return -EFAULT;
29 } 27 }
diff --git a/drivers/acpi/sleep/proc.c b/drivers/acpi/sleep/proc.c
index 09a603f352..4696a85a98 100644
--- a/drivers/acpi/sleep/proc.c
+++ b/drivers/acpi/sleep/proc.c
@@ -25,8 +25,6 @@ static int acpi_system_sleep_seq_show(struct seq_file *seq, void *offset)
25 for (i = 0; i <= ACPI_STATE_S5; i++) { 25 for (i = 0; i <= ACPI_STATE_S5; i++) {
26 if (sleep_states[i]) { 26 if (sleep_states[i]) {
27 seq_printf(seq, "S%d ", i); 27 seq_printf(seq, "S%d ", i);
28 if (i == ACPI_STATE_S4 && acpi_gbl_FACS->S4bios_f)
29 seq_printf(seq, "S4bios ");
30 } 28 }
31 } 29 }
32 30
diff --git a/drivers/atm/idt77105.c b/drivers/atm/idt77105.c
index b8c260ed4b..0aabfc2a59 100644
--- a/drivers/atm/idt77105.c
+++ b/drivers/atm/idt77105.c
@@ -50,10 +50,8 @@ static void idt77105_stats_timer_func(unsigned long);
50static void idt77105_restart_timer_func(unsigned long); 50static void idt77105_restart_timer_func(unsigned long);
51 51
52 52
53static struct timer_list stats_timer = 53static DEFINE_TIMER(stats_timer, idt77105_stats_timer_func, 0, 0);
54 TIMER_INITIALIZER(idt77105_stats_timer_func, 0, 0); 54static DEFINE_TIMER(restart_timer, idt77105_restart_timer_func, 0, 0);
55static struct timer_list restart_timer =
56 TIMER_INITIALIZER(idt77105_restart_timer_func, 0, 0);
57static int start_timer = 1; 55static int start_timer = 1;
58static struct idt77105_priv *idt77105_all = NULL; 56static struct idt77105_priv *idt77105_all = NULL;
59 57
diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
index a43575acb2..2e2e50e116 100644
--- a/drivers/atm/iphase.c
+++ b/drivers/atm/iphase.c
@@ -79,7 +79,7 @@ static IADEV *ia_dev[8];
79static struct atm_dev *_ia_dev[8]; 79static struct atm_dev *_ia_dev[8];
80static int iadev_count; 80static int iadev_count;
81static void ia_led_timer(unsigned long arg); 81static void ia_led_timer(unsigned long arg);
82static struct timer_list ia_timer = TIMER_INITIALIZER(ia_led_timer, 0, 0); 82static DEFINE_TIMER(ia_timer, ia_led_timer, 0, 0);
83static int IA_TX_BUF = DFL_TX_BUFFERS, IA_TX_BUF_SZ = DFL_TX_BUF_SZ; 83static int IA_TX_BUF = DFL_TX_BUFFERS, IA_TX_BUF_SZ = DFL_TX_BUF_SZ;
84static int IA_RX_BUF = DFL_RX_BUFFERS, IA_RX_BUF_SZ = DFL_RX_BUF_SZ; 84static int IA_RX_BUF = DFL_RX_BUFFERS, IA_RX_BUF_SZ = DFL_RX_BUF_SZ;
85static uint IADebugFlag = /* IF_IADBG_ERR | IF_IADBG_CBR| IF_IADBG_INIT_ADAPTER 85static uint IADebugFlag = /* IF_IADBG_ERR | IF_IADBG_CBR| IF_IADBG_INIT_ADAPTER
diff --git a/drivers/base/dmapool.c b/drivers/base/dmapool.c
index c4aebf2f52..60a7ef6a20 100644
--- a/drivers/base/dmapool.c
+++ b/drivers/base/dmapool.c
@@ -262,7 +262,8 @@ dma_pool_destroy (struct dma_pool *pool)
262 * If such a memory block can't be allocated, null is returned. 262 * If such a memory block can't be allocated, null is returned.
263 */ 263 */
264void * 264void *
265dma_pool_alloc (struct dma_pool *pool, int mem_flags, dma_addr_t *handle) 265dma_pool_alloc (struct dma_pool *pool, unsigned int __nocast mem_flags,
266 dma_addr_t *handle)
266{ 267{
267 unsigned long flags; 268 unsigned long flags;
268 struct dma_page *page; 269 struct dma_page *page;
diff --git a/drivers/block/acsi.c b/drivers/block/acsi.c
index ce933de480..0e1f34fef0 100644
--- a/drivers/block/acsi.c
+++ b/drivers/block/acsi.c
@@ -371,7 +371,7 @@ static int acsi_revalidate (struct gendisk *disk);
371/************************* End of Prototypes **************************/ 371/************************* End of Prototypes **************************/
372 372
373 373
374struct timer_list acsi_timer = TIMER_INITIALIZER(acsi_times_out, 0, 0); 374DEFINE_TIMER(acsi_timer, acsi_times_out, 0, 0);
375 375
376 376
377#ifdef CONFIG_ATARI_SLM 377#ifdef CONFIG_ATARI_SLM
diff --git a/drivers/block/acsi_slm.c b/drivers/block/acsi_slm.c
index e3be8c31a7..a5c1c8e871 100644
--- a/drivers/block/acsi_slm.c
+++ b/drivers/block/acsi_slm.c
@@ -268,7 +268,7 @@ static int slm_get_pagesize( int device, int *w, int *h );
268/************************* End of Prototypes **************************/ 268/************************* End of Prototypes **************************/
269 269
270 270
271static struct timer_list slm_timer = TIMER_INITIALIZER(slm_test_ready, 0, 0); 271static DEFINE_TIMER(slm_timer, slm_test_ready, 0, 0);
272 272
273static struct file_operations slm_fops = { 273static struct file_operations slm_fops = {
274 .owner = THIS_MODULE, 274 .owner = THIS_MODULE,
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index db05a5a99f..22bda05fc6 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -371,16 +371,10 @@ static int floppy_release( struct inode * inode, struct file * filp );
371 371
372/************************* End of Prototypes **************************/ 372/************************* End of Prototypes **************************/
373 373
374static struct timer_list motor_off_timer = 374static DEFINE_TIMER(motor_off_timer, fd_motor_off_timer, 0, 0);
375 TIMER_INITIALIZER(fd_motor_off_timer, 0, 0); 375static DEFINE_TIMER(readtrack_timer, fd_readtrack_check, 0, 0);
376static struct timer_list readtrack_timer = 376static DEFINE_TIMER(timeout_timer, fd_times_out, 0, 0);
377 TIMER_INITIALIZER(fd_readtrack_check, 0, 0); 377static DEFINE_TIMER(fd_timer, check_change, 0, 0);
378
379static struct timer_list timeout_timer =
380 TIMER_INITIALIZER(fd_times_out, 0, 0);
381
382static struct timer_list fd_timer =
383 TIMER_INITIALIZER(check_change, 0, 0);
384 378
385static inline void start_motor_off_timer(void) 379static inline void start_motor_off_timer(void)
386{ 380{
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 418b1469d7..28f2c177a5 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -1713,10 +1713,9 @@ static unsigned long pollcomplete(int ctlr)
1713 1713
1714 for (i = 20 * HZ; i > 0; i--) { 1714 for (i = 20 * HZ; i > 0; i--) {
1715 done = hba[ctlr]->access.command_completed(hba[ctlr]); 1715 done = hba[ctlr]->access.command_completed(hba[ctlr]);
1716 if (done == FIFO_EMPTY) { 1716 if (done == FIFO_EMPTY)
1717 set_current_state(TASK_UNINTERRUPTIBLE); 1717 schedule_timeout_uninterruptible(1);
1718 schedule_timeout(1); 1718 else
1719 } else
1720 return (done); 1719 return (done);
1721 } 1720 }
1722 /* Invalid address to tell caller we ran out of time */ 1721 /* Invalid address to tell caller we ran out of time */
diff --git a/drivers/block/cfq-iosched.c b/drivers/block/cfq-iosched.c
index 30c0903c7c..cd056e7e64 100644
--- a/drivers/block/cfq-iosched.c
+++ b/drivers/block/cfq-iosched.c
@@ -2260,6 +2260,8 @@ static void cfq_put_cfqd(struct cfq_data *cfqd)
2260 if (!atomic_dec_and_test(&cfqd->ref)) 2260 if (!atomic_dec_and_test(&cfqd->ref))
2261 return; 2261 return;
2262 2262
2263 blk_put_queue(q);
2264
2263 cfq_shutdown_timer_wq(cfqd); 2265 cfq_shutdown_timer_wq(cfqd);
2264 q->elevator->elevator_data = NULL; 2266 q->elevator->elevator_data = NULL;
2265 2267
@@ -2316,6 +2318,7 @@ static int cfq_init_queue(request_queue_t *q, elevator_t *e)
2316 e->elevator_data = cfqd; 2318 e->elevator_data = cfqd;
2317 2319
2318 cfqd->queue = q; 2320 cfqd->queue = q;
2321 atomic_inc(&q->refcnt);
2319 2322
2320 cfqd->max_queued = q->nr_requests / 4; 2323 cfqd->max_queued = q->nr_requests / 4;
2321 q->nr_batching = cfq_queued; 2324 q->nr_batching = cfq_queued;
diff --git a/drivers/block/deadline-iosched.c b/drivers/block/deadline-iosched.c
index 24594c57c3..52a3ae5289 100644
--- a/drivers/block/deadline-iosched.c
+++ b/drivers/block/deadline-iosched.c
@@ -512,7 +512,10 @@ static int deadline_dispatch_requests(struct deadline_data *dd)
512 /* 512 /*
513 * batches are currently reads XOR writes 513 * batches are currently reads XOR writes
514 */ 514 */
515 drq = dd->next_drq[WRITE] ? : dd->next_drq[READ]; 515 if (dd->next_drq[WRITE])
516 drq = dd->next_drq[WRITE];
517 else
518 drq = dd->next_drq[READ];
516 519
517 if (drq) { 520 if (drq) {
518 /* we have a "next request" */ 521 /* we have a "next request" */
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 888dad5eef..0089547715 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -628,7 +628,7 @@ static inline void debugt(const char *message) { }
628#endif /* DEBUGT */ 628#endif /* DEBUGT */
629 629
630typedef void (*timeout_fn) (unsigned long); 630typedef void (*timeout_fn) (unsigned long);
631static struct timer_list fd_timeout = TIMER_INITIALIZER(floppy_shutdown, 0, 0); 631static DEFINE_TIMER(fd_timeout, floppy_shutdown, 0, 0);
632 632
633static const char *timeout_message; 633static const char *timeout_message;
634 634
@@ -1012,7 +1012,7 @@ static void schedule_bh(void (*handler) (void))
1012 schedule_work(&floppy_work); 1012 schedule_work(&floppy_work);
1013} 1013}
1014 1014
1015static struct timer_list fd_timer = TIMER_INITIALIZER(NULL, 0, 0); 1015static DEFINE_TIMER(fd_timer, NULL, 0, 0);
1016 1016
1017static void cancel_activity(void) 1017static void cancel_activity(void)
1018{ 1018{
diff --git a/drivers/block/paride/pcd.c b/drivers/block/paride/pcd.c
index 7289f67e95..ac5ba46271 100644
--- a/drivers/block/paride/pcd.c
+++ b/drivers/block/paride/pcd.c
@@ -516,8 +516,7 @@ static int pcd_tray_move(struct cdrom_device_info *cdi, int position)
516 516
517static void pcd_sleep(int cs) 517static void pcd_sleep(int cs)
518{ 518{
519 current->state = TASK_INTERRUPTIBLE; 519 schedule_timeout_interruptible(cs);
520 schedule_timeout(cs);
521} 520}
522 521
523static int pcd_reset(struct pcd_unit *cd) 522static int pcd_reset(struct pcd_unit *cd)
diff --git a/drivers/block/paride/pf.c b/drivers/block/paride/pf.c
index 060b1f2a91..711d2f314a 100644
--- a/drivers/block/paride/pf.c
+++ b/drivers/block/paride/pf.c
@@ -507,8 +507,7 @@ static void pf_eject(struct pf_unit *pf)
507 507
508static void pf_sleep(int cs) 508static void pf_sleep(int cs)
509{ 509{
510 current->state = TASK_INTERRUPTIBLE; 510 schedule_timeout_interruptible(cs);
511 schedule_timeout(cs);
512} 511}
513 512
514/* the ATAPI standard actually specifies the contents of all 7 registers 513/* the ATAPI standard actually specifies the contents of all 7 registers
diff --git a/drivers/block/paride/pg.c b/drivers/block/paride/pg.c
index 84d8e291ed..b3982395f2 100644
--- a/drivers/block/paride/pg.c
+++ b/drivers/block/paride/pg.c
@@ -276,8 +276,7 @@ static inline u8 DRIVE(struct pg *dev)
276 276
277static void pg_sleep(int cs) 277static void pg_sleep(int cs)
278{ 278{
279 current->state = TASK_INTERRUPTIBLE; 279 schedule_timeout_interruptible(cs);
280 schedule_timeout(cs);
281} 280}
282 281
283static int pg_wait(struct pg *dev, int go, int stop, unsigned long tmo, char *msg) 282static int pg_wait(struct pg *dev, int go, int stop, unsigned long tmo, char *msg)
diff --git a/drivers/block/paride/pt.c b/drivers/block/paride/pt.c
index 5fe8ee86f0..d8d35233cf 100644
--- a/drivers/block/paride/pt.c
+++ b/drivers/block/paride/pt.c
@@ -383,8 +383,7 @@ static int pt_atapi(struct pt_unit *tape, char *cmd, int dlen, char *buf, char *
383 383
384static void pt_sleep(int cs) 384static void pt_sleep(int cs)
385{ 385{
386 current->state = TASK_INTERRUPTIBLE; 386 schedule_timeout_interruptible(cs);
387 schedule_timeout(cs);
388} 387}
389 388
390static int pt_poll_dsc(struct pt_unit *tape, int pause, int tmo, char *msg) 389static int pt_poll_dsc(struct pt_unit *tape, int pause, int tmo, char *msg)
diff --git a/drivers/block/ps2esdi.c b/drivers/block/ps2esdi.c
index 29548784cb..29d1518be7 100644
--- a/drivers/block/ps2esdi.c
+++ b/drivers/block/ps2esdi.c
@@ -99,8 +99,7 @@ static DECLARE_WAIT_QUEUE_HEAD(ps2esdi_int);
99static int no_int_yet; 99static int no_int_yet;
100static int ps2esdi_drives; 100static int ps2esdi_drives;
101static u_short io_base; 101static u_short io_base;
102static struct timer_list esdi_timer = 102static DEFINE_TIMER(esdi_timer, ps2esdi_reset_timer, 0, 0);
103 TIMER_INITIALIZER(ps2esdi_reset_timer, 0, 0);
104static int reset_status; 103static int reset_status;
105static int ps2esdi_slot = -1; 104static int ps2esdi_slot = -1;
106static int tp720esdi = 0; /* Is it Integrated ESDI of ThinkPad-720? */ 105static int tp720esdi = 0; /* Is it Integrated ESDI of ThinkPad-720? */
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index e5f7494c00..e425ad3eeb 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -834,8 +834,7 @@ static int fd_eject(struct floppy_state *fs)
834 break; 834 break;
835 } 835 }
836 swim3_select(fs, RELAX); 836 swim3_select(fs, RELAX);
837 current->state = TASK_INTERRUPTIBLE; 837 schedule_timeout_interruptible(1);
838 schedule_timeout(1);
839 if (swim3_readbit(fs, DISK_IN) == 0) 838 if (swim3_readbit(fs, DISK_IN) == 0)
840 break; 839 break;
841 } 840 }
@@ -906,8 +905,7 @@ static int floppy_open(struct inode *inode, struct file *filp)
906 break; 905 break;
907 } 906 }
908 swim3_select(fs, RELAX); 907 swim3_select(fs, RELAX);
909 current->state = TASK_INTERRUPTIBLE; 908 schedule_timeout_interruptible(1);
910 schedule_timeout(1);
911 } 909 }
912 if (err == 0 && (swim3_readbit(fs, SEEK_COMPLETE) == 0 910 if (err == 0 && (swim3_readbit(fs, SEEK_COMPLETE) == 0
913 || swim3_readbit(fs, DISK_IN) == 0)) 911 || swim3_readbit(fs, DISK_IN) == 0))
@@ -992,8 +990,7 @@ static int floppy_revalidate(struct gendisk *disk)
992 if (signal_pending(current)) 990 if (signal_pending(current))
993 break; 991 break;
994 swim3_select(fs, RELAX); 992 swim3_select(fs, RELAX);
995 current->state = TASK_INTERRUPTIBLE; 993 schedule_timeout_interruptible(1);
996 schedule_timeout(1);
997 } 994 }
998 ret = swim3_readbit(fs, SEEK_COMPLETE) == 0 995 ret = swim3_readbit(fs, SEEK_COMPLETE) == 0
999 || swim3_readbit(fs, DISK_IN) == 0; 996 || swim3_readbit(fs, DISK_IN) == 0;
diff --git a/drivers/block/swim_iop.c b/drivers/block/swim_iop.c
index a1283f6dc0..89e3c2f8b7 100644
--- a/drivers/block/swim_iop.c
+++ b/drivers/block/swim_iop.c
@@ -338,8 +338,7 @@ static int swimiop_eject(struct floppy_state *fs)
338 err = -EINTR; 338 err = -EINTR;
339 break; 339 break;
340 } 340 }
341 current->state = TASK_INTERRUPTIBLE; 341 schedule_timeout_interruptible(1);
342 schedule_timeout(1);
343 } 342 }
344 release_drive(fs); 343 release_drive(fs);
345 return cmd->error; 344 return cmd->error;
diff --git a/drivers/block/umem.c b/drivers/block/umem.c
index 0c4c121d2e..0f48301342 100644
--- a/drivers/block/umem.c
+++ b/drivers/block/umem.c
@@ -34,6 +34,7 @@
34 * - set initialised bit then. 34 * - set initialised bit then.
35 */ 35 */
36 36
37//#define DEBUG /* uncomment if you want debugging info (pr_debug) */
37#include <linux/config.h> 38#include <linux/config.h>
38#include <linux/sched.h> 39#include <linux/sched.h>
39#include <linux/fs.h> 40#include <linux/fs.h>
@@ -58,10 +59,6 @@
58#include <asm/uaccess.h> 59#include <asm/uaccess.h>
59#include <asm/io.h> 60#include <asm/io.h>
60 61
61#define PRINTK(x...) do {} while (0)
62#define dprintk(x...) do {} while (0)
63/*#define dprintk(x...) printk(x) */
64
65#define MM_MAXCARDS 4 62#define MM_MAXCARDS 4
66#define MM_RAHEAD 2 /* two sectors */ 63#define MM_RAHEAD 2 /* two sectors */
67#define MM_BLKSIZE 1024 /* 1k blocks */ 64#define MM_BLKSIZE 1024 /* 1k blocks */
@@ -299,7 +296,7 @@ static void mm_start_io(struct cardinfo *card)
299 296
300 /* make the last descriptor end the chain */ 297 /* make the last descriptor end the chain */
301 page = &card->mm_pages[card->Active]; 298 page = &card->mm_pages[card->Active];
302 PRINTK("start_io: %d %d->%d\n", card->Active, page->headcnt, page->cnt-1); 299 pr_debug("start_io: %d %d->%d\n", card->Active, page->headcnt, page->cnt-1);
303 desc = &page->desc[page->cnt-1]; 300 desc = &page->desc[page->cnt-1];
304 301
305 desc->control_bits |= cpu_to_le32(DMASCR_CHAIN_COMP_EN); 302 desc->control_bits |= cpu_to_le32(DMASCR_CHAIN_COMP_EN);
@@ -532,7 +529,7 @@ static void process_page(unsigned long data)
532 activate(card); 529 activate(card);
533 } else { 530 } else {
534 /* haven't finished with this one yet */ 531 /* haven't finished with this one yet */
535 PRINTK("do some more\n"); 532 pr_debug("do some more\n");
536 mm_start_io(card); 533 mm_start_io(card);
537 } 534 }
538 out_unlock: 535 out_unlock:
@@ -555,7 +552,7 @@ static void process_page(unsigned long data)
555static int mm_make_request(request_queue_t *q, struct bio *bio) 552static int mm_make_request(request_queue_t *q, struct bio *bio)
556{ 553{
557 struct cardinfo *card = q->queuedata; 554 struct cardinfo *card = q->queuedata;
558 PRINTK("mm_make_request %ld %d\n", bh->b_rsector, bh->b_size); 555 pr_debug("mm_make_request %ld %d\n", bh->b_rsector, bh->b_size);
559 556
560 bio->bi_phys_segments = bio->bi_idx; /* count of completed segments*/ 557 bio->bi_phys_segments = bio->bi_idx; /* count of completed segments*/
561 spin_lock_irq(&card->lock); 558 spin_lock_irq(&card->lock);
diff --git a/drivers/block/xd.c b/drivers/block/xd.c
index 1676033da6..68b6d7b154 100644
--- a/drivers/block/xd.c
+++ b/drivers/block/xd.c
@@ -47,6 +47,7 @@
47#include <linux/wait.h> 47#include <linux/wait.h>
48#include <linux/blkdev.h> 48#include <linux/blkdev.h>
49#include <linux/blkpg.h> 49#include <linux/blkpg.h>
50#include <linux/delay.h>
50 51
51#include <asm/system.h> 52#include <asm/system.h>
52#include <asm/io.h> 53#include <asm/io.h>
@@ -62,7 +63,7 @@ static int xd[5] = { -1,-1,-1,-1, };
62 63
63#define XD_DONT_USE_DMA 0 /* Initial value. may be overriden using 64#define XD_DONT_USE_DMA 0 /* Initial value. may be overriden using
64 "nodma" module option */ 65 "nodma" module option */
65#define XD_INIT_DISK_DELAY (30*HZ/1000) /* 30 ms delay during disk initialization */ 66#define XD_INIT_DISK_DELAY (30) /* 30 ms delay during disk initialization */
66 67
67/* Above may need to be increased if a problem with the 2nd drive detection 68/* Above may need to be increased if a problem with the 2nd drive detection
68 (ST11M controller) or resetting a controller (WD) appears */ 69 (ST11M controller) or resetting a controller (WD) appears */
@@ -529,10 +530,8 @@ static inline u_char xd_waitport (u_short port,u_char flags,u_char mask,u_long t
529 int success; 530 int success;
530 531
531 xdc_busy = 1; 532 xdc_busy = 1;
532 while ((success = ((inb(port) & mask) != flags)) && time_before(jiffies, expiry)) { 533 while ((success = ((inb(port) & mask) != flags)) && time_before(jiffies, expiry))
533 set_current_state(TASK_UNINTERRUPTIBLE); 534 schedule_timeout_uninterruptible(1);
534 schedule_timeout(1);
535 }
536 xdc_busy = 0; 535 xdc_busy = 0;
537 return (success); 536 return (success);
538} 537}
@@ -633,14 +632,12 @@ static u_char __init xd_initdrives (void (*init_drive)(u_char drive))
633 for (i = 0; i < XD_MAXDRIVES; i++) { 632 for (i = 0; i < XD_MAXDRIVES; i++) {
634 xd_build(cmdblk,CMD_TESTREADY,i,0,0,0,0,0); 633 xd_build(cmdblk,CMD_TESTREADY,i,0,0,0,0,0);
635 if (!xd_command(cmdblk,PIO_MODE,NULL,NULL,NULL,XD_TIMEOUT*8)) { 634 if (!xd_command(cmdblk,PIO_MODE,NULL,NULL,NULL,XD_TIMEOUT*8)) {
636 set_current_state(TASK_INTERRUPTIBLE); 635 msleep_interruptible(XD_INIT_DISK_DELAY);
637 schedule_timeout(XD_INIT_DISK_DELAY);
638 636
639 init_drive(count); 637 init_drive(count);
640 count++; 638 count++;
641 639
642 set_current_state(TASK_INTERRUPTIBLE); 640 msleep_interruptible(XD_INIT_DISK_DELAY);
643 schedule_timeout(XD_INIT_DISK_DELAY);
644 } 641 }
645 } 642 }
646 return (count); 643 return (count);
@@ -761,8 +758,7 @@ static void __init xd_wd_init_controller (unsigned int address)
761 758
762 outb(0,XD_RESET); /* reset the controller */ 759 outb(0,XD_RESET); /* reset the controller */
763 760
764 set_current_state(TASK_UNINTERRUPTIBLE); 761 msleep(XD_INIT_DISK_DELAY);
765 schedule_timeout(XD_INIT_DISK_DELAY);
766} 762}
767 763
768static void __init xd_wd_init_drive (u_char drive) 764static void __init xd_wd_init_drive (u_char drive)
@@ -936,8 +932,7 @@ If you need non-standard settings use the xd=... command */
936 xd_maxsectors = 0x01; 932 xd_maxsectors = 0x01;
937 outb(0,XD_RESET); /* reset the controller */ 933 outb(0,XD_RESET); /* reset the controller */
938 934
939 set_current_state(TASK_UNINTERRUPTIBLE); 935 msleep(XD_INIT_DISK_DELAY);
940 schedule_timeout(XD_INIT_DISK_DELAY);
941} 936}
942 937
943static void __init xd_xebec_init_drive (u_char drive) 938static void __init xd_xebec_init_drive (u_char drive)
diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
index 007f6a6624..bb5e8d665a 100644
--- a/drivers/block/z2ram.c
+++ b/drivers/block/z2ram.c
@@ -296,7 +296,7 @@ z2_open( struct inode *inode, struct file *filp )
296 return 0; 296 return 0;
297 297
298err_out_kfree: 298err_out_kfree:
299 kfree( z2ram_map ); 299 kfree(z2ram_map);
300err_out: 300err_out:
301 return rc; 301 return rc;
302} 302}
diff --git a/drivers/cdrom/aztcd.c b/drivers/cdrom/aztcd.c
index 43bf1e5dc3..ce4a1ce59d 100644
--- a/drivers/cdrom/aztcd.c
+++ b/drivers/cdrom/aztcd.c
@@ -297,7 +297,7 @@ static char azt_auto_eject = AZT_AUTO_EJECT;
297 297
298static int AztTimeout, AztTries; 298static int AztTimeout, AztTries;
299static DECLARE_WAIT_QUEUE_HEAD(azt_waitq); 299static DECLARE_WAIT_QUEUE_HEAD(azt_waitq);
300static struct timer_list delay_timer = TIMER_INITIALIZER(NULL, 0, 0); 300static DEFINE_TIMER(delay_timer, NULL, 0, 0);
301 301
302static struct azt_DiskInfo DiskInfo; 302static struct azt_DiskInfo DiskInfo;
303static struct azt_Toc Toc[MAX_TRACKS]; 303static struct azt_Toc Toc[MAX_TRACKS];
diff --git a/drivers/cdrom/gscd.c b/drivers/cdrom/gscd.c
index 7eac10e63b..ad5464ab99 100644
--- a/drivers/cdrom/gscd.c
+++ b/drivers/cdrom/gscd.c
@@ -146,7 +146,7 @@ static int AudioStart_f;
146static int AudioEnd_m; 146static int AudioEnd_m;
147static int AudioEnd_f; 147static int AudioEnd_f;
148 148
149static struct timer_list gscd_timer = TIMER_INITIALIZER(NULL, 0, 0); 149static DEFINE_TIMER(gscd_timer, NULL, 0, 0);
150static DEFINE_SPINLOCK(gscd_lock); 150static DEFINE_SPINLOCK(gscd_lock);
151static struct request_queue *gscd_queue; 151static struct request_queue *gscd_queue;
152 152
diff --git a/drivers/cdrom/optcd.c b/drivers/cdrom/optcd.c
index 351a01dd50..0b0eab4f40 100644
--- a/drivers/cdrom/optcd.c
+++ b/drivers/cdrom/optcd.c
@@ -264,7 +264,7 @@ static inline int flag_low(int flag, unsigned long timeout)
264static int sleep_timeout; /* max # of ticks to sleep */ 264static int sleep_timeout; /* max # of ticks to sleep */
265static DECLARE_WAIT_QUEUE_HEAD(waitq); 265static DECLARE_WAIT_QUEUE_HEAD(waitq);
266static void sleep_timer(unsigned long data); 266static void sleep_timer(unsigned long data);
267static struct timer_list delay_timer = TIMER_INITIALIZER(sleep_timer, 0, 0); 267static DEFINE_TIMER(delay_timer, sleep_timer, 0, 0);
268static DEFINE_SPINLOCK(optcd_lock); 268static DEFINE_SPINLOCK(optcd_lock);
269static struct request_queue *opt_queue; 269static struct request_queue *opt_queue;
270 270
diff --git a/drivers/cdrom/sbpcd.c b/drivers/cdrom/sbpcd.c
index 452d346751..466e9c2974 100644
--- a/drivers/cdrom/sbpcd.c
+++ b/drivers/cdrom/sbpcd.c
@@ -742,13 +742,10 @@ static struct sbpcd_drive *current_drive = D_S;
742unsigned long cli_sti; /* for saving the processor flags */ 742unsigned long cli_sti; /* for saving the processor flags */
743#endif 743#endif
744/*==========================================================================*/ 744/*==========================================================================*/
745static struct timer_list delay_timer = 745static DEFINE_TIMER(delay_timer, mark_timeout_delay, 0, 0);
746 TIMER_INITIALIZER(mark_timeout_delay, 0, 0); 746static DEFINE_TIMER(data_timer, mark_timeout_data, 0, 0);
747static struct timer_list data_timer =
748 TIMER_INITIALIZER(mark_timeout_data, 0, 0);
749#if 0 747#if 0
750static struct timer_list audio_timer = 748static DEFINE_TIMER(audio_timer, mark_timeout_audio, 0, 0);
751 TIMER_INITIALIZER(mark_timeout_audio, 0, 0);
752#endif 749#endif
753/*==========================================================================*/ 750/*==========================================================================*/
754/* 751/*
@@ -830,8 +827,7 @@ static void mark_timeout_audio(u_long i)
830static void sbp_sleep(u_int time) 827static void sbp_sleep(u_int time)
831{ 828{
832 sti(); 829 sti();
833 current->state = TASK_INTERRUPTIBLE; 830 schedule_timeout_interruptible(time);
834 schedule_timeout(time);
835 sti(); 831 sti();
836} 832}
837/*==========================================================================*/ 833/*==========================================================================*/
@@ -4219,7 +4215,8 @@ static int sbpcd_dev_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4219 4215
4220 case CDROMAUDIOBUFSIZ: /* configure the audio buffer size */ 4216 case CDROMAUDIOBUFSIZ: /* configure the audio buffer size */
4221 msg(DBG_IOC,"ioctl: CDROMAUDIOBUFSIZ entered.\n"); 4217 msg(DBG_IOC,"ioctl: CDROMAUDIOBUFSIZ entered.\n");
4222 if (current_drive->sbp_audsiz>0) vfree(current_drive->aud_buf); 4218 if (current_drive->sbp_audsiz>0)
4219 vfree(current_drive->aud_buf);
4223 current_drive->aud_buf=NULL; 4220 current_drive->aud_buf=NULL;
4224 current_drive->sbp_audsiz=arg; 4221 current_drive->sbp_audsiz=arg;
4225 4222
@@ -5913,7 +5910,8 @@ static void sbpcd_exit(void)
5913 put_disk(D_S[j].disk); 5910 put_disk(D_S[j].disk);
5914 devfs_remove("sbp/c0t%d", j); 5911 devfs_remove("sbp/c0t%d", j);
5915 vfree(D_S[j].sbp_buf); 5912 vfree(D_S[j].sbp_buf);
5916 if (D_S[j].sbp_audsiz>0) vfree(D_S[j].aud_buf); 5913 if (D_S[j].sbp_audsiz>0)
5914 vfree(D_S[j].aud_buf);
5917 if ((unregister_cdrom(D_S[j].sbpcd_infop) == -EINVAL)) 5915 if ((unregister_cdrom(D_S[j].sbpcd_infop) == -EINVAL))
5918 { 5916 {
5919 msg(DBG_INF, "What's that: can't unregister info %s.\n", major_name); 5917 msg(DBG_INF, "What's that: can't unregister info %s.\n", major_name);
diff --git a/drivers/cdrom/sjcd.c b/drivers/cdrom/sjcd.c
index 4e7a342ec3..74b1cadbf1 100644
--- a/drivers/cdrom/sjcd.c
+++ b/drivers/cdrom/sjcd.c
@@ -151,7 +151,7 @@ static struct sjcd_stat statistic;
151/* 151/*
152 * Timer. 152 * Timer.
153 */ 153 */
154static struct timer_list sjcd_delay_timer = TIMER_INITIALIZER(NULL, 0, 0); 154static DEFINE_TIMER(sjcd_delay_timer, NULL, 0, 0);
155 155
156#define SJCD_SET_TIMER( func, tmout ) \ 156#define SJCD_SET_TIMER( func, tmout ) \
157 ( sjcd_delay_timer.expires = jiffies+tmout, \ 157 ( sjcd_delay_timer.expires = jiffies+tmout, \
diff --git a/drivers/cdrom/sonycd535.c b/drivers/cdrom/sonycd535.c
index 9f22e8f1f6..e656599264 100644
--- a/drivers/cdrom/sonycd535.c
+++ b/drivers/cdrom/sonycd535.c
@@ -1478,8 +1478,7 @@ static int __init sony535_init(void)
1478 /* look for the CD-ROM, follows the procedure in the DOS driver */ 1478 /* look for the CD-ROM, follows the procedure in the DOS driver */
1479 inb(select_unit_reg); 1479 inb(select_unit_reg);
1480 /* wait for 40 18 Hz ticks (reverse-engineered from DOS driver) */ 1480 /* wait for 40 18 Hz ticks (reverse-engineered from DOS driver) */
1481 set_current_state(TASK_INTERRUPTIBLE); 1481 schedule_timeout_interruptible((HZ+17)*40/18);
1482 schedule_timeout((HZ+17)*40/18);
1483 inb(result_reg); 1482 inb(result_reg);
1484 1483
1485 outb(0, read_status_reg); /* does a reset? */ 1484 outb(0, read_status_reg); /* does a reset? */
diff --git a/drivers/char/agp/backend.c b/drivers/char/agp/backend.c
index 4d4e602fdc..82b43c541c 100644
--- a/drivers/char/agp/backend.c
+++ b/drivers/char/agp/backend.c
@@ -206,10 +206,9 @@ static void agp_backend_cleanup(struct agp_bridge_data *bridge)
206 bridge->driver->cleanup(); 206 bridge->driver->cleanup();
207 if (bridge->driver->free_gatt_table) 207 if (bridge->driver->free_gatt_table)
208 bridge->driver->free_gatt_table(bridge); 208 bridge->driver->free_gatt_table(bridge);
209 if (bridge->key_list) { 209
210 vfree(bridge->key_list); 210 vfree(bridge->key_list);
211 bridge->key_list = NULL; 211 bridge->key_list = NULL;
212 }
213 212
214 if (bridge->driver->agp_destroy_page && 213 if (bridge->driver->agp_destroy_page &&
215 bridge->driver->needs_scratch_page) 214 bridge->driver->needs_scratch_page)
diff --git a/drivers/char/applicom.c b/drivers/char/applicom.c
index 11f9ee5811..927a5bbe11 100644
--- a/drivers/char/applicom.c
+++ b/drivers/char/applicom.c
@@ -172,7 +172,7 @@ static int ac_register_board(unsigned long physloc, void __iomem *loc,
172 172
173void cleanup_module(void) 173void cleanup_module(void)
174{ 174{
175 int i; 175 unsigned int i;
176 176
177 misc_deregister(&ac_miscdev); 177 misc_deregister(&ac_miscdev);
178 178
@@ -195,7 +195,7 @@ int __init applicom_init(void)
195 int i, numisa = 0; 195 int i, numisa = 0;
196 struct pci_dev *dev = NULL; 196 struct pci_dev *dev = NULL;
197 void __iomem *RamIO; 197 void __iomem *RamIO;
198 int boardno; 198 int boardno, ret;
199 199
200 printk(KERN_INFO "Applicom driver: $Id: ac.c,v 1.30 2000/03/22 16:03:57 dwmw2 Exp $\n"); 200 printk(KERN_INFO "Applicom driver: $Id: ac.c,v 1.30 2000/03/22 16:03:57 dwmw2 Exp $\n");
201 201
@@ -294,7 +294,8 @@ int __init applicom_init(void)
294 } 294 }
295 295
296 if (!numisa) 296 if (!numisa)
297 printk(KERN_WARNING"ac.o: No valid ISA Applicom boards found at mem 0x%lx\n",mem); 297 printk(KERN_WARNING "ac.o: No valid ISA Applicom boards found "
298 "at mem 0x%lx\n", mem);
298 299
299 fin: 300 fin:
300 init_waitqueue_head(&FlagSleepRec); 301 init_waitqueue_head(&FlagSleepRec);
@@ -304,7 +305,11 @@ int __init applicom_init(void)
304 DeviceErrorCount = 0; 305 DeviceErrorCount = 0;
305 306
306 if (numboards) { 307 if (numboards) {
307 misc_register(&ac_miscdev); 308 ret = misc_register(&ac_miscdev);
309 if (ret) {
310 printk(KERN_WARNING "ac.o: Unable to register misc device\n");
311 goto out;
312 }
308 for (i = 0; i < MAX_BOARD; i++) { 313 for (i = 0; i < MAX_BOARD; i++) {
309 int serial; 314 int serial;
310 char boardname[(SERIAL_NUMBER - TYPE_CARD) + 1]; 315 char boardname[(SERIAL_NUMBER - TYPE_CARD) + 1];
@@ -337,6 +342,17 @@ int __init applicom_init(void)
337 342
338 else 343 else
339 return -ENXIO; 344 return -ENXIO;
345
346out:
347 for (i = 0; i < MAX_BOARD; i++) {
348 if (!apbs[i].RamIO)
349 continue;
350 if (apbs[i].irq)
351 free_irq(apbs[i].irq, &dummy);
352 iounmap(apbs[i].RamIO);
353 }
354 pci_disable_device(dev);
355 return ret;
340} 356}
341 357
342 358
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index 6a5337bf09..cf4c364846 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -865,7 +865,7 @@ static void cyz_poll(unsigned long);
865static long cyz_polling_cycle = CZ_DEF_POLL; 865static long cyz_polling_cycle = CZ_DEF_POLL;
866 866
867static int cyz_timeron = 0; 867static int cyz_timeron = 0;
868static struct timer_list cyz_timerlist = TIMER_INITIALIZER(cyz_poll, 0, 0); 868static DEFINE_TIMER(cyz_timerlist, cyz_poll, 0, 0);
869 869
870#else /* CONFIG_CYZ_INTR */ 870#else /* CONFIG_CYZ_INTR */
871static void cyz_rx_restart(unsigned long); 871static void cyz_rx_restart(unsigned long);
diff --git a/drivers/char/ftape/lowlevel/fdc-io.c b/drivers/char/ftape/lowlevel/fdc-io.c
index 1704a2a570..b2e0928e84 100644
--- a/drivers/char/ftape/lowlevel/fdc-io.c
+++ b/drivers/char/ftape/lowlevel/fdc-io.c
@@ -387,10 +387,8 @@ int fdc_interrupt_wait(unsigned int time)
387 387
388 set_current_state(TASK_INTERRUPTIBLE); 388 set_current_state(TASK_INTERRUPTIBLE);
389 add_wait_queue(&ftape_wait_intr, &wait); 389 add_wait_queue(&ftape_wait_intr, &wait);
390 while (!ft_interrupt_seen && timeout) { 390 while (!ft_interrupt_seen && timeout)
391 set_current_state(TASK_INTERRUPTIBLE); 391 timeout = schedule_timeout_interruptible(timeout);
392 timeout = schedule_timeout(timeout);
393 }
394 392
395 spin_lock_irq(&current->sighand->siglock); 393 spin_lock_irq(&current->sighand->siglock);
396 current->blocked = old_sigmask; 394 current->blocked = old_sigmask;
diff --git a/drivers/char/hangcheck-timer.c b/drivers/char/hangcheck-timer.c
index 81d811edf3..a54bc93353 100644
--- a/drivers/char/hangcheck-timer.c
+++ b/drivers/char/hangcheck-timer.c
@@ -149,8 +149,7 @@ static unsigned long long hangcheck_tsc, hangcheck_tsc_margin;
149 149
150static void hangcheck_fire(unsigned long); 150static void hangcheck_fire(unsigned long);
151 151
152static struct timer_list hangcheck_ticktock = 152static DEFINE_TIMER(hangcheck_ticktock, hangcheck_fire, 0, 0);
153 TIMER_INITIALIZER(hangcheck_fire, 0, 0);
154 153
155 154
156static void hangcheck_fire(unsigned long data) 155static void hangcheck_fire(unsigned long data)
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index 5fe8461271..de0379b6d5 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -100,14 +100,14 @@ static struct hpets *hpets;
100#endif 100#endif
101 101
102#ifndef readq 102#ifndef readq
103static unsigned long long __inline readq(void __iomem *addr) 103static inline unsigned long long readq(void __iomem *addr)
104{ 104{
105 return readl(addr) | (((unsigned long long)readl(addr + 4)) << 32LL); 105 return readl(addr) | (((unsigned long long)readl(addr + 4)) << 32LL);
106} 106}
107#endif 107#endif
108 108
109#ifndef writeq 109#ifndef writeq
110static void __inline writeq(unsigned long long v, void __iomem *addr) 110static inline void writeq(unsigned long long v, void __iomem *addr)
111{ 111{
112 writel(v & 0xffffffff, addr); 112 writel(v & 0xffffffff, addr);
113 writel(v >> 32, addr + 4); 113 writel(v >> 32, addr + 4);
diff --git a/drivers/char/hw_random.c b/drivers/char/hw_random.c
index 3480535a09..6f673d2de0 100644
--- a/drivers/char/hw_random.c
+++ b/drivers/char/hw_random.c
@@ -513,10 +513,7 @@ static ssize_t rng_dev_read (struct file *filp, char __user *buf, size_t size,
513 return ret ? : -EAGAIN; 513 return ret ? : -EAGAIN;
514 514
515 if(need_resched()) 515 if(need_resched())
516 { 516 schedule_timeout_interruptible(1);
517 current->state = TASK_INTERRUPTIBLE;
518 schedule_timeout(1);
519 }
520 else 517 else
521 udelay(200); /* FIXME: We could poll for 250uS ?? */ 518 udelay(200); /* FIXME: We could poll for 250uS ?? */
522 519
diff --git a/drivers/char/ip2/i2lib.c b/drivers/char/ip2/i2lib.c
index 82c5f30375..ba85eb1b6e 100644
--- a/drivers/char/ip2/i2lib.c
+++ b/drivers/char/ip2/i2lib.c
@@ -655,8 +655,7 @@ i2QueueCommands(int type, i2ChanStrPtr pCh, int timeout, int nCommands,
655 timeout--; // So negative values == forever 655 timeout--; // So negative values == forever
656 656
657 if (!in_interrupt()) { 657 if (!in_interrupt()) {
658 current->state = TASK_INTERRUPTIBLE; 658 schedule_timeout_interruptible(1); // short nap
659 schedule_timeout(1); // short nap
660 } else { 659 } else {
661 // we cannot sched/sleep in interrrupt silly 660 // we cannot sched/sleep in interrrupt silly
662 return 0; 661 return 0;
@@ -1132,8 +1131,7 @@ i2Output(i2ChanStrPtr pCh, const char *pSource, int count, int user )
1132 1131
1133 ip2trace (CHANN, ITRC_OUTPUT, 61, 0 ); 1132 ip2trace (CHANN, ITRC_OUTPUT, 61, 0 );
1134 1133
1135 current->state = TASK_INTERRUPTIBLE; 1134 schedule_timeout_interruptible(2);
1136 schedule_timeout(2);
1137 if (signal_pending(current)) { 1135 if (signal_pending(current)) {
1138 break; 1136 break;
1139 } 1137 }
diff --git a/drivers/char/ip2main.c b/drivers/char/ip2main.c
index 066d7b5cb7..9e4e26aef9 100644
--- a/drivers/char/ip2main.c
+++ b/drivers/char/ip2main.c
@@ -254,7 +254,7 @@ static unsigned long bh_counter = 0;
254 * selected, the board is serviced periodically to see if anything needs doing. 254 * selected, the board is serviced periodically to see if anything needs doing.
255 */ 255 */
256#define POLL_TIMEOUT (jiffies + 1) 256#define POLL_TIMEOUT (jiffies + 1)
257static struct timer_list PollTimer = TIMER_INITIALIZER(ip2_poll, 0, 0); 257static DEFINE_TIMER(PollTimer, ip2_poll, 0, 0);
258static char TimerOn; 258static char TimerOn;
259 259
260#ifdef IP2DEBUG_TRACE 260#ifdef IP2DEBUG_TRACE
diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
index 883ac4352b..a09ff10806 100644
--- a/drivers/char/ipmi/ipmi_devintf.c
+++ b/drivers/char/ipmi/ipmi_devintf.c
@@ -735,7 +735,8 @@ static long compat_ipmi_ioctl(struct file *filep, unsigned int cmd,
735 case COMPAT_IPMICTL_RECEIVE_MSG: 735 case COMPAT_IPMICTL_RECEIVE_MSG:
736 case COMPAT_IPMICTL_RECEIVE_MSG_TRUNC: 736 case COMPAT_IPMICTL_RECEIVE_MSG_TRUNC:
737 { 737 {
738 struct ipmi_recv *precv64, recv64; 738 struct ipmi_recv __user *precv64;
739 struct ipmi_recv recv64;
739 740
740 if (get_compat_ipmi_recv(&recv64, compat_ptr(arg))) 741 if (get_compat_ipmi_recv(&recv64, compat_ptr(arg)))
741 return -EFAULT; 742 return -EFAULT;
@@ -748,7 +749,7 @@ static long compat_ipmi_ioctl(struct file *filep, unsigned int cmd,
748 ((cmd == COMPAT_IPMICTL_RECEIVE_MSG) 749 ((cmd == COMPAT_IPMICTL_RECEIVE_MSG)
749 ? IPMICTL_RECEIVE_MSG 750 ? IPMICTL_RECEIVE_MSG
750 : IPMICTL_RECEIVE_MSG_TRUNC), 751 : IPMICTL_RECEIVE_MSG_TRUNC),
751 (long) precv64); 752 (unsigned long) precv64);
752 if (rc != 0) 753 if (rc != 0)
753 return rc; 754 return rc;
754 755
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 278f841049..b6e5cbfb09 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -1920,8 +1920,7 @@ static int try_get_dev_id(struct smi_info *smi_info)
1920 for (;;) 1920 for (;;)
1921 { 1921 {
1922 if (smi_result == SI_SM_CALL_WITH_DELAY) { 1922 if (smi_result == SI_SM_CALL_WITH_DELAY) {
1923 set_current_state(TASK_UNINTERRUPTIBLE); 1923 schedule_timeout_uninterruptible(1);
1924 schedule_timeout(1);
1925 smi_result = smi_info->handlers->event( 1924 smi_result = smi_info->handlers->event(
1926 smi_info->si_sm, 100); 1925 smi_info->si_sm, 100);
1927 } 1926 }
@@ -2256,10 +2255,8 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2256 2255
2257 /* Wait for the timer to stop. This avoids problems with race 2256 /* Wait for the timer to stop. This avoids problems with race
2258 conditions removing the timer here. */ 2257 conditions removing the timer here. */
2259 while (! new_smi->timer_stopped) { 2258 while (!new_smi->timer_stopped)
2260 set_current_state(TASK_UNINTERRUPTIBLE); 2259 schedule_timeout_uninterruptible(1);
2261 schedule_timeout(1);
2262 }
2263 2260
2264 out_err: 2261 out_err:
2265 if (new_smi->intf) 2262 if (new_smi->intf)
@@ -2379,17 +2376,14 @@ static void __exit cleanup_one_si(struct smi_info *to_clean)
2379 2376
2380 /* Wait for the timer to stop. This avoids problems with race 2377 /* Wait for the timer to stop. This avoids problems with race
2381 conditions removing the timer here. */ 2378 conditions removing the timer here. */
2382 while (! to_clean->timer_stopped) { 2379 while (!to_clean->timer_stopped)
2383 set_current_state(TASK_UNINTERRUPTIBLE); 2380 schedule_timeout_uninterruptible(1);
2384 schedule_timeout(1);
2385 }
2386 2381
2387 /* Interrupts and timeouts are stopped, now make sure the 2382 /* Interrupts and timeouts are stopped, now make sure the
2388 interface is in a clean state. */ 2383 interface is in a clean state. */
2389 while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) { 2384 while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) {
2390 poll(to_clean); 2385 poll(to_clean);
2391 set_current_state(TASK_UNINTERRUPTIBLE); 2386 schedule_timeout_uninterruptible(1);
2392 schedule_timeout(1);
2393 } 2387 }
2394 2388
2395 rv = ipmi_unregister_smi(to_clean->intf); 2389 rv = ipmi_unregister_smi(to_clean->intf);
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index e71aaae855..2da64bf746 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -1037,10 +1037,8 @@ static __exit void ipmi_unregister_watchdog(void)
1037 /* Wait to make sure the message makes it out. The lower layer has 1037 /* Wait to make sure the message makes it out. The lower layer has
1038 pointers to our buffers, we want to make sure they are done before 1038 pointers to our buffers, we want to make sure they are done before
1039 we release our memory. */ 1039 we release our memory. */
1040 while (atomic_read(&set_timeout_tofree)) { 1040 while (atomic_read(&set_timeout_tofree))
1041 set_current_state(TASK_UNINTERRUPTIBLE); 1041 schedule_timeout_uninterruptible(1);
1042 schedule_timeout(1);
1043 }
1044 1042
1045 /* Disconnect from IPMI. */ 1043 /* Disconnect from IPMI. */
1046 rv = ipmi_destroy_user(watchdog_user); 1044 rv = ipmi_destroy_user(watchdog_user);
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index 52a073eee2..9c19e5435a 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -780,7 +780,7 @@ static struct file_operations stli_fsiomem = {
780 * much cheaper on host cpu than using interrupts. It turns out to 780 * much cheaper on host cpu than using interrupts. It turns out to
781 * not increase character latency by much either... 781 * not increase character latency by much either...
782 */ 782 */
783static struct timer_list stli_timerlist = TIMER_INITIALIZER(stli_poll, 0, 0); 783static DEFINE_TIMER(stli_timerlist, stli_poll, 0, 0);
784 784
785static int stli_timeron; 785static int stli_timeron;
786 786
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index 523fd3c8bb..449d029ad4 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -14,7 +14,7 @@
14 * `Sticky' modifier keys, 951006. 14 * `Sticky' modifier keys, 951006.
15 * 15 *
16 * 11-11-96: SAK should now work in the raw mode (Martin Mares) 16 * 11-11-96: SAK should now work in the raw mode (Martin Mares)
17 * 17 *
18 * Modified to provide 'generic' keyboard support by Hamish Macdonald 18 * Modified to provide 'generic' keyboard support by Hamish Macdonald
19 * Merge with the m68k keyboard driver and split-off of the PC low-level 19 * Merge with the m68k keyboard driver and split-off of the PC low-level
20 * parts by Geert Uytterhoeven, May 1997 20 * parts by Geert Uytterhoeven, May 1997
@@ -52,7 +52,7 @@ extern void ctrl_alt_del(void);
52/* 52/*
53 * Some laptops take the 789uiojklm,. keys as number pad when NumLock is on. 53 * Some laptops take the 789uiojklm,. keys as number pad when NumLock is on.
54 * This seems a good reason to start with NumLock off. On HIL keyboards 54 * This seems a good reason to start with NumLock off. On HIL keyboards
55 * of PARISC machines however there is no NumLock key and everyone expects the keypad 55 * of PARISC machines however there is no NumLock key and everyone expects the keypad
56 * to be used for numbers. 56 * to be used for numbers.
57 */ 57 */
58 58
@@ -76,17 +76,17 @@ void compute_shiftstate(void);
76 k_meta, k_ascii, k_lock, k_lowercase,\ 76 k_meta, k_ascii, k_lock, k_lowercase,\
77 k_slock, k_dead2, k_ignore, k_ignore 77 k_slock, k_dead2, k_ignore, k_ignore
78 78
79typedef void (k_handler_fn)(struct vc_data *vc, unsigned char value, 79typedef void (k_handler_fn)(struct vc_data *vc, unsigned char value,
80 char up_flag, struct pt_regs *regs); 80 char up_flag, struct pt_regs *regs);
81static k_handler_fn K_HANDLERS; 81static k_handler_fn K_HANDLERS;
82static k_handler_fn *k_handler[16] = { K_HANDLERS }; 82static k_handler_fn *k_handler[16] = { K_HANDLERS };
83 83
84#define FN_HANDLERS\ 84#define FN_HANDLERS\
85 fn_null, fn_enter, fn_show_ptregs, fn_show_mem,\ 85 fn_null, fn_enter, fn_show_ptregs, fn_show_mem,\
86 fn_show_state, fn_send_intr, fn_lastcons, fn_caps_toggle,\ 86 fn_show_state, fn_send_intr, fn_lastcons, fn_caps_toggle,\
87 fn_num, fn_hold, fn_scroll_forw, fn_scroll_back,\ 87 fn_num, fn_hold, fn_scroll_forw, fn_scroll_back,\
88 fn_boot_it, fn_caps_on, fn_compose, fn_SAK,\ 88 fn_boot_it, fn_caps_on, fn_compose, fn_SAK,\
89 fn_dec_console, fn_inc_console, fn_spawn_con, fn_bare_num 89 fn_dec_console, fn_inc_console, fn_spawn_con, fn_bare_num
90 90
91typedef void (fn_handler_fn)(struct vc_data *vc, struct pt_regs *regs); 91typedef void (fn_handler_fn)(struct vc_data *vc, struct pt_regs *regs);
92static fn_handler_fn FN_HANDLERS; 92static fn_handler_fn FN_HANDLERS;
@@ -159,13 +159,13 @@ static int sysrq_alt;
159 */ 159 */
160int getkeycode(unsigned int scancode) 160int getkeycode(unsigned int scancode)
161{ 161{
162 struct list_head * node; 162 struct list_head *node;
163 struct input_dev *dev = NULL; 163 struct input_dev *dev = NULL;
164 164
165 list_for_each(node,&kbd_handler.h_list) { 165 list_for_each(node, &kbd_handler.h_list) {
166 struct input_handle * handle = to_handle_h(node); 166 struct input_handle *handle = to_handle_h(node);
167 if (handle->dev->keycodesize) { 167 if (handle->dev->keycodesize) {
168 dev = handle->dev; 168 dev = handle->dev;
169 break; 169 break;
170 } 170 }
171 } 171 }
@@ -181,15 +181,15 @@ int getkeycode(unsigned int scancode)
181 181
182int setkeycode(unsigned int scancode, unsigned int keycode) 182int setkeycode(unsigned int scancode, unsigned int keycode)
183{ 183{
184 struct list_head * node; 184 struct list_head *node;
185 struct input_dev *dev = NULL; 185 struct input_dev *dev = NULL;
186 unsigned int i, oldkey; 186 unsigned int i, oldkey;
187 187
188 list_for_each(node,&kbd_handler.h_list) { 188 list_for_each(node, &kbd_handler.h_list) {
189 struct input_handle *handle = to_handle_h(node); 189 struct input_handle *handle = to_handle_h(node);
190 if (handle->dev->keycodesize) { 190 if (handle->dev->keycodesize) {
191 dev = handle->dev; 191 dev = handle->dev;
192 break; 192 break;
193 } 193 }
194 } 194 }
195 195
@@ -200,7 +200,7 @@ int setkeycode(unsigned int scancode, unsigned int keycode)
200 return -EINVAL; 200 return -EINVAL;
201 if (keycode < 0 || keycode > KEY_MAX) 201 if (keycode < 0 || keycode > KEY_MAX)
202 return -EINVAL; 202 return -EINVAL;
203 if (keycode >> (dev->keycodesize * 8)) 203 if (dev->keycodesize < sizeof(keycode) && (keycode >> (dev->keycodesize * 8)))
204 return -EINVAL; 204 return -EINVAL;
205 205
206 oldkey = SET_INPUT_KEYCODE(dev, scancode, keycode); 206 oldkey = SET_INPUT_KEYCODE(dev, scancode, keycode);
@@ -216,11 +216,11 @@ int setkeycode(unsigned int scancode, unsigned int keycode)
216} 216}
217 217
218/* 218/*
219 * Making beeps and bells. 219 * Making beeps and bells.
220 */ 220 */
221static void kd_nosound(unsigned long ignored) 221static void kd_nosound(unsigned long ignored)
222{ 222{
223 struct list_head * node; 223 struct list_head *node;
224 224
225 list_for_each(node,&kbd_handler.h_list) { 225 list_for_each(node,&kbd_handler.h_list) {
226 struct input_handle *handle = to_handle_h(node); 226 struct input_handle *handle = to_handle_h(node);
@@ -233,17 +233,16 @@ static void kd_nosound(unsigned long ignored)
233 } 233 }
234} 234}
235 235
236static struct timer_list kd_mksound_timer = 236static DEFINE_TIMER(kd_mksound_timer, kd_nosound, 0, 0);
237 TIMER_INITIALIZER(kd_nosound, 0, 0);
238 237
239void kd_mksound(unsigned int hz, unsigned int ticks) 238void kd_mksound(unsigned int hz, unsigned int ticks)
240{ 239{
241 struct list_head * node; 240 struct list_head *node;
242 241
243 del_timer(&kd_mksound_timer); 242 del_timer(&kd_mksound_timer);
244 243
245 if (hz) { 244 if (hz) {
246 list_for_each_prev(node,&kbd_handler.h_list) { 245 list_for_each_prev(node, &kbd_handler.h_list) {
247 struct input_handle *handle = to_handle_h(node); 246 struct input_handle *handle = to_handle_h(node);
248 if (test_bit(EV_SND, handle->dev->evbit)) { 247 if (test_bit(EV_SND, handle->dev->evbit)) {
249 if (test_bit(SND_TONE, handle->dev->sndbit)) { 248 if (test_bit(SND_TONE, handle->dev->sndbit)) {
@@ -338,19 +337,19 @@ static void to_utf8(struct vc_data *vc, ushort c)
338 if (c < 0x80) 337 if (c < 0x80)
339 /* 0******* */ 338 /* 0******* */
340 put_queue(vc, c); 339 put_queue(vc, c);
341 else if (c < 0x800) { 340 else if (c < 0x800) {
342 /* 110***** 10****** */ 341 /* 110***** 10****** */
343 put_queue(vc, 0xc0 | (c >> 6)); 342 put_queue(vc, 0xc0 | (c >> 6));
344 put_queue(vc, 0x80 | (c & 0x3f)); 343 put_queue(vc, 0x80 | (c & 0x3f));
345 } else { 344 } else {
346 /* 1110**** 10****** 10****** */ 345 /* 1110**** 10****** 10****** */
347 put_queue(vc, 0xe0 | (c >> 12)); 346 put_queue(vc, 0xe0 | (c >> 12));
348 put_queue(vc, 0x80 | ((c >> 6) & 0x3f)); 347 put_queue(vc, 0x80 | ((c >> 6) & 0x3f));
349 put_queue(vc, 0x80 | (c & 0x3f)); 348 put_queue(vc, 0x80 | (c & 0x3f));
350 } 349 }
351} 350}
352 351
353/* 352/*
354 * Called after returning from RAW mode or when changing consoles - recompute 353 * Called after returning from RAW mode or when changing consoles - recompute
355 * shift_down[] and shift_state from key_down[] maybe called when keymap is 354 * shift_down[] and shift_state from key_down[] maybe called when keymap is
356 * undefined, so that shiftkey release is seen 355 * undefined, so that shiftkey release is seen
@@ -361,7 +360,7 @@ void compute_shiftstate(void)
361 360
362 shift_state = 0; 361 shift_state = 0;
363 memset(shift_down, 0, sizeof(shift_down)); 362 memset(shift_down, 0, sizeof(shift_down));
364 363
365 for (i = 0; i < ARRAY_SIZE(key_down); i++) { 364 for (i = 0; i < ARRAY_SIZE(key_down); i++) {
366 365
367 if (!key_down[i]) 366 if (!key_down[i])
@@ -500,9 +499,9 @@ static void fn_dec_console(struct vc_data *vc, struct pt_regs *regs)
500 if (want_console != -1) 499 if (want_console != -1)
501 cur = want_console; 500 cur = want_console;
502 501
503 for (i = cur-1; i != cur; i--) { 502 for (i = cur - 1; i != cur; i--) {
504 if (i == -1) 503 if (i == -1)
505 i = MAX_NR_CONSOLES-1; 504 i = MAX_NR_CONSOLES - 1;
506 if (vc_cons_allocated(i)) 505 if (vc_cons_allocated(i))
507 break; 506 break;
508 } 507 }
@@ -568,9 +567,9 @@ static void fn_compose(struct vc_data *vc, struct pt_regs *regs)
568 567
569static void fn_spawn_con(struct vc_data *vc, struct pt_regs *regs) 568static void fn_spawn_con(struct vc_data *vc, struct pt_regs *regs)
570{ 569{
571 if (spawnpid) 570 if (spawnpid)
572 if(kill_proc(spawnpid, spawnsig, 1)) 571 if (kill_proc(spawnpid, spawnsig, 1))
573 spawnpid = 0; 572 spawnpid = 0;
574} 573}
575 574
576static void fn_SAK(struct vc_data *vc, struct pt_regs *regs) 575static void fn_SAK(struct vc_data *vc, struct pt_regs *regs)
@@ -604,8 +603,8 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag, struct
604 return; 603 return;
605 if (value >= ARRAY_SIZE(fn_handler)) 604 if (value >= ARRAY_SIZE(fn_handler))
606 return; 605 return;
607 if ((kbd->kbdmode == VC_RAW || 606 if ((kbd->kbdmode == VC_RAW ||
608 kbd->kbdmode == VC_MEDIUMRAW) && 607 kbd->kbdmode == VC_MEDIUMRAW) &&
609 value != KVAL(K_SAK)) 608 value != KVAL(K_SAK))
610 return; /* SAK is allowed even in raw mode */ 609 return; /* SAK is allowed even in raw mode */
611 fn_handler[value](vc, regs); 610 fn_handler[value](vc, regs);
@@ -895,11 +894,11 @@ static inline unsigned char getleds(void)
895 894
896static void kbd_bh(unsigned long dummy) 895static void kbd_bh(unsigned long dummy)
897{ 896{
898 struct list_head * node; 897 struct list_head *node;
899 unsigned char leds = getleds(); 898 unsigned char leds = getleds();
900 899
901 if (leds != ledstate) { 900 if (leds != ledstate) {
902 list_for_each(node,&kbd_handler.h_list) { 901 list_for_each(node, &kbd_handler.h_list) {
903 struct input_handle * handle = to_handle_h(node); 902 struct input_handle * handle = to_handle_h(node);
904 input_event(handle->dev, EV_LED, LED_SCROLLL, !!(leds & 0x01)); 903 input_event(handle->dev, EV_LED, LED_SCROLLL, !!(leds & 0x01));
905 input_event(handle->dev, EV_LED, LED_NUML, !!(leds & 0x02)); 904 input_event(handle->dev, EV_LED, LED_NUML, !!(leds & 0x02));
@@ -964,11 +963,11 @@ static int sparc_l1_a_state = 0;
964extern void sun_do_break(void); 963extern void sun_do_break(void);
965#endif 964#endif
966 965
967static int emulate_raw(struct vc_data *vc, unsigned int keycode, 966static int emulate_raw(struct vc_data *vc, unsigned int keycode,
968 unsigned char up_flag) 967 unsigned char up_flag)
969{ 968{
970 if (keycode > 255 || !x86_keycodes[keycode]) 969 if (keycode > 255 || !x86_keycodes[keycode])
971 return -1; 970 return -1;
972 971
973 switch (keycode) { 972 switch (keycode) {
974 case KEY_PAUSE: 973 case KEY_PAUSE:
@@ -982,7 +981,7 @@ static int emulate_raw(struct vc_data *vc, unsigned int keycode,
982 case KEY_HANJA: 981 case KEY_HANJA:
983 if (!up_flag) put_queue(vc, 0xf2); 982 if (!up_flag) put_queue(vc, 0xf2);
984 return 0; 983 return 0;
985 } 984 }
986 985
987 if (keycode == KEY_SYSRQ && sysrq_alt) { 986 if (keycode == KEY_SYSRQ && sysrq_alt) {
988 put_queue(vc, 0x54 | up_flag); 987 put_queue(vc, 0x54 | up_flag);
@@ -1105,11 +1104,12 @@ static void kbd_keycode(unsigned int keycode, int down,
1105 else 1104 else
1106 clear_bit(keycode, key_down); 1105 clear_bit(keycode, key_down);
1107 1106
1108 if (rep && (!vc_kbd_mode(kbd, VC_REPEAT) || (tty && 1107 if (rep &&
1109 (!L_ECHO(tty) && tty->driver->chars_in_buffer(tty))))) { 1108 (!vc_kbd_mode(kbd, VC_REPEAT) ||
1109 (tty && !L_ECHO(tty) && tty->driver->chars_in_buffer(tty)))) {
1110 /* 1110 /*
1111 * Don't repeat a key if the input buffers are not empty and the 1111 * Don't repeat a key if the input buffers are not empty and the
1112 * characters get aren't echoed locally. This makes key repeat 1112 * characters get aren't echoed locally. This makes key repeat
1113 * usable with slow applications and under heavy loads. 1113 * usable with slow applications and under heavy loads.
1114 */ 1114 */
1115 return; 1115 return;
@@ -1131,7 +1131,8 @@ static void kbd_keycode(unsigned int keycode, int down,
1131 type = KTYP(keysym); 1131 type = KTYP(keysym);
1132 1132
1133 if (type < 0xf0) { 1133 if (type < 0xf0) {
1134 if (down && !raw_mode) to_utf8(vc, keysym); 1134 if (down && !raw_mode)
1135 to_utf8(vc, keysym);
1135 return; 1136 return;
1136 } 1137 }
1137 1138
@@ -1155,7 +1156,7 @@ static void kbd_keycode(unsigned int keycode, int down,
1155 kbd->slockstate = 0; 1156 kbd->slockstate = 0;
1156} 1157}
1157 1158
1158static void kbd_event(struct input_handle *handle, unsigned int event_type, 1159static void kbd_event(struct input_handle *handle, unsigned int event_type,
1159 unsigned int event_code, int value) 1160 unsigned int event_code, int value)
1160{ 1161{
1161 if (event_type == EV_MSC && event_code == MSC_RAW && HW_RAW(handle->dev)) 1162 if (event_type == EV_MSC && event_code == MSC_RAW && HW_RAW(handle->dev))
@@ -1167,15 +1168,13 @@ static void kbd_event(struct input_handle *handle, unsigned int event_type,
1167 schedule_console_callback(); 1168 schedule_console_callback();
1168} 1169}
1169 1170
1170static char kbd_name[] = "kbd";
1171
1172/* 1171/*
1173 * When a keyboard (or other input device) is found, the kbd_connect 1172 * When a keyboard (or other input device) is found, the kbd_connect
1174 * function is called. The function then looks at the device, and if it 1173 * function is called. The function then looks at the device, and if it
1175 * likes it, it can open it and get events from it. In this (kbd_connect) 1174 * likes it, it can open it and get events from it. In this (kbd_connect)
1176 * function, we should decide which VT to bind that keyboard to initially. 1175 * function, we should decide which VT to bind that keyboard to initially.
1177 */ 1176 */
1178static struct input_handle *kbd_connect(struct input_handler *handler, 1177static struct input_handle *kbd_connect(struct input_handler *handler,
1179 struct input_dev *dev, 1178 struct input_dev *dev,
1180 struct input_device_id *id) 1179 struct input_device_id *id)
1181{ 1180{
@@ -1183,18 +1182,19 @@ static struct input_handle *kbd_connect(struct input_handler *handler,
1183 int i; 1182 int i;
1184 1183
1185 for (i = KEY_RESERVED; i < BTN_MISC; i++) 1184 for (i = KEY_RESERVED; i < BTN_MISC; i++)
1186 if (test_bit(i, dev->keybit)) break; 1185 if (test_bit(i, dev->keybit))
1186 break;
1187 1187
1188 if ((i == BTN_MISC) && !test_bit(EV_SND, dev->evbit)) 1188 if (i == BTN_MISC && !test_bit(EV_SND, dev->evbit))
1189 return NULL; 1189 return NULL;
1190 1190
1191 if (!(handle = kmalloc(sizeof(struct input_handle), GFP_KERNEL))) 1191 if (!(handle = kmalloc(sizeof(struct input_handle), GFP_KERNEL)))
1192 return NULL; 1192 return NULL;
1193 memset(handle, 0, sizeof(struct input_handle)); 1193 memset(handle, 0, sizeof(struct input_handle));
1194 1194
1195 handle->dev = dev; 1195 handle->dev = dev;
1196 handle->handler = handler; 1196 handle->handler = handler;
1197 handle->name = kbd_name; 1197 handle->name = "kbd";
1198 1198
1199 input_open_device(handle); 1199 input_open_device(handle);
1200 kbd_refresh_leds(handle); 1200 kbd_refresh_leds(handle);
@@ -1213,11 +1213,11 @@ static struct input_device_id kbd_ids[] = {
1213 .flags = INPUT_DEVICE_ID_MATCH_EVBIT, 1213 .flags = INPUT_DEVICE_ID_MATCH_EVBIT,
1214 .evbit = { BIT(EV_KEY) }, 1214 .evbit = { BIT(EV_KEY) },
1215 }, 1215 },
1216 1216
1217 { 1217 {
1218 .flags = INPUT_DEVICE_ID_MATCH_EVBIT, 1218 .flags = INPUT_DEVICE_ID_MATCH_EVBIT,
1219 .evbit = { BIT(EV_SND) }, 1219 .evbit = { BIT(EV_SND) },
1220 }, 1220 },
1221 1221
1222 { }, /* Terminating entry */ 1222 { }, /* Terminating entry */
1223}; 1223};
diff --git a/drivers/char/lcd.c b/drivers/char/lcd.c
index cf01a720eb..b771611461 100644
--- a/drivers/char/lcd.c
+++ b/drivers/char/lcd.c
@@ -613,10 +613,15 @@ static struct miscdevice lcd_dev = {
613 613
614static int lcd_init(void) 614static int lcd_init(void)
615{ 615{
616 int ret;
616 unsigned long data; 617 unsigned long data;
617 618
618 pr_info("%s\n", LCD_DRIVER); 619 pr_info("%s\n", LCD_DRIVER);
619 misc_register(&lcd_dev); 620 ret = misc_register(&lcd_dev);
621 if (ret) {
622 printk(KERN_WARNING LCD "Unable to register misc device.\n");
623 return ret;
624 }
620 625
621 /* Check region? Naaah! Just snarf it up. */ 626 /* Check region? Naaah! Just snarf it up. */
622/* request_region(RTC_PORT(0), RTC_IO_EXTENT, "lcd");*/ 627/* request_region(RTC_PORT(0), RTC_IO_EXTENT, "lcd");*/
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index 59eebe5a03..2afb9038db 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -128,6 +128,7 @@
128#include <linux/console.h> 128#include <linux/console.h>
129#include <linux/device.h> 129#include <linux/device.h>
130#include <linux/wait.h> 130#include <linux/wait.h>
131#include <linux/jiffies.h>
131 132
132#include <linux/parport.h> 133#include <linux/parport.h>
133#undef LP_STATS 134#undef LP_STATS
@@ -307,7 +308,7 @@ static ssize_t lp_write(struct file * file, const char __user * buf,
307 (LP_F(minor) & LP_ABORT)); 308 (LP_F(minor) & LP_ABORT));
308 309
309#ifdef LP_STATS 310#ifdef LP_STATS
310 if (jiffies-lp_table[minor].lastcall > LP_TIME(minor)) 311 if (time_after(jiffies, lp_table[minor].lastcall + LP_TIME(minor)))
311 lp_table[minor].runchars = 0; 312 lp_table[minor].runchars = 0;
312 313
313 lp_table[minor].lastcall = jiffies; 314 lp_table[minor].lastcall = jiffies;
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index d0ef1ae412..45d012d85e 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -1058,8 +1058,7 @@ static void mxser_close(struct tty_struct *tty, struct file *filp)
1058 */ 1058 */
1059 timeout = jiffies + HZ; 1059 timeout = jiffies + HZ;
1060 while (!(inb(info->base + UART_LSR) & UART_LSR_TEMT)) { 1060 while (!(inb(info->base + UART_LSR) & UART_LSR_TEMT)) {
1061 set_current_state(TASK_INTERRUPTIBLE); 1061 schedule_timeout_interruptible(5);
1062 schedule_timeout(5);
1063 if (time_after(jiffies, timeout)) 1062 if (time_after(jiffies, timeout))
1064 break; 1063 break;
1065 } 1064 }
@@ -1080,10 +1079,8 @@ static void mxser_close(struct tty_struct *tty, struct file *filp)
1080 info->event = 0; 1079 info->event = 0;
1081 info->tty = NULL; 1080 info->tty = NULL;
1082 if (info->blocked_open) { 1081 if (info->blocked_open) {
1083 if (info->close_delay) { 1082 if (info->close_delay)
1084 set_current_state(TASK_INTERRUPTIBLE); 1083 schedule_timeout_interruptible(info->close_delay);
1085 schedule_timeout(info->close_delay);
1086 }
1087 wake_up_interruptible(&info->open_wait); 1084 wake_up_interruptible(&info->open_wait);
1088 } 1085 }
1089 1086
@@ -1801,8 +1798,7 @@ static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
1801#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT 1798#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1802 printk("lsr = %d (jiff=%lu)...", lsr, jiffies); 1799 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
1803#endif 1800#endif
1804 set_current_state(TASK_INTERRUPTIBLE); 1801 schedule_timeout_interruptible(char_time);
1805 schedule_timeout(char_time);
1806 if (signal_pending(current)) 1802 if (signal_pending(current))
1807 break; 1803 break;
1808 if (timeout && time_after(jiffies, orig_jiffies + timeout)) 1804 if (timeout && time_after(jiffies, orig_jiffies + timeout))
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index 09103b3d8f..c9bdf544ed 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -62,7 +62,7 @@
62 62
63static inline unsigned char *alloc_buf(void) 63static inline unsigned char *alloc_buf(void)
64{ 64{
65 int prio = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL; 65 unsigned int prio = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
66 66
67 if (PAGE_SIZE != N_TTY_BUF_SIZE) 67 if (PAGE_SIZE != N_TTY_BUF_SIZE)
68 return kmalloc(N_TTY_BUF_SIZE, prio); 68 return kmalloc(N_TTY_BUF_SIZE, prio);
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 7a0c746481..02d7f046c1 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * linux/drivers/char/pcmcia/synclink_cs.c 2 * linux/drivers/char/pcmcia/synclink_cs.c
3 * 3 *
4 * $Id: synclink_cs.c,v 4.26 2004/08/11 19:30:02 paulkf Exp $ 4 * $Id: synclink_cs.c,v 4.34 2005/09/08 13:20:54 paulkf Exp $
5 * 5 *
6 * Device driver for Microgate SyncLink PC Card 6 * Device driver for Microgate SyncLink PC Card
7 * multiprotocol serial adapter. 7 * multiprotocol serial adapter.
@@ -472,7 +472,7 @@ module_param_array(dosyncppp, int, NULL, 0);
472MODULE_LICENSE("GPL"); 472MODULE_LICENSE("GPL");
473 473
474static char *driver_name = "SyncLink PC Card driver"; 474static char *driver_name = "SyncLink PC Card driver";
475static char *driver_version = "$Revision: 4.26 $"; 475static char *driver_version = "$Revision: 4.34 $";
476 476
477static struct tty_driver *serial_driver; 477static struct tty_driver *serial_driver;
478 478
@@ -1457,6 +1457,8 @@ static int startup(MGSLPC_INFO * info)
1457 1457
1458 info->pending_bh = 0; 1458 info->pending_bh = 0;
1459 1459
1460 memset(&info->icount, 0, sizeof(info->icount));
1461
1460 init_timer(&info->tx_timer); 1462 init_timer(&info->tx_timer);
1461 info->tx_timer.data = (unsigned long)info; 1463 info->tx_timer.data = (unsigned long)info;
1462 info->tx_timer.function = tx_timeout; 1464 info->tx_timer.function = tx_timeout;
@@ -1946,9 +1948,13 @@ static int get_stats(MGSLPC_INFO * info, struct mgsl_icount __user *user_icount)
1946 int err; 1948 int err;
1947 if (debug_level >= DEBUG_LEVEL_INFO) 1949 if (debug_level >= DEBUG_LEVEL_INFO)
1948 printk("get_params(%s)\n", info->device_name); 1950 printk("get_params(%s)\n", info->device_name);
1949 COPY_TO_USER(err,user_icount, &info->icount, sizeof(struct mgsl_icount)); 1951 if (!user_icount) {
1950 if (err) 1952 memset(&info->icount, 0, sizeof(info->icount));
1951 return -EFAULT; 1953 } else {
1954 COPY_TO_USER(err, user_icount, &info->icount, sizeof(struct mgsl_icount));
1955 if (err)
1956 return -EFAULT;
1957 }
1952 return 0; 1958 return 0;
1953} 1959}
1954 1960
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index da32889d22..49f3997fd2 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -149,15 +149,14 @@ static int pty_write_room(struct tty_struct *tty)
149static int pty_chars_in_buffer(struct tty_struct *tty) 149static int pty_chars_in_buffer(struct tty_struct *tty)
150{ 150{
151 struct tty_struct *to = tty->link; 151 struct tty_struct *to = tty->link;
152 ssize_t (*chars_in_buffer)(struct tty_struct *);
153 int count; 152 int count;
154 153
155 /* We should get the line discipline lock for "tty->link" */ 154 /* We should get the line discipline lock for "tty->link" */
156 if (!to || !(chars_in_buffer = to->ldisc.chars_in_buffer)) 155 if (!to || !to->ldisc.chars_in_buffer)
157 return 0; 156 return 0;
158 157
159 /* The ldisc must report 0 if no characters available to be read */ 158 /* The ldisc must report 0 if no characters available to be read */
160 count = chars_in_buffer(to); 159 count = to->ldisc.chars_in_buffer(to);
161 160
162 if (tty->driver->subtype == PTY_TYPE_SLAVE) return count; 161 if (tty->driver->subtype == PTY_TYPE_SLAVE) return count;
163 162
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index 37c8bea8e2..ea2d54be48 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * linux/drivers/char/synclink.c 2 * linux/drivers/char/synclink.c
3 * 3 *
4 * $Id: synclink.c,v 4.28 2004/08/11 19:30:01 paulkf Exp $ 4 * $Id: synclink.c,v 4.37 2005/09/07 13:13:19 paulkf Exp $
5 * 5 *
6 * Device driver for Microgate SyncLink ISA and PCI 6 * Device driver for Microgate SyncLink ISA and PCI
7 * high speed multiprotocol serial adapters. 7 * high speed multiprotocol serial adapters.
@@ -141,9 +141,9 @@ static MGSL_PARAMS default_params = {
141typedef struct _DMABUFFERENTRY 141typedef struct _DMABUFFERENTRY
142{ 142{
143 u32 phys_addr; /* 32-bit flat physical address of data buffer */ 143 u32 phys_addr; /* 32-bit flat physical address of data buffer */
144 u16 count; /* buffer size/data count */ 144 volatile u16 count; /* buffer size/data count */
145 u16 status; /* Control/status field */ 145 volatile u16 status; /* Control/status field */
146 u16 rcc; /* character count field */ 146 volatile u16 rcc; /* character count field */
147 u16 reserved; /* padding required by 16C32 */ 147 u16 reserved; /* padding required by 16C32 */
148 u32 link; /* 32-bit flat link to next buffer entry */ 148 u32 link; /* 32-bit flat link to next buffer entry */
149 char *virt_addr; /* virtual address of data buffer */ 149 char *virt_addr; /* virtual address of data buffer */
@@ -896,7 +896,7 @@ module_param_array(txdmabufs, int, NULL, 0);
896module_param_array(txholdbufs, int, NULL, 0); 896module_param_array(txholdbufs, int, NULL, 0);
897 897
898static char *driver_name = "SyncLink serial driver"; 898static char *driver_name = "SyncLink serial driver";
899static char *driver_version = "$Revision: 4.28 $"; 899static char *driver_version = "$Revision: 4.37 $";
900 900
901static int synclink_init_one (struct pci_dev *dev, 901static int synclink_init_one (struct pci_dev *dev,
902 const struct pci_device_id *ent); 902 const struct pci_device_id *ent);
@@ -1814,6 +1814,8 @@ static int startup(struct mgsl_struct * info)
1814 1814
1815 info->pending_bh = 0; 1815 info->pending_bh = 0;
1816 1816
1817 memset(&info->icount, 0, sizeof(info->icount));
1818
1817 init_timer(&info->tx_timer); 1819 init_timer(&info->tx_timer);
1818 info->tx_timer.data = (unsigned long)info; 1820 info->tx_timer.data = (unsigned long)info;
1819 info->tx_timer.function = mgsl_tx_timeout; 1821 info->tx_timer.function = mgsl_tx_timeout;
@@ -2470,12 +2472,12 @@ static int mgsl_get_stats(struct mgsl_struct * info, struct mgsl_icount __user *
2470 printk("%s(%d):mgsl_get_params(%s)\n", 2472 printk("%s(%d):mgsl_get_params(%s)\n",
2471 __FILE__,__LINE__, info->device_name); 2473 __FILE__,__LINE__, info->device_name);
2472 2474
2473 COPY_TO_USER(err,user_icount, &info->icount, sizeof(struct mgsl_icount)); 2475 if (!user_icount) {
2474 if (err) { 2476 memset(&info->icount, 0, sizeof(info->icount));
2475 if ( debug_level >= DEBUG_LEVEL_INFO ) 2477 } else {
2476 printk( "%s(%d):mgsl_get_stats(%s) user buffer copy failed\n", 2478 COPY_TO_USER(err, user_icount, &info->icount, sizeof(struct mgsl_icount));
2477 __FILE__,__LINE__,info->device_name); 2479 if (err)
2478 return -EFAULT; 2480 return -EFAULT;
2479 } 2481 }
2480 2482
2481 return 0; 2483 return 0;
@@ -6149,6 +6151,11 @@ static void usc_set_async_mode( struct mgsl_struct *info )
6149 usc_OutReg(info, PCR, (u16)((usc_InReg(info, PCR) | BIT13) & ~BIT12)); 6151 usc_OutReg(info, PCR, (u16)((usc_InReg(info, PCR) | BIT13) & ~BIT12));
6150 } 6152 }
6151 6153
6154 if (info->params.loopback) {
6155 info->loopback_bits = 0x300;
6156 outw(0x0300, info->io_base + CCAR);
6157 }
6158
6152} /* end of usc_set_async_mode() */ 6159} /* end of usc_set_async_mode() */
6153 6160
6154/* usc_loopback_frame() 6161/* usc_loopback_frame()
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index 8982eafd0f..6fb165cf8a 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: synclinkmp.c,v 4.34 2005/03/04 15:07:10 paulkf Exp $ 2 * $Id: synclinkmp.c,v 4.38 2005/07/15 13:29:44 paulkf Exp $
3 * 3 *
4 * Device driver for Microgate SyncLink Multiport 4 * Device driver for Microgate SyncLink Multiport
5 * high speed multiprotocol serial adapter. 5 * high speed multiprotocol serial adapter.
@@ -486,7 +486,7 @@ module_param_array(maxframe, int, NULL, 0);
486module_param_array(dosyncppp, int, NULL, 0); 486module_param_array(dosyncppp, int, NULL, 0);
487 487
488static char *driver_name = "SyncLink MultiPort driver"; 488static char *driver_name = "SyncLink MultiPort driver";
489static char *driver_version = "$Revision: 4.34 $"; 489static char *driver_version = "$Revision: 4.38 $";
490 490
491static int synclinkmp_init_one(struct pci_dev *dev,const struct pci_device_id *ent); 491static int synclinkmp_init_one(struct pci_dev *dev,const struct pci_device_id *ent);
492static void synclinkmp_remove_one(struct pci_dev *dev); 492static void synclinkmp_remove_one(struct pci_dev *dev);
@@ -555,7 +555,6 @@ static int set_txidle(SLMP_INFO *info, int idle_mode);
555static int tx_enable(SLMP_INFO *info, int enable); 555static int tx_enable(SLMP_INFO *info, int enable);
556static int tx_abort(SLMP_INFO *info); 556static int tx_abort(SLMP_INFO *info);
557static int rx_enable(SLMP_INFO *info, int enable); 557static int rx_enable(SLMP_INFO *info, int enable);
558static int map_status(int signals);
559static int modem_input_wait(SLMP_INFO *info,int arg); 558static int modem_input_wait(SLMP_INFO *info,int arg);
560static int wait_mgsl_event(SLMP_INFO *info, int __user *mask_ptr); 559static int wait_mgsl_event(SLMP_INFO *info, int __user *mask_ptr);
561static int tiocmget(struct tty_struct *tty, struct file *file); 560static int tiocmget(struct tty_struct *tty, struct file *file);
@@ -644,7 +643,7 @@ static unsigned char tx_active_fifo_level = 16; // tx request FIFO activation le
644static unsigned char tx_negate_fifo_level = 32; // tx request FIFO negation level in bytes 643static unsigned char tx_negate_fifo_level = 32; // tx request FIFO negation level in bytes
645 644
646static u32 misc_ctrl_value = 0x007e4040; 645static u32 misc_ctrl_value = 0x007e4040;
647static u32 lcr1_brdr_value = 0x00800029; 646static u32 lcr1_brdr_value = 0x00800028;
648 647
649static u32 read_ahead_count = 8; 648static u32 read_ahead_count = 8;
650 649
@@ -2749,6 +2748,8 @@ static int startup(SLMP_INFO * info)
2749 2748
2750 info->pending_bh = 0; 2749 info->pending_bh = 0;
2751 2750
2751 memset(&info->icount, 0, sizeof(info->icount));
2752
2752 /* program hardware for current parameters */ 2753 /* program hardware for current parameters */
2753 reset_port(info); 2754 reset_port(info);
2754 2755
@@ -2952,12 +2953,12 @@ static int get_stats(SLMP_INFO * info, struct mgsl_icount __user *user_icount)
2952 printk("%s(%d):%s get_params()\n", 2953 printk("%s(%d):%s get_params()\n",
2953 __FILE__,__LINE__, info->device_name); 2954 __FILE__,__LINE__, info->device_name);
2954 2955
2955 COPY_TO_USER(err,user_icount, &info->icount, sizeof(struct mgsl_icount)); 2956 if (!user_icount) {
2956 if (err) { 2957 memset(&info->icount, 0, sizeof(info->icount));
2957 if ( debug_level >= DEBUG_LEVEL_INFO ) 2958 } else {
2958 printk( "%s(%d):%s get_stats() user buffer copy failed\n", 2959 COPY_TO_USER(err, user_icount, &info->icount, sizeof(struct mgsl_icount));
2959 __FILE__,__LINE__,info->device_name); 2960 if (err)
2960 return -EFAULT; 2961 return -EFAULT;
2961 } 2962 }
2962 2963
2963 return 0; 2964 return 0;
@@ -3108,16 +3109,6 @@ static int rx_enable(SLMP_INFO * info, int enable)
3108 return 0; 3109 return 0;
3109} 3110}
3110 3111
3111static int map_status(int signals)
3112{
3113 /* Map status bits to API event bits */
3114
3115 return ((signals & SerialSignal_DSR) ? MgslEvent_DsrActive : MgslEvent_DsrInactive) +
3116 ((signals & SerialSignal_CTS) ? MgslEvent_CtsActive : MgslEvent_CtsInactive) +
3117 ((signals & SerialSignal_DCD) ? MgslEvent_DcdActive : MgslEvent_DcdInactive) +
3118 ((signals & SerialSignal_RI) ? MgslEvent_RiActive : MgslEvent_RiInactive);
3119}
3120
3121/* wait for specified event to occur 3112/* wait for specified event to occur
3122 */ 3113 */
3123static int wait_mgsl_event(SLMP_INFO * info, int __user *mask_ptr) 3114static int wait_mgsl_event(SLMP_INFO * info, int __user *mask_ptr)
@@ -3144,7 +3135,7 @@ static int wait_mgsl_event(SLMP_INFO * info, int __user *mask_ptr)
3144 3135
3145 /* return immediately if state matches requested events */ 3136 /* return immediately if state matches requested events */
3146 get_signals(info); 3137 get_signals(info);
3147 s = map_status(info->serial_signals); 3138 s = info->serial_signals;
3148 3139
3149 events = mask & 3140 events = mask &
3150 ( ((s & SerialSignal_DSR) ? MgslEvent_DsrActive:MgslEvent_DsrInactive) + 3141 ( ((s & SerialSignal_DSR) ? MgslEvent_DsrActive:MgslEvent_DsrInactive) +
@@ -4488,11 +4479,13 @@ void async_mode(SLMP_INFO *info)
4488 /* MD2, Mode Register 2 4479 /* MD2, Mode Register 2
4489 * 4480 *
4490 * 07..02 Reserved, must be 0 4481 * 07..02 Reserved, must be 0
4491 * 01..00 CNCT<1..0> Channel connection, 0=normal 4482 * 01..00 CNCT<1..0> Channel connection, 00=normal 11=local loopback
4492 * 4483 *
4493 * 0000 0000 4484 * 0000 0000
4494 */ 4485 */
4495 RegValue = 0x00; 4486 RegValue = 0x00;
4487 if (info->params.loopback)
4488 RegValue |= (BIT1 + BIT0);
4496 write_reg(info, MD2, RegValue); 4489 write_reg(info, MD2, RegValue);
4497 4490
4498 /* RXS, Receive clock source 4491 /* RXS, Receive clock source
@@ -4573,9 +4566,6 @@ void async_mode(SLMP_INFO *info)
4573 write_reg(info, IE2, info->ie2_value); 4566 write_reg(info, IE2, info->ie2_value);
4574 4567
4575 set_rate( info, info->params.data_rate * 16 ); 4568 set_rate( info, info->params.data_rate * 16 );
4576
4577 if (info->params.loopback)
4578 enable_loopback(info,1);
4579} 4569}
4580 4570
4581/* Program the SCA for HDLC communications. 4571/* Program the SCA for HDLC communications.
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 9d657127f3..e5953f3433 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -469,21 +469,19 @@ static void tty_ldisc_enable(struct tty_struct *tty)
469 469
470static int tty_set_ldisc(struct tty_struct *tty, int ldisc) 470static int tty_set_ldisc(struct tty_struct *tty, int ldisc)
471{ 471{
472 int retval = 0; 472 int retval = 0;
473 struct tty_ldisc o_ldisc; 473 struct tty_ldisc o_ldisc;
474 char buf[64]; 474 char buf[64];
475 int work; 475 int work;
476 unsigned long flags; 476 unsigned long flags;
477 struct tty_ldisc *ld; 477 struct tty_ldisc *ld;
478 struct tty_struct *o_tty;
478 479
479 if ((ldisc < N_TTY) || (ldisc >= NR_LDISCS)) 480 if ((ldisc < N_TTY) || (ldisc >= NR_LDISCS))
480 return -EINVAL; 481 return -EINVAL;
481 482
482restart: 483restart:
483 484
484 if (tty->ldisc.num == ldisc)
485 return 0; /* We are already in the desired discipline */
486
487 ld = tty_ldisc_get(ldisc); 485 ld = tty_ldisc_get(ldisc);
488 /* Eduardo Blanco <ejbs@cs.cs.com.uy> */ 486 /* Eduardo Blanco <ejbs@cs.cs.com.uy> */
489 /* Cyrus Durgin <cider@speakeasy.org> */ 487 /* Cyrus Durgin <cider@speakeasy.org> */
@@ -494,45 +492,74 @@ restart:
494 if (ld == NULL) 492 if (ld == NULL)
495 return -EINVAL; 493 return -EINVAL;
496 494
497 o_ldisc = tty->ldisc;
498
499 tty_wait_until_sent(tty, 0); 495 tty_wait_until_sent(tty, 0);
500 496
497 if (tty->ldisc.num == ldisc) {
498 tty_ldisc_put(ldisc);
499 return 0;
500 }
501
502 o_ldisc = tty->ldisc;
503 o_tty = tty->link;
504
501 /* 505 /*
502 * Make sure we don't change while someone holds a 506 * Make sure we don't change while someone holds a
503 * reference to the line discipline. The TTY_LDISC bit 507 * reference to the line discipline. The TTY_LDISC bit
504 * prevents anyone taking a reference once it is clear. 508 * prevents anyone taking a reference once it is clear.
505 * We need the lock to avoid racing reference takers. 509 * We need the lock to avoid racing reference takers.
506 */ 510 */
507 511
508 spin_lock_irqsave(&tty_ldisc_lock, flags); 512 spin_lock_irqsave(&tty_ldisc_lock, flags);
509 if(tty->ldisc.refcount) 513 if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) {
510 { 514 if(tty->ldisc.refcount) {
511 /* Free the new ldisc we grabbed. Must drop the lock 515 /* Free the new ldisc we grabbed. Must drop the lock
512 first. */ 516 first. */
517 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
518 tty_ldisc_put(ldisc);
519 /*
520 * There are several reasons we may be busy, including
521 * random momentary I/O traffic. We must therefore
522 * retry. We could distinguish between blocking ops
523 * and retries if we made tty_ldisc_wait() smarter. That
524 * is up for discussion.
525 */
526 if (wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0)
527 return -ERESTARTSYS;
528 goto restart;
529 }
530 if(o_tty && o_tty->ldisc.refcount) {
531 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
532 tty_ldisc_put(ldisc);
533 if (wait_event_interruptible(tty_ldisc_wait, o_tty->ldisc.refcount == 0) < 0)
534 return -ERESTARTSYS;
535 goto restart;
536 }
537 }
538
539 /* if the TTY_LDISC bit is set, then we are racing against another ldisc change */
540
541 if (!test_bit(TTY_LDISC, &tty->flags)) {
513 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 542 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
514 tty_ldisc_put(ldisc); 543 tty_ldisc_put(ldisc);
515 /* 544 ld = tty_ldisc_ref_wait(tty);
516 * There are several reasons we may be busy, including 545 tty_ldisc_deref(ld);
517 * random momentary I/O traffic. We must therefore
518 * retry. We could distinguish between blocking ops
519 * and retries if we made tty_ldisc_wait() smarter. That
520 * is up for discussion.
521 */
522 if(wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0)
523 return -ERESTARTSYS;
524 goto restart; 546 goto restart;
525 } 547 }
526 clear_bit(TTY_LDISC, &tty->flags); 548
549 clear_bit(TTY_LDISC, &tty->flags);
527 clear_bit(TTY_DONT_FLIP, &tty->flags); 550 clear_bit(TTY_DONT_FLIP, &tty->flags);
551 if (o_tty) {
552 clear_bit(TTY_LDISC, &o_tty->flags);
553 clear_bit(TTY_DONT_FLIP, &o_tty->flags);
554 }
528 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 555 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
529 556
530 /* 557 /*
531 * From this point on we know nobody has an ldisc 558 * From this point on we know nobody has an ldisc
532 * usage reference, nor can they obtain one until 559 * usage reference, nor can they obtain one until
533 * we say so later on. 560 * we say so later on.
534 */ 561 */
535 562
536 work = cancel_delayed_work(&tty->flip.work); 563 work = cancel_delayed_work(&tty->flip.work);
537 /* 564 /*
538 * Wait for ->hangup_work and ->flip.work handlers to terminate 565 * Wait for ->hangup_work and ->flip.work handlers to terminate
@@ -583,10 +610,12 @@ restart:
583 */ 610 */
584 611
585 tty_ldisc_enable(tty); 612 tty_ldisc_enable(tty);
613 if (o_tty)
614 tty_ldisc_enable(o_tty);
586 615
587 /* Restart it in case no characters kick it off. Safe if 616 /* Restart it in case no characters kick it off. Safe if
588 already running */ 617 already running */
589 if(work) 618 if (work)
590 schedule_delayed_work(&tty->flip.work, 1); 619 schedule_delayed_work(&tty->flip.work, 1);
591 return retval; 620 return retval;
592} 621}
@@ -2425,6 +2454,7 @@ static void __do_SAK(void *arg)
2425 int i; 2454 int i;
2426 struct file *filp; 2455 struct file *filp;
2427 struct tty_ldisc *disc; 2456 struct tty_ldisc *disc;
2457 struct fdtable *fdt;
2428 2458
2429 if (!tty) 2459 if (!tty)
2430 return; 2460 return;
@@ -2450,8 +2480,9 @@ static void __do_SAK(void *arg)
2450 } 2480 }
2451 task_lock(p); 2481 task_lock(p);
2452 if (p->files) { 2482 if (p->files) {
2453 spin_lock(&p->files->file_lock); 2483 rcu_read_lock();
2454 for (i=0; i < p->files->max_fds; i++) { 2484 fdt = files_fdtable(p->files);
2485 for (i=0; i < fdt->max_fds; i++) {
2455 filp = fcheck_files(p->files, i); 2486 filp = fcheck_files(p->files, i);
2456 if (!filp) 2487 if (!filp)
2457 continue; 2488 continue;
@@ -2464,7 +2495,7 @@ static void __do_SAK(void *arg)
2464 break; 2495 break;
2465 } 2496 }
2466 } 2497 }
2467 spin_unlock(&p->files->file_lock); 2498 rcu_read_unlock();
2468 } 2499 }
2469 task_unlock(p); 2500 task_unlock(p);
2470 } while_each_task_pid(session, PIDTYPE_SID, p); 2501 } while_each_task_pid(session, PIDTYPE_SID, p);
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index b8d0c290b0..1e33cb032e 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -751,6 +751,7 @@ int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines)
751 unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0; 751 unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0;
752 unsigned int old_cols, old_rows, old_row_size, old_screen_size; 752 unsigned int old_cols, old_rows, old_row_size, old_screen_size;
753 unsigned int new_cols, new_rows, new_row_size, new_screen_size; 753 unsigned int new_cols, new_rows, new_row_size, new_screen_size;
754 unsigned int end;
754 unsigned short *newscreen; 755 unsigned short *newscreen;
755 756
756 WARN_CONSOLE_UNLOCKED(); 757 WARN_CONSOLE_UNLOCKED();
@@ -794,20 +795,44 @@ int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines)
794 old_origin = vc->vc_origin; 795 old_origin = vc->vc_origin;
795 new_origin = (long) newscreen; 796 new_origin = (long) newscreen;
796 new_scr_end = new_origin + new_screen_size; 797 new_scr_end = new_origin + new_screen_size;
797 if (new_rows < old_rows) 798
798 old_origin += (old_rows - new_rows) * old_row_size; 799 if (vc->vc_y > new_rows) {
800 if (old_rows - vc->vc_y < new_rows) {
801 /*
802 * Cursor near the bottom, copy contents from the
803 * bottom of buffer
804 */
805 old_origin += (old_rows - new_rows) * old_row_size;
806 end = vc->vc_scr_end;
807 } else {
808 /*
809 * Cursor is in no man's land, copy 1/2 screenful
810 * from the top and bottom of cursor position
811 */
812 old_origin += (vc->vc_y - new_rows/2) * old_row_size;
813 end = old_origin + new_screen_size;
814 }
815 } else
816 /*
817 * Cursor near the top, copy contents from the top of buffer
818 */
819 end = (old_rows > new_rows) ? old_origin + new_screen_size :
820 vc->vc_scr_end;
799 821
800 update_attr(vc); 822 update_attr(vc);
801 823
802 while (old_origin < vc->vc_scr_end) { 824 while (old_origin < end) {
803 scr_memcpyw((unsigned short *) new_origin, (unsigned short *) old_origin, rlth); 825 scr_memcpyw((unsigned short *) new_origin,
826 (unsigned short *) old_origin, rlth);
804 if (rrem) 827 if (rrem)
805 scr_memsetw((void *)(new_origin + rlth), vc->vc_video_erase_char, rrem); 828 scr_memsetw((void *)(new_origin + rlth),
829 vc->vc_video_erase_char, rrem);
806 old_origin += old_row_size; 830 old_origin += old_row_size;
807 new_origin += new_row_size; 831 new_origin += new_row_size;
808 } 832 }
809 if (new_scr_end > new_origin) 833 if (new_scr_end > new_origin)
810 scr_memsetw((void *)new_origin, vc->vc_video_erase_char, new_scr_end - new_origin); 834 scr_memsetw((void *)new_origin, vc->vc_video_erase_char,
835 new_scr_end - new_origin);
811 if (vc->vc_kmalloced) 836 if (vc->vc_kmalloced)
812 kfree(vc->vc_screenbuf); 837 kfree(vc->vc_screenbuf);
813 vc->vc_screenbuf = newscreen; 838 vc->vc_screenbuf = newscreen;
diff --git a/drivers/char/watchdog/mixcomwd.c b/drivers/char/watchdog/mixcomwd.c
index c9b301dcce..7fc2188386 100644
--- a/drivers/char/watchdog/mixcomwd.c
+++ b/drivers/char/watchdog/mixcomwd.c
@@ -59,7 +59,7 @@ static unsigned long mixcomwd_opened; /* long req'd for setbit --RR */
59 59
60static int watchdog_port; 60static int watchdog_port;
61static int mixcomwd_timer_alive; 61static int mixcomwd_timer_alive;
62static struct timer_list mixcomwd_timer = TIMER_INITIALIZER(NULL, 0, 0); 62static DEFINE_TIMER(mixcomwd_timer, NULL, 0, 0);
63static char expect_close; 63static char expect_close;
64 64
65static int nowayout = WATCHDOG_NOWAYOUT; 65static int nowayout = WATCHDOG_NOWAYOUT;
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index f174aee659..9e9cf14073 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -560,7 +560,7 @@ ide_startstop_t __ide_abort(ide_drive_t *drive, struct request *rq)
560EXPORT_SYMBOL_GPL(__ide_abort); 560EXPORT_SYMBOL_GPL(__ide_abort);
561 561
562/** 562/**
563 * ide_abort - abort pending IDE operatins 563 * ide_abort - abort pending IDE operations
564 * @drive: drive the error occurred on 564 * @drive: drive the error occurred on
565 * @msg: message to report 565 * @msg: message to report
566 * 566 *
@@ -623,7 +623,7 @@ static void ide_cmd (ide_drive_t *drive, u8 cmd, u8 nsect,
623 * @drive: drive the completion interrupt occurred on 623 * @drive: drive the completion interrupt occurred on
624 * 624 *
625 * drive_cmd_intr() is invoked on completion of a special DRIVE_CMD. 625 * drive_cmd_intr() is invoked on completion of a special DRIVE_CMD.
626 * We do any necessary daya reading and then wait for the drive to 626 * We do any necessary data reading and then wait for the drive to
627 * go non busy. At that point we may read the error data and complete 627 * go non busy. At that point we may read the error data and complete
628 * the request 628 * the request
629 */ 629 */
@@ -773,7 +773,7 @@ EXPORT_SYMBOL_GPL(ide_init_sg_cmd);
773 773
774/** 774/**
775 * execute_drive_command - issue special drive command 775 * execute_drive_command - issue special drive command
776 * @drive: the drive to issue th command on 776 * @drive: the drive to issue the command on
777 * @rq: the request structure holding the command 777 * @rq: the request structure holding the command
778 * 778 *
779 * execute_drive_cmd() issues a special drive command, usually 779 * execute_drive_cmd() issues a special drive command, usually
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 5a3dc46008..ee38e6b143 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -2903,8 +2903,7 @@ static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
2903 } else if (!(tape->sense_key == 2 && tape->asc == 4 && 2903 } else if (!(tape->sense_key == 2 && tape->asc == 4 &&
2904 (tape->ascq == 1 || tape->ascq == 8))) 2904 (tape->ascq == 1 || tape->ascq == 8)))
2905 return -EIO; 2905 return -EIO;
2906 current->state = TASK_INTERRUPTIBLE; 2906 msleep(100);
2907 schedule_timeout(HZ / 10);
2908 } 2907 }
2909 return -EIO; 2908 return -EIO;
2910} 2909}
diff --git a/drivers/ide/ide-timing.h b/drivers/ide/ide-timing.h
index c1196ce15b..2fcfac6e96 100644
--- a/drivers/ide/ide-timing.h
+++ b/drivers/ide/ide-timing.h
@@ -27,6 +27,7 @@
27 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic 27 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
28 */ 28 */
29 29
30#include <linux/kernel.h>
30#include <linux/hdreg.h> 31#include <linux/hdreg.h>
31 32
32#define XFER_PIO_5 0x0d 33#define XFER_PIO_5 0x0d
@@ -96,11 +97,9 @@ static struct ide_timing ide_timing[] = {
96#define IDE_TIMING_UDMA 0x80 97#define IDE_TIMING_UDMA 0x80
97#define IDE_TIMING_ALL 0xff 98#define IDE_TIMING_ALL 0xff
98 99
99#define MIN(a,b) ((a)<(b)?(a):(b)) 100#define FIT(v,vmin,vmax) max_t(short,min_t(short,v,vmax),vmin)
100#define MAX(a,b) ((a)>(b)?(a):(b)) 101#define ENOUGH(v,unit) (((v)-1)/(unit)+1)
101#define FIT(v,min,max) MAX(MIN(v,max),min) 102#define EZ(v,unit) ((v)?ENOUGH(v,unit):0)
102#define ENOUGH(v,unit) (((v)-1)/(unit)+1)
103#define EZ(v,unit) ((v)?ENOUGH(v,unit):0)
104 103
105#define XFER_MODE 0xf0 104#define XFER_MODE 0xf0
106#define XFER_UDMA_133 0x48 105#define XFER_UDMA_133 0x48
@@ -188,14 +187,14 @@ static void ide_timing_quantize(struct ide_timing *t, struct ide_timing *q, int
188 187
189static void ide_timing_merge(struct ide_timing *a, struct ide_timing *b, struct ide_timing *m, unsigned int what) 188static void ide_timing_merge(struct ide_timing *a, struct ide_timing *b, struct ide_timing *m, unsigned int what)
190{ 189{
191 if (what & IDE_TIMING_SETUP ) m->setup = MAX(a->setup, b->setup); 190 if (what & IDE_TIMING_SETUP ) m->setup = max(a->setup, b->setup);
192 if (what & IDE_TIMING_ACT8B ) m->act8b = MAX(a->act8b, b->act8b); 191 if (what & IDE_TIMING_ACT8B ) m->act8b = max(a->act8b, b->act8b);
193 if (what & IDE_TIMING_REC8B ) m->rec8b = MAX(a->rec8b, b->rec8b); 192 if (what & IDE_TIMING_REC8B ) m->rec8b = max(a->rec8b, b->rec8b);
194 if (what & IDE_TIMING_CYC8B ) m->cyc8b = MAX(a->cyc8b, b->cyc8b); 193 if (what & IDE_TIMING_CYC8B ) m->cyc8b = max(a->cyc8b, b->cyc8b);
195 if (what & IDE_TIMING_ACTIVE ) m->active = MAX(a->active, b->active); 194 if (what & IDE_TIMING_ACTIVE ) m->active = max(a->active, b->active);
196 if (what & IDE_TIMING_RECOVER) m->recover = MAX(a->recover, b->recover); 195 if (what & IDE_TIMING_RECOVER) m->recover = max(a->recover, b->recover);
197 if (what & IDE_TIMING_CYCLE ) m->cycle = MAX(a->cycle, b->cycle); 196 if (what & IDE_TIMING_CYCLE ) m->cycle = max(a->cycle, b->cycle);
198 if (what & IDE_TIMING_UDMA ) m->udma = MAX(a->udma, b->udma); 197 if (what & IDE_TIMING_UDMA ) m->udma = max(a->udma, b->udma);
199} 198}
200 199
201static struct ide_timing* ide_timing_find_mode(short speed) 200static struct ide_timing* ide_timing_find_mode(short speed)
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index f1d1ec4e96..0ccf85fcee 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -43,6 +43,7 @@
43#include <linux/ide.h> 43#include <linux/ide.h>
44#include <linux/hdreg.h> 44#include <linux/hdreg.h>
45#include <linux/major.h> 45#include <linux/major.h>
46#include <linux/delay.h>
46#include <asm/io.h> 47#include <asm/io.h>
47#include <asm/system.h> 48#include <asm/system.h>
48 49
@@ -340,8 +341,7 @@ static void ide_config(dev_link_t *link)
340 break; 341 break;
341 } 342 }
342 } 343 }
343 __set_current_state(TASK_UNINTERRUPTIBLE); 344 msleep(100);
344 schedule_timeout(HZ/10);
345 } 345 }
346 346
347 if (hd < 0) { 347 if (hd < 0) {
@@ -454,9 +454,12 @@ int ide_event(event_t event, int priority,
454static struct pcmcia_device_id ide_ids[] = { 454static struct pcmcia_device_id ide_ids[] = {
455 PCMCIA_DEVICE_FUNC_ID(4), 455 PCMCIA_DEVICE_FUNC_ID(4),
456 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704), 456 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704),
457 PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401),
458 PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000), /* Toshiba */
457 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d), 459 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d),
460 PCMCIA_DEVICE_MANF_CARD(0x00ce, 0x0000), /* Samsung */
458 PCMCIA_DEVICE_MANF_CARD(0x2080, 0x0001), 461 PCMCIA_DEVICE_MANF_CARD(0x2080, 0x0001),
459 PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401), 462 PCMCIA_DEVICE_MANF_CARD(0x4e01, 0x0200), /* Lexar */
460 PCMCIA_DEVICE_PROD_ID123("Caravelle", "PSC-IDE ", "PSC000", 0x8c36137c, 0xd0693ab8, 0x2768a9f0), 463 PCMCIA_DEVICE_PROD_ID123("Caravelle", "PSC-IDE ", "PSC000", 0x8c36137c, 0xd0693ab8, 0x2768a9f0),
461 PCMCIA_DEVICE_PROD_ID123("CDROM", "IDE", "MCD-601p", 0x1b9179ca, 0xede88951, 0x0d902f74), 464 PCMCIA_DEVICE_PROD_ID123("CDROM", "IDE", "MCD-601p", 0x1b9179ca, 0xede88951, 0x0d902f74),
462 PCMCIA_DEVICE_PROD_ID123("PCMCIA", "IDE CARD", "F1", 0x281f1c5d, 0x1907960c, 0xf7fde8b9), 465 PCMCIA_DEVICE_PROD_ID123("PCMCIA", "IDE CARD", "F1", 0x281f1c5d, 0x1907960c, 0xf7fde8b9),
@@ -481,6 +484,7 @@ static struct pcmcia_device_id ide_ids[] = {
481 PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "MK2001MPL", 0xb4585a1a, 0x3489e003), 484 PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "MK2001MPL", 0xb4585a1a, 0x3489e003),
482 PCMCIA_DEVICE_PROD_ID12("WIT", "IDE16", 0x244e5994, 0x3e232852), 485 PCMCIA_DEVICE_PROD_ID12("WIT", "IDE16", 0x244e5994, 0x3e232852),
483 PCMCIA_DEVICE_PROD_ID1("STI Flash", 0xe4a13209), 486 PCMCIA_DEVICE_PROD_ID1("STI Flash", 0xe4a13209),
487 PCMCIA_DEVICE_PROD_ID12("STI", "Flash 5.0", 0xbf2df18d, 0x8cb57a0e),
484 PCMCIA_MFC_DEVICE_PROD_ID12(1, "SanDisk", "ConnectPlus", 0x7a954bd9, 0x74be00c6), 488 PCMCIA_MFC_DEVICE_PROD_ID12(1, "SanDisk", "ConnectPlus", 0x7a954bd9, 0x74be00c6),
485 PCMCIA_DEVICE_NULL, 489 PCMCIA_DEVICE_NULL,
486}; 490};
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index 7b64db10d1..127619a109 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -1334,9 +1334,13 @@ static int __devinit init_hpt366(struct pci_dev *dev)
1334static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name) 1334static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name)
1335{ 1335{
1336 int ret = 0; 1336 int ret = 0;
1337 /* FIXME: Not portable */ 1337
1338 /*
1339 * FIXME: Not portable. Also, why do we enable the ROM in the first place?
1340 * We don't seem to be using it.
1341 */
1338 if (dev->resource[PCI_ROM_RESOURCE].start) 1342 if (dev->resource[PCI_ROM_RESOURCE].start)
1339 pci_write_config_byte(dev, PCI_ROM_ADDRESS, 1343 pci_write_config_dword(dev, PCI_ROM_ADDRESS,
1340 dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE); 1344 dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
1341 1345
1342 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4)); 1346 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c
index 06759b36af..9d6facf2f7 100644
--- a/drivers/ieee1394/video1394.c
+++ b/drivers/ieee1394/video1394.c
@@ -883,7 +883,7 @@ static int __video1394_ioctl(struct file *file,
883 v.channel); 883 v.channel);
884 } 884 }
885 885
886 if (copy_to_user((void *)arg, &v, sizeof(v))) { 886 if (copy_to_user(argp, &v, sizeof(v))) {
887 /* FIXME : free allocated dma resources */ 887 /* FIXME : free allocated dma resources */
888 return -EFAULT; 888 return -EFAULT;
889 } 889 }
diff --git a/drivers/infiniband/Kconfig b/drivers/infiniband/Kconfig
index 32cdfb30e9..325d502e25 100644
--- a/drivers/infiniband/Kconfig
+++ b/drivers/infiniband/Kconfig
@@ -8,15 +8,26 @@ config INFINIBAND
8 any protocols you wish to use as well as drivers for your 8 any protocols you wish to use as well as drivers for your
9 InfiniBand hardware. 9 InfiniBand hardware.
10 10
11config INFINIBAND_USER_VERBS 11config INFINIBAND_USER_MAD
12 tristate "InfiniBand userspace verbs support" 12 tristate "InfiniBand userspace MAD support"
13 depends on INFINIBAND 13 depends on INFINIBAND
14 ---help--- 14 ---help---
15 Userspace InfiniBand verbs support. This is the kernel side 15 Userspace InfiniBand Management Datagram (MAD) support. This
16 of userspace verbs, which allows userspace processes to 16 is the kernel side of the userspace MAD support, which allows
17 directly access InfiniBand hardware for fast-path 17 userspace processes to send and receive MADs. You will also
18 operations. You will also need libibverbs and a hardware 18 need libibumad from <http://www.openib.org>.
19 driver library from <http://www.openib.org>. 19
20config INFINIBAND_USER_ACCESS
21 tristate "InfiniBand userspace access (verbs and CM)"
22 depends on INFINIBAND
23 ---help---
24 Userspace InfiniBand access support. This enables the
25 kernel side of userspace verbs and the userspace
26 communication manager (CM). This allows userspace processes
27 to set up connections and directly access InfiniBand
28 hardware for fast-path operations. You will also need
29 libibverbs, libibcm and a hardware driver library from
30 <http://www.openib.org>.
20 31
21source "drivers/infiniband/hw/mthca/Kconfig" 32source "drivers/infiniband/hw/mthca/Kconfig"
22 33
diff --git a/drivers/infiniband/core/Makefile b/drivers/infiniband/core/Makefile
index 678a7e097f..ec3353f24b 100644
--- a/drivers/infiniband/core/Makefile
+++ b/drivers/infiniband/core/Makefile
@@ -1,6 +1,7 @@
1obj-$(CONFIG_INFINIBAND) += ib_core.o ib_mad.o ib_sa.o \ 1obj-$(CONFIG_INFINIBAND) += ib_core.o ib_mad.o ib_sa.o \
2 ib_cm.o ib_umad.o ib_ucm.o 2 ib_cm.o
3obj-$(CONFIG_INFINIBAND_USER_VERBS) += ib_uverbs.o 3obj-$(CONFIG_INFINIBAND_USER_MAD) += ib_umad.o
4obj-$(CONFIG_INFINIBAND_USER_ACCESS) += ib_uverbs.o ib_ucm.o
4 5
5ib_core-y := packer.o ud_header.o verbs.o sysfs.o \ 6ib_core-y := packer.o ud_header.o verbs.o sysfs.o \
6 device.o fmr_pool.o cache.o 7 device.o fmr_pool.o cache.o
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index 4de93ba274..54db6d4831 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -173,7 +173,8 @@ static int cm_alloc_msg(struct cm_id_private *cm_id_priv,
173 if (IS_ERR(ah)) 173 if (IS_ERR(ah))
174 return PTR_ERR(ah); 174 return PTR_ERR(ah);
175 175
176 m = ib_create_send_mad(mad_agent, 1, cm_id_priv->av.pkey_index, 176 m = ib_create_send_mad(mad_agent, cm_id_priv->id.remote_cm_qpn,
177 cm_id_priv->av.pkey_index,
177 ah, 0, sizeof(struct ib_mad_hdr), 178 ah, 0, sizeof(struct ib_mad_hdr),
178 sizeof(struct ib_mad)-sizeof(struct ib_mad_hdr), 179 sizeof(struct ib_mad)-sizeof(struct ib_mad_hdr),
179 GFP_ATOMIC); 180 GFP_ATOMIC);
@@ -536,6 +537,7 @@ struct ib_cm_id *ib_create_cm_id(ib_cm_handler cm_handler,
536 cm_id_priv->id.state = IB_CM_IDLE; 537 cm_id_priv->id.state = IB_CM_IDLE;
537 cm_id_priv->id.cm_handler = cm_handler; 538 cm_id_priv->id.cm_handler = cm_handler;
538 cm_id_priv->id.context = context; 539 cm_id_priv->id.context = context;
540 cm_id_priv->id.remote_cm_qpn = 1;
539 ret = cm_alloc_id(cm_id_priv); 541 ret = cm_alloc_id(cm_id_priv);
540 if (ret) 542 if (ret)
541 goto error; 543 goto error;
@@ -1313,6 +1315,7 @@ error3: atomic_dec(&cm_id_priv->refcount);
1313 cm_deref_id(listen_cm_id_priv); 1315 cm_deref_id(listen_cm_id_priv);
1314 cm_cleanup_timewait(cm_id_priv->timewait_info); 1316 cm_cleanup_timewait(cm_id_priv->timewait_info);
1315error2: kfree(cm_id_priv->timewait_info); 1317error2: kfree(cm_id_priv->timewait_info);
1318 cm_id_priv->timewait_info = NULL;
1316error1: ib_destroy_cm_id(&cm_id_priv->id); 1319error1: ib_destroy_cm_id(&cm_id_priv->id);
1317 return ret; 1320 return ret;
1318} 1321}
diff --git a/drivers/infiniband/core/mad_rmpp.c b/drivers/infiniband/core/mad_rmpp.c
index 43fd805e02..2bd8b1cc57 100644
--- a/drivers/infiniband/core/mad_rmpp.c
+++ b/drivers/infiniband/core/mad_rmpp.c
@@ -593,7 +593,8 @@ static int send_next_seg(struct ib_mad_send_wr_private *mad_send_wr)
593 rmpp_mad->rmpp_hdr.paylen_newwin = 593 rmpp_mad->rmpp_hdr.paylen_newwin =
594 cpu_to_be32(mad_send_wr->total_seg * 594 cpu_to_be32(mad_send_wr->total_seg *
595 (sizeof(struct ib_rmpp_mad) - 595 (sizeof(struct ib_rmpp_mad) -
596 offsetof(struct ib_rmpp_mad, data))); 596 offsetof(struct ib_rmpp_mad, data)) -
597 mad_send_wr->pad);
597 mad_send_wr->sg_list[0].length = sizeof(struct ib_rmpp_mad); 598 mad_send_wr->sg_list[0].length = sizeof(struct ib_rmpp_mad);
598 } else { 599 } else {
599 mad_send_wr->send_wr.num_sge = 2; 600 mad_send_wr->send_wr.num_sge = 2;
@@ -602,6 +603,7 @@ static int send_next_seg(struct ib_mad_send_wr_private *mad_send_wr)
602 mad_send_wr->sg_list[1].length = sizeof(struct ib_rmpp_mad) - 603 mad_send_wr->sg_list[1].length = sizeof(struct ib_rmpp_mad) -
603 mad_send_wr->data_offset; 604 mad_send_wr->data_offset;
604 mad_send_wr->sg_list[1].lkey = mad_send_wr->sg_list[0].lkey; 605 mad_send_wr->sg_list[1].lkey = mad_send_wr->sg_list[0].lkey;
606 rmpp_mad->rmpp_hdr.paylen_newwin = 0;
605 } 607 }
606 608
607 if (mad_send_wr->seg_num == mad_send_wr->total_seg) { 609 if (mad_send_wr->seg_num == mad_send_wr->total_seg) {
diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
index 126ac80db7..78de2dd1a4 100644
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -113,32 +113,6 @@ static DEFINE_IDR(query_idr);
113static spinlock_t tid_lock; 113static spinlock_t tid_lock;
114static u32 tid; 114static u32 tid;
115 115
116enum {
117 IB_SA_ATTR_CLASS_PORTINFO = 0x01,
118 IB_SA_ATTR_NOTICE = 0x02,
119 IB_SA_ATTR_INFORM_INFO = 0x03,
120 IB_SA_ATTR_NODE_REC = 0x11,
121 IB_SA_ATTR_PORT_INFO_REC = 0x12,
122 IB_SA_ATTR_SL2VL_REC = 0x13,
123 IB_SA_ATTR_SWITCH_REC = 0x14,
124 IB_SA_ATTR_LINEAR_FDB_REC = 0x15,
125 IB_SA_ATTR_RANDOM_FDB_REC = 0x16,
126 IB_SA_ATTR_MCAST_FDB_REC = 0x17,
127 IB_SA_ATTR_SM_INFO_REC = 0x18,
128 IB_SA_ATTR_LINK_REC = 0x20,
129 IB_SA_ATTR_GUID_INFO_REC = 0x30,
130 IB_SA_ATTR_SERVICE_REC = 0x31,
131 IB_SA_ATTR_PARTITION_REC = 0x33,
132 IB_SA_ATTR_RANGE_REC = 0x34,
133 IB_SA_ATTR_PATH_REC = 0x35,
134 IB_SA_ATTR_VL_ARB_REC = 0x36,
135 IB_SA_ATTR_MC_GROUP_REC = 0x37,
136 IB_SA_ATTR_MC_MEMBER_REC = 0x38,
137 IB_SA_ATTR_TRACE_REC = 0x39,
138 IB_SA_ATTR_MULTI_PATH_REC = 0x3a,
139 IB_SA_ATTR_SERVICE_ASSOC_REC = 0x3b
140};
141
142#define PATH_REC_FIELD(field) \ 116#define PATH_REC_FIELD(field) \
143 .struct_offset_bytes = offsetof(struct ib_sa_path_rec, field), \ 117 .struct_offset_bytes = offsetof(struct ib_sa_path_rec, field), \
144 .struct_size_bytes = sizeof ((struct ib_sa_path_rec *) 0)->field, \ 118 .struct_size_bytes = sizeof ((struct ib_sa_path_rec *) 0)->field, \
@@ -431,8 +405,8 @@ static void ib_sa_event(struct ib_event_handler *handler, struct ib_event *event
431 event->event == IB_EVENT_LID_CHANGE || 405 event->event == IB_EVENT_LID_CHANGE ||
432 event->event == IB_EVENT_PKEY_CHANGE || 406 event->event == IB_EVENT_PKEY_CHANGE ||
433 event->event == IB_EVENT_SM_CHANGE) { 407 event->event == IB_EVENT_SM_CHANGE) {
434 struct ib_sa_device *sa_dev = 408 struct ib_sa_device *sa_dev;
435 ib_get_client_data(event->device, &sa_client); 409 sa_dev = container_of(handler, typeof(*sa_dev), event_handler);
436 410
437 schedule_work(&sa_dev->port[event->element.port_num - 411 schedule_work(&sa_dev->port[event->element.port_num -
438 sa_dev->start_port].update_task); 412 sa_dev->start_port].update_task);
diff --git a/drivers/infiniband/core/ucm.c b/drivers/infiniband/core/ucm.c
index 79595826cc..d0f0b0a2ed 100644
--- a/drivers/infiniband/core/ucm.c
+++ b/drivers/infiniband/core/ucm.c
@@ -72,7 +72,6 @@ enum {
72 72
73static struct semaphore ctx_id_mutex; 73static struct semaphore ctx_id_mutex;
74static struct idr ctx_id_table; 74static struct idr ctx_id_table;
75static int ctx_id_rover = 0;
76 75
77static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id) 76static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id)
78{ 77{
@@ -97,33 +96,16 @@ static void ib_ucm_ctx_put(struct ib_ucm_context *ctx)
97 wake_up(&ctx->wait); 96 wake_up(&ctx->wait);
98} 97}
99 98
100static ssize_t ib_ucm_destroy_ctx(struct ib_ucm_file *file, int id) 99static inline int ib_ucm_new_cm_id(int event)
101{ 100{
102 struct ib_ucm_context *ctx; 101 return event == IB_CM_REQ_RECEIVED || event == IB_CM_SIDR_REQ_RECEIVED;
103 struct ib_ucm_event *uevent; 102}
104
105 down(&ctx_id_mutex);
106 ctx = idr_find(&ctx_id_table, id);
107 if (!ctx)
108 ctx = ERR_PTR(-ENOENT);
109 else if (ctx->file != file)
110 ctx = ERR_PTR(-EINVAL);
111 else
112 idr_remove(&ctx_id_table, ctx->id);
113 up(&ctx_id_mutex);
114
115 if (IS_ERR(ctx))
116 return PTR_ERR(ctx);
117
118 atomic_dec(&ctx->ref);
119 wait_event(ctx->wait, !atomic_read(&ctx->ref));
120 103
121 /* No new events will be generated after destroying the cm_id. */ 104static void ib_ucm_cleanup_events(struct ib_ucm_context *ctx)
122 if (!IS_ERR(ctx->cm_id)) 105{
123 ib_destroy_cm_id(ctx->cm_id); 106 struct ib_ucm_event *uevent;
124 107
125 /* Cleanup events not yet reported to the user. */ 108 down(&ctx->file->mutex);
126 down(&file->mutex);
127 list_del(&ctx->file_list); 109 list_del(&ctx->file_list);
128 while (!list_empty(&ctx->events)) { 110 while (!list_empty(&ctx->events)) {
129 111
@@ -133,15 +115,12 @@ static ssize_t ib_ucm_destroy_ctx(struct ib_ucm_file *file, int id)
133 list_del(&uevent->ctx_list); 115 list_del(&uevent->ctx_list);
134 116
135 /* clear incoming connections. */ 117 /* clear incoming connections. */
136 if (uevent->cm_id) 118 if (ib_ucm_new_cm_id(uevent->resp.event))
137 ib_destroy_cm_id(uevent->cm_id); 119 ib_destroy_cm_id(uevent->cm_id);
138 120
139 kfree(uevent); 121 kfree(uevent);
140 } 122 }
141 up(&file->mutex); 123 up(&ctx->file->mutex);
142
143 kfree(ctx);
144 return 0;
145} 124}
146 125
147static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file) 126static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file)
@@ -153,36 +132,31 @@ static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file)
153 if (!ctx) 132 if (!ctx)
154 return NULL; 133 return NULL;
155 134
135 memset(ctx, 0, sizeof *ctx);
156 atomic_set(&ctx->ref, 1); 136 atomic_set(&ctx->ref, 1);
157 init_waitqueue_head(&ctx->wait); 137 init_waitqueue_head(&ctx->wait);
158 ctx->file = file; 138 ctx->file = file;
159
160 INIT_LIST_HEAD(&ctx->events); 139 INIT_LIST_HEAD(&ctx->events);
161 140
162 list_add_tail(&ctx->file_list, &file->ctxs); 141 do {
163 142 result = idr_pre_get(&ctx_id_table, GFP_KERNEL);
164 ctx_id_rover = (ctx_id_rover + 1) & INT_MAX; 143 if (!result)
165retry: 144 goto error;
166 result = idr_pre_get(&ctx_id_table, GFP_KERNEL);
167 if (!result)
168 goto error;
169 145
170 down(&ctx_id_mutex); 146 down(&ctx_id_mutex);
171 result = idr_get_new_above(&ctx_id_table, ctx, ctx_id_rover, &ctx->id); 147 result = idr_get_new(&ctx_id_table, ctx, &ctx->id);
172 up(&ctx_id_mutex); 148 up(&ctx_id_mutex);
149 } while (result == -EAGAIN);
173 150
174 if (result == -EAGAIN)
175 goto retry;
176 if (result) 151 if (result)
177 goto error; 152 goto error;
178 153
154 list_add_tail(&ctx->file_list, &file->ctxs);
179 ucm_dbg("Allocated CM ID <%d>\n", ctx->id); 155 ucm_dbg("Allocated CM ID <%d>\n", ctx->id);
180
181 return ctx; 156 return ctx;
157
182error: 158error:
183 list_del(&ctx->file_list);
184 kfree(ctx); 159 kfree(ctx);
185
186 return NULL; 160 return NULL;
187} 161}
188/* 162/*
@@ -219,12 +193,9 @@ static void ib_ucm_event_path_get(struct ib_ucm_path_rec *upath,
219 kpath->packet_life_time_selector; 193 kpath->packet_life_time_selector;
220} 194}
221 195
222static void ib_ucm_event_req_get(struct ib_ucm_context *ctx, 196static void ib_ucm_event_req_get(struct ib_ucm_req_event_resp *ureq,
223 struct ib_ucm_req_event_resp *ureq,
224 struct ib_cm_req_event_param *kreq) 197 struct ib_cm_req_event_param *kreq)
225{ 198{
226 ureq->listen_id = ctx->id;
227
228 ureq->remote_ca_guid = kreq->remote_ca_guid; 199 ureq->remote_ca_guid = kreq->remote_ca_guid;
229 ureq->remote_qkey = kreq->remote_qkey; 200 ureq->remote_qkey = kreq->remote_qkey;
230 ureq->remote_qpn = kreq->remote_qpn; 201 ureq->remote_qpn = kreq->remote_qpn;
@@ -259,14 +230,6 @@ static void ib_ucm_event_rep_get(struct ib_ucm_rep_event_resp *urep,
259 urep->srq = krep->srq; 230 urep->srq = krep->srq;
260} 231}
261 232
262static void ib_ucm_event_sidr_req_get(struct ib_ucm_context *ctx,
263 struct ib_ucm_sidr_req_event_resp *ureq,
264 struct ib_cm_sidr_req_event_param *kreq)
265{
266 ureq->listen_id = ctx->id;
267 ureq->pkey = kreq->pkey;
268}
269
270static void ib_ucm_event_sidr_rep_get(struct ib_ucm_sidr_rep_event_resp *urep, 233static void ib_ucm_event_sidr_rep_get(struct ib_ucm_sidr_rep_event_resp *urep,
271 struct ib_cm_sidr_rep_event_param *krep) 234 struct ib_cm_sidr_rep_event_param *krep)
272{ 235{
@@ -275,15 +238,14 @@ static void ib_ucm_event_sidr_rep_get(struct ib_ucm_sidr_rep_event_resp *urep,
275 urep->qpn = krep->qpn; 238 urep->qpn = krep->qpn;
276}; 239};
277 240
278static int ib_ucm_event_process(struct ib_ucm_context *ctx, 241static int ib_ucm_event_process(struct ib_cm_event *evt,
279 struct ib_cm_event *evt,
280 struct ib_ucm_event *uvt) 242 struct ib_ucm_event *uvt)
281{ 243{
282 void *info = NULL; 244 void *info = NULL;
283 245
284 switch (evt->event) { 246 switch (evt->event) {
285 case IB_CM_REQ_RECEIVED: 247 case IB_CM_REQ_RECEIVED:
286 ib_ucm_event_req_get(ctx, &uvt->resp.u.req_resp, 248 ib_ucm_event_req_get(&uvt->resp.u.req_resp,
287 &evt->param.req_rcvd); 249 &evt->param.req_rcvd);
288 uvt->data_len = IB_CM_REQ_PRIVATE_DATA_SIZE; 250 uvt->data_len = IB_CM_REQ_PRIVATE_DATA_SIZE;
289 uvt->resp.present = IB_UCM_PRES_PRIMARY; 251 uvt->resp.present = IB_UCM_PRES_PRIMARY;
@@ -331,8 +293,8 @@ static int ib_ucm_event_process(struct ib_ucm_context *ctx,
331 info = evt->param.apr_rcvd.apr_info; 293 info = evt->param.apr_rcvd.apr_info;
332 break; 294 break;
333 case IB_CM_SIDR_REQ_RECEIVED: 295 case IB_CM_SIDR_REQ_RECEIVED:
334 ib_ucm_event_sidr_req_get(ctx, &uvt->resp.u.sidr_req_resp, 296 uvt->resp.u.sidr_req_resp.pkey =
335 &evt->param.sidr_req_rcvd); 297 evt->param.sidr_req_rcvd.pkey;
336 uvt->data_len = IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE; 298 uvt->data_len = IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE;
337 break; 299 break;
338 case IB_CM_SIDR_REP_RECEIVED: 300 case IB_CM_SIDR_REP_RECEIVED:
@@ -378,31 +340,24 @@ static int ib_ucm_event_handler(struct ib_cm_id *cm_id,
378 struct ib_ucm_event *uevent; 340 struct ib_ucm_event *uevent;
379 struct ib_ucm_context *ctx; 341 struct ib_ucm_context *ctx;
380 int result = 0; 342 int result = 0;
381 int id;
382 343
383 ctx = cm_id->context; 344 ctx = cm_id->context;
384 345
385 if (event->event == IB_CM_REQ_RECEIVED ||
386 event->event == IB_CM_SIDR_REQ_RECEIVED)
387 id = IB_UCM_CM_ID_INVALID;
388 else
389 id = ctx->id;
390
391 uevent = kmalloc(sizeof(*uevent), GFP_KERNEL); 346 uevent = kmalloc(sizeof(*uevent), GFP_KERNEL);
392 if (!uevent) 347 if (!uevent)
393 goto err1; 348 goto err1;
394 349
395 memset(uevent, 0, sizeof(*uevent)); 350 memset(uevent, 0, sizeof(*uevent));
396 uevent->resp.id = id; 351 uevent->ctx = ctx;
352 uevent->cm_id = cm_id;
353 uevent->resp.uid = ctx->uid;
354 uevent->resp.id = ctx->id;
397 uevent->resp.event = event->event; 355 uevent->resp.event = event->event;
398 356
399 result = ib_ucm_event_process(ctx, event, uevent); 357 result = ib_ucm_event_process(event, uevent);
400 if (result) 358 if (result)
401 goto err2; 359 goto err2;
402 360
403 uevent->ctx = ctx;
404 uevent->cm_id = (id == IB_UCM_CM_ID_INVALID) ? cm_id : NULL;
405
406 down(&ctx->file->mutex); 361 down(&ctx->file->mutex);
407 list_add_tail(&uevent->file_list, &ctx->file->events); 362 list_add_tail(&uevent->file_list, &ctx->file->events);
408 list_add_tail(&uevent->ctx_list, &ctx->events); 363 list_add_tail(&uevent->ctx_list, &ctx->events);
@@ -414,7 +369,7 @@ err2:
414 kfree(uevent); 369 kfree(uevent);
415err1: 370err1:
416 /* Destroy new cm_id's */ 371 /* Destroy new cm_id's */
417 return (id == IB_UCM_CM_ID_INVALID); 372 return ib_ucm_new_cm_id(event->event);
418} 373}
419 374
420static ssize_t ib_ucm_event(struct ib_ucm_file *file, 375static ssize_t ib_ucm_event(struct ib_ucm_file *file,
@@ -423,7 +378,7 @@ static ssize_t ib_ucm_event(struct ib_ucm_file *file,
423{ 378{
424 struct ib_ucm_context *ctx; 379 struct ib_ucm_context *ctx;
425 struct ib_ucm_event_get cmd; 380 struct ib_ucm_event_get cmd;
426 struct ib_ucm_event *uevent = NULL; 381 struct ib_ucm_event *uevent;
427 int result = 0; 382 int result = 0;
428 DEFINE_WAIT(wait); 383 DEFINE_WAIT(wait);
429 384
@@ -436,7 +391,6 @@ static ssize_t ib_ucm_event(struct ib_ucm_file *file,
436 * wait 391 * wait
437 */ 392 */
438 down(&file->mutex); 393 down(&file->mutex);
439
440 while (list_empty(&file->events)) { 394 while (list_empty(&file->events)) {
441 395
442 if (file->filp->f_flags & O_NONBLOCK) { 396 if (file->filp->f_flags & O_NONBLOCK) {
@@ -463,21 +417,18 @@ static ssize_t ib_ucm_event(struct ib_ucm_file *file,
463 417
464 uevent = list_entry(file->events.next, struct ib_ucm_event, file_list); 418 uevent = list_entry(file->events.next, struct ib_ucm_event, file_list);
465 419
466 if (!uevent->cm_id) 420 if (ib_ucm_new_cm_id(uevent->resp.event)) {
467 goto user; 421 ctx = ib_ucm_ctx_alloc(file);
422 if (!ctx) {
423 result = -ENOMEM;
424 goto done;
425 }
468 426
469 ctx = ib_ucm_ctx_alloc(file); 427 ctx->cm_id = uevent->cm_id;
470 if (!ctx) { 428 ctx->cm_id->context = ctx;
471 result = -ENOMEM; 429 uevent->resp.id = ctx->id;
472 goto done;
473 } 430 }
474 431
475 ctx->cm_id = uevent->cm_id;
476 ctx->cm_id->context = ctx;
477
478 uevent->resp.id = ctx->id;
479
480user:
481 if (copy_to_user((void __user *)(unsigned long)cmd.response, 432 if (copy_to_user((void __user *)(unsigned long)cmd.response,
482 &uevent->resp, sizeof(uevent->resp))) { 433 &uevent->resp, sizeof(uevent->resp))) {
483 result = -EFAULT; 434 result = -EFAULT;
@@ -485,12 +436,10 @@ user:
485 } 436 }
486 437
487 if (uevent->data) { 438 if (uevent->data) {
488
489 if (cmd.data_len < uevent->data_len) { 439 if (cmd.data_len < uevent->data_len) {
490 result = -ENOMEM; 440 result = -ENOMEM;
491 goto done; 441 goto done;
492 } 442 }
493
494 if (copy_to_user((void __user *)(unsigned long)cmd.data, 443 if (copy_to_user((void __user *)(unsigned long)cmd.data,
495 uevent->data, uevent->data_len)) { 444 uevent->data, uevent->data_len)) {
496 result = -EFAULT; 445 result = -EFAULT;
@@ -499,12 +448,10 @@ user:
499 } 448 }
500 449
501 if (uevent->info) { 450 if (uevent->info) {
502
503 if (cmd.info_len < uevent->info_len) { 451 if (cmd.info_len < uevent->info_len) {
504 result = -ENOMEM; 452 result = -ENOMEM;
505 goto done; 453 goto done;
506 } 454 }
507
508 if (copy_to_user((void __user *)(unsigned long)cmd.info, 455 if (copy_to_user((void __user *)(unsigned long)cmd.info,
509 uevent->info, uevent->info_len)) { 456 uevent->info, uevent->info_len)) {
510 result = -EFAULT; 457 result = -EFAULT;
@@ -514,6 +461,7 @@ user:
514 461
515 list_del(&uevent->file_list); 462 list_del(&uevent->file_list);
516 list_del(&uevent->ctx_list); 463 list_del(&uevent->ctx_list);
464 uevent->ctx->events_reported++;
517 465
518 kfree(uevent->data); 466 kfree(uevent->data);
519 kfree(uevent->info); 467 kfree(uevent->info);
@@ -545,6 +493,7 @@ static ssize_t ib_ucm_create_id(struct ib_ucm_file *file,
545 if (!ctx) 493 if (!ctx)
546 return -ENOMEM; 494 return -ENOMEM;
547 495
496 ctx->uid = cmd.uid;
548 ctx->cm_id = ib_create_cm_id(ib_ucm_event_handler, ctx); 497 ctx->cm_id = ib_create_cm_id(ib_ucm_event_handler, ctx);
549 if (IS_ERR(ctx->cm_id)) { 498 if (IS_ERR(ctx->cm_id)) {
550 result = PTR_ERR(ctx->cm_id); 499 result = PTR_ERR(ctx->cm_id);
@@ -561,7 +510,14 @@ static ssize_t ib_ucm_create_id(struct ib_ucm_file *file,
561 return 0; 510 return 0;
562 511
563err: 512err:
564 ib_ucm_destroy_ctx(file, ctx->id); 513 down(&ctx_id_mutex);
514 idr_remove(&ctx_id_table, ctx->id);
515 up(&ctx_id_mutex);
516
517 if (!IS_ERR(ctx->cm_id))
518 ib_destroy_cm_id(ctx->cm_id);
519
520 kfree(ctx);
565 return result; 521 return result;
566} 522}
567 523
@@ -570,11 +526,44 @@ static ssize_t ib_ucm_destroy_id(struct ib_ucm_file *file,
570 int in_len, int out_len) 526 int in_len, int out_len)
571{ 527{
572 struct ib_ucm_destroy_id cmd; 528 struct ib_ucm_destroy_id cmd;
529 struct ib_ucm_destroy_id_resp resp;
530 struct ib_ucm_context *ctx;
531 int result = 0;
532
533 if (out_len < sizeof(resp))
534 return -ENOSPC;
573 535
574 if (copy_from_user(&cmd, inbuf, sizeof(cmd))) 536 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
575 return -EFAULT; 537 return -EFAULT;
576 538
577 return ib_ucm_destroy_ctx(file, cmd.id); 539 down(&ctx_id_mutex);
540 ctx = idr_find(&ctx_id_table, cmd.id);
541 if (!ctx)
542 ctx = ERR_PTR(-ENOENT);
543 else if (ctx->file != file)
544 ctx = ERR_PTR(-EINVAL);
545 else
546 idr_remove(&ctx_id_table, ctx->id);
547 up(&ctx_id_mutex);
548
549 if (IS_ERR(ctx))
550 return PTR_ERR(ctx);
551
552 atomic_dec(&ctx->ref);
553 wait_event(ctx->wait, !atomic_read(&ctx->ref));
554
555 /* No new events will be generated after destroying the cm_id. */
556 ib_destroy_cm_id(ctx->cm_id);
557 /* Cleanup events not yet reported to the user. */
558 ib_ucm_cleanup_events(ctx);
559
560 resp.events_reported = ctx->events_reported;
561 if (copy_to_user((void __user *)(unsigned long)cmd.response,
562 &resp, sizeof(resp)))
563 result = -EFAULT;
564
565 kfree(ctx);
566 return result;
578} 567}
579 568
580static ssize_t ib_ucm_attr_id(struct ib_ucm_file *file, 569static ssize_t ib_ucm_attr_id(struct ib_ucm_file *file,
@@ -609,6 +598,98 @@ static ssize_t ib_ucm_attr_id(struct ib_ucm_file *file,
609 return result; 598 return result;
610} 599}
611 600
601static void ib_ucm_copy_ah_attr(struct ib_ucm_ah_attr *dest_attr,
602 struct ib_ah_attr *src_attr)
603{
604 memcpy(dest_attr->grh_dgid, src_attr->grh.dgid.raw,
605 sizeof src_attr->grh.dgid);
606 dest_attr->grh_flow_label = src_attr->grh.flow_label;
607 dest_attr->grh_sgid_index = src_attr->grh.sgid_index;
608 dest_attr->grh_hop_limit = src_attr->grh.hop_limit;
609 dest_attr->grh_traffic_class = src_attr->grh.traffic_class;
610
611 dest_attr->dlid = src_attr->dlid;
612 dest_attr->sl = src_attr->sl;
613 dest_attr->src_path_bits = src_attr->src_path_bits;
614 dest_attr->static_rate = src_attr->static_rate;
615 dest_attr->is_global = (src_attr->ah_flags & IB_AH_GRH);
616 dest_attr->port_num = src_attr->port_num;
617}
618
619static void ib_ucm_copy_qp_attr(struct ib_ucm_init_qp_attr_resp *dest_attr,
620 struct ib_qp_attr *src_attr)
621{
622 dest_attr->cur_qp_state = src_attr->cur_qp_state;
623 dest_attr->path_mtu = src_attr->path_mtu;
624 dest_attr->path_mig_state = src_attr->path_mig_state;
625 dest_attr->qkey = src_attr->qkey;
626 dest_attr->rq_psn = src_attr->rq_psn;
627 dest_attr->sq_psn = src_attr->sq_psn;
628 dest_attr->dest_qp_num = src_attr->dest_qp_num;
629 dest_attr->qp_access_flags = src_attr->qp_access_flags;
630
631 dest_attr->max_send_wr = src_attr->cap.max_send_wr;
632 dest_attr->max_recv_wr = src_attr->cap.max_recv_wr;
633 dest_attr->max_send_sge = src_attr->cap.max_send_sge;
634 dest_attr->max_recv_sge = src_attr->cap.max_recv_sge;
635 dest_attr->max_inline_data = src_attr->cap.max_inline_data;
636
637 ib_ucm_copy_ah_attr(&dest_attr->ah_attr, &src_attr->ah_attr);
638 ib_ucm_copy_ah_attr(&dest_attr->alt_ah_attr, &src_attr->alt_ah_attr);
639
640 dest_attr->pkey_index = src_attr->pkey_index;
641 dest_attr->alt_pkey_index = src_attr->alt_pkey_index;
642 dest_attr->en_sqd_async_notify = src_attr->en_sqd_async_notify;
643 dest_attr->sq_draining = src_attr->sq_draining;
644 dest_attr->max_rd_atomic = src_attr->max_rd_atomic;
645 dest_attr->max_dest_rd_atomic = src_attr->max_dest_rd_atomic;
646 dest_attr->min_rnr_timer = src_attr->min_rnr_timer;
647 dest_attr->port_num = src_attr->port_num;
648 dest_attr->timeout = src_attr->timeout;
649 dest_attr->retry_cnt = src_attr->retry_cnt;
650 dest_attr->rnr_retry = src_attr->rnr_retry;
651 dest_attr->alt_port_num = src_attr->alt_port_num;
652 dest_attr->alt_timeout = src_attr->alt_timeout;
653}
654
655static ssize_t ib_ucm_init_qp_attr(struct ib_ucm_file *file,
656 const char __user *inbuf,
657 int in_len, int out_len)
658{
659 struct ib_ucm_init_qp_attr_resp resp;
660 struct ib_ucm_init_qp_attr cmd;
661 struct ib_ucm_context *ctx;
662 struct ib_qp_attr qp_attr;
663 int result = 0;
664
665 if (out_len < sizeof(resp))
666 return -ENOSPC;
667
668 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
669 return -EFAULT;
670
671 ctx = ib_ucm_ctx_get(file, cmd.id);
672 if (IS_ERR(ctx))
673 return PTR_ERR(ctx);
674
675 resp.qp_attr_mask = 0;
676 memset(&qp_attr, 0, sizeof qp_attr);
677 qp_attr.qp_state = cmd.qp_state;
678 result = ib_cm_init_qp_attr(ctx->cm_id, &qp_attr, &resp.qp_attr_mask);
679 if (result)
680 goto out;
681
682 ib_ucm_copy_qp_attr(&resp, &qp_attr);
683
684 if (copy_to_user((void __user *)(unsigned long)cmd.response,
685 &resp, sizeof(resp)))
686 result = -EFAULT;
687
688out:
689 ib_ucm_ctx_put(ctx);
690 return result;
691}
692
612static ssize_t ib_ucm_listen(struct ib_ucm_file *file, 693static ssize_t ib_ucm_listen(struct ib_ucm_file *file,
613 const char __user *inbuf, 694 const char __user *inbuf,
614 int in_len, int out_len) 695 int in_len, int out_len)
@@ -808,6 +889,7 @@ static ssize_t ib_ucm_send_rep(struct ib_ucm_file *file,
808 889
809 ctx = ib_ucm_ctx_get(file, cmd.id); 890 ctx = ib_ucm_ctx_get(file, cmd.id);
810 if (!IS_ERR(ctx)) { 891 if (!IS_ERR(ctx)) {
892 ctx->uid = cmd.uid;
811 result = ib_send_cm_rep(ctx->cm_id, &param); 893 result = ib_send_cm_rep(ctx->cm_id, &param);
812 ib_ucm_ctx_put(ctx); 894 ib_ucm_ctx_put(ctx);
813 } else 895 } else
@@ -1086,6 +1168,7 @@ static ssize_t (*ucm_cmd_table[])(struct ib_ucm_file *file,
1086 [IB_USER_CM_CMD_SEND_SIDR_REQ] = ib_ucm_send_sidr_req, 1168 [IB_USER_CM_CMD_SEND_SIDR_REQ] = ib_ucm_send_sidr_req,
1087 [IB_USER_CM_CMD_SEND_SIDR_REP] = ib_ucm_send_sidr_rep, 1169 [IB_USER_CM_CMD_SEND_SIDR_REP] = ib_ucm_send_sidr_rep,
1088 [IB_USER_CM_CMD_EVENT] = ib_ucm_event, 1170 [IB_USER_CM_CMD_EVENT] = ib_ucm_event,
1171 [IB_USER_CM_CMD_INIT_QP_ATTR] = ib_ucm_init_qp_attr,
1089}; 1172};
1090 1173
1091static ssize_t ib_ucm_write(struct file *filp, const char __user *buf, 1174static ssize_t ib_ucm_write(struct file *filp, const char __user *buf,
@@ -1161,12 +1244,18 @@ static int ib_ucm_close(struct inode *inode, struct file *filp)
1161 1244
1162 down(&file->mutex); 1245 down(&file->mutex);
1163 while (!list_empty(&file->ctxs)) { 1246 while (!list_empty(&file->ctxs)) {
1164
1165 ctx = list_entry(file->ctxs.next, 1247 ctx = list_entry(file->ctxs.next,
1166 struct ib_ucm_context, file_list); 1248 struct ib_ucm_context, file_list);
1167
1168 up(&file->mutex); 1249 up(&file->mutex);
1169 ib_ucm_destroy_ctx(file, ctx->id); 1250
1251 down(&ctx_id_mutex);
1252 idr_remove(&ctx_id_table, ctx->id);
1253 up(&ctx_id_mutex);
1254
1255 ib_destroy_cm_id(ctx->cm_id);
1256 ib_ucm_cleanup_events(ctx);
1257 kfree(ctx);
1258
1170 down(&file->mutex); 1259 down(&file->mutex);
1171 } 1260 }
1172 up(&file->mutex); 1261 up(&file->mutex);
diff --git a/drivers/infiniband/core/ucm.h b/drivers/infiniband/core/ucm.h
index c8819b928a..f46f37bc12 100644
--- a/drivers/infiniband/core/ucm.h
+++ b/drivers/infiniband/core/ucm.h
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Intel Corporation. All rights reserved.
3 * 4 *
4 * This software is available to you under a choice of one of two 5 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 6 * licenses. You may choose to be licensed under the terms of the GNU
@@ -43,8 +44,6 @@
43#include <rdma/ib_cm.h> 44#include <rdma/ib_cm.h>
44#include <rdma/ib_user_cm.h> 45#include <rdma/ib_user_cm.h>
45 46
46#define IB_UCM_CM_ID_INVALID 0xffffffff
47
48struct ib_ucm_file { 47struct ib_ucm_file {
49 struct semaphore mutex; 48 struct semaphore mutex;
50 struct file *filp; 49 struct file *filp;
@@ -58,9 +57,11 @@ struct ib_ucm_context {
58 int id; 57 int id;
59 wait_queue_head_t wait; 58 wait_queue_head_t wait;
60 atomic_t ref; 59 atomic_t ref;
60 int events_reported;
61 61
62 struct ib_ucm_file *file; 62 struct ib_ucm_file *file;
63 struct ib_cm_id *cm_id; 63 struct ib_cm_id *cm_id;
64 __u64 uid;
64 65
65 struct list_head events; /* list of pending events. */ 66 struct list_head events; /* list of pending events. */
66 struct list_head file_list; /* member in file ctx list */ 67 struct list_head file_list; /* member in file ctx list */
@@ -71,16 +72,12 @@ struct ib_ucm_event {
71 struct list_head file_list; /* member in file event list */ 72 struct list_head file_list; /* member in file event list */
72 struct list_head ctx_list; /* member in ctx event list */ 73 struct list_head ctx_list; /* member in ctx event list */
73 74
75 struct ib_cm_id *cm_id;
74 struct ib_ucm_event_resp resp; 76 struct ib_ucm_event_resp resp;
75 void *data; 77 void *data;
76 void *info; 78 void *info;
77 int data_len; 79 int data_len;
78 int info_len; 80 int info_len;
79 /*
80 * new connection identifiers needs to be saved until
81 * userspace can get a handle on them.
82 */
83 struct ib_cm_id *cm_id;
84}; 81};
85 82
86#endif /* UCM_H */ 83#endif /* UCM_H */
diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h
index 180b3d4765..b1897bed14 100644
--- a/drivers/infiniband/core/uverbs.h
+++ b/drivers/infiniband/core/uverbs.h
@@ -76,20 +76,28 @@ struct ib_uverbs_file {
76 struct ib_uverbs_event_file comp_file[1]; 76 struct ib_uverbs_event_file comp_file[1];
77}; 77};
78 78
79struct ib_uverbs_async_event { 79struct ib_uverbs_event {
80 struct ib_uverbs_async_event_desc desc; 80 union {
81 struct ib_uverbs_async_event_desc async;
82 struct ib_uverbs_comp_event_desc comp;
83 } desc;
81 struct list_head list; 84 struct list_head list;
85 struct list_head obj_list;
86 u32 *counter;
82}; 87};
83 88
84struct ib_uverbs_comp_event { 89struct ib_uevent_object {
85 struct ib_uverbs_comp_event_desc desc; 90 struct ib_uobject uobject;
86 struct list_head list; 91 struct list_head event_list;
92 u32 events_reported;
87}; 93};
88 94
89struct ib_uobject_mr { 95struct ib_ucq_object {
90 struct ib_uobject uobj; 96 struct ib_uobject uobject;
91 struct page *page_list; 97 struct list_head comp_list;
92 struct scatterlist *sg_list; 98 struct list_head async_list;
99 u32 comp_events_reported;
100 u32 async_events_reported;
93}; 101};
94 102
95extern struct semaphore ib_uverbs_idr_mutex; 103extern struct semaphore ib_uverbs_idr_mutex;
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index ebccf9f38a..e91ebde464 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -590,7 +590,7 @@ ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file,
590 struct ib_uverbs_create_cq cmd; 590 struct ib_uverbs_create_cq cmd;
591 struct ib_uverbs_create_cq_resp resp; 591 struct ib_uverbs_create_cq_resp resp;
592 struct ib_udata udata; 592 struct ib_udata udata;
593 struct ib_uobject *uobj; 593 struct ib_ucq_object *uobj;
594 struct ib_cq *cq; 594 struct ib_cq *cq;
595 int ret; 595 int ret;
596 596
@@ -611,8 +611,12 @@ ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file,
611 if (!uobj) 611 if (!uobj)
612 return -ENOMEM; 612 return -ENOMEM;
613 613
614 uobj->user_handle = cmd.user_handle; 614 uobj->uobject.user_handle = cmd.user_handle;
615 uobj->context = file->ucontext; 615 uobj->uobject.context = file->ucontext;
616 uobj->comp_events_reported = 0;
617 uobj->async_events_reported = 0;
618 INIT_LIST_HEAD(&uobj->comp_list);
619 INIT_LIST_HEAD(&uobj->async_list);
616 620
617 cq = file->device->ib_dev->create_cq(file->device->ib_dev, cmd.cqe, 621 cq = file->device->ib_dev->create_cq(file->device->ib_dev, cmd.cqe,
618 file->ucontext, &udata); 622 file->ucontext, &udata);
@@ -622,7 +626,7 @@ ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file,
622 } 626 }
623 627
624 cq->device = file->device->ib_dev; 628 cq->device = file->device->ib_dev;
625 cq->uobject = uobj; 629 cq->uobject = &uobj->uobject;
626 cq->comp_handler = ib_uverbs_comp_handler; 630 cq->comp_handler = ib_uverbs_comp_handler;
627 cq->event_handler = ib_uverbs_cq_event_handler; 631 cq->event_handler = ib_uverbs_cq_event_handler;
628 cq->cq_context = file; 632 cq->cq_context = file;
@@ -635,7 +639,7 @@ retry:
635 } 639 }
636 640
637 down(&ib_uverbs_idr_mutex); 641 down(&ib_uverbs_idr_mutex);
638 ret = idr_get_new(&ib_uverbs_cq_idr, cq, &uobj->id); 642 ret = idr_get_new(&ib_uverbs_cq_idr, cq, &uobj->uobject.id);
639 up(&ib_uverbs_idr_mutex); 643 up(&ib_uverbs_idr_mutex);
640 644
641 if (ret == -EAGAIN) 645 if (ret == -EAGAIN)
@@ -644,11 +648,11 @@ retry:
644 goto err_cq; 648 goto err_cq;
645 649
646 spin_lock_irq(&file->ucontext->lock); 650 spin_lock_irq(&file->ucontext->lock);
647 list_add_tail(&uobj->list, &file->ucontext->cq_list); 651 list_add_tail(&uobj->uobject.list, &file->ucontext->cq_list);
648 spin_unlock_irq(&file->ucontext->lock); 652 spin_unlock_irq(&file->ucontext->lock);
649 653
650 memset(&resp, 0, sizeof resp); 654 memset(&resp, 0, sizeof resp);
651 resp.cq_handle = uobj->id; 655 resp.cq_handle = uobj->uobject.id;
652 resp.cqe = cq->cqe; 656 resp.cqe = cq->cqe;
653 657
654 if (copy_to_user((void __user *) (unsigned long) cmd.response, 658 if (copy_to_user((void __user *) (unsigned long) cmd.response,
@@ -661,11 +665,11 @@ retry:
661 665
662err_list: 666err_list:
663 spin_lock_irq(&file->ucontext->lock); 667 spin_lock_irq(&file->ucontext->lock);
664 list_del(&uobj->list); 668 list_del(&uobj->uobject.list);
665 spin_unlock_irq(&file->ucontext->lock); 669 spin_unlock_irq(&file->ucontext->lock);
666 670
667 down(&ib_uverbs_idr_mutex); 671 down(&ib_uverbs_idr_mutex);
668 idr_remove(&ib_uverbs_cq_idr, uobj->id); 672 idr_remove(&ib_uverbs_cq_idr, uobj->uobject.id);
669 up(&ib_uverbs_idr_mutex); 673 up(&ib_uverbs_idr_mutex);
670 674
671err_cq: 675err_cq:
@@ -680,21 +684,27 @@ ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
680 const char __user *buf, int in_len, 684 const char __user *buf, int in_len,
681 int out_len) 685 int out_len)
682{ 686{
683 struct ib_uverbs_destroy_cq cmd; 687 struct ib_uverbs_destroy_cq cmd;
684 struct ib_cq *cq; 688 struct ib_uverbs_destroy_cq_resp resp;
685 struct ib_uobject *uobj; 689 struct ib_cq *cq;
686 int ret = -EINVAL; 690 struct ib_ucq_object *uobj;
691 struct ib_uverbs_event *evt, *tmp;
692 u64 user_handle;
693 int ret = -EINVAL;
687 694
688 if (copy_from_user(&cmd, buf, sizeof cmd)) 695 if (copy_from_user(&cmd, buf, sizeof cmd))
689 return -EFAULT; 696 return -EFAULT;
690 697
698 memset(&resp, 0, sizeof resp);
699
691 down(&ib_uverbs_idr_mutex); 700 down(&ib_uverbs_idr_mutex);
692 701
693 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle); 702 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle);
694 if (!cq || cq->uobject->context != file->ucontext) 703 if (!cq || cq->uobject->context != file->ucontext)
695 goto out; 704 goto out;
696 705
697 uobj = cq->uobject; 706 user_handle = cq->uobject->user_handle;
707 uobj = container_of(cq->uobject, struct ib_ucq_object, uobject);
698 708
699 ret = ib_destroy_cq(cq); 709 ret = ib_destroy_cq(cq);
700 if (ret) 710 if (ret)
@@ -703,11 +713,32 @@ ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
703 idr_remove(&ib_uverbs_cq_idr, cmd.cq_handle); 713 idr_remove(&ib_uverbs_cq_idr, cmd.cq_handle);
704 714
705 spin_lock_irq(&file->ucontext->lock); 715 spin_lock_irq(&file->ucontext->lock);
706 list_del(&uobj->list); 716 list_del(&uobj->uobject.list);
707 spin_unlock_irq(&file->ucontext->lock); 717 spin_unlock_irq(&file->ucontext->lock);
708 718
719 spin_lock_irq(&file->comp_file[0].lock);
720 list_for_each_entry_safe(evt, tmp, &uobj->comp_list, obj_list) {
721 list_del(&evt->list);
722 kfree(evt);
723 }
724 spin_unlock_irq(&file->comp_file[0].lock);
725
726 spin_lock_irq(&file->async_file.lock);
727 list_for_each_entry_safe(evt, tmp, &uobj->async_list, obj_list) {
728 list_del(&evt->list);
729 kfree(evt);
730 }
731 spin_unlock_irq(&file->async_file.lock);
732
733 resp.comp_events_reported = uobj->comp_events_reported;
734 resp.async_events_reported = uobj->async_events_reported;
735
709 kfree(uobj); 736 kfree(uobj);
710 737
738 if (copy_to_user((void __user *) (unsigned long) cmd.response,
739 &resp, sizeof resp))
740 ret = -EFAULT;
741
711out: 742out:
712 up(&ib_uverbs_idr_mutex); 743 up(&ib_uverbs_idr_mutex);
713 744
@@ -721,7 +752,7 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
721 struct ib_uverbs_create_qp cmd; 752 struct ib_uverbs_create_qp cmd;
722 struct ib_uverbs_create_qp_resp resp; 753 struct ib_uverbs_create_qp_resp resp;
723 struct ib_udata udata; 754 struct ib_udata udata;
724 struct ib_uobject *uobj; 755 struct ib_uevent_object *uobj;
725 struct ib_pd *pd; 756 struct ib_pd *pd;
726 struct ib_cq *scq, *rcq; 757 struct ib_cq *scq, *rcq;
727 struct ib_srq *srq; 758 struct ib_srq *srq;
@@ -772,8 +803,10 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
772 attr.cap.max_recv_sge = cmd.max_recv_sge; 803 attr.cap.max_recv_sge = cmd.max_recv_sge;
773 attr.cap.max_inline_data = cmd.max_inline_data; 804 attr.cap.max_inline_data = cmd.max_inline_data;
774 805
775 uobj->user_handle = cmd.user_handle; 806 uobj->uobject.user_handle = cmd.user_handle;
776 uobj->context = file->ucontext; 807 uobj->uobject.context = file->ucontext;
808 uobj->events_reported = 0;
809 INIT_LIST_HEAD(&uobj->event_list);
777 810
778 qp = pd->device->create_qp(pd, &attr, &udata); 811 qp = pd->device->create_qp(pd, &attr, &udata);
779 if (IS_ERR(qp)) { 812 if (IS_ERR(qp)) {
@@ -786,7 +819,7 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
786 qp->send_cq = attr.send_cq; 819 qp->send_cq = attr.send_cq;
787 qp->recv_cq = attr.recv_cq; 820 qp->recv_cq = attr.recv_cq;
788 qp->srq = attr.srq; 821 qp->srq = attr.srq;
789 qp->uobject = uobj; 822 qp->uobject = &uobj->uobject;
790 qp->event_handler = attr.event_handler; 823 qp->event_handler = attr.event_handler;
791 qp->qp_context = attr.qp_context; 824 qp->qp_context = attr.qp_context;
792 qp->qp_type = attr.qp_type; 825 qp->qp_type = attr.qp_type;
@@ -805,17 +838,17 @@ retry:
805 goto err_destroy; 838 goto err_destroy;
806 } 839 }
807 840
808 ret = idr_get_new(&ib_uverbs_qp_idr, qp, &uobj->id); 841 ret = idr_get_new(&ib_uverbs_qp_idr, qp, &uobj->uobject.id);
809 842
810 if (ret == -EAGAIN) 843 if (ret == -EAGAIN)
811 goto retry; 844 goto retry;
812 if (ret) 845 if (ret)
813 goto err_destroy; 846 goto err_destroy;
814 847
815 resp.qp_handle = uobj->id; 848 resp.qp_handle = uobj->uobject.id;
816 849
817 spin_lock_irq(&file->ucontext->lock); 850 spin_lock_irq(&file->ucontext->lock);
818 list_add_tail(&uobj->list, &file->ucontext->qp_list); 851 list_add_tail(&uobj->uobject.list, &file->ucontext->qp_list);
819 spin_unlock_irq(&file->ucontext->lock); 852 spin_unlock_irq(&file->ucontext->lock);
820 853
821 if (copy_to_user((void __user *) (unsigned long) cmd.response, 854 if (copy_to_user((void __user *) (unsigned long) cmd.response,
@@ -830,7 +863,7 @@ retry:
830 863
831err_list: 864err_list:
832 spin_lock_irq(&file->ucontext->lock); 865 spin_lock_irq(&file->ucontext->lock);
833 list_del(&uobj->list); 866 list_del(&uobj->uobject.list);
834 spin_unlock_irq(&file->ucontext->lock); 867 spin_unlock_irq(&file->ucontext->lock);
835 868
836err_destroy: 869err_destroy:
@@ -930,21 +963,25 @@ ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file,
930 const char __user *buf, int in_len, 963 const char __user *buf, int in_len,
931 int out_len) 964 int out_len)
932{ 965{
933 struct ib_uverbs_destroy_qp cmd; 966 struct ib_uverbs_destroy_qp cmd;
934 struct ib_qp *qp; 967 struct ib_uverbs_destroy_qp_resp resp;
935 struct ib_uobject *uobj; 968 struct ib_qp *qp;
936 int ret = -EINVAL; 969 struct ib_uevent_object *uobj;
970 struct ib_uverbs_event *evt, *tmp;
971 int ret = -EINVAL;
937 972
938 if (copy_from_user(&cmd, buf, sizeof cmd)) 973 if (copy_from_user(&cmd, buf, sizeof cmd))
939 return -EFAULT; 974 return -EFAULT;
940 975
976 memset(&resp, 0, sizeof resp);
977
941 down(&ib_uverbs_idr_mutex); 978 down(&ib_uverbs_idr_mutex);
942 979
943 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); 980 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
944 if (!qp || qp->uobject->context != file->ucontext) 981 if (!qp || qp->uobject->context != file->ucontext)
945 goto out; 982 goto out;
946 983
947 uobj = qp->uobject; 984 uobj = container_of(qp->uobject, struct ib_uevent_object, uobject);
948 985
949 ret = ib_destroy_qp(qp); 986 ret = ib_destroy_qp(qp);
950 if (ret) 987 if (ret)
@@ -953,11 +990,24 @@ ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file,
953 idr_remove(&ib_uverbs_qp_idr, cmd.qp_handle); 990 idr_remove(&ib_uverbs_qp_idr, cmd.qp_handle);
954 991
955 spin_lock_irq(&file->ucontext->lock); 992 spin_lock_irq(&file->ucontext->lock);
956 list_del(&uobj->list); 993 list_del(&uobj->uobject.list);
957 spin_unlock_irq(&file->ucontext->lock); 994 spin_unlock_irq(&file->ucontext->lock);
958 995
996 spin_lock_irq(&file->async_file.lock);
997 list_for_each_entry_safe(evt, tmp, &uobj->event_list, obj_list) {
998 list_del(&evt->list);
999 kfree(evt);
1000 }
1001 spin_unlock_irq(&file->async_file.lock);
1002
1003 resp.events_reported = uobj->events_reported;
1004
959 kfree(uobj); 1005 kfree(uobj);
960 1006
1007 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1008 &resp, sizeof resp))
1009 ret = -EFAULT;
1010
961out: 1011out:
962 up(&ib_uverbs_idr_mutex); 1012 up(&ib_uverbs_idr_mutex);
963 1013
@@ -1015,7 +1065,7 @@ ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file,
1015 struct ib_uverbs_create_srq cmd; 1065 struct ib_uverbs_create_srq cmd;
1016 struct ib_uverbs_create_srq_resp resp; 1066 struct ib_uverbs_create_srq_resp resp;
1017 struct ib_udata udata; 1067 struct ib_udata udata;
1018 struct ib_uobject *uobj; 1068 struct ib_uevent_object *uobj;
1019 struct ib_pd *pd; 1069 struct ib_pd *pd;
1020 struct ib_srq *srq; 1070 struct ib_srq *srq;
1021 struct ib_srq_init_attr attr; 1071 struct ib_srq_init_attr attr;
@@ -1050,8 +1100,10 @@ ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file,
1050 attr.attr.max_sge = cmd.max_sge; 1100 attr.attr.max_sge = cmd.max_sge;
1051 attr.attr.srq_limit = cmd.srq_limit; 1101 attr.attr.srq_limit = cmd.srq_limit;
1052 1102
1053 uobj->user_handle = cmd.user_handle; 1103 uobj->uobject.user_handle = cmd.user_handle;
1054 uobj->context = file->ucontext; 1104 uobj->uobject.context = file->ucontext;
1105 uobj->events_reported = 0;
1106 INIT_LIST_HEAD(&uobj->event_list);
1055 1107
1056 srq = pd->device->create_srq(pd, &attr, &udata); 1108 srq = pd->device->create_srq(pd, &attr, &udata);
1057 if (IS_ERR(srq)) { 1109 if (IS_ERR(srq)) {
@@ -1061,7 +1113,7 @@ ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file,
1061 1113
1062 srq->device = pd->device; 1114 srq->device = pd->device;
1063 srq->pd = pd; 1115 srq->pd = pd;
1064 srq->uobject = uobj; 1116 srq->uobject = &uobj->uobject;
1065 srq->event_handler = attr.event_handler; 1117 srq->event_handler = attr.event_handler;
1066 srq->srq_context = attr.srq_context; 1118 srq->srq_context = attr.srq_context;
1067 atomic_inc(&pd->usecnt); 1119 atomic_inc(&pd->usecnt);
@@ -1075,17 +1127,17 @@ retry:
1075 goto err_destroy; 1127 goto err_destroy;
1076 } 1128 }
1077 1129
1078 ret = idr_get_new(&ib_uverbs_srq_idr, srq, &uobj->id); 1130 ret = idr_get_new(&ib_uverbs_srq_idr, srq, &uobj->uobject.id);
1079 1131
1080 if (ret == -EAGAIN) 1132 if (ret == -EAGAIN)
1081 goto retry; 1133 goto retry;
1082 if (ret) 1134 if (ret)
1083 goto err_destroy; 1135 goto err_destroy;
1084 1136
1085 resp.srq_handle = uobj->id; 1137 resp.srq_handle = uobj->uobject.id;
1086 1138
1087 spin_lock_irq(&file->ucontext->lock); 1139 spin_lock_irq(&file->ucontext->lock);
1088 list_add_tail(&uobj->list, &file->ucontext->srq_list); 1140 list_add_tail(&uobj->uobject.list, &file->ucontext->srq_list);
1089 spin_unlock_irq(&file->ucontext->lock); 1141 spin_unlock_irq(&file->ucontext->lock);
1090 1142
1091 if (copy_to_user((void __user *) (unsigned long) cmd.response, 1143 if (copy_to_user((void __user *) (unsigned long) cmd.response,
@@ -1100,7 +1152,7 @@ retry:
1100 1152
1101err_list: 1153err_list:
1102 spin_lock_irq(&file->ucontext->lock); 1154 spin_lock_irq(&file->ucontext->lock);
1103 list_del(&uobj->list); 1155 list_del(&uobj->uobject.list);
1104 spin_unlock_irq(&file->ucontext->lock); 1156 spin_unlock_irq(&file->ucontext->lock);
1105 1157
1106err_destroy: 1158err_destroy:
@@ -1149,21 +1201,25 @@ ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file,
1149 const char __user *buf, int in_len, 1201 const char __user *buf, int in_len,
1150 int out_len) 1202 int out_len)
1151{ 1203{
1152 struct ib_uverbs_destroy_srq cmd; 1204 struct ib_uverbs_destroy_srq cmd;
1153 struct ib_srq *srq; 1205 struct ib_uverbs_destroy_srq_resp resp;
1154 struct ib_uobject *uobj; 1206 struct ib_srq *srq;
1155 int ret = -EINVAL; 1207 struct ib_uevent_object *uobj;
1208 struct ib_uverbs_event *evt, *tmp;
1209 int ret = -EINVAL;
1156 1210
1157 if (copy_from_user(&cmd, buf, sizeof cmd)) 1211 if (copy_from_user(&cmd, buf, sizeof cmd))
1158 return -EFAULT; 1212 return -EFAULT;
1159 1213
1160 down(&ib_uverbs_idr_mutex); 1214 down(&ib_uverbs_idr_mutex);
1161 1215
1216 memset(&resp, 0, sizeof resp);
1217
1162 srq = idr_find(&ib_uverbs_srq_idr, cmd.srq_handle); 1218 srq = idr_find(&ib_uverbs_srq_idr, cmd.srq_handle);
1163 if (!srq || srq->uobject->context != file->ucontext) 1219 if (!srq || srq->uobject->context != file->ucontext)
1164 goto out; 1220 goto out;
1165 1221
1166 uobj = srq->uobject; 1222 uobj = container_of(srq->uobject, struct ib_uevent_object, uobject);
1167 1223
1168 ret = ib_destroy_srq(srq); 1224 ret = ib_destroy_srq(srq);
1169 if (ret) 1225 if (ret)
@@ -1172,11 +1228,24 @@ ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file,
1172 idr_remove(&ib_uverbs_srq_idr, cmd.srq_handle); 1228 idr_remove(&ib_uverbs_srq_idr, cmd.srq_handle);
1173 1229
1174 spin_lock_irq(&file->ucontext->lock); 1230 spin_lock_irq(&file->ucontext->lock);
1175 list_del(&uobj->list); 1231 list_del(&uobj->uobject.list);
1176 spin_unlock_irq(&file->ucontext->lock); 1232 spin_unlock_irq(&file->ucontext->lock);
1177 1233
1234 spin_lock_irq(&file->async_file.lock);
1235 list_for_each_entry_safe(evt, tmp, &uobj->event_list, obj_list) {
1236 list_del(&evt->list);
1237 kfree(evt);
1238 }
1239 spin_unlock_irq(&file->async_file.lock);
1240
1241 resp.events_reported = uobj->events_reported;
1242
1178 kfree(uobj); 1243 kfree(uobj);
1179 1244
1245 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1246 &resp, sizeof resp))
1247 ret = -EFAULT;
1248
1180out: 1249out:
1181 up(&ib_uverbs_idr_mutex); 1250 up(&ib_uverbs_idr_mutex);
1182 1251
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index 09caf5b1ef..ce5bdb7af3 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -120,7 +120,7 @@ static int ib_dealloc_ucontext(struct ib_ucontext *context)
120 idr_remove(&ib_uverbs_qp_idr, uobj->id); 120 idr_remove(&ib_uverbs_qp_idr, uobj->id);
121 ib_destroy_qp(qp); 121 ib_destroy_qp(qp);
122 list_del(&uobj->list); 122 list_del(&uobj->list);
123 kfree(uobj); 123 kfree(container_of(uobj, struct ib_uevent_object, uobject));
124 } 124 }
125 125
126 list_for_each_entry_safe(uobj, tmp, &context->cq_list, list) { 126 list_for_each_entry_safe(uobj, tmp, &context->cq_list, list) {
@@ -128,7 +128,7 @@ static int ib_dealloc_ucontext(struct ib_ucontext *context)
128 idr_remove(&ib_uverbs_cq_idr, uobj->id); 128 idr_remove(&ib_uverbs_cq_idr, uobj->id);
129 ib_destroy_cq(cq); 129 ib_destroy_cq(cq);
130 list_del(&uobj->list); 130 list_del(&uobj->list);
131 kfree(uobj); 131 kfree(container_of(uobj, struct ib_ucq_object, uobject));
132 } 132 }
133 133
134 list_for_each_entry_safe(uobj, tmp, &context->srq_list, list) { 134 list_for_each_entry_safe(uobj, tmp, &context->srq_list, list) {
@@ -136,7 +136,7 @@ static int ib_dealloc_ucontext(struct ib_ucontext *context)
136 idr_remove(&ib_uverbs_srq_idr, uobj->id); 136 idr_remove(&ib_uverbs_srq_idr, uobj->id);
137 ib_destroy_srq(srq); 137 ib_destroy_srq(srq);
138 list_del(&uobj->list); 138 list_del(&uobj->list);
139 kfree(uobj); 139 kfree(container_of(uobj, struct ib_uevent_object, uobject));
140 } 140 }
141 141
142 /* XXX Free MWs */ 142 /* XXX Free MWs */
@@ -182,7 +182,7 @@ static ssize_t ib_uverbs_event_read(struct file *filp, char __user *buf,
182 size_t count, loff_t *pos) 182 size_t count, loff_t *pos)
183{ 183{
184 struct ib_uverbs_event_file *file = filp->private_data; 184 struct ib_uverbs_event_file *file = filp->private_data;
185 void *event; 185 struct ib_uverbs_event *event;
186 int eventsz; 186 int eventsz;
187 int ret = 0; 187 int ret = 0;
188 188
@@ -207,21 +207,23 @@ static ssize_t ib_uverbs_event_read(struct file *filp, char __user *buf,
207 return -ENODEV; 207 return -ENODEV;
208 } 208 }
209 209
210 if (file->is_async) { 210 event = list_entry(file->event_list.next, struct ib_uverbs_event, list);
211 event = list_entry(file->event_list.next, 211
212 struct ib_uverbs_async_event, list); 212 if (file->is_async)
213 eventsz = sizeof (struct ib_uverbs_async_event_desc); 213 eventsz = sizeof (struct ib_uverbs_async_event_desc);
214 } else { 214 else
215 event = list_entry(file->event_list.next,
216 struct ib_uverbs_comp_event, list);
217 eventsz = sizeof (struct ib_uverbs_comp_event_desc); 215 eventsz = sizeof (struct ib_uverbs_comp_event_desc);
218 }
219 216
220 if (eventsz > count) { 217 if (eventsz > count) {
221 ret = -EINVAL; 218 ret = -EINVAL;
222 event = NULL; 219 event = NULL;
223 } else 220 } else {
224 list_del(file->event_list.next); 221 list_del(file->event_list.next);
222 if (event->counter) {
223 ++(*event->counter);
224 list_del(&event->obj_list);
225 }
226 }
225 227
226 spin_unlock_irq(&file->lock); 228 spin_unlock_irq(&file->lock);
227 229
@@ -257,16 +259,13 @@ static unsigned int ib_uverbs_event_poll(struct file *filp,
257 259
258static void ib_uverbs_event_release(struct ib_uverbs_event_file *file) 260static void ib_uverbs_event_release(struct ib_uverbs_event_file *file)
259{ 261{
260 struct list_head *entry, *tmp; 262 struct ib_uverbs_event *entry, *tmp;
261 263
262 spin_lock_irq(&file->lock); 264 spin_lock_irq(&file->lock);
263 if (file->fd != -1) { 265 if (file->fd != -1) {
264 file->fd = -1; 266 file->fd = -1;
265 list_for_each_safe(entry, tmp, &file->event_list) 267 list_for_each_entry_safe(entry, tmp, &file->event_list, list)
266 if (file->is_async) 268 kfree(entry);
267 kfree(list_entry(entry, struct ib_uverbs_async_event, list));
268 else
269 kfree(list_entry(entry, struct ib_uverbs_comp_event, list));
270 } 269 }
271 spin_unlock_irq(&file->lock); 270 spin_unlock_irq(&file->lock);
272} 271}
@@ -304,18 +303,23 @@ static struct file_operations uverbs_event_fops = {
304 303
305void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context) 304void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context)
306{ 305{
307 struct ib_uverbs_file *file = cq_context; 306 struct ib_uverbs_file *file = cq_context;
308 struct ib_uverbs_comp_event *entry; 307 struct ib_ucq_object *uobj;
309 unsigned long flags; 308 struct ib_uverbs_event *entry;
309 unsigned long flags;
310 310
311 entry = kmalloc(sizeof *entry, GFP_ATOMIC); 311 entry = kmalloc(sizeof *entry, GFP_ATOMIC);
312 if (!entry) 312 if (!entry)
313 return; 313 return;
314 314
315 entry->desc.cq_handle = cq->uobject->user_handle; 315 uobj = container_of(cq->uobject, struct ib_ucq_object, uobject);
316
317 entry->desc.comp.cq_handle = cq->uobject->user_handle;
318 entry->counter = &uobj->comp_events_reported;
316 319
317 spin_lock_irqsave(&file->comp_file[0].lock, flags); 320 spin_lock_irqsave(&file->comp_file[0].lock, flags);
318 list_add_tail(&entry->list, &file->comp_file[0].event_list); 321 list_add_tail(&entry->list, &file->comp_file[0].event_list);
322 list_add_tail(&entry->obj_list, &uobj->comp_list);
319 spin_unlock_irqrestore(&file->comp_file[0].lock, flags); 323 spin_unlock_irqrestore(&file->comp_file[0].lock, flags);
320 324
321 wake_up_interruptible(&file->comp_file[0].poll_wait); 325 wake_up_interruptible(&file->comp_file[0].poll_wait);
@@ -323,20 +327,25 @@ void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context)
323} 327}
324 328
325static void ib_uverbs_async_handler(struct ib_uverbs_file *file, 329static void ib_uverbs_async_handler(struct ib_uverbs_file *file,
326 __u64 element, __u64 event) 330 __u64 element, __u64 event,
331 struct list_head *obj_list,
332 u32 *counter)
327{ 333{
328 struct ib_uverbs_async_event *entry; 334 struct ib_uverbs_event *entry;
329 unsigned long flags; 335 unsigned long flags;
330 336
331 entry = kmalloc(sizeof *entry, GFP_ATOMIC); 337 entry = kmalloc(sizeof *entry, GFP_ATOMIC);
332 if (!entry) 338 if (!entry)
333 return; 339 return;
334 340
335 entry->desc.element = element; 341 entry->desc.async.element = element;
336 entry->desc.event_type = event; 342 entry->desc.async.event_type = event;
343 entry->counter = counter;
337 344
338 spin_lock_irqsave(&file->async_file.lock, flags); 345 spin_lock_irqsave(&file->async_file.lock, flags);
339 list_add_tail(&entry->list, &file->async_file.event_list); 346 list_add_tail(&entry->list, &file->async_file.event_list);
347 if (obj_list)
348 list_add_tail(&entry->obj_list, obj_list);
340 spin_unlock_irqrestore(&file->async_file.lock, flags); 349 spin_unlock_irqrestore(&file->async_file.lock, flags);
341 350
342 wake_up_interruptible(&file->async_file.poll_wait); 351 wake_up_interruptible(&file->async_file.poll_wait);
@@ -345,23 +354,39 @@ static void ib_uverbs_async_handler(struct ib_uverbs_file *file,
345 354
346void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr) 355void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr)
347{ 356{
348 ib_uverbs_async_handler(context_ptr, 357 struct ib_ucq_object *uobj;
349 event->element.cq->uobject->user_handle, 358
350 event->event); 359 uobj = container_of(event->element.cq->uobject,
360 struct ib_ucq_object, uobject);
361
362 ib_uverbs_async_handler(context_ptr, uobj->uobject.user_handle,
363 event->event, &uobj->async_list,
364 &uobj->async_events_reported);
365
351} 366}
352 367
353void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr) 368void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr)
354{ 369{
355 ib_uverbs_async_handler(context_ptr, 370 struct ib_uevent_object *uobj;
356 event->element.qp->uobject->user_handle, 371
357 event->event); 372 uobj = container_of(event->element.qp->uobject,
373 struct ib_uevent_object, uobject);
374
375 ib_uverbs_async_handler(context_ptr, uobj->uobject.user_handle,
376 event->event, &uobj->event_list,
377 &uobj->events_reported);
358} 378}
359 379
360void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr) 380void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr)
361{ 381{
362 ib_uverbs_async_handler(context_ptr, 382 struct ib_uevent_object *uobj;
363 event->element.srq->uobject->user_handle, 383
364 event->event); 384 uobj = container_of(event->element.srq->uobject,
385 struct ib_uevent_object, uobject);
386
387 ib_uverbs_async_handler(context_ptr, uobj->uobject.user_handle,
388 event->event, &uobj->event_list,
389 &uobj->events_reported);
365} 390}
366 391
367static void ib_uverbs_event_handler(struct ib_event_handler *handler, 392static void ib_uverbs_event_handler(struct ib_event_handler *handler,
@@ -370,7 +395,8 @@ static void ib_uverbs_event_handler(struct ib_event_handler *handler,
370 struct ib_uverbs_file *file = 395 struct ib_uverbs_file *file =
371 container_of(handler, struct ib_uverbs_file, event_handler); 396 container_of(handler, struct ib_uverbs_file, event_handler);
372 397
373 ib_uverbs_async_handler(file, event->element.port_num, event->event); 398 ib_uverbs_async_handler(file, event->element.port_num, event->event,
399 NULL, NULL);
374} 400}
375 401
376static int ib_uverbs_event_init(struct ib_uverbs_event_file *file, 402static int ib_uverbs_event_init(struct ib_uverbs_event_file *file,
diff --git a/drivers/infiniband/hw/mthca/mthca_qp.c b/drivers/infiniband/hw/mthca/mthca_qp.c
index 0164b84d4e..bcef06bf15 100644
--- a/drivers/infiniband/hw/mthca/mthca_qp.c
+++ b/drivers/infiniband/hw/mthca/mthca_qp.c
@@ -220,6 +220,16 @@ static void *get_send_wqe(struct mthca_qp *qp, int n)
220 (PAGE_SIZE - 1)); 220 (PAGE_SIZE - 1));
221} 221}
222 222
223static void mthca_wq_init(struct mthca_wq *wq)
224{
225 spin_lock_init(&wq->lock);
226 wq->next_ind = 0;
227 wq->last_comp = wq->max - 1;
228 wq->head = 0;
229 wq->tail = 0;
230 wq->last = NULL;
231}
232
223void mthca_qp_event(struct mthca_dev *dev, u32 qpn, 233void mthca_qp_event(struct mthca_dev *dev, u32 qpn,
224 enum ib_event_type event_type) 234 enum ib_event_type event_type)
225{ 235{
@@ -833,8 +843,8 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
833 store_attrs(to_msqp(qp), attr, attr_mask); 843 store_attrs(to_msqp(qp), attr, attr_mask);
834 844
835 /* 845 /*
836 * If we are moving QP0 to RTR, bring the IB link up; if we 846 * If we moved QP0 to RTR, bring the IB link up; if we moved
837 * are moving QP0 to RESET or ERROR, bring the link back down. 847 * QP0 to RESET or ERROR, bring the link back down.
838 */ 848 */
839 if (is_qp0(dev, qp)) { 849 if (is_qp0(dev, qp)) {
840 if (cur_state != IB_QPS_RTR && 850 if (cur_state != IB_QPS_RTR &&
@@ -848,6 +858,26 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
848 mthca_CLOSE_IB(dev, to_msqp(qp)->port, &status); 858 mthca_CLOSE_IB(dev, to_msqp(qp)->port, &status);
849 } 859 }
850 860
861 /*
862 * If we moved a kernel QP to RESET, clean up all old CQ
863 * entries and reinitialize the QP.
864 */
865 if (!err && new_state == IB_QPS_RESET && !qp->ibqp.uobject) {
866 mthca_cq_clean(dev, to_mcq(qp->ibqp.send_cq)->cqn, qp->qpn,
867 qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL);
868 if (qp->ibqp.send_cq != qp->ibqp.recv_cq)
869 mthca_cq_clean(dev, to_mcq(qp->ibqp.recv_cq)->cqn, qp->qpn,
870 qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL);
871
872 mthca_wq_init(&qp->sq);
873 mthca_wq_init(&qp->rq);
874
875 if (mthca_is_memfree(dev)) {
876 *qp->sq.db = 0;
877 *qp->rq.db = 0;
878 }
879 }
880
851 return err; 881 return err;
852} 882}
853 883
@@ -1003,16 +1033,6 @@ static void mthca_free_memfree(struct mthca_dev *dev,
1003 } 1033 }
1004} 1034}
1005 1035
1006static void mthca_wq_init(struct mthca_wq* wq)
1007{
1008 spin_lock_init(&wq->lock);
1009 wq->next_ind = 0;
1010 wq->last_comp = wq->max - 1;
1011 wq->head = 0;
1012 wq->tail = 0;
1013 wq->last = NULL;
1014}
1015
1016static int mthca_alloc_qp_common(struct mthca_dev *dev, 1036static int mthca_alloc_qp_common(struct mthca_dev *dev,
1017 struct mthca_pd *pd, 1037 struct mthca_pd *pd,
1018 struct mthca_cq *send_cq, 1038 struct mthca_cq *send_cq,
@@ -1024,6 +1044,7 @@ static int mthca_alloc_qp_common(struct mthca_dev *dev,
1024 int i; 1044 int i;
1025 1045
1026 atomic_set(&qp->refcount, 1); 1046 atomic_set(&qp->refcount, 1);
1047 init_waitqueue_head(&qp->wait);
1027 qp->state = IB_QPS_RESET; 1048 qp->state = IB_QPS_RESET;
1028 qp->atomic_rd_en = 0; 1049 qp->atomic_rd_en = 0;
1029 qp->resp_depth = 0; 1050 qp->resp_depth = 0;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 0e8ac138e3..49d120d2b9 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -1062,6 +1062,8 @@ static void ipoib_remove_one(struct ib_device *device)
1062 ipoib_dev_cleanup(priv->dev); 1062 ipoib_dev_cleanup(priv->dev);
1063 free_netdev(priv->dev); 1063 free_netdev(priv->dev);
1064 } 1064 }
1065
1066 kfree(dev_list);
1065} 1067}
1066 1068
1067static int __init ipoib_init_module(void) 1069static int __init ipoib_init_module(void)
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 19c14c4beb..3738d173f9 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -322,7 +322,7 @@ static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
322 if (t < 0 || t >= dev->keycodemax || !dev->keycodesize) return -EINVAL; 322 if (t < 0 || t >= dev->keycodemax || !dev->keycodesize) return -EINVAL;
323 if (get_user(v, ip + 1)) return -EFAULT; 323 if (get_user(v, ip + 1)) return -EFAULT;
324 if (v < 0 || v > KEY_MAX) return -EINVAL; 324 if (v < 0 || v > KEY_MAX) return -EINVAL;
325 if (v >> (dev->keycodesize * 8)) return -EINVAL; 325 if (dev->keycodesize < sizeof(v) && (v >> (dev->keycodesize * 8))) return -EINVAL;
326 u = SET_INPUT_KEYCODE(dev, t, v); 326 u = SET_INPUT_KEYCODE(dev, t, v);
327 clear_bit(u, dev->keybit); 327 clear_bit(u, dev->keybit);
328 set_bit(v, dev->keybit); 328 set_bit(v, dev->keybit);
@@ -509,7 +509,7 @@ do { \
509 int len = NBITS_COMPAT((max)) * sizeof(compat_long_t); \ 509 int len = NBITS_COMPAT((max)) * sizeof(compat_long_t); \
510 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); \ 510 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); \
511 for (i = 0; i < len / sizeof(compat_long_t); i++) \ 511 for (i = 0; i < len / sizeof(compat_long_t); i++) \
512 if (copy_to_user((compat_long_t*) p + i, \ 512 if (copy_to_user((compat_long_t __user *) p + i, \
513 (compat_long_t*) (bit) + i + 1 - ((i % 2) << 1), \ 513 (compat_long_t*) (bit) + i + 1 - ((i % 2) << 1), \
514 sizeof(compat_long_t))) \ 514 sizeof(compat_long_t))) \
515 return -EFAULT; \ 515 return -EFAULT; \
diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c
index 58728ebaaf..e5a31e55d3 100644
--- a/drivers/input/joystick/iforce/iforce-packets.c
+++ b/drivers/input/joystick/iforce/iforce-packets.c
@@ -249,9 +249,6 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data,
249 249
250int iforce_get_id_packet(struct iforce *iforce, char *packet) 250int iforce_get_id_packet(struct iforce *iforce, char *packet)
251{ 251{
252 DECLARE_WAITQUEUE(wait, current);
253 int timeout = HZ; /* 1 second */
254
255 switch (iforce->bus) { 252 switch (iforce->bus) {
256 253
257 case IFORCE_USB: 254 case IFORCE_USB:
@@ -260,22 +257,13 @@ int iforce_get_id_packet(struct iforce *iforce, char *packet)
260 iforce->cr.bRequest = packet[0]; 257 iforce->cr.bRequest = packet[0];
261 iforce->ctrl->dev = iforce->usbdev; 258 iforce->ctrl->dev = iforce->usbdev;
262 259
263 set_current_state(TASK_INTERRUPTIBLE); 260 if (usb_submit_urb(iforce->ctrl, GFP_ATOMIC))
264 add_wait_queue(&iforce->wait, &wait);
265
266 if (usb_submit_urb(iforce->ctrl, GFP_ATOMIC)) {
267 set_current_state(TASK_RUNNING);
268 remove_wait_queue(&iforce->wait, &wait);
269 return -1; 261 return -1;
270 }
271 262
272 while (timeout && iforce->ctrl->status == -EINPROGRESS) 263 wait_event_interruptible_timeout(iforce->wait,
273 timeout = schedule_timeout(timeout); 264 iforce->ctrl->status != -EINPROGRESS, HZ);
274 265
275 set_current_state(TASK_RUNNING); 266 if (iforce->ctrl->status != -EINPROGRESS) {
276 remove_wait_queue(&iforce->wait, &wait);
277
278 if (!timeout) {
279 usb_unlink_urb(iforce->ctrl); 267 usb_unlink_urb(iforce->ctrl);
280 return -1; 268 return -1;
281 } 269 }
@@ -290,16 +278,10 @@ int iforce_get_id_packet(struct iforce *iforce, char *packet)
290 iforce->expect_packet = FF_CMD_QUERY; 278 iforce->expect_packet = FF_CMD_QUERY;
291 iforce_send_packet(iforce, FF_CMD_QUERY, packet); 279 iforce_send_packet(iforce, FF_CMD_QUERY, packet);
292 280
293 set_current_state(TASK_INTERRUPTIBLE); 281 wait_event_interruptible_timeout(iforce->wait,
294 add_wait_queue(&iforce->wait, &wait); 282 !iforce->expect_packet, HZ);
295
296 while (timeout && iforce->expect_packet)
297 timeout = schedule_timeout(timeout);
298
299 set_current_state(TASK_RUNNING);
300 remove_wait_queue(&iforce->wait, &wait);
301 283
302 if (!timeout) { 284 if (iforce->expect_packet) {
303 iforce->expect_packet = 0; 285 iforce->expect_packet = 0;
304 return -1; 286 return -1;
305 } 287 }
diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c
index 6369a24684..58600f91ef 100644
--- a/drivers/input/joystick/iforce/iforce-usb.c
+++ b/drivers/input/joystick/iforce/iforce-usb.c
@@ -95,6 +95,7 @@ static void iforce_usb_irq(struct urb *urb, struct pt_regs *regs)
95 goto exit; 95 goto exit;
96 } 96 }
97 97
98 wake_up(&iforce->wait);
98 iforce_process_packet(iforce, 99 iforce_process_packet(iforce,
99 (iforce->data[0] << 8) | (urb->actual_length - 1), iforce->data + 1, regs); 100 (iforce->data[0] << 8) | (urb->actual_length - 1), iforce->data + 1, regs);
100 101
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index 4d4985b59a..1ad8c2ee7d 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -208,6 +208,7 @@ struct atkbd {
208 unsigned char resend; 208 unsigned char resend;
209 unsigned char release; 209 unsigned char release;
210 unsigned char bat_xl; 210 unsigned char bat_xl;
211 unsigned char err_xl;
211 unsigned int last; 212 unsigned int last;
212 unsigned long time; 213 unsigned long time;
213}; 214};
@@ -296,15 +297,18 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
296 if (atkbd->emul || 297 if (atkbd->emul ||
297 !(code == ATKBD_RET_EMUL0 || code == ATKBD_RET_EMUL1 || 298 !(code == ATKBD_RET_EMUL0 || code == ATKBD_RET_EMUL1 ||
298 code == ATKBD_RET_HANGUEL || code == ATKBD_RET_HANJA || 299 code == ATKBD_RET_HANGUEL || code == ATKBD_RET_HANJA ||
299 code == ATKBD_RET_ERR || 300 (code == ATKBD_RET_ERR && !atkbd->err_xl) ||
300 (code == ATKBD_RET_BAT && !atkbd->bat_xl))) { 301 (code == ATKBD_RET_BAT && !atkbd->bat_xl))) {
301 atkbd->release = code >> 7; 302 atkbd->release = code >> 7;
302 code &= 0x7f; 303 code &= 0x7f;
303 } 304 }
304 305
305 if (!atkbd->emul && 306 if (!atkbd->emul) {
306 (code & 0x7f) == (ATKBD_RET_BAT & 0x7f)) 307 if ((code & 0x7f) == (ATKBD_RET_BAT & 0x7f))
307 atkbd->bat_xl = !atkbd->release; 308 atkbd->bat_xl = !atkbd->release;
309 if ((code & 0x7f) == (ATKBD_RET_ERR & 0x7f))
310 atkbd->err_xl = !atkbd->release;
311 }
308 } 312 }
309 313
310 switch (code) { 314 switch (code) {
diff --git a/drivers/input/keyboard/sunkbd.c b/drivers/input/keyboard/sunkbd.c
index 596964ceb9..4bae5d8934 100644
--- a/drivers/input/keyboard/sunkbd.c
+++ b/drivers/input/keyboard/sunkbd.c
@@ -44,7 +44,7 @@ MODULE_DESCRIPTION(DRIVER_DESC);
44MODULE_LICENSE("GPL"); 44MODULE_LICENSE("GPL");
45 45
46static unsigned char sunkbd_keycode[128] = { 46static unsigned char sunkbd_keycode[128] = {
47 0,128,114,129,115, 59, 60, 68, 61, 87, 62, 88, 63,100, 64, 0, 47 0,128,114,129,115, 59, 60, 68, 61, 87, 62, 88, 63,100, 64,112,
48 65, 66, 67, 56,103,119, 99, 70,105,130,131,108,106, 1, 2, 3, 48 65, 66, 67, 56,103,119, 99, 70,105,130,131,108,106, 1, 2, 3,
49 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 41, 14,110,113, 98, 55, 49 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 41, 14,110,113, 98, 55,
50 116,132, 83,133,102, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 50 116,132, 83,133,102, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index c4909b4933..82b330bbf0 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -15,4 +15,4 @@ obj-$(CONFIG_MOUSE_SERIAL) += sermouse.o
15obj-$(CONFIG_MOUSE_HIL) += hil_ptr.o 15obj-$(CONFIG_MOUSE_HIL) += hil_ptr.o
16obj-$(CONFIG_MOUSE_VSXXXAA) += vsxxxaa.o 16obj-$(CONFIG_MOUSE_VSXXXAA) += vsxxxaa.o
17 17
18psmouse-objs := psmouse-base.o alps.o logips2pp.o synaptics.o lifebook.o 18psmouse-objs := psmouse-base.o alps.o logips2pp.o synaptics.o lifebook.o trackpoint.o
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 0d68e5e018..b20783f974 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -170,7 +170,7 @@ static void alps_process_packet(struct psmouse *psmouse, struct pt_regs *regs)
170 input_report_key(dev, BTN_TOOL_FINGER, z > 0); 170 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
171 171
172 if (priv->i->flags & ALPS_WHEEL) 172 if (priv->i->flags & ALPS_WHEEL)
173 input_report_rel(dev, REL_WHEEL, ((packet[0] >> 4) & 0x07) | ((packet[2] >> 2) & 0x08)); 173 input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07));
174 174
175 if (priv->i->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) { 175 if (priv->i->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
176 input_report_key(dev, BTN_FORWARD, forward); 176 input_report_key(dev, BTN_FORWARD, forward);
diff --git a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
index 48d2b20d26..7df9652522 100644
--- a/drivers/input/mouse/logips2pp.c
+++ b/drivers/input/mouse/logips2pp.c
@@ -150,12 +150,12 @@ static void ps2pp_set_smartscroll(struct psmouse *psmouse, unsigned int smartscr
150 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); 150 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
151} 151}
152 152
153static ssize_t psmouse_attr_show_smartscroll(struct psmouse *psmouse, char *buf) 153static ssize_t ps2pp_attr_show_smartscroll(struct psmouse *psmouse, void *data, char *buf)
154{ 154{
155 return sprintf(buf, "%d\n", psmouse->smartscroll ? 1 : 0); 155 return sprintf(buf, "%d\n", psmouse->smartscroll ? 1 : 0);
156} 156}
157 157
158static ssize_t psmouse_attr_set_smartscroll(struct psmouse *psmouse, const char *buf, size_t count) 158static ssize_t ps2pp_attr_set_smartscroll(struct psmouse *psmouse, void *data, const char *buf, size_t count)
159{ 159{
160 unsigned long value; 160 unsigned long value;
161 char *rest; 161 char *rest;
@@ -169,7 +169,8 @@ static ssize_t psmouse_attr_set_smartscroll(struct psmouse *psmouse, const char
169 return count; 169 return count;
170} 170}
171 171
172PSMOUSE_DEFINE_ATTR(smartscroll); 172PSMOUSE_DEFINE_ATTR(smartscroll, S_IWUSR | S_IRUGO, NULL,
173 ps2pp_attr_show_smartscroll, ps2pp_attr_set_smartscroll);
173 174
174/* 175/*
175 * Support 800 dpi resolution _only_ if the user wants it (there are good 176 * Support 800 dpi resolution _only_ if the user wants it (there are good
@@ -194,7 +195,7 @@ static void ps2pp_set_resolution(struct psmouse *psmouse, unsigned int resolutio
194 195
195static void ps2pp_disconnect(struct psmouse *psmouse) 196static void ps2pp_disconnect(struct psmouse *psmouse)
196{ 197{
197 device_remove_file(&psmouse->ps2dev.serio->dev, &psmouse_attr_smartscroll); 198 device_remove_file(&psmouse->ps2dev.serio->dev, &psmouse_attr_smartscroll.dattr);
198} 199}
199 200
200static struct ps2pp_info *get_model_info(unsigned char model) 201static struct ps2pp_info *get_model_info(unsigned char model)
@@ -222,6 +223,7 @@ static struct ps2pp_info *get_model_info(unsigned char model)
222 { 80, PS2PP_KIND_WHEEL, PS2PP_SIDE_BTN | PS2PP_WHEEL }, 223 { 80, PS2PP_KIND_WHEEL, PS2PP_SIDE_BTN | PS2PP_WHEEL },
223 { 81, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, 224 { 81, PS2PP_KIND_WHEEL, PS2PP_WHEEL },
224 { 83, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, 225 { 83, PS2PP_KIND_WHEEL, PS2PP_WHEEL },
226 { 86, PS2PP_KIND_WHEEL, PS2PP_WHEEL },
225 { 88, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, 227 { 88, PS2PP_KIND_WHEEL, PS2PP_WHEEL },
226 { 96, 0, 0 }, 228 { 96, 0, 0 },
227 { 97, PS2PP_KIND_TP3, PS2PP_WHEEL | PS2PP_HWHEEL }, 229 { 97, PS2PP_KIND_TP3, PS2PP_WHEEL | PS2PP_HWHEEL },
@@ -379,7 +381,8 @@ int ps2pp_init(struct psmouse *psmouse, int set_properties)
379 psmouse->set_resolution = ps2pp_set_resolution; 381 psmouse->set_resolution = ps2pp_set_resolution;
380 psmouse->disconnect = ps2pp_disconnect; 382 psmouse->disconnect = ps2pp_disconnect;
381 383
382 device_create_file(&psmouse->ps2dev.serio->dev, &psmouse_attr_smartscroll); 384 device_create_file(&psmouse->ps2dev.serio->dev,
385 &psmouse_attr_smartscroll.dattr);
383 } 386 }
384 } 387 }
385 388
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 12bdd3eff9..af24313ff5 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -25,6 +25,7 @@
25#include "logips2pp.h" 25#include "logips2pp.h"
26#include "alps.h" 26#include "alps.h"
27#include "lifebook.h" 27#include "lifebook.h"
28#include "trackpoint.h"
28 29
29#define DRIVER_DESC "PS/2 mouse driver" 30#define DRIVER_DESC "PS/2 mouse driver"
30 31
@@ -57,10 +58,30 @@ static unsigned int psmouse_resetafter;
57module_param_named(resetafter, psmouse_resetafter, uint, 0644); 58module_param_named(resetafter, psmouse_resetafter, uint, 0644);
58MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never)."); 59MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never).");
59 60
60PSMOUSE_DEFINE_ATTR(protocol); 61PSMOUSE_DEFINE_ATTR(protocol, S_IWUSR | S_IRUGO,
61PSMOUSE_DEFINE_ATTR(rate); 62 NULL,
62PSMOUSE_DEFINE_ATTR(resolution); 63 psmouse_attr_show_protocol, psmouse_attr_set_protocol);
63PSMOUSE_DEFINE_ATTR(resetafter); 64PSMOUSE_DEFINE_ATTR(rate, S_IWUSR | S_IRUGO,
65 (void *) offsetof(struct psmouse, rate),
66 psmouse_show_int_attr, psmouse_attr_set_rate);
67PSMOUSE_DEFINE_ATTR(resolution, S_IWUSR | S_IRUGO,
68 (void *) offsetof(struct psmouse, resolution),
69 psmouse_show_int_attr, psmouse_attr_set_resolution);
70PSMOUSE_DEFINE_ATTR(resetafter, S_IWUSR | S_IRUGO,
71 (void *) offsetof(struct psmouse, resetafter),
72 psmouse_show_int_attr, psmouse_set_int_attr);
73
74static struct attribute *psmouse_attributes[] = {
75 &psmouse_attr_protocol.dattr.attr,
76 &psmouse_attr_rate.dattr.attr,
77 &psmouse_attr_resolution.dattr.attr,
78 &psmouse_attr_resetafter.dattr.attr,
79 NULL
80};
81
82static struct attribute_group psmouse_attribute_group = {
83 .attrs = psmouse_attributes,
84};
64 85
65__obsolete_setup("psmouse_noext"); 86__obsolete_setup("psmouse_noext");
66__obsolete_setup("psmouse_resolution="); 87__obsolete_setup("psmouse_resolution=");
@@ -520,6 +541,12 @@ static int psmouse_extensions(struct psmouse *psmouse,
520 return PSMOUSE_IMPS; 541 return PSMOUSE_IMPS;
521 542
522/* 543/*
544 * Try to initialize the IBM TrackPoint
545 */
546 if (max_proto > PSMOUSE_IMEX && trackpoint_detect(psmouse, set_properties) == 0)
547 return PSMOUSE_TRACKPOINT;
548
549/*
523 * Okay, all failed, we have a standard mouse here. The number of the buttons 550 * Okay, all failed, we have a standard mouse here. The number of the buttons
524 * is still a question, though. We assume 3. 551 * is still a question, though. We assume 3.
525 */ 552 */
@@ -600,6 +627,12 @@ static struct psmouse_protocol psmouse_protocols[] = {
600 .init = lifebook_init, 627 .init = lifebook_init,
601 }, 628 },
602 { 629 {
630 .type = PSMOUSE_TRACKPOINT,
631 .name = "TPPS/2",
632 .alias = "trackpoint",
633 .detect = trackpoint_detect,
634 },
635 {
603 .type = PSMOUSE_AUTO, 636 .type = PSMOUSE_AUTO,
604 .name = "auto", 637 .name = "auto",
605 .alias = "any", 638 .alias = "any",
@@ -787,10 +820,7 @@ static void psmouse_disconnect(struct serio *serio)
787 820
788 psmouse = serio_get_drvdata(serio); 821 psmouse = serio_get_drvdata(serio);
789 822
790 device_remove_file(&serio->dev, &psmouse_attr_protocol); 823 sysfs_remove_group(&serio->dev.kobj, &psmouse_attribute_group);
791 device_remove_file(&serio->dev, &psmouse_attr_rate);
792 device_remove_file(&serio->dev, &psmouse_attr_resolution);
793 device_remove_file(&serio->dev, &psmouse_attr_resetafter);
794 824
795 down(&psmouse_sem); 825 down(&psmouse_sem);
796 826
@@ -927,10 +957,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
927 if (parent && parent->pt_activate) 957 if (parent && parent->pt_activate)
928 parent->pt_activate(parent); 958 parent->pt_activate(parent);
929 959
930 device_create_file(&serio->dev, &psmouse_attr_protocol); 960 sysfs_create_group(&serio->dev.kobj, &psmouse_attribute_group);
931 device_create_file(&serio->dev, &psmouse_attr_rate);
932 device_create_file(&serio->dev, &psmouse_attr_resolution);
933 device_create_file(&serio->dev, &psmouse_attr_resetafter);
934 961
935 psmouse_activate(psmouse); 962 psmouse_activate(psmouse);
936 963
@@ -1027,10 +1054,12 @@ static struct serio_driver psmouse_drv = {
1027 .cleanup = psmouse_cleanup, 1054 .cleanup = psmouse_cleanup,
1028}; 1055};
1029 1056
1030ssize_t psmouse_attr_show_helper(struct device *dev, char *buf, 1057ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *devattr,
1031 ssize_t (*handler)(struct psmouse *, char *)) 1058 char *buf)
1032{ 1059{
1033 struct serio *serio = to_serio_port(dev); 1060 struct serio *serio = to_serio_port(dev);
1061 struct psmouse_attribute *attr = to_psmouse_attr(devattr);
1062 struct psmouse *psmouse;
1034 int retval; 1063 int retval;
1035 1064
1036 retval = serio_pin_driver(serio); 1065 retval = serio_pin_driver(serio);
@@ -1042,19 +1071,21 @@ ssize_t psmouse_attr_show_helper(struct device *dev, char *buf,
1042 goto out; 1071 goto out;
1043 } 1072 }
1044 1073
1045 retval = handler(serio_get_drvdata(serio), buf); 1074 psmouse = serio_get_drvdata(serio);
1075
1076 retval = attr->show(psmouse, attr->data, buf);
1046 1077
1047out: 1078out:
1048 serio_unpin_driver(serio); 1079 serio_unpin_driver(serio);
1049 return retval; 1080 return retval;
1050} 1081}
1051 1082
1052ssize_t psmouse_attr_set_helper(struct device *dev, const char *buf, size_t count, 1083ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *devattr,
1053 ssize_t (*handler)(struct psmouse *, const char *, size_t)) 1084 const char *buf, size_t count)
1054{ 1085{
1055 struct serio *serio = to_serio_port(dev); 1086 struct serio *serio = to_serio_port(dev);
1056 struct psmouse *psmouse = serio_get_drvdata(serio); 1087 struct psmouse_attribute *attr = to_psmouse_attr(devattr);
1057 struct psmouse *parent = NULL; 1088 struct psmouse *psmouse, *parent = NULL;
1058 int retval; 1089 int retval;
1059 1090
1060 retval = serio_pin_driver(serio); 1091 retval = serio_pin_driver(serio);
@@ -1070,6 +1101,8 @@ ssize_t psmouse_attr_set_helper(struct device *dev, const char *buf, size_t coun
1070 if (retval) 1101 if (retval)
1071 goto out_unpin; 1102 goto out_unpin;
1072 1103
1104 psmouse = serio_get_drvdata(serio);
1105
1073 if (psmouse->state == PSMOUSE_IGNORE) { 1106 if (psmouse->state == PSMOUSE_IGNORE) {
1074 retval = -ENODEV; 1107 retval = -ENODEV;
1075 goto out_up; 1108 goto out_up;
@@ -1082,7 +1115,7 @@ ssize_t psmouse_attr_set_helper(struct device *dev, const char *buf, size_t coun
1082 1115
1083 psmouse_deactivate(psmouse); 1116 psmouse_deactivate(psmouse);
1084 1117
1085 retval = handler(psmouse, buf, count); 1118 retval = attr->set(psmouse, attr->data, buf, count);
1086 1119
1087 if (retval != -ENODEV) 1120 if (retval != -ENODEV)
1088 psmouse_activate(psmouse); 1121 psmouse_activate(psmouse);
@@ -1097,12 +1130,34 @@ ssize_t psmouse_attr_set_helper(struct device *dev, const char *buf, size_t coun
1097 return retval; 1130 return retval;
1098} 1131}
1099 1132
1100static ssize_t psmouse_attr_show_protocol(struct psmouse *psmouse, char *buf) 1133static ssize_t psmouse_show_int_attr(struct psmouse *psmouse, void *offset, char *buf)
1134{
1135 unsigned long *field = (unsigned long *)((char *)psmouse + (size_t)offset);
1136
1137 return sprintf(buf, "%lu\n", *field);
1138}
1139
1140static ssize_t psmouse_set_int_attr(struct psmouse *psmouse, void *offset, const char *buf, size_t count)
1141{
1142 unsigned long *field = (unsigned long *)((char *)psmouse + (size_t)offset);
1143 unsigned long value;
1144 char *rest;
1145
1146 value = simple_strtoul(buf, &rest, 10);
1147 if (*rest)
1148 return -EINVAL;
1149
1150 *field = value;
1151
1152 return count;
1153}
1154
1155static ssize_t psmouse_attr_show_protocol(struct psmouse *psmouse, void *data, char *buf)
1101{ 1156{
1102 return sprintf(buf, "%s\n", psmouse_protocol_by_type(psmouse->type)->name); 1157 return sprintf(buf, "%s\n", psmouse_protocol_by_type(psmouse->type)->name);
1103} 1158}
1104 1159
1105static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, const char *buf, size_t count) 1160static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, const char *buf, size_t count)
1106{ 1161{
1107 struct serio *serio = psmouse->ps2dev.serio; 1162 struct serio *serio = psmouse->ps2dev.serio;
1108 struct psmouse *parent = NULL; 1163 struct psmouse *parent = NULL;
@@ -1166,12 +1221,7 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, const char *bu
1166 return count; 1221 return count;
1167} 1222}
1168 1223
1169static ssize_t psmouse_attr_show_rate(struct psmouse *psmouse, char *buf) 1224static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const char *buf, size_t count)
1170{
1171 return sprintf(buf, "%d\n", psmouse->rate);
1172}
1173
1174static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, const char *buf, size_t count)
1175{ 1225{
1176 unsigned long value; 1226 unsigned long value;
1177 char *rest; 1227 char *rest;
@@ -1184,12 +1234,7 @@ static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, const char *buf, s
1184 return count; 1234 return count;
1185} 1235}
1186 1236
1187static ssize_t psmouse_attr_show_resolution(struct psmouse *psmouse, char *buf) 1237static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data, const char *buf, size_t count)
1188{
1189 return sprintf(buf, "%d\n", psmouse->resolution);
1190}
1191
1192static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, const char *buf, size_t count)
1193{ 1238{
1194 unsigned long value; 1239 unsigned long value;
1195 char *rest; 1240 char *rest;
@@ -1202,23 +1247,6 @@ static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, const char *
1202 return count; 1247 return count;
1203} 1248}
1204 1249
1205static ssize_t psmouse_attr_show_resetafter(struct psmouse *psmouse, char *buf)
1206{
1207 return sprintf(buf, "%d\n", psmouse->resetafter);
1208}
1209
1210static ssize_t psmouse_attr_set_resetafter(struct psmouse *psmouse, const char *buf, size_t count)
1211{
1212 unsigned long value;
1213 char *rest;
1214
1215 value = simple_strtoul(buf, &rest, 10);
1216 if (*rest)
1217 return -EINVAL;
1218
1219 psmouse->resetafter = value;
1220 return count;
1221}
1222 1250
1223static int psmouse_set_maxproto(const char *val, struct kernel_param *kp) 1251static int psmouse_set_maxproto(const char *val, struct kernel_param *kp)
1224{ 1252{
@@ -1234,7 +1262,7 @@ static int psmouse_set_maxproto(const char *val, struct kernel_param *kp)
1234 1262
1235 *((unsigned int *)kp->arg) = proto->type; 1263 *((unsigned int *)kp->arg) = proto->type;
1236 1264
1237 return 0; \ 1265 return 0;
1238} 1266}
1239 1267
1240static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp) 1268static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp)
diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
index 86691cf434..45d2bd774f 100644
--- a/drivers/input/mouse/psmouse.h
+++ b/drivers/input/mouse/psmouse.h
@@ -78,6 +78,7 @@ enum psmouse_type {
78 PSMOUSE_SYNAPTICS, 78 PSMOUSE_SYNAPTICS,
79 PSMOUSE_ALPS, 79 PSMOUSE_ALPS,
80 PSMOUSE_LIFEBOOK, 80 PSMOUSE_LIFEBOOK,
81 PSMOUSE_TRACKPOINT,
81 PSMOUSE_AUTO /* This one should always be last */ 82 PSMOUSE_AUTO /* This one should always be last */
82}; 83};
83 84
@@ -85,24 +86,37 @@ int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command);
85int psmouse_reset(struct psmouse *psmouse); 86int psmouse_reset(struct psmouse *psmouse);
86void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution); 87void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution);
87 88
88ssize_t psmouse_attr_show_helper(struct device *dev, char *buf, 89
89 ssize_t (*handler)(struct psmouse *, char *)); 90struct psmouse_attribute {
90ssize_t psmouse_attr_set_helper(struct device *dev, const char *buf, size_t count, 91 struct device_attribute dattr;
91 ssize_t (*handler)(struct psmouse *, const char *, size_t)); 92 void *data;
92 93 ssize_t (*show)(struct psmouse *psmouse, void *data, char *buf);
93#define PSMOUSE_DEFINE_ATTR(_name) \ 94 ssize_t (*set)(struct psmouse *psmouse, void *data,
94static ssize_t psmouse_attr_show_##_name(struct psmouse *, char *); \ 95 const char *buf, size_t count);
95static ssize_t psmouse_attr_set_##_name(struct psmouse *, const char *, size_t);\ 96};
96static ssize_t psmouse_do_show_##_name(struct device *d, struct device_attribute *attr, char *b) \ 97#define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
97{ \ 98
98 return psmouse_attr_show_helper(d, b, psmouse_attr_show_##_name); \ 99ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
99} \ 100 char *buf);
100static ssize_t psmouse_do_set_##_name(struct device *d, struct device_attribute *attr, const char *b, size_t s)\ 101ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *attr,
101{ \ 102 const char *buf, size_t count);
102 return psmouse_attr_set_helper(d, b, s, psmouse_attr_set_##_name); \ 103
103} \ 104#define PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set) \
104static struct device_attribute psmouse_attr_##_name = \ 105static ssize_t _show(struct psmouse *, void *data, char *); \
105 __ATTR(_name, S_IWUSR | S_IRUGO, \ 106static ssize_t _set(struct psmouse *, void *data, const char *, size_t); \
106 psmouse_do_show_##_name, psmouse_do_set_##_name); 107static struct psmouse_attribute psmouse_attr_##_name = { \
108 .dattr = { \
109 .attr = { \
110 .name = __stringify(_name), \
111 .mode = _mode, \
112 .owner = THIS_MODULE, \
113 }, \
114 .show = psmouse_attr_show_helper, \
115 .store = psmouse_attr_set_helper, \
116 }, \
117 .data = _data, \
118 .show = _show, \
119 .set = _set, \
120}
107 121
108#endif /* _PSMOUSE_H */ 122#endif /* _PSMOUSE_H */
diff --git a/drivers/input/mouse/trackpoint.c b/drivers/input/mouse/trackpoint.c
new file mode 100644
index 0000000000..b4898d8a68
--- /dev/null
+++ b/drivers/input/mouse/trackpoint.c
@@ -0,0 +1,304 @@
1/*
2 * Stephen Evanchik <evanchsa@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published by
6 * the Free Software Foundation.
7 *
8 * Trademarks are the property of their respective owners.
9 */
10
11#include <linux/delay.h>
12#include <linux/serio.h>
13#include <linux/module.h>
14#include <linux/moduleparam.h>
15#include <linux/input.h>
16#include <linux/libps2.h>
17#include <linux/proc_fs.h>
18#include <asm/uaccess.h>
19#include "psmouse.h"
20#include "trackpoint.h"
21
22/*
23 * Device IO: read, write and toggle bit
24 */
25static int trackpoint_read(struct ps2dev *ps2dev, unsigned char loc, unsigned char *results)
26{
27 if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) ||
28 ps2_command(ps2dev, results, MAKE_PS2_CMD(0, 1, loc))) {
29 return -1;
30 }
31
32 return 0;
33}
34
35static int trackpoint_write(struct ps2dev *ps2dev, unsigned char loc, unsigned char val)
36{
37 if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) ||
38 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_WRITE_MEM)) ||
39 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, loc)) ||
40 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, val))) {
41 return -1;
42 }
43
44 return 0;
45}
46
47static int trackpoint_toggle_bit(struct ps2dev *ps2dev, unsigned char loc, unsigned char mask)
48{
49 /* Bad things will happen if the loc param isn't in this range */
50 if (loc < 0x20 || loc >= 0x2F)
51 return -1;
52
53 if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) ||
54 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_TOGGLE)) ||
55 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, loc)) ||
56 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, mask))) {
57 return -1;
58 }
59
60 return 0;
61}
62
63
64/*
65 * Trackpoint-specific attributes
66 */
67struct trackpoint_attr_data {
68 size_t field_offset;
69 unsigned char command;
70 unsigned char mask;
71};
72
73static ssize_t trackpoint_show_int_attr(struct psmouse *psmouse, void *data, char *buf)
74{
75 struct trackpoint_data *tp = psmouse->private;
76 struct trackpoint_attr_data *attr = data;
77 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset);
78
79 return sprintf(buf, "%u\n", *field);
80}
81
82static ssize_t trackpoint_set_int_attr(struct psmouse *psmouse, void *data,
83 const char *buf, size_t count)
84{
85 struct trackpoint_data *tp = psmouse->private;
86 struct trackpoint_attr_data *attr = data;
87 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset);
88 unsigned long value;
89 char *rest;
90
91 value = simple_strtoul(buf, &rest, 10);
92 if (*rest || value > 255)
93 return -EINVAL;
94
95 *field = value;
96 trackpoint_write(&psmouse->ps2dev, attr->command, value);
97
98 return count;
99}
100
101#define TRACKPOINT_INT_ATTR(_name, _command) \
102 static struct trackpoint_attr_data trackpoint_attr_##_name = { \
103 .field_offset = offsetof(struct trackpoint_data, _name), \
104 .command = _command, \
105 }; \
106 PSMOUSE_DEFINE_ATTR(_name, S_IWUSR | S_IRUGO, \
107 &trackpoint_attr_##_name, \
108 trackpoint_show_int_attr, trackpoint_set_int_attr)
109
110static ssize_t trackpoint_set_bit_attr(struct psmouse *psmouse, void *data,
111 const char *buf, size_t count)
112{
113 struct trackpoint_data *tp = psmouse->private;
114 struct trackpoint_attr_data *attr = data;
115 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset);
116 unsigned long value;
117 char *rest;
118
119 value = simple_strtoul(buf, &rest, 10);
120 if (*rest || value > 1)
121 return -EINVAL;
122
123 if (*field != value) {
124 *field = value;
125 trackpoint_toggle_bit(&psmouse->ps2dev, attr->command, attr->mask);
126 }
127
128 return count;
129}
130
131
132#define TRACKPOINT_BIT_ATTR(_name, _command, _mask) \
133 static struct trackpoint_attr_data trackpoint_attr_##_name = { \
134 .field_offset = offsetof(struct trackpoint_data, _name), \
135 .command = _command, \
136 .mask = _mask, \
137 }; \
138 PSMOUSE_DEFINE_ATTR(_name, S_IWUSR | S_IRUGO, \
139 &trackpoint_attr_##_name, \
140 trackpoint_show_int_attr, trackpoint_set_bit_attr)
141
142TRACKPOINT_INT_ATTR(sensitivity, TP_SENS);
143TRACKPOINT_INT_ATTR(speed, TP_SPEED);
144TRACKPOINT_INT_ATTR(inertia, TP_INERTIA);
145TRACKPOINT_INT_ATTR(reach, TP_REACH);
146TRACKPOINT_INT_ATTR(draghys, TP_DRAGHYS);
147TRACKPOINT_INT_ATTR(mindrag, TP_MINDRAG);
148TRACKPOINT_INT_ATTR(thresh, TP_THRESH);
149TRACKPOINT_INT_ATTR(upthresh, TP_UP_THRESH);
150TRACKPOINT_INT_ATTR(ztime, TP_Z_TIME);
151TRACKPOINT_INT_ATTR(jenks, TP_JENKS_CURV);
152
153TRACKPOINT_BIT_ATTR(press_to_select, TP_TOGGLE_PTSON, TP_MASK_PTSON);
154TRACKPOINT_BIT_ATTR(skipback, TP_TOGGLE_SKIPBACK, TP_MASK_SKIPBACK);
155TRACKPOINT_BIT_ATTR(ext_dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV);
156
157static struct attribute *trackpoint_attrs[] = {
158 &psmouse_attr_sensitivity.dattr.attr,
159 &psmouse_attr_speed.dattr.attr,
160 &psmouse_attr_inertia.dattr.attr,
161 &psmouse_attr_reach.dattr.attr,
162 &psmouse_attr_draghys.dattr.attr,
163 &psmouse_attr_mindrag.dattr.attr,
164 &psmouse_attr_thresh.dattr.attr,
165 &psmouse_attr_upthresh.dattr.attr,
166 &psmouse_attr_ztime.dattr.attr,
167 &psmouse_attr_jenks.dattr.attr,
168 &psmouse_attr_press_to_select.dattr.attr,
169 &psmouse_attr_skipback.dattr.attr,
170 &psmouse_attr_ext_dev.dattr.attr,
171 NULL
172};
173
174static struct attribute_group trackpoint_attr_group = {
175 .attrs = trackpoint_attrs,
176};
177
178static void trackpoint_disconnect(struct psmouse *psmouse)
179{
180 sysfs_remove_group(&psmouse->ps2dev.serio->dev.kobj, &trackpoint_attr_group);
181
182 kfree(psmouse->private);
183 psmouse->private = NULL;
184}
185
186static int trackpoint_sync(struct psmouse *psmouse)
187{
188 unsigned char toggle;
189 struct trackpoint_data *tp = psmouse->private;
190
191 if (!tp)
192 return -1;
193
194 /* Disable features that may make device unusable with this driver */
195 trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_TWOHAND, &toggle);
196 if (toggle & TP_MASK_TWOHAND)
197 trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_TWOHAND, TP_MASK_TWOHAND);
198
199 trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_SOURCE_TAG, &toggle);
200 if (toggle & TP_MASK_SOURCE_TAG)
201 trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_SOURCE_TAG, TP_MASK_SOURCE_TAG);
202
203 trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_MB, &toggle);
204 if (toggle & TP_MASK_MB)
205 trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_MB, TP_MASK_MB);
206
207 /* Push the config to the device */
208 trackpoint_write(&psmouse->ps2dev, TP_SENS, tp->sensitivity);
209 trackpoint_write(&psmouse->ps2dev, TP_INERTIA, tp->inertia);
210 trackpoint_write(&psmouse->ps2dev, TP_SPEED, tp->speed);
211
212 trackpoint_write(&psmouse->ps2dev, TP_REACH, tp->reach);
213 trackpoint_write(&psmouse->ps2dev, TP_DRAGHYS, tp->draghys);
214 trackpoint_write(&psmouse->ps2dev, TP_MINDRAG, tp->mindrag);
215
216 trackpoint_write(&psmouse->ps2dev, TP_THRESH, tp->thresh);
217 trackpoint_write(&psmouse->ps2dev, TP_UP_THRESH, tp->upthresh);
218
219 trackpoint_write(&psmouse->ps2dev, TP_Z_TIME, tp->ztime);
220 trackpoint_write(&psmouse->ps2dev, TP_JENKS_CURV, tp->jenks);
221
222 trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_PTSON, &toggle);
223 if (((toggle & TP_MASK_PTSON) == TP_MASK_PTSON) != tp->press_to_select)
224 trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_PTSON, TP_MASK_PTSON);
225
226 trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_SKIPBACK, &toggle);
227 if (((toggle & TP_MASK_SKIPBACK) == TP_MASK_SKIPBACK) != tp->skipback)
228 trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_SKIPBACK, TP_MASK_SKIPBACK);
229
230 trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_EXT_DEV, &toggle);
231 if (((toggle & TP_MASK_EXT_DEV) == TP_MASK_EXT_DEV) != tp->ext_dev)
232 trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV);
233
234 return 0;
235}
236
237static void trackpoint_defaults(struct trackpoint_data *tp)
238{
239 tp->press_to_select = TP_DEF_PTSON;
240 tp->sensitivity = TP_DEF_SENS;
241 tp->speed = TP_DEF_SPEED;
242 tp->reach = TP_DEF_REACH;
243
244 tp->draghys = TP_DEF_DRAGHYS;
245 tp->mindrag = TP_DEF_MINDRAG;
246
247 tp->thresh = TP_DEF_THRESH;
248 tp->upthresh = TP_DEF_UP_THRESH;
249
250 tp->ztime = TP_DEF_Z_TIME;
251 tp->jenks = TP_DEF_JENKS_CURV;
252
253 tp->inertia = TP_DEF_INERTIA;
254 tp->skipback = TP_DEF_SKIPBACK;
255 tp->ext_dev = TP_DEF_EXT_DEV;
256}
257
258int trackpoint_detect(struct psmouse *psmouse, int set_properties)
259{
260 struct trackpoint_data *priv;
261 struct ps2dev *ps2dev = &psmouse->ps2dev;
262 unsigned char firmware_id;
263 unsigned char button_info;
264 unsigned char param[2];
265
266 param[0] = param[1] = 0;
267
268 if (ps2_command(ps2dev, param, MAKE_PS2_CMD(0, 2, TP_READ_ID)))
269 return -1;
270
271 if (param[0] != TP_MAGIC_IDENT)
272 return -1;
273
274 if (!set_properties)
275 return 0;
276
277 firmware_id = param[1];
278
279 if (trackpoint_read(&psmouse->ps2dev, TP_EXT_BTN, &button_info)) {
280 printk(KERN_WARNING "trackpoint.c: failed to get extended button data\n");
281 button_info = 0;
282 }
283
284 psmouse->private = priv = kcalloc(1, sizeof(struct trackpoint_data), GFP_KERNEL);
285 if (!priv)
286 return -1;
287
288 psmouse->vendor = "IBM";
289 psmouse->name = "TrackPoint";
290
291 psmouse->reconnect = trackpoint_sync;
292 psmouse->disconnect = trackpoint_disconnect;
293
294 trackpoint_defaults(priv);
295 trackpoint_sync(psmouse);
296
297 sysfs_create_group(&ps2dev->serio->dev.kobj, &trackpoint_attr_group);
298
299 printk(KERN_INFO "IBM TrackPoint firmware: 0x%02x, buttons: %d/%d\n",
300 firmware_id, (button_info & 0xf0) >> 4, button_info & 0x0f);
301
302 return 0;
303}
304
diff --git a/drivers/input/mouse/trackpoint.h b/drivers/input/mouse/trackpoint.h
new file mode 100644
index 0000000000..9857d8b6ad
--- /dev/null
+++ b/drivers/input/mouse/trackpoint.h
@@ -0,0 +1,147 @@
1/*
2 * IBM TrackPoint PS/2 mouse driver
3 *
4 * Stephen Evanchik <evanchsa@gmail.com>
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 by
8 * the Free Software Foundation.
9 */
10
11#ifndef _TRACKPOINT_H
12#define _TRACKPOINT_H
13
14/*
15 * These constants are from the TrackPoint System
16 * Engineering documentation Version 4 from IBM Watson
17 * research:
18 * http://wwwcssrv.almaden.ibm.com/trackpoint/download.html
19 */
20
21#define TP_COMMAND 0xE2 /* Commands start with this */
22
23#define TP_READ_ID 0xE1 /* Sent for device identification */
24#define TP_MAGIC_IDENT 0x01 /* Sent after a TP_READ_ID followed */
25 /* by the firmware ID */
26
27
28/*
29 * Commands
30 */
31#define TP_RECALIB 0x51 /* Recalibrate */
32#define TP_POWER_DOWN 0x44 /* Can only be undone through HW reset */
33#define TP_EXT_DEV 0x21 /* Determines if external device is connected (RO) */
34#define TP_EXT_BTN 0x4B /* Read extended button status */
35#define TP_POR 0x7F /* Execute Power on Reset */
36#define TP_POR_RESULTS 0x25 /* Read Power on Self test results */
37#define TP_DISABLE_EXT 0x40 /* Disable external pointing device */
38#define TP_ENABLE_EXT 0x41 /* Enable external pointing device */
39
40/*
41 * Mode manipulation
42 */
43#define TP_SET_SOFT_TRANS 0x4E /* Set mode */
44#define TP_CANCEL_SOFT_TRANS 0xB9 /* Cancel mode */
45#define TP_SET_HARD_TRANS 0x45 /* Mode can only be set */
46
47
48/*
49 * Register oriented commands/properties
50 */
51#define TP_WRITE_MEM 0x81
52#define TP_READ_MEM 0x80 /* Not used in this implementation */
53
54/*
55* RAM Locations for properties
56 */
57#define TP_SENS 0x4A /* Sensitivity */
58#define TP_MB 0x4C /* Read Middle Button Status (RO) */
59#define TP_INERTIA 0x4D /* Negative Inertia */
60#define TP_SPEED 0x60 /* Speed of TP Cursor */
61#define TP_REACH 0x57 /* Backup for Z-axis press */
62#define TP_DRAGHYS 0x58 /* Drag Hysteresis */
63 /* (how hard it is to drag */
64 /* with Z-axis pressed) */
65
66#define TP_MINDRAG 0x59 /* Minimum amount of force needed */
67 /* to trigger dragging */
68
69#define TP_THRESH 0x5C /* Minimum value for a Z-axis press */
70#define TP_UP_THRESH 0x5A /* Used to generate a 'click' on Z-axis */
71#define TP_Z_TIME 0x5E /* How sharp of a press */
72#define TP_JENKS_CURV 0x5D /* Minimum curvature for double click */
73
74/*
75 * Toggling Flag bits
76 */
77#define TP_TOGGLE 0x47 /* Toggle command */
78
79#define TP_TOGGLE_MB 0x23 /* Disable/Enable Middle Button */
80#define TP_MASK_MB 0x01
81#define TP_TOGGLE_EXT_DEV 0x23 /* Toggle external device */
82#define TP_MASK_EXT_DEV 0x02
83#define TP_TOGGLE_DRIFT 0x23 /* Drift Correction */
84#define TP_MASK_DRIFT 0x80
85#define TP_TOGGLE_BURST 0x28 /* Burst Mode */
86#define TP_MASK_BURST 0x80
87#define TP_TOGGLE_PTSON 0x2C /* Press to Select */
88#define TP_MASK_PTSON 0x01
89#define TP_TOGGLE_HARD_TRANS 0x2C /* Alternate method to set Hard Transparency */
90#define TP_MASK_HARD_TRANS 0x80
91#define TP_TOGGLE_TWOHAND 0x2D /* Two handed */
92#define TP_MASK_TWOHAND 0x01
93#define TP_TOGGLE_STICKY_TWO 0x2D /* Sticky two handed */
94#define TP_MASK_STICKY_TWO 0x04
95#define TP_TOGGLE_SKIPBACK 0x2D /* Suppress movement after drag release */
96#define TP_MASK_SKIPBACK 0x08
97#define TP_TOGGLE_SOURCE_TAG 0x20 /* Bit 3 of the first packet will be set to
98 to the origin of the packet (external or TP) */
99#define TP_MASK_SOURCE_TAG 0x80
100#define TP_TOGGLE_EXT_TAG 0x22 /* Bit 3 of the first packet coming from the
101 external device will be forced to 1 */
102#define TP_MASK_EXT_TAG 0x04
103
104
105/* Power on Self Test Results */
106#define TP_POR_SUCCESS 0x3B
107
108/*
109 * Default power on values
110 */
111#define TP_DEF_SENS 0x80
112#define TP_DEF_INERTIA 0x06
113#define TP_DEF_SPEED 0x61
114#define TP_DEF_REACH 0x0A
115
116#define TP_DEF_DRAGHYS 0xFF
117#define TP_DEF_MINDRAG 0x14
118
119#define TP_DEF_THRESH 0x08
120#define TP_DEF_UP_THRESH 0xFF
121#define TP_DEF_Z_TIME 0x26
122#define TP_DEF_JENKS_CURV 0x87
123
124/* Toggles */
125#define TP_DEF_MB 0x00
126#define TP_DEF_PTSON 0x00
127#define TP_DEF_SKIPBACK 0x00
128#define TP_DEF_EXT_DEV 0x01
129
130#define MAKE_PS2_CMD(params, results, cmd) ((params<<12) | (results<<8) | (cmd))
131
132struct trackpoint_data
133{
134 unsigned char sensitivity, speed, inertia, reach;
135 unsigned char draghys, mindrag;
136 unsigned char thresh, upthresh;
137 unsigned char ztime, jenks;
138
139 unsigned char press_to_select;
140 unsigned char skipback;
141
142 unsigned char ext_dev;
143};
144
145extern int trackpoint_detect(struct psmouse *psmouse, int set_properties);
146
147#endif /* _TRACKPOINT_H */
diff --git a/drivers/input/serio/i8042-io.h b/drivers/input/serio/i8042-io.h
index c9e633d21d..9a92216442 100644
--- a/drivers/input/serio/i8042-io.h
+++ b/drivers/input/serio/i8042-io.h
@@ -69,16 +69,16 @@ static inline int i8042_platform_init(void)
69 */ 69 */
70#if !defined(__sh__) && !defined(__alpha__) && !defined(__mips__) && !defined(CONFIG_PPC64) 70#if !defined(__sh__) && !defined(__alpha__) && !defined(__mips__) && !defined(CONFIG_PPC64)
71 if (!request_region(I8042_DATA_REG, 16, "i8042")) 71 if (!request_region(I8042_DATA_REG, 16, "i8042"))
72 return -1; 72 return -EBUSY;
73#endif 73#endif
74 74
75 i8042_reset = 1; 75 i8042_reset = 1;
76 76
77#if defined(CONFIG_PPC64) 77#if defined(CONFIG_PPC64)
78 if (check_legacy_ioport(I8042_DATA_REG)) 78 if (check_legacy_ioport(I8042_DATA_REG))
79 return -1; 79 return -EBUSY;
80 if (!request_region(I8042_DATA_REG, 16, "i8042")) 80 if (!request_region(I8042_DATA_REG, 16, "i8042"))
81 return -1; 81 return -EBUSY;
82#endif 82#endif
83 return 0; 83 return 0;
84} 84}
diff --git a/drivers/input/serio/i8042-ip22io.h b/drivers/input/serio/i8042-ip22io.h
index 863b9c95fb..ee1ad27d6e 100644
--- a/drivers/input/serio/i8042-ip22io.h
+++ b/drivers/input/serio/i8042-ip22io.h
@@ -58,7 +58,7 @@ static inline int i8042_platform_init(void)
58#if 0 58#if 0
59 /* XXX sgi_kh is a virtual address */ 59 /* XXX sgi_kh is a virtual address */
60 if (!request_mem_region(sgi_kh, sizeof(struct hpc_keyb), "i8042")) 60 if (!request_mem_region(sgi_kh, sizeof(struct hpc_keyb), "i8042"))
61 return 1; 61 return -EBUSY;
62#endif 62#endif
63 63
64 i8042_reset = 1; 64 i8042_reset = 1;
diff --git a/drivers/input/serio/i8042-jazzio.h b/drivers/input/serio/i8042-jazzio.h
index 5c20ab1314..13fd7108eb 100644
--- a/drivers/input/serio/i8042-jazzio.h
+++ b/drivers/input/serio/i8042-jazzio.h
@@ -53,7 +53,7 @@ static inline int i8042_platform_init(void)
53#if 0 53#if 0
54 /* XXX JAZZ_KEYBOARD_ADDRESS is a virtual address */ 54 /* XXX JAZZ_KEYBOARD_ADDRESS is a virtual address */
55 if (!request_mem_region(JAZZ_KEYBOARD_ADDRESS, 2, "i8042")) 55 if (!request_mem_region(JAZZ_KEYBOARD_ADDRESS, 2, "i8042"))
56 return 1; 56 return -EBUSY;
57#endif 57#endif
58 58
59 return 0; 59 return 0;
diff --git a/drivers/input/serio/i8042-sparcio.h b/drivers/input/serio/i8042-sparcio.h
index da2a198124..ed9446f6d7 100644
--- a/drivers/input/serio/i8042-sparcio.h
+++ b/drivers/input/serio/i8042-sparcio.h
@@ -48,10 +48,10 @@ static inline void i8042_write_command(int val)
48#define OBP_PS2MS_NAME1 "kdmouse" 48#define OBP_PS2MS_NAME1 "kdmouse"
49#define OBP_PS2MS_NAME2 "mouse" 49#define OBP_PS2MS_NAME2 "mouse"
50 50
51static int i8042_platform_init(void) 51static int __init i8042_platform_init(void)
52{ 52{
53#ifndef CONFIG_PCI 53#ifndef CONFIG_PCI
54 return -1; 54 return -ENODEV;
55#else 55#else
56 char prop[128]; 56 char prop[128];
57 int len; 57 int len;
@@ -59,14 +59,14 @@ static int i8042_platform_init(void)
59 len = prom_getproperty(prom_root_node, "name", prop, sizeof(prop)); 59 len = prom_getproperty(prom_root_node, "name", prop, sizeof(prop));
60 if (len < 0) { 60 if (len < 0) {
61 printk("i8042: Cannot get name property of root OBP node.\n"); 61 printk("i8042: Cannot get name property of root OBP node.\n");
62 return -1; 62 return -ENODEV;
63 } 63 }
64 if (strncmp(prop, "SUNW,JavaStation-1", len) == 0) { 64 if (strncmp(prop, "SUNW,JavaStation-1", len) == 0) {
65 /* Hardcoded values for MrCoffee. */ 65 /* Hardcoded values for MrCoffee. */
66 i8042_kbd_irq = i8042_aux_irq = 13 | 0x20; 66 i8042_kbd_irq = i8042_aux_irq = 13 | 0x20;
67 kbd_iobase = ioremap(0x71300060, 8); 67 kbd_iobase = ioremap(0x71300060, 8);
68 if (!kbd_iobase) 68 if (!kbd_iobase)
69 return -1; 69 return -ENODEV;
70 } else { 70 } else {
71 struct linux_ebus *ebus; 71 struct linux_ebus *ebus;
72 struct linux_ebus_device *edev; 72 struct linux_ebus_device *edev;
@@ -78,7 +78,7 @@ static int i8042_platform_init(void)
78 goto edev_found; 78 goto edev_found;
79 } 79 }
80 } 80 }
81 return -1; 81 return -ENODEV;
82 82
83 edev_found: 83 edev_found:
84 for_each_edevchild(edev, child) { 84 for_each_edevchild(edev, child) {
@@ -96,7 +96,7 @@ static int i8042_platform_init(void)
96 i8042_aux_irq == -1) { 96 i8042_aux_irq == -1) {
97 printk("i8042: Error, 8042 device lacks both kbd and " 97 printk("i8042: Error, 8042 device lacks both kbd and "
98 "mouse nodes.\n"); 98 "mouse nodes.\n");
99 return -1; 99 return -ENODEV;
100 } 100 }
101 } 101 }
102 102
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index 03877c84e6..273bb3b08c 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -138,6 +138,13 @@ static struct dmi_system_id __initdata i8042_dmi_nomux_table[] = {
138 }, 138 },
139 }, 139 },
140 { 140 {
141 .ident = "Fujitsu-Siemens Lifebook E4010",
142 .matches = {
143 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
144 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E4010"),
145 },
146 },
147 {
141 .ident = "Toshiba P10", 148 .ident = "Toshiba P10",
142 .matches = { 149 .matches = {
143 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), 150 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
@@ -256,9 +263,10 @@ static void i8042_pnp_exit(void)
256 } 263 }
257} 264}
258 265
259static int i8042_pnp_init(void) 266static int __init i8042_pnp_init(void)
260{ 267{
261 int result_kbd, result_aux; 268 int result_kbd = 0, result_aux = 0;
269 char kbd_irq_str[4] = { 0 }, aux_irq_str[4] = { 0 };
262 270
263 if (i8042_nopnp) { 271 if (i8042_nopnp) {
264 printk(KERN_INFO "i8042: PNP detection disabled\n"); 272 printk(KERN_INFO "i8042: PNP detection disabled\n");
@@ -267,6 +275,7 @@ static int i8042_pnp_init(void)
267 275
268 if ((result_kbd = pnp_register_driver(&i8042_pnp_kbd_driver)) >= 0) 276 if ((result_kbd = pnp_register_driver(&i8042_pnp_kbd_driver)) >= 0)
269 i8042_pnp_kbd_registered = 1; 277 i8042_pnp_kbd_registered = 1;
278
270 if ((result_aux = pnp_register_driver(&i8042_pnp_aux_driver)) >= 0) 279 if ((result_aux = pnp_register_driver(&i8042_pnp_aux_driver)) >= 0)
271 i8042_pnp_aux_registered = 1; 280 i8042_pnp_aux_registered = 1;
272 281
@@ -280,6 +289,27 @@ static int i8042_pnp_init(void)
280#endif 289#endif
281 } 290 }
282 291
292 if (result_kbd > 0)
293 snprintf(kbd_irq_str, sizeof(kbd_irq_str),
294 "%d", i8042_pnp_kbd_irq);
295 if (result_aux > 0)
296 snprintf(aux_irq_str, sizeof(aux_irq_str),
297 "%d", i8042_pnp_aux_irq);
298
299 printk(KERN_INFO "PNP: PS/2 Controller [%s%s%s] at %#x,%#x irq %s%s%s\n",
300 i8042_pnp_kbd_name, (result_kbd > 0 && result_aux > 0) ? "," : "",
301 i8042_pnp_aux_name,
302 i8042_pnp_data_reg, i8042_pnp_command_reg,
303 kbd_irq_str, (result_kbd > 0 && result_aux > 0) ? "," : "",
304 aux_irq_str);
305
306#if defined(__ia64__)
307 if (result_kbd <= 0)
308 i8042_nokbd = 1;
309 if (result_aux <= 0)
310 i8042_noaux = 1;
311#endif
312
283 if (((i8042_pnp_data_reg & ~0xf) == (i8042_data_reg & ~0xf) && 313 if (((i8042_pnp_data_reg & ~0xf) == (i8042_data_reg & ~0xf) &&
284 i8042_pnp_data_reg != i8042_data_reg) || !i8042_pnp_data_reg) { 314 i8042_pnp_data_reg != i8042_data_reg) || !i8042_pnp_data_reg) {
285 printk(KERN_WARNING "PNP: PS/2 controller has invalid data port %#x; using default %#x\n", 315 printk(KERN_WARNING "PNP: PS/2 controller has invalid data port %#x; using default %#x\n",
@@ -294,53 +324,47 @@ static int i8042_pnp_init(void)
294 i8042_pnp_command_reg = i8042_command_reg; 324 i8042_pnp_command_reg = i8042_command_reg;
295 } 325 }
296 326
297 if (!i8042_pnp_kbd_irq) { 327 if (!i8042_nokbd && !i8042_pnp_kbd_irq) {
298 printk(KERN_WARNING "PNP: PS/2 controller doesn't have KBD irq; using default %#x\n", i8042_kbd_irq); 328 printk(KERN_WARNING "PNP: PS/2 controller doesn't have KBD irq; using default %d\n", i8042_kbd_irq);
299 i8042_pnp_kbd_irq = i8042_kbd_irq; 329 i8042_pnp_kbd_irq = i8042_kbd_irq;
300 } 330 }
301 331
302 if (!i8042_pnp_aux_irq) { 332 if (!i8042_noaux && !i8042_pnp_aux_irq) {
303 printk(KERN_WARNING "PNP: PS/2 controller doesn't have AUX irq; using default %#x\n", i8042_aux_irq); 333 printk(KERN_WARNING "PNP: PS/2 controller doesn't have AUX irq; using default %d\n", i8042_aux_irq);
304 i8042_pnp_aux_irq = i8042_aux_irq; 334 i8042_pnp_aux_irq = i8042_aux_irq;
305 } 335 }
306 336
307#if defined(__ia64__)
308 if (result_aux <= 0)
309 i8042_noaux = 1;
310#endif
311
312 i8042_data_reg = i8042_pnp_data_reg; 337 i8042_data_reg = i8042_pnp_data_reg;
313 i8042_command_reg = i8042_pnp_command_reg; 338 i8042_command_reg = i8042_pnp_command_reg;
314 i8042_kbd_irq = i8042_pnp_kbd_irq; 339 i8042_kbd_irq = i8042_pnp_kbd_irq;
315 i8042_aux_irq = i8042_pnp_aux_irq; 340 i8042_aux_irq = i8042_pnp_aux_irq;
316 341
317 printk(KERN_INFO "PNP: PS/2 Controller [%s%s%s] at %#x,%#x irq %d%s%d\n",
318 i8042_pnp_kbd_name, (result_kbd > 0 && result_aux > 0) ? "," : "", i8042_pnp_aux_name,
319 i8042_data_reg, i8042_command_reg, i8042_kbd_irq,
320 (result_aux > 0) ? "," : "", i8042_aux_irq);
321
322 return 0; 342 return 0;
323} 343}
324 344
345#else
346static inline int i8042_pnp_init(void) { return 0; }
347static inline void i8042_pnp_exit(void) { }
325#endif 348#endif
326 349
327static inline int i8042_platform_init(void) 350static int __init i8042_platform_init(void)
328{ 351{
352 int retval;
353
329/* 354/*
330 * On ix86 platforms touching the i8042 data register region can do really 355 * On ix86 platforms touching the i8042 data register region can do really
331 * bad things. Because of this the region is always reserved on ix86 boxes. 356 * bad things. Because of this the region is always reserved on ix86 boxes.
332 * 357 *
333 * if (!request_region(I8042_DATA_REG, 16, "i8042")) 358 * if (!request_region(I8042_DATA_REG, 16, "i8042"))
334 * return -1; 359 * return -EBUSY;
335 */ 360 */
336 361
337 i8042_kbd_irq = I8042_MAP_IRQ(1); 362 i8042_kbd_irq = I8042_MAP_IRQ(1);
338 i8042_aux_irq = I8042_MAP_IRQ(12); 363 i8042_aux_irq = I8042_MAP_IRQ(12);
339 364
340#ifdef CONFIG_PNP 365 retval = i8042_pnp_init();
341 if (i8042_pnp_init()) 366 if (retval)
342 return -1; 367 return retval;
343#endif
344 368
345#if defined(__ia64__) 369#if defined(__ia64__)
346 i8042_reset = 1; 370 i8042_reset = 1;
@@ -354,14 +378,12 @@ static inline int i8042_platform_init(void)
354 i8042_nomux = 1; 378 i8042_nomux = 1;
355#endif 379#endif
356 380
357 return 0; 381 return retval;
358} 382}
359 383
360static inline void i8042_platform_exit(void) 384static inline void i8042_platform_exit(void)
361{ 385{
362#ifdef CONFIG_PNP
363 i8042_pnp_exit(); 386 i8042_pnp_exit();
364#endif
365} 387}
366 388
367#endif /* _I8042_X86IA64IO_H */ 389#endif /* _I8042_X86IA64IO_H */
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index 708a1d3bea..40d451ce07 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -27,6 +27,10 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
27MODULE_DESCRIPTION("i8042 keyboard and mouse controller driver"); 27MODULE_DESCRIPTION("i8042 keyboard and mouse controller driver");
28MODULE_LICENSE("GPL"); 28MODULE_LICENSE("GPL");
29 29
30static unsigned int i8042_nokbd;
31module_param_named(nokbd, i8042_nokbd, bool, 0);
32MODULE_PARM_DESC(nokbd, "Do not probe or use KBD port.");
33
30static unsigned int i8042_noaux; 34static unsigned int i8042_noaux;
31module_param_named(noaux, i8042_noaux, bool, 0); 35module_param_named(noaux, i8042_noaux, bool, 0);
32MODULE_PARM_DESC(noaux, "Do not probe or use AUX (mouse) port."); 36MODULE_PARM_DESC(noaux, "Do not probe or use AUX (mouse) port.");
@@ -338,10 +342,10 @@ static int i8042_open(struct serio *serio)
338 342
339 return 0; 343 return 0;
340 344
341activate_fail: 345 activate_fail:
342 free_irq(port->irq, i8042_request_irq_cookie); 346 free_irq(port->irq, i8042_request_irq_cookie);
343 347
344irq_fail: 348 irq_fail:
345 serio_unregister_port_delayed(serio); 349 serio_unregister_port_delayed(serio);
346 350
347 return -1; 351 return -1;
@@ -485,7 +489,7 @@ static irqreturn_t i8042_interrupt(int irq, void *dev_id, struct pt_regs *regs)
485 serio_interrupt(port->serio, data, dfl, regs); 489 serio_interrupt(port->serio, data, dfl, regs);
486 490
487 ret = 1; 491 ret = 1;
488out: 492 out:
489 return IRQ_RETVAL(ret); 493 return IRQ_RETVAL(ret);
490} 494}
491 495
@@ -552,7 +556,7 @@ static int i8042_enable_mux_ports(void)
552 * Enable all muxed ports. 556 * Enable all muxed ports.
553 */ 557 */
554 558
555 for (i = 0; i < 4; i++) { 559 for (i = 0; i < I8042_NUM_MUX_PORTS; i++) {
556 i8042_command(&param, I8042_CMD_MUX_PFX + i); 560 i8042_command(&param, I8042_CMD_MUX_PFX + i);
557 i8042_command(&param, I8042_CMD_AUX_ENABLE); 561 i8042_command(&param, I8042_CMD_AUX_ENABLE);
558 } 562 }
@@ -682,7 +686,7 @@ static int __init i8042_port_register(struct i8042_port *port)
682 kfree(port->serio); 686 kfree(port->serio);
683 port->serio = NULL; 687 port->serio = NULL;
684 i8042_ctr |= port->disable; 688 i8042_ctr |= port->disable;
685 return -1; 689 return -EIO;
686 } 690 }
687 691
688 printk(KERN_INFO "serio: i8042 %s port at %#lx,%#lx irq %d\n", 692 printk(KERN_INFO "serio: i8042 %s port at %#lx,%#lx irq %d\n",
@@ -977,85 +981,88 @@ static struct device_driver i8042_driver = {
977 .shutdown = i8042_shutdown, 981 .shutdown = i8042_shutdown,
978}; 982};
979 983
980static void __init i8042_create_kbd_port(void) 984static int __init i8042_create_kbd_port(void)
981{ 985{
982 struct serio *serio; 986 struct serio *serio;
983 struct i8042_port *port = &i8042_ports[I8042_KBD_PORT_NO]; 987 struct i8042_port *port = &i8042_ports[I8042_KBD_PORT_NO];
984 988
985 serio = kmalloc(sizeof(struct serio), GFP_KERNEL); 989 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
986 if (serio) { 990 if (!serio)
987 memset(serio, 0, sizeof(struct serio)); 991 return -ENOMEM;
988 serio->id.type = i8042_direct ? SERIO_8042 : SERIO_8042_XL; 992
989 serio->write = i8042_dumbkbd ? NULL : i8042_kbd_write; 993 serio->id.type = i8042_direct ? SERIO_8042 : SERIO_8042_XL;
990 serio->open = i8042_open; 994 serio->write = i8042_dumbkbd ? NULL : i8042_kbd_write;
991 serio->close = i8042_close; 995 serio->open = i8042_open;
992 serio->start = i8042_start; 996 serio->close = i8042_close;
993 serio->stop = i8042_stop; 997 serio->start = i8042_start;
994 serio->port_data = port; 998 serio->stop = i8042_stop;
995 serio->dev.parent = &i8042_platform_device->dev; 999 serio->port_data = port;
996 strlcpy(serio->name, "i8042 Kbd Port", sizeof(serio->name)); 1000 serio->dev.parent = &i8042_platform_device->dev;
997 strlcpy(serio->phys, I8042_KBD_PHYS_DESC, sizeof(serio->phys)); 1001 strlcpy(serio->name, "i8042 Kbd Port", sizeof(serio->name));
998 1002 strlcpy(serio->phys, I8042_KBD_PHYS_DESC, sizeof(serio->phys));
999 port->serio = serio; 1003
1000 i8042_port_register(port); 1004 port->serio = serio;
1001 } 1005
1006 return i8042_port_register(port);
1002} 1007}
1003 1008
1004static void __init i8042_create_aux_port(void) 1009static int __init i8042_create_aux_port(void)
1005{ 1010{
1006 struct serio *serio; 1011 struct serio *serio;
1007 struct i8042_port *port = &i8042_ports[I8042_AUX_PORT_NO]; 1012 struct i8042_port *port = &i8042_ports[I8042_AUX_PORT_NO];
1008 1013
1009 serio = kmalloc(sizeof(struct serio), GFP_KERNEL); 1014 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
1010 if (serio) { 1015 if (!serio)
1011 memset(serio, 0, sizeof(struct serio)); 1016 return -ENOMEM;
1012 serio->id.type = SERIO_8042; 1017
1013 serio->write = i8042_aux_write; 1018 serio->id.type = SERIO_8042;
1014 serio->open = i8042_open; 1019 serio->write = i8042_aux_write;
1015 serio->close = i8042_close; 1020 serio->open = i8042_open;
1016 serio->start = i8042_start; 1021 serio->close = i8042_close;
1017 serio->stop = i8042_stop; 1022 serio->start = i8042_start;
1018 serio->port_data = port; 1023 serio->stop = i8042_stop;
1019 serio->dev.parent = &i8042_platform_device->dev; 1024 serio->port_data = port;
1020 strlcpy(serio->name, "i8042 Aux Port", sizeof(serio->name)); 1025 serio->dev.parent = &i8042_platform_device->dev;
1021 strlcpy(serio->phys, I8042_AUX_PHYS_DESC, sizeof(serio->phys)); 1026 strlcpy(serio->name, "i8042 Aux Port", sizeof(serio->name));
1022 1027 strlcpy(serio->phys, I8042_AUX_PHYS_DESC, sizeof(serio->phys));
1023 port->serio = serio; 1028
1024 i8042_port_register(port); 1029 port->serio = serio;
1025 } 1030
1031 return i8042_port_register(port);
1026} 1032}
1027 1033
1028static void __init i8042_create_mux_port(int index) 1034static int __init i8042_create_mux_port(int index)
1029{ 1035{
1030 struct serio *serio; 1036 struct serio *serio;
1031 struct i8042_port *port = &i8042_ports[I8042_MUX_PORT_NO + index]; 1037 struct i8042_port *port = &i8042_ports[I8042_MUX_PORT_NO + index];
1032 1038
1033 serio = kmalloc(sizeof(struct serio), GFP_KERNEL); 1039 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
1034 if (serio) { 1040 if (!serio)
1035 memset(serio, 0, sizeof(struct serio)); 1041 return -ENOMEM;
1036 serio->id.type = SERIO_8042; 1042
1037 serio->write = i8042_aux_write; 1043 serio->id.type = SERIO_8042;
1038 serio->open = i8042_open; 1044 serio->write = i8042_aux_write;
1039 serio->close = i8042_close; 1045 serio->open = i8042_open;
1040 serio->start = i8042_start; 1046 serio->close = i8042_close;
1041 serio->stop = i8042_stop; 1047 serio->start = i8042_start;
1042 serio->port_data = port; 1048 serio->stop = i8042_stop;
1043 serio->dev.parent = &i8042_platform_device->dev; 1049 serio->port_data = port;
1044 snprintf(serio->name, sizeof(serio->name), "i8042 Aux-%d Port", index); 1050 serio->dev.parent = &i8042_platform_device->dev;
1045 snprintf(serio->phys, sizeof(serio->phys), I8042_MUX_PHYS_DESC, index + 1); 1051 snprintf(serio->name, sizeof(serio->name), "i8042 Aux-%d Port", index);
1046 1052 snprintf(serio->phys, sizeof(serio->phys), I8042_MUX_PHYS_DESC, index + 1);
1047 *port = i8042_ports[I8042_AUX_PORT_NO]; 1053
1048 port->exists = 0; 1054 *port = i8042_ports[I8042_AUX_PORT_NO];
1049 snprintf(port->name, sizeof(port->name), "AUX%d", index); 1055 port->exists = 0;
1050 port->mux = index; 1056 snprintf(port->name, sizeof(port->name), "AUX%d", index);
1051 port->serio = serio; 1057 port->mux = index;
1052 i8042_port_register(port); 1058 port->serio = serio;
1053 } 1059
1060 return i8042_port_register(port);
1054} 1061}
1055 1062
1056static int __init i8042_init(void) 1063static int __init i8042_init(void)
1057{ 1064{
1058 int i; 1065 int i, have_ports = 0;
1059 int err; 1066 int err;
1060 1067
1061 dbg_init(); 1068 dbg_init();
@@ -1063,43 +1070,73 @@ static int __init i8042_init(void)
1063 init_timer(&i8042_timer); 1070 init_timer(&i8042_timer);
1064 i8042_timer.function = i8042_timer_func; 1071 i8042_timer.function = i8042_timer_func;
1065 1072
1066 if (i8042_platform_init()) 1073 err = i8042_platform_init();
1067 return -EBUSY; 1074 if (err)
1075 return err;
1068 1076
1069 i8042_ports[I8042_AUX_PORT_NO].irq = I8042_AUX_IRQ; 1077 i8042_ports[I8042_AUX_PORT_NO].irq = I8042_AUX_IRQ;
1070 i8042_ports[I8042_KBD_PORT_NO].irq = I8042_KBD_IRQ; 1078 i8042_ports[I8042_KBD_PORT_NO].irq = I8042_KBD_IRQ;
1071 1079
1072 if (i8042_controller_init()) { 1080 if (i8042_controller_init()) {
1073 i8042_platform_exit(); 1081 err = -ENODEV;
1074 return -ENODEV; 1082 goto err_platform_exit;
1075 } 1083 }
1076 1084
1077 err = driver_register(&i8042_driver); 1085 err = driver_register(&i8042_driver);
1078 if (err) { 1086 if (err)
1079 i8042_platform_exit(); 1087 goto err_controller_cleanup;
1080 return err;
1081 }
1082 1088
1083 i8042_platform_device = platform_device_register_simple("i8042", -1, NULL, 0); 1089 i8042_platform_device = platform_device_register_simple("i8042", -1, NULL, 0);
1084 if (IS_ERR(i8042_platform_device)) { 1090 if (IS_ERR(i8042_platform_device)) {
1085 driver_unregister(&i8042_driver); 1091 err = PTR_ERR(i8042_platform_device);
1086 i8042_platform_exit(); 1092 goto err_unregister_driver;
1087 return PTR_ERR(i8042_platform_device);
1088 } 1093 }
1089 1094
1090 if (!i8042_noaux && !i8042_check_aux()) { 1095 if (!i8042_noaux && !i8042_check_aux()) {
1091 if (!i8042_nomux && !i8042_check_mux()) 1096 if (!i8042_nomux && !i8042_check_mux()) {
1092 for (i = 0; i < I8042_NUM_MUX_PORTS; i++) 1097 for (i = 0; i < I8042_NUM_MUX_PORTS; i++) {
1093 i8042_create_mux_port(i); 1098 err = i8042_create_mux_port(i);
1094 else 1099 if (err)
1095 i8042_create_aux_port(); 1100 goto err_unregister_ports;
1101 }
1102 } else {
1103 err = i8042_create_aux_port();
1104 if (err)
1105 goto err_unregister_ports;
1106 }
1107 have_ports = 1;
1096 } 1108 }
1097 1109
1098 i8042_create_kbd_port(); 1110 if (!i8042_nokbd) {
1111 err = i8042_create_kbd_port();
1112 if (err)
1113 goto err_unregister_ports;
1114 have_ports = 1;
1115 }
1116
1117 if (!have_ports) {
1118 err = -ENODEV;
1119 goto err_unregister_device;
1120 }
1099 1121
1100 mod_timer(&i8042_timer, jiffies + I8042_POLL_PERIOD); 1122 mod_timer(&i8042_timer, jiffies + I8042_POLL_PERIOD);
1101 1123
1102 return 0; 1124 return 0;
1125
1126 err_unregister_ports:
1127 for (i = 0; i < I8042_NUM_PORTS; i++)
1128 if (i8042_ports[i].serio)
1129 serio_unregister_port(i8042_ports[i].serio);
1130 err_unregister_device:
1131 platform_device_unregister(i8042_platform_device);
1132 err_unregister_driver:
1133 driver_unregister(&i8042_driver);
1134 err_controller_cleanup:
1135 i8042_controller_cleanup();
1136 err_platform_exit:
1137 i8042_platform_exit();
1138
1139 return err;
1103} 1140}
1104 1141
1105static void __exit i8042_exit(void) 1142static void __exit i8042_exit(void)
diff --git a/drivers/isdn/i4l/isdn_bsdcomp.c b/drivers/isdn/i4l/isdn_bsdcomp.c
index baf4bcad9b..0afe442db3 100644
--- a/drivers/isdn/i4l/isdn_bsdcomp.c
+++ b/drivers/isdn/i4l/isdn_bsdcomp.c
@@ -283,23 +283,19 @@ static void bsd_free (void *state)
283 /* 283 /*
284 * Release the dictionary 284 * Release the dictionary
285 */ 285 */
286 if (db->dict) { 286 vfree(db->dict);
287 vfree (db->dict); 287 db->dict = NULL;
288 db->dict = NULL;
289 }
290 288
291 /* 289 /*
292 * Release the string buffer 290 * Release the string buffer
293 */ 291 */
294 if (db->lens) { 292 vfree(db->lens);
295 vfree (db->lens); 293 db->lens = NULL;
296 db->lens = NULL;
297 }
298 294
299 /* 295 /*
300 * Finally release the structure itself. 296 * Finally release the structure itself.
301 */ 297 */
302 kfree (db); 298 kfree(db);
303 } 299 }
304} 300}
305 301
diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
index eebcb0b97f..8a7d54a5c9 100644
--- a/drivers/isdn/i4l/isdn_common.c
+++ b/drivers/isdn/i4l/isdn_common.c
@@ -1953,7 +1953,8 @@ isdn_add_channels(isdn_driver_t *d, int drvidx, int n, int adding)
1953 kfree(d->rcvcount); 1953 kfree(d->rcvcount);
1954 if (!(d->rcvcount = kmalloc(sizeof(int) * m, GFP_ATOMIC))) { 1954 if (!(d->rcvcount = kmalloc(sizeof(int) * m, GFP_ATOMIC))) {
1955 printk(KERN_WARNING "register_isdn: Could not alloc rcvcount\n"); 1955 printk(KERN_WARNING "register_isdn: Could not alloc rcvcount\n");
1956 if (!adding) kfree(d->rcverr); 1956 if (!adding)
1957 kfree(d->rcverr);
1957 return -1; 1958 return -1;
1958 } 1959 }
1959 memset((char *) d->rcvcount, 0, sizeof(int) * m); 1960 memset((char *) d->rcvcount, 0, sizeof(int) * m);
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 41df4cda66..2fba2bbe72 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -270,19 +270,20 @@ static struct page *read_sb_page(mddev_t *mddev, long offset, unsigned long inde
270 270
271 if (!page) 271 if (!page)
272 return ERR_PTR(-ENOMEM); 272 return ERR_PTR(-ENOMEM);
273 do {
274 ITERATE_RDEV(mddev, rdev, tmp)
275 if (rdev->in_sync && !rdev->faulty)
276 goto found;
277 return ERR_PTR(-EIO);
278 273
279 found: 274 ITERATE_RDEV(mddev, rdev, tmp) {
275 if (! rdev->in_sync || rdev->faulty)
276 continue;
277
280 target = (rdev->sb_offset << 1) + offset + index * (PAGE_SIZE/512); 278 target = (rdev->sb_offset << 1) + offset + index * (PAGE_SIZE/512);
281 279
282 } while (!sync_page_io(rdev->bdev, target, PAGE_SIZE, page, READ)); 280 if (sync_page_io(rdev->bdev, target, PAGE_SIZE, page, READ)) {
281 page->index = index;
282 return page;
283 }
284 }
285 return ERR_PTR(-EIO);
283 286
284 page->index = index;
285 return page;
286} 287}
287 288
288static int write_sb_page(mddev_t *mddev, long offset, struct page *page, int wait) 289static int write_sb_page(mddev_t *mddev, long offset, struct page *page, int wait)
@@ -437,6 +438,7 @@ void bitmap_print_sb(struct bitmap *bitmap)
437 printk(KERN_DEBUG " daemon sleep: %ds\n", le32_to_cpu(sb->daemon_sleep)); 438 printk(KERN_DEBUG " daemon sleep: %ds\n", le32_to_cpu(sb->daemon_sleep));
438 printk(KERN_DEBUG " sync size: %llu KB\n", 439 printk(KERN_DEBUG " sync size: %llu KB\n",
439 (unsigned long long)le64_to_cpu(sb->sync_size)/2); 440 (unsigned long long)le64_to_cpu(sb->sync_size)/2);
441 printk(KERN_DEBUG "max write behind: %d\n", le32_to_cpu(sb->write_behind));
440 kunmap(bitmap->sb_page); 442 kunmap(bitmap->sb_page);
441} 443}
442 444
@@ -445,7 +447,7 @@ static int bitmap_read_sb(struct bitmap *bitmap)
445{ 447{
446 char *reason = NULL; 448 char *reason = NULL;
447 bitmap_super_t *sb; 449 bitmap_super_t *sb;
448 unsigned long chunksize, daemon_sleep; 450 unsigned long chunksize, daemon_sleep, write_behind;
449 unsigned long bytes_read; 451 unsigned long bytes_read;
450 unsigned long long events; 452 unsigned long long events;
451 int err = -EINVAL; 453 int err = -EINVAL;
@@ -474,6 +476,7 @@ static int bitmap_read_sb(struct bitmap *bitmap)
474 476
475 chunksize = le32_to_cpu(sb->chunksize); 477 chunksize = le32_to_cpu(sb->chunksize);
476 daemon_sleep = le32_to_cpu(sb->daemon_sleep); 478 daemon_sleep = le32_to_cpu(sb->daemon_sleep);
479 write_behind = le32_to_cpu(sb->write_behind);
477 480
478 /* verify that the bitmap-specific fields are valid */ 481 /* verify that the bitmap-specific fields are valid */
479 if (sb->magic != cpu_to_le32(BITMAP_MAGIC)) 482 if (sb->magic != cpu_to_le32(BITMAP_MAGIC))
@@ -485,7 +488,9 @@ static int bitmap_read_sb(struct bitmap *bitmap)
485 else if ((1 << ffz(~chunksize)) != chunksize) 488 else if ((1 << ffz(~chunksize)) != chunksize)
486 reason = "bitmap chunksize not a power of 2"; 489 reason = "bitmap chunksize not a power of 2";
487 else if (daemon_sleep < 1 || daemon_sleep > 15) 490 else if (daemon_sleep < 1 || daemon_sleep > 15)
488 reason = "daemon sleep period out of range"; 491 reason = "daemon sleep period out of range (1-15s)";
492 else if (write_behind > COUNTER_MAX)
493 reason = "write-behind limit out of range (0 - 16383)";
489 if (reason) { 494 if (reason) {
490 printk(KERN_INFO "%s: invalid bitmap file superblock: %s\n", 495 printk(KERN_INFO "%s: invalid bitmap file superblock: %s\n",
491 bmname(bitmap), reason); 496 bmname(bitmap), reason);
@@ -518,8 +523,12 @@ success:
518 /* assign fields using values from superblock */ 523 /* assign fields using values from superblock */
519 bitmap->chunksize = chunksize; 524 bitmap->chunksize = chunksize;
520 bitmap->daemon_sleep = daemon_sleep; 525 bitmap->daemon_sleep = daemon_sleep;
526 bitmap->daemon_lastrun = jiffies;
527 bitmap->max_write_behind = write_behind;
521 bitmap->flags |= sb->state; 528 bitmap->flags |= sb->state;
522 bitmap->events_cleared = le64_to_cpu(sb->events_cleared); 529 bitmap->events_cleared = le64_to_cpu(sb->events_cleared);
530 if (sb->state & BITMAP_STALE)
531 bitmap->events_cleared = bitmap->mddev->events;
523 err = 0; 532 err = 0;
524out: 533out:
525 kunmap(bitmap->sb_page); 534 kunmap(bitmap->sb_page);
@@ -617,7 +626,7 @@ static void bitmap_file_unmap(struct bitmap *bitmap)
617 page_cache_release(sb_page); 626 page_cache_release(sb_page);
618} 627}
619 628
620static void bitmap_stop_daemons(struct bitmap *bitmap); 629static void bitmap_stop_daemon(struct bitmap *bitmap);
621 630
622/* dequeue the next item in a page list -- don't call from irq context */ 631/* dequeue the next item in a page list -- don't call from irq context */
623static struct page_list *dequeue_page(struct bitmap *bitmap) 632static struct page_list *dequeue_page(struct bitmap *bitmap)
@@ -659,7 +668,7 @@ static void bitmap_file_put(struct bitmap *bitmap)
659 bitmap->file = NULL; 668 bitmap->file = NULL;
660 spin_unlock_irqrestore(&bitmap->lock, flags); 669 spin_unlock_irqrestore(&bitmap->lock, flags);
661 670
662 bitmap_stop_daemons(bitmap); 671 bitmap_stop_daemon(bitmap);
663 672
664 drain_write_queues(bitmap); 673 drain_write_queues(bitmap);
665 674
@@ -818,7 +827,7 @@ int bitmap_unplug(struct bitmap *bitmap)
818 return 0; 827 return 0;
819} 828}
820 829
821static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset); 830static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed);
822/* * bitmap_init_from_disk -- called at bitmap_create time to initialize 831/* * bitmap_init_from_disk -- called at bitmap_create time to initialize
823 * the in-memory bitmap from the on-disk bitmap -- also, sets up the 832 * the in-memory bitmap from the on-disk bitmap -- also, sets up the
824 * memory mapping of the bitmap file 833 * memory mapping of the bitmap file
@@ -826,8 +835,11 @@ static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset);
826 * if there's no bitmap file, or if the bitmap file had been 835 * if there's no bitmap file, or if the bitmap file had been
827 * previously kicked from the array, we mark all the bits as 836 * previously kicked from the array, we mark all the bits as
828 * 1's in order to cause a full resync. 837 * 1's in order to cause a full resync.
838 *
839 * We ignore all bits for sectors that end earlier than 'start'.
840 * This is used when reading an out-of-date bitmap...
829 */ 841 */
830static int bitmap_init_from_disk(struct bitmap *bitmap) 842static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
831{ 843{
832 unsigned long i, chunks, index, oldindex, bit; 844 unsigned long i, chunks, index, oldindex, bit;
833 struct page *page = NULL, *oldpage = NULL; 845 struct page *page = NULL, *oldpage = NULL;
@@ -914,7 +926,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap)
914 * whole page and write it out 926 * whole page and write it out
915 */ 927 */
916 memset(page_address(page) + offset, 0xff, 928 memset(page_address(page) + offset, 0xff,
917 PAGE_SIZE - offset); 929 PAGE_SIZE - offset);
918 ret = write_page(bitmap, page, 1); 930 ret = write_page(bitmap, page, 1);
919 if (ret) { 931 if (ret) {
920 kunmap(page); 932 kunmap(page);
@@ -928,8 +940,11 @@ static int bitmap_init_from_disk(struct bitmap *bitmap)
928 } 940 }
929 if (test_bit(bit, page_address(page))) { 941 if (test_bit(bit, page_address(page))) {
930 /* if the disk bit is set, set the memory bit */ 942 /* if the disk bit is set, set the memory bit */
931 bitmap_set_memory_bits(bitmap, i << CHUNK_BLOCK_SHIFT(bitmap)); 943 bitmap_set_memory_bits(bitmap, i << CHUNK_BLOCK_SHIFT(bitmap),
944 ((i+1) << (CHUNK_BLOCK_SHIFT(bitmap)) >= start)
945 );
932 bit_cnt++; 946 bit_cnt++;
947 set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN);
933 } 948 }
934 } 949 }
935 950
@@ -1141,6 +1156,9 @@ static void bitmap_writeback_daemon(mddev_t *mddev)
1141 err = -EINTR; 1156 err = -EINTR;
1142 goto out; 1157 goto out;
1143 } 1158 }
1159 if (bitmap == NULL)
1160 /* about to be stopped. */
1161 return;
1144 1162
1145 PRINTK("%s: bitmap writeback daemon woke up...\n", bmname(bitmap)); 1163 PRINTK("%s: bitmap writeback daemon woke up...\n", bmname(bitmap));
1146 /* wait on bitmap page writebacks */ 1164 /* wait on bitmap page writebacks */
@@ -1170,21 +1188,12 @@ static void bitmap_writeback_daemon(mddev_t *mddev)
1170 } 1188 }
1171} 1189}
1172 1190
1173static int bitmap_start_daemon(struct bitmap *bitmap, mdk_thread_t **ptr, 1191static mdk_thread_t *bitmap_start_daemon(struct bitmap *bitmap,
1174 void (*func)(mddev_t *), char *name) 1192 void (*func)(mddev_t *), char *name)
1175{ 1193{
1176 mdk_thread_t *daemon; 1194 mdk_thread_t *daemon;
1177 unsigned long flags;
1178 char namebuf[32]; 1195 char namebuf[32];
1179 1196
1180 spin_lock_irqsave(&bitmap->lock, flags);
1181 *ptr = NULL;
1182
1183 if (!bitmap->file) /* no need for daemon if there's no backing file */
1184 goto out_unlock;
1185
1186 spin_unlock_irqrestore(&bitmap->lock, flags);
1187
1188#ifdef INJECT_FATAL_FAULT_2 1197#ifdef INJECT_FATAL_FAULT_2
1189 daemon = NULL; 1198 daemon = NULL;
1190#else 1199#else
@@ -1194,47 +1203,32 @@ static int bitmap_start_daemon(struct bitmap *bitmap, mdk_thread_t **ptr,
1194 if (!daemon) { 1203 if (!daemon) {
1195 printk(KERN_ERR "%s: failed to start bitmap daemon\n", 1204 printk(KERN_ERR "%s: failed to start bitmap daemon\n",
1196 bmname(bitmap)); 1205 bmname(bitmap));
1197 return -ECHILD; 1206 return ERR_PTR(-ECHILD);
1198 } 1207 }
1199 1208
1200 spin_lock_irqsave(&bitmap->lock, flags);
1201 *ptr = daemon;
1202
1203 md_wakeup_thread(daemon); /* start it running */ 1209 md_wakeup_thread(daemon); /* start it running */
1204 1210
1205 PRINTK("%s: %s daemon (pid %d) started...\n", 1211 PRINTK("%s: %s daemon (pid %d) started...\n",
1206 bmname(bitmap), name, daemon->tsk->pid); 1212 bmname(bitmap), name, daemon->tsk->pid);
1207out_unlock:
1208 spin_unlock_irqrestore(&bitmap->lock, flags);
1209 return 0;
1210}
1211 1213
1212static int bitmap_start_daemons(struct bitmap *bitmap) 1214 return daemon;
1213{
1214 int err = bitmap_start_daemon(bitmap, &bitmap->writeback_daemon,
1215 bitmap_writeback_daemon, "bitmap_wb");
1216 return err;
1217} 1215}
1218 1216
1219static void bitmap_stop_daemon(struct bitmap *bitmap, mdk_thread_t **ptr) 1217static void bitmap_stop_daemon(struct bitmap *bitmap)
1220{ 1218{
1221 mdk_thread_t *daemon; 1219 /* the daemon can't stop itself... it'll just exit instead... */
1222 unsigned long flags; 1220 if (bitmap->writeback_daemon && ! IS_ERR(bitmap->writeback_daemon) &&
1223 1221 current->pid != bitmap->writeback_daemon->tsk->pid) {
1224 spin_lock_irqsave(&bitmap->lock, flags); 1222 mdk_thread_t *daemon;
1225 daemon = *ptr; 1223 unsigned long flags;
1226 *ptr = NULL;
1227 spin_unlock_irqrestore(&bitmap->lock, flags);
1228 if (daemon)
1229 md_unregister_thread(daemon); /* destroy the thread */
1230}
1231 1224
1232static void bitmap_stop_daemons(struct bitmap *bitmap) 1225 spin_lock_irqsave(&bitmap->lock, flags);
1233{ 1226 daemon = bitmap->writeback_daemon;
1234 /* the daemons can't stop themselves... they'll just exit instead... */ 1227 bitmap->writeback_daemon = NULL;
1235 if (bitmap->writeback_daemon && 1228 spin_unlock_irqrestore(&bitmap->lock, flags);
1236 current->pid != bitmap->writeback_daemon->tsk->pid) 1229 if (daemon && ! IS_ERR(daemon))
1237 bitmap_stop_daemon(bitmap, &bitmap->writeback_daemon); 1230 md_unregister_thread(daemon); /* destroy the thread */
1231 }
1238} 1232}
1239 1233
1240static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, 1234static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap,
@@ -1274,9 +1268,16 @@ static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap,
1274 } 1268 }
1275} 1269}
1276 1270
1277int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors) 1271int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, int behind)
1278{ 1272{
1279 if (!bitmap) return 0; 1273 if (!bitmap) return 0;
1274
1275 if (behind) {
1276 atomic_inc(&bitmap->behind_writes);
1277 PRINTK(KERN_DEBUG "inc write-behind count %d/%d\n",
1278 atomic_read(&bitmap->behind_writes), bitmap->max_write_behind);
1279 }
1280
1280 while (sectors) { 1281 while (sectors) {
1281 int blocks; 1282 int blocks;
1282 bitmap_counter_t *bmc; 1283 bitmap_counter_t *bmc;
@@ -1311,9 +1312,15 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect
1311} 1312}
1312 1313
1313void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, 1314void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors,
1314 int success) 1315 int success, int behind)
1315{ 1316{
1316 if (!bitmap) return; 1317 if (!bitmap) return;
1318 if (behind) {
1319 atomic_dec(&bitmap->behind_writes);
1320 PRINTK(KERN_DEBUG "dec write-behind count %d/%d\n",
1321 atomic_read(&bitmap->behind_writes), bitmap->max_write_behind);
1322 }
1323
1317 while (sectors) { 1324 while (sectors) {
1318 int blocks; 1325 int blocks;
1319 unsigned long flags; 1326 unsigned long flags;
@@ -1424,7 +1431,7 @@ void bitmap_close_sync(struct bitmap *bitmap)
1424 } 1431 }
1425} 1432}
1426 1433
1427static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset) 1434static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed)
1428{ 1435{
1429 /* For each chunk covered by any of these sectors, set the 1436 /* For each chunk covered by any of these sectors, set the
1430 * counter to 1 and set resync_needed. They should all 1437 * counter to 1 and set resync_needed. They should all
@@ -1441,7 +1448,7 @@ static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset)
1441 } 1448 }
1442 if (! *bmc) { 1449 if (! *bmc) {
1443 struct page *page; 1450 struct page *page;
1444 *bmc = 1 | NEEDED_MASK; 1451 *bmc = 1 | (needed?NEEDED_MASK:0);
1445 bitmap_count_page(bitmap, offset, 1); 1452 bitmap_count_page(bitmap, offset, 1);
1446 page = filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap)); 1453 page = filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap));
1447 set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN); 1454 set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN);
@@ -1476,17 +1483,14 @@ void bitmap_flush(mddev_t *mddev)
1476/* 1483/*
1477 * free memory that was allocated 1484 * free memory that was allocated
1478 */ 1485 */
1479void bitmap_destroy(mddev_t *mddev) 1486static void bitmap_free(struct bitmap *bitmap)
1480{ 1487{
1481 unsigned long k, pages; 1488 unsigned long k, pages;
1482 struct bitmap_page *bp; 1489 struct bitmap_page *bp;
1483 struct bitmap *bitmap = mddev->bitmap;
1484 1490
1485 if (!bitmap) /* there was no bitmap */ 1491 if (!bitmap) /* there was no bitmap */
1486 return; 1492 return;
1487 1493
1488 mddev->bitmap = NULL; /* disconnect from the md device */
1489
1490 /* release the bitmap file and kill the daemon */ 1494 /* release the bitmap file and kill the daemon */
1491 bitmap_file_put(bitmap); 1495 bitmap_file_put(bitmap);
1492 1496
@@ -1504,6 +1508,17 @@ void bitmap_destroy(mddev_t *mddev)
1504 kfree(bp); 1508 kfree(bp);
1505 kfree(bitmap); 1509 kfree(bitmap);
1506} 1510}
1511void bitmap_destroy(mddev_t *mddev)
1512{
1513 struct bitmap *bitmap = mddev->bitmap;
1514
1515 if (!bitmap) /* there was no bitmap */
1516 return;
1517
1518 mddev->bitmap = NULL; /* disconnect from the md device */
1519
1520 bitmap_free(bitmap);
1521}
1507 1522
1508/* 1523/*
1509 * initialize the bitmap structure 1524 * initialize the bitmap structure
@@ -1517,6 +1532,7 @@ int bitmap_create(mddev_t *mddev)
1517 unsigned long pages; 1532 unsigned long pages;
1518 struct file *file = mddev->bitmap_file; 1533 struct file *file = mddev->bitmap_file;
1519 int err; 1534 int err;
1535 sector_t start;
1520 1536
1521 BUG_ON(sizeof(bitmap_super_t) != 256); 1537 BUG_ON(sizeof(bitmap_super_t) != 256);
1522 1538
@@ -1533,15 +1549,15 @@ int bitmap_create(mddev_t *mddev)
1533 1549
1534 spin_lock_init(&bitmap->lock); 1550 spin_lock_init(&bitmap->lock);
1535 bitmap->mddev = mddev; 1551 bitmap->mddev = mddev;
1536 mddev->bitmap = bitmap;
1537 1552
1538 spin_lock_init(&bitmap->write_lock); 1553 spin_lock_init(&bitmap->write_lock);
1539 INIT_LIST_HEAD(&bitmap->complete_pages); 1554 INIT_LIST_HEAD(&bitmap->complete_pages);
1540 init_waitqueue_head(&bitmap->write_wait); 1555 init_waitqueue_head(&bitmap->write_wait);
1541 bitmap->write_pool = mempool_create(WRITE_POOL_SIZE, write_pool_alloc, 1556 bitmap->write_pool = mempool_create(WRITE_POOL_SIZE, write_pool_alloc,
1542 write_pool_free, NULL); 1557 write_pool_free, NULL);
1558 err = -ENOMEM;
1543 if (!bitmap->write_pool) 1559 if (!bitmap->write_pool)
1544 return -ENOMEM; 1560 goto error;
1545 1561
1546 bitmap->file = file; 1562 bitmap->file = file;
1547 bitmap->offset = mddev->bitmap_offset; 1563 bitmap->offset = mddev->bitmap_offset;
@@ -1549,7 +1565,7 @@ int bitmap_create(mddev_t *mddev)
1549 /* read superblock from bitmap file (this sets bitmap->chunksize) */ 1565 /* read superblock from bitmap file (this sets bitmap->chunksize) */
1550 err = bitmap_read_sb(bitmap); 1566 err = bitmap_read_sb(bitmap);
1551 if (err) 1567 if (err)
1552 return err; 1568 goto error;
1553 1569
1554 bitmap->chunkshift = find_first_bit(&bitmap->chunksize, 1570 bitmap->chunkshift = find_first_bit(&bitmap->chunksize,
1555 sizeof(bitmap->chunksize)); 1571 sizeof(bitmap->chunksize));
@@ -1573,27 +1589,44 @@ int bitmap_create(mddev_t *mddev)
1573#else 1589#else
1574 bitmap->bp = kmalloc(pages * sizeof(*bitmap->bp), GFP_KERNEL); 1590 bitmap->bp = kmalloc(pages * sizeof(*bitmap->bp), GFP_KERNEL);
1575#endif 1591#endif
1592 err = -ENOMEM;
1576 if (!bitmap->bp) 1593 if (!bitmap->bp)
1577 return -ENOMEM; 1594 goto error;
1578 memset(bitmap->bp, 0, pages * sizeof(*bitmap->bp)); 1595 memset(bitmap->bp, 0, pages * sizeof(*bitmap->bp));
1579 1596
1580 bitmap->flags |= BITMAP_ACTIVE; 1597 bitmap->flags |= BITMAP_ACTIVE;
1581 1598
1582 /* now that we have some pages available, initialize the in-memory 1599 /* now that we have some pages available, initialize the in-memory
1583 * bitmap from the on-disk bitmap */ 1600 * bitmap from the on-disk bitmap */
1584 err = bitmap_init_from_disk(bitmap); 1601 start = 0;
1602 if (mddev->degraded == 0
1603 || bitmap->events_cleared == mddev->events)
1604 /* no need to keep dirty bits to optimise a re-add of a missing device */
1605 start = mddev->recovery_cp;
1606 err = bitmap_init_from_disk(bitmap, start);
1585 1607
1586 if (err) 1608 if (err)
1587 return err; 1609 goto error;
1588 1610
1589 printk(KERN_INFO "created bitmap (%lu pages) for device %s\n", 1611 printk(KERN_INFO "created bitmap (%lu pages) for device %s\n",
1590 pages, bmname(bitmap)); 1612 pages, bmname(bitmap));
1591 1613
1592 /* kick off the bitmap daemons */ 1614 mddev->bitmap = bitmap;
1593 err = bitmap_start_daemons(bitmap); 1615
1594 if (err) 1616 if (file)
1595 return err; 1617 /* kick off the bitmap writeback daemon */
1618 bitmap->writeback_daemon =
1619 bitmap_start_daemon(bitmap,
1620 bitmap_writeback_daemon,
1621 "bitmap_wb");
1622
1623 if (IS_ERR(bitmap->writeback_daemon))
1624 return PTR_ERR(bitmap->writeback_daemon);
1596 return bitmap_update_sb(bitmap); 1625 return bitmap_update_sb(bitmap);
1626
1627 error:
1628 bitmap_free(bitmap);
1629 return err;
1597} 1630}
1598 1631
1599/* the bitmap API -- for raid personalities */ 1632/* the bitmap API -- for raid personalities */
diff --git a/drivers/md/dm-exception-store.c b/drivers/md/dm-exception-store.c
index 17212b4201..cc07bbebbb 100644
--- a/drivers/md/dm-exception-store.c
+++ b/drivers/md/dm-exception-store.c
@@ -568,12 +568,9 @@ int dm_create_persistent(struct exception_store *store, uint32_t chunk_size)
568 568
569 bad: 569 bad:
570 dm_io_put(sectors_to_pages(chunk_size)); 570 dm_io_put(sectors_to_pages(chunk_size));
571 if (ps) { 571 if (ps && ps->area)
572 if (ps->area) 572 free_area(ps);
573 free_area(ps); 573 kfree(ps);
574
575 kfree(ps);
576 }
577 return r; 574 return r;
578} 575}
579 576
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index b08df8b9b2..8632825137 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -375,16 +375,18 @@ static void rh_inc(struct region_hash *rh, region_t region)
375 375
376 read_lock(&rh->hash_lock); 376 read_lock(&rh->hash_lock);
377 reg = __rh_find(rh, region); 377 reg = __rh_find(rh, region);
378
379 atomic_inc(&reg->pending);
380
381 spin_lock_irq(&rh->region_lock);
378 if (reg->state == RH_CLEAN) { 382 if (reg->state == RH_CLEAN) {
379 rh->log->type->mark_region(rh->log, reg->key); 383 rh->log->type->mark_region(rh->log, reg->key);
380 384
381 spin_lock_irq(&rh->region_lock);
382 reg->state = RH_DIRTY; 385 reg->state = RH_DIRTY;
383 list_del_init(&reg->list); /* take off the clean list */ 386 list_del_init(&reg->list); /* take off the clean list */
384 spin_unlock_irq(&rh->region_lock);
385 } 387 }
388 spin_unlock_irq(&rh->region_lock);
386 389
387 atomic_inc(&reg->pending);
388 read_unlock(&rh->hash_lock); 390 read_unlock(&rh->hash_lock);
389} 391}
390 392
@@ -408,6 +410,10 @@ static void rh_dec(struct region_hash *rh, region_t region)
408 410
409 if (atomic_dec_and_test(&reg->pending)) { 411 if (atomic_dec_and_test(&reg->pending)) {
410 spin_lock_irqsave(&rh->region_lock, flags); 412 spin_lock_irqsave(&rh->region_lock, flags);
413 if (atomic_read(&reg->pending)) { /* check race */
414 spin_unlock_irqrestore(&rh->region_lock, flags);
415 return;
416 }
411 if (reg->state == RH_RECOVERING) { 417 if (reg->state == RH_RECOVERING) {
412 list_add_tail(&reg->list, &rh->quiesced_regions); 418 list_add_tail(&reg->list, &rh->quiesced_regions);
413 } else { 419 } else {
diff --git a/drivers/md/linear.c b/drivers/md/linear.c
index 8d740013d7..bb279fad2f 100644
--- a/drivers/md/linear.c
+++ b/drivers/md/linear.c
@@ -38,7 +38,8 @@ static inline dev_info_t *which_dev(mddev_t *mddev, sector_t sector)
38 /* 38 /*
39 * sector_div(a,b) returns the remainer and sets a to a/b 39 * sector_div(a,b) returns the remainer and sets a to a/b
40 */ 40 */
41 (void)sector_div(block, conf->smallest->size); 41 block >>= conf->preshift;
42 (void)sector_div(block, conf->hash_spacing);
42 hash = conf->hash_table[block]; 43 hash = conf->hash_table[block];
43 44
44 while ((sector>>1) >= (hash->size + hash->offset)) 45 while ((sector>>1) >= (hash->size + hash->offset))
@@ -47,7 +48,7 @@ static inline dev_info_t *which_dev(mddev_t *mddev, sector_t sector)
47} 48}
48 49
49/** 50/**
50 * linear_mergeable_bvec -- tell bio layer if a two requests can be merged 51 * linear_mergeable_bvec -- tell bio layer if two requests can be merged
51 * @q: request queue 52 * @q: request queue
52 * @bio: the buffer head that's been built up so far 53 * @bio: the buffer head that's been built up so far
53 * @biovec: the request that could be merged to it. 54 * @biovec: the request that could be merged to it.
@@ -116,7 +117,7 @@ static int linear_run (mddev_t *mddev)
116 dev_info_t **table; 117 dev_info_t **table;
117 mdk_rdev_t *rdev; 118 mdk_rdev_t *rdev;
118 int i, nb_zone, cnt; 119 int i, nb_zone, cnt;
119 sector_t start; 120 sector_t min_spacing;
120 sector_t curr_offset; 121 sector_t curr_offset;
121 struct list_head *tmp; 122 struct list_head *tmp;
122 123
@@ -127,11 +128,6 @@ static int linear_run (mddev_t *mddev)
127 memset(conf, 0, sizeof(*conf) + mddev->raid_disks*sizeof(dev_info_t)); 128 memset(conf, 0, sizeof(*conf) + mddev->raid_disks*sizeof(dev_info_t));
128 mddev->private = conf; 129 mddev->private = conf;
129 130
130 /*
131 * Find the smallest device.
132 */
133
134 conf->smallest = NULL;
135 cnt = 0; 131 cnt = 0;
136 mddev->array_size = 0; 132 mddev->array_size = 0;
137 133
@@ -159,8 +155,6 @@ static int linear_run (mddev_t *mddev)
159 disk->size = rdev->size; 155 disk->size = rdev->size;
160 mddev->array_size += rdev->size; 156 mddev->array_size += rdev->size;
161 157
162 if (!conf->smallest || (disk->size < conf->smallest->size))
163 conf->smallest = disk;
164 cnt++; 158 cnt++;
165 } 159 }
166 if (cnt != mddev->raid_disks) { 160 if (cnt != mddev->raid_disks) {
@@ -168,6 +162,36 @@ static int linear_run (mddev_t *mddev)
168 goto out; 162 goto out;
169 } 163 }
170 164
165 min_spacing = mddev->array_size;
166 sector_div(min_spacing, PAGE_SIZE/sizeof(struct dev_info *));
167
168 /* min_spacing is the minimum spacing that will fit the hash
169 * table in one PAGE. This may be much smaller than needed.
170 * We find the smallest non-terminal set of consecutive devices
171 * that is larger than min_spacing as use the size of that as
172 * the actual spacing
173 */
174 conf->hash_spacing = mddev->array_size;
175 for (i=0; i < cnt-1 ; i++) {
176 sector_t sz = 0;
177 int j;
178 for (j=i; i<cnt-1 && sz < min_spacing ; j++)
179 sz += conf->disks[j].size;
180 if (sz >= min_spacing && sz < conf->hash_spacing)
181 conf->hash_spacing = sz;
182 }
183
184 /* hash_spacing may be too large for sector_div to work with,
185 * so we might need to pre-shift
186 */
187 conf->preshift = 0;
188 if (sizeof(sector_t) > sizeof(u32)) {
189 sector_t space = conf->hash_spacing;
190 while (space > (sector_t)(~(u32)0)) {
191 space >>= 1;
192 conf->preshift++;
193 }
194 }
171 /* 195 /*
172 * This code was restructured to work around a gcc-2.95.3 internal 196 * This code was restructured to work around a gcc-2.95.3 internal
173 * compiler error. Alter it with care. 197 * compiler error. Alter it with care.
@@ -177,39 +201,52 @@ static int linear_run (mddev_t *mddev)
177 unsigned round; 201 unsigned round;
178 unsigned long base; 202 unsigned long base;
179 203
180 sz = mddev->array_size; 204 sz = mddev->array_size >> conf->preshift;
181 base = conf->smallest->size; 205 sz += 1; /* force round-up */
206 base = conf->hash_spacing >> conf->preshift;
182 round = sector_div(sz, base); 207 round = sector_div(sz, base);
183 nb_zone = conf->nr_zones = sz + (round ? 1 : 0); 208 nb_zone = sz + (round ? 1 : 0);
184 } 209 }
185 210 BUG_ON(nb_zone > PAGE_SIZE / sizeof(struct dev_info *));
186 conf->hash_table = kmalloc (sizeof (dev_info_t*) * nb_zone, 211
212 conf->hash_table = kmalloc (sizeof (struct dev_info *) * nb_zone,
187 GFP_KERNEL); 213 GFP_KERNEL);
188 if (!conf->hash_table) 214 if (!conf->hash_table)
189 goto out; 215 goto out;
190 216
191 /* 217 /*
192 * Here we generate the linear hash table 218 * Here we generate the linear hash table
219 * First calculate the device offsets.
193 */ 220 */
221 conf->disks[0].offset = 0;
222 for (i=1; i<mddev->raid_disks; i++)
223 conf->disks[i].offset =
224 conf->disks[i-1].offset +
225 conf->disks[i-1].size;
226
194 table = conf->hash_table; 227 table = conf->hash_table;
195 start = 0;
196 curr_offset = 0; 228 curr_offset = 0;
197 for (i = 0; i < cnt; i++) { 229 i = 0;
198 dev_info_t *disk = conf->disks + i; 230 for (curr_offset = 0;
231 curr_offset < mddev->array_size;
232 curr_offset += conf->hash_spacing) {
199 233
200 disk->offset = curr_offset; 234 while (i < mddev->raid_disks-1 &&
201 curr_offset += disk->size; 235 curr_offset >= conf->disks[i+1].offset)
236 i++;
202 237
203 /* 'curr_offset' is the end of this disk 238 *table ++ = conf->disks + i;
204 * 'start' is the start of table 239 }
240
241 if (conf->preshift) {
242 conf->hash_spacing >>= conf->preshift;
243 /* round hash_spacing up so that when we divide by it,
244 * we err on the side of "too-low", which is safest.
205 */ 245 */
206 while (start < curr_offset) { 246 conf->hash_spacing++;
207 *table++ = disk;
208 start += conf->smallest->size;
209 }
210 } 247 }
211 if (table-conf->hash_table != nb_zone) 248
212 BUG(); 249 BUG_ON(table - conf->hash_table > nb_zone);
213 250
214 blk_queue_merge_bvec(mddev->queue, linear_mergeable_bvec); 251 blk_queue_merge_bvec(mddev->queue, linear_mergeable_bvec);
215 mddev->queue->unplug_fn = linear_unplug; 252 mddev->queue->unplug_fn = linear_unplug;
@@ -238,6 +275,11 @@ static int linear_make_request (request_queue_t *q, struct bio *bio)
238 dev_info_t *tmp_dev; 275 dev_info_t *tmp_dev;
239 sector_t block; 276 sector_t block;
240 277
278 if (unlikely(bio_barrier(bio))) {
279 bio_endio(bio, bio->bi_size, -EOPNOTSUPP);
280 return 0;
281 }
282
241 if (bio_data_dir(bio)==WRITE) { 283 if (bio_data_dir(bio)==WRITE) {
242 disk_stat_inc(mddev->gendisk, writes); 284 disk_stat_inc(mddev->gendisk, writes);
243 disk_stat_add(mddev->gendisk, write_sectors, bio_sectors(bio)); 285 disk_stat_add(mddev->gendisk, write_sectors, bio_sectors(bio));
@@ -294,7 +336,7 @@ static void linear_status (struct seq_file *seq, mddev_t *mddev)
294 sector_t s = 0; 336 sector_t s = 0;
295 337
296 seq_printf(seq, " "); 338 seq_printf(seq, " ");
297 for (j = 0; j < conf->nr_zones; j++) 339 for (j = 0; j < mddev->raid_disks; j++)
298 { 340 {
299 char b[BDEVNAME_SIZE]; 341 char b[BDEVNAME_SIZE];
300 s += conf->smallest_size; 342 s += conf->smallest_size;
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 20ca80b7dc..2897df90df 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -34,6 +34,7 @@
34 34
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/config.h> 36#include <linux/config.h>
37#include <linux/kthread.h>
37#include <linux/linkage.h> 38#include <linux/linkage.h>
38#include <linux/raid/md.h> 39#include <linux/raid/md.h>
39#include <linux/raid/bitmap.h> 40#include <linux/raid/bitmap.h>
@@ -73,7 +74,7 @@ static DEFINE_SPINLOCK(pers_lock);
73 * Current RAID-1,4,5 parallel reconstruction 'guaranteed speed limit' 74 * Current RAID-1,4,5 parallel reconstruction 'guaranteed speed limit'
74 * is 1000 KB/sec, so the extra system load does not show up that much. 75 * is 1000 KB/sec, so the extra system load does not show up that much.
75 * Increase it if you want to have more _guaranteed_ speed. Note that 76 * Increase it if you want to have more _guaranteed_ speed. Note that
76 * the RAID driver will use the maximum available bandwith if the IO 77 * the RAID driver will use the maximum available bandwidth if the IO
77 * subsystem is idle. There is also an 'absolute maximum' reconstruction 78 * subsystem is idle. There is also an 'absolute maximum' reconstruction
78 * speed limit - in case reconstruction slows down your system despite 79 * speed limit - in case reconstruction slows down your system despite
79 * idle IO detection. 80 * idle IO detection.
@@ -393,7 +394,7 @@ int sync_page_io(struct block_device *bdev, sector_t sector, int size,
393 return ret; 394 return ret;
394} 395}
395 396
396static int read_disk_sb(mdk_rdev_t * rdev) 397static int read_disk_sb(mdk_rdev_t * rdev, int size)
397{ 398{
398 char b[BDEVNAME_SIZE]; 399 char b[BDEVNAME_SIZE];
399 if (!rdev->sb_page) { 400 if (!rdev->sb_page) {
@@ -404,7 +405,7 @@ static int read_disk_sb(mdk_rdev_t * rdev)
404 return 0; 405 return 0;
405 406
406 407
407 if (!sync_page_io(rdev->bdev, rdev->sb_offset<<1, MD_SB_BYTES, rdev->sb_page, READ)) 408 if (!sync_page_io(rdev->bdev, rdev->sb_offset<<1, size, rdev->sb_page, READ))
408 goto fail; 409 goto fail;
409 rdev->sb_loaded = 1; 410 rdev->sb_loaded = 1;
410 return 0; 411 return 0;
@@ -531,7 +532,7 @@ static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version
531 sb_offset = calc_dev_sboffset(rdev->bdev); 532 sb_offset = calc_dev_sboffset(rdev->bdev);
532 rdev->sb_offset = sb_offset; 533 rdev->sb_offset = sb_offset;
533 534
534 ret = read_disk_sb(rdev); 535 ret = read_disk_sb(rdev, MD_SB_BYTES);
535 if (ret) return ret; 536 if (ret) return ret;
536 537
537 ret = -EINVAL; 538 ret = -EINVAL;
@@ -564,6 +565,7 @@ static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version
564 565
565 rdev->preferred_minor = sb->md_minor; 566 rdev->preferred_minor = sb->md_minor;
566 rdev->data_offset = 0; 567 rdev->data_offset = 0;
568 rdev->sb_size = MD_SB_BYTES;
567 569
568 if (sb->level == LEVEL_MULTIPATH) 570 if (sb->level == LEVEL_MULTIPATH)
569 rdev->desc_nr = -1; 571 rdev->desc_nr = -1;
@@ -623,6 +625,7 @@ static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev)
623 mddev->size = sb->size; 625 mddev->size = sb->size;
624 mddev->events = md_event(sb); 626 mddev->events = md_event(sb);
625 mddev->bitmap_offset = 0; 627 mddev->bitmap_offset = 0;
628 mddev->default_bitmap_offset = MD_SB_BYTES >> 9;
626 629
627 if (sb->state & (1<<MD_SB_CLEAN)) 630 if (sb->state & (1<<MD_SB_CLEAN))
628 mddev->recovery_cp = MaxSector; 631 mddev->recovery_cp = MaxSector;
@@ -643,12 +646,12 @@ static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev)
643 646
644 if (sb->state & (1<<MD_SB_BITMAP_PRESENT) && 647 if (sb->state & (1<<MD_SB_BITMAP_PRESENT) &&
645 mddev->bitmap_file == NULL) { 648 mddev->bitmap_file == NULL) {
646 if (mddev->level != 1) { 649 if (mddev->level != 1 && mddev->level != 5 && mddev->level != 6) {
647 /* FIXME use a better test */ 650 /* FIXME use a better test */
648 printk(KERN_WARNING "md: bitmaps only support for raid1\n"); 651 printk(KERN_WARNING "md: bitmaps only support for raid1\n");
649 return -EINVAL; 652 return -EINVAL;
650 } 653 }
651 mddev->bitmap_offset = (MD_SB_BYTES >> 9); 654 mddev->bitmap_offset = mddev->default_bitmap_offset;
652 } 655 }
653 656
654 } else if (mddev->pers == NULL) { 657 } else if (mddev->pers == NULL) {
@@ -669,6 +672,7 @@ static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev)
669 672
670 if (mddev->level != LEVEL_MULTIPATH) { 673 if (mddev->level != LEVEL_MULTIPATH) {
671 rdev->faulty = 0; 674 rdev->faulty = 0;
675 rdev->flags = 0;
672 desc = sb->disks + rdev->desc_nr; 676 desc = sb->disks + rdev->desc_nr;
673 677
674 if (desc->state & (1<<MD_DISK_FAULTY)) 678 if (desc->state & (1<<MD_DISK_FAULTY))
@@ -678,6 +682,8 @@ static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev)
678 rdev->in_sync = 1; 682 rdev->in_sync = 1;
679 rdev->raid_disk = desc->raid_disk; 683 rdev->raid_disk = desc->raid_disk;
680 } 684 }
685 if (desc->state & (1<<MD_DISK_WRITEMOSTLY))
686 set_bit(WriteMostly, &rdev->flags);
681 } else /* MULTIPATH are always insync */ 687 } else /* MULTIPATH are always insync */
682 rdev->in_sync = 1; 688 rdev->in_sync = 1;
683 return 0; 689 return 0;
@@ -706,6 +712,8 @@ static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev)
706 int i; 712 int i;
707 int active=0, working=0,failed=0,spare=0,nr_disks=0; 713 int active=0, working=0,failed=0,spare=0,nr_disks=0;
708 714
715 rdev->sb_size = MD_SB_BYTES;
716
709 sb = (mdp_super_t*)page_address(rdev->sb_page); 717 sb = (mdp_super_t*)page_address(rdev->sb_page);
710 718
711 memset(sb, 0, sizeof(*sb)); 719 memset(sb, 0, sizeof(*sb));
@@ -776,6 +784,8 @@ static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev)
776 spare++; 784 spare++;
777 working++; 785 working++;
778 } 786 }
787 if (test_bit(WriteMostly, &rdev2->flags))
788 d->state |= (1<<MD_DISK_WRITEMOSTLY);
779 } 789 }
780 790
781 /* now set the "removed" and "faulty" bits on any missing devices */ 791 /* now set the "removed" and "faulty" bits on any missing devices */
@@ -831,6 +841,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
831 int ret; 841 int ret;
832 sector_t sb_offset; 842 sector_t sb_offset;
833 char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; 843 char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE];
844 int bmask;
834 845
835 /* 846 /*
836 * Calculate the position of the superblock. 847 * Calculate the position of the superblock.
@@ -859,7 +870,10 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
859 } 870 }
860 rdev->sb_offset = sb_offset; 871 rdev->sb_offset = sb_offset;
861 872
862 ret = read_disk_sb(rdev); 873 /* superblock is rarely larger than 1K, but it can be larger,
874 * and it is safe to read 4k, so we do that
875 */
876 ret = read_disk_sb(rdev, 4096);
863 if (ret) return ret; 877 if (ret) return ret;
864 878
865 879
@@ -869,7 +883,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
869 sb->major_version != cpu_to_le32(1) || 883 sb->major_version != cpu_to_le32(1) ||
870 le32_to_cpu(sb->max_dev) > (4096-256)/2 || 884 le32_to_cpu(sb->max_dev) > (4096-256)/2 ||
871 le64_to_cpu(sb->super_offset) != (rdev->sb_offset<<1) || 885 le64_to_cpu(sb->super_offset) != (rdev->sb_offset<<1) ||
872 sb->feature_map != 0) 886 (le32_to_cpu(sb->feature_map) & ~MD_FEATURE_ALL) != 0)
873 return -EINVAL; 887 return -EINVAL;
874 888
875 if (calc_sb_1_csum(sb) != sb->sb_csum) { 889 if (calc_sb_1_csum(sb) != sb->sb_csum) {
@@ -885,6 +899,11 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
885 rdev->preferred_minor = 0xffff; 899 rdev->preferred_minor = 0xffff;
886 rdev->data_offset = le64_to_cpu(sb->data_offset); 900 rdev->data_offset = le64_to_cpu(sb->data_offset);
887 901
902 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
903 bmask = queue_hardsect_size(rdev->bdev->bd_disk->queue)-1;
904 if (rdev->sb_size & bmask)
905 rdev-> sb_size = (rdev->sb_size | bmask)+1;
906
888 if (refdev == 0) 907 if (refdev == 0)
889 return 1; 908 return 1;
890 else { 909 else {
@@ -939,13 +958,15 @@ static int super_1_validate(mddev_t *mddev, mdk_rdev_t *rdev)
939 mddev->size = le64_to_cpu(sb->size)/2; 958 mddev->size = le64_to_cpu(sb->size)/2;
940 mddev->events = le64_to_cpu(sb->events); 959 mddev->events = le64_to_cpu(sb->events);
941 mddev->bitmap_offset = 0; 960 mddev->bitmap_offset = 0;
961 mddev->default_bitmap_offset = 0;
962 mddev->default_bitmap_offset = 1024;
942 963
943 mddev->recovery_cp = le64_to_cpu(sb->resync_offset); 964 mddev->recovery_cp = le64_to_cpu(sb->resync_offset);
944 memcpy(mddev->uuid, sb->set_uuid, 16); 965 memcpy(mddev->uuid, sb->set_uuid, 16);
945 966
946 mddev->max_disks = (4096-256)/2; 967 mddev->max_disks = (4096-256)/2;
947 968
948 if ((le32_to_cpu(sb->feature_map) & 1) && 969 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET) &&
949 mddev->bitmap_file == NULL ) { 970 mddev->bitmap_file == NULL ) {
950 if (mddev->level != 1) { 971 if (mddev->level != 1) {
951 printk(KERN_WARNING "md: bitmaps only supported for raid1\n"); 972 printk(KERN_WARNING "md: bitmaps only supported for raid1\n");
@@ -986,6 +1007,9 @@ static int super_1_validate(mddev_t *mddev, mdk_rdev_t *rdev)
986 rdev->raid_disk = role; 1007 rdev->raid_disk = role;
987 break; 1008 break;
988 } 1009 }
1010 rdev->flags = 0;
1011 if (sb->devflags & WriteMostly1)
1012 set_bit(WriteMostly, &rdev->flags);
989 } else /* MULTIPATH are always insync */ 1013 } else /* MULTIPATH are always insync */
990 rdev->in_sync = 1; 1014 rdev->in_sync = 1;
991 1015
@@ -1017,7 +1041,7 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev)
1017 1041
1018 if (mddev->bitmap && mddev->bitmap_file == NULL) { 1042 if (mddev->bitmap && mddev->bitmap_file == NULL) {
1019 sb->bitmap_offset = cpu_to_le32((__u32)mddev->bitmap_offset); 1043 sb->bitmap_offset = cpu_to_le32((__u32)mddev->bitmap_offset);
1020 sb->feature_map = cpu_to_le32(1); 1044 sb->feature_map = cpu_to_le32(MD_FEATURE_BITMAP_OFFSET);
1021 } 1045 }
1022 1046
1023 max_dev = 0; 1047 max_dev = 0;
@@ -1363,7 +1387,7 @@ repeat:
1363 dprintk("%s ", bdevname(rdev->bdev,b)); 1387 dprintk("%s ", bdevname(rdev->bdev,b));
1364 if (!rdev->faulty) { 1388 if (!rdev->faulty) {
1365 md_super_write(mddev,rdev, 1389 md_super_write(mddev,rdev,
1366 rdev->sb_offset<<1, MD_SB_BYTES, 1390 rdev->sb_offset<<1, rdev->sb_size,
1367 rdev->sb_page); 1391 rdev->sb_page);
1368 dprintk(KERN_INFO "(write) %s's sb offset: %llu\n", 1392 dprintk(KERN_INFO "(write) %s's sb offset: %llu\n",
1369 bdevname(rdev->bdev,b), 1393 bdevname(rdev->bdev,b),
@@ -2073,6 +2097,8 @@ static int get_array_info(mddev_t * mddev, void __user * arg)
2073 info.state = 0; 2097 info.state = 0;
2074 if (mddev->in_sync) 2098 if (mddev->in_sync)
2075 info.state = (1<<MD_SB_CLEAN); 2099 info.state = (1<<MD_SB_CLEAN);
2100 if (mddev->bitmap && mddev->bitmap_offset)
2101 info.state = (1<<MD_SB_BITMAP_PRESENT);
2076 info.active_disks = active; 2102 info.active_disks = active;
2077 info.working_disks = working; 2103 info.working_disks = working;
2078 info.failed_disks = failed; 2104 info.failed_disks = failed;
@@ -2087,7 +2113,7 @@ static int get_array_info(mddev_t * mddev, void __user * arg)
2087 return 0; 2113 return 0;
2088} 2114}
2089 2115
2090static int get_bitmap_file(mddev_t * mddev, void * arg) 2116static int get_bitmap_file(mddev_t * mddev, void __user * arg)
2091{ 2117{
2092 mdu_bitmap_file_t *file = NULL; /* too big for stack allocation */ 2118 mdu_bitmap_file_t *file = NULL; /* too big for stack allocation */
2093 char *ptr, *buf = NULL; 2119 char *ptr, *buf = NULL;
@@ -2146,6 +2172,8 @@ static int get_disk_info(mddev_t * mddev, void __user * arg)
2146 info.state |= (1<<MD_DISK_ACTIVE); 2172 info.state |= (1<<MD_DISK_ACTIVE);
2147 info.state |= (1<<MD_DISK_SYNC); 2173 info.state |= (1<<MD_DISK_SYNC);
2148 } 2174 }
2175 if (test_bit(WriteMostly, &rdev->flags))
2176 info.state |= (1<<MD_DISK_WRITEMOSTLY);
2149 } else { 2177 } else {
2150 info.major = info.minor = 0; 2178 info.major = info.minor = 0;
2151 info.raid_disk = -1; 2179 info.raid_disk = -1;
@@ -2210,8 +2238,11 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
2210 mdname(mddev)); 2238 mdname(mddev));
2211 return -EINVAL; 2239 return -EINVAL;
2212 } 2240 }
2213 rdev = md_import_device(dev, mddev->major_version, 2241 if (mddev->persistent)
2214 mddev->minor_version); 2242 rdev = md_import_device(dev, mddev->major_version,
2243 mddev->minor_version);
2244 else
2245 rdev = md_import_device(dev, -1, -1);
2215 if (IS_ERR(rdev)) { 2246 if (IS_ERR(rdev)) {
2216 printk(KERN_WARNING 2247 printk(KERN_WARNING
2217 "md: md_import_device returned %ld\n", 2248 "md: md_import_device returned %ld\n",
@@ -2231,6 +2262,9 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
2231 rdev->saved_raid_disk = rdev->raid_disk; 2262 rdev->saved_raid_disk = rdev->raid_disk;
2232 2263
2233 rdev->in_sync = 0; /* just to be sure */ 2264 rdev->in_sync = 0; /* just to be sure */
2265 if (info->state & (1<<MD_DISK_WRITEMOSTLY))
2266 set_bit(WriteMostly, &rdev->flags);
2267
2234 rdev->raid_disk = -1; 2268 rdev->raid_disk = -1;
2235 err = bind_rdev_to_array(rdev, mddev); 2269 err = bind_rdev_to_array(rdev, mddev);
2236 if (err) 2270 if (err)
@@ -2271,6 +2305,9 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
2271 else 2305 else
2272 rdev->in_sync = 0; 2306 rdev->in_sync = 0;
2273 2307
2308 if (info->state & (1<<MD_DISK_WRITEMOSTLY))
2309 set_bit(WriteMostly, &rdev->flags);
2310
2274 err = bind_rdev_to_array(rdev, mddev); 2311 err = bind_rdev_to_array(rdev, mddev);
2275 if (err) { 2312 if (err) {
2276 export_rdev(rdev); 2313 export_rdev(rdev);
@@ -2430,25 +2467,51 @@ static int set_bitmap_file(mddev_t *mddev, int fd)
2430{ 2467{
2431 int err; 2468 int err;
2432 2469
2433 if (mddev->pers) 2470 if (mddev->pers) {
2434 return -EBUSY; 2471 if (!mddev->pers->quiesce)
2472 return -EBUSY;
2473 if (mddev->recovery || mddev->sync_thread)
2474 return -EBUSY;
2475 /* we should be able to change the bitmap.. */
2476 }
2435 2477
2436 mddev->bitmap_file = fget(fd);
2437 2478
2438 if (mddev->bitmap_file == NULL) { 2479 if (fd >= 0) {
2439 printk(KERN_ERR "%s: error: failed to get bitmap file\n", 2480 if (mddev->bitmap)
2440 mdname(mddev)); 2481 return -EEXIST; /* cannot add when bitmap is present */
2441 return -EBADF; 2482 mddev->bitmap_file = fget(fd);
2442 }
2443 2483
2444 err = deny_bitmap_write_access(mddev->bitmap_file); 2484 if (mddev->bitmap_file == NULL) {
2445 if (err) { 2485 printk(KERN_ERR "%s: error: failed to get bitmap file\n",
2446 printk(KERN_ERR "%s: error: bitmap file is already in use\n", 2486 mdname(mddev));
2447 mdname(mddev)); 2487 return -EBADF;
2448 fput(mddev->bitmap_file); 2488 }
2449 mddev->bitmap_file = NULL; 2489
2450 } else 2490 err = deny_bitmap_write_access(mddev->bitmap_file);
2491 if (err) {
2492 printk(KERN_ERR "%s: error: bitmap file is already in use\n",
2493 mdname(mddev));
2494 fput(mddev->bitmap_file);
2495 mddev->bitmap_file = NULL;
2496 return err;
2497 }
2451 mddev->bitmap_offset = 0; /* file overrides offset */ 2498 mddev->bitmap_offset = 0; /* file overrides offset */
2499 } else if (mddev->bitmap == NULL)
2500 return -ENOENT; /* cannot remove what isn't there */
2501 err = 0;
2502 if (mddev->pers) {
2503 mddev->pers->quiesce(mddev, 1);
2504 if (fd >= 0)
2505 err = bitmap_create(mddev);
2506 if (fd < 0 || err)
2507 bitmap_destroy(mddev);
2508 mddev->pers->quiesce(mddev, 0);
2509 } else if (fd < 0) {
2510 if (mddev->bitmap_file)
2511 fput(mddev->bitmap_file);
2512 mddev->bitmap_file = NULL;
2513 }
2514
2452 return err; 2515 return err;
2453} 2516}
2454 2517
@@ -2528,6 +2591,11 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info)
2528{ 2591{
2529 int rv = 0; 2592 int rv = 0;
2530 int cnt = 0; 2593 int cnt = 0;
2594 int state = 0;
2595
2596 /* calculate expected state,ignoring low bits */
2597 if (mddev->bitmap && mddev->bitmap_offset)
2598 state |= (1 << MD_SB_BITMAP_PRESENT);
2531 2599
2532 if (mddev->major_version != info->major_version || 2600 if (mddev->major_version != info->major_version ||
2533 mddev->minor_version != info->minor_version || 2601 mddev->minor_version != info->minor_version ||
@@ -2536,12 +2604,16 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info)
2536 mddev->level != info->level || 2604 mddev->level != info->level ||
2537/* mddev->layout != info->layout || */ 2605/* mddev->layout != info->layout || */
2538 !mddev->persistent != info->not_persistent|| 2606 !mddev->persistent != info->not_persistent||
2539 mddev->chunk_size != info->chunk_size ) 2607 mddev->chunk_size != info->chunk_size ||
2608 /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT to change */
2609 ((state^info->state) & 0xfffffe00)
2610 )
2540 return -EINVAL; 2611 return -EINVAL;
2541 /* Check there is only one change */ 2612 /* Check there is only one change */
2542 if (mddev->size != info->size) cnt++; 2613 if (mddev->size != info->size) cnt++;
2543 if (mddev->raid_disks != info->raid_disks) cnt++; 2614 if (mddev->raid_disks != info->raid_disks) cnt++;
2544 if (mddev->layout != info->layout) cnt++; 2615 if (mddev->layout != info->layout) cnt++;
2616 if ((state ^ info->state) & (1<<MD_SB_BITMAP_PRESENT)) cnt++;
2545 if (cnt == 0) return 0; 2617 if (cnt == 0) return 0;
2546 if (cnt > 1) return -EINVAL; 2618 if (cnt > 1) return -EINVAL;
2547 2619
@@ -2620,6 +2692,35 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info)
2620 } 2692 }
2621 } 2693 }
2622 } 2694 }
2695 if ((state ^ info->state) & (1<<MD_SB_BITMAP_PRESENT)) {
2696 if (mddev->pers->quiesce == NULL)
2697 return -EINVAL;
2698 if (mddev->recovery || mddev->sync_thread)
2699 return -EBUSY;
2700 if (info->state & (1<<MD_SB_BITMAP_PRESENT)) {
2701 /* add the bitmap */
2702 if (mddev->bitmap)
2703 return -EEXIST;
2704 if (mddev->default_bitmap_offset == 0)
2705 return -EINVAL;
2706 mddev->bitmap_offset = mddev->default_bitmap_offset;
2707 mddev->pers->quiesce(mddev, 1);
2708 rv = bitmap_create(mddev);
2709 if (rv)
2710 bitmap_destroy(mddev);
2711 mddev->pers->quiesce(mddev, 0);
2712 } else {
2713 /* remove the bitmap */
2714 if (!mddev->bitmap)
2715 return -ENOENT;
2716 if (mddev->bitmap->file)
2717 return -EINVAL;
2718 mddev->pers->quiesce(mddev, 1);
2719 bitmap_destroy(mddev);
2720 mddev->pers->quiesce(mddev, 0);
2721 mddev->bitmap_offset = 0;
2722 }
2723 }
2623 md_update_sb(mddev); 2724 md_update_sb(mddev);
2624 return rv; 2725 return rv;
2625} 2726}
@@ -2781,7 +2882,7 @@ static int md_ioctl(struct inode *inode, struct file *file,
2781 goto done_unlock; 2882 goto done_unlock;
2782 2883
2783 case GET_BITMAP_FILE: 2884 case GET_BITMAP_FILE:
2784 err = get_bitmap_file(mddev, (void *)arg); 2885 err = get_bitmap_file(mddev, argp);
2785 goto done_unlock; 2886 goto done_unlock;
2786 2887
2787 case GET_DISK_INFO: 2888 case GET_DISK_INFO:
@@ -2950,18 +3051,6 @@ static int md_thread(void * arg)
2950{ 3051{
2951 mdk_thread_t *thread = arg; 3052 mdk_thread_t *thread = arg;
2952 3053
2953 lock_kernel();
2954
2955 /*
2956 * Detach thread
2957 */
2958
2959 daemonize(thread->name, mdname(thread->mddev));
2960
2961 current->exit_signal = SIGCHLD;
2962 allow_signal(SIGKILL);
2963 thread->tsk = current;
2964
2965 /* 3054 /*
2966 * md_thread is a 'system-thread', it's priority should be very 3055 * md_thread is a 'system-thread', it's priority should be very
2967 * high. We avoid resource deadlocks individually in each 3056 * high. We avoid resource deadlocks individually in each
@@ -2973,14 +3062,14 @@ static int md_thread(void * arg)
2973 * bdflush, otherwise bdflush will deadlock if there are too 3062 * bdflush, otherwise bdflush will deadlock if there are too
2974 * many dirty RAID5 blocks. 3063 * many dirty RAID5 blocks.
2975 */ 3064 */
2976 unlock_kernel();
2977 3065
2978 complete(thread->event); 3066 complete(thread->event);
2979 while (thread->run) { 3067 while (!kthread_should_stop()) {
2980 void (*run)(mddev_t *); 3068 void (*run)(mddev_t *);
2981 3069
2982 wait_event_interruptible_timeout(thread->wqueue, 3070 wait_event_interruptible_timeout(thread->wqueue,
2983 test_bit(THREAD_WAKEUP, &thread->flags), 3071 test_bit(THREAD_WAKEUP, &thread->flags)
3072 || kthread_should_stop(),
2984 thread->timeout); 3073 thread->timeout);
2985 try_to_freeze(); 3074 try_to_freeze();
2986 3075
@@ -2989,11 +3078,8 @@ static int md_thread(void * arg)
2989 run = thread->run; 3078 run = thread->run;
2990 if (run) 3079 if (run)
2991 run(thread->mddev); 3080 run(thread->mddev);
2992
2993 if (signal_pending(current))
2994 flush_signals(current);
2995 } 3081 }
2996 complete(thread->event); 3082
2997 return 0; 3083 return 0;
2998} 3084}
2999 3085
@@ -3010,11 +3096,9 @@ mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev,
3010 const char *name) 3096 const char *name)
3011{ 3097{
3012 mdk_thread_t *thread; 3098 mdk_thread_t *thread;
3013 int ret;
3014 struct completion event; 3099 struct completion event;
3015 3100
3016 thread = (mdk_thread_t *) kmalloc 3101 thread = kmalloc(sizeof(mdk_thread_t), GFP_KERNEL);
3017 (sizeof(mdk_thread_t), GFP_KERNEL);
3018 if (!thread) 3102 if (!thread)
3019 return NULL; 3103 return NULL;
3020 3104
@@ -3027,8 +3111,8 @@ mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev,
3027 thread->mddev = mddev; 3111 thread->mddev = mddev;
3028 thread->name = name; 3112 thread->name = name;
3029 thread->timeout = MAX_SCHEDULE_TIMEOUT; 3113 thread->timeout = MAX_SCHEDULE_TIMEOUT;
3030 ret = kernel_thread(md_thread, thread, 0); 3114 thread->tsk = kthread_run(md_thread, thread, mdname(thread->mddev));
3031 if (ret < 0) { 3115 if (IS_ERR(thread->tsk)) {
3032 kfree(thread); 3116 kfree(thread);
3033 return NULL; 3117 return NULL;
3034 } 3118 }
@@ -3038,21 +3122,9 @@ mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev,
3038 3122
3039void md_unregister_thread(mdk_thread_t *thread) 3123void md_unregister_thread(mdk_thread_t *thread)
3040{ 3124{
3041 struct completion event;
3042
3043 init_completion(&event);
3044
3045 thread->event = &event;
3046
3047 /* As soon as ->run is set to NULL, the task could disappear,
3048 * so we need to hold tasklist_lock until we have sent the signal
3049 */
3050 dprintk("interrupting MD-thread pid %d\n", thread->tsk->pid); 3125 dprintk("interrupting MD-thread pid %d\n", thread->tsk->pid);
3051 read_lock(&tasklist_lock); 3126
3052 thread->run = NULL; 3127 kthread_stop(thread->tsk);
3053 send_sig(SIGKILL, thread->tsk, 1);
3054 read_unlock(&tasklist_lock);
3055 wait_for_completion(&event);
3056 kfree(thread); 3128 kfree(thread);
3057} 3129}
3058 3130
@@ -3259,10 +3331,13 @@ static int md_seq_show(struct seq_file *seq, void *v)
3259 char b[BDEVNAME_SIZE]; 3331 char b[BDEVNAME_SIZE];
3260 seq_printf(seq, " %s[%d]", 3332 seq_printf(seq, " %s[%d]",
3261 bdevname(rdev->bdev,b), rdev->desc_nr); 3333 bdevname(rdev->bdev,b), rdev->desc_nr);
3334 if (test_bit(WriteMostly, &rdev->flags))
3335 seq_printf(seq, "(W)");
3262 if (rdev->faulty) { 3336 if (rdev->faulty) {
3263 seq_printf(seq, "(F)"); 3337 seq_printf(seq, "(F)");
3264 continue; 3338 continue;
3265 } 3339 } else if (rdev->raid_disk < 0)
3340 seq_printf(seq, "(S)"); /* spare */
3266 size += rdev->size; 3341 size += rdev->size;
3267 } 3342 }
3268 3343
@@ -3274,6 +3349,15 @@ static int md_seq_show(struct seq_file *seq, void *v)
3274 seq_printf(seq, "\n %llu blocks", 3349 seq_printf(seq, "\n %llu blocks",
3275 (unsigned long long)size); 3350 (unsigned long long)size);
3276 } 3351 }
3352 if (mddev->persistent) {
3353 if (mddev->major_version != 0 ||
3354 mddev->minor_version != 90) {
3355 seq_printf(seq," super %d.%d",
3356 mddev->major_version,
3357 mddev->minor_version);
3358 }
3359 } else
3360 seq_printf(seq, " super non-persistent");
3277 3361
3278 if (mddev->pers) { 3362 if (mddev->pers) {
3279 mddev->pers->status (seq, mddev); 3363 mddev->pers->status (seq, mddev);
@@ -3416,7 +3500,6 @@ void md_done_sync(mddev_t *mddev, int blocks, int ok)
3416 */ 3500 */
3417void md_write_start(mddev_t *mddev, struct bio *bi) 3501void md_write_start(mddev_t *mddev, struct bio *bi)
3418{ 3502{
3419 DEFINE_WAIT(w);
3420 if (bio_data_dir(bi) != WRITE) 3503 if (bio_data_dir(bi) != WRITE)
3421 return; 3504 return;
3422 3505
@@ -3533,7 +3616,7 @@ static void md_do_sync(mddev_t *mddev)
3533 printk(KERN_INFO "md: syncing RAID array %s\n", mdname(mddev)); 3616 printk(KERN_INFO "md: syncing RAID array %s\n", mdname(mddev));
3534 printk(KERN_INFO "md: minimum _guaranteed_ reconstruction speed:" 3617 printk(KERN_INFO "md: minimum _guaranteed_ reconstruction speed:"
3535 " %d KB/sec/disc.\n", sysctl_speed_limit_min); 3618 " %d KB/sec/disc.\n", sysctl_speed_limit_min);
3536 printk(KERN_INFO "md: using maximum available idle IO bandwith " 3619 printk(KERN_INFO "md: using maximum available idle IO bandwidth "
3537 "(but not more than %d KB/sec) for reconstruction.\n", 3620 "(but not more than %d KB/sec) for reconstruction.\n",
3538 sysctl_speed_limit_max); 3621 sysctl_speed_limit_max);
3539 3622
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 2d2ca7fa02..286342375f 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -169,6 +169,11 @@ static int multipath_make_request (request_queue_t *q, struct bio * bio)
169 struct multipath_bh * mp_bh; 169 struct multipath_bh * mp_bh;
170 struct multipath_info *multipath; 170 struct multipath_info *multipath;
171 171
172 if (unlikely(bio_barrier(bio))) {
173 bio_endio(bio, bio->bi_size, -EOPNOTSUPP);
174 return 0;
175 }
176
172 mp_bh = mempool_alloc(conf->pool, GFP_NOIO); 177 mp_bh = mempool_alloc(conf->pool, GFP_NOIO);
173 178
174 mp_bh->master_bio = bio; 179 mp_bh->master_bio = bio;
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 2120710172..f6757259ce 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -404,6 +404,11 @@ static int raid0_make_request (request_queue_t *q, struct bio *bio)
404 unsigned long chunk; 404 unsigned long chunk;
405 sector_t block, rsect; 405 sector_t block, rsect;
406 406
407 if (unlikely(bio_barrier(bio))) {
408 bio_endio(bio, bio->bi_size, -EOPNOTSUPP);
409 return 0;
410 }
411
407 if (bio_data_dir(bio)==WRITE) { 412 if (bio_data_dir(bio)==WRITE) {
408 disk_stat_inc(mddev->gendisk, writes); 413 disk_stat_inc(mddev->gendisk, writes);
409 disk_stat_add(mddev->gendisk, write_sectors, bio_sectors(bio)); 414 disk_stat_add(mddev->gendisk, write_sectors, bio_sectors(bio));
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 51d9645ed0..a93ca47814 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -222,8 +222,17 @@ static void raid_end_bio_io(r1bio_t *r1_bio)
222{ 222{
223 struct bio *bio = r1_bio->master_bio; 223 struct bio *bio = r1_bio->master_bio;
224 224
225 bio_endio(bio, bio->bi_size, 225 /* if nobody has done the final endio yet, do it now */
226 test_bit(R1BIO_Uptodate, &r1_bio->state) ? 0 : -EIO); 226 if (!test_and_set_bit(R1BIO_Returned, &r1_bio->state)) {
227 PRINTK(KERN_DEBUG "raid1: sync end %s on sectors %llu-%llu\n",
228 (bio_data_dir(bio) == WRITE) ? "write" : "read",
229 (unsigned long long) bio->bi_sector,
230 (unsigned long long) bio->bi_sector +
231 (bio->bi_size >> 9) - 1);
232
233 bio_endio(bio, bio->bi_size,
234 test_bit(R1BIO_Uptodate, &r1_bio->state) ? 0 : -EIO);
235 }
227 free_r1bio(r1_bio); 236 free_r1bio(r1_bio);
228} 237}
229 238
@@ -292,7 +301,7 @@ static int raid1_end_write_request(struct bio *bio, unsigned int bytes_done, int
292{ 301{
293 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 302 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
294 r1bio_t * r1_bio = (r1bio_t *)(bio->bi_private); 303 r1bio_t * r1_bio = (r1bio_t *)(bio->bi_private);
295 int mirror; 304 int mirror, behind;
296 conf_t *conf = mddev_to_conf(r1_bio->mddev); 305 conf_t *conf = mddev_to_conf(r1_bio->mddev);
297 306
298 if (bio->bi_size) 307 if (bio->bi_size)
@@ -323,16 +332,46 @@ static int raid1_end_write_request(struct bio *bio, unsigned int bytes_done, int
323 332
324 update_head_pos(mirror, r1_bio); 333 update_head_pos(mirror, r1_bio);
325 334
335 behind = test_bit(R1BIO_BehindIO, &r1_bio->state);
336 if (behind) {
337 if (test_bit(WriteMostly, &conf->mirrors[mirror].rdev->flags))
338 atomic_dec(&r1_bio->behind_remaining);
339
340 /* In behind mode, we ACK the master bio once the I/O has safely
341 * reached all non-writemostly disks. Setting the Returned bit
342 * ensures that this gets done only once -- we don't ever want to
343 * return -EIO here, instead we'll wait */
344
345 if (atomic_read(&r1_bio->behind_remaining) >= (atomic_read(&r1_bio->remaining)-1) &&
346 test_bit(R1BIO_Uptodate, &r1_bio->state)) {
347 /* Maybe we can return now */
348 if (!test_and_set_bit(R1BIO_Returned, &r1_bio->state)) {
349 struct bio *mbio = r1_bio->master_bio;
350 PRINTK(KERN_DEBUG "raid1: behind end write sectors %llu-%llu\n",
351 (unsigned long long) mbio->bi_sector,
352 (unsigned long long) mbio->bi_sector +
353 (mbio->bi_size >> 9) - 1);
354 bio_endio(mbio, mbio->bi_size, 0);
355 }
356 }
357 }
326 /* 358 /*
327 * 359 *
328 * Let's see if all mirrored write operations have finished 360 * Let's see if all mirrored write operations have finished
329 * already. 361 * already.
330 */ 362 */
331 if (atomic_dec_and_test(&r1_bio->remaining)) { 363 if (atomic_dec_and_test(&r1_bio->remaining)) {
364 if (test_bit(R1BIO_BehindIO, &r1_bio->state)) {
365 /* free extra copy of the data pages */
366 int i = bio->bi_vcnt;
367 while (i--)
368 __free_page(bio->bi_io_vec[i].bv_page);
369 }
332 /* clear the bitmap if all writes complete successfully */ 370 /* clear the bitmap if all writes complete successfully */
333 bitmap_endwrite(r1_bio->mddev->bitmap, r1_bio->sector, 371 bitmap_endwrite(r1_bio->mddev->bitmap, r1_bio->sector,
334 r1_bio->sectors, 372 r1_bio->sectors,
335 !test_bit(R1BIO_Degraded, &r1_bio->state)); 373 !test_bit(R1BIO_Degraded, &r1_bio->state),
374 behind);
336 md_write_end(r1_bio->mddev); 375 md_write_end(r1_bio->mddev);
337 raid_end_bio_io(r1_bio); 376 raid_end_bio_io(r1_bio);
338 } 377 }
@@ -360,13 +399,14 @@ static int read_balance(conf_t *conf, r1bio_t *r1_bio)
360{ 399{
361 const unsigned long this_sector = r1_bio->sector; 400 const unsigned long this_sector = r1_bio->sector;
362 int new_disk = conf->last_used, disk = new_disk; 401 int new_disk = conf->last_used, disk = new_disk;
402 int wonly_disk = -1;
363 const int sectors = r1_bio->sectors; 403 const int sectors = r1_bio->sectors;
364 sector_t new_distance, current_distance; 404 sector_t new_distance, current_distance;
365 mdk_rdev_t *new_rdev, *rdev; 405 mdk_rdev_t *rdev;
366 406
367 rcu_read_lock(); 407 rcu_read_lock();
368 /* 408 /*
369 * Check if it if we can balance. We can balance on the whole 409 * Check if we can balance. We can balance on the whole
370 * device if no resync is going on, or below the resync window. 410 * device if no resync is going on, or below the resync window.
371 * We take the first readable disk when above the resync window. 411 * We take the first readable disk when above the resync window.
372 */ 412 */
@@ -376,11 +416,16 @@ static int read_balance(conf_t *conf, r1bio_t *r1_bio)
376 /* Choose the first operation device, for consistancy */ 416 /* Choose the first operation device, for consistancy */
377 new_disk = 0; 417 new_disk = 0;
378 418
379 while ((new_rdev=conf->mirrors[new_disk].rdev) == NULL || 419 for (rdev = conf->mirrors[new_disk].rdev;
380 !new_rdev->in_sync) { 420 !rdev || !rdev->in_sync
381 new_disk++; 421 || test_bit(WriteMostly, &rdev->flags);
382 if (new_disk == conf->raid_disks) { 422 rdev = conf->mirrors[++new_disk].rdev) {
383 new_disk = -1; 423
424 if (rdev && rdev->in_sync)
425 wonly_disk = new_disk;
426
427 if (new_disk == conf->raid_disks - 1) {
428 new_disk = wonly_disk;
384 break; 429 break;
385 } 430 }
386 } 431 }
@@ -389,16 +434,26 @@ static int read_balance(conf_t *conf, r1bio_t *r1_bio)
389 434
390 435
391 /* make sure the disk is operational */ 436 /* make sure the disk is operational */
392 while ((new_rdev=conf->mirrors[new_disk].rdev) == NULL || 437 for (rdev = conf->mirrors[new_disk].rdev;
393 !new_rdev->in_sync) { 438 !rdev || !rdev->in_sync ||
439 test_bit(WriteMostly, &rdev->flags);
440 rdev = conf->mirrors[new_disk].rdev) {
441
442 if (rdev && rdev->in_sync)
443 wonly_disk = new_disk;
444
394 if (new_disk <= 0) 445 if (new_disk <= 0)
395 new_disk = conf->raid_disks; 446 new_disk = conf->raid_disks;
396 new_disk--; 447 new_disk--;
397 if (new_disk == disk) { 448 if (new_disk == disk) {
398 new_disk = -1; 449 new_disk = wonly_disk;
399 goto rb_out; 450 break;
400 } 451 }
401 } 452 }
453
454 if (new_disk < 0)
455 goto rb_out;
456
402 disk = new_disk; 457 disk = new_disk;
403 /* now disk == new_disk == starting point for search */ 458 /* now disk == new_disk == starting point for search */
404 459
@@ -419,37 +474,41 @@ static int read_balance(conf_t *conf, r1bio_t *r1_bio)
419 disk = conf->raid_disks; 474 disk = conf->raid_disks;
420 disk--; 475 disk--;
421 476
422 if ((rdev=conf->mirrors[disk].rdev) == NULL || 477 rdev = conf->mirrors[disk].rdev;
423 !rdev->in_sync) 478
479 if (!rdev ||
480 !rdev->in_sync ||
481 test_bit(WriteMostly, &rdev->flags))
424 continue; 482 continue;
425 483
426 if (!atomic_read(&rdev->nr_pending)) { 484 if (!atomic_read(&rdev->nr_pending)) {
427 new_disk = disk; 485 new_disk = disk;
428 new_rdev = rdev;
429 break; 486 break;
430 } 487 }
431 new_distance = abs(this_sector - conf->mirrors[disk].head_position); 488 new_distance = abs(this_sector - conf->mirrors[disk].head_position);
432 if (new_distance < current_distance) { 489 if (new_distance < current_distance) {
433 current_distance = new_distance; 490 current_distance = new_distance;
434 new_disk = disk; 491 new_disk = disk;
435 new_rdev = rdev;
436 } 492 }
437 } while (disk != conf->last_used); 493 } while (disk != conf->last_used);
438 494
439rb_out: 495 rb_out:
440 496
441 497
442 if (new_disk >= 0) { 498 if (new_disk >= 0) {
443 conf->next_seq_sect = this_sector + sectors; 499 rdev = conf->mirrors[new_disk].rdev;
444 conf->last_used = new_disk; 500 if (!rdev)
445 atomic_inc(&new_rdev->nr_pending); 501 goto retry;
446 if (!new_rdev->in_sync) { 502 atomic_inc(&rdev->nr_pending);
503 if (!rdev->in_sync) {
447 /* cannot risk returning a device that failed 504 /* cannot risk returning a device that failed
448 * before we inc'ed nr_pending 505 * before we inc'ed nr_pending
449 */ 506 */
450 atomic_dec(&new_rdev->nr_pending); 507 atomic_dec(&rdev->nr_pending);
451 goto retry; 508 goto retry;
452 } 509 }
510 conf->next_seq_sect = this_sector + sectors;
511 conf->last_used = new_disk;
453 } 512 }
454 rcu_read_unlock(); 513 rcu_read_unlock();
455 514
@@ -542,6 +601,39 @@ static void device_barrier(conf_t *conf, sector_t sect)
542 spin_unlock_irq(&conf->resync_lock); 601 spin_unlock_irq(&conf->resync_lock);
543} 602}
544 603
604/* duplicate the data pages for behind I/O */
605static struct page **alloc_behind_pages(struct bio *bio)
606{
607 int i;
608 struct bio_vec *bvec;
609 struct page **pages = kmalloc(bio->bi_vcnt * sizeof(struct page *),
610 GFP_NOIO);
611 if (unlikely(!pages))
612 goto do_sync_io;
613
614 memset(pages, 0, bio->bi_vcnt * sizeof(struct page *));
615
616 bio_for_each_segment(bvec, bio, i) {
617 pages[i] = alloc_page(GFP_NOIO);
618 if (unlikely(!pages[i]))
619 goto do_sync_io;
620 memcpy(kmap(pages[i]) + bvec->bv_offset,
621 kmap(bvec->bv_page) + bvec->bv_offset, bvec->bv_len);
622 kunmap(pages[i]);
623 kunmap(bvec->bv_page);
624 }
625
626 return pages;
627
628do_sync_io:
629 if (pages)
630 for (i = 0; i < bio->bi_vcnt && pages[i]; i++)
631 __free_page(pages[i]);
632 kfree(pages);
633 PRINTK("%dB behind alloc failed, doing sync I/O\n", bio->bi_size);
634 return NULL;
635}
636
545static int make_request(request_queue_t *q, struct bio * bio) 637static int make_request(request_queue_t *q, struct bio * bio)
546{ 638{
547 mddev_t *mddev = q->queuedata; 639 mddev_t *mddev = q->queuedata;
@@ -554,7 +646,12 @@ static int make_request(request_queue_t *q, struct bio * bio)
554 struct bitmap *bitmap = mddev->bitmap; 646 struct bitmap *bitmap = mddev->bitmap;
555 unsigned long flags; 647 unsigned long flags;
556 struct bio_list bl; 648 struct bio_list bl;
649 struct page **behind_pages = NULL;
557 650
651 if (unlikely(bio_barrier(bio))) {
652 bio_endio(bio, bio->bi_size, -EOPNOTSUPP);
653 return 0;
654 }
558 655
559 /* 656 /*
560 * Register the new request and wait if the reconstruction 657 * Register the new request and wait if the reconstruction
@@ -589,8 +686,6 @@ static int make_request(request_queue_t *q, struct bio * bio)
589 r1_bio->mddev = mddev; 686 r1_bio->mddev = mddev;
590 r1_bio->sector = bio->bi_sector; 687 r1_bio->sector = bio->bi_sector;
591 688
592 r1_bio->state = 0;
593
594 if (bio_data_dir(bio) == READ) { 689 if (bio_data_dir(bio) == READ) {
595 /* 690 /*
596 * read balancing logic: 691 * read balancing logic:
@@ -651,13 +746,22 @@ static int make_request(request_queue_t *q, struct bio * bio)
651 } 746 }
652 rcu_read_unlock(); 747 rcu_read_unlock();
653 748
749 BUG_ON(targets == 0); /* we never fail the last device */
750
654 if (targets < conf->raid_disks) { 751 if (targets < conf->raid_disks) {
655 /* array is degraded, we will not clear the bitmap 752 /* array is degraded, we will not clear the bitmap
656 * on I/O completion (see raid1_end_write_request) */ 753 * on I/O completion (see raid1_end_write_request) */
657 set_bit(R1BIO_Degraded, &r1_bio->state); 754 set_bit(R1BIO_Degraded, &r1_bio->state);
658 } 755 }
659 756
757 /* do behind I/O ? */
758 if (bitmap &&
759 atomic_read(&bitmap->behind_writes) < bitmap->max_write_behind &&
760 (behind_pages = alloc_behind_pages(bio)) != NULL)
761 set_bit(R1BIO_BehindIO, &r1_bio->state);
762
660 atomic_set(&r1_bio->remaining, 0); 763 atomic_set(&r1_bio->remaining, 0);
764 atomic_set(&r1_bio->behind_remaining, 0);
661 765
662 bio_list_init(&bl); 766 bio_list_init(&bl);
663 for (i = 0; i < disks; i++) { 767 for (i = 0; i < disks; i++) {
@@ -674,12 +778,31 @@ static int make_request(request_queue_t *q, struct bio * bio)
674 mbio->bi_rw = WRITE; 778 mbio->bi_rw = WRITE;
675 mbio->bi_private = r1_bio; 779 mbio->bi_private = r1_bio;
676 780
781 if (behind_pages) {
782 struct bio_vec *bvec;
783 int j;
784
785 /* Yes, I really want the '__' version so that
786 * we clear any unused pointer in the io_vec, rather
787 * than leave them unchanged. This is important
788 * because when we come to free the pages, we won't
789 * know the originial bi_idx, so we just free
790 * them all
791 */
792 __bio_for_each_segment(bvec, mbio, j, 0)
793 bvec->bv_page = behind_pages[j];
794 if (test_bit(WriteMostly, &conf->mirrors[i].rdev->flags))
795 atomic_inc(&r1_bio->behind_remaining);
796 }
797
677 atomic_inc(&r1_bio->remaining); 798 atomic_inc(&r1_bio->remaining);
678 799
679 bio_list_add(&bl, mbio); 800 bio_list_add(&bl, mbio);
680 } 801 }
802 kfree(behind_pages); /* the behind pages are attached to the bios now */
681 803
682 bitmap_startwrite(bitmap, bio->bi_sector, r1_bio->sectors); 804 bitmap_startwrite(bitmap, bio->bi_sector, r1_bio->sectors,
805 test_bit(R1BIO_BehindIO, &r1_bio->state));
683 spin_lock_irqsave(&conf->device_lock, flags); 806 spin_lock_irqsave(&conf->device_lock, flags);
684 bio_list_merge(&conf->pending_bio_list, &bl); 807 bio_list_merge(&conf->pending_bio_list, &bl);
685 bio_list_init(&bl); 808 bio_list_init(&bl);
@@ -1105,6 +1228,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1105 sector_t max_sector, nr_sectors; 1228 sector_t max_sector, nr_sectors;
1106 int disk; 1229 int disk;
1107 int i; 1230 int i;
1231 int wonly;
1108 int write_targets = 0; 1232 int write_targets = 0;
1109 int sync_blocks; 1233 int sync_blocks;
1110 int still_degraded = 0; 1234 int still_degraded = 0;
@@ -1160,14 +1284,21 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1160 */ 1284 */
1161 disk = conf->last_used; 1285 disk = conf->last_used;
1162 /* make sure disk is operational */ 1286 /* make sure disk is operational */
1163 1287 wonly = disk;
1164 while (conf->mirrors[disk].rdev == NULL || 1288 while (conf->mirrors[disk].rdev == NULL ||
1165 !conf->mirrors[disk].rdev->in_sync) { 1289 !conf->mirrors[disk].rdev->in_sync ||
1290 test_bit(WriteMostly, &conf->mirrors[disk].rdev->flags)
1291 ) {
1292 if (conf->mirrors[disk].rdev &&
1293 conf->mirrors[disk].rdev->in_sync)
1294 wonly = disk;
1166 if (disk <= 0) 1295 if (disk <= 0)
1167 disk = conf->raid_disks; 1296 disk = conf->raid_disks;
1168 disk--; 1297 disk--;
1169 if (disk == conf->last_used) 1298 if (disk == conf->last_used) {
1299 disk = wonly;
1170 break; 1300 break;
1301 }
1171 } 1302 }
1172 conf->last_used = disk; 1303 conf->last_used = disk;
1173 atomic_inc(&conf->mirrors[disk].rdev->nr_pending); 1304 atomic_inc(&conf->mirrors[disk].rdev->nr_pending);
@@ -1439,6 +1570,17 @@ out:
1439static int stop(mddev_t *mddev) 1570static int stop(mddev_t *mddev)
1440{ 1571{
1441 conf_t *conf = mddev_to_conf(mddev); 1572 conf_t *conf = mddev_to_conf(mddev);
1573 struct bitmap *bitmap = mddev->bitmap;
1574 int behind_wait = 0;
1575
1576 /* wait for behind writes to complete */
1577 while (bitmap && atomic_read(&bitmap->behind_writes) > 0) {
1578 behind_wait++;
1579 printk(KERN_INFO "raid1: behind writes in progress on device %s, waiting to stop (%d)\n", mdname(mddev), behind_wait);
1580 set_current_state(TASK_UNINTERRUPTIBLE);
1581 schedule_timeout(HZ); /* wait a second */
1582 /* need to kick something here to make sure I/O goes? */
1583 }
1442 1584
1443 md_unregister_thread(mddev->thread); 1585 md_unregister_thread(mddev->thread);
1444 mddev->thread = NULL; 1586 mddev->thread = NULL;
@@ -1561,6 +1703,35 @@ static int raid1_reshape(mddev_t *mddev, int raid_disks)
1561 return 0; 1703 return 0;
1562} 1704}
1563 1705
1706static void raid1_quiesce(mddev_t *mddev, int state)
1707{
1708 conf_t *conf = mddev_to_conf(mddev);
1709
1710 switch(state) {
1711 case 1:
1712 spin_lock_irq(&conf->resync_lock);
1713 conf->barrier++;
1714 wait_event_lock_irq(conf->wait_idle, !conf->nr_pending,
1715 conf->resync_lock, raid1_unplug(mddev->queue));
1716 spin_unlock_irq(&conf->resync_lock);
1717 break;
1718 case 0:
1719 spin_lock_irq(&conf->resync_lock);
1720 conf->barrier--;
1721 spin_unlock_irq(&conf->resync_lock);
1722 wake_up(&conf->wait_resume);
1723 wake_up(&conf->wait_idle);
1724 break;
1725 }
1726 if (mddev->thread) {
1727 if (mddev->bitmap)
1728 mddev->thread->timeout = mddev->bitmap->daemon_sleep * HZ;
1729 else
1730 mddev->thread->timeout = MAX_SCHEDULE_TIMEOUT;
1731 md_wakeup_thread(mddev->thread);
1732 }
1733}
1734
1564 1735
1565static mdk_personality_t raid1_personality = 1736static mdk_personality_t raid1_personality =
1566{ 1737{
@@ -1577,6 +1748,7 @@ static mdk_personality_t raid1_personality =
1577 .sync_request = sync_request, 1748 .sync_request = sync_request,
1578 .resize = raid1_resize, 1749 .resize = raid1_resize,
1579 .reshape = raid1_reshape, 1750 .reshape = raid1_reshape,
1751 .quiesce = raid1_quiesce,
1580}; 1752};
1581 1753
1582static int __init raid_init(void) 1754static int __init raid_init(void)
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 62ebb1bc72..5bd1e9ec89 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -538,7 +538,8 @@ static int read_balance(conf_t *conf, r10bio_t *r10_bio)
538 } 538 }
539 539
540 540
541 current_distance = abs(this_sector - conf->mirrors[disk].head_position); 541 current_distance = abs(r10_bio->devs[slot].addr -
542 conf->mirrors[disk].head_position);
542 543
543 /* Find the disk whose head is closest */ 544 /* Find the disk whose head is closest */
544 545
@@ -668,6 +669,11 @@ static int make_request(request_queue_t *q, struct bio * bio)
668 int i; 669 int i;
669 int chunk_sects = conf->chunk_mask + 1; 670 int chunk_sects = conf->chunk_mask + 1;
670 671
672 if (unlikely(bio_barrier(bio))) {
673 bio_endio(bio, bio->bi_size, -EOPNOTSUPP);
674 return 0;
675 }
676
671 /* If this request crosses a chunk boundary, we need to 677 /* If this request crosses a chunk boundary, we need to
672 * split it. This will only happen for 1 PAGE (or less) requests. 678 * split it. This will only happen for 1 PAGE (or less) requests.
673 */ 679 */
@@ -900,6 +906,27 @@ static void close_sync(conf_t *conf)
900 conf->r10buf_pool = NULL; 906 conf->r10buf_pool = NULL;
901} 907}
902 908
909/* check if there are enough drives for
910 * every block to appear on atleast one
911 */
912static int enough(conf_t *conf)
913{
914 int first = 0;
915
916 do {
917 int n = conf->copies;
918 int cnt = 0;
919 while (n--) {
920 if (conf->mirrors[first].rdev)
921 cnt++;
922 first = (first+1) % conf->raid_disks;
923 }
924 if (cnt == 0)
925 return 0;
926 } while (first != 0);
927 return 1;
928}
929
903static int raid10_spare_active(mddev_t *mddev) 930static int raid10_spare_active(mddev_t *mddev)
904{ 931{
905 int i; 932 int i;
@@ -938,6 +965,8 @@ static int raid10_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
938 * very different from resync 965 * very different from resync
939 */ 966 */
940 return 0; 967 return 0;
968 if (!enough(conf))
969 return 0;
941 970
942 for (mirror=0; mirror < mddev->raid_disks; mirror++) 971 for (mirror=0; mirror < mddev->raid_disks; mirror++)
943 if ( !(p=conf->mirrors+mirror)->rdev) { 972 if ( !(p=conf->mirrors+mirror)->rdev) {
@@ -1445,7 +1474,13 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1445 } 1474 }
1446 } 1475 }
1447 if (j == conf->copies) { 1476 if (j == conf->copies) {
1448 BUG(); 1477 /* Cannot recover, so abort the recovery */
1478 put_buf(r10_bio);
1479 r10_bio = rb2;
1480 if (!test_and_set_bit(MD_RECOVERY_ERR, &mddev->recovery))
1481 printk(KERN_INFO "raid10: %s: insufficient working devices for recovery.\n",
1482 mdname(mddev));
1483 break;
1449 } 1484 }
1450 } 1485 }
1451 if (biolist == NULL) { 1486 if (biolist == NULL) {
@@ -1678,9 +1713,10 @@ static int run(mddev_t *mddev)
1678 init_waitqueue_head(&conf->wait_idle); 1713 init_waitqueue_head(&conf->wait_idle);
1679 init_waitqueue_head(&conf->wait_resume); 1714 init_waitqueue_head(&conf->wait_resume);
1680 1715
1681 if (!conf->working_disks) { 1716 /* need to check that every block has at least one working mirror */
1682 printk(KERN_ERR "raid10: no operational mirrors for %s\n", 1717 if (!enough(conf)) {
1683 mdname(mddev)); 1718 printk(KERN_ERR "raid10: not enough operational mirrors for %s\n",
1719 mdname(mddev));
1684 goto out_free_conf; 1720 goto out_free_conf;
1685 } 1721 }
1686 1722
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 43f231a467..4683ca24c0 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -24,6 +24,8 @@
24#include <linux/bitops.h> 24#include <linux/bitops.h>
25#include <asm/atomic.h> 25#include <asm/atomic.h>
26 26
27#include <linux/raid/bitmap.h>
28
27/* 29/*
28 * Stripe cache 30 * Stripe cache
29 */ 31 */
@@ -79,8 +81,13 @@ static inline void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
79 if (test_bit(STRIPE_HANDLE, &sh->state)) { 81 if (test_bit(STRIPE_HANDLE, &sh->state)) {
80 if (test_bit(STRIPE_DELAYED, &sh->state)) 82 if (test_bit(STRIPE_DELAYED, &sh->state))
81 list_add_tail(&sh->lru, &conf->delayed_list); 83 list_add_tail(&sh->lru, &conf->delayed_list);
82 else 84 else if (test_bit(STRIPE_BIT_DELAY, &sh->state) &&
85 conf->seq_write == sh->bm_seq)
86 list_add_tail(&sh->lru, &conf->bitmap_list);
87 else {
88 clear_bit(STRIPE_BIT_DELAY, &sh->state);
83 list_add_tail(&sh->lru, &conf->handle_list); 89 list_add_tail(&sh->lru, &conf->handle_list);
90 }
84 md_wakeup_thread(conf->mddev->thread); 91 md_wakeup_thread(conf->mddev->thread);
85 } else { 92 } else {
86 if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { 93 if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) {
@@ -244,6 +251,9 @@ static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector
244 spin_lock_irq(&conf->device_lock); 251 spin_lock_irq(&conf->device_lock);
245 252
246 do { 253 do {
254 wait_event_lock_irq(conf->wait_for_stripe,
255 conf->quiesce == 0,
256 conf->device_lock, /* nothing */);
247 sh = __find_stripe(conf, sector); 257 sh = __find_stripe(conf, sector);
248 if (!sh) { 258 if (!sh) {
249 if (!conf->inactive_blocked) 259 if (!conf->inactive_blocked)
@@ -803,6 +813,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
803{ 813{
804 struct bio **bip; 814 struct bio **bip;
805 raid5_conf_t *conf = sh->raid_conf; 815 raid5_conf_t *conf = sh->raid_conf;
816 int firstwrite=0;
806 817
807 PRINTK("adding bh b#%llu to stripe s#%llu\n", 818 PRINTK("adding bh b#%llu to stripe s#%llu\n",
808 (unsigned long long)bi->bi_sector, 819 (unsigned long long)bi->bi_sector,
@@ -811,9 +822,11 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
811 822
812 spin_lock(&sh->lock); 823 spin_lock(&sh->lock);
813 spin_lock_irq(&conf->device_lock); 824 spin_lock_irq(&conf->device_lock);
814 if (forwrite) 825 if (forwrite) {
815 bip = &sh->dev[dd_idx].towrite; 826 bip = &sh->dev[dd_idx].towrite;
816 else 827 if (*bip == NULL && sh->dev[dd_idx].written == NULL)
828 firstwrite = 1;
829 } else
817 bip = &sh->dev[dd_idx].toread; 830 bip = &sh->dev[dd_idx].toread;
818 while (*bip && (*bip)->bi_sector < bi->bi_sector) { 831 while (*bip && (*bip)->bi_sector < bi->bi_sector) {
819 if ((*bip)->bi_sector + ((*bip)->bi_size >> 9) > bi->bi_sector) 832 if ((*bip)->bi_sector + ((*bip)->bi_size >> 9) > bi->bi_sector)
@@ -836,6 +849,13 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
836 (unsigned long long)bi->bi_sector, 849 (unsigned long long)bi->bi_sector,
837 (unsigned long long)sh->sector, dd_idx); 850 (unsigned long long)sh->sector, dd_idx);
838 851
852 if (conf->mddev->bitmap && firstwrite) {
853 sh->bm_seq = conf->seq_write;
854 bitmap_startwrite(conf->mddev->bitmap, sh->sector,
855 STRIPE_SECTORS, 0);
856 set_bit(STRIPE_BIT_DELAY, &sh->state);
857 }
858
839 if (forwrite) { 859 if (forwrite) {
840 /* check if page is covered */ 860 /* check if page is covered */
841 sector_t sector = sh->dev[dd_idx].sector; 861 sector_t sector = sh->dev[dd_idx].sector;
@@ -958,12 +978,13 @@ static void handle_stripe(struct stripe_head *sh)
958 * need to be failed 978 * need to be failed
959 */ 979 */
960 if (failed > 1 && to_read+to_write+written) { 980 if (failed > 1 && to_read+to_write+written) {
961 spin_lock_irq(&conf->device_lock);
962 for (i=disks; i--; ) { 981 for (i=disks; i--; ) {
982 int bitmap_end = 0;
983 spin_lock_irq(&conf->device_lock);
963 /* fail all writes first */ 984 /* fail all writes first */
964 bi = sh->dev[i].towrite; 985 bi = sh->dev[i].towrite;
965 sh->dev[i].towrite = NULL; 986 sh->dev[i].towrite = NULL;
966 if (bi) to_write--; 987 if (bi) { to_write--; bitmap_end = 1; }
967 988
968 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) 989 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
969 wake_up(&conf->wait_for_overlap); 990 wake_up(&conf->wait_for_overlap);
@@ -981,6 +1002,7 @@ static void handle_stripe(struct stripe_head *sh)
981 /* and fail all 'written' */ 1002 /* and fail all 'written' */
982 bi = sh->dev[i].written; 1003 bi = sh->dev[i].written;
983 sh->dev[i].written = NULL; 1004 sh->dev[i].written = NULL;
1005 if (bi) bitmap_end = 1;
984 while (bi && bi->bi_sector < sh->dev[i].sector + STRIPE_SECTORS) { 1006 while (bi && bi->bi_sector < sh->dev[i].sector + STRIPE_SECTORS) {
985 struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector); 1007 struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector);
986 clear_bit(BIO_UPTODATE, &bi->bi_flags); 1008 clear_bit(BIO_UPTODATE, &bi->bi_flags);
@@ -1009,8 +1031,11 @@ static void handle_stripe(struct stripe_head *sh)
1009 bi = nextbi; 1031 bi = nextbi;
1010 } 1032 }
1011 } 1033 }
1034 spin_unlock_irq(&conf->device_lock);
1035 if (bitmap_end)
1036 bitmap_endwrite(conf->mddev->bitmap, sh->sector,
1037 STRIPE_SECTORS, 0, 0);
1012 } 1038 }
1013 spin_unlock_irq(&conf->device_lock);
1014 } 1039 }
1015 if (failed > 1 && syncing) { 1040 if (failed > 1 && syncing) {
1016 md_done_sync(conf->mddev, STRIPE_SECTORS,0); 1041 md_done_sync(conf->mddev, STRIPE_SECTORS,0);
@@ -1038,6 +1063,7 @@ static void handle_stripe(struct stripe_head *sh)
1038 test_bit(R5_UPTODATE, &dev->flags) ) { 1063 test_bit(R5_UPTODATE, &dev->flags) ) {
1039 /* We can return any write requests */ 1064 /* We can return any write requests */
1040 struct bio *wbi, *wbi2; 1065 struct bio *wbi, *wbi2;
1066 int bitmap_end = 0;
1041 PRINTK("Return write for disc %d\n", i); 1067 PRINTK("Return write for disc %d\n", i);
1042 spin_lock_irq(&conf->device_lock); 1068 spin_lock_irq(&conf->device_lock);
1043 wbi = dev->written; 1069 wbi = dev->written;
@@ -1051,7 +1077,13 @@ static void handle_stripe(struct stripe_head *sh)
1051 } 1077 }
1052 wbi = wbi2; 1078 wbi = wbi2;
1053 } 1079 }
1080 if (dev->towrite == NULL)
1081 bitmap_end = 1;
1054 spin_unlock_irq(&conf->device_lock); 1082 spin_unlock_irq(&conf->device_lock);
1083 if (bitmap_end)
1084 bitmap_endwrite(conf->mddev->bitmap, sh->sector,
1085 STRIPE_SECTORS,
1086 !test_bit(STRIPE_DEGRADED, &sh->state), 0);
1055 } 1087 }
1056 } 1088 }
1057 } 1089 }
@@ -1175,7 +1207,8 @@ static void handle_stripe(struct stripe_head *sh)
1175 } 1207 }
1176 } 1208 }
1177 /* now if nothing is locked, and if we have enough data, we can start a write request */ 1209 /* now if nothing is locked, and if we have enough data, we can start a write request */
1178 if (locked == 0 && (rcw == 0 ||rmw == 0)) { 1210 if (locked == 0 && (rcw == 0 ||rmw == 0) &&
1211 !test_bit(STRIPE_BIT_DELAY, &sh->state)) {
1179 PRINTK("Computing parity...\n"); 1212 PRINTK("Computing parity...\n");
1180 compute_parity(sh, rcw==0 ? RECONSTRUCT_WRITE : READ_MODIFY_WRITE); 1213 compute_parity(sh, rcw==0 ? RECONSTRUCT_WRITE : READ_MODIFY_WRITE);
1181 /* now every locked buffer is ready to be written */ 1214 /* now every locked buffer is ready to be written */
@@ -1231,6 +1264,7 @@ static void handle_stripe(struct stripe_head *sh)
1231 dev = &sh->dev[failed_num]; 1264 dev = &sh->dev[failed_num];
1232 set_bit(R5_LOCKED, &dev->flags); 1265 set_bit(R5_LOCKED, &dev->flags);
1233 set_bit(R5_Wantwrite, &dev->flags); 1266 set_bit(R5_Wantwrite, &dev->flags);
1267 clear_bit(STRIPE_DEGRADED, &sh->state);
1234 locked++; 1268 locked++;
1235 set_bit(STRIPE_INSYNC, &sh->state); 1269 set_bit(STRIPE_INSYNC, &sh->state);
1236 set_bit(R5_Syncio, &dev->flags); 1270 set_bit(R5_Syncio, &dev->flags);
@@ -1298,6 +1332,8 @@ static void handle_stripe(struct stripe_head *sh)
1298 bi->bi_next = NULL; 1332 bi->bi_next = NULL;
1299 generic_make_request(bi); 1333 generic_make_request(bi);
1300 } else { 1334 } else {
1335 if (rw == 1)
1336 set_bit(STRIPE_DEGRADED, &sh->state);
1301 PRINTK("skip op %ld on disc %d for sector %llu\n", 1337 PRINTK("skip op %ld on disc %d for sector %llu\n",
1302 bi->bi_rw, i, (unsigned long long)sh->sector); 1338 bi->bi_rw, i, (unsigned long long)sh->sector);
1303 clear_bit(R5_LOCKED, &sh->dev[i].flags); 1339 clear_bit(R5_LOCKED, &sh->dev[i].flags);
@@ -1322,6 +1358,20 @@ static inline void raid5_activate_delayed(raid5_conf_t *conf)
1322 } 1358 }
1323} 1359}
1324 1360
1361static inline void activate_bit_delay(raid5_conf_t *conf)
1362{
1363 /* device_lock is held */
1364 struct list_head head;
1365 list_add(&head, &conf->bitmap_list);
1366 list_del_init(&conf->bitmap_list);
1367 while (!list_empty(&head)) {
1368 struct stripe_head *sh = list_entry(head.next, struct stripe_head, lru);
1369 list_del_init(&sh->lru);
1370 atomic_inc(&sh->count);
1371 __release_stripe(conf, sh);
1372 }
1373}
1374
1325static void unplug_slaves(mddev_t *mddev) 1375static void unplug_slaves(mddev_t *mddev)
1326{ 1376{
1327 raid5_conf_t *conf = mddev_to_conf(mddev); 1377 raid5_conf_t *conf = mddev_to_conf(mddev);
@@ -1354,8 +1404,10 @@ static void raid5_unplug_device(request_queue_t *q)
1354 1404
1355 spin_lock_irqsave(&conf->device_lock, flags); 1405 spin_lock_irqsave(&conf->device_lock, flags);
1356 1406
1357 if (blk_remove_plug(q)) 1407 if (blk_remove_plug(q)) {
1408 conf->seq_flush++;
1358 raid5_activate_delayed(conf); 1409 raid5_activate_delayed(conf);
1410 }
1359 md_wakeup_thread(mddev->thread); 1411 md_wakeup_thread(mddev->thread);
1360 1412
1361 spin_unlock_irqrestore(&conf->device_lock, flags); 1413 spin_unlock_irqrestore(&conf->device_lock, flags);
@@ -1411,6 +1463,11 @@ static int make_request (request_queue_t *q, struct bio * bi)
1411 sector_t logical_sector, last_sector; 1463 sector_t logical_sector, last_sector;
1412 struct stripe_head *sh; 1464 struct stripe_head *sh;
1413 1465
1466 if (unlikely(bio_barrier(bi))) {
1467 bio_endio(bi, bi->bi_size, -EOPNOTSUPP);
1468 return 0;
1469 }
1470
1414 md_write_start(mddev, bi); 1471 md_write_start(mddev, bi);
1415 1472
1416 if (bio_data_dir(bi)==WRITE) { 1473 if (bio_data_dir(bi)==WRITE) {
@@ -1488,10 +1545,20 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1488 sector_t first_sector; 1545 sector_t first_sector;
1489 int raid_disks = conf->raid_disks; 1546 int raid_disks = conf->raid_disks;
1490 int data_disks = raid_disks-1; 1547 int data_disks = raid_disks-1;
1548 sector_t max_sector = mddev->size << 1;
1549 int sync_blocks;
1491 1550
1492 if (sector_nr >= mddev->size <<1) { 1551 if (sector_nr >= max_sector) {
1493 /* just being told to finish up .. nothing much to do */ 1552 /* just being told to finish up .. nothing much to do */
1494 unplug_slaves(mddev); 1553 unplug_slaves(mddev);
1554
1555 if (mddev->curr_resync < max_sector) /* aborted */
1556 bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
1557 &sync_blocks, 1);
1558 else /* compelted sync */
1559 conf->fullsync = 0;
1560 bitmap_close_sync(mddev->bitmap);
1561
1495 return 0; 1562 return 0;
1496 } 1563 }
1497 /* if there is 1 or more failed drives and we are trying 1564 /* if there is 1 or more failed drives and we are trying
@@ -1503,6 +1570,13 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1503 *skipped = 1; 1570 *skipped = 1;
1504 return rv; 1571 return rv;
1505 } 1572 }
1573 if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) &&
1574 !conf->fullsync && sync_blocks >= STRIPE_SECTORS) {
1575 /* we can skip this block, and probably more */
1576 sync_blocks /= STRIPE_SECTORS;
1577 *skipped = 1;
1578 return sync_blocks * STRIPE_SECTORS; /* keep things rounded to whole stripes */
1579 }
1506 1580
1507 x = sector_nr; 1581 x = sector_nr;
1508 chunk_offset = sector_div(x, sectors_per_chunk); 1582 chunk_offset = sector_div(x, sectors_per_chunk);
@@ -1520,6 +1594,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1520 set_current_state(TASK_UNINTERRUPTIBLE); 1594 set_current_state(TASK_UNINTERRUPTIBLE);
1521 schedule_timeout(1); 1595 schedule_timeout(1);
1522 } 1596 }
1597 bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 0);
1523 spin_lock(&sh->lock); 1598 spin_lock(&sh->lock);
1524 set_bit(STRIPE_SYNCING, &sh->state); 1599 set_bit(STRIPE_SYNCING, &sh->state);
1525 clear_bit(STRIPE_INSYNC, &sh->state); 1600 clear_bit(STRIPE_INSYNC, &sh->state);
@@ -1553,6 +1628,13 @@ static void raid5d (mddev_t *mddev)
1553 while (1) { 1628 while (1) {
1554 struct list_head *first; 1629 struct list_head *first;
1555 1630
1631 if (conf->seq_flush - conf->seq_write > 0) {
1632 int seq = conf->seq_flush;
1633 bitmap_unplug(mddev->bitmap);
1634 conf->seq_write = seq;
1635 activate_bit_delay(conf);
1636 }
1637
1556 if (list_empty(&conf->handle_list) && 1638 if (list_empty(&conf->handle_list) &&
1557 atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD && 1639 atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD &&
1558 !blk_queue_plugged(mddev->queue) && 1640 !blk_queue_plugged(mddev->queue) &&
@@ -1586,7 +1668,7 @@ static void raid5d (mddev_t *mddev)
1586 PRINTK("--- raid5d inactive\n"); 1668 PRINTK("--- raid5d inactive\n");
1587} 1669}
1588 1670
1589static int run (mddev_t *mddev) 1671static int run(mddev_t *mddev)
1590{ 1672{
1591 raid5_conf_t *conf; 1673 raid5_conf_t *conf;
1592 int raid_disk, memory; 1674 int raid_disk, memory;
@@ -1616,6 +1698,7 @@ static int run (mddev_t *mddev)
1616 init_waitqueue_head(&conf->wait_for_overlap); 1698 init_waitqueue_head(&conf->wait_for_overlap);
1617 INIT_LIST_HEAD(&conf->handle_list); 1699 INIT_LIST_HEAD(&conf->handle_list);
1618 INIT_LIST_HEAD(&conf->delayed_list); 1700 INIT_LIST_HEAD(&conf->delayed_list);
1701 INIT_LIST_HEAD(&conf->bitmap_list);
1619 INIT_LIST_HEAD(&conf->inactive_list); 1702 INIT_LIST_HEAD(&conf->inactive_list);
1620 atomic_set(&conf->active_stripes, 0); 1703 atomic_set(&conf->active_stripes, 0);
1621 atomic_set(&conf->preread_active_stripes, 0); 1704 atomic_set(&conf->preread_active_stripes, 0);
@@ -1727,6 +1810,9 @@ memory = conf->max_nr_stripes * (sizeof(struct stripe_head) +
1727 1810
1728 /* Ok, everything is just fine now */ 1811 /* Ok, everything is just fine now */
1729 1812
1813 if (mddev->bitmap)
1814 mddev->thread->timeout = mddev->bitmap->daemon_sleep * HZ;
1815
1730 mddev->queue->unplug_fn = raid5_unplug_device; 1816 mddev->queue->unplug_fn = raid5_unplug_device;
1731 mddev->queue->issue_flush_fn = raid5_issue_flush; 1817 mddev->queue->issue_flush_fn = raid5_issue_flush;
1732 1818
@@ -1907,6 +1993,8 @@ static int raid5_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
1907 rdev->in_sync = 0; 1993 rdev->in_sync = 0;
1908 rdev->raid_disk = disk; 1994 rdev->raid_disk = disk;
1909 found = 1; 1995 found = 1;
1996 if (rdev->saved_raid_disk != disk)
1997 conf->fullsync = 1;
1910 p->rdev = rdev; 1998 p->rdev = rdev;
1911 break; 1999 break;
1912 } 2000 }
@@ -1936,6 +2024,35 @@ static int raid5_resize(mddev_t *mddev, sector_t sectors)
1936 return 0; 2024 return 0;
1937} 2025}
1938 2026
2027static void raid5_quiesce(mddev_t *mddev, int state)
2028{
2029 raid5_conf_t *conf = mddev_to_conf(mddev);
2030
2031 switch(state) {
2032 case 1: /* stop all writes */
2033 spin_lock_irq(&conf->device_lock);
2034 conf->quiesce = 1;
2035 wait_event_lock_irq(conf->wait_for_stripe,
2036 atomic_read(&conf->active_stripes) == 0,
2037 conf->device_lock, /* nothing */);
2038 spin_unlock_irq(&conf->device_lock);
2039 break;
2040
2041 case 0: /* re-enable writes */
2042 spin_lock_irq(&conf->device_lock);
2043 conf->quiesce = 0;
2044 wake_up(&conf->wait_for_stripe);
2045 spin_unlock_irq(&conf->device_lock);
2046 break;
2047 }
2048 if (mddev->thread) {
2049 if (mddev->bitmap)
2050 mddev->thread->timeout = mddev->bitmap->daemon_sleep * HZ;
2051 else
2052 mddev->thread->timeout = MAX_SCHEDULE_TIMEOUT;
2053 md_wakeup_thread(mddev->thread);
2054 }
2055}
1939static mdk_personality_t raid5_personality= 2056static mdk_personality_t raid5_personality=
1940{ 2057{
1941 .name = "raid5", 2058 .name = "raid5",
@@ -1950,6 +2067,7 @@ static mdk_personality_t raid5_personality=
1950 .spare_active = raid5_spare_active, 2067 .spare_active = raid5_spare_active,
1951 .sync_request = sync_request, 2068 .sync_request = sync_request,
1952 .resize = raid5_resize, 2069 .resize = raid5_resize,
2070 .quiesce = raid5_quiesce,
1953}; 2071};
1954 2072
1955static int __init raid5_init (void) 2073static int __init raid5_init (void)
diff --git a/drivers/md/raid6main.c b/drivers/md/raid6main.c
index 495dee1d1e..267eb1430c 100644
--- a/drivers/md/raid6main.c
+++ b/drivers/md/raid6main.c
@@ -29,6 +29,8 @@
29#include <asm/atomic.h> 29#include <asm/atomic.h>
30#include "raid6.h" 30#include "raid6.h"
31 31
32#include <linux/raid/bitmap.h>
33
32/* 34/*
33 * Stripe cache 35 * Stripe cache
34 */ 36 */
@@ -98,8 +100,13 @@ static inline void __release_stripe(raid6_conf_t *conf, struct stripe_head *sh)
98 if (test_bit(STRIPE_HANDLE, &sh->state)) { 100 if (test_bit(STRIPE_HANDLE, &sh->state)) {
99 if (test_bit(STRIPE_DELAYED, &sh->state)) 101 if (test_bit(STRIPE_DELAYED, &sh->state))
100 list_add_tail(&sh->lru, &conf->delayed_list); 102 list_add_tail(&sh->lru, &conf->delayed_list);
101 else 103 else if (test_bit(STRIPE_BIT_DELAY, &sh->state) &&
104 conf->seq_write == sh->bm_seq)
105 list_add_tail(&sh->lru, &conf->bitmap_list);
106 else {
107 clear_bit(STRIPE_BIT_DELAY, &sh->state);
102 list_add_tail(&sh->lru, &conf->handle_list); 108 list_add_tail(&sh->lru, &conf->handle_list);
109 }
103 md_wakeup_thread(conf->mddev->thread); 110 md_wakeup_thread(conf->mddev->thread);
104 } else { 111 } else {
105 if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { 112 if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) {
@@ -262,6 +269,9 @@ static struct stripe_head *get_active_stripe(raid6_conf_t *conf, sector_t sector
262 spin_lock_irq(&conf->device_lock); 269 spin_lock_irq(&conf->device_lock);
263 270
264 do { 271 do {
272 wait_event_lock_irq(conf->wait_for_stripe,
273 conf->quiesce == 0,
274 conf->device_lock, /* nothing */);
265 sh = __find_stripe(conf, sector); 275 sh = __find_stripe(conf, sector);
266 if (!sh) { 276 if (!sh) {
267 if (!conf->inactive_blocked) 277 if (!conf->inactive_blocked)
@@ -906,6 +916,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
906{ 916{
907 struct bio **bip; 917 struct bio **bip;
908 raid6_conf_t *conf = sh->raid_conf; 918 raid6_conf_t *conf = sh->raid_conf;
919 int firstwrite=0;
909 920
910 PRINTK("adding bh b#%llu to stripe s#%llu\n", 921 PRINTK("adding bh b#%llu to stripe s#%llu\n",
911 (unsigned long long)bi->bi_sector, 922 (unsigned long long)bi->bi_sector,
@@ -914,9 +925,11 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
914 925
915 spin_lock(&sh->lock); 926 spin_lock(&sh->lock);
916 spin_lock_irq(&conf->device_lock); 927 spin_lock_irq(&conf->device_lock);
917 if (forwrite) 928 if (forwrite) {
918 bip = &sh->dev[dd_idx].towrite; 929 bip = &sh->dev[dd_idx].towrite;
919 else 930 if (*bip == NULL && sh->dev[dd_idx].written == NULL)
931 firstwrite = 1;
932 } else
920 bip = &sh->dev[dd_idx].toread; 933 bip = &sh->dev[dd_idx].toread;
921 while (*bip && (*bip)->bi_sector < bi->bi_sector) { 934 while (*bip && (*bip)->bi_sector < bi->bi_sector) {
922 if ((*bip)->bi_sector + ((*bip)->bi_size >> 9) > bi->bi_sector) 935 if ((*bip)->bi_sector + ((*bip)->bi_size >> 9) > bi->bi_sector)
@@ -939,6 +952,13 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
939 (unsigned long long)bi->bi_sector, 952 (unsigned long long)bi->bi_sector,
940 (unsigned long long)sh->sector, dd_idx); 953 (unsigned long long)sh->sector, dd_idx);
941 954
955 if (conf->mddev->bitmap && firstwrite) {
956 sh->bm_seq = conf->seq_write;
957 bitmap_startwrite(conf->mddev->bitmap, sh->sector,
958 STRIPE_SECTORS, 0);
959 set_bit(STRIPE_BIT_DELAY, &sh->state);
960 }
961
942 if (forwrite) { 962 if (forwrite) {
943 /* check if page is covered */ 963 /* check if page is covered */
944 sector_t sector = sh->dev[dd_idx].sector; 964 sector_t sector = sh->dev[dd_idx].sector;
@@ -1066,12 +1086,13 @@ static void handle_stripe(struct stripe_head *sh)
1066 * need to be failed 1086 * need to be failed
1067 */ 1087 */
1068 if (failed > 2 && to_read+to_write+written) { 1088 if (failed > 2 && to_read+to_write+written) {
1069 spin_lock_irq(&conf->device_lock);
1070 for (i=disks; i--; ) { 1089 for (i=disks; i--; ) {
1090 int bitmap_end = 0;
1091 spin_lock_irq(&conf->device_lock);
1071 /* fail all writes first */ 1092 /* fail all writes first */
1072 bi = sh->dev[i].towrite; 1093 bi = sh->dev[i].towrite;
1073 sh->dev[i].towrite = NULL; 1094 sh->dev[i].towrite = NULL;
1074 if (bi) to_write--; 1095 if (bi) { to_write--; bitmap_end = 1; }
1075 1096
1076 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) 1097 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
1077 wake_up(&conf->wait_for_overlap); 1098 wake_up(&conf->wait_for_overlap);
@@ -1089,6 +1110,7 @@ static void handle_stripe(struct stripe_head *sh)
1089 /* and fail all 'written' */ 1110 /* and fail all 'written' */
1090 bi = sh->dev[i].written; 1111 bi = sh->dev[i].written;
1091 sh->dev[i].written = NULL; 1112 sh->dev[i].written = NULL;
1113 if (bi) bitmap_end = 1;
1092 while (bi && bi->bi_sector < sh->dev[i].sector + STRIPE_SECTORS) { 1114 while (bi && bi->bi_sector < sh->dev[i].sector + STRIPE_SECTORS) {
1093 struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector); 1115 struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector);
1094 clear_bit(BIO_UPTODATE, &bi->bi_flags); 1116 clear_bit(BIO_UPTODATE, &bi->bi_flags);
@@ -1117,8 +1139,11 @@ static void handle_stripe(struct stripe_head *sh)
1117 bi = nextbi; 1139 bi = nextbi;
1118 } 1140 }
1119 } 1141 }
1142 spin_unlock_irq(&conf->device_lock);
1143 if (bitmap_end)
1144 bitmap_endwrite(conf->mddev->bitmap, sh->sector,
1145 STRIPE_SECTORS, 0, 0);
1120 } 1146 }
1121 spin_unlock_irq(&conf->device_lock);
1122 } 1147 }
1123 if (failed > 2 && syncing) { 1148 if (failed > 2 && syncing) {
1124 md_done_sync(conf->mddev, STRIPE_SECTORS,0); 1149 md_done_sync(conf->mddev, STRIPE_SECTORS,0);
@@ -1155,6 +1180,7 @@ static void handle_stripe(struct stripe_head *sh)
1155 if (!test_bit(R5_LOCKED, &dev->flags) && 1180 if (!test_bit(R5_LOCKED, &dev->flags) &&
1156 test_bit(R5_UPTODATE, &dev->flags) ) { 1181 test_bit(R5_UPTODATE, &dev->flags) ) {
1157 /* We can return any write requests */ 1182 /* We can return any write requests */
1183 int bitmap_end = 0;
1158 struct bio *wbi, *wbi2; 1184 struct bio *wbi, *wbi2;
1159 PRINTK("Return write for stripe %llu disc %d\n", 1185 PRINTK("Return write for stripe %llu disc %d\n",
1160 (unsigned long long)sh->sector, i); 1186 (unsigned long long)sh->sector, i);
@@ -1170,7 +1196,13 @@ static void handle_stripe(struct stripe_head *sh)
1170 } 1196 }
1171 wbi = wbi2; 1197 wbi = wbi2;
1172 } 1198 }
1199 if (dev->towrite == NULL)
1200 bitmap_end = 1;
1173 spin_unlock_irq(&conf->device_lock); 1201 spin_unlock_irq(&conf->device_lock);
1202 if (bitmap_end)
1203 bitmap_endwrite(conf->mddev->bitmap, sh->sector,
1204 STRIPE_SECTORS,
1205 !test_bit(STRIPE_DEGRADED, &sh->state), 0);
1174 } 1206 }
1175 } 1207 }
1176 } 1208 }
@@ -1285,7 +1317,8 @@ static void handle_stripe(struct stripe_head *sh)
1285 } 1317 }
1286 } 1318 }
1287 /* now if nothing is locked, and if we have enough data, we can start a write request */ 1319 /* now if nothing is locked, and if we have enough data, we can start a write request */
1288 if (locked == 0 && rcw == 0) { 1320 if (locked == 0 && rcw == 0 &&
1321 !test_bit(STRIPE_BIT_DELAY, &sh->state)) {
1289 if ( must_compute > 0 ) { 1322 if ( must_compute > 0 ) {
1290 /* We have failed blocks and need to compute them */ 1323 /* We have failed blocks and need to compute them */
1291 switch ( failed ) { 1324 switch ( failed ) {
@@ -1388,6 +1421,7 @@ static void handle_stripe(struct stripe_head *sh)
1388 bdev = &sh->dev[failed_num[1]]; 1421 bdev = &sh->dev[failed_num[1]];
1389 locked += !test_bit(R5_LOCKED, &bdev->flags); 1422 locked += !test_bit(R5_LOCKED, &bdev->flags);
1390 set_bit(R5_LOCKED, &bdev->flags); 1423 set_bit(R5_LOCKED, &bdev->flags);
1424 clear_bit(STRIPE_DEGRADED, &sh->state);
1391 set_bit(R5_Wantwrite, &bdev->flags); 1425 set_bit(R5_Wantwrite, &bdev->flags);
1392 1426
1393 set_bit(STRIPE_INSYNC, &sh->state); 1427 set_bit(STRIPE_INSYNC, &sh->state);
@@ -1457,6 +1491,8 @@ static void handle_stripe(struct stripe_head *sh)
1457 bi->bi_next = NULL; 1491 bi->bi_next = NULL;
1458 generic_make_request(bi); 1492 generic_make_request(bi);
1459 } else { 1493 } else {
1494 if (rw == 1)
1495 set_bit(STRIPE_DEGRADED, &sh->state);
1460 PRINTK("skip op %ld on disc %d for sector %llu\n", 1496 PRINTK("skip op %ld on disc %d for sector %llu\n",
1461 bi->bi_rw, i, (unsigned long long)sh->sector); 1497 bi->bi_rw, i, (unsigned long long)sh->sector);
1462 clear_bit(R5_LOCKED, &sh->dev[i].flags); 1498 clear_bit(R5_LOCKED, &sh->dev[i].flags);
@@ -1481,6 +1517,20 @@ static inline void raid6_activate_delayed(raid6_conf_t *conf)
1481 } 1517 }
1482} 1518}
1483 1519
1520static inline void activate_bit_delay(raid6_conf_t *conf)
1521{
1522 /* device_lock is held */
1523 struct list_head head;
1524 list_add(&head, &conf->bitmap_list);
1525 list_del_init(&conf->bitmap_list);
1526 while (!list_empty(&head)) {
1527 struct stripe_head *sh = list_entry(head.next, struct stripe_head, lru);
1528 list_del_init(&sh->lru);
1529 atomic_inc(&sh->count);
1530 __release_stripe(conf, sh);
1531 }
1532}
1533
1484static void unplug_slaves(mddev_t *mddev) 1534static void unplug_slaves(mddev_t *mddev)
1485{ 1535{
1486 raid6_conf_t *conf = mddev_to_conf(mddev); 1536 raid6_conf_t *conf = mddev_to_conf(mddev);
@@ -1513,8 +1563,10 @@ static void raid6_unplug_device(request_queue_t *q)
1513 1563
1514 spin_lock_irqsave(&conf->device_lock, flags); 1564 spin_lock_irqsave(&conf->device_lock, flags);
1515 1565
1516 if (blk_remove_plug(q)) 1566 if (blk_remove_plug(q)) {
1567 conf->seq_flush++;
1517 raid6_activate_delayed(conf); 1568 raid6_activate_delayed(conf);
1569 }
1518 md_wakeup_thread(mddev->thread); 1570 md_wakeup_thread(mddev->thread);
1519 1571
1520 spin_unlock_irqrestore(&conf->device_lock, flags); 1572 spin_unlock_irqrestore(&conf->device_lock, flags);
@@ -1570,6 +1622,11 @@ static int make_request (request_queue_t *q, struct bio * bi)
1570 sector_t logical_sector, last_sector; 1622 sector_t logical_sector, last_sector;
1571 struct stripe_head *sh; 1623 struct stripe_head *sh;
1572 1624
1625 if (unlikely(bio_barrier(bi))) {
1626 bio_endio(bi, bi->bi_size, -EOPNOTSUPP);
1627 return 0;
1628 }
1629
1573 md_write_start(mddev, bi); 1630 md_write_start(mddev, bi);
1574 1631
1575 if (bio_data_dir(bi)==WRITE) { 1632 if (bio_data_dir(bi)==WRITE) {
@@ -1647,10 +1704,20 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1647 sector_t first_sector; 1704 sector_t first_sector;
1648 int raid_disks = conf->raid_disks; 1705 int raid_disks = conf->raid_disks;
1649 int data_disks = raid_disks - 2; 1706 int data_disks = raid_disks - 2;
1707 sector_t max_sector = mddev->size << 1;
1708 int sync_blocks;
1650 1709
1651 if (sector_nr >= mddev->size <<1) { 1710 if (sector_nr >= max_sector) {
1652 /* just being told to finish up .. nothing much to do */ 1711 /* just being told to finish up .. nothing much to do */
1653 unplug_slaves(mddev); 1712 unplug_slaves(mddev);
1713
1714 if (mddev->curr_resync < max_sector) /* aborted */
1715 bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
1716 &sync_blocks, 1);
1717 else /* compelted sync */
1718 conf->fullsync = 0;
1719 bitmap_close_sync(mddev->bitmap);
1720
1654 return 0; 1721 return 0;
1655 } 1722 }
1656 /* if there are 2 or more failed drives and we are trying 1723 /* if there are 2 or more failed drives and we are trying
@@ -1662,6 +1729,13 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1662 *skipped = 1; 1729 *skipped = 1;
1663 return rv; 1730 return rv;
1664 } 1731 }
1732 if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) &&
1733 !conf->fullsync && sync_blocks >= STRIPE_SECTORS) {
1734 /* we can skip this block, and probably more */
1735 sync_blocks /= STRIPE_SECTORS;
1736 *skipped = 1;
1737 return sync_blocks * STRIPE_SECTORS; /* keep things rounded to whole stripes */
1738 }
1665 1739
1666 x = sector_nr; 1740 x = sector_nr;
1667 chunk_offset = sector_div(x, sectors_per_chunk); 1741 chunk_offset = sector_div(x, sectors_per_chunk);
@@ -1679,6 +1753,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1679 set_current_state(TASK_UNINTERRUPTIBLE); 1753 set_current_state(TASK_UNINTERRUPTIBLE);
1680 schedule_timeout(1); 1754 schedule_timeout(1);
1681 } 1755 }
1756 bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 0);
1682 spin_lock(&sh->lock); 1757 spin_lock(&sh->lock);
1683 set_bit(STRIPE_SYNCING, &sh->state); 1758 set_bit(STRIPE_SYNCING, &sh->state);
1684 clear_bit(STRIPE_INSYNC, &sh->state); 1759 clear_bit(STRIPE_INSYNC, &sh->state);
@@ -1712,6 +1787,13 @@ static void raid6d (mddev_t *mddev)
1712 while (1) { 1787 while (1) {
1713 struct list_head *first; 1788 struct list_head *first;
1714 1789
1790 if (conf->seq_flush - conf->seq_write > 0) {
1791 int seq = conf->seq_flush;
1792 bitmap_unplug(mddev->bitmap);
1793 conf->seq_write = seq;
1794 activate_bit_delay(conf);
1795 }
1796
1715 if (list_empty(&conf->handle_list) && 1797 if (list_empty(&conf->handle_list) &&
1716 atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD && 1798 atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD &&
1717 !blk_queue_plugged(mddev->queue) && 1799 !blk_queue_plugged(mddev->queue) &&
@@ -1745,7 +1827,7 @@ static void raid6d (mddev_t *mddev)
1745 PRINTK("--- raid6d inactive\n"); 1827 PRINTK("--- raid6d inactive\n");
1746} 1828}
1747 1829
1748static int run (mddev_t *mddev) 1830static int run(mddev_t *mddev)
1749{ 1831{
1750 raid6_conf_t *conf; 1832 raid6_conf_t *conf;
1751 int raid_disk, memory; 1833 int raid_disk, memory;
@@ -1775,6 +1857,7 @@ static int run (mddev_t *mddev)
1775 init_waitqueue_head(&conf->wait_for_overlap); 1857 init_waitqueue_head(&conf->wait_for_overlap);
1776 INIT_LIST_HEAD(&conf->handle_list); 1858 INIT_LIST_HEAD(&conf->handle_list);
1777 INIT_LIST_HEAD(&conf->delayed_list); 1859 INIT_LIST_HEAD(&conf->delayed_list);
1860 INIT_LIST_HEAD(&conf->bitmap_list);
1778 INIT_LIST_HEAD(&conf->inactive_list); 1861 INIT_LIST_HEAD(&conf->inactive_list);
1779 atomic_set(&conf->active_stripes, 0); 1862 atomic_set(&conf->active_stripes, 0);
1780 atomic_set(&conf->preread_active_stripes, 0); 1863 atomic_set(&conf->preread_active_stripes, 0);
@@ -1894,6 +1977,9 @@ static int run (mddev_t *mddev)
1894 /* Ok, everything is just fine now */ 1977 /* Ok, everything is just fine now */
1895 mddev->array_size = mddev->size * (mddev->raid_disks - 2); 1978 mddev->array_size = mddev->size * (mddev->raid_disks - 2);
1896 1979
1980 if (mddev->bitmap)
1981 mddev->thread->timeout = mddev->bitmap->daemon_sleep * HZ;
1982
1897 mddev->queue->unplug_fn = raid6_unplug_device; 1983 mddev->queue->unplug_fn = raid6_unplug_device;
1898 mddev->queue->issue_flush_fn = raid6_issue_flush; 1984 mddev->queue->issue_flush_fn = raid6_issue_flush;
1899 return 0; 1985 return 0;
@@ -2071,6 +2157,8 @@ static int raid6_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
2071 rdev->in_sync = 0; 2157 rdev->in_sync = 0;
2072 rdev->raid_disk = disk; 2158 rdev->raid_disk = disk;
2073 found = 1; 2159 found = 1;
2160 if (rdev->saved_raid_disk != disk)
2161 conf->fullsync = 1;
2074 p->rdev = rdev; 2162 p->rdev = rdev;
2075 break; 2163 break;
2076 } 2164 }
@@ -2100,6 +2188,35 @@ static int raid6_resize(mddev_t *mddev, sector_t sectors)
2100 return 0; 2188 return 0;
2101} 2189}
2102 2190
2191static void raid6_quiesce(mddev_t *mddev, int state)
2192{
2193 raid6_conf_t *conf = mddev_to_conf(mddev);
2194
2195 switch(state) {
2196 case 1: /* stop all writes */
2197 spin_lock_irq(&conf->device_lock);
2198 conf->quiesce = 1;
2199 wait_event_lock_irq(conf->wait_for_stripe,
2200 atomic_read(&conf->active_stripes) == 0,
2201 conf->device_lock, /* nothing */);
2202 spin_unlock_irq(&conf->device_lock);
2203 break;
2204
2205 case 0: /* re-enable writes */
2206 spin_lock_irq(&conf->device_lock);
2207 conf->quiesce = 0;
2208 wake_up(&conf->wait_for_stripe);
2209 spin_unlock_irq(&conf->device_lock);
2210 break;
2211 }
2212 if (mddev->thread) {
2213 if (mddev->bitmap)
2214 mddev->thread->timeout = mddev->bitmap->daemon_sleep * HZ;
2215 else
2216 mddev->thread->timeout = MAX_SCHEDULE_TIMEOUT;
2217 md_wakeup_thread(mddev->thread);
2218 }
2219}
2103static mdk_personality_t raid6_personality= 2220static mdk_personality_t raid6_personality=
2104{ 2221{
2105 .name = "raid6", 2222 .name = "raid6",
@@ -2114,6 +2231,7 @@ static mdk_personality_t raid6_personality=
2114 .spare_active = raid6_spare_active, 2231 .spare_active = raid6_spare_active,
2115 .sync_request = sync_request, 2232 .sync_request = sync_request,
2116 .resize = raid6_resize, 2233 .resize = raid6_resize,
2234 .quiesce = raid6_quiesce,
2117}; 2235};
2118 2236
2119static int __init raid6_init (void) 2237static int __init raid6_init (void)
diff --git a/drivers/media/Makefile b/drivers/media/Makefile
index 772d6112fb..c578a529e7 100644
--- a/drivers/media/Makefile
+++ b/drivers/media/Makefile
@@ -2,4 +2,7 @@
2# Makefile for the kernel multimedia device drivers. 2# Makefile for the kernel multimedia device drivers.
3# 3#
4 4
5obj-y := video/ radio/ dvb/ common/ 5obj-y := common/
6obj-$(CONFIG_VIDEO_DEV) += video/
7obj-$(CONFIG_VIDEO_DEV) += radio/
8obj-$(CONFIG_DVB) += dvb/
diff --git a/drivers/media/common/ir-common.c b/drivers/media/common/ir-common.c
index ab7a1fba44..a0e700d7a4 100644
--- a/drivers/media/common/ir-common.c
+++ b/drivers/media/common/ir-common.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: ir-common.c,v 1.11 2005/07/07 14:44:43 mchehab Exp $
3 * 2 *
4 * some common structs and functions to handle infrared remotes via 3 * some common structs and functions to handle infrared remotes via
5 * input layer ... 4 * input layer ...
@@ -335,6 +334,72 @@ int ir_dump_samples(u32 *samples, int count)
335 return 0; 334 return 0;
336} 335}
337 336
337/* decode raw samples, pulse distance coding used by NEC remotes */
338int ir_decode_pulsedistance(u32 *samples, int count, int low, int high)
339{
340 int i,last,bit,len;
341 u32 curBit;
342 u32 value;
343
344 /* find start burst */
345 for (i = len = 0; i < count * 32; i++) {
346 bit = getbit(samples,i);
347 if (bit) {
348 len++;
349 } else {
350 if (len >= 29)
351 break;
352 len = 0;
353 }
354 }
355
356 /* start burst to short */
357 if (len < 29)
358 return 0xffffffff;
359
360 /* find start silence */
361 for (len = 0; i < count * 32; i++) {
362 bit = getbit(samples,i);
363 if (bit) {
364 break;
365 } else {
366 len++;
367 }
368 }
369
370 /* silence to short */
371 if (len < 7)
372 return 0xffffffff;
373
374 /* go decoding */
375 len = 0;
376 last = 1;
377 value = 0; curBit = 1;
378 for (; i < count * 32; i++) {
379 bit = getbit(samples,i);
380 if (last) {
381 if(bit) {
382 continue;
383 } else {
384 len = 1;
385 }
386 } else {
387 if (bit) {
388 if (len > (low + high) /2)
389 value |= curBit;
390 curBit <<= 1;
391 if (curBit == 1)
392 break;
393 } else {
394 len++;
395 }
396 }
397 last = bit;
398 }
399
400 return value;
401}
402
338/* decode raw samples, biphase coding, used by rc5 for example */ 403/* decode raw samples, biphase coding, used by rc5 for example */
339int ir_decode_biphase(u32 *samples, int count, int low, int high) 404int ir_decode_biphase(u32 *samples, int count, int low, int high)
340{ 405{
@@ -383,6 +448,7 @@ EXPORT_SYMBOL_GPL(ir_input_keydown);
383EXPORT_SYMBOL_GPL(ir_extract_bits); 448EXPORT_SYMBOL_GPL(ir_extract_bits);
384EXPORT_SYMBOL_GPL(ir_dump_samples); 449EXPORT_SYMBOL_GPL(ir_dump_samples);
385EXPORT_SYMBOL_GPL(ir_decode_biphase); 450EXPORT_SYMBOL_GPL(ir_decode_biphase);
451EXPORT_SYMBOL_GPL(ir_decode_pulsedistance);
386 452
387/* 453/*
388 * Local variables: 454 * Local variables:
diff --git a/drivers/media/common/saa7146_core.c b/drivers/media/common/saa7146_core.c
index cd5828b5e9..206cc2f61f 100644
--- a/drivers/media/common/saa7146_core.c
+++ b/drivers/media/common/saa7146_core.c
@@ -168,10 +168,8 @@ void saa7146_pgtable_free(struct pci_dev *pci, struct saa7146_pgtable *pt)
168 return; 168 return;
169 pci_free_consistent(pci, pt->size, pt->cpu, pt->dma); 169 pci_free_consistent(pci, pt->size, pt->cpu, pt->dma);
170 pt->cpu = NULL; 170 pt->cpu = NULL;
171 if (NULL != pt->slist) { 171 kfree(pt->slist);
172 kfree(pt->slist); 172 pt->slist = NULL;
173 pt->slist = NULL;
174 }
175} 173}
176 174
177int saa7146_pgtable_alloc(struct pci_dev *pci, struct saa7146_pgtable *pt) 175int saa7146_pgtable_alloc(struct pci_dev *pci, struct saa7146_pgtable *pt)
diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c
index c04fd11526..37888989ea 100644
--- a/drivers/media/common/saa7146_fops.c
+++ b/drivers/media/common/saa7146_fops.c
@@ -1,5 +1,4 @@
1#include <media/saa7146_vv.h> 1#include <media/saa7146_vv.h>
2#include <linux/version.h>
3 2
4#define BOARD_CAN_DO_VBI(dev) (dev->revision != 0 && dev->vv_data->vbi_minor != -1) 3#define BOARD_CAN_DO_VBI(dev) (dev->revision != 0 && dev->vv_data->vbi_minor != -1)
5 4
diff --git a/drivers/media/common/saa7146_i2c.c b/drivers/media/common/saa7146_i2c.c
index 6284894505..fec6beab8c 100644
--- a/drivers/media/common/saa7146_i2c.c
+++ b/drivers/media/common/saa7146_i2c.c
@@ -1,4 +1,3 @@
1#include <linux/version.h>
2#include <media/saa7146_vv.h> 1#include <media/saa7146_vv.h>
3 2
4static u32 saa7146_i2c_func(struct i2c_adapter *adapter) 3static u32 saa7146_i2c_func(struct i2c_adapter *adapter)
@@ -402,12 +401,9 @@ int saa7146_i2c_adapter_prepare(struct saa7146_dev *dev, struct i2c_adapter *i2c
402 saa7146_i2c_reset(dev); 401 saa7146_i2c_reset(dev);
403 402
404 if( NULL != i2c_adapter ) { 403 if( NULL != i2c_adapter ) {
405#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
406 i2c_adapter->data = dev;
407#else
408 BUG_ON(!i2c_adapter->class); 404 BUG_ON(!i2c_adapter->class);
409 i2c_set_adapdata(i2c_adapter,dev); 405 i2c_set_adapdata(i2c_adapter,dev);
410#endif 406 i2c_adapter->dev.parent = &dev->pci->dev;
411 i2c_adapter->algo = &saa7146_algo; 407 i2c_adapter->algo = &saa7146_algo;
412 i2c_adapter->algo_data = NULL; 408 i2c_adapter->algo_data = NULL;
413 i2c_adapter->id = I2C_HW_SAA7146; 409 i2c_adapter->id = I2C_HW_SAA7146;
diff --git a/drivers/media/dvb/b2c2/flexcop-fe-tuner.c b/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
index 0410cc96a4..47e28b0ee9 100644
--- a/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
+++ b/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
@@ -164,12 +164,11 @@ static int samsung_tbmu24112_set_symbol_rate(struct dvb_frontend* fe, u32 srate,
164 return 0; 164 return 0;
165} 165}
166 166
167static int samsung_tbmu24112_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 167static int samsung_tbmu24112_pll_set(struct dvb_frontend* fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters* params)
168{ 168{
169 u8 buf[4]; 169 u8 buf[4];
170 u32 div; 170 u32 div;
171 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) }; 171 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
172 struct flexcop_device *fc = fe->dvb->priv;
173 172
174 div = params->frequency / 125; 173 div = params->frequency / 125;
175 174
@@ -180,7 +179,7 @@ static int samsung_tbmu24112_pll_set(struct dvb_frontend* fe, struct dvb_fronten
180 179
181 if (params->frequency < 1500000) buf[3] |= 0x10; 180 if (params->frequency < 1500000) buf[3] |= 0x10;
182 181
183 if (i2c_transfer(&fc->i2c_adap, &msg, 1) != 1) 182 if (i2c_transfer(i2c, &msg, 1) != 1)
184 return -EIO; 183 return -EIO;
185 return 0; 184 return 0;
186} 185}
@@ -335,8 +334,103 @@ static struct mt312_config skystar23_samsung_tbdu18132_config = {
335 .pll_set = skystar23_samsung_tbdu18132_pll_set, 334 .pll_set = skystar23_samsung_tbdu18132_pll_set,
336}; 335};
337 336
337
338static u8 alps_tdee4_stv0297_inittab[] = {
339 0x80, 0x01,
340 0x80, 0x00,
341 0x81, 0x01,
342 0x81, 0x00,
343 0x00, 0x09,
344 0x01, 0x69,
345 0x03, 0x00,
346 0x04, 0x00,
347 0x07, 0x00,
348 0x08, 0x00,
349 0x20, 0x00,
350 0x21, 0x40,
351 0x22, 0x00,
352 0x23, 0x00,
353 0x24, 0x40,
354 0x25, 0x88,
355 0x30, 0xff,
356 0x31, 0x00,
357 0x32, 0xff,
358 0x33, 0x00,
359 0x34, 0x50,
360 0x35, 0x7f,
361 0x36, 0x00,
362 0x37, 0x20,
363 0x38, 0x00,
364 0x40, 0x1c,
365 0x41, 0xff,
366 0x42, 0x29,
367 0x43, 0x00,
368 0x44, 0xff,
369 0x45, 0x00,
370 0x46, 0x00,
371 0x49, 0x04,
372 0x4a, 0x00,
373 0x4b, 0xf8,
374 0x52, 0x30,
375 0x55, 0xae,
376 0x56, 0x47,
377 0x57, 0xe1,
378 0x58, 0x3a,
379 0x5a, 0x1e,
380 0x5b, 0x34,
381 0x60, 0x00,
382 0x63, 0x00,
383 0x64, 0x00,
384 0x65, 0x00,
385 0x66, 0x00,
386 0x67, 0x00,
387 0x68, 0x00,
388 0x69, 0x00,
389 0x6a, 0x02,
390 0x6b, 0x00,
391 0x70, 0xff,
392 0x71, 0x00,
393 0x72, 0x00,
394 0x73, 0x00,
395 0x74, 0x0c,
396 0x80, 0x00,
397 0x81, 0x00,
398 0x82, 0x00,
399 0x83, 0x00,
400 0x84, 0x04,
401 0x85, 0x80,
402 0x86, 0x24,
403 0x87, 0x78,
404 0x88, 0x10,
405 0x89, 0x00,
406 0x90, 0x01,
407 0x91, 0x01,
408 0xa0, 0x04,
409 0xa1, 0x00,
410 0xa2, 0x00,
411 0xb0, 0x91,
412 0xb1, 0x0b,
413 0xc0, 0x53,
414 0xc1, 0x70,
415 0xc2, 0x12,
416 0xd0, 0x00,
417 0xd1, 0x00,
418 0xd2, 0x00,
419 0xd3, 0x00,
420 0xd4, 0x00,
421 0xd5, 0x00,
422 0xde, 0x00,
423 0xdf, 0x00,
424 0x61, 0x49,
425 0x62, 0x0b,
426 0x53, 0x08,
427 0x59, 0x08,
428 0xff, 0xff,
429};
430
338static struct stv0297_config alps_tdee4_stv0297_config = { 431static struct stv0297_config alps_tdee4_stv0297_config = {
339 .demod_address = 0x1c, 432 .demod_address = 0x1c,
433 .inittab = alps_tdee4_stv0297_inittab,
340// .invert = 1, 434// .invert = 1,
341// .pll_set = alps_tdee4_stv0297_pll_set, 435// .pll_set = alps_tdee4_stv0297_pll_set,
342}; 436};
@@ -370,7 +464,7 @@ int flexcop_frontend_init(struct flexcop_device *fc)
370 info("found the bcm3510 at i2c address: 0x%02x",air2pc_atsc_first_gen_config.demod_address); 464 info("found the bcm3510 at i2c address: 0x%02x",air2pc_atsc_first_gen_config.demod_address);
371 } else 465 } else
372 /* try the cable dvb (stv0297) */ 466 /* try the cable dvb (stv0297) */
373 if ((fc->fe = stv0297_attach(&alps_tdee4_stv0297_config, &fc->i2c_adap, 0xf8)) != NULL) { 467 if ((fc->fe = stv0297_attach(&alps_tdee4_stv0297_config, &fc->i2c_adap)) != NULL) {
374 fc->dev_type = FC_CABLE; 468 fc->dev_type = FC_CABLE;
375 info("found the stv0297 at i2c address: 0x%02x",alps_tdee4_stv0297_config.demod_address); 469 info("found the stv0297 at i2c address: 0x%02x",alps_tdee4_stv0297_config.demod_address);
376 } else 470 } else
diff --git a/drivers/media/dvb/bt8xx/bt878.c b/drivers/media/dvb/bt8xx/bt878.c
index 3c5a8e273c..f295714500 100644
--- a/drivers/media/dvb/bt8xx/bt878.c
+++ b/drivers/media/dvb/bt8xx/bt878.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * bt878.c: part of the driver for the Pinnacle PCTV Sat DVB PCI card 2 * bt878.c: part of the driver for the Pinnacle PCTV Sat DVB PCI card
3 * 3 *
4 * Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@t-online.de> 4 * Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@htp-tel.de>
5 * 5 *
6 * large parts based on the bttv driver 6 * large parts based on the bttv driver
7 * Copyright (C) 1996,97,98 Ralph Metzler (rjkm@metzlerbros.de) 7 * Copyright (C) 1996,97,98 Ralph Metzler (rjkm@metzlerbros.de)
@@ -219,7 +219,7 @@ void bt878_start(struct bt878 *bt, u32 controlreg, u32 op_sync_orin,
219 controlreg &= ~0x1f; 219 controlreg &= ~0x1f;
220 controlreg |= 0x1b; 220 controlreg |= 0x1b;
221 221
222 btwrite(cpu_to_le32(bt->risc_dma), BT878_ARISC_START); 222 btwrite(bt->risc_dma, BT878_ARISC_START);
223 223
224 /* original int mask had : 224 /* original int mask had :
225 * 6 2 8 4 0 225 * 6 2 8 4 0
diff --git a/drivers/media/dvb/bt8xx/bt878.h b/drivers/media/dvb/bt8xx/bt878.h
index 837623f7fc..a73baf00ca 100644
--- a/drivers/media/dvb/bt8xx/bt878.h
+++ b/drivers/media/dvb/bt8xx/bt878.h
@@ -1,7 +1,7 @@
1/* 1/*
2 bt878.h - Bt878 audio module (register offsets) 2 bt878.h - Bt878 audio module (register offsets)
3 3
4 Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@t-online.de> 4 Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@htp-tel.de>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index 07a0b0a968..34a837a1ab 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -1,5 +1,4 @@
1/* 1/*
2
3 Frontend/Card driver for TwinHan DST Frontend 2 Frontend/Card driver for TwinHan DST Frontend
4 Copyright (C) 2003 Jamie Honan 3 Copyright (C) 2003 Jamie Honan
5 Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com) 4 Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com)
@@ -19,7 +18,6 @@
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/ 19*/
21 20
22
23#include <linux/kernel.h> 21#include <linux/kernel.h>
24#include <linux/module.h> 22#include <linux/module.h>
25#include <linux/init.h> 23#include <linux/init.h>
@@ -28,31 +26,45 @@
28#include <linux/vmalloc.h> 26#include <linux/vmalloc.h>
29#include <linux/delay.h> 27#include <linux/delay.h>
30#include <asm/div64.h> 28#include <asm/div64.h>
31
32#include "dvb_frontend.h" 29#include "dvb_frontend.h"
33#include "dst_priv.h" 30#include "dst_priv.h"
34#include "dst_common.h" 31#include "dst_common.h"
35 32
36
37static unsigned int verbose = 1; 33static unsigned int verbose = 1;
38module_param(verbose, int, 0644); 34module_param(verbose, int, 0644);
39MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)"); 35MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
40 36
41static unsigned int debug = 1;
42module_param(debug, int, 0644);
43MODULE_PARM_DESC(debug, "debug messages, default is 0 (yes)");
44
45static unsigned int dst_addons; 37static unsigned int dst_addons;
46module_param(dst_addons, int, 0644); 38module_param(dst_addons, int, 0644);
47MODULE_PARM_DESC(dst_addons, "CA daughterboard, default is 0 (No addons)"); 39MODULE_PARM_DESC(dst_addons, "CA daughterboard, default is 0 (No addons)");
48 40
49#define dprintk if (debug) printk 41#define HAS_LOCK 1
50 42#define ATTEMPT_TUNE 2
51#define HAS_LOCK 1 43#define HAS_POWER 4
52#define ATTEMPT_TUNE 2 44
53#define HAS_POWER 4 45#define DST_ERROR 0
54 46#define DST_NOTICE 1
55static void dst_packsize(struct dst_state* state, int psize) 47#define DST_INFO 2
48#define DST_DEBUG 3
49
50#define dprintk(x, y, z, format, arg...) do { \
51 if (z) { \
52 if ((x > DST_ERROR) && (x > y)) \
53 printk(KERN_ERR "%s: " format "\n", __FUNCTION__ , ##arg); \
54 else if ((x > DST_NOTICE) && (x > y)) \
55 printk(KERN_NOTICE "%s: " format "\n", __FUNCTION__ , ##arg); \
56 else if ((x > DST_INFO) && (x > y)) \
57 printk(KERN_INFO "%s: " format "\n", __FUNCTION__ , ##arg); \
58 else if ((x > DST_DEBUG) && (x > y)) \
59 printk(KERN_DEBUG "%s: " format "\n", __FUNCTION__ , ##arg); \
60 } else { \
61 if (x > y) \
62 printk(format, ##arg); \
63 } \
64} while(0)
65
66
67static void dst_packsize(struct dst_state *state, int psize)
56{ 68{
57 union dst_gpio_packet bits; 69 union dst_gpio_packet bits;
58 70
@@ -60,7 +72,7 @@ static void dst_packsize(struct dst_state* state, int psize)
60 bt878_device_control(state->bt, DST_IG_TS, &bits); 72 bt878_device_control(state->bt, DST_IG_TS, &bits);
61} 73}
62 74
63int dst_gpio_outb(struct dst_state* state, u32 mask, u32 enbb, u32 outhigh, int delay) 75int dst_gpio_outb(struct dst_state *state, u32 mask, u32 enbb, u32 outhigh, int delay)
64{ 76{
65 union dst_gpio_packet enb; 77 union dst_gpio_packet enb;
66 union dst_gpio_packet bits; 78 union dst_gpio_packet bits;
@@ -68,63 +80,55 @@ int dst_gpio_outb(struct dst_state* state, u32 mask, u32 enbb, u32 outhigh, int
68 80
69 enb.enb.mask = mask; 81 enb.enb.mask = mask;
70 enb.enb.enable = enbb; 82 enb.enb.enable = enbb;
71 if (verbose > 4)
72 dprintk("%s: mask=[%04x], enbb=[%04x], outhigh=[%04x]\n", __FUNCTION__, mask, enbb, outhigh);
73 83
84 dprintk(verbose, DST_INFO, 1, "mask=[%04x], enbb=[%04x], outhigh=[%04x]", mask, enbb, outhigh);
74 if ((err = bt878_device_control(state->bt, DST_IG_ENABLE, &enb)) < 0) { 85 if ((err = bt878_device_control(state->bt, DST_IG_ENABLE, &enb)) < 0) {
75 dprintk("%s: dst_gpio_enb error (err == %i, mask == %02x, enb == %02x)\n", __FUNCTION__, err, mask, enbb); 86 dprintk(verbose, DST_INFO, 1, "dst_gpio_enb error (err == %i, mask == %02x, enb == %02x)", err, mask, enbb);
76 return -EREMOTEIO; 87 return -EREMOTEIO;
77 } 88 }
78 udelay(1000); 89 udelay(1000);
79 /* because complete disabling means no output, no need to do output packet */ 90 /* because complete disabling means no output, no need to do output packet */
80 if (enbb == 0) 91 if (enbb == 0)
81 return 0; 92 return 0;
82
83 if (delay) 93 if (delay)
84 msleep(10); 94 msleep(10);
85
86 bits.outp.mask = enbb; 95 bits.outp.mask = enbb;
87 bits.outp.highvals = outhigh; 96 bits.outp.highvals = outhigh;
88
89 if ((err = bt878_device_control(state->bt, DST_IG_WRITE, &bits)) < 0) { 97 if ((err = bt878_device_control(state->bt, DST_IG_WRITE, &bits)) < 0) {
90 dprintk("%s: dst_gpio_outb error (err == %i, enbb == %02x, outhigh == %02x)\n", __FUNCTION__, err, enbb, outhigh); 98 dprintk(verbose, DST_INFO, 1, "dst_gpio_outb error (err == %i, enbb == %02x, outhigh == %02x)", err, enbb, outhigh);
91 return -EREMOTEIO; 99 return -EREMOTEIO;
92 } 100 }
101
93 return 0; 102 return 0;
94} 103}
95EXPORT_SYMBOL(dst_gpio_outb); 104EXPORT_SYMBOL(dst_gpio_outb);
96 105
97int dst_gpio_inb(struct dst_state *state, u8 * result) 106int dst_gpio_inb(struct dst_state *state, u8 *result)
98{ 107{
99 union dst_gpio_packet rd_packet; 108 union dst_gpio_packet rd_packet;
100 int err; 109 int err;
101 110
102 *result = 0; 111 *result = 0;
103
104 if ((err = bt878_device_control(state->bt, DST_IG_READ, &rd_packet)) < 0) { 112 if ((err = bt878_device_control(state->bt, DST_IG_READ, &rd_packet)) < 0) {
105 dprintk("%s: dst_gpio_inb error (err == %i)\n", __FUNCTION__, err); 113 dprintk(verbose, DST_ERROR, 1, "dst_gpio_inb error (err == %i)\n", err);
106 return -EREMOTEIO; 114 return -EREMOTEIO;
107 } 115 }
108
109 *result = (u8) rd_packet.rd.value; 116 *result = (u8) rd_packet.rd.value;
117
110 return 0; 118 return 0;
111} 119}
112EXPORT_SYMBOL(dst_gpio_inb); 120EXPORT_SYMBOL(dst_gpio_inb);
113 121
114int rdc_reset_state(struct dst_state *state) 122int rdc_reset_state(struct dst_state *state)
115{ 123{
116 if (verbose > 1) 124 dprintk(verbose, DST_INFO, 1, "Resetting state machine");
117 dprintk("%s: Resetting state machine\n", __FUNCTION__);
118
119 if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, 0, NO_DELAY) < 0) { 125 if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, 0, NO_DELAY) < 0) {
120 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__); 126 dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
121 return -1; 127 return -1;
122 } 128 }
123
124 msleep(10); 129 msleep(10);
125
126 if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, RDC_8820_INT, NO_DELAY) < 0) { 130 if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, RDC_8820_INT, NO_DELAY) < 0) {
127 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__); 131 dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
128 msleep(10); 132 msleep(10);
129 return -1; 133 return -1;
130 } 134 }
@@ -135,16 +139,14 @@ EXPORT_SYMBOL(rdc_reset_state);
135 139
136int rdc_8820_reset(struct dst_state *state) 140int rdc_8820_reset(struct dst_state *state)
137{ 141{
138 if (verbose > 1) 142 dprintk(verbose, DST_DEBUG, 1, "Resetting DST");
139 dprintk("%s: Resetting DST\n", __FUNCTION__);
140
141 if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, 0, NO_DELAY) < 0) { 143 if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, 0, NO_DELAY) < 0) {
142 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__); 144 dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
143 return -1; 145 return -1;
144 } 146 }
145 udelay(1000); 147 udelay(1000);
146 if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, RDC_8820_RESET, DELAY) < 0) { 148 if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, RDC_8820_RESET, DELAY) < 0) {
147 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__); 149 dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
148 return -1; 150 return -1;
149 } 151 }
150 152
@@ -155,10 +157,11 @@ EXPORT_SYMBOL(rdc_8820_reset);
155int dst_pio_enable(struct dst_state *state) 157int dst_pio_enable(struct dst_state *state)
156{ 158{
157 if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_ENABLE, 0, NO_DELAY) < 0) { 159 if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_ENABLE, 0, NO_DELAY) < 0) {
158 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__); 160 dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
159 return -1; 161 return -1;
160 } 162 }
161 udelay(1000); 163 udelay(1000);
164
162 return 0; 165 return 0;
163} 166}
164EXPORT_SYMBOL(dst_pio_enable); 167EXPORT_SYMBOL(dst_pio_enable);
@@ -166,7 +169,7 @@ EXPORT_SYMBOL(dst_pio_enable);
166int dst_pio_disable(struct dst_state *state) 169int dst_pio_disable(struct dst_state *state)
167{ 170{
168 if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_DISABLE, RDC_8820_PIO_0_DISABLE, NO_DELAY) < 0) { 171 if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_DISABLE, RDC_8820_PIO_0_DISABLE, NO_DELAY) < 0) {
169 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__); 172 dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
170 return -1; 173 return -1;
171 } 174 }
172 if (state->type_flags & DST_TYPE_HAS_FW_1) 175 if (state->type_flags & DST_TYPE_HAS_FW_1)
@@ -183,19 +186,16 @@ int dst_wait_dst_ready(struct dst_state *state, u8 delay_mode)
183 186
184 for (i = 0; i < 200; i++) { 187 for (i = 0; i < 200; i++) {
185 if (dst_gpio_inb(state, &reply) < 0) { 188 if (dst_gpio_inb(state, &reply) < 0) {
186 dprintk("%s: dst_gpio_inb ERROR !\n", __FUNCTION__); 189 dprintk(verbose, DST_ERROR, 1, "dst_gpio_inb ERROR !");
187 return -1; 190 return -1;
188 } 191 }
189
190 if ((reply & RDC_8820_PIO_0_ENABLE) == 0) { 192 if ((reply & RDC_8820_PIO_0_ENABLE) == 0) {
191 if (verbose > 4) 193 dprintk(verbose, DST_INFO, 1, "dst wait ready after %d", i);
192 dprintk("%s: dst wait ready after %d\n", __FUNCTION__, i);
193 return 1; 194 return 1;
194 } 195 }
195 msleep(10); 196 msleep(10);
196 } 197 }
197 if (verbose > 1) 198 dprintk(verbose, DST_NOTICE, 1, "dst wait NOT ready after %d", i);
198 dprintk("%s: dst wait NOT ready after %d\n", __FUNCTION__, i);
199 199
200 return 0; 200 return 0;
201} 201}
@@ -203,7 +203,7 @@ EXPORT_SYMBOL(dst_wait_dst_ready);
203 203
204int dst_error_recovery(struct dst_state *state) 204int dst_error_recovery(struct dst_state *state)
205{ 205{
206 dprintk("%s: Trying to return from previous errors...\n", __FUNCTION__); 206 dprintk(verbose, DST_NOTICE, 1, "Trying to return from previous errors.");
207 dst_pio_disable(state); 207 dst_pio_disable(state);
208 msleep(10); 208 msleep(10);
209 dst_pio_enable(state); 209 dst_pio_enable(state);
@@ -215,7 +215,7 @@ EXPORT_SYMBOL(dst_error_recovery);
215 215
216int dst_error_bailout(struct dst_state *state) 216int dst_error_bailout(struct dst_state *state)
217{ 217{
218 dprintk("%s: Trying to bailout from previous error...\n", __FUNCTION__); 218 dprintk(verbose, DST_INFO, 1, "Trying to bailout from previous error.");
219 rdc_8820_reset(state); 219 rdc_8820_reset(state);
220 dst_pio_disable(state); 220 dst_pio_disable(state);
221 msleep(10); 221 msleep(10);
@@ -224,17 +224,15 @@ int dst_error_bailout(struct dst_state *state)
224} 224}
225EXPORT_SYMBOL(dst_error_bailout); 225EXPORT_SYMBOL(dst_error_bailout);
226 226
227 227int dst_comm_init(struct dst_state *state)
228int dst_comm_init(struct dst_state* state)
229{ 228{
230 if (verbose > 1) 229 dprintk(verbose, DST_INFO, 1, "Initializing DST.");
231 dprintk ("%s: Initializing DST..\n", __FUNCTION__);
232 if ((dst_pio_enable(state)) < 0) { 230 if ((dst_pio_enable(state)) < 0) {
233 dprintk("%s: PIO Enable Failed.\n", __FUNCTION__); 231 dprintk(verbose, DST_ERROR, 1, "PIO Enable Failed");
234 return -1; 232 return -1;
235 } 233 }
236 if ((rdc_reset_state(state)) < 0) { 234 if ((rdc_reset_state(state)) < 0) {
237 dprintk("%s: RDC 8820 State RESET Failed.\n", __FUNCTION__); 235 dprintk(verbose, DST_ERROR, 1, "RDC 8820 State RESET Failed.");
238 return -1; 236 return -1;
239 } 237 }
240 if (state->type_flags & DST_TYPE_HAS_FW_1) 238 if (state->type_flags & DST_TYPE_HAS_FW_1)
@@ -246,36 +244,33 @@ int dst_comm_init(struct dst_state* state)
246} 244}
247EXPORT_SYMBOL(dst_comm_init); 245EXPORT_SYMBOL(dst_comm_init);
248 246
249
250int write_dst(struct dst_state *state, u8 *data, u8 len) 247int write_dst(struct dst_state *state, u8 *data, u8 len)
251{ 248{
252 struct i2c_msg msg = { 249 struct i2c_msg msg = {
253 .addr = state->config->demod_address,.flags = 0,.buf = data,.len = len 250 .addr = state->config->demod_address,
251 .flags = 0,
252 .buf = data,
253 .len = len
254 }; 254 };
255 255
256 int err; 256 int err;
257 int cnt; 257 u8 cnt, i;
258 if (debug && (verbose > 4)) { 258
259 u8 i; 259 dprintk(verbose, DST_NOTICE, 0, "writing [ ");
260 if (verbose > 4) { 260 for (i = 0; i < len; i++)
261 dprintk("%s writing [ ", __FUNCTION__); 261 dprintk(verbose, DST_NOTICE, 0, "%02x ", data[i]);
262 for (i = 0; i < len; i++) 262 dprintk(verbose, DST_NOTICE, 0, "]\n");
263 dprintk("%02x ", data[i]); 263
264 dprintk("]\n");
265 }
266 }
267 for (cnt = 0; cnt < 2; cnt++) { 264 for (cnt = 0; cnt < 2; cnt++) {
268 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) { 265 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
269 dprintk("%s: _write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, data[0]); 266 dprintk(verbose, DST_INFO, 1, "_write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)", err, len, data[0]);
270 dst_error_recovery(state); 267 dst_error_recovery(state);
271 continue; 268 continue;
272 } else 269 } else
273 break; 270 break;
274 } 271 }
275
276 if (cnt >= 2) { 272 if (cnt >= 2) {
277 if (verbose > 1) 273 dprintk(verbose, DST_INFO, 1, "RDC 8820 RESET");
278 printk("%s: RDC 8820 RESET...\n", __FUNCTION__);
279 dst_error_bailout(state); 274 dst_error_bailout(state);
280 275
281 return -1; 276 return -1;
@@ -285,36 +280,37 @@ int write_dst(struct dst_state *state, u8 *data, u8 len)
285} 280}
286EXPORT_SYMBOL(write_dst); 281EXPORT_SYMBOL(write_dst);
287 282
288int read_dst(struct dst_state *state, u8 * ret, u8 len) 283int read_dst(struct dst_state *state, u8 *ret, u8 len)
289{ 284{
290 struct i2c_msg msg = {.addr = state->config->demod_address,.flags = I2C_M_RD,.buf = ret,.len = len }; 285 struct i2c_msg msg = {
286 .addr = state->config->demod_address,
287 .flags = I2C_M_RD,
288 .buf = ret,
289 .len = len
290 };
291
291 int err; 292 int err;
292 int cnt; 293 int cnt;
293 294
294 for (cnt = 0; cnt < 2; cnt++) { 295 for (cnt = 0; cnt < 2; cnt++) {
295 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) { 296 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
296 297 dprintk(verbose, DST_INFO, 1, "read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)", err, len, ret[0]);
297 dprintk("%s: read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, ret[0]);
298 dst_error_recovery(state); 298 dst_error_recovery(state);
299
300 continue; 299 continue;
301 } else 300 } else
302 break; 301 break;
303 } 302 }
304 if (cnt >= 2) { 303 if (cnt >= 2) {
305 if (verbose > 1) 304 dprintk(verbose, DST_INFO, 1, "RDC 8820 RESET");
306 printk("%s: RDC 8820 RESET...\n", __FUNCTION__);
307 dst_error_bailout(state); 305 dst_error_bailout(state);
308 306
309 return -1; 307 return -1;
310 } 308 }
311 if (debug && (verbose > 4)) { 309 dprintk(verbose, DST_DEBUG, 1, "reply is 0x%x", ret[0]);
312 dprintk("%s reply is 0x%x\n", __FUNCTION__, ret[0]); 310 for (err = 1; err < len; err++)
313 for (err = 1; err < len; err++) 311 dprintk(verbose, DST_DEBUG, 0, " 0x%x", ret[err]);
314 dprintk(" 0x%x", ret[err]); 312 if (err > 1)
315 if (err > 1) 313 dprintk(verbose, DST_DEBUG, 0, "\n");
316 dprintk("\n");
317 }
318 314
319 return 0; 315 return 0;
320} 316}
@@ -323,19 +319,16 @@ EXPORT_SYMBOL(read_dst);
323static int dst_set_polarization(struct dst_state *state) 319static int dst_set_polarization(struct dst_state *state)
324{ 320{
325 switch (state->voltage) { 321 switch (state->voltage) {
326 case SEC_VOLTAGE_13: // vertical 322 case SEC_VOLTAGE_13: /* Vertical */
327 printk("%s: Polarization=[Vertical]\n", __FUNCTION__); 323 dprintk(verbose, DST_INFO, 1, "Polarization=[Vertical]");
328 state->tx_tuna[8] &= ~0x40; //1 324 state->tx_tuna[8] &= ~0x40;
329 break; 325 break;
330 326 case SEC_VOLTAGE_18: /* Horizontal */
331 case SEC_VOLTAGE_18: // horizontal 327 dprintk(verbose, DST_INFO, 1, "Polarization=[Horizontal]");
332 printk("%s: Polarization=[Horizontal]\n", __FUNCTION__); 328 state->tx_tuna[8] |= 0x40;
333 state->tx_tuna[8] |= 0x40; // 0 329 break;
334 break; 330 case SEC_VOLTAGE_OFF:
335 331 break;
336 case SEC_VOLTAGE_OFF:
337
338 break;
339 } 332 }
340 333
341 return 0; 334 return 0;
@@ -344,14 +337,12 @@ static int dst_set_polarization(struct dst_state *state)
344static int dst_set_freq(struct dst_state *state, u32 freq) 337static int dst_set_freq(struct dst_state *state, u32 freq)
345{ 338{
346 state->frequency = freq; 339 state->frequency = freq;
347 if (debug > 4) 340 dprintk(verbose, DST_INFO, 1, "set Frequency %u", freq);
348 dprintk("%s: set Frequency %u\n", __FUNCTION__, freq);
349 341
350 if (state->dst_type == DST_TYPE_IS_SAT) { 342 if (state->dst_type == DST_TYPE_IS_SAT) {
351 freq = freq / 1000; 343 freq = freq / 1000;
352 if (freq < 950 || freq > 2150) 344 if (freq < 950 || freq > 2150)
353 return -EINVAL; 345 return -EINVAL;
354
355 state->tx_tuna[2] = (freq >> 8); 346 state->tx_tuna[2] = (freq >> 8);
356 state->tx_tuna[3] = (u8) freq; 347 state->tx_tuna[3] = (u8) freq;
357 state->tx_tuna[4] = 0x01; 348 state->tx_tuna[4] = 0x01;
@@ -360,27 +351,25 @@ static int dst_set_freq(struct dst_state *state, u32 freq)
360 if (freq < 1531) 351 if (freq < 1531)
361 state->tx_tuna[8] |= 0x04; 352 state->tx_tuna[8] |= 0x04;
362 } 353 }
363
364 } else if (state->dst_type == DST_TYPE_IS_TERR) { 354 } else if (state->dst_type == DST_TYPE_IS_TERR) {
365 freq = freq / 1000; 355 freq = freq / 1000;
366 if (freq < 137000 || freq > 858000) 356 if (freq < 137000 || freq > 858000)
367 return -EINVAL; 357 return -EINVAL;
368
369 state->tx_tuna[2] = (freq >> 16) & 0xff; 358 state->tx_tuna[2] = (freq >> 16) & 0xff;
370 state->tx_tuna[3] = (freq >> 8) & 0xff; 359 state->tx_tuna[3] = (freq >> 8) & 0xff;
371 state->tx_tuna[4] = (u8) freq; 360 state->tx_tuna[4] = (u8) freq;
372
373 } else if (state->dst_type == DST_TYPE_IS_CABLE) { 361 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
362 freq = freq / 1000;
374 state->tx_tuna[2] = (freq >> 16) & 0xff; 363 state->tx_tuna[2] = (freq >> 16) & 0xff;
375 state->tx_tuna[3] = (freq >> 8) & 0xff; 364 state->tx_tuna[3] = (freq >> 8) & 0xff;
376 state->tx_tuna[4] = (u8) freq; 365 state->tx_tuna[4] = (u8) freq;
377
378 } else 366 } else
379 return -EINVAL; 367 return -EINVAL;
368
380 return 0; 369 return 0;
381} 370}
382 371
383static int dst_set_bandwidth(struct dst_state* state, fe_bandwidth_t bandwidth) 372static int dst_set_bandwidth(struct dst_state *state, fe_bandwidth_t bandwidth)
384{ 373{
385 state->bandwidth = bandwidth; 374 state->bandwidth = bandwidth;
386 375
@@ -388,103 +377,95 @@ static int dst_set_bandwidth(struct dst_state* state, fe_bandwidth_t bandwidth)
388 return 0; 377 return 0;
389 378
390 switch (bandwidth) { 379 switch (bandwidth) {
391 case BANDWIDTH_6_MHZ: 380 case BANDWIDTH_6_MHZ:
392 if (state->dst_hw_cap & DST_TYPE_HAS_CA) 381 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
393 state->tx_tuna[7] = 0x06; 382 state->tx_tuna[7] = 0x06;
394 else { 383 else {
395 state->tx_tuna[6] = 0x06; 384 state->tx_tuna[6] = 0x06;
396 state->tx_tuna[7] = 0x00; 385 state->tx_tuna[7] = 0x00;
397 } 386 }
398 break; 387 break;
399 388 case BANDWIDTH_7_MHZ:
400 case BANDWIDTH_7_MHZ: 389 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
401 if (state->dst_hw_cap & DST_TYPE_HAS_CA) 390 state->tx_tuna[7] = 0x07;
402 state->tx_tuna[7] = 0x07; 391 else {
403 else { 392 state->tx_tuna[6] = 0x07;
404 state->tx_tuna[6] = 0x07; 393 state->tx_tuna[7] = 0x00;
405 state->tx_tuna[7] = 0x00; 394 }
406 } 395 break;
407 break; 396 case BANDWIDTH_8_MHZ:
408 397 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
409 case BANDWIDTH_8_MHZ: 398 state->tx_tuna[7] = 0x08;
410 if (state->dst_hw_cap & DST_TYPE_HAS_CA) 399 else {
411 state->tx_tuna[7] = 0x08; 400 state->tx_tuna[6] = 0x08;
412 else { 401 state->tx_tuna[7] = 0x00;
413 state->tx_tuna[6] = 0x08; 402 }
414 state->tx_tuna[7] = 0x00; 403 break;
415 } 404 default:
416 break; 405 return -EINVAL;
417
418 default:
419 return -EINVAL;
420 } 406 }
407
421 return 0; 408 return 0;
422} 409}
423 410
424static int dst_set_inversion(struct dst_state* state, fe_spectral_inversion_t inversion) 411static int dst_set_inversion(struct dst_state *state, fe_spectral_inversion_t inversion)
425{ 412{
426 state->inversion = inversion; 413 state->inversion = inversion;
427 switch (inversion) { 414 switch (inversion) {
428 case INVERSION_OFF: // Inversion = Normal 415 case INVERSION_OFF: /* Inversion = Normal */
429 state->tx_tuna[8] &= ~0x80; 416 state->tx_tuna[8] &= ~0x80;
430 break; 417 break;
431 418 case INVERSION_ON:
432 case INVERSION_ON: 419 state->tx_tuna[8] |= 0x80;
433 state->tx_tuna[8] |= 0x80; 420 break;
434 break; 421 default:
435 default: 422 return -EINVAL;
436 return -EINVAL;
437 } 423 }
424
438 return 0; 425 return 0;
439} 426}
440 427
441static int dst_set_fec(struct dst_state* state, fe_code_rate_t fec) 428static int dst_set_fec(struct dst_state *state, fe_code_rate_t fec)
442{ 429{
443 state->fec = fec; 430 state->fec = fec;
444 return 0; 431 return 0;
445} 432}
446 433
447static fe_code_rate_t dst_get_fec(struct dst_state* state) 434static fe_code_rate_t dst_get_fec(struct dst_state *state)
448{ 435{
449 return state->fec; 436 return state->fec;
450} 437}
451 438
452static int dst_set_symbolrate(struct dst_state* state, u32 srate) 439static int dst_set_symbolrate(struct dst_state *state, u32 srate)
453{ 440{
454 u8 *val;
455 u32 symcalc; 441 u32 symcalc;
456 u64 sval; 442 u64 sval;
457 443
458 state->symbol_rate = srate; 444 state->symbol_rate = srate;
459
460 if (state->dst_type == DST_TYPE_IS_TERR) { 445 if (state->dst_type == DST_TYPE_IS_TERR) {
461 return 0; 446 return 0;
462 } 447 }
463 if (debug > 4) 448 dprintk(verbose, DST_INFO, 1, "set symrate %u", srate);
464 dprintk("%s: set symrate %u\n", __FUNCTION__, srate);
465 srate /= 1000; 449 srate /= 1000;
466 val = &state->tx_tuna[0];
467
468 if (state->type_flags & DST_TYPE_HAS_SYMDIV) { 450 if (state->type_flags & DST_TYPE_HAS_SYMDIV) {
469 sval = srate; 451 sval = srate;
470 sval <<= 20; 452 sval <<= 20;
471 do_div(sval, 88000); 453 do_div(sval, 88000);
472 symcalc = (u32) sval; 454 symcalc = (u32) sval;
473 455 dprintk(verbose, DST_INFO, 1, "set symcalc %u", symcalc);
474 if (debug > 4) 456 state->tx_tuna[5] = (u8) (symcalc >> 12);
475 dprintk("%s: set symcalc %u\n", __FUNCTION__, symcalc); 457 state->tx_tuna[6] = (u8) (symcalc >> 4);
476 458 state->tx_tuna[7] = (u8) (symcalc << 4);
477 val[5] = (u8) (symcalc >> 12);
478 val[6] = (u8) (symcalc >> 4);
479 val[7] = (u8) (symcalc << 4);
480 } else { 459 } else {
481 val[5] = (u8) (srate >> 16) & 0x7f; 460 state->tx_tuna[5] = (u8) (srate >> 16) & 0x7f;
482 val[6] = (u8) (srate >> 8); 461 state->tx_tuna[6] = (u8) (srate >> 8);
483 val[7] = (u8) srate; 462 state->tx_tuna[7] = (u8) srate;
463 }
464 state->tx_tuna[8] &= ~0x20;
465 if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
466 if (srate > 8000)
467 state->tx_tuna[8] |= 0x20;
484 } 468 }
485 val[8] &= ~0x20;
486 if (srate > 8000)
487 val[8] |= 0x20;
488 return 0; 469 return 0;
489} 470}
490 471
@@ -496,32 +477,27 @@ static int dst_set_modulation(struct dst_state *state, fe_modulation_t modulatio
496 477
497 state->modulation = modulation; 478 state->modulation = modulation;
498 switch (modulation) { 479 switch (modulation) {
499 case QAM_16: 480 case QAM_16:
500 state->tx_tuna[8] = 0x10; 481 state->tx_tuna[8] = 0x10;
501 break; 482 break;
502 483 case QAM_32:
503 case QAM_32: 484 state->tx_tuna[8] = 0x20;
504 state->tx_tuna[8] = 0x20; 485 break;
505 break; 486 case QAM_64:
506 487 state->tx_tuna[8] = 0x40;
507 case QAM_64: 488 break;
508 state->tx_tuna[8] = 0x40; 489 case QAM_128:
509 break; 490 state->tx_tuna[8] = 0x80;
510 491 break;
511 case QAM_128: 492 case QAM_256:
512 state->tx_tuna[8] = 0x80; 493 state->tx_tuna[8] = 0x00;
513 break; 494 break;
514 495 case QPSK:
515 case QAM_256: 496 case QAM_AUTO:
516 state->tx_tuna[8] = 0x00; 497 case VSB_8:
517 break; 498 case VSB_16:
518 499 default:
519 case QPSK: 500 return -EINVAL;
520 case QAM_AUTO:
521 case VSB_8:
522 case VSB_16:
523 default:
524 return -EINVAL;
525 501
526 } 502 }
527 503
@@ -534,7 +510,7 @@ static fe_modulation_t dst_get_modulation(struct dst_state *state)
534} 510}
535 511
536 512
537u8 dst_check_sum(u8 * buf, u32 len) 513u8 dst_check_sum(u8 *buf, u32 len)
538{ 514{
539 u32 i; 515 u32 i;
540 u8 val = 0; 516 u8 val = 0;
@@ -549,26 +525,24 @@ EXPORT_SYMBOL(dst_check_sum);
549 525
550static void dst_type_flags_print(u32 type_flags) 526static void dst_type_flags_print(u32 type_flags)
551{ 527{
552 printk("DST type flags :"); 528 dprintk(verbose, DST_ERROR, 0, "DST type flags :");
553 if (type_flags & DST_TYPE_HAS_NEWTUNE) 529 if (type_flags & DST_TYPE_HAS_NEWTUNE)
554 printk(" 0x%x newtuner", DST_TYPE_HAS_NEWTUNE); 530 dprintk(verbose, DST_ERROR, 0, " 0x%x newtuner", DST_TYPE_HAS_NEWTUNE);
555 if (type_flags & DST_TYPE_HAS_TS204) 531 if (type_flags & DST_TYPE_HAS_TS204)
556 printk(" 0x%x ts204", DST_TYPE_HAS_TS204); 532 dprintk(verbose, DST_ERROR, 0, " 0x%x ts204", DST_TYPE_HAS_TS204);
557 if (type_flags & DST_TYPE_HAS_SYMDIV) 533 if (type_flags & DST_TYPE_HAS_SYMDIV)
558 printk(" 0x%x symdiv", DST_TYPE_HAS_SYMDIV); 534 dprintk(verbose, DST_ERROR, 0, " 0x%x symdiv", DST_TYPE_HAS_SYMDIV);
559 if (type_flags & DST_TYPE_HAS_FW_1) 535 if (type_flags & DST_TYPE_HAS_FW_1)
560 printk(" 0x%x firmware version = 1", DST_TYPE_HAS_FW_1); 536 dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 1", DST_TYPE_HAS_FW_1);
561 if (type_flags & DST_TYPE_HAS_FW_2) 537 if (type_flags & DST_TYPE_HAS_FW_2)
562 printk(" 0x%x firmware version = 2", DST_TYPE_HAS_FW_2); 538 dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 2", DST_TYPE_HAS_FW_2);
563 if (type_flags & DST_TYPE_HAS_FW_3) 539 if (type_flags & DST_TYPE_HAS_FW_3)
564 printk(" 0x%x firmware version = 3", DST_TYPE_HAS_FW_3); 540 dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 3", DST_TYPE_HAS_FW_3);
565// if ((type_flags & DST_TYPE_HAS_FW_BUILD) && new_fw) 541 dprintk(verbose, DST_ERROR, 0, "\n");
566
567 printk("\n");
568} 542}
569 543
570 544
571static int dst_type_print (u8 type) 545static int dst_type_print(u8 type)
572{ 546{
573 char *otype; 547 char *otype;
574 switch (type) { 548 switch (type) {
@@ -585,10 +559,10 @@ static int dst_type_print (u8 type)
585 break; 559 break;
586 560
587 default: 561 default:
588 printk("%s: invalid dst type %d\n", __FUNCTION__, type); 562 dprintk(verbose, DST_INFO, 1, "invalid dst type %d", type);
589 return -EINVAL; 563 return -EINVAL;
590 } 564 }
591 printk("DST type : %s\n", otype); 565 dprintk(verbose, DST_INFO, 1, "DST type: %s", otype);
592 566
593 return 0; 567 return 0;
594} 568}
@@ -700,7 +674,7 @@ struct dst_types dst_tlist[] = {
700 .offset = 1, 674 .offset = 1,
701 .dst_type = DST_TYPE_IS_CABLE, 675 .dst_type = DST_TYPE_IS_CABLE,
702 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1 676 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1
703 | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD, 677 | DST_TYPE_HAS_FW_2,
704 .dst_feature = DST_TYPE_HAS_CA 678 .dst_feature = DST_TYPE_HAS_CA
705 }, 679 },
706 680
@@ -708,7 +682,7 @@ struct dst_types dst_tlist[] = {
708 .device_id = "DCTNEW", 682 .device_id = "DCTNEW",
709 .offset = 1, 683 .offset = 1,
710 .dst_type = DST_TYPE_IS_CABLE, 684 .dst_type = DST_TYPE_IS_CABLE,
711 .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_3, 685 .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_3 | DST_TYPE_HAS_FW_BUILD,
712 .dst_feature = 0 686 .dst_feature = 0
713 }, 687 },
714 688
@@ -716,7 +690,7 @@ struct dst_types dst_tlist[] = {
716 .device_id = "DTT-CI", 690 .device_id = "DTT-CI",
717 .offset = 1, 691 .offset = 1,
718 .dst_type = DST_TYPE_IS_TERR, 692 .dst_type = DST_TYPE_IS_TERR,
719 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD, 693 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2,
720 .dst_feature = 0 694 .dst_feature = 0
721 }, 695 },
722 696
@@ -756,6 +730,71 @@ struct dst_types dst_tlist[] = {
756 730
757}; 731};
758 732
733static int dst_get_mac(struct dst_state *state)
734{
735 u8 get_mac[] = { 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
736 get_mac[7] = dst_check_sum(get_mac, 7);
737 if (dst_command(state, get_mac, 8) < 0) {
738 dprintk(verbose, DST_INFO, 1, "Unsupported Command");
739 return -1;
740 }
741 memset(&state->mac_address, '\0', 8);
742 memcpy(&state->mac_address, &state->rxbuffer, 6);
743 dprintk(verbose, DST_ERROR, 1, "MAC Address=[%02x:%02x:%02x:%02x:%02x:%02x]",
744 state->mac_address[0], state->mac_address[1], state->mac_address[2],
745 state->mac_address[4], state->mac_address[5], state->mac_address[6]);
746
747 return 0;
748}
749
750static int dst_fw_ver(struct dst_state *state)
751{
752 u8 get_ver[] = { 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
753 get_ver[7] = dst_check_sum(get_ver, 7);
754 if (dst_command(state, get_ver, 8) < 0) {
755 dprintk(verbose, DST_INFO, 1, "Unsupported Command");
756 return -1;
757 }
758 memset(&state->fw_version, '\0', 8);
759 memcpy(&state->fw_version, &state->rxbuffer, 8);
760 dprintk(verbose, DST_ERROR, 1, "Firmware Ver = %x.%x Build = %02x, on %x:%x, %x-%x-20%02x",
761 state->fw_version[0] >> 4, state->fw_version[0] & 0x0f,
762 state->fw_version[1],
763 state->fw_version[5], state->fw_version[6],
764 state->fw_version[4], state->fw_version[3], state->fw_version[2]);
765
766 return 0;
767}
768
769static int dst_card_type(struct dst_state *state)
770{
771 u8 get_type[] = { 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
772 get_type[7] = dst_check_sum(get_type, 7);
773 if (dst_command(state, get_type, 8) < 0) {
774 dprintk(verbose, DST_INFO, 1, "Unsupported Command");
775 return -1;
776 }
777 memset(&state->card_info, '\0', 8);
778 memcpy(&state->card_info, &state->rxbuffer, 8);
779 dprintk(verbose, DST_ERROR, 1, "Device Model=[%s]", &state->card_info[0]);
780
781 return 0;
782}
783
784static int dst_get_vendor(struct dst_state *state)
785{
786 u8 get_vendor[] = { 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
787 get_vendor[7] = dst_check_sum(get_vendor, 7);
788 if (dst_command(state, get_vendor, 8) < 0) {
789 dprintk(verbose, DST_INFO, 1, "Unsupported Command");
790 return -1;
791 }
792 memset(&state->vendor, '\0', 8);
793 memcpy(&state->vendor, &state->rxbuffer, 8);
794 dprintk(verbose, DST_ERROR, 1, "Vendor=[%s]", &state->vendor[0]);
795
796 return 0;
797}
759 798
760static int dst_get_device_id(struct dst_state *state) 799static int dst_get_device_id(struct dst_state *state)
761{ 800{
@@ -772,53 +811,45 @@ static int dst_get_device_id(struct dst_state *state)
772 811
773 if (write_dst(state, device_type, FIXED_COMM)) 812 if (write_dst(state, device_type, FIXED_COMM))
774 return -1; /* Write failed */ 813 return -1; /* Write failed */
775
776 if ((dst_pio_disable(state)) < 0) 814 if ((dst_pio_disable(state)) < 0)
777 return -1; 815 return -1;
778
779 if (read_dst(state, &reply, GET_ACK)) 816 if (read_dst(state, &reply, GET_ACK))
780 return -1; /* Read failure */ 817 return -1; /* Read failure */
781
782 if (reply != ACK) { 818 if (reply != ACK) {
783 dprintk("%s: Write not Acknowledged! [Reply=0x%02x]\n", __FUNCTION__, reply); 819 dprintk(verbose, DST_INFO, 1, "Write not Acknowledged! [Reply=0x%02x]", reply);
784 return -1; /* Unack'd write */ 820 return -1; /* Unack'd write */
785 } 821 }
786
787 if (!dst_wait_dst_ready(state, DEVICE_INIT)) 822 if (!dst_wait_dst_ready(state, DEVICE_INIT))
788 return -1; /* DST not ready yet */ 823 return -1; /* DST not ready yet */
789
790 if (read_dst(state, state->rxbuffer, FIXED_COMM)) 824 if (read_dst(state, state->rxbuffer, FIXED_COMM))
791 return -1; 825 return -1;
792 826
793 dst_pio_disable(state); 827 dst_pio_disable(state);
794
795 if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) { 828 if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
796 dprintk("%s: Checksum failure! \n", __FUNCTION__); 829 dprintk(verbose, DST_INFO, 1, "Checksum failure!");
797 return -1; /* Checksum failure */ 830 return -1; /* Checksum failure */
798 } 831 }
799
800 state->rxbuffer[7] = '\0'; 832 state->rxbuffer[7] = '\0';
801 833
802 for (i = 0, p_dst_type = dst_tlist; i < ARRAY_SIZE (dst_tlist); i++, p_dst_type++) { 834 for (i = 0, p_dst_type = dst_tlist; i < ARRAY_SIZE(dst_tlist); i++, p_dst_type++) {
803 if (!strncmp (&state->rxbuffer[p_dst_type->offset], p_dst_type->device_id, strlen (p_dst_type->device_id))) { 835 if (!strncmp (&state->rxbuffer[p_dst_type->offset], p_dst_type->device_id, strlen (p_dst_type->device_id))) {
804 use_type_flags = p_dst_type->type_flags; 836 use_type_flags = p_dst_type->type_flags;
805 use_dst_type = p_dst_type->dst_type; 837 use_dst_type = p_dst_type->dst_type;
806 838
807 /* Card capabilities */ 839 /* Card capabilities */
808 state->dst_hw_cap = p_dst_type->dst_feature; 840 state->dst_hw_cap = p_dst_type->dst_feature;
809 printk ("%s: Recognise [%s]\n", __FUNCTION__, p_dst_type->device_id); 841 dprintk(verbose, DST_ERROR, 1, "Recognise [%s]\n", p_dst_type->device_id);
810 842
811 break; 843 break;
812 } 844 }
813 } 845 }
814 846
815 if (i >= sizeof (dst_tlist) / sizeof (dst_tlist [0])) { 847 if (i >= sizeof (dst_tlist) / sizeof (dst_tlist [0])) {
816 printk("%s: Unable to recognize %s or %s\n", __FUNCTION__, &state->rxbuffer[0], &state->rxbuffer[1]); 848 dprintk(verbose, DST_ERROR, 1, "Unable to recognize %s or %s", &state->rxbuffer[0], &state->rxbuffer[1]);
817 printk("%s: please email linux-dvb@linuxtv.org with this type in\n", __FUNCTION__); 849 dprintk(verbose, DST_ERROR, 1, "please email linux-dvb@linuxtv.org with this type in");
818 use_dst_type = DST_TYPE_IS_SAT; 850 use_dst_type = DST_TYPE_IS_SAT;
819 use_type_flags = DST_TYPE_HAS_SYMDIV; 851 use_type_flags = DST_TYPE_HAS_SYMDIV;
820 } 852 }
821
822 dst_type_print(use_dst_type); 853 dst_type_print(use_dst_type);
823 state->type_flags = use_type_flags; 854 state->type_flags = use_type_flags;
824 state->dst_type = use_dst_type; 855 state->dst_type = use_dst_type;
@@ -834,7 +865,7 @@ static int dst_get_device_id(struct dst_state *state)
834static int dst_probe(struct dst_state *state) 865static int dst_probe(struct dst_state *state)
835{ 866{
836 if ((rdc_8820_reset(state)) < 0) { 867 if ((rdc_8820_reset(state)) < 0) {
837 dprintk("%s: RDC 8820 RESET Failed.\n", __FUNCTION__); 868 dprintk(verbose, DST_ERROR, 1, "RDC 8820 RESET Failed.");
838 return -1; 869 return -1;
839 } 870 }
840 if (dst_addons & DST_TYPE_HAS_CA) 871 if (dst_addons & DST_TYPE_HAS_CA)
@@ -843,80 +874,87 @@ static int dst_probe(struct dst_state *state)
843 msleep(100); 874 msleep(100);
844 875
845 if ((dst_comm_init(state)) < 0) { 876 if ((dst_comm_init(state)) < 0) {
846 dprintk("%s: DST Initialization Failed.\n", __FUNCTION__); 877 dprintk(verbose, DST_ERROR, 1, "DST Initialization Failed.");
847 return -1; 878 return -1;
848 } 879 }
849 msleep(100); 880 msleep(100);
850 if (dst_get_device_id(state) < 0) { 881 if (dst_get_device_id(state) < 0) {
851 dprintk("%s: unknown device.\n", __FUNCTION__); 882 dprintk(verbose, DST_ERROR, 1, "unknown device.");
852 return -1; 883 return -1;
853 } 884 }
885 if (dst_get_mac(state) < 0) {
886 dprintk(verbose, DST_INFO, 1, "MAC: Unsupported command");
887 return 0;
888 }
889 if (state->type_flags & DST_TYPE_HAS_FW_BUILD) {
890 if (dst_fw_ver(state) < 0) {
891 dprintk(verbose, DST_INFO, 1, "FW: Unsupported command");
892 return 0;
893 }
894 if (dst_card_type(state) < 0) {
895 dprintk(verbose, DST_INFO, 1, "Card: Unsupported command");
896 return 0;
897 }
898 if (dst_get_vendor(state) < 0) {
899 dprintk(verbose, DST_INFO, 1, "Vendor: Unsupported command");
900 return 0;
901 }
902 }
854 903
855 return 0; 904 return 0;
856} 905}
857 906
858int dst_command(struct dst_state* state, u8 * data, u8 len) 907int dst_command(struct dst_state *state, u8 *data, u8 len)
859{ 908{
860 u8 reply; 909 u8 reply;
861 if ((dst_comm_init(state)) < 0) { 910 if ((dst_comm_init(state)) < 0) {
862 dprintk("%s: DST Communication Initialization Failed.\n", __FUNCTION__); 911 dprintk(verbose, DST_NOTICE, 1, "DST Communication Initialization Failed.");
863 return -1; 912 return -1;
864 } 913 }
865
866 if (write_dst(state, data, len)) { 914 if (write_dst(state, data, len)) {
867 if (verbose > 1) 915 dprintk(verbose, DST_INFO, 1, "Tring to recover.. ");
868 dprintk("%s: Tring to recover.. \n", __FUNCTION__);
869 if ((dst_error_recovery(state)) < 0) { 916 if ((dst_error_recovery(state)) < 0) {
870 dprintk("%s: Recovery Failed.\n", __FUNCTION__); 917 dprintk(verbose, DST_ERROR, 1, "Recovery Failed.");
871 return -1; 918 return -1;
872 } 919 }
873 return -1; 920 return -1;
874 } 921 }
875 if ((dst_pio_disable(state)) < 0) { 922 if ((dst_pio_disable(state)) < 0) {
876 dprintk("%s: PIO Disable Failed.\n", __FUNCTION__); 923 dprintk(verbose, DST_ERROR, 1, "PIO Disable Failed.");
877 return -1; 924 return -1;
878 } 925 }
879 if (state->type_flags & DST_TYPE_HAS_FW_1) 926 if (state->type_flags & DST_TYPE_HAS_FW_1)
880 udelay(3000); 927 udelay(3000);
881
882 if (read_dst(state, &reply, GET_ACK)) { 928 if (read_dst(state, &reply, GET_ACK)) {
883 if (verbose > 1) 929 dprintk(verbose, DST_DEBUG, 1, "Trying to recover.. ");
884 dprintk("%s: Trying to recover.. \n", __FUNCTION__);
885 if ((dst_error_recovery(state)) < 0) { 930 if ((dst_error_recovery(state)) < 0) {
886 dprintk("%s: Recovery Failed.\n", __FUNCTION__); 931 dprintk(verbose, DST_INFO, 1, "Recovery Failed.");
887 return -1; 932 return -1;
888 } 933 }
889 return -1; 934 return -1;
890 } 935 }
891
892 if (reply != ACK) { 936 if (reply != ACK) {
893 dprintk("%s: write not acknowledged 0x%02x \n", __FUNCTION__, reply); 937 dprintk(verbose, DST_INFO, 1, "write not acknowledged 0x%02x ", reply);
894 return -1; 938 return -1;
895 } 939 }
896 if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3)) 940 if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3))
897 return 0; 941 return 0;
898
899// udelay(3000);
900 if (state->type_flags & DST_TYPE_HAS_FW_1) 942 if (state->type_flags & DST_TYPE_HAS_FW_1)
901 udelay(3000); 943 udelay(3000);
902 else 944 else
903 udelay(2000); 945 udelay(2000);
904
905 if (!dst_wait_dst_ready(state, NO_DELAY)) 946 if (!dst_wait_dst_ready(state, NO_DELAY))
906 return -1; 947 return -1;
907
908 if (read_dst(state, state->rxbuffer, FIXED_COMM)) { 948 if (read_dst(state, state->rxbuffer, FIXED_COMM)) {
909 if (verbose > 1) 949 dprintk(verbose, DST_DEBUG, 1, "Trying to recover.. ");
910 dprintk("%s: Trying to recover.. \n", __FUNCTION__);
911 if ((dst_error_recovery(state)) < 0) { 950 if ((dst_error_recovery(state)) < 0) {
912 dprintk("%s: Recovery failed.\n", __FUNCTION__); 951 dprintk(verbose, DST_INFO, 1, "Recovery failed.");
913 return -1; 952 return -1;
914 } 953 }
915 return -1; 954 return -1;
916 } 955 }
917
918 if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) { 956 if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
919 dprintk("%s: checksum failure\n", __FUNCTION__); 957 dprintk(verbose, DST_INFO, 1, "checksum failure");
920 return -1; 958 return -1;
921 } 959 }
922 960
@@ -924,11 +962,11 @@ int dst_command(struct dst_state* state, u8 * data, u8 len)
924} 962}
925EXPORT_SYMBOL(dst_command); 963EXPORT_SYMBOL(dst_command);
926 964
927static int dst_get_signal(struct dst_state* state) 965static int dst_get_signal(struct dst_state *state)
928{ 966{
929 int retval; 967 int retval;
930 u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb }; 968 u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
931 dprintk("%s: Getting Signal strength and other parameters\n", __FUNCTION__); 969 //dprintk("%s: Getting Signal strength and other parameters\n", __FUNCTION__);
932 if ((state->diseq_flags & ATTEMPT_TUNE) == 0) { 970 if ((state->diseq_flags & ATTEMPT_TUNE) == 0) {
933 state->decode_lock = state->decode_strength = state->decode_snr = 0; 971 state->decode_lock = state->decode_strength = state->decode_snr = 0;
934 return 0; 972 return 0;
@@ -955,13 +993,12 @@ static int dst_get_signal(struct dst_state* state)
955 return 0; 993 return 0;
956} 994}
957 995
958static int dst_tone_power_cmd(struct dst_state* state) 996static int dst_tone_power_cmd(struct dst_state *state)
959{ 997{
960 u8 paket[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 }; 998 u8 paket[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 };
961 999
962 if (state->dst_type == DST_TYPE_IS_TERR) 1000 if (state->dst_type == DST_TYPE_IS_TERR)
963 return 0; 1001 return 0;
964
965 paket[4] = state->tx_tuna[4]; 1002 paket[4] = state->tx_tuna[4];
966 paket[2] = state->tx_tuna[2]; 1003 paket[2] = state->tx_tuna[2];
967 paket[3] = state->tx_tuna[3]; 1004 paket[3] = state->tx_tuna[3];
@@ -971,61 +1008,53 @@ static int dst_tone_power_cmd(struct dst_state* state)
971 return 0; 1008 return 0;
972} 1009}
973 1010
974static int dst_get_tuna(struct dst_state* state) 1011static int dst_get_tuna(struct dst_state *state)
975{ 1012{
976 int retval; 1013 int retval;
977 1014
978 if ((state->diseq_flags & ATTEMPT_TUNE) == 0) 1015 if ((state->diseq_flags & ATTEMPT_TUNE) == 0)
979 return 0; 1016 return 0;
980
981 state->diseq_flags &= ~(HAS_LOCK); 1017 state->diseq_flags &= ~(HAS_LOCK);
982 if (!dst_wait_dst_ready(state, NO_DELAY)) 1018 if (!dst_wait_dst_ready(state, NO_DELAY))
983 return 0; 1019 return 0;
984 1020 if (state->type_flags & DST_TYPE_HAS_NEWTUNE)
985 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
986 /* how to get variable length reply ???? */ 1021 /* how to get variable length reply ???? */
987 retval = read_dst(state, state->rx_tuna, 10); 1022 retval = read_dst(state, state->rx_tuna, 10);
988 } else { 1023 else
989 retval = read_dst(state, &state->rx_tuna[2], FIXED_COMM); 1024 retval = read_dst(state, &state->rx_tuna[2], FIXED_COMM);
990 }
991
992 if (retval < 0) { 1025 if (retval < 0) {
993 dprintk("%s: read not successful\n", __FUNCTION__); 1026 dprintk(verbose, DST_DEBUG, 1, "read not successful");
994 return 0; 1027 return 0;
995 } 1028 }
996
997 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) { 1029 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
998 if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) { 1030 if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) {
999 dprintk("%s: checksum failure?\n", __FUNCTION__); 1031 dprintk(verbose, DST_INFO, 1, "checksum failure ? ");
1000 return 0; 1032 return 0;
1001 } 1033 }
1002 } else { 1034 } else {
1003 if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[2], 7)) { 1035 if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[2], 7)) {
1004 dprintk("%s: checksum failure?\n", __FUNCTION__); 1036 dprintk(verbose, DST_INFO, 1, "checksum failure? ");
1005 return 0; 1037 return 0;
1006 } 1038 }
1007 } 1039 }
1008 if (state->rx_tuna[2] == 0 && state->rx_tuna[3] == 0) 1040 if (state->rx_tuna[2] == 0 && state->rx_tuna[3] == 0)
1009 return 0; 1041 return 0;
1010 state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3]; 1042 state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3];
1011
1012 state->decode_lock = 1; 1043 state->decode_lock = 1;
1013 state->diseq_flags |= HAS_LOCK; 1044 state->diseq_flags |= HAS_LOCK;
1014 1045
1015 return 1; 1046 return 1;
1016} 1047}
1017 1048
1018static int dst_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage); 1049static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage);
1019 1050
1020static int dst_write_tuna(struct dvb_frontend* fe) 1051static int dst_write_tuna(struct dvb_frontend *fe)
1021{ 1052{
1022 struct dst_state* state = fe->demodulator_priv; 1053 struct dst_state *state = fe->demodulator_priv;
1023 int retval; 1054 int retval;
1024 u8 reply; 1055 u8 reply;
1025 1056
1026 if (debug > 4) 1057 dprintk(verbose, DST_INFO, 1, "type_flags 0x%x ", state->type_flags);
1027 dprintk("%s: type_flags 0x%x \n", __FUNCTION__, state->type_flags);
1028
1029 state->decode_freq = 0; 1058 state->decode_freq = 0;
1030 state->decode_lock = state->decode_strength = state->decode_snr = 0; 1059 state->decode_lock = state->decode_strength = state->decode_snr = 0;
1031 if (state->dst_type == DST_TYPE_IS_SAT) { 1060 if (state->dst_type == DST_TYPE_IS_SAT) {
@@ -1035,35 +1064,31 @@ static int dst_write_tuna(struct dvb_frontend* fe)
1035 state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE); 1064 state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE);
1036 1065
1037 if ((dst_comm_init(state)) < 0) { 1066 if ((dst_comm_init(state)) < 0) {
1038 dprintk("%s: DST Communication initialization failed.\n", __FUNCTION__); 1067 dprintk(verbose, DST_DEBUG, 1, "DST Communication initialization failed.");
1039 return -1; 1068 return -1;
1040 } 1069 }
1041
1042 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) { 1070 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
1043 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9); 1071 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9);
1044 retval = write_dst(state, &state->tx_tuna[0], 10); 1072 retval = write_dst(state, &state->tx_tuna[0], 10);
1045
1046 } else { 1073 } else {
1047 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[2], 7); 1074 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[2], 7);
1048 retval = write_dst(state, &state->tx_tuna[2], FIXED_COMM); 1075 retval = write_dst(state, &state->tx_tuna[2], FIXED_COMM);
1049 } 1076 }
1050 if (retval < 0) { 1077 if (retval < 0) {
1051 dst_pio_disable(state); 1078 dst_pio_disable(state);
1052 dprintk("%s: write not successful\n", __FUNCTION__); 1079 dprintk(verbose, DST_DEBUG, 1, "write not successful");
1053 return retval; 1080 return retval;
1054 } 1081 }
1055
1056 if ((dst_pio_disable(state)) < 0) { 1082 if ((dst_pio_disable(state)) < 0) {
1057 dprintk("%s: DST PIO disable failed !\n", __FUNCTION__); 1083 dprintk(verbose, DST_DEBUG, 1, "DST PIO disable failed !");
1058 return -1; 1084 return -1;
1059 } 1085 }
1060
1061 if ((read_dst(state, &reply, GET_ACK) < 0)) { 1086 if ((read_dst(state, &reply, GET_ACK) < 0)) {
1062 dprintk("%s: read verify not successful.\n", __FUNCTION__); 1087 dprintk(verbose, DST_DEBUG, 1, "read verify not successful.");
1063 return -1; 1088 return -1;
1064 } 1089 }
1065 if (reply != ACK) { 1090 if (reply != ACK) {
1066 dprintk("%s: write not acknowledged 0x%02x \n", __FUNCTION__, reply); 1091 dprintk(verbose, DST_DEBUG, 1, "write not acknowledged 0x%02x ", reply);
1067 return 0; 1092 return 0;
1068 } 1093 }
1069 state->diseq_flags |= ATTEMPT_TUNE; 1094 state->diseq_flags |= ATTEMPT_TUNE;
@@ -1085,14 +1110,13 @@ static int dst_write_tuna(struct dvb_frontend* fe)
1085 * Diseqc 4 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xfc, 0xe0 1110 * Diseqc 4 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xfc, 0xe0
1086 */ 1111 */
1087 1112
1088static int dst_set_diseqc(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd) 1113static int dst_set_diseqc(struct dvb_frontend *fe, struct dvb_diseqc_master_cmd *cmd)
1089{ 1114{
1090 struct dst_state* state = fe->demodulator_priv; 1115 struct dst_state *state = fe->demodulator_priv;
1091 u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec }; 1116 u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };
1092 1117
1093 if (state->dst_type != DST_TYPE_IS_SAT) 1118 if (state->dst_type != DST_TYPE_IS_SAT)
1094 return 0; 1119 return 0;
1095
1096 if (cmd->msg_len == 0 || cmd->msg_len > 4) 1120 if (cmd->msg_len == 0 || cmd->msg_len > 4)
1097 return -EINVAL; 1121 return -EINVAL;
1098 memcpy(&paket[3], cmd->msg, cmd->msg_len); 1122 memcpy(&paket[3], cmd->msg, cmd->msg_len);
@@ -1101,65 +1125,61 @@ static int dst_set_diseqc(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd*
1101 return 0; 1125 return 0;
1102} 1126}
1103 1127
1104static int dst_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) 1128static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
1105{ 1129{
1106 int need_cmd; 1130 int need_cmd;
1107 struct dst_state* state = fe->demodulator_priv; 1131 struct dst_state *state = fe->demodulator_priv;
1108 1132
1109 state->voltage = voltage; 1133 state->voltage = voltage;
1110
1111 if (state->dst_type != DST_TYPE_IS_SAT) 1134 if (state->dst_type != DST_TYPE_IS_SAT)
1112 return 0; 1135 return 0;
1113 1136
1114 need_cmd = 0; 1137 need_cmd = 0;
1115 switch (voltage) {
1116 case SEC_VOLTAGE_13:
1117 case SEC_VOLTAGE_18:
1118 if ((state->diseq_flags & HAS_POWER) == 0)
1119 need_cmd = 1;
1120 state->diseq_flags |= HAS_POWER;
1121 state->tx_tuna[4] = 0x01;
1122 break;
1123 1138
1124 case SEC_VOLTAGE_OFF: 1139 switch (voltage) {
1140 case SEC_VOLTAGE_13:
1141 case SEC_VOLTAGE_18:
1142 if ((state->diseq_flags & HAS_POWER) == 0)
1125 need_cmd = 1; 1143 need_cmd = 1;
1126 state->diseq_flags &= ~(HAS_POWER | HAS_LOCK | ATTEMPT_TUNE); 1144 state->diseq_flags |= HAS_POWER;
1127 state->tx_tuna[4] = 0x00; 1145 state->tx_tuna[4] = 0x01;
1128 break; 1146 break;
1129 1147 case SEC_VOLTAGE_OFF:
1130 default: 1148 need_cmd = 1;
1131 return -EINVAL; 1149 state->diseq_flags &= ~(HAS_POWER | HAS_LOCK | ATTEMPT_TUNE);
1150 state->tx_tuna[4] = 0x00;
1151 break;
1152 default:
1153 return -EINVAL;
1132 } 1154 }
1155
1133 if (need_cmd) 1156 if (need_cmd)
1134 dst_tone_power_cmd(state); 1157 dst_tone_power_cmd(state);
1135 1158
1136 return 0; 1159 return 0;
1137} 1160}
1138 1161
1139static int dst_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 1162static int dst_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
1140{ 1163{
1141 struct dst_state* state = fe->demodulator_priv; 1164 struct dst_state *state = fe->demodulator_priv;
1142 1165
1143 state->tone = tone; 1166 state->tone = tone;
1144
1145 if (state->dst_type != DST_TYPE_IS_SAT) 1167 if (state->dst_type != DST_TYPE_IS_SAT)
1146 return 0; 1168 return 0;
1147 1169
1148 switch (tone) { 1170 switch (tone) {
1149 case SEC_TONE_OFF: 1171 case SEC_TONE_OFF:
1150 if (state->type_flags & DST_TYPE_HAS_OBS_REGS) 1172 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1151 state->tx_tuna[2] = 0x00; 1173 state->tx_tuna[2] = 0x00;
1152 else 1174 else
1153 state->tx_tuna[2] = 0xff; 1175 state->tx_tuna[2] = 0xff;
1154 1176 break;
1155 break;
1156
1157 case SEC_TONE_ON:
1158 state->tx_tuna[2] = 0x02;
1159 break;
1160 1177
1161 default: 1178 case SEC_TONE_ON:
1162 return -EINVAL; 1179 state->tx_tuna[2] = 0x02;
1180 break;
1181 default:
1182 return -EINVAL;
1163 } 1183 }
1164 dst_tone_power_cmd(state); 1184 dst_tone_power_cmd(state);
1165 1185
@@ -1172,16 +1192,14 @@ static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
1172 1192
1173 if (state->dst_type != DST_TYPE_IS_SAT) 1193 if (state->dst_type != DST_TYPE_IS_SAT)
1174 return 0; 1194 return 0;
1175
1176 state->minicmd = minicmd; 1195 state->minicmd = minicmd;
1177
1178 switch (minicmd) { 1196 switch (minicmd) {
1179 case SEC_MINI_A: 1197 case SEC_MINI_A:
1180 state->tx_tuna[3] = 0x02; 1198 state->tx_tuna[3] = 0x02;
1181 break; 1199 break;
1182 case SEC_MINI_B: 1200 case SEC_MINI_B:
1183 state->tx_tuna[3] = 0xff; 1201 state->tx_tuna[3] = 0xff;
1184 break; 1202 break;
1185 } 1203 }
1186 dst_tone_power_cmd(state); 1204 dst_tone_power_cmd(state);
1187 1205
@@ -1189,42 +1207,37 @@ static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
1189} 1207}
1190 1208
1191 1209
1192static int dst_init(struct dvb_frontend* fe) 1210static int dst_init(struct dvb_frontend *fe)
1193{ 1211{
1194 struct dst_state* state = fe->demodulator_priv; 1212 struct dst_state *state = fe->demodulator_priv;
1195 static u8 ini_satci_tuna[] = { 9, 0, 3, 0xb6, 1, 0, 0x73, 0x21, 0, 0 }; 1213
1196 static u8 ini_satfta_tuna[] = { 0, 0, 3, 0xb6, 1, 0x55, 0xbd, 0x50, 0, 0 }; 1214 static u8 sat_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x00, 0x73, 0x21, 0x00, 0x00 };
1197 static u8 ini_tvfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; 1215 static u8 sat_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x55, 0xbd, 0x50, 0x00, 0x00 };
1198 static u8 ini_tvci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; 1216 static u8 ter_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1199 static u8 ini_cabfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; 1217 static u8 ter_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1200 static u8 ini_cabci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; 1218 static u8 cab_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1201// state->inversion = INVERSION_ON; 1219 static u8 cab_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1220
1202 state->inversion = INVERSION_OFF; 1221 state->inversion = INVERSION_OFF;
1203 state->voltage = SEC_VOLTAGE_13; 1222 state->voltage = SEC_VOLTAGE_13;
1204 state->tone = SEC_TONE_OFF; 1223 state->tone = SEC_TONE_OFF;
1205 state->symbol_rate = 29473000;
1206 state->fec = FEC_AUTO;
1207 state->diseq_flags = 0; 1224 state->diseq_flags = 0;
1208 state->k22 = 0x02; 1225 state->k22 = 0x02;
1209 state->bandwidth = BANDWIDTH_7_MHZ; 1226 state->bandwidth = BANDWIDTH_7_MHZ;
1210 state->cur_jiff = jiffies; 1227 state->cur_jiff = jiffies;
1211 if (state->dst_type == DST_TYPE_IS_SAT) { 1228 if (state->dst_type == DST_TYPE_IS_SAT)
1212 state->frequency = 950000; 1229 memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? sat_tuna_188 : sat_tuna_204), sizeof (sat_tuna_204));
1213 memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ini_satci_tuna : ini_satfta_tuna), sizeof(ini_satfta_tuna)); 1230 else if (state->dst_type == DST_TYPE_IS_TERR)
1214 } else if (state->dst_type == DST_TYPE_IS_TERR) { 1231 memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ter_tuna_188 : ter_tuna_204), sizeof (ter_tuna_204));
1215 state->frequency = 137000000; 1232 else if (state->dst_type == DST_TYPE_IS_CABLE)
1216 memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ini_tvci_tuna : ini_tvfta_tuna), sizeof(ini_tvfta_tuna)); 1233 memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? cab_tuna_188 : cab_tuna_204), sizeof (cab_tuna_204));
1217 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
1218 state->frequency = 51000000;
1219 memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ini_cabci_tuna : ini_cabfta_tuna), sizeof(ini_cabfta_tuna));
1220 }
1221 1234
1222 return 0; 1235 return 0;
1223} 1236}
1224 1237
1225static int dst_read_status(struct dvb_frontend* fe, fe_status_t* status) 1238static int dst_read_status(struct dvb_frontend *fe, fe_status_t *status)
1226{ 1239{
1227 struct dst_state* state = fe->demodulator_priv; 1240 struct dst_state *state = fe->demodulator_priv;
1228 1241
1229 *status = 0; 1242 *status = 0;
1230 if (state->diseq_flags & HAS_LOCK) { 1243 if (state->diseq_flags & HAS_LOCK) {
@@ -1236,9 +1249,9 @@ static int dst_read_status(struct dvb_frontend* fe, fe_status_t* status)
1236 return 0; 1249 return 0;
1237} 1250}
1238 1251
1239static int dst_read_signal_strength(struct dvb_frontend* fe, u16* strength) 1252static int dst_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
1240{ 1253{
1241 struct dst_state* state = fe->demodulator_priv; 1254 struct dst_state *state = fe->demodulator_priv;
1242 1255
1243 dst_get_signal(state); 1256 dst_get_signal(state);
1244 *strength = state->decode_strength; 1257 *strength = state->decode_strength;
@@ -1246,9 +1259,9 @@ static int dst_read_signal_strength(struct dvb_frontend* fe, u16* strength)
1246 return 0; 1259 return 0;
1247} 1260}
1248 1261
1249static int dst_read_snr(struct dvb_frontend* fe, u16* snr) 1262static int dst_read_snr(struct dvb_frontend *fe, u16 *snr)
1250{ 1263{
1251 struct dst_state* state = fe->demodulator_priv; 1264 struct dst_state *state = fe->demodulator_priv;
1252 1265
1253 dst_get_signal(state); 1266 dst_get_signal(state);
1254 *snr = state->decode_snr; 1267 *snr = state->decode_snr;
@@ -1256,28 +1269,24 @@ static int dst_read_snr(struct dvb_frontend* fe, u16* snr)
1256 return 0; 1269 return 0;
1257} 1270}
1258 1271
1259static int dst_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 1272static int dst_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
1260{ 1273{
1261 struct dst_state* state = fe->demodulator_priv; 1274 struct dst_state *state = fe->demodulator_priv;
1262 1275
1263 dst_set_freq(state, p->frequency); 1276 dst_set_freq(state, p->frequency);
1264 if (verbose > 4) 1277 dprintk(verbose, DST_DEBUG, 1, "Set Frequency=[%d]", p->frequency);
1265 dprintk("Set Frequency=[%d]\n", p->frequency);
1266 1278
1267// dst_set_inversion(state, p->inversion);
1268 if (state->dst_type == DST_TYPE_IS_SAT) { 1279 if (state->dst_type == DST_TYPE_IS_SAT) {
1269 if (state->type_flags & DST_TYPE_HAS_OBS_REGS) 1280 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1270 dst_set_inversion(state, p->inversion); 1281 dst_set_inversion(state, p->inversion);
1271
1272 dst_set_fec(state, p->u.qpsk.fec_inner); 1282 dst_set_fec(state, p->u.qpsk.fec_inner);
1273 dst_set_symbolrate(state, p->u.qpsk.symbol_rate); 1283 dst_set_symbolrate(state, p->u.qpsk.symbol_rate);
1274 dst_set_polarization(state); 1284 dst_set_polarization(state);
1275 if (verbose > 4) 1285 dprintk(verbose, DST_DEBUG, 1, "Set Symbolrate=[%d]", p->u.qpsk.symbol_rate);
1276 dprintk("Set Symbolrate=[%d]\n", p->u.qpsk.symbol_rate);
1277 1286
1278 } else if (state->dst_type == DST_TYPE_IS_TERR) { 1287 } else if (state->dst_type == DST_TYPE_IS_TERR)
1279 dst_set_bandwidth(state, p->u.ofdm.bandwidth); 1288 dst_set_bandwidth(state, p->u.ofdm.bandwidth);
1280 } else if (state->dst_type == DST_TYPE_IS_CABLE) { 1289 else if (state->dst_type == DST_TYPE_IS_CABLE) {
1281 dst_set_fec(state, p->u.qam.fec_inner); 1290 dst_set_fec(state, p->u.qam.fec_inner);
1282 dst_set_symbolrate(state, p->u.qam.symbol_rate); 1291 dst_set_symbolrate(state, p->u.qam.symbol_rate);
1283 dst_set_modulation(state, p->u.qam.modulation); 1292 dst_set_modulation(state, p->u.qam.modulation);
@@ -1287,16 +1296,14 @@ static int dst_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_paramet
1287 return 0; 1296 return 0;
1288} 1297}
1289 1298
1290static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 1299static int dst_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
1291{ 1300{
1292 struct dst_state* state = fe->demodulator_priv; 1301 struct dst_state *state = fe->demodulator_priv;
1293 1302
1294 p->frequency = state->decode_freq; 1303 p->frequency = state->decode_freq;
1295// p->inversion = state->inversion;
1296 if (state->dst_type == DST_TYPE_IS_SAT) { 1304 if (state->dst_type == DST_TYPE_IS_SAT) {
1297 if (state->type_flags & DST_TYPE_HAS_OBS_REGS) 1305 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1298 p->inversion = state->inversion; 1306 p->inversion = state->inversion;
1299
1300 p->u.qpsk.symbol_rate = state->symbol_rate; 1307 p->u.qpsk.symbol_rate = state->symbol_rate;
1301 p->u.qpsk.fec_inner = dst_get_fec(state); 1308 p->u.qpsk.fec_inner = dst_get_fec(state);
1302 } else if (state->dst_type == DST_TYPE_IS_TERR) { 1309 } else if (state->dst_type == DST_TYPE_IS_TERR) {
@@ -1304,16 +1311,15 @@ static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_paramet
1304 } else if (state->dst_type == DST_TYPE_IS_CABLE) { 1311 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
1305 p->u.qam.symbol_rate = state->symbol_rate; 1312 p->u.qam.symbol_rate = state->symbol_rate;
1306 p->u.qam.fec_inner = dst_get_fec(state); 1313 p->u.qam.fec_inner = dst_get_fec(state);
1307// p->u.qam.modulation = QAM_AUTO;
1308 p->u.qam.modulation = dst_get_modulation(state); 1314 p->u.qam.modulation = dst_get_modulation(state);
1309 } 1315 }
1310 1316
1311 return 0; 1317 return 0;
1312} 1318}
1313 1319
1314static void dst_release(struct dvb_frontend* fe) 1320static void dst_release(struct dvb_frontend *fe)
1315{ 1321{
1316 struct dst_state* state = fe->demodulator_priv; 1322 struct dst_state *state = fe->demodulator_priv;
1317 kfree(state); 1323 kfree(state);
1318} 1324}
1319 1325
@@ -1321,9 +1327,8 @@ static struct dvb_frontend_ops dst_dvbt_ops;
1321static struct dvb_frontend_ops dst_dvbs_ops; 1327static struct dvb_frontend_ops dst_dvbs_ops;
1322static struct dvb_frontend_ops dst_dvbc_ops; 1328static struct dvb_frontend_ops dst_dvbc_ops;
1323 1329
1324struct dst_state* dst_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter) 1330struct dst_state *dst_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter)
1325{ 1331{
1326
1327 /* check if the ASIC is there */ 1332 /* check if the ASIC is there */
1328 if (dst_probe(state) < 0) { 1333 if (dst_probe(state) < 0) {
1329 if (state) 1334 if (state)
@@ -1336,17 +1341,14 @@ struct dst_state* dst_attach(struct dst_state *state, struct dvb_adapter *dvb_ad
1336 case DST_TYPE_IS_TERR: 1341 case DST_TYPE_IS_TERR:
1337 memcpy(&state->ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops)); 1342 memcpy(&state->ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops));
1338 break; 1343 break;
1339
1340 case DST_TYPE_IS_CABLE: 1344 case DST_TYPE_IS_CABLE:
1341 memcpy(&state->ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops)); 1345 memcpy(&state->ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops));
1342 break; 1346 break;
1343
1344 case DST_TYPE_IS_SAT: 1347 case DST_TYPE_IS_SAT:
1345 memcpy(&state->ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops)); 1348 memcpy(&state->ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops));
1346 break; 1349 break;
1347
1348 default: 1350 default:
1349 printk("%s: unknown DST type. please report to the LinuxTV.org DVB mailinglist.\n", __FUNCTION__); 1351 dprintk(verbose, DST_ERROR, 1, "unknown DST type. please report to the LinuxTV.org DVB mailinglist.");
1350 if (state) 1352 if (state)
1351 kfree(state); 1353 kfree(state);
1352 1354
@@ -1374,12 +1376,9 @@ static struct dvb_frontend_ops dst_dvbt_ops = {
1374 }, 1376 },
1375 1377
1376 .release = dst_release, 1378 .release = dst_release,
1377
1378 .init = dst_init, 1379 .init = dst_init,
1379
1380 .set_frontend = dst_set_frontend, 1380 .set_frontend = dst_set_frontend,
1381 .get_frontend = dst_get_frontend, 1381 .get_frontend = dst_get_frontend,
1382
1383 .read_status = dst_read_status, 1382 .read_status = dst_read_status,
1384 .read_signal_strength = dst_read_signal_strength, 1383 .read_signal_strength = dst_read_signal_strength,
1385 .read_snr = dst_read_snr, 1384 .read_snr = dst_read_snr,
@@ -1401,16 +1400,12 @@ static struct dvb_frontend_ops dst_dvbs_ops = {
1401 }, 1400 },
1402 1401
1403 .release = dst_release, 1402 .release = dst_release,
1404
1405 .init = dst_init, 1403 .init = dst_init,
1406
1407 .set_frontend = dst_set_frontend, 1404 .set_frontend = dst_set_frontend,
1408 .get_frontend = dst_get_frontend, 1405 .get_frontend = dst_get_frontend,
1409
1410 .read_status = dst_read_status, 1406 .read_status = dst_read_status,
1411 .read_signal_strength = dst_read_signal_strength, 1407 .read_signal_strength = dst_read_signal_strength,
1412 .read_snr = dst_read_snr, 1408 .read_snr = dst_read_snr,
1413
1414 .diseqc_send_burst = dst_send_burst, 1409 .diseqc_send_burst = dst_send_burst,
1415 .diseqc_send_master_cmd = dst_set_diseqc, 1410 .diseqc_send_master_cmd = dst_set_diseqc,
1416 .set_voltage = dst_set_voltage, 1411 .set_voltage = dst_set_voltage,
@@ -1432,18 +1427,14 @@ static struct dvb_frontend_ops dst_dvbc_ops = {
1432 }, 1427 },
1433 1428
1434 .release = dst_release, 1429 .release = dst_release,
1435
1436 .init = dst_init, 1430 .init = dst_init,
1437
1438 .set_frontend = dst_set_frontend, 1431 .set_frontend = dst_set_frontend,
1439 .get_frontend = dst_get_frontend, 1432 .get_frontend = dst_get_frontend,
1440
1441 .read_status = dst_read_status, 1433 .read_status = dst_read_status,
1442 .read_signal_strength = dst_read_signal_strength, 1434 .read_signal_strength = dst_read_signal_strength,
1443 .read_snr = dst_read_snr, 1435 .read_snr = dst_read_snr,
1444}; 1436};
1445 1437
1446
1447MODULE_DESCRIPTION("DST DVB-S/T/C Combo Frontend driver"); 1438MODULE_DESCRIPTION("DST DVB-S/T/C Combo Frontend driver");
1448MODULE_AUTHOR("Jamie Honan, Manu Abraham"); 1439MODULE_AUTHOR("Jamie Honan, Manu Abraham");
1449MODULE_LICENSE("GPL"); 1440MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/bt8xx/dst_ca.c b/drivers/media/dvb/bt8xx/dst_ca.c
index bfaacd5fc2..6776a59204 100644
--- a/drivers/media/dvb/bt8xx/dst_ca.c
+++ b/drivers/media/dvb/bt8xx/dst_ca.c
@@ -18,30 +18,42 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21
22
23#include <linux/kernel.h> 21#include <linux/kernel.h>
24#include <linux/module.h> 22#include <linux/module.h>
25#include <linux/init.h> 23#include <linux/init.h>
26#include <linux/string.h> 24#include <linux/string.h>
27
28#include <linux/dvb/ca.h> 25#include <linux/dvb/ca.h>
29#include "dvbdev.h" 26#include "dvbdev.h"
30#include "dvb_frontend.h" 27#include "dvb_frontend.h"
31
32#include "dst_ca.h" 28#include "dst_ca.h"
33#include "dst_common.h" 29#include "dst_common.h"
34 30
31#define DST_CA_ERROR 0
32#define DST_CA_NOTICE 1
33#define DST_CA_INFO 2
34#define DST_CA_DEBUG 3
35
36#define dprintk(x, y, z, format, arg...) do { \
37 if (z) { \
38 if ((x > DST_CA_ERROR) && (x > y)) \
39 printk(KERN_ERR "%s: " format "\n", __FUNCTION__ , ##arg); \
40 else if ((x > DST_CA_NOTICE) && (x > y)) \
41 printk(KERN_NOTICE "%s: " format "\n", __FUNCTION__ , ##arg); \
42 else if ((x > DST_CA_INFO) && (x > y)) \
43 printk(KERN_INFO "%s: " format "\n", __FUNCTION__ , ##arg); \
44 else if ((x > DST_CA_DEBUG) && (x > y)) \
45 printk(KERN_DEBUG "%s: " format "\n", __FUNCTION__ , ##arg); \
46 } else { \
47 if (x > y) \
48 printk(format, ## arg); \
49 } \
50} while(0)
51
52
35static unsigned int verbose = 5; 53static unsigned int verbose = 5;
36module_param(verbose, int, 0644); 54module_param(verbose, int, 0644);
37MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)"); 55MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
38 56
39static unsigned int debug = 1;
40module_param(debug, int, 0644);
41MODULE_PARM_DESC(debug, "debug messages, default is 1 (yes)");
42
43#define dprintk if (debug) printk
44
45/* Need some more work */ 57/* Need some more work */
46static int ca_set_slot_descr(void) 58static int ca_set_slot_descr(void)
47{ 59{
@@ -61,27 +73,20 @@ static int put_checksum(u8 *check_string, int length)
61{ 73{
62 u8 i = 0, checksum = 0; 74 u8 i = 0, checksum = 0;
63 75
64 if (verbose > 3) { 76 dprintk(verbose, DST_CA_DEBUG, 1, " ========================= Checksum calculation ===========================");
65 dprintk("%s: ========================= Checksum calculation ===========================\n", __FUNCTION__); 77 dprintk(verbose, DST_CA_DEBUG, 1, " String Length=[0x%02x]", length);
66 dprintk("%s: String Length=[0x%02x]\n", __FUNCTION__, length); 78 dprintk(verbose, DST_CA_DEBUG, 1, " String=[");
67 79
68 dprintk("%s: String=[", __FUNCTION__);
69 }
70 while (i < length) { 80 while (i < length) {
71 if (verbose > 3) 81 dprintk(verbose, DST_CA_DEBUG, 0, " %02x", check_string[i]);
72 dprintk(" %02x", check_string[i]);
73 checksum += check_string[i]; 82 checksum += check_string[i];
74 i++; 83 i++;
75 } 84 }
76 if (verbose > 3) { 85 dprintk(verbose, DST_CA_DEBUG, 0, " ]\n");
77 dprintk(" ]\n"); 86 dprintk(verbose, DST_CA_DEBUG, 1, "Sum=[%02x]\n", checksum);
78 dprintk("%s: Sum=[%02x]\n", __FUNCTION__, checksum);
79 }
80 check_string[length] = ~checksum + 1; 87 check_string[length] = ~checksum + 1;
81 if (verbose > 3) { 88 dprintk(verbose, DST_CA_DEBUG, 1, " Checksum=[%02x]", check_string[length]);
82 dprintk("%s: Checksum=[%02x]\n", __FUNCTION__, check_string[length]); 89 dprintk(verbose, DST_CA_DEBUG, 1, " ==========================================================================");
83 dprintk("%s: ==========================================================================\n", __FUNCTION__);
84 }
85 90
86 return 0; 91 return 0;
87} 92}
@@ -94,30 +99,26 @@ static int dst_ci_command(struct dst_state* state, u8 * data, u8 *ca_string, u8
94 msleep(65); 99 msleep(65);
95 100
96 if (write_dst(state, data, len)) { 101 if (write_dst(state, data, len)) {
97 dprintk("%s: Write not successful, trying to recover\n", __FUNCTION__); 102 dprintk(verbose, DST_CA_INFO, 1, " Write not successful, trying to recover");
98 dst_error_recovery(state); 103 dst_error_recovery(state);
99 return -1; 104 return -1;
100 } 105 }
101
102 if ((dst_pio_disable(state)) < 0) { 106 if ((dst_pio_disable(state)) < 0) {
103 dprintk("%s: DST PIO disable failed.\n", __FUNCTION__); 107 dprintk(verbose, DST_CA_ERROR, 1, " DST PIO disable failed.");
104 return -1; 108 return -1;
105 } 109 }
106
107 if (read_dst(state, &reply, GET_ACK) < 0) { 110 if (read_dst(state, &reply, GET_ACK) < 0) {
108 dprintk("%s: Read not successful, trying to recover\n", __FUNCTION__); 111 dprintk(verbose, DST_CA_INFO, 1, " Read not successful, trying to recover");
109 dst_error_recovery(state); 112 dst_error_recovery(state);
110 return -1; 113 return -1;
111 } 114 }
112
113 if (read) { 115 if (read) {
114 if (! dst_wait_dst_ready(state, LONG_DELAY)) { 116 if (! dst_wait_dst_ready(state, LONG_DELAY)) {
115 dprintk("%s: 8820 not ready\n", __FUNCTION__); 117 dprintk(verbose, DST_CA_NOTICE, 1, " 8820 not ready");
116 return -1; 118 return -1;
117 } 119 }
118
119 if (read_dst(state, ca_string, 128) < 0) { /* Try to make this dynamic */ 120 if (read_dst(state, ca_string, 128) < 0) { /* Try to make this dynamic */
120 dprintk("%s: Read not successful, trying to recover\n", __FUNCTION__); 121 dprintk(verbose, DST_CA_INFO, 1, " Read not successful, trying to recover");
121 dst_error_recovery(state); 122 dst_error_recovery(state);
122 return -1; 123 return -1;
123 } 124 }
@@ -133,8 +134,7 @@ static int dst_put_ci(struct dst_state *state, u8 *data, int len, u8 *ca_string,
133 134
134 while (dst_ca_comm_err < RETRIES) { 135 while (dst_ca_comm_err < RETRIES) {
135 dst_comm_init(state); 136 dst_comm_init(state);
136 if (verbose > 2) 137 dprintk(verbose, DST_CA_NOTICE, 1, " Put Command");
137 dprintk("%s: Put Command\n", __FUNCTION__);
138 if (dst_ci_command(state, data, ca_string, len, read)) { // If error 138 if (dst_ci_command(state, data, ca_string, len, read)) { // If error
139 dst_error_recovery(state); 139 dst_error_recovery(state);
140 dst_ca_comm_err++; // work required here. 140 dst_ca_comm_err++; // work required here.
@@ -153,18 +153,15 @@ static int ca_get_app_info(struct dst_state *state)
153 153
154 put_checksum(&command[0], command[0]); 154 put_checksum(&command[0], command[0]);
155 if ((dst_put_ci(state, command, sizeof(command), state->messages, GET_REPLY)) < 0) { 155 if ((dst_put_ci(state, command, sizeof(command), state->messages, GET_REPLY)) < 0) {
156 dprintk("%s: -->dst_put_ci FAILED !\n", __FUNCTION__); 156 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
157 return -1; 157 return -1;
158 } 158 }
159 if (verbose > 1) { 159 dprintk(verbose, DST_CA_INFO, 1, " -->dst_put_ci SUCCESS !");
160 dprintk("%s: -->dst_put_ci SUCCESS !\n", __FUNCTION__); 160 dprintk(verbose, DST_CA_INFO, 1, " ================================ CI Module Application Info ======================================");
161 161 dprintk(verbose, DST_CA_INFO, 1, " Application Type=[%d], Application Vendor=[%d], Vendor Code=[%d]\n%s: Application info=[%s]",
162 dprintk("%s: ================================ CI Module Application Info ======================================\n", __FUNCTION__); 162 state->messages[7], (state->messages[8] << 8) | state->messages[9],
163 dprintk("%s: Application Type=[%d], Application Vendor=[%d], Vendor Code=[%d]\n%s: Application info=[%s]\n", 163 (state->messages[10] << 8) | state->messages[11], __FUNCTION__, (char *)(&state->messages[12]));
164 __FUNCTION__, state->messages[7], (state->messages[8] << 8) | state->messages[9], 164 dprintk(verbose, DST_CA_INFO, 1, " ==================================================================================================");
165 (state->messages[10] << 8) | state->messages[11], __FUNCTION__, (char *)(&state->messages[12]));
166 dprintk("%s: ==================================================================================================\n", __FUNCTION__);
167 }
168 165
169 return 0; 166 return 0;
170} 167}
@@ -177,31 +174,26 @@ static int ca_get_slot_caps(struct dst_state *state, struct ca_caps *p_ca_caps,
177 174
178 put_checksum(&slot_command[0], slot_command[0]); 175 put_checksum(&slot_command[0], slot_command[0]);
179 if ((dst_put_ci(state, slot_command, sizeof (slot_command), slot_cap, GET_REPLY)) < 0) { 176 if ((dst_put_ci(state, slot_command, sizeof (slot_command), slot_cap, GET_REPLY)) < 0) {
180 dprintk("%s: -->dst_put_ci FAILED !\n", __FUNCTION__); 177 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
181 return -1; 178 return -1;
182 } 179 }
183 if (verbose > 1) 180 dprintk(verbose, DST_CA_NOTICE, 1, " -->dst_put_ci SUCCESS !");
184 dprintk("%s: -->dst_put_ci SUCCESS !\n", __FUNCTION__);
185 181
186 /* Will implement the rest soon */ 182 /* Will implement the rest soon */
187 183
188 if (verbose > 1) { 184 dprintk(verbose, DST_CA_INFO, 1, " Slot cap = [%d]", slot_cap[7]);
189 dprintk("%s: Slot cap = [%d]\n", __FUNCTION__, slot_cap[7]); 185 dprintk(verbose, DST_CA_INFO, 0, "===================================\n");
190 dprintk("===================================\n"); 186 for (i = 0; i < 8; i++)
191 for (i = 0; i < 8; i++) 187 dprintk(verbose, DST_CA_INFO, 0, " %d", slot_cap[i]);
192 dprintk(" %d", slot_cap[i]); 188 dprintk(verbose, DST_CA_INFO, 0, "\n");
193 dprintk("\n");
194 }
195 189
196 p_ca_caps->slot_num = 1; 190 p_ca_caps->slot_num = 1;
197 p_ca_caps->slot_type = 1; 191 p_ca_caps->slot_type = 1;
198 p_ca_caps->descr_num = slot_cap[7]; 192 p_ca_caps->descr_num = slot_cap[7];
199 p_ca_caps->descr_type = 1; 193 p_ca_caps->descr_type = 1;
200 194
201 195 if (copy_to_user((struct ca_caps *)arg, p_ca_caps, sizeof (struct ca_caps)))
202 if (copy_to_user((struct ca_caps *)arg, p_ca_caps, sizeof (struct ca_caps))) {
203 return -EFAULT; 196 return -EFAULT;
204 }
205 197
206 return 0; 198 return 0;
207} 199}
@@ -222,46 +214,37 @@ static int ca_get_slot_info(struct dst_state *state, struct ca_slot_info *p_ca_s
222 214
223 put_checksum(&slot_command[0], 7); 215 put_checksum(&slot_command[0], 7);
224 if ((dst_put_ci(state, slot_command, sizeof (slot_command), slot_info, GET_REPLY)) < 0) { 216 if ((dst_put_ci(state, slot_command, sizeof (slot_command), slot_info, GET_REPLY)) < 0) {
225 dprintk("%s: -->dst_put_ci FAILED !\n", __FUNCTION__); 217 dprintk(verbose, DST_CA_ERROR, 1, " -->dst_put_ci FAILED !");
226 return -1; 218 return -1;
227 } 219 }
228 if (verbose > 1) 220 dprintk(verbose, DST_CA_INFO, 1, " -->dst_put_ci SUCCESS !");
229 dprintk("%s: -->dst_put_ci SUCCESS !\n", __FUNCTION__);
230 221
231 /* Will implement the rest soon */ 222 /* Will implement the rest soon */
232 223
233 if (verbose > 1) { 224 dprintk(verbose, DST_CA_INFO, 1, " Slot info = [%d]", slot_info[3]);
234 dprintk("%s: Slot info = [%d]\n", __FUNCTION__, slot_info[3]); 225 dprintk(verbose, DST_CA_INFO, 0, "===================================\n");
235 dprintk("===================================\n"); 226 for (i = 0; i < 8; i++)
236 for (i = 0; i < 8; i++) 227 dprintk(verbose, DST_CA_INFO, 0, " %d", slot_info[i]);
237 dprintk(" %d", slot_info[i]); 228 dprintk(verbose, DST_CA_INFO, 0, "\n");
238 dprintk("\n");
239 }
240 229
241 if (slot_info[4] & 0x80) { 230 if (slot_info[4] & 0x80) {
242 p_ca_slot_info->flags = CA_CI_MODULE_PRESENT; 231 p_ca_slot_info->flags = CA_CI_MODULE_PRESENT;
243 p_ca_slot_info->num = 1; 232 p_ca_slot_info->num = 1;
244 p_ca_slot_info->type = CA_CI; 233 p_ca_slot_info->type = CA_CI;
245 } 234 } else if (slot_info[4] & 0x40) {
246 else if (slot_info[4] & 0x40) {
247 p_ca_slot_info->flags = CA_CI_MODULE_READY; 235 p_ca_slot_info->flags = CA_CI_MODULE_READY;
248 p_ca_slot_info->num = 1; 236 p_ca_slot_info->num = 1;
249 p_ca_slot_info->type = CA_CI; 237 p_ca_slot_info->type = CA_CI;
250 } 238 } else
251 else {
252 p_ca_slot_info->flags = 0; 239 p_ca_slot_info->flags = 0;
253 }
254 240
255 if (copy_to_user((struct ca_slot_info *)arg, p_ca_slot_info, sizeof (struct ca_slot_info))) { 241 if (copy_to_user((struct ca_slot_info *)arg, p_ca_slot_info, sizeof (struct ca_slot_info)))
256 return -EFAULT; 242 return -EFAULT;
257 }
258 243
259 return 0; 244 return 0;
260} 245}
261 246
262 247
263
264
265static int ca_get_message(struct dst_state *state, struct ca_msg *p_ca_message, void *arg) 248static int ca_get_message(struct dst_state *state, struct ca_msg *p_ca_message, void *arg)
266{ 249{
267 u8 i = 0; 250 u8 i = 0;
@@ -270,24 +253,21 @@ static int ca_get_message(struct dst_state *state, struct ca_msg *p_ca_message,
270 if (copy_from_user(p_ca_message, (void *)arg, sizeof (struct ca_msg))) 253 if (copy_from_user(p_ca_message, (void *)arg, sizeof (struct ca_msg)))
271 return -EFAULT; 254 return -EFAULT;
272 255
273
274 if (p_ca_message->msg) { 256 if (p_ca_message->msg) {
275 if (verbose > 3) 257 dprintk(verbose, DST_CA_NOTICE, 1, " Message = [%02x %02x %02x]", p_ca_message->msg[0], p_ca_message->msg[1], p_ca_message->msg[2]);
276 dprintk("Message = [%02x %02x %02x]\n", p_ca_message->msg[0], p_ca_message->msg[1], p_ca_message->msg[2]);
277 258
278 for (i = 0; i < 3; i++) { 259 for (i = 0; i < 3; i++) {
279 command = command | p_ca_message->msg[i]; 260 command = command | p_ca_message->msg[i];
280 if (i < 2) 261 if (i < 2)
281 command = command << 8; 262 command = command << 8;
282 } 263 }
283 if (verbose > 3) 264 dprintk(verbose, DST_CA_NOTICE, 1, " Command=[0x%x]", command);
284 dprintk("%s:Command=[0x%x]\n", __FUNCTION__, command);
285 265
286 switch (command) { 266 switch (command) {
287 case CA_APP_INFO: 267 case CA_APP_INFO:
288 memcpy(p_ca_message->msg, state->messages, 128); 268 memcpy(p_ca_message->msg, state->messages, 128);
289 if (copy_to_user((void *)arg, p_ca_message, sizeof (struct ca_msg)) ) 269 if (copy_to_user((void *)arg, p_ca_message, sizeof (struct ca_msg)) )
290 return -EFAULT; 270 return -EFAULT;
291 break; 271 break;
292 } 272 }
293 } 273 }
@@ -298,10 +278,13 @@ static int ca_get_message(struct dst_state *state, struct ca_msg *p_ca_message,
298static int handle_dst_tag(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u32 length) 278static int handle_dst_tag(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u32 length)
299{ 279{
300 if (state->dst_hw_cap & DST_TYPE_HAS_SESSION) { 280 if (state->dst_hw_cap & DST_TYPE_HAS_SESSION) {
301 hw_buffer->msg[2] = p_ca_message->msg[1]; /* MSB */ 281 hw_buffer->msg[2] = p_ca_message->msg[1]; /* MSB */
302 hw_buffer->msg[3] = p_ca_message->msg[2]; /* LSB */ 282 hw_buffer->msg[3] = p_ca_message->msg[2]; /* LSB */
303 } 283 } else {
304 else { 284 if (length > 247) {
285 dprintk(verbose, DST_CA_ERROR, 1, " Message too long ! *** Bailing Out *** !");
286 return -1;
287 }
305 hw_buffer->msg[0] = (length & 0xff) + 7; 288 hw_buffer->msg[0] = (length & 0xff) + 7;
306 hw_buffer->msg[1] = 0x40; 289 hw_buffer->msg[1] = 0x40;
307 hw_buffer->msg[2] = 0x03; 290 hw_buffer->msg[2] = 0x03;
@@ -309,6 +292,11 @@ static int handle_dst_tag(struct dst_state *state, struct ca_msg *p_ca_message,
309 hw_buffer->msg[4] = 0x03; 292 hw_buffer->msg[4] = 0x03;
310 hw_buffer->msg[5] = length & 0xff; 293 hw_buffer->msg[5] = length & 0xff;
311 hw_buffer->msg[6] = 0x00; 294 hw_buffer->msg[6] = 0x00;
295 /*
296 * Need to compute length for EN50221 section 8.3.2, for the time being
297 * assuming 8.3.2 is not applicable
298 */
299 memcpy(&hw_buffer->msg[7], &p_ca_message->msg[4], length);
312 } 300 }
313 return 0; 301 return 0;
314} 302}
@@ -317,13 +305,12 @@ static int handle_dst_tag(struct dst_state *state, struct ca_msg *p_ca_message,
317static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 length, u8 reply) 305static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 length, u8 reply)
318{ 306{
319 if ((dst_put_ci(state, hw_buffer->msg, length, hw_buffer->msg, reply)) < 0) { 307 if ((dst_put_ci(state, hw_buffer->msg, length, hw_buffer->msg, reply)) < 0) {
320 dprintk("%s: DST-CI Command failed.\n", __FUNCTION__); 308 dprintk(verbose, DST_CA_ERROR, 1, " DST-CI Command failed.");
321 dprintk("%s: Resetting DST.\n", __FUNCTION__); 309 dprintk(verbose, DST_CA_NOTICE, 1, " Resetting DST.");
322 rdc_reset_state(state); 310 rdc_reset_state(state);
323 return -1; 311 return -1;
324 } 312 }
325 if (verbose > 2) 313 dprintk(verbose, DST_CA_NOTICE, 1, " DST-CI Command succes.");
326 dprintk("%s: DST-CI Command succes.\n", __FUNCTION__);
327 314
328 return 0; 315 return 0;
329} 316}
@@ -334,130 +321,47 @@ u32 asn_1_decode(u8 *asn_1_array)
334 u32 length = 0; 321 u32 length = 0;
335 322
336 length_field = asn_1_array[0]; 323 length_field = asn_1_array[0];
337 dprintk("%s: Length field=[%02x]\n", __FUNCTION__, length_field); 324 dprintk(verbose, DST_CA_DEBUG, 1, " Length field=[%02x]", length_field);
338 if (length_field < 0x80) { 325 if (length_field < 0x80) {
339 length = length_field & 0x7f; 326 length = length_field & 0x7f;
340 dprintk("%s: Length=[%02x]\n", __FUNCTION__, length); 327 dprintk(verbose, DST_CA_DEBUG, 1, " Length=[%02x]\n", length);
341 } else { 328 } else {
342 word_count = length_field & 0x7f; 329 word_count = length_field & 0x7f;
343 for (count = 0; count < word_count; count++) { 330 for (count = 0; count < word_count; count++) {
344 length = (length | asn_1_array[count + 1]) << 8; 331 length = (length | asn_1_array[count + 1]) << 8;
345 dprintk("%s: Length=[%04x]\n", __FUNCTION__, length); 332 dprintk(verbose, DST_CA_DEBUG, 1, " Length=[%04x]", length);
346 } 333 }
347 } 334 }
348 return length; 335 return length;
349} 336}
350 337
351static int init_buffer(u8 *buffer, u32 length)
352{
353 u32 i;
354 for (i = 0; i < length; i++)
355 buffer[i] = 0;
356
357 return 0;
358}
359
360static int debug_string(u8 *msg, u32 length, u32 offset) 338static int debug_string(u8 *msg, u32 length, u32 offset)
361{ 339{
362 u32 i; 340 u32 i;
363 341
364 dprintk(" String=[ "); 342 dprintk(verbose, DST_CA_DEBUG, 0, " String=[ ");
365 for (i = offset; i < length; i++) 343 for (i = offset; i < length; i++)
366 dprintk("%02x ", msg[i]); 344 dprintk(verbose, DST_CA_DEBUG, 0, "%02x ", msg[i]);
367 dprintk("]\n"); 345 dprintk(verbose, DST_CA_DEBUG, 0, "]\n");
368
369 return 0;
370}
371
372static int copy_string(u8 *destination, u8 *source, u32 dest_offset, u32 source_offset, u32 length)
373{
374 u32 i;
375 dprintk("%s: Copying [", __FUNCTION__);
376 for (i = 0; i < length; i++) {
377 destination[i + dest_offset] = source[i + source_offset];
378 dprintk(" %02x", source[i + source_offset]);
379 }
380 dprintk("]\n");
381
382 return i;
383}
384
385static int modify_4_bits(u8 *message, u32 pos)
386{
387 message[pos] &= 0x0f;
388 346
389 return 0; 347 return 0;
390} 348}
391 349
392
393
394static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query) 350static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query)
395{ 351{
396 u32 length = 0, count = 0; 352 u32 length = 0;
397 u8 asn_1_words, program_header_length; 353 u8 tag_length = 8;
398 u16 program_info_length = 0, es_info_length = 0;
399 u32 hw_offset = 0, buf_offset = 0, i;
400 u8 dst_tag_length;
401 354
402 length = asn_1_decode(&p_ca_message->msg[3]); 355 length = asn_1_decode(&p_ca_message->msg[3]);
403 dprintk("%s: CA Message length=[%d]\n", __FUNCTION__, length); 356 dprintk(verbose, DST_CA_DEBUG, 1, " CA Message length=[%d]", length);
404 dprintk("%s: ASN.1 ", __FUNCTION__); 357 debug_string(&p_ca_message->msg[4], length, 0); /* length is excluding tag & length */
405 debug_string(&p_ca_message->msg[4], length, 0); // length does not include tag and length
406 358
407 init_buffer(hw_buffer->msg, length); 359 memset(hw_buffer->msg, '\0', length);
408 handle_dst_tag(state, p_ca_message, hw_buffer, length); 360 handle_dst_tag(state, p_ca_message, hw_buffer, length);
361 put_checksum(hw_buffer->msg, hw_buffer->msg[0]);
409 362
410 hw_offset = 7; 363 debug_string(hw_buffer->msg, (length + tag_length), 0); /* tags too */
411 asn_1_words = 1; // just a hack to test, should compute this one 364 write_to_8820(state, hw_buffer, (length + tag_length), reply);
412 buf_offset = 3;
413 program_header_length = 6;
414 dst_tag_length = 7;
415
416// debug_twinhan_ca_params(state, p_ca_message, hw_buffer, reply, query, length, hw_offset, buf_offset);
417// dprintk("%s: Program Header(BUF)", __FUNCTION__);
418// debug_string(&p_ca_message->msg[4], program_header_length, 0);
419// dprintk("%s: Copying Program header\n", __FUNCTION__);
420 copy_string(hw_buffer->msg, p_ca_message->msg, hw_offset, (buf_offset + asn_1_words), program_header_length);
421 buf_offset += program_header_length, hw_offset += program_header_length;
422 modify_4_bits(hw_buffer->msg, (hw_offset - 2));
423 if (state->type_flags & DST_TYPE_HAS_INC_COUNT) { // workaround
424 dprintk("%s: Probably an ASIC bug !!!\n", __FUNCTION__);
425 debug_string(hw_buffer->msg, (hw_offset + program_header_length), 0);
426 hw_buffer->msg[hw_offset - 1] += 1;
427 }
428
429// dprintk("%s: Program Header(HW), Count=[%d]", __FUNCTION__, count);
430// debug_string(hw_buffer->msg, hw_offset, 0);
431
432 program_info_length = ((program_info_length | (p_ca_message->msg[buf_offset - 1] & 0x0f)) << 8) | p_ca_message->msg[buf_offset];
433 dprintk("%s: Program info length=[%02x]\n", __FUNCTION__, program_info_length);
434 if (program_info_length) {
435 count = copy_string(hw_buffer->msg, p_ca_message->msg, hw_offset, (buf_offset + 1), (program_info_length + 1) ); // copy next elem, not current
436 buf_offset += count, hw_offset += count;
437// dprintk("%s: Program level ", __FUNCTION__);
438// debug_string(hw_buffer->msg, hw_offset, 0);
439 }
440
441 buf_offset += 1;// hw_offset += 1;
442 for (i = buf_offset; i < length; i++) {
443// dprintk("%s: Stream Header ", __FUNCTION__);
444 count = copy_string(hw_buffer->msg, p_ca_message->msg, hw_offset, buf_offset, 5);
445 modify_4_bits(hw_buffer->msg, (hw_offset + 3));
446
447 hw_offset += 5, buf_offset += 5, i += 4;
448// debug_string(hw_buffer->msg, hw_offset, (hw_offset - 5));
449 es_info_length = ((es_info_length | (p_ca_message->msg[buf_offset - 1] & 0x0f)) << 8) | p_ca_message->msg[buf_offset];
450 dprintk("%s: ES info length=[%02x]\n", __FUNCTION__, es_info_length);
451 if (es_info_length) {
452 // copy descriptors @ STREAM level
453 dprintk("%s: Descriptors @ STREAM level...!!! \n", __FUNCTION__);
454 }
455
456 }
457 hw_buffer->msg[length + dst_tag_length] = dst_check_sum(hw_buffer->msg, (length + dst_tag_length));
458// dprintk("%s: Total length=[%d], Checksum=[%02x]\n", __FUNCTION__, (length + dst_tag_length), hw_buffer->msg[length + dst_tag_length]);
459 debug_string(hw_buffer->msg, (length + dst_tag_length + 1), 0); // dst tags also
460 write_to_8820(state, hw_buffer, (length + dst_tag_length + 1), reply); // checksum
461 365
462 return 0; 366 return 0;
463} 367}
@@ -471,26 +375,24 @@ static int dst_check_ca_pmt(struct dst_state *state, struct ca_msg *p_ca_message
471 /* Do test board */ 375 /* Do test board */
472 /* Not there yet but soon */ 376 /* Not there yet but soon */
473 377
474
475 /* CA PMT Reply capable */ 378 /* CA PMT Reply capable */
476 if (ca_pmt_reply_test) { 379 if (ca_pmt_reply_test) {
477 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 1, GET_REPLY)) < 0) { 380 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 1, GET_REPLY)) < 0) {
478 dprintk("%s: ca_set_pmt.. failed !\n", __FUNCTION__); 381 dprintk(verbose, DST_CA_ERROR, 1, " ca_set_pmt.. failed !");
479 return -1; 382 return -1;
480 } 383 }
481 384
482 /* Process CA PMT Reply */ 385 /* Process CA PMT Reply */
483 /* will implement soon */ 386 /* will implement soon */
484 dprintk("%s: Not there yet\n", __FUNCTION__); 387 dprintk(verbose, DST_CA_ERROR, 1, " Not there yet");
485 } 388 }
486 /* CA PMT Reply not capable */ 389 /* CA PMT Reply not capable */
487 if (!ca_pmt_reply_test) { 390 if (!ca_pmt_reply_test) {
488 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, NO_REPLY)) < 0) { 391 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, NO_REPLY)) < 0) {
489 dprintk("%s: ca_set_pmt.. failed !\n", __FUNCTION__); 392 dprintk(verbose, DST_CA_ERROR, 1, " ca_set_pmt.. failed !");
490 return -1; 393 return -1;
491 } 394 }
492 if (verbose > 3) 395 dprintk(verbose, DST_CA_NOTICE, 1, " ca_set_pmt.. success !");
493 dprintk("%s: ca_set_pmt.. success !\n", __FUNCTION__);
494 /* put a dummy message */ 396 /* put a dummy message */
495 397
496 } 398 }
@@ -506,11 +408,10 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message,
506 struct ca_msg *hw_buffer; 408 struct ca_msg *hw_buffer;
507 409
508 if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) { 410 if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
509 dprintk("%s: Memory allocation failure\n", __FUNCTION__); 411 dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
510 return -ENOMEM; 412 return -ENOMEM;
511 } 413 }
512 if (verbose > 3) 414 dprintk(verbose, DST_CA_DEBUG, 1, " ");
513 dprintk("%s\n", __FUNCTION__);
514 415
515 if (copy_from_user(p_ca_message, (void *)arg, sizeof (struct ca_msg))) 416 if (copy_from_user(p_ca_message, (void *)arg, sizeof (struct ca_msg)))
516 return -EFAULT; 417 return -EFAULT;
@@ -525,51 +426,35 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message,
525 if (i < 2) 426 if (i < 2)
526 command = command << 8; 427 command = command << 8;
527 } 428 }
528 if (verbose > 3) 429 dprintk(verbose, DST_CA_DEBUG, 1, " Command=[0x%x]\n", command);
529 dprintk("%s:Command=[0x%x]\n", __FUNCTION__, command);
530 430
531 switch (command) { 431 switch (command) {
532 case CA_PMT: 432 case CA_PMT:
533 if (verbose > 3) 433 dprintk(verbose, DST_CA_DEBUG, 1, "Command = SEND_CA_PMT");
534// dprintk("Command = SEND_CA_PMT\n"); 434 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { // code simplification started
535 dprintk("Command = SEND_CA_PMT\n"); 435 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT Failed !");
536// if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { 436 return -1;
537 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { // code simplification started 437 }
538 dprintk("%s: -->CA_PMT Failed !\n", __FUNCTION__); 438 dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT Success !");
539 return -1; 439 break;
540 } 440 case CA_PMT_REPLY:
541 if (verbose > 3) 441 dprintk(verbose, DST_CA_INFO, 1, "Command = CA_PMT_REPLY");
542 dprintk("%s: -->CA_PMT Success !\n", __FUNCTION__); 442 /* Have to handle the 2 basic types of cards here */
543// retval = dummy_set_pmt(state, p_ca_message, hw_buffer, 0, 0); 443 if ((dst_check_ca_pmt(state, p_ca_message, hw_buffer)) < 0) {
544 444 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT_REPLY Failed !");
545 break; 445 return -1;
546 446 }
547 case CA_PMT_REPLY: 447 dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT_REPLY Success !");
548 if (verbose > 3) 448 break;
549 dprintk("Command = CA_PMT_REPLY\n"); 449 case CA_APP_INFO_ENQUIRY: // only for debugging
550 /* Have to handle the 2 basic types of cards here */ 450 dprintk(verbose, DST_CA_INFO, 1, " Getting Cam Application information");
551 if ((dst_check_ca_pmt(state, p_ca_message, hw_buffer)) < 0) { 451
552 dprintk("%s: -->CA_PMT_REPLY Failed !\n", __FUNCTION__); 452 if ((ca_get_app_info(state)) < 0) {
553 return -1; 453 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_APP_INFO_ENQUIRY Failed !");
554 } 454 return -1;
555 if (verbose > 3) 455 }
556 dprintk("%s: -->CA_PMT_REPLY Success !\n", __FUNCTION__); 456 dprintk(verbose, DST_CA_INFO, 1, " -->CA_APP_INFO_ENQUIRY Success !");
557 457 break;
558 /* Certain boards do behave different ? */
559// retval = ca_set_pmt(state, p_ca_message, hw_buffer, 1, 1);
560
561 case CA_APP_INFO_ENQUIRY: // only for debugging
562 if (verbose > 3)
563 dprintk("%s: Getting Cam Application information\n", __FUNCTION__);
564
565 if ((ca_get_app_info(state)) < 0) {
566 dprintk("%s: -->CA_APP_INFO_ENQUIRY Failed !\n", __FUNCTION__);
567 return -1;
568 }
569 if (verbose > 3)
570 dprintk("%s: -->CA_APP_INFO_ENQUIRY Success !\n", __FUNCTION__);
571
572 break;
573 } 458 }
574 } 459 }
575 return 0; 460 return 0;
@@ -584,121 +469,88 @@ static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd
584 struct ca_msg *p_ca_message; 469 struct ca_msg *p_ca_message;
585 470
586 if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) { 471 if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
587 dprintk("%s: Memory allocation failure\n", __FUNCTION__); 472 dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
588 return -ENOMEM; 473 return -ENOMEM;
589 } 474 }
590
591 if ((p_ca_slot_info = (struct ca_slot_info *) kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL)) == NULL) { 475 if ((p_ca_slot_info = (struct ca_slot_info *) kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL)) == NULL) {
592 dprintk("%s: Memory allocation failure\n", __FUNCTION__); 476 dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
593 return -ENOMEM; 477 return -ENOMEM;
594 } 478 }
595
596 if ((p_ca_caps = (struct ca_caps *) kmalloc(sizeof (struct ca_caps), GFP_KERNEL)) == NULL) { 479 if ((p_ca_caps = (struct ca_caps *) kmalloc(sizeof (struct ca_caps), GFP_KERNEL)) == NULL) {
597 dprintk("%s: Memory allocation failure\n", __FUNCTION__); 480 dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
598 return -ENOMEM; 481 return -ENOMEM;
599 } 482 }
600
601 /* We have now only the standard ioctl's, the driver is upposed to handle internals. */ 483 /* We have now only the standard ioctl's, the driver is upposed to handle internals. */
602 switch (cmd) { 484 switch (cmd) {
603 case CA_SEND_MSG: 485 case CA_SEND_MSG:
604 if (verbose > 1) 486 dprintk(verbose, DST_CA_INFO, 1, " Sending message");
605 dprintk("%s: Sending message\n", __FUNCTION__); 487 if ((ca_send_message(state, p_ca_message, arg)) < 0) {
606 if ((ca_send_message(state, p_ca_message, arg)) < 0) { 488 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SEND_MSG Failed !");
607 dprintk("%s: -->CA_SEND_MSG Failed !\n", __FUNCTION__); 489 return -1;
608 return -1; 490 }
609 } 491 break;
610 492 case CA_GET_MSG:
611 break; 493 dprintk(verbose, DST_CA_INFO, 1, " Getting message");
612 494 if ((ca_get_message(state, p_ca_message, arg)) < 0) {
613 case CA_GET_MSG: 495 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_MSG Failed !");
614 if (verbose > 1) 496 return -1;
615 dprintk("%s: Getting message\n", __FUNCTION__); 497 }
616 if ((ca_get_message(state, p_ca_message, arg)) < 0) { 498 dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_MSG Success !");
617 dprintk("%s: -->CA_GET_MSG Failed !\n", __FUNCTION__); 499 break;
618 return -1; 500 case CA_RESET:
619 } 501 dprintk(verbose, DST_CA_ERROR, 1, " Resetting DST");
620 if (verbose > 1) 502 dst_error_bailout(state);
621 dprintk("%s: -->CA_GET_MSG Success !\n", __FUNCTION__); 503 msleep(4000);
622 504 break;
623 break; 505 case CA_GET_SLOT_INFO:
624 506 dprintk(verbose, DST_CA_INFO, 1, " Getting Slot info");
625 case CA_RESET: 507 if ((ca_get_slot_info(state, p_ca_slot_info, arg)) < 0) {
626 if (verbose > 1) 508 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_SLOT_INFO Failed !");
627 dprintk("%s: Resetting DST\n", __FUNCTION__); 509 return -1;
628 dst_error_bailout(state); 510 }
629 msleep(4000); 511 dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_SLOT_INFO Success !");
630 512 break;
631 break; 513 case CA_GET_CAP:
632 514 dprintk(verbose, DST_CA_INFO, 1, " Getting Slot capabilities");
633 case CA_GET_SLOT_INFO: 515 if ((ca_get_slot_caps(state, p_ca_caps, arg)) < 0) {
634 if (verbose > 1) 516 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_CAP Failed !");
635 dprintk("%s: Getting Slot info\n", __FUNCTION__); 517 return -1;
636 if ((ca_get_slot_info(state, p_ca_slot_info, arg)) < 0) { 518 }
637 dprintk("%s: -->CA_GET_SLOT_INFO Failed !\n", __FUNCTION__); 519 dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_CAP Success !");
638 return -1; 520 break;
639 } 521 case CA_GET_DESCR_INFO:
640 if (verbose > 1) 522 dprintk(verbose, DST_CA_INFO, 1, " Getting descrambler description");
641 dprintk("%s: -->CA_GET_SLOT_INFO Success !\n", __FUNCTION__); 523 if ((ca_get_slot_descr(state, p_ca_message, arg)) < 0) {
642 524 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_DESCR_INFO Failed !");
643 break; 525 return -1;
644 526 }
645 case CA_GET_CAP: 527 dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_DESCR_INFO Success !");
646 if (verbose > 1) 528 break;
647 dprintk("%s: Getting Slot capabilities\n", __FUNCTION__); 529 case CA_SET_DESCR:
648 if ((ca_get_slot_caps(state, p_ca_caps, arg)) < 0) { 530 dprintk(verbose, DST_CA_INFO, 1, " Setting descrambler");
649 dprintk("%s: -->CA_GET_CAP Failed !\n", __FUNCTION__); 531 if ((ca_set_slot_descr()) < 0) {
650 return -1; 532 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_DESCR Failed !");
651 } 533 return -1;
652 if (verbose > 1) 534 }
653 dprintk("%s: -->CA_GET_CAP Success !\n", __FUNCTION__); 535 dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_DESCR Success !");
654 536 break;
655 break; 537 case CA_SET_PID:
656 538 dprintk(verbose, DST_CA_INFO, 1, " Setting PID");
657 case CA_GET_DESCR_INFO: 539 if ((ca_set_pid()) < 0) {
658 if (verbose > 1) 540 dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_PID Failed !");
659 dprintk("%s: Getting descrambler description\n", __FUNCTION__); 541 return -1;
660 if ((ca_get_slot_descr(state, p_ca_message, arg)) < 0) { 542 }
661 dprintk("%s: -->CA_GET_DESCR_INFO Failed !\n", __FUNCTION__); 543 dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_PID Success !");
662 return -1; 544 default:
663 } 545 return -EOPNOTSUPP;
664 if (verbose > 1) 546 };
665 dprintk("%s: -->CA_GET_DESCR_INFO Success !\n", __FUNCTION__);
666
667 break;
668
669 case CA_SET_DESCR:
670 if (verbose > 1)
671 dprintk("%s: Setting descrambler\n", __FUNCTION__);
672 if ((ca_set_slot_descr()) < 0) {
673 dprintk("%s: -->CA_SET_DESCR Failed !\n", __FUNCTION__);
674 return -1;
675 }
676 if (verbose > 1)
677 dprintk("%s: -->CA_SET_DESCR Success !\n", __FUNCTION__);
678
679 break;
680
681 case CA_SET_PID:
682 if (verbose > 1)
683 dprintk("%s: Setting PID\n", __FUNCTION__);
684 if ((ca_set_pid()) < 0) {
685 dprintk("%s: -->CA_SET_PID Failed !\n", __FUNCTION__);
686 return -1;
687 }
688 if (verbose > 1)
689 dprintk("%s: -->CA_SET_PID Success !\n", __FUNCTION__);
690
691 default:
692 return -EOPNOTSUPP;
693 };
694 547
695 return 0; 548 return 0;
696} 549}
697 550
698static int dst_ca_open(struct inode *inode, struct file *file) 551static int dst_ca_open(struct inode *inode, struct file *file)
699{ 552{
700 if (verbose > 4) 553 dprintk(verbose, DST_CA_DEBUG, 1, " Device opened [%p] ", file);
701 dprintk("%s:Device opened [%p]\n", __FUNCTION__, file);
702 try_module_get(THIS_MODULE); 554 try_module_get(THIS_MODULE);
703 555
704 return 0; 556 return 0;
@@ -706,27 +558,24 @@ static int dst_ca_open(struct inode *inode, struct file *file)
706 558
707static int dst_ca_release(struct inode *inode, struct file *file) 559static int dst_ca_release(struct inode *inode, struct file *file)
708{ 560{
709 if (verbose > 4) 561 dprintk(verbose, DST_CA_DEBUG, 1, " Device closed.");
710 dprintk("%s:Device closed.\n", __FUNCTION__);
711 module_put(THIS_MODULE); 562 module_put(THIS_MODULE);
712 563
713 return 0; 564 return 0;
714} 565}
715 566
716static int dst_ca_read(struct file *file, char __user * buffer, size_t length, loff_t * offset) 567static int dst_ca_read(struct file *file, char __user *buffer, size_t length, loff_t *offset)
717{ 568{
718 int bytes_read = 0; 569 int bytes_read = 0;
719 570
720 if (verbose > 4) 571 dprintk(verbose, DST_CA_DEBUG, 1, " Device read.");
721 dprintk("%s:Device read.\n", __FUNCTION__);
722 572
723 return bytes_read; 573 return bytes_read;
724} 574}
725 575
726static int dst_ca_write(struct file *file, const char __user * buffer, size_t length, loff_t * offset) 576static int dst_ca_write(struct file *file, const char __user *buffer, size_t length, loff_t *offset)
727{ 577{
728 if (verbose > 4) 578 dprintk(verbose, DST_CA_DEBUG, 1, " Device write.");
729 dprintk("%s:Device write.\n", __FUNCTION__);
730 579
731 return 0; 580 return 0;
732} 581}
@@ -751,8 +600,7 @@ static struct dvb_device dvbdev_ca = {
751int dst_ca_attach(struct dst_state *dst, struct dvb_adapter *dvb_adapter) 600int dst_ca_attach(struct dst_state *dst, struct dvb_adapter *dvb_adapter)
752{ 601{
753 struct dvb_device *dvbdev; 602 struct dvb_device *dvbdev;
754 if (verbose > 4) 603 dprintk(verbose, DST_CA_ERROR, 1, "registering DST-CA device");
755 dprintk("%s:registering DST-CA device\n", __FUNCTION__);
756 dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst, DVB_DEVICE_CA); 604 dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst, DVB_DEVICE_CA);
757 return 0; 605 return 0;
758} 606}
diff --git a/drivers/media/dvb/bt8xx/dst_common.h b/drivers/media/dvb/bt8xx/dst_common.h
index ef532a6ace..3281a6ca36 100644
--- a/drivers/media/dvb/bt8xx/dst_common.h
+++ b/drivers/media/dvb/bt8xx/dst_common.h
@@ -61,7 +61,6 @@
61#define DST_TYPE_HAS_ANALOG 64 /* Analog inputs */ 61#define DST_TYPE_HAS_ANALOG 64 /* Analog inputs */
62#define DST_TYPE_HAS_SESSION 128 62#define DST_TYPE_HAS_SESSION 128
63 63
64
65#define RDC_8820_PIO_0_DISABLE 0 64#define RDC_8820_PIO_0_DISABLE 0
66#define RDC_8820_PIO_0_ENABLE 1 65#define RDC_8820_PIO_0_ENABLE 1
67#define RDC_8820_INT 2 66#define RDC_8820_INT 2
@@ -114,6 +113,10 @@ struct dst_state {
114 fe_sec_mini_cmd_t minicmd; 113 fe_sec_mini_cmd_t minicmd;
115 fe_modulation_t modulation; 114 fe_modulation_t modulation;
116 u8 messages[256]; 115 u8 messages[256];
116 u8 mac_address[8];
117 u8 fw_version[8];
118 u8 card_info[8];
119 u8 vendor[8];
117}; 120};
118 121
119struct dst_types { 122struct dst_types {
@@ -124,15 +127,12 @@ struct dst_types {
124 u32 dst_feature; 127 u32 dst_feature;
125}; 128};
126 129
127
128
129struct dst_config 130struct dst_config
130{ 131{
131 /* the ASIC i2c address */ 132 /* the ASIC i2c address */
132 u8 demod_address; 133 u8 demod_address;
133}; 134};
134 135
135
136int rdc_reset_state(struct dst_state *state); 136int rdc_reset_state(struct dst_state *state);
137int rdc_8820_reset(struct dst_state *state); 137int rdc_8820_reset(struct dst_state *state);
138 138
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
index 6f857c6091..c5c7672cd5 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
@@ -32,9 +32,7 @@
32#include "dvbdev.h" 32#include "dvbdev.h"
33#include "dvb_demux.h" 33#include "dvb_demux.h"
34#include "dvb_frontend.h" 34#include "dvb_frontend.h"
35
36#include "dvb-bt8xx.h" 35#include "dvb-bt8xx.h"
37
38#include "bt878.h" 36#include "bt878.h"
39 37
40static int debug; 38static int debug;
@@ -43,9 +41,11 @@ module_param(debug, int, 0644);
43MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off)."); 41MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
44 42
45#define dprintk( args... ) \ 43#define dprintk( args... ) \
46 do { \ 44 do \
47 if (debug) printk(KERN_DEBUG args); \ 45 if (debug) printk(KERN_DEBUG args); \
48 } while (0) 46 while (0)
47
48#define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */
49 49
50static void dvb_bt8xx_task(unsigned long data) 50static void dvb_bt8xx_task(unsigned long data)
51{ 51{
@@ -119,14 +119,12 @@ static struct bt878 __init *dvb_bt8xx_878_match(unsigned int bttv_nr, struct pci
119 unsigned int card_nr; 119 unsigned int card_nr;
120 120
121 /* Hmm, n squared. Hope n is small */ 121 /* Hmm, n squared. Hope n is small */
122 for (card_nr = 0; card_nr < bt878_num; card_nr++) { 122 for (card_nr = 0; card_nr < bt878_num; card_nr++)
123 if (is_pci_slot_eq(bt878[card_nr].dev, bttv_pci_dev)) 123 if (is_pci_slot_eq(bt878[card_nr].dev, bttv_pci_dev))
124 return &bt878[card_nr]; 124 return &bt878[card_nr];
125 }
126 return NULL; 125 return NULL;
127} 126}
128 127
129
130static int thomson_dtt7579_demod_init(struct dvb_frontend* fe) 128static int thomson_dtt7579_demod_init(struct dvb_frontend* fe)
131{ 129{
132 static u8 mt352_clock_config [] = { 0x89, 0x38, 0x38 }; 130 static u8 mt352_clock_config [] = { 0x89, 0x38, 0x38 };
@@ -154,16 +152,21 @@ static int thomson_dtt7579_pll_set(struct dvb_frontend* fe, struct dvb_frontend_
154 unsigned char bs = 0; 152 unsigned char bs = 0;
155 unsigned char cp = 0; 153 unsigned char cp = 0;
156 154
157 #define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */
158 div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6; 155 div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6;
159 156
160 if (params->frequency < 542000000) cp = 0xb4; 157 if (params->frequency < 542000000)
161 else if (params->frequency < 771000000) cp = 0xbc; 158 cp = 0xb4;
162 else cp = 0xf4; 159 else if (params->frequency < 771000000)
160 cp = 0xbc;
161 else
162 cp = 0xf4;
163 163
164 if (params->frequency == 0) bs = 0x03; 164 if (params->frequency == 0)
165 else if (params->frequency < 443250000) bs = 0x02; 165 bs = 0x03;
166 else bs = 0x08; 166 else if (params->frequency < 443250000)
167 bs = 0x02;
168 else
169 bs = 0x08;
167 170
168 pllbuf[0] = 0xc0; // Note: non-linux standard PLL i2c address 171 pllbuf[0] = 0xc0; // Note: non-linux standard PLL i2c address
169 pllbuf[1] = div >> 8; 172 pllbuf[1] = div >> 8;
@@ -175,7 +178,6 @@ static int thomson_dtt7579_pll_set(struct dvb_frontend* fe, struct dvb_frontend_
175} 178}
176 179
177static struct mt352_config thomson_dtt7579_config = { 180static struct mt352_config thomson_dtt7579_config = {
178
179 .demod_address = 0x0f, 181 .demod_address = 0x0f,
180 .demod_init = thomson_dtt7579_demod_init, 182 .demod_init = thomson_dtt7579_demod_init,
181 .pll_set = thomson_dtt7579_pll_set, 183 .pll_set = thomson_dtt7579_pll_set,
@@ -183,25 +185,26 @@ static struct mt352_config thomson_dtt7579_config = {
183 185
184static int cx24108_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 186static int cx24108_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
185{ 187{
186 u32 freq = params->frequency; 188 u32 freq = params->frequency;
187
188 int i, a, n, pump;
189 u32 band, pll;
190 189
190 int i, a, n, pump;
191 u32 band, pll;
191 192
192 u32 osci[]={950000,1019000,1075000,1178000,1296000,1432000, 193 u32 osci[]={950000,1019000,1075000,1178000,1296000,1432000,
193 1576000,1718000,1856000,2036000,2150000}; 194 1576000,1718000,1856000,2036000,2150000};
194 u32 bandsel[]={0,0x00020000,0x00040000,0x00100800,0x00101000, 195 u32 bandsel[]={0,0x00020000,0x00040000,0x00100800,0x00101000,
195 0x00102000,0x00104000,0x00108000,0x00110000, 196 0x00102000,0x00104000,0x00108000,0x00110000,
196 0x00120000,0x00140000}; 197 0x00120000,0x00140000};
197 198
198#define XTAL 1011100 /* Hz, really 1.0111 MHz and a /10 prescaler */ 199 #define XTAL 1011100 /* Hz, really 1.0111 MHz and a /10 prescaler */
199 printk("cx24108 debug: entering SetTunerFreq, freq=%d\n",freq); 200 printk("cx24108 debug: entering SetTunerFreq, freq=%d\n",freq);
200 201
201 /* This is really the bit driving the tuner chip cx24108 */ 202 /* This is really the bit driving the tuner chip cx24108 */
202 203
203 if(freq<950000) freq=950000; /* kHz */ 204 if (freq<950000)
204 if(freq>2150000) freq=2150000; /* satellite IF is 950..2150MHz */ 205 freq = 950000; /* kHz */
206 else if (freq>2150000)
207 freq = 2150000; /* satellite IF is 950..2150MHz */
205 208
206 /* decide which VCO to use for the input frequency */ 209 /* decide which VCO to use for the input frequency */
207 for(i=1;(i<sizeof(osci)/sizeof(osci[0]))&&(osci[i]<freq);i++); 210 for(i=1;(i<sizeof(osci)/sizeof(osci[0]))&&(osci[i]<freq);i++);
@@ -228,25 +231,22 @@ static int cx24108_pll_set(struct dvb_frontend* fe, struct dvb_frontend_paramete
228 cx24110_pll_write(fe,0x500c0000); 231 cx24110_pll_write(fe,0x500c0000);
229 cx24110_pll_write(fe,0x83f1f800); 232 cx24110_pll_write(fe,0x83f1f800);
230 cx24110_pll_write(fe,pll); 233 cx24110_pll_write(fe,pll);
231/* writereg(client,0x56,0x7f);*/ 234 //writereg(client,0x56,0x7f);
232 235
233 return 0; 236 return 0;
234} 237}
235 238
236static int pinnsat_pll_init(struct dvb_frontend* fe) 239static int pinnsat_pll_init(struct dvb_frontend* fe)
237{ 240{
238 return 0; 241 return 0;
239} 242}
240 243
241
242static struct cx24110_config pctvsat_config = { 244static struct cx24110_config pctvsat_config = {
243
244 .demod_address = 0x55, 245 .demod_address = 0x55,
245 .pll_init = pinnsat_pll_init, 246 .pll_init = pinnsat_pll_init,
246 .pll_set = cx24108_pll_set, 247 .pll_set = cx24108_pll_set,
247}; 248};
248 249
249
250static int microtune_mt7202dtf_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 250static int microtune_mt7202dtf_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
251{ 251{
252 struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *) fe->dvb->priv; 252 struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *) fe->dvb->priv;
@@ -258,15 +258,23 @@ static int microtune_mt7202dtf_pll_set(struct dvb_frontend* fe, struct dvb_front
258 div = (36000000 + params->frequency + 83333) / 166666; 258 div = (36000000 + params->frequency + 83333) / 166666;
259 cfg = 0x88; 259 cfg = 0x88;
260 260
261 if (params->frequency < 175000000) cpump = 2; 261 if (params->frequency < 175000000)
262 else if (params->frequency < 390000000) cpump = 1; 262 cpump = 2;
263 else if (params->frequency < 470000000) cpump = 2; 263 else if (params->frequency < 390000000)
264 else if (params->frequency < 750000000) cpump = 2; 264 cpump = 1;
265 else cpump = 3; 265 else if (params->frequency < 470000000)
266 cpump = 2;
267 else if (params->frequency < 750000000)
268 cpump = 2;
269 else
270 cpump = 3;
266 271
267 if (params->frequency < 175000000) band_select = 0x0e; 272 if (params->frequency < 175000000)
268 else if (params->frequency < 470000000) band_select = 0x05; 273 band_select = 0x0e;
269 else band_select = 0x03; 274 else if (params->frequency < 470000000)
275 band_select = 0x05;
276 else
277 band_select = 0x03;
270 278
271 data[0] = (div >> 8) & 0x7f; 279 data[0] = (div >> 8) & 0x7f;
272 data[1] = div & 0xff; 280 data[1] = div & 0xff;
@@ -285,14 +293,11 @@ static int microtune_mt7202dtf_request_firmware(struct dvb_frontend* fe, const s
285} 293}
286 294
287static struct sp887x_config microtune_mt7202dtf_config = { 295static struct sp887x_config microtune_mt7202dtf_config = {
288
289 .demod_address = 0x70, 296 .demod_address = 0x70,
290 .pll_set = microtune_mt7202dtf_pll_set, 297 .pll_set = microtune_mt7202dtf_pll_set,
291 .request_firmware = microtune_mt7202dtf_request_firmware, 298 .request_firmware = microtune_mt7202dtf_request_firmware,
292}; 299};
293 300
294
295
296static int advbt771_samsung_tdtc9251dh0_demod_init(struct dvb_frontend* fe) 301static int advbt771_samsung_tdtc9251dh0_demod_init(struct dvb_frontend* fe)
297{ 302{
298 static u8 mt352_clock_config [] = { 0x89, 0x38, 0x2d }; 303 static u8 mt352_clock_config [] = { 0x89, 0x38, 0x2d };
@@ -303,7 +308,6 @@ static int advbt771_samsung_tdtc9251dh0_demod_init(struct dvb_frontend* fe)
303 static u8 mt352_av771_extra[] = { 0xB5, 0x7A }; 308 static u8 mt352_av771_extra[] = { 0xB5, 0x7A };
304 static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 }; 309 static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
305 310
306
307 mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config)); 311 mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
308 udelay(2000); 312 udelay(2000);
309 mt352_write(fe, mt352_reset, sizeof(mt352_reset)); 313 mt352_write(fe, mt352_reset, sizeof(mt352_reset));
@@ -323,28 +327,45 @@ static int advbt771_samsung_tdtc9251dh0_pll_set(struct dvb_frontend* fe, struct
323 unsigned char bs = 0; 327 unsigned char bs = 0;
324 unsigned char cp = 0; 328 unsigned char cp = 0;
325 329
326 #define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */
327 div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6; 330 div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6;
328 331
329 if (params->frequency < 150000000) cp = 0xB4; 332 if (params->frequency < 150000000)
330 else if (params->frequency < 173000000) cp = 0xBC; 333 cp = 0xB4;
331 else if (params->frequency < 250000000) cp = 0xB4; 334 else if (params->frequency < 173000000)
332 else if (params->frequency < 400000000) cp = 0xBC; 335 cp = 0xBC;
333 else if (params->frequency < 420000000) cp = 0xF4; 336 else if (params->frequency < 250000000)
334 else if (params->frequency < 470000000) cp = 0xFC; 337 cp = 0xB4;
335 else if (params->frequency < 600000000) cp = 0xBC; 338 else if (params->frequency < 400000000)
336 else if (params->frequency < 730000000) cp = 0xF4; 339 cp = 0xBC;
337 else cp = 0xFC; 340 else if (params->frequency < 420000000)
338 341 cp = 0xF4;
339 if (params->frequency < 150000000) bs = 0x01; 342 else if (params->frequency < 470000000)
340 else if (params->frequency < 173000000) bs = 0x01; 343 cp = 0xFC;
341 else if (params->frequency < 250000000) bs = 0x02; 344 else if (params->frequency < 600000000)
342 else if (params->frequency < 400000000) bs = 0x02; 345 cp = 0xBC;
343 else if (params->frequency < 420000000) bs = 0x02; 346 else if (params->frequency < 730000000)
344 else if (params->frequency < 470000000) bs = 0x02; 347 cp = 0xF4;
345 else if (params->frequency < 600000000) bs = 0x08; 348 else
346 else if (params->frequency < 730000000) bs = 0x08; 349 cp = 0xFC;
347 else bs = 0x08; 350
351 if (params->frequency < 150000000)
352 bs = 0x01;
353 else if (params->frequency < 173000000)
354 bs = 0x01;
355 else if (params->frequency < 250000000)
356 bs = 0x02;
357 else if (params->frequency < 400000000)
358 bs = 0x02;
359 else if (params->frequency < 420000000)
360 bs = 0x02;
361 else if (params->frequency < 470000000)
362 bs = 0x02;
363 else if (params->frequency < 600000000)
364 bs = 0x08;
365 else if (params->frequency < 730000000)
366 bs = 0x08;
367 else
368 bs = 0x08;
348 369
349 pllbuf[0] = 0xc2; // Note: non-linux standard PLL i2c address 370 pllbuf[0] = 0xc2; // Note: non-linux standard PLL i2c address
350 pllbuf[1] = div >> 8; 371 pllbuf[1] = div >> 8;
@@ -356,19 +377,15 @@ static int advbt771_samsung_tdtc9251dh0_pll_set(struct dvb_frontend* fe, struct
356} 377}
357 378
358static struct mt352_config advbt771_samsung_tdtc9251dh0_config = { 379static struct mt352_config advbt771_samsung_tdtc9251dh0_config = {
359
360 .demod_address = 0x0f, 380 .demod_address = 0x0f,
361 .demod_init = advbt771_samsung_tdtc9251dh0_demod_init, 381 .demod_init = advbt771_samsung_tdtc9251dh0_demod_init,
362 .pll_set = advbt771_samsung_tdtc9251dh0_pll_set, 382 .pll_set = advbt771_samsung_tdtc9251dh0_pll_set,
363}; 383};
364 384
365
366static struct dst_config dst_config = { 385static struct dst_config dst_config = {
367
368 .demod_address = 0x55, 386 .demod_address = 0x55,
369}; 387};
370 388
371
372static int or51211_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name) 389static int or51211_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name)
373{ 390{
374 struct dvb_bt8xx_card* bt = (struct dvb_bt8xx_card*) fe->dvb->priv; 391 struct dvb_bt8xx_card* bt = (struct dvb_bt8xx_card*) fe->dvb->priv;
@@ -398,10 +415,8 @@ static void or51211_reset(struct dvb_frontend * fe)
398 */ 415 */
399 /* reset & PRM1,2&4 are outputs */ 416 /* reset & PRM1,2&4 are outputs */
400 int ret = bttv_gpio_enable(bt->bttv_nr, 0x001F, 0x001F); 417 int ret = bttv_gpio_enable(bt->bttv_nr, 0x001F, 0x001F);
401 if (ret != 0) { 418 if (ret != 0)
402 printk(KERN_WARNING "or51211: Init Error - Can't Reset DVR " 419 printk(KERN_WARNING "or51211: Init Error - Can't Reset DVR (%i)\n", ret);
403 "(%i)\n", ret);
404 }
405 bttv_write_gpio(bt->bttv_nr, 0x001F, 0x0000); /* Reset */ 420 bttv_write_gpio(bt->bttv_nr, 0x001F, 0x0000); /* Reset */
406 msleep(20); 421 msleep(20);
407 /* Now set for normal operation */ 422 /* Now set for normal operation */
@@ -417,7 +432,6 @@ static void or51211_sleep(struct dvb_frontend * fe)
417} 432}
418 433
419static struct or51211_config or51211_config = { 434static struct or51211_config or51211_config = {
420
421 .demod_address = 0x15, 435 .demod_address = 0x15,
422 .request_firmware = or51211_request_firmware, 436 .request_firmware = or51211_request_firmware,
423 .setmode = or51211_setmode, 437 .setmode = or51211_setmode,
@@ -425,7 +439,6 @@ static struct or51211_config or51211_config = {
425 .sleep = or51211_sleep, 439 .sleep = or51211_sleep,
426}; 440};
427 441
428
429static int vp3021_alps_tded4_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 442static int vp3021_alps_tded4_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
430{ 443{
431 struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *) fe->dvb->priv; 444 struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *) fe->dvb->priv;
@@ -454,12 +467,84 @@ static int vp3021_alps_tded4_pll_set(struct dvb_frontend* fe, struct dvb_fronten
454} 467}
455 468
456static struct nxt6000_config vp3021_alps_tded4_config = { 469static struct nxt6000_config vp3021_alps_tded4_config = {
457
458 .demod_address = 0x0a, 470 .demod_address = 0x0a,
459 .clock_inversion = 1, 471 .clock_inversion = 1,
460 .pll_set = vp3021_alps_tded4_pll_set, 472 .pll_set = vp3021_alps_tded4_pll_set,
461}; 473};
462 474
475static int digitv_alps_tded4_demod_init(struct dvb_frontend* fe)
476{
477 static u8 mt352_clock_config [] = { 0x89, 0x38, 0x2d };
478 static u8 mt352_reset [] = { 0x50, 0x80 };
479 static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 };
480 static u8 mt352_agc_cfg [] = { 0x67, 0x20, 0xa0 };
481 static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
482
483 mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
484 udelay(2000);
485 mt352_write(fe, mt352_reset, sizeof(mt352_reset));
486 mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
487 mt352_write(fe, mt352_agc_cfg,sizeof(mt352_agc_cfg));
488 mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg));
489
490 return 0;
491}
492
493static int digitv_alps_tded4_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u8* pllbuf)
494{
495 u32 div;
496 struct dvb_ofdm_parameters *op = &params->u.ofdm;
497
498 div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6;
499
500 pllbuf[0] = 0xc2;
501 pllbuf[1] = (div >> 8) & 0x7F;
502 pllbuf[2] = div & 0xFF;
503 pllbuf[3] = 0x85;
504
505 dprintk("frequency %u, div %u\n", params->frequency, div);
506
507 if (params->frequency < 470000000)
508 pllbuf[4] = 0x02;
509 else if (params->frequency > 823000000)
510 pllbuf[4] = 0x88;
511 else
512 pllbuf[4] = 0x08;
513
514 if (op->bandwidth == 8)
515 pllbuf[4] |= 0x04;
516
517 return 0;
518}
519
520static void digitv_alps_tded4_reset(struct dvb_bt8xx_card *bt)
521{
522 /*
523 * Reset the frontend, must be called before trying
524 * to initialise the MT352 or mt352_attach
525 * will fail.
526 *
527 * Presumably not required for the NXT6000 frontend.
528 *
529 */
530
531 int ret = bttv_gpio_enable(bt->bttv_nr, 0x08, 0x08);
532 if (ret != 0)
533 printk(KERN_WARNING "digitv_alps_tded4: Init Error - Can't Reset DVR (%i)\n", ret);
534
535 /* Pulse the reset line */
536 bttv_write_gpio(bt->bttv_nr, 0x08, 0x08); /* High */
537 bttv_write_gpio(bt->bttv_nr, 0x08, 0x00); /* Low */
538 msleep(100);
539
540 bttv_write_gpio(bt->bttv_nr, 0x08, 0x08); /* High */
541}
542
543static struct mt352_config digitv_alps_tded4_config = {
544 .demod_address = 0x0a,
545 .demod_init = digitv_alps_tded4_demod_init,
546 .pll_set = digitv_alps_tded4_pll_set,
547};
463 548
464static void frontend_init(struct dvb_bt8xx_card *card, u32 type) 549static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
465{ 550{
@@ -473,7 +558,6 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
473 if (card->fe != NULL) { 558 if (card->fe != NULL) {
474 card->fe->ops->info.frequency_min = 174000000; 559 card->fe->ops->info.frequency_min = 174000000;
475 card->fe->ops->info.frequency_max = 862000000; 560 card->fe->ops->info.frequency_max = 862000000;
476 break;
477 } 561 }
478 break; 562 break;
479#endif 563#endif
@@ -483,17 +567,28 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
483#else 567#else
484 case BTTV_NEBULA_DIGITV: 568 case BTTV_NEBULA_DIGITV:
485#endif 569#endif
570 /*
571 * It is possible to determine the correct frontend using the I2C bus (see the Nebula SDK);
572 * this would be a cleaner solution than trying each frontend in turn.
573 */
574
575 /* Old Nebula (marked (c)2003 on high profile pci card) has nxt6000 demod */
486 card->fe = nxt6000_attach(&vp3021_alps_tded4_config, card->i2c_adapter); 576 card->fe = nxt6000_attach(&vp3021_alps_tded4_config, card->i2c_adapter);
487 if (card->fe != NULL) { 577 if (card->fe != NULL) {
578 dprintk ("dvb_bt8xx: an nxt6000 was detected on your digitv card\n");
488 break; 579 break;
489 } 580 }
581
582 /* New Nebula (marked (c)2005 on low profile pci card) has mt352 demod */
583 digitv_alps_tded4_reset(card);
584 card->fe = mt352_attach(&digitv_alps_tded4_config, card->i2c_adapter);
585
586 if (card->fe != NULL)
587 dprintk ("dvb_bt8xx: an mt352 was detected on your digitv card\n");
490 break; 588 break;
491 589
492 case BTTV_AVDVBT_761: 590 case BTTV_AVDVBT_761:
493 card->fe = sp887x_attach(&microtune_mt7202dtf_config, card->i2c_adapter); 591 card->fe = sp887x_attach(&microtune_mt7202dtf_config, card->i2c_adapter);
494 if (card->fe != NULL) {
495 break;
496 }
497 break; 592 break;
498 593
499 case BTTV_AVDVBT_771: 594 case BTTV_AVDVBT_771:
@@ -501,7 +596,6 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
501 if (card->fe != NULL) { 596 if (card->fe != NULL) {
502 card->fe->ops->info.frequency_min = 174000000; 597 card->fe->ops->info.frequency_min = 174000000;
503 card->fe->ops->info.frequency_max = 862000000; 598 card->fe->ops->info.frequency_max = 862000000;
504 break;
505 } 599 }
506 break; 600 break;
507 601
@@ -522,54 +616,41 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
522 616
523 /* Attach other DST peripherals if any */ 617 /* Attach other DST peripherals if any */
524 /* Conditional Access device */ 618 /* Conditional Access device */
525 if (state->dst_hw_cap & DST_TYPE_HAS_CA) { 619 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
526 ret = dst_ca_attach(state, &card->dvb_adapter); 620 ret = dst_ca_attach(state, &card->dvb_adapter);
527 }
528 if (card->fe != NULL) {
529 break;
530 }
531 break; 621 break;
532 622
533 case BTTV_PINNACLESAT: 623 case BTTV_PINNACLESAT:
534 card->fe = cx24110_attach(&pctvsat_config, card->i2c_adapter); 624 card->fe = cx24110_attach(&pctvsat_config, card->i2c_adapter);
535 if (card->fe != NULL) {
536 break;
537 }
538 break; 625 break;
539 626
540 case BTTV_PC_HDTV: 627 case BTTV_PC_HDTV:
541 card->fe = or51211_attach(&or51211_config, card->i2c_adapter); 628 card->fe = or51211_attach(&or51211_config, card->i2c_adapter);
542 if (card->fe != NULL) {
543 break;
544 }
545 break; 629 break;
546 } 630 }
547 631
548 if (card->fe == NULL) { 632 if (card->fe == NULL)
549 printk("dvb-bt8xx: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n", 633 printk("dvb-bt8xx: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n",
550 card->bt->dev->vendor, 634 card->bt->dev->vendor,
551 card->bt->dev->device, 635 card->bt->dev->device,
552 card->bt->dev->subsystem_vendor, 636 card->bt->dev->subsystem_vendor,
553 card->bt->dev->subsystem_device); 637 card->bt->dev->subsystem_device);
554 } else { 638 else
555 if (dvb_register_frontend(&card->dvb_adapter, card->fe)) { 639 if (dvb_register_frontend(&card->dvb_adapter, card->fe)) {
556 printk("dvb-bt8xx: Frontend registration failed!\n"); 640 printk("dvb-bt8xx: Frontend registration failed!\n");
557 if (card->fe->ops->release) 641 if (card->fe->ops->release)
558 card->fe->ops->release(card->fe); 642 card->fe->ops->release(card->fe);
559 card->fe = NULL; 643 card->fe = NULL;
560 } 644 }
561 }
562} 645}
563 646
564static int __init dvb_bt8xx_load_card(struct dvb_bt8xx_card *card, u32 type) 647static int __init dvb_bt8xx_load_card(struct dvb_bt8xx_card *card, u32 type)
565{ 648{
566 int result; 649 int result;
567 650
568 if ((result = dvb_register_adapter(&card->dvb_adapter, card->card_name, 651 if ((result = dvb_register_adapter(&card->dvb_adapter, card->card_name, THIS_MODULE)) < 0) {
569 THIS_MODULE)) < 0) {
570 printk("dvb_bt8xx: dvb_register_adapter failed (errno = %d)\n", result); 652 printk("dvb_bt8xx: dvb_register_adapter failed (errno = %d)\n", result);
571 return result; 653 return result;
572
573 } 654 }
574 card->dvb_adapter.priv = card; 655 card->dvb_adapter.priv = card;
575 656
@@ -664,8 +745,7 @@ static int dvb_bt8xx_probe(struct device *dev)
664 strncpy(card->card_name, sub->core->name, sizeof(sub->core->name)); 745 strncpy(card->card_name, sub->core->name, sizeof(sub->core->name));
665 card->i2c_adapter = &sub->core->i2c_adap; 746 card->i2c_adapter = &sub->core->i2c_adap;
666 747
667 switch(sub->core->type) 748 switch(sub->core->type) {
668 {
669 case BTTV_PINNACLESAT: 749 case BTTV_PINNACLESAT:
670 card->gpio_mode = 0x0400c060; 750 card->gpio_mode = 0x0400c060;
671 /* should be: BT878_A_GAIN=0,BT878_A_PWRDN,BT878_DA_DPM,BT878_DA_SBR, 751 /* should be: BT878_A_GAIN=0,BT878_A_PWRDN,BT878_DA_DPM,BT878_DA_SBR,
@@ -751,7 +831,6 @@ static int dvb_bt8xx_probe(struct device *dev)
751 831
752 kfree(card); 832 kfree(card);
753 return -EFAULT; 833 return -EFAULT;
754
755 } 834 }
756 835
757 init_MUTEX(&card->bt->gpio_lock); 836 init_MUTEX(&card->bt->gpio_lock);
@@ -779,7 +858,8 @@ static int dvb_bt8xx_remove(struct device *dev)
779 card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw); 858 card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw);
780 dvb_dmxdev_release(&card->dmxdev); 859 dvb_dmxdev_release(&card->dmxdev);
781 dvb_dmx_release(&card->demux); 860 dvb_dmx_release(&card->demux);
782 if (card->fe) dvb_unregister_frontend(card->fe); 861 if (card->fe)
862 dvb_unregister_frontend(card->fe);
783 dvb_unregister_adapter(&card->dvb_adapter); 863 dvb_unregister_adapter(&card->dvb_adapter);
784 864
785 kfree(card); 865 kfree(card);
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.h b/drivers/media/dvb/bt8xx/dvb-bt8xx.h
index 2923b3b0dd..9ec8e5bd6c 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.h
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.h
@@ -2,7 +2,7 @@
2 * Bt8xx based DVB adapter driver 2 * Bt8xx based DVB adapter driver
3 * 3 *
4 * Copyright (C) 2002,2003 Florian Schirmer <jolt@tuxbox.org> 4 * Copyright (C) 2002,2003 Florian Schirmer <jolt@tuxbox.org>
5 * Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@t-online.de> 5 * Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@htp-tel.de>
6 * Copyright (C) 1999-2001 Ralph Metzler & Marcus Metzler for convergence integrated media GmbH 6 * Copyright (C) 1999-2001 Ralph Metzler & Marcus Metzler for convergence integrated media GmbH
7 * Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de> 7 * Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de>
8 * 8 *
diff --git a/drivers/media/dvb/cinergyT2/Kconfig b/drivers/media/dvb/cinergyT2/Kconfig
index 226714085f..7cf4c4a888 100644
--- a/drivers/media/dvb/cinergyT2/Kconfig
+++ b/drivers/media/dvb/cinergyT2/Kconfig
@@ -77,7 +77,7 @@ config DVB_CINERGYT2_ENABLE_RC_INPUT_DEVICE
77config DVB_CINERGYT2_RC_QUERY_INTERVAL 77config DVB_CINERGYT2_RC_QUERY_INTERVAL
78 int "Infrared Remote Controller update interval [milliseconds]" 78 int "Infrared Remote Controller update interval [milliseconds]"
79 depends on DVB_CINERGYT2_TUNING && DVB_CINERGYT2_ENABLE_RC_INPUT_DEVICE 79 depends on DVB_CINERGYT2_TUNING && DVB_CINERGYT2_ENABLE_RC_INPUT_DEVICE
80 default "100" 80 default "50"
81 help 81 help
82 If you have a very fast-repeating remote control you can try lower 82 If you have a very fast-repeating remote control you can try lower
83 values, for normal consumer receivers the default value should be 83 values, for normal consumer receivers the default value should be
diff --git a/drivers/media/dvb/cinergyT2/cinergyT2.c b/drivers/media/dvb/cinergyT2/cinergyT2.c
index 9ea5747b12..6db0929ef5 100644
--- a/drivers/media/dvb/cinergyT2/cinergyT2.c
+++ b/drivers/media/dvb/cinergyT2/cinergyT2.c
@@ -25,7 +25,6 @@
25#include <linux/config.h> 25#include <linux/config.h>
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/version.h>
29#include <linux/slab.h> 28#include <linux/slab.h>
30#include <linux/usb.h> 29#include <linux/usb.h>
31#include <linux/pci.h> 30#include <linux/pci.h>
@@ -36,7 +35,6 @@
36#include "dvb_demux.h" 35#include "dvb_demux.h"
37#include "dvb_net.h" 36#include "dvb_net.h"
38 37
39
40#ifdef CONFIG_DVB_CINERGYT2_TUNING 38#ifdef CONFIG_DVB_CINERGYT2_TUNING
41 #define STREAM_URB_COUNT (CONFIG_DVB_CINERGYT2_STREAM_URB_COUNT) 39 #define STREAM_URB_COUNT (CONFIG_DVB_CINERGYT2_STREAM_URB_COUNT)
42 #define STREAM_BUF_SIZE (CONFIG_DVB_CINERGYT2_STREAM_BUF_SIZE) 40 #define STREAM_BUF_SIZE (CONFIG_DVB_CINERGYT2_STREAM_BUF_SIZE)
@@ -49,7 +47,7 @@
49 #define STREAM_URB_COUNT (32) 47 #define STREAM_URB_COUNT (32)
50 #define STREAM_BUF_SIZE (512) /* bytes */ 48 #define STREAM_BUF_SIZE (512) /* bytes */
51 #define ENABLE_RC (1) 49 #define ENABLE_RC (1)
52 #define RC_QUERY_INTERVAL (100) /* milliseconds */ 50 #define RC_QUERY_INTERVAL (50) /* milliseconds */
53 #define QUERY_INTERVAL (333) /* milliseconds */ 51 #define QUERY_INTERVAL (333) /* milliseconds */
54#endif 52#endif
55 53
@@ -142,6 +140,8 @@ struct cinergyt2 {
142 struct input_dev rc_input_dev; 140 struct input_dev rc_input_dev;
143 struct work_struct rc_query_work; 141 struct work_struct rc_query_work;
144 int rc_input_event; 142 int rc_input_event;
143 u32 rc_last_code;
144 unsigned long last_event_jiffies;
145#endif 145#endif
146}; 146};
147 147
@@ -156,7 +156,7 @@ struct cinergyt2_rc_event {
156 uint32_t value; 156 uint32_t value;
157} __attribute__((packed)); 157} __attribute__((packed));
158 158
159static const uint32_t rc_keys [] = { 159static const uint32_t rc_keys[] = {
160 CINERGYT2_RC_EVENT_TYPE_NEC, 0xfe01eb04, KEY_POWER, 160 CINERGYT2_RC_EVENT_TYPE_NEC, 0xfe01eb04, KEY_POWER,
161 CINERGYT2_RC_EVENT_TYPE_NEC, 0xfd02eb04, KEY_1, 161 CINERGYT2_RC_EVENT_TYPE_NEC, 0xfd02eb04, KEY_1,
162 CINERGYT2_RC_EVENT_TYPE_NEC, 0xfc03eb04, KEY_2, 162 CINERGYT2_RC_EVENT_TYPE_NEC, 0xfc03eb04, KEY_2,
@@ -685,52 +685,68 @@ static struct dvb_device cinergyt2_fe_template = {
685#ifdef ENABLE_RC 685#ifdef ENABLE_RC
686static void cinergyt2_query_rc (void *data) 686static void cinergyt2_query_rc (void *data)
687{ 687{
688 struct cinergyt2 *cinergyt2 = (struct cinergyt2 *) data; 688 struct cinergyt2 *cinergyt2 = data;
689 char buf [1] = { CINERGYT2_EP1_GET_RC_EVENTS }; 689 char buf[1] = { CINERGYT2_EP1_GET_RC_EVENTS };
690 struct cinergyt2_rc_event rc_events[12]; 690 struct cinergyt2_rc_event rc_events[12];
691 int n, len; 691 int n, len, i;
692 692
693 if (down_interruptible(&cinergyt2->sem)) 693 if (down_interruptible(&cinergyt2->sem))
694 return; 694 return;
695 695
696 len = cinergyt2_command(cinergyt2, buf, sizeof(buf), 696 len = cinergyt2_command(cinergyt2, buf, sizeof(buf),
697 (char *) rc_events, sizeof(rc_events)); 697 (char *) rc_events, sizeof(rc_events));
698 698 if (len < 0)
699 for (n=0; len>0 && n<(len/sizeof(rc_events[0])); n++) { 699 goto out;
700 int i; 700 if (len == 0) {
701 if (time_after(jiffies, cinergyt2->last_event_jiffies +
702 msecs_to_jiffies(150))) {
703 /* stop key repeat */
704 if (cinergyt2->rc_input_event != KEY_MAX) {
705 dprintk(1, "rc_input_event=%d Up\n", cinergyt2->rc_input_event);
706 input_report_key(&cinergyt2->rc_input_dev,
707 cinergyt2->rc_input_event, 0);
708 cinergyt2->rc_input_event = KEY_MAX;
709 }
710 cinergyt2->rc_last_code = ~0;
711 }
712 goto out;
713 }
714 cinergyt2->last_event_jiffies = jiffies;
701 715
702/* dprintk(1,"rc_events[%d].value = %x, type=%x\n",n,le32_to_cpu(rc_events[n].value),rc_events[n].type);*/ 716 for (n = 0; n < (len / sizeof(rc_events[0])); n++) {
717 dprintk(1, "rc_events[%d].value = %x, type=%x\n",
718 n, le32_to_cpu(rc_events[n].value), rc_events[n].type);
703 719
704 if (rc_events[n].type == CINERGYT2_RC_EVENT_TYPE_NEC && 720 if (rc_events[n].type == CINERGYT2_RC_EVENT_TYPE_NEC &&
705 rc_events[n].value == ~0) 721 rc_events[n].value == ~0) {
706 { 722 /* keyrepeat bit -> just repeat last rc_input_event */
707 /**
708 * keyrepeat bit. If we would handle this properly
709 * we would need to emit down events as long the
710 * keyrepeat goes, a up event if no further
711 * repeat bits occur. Would need a timer to implement
712 * and no other driver does this, so we simply
713 * emit the last key up/down sequence again.
714 */
715 } else { 723 } else {
716 cinergyt2->rc_input_event = KEY_MAX; 724 cinergyt2->rc_input_event = KEY_MAX;
717 for (i=0; i<sizeof(rc_keys)/sizeof(rc_keys[0]); i+=3) { 725 for (i = 0; i < sizeof(rc_keys) / sizeof(rc_keys[0]); i += 3) {
718 if (rc_keys[i+0] == rc_events[n].type && 726 if (rc_keys[i + 0] == rc_events[n].type &&
719 rc_keys[i+1] == le32_to_cpu(rc_events[n].value)) 727 rc_keys[i + 1] == le32_to_cpu(rc_events[n].value)) {
720 { 728 cinergyt2->rc_input_event = rc_keys[i + 2];
721 cinergyt2->rc_input_event = rc_keys[i+2];
722 break; 729 break;
723 } 730 }
724 } 731 }
725 } 732 }
726 733
727 if (cinergyt2->rc_input_event != KEY_MAX) { 734 if (cinergyt2->rc_input_event != KEY_MAX) {
728 input_report_key(&cinergyt2->rc_input_dev, cinergyt2->rc_input_event, 1); 735 if (rc_events[n].value == cinergyt2->rc_last_code &&
729 input_report_key(&cinergyt2->rc_input_dev, cinergyt2->rc_input_event, 0); 736 cinergyt2->rc_last_code != ~0) {
730 input_sync(&cinergyt2->rc_input_dev); 737 /* emit a key-up so the double event is recognized */
738 dprintk(1, "rc_input_event=%d UP\n", cinergyt2->rc_input_event);
739 input_report_key(&cinergyt2->rc_input_dev,
740 cinergyt2->rc_input_event, 0);
741 }
742 dprintk(1, "rc_input_event=%d\n", cinergyt2->rc_input_event);
743 input_report_key(&cinergyt2->rc_input_dev,
744 cinergyt2->rc_input_event, 1);
745 cinergyt2->rc_last_code = rc_events[n].value;
731 } 746 }
732 } 747 }
733 748
749out:
734 schedule_delayed_work(&cinergyt2->rc_query_work, 750 schedule_delayed_work(&cinergyt2->rc_query_work,
735 msecs_to_jiffies(RC_QUERY_INTERVAL)); 751 msecs_to_jiffies(RC_QUERY_INTERVAL));
736 752
@@ -772,7 +788,10 @@ static int cinergyt2_probe (struct usb_interface *intf,
772 const struct usb_device_id *id) 788 const struct usb_device_id *id)
773{ 789{
774 struct cinergyt2 *cinergyt2; 790 struct cinergyt2 *cinergyt2;
775 int i, err; 791 int err;
792#ifdef ENABLE_RC
793 int i;
794#endif
776 795
777 if (!(cinergyt2 = kmalloc (sizeof(struct cinergyt2), GFP_KERNEL))) { 796 if (!(cinergyt2 = kmalloc (sizeof(struct cinergyt2), GFP_KERNEL))) {
778 dprintk(1, "out of memory?!?\n"); 797 dprintk(1, "out of memory?!?\n");
@@ -828,19 +847,18 @@ static int cinergyt2_probe (struct usb_interface *intf,
828 DVB_DEVICE_FRONTEND); 847 DVB_DEVICE_FRONTEND);
829 848
830#ifdef ENABLE_RC 849#ifdef ENABLE_RC
831 init_input_dev(&cinergyt2->rc_input_dev); 850 cinergyt2->rc_input_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
832 851 cinergyt2->rc_input_dev.keycodesize = 0;
833 cinergyt2->rc_input_dev.evbit[0] = BIT(EV_KEY); 852 cinergyt2->rc_input_dev.keycodemax = 0;
834 cinergyt2->rc_input_dev.keycodesize = sizeof(unsigned char);
835 cinergyt2->rc_input_dev.keycodemax = KEY_MAX;
836 cinergyt2->rc_input_dev.name = DRIVER_NAME " remote control"; 853 cinergyt2->rc_input_dev.name = DRIVER_NAME " remote control";
837 854
838 for (i=0; i<sizeof(rc_keys)/sizeof(rc_keys[0]); i+=3) 855 for (i = 0; i < sizeof(rc_keys) / sizeof(rc_keys[0]); i += 3)
839 set_bit(rc_keys[i+2], cinergyt2->rc_input_dev.keybit); 856 set_bit(rc_keys[i + 2], cinergyt2->rc_input_dev.keybit);
840 857
841 input_register_device(&cinergyt2->rc_input_dev); 858 input_register_device(&cinergyt2->rc_input_dev);
842 859
843 cinergyt2->rc_input_event = KEY_MAX; 860 cinergyt2->rc_input_event = KEY_MAX;
861 cinergyt2->rc_last_code = ~0;
844 862
845 INIT_WORK(&cinergyt2->rc_query_work, cinergyt2_query_rc, cinergyt2); 863 INIT_WORK(&cinergyt2->rc_query_work, cinergyt2_query_rc, cinergyt2);
846 schedule_delayed_work(&cinergyt2->rc_query_work, HZ/2); 864 schedule_delayed_work(&cinergyt2->rc_query_work, HZ/2);
diff --git a/drivers/media/dvb/dvb-core/demux.h b/drivers/media/dvb/dvb-core/demux.h
index fb55eaa5c8..9719a3b30f 100644
--- a/drivers/media/dvb/dvb-core/demux.h
+++ b/drivers/media/dvb/dvb-core/demux.h
@@ -30,6 +30,7 @@
30#include <linux/errno.h> 30#include <linux/errno.h>
31#include <linux/list.h> 31#include <linux/list.h>
32#include <linux/time.h> 32#include <linux/time.h>
33#include <linux/dvb/dmx.h>
33 34
34/*--------------------------------------------------------------------------*/ 35/*--------------------------------------------------------------------------*/
35/* Common definitions */ 36/* Common definitions */
@@ -124,9 +125,7 @@ struct dmx_ts_feed {
124 u16 pid, 125 u16 pid,
125 int type, 126 int type,
126 enum dmx_ts_pes pes_type, 127 enum dmx_ts_pes pes_type,
127 size_t callback_length,
128 size_t circular_buffer_size, 128 size_t circular_buffer_size,
129 int descramble,
130 struct timespec timeout); 129 struct timespec timeout);
131 int (*start_filtering) (struct dmx_ts_feed* feed); 130 int (*start_filtering) (struct dmx_ts_feed* feed);
132 int (*stop_filtering) (struct dmx_ts_feed* feed); 131 int (*stop_filtering) (struct dmx_ts_feed* feed);
@@ -159,7 +158,6 @@ struct dmx_section_feed {
159 int (*set) (struct dmx_section_feed* feed, 158 int (*set) (struct dmx_section_feed* feed,
160 u16 pid, 159 u16 pid,
161 size_t circular_buffer_size, 160 size_t circular_buffer_size,
162 int descramble,
163 int check_crc); 161 int check_crc);
164 int (*allocate_filter) (struct dmx_section_feed* feed, 162 int (*allocate_filter) (struct dmx_section_feed* feed,
165 struct dmx_section_filter** filter); 163 struct dmx_section_filter** filter);
@@ -207,7 +205,6 @@ struct dmx_frontend {
207 struct list_head connectivity_list; /* List of front-ends that can 205 struct list_head connectivity_list; /* List of front-ends that can
208 be connected to a particular 206 be connected to a particular
209 demux */ 207 demux */
210 void* priv; /* Pointer to private data of the API client */
211 enum dmx_frontend_source source; 208 enum dmx_frontend_source source;
212}; 209};
213 210
@@ -225,8 +222,6 @@ struct dmx_frontend {
225#define DMX_MEMORY_BASED_FILTERING 8 /* write() available */ 222#define DMX_MEMORY_BASED_FILTERING 8 /* write() available */
226#define DMX_CRC_CHECKING 16 223#define DMX_CRC_CHECKING 16
227#define DMX_TS_DESCRAMBLING 32 224#define DMX_TS_DESCRAMBLING 32
228#define DMX_SECTION_PAYLOAD_DESCRAMBLING 64
229#define DMX_MAC_ADDRESS_DESCRAMBLING 128
230 225
231/* 226/*
232 * Demux resource type identifier. 227 * Demux resource type identifier.
@@ -244,9 +239,7 @@ struct dmx_frontend {
244struct dmx_demux { 239struct dmx_demux {
245 u32 capabilities; /* Bitfield of capability flags */ 240 u32 capabilities; /* Bitfield of capability flags */
246 struct dmx_frontend* frontend; /* Front-end connected to the demux */ 241 struct dmx_frontend* frontend; /* Front-end connected to the demux */
247 struct list_head reg_list; /* List of registered demuxes */
248 void* priv; /* Pointer to private data of the API client */ 242 void* priv; /* Pointer to private data of the API client */
249 int users; /* Number of users */
250 int (*open) (struct dmx_demux* demux); 243 int (*open) (struct dmx_demux* demux);
251 int (*close) (struct dmx_demux* demux); 244 int (*close) (struct dmx_demux* demux);
252 int (*write) (struct dmx_demux* demux, const char* buf, size_t count); 245 int (*write) (struct dmx_demux* demux, const char* buf, size_t count);
@@ -260,17 +253,6 @@ struct dmx_demux {
260 dmx_section_cb callback); 253 dmx_section_cb callback);
261 int (*release_section_feed) (struct dmx_demux* demux, 254 int (*release_section_feed) (struct dmx_demux* demux,
262 struct dmx_section_feed* feed); 255 struct dmx_section_feed* feed);
263 int (*descramble_mac_address) (struct dmx_demux* demux,
264 u8* buffer1,
265 size_t buffer1_length,
266 u8* buffer2,
267 size_t buffer2_length,
268 u16 pid);
269 int (*descramble_section_payload) (struct dmx_demux* demux,
270 u8* buffer1,
271 size_t buffer1_length,
272 u8* buffer2, size_t buffer2_length,
273 u16 pid);
274 int (*add_frontend) (struct dmx_demux* demux, 256 int (*add_frontend) (struct dmx_demux* demux,
275 struct dmx_frontend* frontend); 257 struct dmx_frontend* frontend);
276 int (*remove_frontend) (struct dmx_demux* demux, 258 int (*remove_frontend) (struct dmx_demux* demux,
@@ -282,20 +264,12 @@ struct dmx_demux {
282 264
283 int (*get_pes_pids) (struct dmx_demux* demux, u16 *pids); 265 int (*get_pes_pids) (struct dmx_demux* demux, u16 *pids);
284 266
267 int (*get_caps) (struct dmx_demux* demux, struct dmx_caps *caps);
268
269 int (*set_source) (struct dmx_demux* demux, const dmx_source_t *src);
270
285 int (*get_stc) (struct dmx_demux* demux, unsigned int num, 271 int (*get_stc) (struct dmx_demux* demux, unsigned int num,
286 u64 *stc, unsigned int *base); 272 u64 *stc, unsigned int *base);
287}; 273};
288 274
289/*--------------------------------------------------------------------------*/
290/* Demux directory */
291/*--------------------------------------------------------------------------*/
292
293/*
294 * DMX_DIR_ENTRY(): Casts elements in the list of registered
295 * demuxes from the generic type struct list_head* to the type struct dmx_demux
296 *.
297 */
298
299#define DMX_DIR_ENTRY(list) list_entry(list, struct dmx_demux, reg_list)
300
301#endif /* #ifndef __DEMUX_H */ 275#endif /* #ifndef __DEMUX_H */
diff --git a/drivers/media/dvb/dvb-core/dmxdev.c b/drivers/media/dvb/dvb-core/dmxdev.c
index 68050cd527..8028c3a5e2 100644
--- a/drivers/media/dvb/dvb-core/dmxdev.c
+++ b/drivers/media/dvb/dvb-core/dmxdev.c
@@ -571,7 +571,7 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
571 return ret; 571 return ret;
572 } 572 }
573 573
574 ret=(*secfeed)->set(*secfeed, para->pid, 32768, 0, 574 ret=(*secfeed)->set(*secfeed, para->pid, 32768,
575 (para->flags & DMX_CHECK_CRC) ? 1 : 0); 575 (para->flags & DMX_CHECK_CRC) ? 1 : 0);
576 576
577 if (ret<0) { 577 if (ret<0) {
@@ -654,7 +654,7 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
654 (*tsfeed)->priv = (void *) filter; 654 (*tsfeed)->priv = (void *) filter;
655 655
656 ret = (*tsfeed)->set(*tsfeed, para->pid, ts_type, ts_pes, 656 ret = (*tsfeed)->set(*tsfeed, para->pid, ts_type, ts_pes,
657 188, 32768, 0, timeout); 657 32768, timeout);
658 658
659 if (ret < 0) { 659 if (ret < 0) {
660 dmxdev->demux->release_ts_feed(dmxdev->demux, *tsfeed); 660 dmxdev->demux->release_ts_feed(dmxdev->demux, *tsfeed);
@@ -929,6 +929,22 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
929 dmxdev->demux->get_pes_pids(dmxdev->demux, (u16 *)parg); 929 dmxdev->demux->get_pes_pids(dmxdev->demux, (u16 *)parg);
930 break; 930 break;
931 931
932 case DMX_GET_CAPS:
933 if (!dmxdev->demux->get_caps) {
934 ret = -EINVAL;
935 break;
936 }
937 ret = dmxdev->demux->get_caps(dmxdev->demux, parg);
938 break;
939
940 case DMX_SET_SOURCE:
941 if (!dmxdev->demux->set_source) {
942 ret = -EINVAL;
943 break;
944 }
945 ret = dmxdev->demux->set_source(dmxdev->demux, parg);
946 break;
947
932 case DMX_GET_STC: 948 case DMX_GET_STC:
933 if (!dmxdev->demux->get_stc) { 949 if (!dmxdev->demux->get_stc) {
934 ret=-EINVAL; 950 ret=-EINVAL;
diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
index 0eb9aa711f..88757e2634 100644
--- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
@@ -47,7 +47,7 @@ MODULE_PARM_DESC(cam_debug, "enable verbose debug messages");
47 47
48#define dprintk if (dvb_ca_en50221_debug) printk 48#define dprintk if (dvb_ca_en50221_debug) printk
49 49
50#define INIT_TIMEOUT_SECS 5 50#define INIT_TIMEOUT_SECS 10
51 51
52#define HOST_LINK_BUF_SIZE 0x200 52#define HOST_LINK_BUF_SIZE 0x200
53 53
diff --git a/drivers/media/dvb/dvb-core/dvb_demux.c b/drivers/media/dvb/dvb-core/dvb_demux.c
index ac9889d222..dc476dda2b 100644
--- a/drivers/media/dvb/dvb-core/dvb_demux.c
+++ b/drivers/media/dvb/dvb-core/dvb_demux.c
@@ -38,82 +38,52 @@
38*/ 38*/
39// #define DVB_DEMUX_SECTION_LOSS_LOG 39// #define DVB_DEMUX_SECTION_LOSS_LOG
40 40
41
42static LIST_HEAD(dmx_muxs);
43
44
45static int dmx_register_demux(struct dmx_demux *demux)
46{
47 demux->users = 0;
48 list_add(&demux->reg_list, &dmx_muxs);
49 return 0;
50}
51
52static int dmx_unregister_demux(struct dmx_demux* demux)
53{
54 struct list_head *pos, *n, *head=&dmx_muxs;
55
56 list_for_each_safe (pos, n, head) {
57 if (DMX_DIR_ENTRY(pos) == demux) {
58 if (demux->users>0)
59 return -EINVAL;
60 list_del(pos);
61 return 0;
62 }
63 }
64
65 return -ENODEV;
66}
67
68
69/****************************************************************************** 41/******************************************************************************
70 * static inlined helper functions 42 * static inlined helper functions
71 ******************************************************************************/ 43 ******************************************************************************/
72 44
73
74static inline u16 section_length(const u8 *buf) 45static inline u16 section_length(const u8 *buf)
75{ 46{
76 return 3+((buf[1]&0x0f)<<8)+buf[2]; 47 return 3 + ((buf[1] & 0x0f) << 8) + buf[2];
77} 48}
78 49
79
80static inline u16 ts_pid(const u8 *buf) 50static inline u16 ts_pid(const u8 *buf)
81{ 51{
82 return ((buf[1]&0x1f)<<8)+buf[2]; 52 return ((buf[1] & 0x1f) << 8) + buf[2];
83} 53}
84 54
85
86static inline u8 payload(const u8 *tsp) 55static inline u8 payload(const u8 *tsp)
87{ 56{
88 if (!(tsp[3] & 0x10)) // no payload? 57 if (!(tsp[3] & 0x10)) // no payload?
89 return 0; 58 return 0;
90 if (tsp[3] & 0x20) { // adaptation field? 59
91 if (tsp[4] > 183) // corrupted data? 60 if (tsp[3] & 0x20) { // adaptation field?
61 if (tsp[4] > 183) // corrupted data?
92 return 0; 62 return 0;
93 else 63 else
94 return 184-1-tsp[4]; 64 return 184 - 1 - tsp[4];
95 } 65 }
66
96 return 184; 67 return 184;
97} 68}
98 69
99 70static u32 dvb_dmx_crc32(struct dvb_demux_feed *f, const u8 *src, size_t len)
100static u32 dvb_dmx_crc32 (struct dvb_demux_feed *f, const u8 *src, size_t len)
101{ 71{
102 return (f->feed.sec.crc_val = crc32_be (f->feed.sec.crc_val, src, len)); 72 return (f->feed.sec.crc_val = crc32_be(f->feed.sec.crc_val, src, len));
103} 73}
104 74
105 75static void dvb_dmx_memcopy(struct dvb_demux_feed *f, u8 *d, const u8 *s,
106static void dvb_dmx_memcopy (struct dvb_demux_feed *f, u8 *d, const u8 *s, size_t len) 76 size_t len)
107{ 77{
108 memcpy (d, s, len); 78 memcpy(d, s, len);
109} 79}
110 80
111
112/****************************************************************************** 81/******************************************************************************
113 * Software filter functions 82 * Software filter functions
114 ******************************************************************************/ 83 ******************************************************************************/
115 84
116static inline int dvb_dmx_swfilter_payload (struct dvb_demux_feed *feed, const u8 *buf) 85static inline int dvb_dmx_swfilter_payload(struct dvb_demux_feed *feed,
86 const u8 *buf)
117{ 87{
118 int count = payload(buf); 88 int count = payload(buf);
119 int p; 89 int p;
@@ -123,32 +93,31 @@ static inline int dvb_dmx_swfilter_payload (struct dvb_demux_feed *feed, const u
123 if (count == 0) 93 if (count == 0)
124 return -1; 94 return -1;
125 95
126 p = 188-count; 96 p = 188 - count;
127 97
128 /* 98 /*
129 cc=buf[3]&0x0f; 99 cc = buf[3] & 0x0f;
130 ccok=((dvbdmxfeed->cc+1)&0x0f)==cc ? 1 : 0; 100 ccok = ((feed->cc + 1) & 0x0f) == cc;
131 dvbdmxfeed->cc=cc; 101 feed->cc = cc;
132 if (!ccok) 102 if (!ccok)
133 printk("missed packet!\n"); 103 printk("missed packet!\n");
134 */ 104 */
135 105
136 if (buf[1] & 0x40) // PUSI ? 106 if (buf[1] & 0x40) // PUSI ?
137 feed->peslen = 0xfffa; 107 feed->peslen = 0xfffa;
138 108
139 feed->peslen += count; 109 feed->peslen += count;
140 110
141 return feed->cb.ts (&buf[p], count, NULL, 0, &feed->feed.ts, DMX_OK); 111 return feed->cb.ts(&buf[p], count, NULL, 0, &feed->feed.ts, DMX_OK);
142} 112}
143 113
144 114static int dvb_dmx_swfilter_sectionfilter(struct dvb_demux_feed *feed,
145static int dvb_dmx_swfilter_sectionfilter (struct dvb_demux_feed *feed, 115 struct dvb_demux_filter *f)
146 struct dvb_demux_filter *f)
147{ 116{
148 u8 neq = 0; 117 u8 neq = 0;
149 int i; 118 int i;
150 119
151 for (i=0; i<DVB_DEMUX_MASK_MAX; i++) { 120 for (i = 0; i < DVB_DEMUX_MASK_MAX; i++) {
152 u8 xor = f->filter.filter_value[i] ^ feed->feed.sec.secbuf[i]; 121 u8 xor = f->filter.filter_value[i] ^ feed->feed.sec.secbuf[i];
153 122
154 if (f->maskandmode[i] & xor) 123 if (f->maskandmode[i] & xor)
@@ -160,12 +129,11 @@ static int dvb_dmx_swfilter_sectionfilter (struct dvb_demux_feed *feed,
160 if (f->doneq && !neq) 129 if (f->doneq && !neq)
161 return 0; 130 return 0;
162 131
163 return feed->cb.sec (feed->feed.sec.secbuf, feed->feed.sec.seclen, 132 return feed->cb.sec(feed->feed.sec.secbuf, feed->feed.sec.seclen,
164 NULL, 0, &f->filter, DMX_OK); 133 NULL, 0, &f->filter, DMX_OK);
165} 134}
166 135
167 136static inline int dvb_dmx_swfilter_section_feed(struct dvb_demux_feed *feed)
168static inline int dvb_dmx_swfilter_section_feed (struct dvb_demux_feed *feed)
169{ 137{
170 struct dvb_demux *demux = feed->demux; 138 struct dvb_demux *demux = feed->demux;
171 struct dvb_demux_filter *f = feed->filter; 139 struct dvb_demux_filter *f = feed->filter;
@@ -195,26 +163,24 @@ static inline int dvb_dmx_swfilter_section_feed (struct dvb_demux_feed *feed)
195 return 0; 163 return 0;
196} 164}
197 165
198
199static void dvb_dmx_swfilter_section_new(struct dvb_demux_feed *feed) 166static void dvb_dmx_swfilter_section_new(struct dvb_demux_feed *feed)
200{ 167{
201 struct dmx_section_feed *sec = &feed->feed.sec; 168 struct dmx_section_feed *sec = &feed->feed.sec;
202 169
203#ifdef DVB_DEMUX_SECTION_LOSS_LOG 170#ifdef DVB_DEMUX_SECTION_LOSS_LOG
204 if(sec->secbufp < sec->tsfeedp) 171 if (sec->secbufp < sec->tsfeedp) {
205 {
206 int i, n = sec->tsfeedp - sec->secbufp; 172 int i, n = sec->tsfeedp - sec->secbufp;
207 173
208 /* section padding is done with 0xff bytes entirely. 174 /*
209 ** due to speed reasons, we won't check all of them 175 * Section padding is done with 0xff bytes entirely.
210 ** but just first and last 176 * Due to speed reasons, we won't check all of them
211 */ 177 * but just first and last.
212 if(sec->secbuf[0] != 0xff || sec->secbuf[n-1] != 0xff) 178 */
213 { 179 if (sec->secbuf[0] != 0xff || sec->secbuf[n - 1] != 0xff) {
214 printk("dvb_demux.c section ts padding loss: %d/%d\n", 180 printk("dvb_demux.c section ts padding loss: %d/%d\n",
215 n, sec->tsfeedp); 181 n, sec->tsfeedp);
216 printk("dvb_demux.c pad data:"); 182 printk("dvb_demux.c pad data:");
217 for(i = 0; i < n; i++) 183 for (i = 0; i < n; i++)
218 printk(" %02x", sec->secbuf[i]); 184 printk(" %02x", sec->secbuf[i]);
219 printk("\n"); 185 printk("\n");
220 } 186 }
@@ -226,82 +192,81 @@ static void dvb_dmx_swfilter_section_new(struct dvb_demux_feed *feed)
226} 192}
227 193
228/* 194/*
229** Losless Section Demux 1.4.1 by Emard 195 * Losless Section Demux 1.4.1 by Emard
230** Valsecchi Patrick: 196 * Valsecchi Patrick:
231** - middle of section A (no PUSI) 197 * - middle of section A (no PUSI)
232** - end of section A and start of section B 198 * - end of section A and start of section B
233** (with PUSI pointing to the start of the second section) 199 * (with PUSI pointing to the start of the second section)
234** 200 *
235** In this case, without feed->pusi_seen you'll receive a garbage section 201 * In this case, without feed->pusi_seen you'll receive a garbage section
236** consisting of the end of section A. Basically because tsfeedp 202 * consisting of the end of section A. Basically because tsfeedp
237** is incemented and the use=0 condition is not raised 203 * is incemented and the use=0 condition is not raised
238** when the second packet arrives. 204 * when the second packet arrives.
239** 205 *
240** Fix: 206 * Fix:
241** when demux is started, let feed->pusi_seen = 0 to 207 * when demux is started, let feed->pusi_seen = 0 to
242** prevent initial feeding of garbage from the end of 208 * prevent initial feeding of garbage from the end of
243** previous section. When you for the first time see PUSI=1 209 * previous section. When you for the first time see PUSI=1
244** then set feed->pusi_seen = 1 210 * then set feed->pusi_seen = 1
245*/ 211 */
246static int dvb_dmx_swfilter_section_copy_dump(struct dvb_demux_feed *feed, const u8 *buf, u8 len) 212static int dvb_dmx_swfilter_section_copy_dump(struct dvb_demux_feed *feed,
213 const u8 *buf, u8 len)
247{ 214{
248 struct dvb_demux *demux = feed->demux; 215 struct dvb_demux *demux = feed->demux;
249 struct dmx_section_feed *sec = &feed->feed.sec; 216 struct dmx_section_feed *sec = &feed->feed.sec;
250 u16 limit, seclen, n; 217 u16 limit, seclen, n;
251 218
252 if(sec->tsfeedp >= DMX_MAX_SECFEED_SIZE) 219 if (sec->tsfeedp >= DMX_MAX_SECFEED_SIZE)
253 return 0; 220 return 0;
254 221
255 if(sec->tsfeedp + len > DMX_MAX_SECFEED_SIZE) 222 if (sec->tsfeedp + len > DMX_MAX_SECFEED_SIZE) {
256 {
257#ifdef DVB_DEMUX_SECTION_LOSS_LOG 223#ifdef DVB_DEMUX_SECTION_LOSS_LOG
258 printk("dvb_demux.c section buffer full loss: %d/%d\n", 224 printk("dvb_demux.c section buffer full loss: %d/%d\n",
259 sec->tsfeedp + len - DMX_MAX_SECFEED_SIZE, DMX_MAX_SECFEED_SIZE); 225 sec->tsfeedp + len - DMX_MAX_SECFEED_SIZE,
226 DMX_MAX_SECFEED_SIZE);
260#endif 227#endif
261 len = DMX_MAX_SECFEED_SIZE - sec->tsfeedp; 228 len = DMX_MAX_SECFEED_SIZE - sec->tsfeedp;
262 } 229 }
263 230
264 if(len <= 0) 231 if (len <= 0)
265 return 0; 232 return 0;
266 233
267 demux->memcopy(feed, sec->secbuf_base + sec->tsfeedp, buf, len); 234 demux->memcopy(feed, sec->secbuf_base + sec->tsfeedp, buf, len);
268 sec->tsfeedp += len; 235 sec->tsfeedp += len;
269 236
270 /* ----------------------------------------------------- 237 /*
271 ** Dump all the sections we can find in the data (Emard) 238 * Dump all the sections we can find in the data (Emard)
272 */ 239 */
273
274 limit = sec->tsfeedp; 240 limit = sec->tsfeedp;
275 if(limit > DMX_MAX_SECFEED_SIZE) 241 if (limit > DMX_MAX_SECFEED_SIZE)
276 return -1; /* internal error should never happen */ 242 return -1; /* internal error should never happen */
277 243
278 /* to be sure always set secbuf */ 244 /* to be sure always set secbuf */
279 sec->secbuf = sec->secbuf_base + sec->secbufp; 245 sec->secbuf = sec->secbuf_base + sec->secbufp;
280 246
281 for(n = 0; sec->secbufp + 2 < limit; n++) 247 for (n = 0; sec->secbufp + 2 < limit; n++) {
282 {
283 seclen = section_length(sec->secbuf); 248 seclen = section_length(sec->secbuf);
284 if(seclen <= 0 || seclen > DMX_MAX_SECFEED_SIZE 249 if (seclen <= 0 || seclen > DMX_MAX_SECFEED_SIZE
285 || seclen + sec->secbufp > limit) 250 || seclen + sec->secbufp > limit)
286 return 0; 251 return 0;
287 sec->seclen = seclen; 252 sec->seclen = seclen;
288 sec->crc_val = ~0; 253 sec->crc_val = ~0;
289 /* dump [secbuf .. secbuf+seclen) */ 254 /* dump [secbuf .. secbuf+seclen) */
290 if(feed->pusi_seen) 255 if (feed->pusi_seen)
291 dvb_dmx_swfilter_section_feed(feed); 256 dvb_dmx_swfilter_section_feed(feed);
292#ifdef DVB_DEMUX_SECTION_LOSS_LOG 257#ifdef DVB_DEMUX_SECTION_LOSS_LOG
293 else 258 else
294 printk("dvb_demux.c pusi not seen, discarding section data\n"); 259 printk("dvb_demux.c pusi not seen, discarding section data\n");
295#endif 260#endif
296 sec->secbufp += seclen; /* secbufp and secbuf moving together is */ 261 sec->secbufp += seclen; /* secbufp and secbuf moving together is */
297 sec->secbuf += seclen; /* redundand but saves pointer arithmetic */ 262 sec->secbuf += seclen; /* redundant but saves pointer arithmetic */
298 } 263 }
299 264
300 return 0; 265 return 0;
301} 266}
302 267
303 268static int dvb_dmx_swfilter_section_packet(struct dvb_demux_feed *feed,
304static int dvb_dmx_swfilter_section_packet(struct dvb_demux_feed *feed, const u8 *buf) 269 const u8 *buf)
305{ 270{
306 u8 p, count; 271 u8 p, count;
307 int ccok, dc_i = 0; 272 int ccok, dc_i = 0;
@@ -309,10 +274,10 @@ static int dvb_dmx_swfilter_section_packet(struct dvb_demux_feed *feed, const u8
309 274
310 count = payload(buf); 275 count = payload(buf);
311 276
312 if (count == 0) /* count == 0 if no payload or out of range */ 277 if (count == 0) /* count == 0 if no payload or out of range */
313 return -1; 278 return -1;
314 279
315 p = 188 - count; /* payload start */ 280 p = 188 - count; /* payload start */
316 281
317 cc = buf[3] & 0x0f; 282 cc = buf[3] & 0x0f;
318 ccok = ((feed->cc + 1) & 0x0f) == cc; 283 ccok = ((feed->cc + 1) & 0x0f) == cc;
@@ -326,52 +291,53 @@ static int dvb_dmx_swfilter_section_packet(struct dvb_demux_feed *feed, const u8
326 291
327 if (!ccok || dc_i) { 292 if (!ccok || dc_i) {
328#ifdef DVB_DEMUX_SECTION_LOSS_LOG 293#ifdef DVB_DEMUX_SECTION_LOSS_LOG
329 printk("dvb_demux.c discontinuity detected %d bytes lost\n", count); 294 printk("dvb_demux.c discontinuity detected %d bytes lost\n",
330 /* those bytes under sume circumstances will again be reported 295 count);
331 ** in the following dvb_dmx_swfilter_section_new 296 /*
332 */ 297 * those bytes under sume circumstances will again be reported
298 * in the following dvb_dmx_swfilter_section_new
299 */
333#endif 300#endif
334 /* Discontinuity detected. Reset pusi_seen = 0 to 301 /*
335 ** stop feeding of suspicious data until next PUSI=1 arrives 302 * Discontinuity detected. Reset pusi_seen = 0 to
336 */ 303 * stop feeding of suspicious data until next PUSI=1 arrives
304 */
337 feed->pusi_seen = 0; 305 feed->pusi_seen = 0;
338 dvb_dmx_swfilter_section_new(feed); 306 dvb_dmx_swfilter_section_new(feed);
339 return 0;
340 } 307 }
341 308
342 if (buf[1] & 0x40) { 309 if (buf[1] & 0x40) {
343 // PUSI=1 (is set), section boundary is here 310 /* PUSI=1 (is set), section boundary is here */
344 if (count > 1 && buf[p] < count) { 311 if (count > 1 && buf[p] < count) {
345 const u8 *before = buf+p+1; 312 const u8 *before = &buf[p + 1];
346 u8 before_len = buf[p]; 313 u8 before_len = buf[p];
347 const u8 *after = before+before_len; 314 const u8 *after = &before[before_len];
348 u8 after_len = count-1-before_len; 315 u8 after_len = count - 1 - before_len;
349 316
350 dvb_dmx_swfilter_section_copy_dump(feed, before, before_len); 317 dvb_dmx_swfilter_section_copy_dump(feed, before,
318 before_len);
351 /* before start of new section, set pusi_seen = 1 */ 319 /* before start of new section, set pusi_seen = 1 */
352 feed->pusi_seen = 1; 320 feed->pusi_seen = 1;
353 dvb_dmx_swfilter_section_new(feed); 321 dvb_dmx_swfilter_section_new(feed);
354 dvb_dmx_swfilter_section_copy_dump(feed, after, after_len); 322 dvb_dmx_swfilter_section_copy_dump(feed, after,
323 after_len);
355 } 324 }
356#ifdef DVB_DEMUX_SECTION_LOSS_LOG 325#ifdef DVB_DEMUX_SECTION_LOSS_LOG
357 else 326 else if (count > 0)
358 if (count > 0) 327 printk("dvb_demux.c PUSI=1 but %d bytes lost\n", count);
359 printk("dvb_demux.c PUSI=1 but %d bytes lost\n", count);
360#endif 328#endif
361 } else { 329 } else {
362 // PUSI=0 (is not set), no section boundary 330 /* PUSI=0 (is not set), no section boundary */
363 const u8 *entire = buf+p; 331 dvb_dmx_swfilter_section_copy_dump(feed, &buf[p], count);
364 u8 entire_len = count;
365
366 dvb_dmx_swfilter_section_copy_dump(feed, entire, entire_len);
367 } 332 }
333
368 return 0; 334 return 0;
369} 335}
370 336
371 337static inline void dvb_dmx_swfilter_packet_type(struct dvb_demux_feed *feed,
372static inline void dvb_dmx_swfilter_packet_type(struct dvb_demux_feed *feed, const u8 *buf) 338 const u8 *buf)
373{ 339{
374 switch(feed->type) { 340 switch (feed->type) {
375 case DMX_TYPE_TS: 341 case DMX_TYPE_TS:
376 if (!feed->feed.ts.is_filtering) 342 if (!feed->feed.ts.is_filtering)
377 break; 343 break;
@@ -379,7 +345,8 @@ static inline void dvb_dmx_swfilter_packet_type(struct dvb_demux_feed *feed, con
379 if (feed->ts_type & TS_PAYLOAD_ONLY) 345 if (feed->ts_type & TS_PAYLOAD_ONLY)
380 dvb_dmx_swfilter_payload(feed, buf); 346 dvb_dmx_swfilter_payload(feed, buf);
381 else 347 else
382 feed->cb.ts(buf, 188, NULL, 0, &feed->feed.ts, DMX_OK); 348 feed->cb.ts(buf, 188, NULL, 0, &feed->feed.ts,
349 DMX_OK);
383 } 350 }
384 if (feed->ts_type & TS_DECODER) 351 if (feed->ts_type & TS_DECODER)
385 if (feed->demux->write_to_decoder) 352 if (feed->demux->write_to_decoder)
@@ -390,7 +357,7 @@ static inline void dvb_dmx_swfilter_packet_type(struct dvb_demux_feed *feed, con
390 if (!feed->feed.sec.is_filtering) 357 if (!feed->feed.sec.is_filtering)
391 break; 358 break;
392 if (dvb_dmx_swfilter_section_packet(feed, buf) < 0) 359 if (dvb_dmx_swfilter_section_packet(feed, buf) < 0)
393 feed->feed.sec.seclen = feed->feed.sec.secbufp=0; 360 feed->feed.sec.seclen = feed->feed.sec.secbufp = 0;
394 break; 361 break;
395 362
396 default: 363 default:
@@ -406,7 +373,7 @@ static inline void dvb_dmx_swfilter_packet_type(struct dvb_demux_feed *feed, con
406static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf) 373static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf)
407{ 374{
408 struct dvb_demux_feed *feed; 375 struct dvb_demux_feed *feed;
409 struct list_head *pos, *head=&demux->feed_list; 376 struct list_head *pos, *head = &demux->feed_list;
410 u16 pid = ts_pid(buf); 377 u16 pid = ts_pid(buf);
411 int dvr_done = 0; 378 int dvr_done = 0;
412 379
@@ -432,21 +399,21 @@ static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf)
432 } 399 }
433} 400}
434 401
435void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf, size_t count) 402void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf,
403 size_t count)
436{ 404{
437 spin_lock(&demux->lock); 405 spin_lock(&demux->lock);
438 406
439 while (count--) { 407 while (count--) {
440 if(buf[0] == 0x47) { 408 if (buf[0] == 0x47)
441 dvb_dmx_swfilter_packet(demux, buf); 409 dvb_dmx_swfilter_packet(demux, buf);
442 }
443 buf += 188; 410 buf += 188;
444 } 411 }
445 412
446 spin_unlock(&demux->lock); 413 spin_unlock(&demux->lock);
447} 414}
448EXPORT_SYMBOL(dvb_dmx_swfilter_packets);
449 415
416EXPORT_SYMBOL(dvb_dmx_swfilter_packets);
450 417
451void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count) 418void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count)
452{ 419{
@@ -454,8 +421,10 @@ void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count)
454 421
455 spin_lock(&demux->lock); 422 spin_lock(&demux->lock);
456 423
457 if ((i = demux->tsbufp)) { 424 if (demux->tsbufp) {
458 if (count < (j=188-i)) { 425 i = demux->tsbufp;
426 j = 188 - i;
427 if (count < j) {
459 memcpy(&demux->tsbuf[i], buf, count); 428 memcpy(&demux->tsbuf[i], buf, count);
460 demux->tsbufp += count; 429 demux->tsbufp += count;
461 goto bailout; 430 goto bailout;
@@ -469,13 +438,13 @@ void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count)
469 438
470 while (p < count) { 439 while (p < count) {
471 if (buf[p] == 0x47) { 440 if (buf[p] == 0x47) {
472 if (count-p >= 188) { 441 if (count - p >= 188) {
473 dvb_dmx_swfilter_packet(demux, buf+p); 442 dvb_dmx_swfilter_packet(demux, &buf[p]);
474 p += 188; 443 p += 188;
475 } else { 444 } else {
476 i = count-p; 445 i = count - p;
477 memcpy(demux->tsbuf, buf+p, i); 446 memcpy(demux->tsbuf, &buf[p], i);
478 demux->tsbufp=i; 447 demux->tsbufp = i;
479 goto bailout; 448 goto bailout;
480 } 449 }
481 } else 450 } else
@@ -485,24 +454,29 @@ void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count)
485bailout: 454bailout:
486 spin_unlock(&demux->lock); 455 spin_unlock(&demux->lock);
487} 456}
457
488EXPORT_SYMBOL(dvb_dmx_swfilter); 458EXPORT_SYMBOL(dvb_dmx_swfilter);
489 459
490void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf, size_t count) 460void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf, size_t count)
491{ 461{
492 int p = 0,i, j; 462 int p = 0, i, j;
493 u8 tmppack[188]; 463 u8 tmppack[188];
464
494 spin_lock(&demux->lock); 465 spin_lock(&demux->lock);
495 466
496 if ((i = demux->tsbufp)) { 467 if (demux->tsbufp) {
497 if (count < (j=204-i)) { 468 i = demux->tsbufp;
469 j = 204 - i;
470 if (count < j) {
498 memcpy(&demux->tsbuf[i], buf, count); 471 memcpy(&demux->tsbuf[i], buf, count);
499 demux->tsbufp += count; 472 demux->tsbufp += count;
500 goto bailout; 473 goto bailout;
501 } 474 }
502 memcpy(&demux->tsbuf[i], buf, j); 475 memcpy(&demux->tsbuf[i], buf, j);
503 if ((demux->tsbuf[0] == 0x47)|(demux->tsbuf[0]==0xB8)) { 476 if ((demux->tsbuf[0] == 0x47) | (demux->tsbuf[0] == 0xB8)) {
504 memcpy(tmppack, demux->tsbuf, 188); 477 memcpy(tmppack, demux->tsbuf, 188);
505 if (tmppack[0] == 0xB8) tmppack[0] = 0x47; 478 if (tmppack[0] == 0xB8)
479 tmppack[0] = 0x47;
506 dvb_dmx_swfilter_packet(demux, tmppack); 480 dvb_dmx_swfilter_packet(demux, tmppack);
507 } 481 }
508 demux->tsbufp = 0; 482 demux->tsbufp = 0;
@@ -510,16 +484,17 @@ void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf, size_t count)
510 } 484 }
511 485
512 while (p < count) { 486 while (p < count) {
513 if ((buf[p] == 0x47)|(buf[p] == 0xB8)) { 487 if ((buf[p] == 0x47) | (buf[p] == 0xB8)) {
514 if (count-p >= 204) { 488 if (count - p >= 204) {
515 memcpy(tmppack, buf+p, 188); 489 memcpy(tmppack, &buf[p], 188);
516 if (tmppack[0] == 0xB8) tmppack[0] = 0x47; 490 if (tmppack[0] == 0xB8)
491 tmppack[0] = 0x47;
517 dvb_dmx_swfilter_packet(demux, tmppack); 492 dvb_dmx_swfilter_packet(demux, tmppack);
518 p += 204; 493 p += 204;
519 } else { 494 } else {
520 i = count-p; 495 i = count - p;
521 memcpy(demux->tsbuf, buf+p, i); 496 memcpy(demux->tsbuf, &buf[p], i);
522 demux->tsbufp=i; 497 demux->tsbufp = i;
523 goto bailout; 498 goto bailout;
524 } 499 }
525 } else { 500 } else {
@@ -530,14 +505,14 @@ void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf, size_t count)
530bailout: 505bailout:
531 spin_unlock(&demux->lock); 506 spin_unlock(&demux->lock);
532} 507}
533EXPORT_SYMBOL(dvb_dmx_swfilter_204);
534 508
509EXPORT_SYMBOL(dvb_dmx_swfilter_204);
535 510
536static struct dvb_demux_filter * dvb_dmx_filter_alloc(struct dvb_demux *demux) 511static struct dvb_demux_filter *dvb_dmx_filter_alloc(struct dvb_demux *demux)
537{ 512{
538 int i; 513 int i;
539 514
540 for (i=0; i<demux->filternum; i++) 515 for (i = 0; i < demux->filternum; i++)
541 if (demux->filter[i].state == DMX_STATE_FREE) 516 if (demux->filter[i].state == DMX_STATE_FREE)
542 break; 517 break;
543 518
@@ -549,11 +524,11 @@ static struct dvb_demux_filter * dvb_dmx_filter_alloc(struct dvb_demux *demux)
549 return &demux->filter[i]; 524 return &demux->filter[i];
550} 525}
551 526
552static struct dvb_demux_feed * dvb_dmx_feed_alloc(struct dvb_demux *demux) 527static struct dvb_demux_feed *dvb_dmx_feed_alloc(struct dvb_demux *demux)
553{ 528{
554 int i; 529 int i;
555 530
556 for (i=0; i<demux->feednum; i++) 531 for (i = 0; i < demux->feednum; i++)
557 if (demux->feed[i].state == DMX_STATE_FREE) 532 if (demux->feed[i].state == DMX_STATE_FREE)
558 break; 533 break;
559 534
@@ -581,7 +556,7 @@ static void dvb_demux_feed_add(struct dvb_demux_feed *feed)
581 spin_lock_irq(&feed->demux->lock); 556 spin_lock_irq(&feed->demux->lock);
582 if (dvb_demux_feed_find(feed)) { 557 if (dvb_demux_feed_find(feed)) {
583 printk(KERN_ERR "%s: feed already in list (type=%x state=%x pid=%x)\n", 558 printk(KERN_ERR "%s: feed already in list (type=%x state=%x pid=%x)\n",
584 __FUNCTION__, feed->type, feed->state, feed->pid); 559 __FUNCTION__, feed->type, feed->state, feed->pid);
585 goto out; 560 goto out;
586 } 561 }
587 562
@@ -595,7 +570,7 @@ static void dvb_demux_feed_del(struct dvb_demux_feed *feed)
595 spin_lock_irq(&feed->demux->lock); 570 spin_lock_irq(&feed->demux->lock);
596 if (!(dvb_demux_feed_find(feed))) { 571 if (!(dvb_demux_feed_find(feed))) {
597 printk(KERN_ERR "%s: feed not in list (type=%x state=%x pid=%x)\n", 572 printk(KERN_ERR "%s: feed not in list (type=%x state=%x pid=%x)\n",
598 __FUNCTION__, feed->type, feed->state, feed->pid); 573 __FUNCTION__, feed->type, feed->state, feed->pid);
599 goto out; 574 goto out;
600 } 575 }
601 576
@@ -604,18 +579,17 @@ out:
604 spin_unlock_irq(&feed->demux->lock); 579 spin_unlock_irq(&feed->demux->lock);
605} 580}
606 581
607static int dmx_ts_feed_set (struct dmx_ts_feed* ts_feed, u16 pid, int ts_type, 582static int dmx_ts_feed_set(struct dmx_ts_feed *ts_feed, u16 pid, int ts_type,
608 enum dmx_ts_pes pes_type, size_t callback_length, 583 enum dmx_ts_pes pes_type,
609 size_t circular_buffer_size, int descramble, 584 size_t circular_buffer_size, struct timespec timeout)
610 struct timespec timeout)
611{ 585{
612 struct dvb_demux_feed *feed = (struct dvb_demux_feed *) ts_feed; 586 struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed;
613 struct dvb_demux *demux = feed->demux; 587 struct dvb_demux *demux = feed->demux;
614 588
615 if (pid > DMX_MAX_PID) 589 if (pid > DMX_MAX_PID)
616 return -EINVAL; 590 return -EINVAL;
617 591
618 if (down_interruptible (&demux->mutex)) 592 if (down_interruptible(&demux->mutex))
619 return -ERESTARTSYS; 593 return -ERESTARTSYS;
620 594
621 if (ts_type & TS_DECODER) { 595 if (ts_type & TS_DECODER) {
@@ -638,20 +612,13 @@ static int dmx_ts_feed_set (struct dmx_ts_feed* ts_feed, u16 pid, int ts_type,
638 612
639 feed->pid = pid; 613 feed->pid = pid;
640 feed->buffer_size = circular_buffer_size; 614 feed->buffer_size = circular_buffer_size;
641 feed->descramble = descramble;
642 feed->timeout = timeout; 615 feed->timeout = timeout;
643 feed->cb_length = callback_length;
644 feed->ts_type = ts_type; 616 feed->ts_type = ts_type;
645 feed->pes_type = pes_type; 617 feed->pes_type = pes_type;
646 618
647 if (feed->descramble) {
648 up(&demux->mutex);
649 return -ENOSYS;
650 }
651
652 if (feed->buffer_size) { 619 if (feed->buffer_size) {
653#ifdef NOBUFS 620#ifdef NOBUFS
654 feed->buffer=NULL; 621 feed->buffer = NULL;
655#else 622#else
656 feed->buffer = vmalloc(feed->buffer_size); 623 feed->buffer = vmalloc(feed->buffer_size);
657 if (!feed->buffer) { 624 if (!feed->buffer) {
@@ -667,14 +634,13 @@ static int dmx_ts_feed_set (struct dmx_ts_feed* ts_feed, u16 pid, int ts_type,
667 return 0; 634 return 0;
668} 635}
669 636
670 637static int dmx_ts_feed_start_filtering(struct dmx_ts_feed *ts_feed)
671static int dmx_ts_feed_start_filtering(struct dmx_ts_feed* ts_feed)
672{ 638{
673 struct dvb_demux_feed *feed = (struct dvb_demux_feed *) ts_feed; 639 struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed;
674 struct dvb_demux *demux = feed->demux; 640 struct dvb_demux *demux = feed->demux;
675 int ret; 641 int ret;
676 642
677 if (down_interruptible (&demux->mutex)) 643 if (down_interruptible(&demux->mutex))
678 return -ERESTARTSYS; 644 return -ERESTARTSYS;
679 645
680 if (feed->state != DMX_STATE_READY || feed->type != DMX_TYPE_TS) { 646 if (feed->state != DMX_STATE_READY || feed->type != DMX_TYPE_TS) {
@@ -701,13 +667,13 @@ static int dmx_ts_feed_start_filtering(struct dmx_ts_feed* ts_feed)
701 return 0; 667 return 0;
702} 668}
703 669
704static int dmx_ts_feed_stop_filtering(struct dmx_ts_feed* ts_feed) 670static int dmx_ts_feed_stop_filtering(struct dmx_ts_feed *ts_feed)
705{ 671{
706 struct dvb_demux_feed *feed = (struct dvb_demux_feed *) ts_feed; 672 struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed;
707 struct dvb_demux *demux = feed->demux; 673 struct dvb_demux *demux = feed->demux;
708 int ret; 674 int ret;
709 675
710 if (down_interruptible (&demux->mutex)) 676 if (down_interruptible(&demux->mutex))
711 return -ERESTARTSYS; 677 return -ERESTARTSYS;
712 678
713 if (feed->state < DMX_STATE_GO) { 679 if (feed->state < DMX_STATE_GO) {
@@ -731,13 +697,14 @@ static int dmx_ts_feed_stop_filtering(struct dmx_ts_feed* ts_feed)
731 return ret; 697 return ret;
732} 698}
733 699
734static int dvbdmx_allocate_ts_feed (struct dmx_demux *dmx, struct dmx_ts_feed **ts_feed, 700static int dvbdmx_allocate_ts_feed(struct dmx_demux *dmx,
735 dmx_ts_cb callback) 701 struct dmx_ts_feed **ts_feed,
702 dmx_ts_cb callback)
736{ 703{
737 struct dvb_demux *demux = (struct dvb_demux *) dmx; 704 struct dvb_demux *demux = (struct dvb_demux *)dmx;
738 struct dvb_demux_feed *feed; 705 struct dvb_demux_feed *feed;
739 706
740 if (down_interruptible (&demux->mutex)) 707 if (down_interruptible(&demux->mutex))
741 return -ERESTARTSYS; 708 return -ERESTARTSYS;
742 709
743 if (!(feed = dvb_dmx_feed_alloc(demux))) { 710 if (!(feed = dvb_dmx_feed_alloc(demux))) {
@@ -760,7 +727,6 @@ static int dvbdmx_allocate_ts_feed (struct dmx_demux *dmx, struct dmx_ts_feed **
760 (*ts_feed)->stop_filtering = dmx_ts_feed_stop_filtering; 727 (*ts_feed)->stop_filtering = dmx_ts_feed_stop_filtering;
761 (*ts_feed)->set = dmx_ts_feed_set; 728 (*ts_feed)->set = dmx_ts_feed_set;
762 729
763
764 if (!(feed->filter = dvb_dmx_filter_alloc(demux))) { 730 if (!(feed->filter = dvb_dmx_filter_alloc(demux))) {
765 feed->state = DMX_STATE_FREE; 731 feed->state = DMX_STATE_FREE;
766 up(&demux->mutex); 732 up(&demux->mutex);
@@ -776,22 +742,22 @@ static int dvbdmx_allocate_ts_feed (struct dmx_demux *dmx, struct dmx_ts_feed **
776 return 0; 742 return 0;
777} 743}
778 744
779static int dvbdmx_release_ts_feed(struct dmx_demux *dmx, struct dmx_ts_feed *ts_feed) 745static int dvbdmx_release_ts_feed(struct dmx_demux *dmx,
746 struct dmx_ts_feed *ts_feed)
780{ 747{
781 struct dvb_demux *demux = (struct dvb_demux *) dmx; 748 struct dvb_demux *demux = (struct dvb_demux *)dmx;
782 struct dvb_demux_feed *feed = (struct dvb_demux_feed *) ts_feed; 749 struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed;
783 750
784 if (down_interruptible (&demux->mutex)) 751 if (down_interruptible(&demux->mutex))
785 return -ERESTARTSYS; 752 return -ERESTARTSYS;
786 753
787 if (feed->state == DMX_STATE_FREE) { 754 if (feed->state == DMX_STATE_FREE) {
788 up(&demux->mutex); 755 up(&demux->mutex);
789 return -EINVAL; 756 return -EINVAL;
790 } 757 }
791
792#ifndef NOBUFS 758#ifndef NOBUFS
793 vfree(feed->buffer); 759 vfree(feed->buffer);
794 feed->buffer=0; 760 feed->buffer = NULL;
795#endif 761#endif
796 762
797 feed->state = DMX_STATE_FREE; 763 feed->state = DMX_STATE_FREE;
@@ -808,19 +774,18 @@ static int dvbdmx_release_ts_feed(struct dmx_demux *dmx, struct dmx_ts_feed *ts_
808 return 0; 774 return 0;
809} 775}
810 776
811
812/****************************************************************************** 777/******************************************************************************
813 * dmx_section_feed API calls 778 * dmx_section_feed API calls
814 ******************************************************************************/ 779 ******************************************************************************/
815 780
816static int dmx_section_feed_allocate_filter(struct dmx_section_feed* feed, 781static int dmx_section_feed_allocate_filter(struct dmx_section_feed *feed,
817 struct dmx_section_filter** filter) 782 struct dmx_section_filter **filter)
818{ 783{
819 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; 784 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed;
820 struct dvb_demux *dvbdemux = dvbdmxfeed->demux; 785 struct dvb_demux *dvbdemux = dvbdmxfeed->demux;
821 struct dvb_demux_filter *dvbdmxfilter; 786 struct dvb_demux_filter *dvbdmxfilter;
822 787
823 if (down_interruptible (&dvbdemux->mutex)) 788 if (down_interruptible(&dvbdemux->mutex))
824 return -ERESTARTSYS; 789 return -ERESTARTSYS;
825 790
826 dvbdmxfilter = dvb_dmx_filter_alloc(dvbdemux); 791 dvbdmxfilter = dvb_dmx_filter_alloc(dvbdemux);
@@ -844,36 +809,29 @@ static int dmx_section_feed_allocate_filter(struct dmx_section_feed* feed,
844 return 0; 809 return 0;
845} 810}
846 811
847 812static int dmx_section_feed_set(struct dmx_section_feed *feed,
848static int dmx_section_feed_set(struct dmx_section_feed* feed, 813 u16 pid, size_t circular_buffer_size,
849 u16 pid, size_t circular_buffer_size, 814 int check_crc)
850 int descramble, int check_crc)
851{ 815{
852 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; 816 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed;
853 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 817 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
854 818
855 if (pid > 0x1fff) 819 if (pid > 0x1fff)
856 return -EINVAL; 820 return -EINVAL;
857 821
858 if (down_interruptible (&dvbdmx->mutex)) 822 if (down_interruptible(&dvbdmx->mutex))
859 return -ERESTARTSYS; 823 return -ERESTARTSYS;
860 824
861 dvb_demux_feed_add(dvbdmxfeed); 825 dvb_demux_feed_add(dvbdmxfeed);
862 826
863 dvbdmxfeed->pid = pid; 827 dvbdmxfeed->pid = pid;
864 dvbdmxfeed->buffer_size = circular_buffer_size; 828 dvbdmxfeed->buffer_size = circular_buffer_size;
865 dvbdmxfeed->descramble = descramble;
866 if (dvbdmxfeed->descramble) {
867 up(&dvbdmx->mutex);
868 return -ENOSYS;
869 }
870
871 dvbdmxfeed->feed.sec.check_crc = check_crc; 829 dvbdmxfeed->feed.sec.check_crc = check_crc;
872 830
873#ifdef NOBUFS 831#ifdef NOBUFS
874 dvbdmxfeed->buffer = NULL; 832 dvbdmxfeed->buffer = NULL;
875#else 833#else
876 dvbdmxfeed->buffer=vmalloc(dvbdmxfeed->buffer_size); 834 dvbdmxfeed->buffer = vmalloc(dvbdmxfeed->buffer_size);
877 if (!dvbdmxfeed->buffer) { 835 if (!dvbdmxfeed->buffer) {
878 up(&dvbdmx->mutex); 836 up(&dvbdmx->mutex);
879 return -ENOMEM; 837 return -ENOMEM;
@@ -885,7 +843,6 @@ static int dmx_section_feed_set(struct dmx_section_feed* feed,
885 return 0; 843 return 0;
886} 844}
887 845
888
889static void prepare_secfilters(struct dvb_demux_feed *dvbdmxfeed) 846static void prepare_secfilters(struct dvb_demux_feed *dvbdmxfeed)
890{ 847{
891 int i; 848 int i;
@@ -893,12 +850,12 @@ static void prepare_secfilters(struct dvb_demux_feed *dvbdmxfeed)
893 struct dmx_section_filter *sf; 850 struct dmx_section_filter *sf;
894 u8 mask, mode, doneq; 851 u8 mask, mode, doneq;
895 852
896 if (!(f=dvbdmxfeed->filter)) 853 if (!(f = dvbdmxfeed->filter))
897 return; 854 return;
898 do { 855 do {
899 sf = &f->filter; 856 sf = &f->filter;
900 doneq = 0; 857 doneq = 0;
901 for (i=0; i<DVB_DEMUX_MASK_MAX; i++) { 858 for (i = 0; i < DVB_DEMUX_MASK_MAX; i++) {
902 mode = sf->filter_mode[i]; 859 mode = sf->filter_mode[i];
903 mask = sf->filter_mask[i]; 860 mask = sf->filter_mask[i];
904 f->maskandmode[i] = mask & mode; 861 f->maskandmode[i] = mask & mode;
@@ -908,14 +865,13 @@ static void prepare_secfilters(struct dvb_demux_feed *dvbdmxfeed)
908 } while ((f = f->next)); 865 } while ((f = f->next));
909} 866}
910 867
911
912static int dmx_section_feed_start_filtering(struct dmx_section_feed *feed) 868static int dmx_section_feed_start_filtering(struct dmx_section_feed *feed)
913{ 869{
914 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; 870 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed;
915 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 871 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
916 int ret; 872 int ret;
917 873
918 if (down_interruptible (&dvbdmx->mutex)) 874 if (down_interruptible(&dvbdmx->mutex))
919 return -ERESTARTSYS; 875 return -ERESTARTSYS;
920 876
921 if (feed->is_filtering) { 877 if (feed->is_filtering) {
@@ -954,14 +910,13 @@ static int dmx_section_feed_start_filtering(struct dmx_section_feed *feed)
954 return 0; 910 return 0;
955} 911}
956 912
957 913static int dmx_section_feed_stop_filtering(struct dmx_section_feed *feed)
958static int dmx_section_feed_stop_filtering(struct dmx_section_feed* feed)
959{ 914{
960 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; 915 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed;
961 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 916 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
962 int ret; 917 int ret;
963 918
964 if (down_interruptible (&dvbdmx->mutex)) 919 if (down_interruptible(&dvbdmx->mutex))
965 return -ERESTARTSYS; 920 return -ERESTARTSYS;
966 921
967 if (!dvbdmx->stop_feed) { 922 if (!dvbdmx->stop_feed) {
@@ -980,15 +935,14 @@ static int dmx_section_feed_stop_filtering(struct dmx_section_feed* feed)
980 return ret; 935 return ret;
981} 936}
982 937
983
984static int dmx_section_feed_release_filter(struct dmx_section_feed *feed, 938static int dmx_section_feed_release_filter(struct dmx_section_feed *feed,
985 struct dmx_section_filter* filter) 939 struct dmx_section_filter *filter)
986{ 940{
987 struct dvb_demux_filter *dvbdmxfilter = (struct dvb_demux_filter *) filter, *f; 941 struct dvb_demux_filter *dvbdmxfilter = (struct dvb_demux_filter *)filter, *f;
988 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; 942 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed;
989 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 943 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
990 944
991 if (down_interruptible (&dvbdmx->mutex)) 945 if (down_interruptible(&dvbdmx->mutex))
992 return -ERESTARTSYS; 946 return -ERESTARTSYS;
993 947
994 if (dvbdmxfilter->feed != dvbdmxfeed) { 948 if (dvbdmxfilter->feed != dvbdmxfeed) {
@@ -1005,7 +959,7 @@ static int dmx_section_feed_release_filter(struct dmx_section_feed *feed,
1005 if (f == dvbdmxfilter) { 959 if (f == dvbdmxfilter) {
1006 dvbdmxfeed->filter = dvbdmxfilter->next; 960 dvbdmxfeed->filter = dvbdmxfilter->next;
1007 } else { 961 } else {
1008 while(f->next != dvbdmxfilter) 962 while (f->next != dvbdmxfilter)
1009 f = f->next; 963 f = f->next;
1010 f->next = f->next->next; 964 f->next = f->next->next;
1011 } 965 }
@@ -1020,10 +974,10 @@ static int dvbdmx_allocate_section_feed(struct dmx_demux *demux,
1020 struct dmx_section_feed **feed, 974 struct dmx_section_feed **feed,
1021 dmx_section_cb callback) 975 dmx_section_cb callback)
1022{ 976{
1023 struct dvb_demux *dvbdmx = (struct dvb_demux *) demux; 977 struct dvb_demux *dvbdmx = (struct dvb_demux *)demux;
1024 struct dvb_demux_feed *dvbdmxfeed; 978 struct dvb_demux_feed *dvbdmxfeed;
1025 979
1026 if (down_interruptible (&dvbdmx->mutex)) 980 if (down_interruptible(&dvbdmx->mutex))
1027 return -ERESTARTSYS; 981 return -ERESTARTSYS;
1028 982
1029 if (!(dvbdmxfeed = dvb_dmx_feed_alloc(dvbdmx))) { 983 if (!(dvbdmxfeed = dvb_dmx_feed_alloc(dvbdmx))) {
@@ -1041,7 +995,7 @@ static int dvbdmx_allocate_section_feed(struct dmx_demux *demux,
1041 dvbdmxfeed->filter = NULL; 995 dvbdmxfeed->filter = NULL;
1042 dvbdmxfeed->buffer = NULL; 996 dvbdmxfeed->buffer = NULL;
1043 997
1044 (*feed)=&dvbdmxfeed->feed.sec; 998 (*feed) = &dvbdmxfeed->feed.sec;
1045 (*feed)->is_filtering = 0; 999 (*feed)->is_filtering = 0;
1046 (*feed)->parent = demux; 1000 (*feed)->parent = demux;
1047 (*feed)->priv = NULL; 1001 (*feed)->priv = NULL;
@@ -1059,21 +1013,21 @@ static int dvbdmx_allocate_section_feed(struct dmx_demux *demux,
1059static int dvbdmx_release_section_feed(struct dmx_demux *demux, 1013static int dvbdmx_release_section_feed(struct dmx_demux *demux,
1060 struct dmx_section_feed *feed) 1014 struct dmx_section_feed *feed)
1061{ 1015{
1062 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; 1016 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed;
1063 struct dvb_demux *dvbdmx = (struct dvb_demux *) demux; 1017 struct dvb_demux *dvbdmx = (struct dvb_demux *)demux;
1064 1018
1065 if (down_interruptible (&dvbdmx->mutex)) 1019 if (down_interruptible(&dvbdmx->mutex))
1066 return -ERESTARTSYS; 1020 return -ERESTARTSYS;
1067 1021
1068 if (dvbdmxfeed->state==DMX_STATE_FREE) { 1022 if (dvbdmxfeed->state == DMX_STATE_FREE) {
1069 up(&dvbdmx->mutex); 1023 up(&dvbdmx->mutex);
1070 return -EINVAL; 1024 return -EINVAL;
1071 } 1025 }
1072#ifndef NOBUFS 1026#ifndef NOBUFS
1073 vfree(dvbdmxfeed->buffer); 1027 vfree(dvbdmxfeed->buffer);
1074 dvbdmxfeed->buffer=0; 1028 dvbdmxfeed->buffer = NULL;
1075#endif 1029#endif
1076 dvbdmxfeed->state=DMX_STATE_FREE; 1030 dvbdmxfeed->state = DMX_STATE_FREE;
1077 1031
1078 dvb_demux_feed_del(dvbdmxfeed); 1032 dvb_demux_feed_del(dvbdmxfeed);
1079 1033
@@ -1083,14 +1037,13 @@ static int dvbdmx_release_section_feed(struct dmx_demux *demux,
1083 return 0; 1037 return 0;
1084} 1038}
1085 1039
1086
1087/****************************************************************************** 1040/******************************************************************************
1088 * dvb_demux kernel data API calls 1041 * dvb_demux kernel data API calls
1089 ******************************************************************************/ 1042 ******************************************************************************/
1090 1043
1091static int dvbdmx_open(struct dmx_demux *demux) 1044static int dvbdmx_open(struct dmx_demux *demux)
1092{ 1045{
1093 struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; 1046 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1094 1047
1095 if (dvbdemux->users >= MAX_DVB_DEMUX_USERS) 1048 if (dvbdemux->users >= MAX_DVB_DEMUX_USERS)
1096 return -EUSERS; 1049 return -EUSERS;
@@ -1099,10 +1052,9 @@ static int dvbdmx_open(struct dmx_demux *demux)
1099 return 0; 1052 return 0;
1100} 1053}
1101 1054
1102
1103static int dvbdmx_close(struct dmx_demux *demux) 1055static int dvbdmx_close(struct dmx_demux *demux)
1104{ 1056{
1105 struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; 1057 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1106 1058
1107 if (dvbdemux->users == 0) 1059 if (dvbdemux->users == 0)
1108 return -ENODEV; 1060 return -ENODEV;
@@ -1112,15 +1064,14 @@ static int dvbdmx_close(struct dmx_demux *demux)
1112 return 0; 1064 return 0;
1113} 1065}
1114 1066
1115
1116static int dvbdmx_write(struct dmx_demux *demux, const char *buf, size_t count) 1067static int dvbdmx_write(struct dmx_demux *demux, const char *buf, size_t count)
1117{ 1068{
1118 struct dvb_demux *dvbdemux=(struct dvb_demux *) demux; 1069 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1119 1070
1120 if ((!demux->frontend) || (demux->frontend->source != DMX_MEMORY_FE)) 1071 if ((!demux->frontend) || (demux->frontend->source != DMX_MEMORY_FE))
1121 return -EINVAL; 1072 return -EINVAL;
1122 1073
1123 if (down_interruptible (&dvbdemux->mutex)) 1074 if (down_interruptible(&dvbdemux->mutex))
1124 return -ERESTARTSYS; 1075 return -ERESTARTSYS;
1125 dvb_dmx_swfilter(dvbdemux, buf, count); 1076 dvb_dmx_swfilter(dvbdemux, buf, count);
1126 up(&dvbdemux->mutex); 1077 up(&dvbdemux->mutex);
@@ -1130,10 +1081,10 @@ static int dvbdmx_write(struct dmx_demux *demux, const char *buf, size_t count)
1130 return count; 1081 return count;
1131} 1082}
1132 1083
1133 1084static int dvbdmx_add_frontend(struct dmx_demux *demux,
1134static int dvbdmx_add_frontend(struct dmx_demux *demux, struct dmx_frontend *frontend) 1085 struct dmx_frontend *frontend)
1135{ 1086{
1136 struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; 1087 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1137 struct list_head *head = &dvbdemux->frontend_list; 1088 struct list_head *head = &dvbdemux->frontend_list;
1138 1089
1139 list_add(&(frontend->connectivity_list), head); 1090 list_add(&(frontend->connectivity_list), head);
@@ -1141,13 +1092,13 @@ static int dvbdmx_add_frontend(struct dmx_demux *demux, struct dmx_frontend *fro
1141 return 0; 1092 return 0;
1142} 1093}
1143 1094
1144 1095static int dvbdmx_remove_frontend(struct dmx_demux *demux,
1145static int dvbdmx_remove_frontend(struct dmx_demux *demux, struct dmx_frontend *frontend) 1096 struct dmx_frontend *frontend)
1146{ 1097{
1147 struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; 1098 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1148 struct list_head *pos, *n, *head = &dvbdemux->frontend_list; 1099 struct list_head *pos, *n, *head = &dvbdemux->frontend_list;
1149 1100
1150 list_for_each_safe (pos, n, head) { 1101 list_for_each_safe(pos, n, head) {
1151 if (DMX_FE_ENTRY(pos) == frontend) { 1102 if (DMX_FE_ENTRY(pos) == frontend) {
1152 list_del(pos); 1103 list_del(pos);
1153 return 0; 1104 return 0;
@@ -1157,25 +1108,25 @@ static int dvbdmx_remove_frontend(struct dmx_demux *demux, struct dmx_frontend *
1157 return -ENODEV; 1108 return -ENODEV;
1158} 1109}
1159 1110
1160 1111static struct list_head *dvbdmx_get_frontends(struct dmx_demux *demux)
1161static struct list_head * dvbdmx_get_frontends(struct dmx_demux *demux)
1162{ 1112{
1163 struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; 1113 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1164 1114
1165 if (list_empty(&dvbdemux->frontend_list)) 1115 if (list_empty(&dvbdemux->frontend_list))
1166 return NULL; 1116 return NULL;
1117
1167 return &dvbdemux->frontend_list; 1118 return &dvbdemux->frontend_list;
1168} 1119}
1169 1120
1170 1121static int dvbdmx_connect_frontend(struct dmx_demux *demux,
1171static int dvbdmx_connect_frontend(struct dmx_demux *demux, struct dmx_frontend *frontend) 1122 struct dmx_frontend *frontend)
1172{ 1123{
1173 struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; 1124 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1174 1125
1175 if (demux->frontend) 1126 if (demux->frontend)
1176 return -EINVAL; 1127 return -EINVAL;
1177 1128
1178 if (down_interruptible (&dvbdemux->mutex)) 1129 if (down_interruptible(&dvbdemux->mutex))
1179 return -ERESTARTSYS; 1130 return -ERESTARTSYS;
1180 1131
1181 demux->frontend = frontend; 1132 demux->frontend = frontend;
@@ -1183,12 +1134,11 @@ static int dvbdmx_connect_frontend(struct dmx_demux *demux, struct dmx_frontend
1183 return 0; 1134 return 0;
1184} 1135}
1185 1136
1186
1187static int dvbdmx_disconnect_frontend(struct dmx_demux *demux) 1137static int dvbdmx_disconnect_frontend(struct dmx_demux *demux)
1188{ 1138{
1189 struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; 1139 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1190 1140
1191 if (down_interruptible (&dvbdemux->mutex)) 1141 if (down_interruptible(&dvbdemux->mutex))
1192 return -ERESTARTSYS; 1142 return -ERESTARTSYS;
1193 1143
1194 demux->frontend = NULL; 1144 demux->frontend = NULL;
@@ -1196,44 +1146,42 @@ static int dvbdmx_disconnect_frontend(struct dmx_demux *demux)
1196 return 0; 1146 return 0;
1197} 1147}
1198 1148
1199 1149static int dvbdmx_get_pes_pids(struct dmx_demux *demux, u16 * pids)
1200static int dvbdmx_get_pes_pids(struct dmx_demux *demux, u16 *pids)
1201{ 1150{
1202 struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; 1151 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1203 1152
1204 memcpy(pids, dvbdemux->pids, 5*sizeof(u16)); 1153 memcpy(pids, dvbdemux->pids, 5 * sizeof(u16));
1205 return 0; 1154 return 0;
1206} 1155}
1207 1156
1208
1209int dvb_dmx_init(struct dvb_demux *dvbdemux) 1157int dvb_dmx_init(struct dvb_demux *dvbdemux)
1210{ 1158{
1211 int i, err; 1159 int i;
1212 struct dmx_demux *dmx = &dvbdemux->dmx; 1160 struct dmx_demux *dmx = &dvbdemux->dmx;
1213 1161
1214 dvbdemux->users = 0; 1162 dvbdemux->users = 0;
1215 dvbdemux->filter = vmalloc(dvbdemux->filternum*sizeof(struct dvb_demux_filter)); 1163 dvbdemux->filter = vmalloc(dvbdemux->filternum * sizeof(struct dvb_demux_filter));
1216 1164
1217 if (!dvbdemux->filter) 1165 if (!dvbdemux->filter)
1218 return -ENOMEM; 1166 return -ENOMEM;
1219 1167
1220 dvbdemux->feed = vmalloc(dvbdemux->feednum*sizeof(struct dvb_demux_feed)); 1168 dvbdemux->feed = vmalloc(dvbdemux->feednum * sizeof(struct dvb_demux_feed));
1221 if (!dvbdemux->feed) { 1169 if (!dvbdemux->feed) {
1222 vfree(dvbdemux->filter); 1170 vfree(dvbdemux->filter);
1223 return -ENOMEM; 1171 return -ENOMEM;
1224 } 1172 }
1225 for (i=0; i<dvbdemux->filternum; i++) { 1173 for (i = 0; i < dvbdemux->filternum; i++) {
1226 dvbdemux->filter[i].state = DMX_STATE_FREE; 1174 dvbdemux->filter[i].state = DMX_STATE_FREE;
1227 dvbdemux->filter[i].index = i; 1175 dvbdemux->filter[i].index = i;
1228 } 1176 }
1229 for (i=0; i<dvbdemux->feednum; i++) { 1177 for (i = 0; i < dvbdemux->feednum; i++) {
1230 dvbdemux->feed[i].state = DMX_STATE_FREE; 1178 dvbdemux->feed[i].state = DMX_STATE_FREE;
1231 dvbdemux->feed[i].index = i; 1179 dvbdemux->feed[i].index = i;
1232 } 1180 }
1233 dvbdemux->frontend_list.next= 1181
1234 dvbdemux->frontend_list.prev= 1182 INIT_LIST_HEAD(&dvbdemux->frontend_list);
1235 &dvbdemux->frontend_list; 1183
1236 for (i=0; i<DMX_TS_PES_OTHER; i++) { 1184 for (i = 0; i < DMX_TS_PES_OTHER; i++) {
1237 dvbdemux->pesfilter[i] = NULL; 1185 dvbdemux->pesfilter[i] = NULL;
1238 dvbdemux->pids[i] = 0xffff; 1186 dvbdemux->pids[i] = 0xffff;
1239 } 1187 }
@@ -1247,12 +1195,11 @@ int dvb_dmx_init(struct dvb_demux *dvbdemux)
1247 if (!dvbdemux->check_crc32) 1195 if (!dvbdemux->check_crc32)
1248 dvbdemux->check_crc32 = dvb_dmx_crc32; 1196 dvbdemux->check_crc32 = dvb_dmx_crc32;
1249 1197
1250 if (!dvbdemux->memcopy) 1198 if (!dvbdemux->memcopy)
1251 dvbdemux->memcopy = dvb_dmx_memcopy; 1199 dvbdemux->memcopy = dvb_dmx_memcopy;
1252 1200
1253 dmx->frontend = NULL; 1201 dmx->frontend = NULL;
1254 dmx->reg_list.prev = dmx->reg_list.next = &dmx->reg_list; 1202 dmx->priv = dvbdemux;
1255 dmx->priv = (void *) dvbdemux;
1256 dmx->open = dvbdmx_open; 1203 dmx->open = dvbdmx_open;
1257 dmx->close = dvbdmx_close; 1204 dmx->close = dvbdmx_close;
1258 dmx->write = dvbdmx_write; 1205 dmx->write = dvbdmx_write;
@@ -1261,9 +1208,6 @@ int dvb_dmx_init(struct dvb_demux *dvbdemux)
1261 dmx->allocate_section_feed = dvbdmx_allocate_section_feed; 1208 dmx->allocate_section_feed = dvbdmx_allocate_section_feed;
1262 dmx->release_section_feed = dvbdmx_release_section_feed; 1209 dmx->release_section_feed = dvbdmx_release_section_feed;
1263 1210
1264 dmx->descramble_mac_address = NULL;
1265 dmx->descramble_section_payload = NULL;
1266
1267 dmx->add_frontend = dvbdmx_add_frontend; 1211 dmx->add_frontend = dvbdmx_add_frontend;
1268 dmx->remove_frontend = dvbdmx_remove_frontend; 1212 dmx->remove_frontend = dvbdmx_remove_frontend;
1269 dmx->get_frontends = dvbdmx_get_frontends; 1213 dmx->get_frontends = dvbdmx_get_frontends;
@@ -1274,21 +1218,15 @@ int dvb_dmx_init(struct dvb_demux *dvbdemux)
1274 sema_init(&dvbdemux->mutex, 1); 1218 sema_init(&dvbdemux->mutex, 1);
1275 spin_lock_init(&dvbdemux->lock); 1219 spin_lock_init(&dvbdemux->lock);
1276 1220
1277 if ((err = dmx_register_demux(dmx)) < 0)
1278 return err;
1279
1280 return 0; 1221 return 0;
1281} 1222}
1282EXPORT_SYMBOL(dvb_dmx_init);
1283 1223
1224EXPORT_SYMBOL(dvb_dmx_init);
1284 1225
1285int dvb_dmx_release(struct dvb_demux *dvbdemux) 1226void dvb_dmx_release(struct dvb_demux *dvbdemux)
1286{ 1227{
1287 struct dmx_demux *dmx = &dvbdemux->dmx;
1288
1289 dmx_unregister_demux(dmx);
1290 vfree(dvbdemux->filter); 1228 vfree(dvbdemux->filter);
1291 vfree(dvbdemux->feed); 1229 vfree(dvbdemux->feed);
1292 return 0;
1293} 1230}
1231
1294EXPORT_SYMBOL(dvb_dmx_release); 1232EXPORT_SYMBOL(dvb_dmx_release);
diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
index c09beb3916..0cc888339d 100644
--- a/drivers/media/dvb/dvb-core/dvb_demux.h
+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
@@ -20,7 +20,6 @@
20 * 20 *
21 */ 21 */
22 22
23
24#ifndef _DVB_DEMUX_H_ 23#ifndef _DVB_DEMUX_H_
25#define _DVB_DEMUX_H_ 24#define _DVB_DEMUX_H_
26 25
@@ -44,103 +43,98 @@
44#define DVB_DEMUX_MASK_MAX 18 43#define DVB_DEMUX_MASK_MAX 18
45 44
46struct dvb_demux_filter { 45struct dvb_demux_filter {
47 struct dmx_section_filter filter; 46 struct dmx_section_filter filter;
48 u8 maskandmode [DMX_MAX_FILTER_SIZE]; 47 u8 maskandmode[DMX_MAX_FILTER_SIZE];
49 u8 maskandnotmode [DMX_MAX_FILTER_SIZE]; 48 u8 maskandnotmode[DMX_MAX_FILTER_SIZE];
50 int doneq; 49 int doneq;
51 50
52 struct dvb_demux_filter *next; 51 struct dvb_demux_filter *next;
53 struct dvb_demux_feed *feed; 52 struct dvb_demux_feed *feed;
54 int index; 53 int index;
55 int state; 54 int state;
56 int type; 55 int type;
57 int pesto;
58
59 u16 handle;
60 u16 hw_handle;
61 struct timer_list timer;
62 int ts_state;
63};
64 56
57 u16 hw_handle;
58 struct timer_list timer;
59};
65 60
66#define DMX_FEED_ENTRY(pos) list_entry(pos, struct dvb_demux_feed, list_head) 61#define DMX_FEED_ENTRY(pos) list_entry(pos, struct dvb_demux_feed, list_head)
67 62
68struct dvb_demux_feed { 63struct dvb_demux_feed {
69 union { 64 union {
70 struct dmx_ts_feed ts; 65 struct dmx_ts_feed ts;
71 struct dmx_section_feed sec; 66 struct dmx_section_feed sec;
72 } feed; 67 } feed;
73 68
74 union { 69 union {
75 dmx_ts_cb ts; 70 dmx_ts_cb ts;
76 dmx_section_cb sec; 71 dmx_section_cb sec;
77 } cb; 72 } cb;
78 73
79 struct dvb_demux *demux; 74 struct dvb_demux *demux;
80 void *priv; 75 void *priv;
81 int type; 76 int type;
82 int state; 77 int state;
83 u16 pid; 78 u16 pid;
84 u8 *buffer; 79 u8 *buffer;
85 int buffer_size; 80 int buffer_size;
86 int descramble;
87 81
88 struct timespec timeout; 82 struct timespec timeout;
89 struct dvb_demux_filter *filter; 83 struct dvb_demux_filter *filter;
90 int cb_length;
91 84
92 int ts_type; 85 int ts_type;
93 enum dmx_ts_pes pes_type; 86 enum dmx_ts_pes pes_type;
94 87
95 int cc; 88 int cc;
96 int pusi_seen; /* prevents feeding of garbage from previous section */ 89 int pusi_seen; /* prevents feeding of garbage from previous section */
97 90
98 u16 peslen; 91 u16 peslen;
99 92
100 struct list_head list_head; 93 struct list_head list_head;
101 int index; /* a unique index for each feed (can be used as hardware pid filter index) */ 94 unsigned int index; /* a unique index for each feed (can be used as hardware pid filter index) */
102}; 95};
103 96
104struct dvb_demux { 97struct dvb_demux {
105 struct dmx_demux dmx; 98 struct dmx_demux dmx;
106 void *priv; 99 void *priv;
107 int filternum; 100 int filternum;
108 int feednum; 101 int feednum;
109 int (*start_feed) (struct dvb_demux_feed *feed); 102 int (*start_feed)(struct dvb_demux_feed *feed);
110 int (*stop_feed) (struct dvb_demux_feed *feed); 103 int (*stop_feed)(struct dvb_demux_feed *feed);
111 int (*write_to_decoder) (struct dvb_demux_feed *feed, 104 int (*write_to_decoder)(struct dvb_demux_feed *feed,
112 const u8 *buf, size_t len); 105 const u8 *buf, size_t len);
113 u32 (*check_crc32) (struct dvb_demux_feed *feed, 106 u32 (*check_crc32)(struct dvb_demux_feed *feed,
114 const u8 *buf, size_t len); 107 const u8 *buf, size_t len);
115 void (*memcopy) (struct dvb_demux_feed *feed, u8 *dst, 108 void (*memcopy)(struct dvb_demux_feed *feed, u8 *dst,
116 const u8 *src, size_t len); 109 const u8 *src, size_t len);
117 110
118 int users; 111 int users;
119#define MAX_DVB_DEMUX_USERS 10 112#define MAX_DVB_DEMUX_USERS 10
120 struct dvb_demux_filter *filter; 113 struct dvb_demux_filter *filter;
121 struct dvb_demux_feed *feed; 114 struct dvb_demux_feed *feed;
122 115
123 struct list_head frontend_list; 116 struct list_head frontend_list;
124 117
125 struct dvb_demux_feed *pesfilter[DMX_TS_PES_OTHER]; 118 struct dvb_demux_feed *pesfilter[DMX_TS_PES_OTHER];
126 u16 pids[DMX_TS_PES_OTHER]; 119 u16 pids[DMX_TS_PES_OTHER];
127 int playing; 120 int playing;
128 int recording; 121 int recording;
129 122
130#define DMX_MAX_PID 0x2000 123#define DMX_MAX_PID 0x2000
131 struct list_head feed_list; 124 struct list_head feed_list;
132 u8 tsbuf[204]; 125 u8 tsbuf[204];
133 int tsbufp; 126 int tsbufp;
134 127
135 struct semaphore mutex; 128 struct semaphore mutex;
136 spinlock_t lock; 129 spinlock_t lock;
137}; 130};
138 131
139
140int dvb_dmx_init(struct dvb_demux *dvbdemux); 132int dvb_dmx_init(struct dvb_demux *dvbdemux);
141int dvb_dmx_release(struct dvb_demux *dvbdemux); 133void dvb_dmx_release(struct dvb_demux *dvbdemux);
142void dvb_dmx_swfilter_packets(struct dvb_demux *dvbdmx, const u8 *buf, size_t count); 134void dvb_dmx_swfilter_packets(struct dvb_demux *dvbdmx, const u8 *buf,
135 size_t count);
143void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count); 136void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count);
144void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf, size_t count); 137void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf,
138 size_t count);
145 139
146#endif /* _DVB_DEMUX_H_ */ 140#endif /* _DVB_DEMUX_H_ */
diff --git a/drivers/media/dvb/dvb-core/dvb_net.c b/drivers/media/dvb/dvb-core/dvb_net.c
index 6a968c346a..87935490bf 100644
--- a/drivers/media/dvb/dvb-core/dvb_net.c
+++ b/drivers/media/dvb/dvb-core/dvb_net.c
@@ -62,7 +62,6 @@
62#include <linux/uio.h> 62#include <linux/uio.h>
63#include <asm/uaccess.h> 63#include <asm/uaccess.h>
64#include <linux/crc32.h> 64#include <linux/crc32.h>
65#include <linux/version.h>
66 65
67#include "dvb_demux.h" 66#include "dvb_demux.h"
68#include "dvb_net.h" 67#include "dvb_net.h"
@@ -171,11 +170,7 @@ static unsigned short dvb_net_eth_type_trans(struct sk_buff *skb,
171 170
172 skb->mac.raw=skb->data; 171 skb->mac.raw=skb->data;
173 skb_pull(skb,dev->hard_header_len); 172 skb_pull(skb,dev->hard_header_len);
174#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,8)
175 eth = skb->mac.ethernet;
176#else
177 eth = eth_hdr(skb); 173 eth = eth_hdr(skb);
178#endif
179 174
180 if (*eth->h_dest & 1) { 175 if (*eth->h_dest & 1) {
181 if(memcmp(eth->h_dest,dev->broadcast, ETH_ALEN)==0) 176 if(memcmp(eth->h_dest,dev->broadcast, ETH_ALEN)==0)
@@ -908,7 +903,7 @@ static int dvb_net_feed_start(struct net_device *dev)
908 return ret; 903 return ret;
909 } 904 }
910 905
911 ret = priv->secfeed->set(priv->secfeed, priv->pid, 32768, 0, 1); 906 ret = priv->secfeed->set(priv->secfeed, priv->pid, 32768, 1);
912 907
913 if (ret<0) { 908 if (ret<0) {
914 printk("%s: could not set section feed\n", dev->name); 909 printk("%s: could not set section feed\n", dev->name);
@@ -960,9 +955,7 @@ static int dvb_net_feed_start(struct net_device *dev)
960 priv->tsfeed->priv = (void *)dev; 955 priv->tsfeed->priv = (void *)dev;
961 ret = priv->tsfeed->set(priv->tsfeed, priv->pid, 956 ret = priv->tsfeed->set(priv->tsfeed, priv->pid,
962 TS_PACKET, DMX_TS_PES_OTHER, 957 TS_PACKET, DMX_TS_PES_OTHER,
963 188 * 100, /* nr. of bytes delivered per callback */
964 32768, /* circular buffer size */ 958 32768, /* circular buffer size */
965 0, /* descramble */
966 timeout); 959 timeout);
967 960
968 if (ret < 0) { 961 if (ret < 0) {
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index 612e5b087b..54e2b29076 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -93,13 +93,30 @@ config DVB_USB_DIGITV
93 Say Y here to support the Nebula Electronics uDigitV USB2.0 DVB-T receiver. 93 Say Y here to support the Nebula Electronics uDigitV USB2.0 DVB-T receiver.
94 94
95config DVB_USB_VP7045 95config DVB_USB_VP7045
96 tristate "TwinhanDTV Alpha/MagicBoxII and DNTV tinyUSB2 DVB-T USB2.0 support" 96 tristate "TwinhanDTV Alpha/MagicBoxII, DNTV tinyUSB2, Beetle USB2.0 support"
97 depends on DVB_USB 97 depends on DVB_USB
98 help 98 help
99 Say Y here to support the 99 Say Y here to support the
100
100 TwinhanDTV Alpha (stick) (VP-7045), 101 TwinhanDTV Alpha (stick) (VP-7045),
101 TwinhanDTV MagicBox II (VP-7046) and 102 TwinhanDTV MagicBox II (VP-7046),
102 DigitalNow TinyUSB 2 DVB-t DVB-T USB2.0 receivers. 103 DigitalNow TinyUSB 2 DVB-t,
104 DigitalRise USB 2.0 Ter (Beetle) and
105 TYPHOON DVB-T USB DRIVE
106
107 DVB-T USB2.0 receivers.
108
109config DVB_USB_VP702X
110 tristate "TwinhanDTV StarBox and clones DVB-S USB2.0 support"
111 depends on DVB_USB
112 help
113 Say Y here to support the
114
115 TwinhanDTV StarBox,
116 DigitalRise USB Starbox and
117 TYPHOON DVB-S USB 2.0 BOX
118
119 DVB-S USB2.0 receivers.
103 120
104config DVB_USB_NOVA_T_USB2 121config DVB_USB_NOVA_T_USB2
105 tristate "Hauppauge WinTV-NOVA-T usb2 DVB-T USB2.0 support" 122 tristate "Hauppauge WinTV-NOVA-T usb2 DVB-T USB2.0 support"
diff --git a/drivers/media/dvb/dvb-usb/Makefile b/drivers/media/dvb/dvb-usb/Makefile
index 746d87ed6f..2dc9aad968 100644
--- a/drivers/media/dvb/dvb-usb/Makefile
+++ b/drivers/media/dvb/dvb-usb/Makefile
@@ -4,6 +4,9 @@ obj-$(CONFIG_DVB_USB) += dvb-usb.o
4dvb-usb-vp7045-objs = vp7045.o vp7045-fe.o 4dvb-usb-vp7045-objs = vp7045.o vp7045-fe.o
5obj-$(CONFIG_DVB_USB_VP7045) += dvb-usb-vp7045.o 5obj-$(CONFIG_DVB_USB_VP7045) += dvb-usb-vp7045.o
6 6
7dvb-usb-vp702x-objs = vp702x.o vp702x-fe.o
8obj-$(CONFIG_DVB_USB_VP702X) += dvb-usb-vp702x.o
9
7dvb-usb-dtt200u-objs = dtt200u.o dtt200u-fe.o 10dvb-usb-dtt200u-objs = dtt200u.o dtt200u-fe.o
8obj-$(CONFIG_DVB_USB_DTT200U) += dvb-usb-dtt200u.o 11obj-$(CONFIG_DVB_USB_DTT200U) += dvb-usb-dtt200u.o
9 12
diff --git a/drivers/media/dvb/dvb-usb/a800.c b/drivers/media/dvb/dvb-usb/a800.c
index f2fcc2f1f8..e55322ef76 100644
--- a/drivers/media/dvb/dvb-usb/a800.c
+++ b/drivers/media/dvb/dvb-usb/a800.c
@@ -90,7 +90,7 @@ static struct dvb_usb_properties a800_properties;
90static int a800_probe(struct usb_interface *intf, 90static int a800_probe(struct usb_interface *intf,
91 const struct usb_device_id *id) 91 const struct usb_device_id *id)
92{ 92{
93 return dvb_usb_device_init(intf,&a800_properties,THIS_MODULE); 93 return dvb_usb_device_init(intf,&a800_properties,THIS_MODULE,NULL);
94} 94}
95 95
96/* do not change the order of the ID table */ 96/* do not change the order of the ID table */
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
index 9e96a188f1..3fe383f4bb 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.c
+++ b/drivers/media/dvb/dvb-usb/cxusb.c
@@ -48,35 +48,26 @@ static int cxusb_ctrl_msg(struct dvb_usb_device *d,
48 return 0; 48 return 0;
49} 49}
50 50
51/* I2C */ 51/* GPIO */
52static void cxusb_set_i2c_path(struct dvb_usb_device *d, enum cxusb_i2c_pathes path) 52static void cxusb_gpio_tuner(struct dvb_usb_device *d, int onoff)
53{ 53{
54 struct cxusb_state *st = d->priv; 54 struct cxusb_state *st = d->priv;
55 u8 o[2],i; 55 u8 o[2],i;
56 56
57 if (path == st->cur_i2c_path) 57 if (st->gpio_write_state[GPIO_TUNER] == onoff)
58 return; 58 return;
59 59
60 o[0] = IOCTL_SET_I2C_PATH; 60 o[0] = GPIO_TUNER;
61 switch (path) { 61 o[1] = onoff;
62 case PATH_CX22702: 62 cxusb_ctrl_msg(d,CMD_GPIO_WRITE,o,2,&i,1);
63 o[1] = 0;
64 break;
65 case PATH_TUNER_OTHER:
66 o[1] = 1;
67 break;
68 default:
69 err("unkown i2c path");
70 return;
71 }
72 cxusb_ctrl_msg(d,CMD_IOCTL,o,2,&i,1);
73 63
74 if (i != 0x01) 64 if (i != 0x01)
75 deb_info("i2c_path setting failed.\n"); 65 deb_info("gpio_write failed.\n");
76 66
77 st->cur_i2c_path = path; 67 st->gpio_write_state[GPIO_TUNER] = onoff;
78} 68}
79 69
70/* I2C */
80static int cxusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num) 71static int cxusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
81{ 72{
82 struct dvb_usb_device *d = i2c_get_adapdata(adap); 73 struct dvb_usb_device *d = i2c_get_adapdata(adap);
@@ -92,10 +83,10 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
92 83
93 switch (msg[i].addr) { 84 switch (msg[i].addr) {
94 case 0x63: 85 case 0x63:
95 cxusb_set_i2c_path(d,PATH_CX22702); 86 cxusb_gpio_tuner(d,0);
96 break; 87 break;
97 default: 88 default:
98 cxusb_set_i2c_path(d,PATH_TUNER_OTHER); 89 cxusb_gpio_tuner(d,1);
99 break; 90 break;
100 } 91 }
101 92
@@ -147,16 +138,20 @@ static struct i2c_algorithm cxusb_i2c_algo = {
147 138
148static int cxusb_power_ctrl(struct dvb_usb_device *d, int onoff) 139static int cxusb_power_ctrl(struct dvb_usb_device *d, int onoff)
149{ 140{
150 return 0; 141 u8 b = 0;
142 if (onoff)
143 return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);
144 else
145 return cxusb_ctrl_msg(d, CMD_POWER_OFF, &b, 1, NULL, 0);
151} 146}
152 147
153static int cxusb_streaming_ctrl(struct dvb_usb_device *d, int onoff) 148static int cxusb_streaming_ctrl(struct dvb_usb_device *d, int onoff)
154{ 149{
155 u8 buf[2] = { 0x03, 0x00 }; 150 u8 buf[2] = { 0x03, 0x00 };
156 if (onoff) 151 if (onoff)
157 cxusb_ctrl_msg(d,0x36, buf, 2, NULL, 0); 152 cxusb_ctrl_msg(d,CMD_STREAMING_ON, buf, 2, NULL, 0);
158 else 153 else
159 cxusb_ctrl_msg(d,0x37, NULL, 0, NULL, 0); 154 cxusb_ctrl_msg(d,CMD_STREAMING_OFF, NULL, 0, NULL, 0);
160 155
161 return 0; 156 return 0;
162} 157}
@@ -182,22 +177,11 @@ static int cxusb_tuner_attach(struct dvb_usb_device *d)
182 177
183static int cxusb_frontend_attach(struct dvb_usb_device *d) 178static int cxusb_frontend_attach(struct dvb_usb_device *d)
184{ 179{
185 u8 buf[2] = { 0x03, 0x00 }; 180 u8 b;
186 u8 b = 0;
187
188 if (usb_set_interface(d->udev,0,0) < 0)
189 err("set interface to alts=0 failed");
190
191 cxusb_ctrl_msg(d,0xde,&b,0,NULL,0);
192 cxusb_set_i2c_path(d,PATH_TUNER_OTHER);
193 cxusb_ctrl_msg(d,CMD_POWER_OFF, NULL, 0, &b, 1);
194
195 if (usb_set_interface(d->udev,0,6) < 0) 181 if (usb_set_interface(d->udev,0,6) < 0)
196 err("set interface failed"); 182 err("set interface failed");
197 183
198 cxusb_ctrl_msg(d,0x36, buf, 2, NULL, 0); 184 cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, &b, 1);
199 cxusb_set_i2c_path(d,PATH_CX22702);
200 cxusb_ctrl_msg(d,CMD_POWER_ON, NULL, 0, &b, 1);
201 185
202 if ((d->fe = cx22702_attach(&cxusb_cx22702_config, &d->i2c_adap)) != NULL) 186 if ((d->fe = cx22702_attach(&cxusb_cx22702_config, &d->i2c_adap)) != NULL)
203 return 0; 187 return 0;
@@ -211,7 +195,7 @@ static struct dvb_usb_properties cxusb_properties;
211static int cxusb_probe(struct usb_interface *intf, 195static int cxusb_probe(struct usb_interface *intf,
212 const struct usb_device_id *id) 196 const struct usb_device_id *id)
213{ 197{
214 return dvb_usb_device_init(intf,&cxusb_properties,THIS_MODULE); 198 return dvb_usb_device_init(intf,&cxusb_properties,THIS_MODULE,NULL);
215} 199}
216 200
217static struct usb_device_id cxusb_table [] = { 201static struct usb_device_id cxusb_table [] = {
@@ -237,14 +221,12 @@ static struct dvb_usb_properties cxusb_properties = {
237 .generic_bulk_ctrl_endpoint = 0x01, 221 .generic_bulk_ctrl_endpoint = 0x01,
238 /* parameter for the MPEG2-data transfer */ 222 /* parameter for the MPEG2-data transfer */
239 .urb = { 223 .urb = {
240 .type = DVB_USB_ISOC, 224 .type = DVB_USB_BULK,
241 .count = 5, 225 .count = 5,
242 .endpoint = 0x02, 226 .endpoint = 0x02,
243 .u = { 227 .u = {
244 .isoc = { 228 .bulk = {
245 .framesperurb = 32, 229 .buffersize = 8192,
246 .framesize = 940,
247 .interval = 5,
248 } 230 }
249 } 231 }
250 }, 232 },
diff --git a/drivers/media/dvb/dvb-usb/cxusb.h b/drivers/media/dvb/dvb-usb/cxusb.h
index 1d79016e31..135c2a81f5 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.h
+++ b/drivers/media/dvb/dvb-usb/cxusb.h
@@ -1,30 +1,31 @@
1#ifndef _DVB_USB_CXUSB_H_ 1#ifndef _DVB_USB_CXUSB_H_
2#define _DVB_USB_CXUSB_H_ 2#define _DVB_USB_CXUSB_H_
3 3
4#define DVB_USB_LOG_PREFIX "digitv" 4#define DVB_USB_LOG_PREFIX "cxusb"
5#include "dvb-usb.h" 5#include "dvb-usb.h"
6 6
7extern int dvb_usb_cxusb_debug; 7extern int dvb_usb_cxusb_debug;
8#define deb_info(args...) dprintk(dvb_usb_cxusb_debug,0x01,args) 8#define deb_info(args...) dprintk(dvb_usb_cxusb_debug,0x01,args)
9 9
10/* usb commands - some of it are guesses, don't have a reference yet */ 10/* usb commands - some of it are guesses, don't have a reference yet */
11#define CMD_I2C_WRITE 0x08 11#define CMD_I2C_WRITE 0x08
12#define CMD_I2C_READ 0x09 12#define CMD_I2C_READ 0x09
13 13
14#define CMD_IOCTL 0x0e 14#define CMD_GPIO_READ 0x0d
15#define IOCTL_SET_I2C_PATH 0x02 15#define CMD_GPIO_WRITE 0x0e
16#define GPIO_TUNER 0x02
16 17
17#define CMD_POWER_OFF 0x50 18#define CMD_POWER_OFF 0xdc
18#define CMD_POWER_ON 0x51 19#define CMD_POWER_ON 0xde
19 20
20enum cxusb_i2c_pathes { 21#define CMD_STREAMING_ON 0x36
21 PATH_UNDEF = 0x00, 22#define CMD_STREAMING_OFF 0x37
22 PATH_CX22702 = 0x01, 23
23 PATH_TUNER_OTHER = 0x02, 24#define CMD_ANALOG 0x50
24}; 25#define CMD_DIGITAL 0x51
25 26
26struct cxusb_state { 27struct cxusb_state {
27 enum cxusb_i2c_pathes cur_i2c_path; 28 u8 gpio_write_state[3];
28}; 29};
29 30
30#endif 31#endif
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mb.c b/drivers/media/dvb/dvb-usb/dibusb-mb.c
index 828b5182e1..0058505634 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-mb.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-mb.c
@@ -86,9 +86,9 @@ static struct dvb_usb_properties dibusb2_0b_properties;
86static int dibusb_probe(struct usb_interface *intf, 86static int dibusb_probe(struct usb_interface *intf,
87 const struct usb_device_id *id) 87 const struct usb_device_id *id)
88{ 88{
89 if (dvb_usb_device_init(intf,&dibusb1_1_properties,THIS_MODULE) == 0 || 89 if (dvb_usb_device_init(intf,&dibusb1_1_properties,THIS_MODULE,NULL) == 0 ||
90 dvb_usb_device_init(intf,&dibusb1_1_an2235_properties,THIS_MODULE) == 0 || 90 dvb_usb_device_init(intf,&dibusb1_1_an2235_properties,THIS_MODULE,NULL) == 0 ||
91 dvb_usb_device_init(intf,&dibusb2_0b_properties,THIS_MODULE) == 0) 91 dvb_usb_device_init(intf,&dibusb2_0b_properties,THIS_MODULE,NULL) == 0)
92 return 0; 92 return 0;
93 93
94 return -EINVAL; 94 return -EINVAL;
@@ -126,10 +126,12 @@ static struct usb_device_id dibusb_dib3000mb_table [] = {
126/* 25 */ { USB_DEVICE(USB_VID_KYE, USB_PID_KYE_DVB_T_COLD) }, 126/* 25 */ { USB_DEVICE(USB_VID_KYE, USB_PID_KYE_DVB_T_COLD) },
127/* 26 */ { USB_DEVICE(USB_VID_KYE, USB_PID_KYE_DVB_T_WARM) }, 127/* 26 */ { USB_DEVICE(USB_VID_KYE, USB_PID_KYE_DVB_T_WARM) },
128 128
129/* 27 */ { USB_DEVICE(USB_VID_KWORLD, USB_PID_KWORLD_VSTREAM_COLD) },
130
129// #define DVB_USB_DIBUSB_MB_FAULTY_USB_IDs 131// #define DVB_USB_DIBUSB_MB_FAULTY_USB_IDs
130 132
131#ifdef DVB_USB_DIBUSB_MB_FAULTY_USB_IDs 133#ifdef DVB_USB_DIBUSB_MB_FAULTY_USB_IDs
132/* 27 */ { USB_DEVICE(USB_VID_ANCHOR, USB_PID_ULTIMA_TVBOX_ANCHOR_COLD) }, 134/* 28 */ { USB_DEVICE(USB_VID_ANCHOR, USB_PID_ULTIMA_TVBOX_ANCHOR_COLD) },
133#endif 135#endif
134 { } /* Terminating entry */ 136 { } /* Terminating entry */
135}; 137};
@@ -262,7 +264,7 @@ static struct dvb_usb_properties dibusb1_1_an2235_properties = {
262 }, 264 },
263#ifdef DVB_USB_DIBUSB_MB_FAULTY_USB_IDs 265#ifdef DVB_USB_DIBUSB_MB_FAULTY_USB_IDs
264 { "Artec T1 USB1.1 TVBOX with AN2235 (faulty USB IDs)", 266 { "Artec T1 USB1.1 TVBOX with AN2235 (faulty USB IDs)",
265 { &dibusb_dib3000mb_table[27], NULL }, 267 { &dibusb_dib3000mb_table[28], NULL },
266 { NULL }, 268 { NULL },
267 }, 269 },
268#endif 270#endif
@@ -306,12 +308,16 @@ static struct dvb_usb_properties dibusb2_0b_properties = {
306 } 308 }
307 }, 309 },
308 310
309 .num_device_descs = 1, 311 .num_device_descs = 2,
310 .devices = { 312 .devices = {
311 { "KWorld/ADSTech Instant DVB-T USB 2.0", 313 { "KWorld/ADSTech Instant DVB-T USB2.0",
312 { &dibusb_dib3000mb_table[23], NULL }, 314 { &dibusb_dib3000mb_table[23], NULL },
313 { &dibusb_dib3000mb_table[24], NULL }, 315 { &dibusb_dib3000mb_table[24], NULL },
314 }, 316 },
317 { "KWorld Xpert DVB-T USB2.0",
318 { &dibusb_dib3000mb_table[27], NULL },
319 { NULL }
320 },
315 } 321 }
316}; 322};
317 323
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mc.c b/drivers/media/dvb/dvb-usb/dibusb-mc.c
index e9dac430f3..6a0912eab3 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-mc.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-mc.c
@@ -20,7 +20,7 @@ static struct dvb_usb_properties dibusb_mc_properties;
20static int dibusb_mc_probe(struct usb_interface *intf, 20static int dibusb_mc_probe(struct usb_interface *intf,
21 const struct usb_device_id *id) 21 const struct usb_device_id *id)
22{ 22{
23 return dvb_usb_device_init(intf,&dibusb_mc_properties,THIS_MODULE); 23 return dvb_usb_device_init(intf,&dibusb_mc_properties,THIS_MODULE,NULL);
24} 24}
25 25
26/* do not change the order of the ID table */ 26/* do not change the order of the ID table */
diff --git a/drivers/media/dvb/dvb-usb/digitv.c b/drivers/media/dvb/dvb-usb/digitv.c
index f70e0be092..74545f82ef 100644
--- a/drivers/media/dvb/dvb-usb/digitv.c
+++ b/drivers/media/dvb/dvb-usb/digitv.c
@@ -111,31 +111,28 @@ static int digitv_mt352_demod_init(struct dvb_frontend *fe)
111} 111}
112 112
113static struct mt352_config digitv_mt352_config = { 113static struct mt352_config digitv_mt352_config = {
114 .demod_address = 0x0, /* ignored by the digitv anyway */
115 .demod_init = digitv_mt352_demod_init, 114 .demod_init = digitv_mt352_demod_init,
116 .pll_set = dvb_usb_pll_set, 115 .pll_set = dvb_usb_pll_set,
117}; 116};
118 117
119static struct nxt6000_config digitv_nxt6000_config = { 118static int digitv_nxt6000_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep)
120 .demod_address = 0x0, /* ignored by the digitv anyway */ 119{
121 .clock_inversion = 0x0, 120 struct dvb_usb_device *d = fe->dvb->priv;
121 u8 b[5];
122 dvb_usb_pll_set(fe,fep,b);
123 return digitv_ctrl_msg(d,USB_WRITE_TUNER,0,&b[1],4,NULL,0);
124}
122 125
123 .pll_init = NULL, 126static struct nxt6000_config digitv_nxt6000_config = {
124 .pll_set = NULL, 127 .clock_inversion = 1,
128 .pll_set = digitv_nxt6000_pll_set,
125}; 129};
126 130
127static int digitv_frontend_attach(struct dvb_usb_device *d) 131static int digitv_frontend_attach(struct dvb_usb_device *d)
128{ 132{
129 if ((d->fe = mt352_attach(&digitv_mt352_config, &d->i2c_adap)) != NULL) 133 if ((d->fe = mt352_attach(&digitv_mt352_config, &d->i2c_adap)) != NULL ||
134 (d->fe = nxt6000_attach(&digitv_nxt6000_config, &d->i2c_adap)) != NULL)
130 return 0; 135 return 0;
131 if ((d->fe = nxt6000_attach(&digitv_nxt6000_config, &d->i2c_adap)) != NULL) {
132
133 warn("nxt6000 support is not done yet, in fact you are one of the first "
134 "person who wants to use this device in Linux. Please report to "
135 "linux-dvb@linuxtv.org");
136
137 return 0;
138 }
139 return -EIO; 136 return -EIO;
140} 137}
141 138
@@ -173,7 +170,18 @@ static struct dvb_usb_properties digitv_properties;
173static int digitv_probe(struct usb_interface *intf, 170static int digitv_probe(struct usb_interface *intf,
174 const struct usb_device_id *id) 171 const struct usb_device_id *id)
175{ 172{
176 return dvb_usb_device_init(intf,&digitv_properties,THIS_MODULE); 173 struct dvb_usb_device *d;
174 int ret;
175 if ((ret = dvb_usb_device_init(intf,&digitv_properties,THIS_MODULE,&d)) == 0) {
176 u8 b[4] = { 0 };
177
178 b[0] = 1;
179 digitv_ctrl_msg(d,USB_WRITE_REMOTE_TYPE,0,b,4,NULL,0);
180
181 b[0] = 0;
182 digitv_ctrl_msg(d,USB_WRITE_REMOTE,0,b,4,NULL,0);
183 }
184 return ret;
177} 185}
178 186
179static struct usb_device_id digitv_table [] = { 187static struct usb_device_id digitv_table [] = {
diff --git a/drivers/media/dvb/dvb-usb/dtt200u-fe.c b/drivers/media/dvb/dvb-usb/dtt200u-fe.c
index b032523b07..0a94ec22ae 100644
--- a/drivers/media/dvb/dvb-usb/dtt200u-fe.c
+++ b/drivers/media/dvb/dvb-usb/dtt200u-fe.c
@@ -18,6 +18,7 @@ struct dtt200u_fe_state {
18 18
19 struct dvb_frontend_parameters fep; 19 struct dvb_frontend_parameters fep;
20 struct dvb_frontend frontend; 20 struct dvb_frontend frontend;
21 struct dvb_frontend_ops ops;
21}; 22};
22 23
23static int dtt200u_fe_read_status(struct dvb_frontend* fe, fe_status_t *stat) 24static int dtt200u_fe_read_status(struct dvb_frontend* fe, fe_status_t *stat)
@@ -163,8 +164,9 @@ struct dvb_frontend* dtt200u_fe_attach(struct dvb_usb_device *d)
163 deb_info("attaching frontend dtt200u\n"); 164 deb_info("attaching frontend dtt200u\n");
164 165
165 state->d = d; 166 state->d = d;
167 memcpy(&state->ops,&dtt200u_fe_ops,sizeof(struct dvb_frontend_ops));
166 168
167 state->frontend.ops = &dtt200u_fe_ops; 169 state->frontend.ops = &state->ops;
168 state->frontend.demodulator_priv = state; 170 state->frontend.demodulator_priv = state;
169 171
170 goto success; 172 goto success;
diff --git a/drivers/media/dvb/dvb-usb/dtt200u.c b/drivers/media/dvb/dvb-usb/dtt200u.c
index 47dba6e459..5aa12ebab3 100644
--- a/drivers/media/dvb/dvb-usb/dtt200u.c
+++ b/drivers/media/dvb/dvb-usb/dtt200u.c
@@ -98,20 +98,19 @@ static struct dvb_usb_properties wt220u_properties;
98static int dtt200u_usb_probe(struct usb_interface *intf, 98static int dtt200u_usb_probe(struct usb_interface *intf,
99 const struct usb_device_id *id) 99 const struct usb_device_id *id)
100{ 100{
101 if (dvb_usb_device_init(intf,&dtt200u_properties,THIS_MODULE) == 0 || 101 if (dvb_usb_device_init(intf,&dtt200u_properties,THIS_MODULE,NULL) == 0 ||
102 dvb_usb_device_init(intf,&wt220u_properties,THIS_MODULE) == 0) 102 dvb_usb_device_init(intf,&wt220u_properties,THIS_MODULE,NULL) == 0)
103 return 0; 103 return 0;
104 104
105 return -ENODEV; 105 return -ENODEV;
106} 106}
107 107
108static struct usb_device_id dtt200u_usb_table [] = { 108static struct usb_device_id dtt200u_usb_table [] = {
109// { USB_DEVICE(0x04b4,0x8613) }, 109 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_DTT200U_COLD) },
110 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_DTT200U_COLD) }, 110 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_DTT200U_WARM) },
111 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_DTT200U_WARM) }, 111 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_COLD) },
112 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_COLD) }, 112 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_WARM) },
113 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_WARM) }, 113 { 0 },
114 { 0 },
115}; 114};
116MODULE_DEVICE_TABLE(usb, dtt200u_usb_table); 115MODULE_DEVICE_TABLE(usb, dtt200u_usb_table);
117 116
@@ -189,7 +188,7 @@ static struct dvb_usb_properties wt220u_properties = {
189 188
190 .num_device_descs = 1, 189 .num_device_descs = 1,
191 .devices = { 190 .devices = {
192 { .name = "WideView WT-220U PenType Receiver (and clones)", 191 { .name = "WideView WT-220U PenType Receiver (Typhoon/Freecom)",
193 .cold_ids = { &dtt200u_usb_table[2], NULL }, 192 .cold_ids = { &dtt200u_usb_table[2], NULL },
194 .warm_ids = { &dtt200u_usb_table[3], NULL }, 193 .warm_ids = { &dtt200u_usb_table[3], NULL },
195 }, 194 },
@@ -201,9 +200,9 @@ static struct dvb_usb_properties wt220u_properties = {
201static struct usb_driver dtt200u_usb_driver = { 200static struct usb_driver dtt200u_usb_driver = {
202 .owner = THIS_MODULE, 201 .owner = THIS_MODULE,
203 .name = "dvb_usb_dtt200u", 202 .name = "dvb_usb_dtt200u",
204 .probe = dtt200u_usb_probe, 203 .probe = dtt200u_usb_probe,
205 .disconnect = dvb_usb_device_exit, 204 .disconnect = dvb_usb_device_exit,
206 .id_table = dtt200u_usb_table, 205 .id_table = dtt200u_usb_table,
207}; 206};
208 207
209/* module stuff */ 208/* module stuff */
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index 794d513a84..0818996bf1 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -24,8 +24,10 @@
24#define USB_VID_HANFTEK 0x15f4 24#define USB_VID_HANFTEK 0x15f4
25#define USB_VID_HAUPPAUGE 0x2040 25#define USB_VID_HAUPPAUGE 0x2040
26#define USB_VID_HYPER_PALTEK 0x1025 26#define USB_VID_HYPER_PALTEK 0x1025
27#define USB_VID_KWORLD 0xeb2a
27#define USB_VID_KYE 0x0458 28#define USB_VID_KYE 0x0458
28#define USB_VID_MEDION 0x1660 29#define USB_VID_MEDION 0x1660
30#define USB_VID_PINNACLE 0x2304
29#define USB_VID_VISIONPLUS 0x13d3 31#define USB_VID_VISIONPLUS 0x13d3
30#define USB_VID_TWINHAN 0x1822 32#define USB_VID_TWINHAN 0x1822
31#define USB_VID_ULTIMA_ELECTRONIC 0x05d8 33#define USB_VID_ULTIMA_ELECTRONIC 0x05d8
@@ -52,12 +54,14 @@
52#define USB_PID_KWORLD_VSTREAM_WARM 0x17df 54#define USB_PID_KWORLD_VSTREAM_WARM 0x17df
53#define USB_PID_TWINHAN_VP7041_COLD 0x3201 55#define USB_PID_TWINHAN_VP7041_COLD 0x3201
54#define USB_PID_TWINHAN_VP7041_WARM 0x3202 56#define USB_PID_TWINHAN_VP7041_WARM 0x3202
57#define USB_PID_TWINHAN_VP7020_COLD 0x3203
58#define USB_PID_TWINHAN_VP7020_WARM 0x3204
55#define USB_PID_TWINHAN_VP7045_COLD 0x3205 59#define USB_PID_TWINHAN_VP7045_COLD 0x3205
56#define USB_PID_TWINHAN_VP7045_WARM 0x3206 60#define USB_PID_TWINHAN_VP7045_WARM 0x3206
57#define USB_PID_DNTV_TINYUSB2_COLD 0x3223
58#define USB_PID_DNTV_TINYUSB2_WARM 0x3224
59#define USB_PID_TWINHAN_VP7021_COLD 0x3207 61#define USB_PID_TWINHAN_VP7021_COLD 0x3207
60#define USB_PID_TWINHAN_VP7021_WARM 0x3208 62#define USB_PID_TWINHAN_VP7021_WARM 0x3208
63#define USB_PID_DNTV_TINYUSB2_COLD 0x3223
64#define USB_PID_DNTV_TINYUSB2_WARM 0x3224
61#define USB_PID_ULTIMA_TVBOX_COLD 0x8105 65#define USB_PID_ULTIMA_TVBOX_COLD 0x8105
62#define USB_PID_ULTIMA_TVBOX_WARM 0x8106 66#define USB_PID_ULTIMA_TVBOX_WARM 0x8106
63#define USB_PID_ULTIMA_TVBOX_AN2235_COLD 0x8107 67#define USB_PID_ULTIMA_TVBOX_AN2235_COLD 0x8107
@@ -85,5 +89,7 @@
85#define USB_PID_MEDION_MD95700 0x0932 89#define USB_PID_MEDION_MD95700 0x0932
86#define USB_PID_KYE_DVB_T_COLD 0x701e 90#define USB_PID_KYE_DVB_T_COLD 0x701e
87#define USB_PID_KYE_DVB_T_WARM 0x701f 91#define USB_PID_KYE_DVB_T_WARM 0x701f
92#define USB_PID_PCTV_200E 0x020e
93#define USB_PID_PCTV_400E 0x020f
88 94
89#endif 95#endif
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-init.c b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
index 65f0c095ab..a902059812 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-init.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
@@ -128,7 +128,9 @@ static struct dvb_usb_device_description * dvb_usb_find_device(struct usb_device
128/* 128/*
129 * USB 129 * USB
130 */ 130 */
131int dvb_usb_device_init(struct usb_interface *intf, struct dvb_usb_properties *props, struct module *owner) 131
132int dvb_usb_device_init(struct usb_interface *intf, struct dvb_usb_properties
133 *props, struct module *owner,struct dvb_usb_device **du)
132{ 134{
133 struct usb_device *udev = interface_to_usbdev(intf); 135 struct usb_device *udev = interface_to_usbdev(intf);
134 struct dvb_usb_device *d = NULL; 136 struct dvb_usb_device *d = NULL;
@@ -170,6 +172,9 @@ int dvb_usb_device_init(struct usb_interface *intf, struct dvb_usb_properties *p
170 172
171 usb_set_intfdata(intf, d); 173 usb_set_intfdata(intf, d);
172 174
175 if (du != NULL)
176 *du = d;
177
173 ret = dvb_usb_init(d); 178 ret = dvb_usb_init(d);
174 } 179 }
175 180
@@ -196,19 +201,6 @@ void dvb_usb_device_exit(struct usb_interface *intf)
196} 201}
197EXPORT_SYMBOL(dvb_usb_device_exit); 202EXPORT_SYMBOL(dvb_usb_device_exit);
198 203
199/* module stuff */
200static int __init dvb_usb_module_init(void)
201{
202 return 0;
203}
204
205static void __exit dvb_usb_module_exit(void)
206{
207}
208
209module_init (dvb_usb_module_init);
210module_exit (dvb_usb_module_exit);
211
212MODULE_VERSION("0.3"); 204MODULE_VERSION("0.3");
213MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>"); 205MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
214MODULE_DESCRIPTION("A library module containing commonly used USB and DVB function USB DVB devices"); 206MODULE_DESCRIPTION("A library module containing commonly used USB and DVB function USB DVB devices");
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb.h b/drivers/media/dvb/dvb-usb/dvb-usb.h
index a80567caf5..0e4f1035b0 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb.h
@@ -127,7 +127,7 @@ struct dvb_usb_device;
127 * helper functions. 127 * helper functions.
128 * 128 *
129 * @urb: describes the kind of USB transfer used for MPEG2-TS-streaming. 129 * @urb: describes the kind of USB transfer used for MPEG2-TS-streaming.
130 * Currently only BULK is implemented 130 * (BULK or ISOC)
131 * 131 *
132 * @num_device_descs: number of struct dvb_usb_device_description in @devices 132 * @num_device_descs: number of struct dvb_usb_device_description in @devices
133 * @devices: array of struct dvb_usb_device_description compatibles with these 133 * @devices: array of struct dvb_usb_device_description compatibles with these
@@ -310,7 +310,7 @@ struct dvb_usb_device {
310 void *priv; 310 void *priv;
311}; 311};
312 312
313extern int dvb_usb_device_init(struct usb_interface *, struct dvb_usb_properties *, struct module *); 313extern int dvb_usb_device_init(struct usb_interface *, struct dvb_usb_properties *, struct module *, struct dvb_usb_device **);
314extern void dvb_usb_device_exit(struct usb_interface *); 314extern void dvb_usb_device_exit(struct usb_interface *);
315 315
316/* the generic read/write method for device control */ 316/* the generic read/write method for device control */
diff --git a/drivers/media/dvb/dvb-usb/nova-t-usb2.c b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
index 258a92bfbc..1841a66427 100644
--- a/drivers/media/dvb/dvb-usb/nova-t-usb2.c
+++ b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
@@ -144,7 +144,7 @@ static struct dvb_usb_properties nova_t_properties;
144static int nova_t_probe(struct usb_interface *intf, 144static int nova_t_probe(struct usb_interface *intf,
145 const struct usb_device_id *id) 145 const struct usb_device_id *id)
146{ 146{
147 return dvb_usb_device_init(intf,&nova_t_properties,THIS_MODULE); 147 return dvb_usb_device_init(intf,&nova_t_properties,THIS_MODULE,NULL);
148} 148}
149 149
150/* do not change the order of the ID table */ 150/* do not change the order of the ID table */
diff --git a/drivers/media/dvb/dvb-usb/umt-010.c b/drivers/media/dvb/dvb-usb/umt-010.c
index 2112ac3cf5..6fd67657c2 100644
--- a/drivers/media/dvb/dvb-usb/umt-010.c
+++ b/drivers/media/dvb/dvb-usb/umt-010.c
@@ -77,7 +77,7 @@ static struct dvb_usb_properties umt_properties;
77static int umt_probe(struct usb_interface *intf, 77static int umt_probe(struct usb_interface *intf,
78 const struct usb_device_id *id) 78 const struct usb_device_id *id)
79{ 79{
80 if (dvb_usb_device_init(intf,&umt_properties,THIS_MODULE) == 0) 80 if (dvb_usb_device_init(intf,&umt_properties,THIS_MODULE,NULL) == 0)
81 return 0; 81 return 0;
82 return -EINVAL; 82 return -EINVAL;
83} 83}
diff --git a/drivers/media/dvb/dvb-usb/vp702x-fe.c b/drivers/media/dvb/dvb-usb/vp702x-fe.c
new file mode 100644
index 0000000000..f20d8dbd0b
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/vp702x-fe.c
@@ -0,0 +1,339 @@
1/* DVB frontend part of the Linux driver for the TwinhanDTV StarBox USB2.0
2 * DVB-S receiver.
3 *
4 * Copyright (C) 2005 Ralph Metzler <rjkm@metzlerbros.de>
5 * Metzler Brothers Systementwicklung GbR
6 *
7 * Copyright (C) 2005 Patrick Boettcher <patrick.boettcher@desy.de>
8 *
9 * Thanks to Twinhan who kindly provided hardware and information.
10 *
11 * This file can be removed soon, after the DST-driver is rewritten to provice
12 * the frontend-controlling separately.
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the Free
16 * Software Foundation, version 2.
17 *
18 * see Documentation/dvb/README.dvb-usb for more information
19 *
20 */
21#include "vp702x.h"
22
23struct vp702x_fe_state {
24 struct dvb_frontend fe;
25 struct dvb_usb_device *d;
26
27 fe_sec_voltage_t voltage;
28 fe_sec_tone_mode_t tone_mode;
29
30 u8 lnb_buf[8];
31
32 u8 lock;
33 u8 sig;
34 u8 snr;
35
36 unsigned long next_status_check;
37 unsigned long status_check_interval;
38};
39
40static int vp702x_fe_refresh_state(struct vp702x_fe_state *st)
41{
42 u8 buf[10];
43 if (time_after(jiffies,st->next_status_check)) {
44 vp702x_usb_in_op(st->d,READ_STATUS,0,0,buf,10);
45
46 st->lock = buf[4];
47 vp702x_usb_in_op(st->d,READ_TUNER_REG_REQ,0x11,0,&st->snr,1);
48 vp702x_usb_in_op(st->d,READ_TUNER_REG_REQ,0x15,0,&st->sig,1);
49
50 st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000;
51 }
52 return 0;
53}
54
55static u8 vp702x_chksum(u8 *buf,int f, int count)
56{
57 u8 s = 0;
58 int i;
59 for (i = f; i < f+count; i++)
60 s += buf[i];
61 return ~s+1;
62}
63
64static int vp702x_fe_read_status(struct dvb_frontend* fe, fe_status_t *status)
65{
66 struct vp702x_fe_state *st = fe->demodulator_priv;
67 vp702x_fe_refresh_state(st);
68 deb_fe("%s\n",__FUNCTION__);
69
70 if (st->lock == 0)
71 *status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI | FE_HAS_SIGNAL | FE_HAS_CARRIER;
72 else
73 *status = 0;
74
75 deb_fe("real state: %x\n",*status);
76 *status = 0x1f;
77
78 if (*status & FE_HAS_LOCK)
79 st->status_check_interval = 1000;
80 else
81 st->status_check_interval = 250;
82 return 0;
83}
84
85/* not supported by this Frontend */
86static int vp702x_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
87{
88 struct vp702x_fe_state *st = fe->demodulator_priv;
89 vp702x_fe_refresh_state(st);
90 *ber = 0;
91 return 0;
92}
93
94/* not supported by this Frontend */
95static int vp702x_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
96{
97 struct vp702x_fe_state *st = fe->demodulator_priv;
98 vp702x_fe_refresh_state(st);
99 *unc = 0;
100 return 0;
101}
102
103static int vp702x_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
104{
105 struct vp702x_fe_state *st = fe->demodulator_priv;
106 vp702x_fe_refresh_state(st);
107
108 *strength = (st->sig << 8) | st->sig;
109 return 0;
110}
111
112static int vp702x_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
113{
114 u8 _snr;
115 struct vp702x_fe_state *st = fe->demodulator_priv;
116 vp702x_fe_refresh_state(st);
117
118 _snr = (st->snr & 0x1f) * 0xff / 0x1f;
119 *snr = (_snr << 8) | _snr;
120 return 0;
121}
122
123static int vp702x_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
124{
125 deb_fe("%s\n",__FUNCTION__);
126 tune->min_delay_ms = 2000;
127 return 0;
128}
129
130static int vp702x_fe_set_frontend(struct dvb_frontend* fe,
131 struct dvb_frontend_parameters *fep)
132{
133 struct vp702x_fe_state *st = fe->demodulator_priv;
134 u32 freq = fep->frequency/1000;
135 /*CalFrequency*/
136/* u16 frequencyRef[16] = { 2, 4, 8, 16, 32, 64, 128, 256, 24, 5, 10, 20, 40, 80, 160, 320 }; */
137 u64 sr;
138 u8 cmd[8] = { 0 },ibuf[10];
139
140 cmd[0] = (freq >> 8) & 0x7f;
141 cmd[1] = freq & 0xff;
142 cmd[2] = 1; /* divrate == 4 -> frequencyRef[1] -> 1 here */
143
144 sr = (u64) (fep->u.qpsk.symbol_rate/1000) << 20;
145 do_div(sr,88000);
146 cmd[3] = (sr >> 12) & 0xff;
147 cmd[4] = (sr >> 4) & 0xff;
148 cmd[5] = (sr << 4) & 0xf0;
149
150 deb_fe("setting frontend to: %u -> %u (%x) LNB-based GHz, symbolrate: %d -> %Lu (%Lx)\n",
151 fep->frequency,freq,freq, fep->u.qpsk.symbol_rate, sr, sr);
152
153/* if (fep->inversion == INVERSION_ON)
154 cmd[6] |= 0x80; */
155
156 if (st->voltage == SEC_VOLTAGE_18)
157 cmd[6] |= 0x40;
158
159/* if (fep->u.qpsk.symbol_rate > 8000000)
160 cmd[6] |= 0x20;
161
162 if (fep->frequency < 1531000)
163 cmd[6] |= 0x04;
164
165 if (st->tone_mode == SEC_TONE_ON)
166 cmd[6] |= 0x01;*/
167
168 cmd[7] = vp702x_chksum(cmd,0,7);
169
170 st->status_check_interval = 250;
171 st->next_status_check = jiffies;
172
173 vp702x_usb_in_op(st->d, RESET_TUNER, 0, 0, NULL, 0);
174 msleep(30);
175 vp702x_usb_inout_op(st->d,cmd,8,ibuf,10,100);
176
177 if (ibuf[2] == 0 && ibuf[3] == 0)
178 deb_fe("tuning failed.\n");
179 else
180 deb_fe("tuning succeeded.\n");
181
182 return 0;
183}
184
185static int vp702x_fe_get_frontend(struct dvb_frontend* fe,
186 struct dvb_frontend_parameters *fep)
187{
188 deb_fe("%s\n",__FUNCTION__);
189 return 0;
190}
191
192static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe,
193 struct dvb_diseqc_master_cmd *m)
194{
195 struct vp702x_fe_state *st = fe->demodulator_priv;
196 u8 cmd[8],ibuf[10];
197 memset(cmd,0,8);
198
199 deb_fe("%s\n",__FUNCTION__);
200
201 if (m->msg_len > 4)
202 return -EINVAL;
203
204 cmd[1] = SET_DISEQC_CMD;
205 cmd[2] = m->msg_len;
206 memcpy(&cmd[3], m->msg, m->msg_len);
207 cmd[7] = vp702x_chksum(cmd,0,7);
208
209 vp702x_usb_inout_op(st->d,cmd,8,ibuf,10,100);
210
211 if (ibuf[2] == 0 && ibuf[3] == 0)
212 deb_fe("diseqc cmd failed.\n");
213 else
214 deb_fe("diseqc cmd succeeded.\n");
215
216 return 0;
217}
218
219static int vp702x_fe_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t burst)
220{
221 deb_fe("%s\n",__FUNCTION__);
222 return 0;
223}
224
225static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
226{
227 struct vp702x_fe_state *st = fe->demodulator_priv;
228 u8 ibuf[10];
229 deb_fe("%s\n",__FUNCTION__);
230
231 st->tone_mode = tone;
232
233 if (tone == SEC_TONE_ON)
234 st->lnb_buf[2] = 0x02;
235 else
236 st->lnb_buf[2] = 0x00;
237
238 st->lnb_buf[7] = vp702x_chksum(st->lnb_buf,0,7);
239
240 vp702x_usb_inout_op(st->d,st->lnb_buf,8,ibuf,10,100);
241 if (ibuf[2] == 0 && ibuf[3] == 0)
242 deb_fe("set_tone cmd failed.\n");
243 else
244 deb_fe("set_tone cmd succeeded.\n");
245
246 return 0;
247}
248
249static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t
250 voltage)
251{
252 struct vp702x_fe_state *st = fe->demodulator_priv;
253 u8 ibuf[10];
254 deb_fe("%s\n",__FUNCTION__);
255
256 st->voltage = voltage;
257
258 if (voltage != SEC_VOLTAGE_OFF)
259 st->lnb_buf[4] = 0x01;
260 else
261 st->lnb_buf[4] = 0x00;
262
263 st->lnb_buf[7] = vp702x_chksum(st->lnb_buf,0,7);
264
265 vp702x_usb_inout_op(st->d,st->lnb_buf,8,ibuf,10,100);
266 if (ibuf[2] == 0 && ibuf[3] == 0)
267 deb_fe("set_voltage cmd failed.\n");
268 else
269 deb_fe("set_voltage cmd succeeded.\n");
270
271 return 0;
272}
273
274static void vp702x_fe_release(struct dvb_frontend* fe)
275{
276 struct vp702x_fe_state *st = fe->demodulator_priv;
277 kfree(st);
278}
279
280static struct dvb_frontend_ops vp702x_fe_ops;
281
282struct dvb_frontend * vp702x_fe_attach(struct dvb_usb_device *d)
283{
284 struct vp702x_fe_state *s = kmalloc(sizeof(struct vp702x_fe_state), GFP_KERNEL);
285 if (s == NULL)
286 goto error;
287 memset(s,0,sizeof(struct vp702x_fe_state));
288
289 s->d = d;
290 s->fe.ops = &vp702x_fe_ops;
291 s->fe.demodulator_priv = s;
292
293 s->lnb_buf[1] = SET_LNB_POWER;
294 s->lnb_buf[3] = 0xff; /* 0=tone burst, 2=data burst, ff=off */
295
296 goto success;
297error:
298 return NULL;
299success:
300 return &s->fe;
301}
302
303
304static struct dvb_frontend_ops vp702x_fe_ops = {
305 .info = {
306 .name = "Twinhan DST-like frontend (VP7021/VP7020) DVB-S",
307 .type = FE_QPSK,
308 .frequency_min = 950000,
309 .frequency_max = 2150000,
310 .frequency_stepsize = 1000, /* kHz for QPSK frontends */
311 .frequency_tolerance = 0,
312 .symbol_rate_min = 1000000,
313 .symbol_rate_max = 45000000,
314 .symbol_rate_tolerance = 500, /* ppm */
315 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
316 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |
317 FE_CAN_QPSK |
318 FE_CAN_FEC_AUTO
319 },
320 .release = vp702x_fe_release,
321
322 .init = NULL,
323 .sleep = NULL,
324
325 .set_frontend = vp702x_fe_set_frontend,
326 .get_frontend = vp702x_fe_get_frontend,
327 .get_tune_settings = vp702x_fe_get_tune_settings,
328
329 .read_status = vp702x_fe_read_status,
330 .read_ber = vp702x_fe_read_ber,
331 .read_signal_strength = vp702x_fe_read_signal_strength,
332 .read_snr = vp702x_fe_read_snr,
333 .read_ucblocks = vp702x_fe_read_unc_blocks,
334
335 .diseqc_send_master_cmd = vp702x_fe_send_diseqc_msg,
336 .diseqc_send_burst = vp702x_fe_send_diseqc_burst,
337 .set_tone = vp702x_fe_set_tone,
338 .set_voltage = vp702x_fe_set_voltage,
339};
diff --git a/drivers/media/dvb/dvb-usb/vp702x.c b/drivers/media/dvb/dvb-usb/vp702x.c
new file mode 100644
index 0000000000..de13c04e8e
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/vp702x.c
@@ -0,0 +1,290 @@
1/* DVB USB compliant Linux driver for the TwinhanDTV StarBox USB2.0 DVB-S
2 * receiver.
3 *
4 * Copyright (C) 2005 Ralph Metzler <rjkm@metzlerbros.de>
5 * Metzler Brothers Systementwicklung GbR
6 *
7 * Copyright (C) 2005 Patrick Boettcher <patrick.boettcher@desy.de>
8 *
9 * Thanks to Twinhan who kindly provided hardware and information.
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation, version 2.
14 *
15 * see Documentation/dvb/README.dvb-usb for more information
16 */
17#include "vp702x.h"
18
19/* debug */
20int dvb_usb_vp702x_debug;
21module_param_named(debug,dvb_usb_vp702x_debug, int, 0644);
22MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS);
23
24struct vp702x_state {
25 u8 pid_table[17]; /* [16] controls the pid_table state */
26};
27
28/* check for mutex FIXME */
29int vp702x_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen)
30{
31 int ret = 0,try = 0;
32
33 while (ret >= 0 && ret != blen && try < 3) {
34 ret = usb_control_msg(d->udev,
35 usb_rcvctrlpipe(d->udev,0),
36 req,
37 USB_TYPE_VENDOR | USB_DIR_IN,
38 value,index,b,blen,
39 2000);
40 deb_info("reading number %d (ret: %d)\n",try,ret);
41 try++;
42 }
43
44 if (ret < 0 || ret != blen) {
45 warn("usb in operation failed.");
46 ret = -EIO;
47 } else
48 ret = 0;
49
50 deb_xfer("in: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
51 debug_dump(b,blen,deb_xfer);
52
53 return ret;
54}
55
56int vp702x_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen)
57{
58 deb_xfer("out: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
59 debug_dump(b,blen,deb_xfer);
60
61 if (usb_control_msg(d->udev,
62 usb_sndctrlpipe(d->udev,0),
63 req,
64 USB_TYPE_VENDOR | USB_DIR_OUT,
65 value,index,b,blen,
66 2000) != blen) {
67 warn("usb out operation failed.");
68 return -EIO;
69 } else
70 return 0;
71}
72
73int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i, int ilen, int msec)
74{
75 int ret;
76
77 if ((ret = down_interruptible(&d->usb_sem)))
78 return ret;
79
80 if ((ret = vp702x_usb_out_op(d,REQUEST_OUT,0,0,o,olen)) < 0)
81 goto unlock;
82 msleep(msec);
83 ret = vp702x_usb_in_op(d,REQUEST_IN,0,0,i,ilen);
84
85unlock:
86 up(&d->usb_sem);
87
88 return ret;
89}
90
91int vp702x_usb_inout_cmd(struct dvb_usb_device *d, u8 cmd, u8 *o, int olen, u8 *i, int ilen, int msec)
92{
93 u8 bout[olen+2];
94 u8 bin[ilen+1];
95 int ret = 0;
96
97 bout[0] = 0x00;
98 bout[1] = cmd;
99 memcpy(&bout[2],o,olen);
100
101 ret = vp702x_usb_inout_op(d, bout, olen+2, bin, ilen+1,msec);
102
103 if (ret == 0)
104 memcpy(i,&bin[1],ilen);
105
106 return ret;
107}
108
109static int vp702x_pid_filter(struct dvb_usb_device *d, int index, u16 pid, int onoff)
110{
111 struct vp702x_state *st = d->priv;
112 u8 buf[9];
113
114 if (onoff) {
115 st->pid_table[16] |= 1 << index;
116 st->pid_table[index*2] = (pid >> 8) & 0xff;
117 st->pid_table[index*2+1] = pid & 0xff;
118 } else {
119 st->pid_table[16] &= ~(1 << index);
120 st->pid_table[index*2] = st->pid_table[index*2+1] = 0;
121 }
122
123 return vp702x_usb_inout_cmd(d,SET_PID_FILTER,st->pid_table,17,buf,9,10);
124}
125
126static int vp702x_power_ctrl(struct dvb_usb_device *d, int onoff)
127{
128 vp702x_usb_in_op(d,RESET_TUNER,0,0,NULL,0);
129
130 vp702x_usb_in_op(d,SET_TUNER_POWER_REQ,0,onoff,NULL,0);
131 return vp702x_usb_in_op(d,SET_TUNER_POWER_REQ,0,onoff,NULL,0);
132}
133
134/* keys for the enclosed remote control */
135static struct dvb_usb_rc_key vp702x_rc_keys[] = {
136 { 0x00, 0x01, KEY_1 },
137 { 0x00, 0x02, KEY_2 },
138};
139
140/* remote control stuff (does not work with my box) */
141static int vp702x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
142{
143 u8 key[10];
144 int i;
145
146/* remove the following return to enabled remote querying */
147 return 0;
148
149 vp702x_usb_in_op(d,READ_REMOTE_REQ,0,0,key,10);
150
151 deb_rc("remote query key: %x %d\n",key[1],key[1]);
152
153 if (key[1] == 0x44) {
154 *state = REMOTE_NO_KEY_PRESSED;
155 return 0;
156 }
157
158 for (i = 0; i < ARRAY_SIZE(vp702x_rc_keys); i++)
159 if (vp702x_rc_keys[i].custom == key[1]) {
160 *state = REMOTE_KEY_PRESSED;
161 *event = vp702x_rc_keys[i].event;
162 break;
163 }
164 return 0;
165}
166
167static int vp702x_read_mac_addr(struct dvb_usb_device *d,u8 mac[6])
168{
169 u8 macb[9];
170 if (vp702x_usb_inout_cmd(d, GET_MAC_ADDRESS, NULL, 0, macb, 9, 10))
171 return -EIO;
172 memcpy(mac,&macb[3],6);
173 return 0;
174}
175
176static int vp702x_frontend_attach(struct dvb_usb_device *d)
177{
178 u8 buf[9] = { 0 };
179
180 if (vp702x_usb_inout_cmd(d, GET_SYSTEM_STRING, NULL, 0, buf, 9, 10))
181 return -EIO;
182
183 buf[8] = '\0';
184 info("system string: %s",&buf[1]);
185
186 d->fe = vp702x_fe_attach(d);
187 return 0;
188}
189
190static struct dvb_usb_properties vp702x_properties;
191
192static int vp702x_usb_probe(struct usb_interface *intf,
193 const struct usb_device_id *id)
194{
195 struct usb_device *udev = interface_to_usbdev(intf);
196
197 usb_clear_halt(udev,usb_sndctrlpipe(udev,0));
198 usb_clear_halt(udev,usb_rcvctrlpipe(udev,0));
199
200 return dvb_usb_device_init(intf,&vp702x_properties,THIS_MODULE,NULL);
201}
202
203static struct usb_device_id vp702x_usb_table [] = {
204 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7021_COLD) },
205 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7021_WARM) },
206 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7020_COLD) },
207 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7020_WARM) },
208 { 0 },
209};
210MODULE_DEVICE_TABLE(usb, vp702x_usb_table);
211
212static struct dvb_usb_properties vp702x_properties = {
213 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_NEED_PID_FILTERING,
214 .pid_filter_count = 8, /* !!! */
215
216 .usb_ctrl = CYPRESS_FX2,
217 .firmware = "dvb-usb-vp702x-01.fw",
218
219 .pid_filter = vp702x_pid_filter,
220 .power_ctrl = vp702x_power_ctrl,
221 .frontend_attach = vp702x_frontend_attach,
222 .read_mac_address = vp702x_read_mac_addr,
223
224 .rc_key_map = vp702x_rc_keys,
225 .rc_key_map_size = ARRAY_SIZE(vp702x_rc_keys),
226 .rc_interval = 400,
227 .rc_query = vp702x_rc_query,
228
229 .size_of_priv = sizeof(struct vp702x_state),
230
231 /* parameter for the MPEG2-data transfer */
232 .urb = {
233 .type = DVB_USB_BULK,
234 .count = 7,
235 .endpoint = 0x02,
236 .u = {
237 .bulk = {
238 .buffersize = 4096,
239 }
240 }
241 },
242
243 .num_device_descs = 2,
244 .devices = {
245 { .name = "TwinhanDTV StarBox DVB-S USB2.0 (VP7021)",
246 .cold_ids = { &vp702x_usb_table[0], NULL },
247 .warm_ids = { &vp702x_usb_table[1], NULL },
248 },
249 { .name = "TwinhanDTV StarBox DVB-S USB2.0 (VP7020)",
250 .cold_ids = { &vp702x_usb_table[2], NULL },
251 .warm_ids = { &vp702x_usb_table[3], NULL },
252 },
253 { 0 },
254 }
255};
256
257/* usb specific object needed to register this driver with the usb subsystem */
258static struct usb_driver vp702x_usb_driver = {
259 .owner = THIS_MODULE,
260 .name = "dvb-usb-vp702x",
261 .probe = vp702x_usb_probe,
262 .disconnect = dvb_usb_device_exit,
263 .id_table = vp702x_usb_table,
264};
265
266/* module stuff */
267static int __init vp702x_usb_module_init(void)
268{
269 int result;
270 if ((result = usb_register(&vp702x_usb_driver))) {
271 err("usb_register failed. (%d)",result);
272 return result;
273 }
274
275 return 0;
276}
277
278static void __exit vp702x_usb_module_exit(void)
279{
280 /* deregister this driver from the USB subsystem */
281 usb_deregister(&vp702x_usb_driver);
282}
283
284module_init(vp702x_usb_module_init);
285module_exit(vp702x_usb_module_exit);
286
287MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
288MODULE_DESCRIPTION("Driver for Twinhan StarBox DVB-S USB2.0 and clones");
289MODULE_VERSION("1.0-alpha");
290MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/vp702x.h b/drivers/media/dvb/dvb-usb/vp702x.h
new file mode 100644
index 0000000000..4a3e8c7eca
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/vp702x.h
@@ -0,0 +1,109 @@
1#ifndef _DVB_USB_VP7021_H_
2#define _DVB_USB_VP7021_H_
3
4#define DVB_USB_LOG_PREFIX "vp702x"
5#include "dvb-usb.h"
6
7extern int dvb_usb_vp702x_debug;
8#define deb_info(args...) dprintk(dvb_usb_vp702x_debug,0x01,args)
9#define deb_xfer(args...) dprintk(dvb_usb_vp702x_debug,0x02,args)
10#define deb_rc(args...) dprintk(dvb_usb_vp702x_debug,0x04,args)
11#define deb_fe(args...) dprintk(dvb_usb_vp702x_debug,0x08,args)
12
13/* commands are read and written with USB control messages */
14
15/* consecutive read/write operation */
16#define REQUEST_OUT 0xB2
17#define REQUEST_IN 0xB3
18
19/* the out-buffer of these consecutive operations contain sub-commands when b[0] = 0
20 * request: 0xB2; i: 0; v: 0; b[0] = 0, b[1] = subcmd, additional buffer
21 * the returning buffer looks as follows
22 * request: 0xB3; i: 0; v: 0; b[0] = 0xB3, additional buffer */
23
24#define GET_TUNER_STATUS 0x05
25/* additional in buffer:
26 * 0 1 2 3 4 5 6 7 8
27 * N/A N/A 0x05 signal-quality N/A N/A signal-strength lock==0 N/A */
28
29#define GET_SYSTEM_STRING 0x06
30/* additional in buffer:
31 * 0 1 2 3 4 5 6 7 8
32 * N/A 'U' 'S' 'B' '7' '0' '2' 'X' N/A */
33
34#define SET_DISEQC_CMD 0x08
35/* additional out buffer:
36 * 0 1 2 3 4
37 * len X1 X2 X3 X4
38 * additional in buffer:
39 * 0 1 2
40 * N/A 0 0 b[1] == b[2] == 0 -> success otherwise not */
41
42#define SET_LNB_POWER 0x09
43/* additional out buffer:
44 * 0 1 2
45 * 0x00 0xff 1 = on, 0 = off
46 * additional in buffer:
47 * 0 1 2
48 * N/A 0 0 b[1] == b[2] == 0 -> success otherwise not */
49
50#define GET_MAC_ADDRESS 0x0A
51/* #define GET_MAC_ADDRESS 0x0B */
52/* additional in buffer:
53 * 0 1 2 3 4 5 6 7 8
54 * N/A N/A 0x0A or 0x0B MAC0 MAC1 MAC2 MAC3 MAC4 MAC5 */
55
56#define SET_PID_FILTER 0x11
57/* additional in buffer:
58 * 0 1 ... 14 15 16
59 * PID0_MSB PID0_LSB ... PID7_MSB PID7_LSB PID_active (bits) */
60
61/* request: 0xB2; i: 0; v: 0;
62 * b[0] != 0 -> tune and lock a channel
63 * 0 1 2 3 4 5 6 7
64 * freq0 freq1 divstep srate0 srate1 srate2 flag chksum
65 */
66
67
68/* one direction requests */
69#define READ_REMOTE_REQ 0xB4
70/* IN i: 0; v: 0; b[0] == request, b[1] == key */
71
72#define READ_PID_NUMBER_REQ 0xB5
73/* IN i: 0; v: 0; b[0] == request, b[1] == 0, b[2] = pid number */
74
75#define WRITE_EEPROM_REQ 0xB6
76/* OUT i: offset; v: value to write; no extra buffer */
77
78#define READ_EEPROM_REQ 0xB7
79/* IN i: bufferlen; v: offset; buffer with bufferlen bytes */
80
81#define READ_STATUS 0xB8
82/* IN i: 0; v: 0; bufferlen 10 */
83
84#define READ_TUNER_REG_REQ 0xB9
85/* IN i: 0; v: register; b[0] = value */
86
87#define READ_FX2_REG_REQ 0xBA
88/* IN i: offset; v: 0; b[0] = value */
89
90#define WRITE_FX2_REG_REQ 0xBB
91/* OUT i: offset; v: value to write; 1 byte extra buffer */
92
93#define SET_TUNER_POWER_REQ 0xBC
94/* IN i: 0 = power off, 1 = power on */
95
96#define WRITE_TUNER_REG_REQ 0xBD
97/* IN i: register, v: value to write, no extra buffer */
98
99#define RESET_TUNER 0xBE
100/* IN i: 0, v: 0, no extra buffer */
101
102extern struct dvb_frontend * vp702x_fe_attach(struct dvb_usb_device *d);
103
104extern int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i, int ilen, int msec);
105extern int vp702x_usb_inout_cmd(struct dvb_usb_device *d, u8 cmd, u8 *o, int olen, u8 *i, int ilen, int msec);
106extern int vp702x_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen);
107extern int vp702x_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen);
108
109#endif
diff --git a/drivers/media/dvb/dvb-usb/vp7045.c b/drivers/media/dvb/dvb-usb/vp7045.c
index 9ac95f54f9..0f57abeb6d 100644
--- a/drivers/media/dvb/dvb-usb/vp7045.c
+++ b/drivers/media/dvb/dvb-usb/vp7045.c
@@ -164,7 +164,6 @@ static int vp7045_read_eeprom(struct dvb_usb_device *d,u8 *buf, int len, int off
164 return 0; 164 return 0;
165} 165}
166 166
167
168static int vp7045_read_mac_addr(struct dvb_usb_device *d,u8 mac[6]) 167static int vp7045_read_mac_addr(struct dvb_usb_device *d,u8 mac[6])
169{ 168{
170 return vp7045_read_eeprom(d,mac, 6, MAC_0_ADDR); 169 return vp7045_read_eeprom(d,mac, 6, MAC_0_ADDR);
@@ -199,7 +198,7 @@ static struct dvb_usb_properties vp7045_properties;
199static int vp7045_usb_probe(struct usb_interface *intf, 198static int vp7045_usb_probe(struct usb_interface *intf,
200 const struct usb_device_id *id) 199 const struct usb_device_id *id)
201{ 200{
202 return dvb_usb_device_init(intf,&vp7045_properties,THIS_MODULE); 201 return dvb_usb_device_init(intf,&vp7045_properties,THIS_MODULE,NULL);
203} 202}
204 203
205static struct usb_device_id vp7045_usb_table [] = { 204static struct usb_device_id vp7045_usb_table [] = {
@@ -256,9 +255,9 @@ static struct dvb_usb_properties vp7045_properties = {
256static struct usb_driver vp7045_usb_driver = { 255static struct usb_driver vp7045_usb_driver = {
257 .owner = THIS_MODULE, 256 .owner = THIS_MODULE,
258 .name = "dvb_usb_vp7045", 257 .name = "dvb_usb_vp7045",
259 .probe = vp7045_usb_probe, 258 .probe = vp7045_usb_probe,
260 .disconnect = dvb_usb_device_exit, 259 .disconnect = dvb_usb_device_exit,
261 .id_table = vp7045_usb_table, 260 .id_table = vp7045_usb_table,
262}; 261};
263 262
264/* module stuff */ 263/* module stuff */
diff --git a/drivers/media/dvb/frontends/cx24110.c b/drivers/media/dvb/frontends/cx24110.c
index 8222b88cb4..d4b97989e3 100644
--- a/drivers/media/dvb/frontends/cx24110.c
+++ b/drivers/media/dvb/frontends/cx24110.c
@@ -1,7 +1,7 @@
1/* 1/*
2 cx24110 - Single Chip Satellite Channel Receiver driver module 2 cx24110 - Single Chip Satellite Channel Receiver driver module
3 3
4 Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@t-online.de> based on 4 Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@htp-tel.de> based on
5 work 5 work
6 Copyright (C) 1999 Convergence Integrated Media GmbH <ralph@convergence.de> 6 Copyright (C) 1999 Convergence Integrated Media GmbH <ralph@convergence.de>
7 7
@@ -387,8 +387,9 @@ static int cx24110_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltag
387 387
388static int cx24110_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t burst) 388static int cx24110_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t burst)
389{ 389{
390 int rv, bit, i; 390 int rv, bit;
391 struct cx24110_state *state = fe->demodulator_priv; 391 struct cx24110_state *state = fe->demodulator_priv;
392 unsigned long timeout;
392 393
393 if (burst == SEC_MINI_A) 394 if (burst == SEC_MINI_A)
394 bit = 0x00; 395 bit = 0x00;
@@ -398,12 +399,14 @@ static int cx24110_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t
398 return -EINVAL; 399 return -EINVAL;
399 400
400 rv = cx24110_readreg(state, 0x77); 401 rv = cx24110_readreg(state, 0x77);
401 cx24110_writereg(state, 0x77, rv|0x04); 402 if (!(rv & 0x04))
403 cx24110_writereg(state, 0x77, rv | 0x04);
402 404
403 rv = cx24110_readreg(state, 0x76); 405 rv = cx24110_readreg(state, 0x76);
404 cx24110_writereg(state, 0x76, ((rv & 0x90) | 0x40 | bit)); 406 cx24110_writereg(state, 0x76, ((rv & 0x90) | 0x40 | bit));
405 for (i = 500; i-- > 0 && !(cx24110_readreg(state,0x76)&0x40) ; ) 407 timeout = jiffies + msecs_to_jiffies(100);
406 ; /* wait for LNB ready */ 408 while (!time_after(jiffies, timeout) && !(cx24110_readreg(state, 0x76) & 0x40))
409 ; /* wait for LNB ready */
407 410
408 return 0; 411 return 0;
409} 412}
@@ -413,17 +416,22 @@ static int cx24110_send_diseqc_msg(struct dvb_frontend* fe,
413{ 416{
414 int i, rv; 417 int i, rv;
415 struct cx24110_state *state = fe->demodulator_priv; 418 struct cx24110_state *state = fe->demodulator_priv;
419 unsigned long timeout;
416 420
417 for (i = 0; i < cmd->msg_len; i++) 421 for (i = 0; i < cmd->msg_len; i++)
418 cx24110_writereg(state, 0x79 + i, cmd->msg[i]); 422 cx24110_writereg(state, 0x79 + i, cmd->msg[i]);
419 423
420 rv = cx24110_readreg(state, 0x77); 424 rv = cx24110_readreg(state, 0x77);
421 cx24110_writereg(state, 0x77, rv|0x04); 425 if (rv & 0x04) {
426 cx24110_writereg(state, 0x77, rv & ~0x04);
427 msleep(30); /* reportedly fixes switching problems */
428 }
422 429
423 rv = cx24110_readreg(state, 0x76); 430 rv = cx24110_readreg(state, 0x76);
424 431
425 cx24110_writereg(state, 0x76, ((rv & 0x90) | 0x40) | ((cmd->msg_len-3) & 3)); 432 cx24110_writereg(state, 0x76, ((rv & 0x90) | 0x40) | ((cmd->msg_len-3) & 3));
426 for (i=500; i-- > 0 && !(cx24110_readreg(state,0x76)&0x40);) 433 timeout = jiffies + msecs_to_jiffies(100);
434 while (!time_after(jiffies, timeout) && !(cx24110_readreg(state, 0x76) & 0x40))
427 ; /* wait for LNB ready */ 435 ; /* wait for LNB ready */
428 436
429 return 0; 437 return 0;
diff --git a/drivers/media/dvb/frontends/cx24110.h b/drivers/media/dvb/frontends/cx24110.h
index 6b663f4744..b63ecf2642 100644
--- a/drivers/media/dvb/frontends/cx24110.h
+++ b/drivers/media/dvb/frontends/cx24110.h
@@ -1,7 +1,7 @@
1/* 1/*
2 cx24110 - Single Chip Satellite Channel Receiver driver module 2 cx24110 - Single Chip Satellite Channel Receiver driver module
3 3
4 Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@t-online.de> based on 4 Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@htp-tel.de> based on
5 work 5 work
6 Copyright (C) 1999 Convergence Integrated Media GmbH <ralph@convergence.de> 6 Copyright (C) 1999 Convergence Integrated Media GmbH <ralph@convergence.de>
7 7
diff --git a/drivers/media/dvb/frontends/dib3000mb.c b/drivers/media/dvb/frontends/dib3000mb.c
index cd434b7cf9..21433e1831 100644
--- a/drivers/media/dvb/frontends/dib3000mb.c
+++ b/drivers/media/dvb/frontends/dib3000mb.c
@@ -23,7 +23,6 @@
23 23
24#include <linux/config.h> 24#include <linux/config.h>
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/version.h>
27#include <linux/module.h> 26#include <linux/module.h>
28#include <linux/moduleparam.h> 27#include <linux/moduleparam.h>
29#include <linux/init.h> 28#include <linux/init.h>
diff --git a/drivers/media/dvb/frontends/dib3000mc.c b/drivers/media/dvb/frontends/dib3000mc.c
index cd33705a43..441de665fe 100644
--- a/drivers/media/dvb/frontends/dib3000mc.c
+++ b/drivers/media/dvb/frontends/dib3000mc.c
@@ -22,7 +22,6 @@
22 */ 22 */
23#include <linux/config.h> 23#include <linux/config.h>
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/version.h>
26#include <linux/module.h> 25#include <linux/module.h>
27#include <linux/moduleparam.h> 26#include <linux/moduleparam.h>
28#include <linux/init.h> 27#include <linux/init.h>
diff --git a/drivers/media/dvb/frontends/mt352.c b/drivers/media/dvb/frontends/mt352.c
index d32dc4de9e..cc1bc0edd6 100644
--- a/drivers/media/dvb/frontends/mt352.c
+++ b/drivers/media/dvb/frontends/mt352.c
@@ -462,9 +462,11 @@ static int mt352_read_signal_strength(struct dvb_frontend* fe, u16* strength)
462{ 462{
463 struct mt352_state* state = fe->demodulator_priv; 463 struct mt352_state* state = fe->demodulator_priv;
464 464
465 u16 signal = ((mt352_read_register(state, AGC_GAIN_1) << 8) & 0x0f) | 465 /* align the 12 bit AGC gain with the most significant bits */
466 (mt352_read_register(state, AGC_GAIN_0)); 466 u16 signal = ((mt352_read_register(state, AGC_GAIN_1) & 0x0f) << 12) |
467 (mt352_read_register(state, AGC_GAIN_0) << 4);
467 468
469 /* inverse of gain is signal strength */
468 *strength = ~signal; 470 *strength = ~signal;
469 return 0; 471 return 0;
470} 472}
diff --git a/drivers/media/dvb/frontends/nxt6000.c b/drivers/media/dvb/frontends/nxt6000.c
index 966de9853d..88a57b7911 100644
--- a/drivers/media/dvb/frontends/nxt6000.c
+++ b/drivers/media/dvb/frontends/nxt6000.c
@@ -482,6 +482,7 @@ static int nxt6000_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
482 if ((result = nxt6000_set_inversion(state, param->inversion)) < 0) 482 if ((result = nxt6000_set_inversion(state, param->inversion)) < 0)
483 return result; 483 return result;
484 484
485 msleep(500);
485 return 0; 486 return 0;
486} 487}
487 488
@@ -525,6 +526,12 @@ static int nxt6000_read_signal_strength(struct dvb_frontend* fe, u16* signal_str
525 return 0; 526 return 0;
526} 527}
527 528
529static int nxt6000_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
530{
531 tune->min_delay_ms = 500;
532 return 0;
533}
534
528static struct dvb_frontend_ops nxt6000_ops; 535static struct dvb_frontend_ops nxt6000_ops;
529 536
530struct dvb_frontend* nxt6000_attach(const struct nxt6000_config* config, 537struct dvb_frontend* nxt6000_attach(const struct nxt6000_config* config,
@@ -578,6 +585,8 @@ static struct dvb_frontend_ops nxt6000_ops = {
578 585
579 .init = nxt6000_init, 586 .init = nxt6000_init,
580 587
588 .get_tune_settings = nxt6000_fe_get_tune_settings,
589
581 .set_frontend = nxt6000_set_frontend, 590 .set_frontend = nxt6000_set_frontend,
582 591
583 .read_status = nxt6000_read_status, 592 .read_status = nxt6000_read_status,
diff --git a/drivers/media/dvb/frontends/or51132.c b/drivers/media/dvb/frontends/or51132.c
index cc0a77c790..b6d0eecc59 100644
--- a/drivers/media/dvb/frontends/or51132.c
+++ b/drivers/media/dvb/frontends/or51132.c
@@ -370,22 +370,19 @@ static int or51132_set_parameters(struct dvb_frontend* fe,
370 or51132_setmode(fe); 370 or51132_setmode(fe);
371 } 371 }
372 372
373 /* Change only if we are actually changing the channel */ 373 dvb_pll_configure(state->config->pll_desc, buf,
374 if (state->current_frequency != param->frequency) { 374 param->frequency, 0);
375 dvb_pll_configure(state->config->pll_desc, buf, 375 dprintk("set_parameters tuner bytes: 0x%02x 0x%02x "
376 param->frequency, 0); 376 "0x%02x 0x%02x\n",buf[0],buf[1],buf[2],buf[3]);
377 dprintk("set_parameters tuner bytes: 0x%02x 0x%02x " 377 if (i2c_writebytes(state, state->config->pll_address ,buf, 4))
378 "0x%02x 0x%02x\n",buf[0],buf[1],buf[2],buf[3]); 378 printk(KERN_WARNING "or51132: set_parameters error "
379 if (i2c_writebytes(state, state->config->pll_address ,buf, 4)) 379 "writing to tuner\n");
380 printk(KERN_WARNING "or51132: set_parameters error " 380
381 "writing to tuner\n"); 381 /* Set to current mode */
382 382 or51132_setmode(fe);
383 /* Set to current mode */ 383
384 or51132_setmode(fe); 384 /* Update current frequency */
385 385 state->current_frequency = param->frequency;
386 /* Update current frequency */
387 state->current_frequency = param->frequency;
388 }
389 return 0; 386 return 0;
390} 387}
391 388
diff --git a/drivers/media/dvb/frontends/s5h1420.c b/drivers/media/dvb/frontends/s5h1420.c
index 4f396ac8de..c7fe27fd53 100644
--- a/drivers/media/dvb/frontends/s5h1420.c
+++ b/drivers/media/dvb/frontends/s5h1420.c
@@ -48,7 +48,8 @@ struct s5h1420_state {
48}; 48};
49 49
50static u32 s5h1420_getsymbolrate(struct s5h1420_state* state); 50static u32 s5h1420_getsymbolrate(struct s5h1420_state* state);
51static int s5h1420_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings); 51static int s5h1420_get_tune_settings(struct dvb_frontend* fe,
52 struct dvb_frontend_tune_settings* fesettings);
52 53
53 54
54static int debug = 0; 55static int debug = 0;
@@ -91,7 +92,8 @@ static int s5h1420_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltag
91 92
92 switch(voltage) { 93 switch(voltage) {
93 case SEC_VOLTAGE_13: 94 case SEC_VOLTAGE_13:
94 s5h1420_writereg(state, 0x3c, (s5h1420_readreg(state, 0x3c) & 0xfe) | 0x02); 95 s5h1420_writereg(state, 0x3c,
96 (s5h1420_readreg(state, 0x3c) & 0xfe) | 0x02);
95 break; 97 break;
96 98
97 case SEC_VOLTAGE_18: 99 case SEC_VOLTAGE_18:
@@ -112,18 +114,21 @@ static int s5h1420_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
112 114
113 switch(tone) { 115 switch(tone) {
114 case SEC_TONE_ON: 116 case SEC_TONE_ON:
115 s5h1420_writereg(state, 0x3b, (s5h1420_readreg(state, 0x3b) & 0x74) | 0x08); 117 s5h1420_writereg(state, 0x3b,
118 (s5h1420_readreg(state, 0x3b) & 0x74) | 0x08);
116 break; 119 break;
117 120
118 case SEC_TONE_OFF: 121 case SEC_TONE_OFF:
119 s5h1420_writereg(state, 0x3b, (s5h1420_readreg(state, 0x3b) & 0x74) | 0x01); 122 s5h1420_writereg(state, 0x3b,
123 (s5h1420_readreg(state, 0x3b) & 0x74) | 0x01);
120 break; 124 break;
121 } 125 }
122 126
123 return 0; 127 return 0;
124} 128}
125 129
126static int s5h1420_send_master_cmd (struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd) 130static int s5h1420_send_master_cmd (struct dvb_frontend* fe,
131 struct dvb_diseqc_master_cmd* cmd)
127{ 132{
128 struct s5h1420_state* state = fe->demodulator_priv; 133 struct s5h1420_state* state = fe->demodulator_priv;
129 u8 val; 134 u8 val;
@@ -131,6 +136,9 @@ static int s5h1420_send_master_cmd (struct dvb_frontend* fe, struct dvb_diseqc_m
131 unsigned long timeout; 136 unsigned long timeout;
132 int result = 0; 137 int result = 0;
133 138
139 if (cmd->msg_len > 8)
140 return -EINVAL;
141
134 /* setup for DISEQC */ 142 /* setup for DISEQC */
135 val = s5h1420_readreg(state, 0x3b); 143 val = s5h1420_readreg(state, 0x3b);
136 s5h1420_writereg(state, 0x3b, 0x02); 144 s5h1420_writereg(state, 0x3b, 0x02);
@@ -138,16 +146,17 @@ static int s5h1420_send_master_cmd (struct dvb_frontend* fe, struct dvb_diseqc_m
138 146
139 /* write the DISEQC command bytes */ 147 /* write the DISEQC command bytes */
140 for(i=0; i< cmd->msg_len; i++) { 148 for(i=0; i< cmd->msg_len; i++) {
141 s5h1420_writereg(state, 0x3c + i, cmd->msg[i]); 149 s5h1420_writereg(state, 0x3d + i, cmd->msg[i]);
142 } 150 }
143 151
144 /* kick off transmission */ 152 /* kick off transmission */
145 s5h1420_writereg(state, 0x3b, s5h1420_readreg(state, 0x3b) | ((cmd->msg_len-1) << 4) | 0x08); 153 s5h1420_writereg(state, 0x3b, s5h1420_readreg(state, 0x3b) |
154 ((cmd->msg_len-1) << 4) | 0x08);
146 155
147 /* wait for transmission to complete */ 156 /* wait for transmission to complete */
148 timeout = jiffies + ((100*HZ) / 1000); 157 timeout = jiffies + ((100*HZ) / 1000);
149 while(time_before(jiffies, timeout)) { 158 while(time_before(jiffies, timeout)) {
150 if (s5h1420_readreg(state, 0x3b) & 0x08) 159 if (!(s5h1420_readreg(state, 0x3b) & 0x08))
151 break; 160 break;
152 161
153 msleep(5); 162 msleep(5);
@@ -161,7 +170,8 @@ static int s5h1420_send_master_cmd (struct dvb_frontend* fe, struct dvb_diseqc_m
161 return result; 170 return result;
162} 171}
163 172
164static int s5h1420_recv_slave_reply (struct dvb_frontend* fe, struct dvb_diseqc_slave_reply* reply) 173static int s5h1420_recv_slave_reply (struct dvb_frontend* fe,
174 struct dvb_diseqc_slave_reply* reply)
165{ 175{
166 struct s5h1420_state* state = fe->demodulator_priv; 176 struct s5h1420_state* state = fe->demodulator_priv;
167 u8 val; 177 u8 val;
@@ -205,7 +215,7 @@ static int s5h1420_recv_slave_reply (struct dvb_frontend* fe, struct dvb_diseqc_
205 215
206 /* extract data */ 216 /* extract data */
207 for(i=0; i< length; i++) { 217 for(i=0; i< length; i++) {
208 reply->msg[i] = s5h1420_readreg(state, 0x3c + i); 218 reply->msg[i] = s5h1420_readreg(state, 0x3d + i);
209 } 219 }
210 220
211exit: 221exit:
@@ -236,7 +246,7 @@ static int s5h1420_send_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t minicm
236 s5h1420_writereg(state, 0x3b, s5h1420_readreg(state, 0x3b) | 0x08); 246 s5h1420_writereg(state, 0x3b, s5h1420_readreg(state, 0x3b) | 0x08);
237 247
238 /* wait for transmission to complete */ 248 /* wait for transmission to complete */
239 timeout = jiffies + ((20*HZ) / 1000); 249 timeout = jiffies + ((100*HZ) / 1000);
240 while(time_before(jiffies, timeout)) { 250 while(time_before(jiffies, timeout)) {
241 if (!(s5h1420_readreg(state, 0x3b) & 0x08)) 251 if (!(s5h1420_readreg(state, 0x3b) & 0x08))
242 break; 252 break;
@@ -259,9 +269,9 @@ static fe_status_t s5h1420_get_status_bits(struct s5h1420_state* state)
259 269
260 val = s5h1420_readreg(state, 0x14); 270 val = s5h1420_readreg(state, 0x14);
261 if (val & 0x02) 271 if (val & 0x02)
262 status |= FE_HAS_SIGNAL; // FIXME: not sure if this is right 272 status |= FE_HAS_SIGNAL;
263 if (val & 0x01) 273 if (val & 0x01)
264 status |= FE_HAS_CARRIER; // FIXME: not sure if this is right 274 status |= FE_HAS_CARRIER;
265 val = s5h1420_readreg(state, 0x36); 275 val = s5h1420_readreg(state, 0x36);
266 if (val & 0x01) 276 if (val & 0x01)
267 status |= FE_HAS_VITERBI; 277 status |= FE_HAS_VITERBI;
@@ -284,8 +294,8 @@ static int s5h1420_read_status(struct dvb_frontend* fe, fe_status_t* status)
284 /* determine lock state */ 294 /* determine lock state */
285 *status = s5h1420_get_status_bits(state); 295 *status = s5h1420_get_status_bits(state);
286 296
287 /* fix for FEC 5/6 inversion issue - if it doesn't quite lock, invert the inversion, 297 /* fix for FEC 5/6 inversion issue - if it doesn't quite lock, invert
288 wait a bit and check again */ 298 the inversion, wait a bit and check again */
289 if (*status == (FE_HAS_SIGNAL|FE_HAS_CARRIER|FE_HAS_VITERBI)) { 299 if (*status == (FE_HAS_SIGNAL|FE_HAS_CARRIER|FE_HAS_VITERBI)) {
290 val = s5h1420_readreg(state, 0x32); 300 val = s5h1420_readreg(state, 0x32);
291 if ((val & 0x07) == 0x03) { 301 if ((val & 0x07) == 0x03) {
@@ -330,6 +340,10 @@ static int s5h1420_read_status(struct dvb_frontend* fe, fe_status_t* status)
330 tmp = (tmp * 2 * 7) / 8; 340 tmp = (tmp * 2 * 7) / 8;
331 break; 341 break;
332 } 342 }
343 if (tmp == 0) {
344 printk("s5h1420: avoided division by 0\n");
345 tmp = 1;
346 }
333 tmp = state->fclk / tmp; 347 tmp = state->fclk / tmp;
334 348
335 /* set the MPEG_CLK_INTL for the calculated data rate */ 349 /* set the MPEG_CLK_INTL for the calculated data rate */
@@ -368,16 +382,21 @@ static int s5h1420_read_ber(struct dvb_frontend* fe, u32* ber)
368 382
369 s5h1420_writereg(state, 0x46, 0x1d); 383 s5h1420_writereg(state, 0x46, 0x1d);
370 mdelay(25); 384 mdelay(25);
371 return (s5h1420_readreg(state, 0x48) << 8) | s5h1420_readreg(state, 0x47); 385
386 *ber = (s5h1420_readreg(state, 0x48) << 8) | s5h1420_readreg(state, 0x47);
387
388 return 0;
372} 389}
373 390
374static int s5h1420_read_signal_strength(struct dvb_frontend* fe, u16* strength) 391static int s5h1420_read_signal_strength(struct dvb_frontend* fe, u16* strength)
375{ 392{
376 struct s5h1420_state* state = fe->demodulator_priv; 393 struct s5h1420_state* state = fe->demodulator_priv;
377 394
378 u8 val = 0xff - s5h1420_readreg(state, 0x15); 395 u8 val = s5h1420_readreg(state, 0x15);
379 396
380 return (int) ((val << 8) | val); 397 *strength = (u16) ((val << 8) | val);
398
399 return 0;
381} 400}
382 401
383static int s5h1420_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) 402static int s5h1420_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
@@ -386,7 +405,10 @@ static int s5h1420_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
386 405
387 s5h1420_writereg(state, 0x46, 0x1f); 406 s5h1420_writereg(state, 0x46, 0x1f);
388 mdelay(25); 407 mdelay(25);
389 return (s5h1420_readreg(state, 0x48) << 8) | s5h1420_readreg(state, 0x47); 408
409 *ucblocks = (s5h1420_readreg(state, 0x48) << 8) | s5h1420_readreg(state, 0x47);
410
411 return 0;
390} 412}
391 413
392static void s5h1420_reset(struct s5h1420_state* state) 414static void s5h1420_reset(struct s5h1420_state* state)
@@ -396,11 +418,12 @@ static void s5h1420_reset(struct s5h1420_state* state)
396 udelay(10); 418 udelay(10);
397} 419}
398 420
399static void s5h1420_setsymbolrate(struct s5h1420_state* state, struct dvb_frontend_parameters *p) 421static void s5h1420_setsymbolrate(struct s5h1420_state* state,
422 struct dvb_frontend_parameters *p)
400{ 423{
401 u64 val; 424 u64 val;
402 425
403 val = (p->u.qpsk.symbol_rate / 1000) * (1<<24); 426 val = ((u64) p->u.qpsk.symbol_rate / 1000ULL) * (1ULL<<24);
404 if (p->u.qpsk.symbol_rate <= 21000000) { 427 if (p->u.qpsk.symbol_rate <= 21000000) {
405 val *= 2; 428 val *= 2;
406 } 429 }
@@ -415,7 +438,7 @@ static void s5h1420_setsymbolrate(struct s5h1420_state* state, struct dvb_fronte
415 438
416static u32 s5h1420_getsymbolrate(struct s5h1420_state* state) 439static u32 s5h1420_getsymbolrate(struct s5h1420_state* state)
417{ 440{
418 u64 val; 441 u64 val = 0;
419 int sampling = 2; 442 int sampling = 2;
420 443
421 if (s5h1420_readreg(state, 0x05) & 0x2) 444 if (s5h1420_readreg(state, 0x05) & 0x2)
@@ -427,10 +450,10 @@ static u32 s5h1420_getsymbolrate(struct s5h1420_state* state)
427 val |= s5h1420_readreg(state, 0x13); 450 val |= s5h1420_readreg(state, 0x13);
428 s5h1420_writereg(state, 0x06, s5h1420_readreg(state, 0x06) & 0xf7); 451 s5h1420_writereg(state, 0x06, s5h1420_readreg(state, 0x06) & 0xf7);
429 452
430 val *= (state->fclk / 1000); 453 val *= (state->fclk / 1000ULL);
431 do_div(val, ((1<<24) * sampling)); 454 do_div(val, ((1<<24) * sampling));
432 455
433 return (u32) (val * 1000); 456 return (u32) (val * 1000ULL);
434} 457}
435 458
436static void s5h1420_setfreqoffset(struct s5h1420_state* state, int freqoffset) 459static void s5h1420_setfreqoffset(struct s5h1420_state* state, int freqoffset)
@@ -463,46 +486,55 @@ static int s5h1420_getfreqoffset(struct s5h1420_state* state)
463 486
464 /* remember freqoffset is in kHz, but the chip wants the offset in Hz, so 487 /* remember freqoffset is in kHz, but the chip wants the offset in Hz, so
465 * divide fclk by 1000000 to get the correct value. */ 488 * divide fclk by 1000000 to get the correct value. */
466 val = - ((val * (state->fclk/1000000)) / (1<<24)); 489 val = (((-val) * (state->fclk/1000000)) / (1<<24));
467 490
468 return val; 491 return val;
469} 492}
470 493
471static void s5h1420_setfec(struct s5h1420_state* state, struct dvb_frontend_parameters *p) 494static void s5h1420_setfec_inversion(struct s5h1420_state* state,
495 struct dvb_frontend_parameters *p)
472{ 496{
497 u8 inversion = 0;
498
499 if (p->inversion == INVERSION_OFF) {
500 inversion = state->config->invert ? 0x08 : 0;
501 } else if (p->inversion == INVERSION_ON) {
502 inversion = state->config->invert ? 0 : 0x08;
503 }
504
473 if ((p->u.qpsk.fec_inner == FEC_AUTO) || (p->inversion == INVERSION_AUTO)) { 505 if ((p->u.qpsk.fec_inner == FEC_AUTO) || (p->inversion == INVERSION_AUTO)) {
474 s5h1420_writereg(state, 0x31, 0x00);
475 s5h1420_writereg(state, 0x30, 0x3f); 506 s5h1420_writereg(state, 0x30, 0x3f);
507 s5h1420_writereg(state, 0x31, 0x00 | inversion);
476 } else { 508 } else {
477 switch(p->u.qpsk.fec_inner) { 509 switch(p->u.qpsk.fec_inner) {
478 case FEC_1_2: 510 case FEC_1_2:
479 s5h1420_writereg(state, 0x31, 0x10);
480 s5h1420_writereg(state, 0x30, 0x01); 511 s5h1420_writereg(state, 0x30, 0x01);
512 s5h1420_writereg(state, 0x31, 0x10 | inversion);
481 break; 513 break;
482 514
483 case FEC_2_3: 515 case FEC_2_3:
484 s5h1420_writereg(state, 0x31, 0x11);
485 s5h1420_writereg(state, 0x30, 0x02); 516 s5h1420_writereg(state, 0x30, 0x02);
517 s5h1420_writereg(state, 0x31, 0x11 | inversion);
486 break; 518 break;
487 519
488 case FEC_3_4: 520 case FEC_3_4:
489 s5h1420_writereg(state, 0x31, 0x12);
490 s5h1420_writereg(state, 0x30, 0x04); 521 s5h1420_writereg(state, 0x30, 0x04);
491 break; 522 s5h1420_writereg(state, 0x31, 0x12 | inversion);
523 break;
492 524
493 case FEC_5_6: 525 case FEC_5_6:
494 s5h1420_writereg(state, 0x31, 0x13);
495 s5h1420_writereg(state, 0x30, 0x08); 526 s5h1420_writereg(state, 0x30, 0x08);
527 s5h1420_writereg(state, 0x31, 0x13 | inversion);
496 break; 528 break;
497 529
498 case FEC_6_7: 530 case FEC_6_7:
499 s5h1420_writereg(state, 0x31, 0x14);
500 s5h1420_writereg(state, 0x30, 0x10); 531 s5h1420_writereg(state, 0x30, 0x10);
532 s5h1420_writereg(state, 0x31, 0x14 | inversion);
501 break; 533 break;
502 534
503 case FEC_7_8: 535 case FEC_7_8:
504 s5h1420_writereg(state, 0x31, 0x15);
505 s5h1420_writereg(state, 0x30, 0x20); 536 s5h1420_writereg(state, 0x30, 0x20);
537 s5h1420_writereg(state, 0x31, 0x15 | inversion);
506 break; 538 break;
507 539
508 default: 540 default:
@@ -536,22 +568,6 @@ static fe_code_rate_t s5h1420_getfec(struct s5h1420_state* state)
536 return FEC_NONE; 568 return FEC_NONE;
537} 569}
538 570
539static void s5h1420_setinversion(struct s5h1420_state* state, struct dvb_frontend_parameters *p)
540{
541 if ((p->u.qpsk.fec_inner == FEC_AUTO) || (p->inversion == INVERSION_AUTO)) {
542 s5h1420_writereg(state, 0x31, 0x00);
543 s5h1420_writereg(state, 0x30, 0x3f);
544 } else {
545 u8 tmp = s5h1420_readreg(state, 0x31) & 0xf7;
546 tmp |= 0x10;
547
548 if (p->inversion == INVERSION_ON)
549 tmp |= 0x80;
550
551 s5h1420_writereg(state, 0x31, tmp);
552 }
553}
554
555static fe_spectral_inversion_t s5h1420_getinversion(struct s5h1420_state* state) 571static fe_spectral_inversion_t s5h1420_getinversion(struct s5h1420_state* state)
556{ 572{
557 if (s5h1420_readreg(state, 0x32) & 0x08) 573 if (s5h1420_readreg(state, 0x32) & 0x08)
@@ -560,35 +576,35 @@ static fe_spectral_inversion_t s5h1420_getinversion(struct s5h1420_state* state)
560 return INVERSION_OFF; 576 return INVERSION_OFF;
561} 577}
562 578
563static int s5h1420_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 579static int s5h1420_set_frontend(struct dvb_frontend* fe,
580 struct dvb_frontend_parameters *p)
564{ 581{
565 struct s5h1420_state* state = fe->demodulator_priv; 582 struct s5h1420_state* state = fe->demodulator_priv;
566 u32 frequency_delta; 583 int frequency_delta;
567 struct dvb_frontend_tune_settings fesettings; 584 struct dvb_frontend_tune_settings fesettings;
585 u32 tmp;
568 586
569 /* check if we should do a fast-tune */ 587 /* check if we should do a fast-tune */
570 memcpy(&fesettings.parameters, p, sizeof(struct dvb_frontend_parameters)); 588 memcpy(&fesettings.parameters, p, sizeof(struct dvb_frontend_parameters));
571 s5h1420_get_tune_settings(fe, &fesettings); 589 s5h1420_get_tune_settings(fe, &fesettings);
572 frequency_delta = p->frequency - state->tunedfreq; 590 frequency_delta = p->frequency - state->tunedfreq;
573 if ((frequency_delta > -fesettings.max_drift) && (frequency_delta < fesettings.max_drift) && 591 if ((frequency_delta > -fesettings.max_drift) &&
592 (frequency_delta < fesettings.max_drift) &&
574 (frequency_delta != 0) && 593 (frequency_delta != 0) &&
575 (state->fec_inner == p->u.qpsk.fec_inner) && 594 (state->fec_inner == p->u.qpsk.fec_inner) &&
576 (state->symbol_rate == p->u.qpsk.symbol_rate)) { 595 (state->symbol_rate == p->u.qpsk.symbol_rate)) {
577 596
578 s5h1420_setfreqoffset(state, frequency_delta); 597 if (state->config->pll_set) {
598 s5h1420_writereg (state, 0x02, s5h1420_readreg(state,0x02) | 1);
599 state->config->pll_set(fe, p, &tmp);
600 s5h1420_setfreqoffset(state, p->frequency - tmp);
601 }
579 return 0; 602 return 0;
580 } 603 }
581 604
582 /* first of all, software reset */ 605 /* first of all, software reset */
583 s5h1420_reset(state); 606 s5h1420_reset(state);
584 607
585 /* set tuner PLL */
586 if (state->config->pll_set) {
587 s5h1420_writereg (state, 0x02, s5h1420_readreg(state,0x02) | 1);
588 state->config->pll_set(fe, p, &state->tunedfreq);
589 s5h1420_writereg (state, 0x02, s5h1420_readreg(state,0x02) & 0xfe);
590 }
591
592 /* set s5h1420 fclk PLL according to desired symbol rate */ 608 /* set s5h1420 fclk PLL according to desired symbol rate */
593 if (p->u.qpsk.symbol_rate > 28000000) { 609 if (p->u.qpsk.symbol_rate > 28000000) {
594 state->fclk = 88000000; 610 state->fclk = 88000000;
@@ -609,8 +625,9 @@ static int s5h1420_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
609 625
610 /* set misc registers */ 626 /* set misc registers */
611 s5h1420_writereg(state, 0x02, 0x00); 627 s5h1420_writereg(state, 0x02, 0x00);
628 s5h1420_writereg(state, 0x06, 0x00);
612 s5h1420_writereg(state, 0x07, 0xb0); 629 s5h1420_writereg(state, 0x07, 0xb0);
613 s5h1420_writereg(state, 0x0a, 0x67); 630 s5h1420_writereg(state, 0x0a, 0xe7);
614 s5h1420_writereg(state, 0x0b, 0x78); 631 s5h1420_writereg(state, 0x0b, 0x78);
615 s5h1420_writereg(state, 0x0c, 0x48); 632 s5h1420_writereg(state, 0x0c, 0x48);
616 s5h1420_writereg(state, 0x0d, 0x6b); 633 s5h1420_writereg(state, 0x0d, 0x6b);
@@ -626,21 +643,26 @@ static int s5h1420_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
626 /* start QPSK */ 643 /* start QPSK */
627 s5h1420_writereg(state, 0x05, s5h1420_readreg(state, 0x05) | 1); 644 s5h1420_writereg(state, 0x05, s5h1420_readreg(state, 0x05) | 1);
628 645
629 /* set the frequency offset to adjust for PLL inaccuracy */ 646 /* set tuner PLL */
630 s5h1420_setfreqoffset(state, p->frequency - state->tunedfreq); 647 if (state->config->pll_set) {
648 s5h1420_writereg (state, 0x02, s5h1420_readreg(state,0x02) | 1);
649 state->config->pll_set(fe, p, &tmp);
650 s5h1420_setfreqoffset(state, 0);
651 }
631 652
632 /* set the reset of the parameters */ 653 /* set the reset of the parameters */
633 s5h1420_setsymbolrate(state, p); 654 s5h1420_setsymbolrate(state, p);
634 s5h1420_setinversion(state, p); 655 s5h1420_setfec_inversion(state, p);
635 s5h1420_setfec(state, p);
636 656
637 state->fec_inner = p->u.qpsk.fec_inner; 657 state->fec_inner = p->u.qpsk.fec_inner;
638 state->symbol_rate = p->u.qpsk.symbol_rate; 658 state->symbol_rate = p->u.qpsk.symbol_rate;
639 state->postlocked = 0; 659 state->postlocked = 0;
660 state->tunedfreq = p->frequency;
640 return 0; 661 return 0;
641} 662}
642 663
643static int s5h1420_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 664static int s5h1420_get_frontend(struct dvb_frontend* fe,
665 struct dvb_frontend_parameters *p)
644{ 666{
645 struct s5h1420_state* state = fe->demodulator_priv; 667 struct s5h1420_state* state = fe->demodulator_priv;
646 668
@@ -652,7 +674,8 @@ static int s5h1420_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
652 return 0; 674 return 0;
653} 675}
654 676
655static int s5h1420_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings) 677static int s5h1420_get_tune_settings(struct dvb_frontend* fe,
678 struct dvb_frontend_tune_settings* fesettings)
656{ 679{
657 if (fesettings->parameters.u.qpsk.symbol_rate > 20000000) { 680 if (fesettings->parameters.u.qpsk.symbol_rate > 20000000) {
658 fesettings->min_delay_ms = 50; 681 fesettings->min_delay_ms = 50;
@@ -717,7 +740,8 @@ static void s5h1420_release(struct dvb_frontend* fe)
717 740
718static struct dvb_frontend_ops s5h1420_ops; 741static struct dvb_frontend_ops s5h1420_ops;
719 742
720struct dvb_frontend* s5h1420_attach(const struct s5h1420_config* config, struct i2c_adapter* i2c) 743struct dvb_frontend* s5h1420_attach(const struct s5h1420_config* config,
744 struct i2c_adapter* i2c)
721{ 745{
722 struct s5h1420_state* state = NULL; 746 struct s5h1420_state* state = NULL;
723 u8 identity; 747 u8 identity;
diff --git a/drivers/media/dvb/frontends/s5h1420.h b/drivers/media/dvb/frontends/s5h1420.h
index b687fc77ce..872028ddf2 100644
--- a/drivers/media/dvb/frontends/s5h1420.h
+++ b/drivers/media/dvb/frontends/s5h1420.h
@@ -30,6 +30,9 @@ struct s5h1420_config
30 /* the demodulator's i2c address */ 30 /* the demodulator's i2c address */
31 u8 demod_address; 31 u8 demod_address;
32 32
33 /* does the inversion require inversion? */
34 u8 invert:1;
35
33 /* PLL maintenance */ 36 /* PLL maintenance */
34 int (*pll_init)(struct dvb_frontend* fe); 37 int (*pll_init)(struct dvb_frontend* fe);
35 int (*pll_set)(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u32* freqout); 38 int (*pll_set)(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u32* freqout);
diff --git a/drivers/media/dvb/frontends/stv0297.c b/drivers/media/dvb/frontends/stv0297.c
index 928aca052a..8d09afd754 100644
--- a/drivers/media/dvb/frontends/stv0297.c
+++ b/drivers/media/dvb/frontends/stv0297.c
@@ -35,7 +35,6 @@ struct stv0297_state {
35 struct dvb_frontend frontend; 35 struct dvb_frontend frontend;
36 36
37 unsigned long base_freq; 37 unsigned long base_freq;
38 u8 pwm;
39}; 38};
40 39
41#if 1 40#if 1
@@ -46,94 +45,6 @@ struct stv0297_state {
46 45
47#define STV0297_CLOCK_KHZ 28900 46#define STV0297_CLOCK_KHZ 28900
48 47
49static u8 init_tab[] = {
50 0x00, 0x09,
51 0x01, 0x69,
52 0x03, 0x00,
53 0x04, 0x00,
54 0x07, 0x00,
55 0x08, 0x00,
56 0x20, 0x00,
57 0x21, 0x40,
58 0x22, 0x00,
59 0x23, 0x00,
60 0x24, 0x40,
61 0x25, 0x88,
62 0x30, 0xff,
63 0x31, 0x00,
64 0x32, 0xff,
65 0x33, 0x00,
66 0x34, 0x50,
67 0x35, 0x7f,
68 0x36, 0x00,
69 0x37, 0x20,
70 0x38, 0x00,
71 0x40, 0x1c,
72 0x41, 0xff,
73 0x42, 0x29,
74 0x43, 0x00,
75 0x44, 0xff,
76 0x45, 0x00,
77 0x46, 0x00,
78 0x49, 0x04,
79 0x4a, 0xff,
80 0x4b, 0x7f,
81 0x52, 0x30,
82 0x55, 0xae,
83 0x56, 0x47,
84 0x57, 0xe1,
85 0x58, 0x3a,
86 0x5a, 0x1e,
87 0x5b, 0x34,
88 0x60, 0x00,
89 0x63, 0x00,
90 0x64, 0x00,
91 0x65, 0x00,
92 0x66, 0x00,
93 0x67, 0x00,
94 0x68, 0x00,
95 0x69, 0x00,
96 0x6a, 0x02,
97 0x6b, 0x00,
98 0x70, 0xff,
99 0x71, 0x00,
100 0x72, 0x00,
101 0x73, 0x00,
102 0x74, 0x0c,
103 0x80, 0x00,
104 0x81, 0x00,
105 0x82, 0x00,
106 0x83, 0x00,
107 0x84, 0x04,
108 0x85, 0x80,
109 0x86, 0x24,
110 0x87, 0x78,
111 0x88, 0x00,
112 0x89, 0x00,
113 0x90, 0x01,
114 0x91, 0x01,
115 0xa0, 0x00,
116 0xa1, 0x00,
117 0xa2, 0x00,
118 0xb0, 0x91,
119 0xb1, 0x0b,
120 0xc0, 0x53,
121 0xc1, 0x70,
122 0xc2, 0x12,
123 0xd0, 0x00,
124 0xd1, 0x00,
125 0xd2, 0x00,
126 0xd3, 0x00,
127 0xd4, 0x00,
128 0xd5, 0x00,
129 0xde, 0x00,
130 0xdf, 0x00,
131 0x61, 0x49,
132 0x62, 0x0b,
133 0x53, 0x08,
134 0x59, 0x08,
135};
136
137 48
138static int stv0297_writereg(struct stv0297_state *state, u8 reg, u8 data) 49static int stv0297_writereg(struct stv0297_state *state, u8 reg, u8 data)
139{ 50{
@@ -378,34 +289,9 @@ static int stv0297_init(struct dvb_frontend *fe)
378 struct stv0297_state *state = fe->demodulator_priv; 289 struct stv0297_state *state = fe->demodulator_priv;
379 int i; 290 int i;
380 291
381 /* soft reset */
382 stv0297_writereg_mask(state, 0x80, 1, 1);
383 stv0297_writereg_mask(state, 0x80, 1, 0);
384
385 /* reset deinterleaver */
386 stv0297_writereg_mask(state, 0x81, 1, 1);
387 stv0297_writereg_mask(state, 0x81, 1, 0);
388
389 /* load init table */ 292 /* load init table */
390 for (i = 0; i < sizeof(init_tab); i += 2) { 293 for (i=0; !(state->config->inittab[i] == 0xff && state->config->inittab[i+1] == 0xff); i+=2)
391 stv0297_writereg(state, init_tab[i], init_tab[i + 1]); 294 stv0297_writereg(state, state->config->inittab[i], state->config->inittab[i+1]);
392 }
393
394 /* set a dummy symbol rate */
395 stv0297_set_symbolrate(state, 6900);
396
397 /* invert AGC1 polarity */
398 stv0297_writereg_mask(state, 0x88, 0x10, 0x10);
399
400 /* setup bit error counting */
401 stv0297_writereg_mask(state, 0xA0, 0x80, 0x00);
402 stv0297_writereg_mask(state, 0xA0, 0x10, 0x00);
403 stv0297_writereg_mask(state, 0xA0, 0x08, 0x00);
404 stv0297_writereg_mask(state, 0xA0, 0x07, 0x04);
405
406 /* min + max PWM */
407 stv0297_writereg(state, 0x4a, 0x00);
408 stv0297_writereg(state, 0x4b, state->pwm);
409 msleep(200); 295 msleep(200);
410 296
411 if (state->config->pll_init) 297 if (state->config->pll_init)
@@ -606,7 +492,13 @@ static int stv0297_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_par
606 stv0297_set_inversion(state, inversion); 492 stv0297_set_inversion(state, inversion);
607 493
608 /* kick off lock */ 494 /* kick off lock */
609 stv0297_writereg_mask(state, 0x88, 0x08, 0x08); 495 /* Disable corner detection for higher QAMs */
496 if (p->u.qam.modulation == QAM_128 ||
497 p->u.qam.modulation == QAM_256)
498 stv0297_writereg_mask(state, 0x88, 0x08, 0x00);
499 else
500 stv0297_writereg_mask(state, 0x88, 0x08, 0x08);
501
610 stv0297_writereg_mask(state, 0x5a, 0x20, 0x00); 502 stv0297_writereg_mask(state, 0x5a, 0x20, 0x00);
611 stv0297_writereg_mask(state, 0x6a, 0x01, 0x01); 503 stv0297_writereg_mask(state, 0x6a, 0x01, 0x01);
612 stv0297_writereg_mask(state, 0x43, 0x40, 0x40); 504 stv0297_writereg_mask(state, 0x43, 0x40, 0x40);
@@ -732,7 +624,7 @@ static void stv0297_release(struct dvb_frontend *fe)
732static struct dvb_frontend_ops stv0297_ops; 624static struct dvb_frontend_ops stv0297_ops;
733 625
734struct dvb_frontend *stv0297_attach(const struct stv0297_config *config, 626struct dvb_frontend *stv0297_attach(const struct stv0297_config *config,
735 struct i2c_adapter *i2c, int pwm) 627 struct i2c_adapter *i2c)
736{ 628{
737 struct stv0297_state *state = NULL; 629 struct stv0297_state *state = NULL;
738 630
@@ -746,7 +638,6 @@ struct dvb_frontend *stv0297_attach(const struct stv0297_config *config,
746 state->i2c = i2c; 638 state->i2c = i2c;
747 memcpy(&state->ops, &stv0297_ops, sizeof(struct dvb_frontend_ops)); 639 memcpy(&state->ops, &stv0297_ops, sizeof(struct dvb_frontend_ops));
748 state->base_freq = 0; 640 state->base_freq = 0;
749 state->pwm = pwm;
750 641
751 /* check if the demod is there */ 642 /* check if the demod is there */
752 if ((stv0297_readreg(state, 0x80) & 0x70) != 0x20) 643 if ((stv0297_readreg(state, 0x80) & 0x70) != 0x20)
diff --git a/drivers/media/dvb/frontends/stv0297.h b/drivers/media/dvb/frontends/stv0297.h
index 3be5359893..9e53f019db 100644
--- a/drivers/media/dvb/frontends/stv0297.h
+++ b/drivers/media/dvb/frontends/stv0297.h
@@ -29,6 +29,12 @@ struct stv0297_config
29 /* the demodulator's i2c address */ 29 /* the demodulator's i2c address */
30 u8 demod_address; 30 u8 demod_address;
31 31
32 /* inittab - array of pairs of values.
33 * First of each pair is the register, second is the value.
34 * List should be terminated with an 0xff, 0xff pair.
35 */
36 u8* inittab;
37
32 /* does the "inversion" need inverted? */ 38 /* does the "inversion" need inverted? */
33 u8 invert:1; 39 u8 invert:1;
34 40
@@ -38,7 +44,7 @@ struct stv0297_config
38}; 44};
39 45
40extern struct dvb_frontend* stv0297_attach(const struct stv0297_config* config, 46extern struct dvb_frontend* stv0297_attach(const struct stv0297_config* config,
41 struct i2c_adapter* i2c, int pwm); 47 struct i2c_adapter* i2c);
42extern int stv0297_enable_plli2c(struct dvb_frontend* fe); 48extern int stv0297_enable_plli2c(struct dvb_frontend* fe);
43 49
44#endif // STV0297_H 50#endif // STV0297_H
diff --git a/drivers/media/dvb/frontends/stv0299.c b/drivers/media/dvb/frontends/stv0299.c
index cfa3928bb4..2d62931f20 100644
--- a/drivers/media/dvb/frontends/stv0299.c
+++ b/drivers/media/dvb/frontends/stv0299.c
@@ -63,12 +63,8 @@ struct stv0299_state {
63 u32 tuner_frequency; 63 u32 tuner_frequency;
64 u32 symbol_rate; 64 u32 symbol_rate;
65 fe_code_rate_t fec_inner; 65 fe_code_rate_t fec_inner;
66 int errmode;
67}; 66};
68 67
69#define STATUS_BER 0
70#define STATUS_UCBLOCKS 1
71
72static int debug; 68static int debug;
73static int debug_legacy_dish_switch; 69static int debug_legacy_dish_switch;
74#define dprintk(args...) \ 70#define dprintk(args...) \
@@ -481,7 +477,7 @@ static int stv0299_init (struct dvb_frontend* fe)
481 477
482 if (state->config->pll_init) { 478 if (state->config->pll_init) {
483 stv0299_writeregI(state, 0x05, 0xb5); /* enable i2c repeater on stv0299 */ 479 stv0299_writeregI(state, 0x05, 0xb5); /* enable i2c repeater on stv0299 */
484 state->config->pll_init(fe); 480 state->config->pll_init(fe, state->i2c);
485 stv0299_writeregI(state, 0x05, 0x35); /* disable i2c repeater on stv0299 */ 481 stv0299_writeregI(state, 0x05, 0x35); /* disable i2c repeater on stv0299 */
486 } 482 }
487 483
@@ -520,7 +516,8 @@ static int stv0299_read_ber(struct dvb_frontend* fe, u32* ber)
520{ 516{
521 struct stv0299_state* state = fe->demodulator_priv; 517 struct stv0299_state* state = fe->demodulator_priv;
522 518
523 if (state->errmode != STATUS_BER) return 0; 519 stv0299_writeregI(state, 0x34, (stv0299_readreg(state, 0x34) & 0xcf) | 0x10);
520 msleep(100);
524 *ber = (stv0299_readreg (state, 0x1d) << 8) | stv0299_readreg (state, 0x1e); 521 *ber = (stv0299_readreg (state, 0x1d) << 8) | stv0299_readreg (state, 0x1e);
525 522
526 return 0; 523 return 0;
@@ -559,8 +556,9 @@ static int stv0299_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
559{ 556{
560 struct stv0299_state* state = fe->demodulator_priv; 557 struct stv0299_state* state = fe->demodulator_priv;
561 558
562 if (state->errmode != STATUS_UCBLOCKS) *ucblocks = 0; 559 stv0299_writeregI(state, 0x34, (stv0299_readreg(state, 0x34) & 0xcf) | 0x30);
563 else *ucblocks = (stv0299_readreg (state, 0x1d) << 8) | stv0299_readreg (state, 0x1e); 560 msleep(100);
561 *ucblocks = (stv0299_readreg (state, 0x1d) << 8) | stv0299_readreg (state, 0x1e);
564 562
565 return 0; 563 return 0;
566} 564}
@@ -603,7 +601,7 @@ static int stv0299_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
603 } else { 601 } else {
604 /* A "normal" tune is requested */ 602 /* A "normal" tune is requested */
605 stv0299_writeregI(state, 0x05, 0xb5); /* enable i2c repeater on stv0299 */ 603 stv0299_writeregI(state, 0x05, 0xb5); /* enable i2c repeater on stv0299 */
606 state->config->pll_set(fe, p); 604 state->config->pll_set(fe, state->i2c, p);
607 stv0299_writeregI(state, 0x05, 0x35); /* disable i2c repeater on stv0299 */ 605 stv0299_writeregI(state, 0x05, 0x35); /* disable i2c repeater on stv0299 */
608 606
609 stv0299_writeregI(state, 0x32, 0x80); 607 stv0299_writeregI(state, 0x32, 0x80);
@@ -615,7 +613,7 @@ static int stv0299_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
615 } 613 }
616 } else { 614 } else {
617 stv0299_writeregI(state, 0x05, 0xb5); /* enable i2c repeater on stv0299 */ 615 stv0299_writeregI(state, 0x05, 0xb5); /* enable i2c repeater on stv0299 */
618 state->config->pll_set(fe, p); 616 state->config->pll_set(fe, state->i2c, p);
619 stv0299_writeregI(state, 0x05, 0x35); /* disable i2c repeater on stv0299 */ 617 stv0299_writeregI(state, 0x05, 0x35); /* disable i2c repeater on stv0299 */
620 618
621 stv0299_set_FEC (state, p->u.qpsk.fec_inner); 619 stv0299_set_FEC (state, p->u.qpsk.fec_inner);
@@ -709,7 +707,6 @@ struct dvb_frontend* stv0299_attach(const struct stv0299_config* config,
709 state->tuner_frequency = 0; 707 state->tuner_frequency = 0;
710 state->symbol_rate = 0; 708 state->symbol_rate = 0;
711 state->fec_inner = 0; 709 state->fec_inner = 0;
712 state->errmode = STATUS_BER;
713 710
714 /* check if the demod is there */ 711 /* check if the demod is there */
715 stv0299_writeregI(state, 0x02, 0x34); /* standby off */ 712 stv0299_writeregI(state, 0x02, 0x34); /* standby off */
diff --git a/drivers/media/dvb/frontends/stv0299.h b/drivers/media/dvb/frontends/stv0299.h
index 79457a80a1..d0c4484861 100644
--- a/drivers/media/dvb/frontends/stv0299.h
+++ b/drivers/media/dvb/frontends/stv0299.h
@@ -92,8 +92,8 @@ struct stv0299_config
92 int (*set_symbol_rate)(struct dvb_frontend* fe, u32 srate, u32 ratio); 92 int (*set_symbol_rate)(struct dvb_frontend* fe, u32 srate, u32 ratio);
93 93
94 /* PLL maintenance */ 94 /* PLL maintenance */
95 int (*pll_init)(struct dvb_frontend* fe); 95 int (*pll_init)(struct dvb_frontend *fe, struct i2c_adapter *i2c);
96 int (*pll_set)(struct dvb_frontend* fe, struct dvb_frontend_parameters* params); 96 int (*pll_set)(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters *params);
97}; 97};
98 98
99extern int stv0299_writereg (struct dvb_frontend* fe, u8 reg, u8 data); 99extern int stv0299_writereg (struct dvb_frontend* fe, u8 reg, u8 data);
diff --git a/drivers/media/dvb/frontends/tda1004x.c b/drivers/media/dvb/frontends/tda1004x.c
index ab0c032472..74cea9f8d7 100644
--- a/drivers/media/dvb/frontends/tda1004x.c
+++ b/drivers/media/dvb/frontends/tda1004x.c
@@ -1046,8 +1046,7 @@ static int tda1004x_read_snr(struct dvb_frontend* fe, u16 * snr)
1046 tmp = tda1004x_read_byte(state, TDA1004X_SNR); 1046 tmp = tda1004x_read_byte(state, TDA1004X_SNR);
1047 if (tmp < 0) 1047 if (tmp < 0)
1048 return -EIO; 1048 return -EIO;
1049 if (tmp) 1049 tmp = 255 - tmp;
1050 tmp = 255 - tmp;
1051 1050
1052 *snr = ((tmp << 8) | tmp); 1051 *snr = ((tmp << 8) | tmp);
1053 dprintk("%s: snr=0x%x\n", __FUNCTION__, *snr); 1052 dprintk("%s: snr=0x%x\n", __FUNCTION__, *snr);
diff --git a/drivers/media/dvb/frontends/ves1820.c b/drivers/media/dvb/frontends/ves1820.c
index 70fb44b391..c6d276618e 100644
--- a/drivers/media/dvb/frontends/ves1820.c
+++ b/drivers/media/dvb/frontends/ves1820.c
@@ -194,19 +194,18 @@ static int ves1820_init(struct dvb_frontend* fe)
194{ 194{
195 struct ves1820_state* state = fe->demodulator_priv; 195 struct ves1820_state* state = fe->demodulator_priv;
196 int i; 196 int i;
197 int val;
198 197
199 ves1820_writereg(state, 0, 0); 198 ves1820_writereg(state, 0, 0);
200 199
201 for (i = 0; i < 53; i++) { 200 for (i = 0; i < sizeof(ves1820_inittab); i++)
202 val = ves1820_inittab[i]; 201 ves1820_writereg(state, i, ves1820_inittab[i]);
203 if ((i == 2) && (state->config->selagc)) val |= 0x08; 202 if (state->config->selagc)
204 ves1820_writereg(state, i, val); 203 ves1820_writereg(state, 2, ves1820_inittab[2] | 0x08);
205 }
206 204
207 ves1820_writereg(state, 0x34, state->pwm); 205 ves1820_writereg(state, 0x34, state->pwm);
208 206
209 if (state->config->pll_init) state->config->pll_init(fe); 207 if (state->config->pll_init)
208 state->config->pll_init(fe);
210 209
211 return 0; 210 return 0;
212} 211}
@@ -234,7 +233,7 @@ static int ves1820_set_parameters(struct dvb_frontend* fe, struct dvb_frontend_p
234 ves1820_writereg(state, 0x09, reg0x09[real_qam]); 233 ves1820_writereg(state, 0x09, reg0x09[real_qam]);
235 234
236 ves1820_setup_reg0(state, reg0x00[real_qam], p->inversion); 235 ves1820_setup_reg0(state, reg0x00[real_qam], p->inversion);
237 236 ves1820_writereg(state, 2, ves1820_inittab[2] | (state->config->selagc ? 0x08 : 0));
238 return 0; 237 return 0;
239} 238}
240 239
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index e4c6e87f6c..22b203f8ff 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -168,7 +168,9 @@ static void init_av7110_av(struct av7110 *av7110)
168 if (ret < 0) 168 if (ret < 0)
169 printk("dvb-ttpci:cannot switch on SCART(AD):%d\n",ret); 169 printk("dvb-ttpci:cannot switch on SCART(AD):%d\n",ret);
170 if (rgb_on && 170 if (rgb_on &&
171 (av7110->dev->pci->subsystem_vendor == 0x110a) && (av7110->dev->pci->subsystem_device == 0x0000)) { 171 ((av7110->dev->pci->subsystem_vendor == 0x110a) ||
172 (av7110->dev->pci->subsystem_vendor == 0x13c2)) &&
173 (av7110->dev->pci->subsystem_device == 0x0000)) {
172 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI); // RGB on, SCART pin 16 174 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI); // RGB on, SCART pin 16
173 //saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO); // SCARTpin 8 175 //saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO); // SCARTpin 8
174 } 176 }
@@ -177,9 +179,6 @@ static void init_av7110_av(struct av7110 *av7110)
177 ret = av7110_set_volume(av7110, av7110->mixer.volume_left, av7110->mixer.volume_right); 179 ret = av7110_set_volume(av7110, av7110->mixer.volume_left, av7110->mixer.volume_right);
178 if (ret < 0) 180 if (ret < 0)
179 printk("dvb-ttpci:cannot set volume :%d\n",ret); 181 printk("dvb-ttpci:cannot set volume :%d\n",ret);
180 ret = av7110_setup_irc_config(av7110, 0);
181 if (ret < 0)
182 printk("dvb-ttpci:cannot setup irc config :%d\n",ret);
183} 182}
184 183
185static void recover_arm(struct av7110 *av7110) 184static void recover_arm(struct av7110 *av7110)
@@ -265,60 +264,6 @@ static int arm_thread(void *data)
265} 264}
266 265
267 266
268/**
269 * Hack! we save the last av7110 ptr. This should be ok, since
270 * you rarely will use more then one IR control.
271 *
272 * If we want to support multiple controls we would have to do much more...
273 */
274int av7110_setup_irc_config(struct av7110 *av7110, u32 ir_config)
275{
276 int ret = 0;
277 static struct av7110 *last;
278
279 dprintk(4, "%p\n", av7110);
280
281 if (!av7110)
282 av7110 = last;
283 else
284 last = av7110;
285
286 if (av7110) {
287 ret = av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, SetIR, 1, ir_config);
288 av7110->ir_config = ir_config;
289 }
290 return ret;
291}
292
293static void (*irc_handler)(u32);
294
295void av7110_register_irc_handler(void (*func)(u32))
296{
297 dprintk(4, "registering %p\n", func);
298 irc_handler = func;
299}
300
301void av7110_unregister_irc_handler(void (*func)(u32))
302{
303 dprintk(4, "unregistering %p\n", func);
304 irc_handler = NULL;
305}
306
307static void run_handlers(unsigned long ircom)
308{
309 if (irc_handler != NULL)
310 (*irc_handler)((u32) ircom);
311}
312
313static DECLARE_TASKLET(irtask, run_handlers, 0);
314
315static void IR_handle(struct av7110 *av7110, u32 ircom)
316{
317 dprintk(4, "ircommand = %08x\n", ircom);
318 irtask.data = (unsigned long) ircom;
319 tasklet_schedule(&irtask);
320}
321
322/**************************************************************************** 267/****************************************************************************
323 * IRQ handling 268 * IRQ handling
324 ****************************************************************************/ 269 ****************************************************************************/
@@ -711,8 +656,9 @@ static void gpioirq(unsigned long data)
711 return; 656 return;
712 657
713 case DATA_IRCOMMAND: 658 case DATA_IRCOMMAND:
714 IR_handle(av7110, 659 if (av7110->ir_handler)
715 swahw32(irdebi(av7110, DEBINOSWAP, Reserved, 0, 4))); 660 av7110->ir_handler(av7110,
661 swahw32(irdebi(av7110, DEBINOSWAP, Reserved, 0, 4)));
716 iwdebi(av7110, DEBINOSWAP, RX_BUFF, 0, 2); 662 iwdebi(av7110, DEBINOSWAP, RX_BUFF, 0, 2);
717 break; 663 break;
718 664
@@ -1668,9 +1614,8 @@ static int alps_bsru6_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ra
1668 return 0; 1614 return 0;
1669} 1615}
1670 1616
1671static int alps_bsru6_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 1617static int alps_bsru6_pll_set(struct dvb_frontend* fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters* params)
1672{ 1618{
1673 struct av7110* av7110 = (struct av7110*) fe->dvb->priv;
1674 int ret; 1619 int ret;
1675 u8 data[4]; 1620 u8 data[4];
1676 u32 div; 1621 u32 div;
@@ -1687,7 +1632,7 @@ static int alps_bsru6_pll_set(struct dvb_frontend* fe, struct dvb_frontend_param
1687 1632
1688 if (params->frequency > 1530000) data[3] = 0xc0; 1633 if (params->frequency > 1530000) data[3] = 0xc0;
1689 1634
1690 ret = i2c_transfer(&av7110->i2c_adap, &msg, 1); 1635 ret = i2c_transfer(i2c, &msg, 1);
1691 if (ret != 1) 1636 if (ret != 1)
1692 return -EIO; 1637 return -EIO;
1693 return 0; 1638 return 0;
@@ -1751,9 +1696,8 @@ static u8 alps_bsbe1_inittab[] = {
1751 0xff, 0xff 1696 0xff, 0xff
1752}; 1697};
1753 1698
1754static int alps_bsbe1_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 1699static int alps_bsbe1_pll_set(struct dvb_frontend* fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters* params)
1755{ 1700{
1756 struct av7110* av7110 = (struct av7110*) fe->dvb->priv;
1757 int ret; 1701 int ret;
1758 u8 data[4]; 1702 u8 data[4];
1759 u32 div; 1703 u32 div;
@@ -1768,7 +1712,7 @@ static int alps_bsbe1_pll_set(struct dvb_frontend* fe, struct dvb_frontend_param
1768 data[2] = 0x80 | ((div & 0x18000) >> 10) | 4; 1712 data[2] = 0x80 | ((div & 0x18000) >> 10) | 4;
1769 data[3] = (params->frequency > 1530000) ? 0xE0 : 0xE4; 1713 data[3] = (params->frequency > 1530000) ? 0xE0 : 0xE4;
1770 1714
1771 ret = i2c_transfer(&av7110->i2c_adap, &msg, 1); 1715 ret = i2c_transfer(i2c, &msg, 1);
1772 return (ret != 1) ? -EIO : 0; 1716 return (ret != 1) ? -EIO : 0;
1773} 1717}
1774 1718
@@ -1936,6 +1880,98 @@ static struct sp8870_config alps_tdlb7_config = {
1936}; 1880};
1937 1881
1938 1882
1883static u8 nexusca_stv0297_inittab[] = {
1884 0x80, 0x01,
1885 0x80, 0x00,
1886 0x81, 0x01,
1887 0x81, 0x00,
1888 0x00, 0x09,
1889 0x01, 0x69,
1890 0x03, 0x00,
1891 0x04, 0x00,
1892 0x07, 0x00,
1893 0x08, 0x00,
1894 0x20, 0x00,
1895 0x21, 0x40,
1896 0x22, 0x00,
1897 0x23, 0x00,
1898 0x24, 0x40,
1899 0x25, 0x88,
1900 0x30, 0xff,
1901 0x31, 0x00,
1902 0x32, 0xff,
1903 0x33, 0x00,
1904 0x34, 0x50,
1905 0x35, 0x7f,
1906 0x36, 0x00,
1907 0x37, 0x20,
1908 0x38, 0x00,
1909 0x40, 0x1c,
1910 0x41, 0xff,
1911 0x42, 0x29,
1912 0x43, 0x00,
1913 0x44, 0xff,
1914 0x45, 0x00,
1915 0x46, 0x00,
1916 0x49, 0x04,
1917 0x4a, 0x00,
1918 0x4b, 0x7b,
1919 0x52, 0x30,
1920 0x55, 0xae,
1921 0x56, 0x47,
1922 0x57, 0xe1,
1923 0x58, 0x3a,
1924 0x5a, 0x1e,
1925 0x5b, 0x34,
1926 0x60, 0x00,
1927 0x63, 0x00,
1928 0x64, 0x00,
1929 0x65, 0x00,
1930 0x66, 0x00,
1931 0x67, 0x00,
1932 0x68, 0x00,
1933 0x69, 0x00,
1934 0x6a, 0x02,
1935 0x6b, 0x00,
1936 0x70, 0xff,
1937 0x71, 0x00,
1938 0x72, 0x00,
1939 0x73, 0x00,
1940 0x74, 0x0c,
1941 0x80, 0x00,
1942 0x81, 0x00,
1943 0x82, 0x00,
1944 0x83, 0x00,
1945 0x84, 0x04,
1946 0x85, 0x80,
1947 0x86, 0x24,
1948 0x87, 0x78,
1949 0x88, 0x10,
1950 0x89, 0x00,
1951 0x90, 0x01,
1952 0x91, 0x01,
1953 0xa0, 0x04,
1954 0xa1, 0x00,
1955 0xa2, 0x00,
1956 0xb0, 0x91,
1957 0xb1, 0x0b,
1958 0xc0, 0x53,
1959 0xc1, 0x70,
1960 0xc2, 0x12,
1961 0xd0, 0x00,
1962 0xd1, 0x00,
1963 0xd2, 0x00,
1964 0xd3, 0x00,
1965 0xd4, 0x00,
1966 0xd5, 0x00,
1967 0xde, 0x00,
1968 0xdf, 0x00,
1969 0x61, 0x49,
1970 0x62, 0x0b,
1971 0x53, 0x08,
1972 0x59, 0x08,
1973 0xff, 0xff,
1974};
1939 1975
1940static int nexusca_stv0297_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 1976static int nexusca_stv0297_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
1941{ 1977{
@@ -1984,6 +2020,7 @@ static int nexusca_stv0297_pll_set(struct dvb_frontend* fe, struct dvb_frontend_
1984static struct stv0297_config nexusca_stv0297_config = { 2020static struct stv0297_config nexusca_stv0297_config = {
1985 2021
1986 .demod_address = 0x1C, 2022 .demod_address = 0x1C,
2023 .inittab = nexusca_stv0297_inittab,
1987 .invert = 1, 2024 .invert = 1,
1988 .pll_set = nexusca_stv0297_pll_set, 2025 .pll_set = nexusca_stv0297_pll_set,
1989}; 2026};
@@ -2261,7 +2298,7 @@ static int frontend_init(struct av7110 *av7110)
2261 2298
2262 case 0x000A: // Hauppauge/TT Nexus-CA rev1.X 2299 case 0x000A: // Hauppauge/TT Nexus-CA rev1.X
2263 2300
2264 av7110->fe = stv0297_attach(&nexusca_stv0297_config, &av7110->i2c_adap, 0x7b); 2301 av7110->fe = stv0297_attach(&nexusca_stv0297_config, &av7110->i2c_adap);
2265 if (av7110->fe) { 2302 if (av7110->fe) {
2266 /* set TDA9819 into DVB mode */ 2303 /* set TDA9819 into DVB mode */
2267 saa7146_setgpio(av7110->dev, 1, SAA7146_GPIO_OUTLO); // TDA9198 pin9(STD) 2304 saa7146_setgpio(av7110->dev, 1, SAA7146_GPIO_OUTLO); // TDA9198 pin9(STD)
@@ -2692,7 +2729,7 @@ static int av7110_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_d
2692 goto err_av7110_exit_v4l_12; 2729 goto err_av7110_exit_v4l_12;
2693 2730
2694#if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE) 2731#if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE)
2695 av7110_ir_init(); 2732 av7110_ir_init(av7110);
2696#endif 2733#endif
2697 printk(KERN_INFO "dvb-ttpci: found av7110-%d.\n", av7110_num); 2734 printk(KERN_INFO "dvb-ttpci: found av7110-%d.\n", av7110_num);
2698 av7110_num++; 2735 av7110_num++;
@@ -2734,6 +2771,9 @@ static int av7110_detach(struct saa7146_dev* saa)
2734 struct av7110 *av7110 = saa->ext_priv; 2771 struct av7110 *av7110 = saa->ext_priv;
2735 dprintk(4, "%p\n", av7110); 2772 dprintk(4, "%p\n", av7110);
2736 2773
2774#if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE)
2775 av7110_ir_exit(av7110);
2776#endif
2737 if (budgetpatch) { 2777 if (budgetpatch) {
2738 /* Disable RPS1 */ 2778 /* Disable RPS1 */
2739 saa7146_write(saa, MC1, MASK_29); 2779 saa7146_write(saa, MC1, MASK_29);
@@ -2830,7 +2870,7 @@ static struct saa7146_pci_extension_data x_var = { \
2830 .ext_priv = x_name, \ 2870 .ext_priv = x_name, \
2831 .ext = &av7110_extension } 2871 .ext = &av7110_extension }
2832 2872
2833MAKE_AV7110_INFO(tts_1_X, "Technotrend/Hauppauge WinTV DVB-S rev1.X"); 2873MAKE_AV7110_INFO(tts_1_X_fsc,"Technotrend/Hauppauge WinTV DVB-S rev1.X or Fujitsu Siemens DVB-C");
2834MAKE_AV7110_INFO(ttt_1_X, "Technotrend/Hauppauge WinTV DVB-T rev1.X"); 2874MAKE_AV7110_INFO(ttt_1_X, "Technotrend/Hauppauge WinTV DVB-T rev1.X");
2835MAKE_AV7110_INFO(ttc_1_X, "Technotrend/Hauppauge WinTV Nexus-CA rev1.X"); 2875MAKE_AV7110_INFO(ttc_1_X, "Technotrend/Hauppauge WinTV Nexus-CA rev1.X");
2836MAKE_AV7110_INFO(ttc_2_X, "Technotrend/Hauppauge WinTV DVB-C rev2.X"); 2876MAKE_AV7110_INFO(ttc_2_X, "Technotrend/Hauppauge WinTV DVB-C rev2.X");
@@ -2842,16 +2882,16 @@ MAKE_AV7110_INFO(fsc, "Fujitsu Siemens DVB-C");
2842MAKE_AV7110_INFO(fss, "Fujitsu Siemens DVB-S rev1.6"); 2882MAKE_AV7110_INFO(fss, "Fujitsu Siemens DVB-S rev1.6");
2843 2883
2844static struct pci_device_id pci_tbl[] = { 2884static struct pci_device_id pci_tbl[] = {
2845 MAKE_EXTENSION_PCI(fsc, 0x110a, 0x0000), 2885 MAKE_EXTENSION_PCI(fsc, 0x110a, 0x0000),
2846 MAKE_EXTENSION_PCI(tts_1_X, 0x13c2, 0x0000), 2886 MAKE_EXTENSION_PCI(tts_1_X_fsc, 0x13c2, 0x0000),
2847 MAKE_EXTENSION_PCI(ttt_1_X, 0x13c2, 0x0001), 2887 MAKE_EXTENSION_PCI(ttt_1_X, 0x13c2, 0x0001),
2848 MAKE_EXTENSION_PCI(ttc_2_X, 0x13c2, 0x0002), 2888 MAKE_EXTENSION_PCI(ttc_2_X, 0x13c2, 0x0002),
2849 MAKE_EXTENSION_PCI(tts_2_X, 0x13c2, 0x0003), 2889 MAKE_EXTENSION_PCI(tts_2_X, 0x13c2, 0x0003),
2850 MAKE_EXTENSION_PCI(fss, 0x13c2, 0x0006), 2890 MAKE_EXTENSION_PCI(fss, 0x13c2, 0x0006),
2851 MAKE_EXTENSION_PCI(ttt, 0x13c2, 0x0008), 2891 MAKE_EXTENSION_PCI(ttt, 0x13c2, 0x0008),
2852 MAKE_EXTENSION_PCI(ttc_1_X, 0x13c2, 0x000a), 2892 MAKE_EXTENSION_PCI(ttc_1_X, 0x13c2, 0x000a),
2853 MAKE_EXTENSION_PCI(tts_2_3, 0x13c2, 0x000e), 2893 MAKE_EXTENSION_PCI(tts_2_3, 0x13c2, 0x000e),
2854 MAKE_EXTENSION_PCI(tts_1_3se, 0x13c2, 0x1002), 2894 MAKE_EXTENSION_PCI(tts_1_3se, 0x13c2, 0x1002),
2855 2895
2856/* MAKE_EXTENSION_PCI(???, 0x13c2, 0x0004), UNDEFINED CARD */ // Galaxis DVB PC-Sat-Carte 2896/* MAKE_EXTENSION_PCI(???, 0x13c2, 0x0004), UNDEFINED CARD */ // Galaxis DVB PC-Sat-Carte
2857/* MAKE_EXTENSION_PCI(???, 0x13c2, 0x0005), UNDEFINED CARD */ // Technisat SkyStar1 2897/* MAKE_EXTENSION_PCI(???, 0x13c2, 0x0005), UNDEFINED CARD */ // Technisat SkyStar1
@@ -2889,9 +2929,6 @@ static int __init av7110_init(void)
2889 2929
2890static void __exit av7110_exit(void) 2930static void __exit av7110_exit(void)
2891{ 2931{
2892#if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE)
2893 av7110_ir_exit();
2894#endif
2895 saa7146_unregister_extension(&av7110_extension); 2932 saa7146_unregister_extension(&av7110_extension);
2896} 2933}
2897 2934
diff --git a/drivers/media/dvb/ttpci/av7110.h b/drivers/media/dvb/ttpci/av7110.h
index 508b7739c6..cce00ef293 100644
--- a/drivers/media/dvb/ttpci/av7110.h
+++ b/drivers/media/dvb/ttpci/av7110.h
@@ -228,7 +228,10 @@ struct av7110 {
228 struct dvb_video_events video_events; 228 struct dvb_video_events video_events;
229 video_size_t video_size; 229 video_size_t video_size;
230 230
231 u32 ir_config; 231 u32 ir_config;
232 u32 ir_command;
233 void (*ir_handler)(struct av7110 *av7110, u32 ircom);
234 struct tasklet_struct ir_tasklet;
232 235
233 /* firmware stuff */ 236 /* firmware stuff */
234 unsigned char *bin_fw; 237 unsigned char *bin_fw;
@@ -257,12 +260,10 @@ struct av7110 {
257extern int ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid, 260extern int ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid,
258 u16 subpid, u16 pcrpid); 261 u16 subpid, u16 pcrpid);
259 262
260extern void av7110_register_irc_handler(void (*func)(u32));
261extern void av7110_unregister_irc_handler(void (*func)(u32));
262extern int av7110_setup_irc_config (struct av7110 *av7110, u32 ir_config); 263extern int av7110_setup_irc_config (struct av7110 *av7110, u32 ir_config);
263 264
264extern int av7110_ir_init (void); 265extern int av7110_ir_init(struct av7110 *av7110);
265extern void av7110_ir_exit (void); 266extern void av7110_ir_exit(struct av7110 *av7110);
266 267
267/* msp3400 i2c subaddresses */ 268/* msp3400 i2c subaddresses */
268#define MSP_WR_DEM 0x10 269#define MSP_WR_DEM 0x10
diff --git a/drivers/media/dvb/ttpci/av7110_hw.c b/drivers/media/dvb/ttpci/av7110_hw.c
index 1220826696..7442f56a72 100644
--- a/drivers/media/dvb/ttpci/av7110_hw.c
+++ b/drivers/media/dvb/ttpci/av7110_hw.c
@@ -41,6 +41,8 @@
41#include "av7110.h" 41#include "av7110.h"
42#include "av7110_hw.h" 42#include "av7110_hw.h"
43 43
44#define _NOHANDSHAKE
45
44/**************************************************************************** 46/****************************************************************************
45 * DEBI functions 47 * DEBI functions
46 ****************************************************************************/ 48 ****************************************************************************/
@@ -364,7 +366,8 @@ static int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
364 msleep(1); 366 msleep(1);
365 } 367 }
366 368
367 wdebi(av7110, DEBINOSWAP, COM_IF_LOCK, 0xffff, 2); 369 if (FW_VERSION(av7110->arm_app) <= 0x261f)
370 wdebi(av7110, DEBINOSWAP, COM_IF_LOCK, 0xffff, 2);
368 371
369#ifndef _NOHANDSHAKE 372#ifndef _NOHANDSHAKE
370 start = jiffies; 373 start = jiffies;
@@ -437,7 +440,8 @@ static int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
437 440
438 wdebi(av7110, DEBINOSWAP, COMMAND, (u32) buf[0], 2); 441 wdebi(av7110, DEBINOSWAP, COMMAND, (u32) buf[0], 2);
439 442
440 wdebi(av7110, DEBINOSWAP, COM_IF_LOCK, 0x0000, 2); 443 if (FW_VERSION(av7110->arm_app) <= 0x261f)
444 wdebi(av7110, DEBINOSWAP, COM_IF_LOCK, 0x0000, 2);
441 445
442#ifdef COM_DEBUG 446#ifdef COM_DEBUG
443 start = jiffies; 447 start = jiffies;
diff --git a/drivers/media/dvb/ttpci/av7110_ir.c b/drivers/media/dvb/ttpci/av7110_ir.c
index 665cdb8a3f..357a3728ec 100644
--- a/drivers/media/dvb/ttpci/av7110_ir.c
+++ b/drivers/media/dvb/ttpci/av7110_ir.c
@@ -7,16 +7,16 @@
7#include <asm/bitops.h> 7#include <asm/bitops.h>
8 8
9#include "av7110.h" 9#include "av7110.h"
10#include "av7110_hw.h"
10 11
11#define UP_TIMEOUT (HZ/4) 12#define UP_TIMEOUT (HZ*7/25)
12 13
13/* enable ir debugging by or'ing debug with 16 */ 14/* enable ir debugging by or'ing debug with 16 */
14 15
15static int ir_initialized; 16static int av_cnt;
17static struct av7110 *av_list[4];
16static struct input_dev input_dev; 18static struct input_dev input_dev;
17 19
18static u32 ir_config;
19
20static u16 key_map [256] = { 20static u16 key_map [256] = {
21 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, 21 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7,
22 KEY_8, KEY_9, KEY_BACK, 0, KEY_POWER, KEY_MUTE, 0, KEY_INFO, 22 KEY_8, KEY_9, KEY_BACK, 0, KEY_POWER, KEY_MUTE, 0, KEY_INFO,
@@ -53,8 +53,11 @@ static void av7110_emit_keyup(unsigned long data)
53static struct timer_list keyup_timer = { .function = av7110_emit_keyup }; 53static struct timer_list keyup_timer = { .function = av7110_emit_keyup };
54 54
55 55
56static void av7110_emit_key(u32 ircom) 56static void av7110_emit_key(unsigned long parm)
57{ 57{
58 struct av7110 *av7110 = (struct av7110 *) parm;
59 u32 ir_config = av7110->ir_config;
60 u32 ircom = av7110->ir_command;
58 u8 data; 61 u8 data;
59 u8 addr; 62 u8 addr;
60 static u16 old_toggle = 0; 63 static u16 old_toggle = 0;
@@ -62,19 +65,33 @@ static void av7110_emit_key(u32 ircom)
62 u16 keycode; 65 u16 keycode;
63 66
64 /* extract device address and data */ 67 /* extract device address and data */
65 if (ir_config & 0x0001) { 68 switch (ir_config & 0x0003) {
66 /* TODO RCMM: ? bits device address, 8 bits data */ 69 case 0: /* RC5: 5 bits device address, 6 bits data */
70 data = ircom & 0x3f;
71 addr = (ircom >> 6) & 0x1f;
72 break;
73
74 case 1: /* RCMM: 8(?) bits device address, 8(?) bits data */
67 data = ircom & 0xff; 75 data = ircom & 0xff;
68 addr = (ircom >> 8) & 0xff; 76 addr = (ircom >> 8) & 0xff;
69 } else { 77 break;
70 /* RC5: 5 bits device address, 6 bits data */ 78
79 case 2: /* extended RC5: 5 bits device address, 7 bits data */
71 data = ircom & 0x3f; 80 data = ircom & 0x3f;
72 addr = (ircom >> 6) & 0x1f; 81 addr = (ircom >> 6) & 0x1f;
82 /* invert 7th data bit for backward compatibility with RC5 keymaps */
83 if (!(ircom & 0x1000))
84 data |= 0x40;
85 break;
86
87 default:
88 printk("invalid ir_config %x\n", ir_config);
89 return;
73 } 90 }
74 91
75 keycode = key_map[data]; 92 keycode = key_map[data];
76 93
77 dprintk(16, "#########%08x######### addr %i data 0x%02x (keycode %i)\n", 94 dprintk(16, "code %08x -> addr %i data 0x%02x -> keycode %i\n",
78 ircom, addr, data, keycode); 95 ircom, addr, data, keycode);
79 96
80 /* check device address (if selected) */ 97 /* check device address (if selected) */
@@ -87,10 +104,10 @@ static void av7110_emit_key(u32 ircom)
87 return; 104 return;
88 } 105 }
89 106
90 if (ir_config & 0x0001) 107 if ((ir_config & 0x0003) == 1)
91 new_toggle = 0; /* RCMM */ 108 new_toggle = 0; /* RCMM */
92 else 109 else
93 new_toggle = (ircom & 0x800); /* RC5 */ 110 new_toggle = (ircom & 0x800); /* RC5, extended RC5 */
94 111
95 if (timer_pending(&keyup_timer)) { 112 if (timer_pending(&keyup_timer)) {
96 del_timer(&keyup_timer); 113 del_timer(&keyup_timer);
@@ -137,6 +154,8 @@ static int av7110_ir_write_proc(struct file *file, const char __user *buffer,
137{ 154{
138 char *page; 155 char *page;
139 int size = 4 + 256 * sizeof(u16); 156 int size = 4 + 256 * sizeof(u16);
157 u32 ir_config;
158 int i;
140 159
141 if (count < size) 160 if (count < size)
142 return -EINVAL; 161 return -EINVAL;
@@ -153,60 +172,95 @@ static int av7110_ir_write_proc(struct file *file, const char __user *buffer,
153 memcpy(&ir_config, page, 4); 172 memcpy(&ir_config, page, 4);
154 memcpy(&key_map, page + 4, 256 * sizeof(u16)); 173 memcpy(&key_map, page + 4, 256 * sizeof(u16));
155 vfree(page); 174 vfree(page);
156 av7110_setup_irc_config(NULL, ir_config); 175 if (FW_VERSION(av_list[0]->arm_app) >= 0x2620 && !(ir_config & 0x0001))
176 ir_config |= 0x0002; /* enable extended RC5 */
177 for (i = 0; i < av_cnt; i++)
178 av7110_setup_irc_config(av_list[i], ir_config);
157 input_register_keys(); 179 input_register_keys();
158 return count; 180 return count;
159} 181}
160 182
161 183
162int __init av7110_ir_init(void) 184int av7110_setup_irc_config(struct av7110 *av7110, u32 ir_config)
163{ 185{
164 static struct proc_dir_entry *e; 186 int ret = 0;
165 187
166 if (ir_initialized) 188 dprintk(4, "%p\n", av7110);
167 return 0; 189 if (av7110) {
190 ret = av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, SetIR, 1, ir_config);
191 av7110->ir_config = ir_config;
192 }
193 return ret;
194}
168 195
169 init_timer(&keyup_timer);
170 keyup_timer.data = 0;
171 196
172 input_dev.name = "DVB on-card IR receiver"; 197static void ir_handler(struct av7110 *av7110, u32 ircom)
198{
199 dprintk(4, "ircommand = %08x\n", ircom);
200 av7110->ir_command = ircom;
201 tasklet_schedule(&av7110->ir_tasklet);
202}
173 203
174 /**
175 * enable keys
176 */
177 set_bit(EV_KEY, input_dev.evbit);
178 set_bit(EV_REP, input_dev.evbit);
179 204
180 input_register_keys(); 205int __init av7110_ir_init(struct av7110 *av7110)
206{
207 static struct proc_dir_entry *e;
181 208
182 input_register_device(&input_dev); 209 if (av_cnt >= sizeof av_list/sizeof av_list[0])
183 input_dev.timer.function = input_repeat_key; 210 return -ENOSPC;
184 211
185 av7110_setup_irc_config(NULL, 0x0001); 212 av7110_setup_irc_config(av7110, 0x0001);
186 av7110_register_irc_handler(av7110_emit_key); 213 av_list[av_cnt++] = av7110;
187 214
188 e = create_proc_entry("av7110_ir", S_IFREG | S_IRUGO | S_IWUSR, NULL); 215 if (av_cnt == 1) {
189 if (e) { 216 init_timer(&keyup_timer);
190 e->write_proc = av7110_ir_write_proc; 217 keyup_timer.data = 0;
191 e->size = 4 + 256 * sizeof(u16); 218
219 input_dev.name = "DVB on-card IR receiver";
220 set_bit(EV_KEY, input_dev.evbit);
221 set_bit(EV_REP, input_dev.evbit);
222 input_register_keys();
223 input_register_device(&input_dev);
224 input_dev.timer.function = input_repeat_key;
225
226 e = create_proc_entry("av7110_ir", S_IFREG | S_IRUGO | S_IWUSR, NULL);
227 if (e) {
228 e->write_proc = av7110_ir_write_proc;
229 e->size = 4 + 256 * sizeof(u16);
230 }
192 } 231 }
193 232
194 ir_initialized = 1; 233 tasklet_init(&av7110->ir_tasklet, av7110_emit_key, (unsigned long) av7110);
234 av7110->ir_handler = ir_handler;
235
195 return 0; 236 return 0;
196} 237}
197 238
198 239
199void __exit av7110_ir_exit(void) 240void __exit av7110_ir_exit(struct av7110 *av7110)
200{ 241{
201 if (ir_initialized == 0) 242 int i;
243
244 if (av_cnt == 0)
202 return; 245 return;
203 del_timer_sync(&keyup_timer); 246
204 remove_proc_entry("av7110_ir", NULL); 247 av7110->ir_handler = NULL;
205 av7110_unregister_irc_handler(av7110_emit_key); 248 tasklet_kill(&av7110->ir_tasklet);
206 input_unregister_device(&input_dev); 249 for (i = 0; i < av_cnt; i++)
207 ir_initialized = 0; 250 if (av_list[i] == av7110) {
251 av_list[i] = av_list[av_cnt-1];
252 av_list[av_cnt-1] = NULL;
253 break;
254 }
255
256 if (av_cnt == 1) {
257 del_timer_sync(&keyup_timer);
258 remove_proc_entry("av7110_ir", NULL);
259 input_unregister_device(&input_dev);
260 }
261
262 av_cnt--;
208} 263}
209 264
210//MODULE_AUTHOR("Holger Waechtler <holger@convergence.de>"); 265//MODULE_AUTHOR("Holger Waechtler <holger@convergence.de>");
211//MODULE_LICENSE("GPL"); 266//MODULE_LICENSE("GPL");
212
diff --git a/drivers/media/dvb/ttpci/av7110_v4l.c b/drivers/media/dvb/ttpci/av7110_v4l.c
index e65fc36e2c..6af74f78b3 100644
--- a/drivers/media/dvb/ttpci/av7110_v4l.c
+++ b/drivers/media/dvb/ttpci/av7110_v4l.c
@@ -70,7 +70,7 @@ static int msp_readreg(struct av7110 *av7110, u8 dev, u16 reg, u16 *val)
70 return 0; 70 return 0;
71} 71}
72 72
73static struct v4l2_input inputs[2] = { 73static struct v4l2_input inputs[4] = {
74 { 74 {
75 .index = 0, 75 .index = 0,
76 .name = "DVB", 76 .name = "DVB",
@@ -87,6 +87,22 @@ static struct v4l2_input inputs[2] = {
87 .tuner = 0, 87 .tuner = 0,
88 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 88 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
89 .status = 0, 89 .status = 0,
90 }, {
91 .index = 2,
92 .name = "Video",
93 .type = V4L2_INPUT_TYPE_CAMERA,
94 .audioset = 0,
95 .tuner = 0,
96 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
97 .status = 0,
98 }, {
99 .index = 3,
100 .name = "Y/C",
101 .type = V4L2_INPUT_TYPE_CAMERA,
102 .audioset = 0,
103 .tuner = 0,
104 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
105 .status = 0,
90 } 106 }
91}; 107};
92 108
@@ -212,24 +228,44 @@ static int av7110_dvb_c_switch(struct saa7146_fh *fh)
212 } 228 }
213 229
214 if (0 != av7110->current_input) { 230 if (0 != av7110->current_input) {
231 dprintk(1, "switching to analog TV:\n");
215 adswitch = 1; 232 adswitch = 1;
216 source = SAA7146_HPS_SOURCE_PORT_B; 233 source = SAA7146_HPS_SOURCE_PORT_B;
217 sync = SAA7146_HPS_SYNC_PORT_B; 234 sync = SAA7146_HPS_SYNC_PORT_B;
218 memcpy(standard, analog_standard, sizeof(struct saa7146_standard) * 2); 235 memcpy(standard, analog_standard, sizeof(struct saa7146_standard) * 2);
219 dprintk(1, "switching to analog TV\n");
220 msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0000); // loudspeaker source
221 msp_writereg(av7110, MSP_WR_DSP, 0x0009, 0x0000); // headphone source
222 msp_writereg(av7110, MSP_WR_DSP, 0x000a, 0x0000); // SCART 1 source
223 msp_writereg(av7110, MSP_WR_DSP, 0x000e, 0x3000); // FM matrix, mono
224 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x4f00); // loudspeaker + headphone
225 msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x4f00); // SCART 1 volume
226 236
227 if (av7110->analog_tuner_flags & ANALOG_TUNER_VES1820) { 237 switch (av7110->current_input) {
228 if (ves1820_writereg(dev, 0x09, 0x0f, 0x60)) 238 case 1:
229 dprintk(1, "setting band in demodulator failed.\n"); 239 dprintk(1, "switching SAA7113 to Analog Tuner Input.\n");
230 } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) { 240 msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0000); // loudspeaker source
231 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI); // TDA9198 pin9(STD) 241 msp_writereg(av7110, MSP_WR_DSP, 0x0009, 0x0000); // headphone source
232 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI); // TDA9198 pin30(VIF) 242 msp_writereg(av7110, MSP_WR_DSP, 0x000a, 0x0000); // SCART 1 source
243 msp_writereg(av7110, MSP_WR_DSP, 0x000e, 0x3000); // FM matrix, mono
244 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x4f00); // loudspeaker + headphone
245 msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x4f00); // SCART 1 volume
246
247 if (av7110->analog_tuner_flags & ANALOG_TUNER_VES1820) {
248 if (ves1820_writereg(dev, 0x09, 0x0f, 0x60))
249 dprintk(1, "setting band in demodulator failed.\n");
250 } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) {
251 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI); // TDA9198 pin9(STD)
252 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI); // TDA9198 pin30(VIF)
253 }
254 if (i2c_writereg(av7110, 0x48, 0x02, 0xd0) != 1)
255 dprintk(1, "saa7113 write failed @ card %d", av7110->dvb_adapter.num);
256 break;
257 case 2:
258 dprintk(1, "switching SAA7113 to Video AV CVBS Input.\n");
259 if (i2c_writereg(av7110, 0x48, 0x02, 0xd2) != 1)
260 dprintk(1, "saa7113 write failed @ card %d", av7110->dvb_adapter.num);
261 break;
262 case 3:
263 dprintk(1, "switching SAA7113 to Video AV Y/C Input.\n");
264 if (i2c_writereg(av7110, 0x48, 0x02, 0xd9) != 1)
265 dprintk(1, "saa7113 write failed @ card %d", av7110->dvb_adapter.num);
266 break;
267 default:
268 dprintk(1, "switching SAA7113 to Input: AV7110: SAA7113: invalid input.\n");
233 } 269 }
234 } else { 270 } else {
235 adswitch = 0; 271 adswitch = 0;
@@ -300,7 +336,6 @@ static int av7110_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
300 // FIXME: standard / stereo detection is still broken 336 // FIXME: standard / stereo detection is still broken
301 msp_readreg(av7110, MSP_RD_DEM, 0x007e, &stereo_det); 337 msp_readreg(av7110, MSP_RD_DEM, 0x007e, &stereo_det);
302 dprintk(1, "VIDIOC_G_TUNER: msp3400 TV standard detection: 0x%04x\n", stereo_det); 338 dprintk(1, "VIDIOC_G_TUNER: msp3400 TV standard detection: 0x%04x\n", stereo_det);
303
304 msp_readreg(av7110, MSP_RD_DSP, 0x0018, &stereo_det); 339 msp_readreg(av7110, MSP_RD_DSP, 0x0018, &stereo_det);
305 dprintk(1, "VIDIOC_G_TUNER: msp3400 stereo detection: 0x%04x\n", stereo_det); 340 dprintk(1, "VIDIOC_G_TUNER: msp3400 stereo detection: 0x%04x\n", stereo_det);
306 stereo = (s8)(stereo_det >> 8); 341 stereo = (s8)(stereo_det >> 8);
@@ -310,7 +345,7 @@ static int av7110_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
310 t->audmode = V4L2_TUNER_MODE_STEREO; 345 t->audmode = V4L2_TUNER_MODE_STEREO;
311 } 346 }
312 else if (stereo < -0x10) { 347 else if (stereo < -0x10) {
313 /* bilingual*/ 348 /* bilingual */
314 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; 349 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
315 t->audmode = V4L2_TUNER_MODE_LANG1; 350 t->audmode = V4L2_TUNER_MODE_LANG1;
316 } 351 }
@@ -344,7 +379,7 @@ static int av7110_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
344 fm_matrix = 0x3000; // mono 379 fm_matrix = 0x3000; // mono
345 src = 0x0010; 380 src = 0x0010;
346 break; 381 break;
347 default: /* case V4L2_TUNER_MODE_MONO: {*/ 382 default: /* case V4L2_TUNER_MODE_MONO: */
348 dprintk(2, "VIDIOC_S_TUNER: TDA9840_SET_MONO\n"); 383 dprintk(2, "VIDIOC_S_TUNER: TDA9840_SET_MONO\n");
349 fm_matrix = 0x3000; // mono 384 fm_matrix = 0x3000; // mono
350 src = 0x0030; 385 src = 0x0030;
@@ -406,7 +441,7 @@ static int av7110_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
406 dprintk(2, "VIDIOC_ENUMINPUT: %d\n", i->index); 441 dprintk(2, "VIDIOC_ENUMINPUT: %d\n", i->index);
407 442
408 if (av7110->analog_tuner_flags) { 443 if (av7110->analog_tuner_flags) {
409 if (i->index < 0 || i->index >= 2) 444 if (i->index < 0 || i->index >= 4)
410 return -EINVAL; 445 return -EINVAL;
411 } else { 446 } else {
412 if (i->index != 0) 447 if (i->index != 0)
@@ -433,10 +468,9 @@ static int av7110_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
433 if (!av7110->analog_tuner_flags) 468 if (!av7110->analog_tuner_flags)
434 return 0; 469 return 0;
435 470
436 if (input < 0 || input >= 2) 471 if (input < 0 || input >= 4)
437 return -EINVAL; 472 return -EINVAL;
438 473
439 /* FIXME: switch inputs here */
440 av7110->current_input = input; 474 av7110->current_input = input;
441 return av7110_dvb_c_switch(fh); 475 return av7110_dvb_c_switch(fh);
442 } 476 }
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
index 9746d2bb91..7692cd23f8 100644
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ b/drivers/media/dvb/ttpci/budget-av.c
@@ -192,7 +192,7 @@ static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot)
192{ 192{
193 struct budget_av *budget_av = (struct budget_av *) ca->data; 193 struct budget_av *budget_av = (struct budget_av *) ca->data;
194 struct saa7146_dev *saa = budget_av->budget.dev; 194 struct saa7146_dev *saa = budget_av->budget.dev;
195 int timeout = 50; // 5 seconds (4.4.6 Ready) 195 int timeout = 500; // 5 seconds (4.4.6 Ready)
196 196
197 if (slot != 0) 197 if (slot != 0)
198 return -EINVAL; 198 return -EINVAL;
@@ -217,7 +217,6 @@ static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot)
217 { 217 {
218 printk(KERN_ERR "budget-av: cam reset failed (timeout).\n"); 218 printk(KERN_ERR "budget-av: cam reset failed (timeout).\n");
219 saa7146_setgpio(saa, 2, SAA7146_GPIO_OUTHI); /* disable card */ 219 saa7146_setgpio(saa, 2, SAA7146_GPIO_OUTHI); /* disable card */
220 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTHI); /* Vcc off */
221 return -ETIMEDOUT; 220 return -ETIMEDOUT;
222 } 221 }
223 222
@@ -276,7 +275,6 @@ static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open
276 { 275 {
277 printk(KERN_INFO "budget-av: cam ejected\n"); 276 printk(KERN_INFO "budget-av: cam ejected\n");
278 saa7146_setgpio(saa, 2, SAA7146_GPIO_OUTHI); /* disable card */ 277 saa7146_setgpio(saa, 2, SAA7146_GPIO_OUTHI); /* disable card */
279 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTHI); /* Vcc off */
280 budget_av->slot_status = 0; 278 budget_av->slot_status = 0;
281 } 279 }
282 } 280 }
@@ -453,9 +451,9 @@ static int philips_su1278_ty_ci_set_symbol_rate(struct dvb_frontend *fe, u32 sra
453} 451}
454 452
455static int philips_su1278_ty_ci_pll_set(struct dvb_frontend *fe, 453static int philips_su1278_ty_ci_pll_set(struct dvb_frontend *fe,
454 struct i2c_adapter *i2c,
456 struct dvb_frontend_parameters *params) 455 struct dvb_frontend_parameters *params)
457{ 456{
458 struct budget_av *budget_av = (struct budget_av *) fe->dvb->priv;
459 u32 div; 457 u32 div;
460 u8 buf[4]; 458 u8 buf[4];
461 struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof(buf) }; 459 struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof(buf) };
@@ -481,7 +479,7 @@ static int philips_su1278_ty_ci_pll_set(struct dvb_frontend *fe,
481 else if (params->frequency < 2150000) 479 else if (params->frequency < 2150000)
482 buf[3] |= 0xC0; 480 buf[3] |= 0xC0;
483 481
484 if (i2c_transfer(&budget_av->budget.i2c_adap, &msg, 1) != 1) 482 if (i2c_transfer(i2c, &msg, 1) != 1)
485 return -EIO; 483 return -EIO;
486 return 0; 484 return 0;
487} 485}
@@ -745,6 +743,7 @@ static void frontend_init(struct budget_av *budget_av)
745 case SUBID_DVBC_KNC1_PLUS: 743 case SUBID_DVBC_KNC1_PLUS:
746 case SUBID_DVBT_KNC1_PLUS: 744 case SUBID_DVBT_KNC1_PLUS:
747 // Enable / PowerON Frontend 745 // Enable / PowerON Frontend
746 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTLO);
748 saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTHI); 747 saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTHI);
749 break; 748 break;
750 } 749 }
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
index a1267054bc..2980db3ef2 100644
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ b/drivers/media/dvb/ttpci/budget-ci.c
@@ -40,6 +40,7 @@
40 40
41#include "dvb_ca_en50221.h" 41#include "dvb_ca_en50221.h"
42#include "stv0299.h" 42#include "stv0299.h"
43#include "stv0297.h"
43#include "tda1004x.h" 44#include "tda1004x.h"
44 45
45#define DEBIADDR_IR 0x1234 46#define DEBIADDR_IR 0x1234
@@ -548,9 +549,8 @@ static int alps_bsru6_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ra
548 return 0; 549 return 0;
549} 550}
550 551
551static int alps_bsru6_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params) 552static int alps_bsru6_pll_set(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters *params)
552{ 553{
553 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
554 u8 buf[4]; 554 u8 buf[4];
555 u32 div; 555 u32 div;
556 struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof(buf) }; 556 struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof(buf) };
@@ -567,7 +567,7 @@ static int alps_bsru6_pll_set(struct dvb_frontend *fe, struct dvb_frontend_param
567 if (params->frequency > 1530000) 567 if (params->frequency > 1530000)
568 buf[3] = 0xc0; 568 buf[3] = 0xc0;
569 569
570 if (i2c_transfer(&budget_ci->budget.i2c_adap, &msg, 1) != 1) 570 if (i2c_transfer(i2c, &msg, 1) != 1)
571 return -EIO; 571 return -EIO;
572 return 0; 572 return 0;
573} 573}
@@ -669,9 +669,9 @@ static int philips_su1278_tt_set_symbol_rate(struct dvb_frontend *fe, u32 srate,
669} 669}
670 670
671static int philips_su1278_tt_pll_set(struct dvb_frontend *fe, 671static int philips_su1278_tt_pll_set(struct dvb_frontend *fe,
672 struct i2c_adapter *i2c,
672 struct dvb_frontend_parameters *params) 673 struct dvb_frontend_parameters *params)
673{ 674{
674 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
675 u32 div; 675 u32 div;
676 u8 buf[4]; 676 u8 buf[4];
677 struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) }; 677 struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) };
@@ -697,7 +697,7 @@ static int philips_su1278_tt_pll_set(struct dvb_frontend *fe,
697 else if (params->frequency < 2150000) 697 else if (params->frequency < 2150000)
698 buf[3] |= 0xC0; 698 buf[3] |= 0xC0;
699 699
700 if (i2c_transfer(&budget_ci->budget.i2c_adap, &msg, 1) != 1) 700 if (i2c_transfer(i2c, &msg, 1) != 1)
701 return -EIO; 701 return -EIO;
702 return 0; 702 return 0;
703} 703}
@@ -848,6 +848,180 @@ static struct tda1004x_config philips_tdm1316l_config = {
848 .request_firmware = philips_tdm1316l_request_firmware, 848 .request_firmware = philips_tdm1316l_request_firmware,
849}; 849};
850 850
851static int dvbc_philips_tdm1316l_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
852{
853 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
854 u8 tuner_buf[5];
855 struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,
856 .flags = 0,
857 .buf = tuner_buf,
858 .len = sizeof(tuner_buf) };
859 int tuner_frequency = 0;
860 u8 band, cp, filter;
861
862 // determine charge pump
863 tuner_frequency = params->frequency + 36125000;
864 if (tuner_frequency < 87000000)
865 return -EINVAL;
866 else if (tuner_frequency < 130000000) {
867 cp = 3;
868 band = 1;
869 } else if (tuner_frequency < 160000000) {
870 cp = 5;
871 band = 1;
872 } else if (tuner_frequency < 200000000) {
873 cp = 6;
874 band = 1;
875 } else if (tuner_frequency < 290000000) {
876 cp = 3;
877 band = 2;
878 } else if (tuner_frequency < 420000000) {
879 cp = 5;
880 band = 2;
881 } else if (tuner_frequency < 480000000) {
882 cp = 6;
883 band = 2;
884 } else if (tuner_frequency < 620000000) {
885 cp = 3;
886 band = 4;
887 } else if (tuner_frequency < 830000000) {
888 cp = 5;
889 band = 4;
890 } else if (tuner_frequency < 895000000) {
891 cp = 7;
892 band = 4;
893 } else
894 return -EINVAL;
895
896 // assume PLL filter should always be 8MHz for the moment.
897 filter = 1;
898
899 // calculate divisor
900 tuner_frequency = (params->frequency + 36125000 + (62500/2)) / 62500;
901
902 // setup tuner buffer
903 tuner_buf[0] = tuner_frequency >> 8;
904 tuner_buf[1] = tuner_frequency & 0xff;
905 tuner_buf[2] = 0xc8;
906 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
907 tuner_buf[4] = 0x80;
908
909 stv0297_enable_plli2c(fe);
910 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
911 return -EIO;
912
913 msleep(50);
914
915 stv0297_enable_plli2c(fe);
916 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
917 return -EIO;
918
919 msleep(1);
920
921 return 0;
922}
923
924static u8 dvbc_philips_tdm1316l_inittab[] = {
925 0x80, 0x01,
926 0x80, 0x00,
927 0x81, 0x01,
928 0x81, 0x00,
929 0x00, 0x09,
930 0x01, 0x69,
931 0x03, 0x00,
932 0x04, 0x00,
933 0x07, 0x00,
934 0x08, 0x00,
935 0x20, 0x00,
936 0x21, 0x40,
937 0x22, 0x00,
938 0x23, 0x00,
939 0x24, 0x40,
940 0x25, 0x88,
941 0x30, 0xff,
942 0x31, 0x00,
943 0x32, 0xff,
944 0x33, 0x00,
945 0x34, 0x50,
946 0x35, 0x7f,
947 0x36, 0x00,
948 0x37, 0x20,
949 0x38, 0x00,
950 0x40, 0x1c,
951 0x41, 0xff,
952 0x42, 0x29,
953 0x43, 0x20,
954 0x44, 0xff,
955 0x45, 0x00,
956 0x46, 0x00,
957 0x49, 0x04,
958 0x4a, 0x00,
959 0x4b, 0x7b,
960 0x52, 0x30,
961 0x55, 0xae,
962 0x56, 0x47,
963 0x57, 0xe1,
964 0x58, 0x3a,
965 0x5a, 0x1e,
966 0x5b, 0x34,
967 0x60, 0x00,
968 0x63, 0x00,
969 0x64, 0x00,
970 0x65, 0x00,
971 0x66, 0x00,
972 0x67, 0x00,
973 0x68, 0x00,
974 0x69, 0x00,
975 0x6a, 0x02,
976 0x6b, 0x00,
977 0x70, 0xff,
978 0x71, 0x00,
979 0x72, 0x00,
980 0x73, 0x00,
981 0x74, 0x0c,
982 0x80, 0x00,
983 0x81, 0x00,
984 0x82, 0x00,
985 0x83, 0x00,
986 0x84, 0x04,
987 0x85, 0x80,
988 0x86, 0x24,
989 0x87, 0x78,
990 0x88, 0x10,
991 0x89, 0x00,
992 0x90, 0x01,
993 0x91, 0x01,
994 0xa0, 0x04,
995 0xa1, 0x00,
996 0xa2, 0x00,
997 0xb0, 0x91,
998 0xb1, 0x0b,
999 0xc0, 0x53,
1000 0xc1, 0x70,
1001 0xc2, 0x12,
1002 0xd0, 0x00,
1003 0xd1, 0x00,
1004 0xd2, 0x00,
1005 0xd3, 0x00,
1006 0xd4, 0x00,
1007 0xd5, 0x00,
1008 0xde, 0x00,
1009 0xdf, 0x00,
1010 0x61, 0x38,
1011 0x62, 0x0a,
1012 0x53, 0x13,
1013 0x59, 0x08,
1014 0xff, 0xff,
1015};
1016
1017static struct stv0297_config dvbc_philips_tdm1316l_config = {
1018 .demod_address = 0x1c,
1019 .inittab = dvbc_philips_tdm1316l_inittab,
1020 .invert = 0,
1021 .pll_set = dvbc_philips_tdm1316l_pll_set,
1022};
1023
1024
851 1025
852 1026
853static void frontend_init(struct budget_ci *budget_ci) 1027static void frontend_init(struct budget_ci *budget_ci)
@@ -869,6 +1043,15 @@ static void frontend_init(struct budget_ci *budget_ci)
869 } 1043 }
870 break; 1044 break;
871 1045
1046 case 0x1010: // TT DVB-C CI budget (stv0297/Philips tdm1316l(tda6651tt))
1047 budget_ci->tuner_pll_address = 0x61;
1048 budget_ci->budget.dvb_frontend =
1049 stv0297_attach(&dvbc_philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
1050 if (budget_ci->budget.dvb_frontend) {
1051 break;
1052 }
1053 break;
1054
872 case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889) 1055 case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889)
873 budget_ci->tuner_pll_address = 0x63; 1056 budget_ci->tuner_pll_address = 0x63;
874 budget_ci->budget.dvb_frontend = 1057 budget_ci->budget.dvb_frontend =
@@ -878,7 +1061,7 @@ static void frontend_init(struct budget_ci *budget_ci)
878 } 1061 }
879 break; 1062 break;
880 1063
881 case 0x1012: // Hauppauge/TT Nova-T CI budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889) 1064 case 0x1012: // TT DVB-T CI budget (tda10046/Philips tdm1316l(tda6651tt))
882 budget_ci->tuner_pll_address = 0x60; 1065 budget_ci->tuner_pll_address = 0x60;
883 budget_ci->budget.dvb_frontend = 1066 budget_ci->budget.dvb_frontend =
884 tda10046_attach(&philips_tdm1316l_config, &budget_ci->budget.i2c_adap); 1067 tda10046_attach(&philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
@@ -966,10 +1149,12 @@ static struct saa7146_extension budget_extension;
966MAKE_BUDGET_INFO(ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC); 1149MAKE_BUDGET_INFO(ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC);
967MAKE_BUDGET_INFO(ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT); 1150MAKE_BUDGET_INFO(ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
968MAKE_BUDGET_INFO(ttbtci, "TT-Budget-T-CI PCI", BUDGET_TT); 1151MAKE_BUDGET_INFO(ttbtci, "TT-Budget-T-CI PCI", BUDGET_TT);
1152MAKE_BUDGET_INFO(ttbcci, "TT-Budget-C-CI PCI", BUDGET_TT);
969 1153
970static struct pci_device_id pci_tbl[] = { 1154static struct pci_device_id pci_tbl[] = {
971 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c), 1155 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c),
972 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100f), 1156 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100f),
1157 MAKE_EXTENSION_PCI(ttbcci, 0x13c2, 0x1010),
973 MAKE_EXTENSION_PCI(ttbt2, 0x13c2, 0x1011), 1158 MAKE_EXTENSION_PCI(ttbt2, 0x13c2, 0x1011),
974 MAKE_EXTENSION_PCI(ttbtci, 0x13c2, 0x1012), 1159 MAKE_EXTENSION_PCI(ttbtci, 0x13c2, 0x1012),
975 { 1160 {
diff --git a/drivers/media/dvb/ttpci/budget-patch.c b/drivers/media/dvb/ttpci/budget-patch.c
index 8142e26b47..b1f21ef0e3 100644
--- a/drivers/media/dvb/ttpci/budget-patch.c
+++ b/drivers/media/dvb/ttpci/budget-patch.c
@@ -353,9 +353,8 @@ static int alps_bsru6_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ra
353 return 0; 353 return 0;
354} 354}
355 355
356static int alps_bsru6_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 356static int alps_bsru6_pll_set(struct dvb_frontend* fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters* params)
357{ 357{
358 struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv;
359 u8 data[4]; 358 u8 data[4];
360 u32 div; 359 u32 div;
361 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) }; 360 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
@@ -370,7 +369,7 @@ static int alps_bsru6_pll_set(struct dvb_frontend* fe, struct dvb_frontend_param
370 369
371 if (params->frequency > 1530000) data[3] = 0xc0; 370 if (params->frequency > 1530000) data[3] = 0xc0;
372 371
373 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO; 372 if (i2c_transfer(i2c, &msg, 1) != 1) return -EIO;
374 return 0; 373 return 0;
375} 374}
376 375
diff --git a/drivers/media/dvb/ttpci/budget.c b/drivers/media/dvb/ttpci/budget.c
index 9961917e8a..43d6c82686 100644
--- a/drivers/media/dvb/ttpci/budget.c
+++ b/drivers/media/dvb/ttpci/budget.c
@@ -332,9 +332,8 @@ static int alps_bsru6_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ra
332 return 0; 332 return 0;
333} 333}
334 334
335static int alps_bsru6_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 335static int alps_bsru6_pll_set(struct dvb_frontend* fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters* params)
336{ 336{
337 struct budget* budget = (struct budget*) fe->dvb->priv;
338 u8 data[4]; 337 u8 data[4];
339 u32 div; 338 u32 div;
340 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) }; 339 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
@@ -349,7 +348,7 @@ static int alps_bsru6_pll_set(struct dvb_frontend* fe, struct dvb_frontend_param
349 348
350 if (params->frequency > 1530000) data[3] = 0xc0; 349 if (params->frequency > 1530000) data[3] = 0xc0;
351 350
352 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO; 351 if (i2c_transfer(i2c, &msg, 1) != 1) return -EIO;
353 return 0; 352 return 0;
354} 353}
355 354
@@ -481,6 +480,7 @@ static int s5h1420_pll_set(struct dvb_frontend* fe, struct dvb_frontend_paramete
481 480
482static struct s5h1420_config s5h1420_config = { 481static struct s5h1420_config s5h1420_config = {
483 .demod_address = 0x53, 482 .demod_address = 0x53,
483 .invert = 1,
484 .pll_set = s5h1420_pll_set, 484 .pll_set = s5h1420_pll_set,
485}; 485};
486 486
diff --git a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
index 7daf7b1598..d200ab0ad9 100644
--- a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
@@ -18,6 +18,7 @@
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/time.h> 19#include <linux/time.h>
20#include <linux/errno.h> 20#include <linux/errno.h>
21#include <linux/jiffies.h>
21#include <asm/semaphore.h> 22#include <asm/semaphore.h>
22 23
23#include "dvb_frontend.h" 24#include "dvb_frontend.h"
@@ -570,7 +571,8 @@ static void ttusb_handle_sec_data(struct ttusb_channel *channel,
570 const u8 * data, int len); 571 const u8 * data, int len);
571#endif 572#endif
572 573
573static int numpkt = 0, lastj, numts, numstuff, numsec, numinvalid; 574static int numpkt = 0, numts, numstuff, numsec, numinvalid;
575static unsigned long lastj;
574 576
575static void ttusb_process_muxpack(struct ttusb *ttusb, const u8 * muxpack, 577static void ttusb_process_muxpack(struct ttusb *ttusb, const u8 * muxpack,
576 int len) 578 int len)
@@ -779,7 +781,7 @@ static void ttusb_iso_irq(struct urb *urb, struct pt_regs *ptregs)
779 u8 *data; 781 u8 *data;
780 int len; 782 int len;
781 numpkt++; 783 numpkt++;
782 if ((jiffies - lastj) >= HZ) { 784 if (time_after_eq(jiffies, lastj + HZ)) {
783#if DEBUG > 2 785#if DEBUG > 2
784 printk 786 printk
785 ("frames/s: %d (ts: %d, stuff %d, sec: %d, invalid: %d, all: %d)\n", 787 ("frames/s: %d (ts: %d, stuff %d, sec: %d, invalid: %d, all: %d)\n",
@@ -1299,7 +1301,7 @@ static int alps_stv0299_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32
1299 return 0; 1301 return 0;
1300} 1302}
1301 1303
1302static int philips_tsa5059_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params) 1304static int philips_tsa5059_pll_set(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct dvb_frontend_parameters *params)
1303{ 1305{
1304 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv; 1306 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
1305 u8 buf[4]; 1307 u8 buf[4];
@@ -1322,7 +1324,7 @@ static int philips_tsa5059_pll_set(struct dvb_frontend *fe, struct dvb_frontend_
1322 if (ttusb->revision == TTUSB_REV_2_2) 1324 if (ttusb->revision == TTUSB_REV_2_2)
1323 buf[3] |= 0x20; 1325 buf[3] |= 0x20;
1324 1326
1325 if (i2c_transfer(&ttusb->i2c_adap, &msg, 1) != 1) 1327 if (i2c_transfer(i2c, &msg, 1) != 1)
1326 return -EIO; 1328 return -EIO;
1327 1329
1328 return 0; 1330 return 0;
diff --git a/drivers/media/dvb/ttusb-dec/ttusb_dec.c b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
index 45c9a9a08e..3d08fc83a7 100644
--- a/drivers/media/dvb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
@@ -28,7 +28,6 @@
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/spinlock.h> 29#include <linux/spinlock.h>
30#include <linux/usb.h> 30#include <linux/usb.h>
31#include <linux/version.h>
32#include <linux/interrupt.h> 31#include <linux/interrupt.h>
33#include <linux/firmware.h> 32#include <linux/firmware.h>
34#include <linux/crc32.h> 33#include <linux/crc32.h>
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 16c85c081e..9357035581 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -22,12 +22,21 @@ config VIDEO_BT848
22 the Miro, Hauppauge and STB boards. Please read the material in 22 the Miro, Hauppauge and STB boards. Please read the material in
23 <file:Documentation/video4linux/bttv/> for more information. 23 <file:Documentation/video4linux/bttv/> for more information.
24 24
25 If you say Y or M here, you need to say Y or M to "I2C support" and
26 "I2C bit-banging interfaces" in the device drivers section.
27
28 To compile this driver as a module, choose M here: the 25 To compile this driver as a module, choose M here: the
29 module will be called bttv. 26 module will be called bttv.
30 27
28config VIDEO_SAA6588
29 tristate "SAA6588 Radio Chip RDS decoder support on BT848 cards"
30 depends on VIDEO_DEV && I2C && VIDEO_BT848
31
32 help
33 Support for Radio Data System (RDS) decoder. This allows seeing
34 radio station identification transmitted using this standard.
35 Currentlly, it works only with bt8x8 chips.
36
37 To compile this driver as a module, choose M here: the
38 module will be called saa6588.
39
31config VIDEO_PMS 40config VIDEO_PMS
32 tristate "Mediavision Pro Movie Studio Video For Linux" 41 tristate "Mediavision Pro Movie Studio Video For Linux"
33 depends on VIDEO_DEV && ISA 42 depends on VIDEO_DEV && ISA
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 3e6f5347da..046b82de92 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -5,6 +5,7 @@
5bttv-objs := bttv-driver.o bttv-cards.o bttv-if.o \ 5bttv-objs := bttv-driver.o bttv-cards.o bttv-if.o \
6 bttv-risc.o bttv-vbi.o bttv-i2c.o bttv-gpio.o 6 bttv-risc.o bttv-vbi.o bttv-i2c.o bttv-gpio.o
7zoran-objs := zr36120.o zr36120_i2c.o zr36120_mem.o 7zoran-objs := zr36120.o zr36120_i2c.o zr36120_mem.o
8rds-objs := saa6588.o
8zr36067-objs := zoran_procfs.o zoran_device.o \ 9zr36067-objs := zoran_procfs.o zoran_device.o \
9 zoran_driver.o zoran_card.o 10 zoran_driver.o zoran_card.o
10tuner-objs := tuner-core.o tuner-simple.o mt20xx.o tda8290.o tea5767.o 11tuner-objs := tuner-core.o tuner-simple.o mt20xx.o tda8290.o tea5767.o
@@ -15,6 +16,7 @@ obj-$(CONFIG_VIDEO_BT848) += bttv.o msp3400.o tvaudio.o \
15obj-$(CONFIG_SOUND_TVMIXER) += tvmixer.o 16obj-$(CONFIG_SOUND_TVMIXER) += tvmixer.o
16 17
17obj-$(CONFIG_VIDEO_ZR36120) += zoran.o 18obj-$(CONFIG_VIDEO_ZR36120) += zoran.o
19obj-$(CONFIG_VIDEO_SAA6588) += rds.o
18obj-$(CONFIG_VIDEO_SAA5246A) += saa5246a.o 20obj-$(CONFIG_VIDEO_SAA5246A) += saa5246a.o
19obj-$(CONFIG_VIDEO_SAA5249) += saa5249.o 21obj-$(CONFIG_VIDEO_SAA5249) += saa5249.o
20obj-$(CONFIG_VIDEO_CQCAM) += c-qcam.o 22obj-$(CONFIG_VIDEO_CQCAM) += c-qcam.o
diff --git a/drivers/media/video/btcx-risc.c b/drivers/media/video/btcx-risc.c
index 7f2d515d28..a48de3c0e3 100644
--- a/drivers/media/video/btcx-risc.c
+++ b/drivers/media/video/btcx-risc.c
@@ -1,5 +1,4 @@
1/* 1/*
2 $Id: btcx-risc.c,v 1.6 2005/02/21 13:57:59 kraxel Exp $
3 2
4 btcx-risc.c 3 btcx-risc.c
5 4
diff --git a/drivers/media/video/btcx-risc.h b/drivers/media/video/btcx-risc.h
index 41f60395a5..503e6c6d7b 100644
--- a/drivers/media/video/btcx-risc.h
+++ b/drivers/media/video/btcx-risc.h
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: btcx-risc.h,v 1.2 2004/09/15 16:15:24 kraxel Exp $
3 */ 2 */
4struct btcx_riscmem { 3struct btcx_riscmem {
5 unsigned int size; 4 unsigned int size;
diff --git a/drivers/media/video/bttv-cards.c b/drivers/media/video/bttv-cards.c
index a97b9b958e..190977a1e5 100644
--- a/drivers/media/video/bttv-cards.c
+++ b/drivers/media/video/bttv-cards.c
@@ -1,5 +1,4 @@
1/* 1/*
2 $Id: bttv-cards.c,v 1.54 2005/07/19 18:26:46 mkrufky Exp $
3 2
4 bttv-cards.c 3 bttv-cards.c
5 4
@@ -169,10 +168,10 @@ static struct CARD {
169 { 0xd01810fc, BTTV_GVBCTV5PCI, "I-O Data Co. GV-BCTV5/PCI" }, 168 { 0xd01810fc, BTTV_GVBCTV5PCI, "I-O Data Co. GV-BCTV5/PCI" },
170 169
171 { 0x001211bd, BTTV_PINNACLE, "Pinnacle PCTV" }, 170 { 0x001211bd, BTTV_PINNACLE, "Pinnacle PCTV" },
172 // some cards ship with byteswapped IDs ... 171 /* some cards ship with byteswapped IDs ... */
173 { 0x1200bd11, BTTV_PINNACLE, "Pinnacle PCTV [bswap]" }, 172 { 0x1200bd11, BTTV_PINNACLE, "Pinnacle PCTV [bswap]" },
174 { 0xff00bd11, BTTV_PINNACLE, "Pinnacle PCTV [bswap]" }, 173 { 0xff00bd11, BTTV_PINNACLE, "Pinnacle PCTV [bswap]" },
175 // this seems to happen as well ... 174 /* this seems to happen as well ... */
176 { 0xff1211bd, BTTV_PINNACLE, "Pinnacle PCTV" }, 175 { 0xff1211bd, BTTV_PINNACLE, "Pinnacle PCTV" },
177 176
178 { 0x3000121a, BTTV_VOODOOTV_FM, "3Dfx VoodooTV FM/ VoodooTV 200" }, 177 { 0x3000121a, BTTV_VOODOOTV_FM, "3Dfx VoodooTV FM/ VoodooTV 200" },
@@ -200,12 +199,12 @@ static struct CARD {
200 199
201 { 0x1123153b, BTTV_TERRATVRADIO, "Terratec TV Radio+" }, 200 { 0x1123153b, BTTV_TERRATVRADIO, "Terratec TV Radio+" },
202 { 0x1127153b, BTTV_TERRATV, "Terratec TV+ (V1.05)" }, 201 { 0x1127153b, BTTV_TERRATV, "Terratec TV+ (V1.05)" },
203 // clashes with FlyVideo 202 /* clashes with FlyVideo
204 //{ 0x18521852, BTTV_TERRATV, "Terratec TV+ (V1.10)" }, 203 *{ 0x18521852, BTTV_TERRATV, "Terratec TV+ (V1.10)" }, */
205 { 0x1134153b, BTTV_TERRATVALUE, "Terratec TValue (LR102)" }, 204 { 0x1134153b, BTTV_TERRATVALUE, "Terratec TValue (LR102)" },
206 { 0x1135153b, BTTV_TERRATVALUER, "Terratec TValue Radio" }, // LR102 205 { 0x1135153b, BTTV_TERRATVALUER, "Terratec TValue Radio" }, /* LR102 */
207 { 0x5018153b, BTTV_TERRATVALUE, "Terratec TValue" }, // ?? 206 { 0x5018153b, BTTV_TERRATVALUE, "Terratec TValue" }, /* ?? */
208 { 0xff3b153b, BTTV_TERRATVALUER, "Terratec TValue Radio" }, // ?? 207 { 0xff3b153b, BTTV_TERRATVALUER, "Terratec TValue Radio" }, /* ?? */
209 208
210 { 0x400015b0, BTTV_ZOLTRIX_GENIE, "Zoltrix Genie TV" }, 209 { 0x400015b0, BTTV_ZOLTRIX_GENIE, "Zoltrix Genie TV" },
211 { 0x400a15b0, BTTV_ZOLTRIX_GENIE, "Zoltrix Genie TV" }, 210 { 0x400a15b0, BTTV_ZOLTRIX_GENIE, "Zoltrix Genie TV" },
@@ -287,10 +286,12 @@ static struct CARD {
287 { 0x01071805, BTTV_PICOLO_TETRA_CHIP, "Picolo Tetra Chip #3" }, 286 { 0x01071805, BTTV_PICOLO_TETRA_CHIP, "Picolo Tetra Chip #3" },
288 { 0x01081805, BTTV_PICOLO_TETRA_CHIP, "Picolo Tetra Chip #4" }, 287 { 0x01081805, BTTV_PICOLO_TETRA_CHIP, "Picolo Tetra Chip #4" },
289 288
290 // likely broken, vendor id doesn't match the other magic views ... 289 { 0x15409511, BTTV_ACORP_Y878F, "Acorp Y878F" },
291 //{ 0xa0fca04f, BTTV_MAGICTVIEW063, "Guillemot Maxi TV Video 3" },
292 290
293 // DVB cards (using pci function .1 for mpeg data xfer) 291 /* likely broken, vendor id doesn't match the other magic views ...
292 * { 0xa0fca04f, BTTV_MAGICTVIEW063, "Guillemot Maxi TV Video 3" }, */
293
294 /* DVB cards (using pci function .1 for mpeg data xfer) */
294 { 0x01010071, BTTV_NEBULA_DIGITV, "Nebula Electronics DigiTV" }, 295 { 0x01010071, BTTV_NEBULA_DIGITV, "Nebula Electronics DigiTV" },
295 { 0x07611461, BTTV_AVDVBT_761, "AverMedia AverTV DVB-T 761" }, 296 { 0x07611461, BTTV_AVDVBT_761, "AverMedia AverTV DVB-T 761" },
296 { 0x001c11bd, BTTV_PINNACLESAT, "Pinnacle PCTV Sat" }, 297 { 0x001c11bd, BTTV_PINNACLESAT, "Pinnacle PCTV Sat" },
@@ -298,7 +299,8 @@ static struct CARD {
298 { 0x00011822, BTTV_TWINHAN_DST, "Twinhan VisionPlus DVB" }, 299 { 0x00011822, BTTV_TWINHAN_DST, "Twinhan VisionPlus DVB" },
299 { 0xfc00270f, BTTV_TWINHAN_DST, "ChainTech digitop DST-1000 DVB-S" }, 300 { 0xfc00270f, BTTV_TWINHAN_DST, "ChainTech digitop DST-1000 DVB-S" },
300 { 0x07711461, BTTV_AVDVBT_771, "AVermedia AverTV DVB-T 771" }, 301 { 0x07711461, BTTV_AVDVBT_771, "AVermedia AverTV DVB-T 771" },
301 { 0xdb1018ac, BTTV_DVICO_DVBT_LITE, "DVICO FusionHDTV DVB-T Lite" }, 302 { 0xdb1018ac, BTTV_DVICO_DVBT_LITE, "DViCO FusionHDTV DVB-T Lite" },
303 { 0xd50018ac, BTTV_DVICO_FUSIONHDTV_5_LITE, "DViCO FusionHDTV 5 Lite" },
302 304
303 { 0, -1, NULL } 305 { 0, -1, NULL }
304}; 306};
@@ -316,6 +318,7 @@ struct tvcard bttv_tvcards[] = {
316 .svhs = 2, 318 .svhs = 2,
317 .muxsel = { 2, 3, 1, 0}, 319 .muxsel = { 2, 3, 1, 0},
318 .tuner_type = -1, 320 .tuner_type = -1,
321 .tuner_addr = ADDR_UNSET,
319},{ 322},{
320 .name = "MIRO PCTV", 323 .name = "MIRO PCTV",
321 .video_inputs = 4, 324 .video_inputs = 4,
@@ -327,6 +330,7 @@ struct tvcard bttv_tvcards[] = {
327 .audiomux = { 2, 0, 0, 0, 10}, 330 .audiomux = { 2, 0, 0, 0, 10},
328 .needs_tvaudio = 1, 331 .needs_tvaudio = 1,
329 .tuner_type = -1, 332 .tuner_type = -1,
333 .tuner_addr = ADDR_UNSET,
330},{ 334},{
331 .name = "Hauppauge (bt848)", 335 .name = "Hauppauge (bt848)",
332 .video_inputs = 4, 336 .video_inputs = 4,
@@ -338,6 +342,7 @@ struct tvcard bttv_tvcards[] = {
338 .audiomux = { 0, 1, 2, 3, 4}, 342 .audiomux = { 0, 1, 2, 3, 4},
339 .needs_tvaudio = 1, 343 .needs_tvaudio = 1,
340 .tuner_type = -1, 344 .tuner_type = -1,
345 .tuner_addr = ADDR_UNSET,
341},{ 346},{
342 .name = "STB, Gateway P/N 6000699 (bt848)", 347 .name = "STB, Gateway P/N 6000699 (bt848)",
343 .video_inputs = 3, 348 .video_inputs = 3,
@@ -350,6 +355,7 @@ struct tvcard bttv_tvcards[] = {
350 .no_msp34xx = 1, 355 .no_msp34xx = 1,
351 .needs_tvaudio = 1, 356 .needs_tvaudio = 1,
352 .tuner_type = TUNER_PHILIPS_NTSC, 357 .tuner_type = TUNER_PHILIPS_NTSC,
358 .tuner_addr = ADDR_UNSET,
353 .pll = PLL_28, 359 .pll = PLL_28,
354 .has_radio = 1, 360 .has_radio = 1,
355},{ 361},{
@@ -365,6 +371,7 @@ struct tvcard bttv_tvcards[] = {
365 .audiomux = { 0 }, 371 .audiomux = { 0 },
366 .needs_tvaudio = 0, 372 .needs_tvaudio = 0,
367 .tuner_type = 4, 373 .tuner_type = 4,
374 .tuner_addr = ADDR_UNSET,
368},{ 375},{
369 .name = "Diamond DTV2000", 376 .name = "Diamond DTV2000",
370 .video_inputs = 4, 377 .video_inputs = 4,
@@ -376,6 +383,7 @@ struct tvcard bttv_tvcards[] = {
376 .audiomux = { 0, 1, 0, 1, 3}, 383 .audiomux = { 0, 1, 0, 1, 3},
377 .needs_tvaudio = 1, 384 .needs_tvaudio = 1,
378 .tuner_type = -1, 385 .tuner_type = -1,
386 .tuner_addr = ADDR_UNSET,
379},{ 387},{
380 .name = "AVerMedia TVPhone", 388 .name = "AVerMedia TVPhone",
381 .video_inputs = 3, 389 .video_inputs = 3,
@@ -388,6 +396,7 @@ struct tvcard bttv_tvcards[] = {
388 /* 0x04 for some cards ?? */ 396 /* 0x04 for some cards ?? */
389 .needs_tvaudio = 1, 397 .needs_tvaudio = 1,
390 .tuner_type = -1, 398 .tuner_type = -1,
399 .tuner_addr = ADDR_UNSET,
391 .audio_hook = avermedia_tvphone_audio, 400 .audio_hook = avermedia_tvphone_audio,
392 .has_remote = 1, 401 .has_remote = 1,
393},{ 402},{
@@ -401,6 +410,7 @@ struct tvcard bttv_tvcards[] = {
401 .audiomux = {0 }, 410 .audiomux = {0 },
402 .needs_tvaudio = 1, 411 .needs_tvaudio = 1,
403 .tuner_type = -1, 412 .tuner_type = -1,
413 .tuner_addr = ADDR_UNSET,
404},{ 414},{
405 415
406/* ---- card 0x08 ---------------------------------- */ 416/* ---- card 0x08 ---------------------------------- */
@@ -415,6 +425,7 @@ struct tvcard bttv_tvcards[] = {
415 .needs_tvaudio = 1, 425 .needs_tvaudio = 1,
416 .pll = PLL_28, 426 .pll = PLL_28,
417 .tuner_type = -1, 427 .tuner_type = -1,
428 .tuner_addr = ADDR_UNSET,
418},{ 429},{
419 .name = "IMS/IXmicro TurboTV", 430 .name = "IMS/IXmicro TurboTV",
420 .video_inputs = 3, 431 .video_inputs = 3,
@@ -427,6 +438,7 @@ struct tvcard bttv_tvcards[] = {
427 .needs_tvaudio = 0, 438 .needs_tvaudio = 0,
428 .pll = PLL_28, 439 .pll = PLL_28,
429 .tuner_type = TUNER_TEMIC_PAL, 440 .tuner_type = TUNER_TEMIC_PAL,
441 .tuner_addr = ADDR_UNSET,
430},{ 442},{
431 .name = "Hauppauge (bt878)", 443 .name = "Hauppauge (bt878)",
432 .video_inputs = 4, 444 .video_inputs = 4,
@@ -439,6 +451,7 @@ struct tvcard bttv_tvcards[] = {
439 .needs_tvaudio = 1, 451 .needs_tvaudio = 1,
440 .pll = PLL_28, 452 .pll = PLL_28,
441 .tuner_type = -1, 453 .tuner_type = -1,
454 .tuner_addr = ADDR_UNSET,
442},{ 455},{
443 .name = "MIRO PCTV pro", 456 .name = "MIRO PCTV pro",
444 .video_inputs = 3, 457 .video_inputs = 3,
@@ -450,6 +463,7 @@ struct tvcard bttv_tvcards[] = {
450 .audiomux = { 0x20001,0x10001, 0, 0,10}, 463 .audiomux = { 0x20001,0x10001, 0, 0,10},
451 .needs_tvaudio = 1, 464 .needs_tvaudio = 1,
452 .tuner_type = -1, 465 .tuner_type = -1,
466 .tuner_addr = ADDR_UNSET,
453},{ 467},{
454 468
455/* ---- card 0x0c ---------------------------------- */ 469/* ---- card 0x0c ---------------------------------- */
@@ -463,6 +477,7 @@ struct tvcard bttv_tvcards[] = {
463 .audiomux = { 13, 14, 11, 7, 0, 0}, 477 .audiomux = { 13, 14, 11, 7, 0, 0},
464 .needs_tvaudio = 1, 478 .needs_tvaudio = 1,
465 .tuner_type = -1, 479 .tuner_type = -1,
480 .tuner_addr = ADDR_UNSET,
466},{ 481},{
467 .name = "AVerMedia TVCapture 98", 482 .name = "AVerMedia TVCapture 98",
468 .video_inputs = 3, 483 .video_inputs = 3,
@@ -476,6 +491,7 @@ struct tvcard bttv_tvcards[] = {
476 .msp34xx_alt = 1, 491 .msp34xx_alt = 1,
477 .pll = PLL_28, 492 .pll = PLL_28,
478 .tuner_type = TUNER_PHILIPS_PAL, 493 .tuner_type = TUNER_PHILIPS_PAL,
494 .tuner_addr = ADDR_UNSET,
479 .audio_hook = avermedia_tv_stereo_audio, 495 .audio_hook = avermedia_tv_stereo_audio,
480},{ 496},{
481 .name = "Aimslab Video Highway Xtreme (VHX)", 497 .name = "Aimslab Video Highway Xtreme (VHX)",
@@ -489,6 +505,7 @@ struct tvcard bttv_tvcards[] = {
489 .needs_tvaudio = 1, 505 .needs_tvaudio = 1,
490 .pll = PLL_28, 506 .pll = PLL_28,
491 .tuner_type = -1, 507 .tuner_type = -1,
508 .tuner_addr = ADDR_UNSET,
492},{ 509},{
493 .name = "Zoltrix TV-Max", 510 .name = "Zoltrix TV-Max",
494 .video_inputs = 3, 511 .video_inputs = 3,
@@ -500,6 +517,7 @@ struct tvcard bttv_tvcards[] = {
500 .audiomux = {0 , 0, 1 , 0, 10}, 517 .audiomux = {0 , 0, 1 , 0, 10},
501 .needs_tvaudio = 1, 518 .needs_tvaudio = 1,
502 .tuner_type = -1, 519 .tuner_type = -1,
520 .tuner_addr = ADDR_UNSET,
503},{ 521},{
504 522
505/* ---- card 0x10 ---------------------------------- */ 523/* ---- card 0x10 ---------------------------------- */
@@ -510,7 +528,7 @@ struct tvcard bttv_tvcards[] = {
510 .svhs = 2, 528 .svhs = 2,
511 .gpiomask = 0x01fe00, 529 .gpiomask = 0x01fe00,
512 .muxsel = { 2, 3, 1, 1}, 530 .muxsel = { 2, 3, 1, 1},
513 // 2003-10-20 by "Anton A. Arapov" <arapov@mail.ru> 531 /* 2003-10-20 by "Anton A. Arapov" <arapov@mail.ru> */
514 .audiomux = { 0x001e00, 0, 0x018000, 0x014000, 0x002000, 0 }, 532 .audiomux = { 0x001e00, 0, 0x018000, 0x014000, 0x002000, 0 },
515 .needs_tvaudio = 1, 533 .needs_tvaudio = 1,
516 .pll = PLL_28, 534 .pll = PLL_28,
@@ -526,6 +544,7 @@ struct tvcard bttv_tvcards[] = {
526 .audiomux = { 0x4fa007,0xcfa007,0xcfa007,0xcfa007,0xcfa007,0xcfa007}, 544 .audiomux = { 0x4fa007,0xcfa007,0xcfa007,0xcfa007,0xcfa007,0xcfa007},
527 .needs_tvaudio = 1, 545 .needs_tvaudio = 1,
528 .tuner_type = -1, 546 .tuner_type = -1,
547 .tuner_addr = ADDR_UNSET,
529 .audio_hook = winview_audio, 548 .audio_hook = winview_audio,
530 .has_radio = 1, 549 .has_radio = 1,
531},{ 550},{
@@ -539,6 +558,7 @@ struct tvcard bttv_tvcards[] = {
539 .audiomux = {1, 0, 0, 0, 0}, 558 .audiomux = {1, 0, 0, 0, 0},
540 .needs_tvaudio = 1, 559 .needs_tvaudio = 1,
541 .tuner_type = -1, 560 .tuner_type = -1,
561 .tuner_addr = ADDR_UNSET,
542},{ 562},{
543 .name = "Lifeview FlyVideo II EZ /FlyKit LR38 Bt848 (capture only)", 563 .name = "Lifeview FlyVideo II EZ /FlyKit LR38 Bt848 (capture only)",
544 .video_inputs = 4, 564 .video_inputs = 4,
@@ -550,6 +570,7 @@ struct tvcard bttv_tvcards[] = {
550 .audiomux = { 0 }, 570 .audiomux = { 0 },
551 .no_msp34xx = 1, 571 .no_msp34xx = 1,
552 .tuner_type = -1, 572 .tuner_type = -1,
573 .tuner_addr = ADDR_UNSET,
553},{ 574},{
554 575
555/* ---- card 0x14 ---------------------------------- */ 576/* ---- card 0x14 ---------------------------------- */
@@ -560,10 +581,11 @@ struct tvcard bttv_tvcards[] = {
560 .svhs = 2, 581 .svhs = 2,
561 .muxsel = {2, 3, 1, 1}, 582 .muxsel = {2, 3, 1, 1},
562 .tuner_type = -1, 583 .tuner_type = -1,
584 .tuner_addr = ADDR_UNSET,
563},{ 585},{
564 .name = "Lifeview FlyVideo 98/ Lucky Star Image World ConferenceTV LR50", 586 .name = "Lifeview FlyVideo 98/ Lucky Star Image World ConferenceTV LR50",
565 .video_inputs = 4, 587 .video_inputs = 4,
566 .audio_inputs = 2, // tuner, line in 588 .audio_inputs = 2, /* tuner, line in */
567 .tuner = 0, 589 .tuner = 0,
568 .svhs = 2, 590 .svhs = 2,
569 .gpiomask = 0x1800, 591 .gpiomask = 0x1800,
@@ -571,6 +593,7 @@ struct tvcard bttv_tvcards[] = {
571 .audiomux = { 0, 0x800, 0x1000, 0x1000, 0x1800}, 593 .audiomux = { 0, 0x800, 0x1000, 0x1000, 0x1800},
572 .pll = PLL_28, 594 .pll = PLL_28,
573 .tuner_type = TUNER_PHILIPS_PAL_I, 595 .tuner_type = TUNER_PHILIPS_PAL_I,
596 .tuner_addr = ADDR_UNSET,
574},{ 597},{
575 .name = "Askey CPH050/ Phoebe Tv Master + FM", 598 .name = "Askey CPH050/ Phoebe Tv Master + FM",
576 .video_inputs = 3, 599 .video_inputs = 3,
@@ -583,6 +606,7 @@ struct tvcard bttv_tvcards[] = {
583 .needs_tvaudio = 1, 606 .needs_tvaudio = 1,
584 .pll = PLL_28, 607 .pll = PLL_28,
585 .tuner_type = -1, 608 .tuner_type = -1,
609 .tuner_addr = ADDR_UNSET,
586},{ 610},{
587 .name = "Modular Technology MM201/MM202/MM205/MM210/MM215 PCTV, bt878", 611 .name = "Modular Technology MM201/MM202/MM205/MM210/MM215 PCTV, bt878",
588 .video_inputs = 3, 612 .video_inputs = 3,
@@ -591,11 +615,12 @@ struct tvcard bttv_tvcards[] = {
591 .svhs = -1, 615 .svhs = -1,
592 .gpiomask = 7, 616 .gpiomask = 7,
593 .muxsel = { 2, 3, -1 }, 617 .muxsel = { 2, 3, -1 },
594 .digital_mode = DIGITAL_MODE_CAMERA, 618 .digital_mode = DIGITAL_MODE_CAMERA,
595 .audiomux = { 0, 0, 0, 0, 0 }, 619 .audiomux = { 0, 0, 0, 0, 0 },
596 .no_msp34xx = 1, 620 .no_msp34xx = 1,
597 .pll = PLL_28, 621 .pll = PLL_28,
598 .tuner_type = TUNER_ALPS_TSBB5_PAL_I, 622 .tuner_type = TUNER_ALPS_TSBB5_PAL_I,
623 .tuner_addr = ADDR_UNSET,
599},{ 624},{
600 625
601/* ---- card 0x18 ---------------------------------- */ 626/* ---- card 0x18 ---------------------------------- */
@@ -610,6 +635,7 @@ struct tvcard bttv_tvcards[] = {
610 .needs_tvaudio = 1, 635 .needs_tvaudio = 1,
611 .pll = PLL_28, 636 .pll = PLL_28,
612 .tuner_type = -1, 637 .tuner_type = -1,
638 .tuner_addr = ADDR_UNSET,
613 .has_remote = 1, 639 .has_remote = 1,
614},{ 640},{
615 .name = "Terratec TerraTV+ Version 1.0 (Bt848)/ Terra TValue Version 1.0/ Vobis TV-Boostar", 641 .name = "Terratec TerraTV+ Version 1.0 (Bt848)/ Terra TValue Version 1.0/ Vobis TV-Boostar",
@@ -622,6 +648,7 @@ struct tvcard bttv_tvcards[] = {
622 .audiomux = { 0x20000, 0x30000, 0x10000, 0, 0x40000}, 648 .audiomux = { 0x20000, 0x30000, 0x10000, 0, 0x40000},
623 .needs_tvaudio = 0, 649 .needs_tvaudio = 0,
624 .tuner_type = TUNER_PHILIPS_PAL, 650 .tuner_type = TUNER_PHILIPS_PAL,
651 .tuner_addr = ADDR_UNSET,
625 .audio_hook = terratv_audio, 652 .audio_hook = terratv_audio,
626},{ 653},{
627 .name = "Hauppauge WinCam newer (bt878)", 654 .name = "Hauppauge WinCam newer (bt878)",
@@ -634,6 +661,7 @@ struct tvcard bttv_tvcards[] = {
634 .audiomux = { 0, 1, 2, 3, 4}, 661 .audiomux = { 0, 1, 2, 3, 4},
635 .needs_tvaudio = 1, 662 .needs_tvaudio = 1,
636 .tuner_type = -1, 663 .tuner_type = -1,
664 .tuner_addr = ADDR_UNSET,
637},{ 665},{
638 .name = "Lifeview FlyVideo 98/ MAXI TV Video PCI2 LR50", 666 .name = "Lifeview FlyVideo 98/ MAXI TV Video PCI2 LR50",
639 .video_inputs = 4, 667 .video_inputs = 4,
@@ -645,6 +673,7 @@ struct tvcard bttv_tvcards[] = {
645 .audiomux = { 0, 0x800, 0x1000, 0x1000, 0x1800}, 673 .audiomux = { 0, 0x800, 0x1000, 0x1000, 0x1800},
646 .pll = PLL_28, 674 .pll = PLL_28,
647 .tuner_type = TUNER_PHILIPS_SECAM, 675 .tuner_type = TUNER_PHILIPS_SECAM,
676 .tuner_addr = ADDR_UNSET,
648},{ 677},{
649 678
650/* ---- card 0x1c ---------------------------------- */ 679/* ---- card 0x1c ---------------------------------- */
@@ -658,37 +687,38 @@ struct tvcard bttv_tvcards[] = {
658 .audiomux = { 0x20000, 0x30000, 0x10000, 0x00000, 0x40000}, 687 .audiomux = { 0x20000, 0x30000, 0x10000, 0x00000, 0x40000},
659 .needs_tvaudio = 0, 688 .needs_tvaudio = 0,
660 .tuner_type = TUNER_PHILIPS_PAL, 689 .tuner_type = TUNER_PHILIPS_PAL,
690 .tuner_addr = ADDR_UNSET,
661 .audio_hook = terratv_audio, 691 .audio_hook = terratv_audio,
662 /* GPIO wiring: 692 /* GPIO wiring:
663 External 20 pin connector (for Active Radio Upgrade board) 693 External 20 pin connector (for Active Radio Upgrade board)
664 gpio00: i2c-sda 694 gpio00: i2c-sda
665 gpio01: i2c-scl 695 gpio01: i2c-scl
666 gpio02: om5610-data 696 gpio02: om5610-data
667 gpio03: om5610-clk 697 gpio03: om5610-clk
668 gpio04: om5610-wre 698 gpio04: om5610-wre
669 gpio05: om5610-stereo 699 gpio05: om5610-stereo
670 gpio06: rds6588-davn 700 gpio06: rds6588-davn
671 gpio07: Pin 7 n.c. 701 gpio07: Pin 7 n.c.
672 gpio08: nIOW 702 gpio08: nIOW
673 gpio09+10: nIOR, nSEL ?? (bt878) 703 gpio09+10: nIOR, nSEL ?? (bt878)
674 gpio09: nIOR (bt848) 704 gpio09: nIOR (bt848)
675 gpio10: nSEL (bt848) 705 gpio10: nSEL (bt848)
676 Sound Routing: 706 Sound Routing:
677 gpio16: u2-A0 (1st 4052bt) 707 gpio16: u2-A0 (1st 4052bt)
678 gpio17: u2-A1 708 gpio17: u2-A1
679 gpio18: u2-nEN 709 gpio18: u2-nEN
680 gpio19: u4-A0 (2nd 4052) 710 gpio19: u4-A0 (2nd 4052)
681 gpio20: u4-A1 711 gpio20: u4-A1
682 u4-nEN - GND 712 u4-nEN - GND
683 Btspy: 713 Btspy:
684 00000 : Cdrom (internal audio input) 714 00000 : Cdrom (internal audio input)
685 10000 : ext. Video audio input 715 10000 : ext. Video audio input
686 20000 : TV Mono 716 20000 : TV Mono
687 a0000 : TV Mono/2 717 a0000 : TV Mono/2
688 1a0000 : TV Stereo 718 1a0000 : TV Stereo
689 30000 : Radio 719 30000 : Radio
690 40000 : Mute 720 40000 : Mute
691 */ 721*/
692 722
693},{ 723},{
694 /* Jannik Fritsch <jannik@techfak.uni-bielefeld.de> */ 724 /* Jannik Fritsch <jannik@techfak.uni-bielefeld.de> */
@@ -702,6 +732,7 @@ struct tvcard bttv_tvcards[] = {
702 .audiomux = { 0 }, 732 .audiomux = { 0 },
703 .needs_tvaudio = 1, 733 .needs_tvaudio = 1,
704 .tuner_type = -1, 734 .tuner_type = -1,
735 .tuner_addr = ADDR_UNSET,
705 .muxsel_hook = PXC200_muxsel, 736 .muxsel_hook = PXC200_muxsel,
706 737
707},{ 738},{
@@ -710,11 +741,12 @@ struct tvcard bttv_tvcards[] = {
710 .audio_inputs = 1, 741 .audio_inputs = 1,
711 .tuner = 0, 742 .tuner = 0,
712 .svhs = 2, 743 .svhs = 2,
713 .gpiomask = 0x1800, //0x8dfe00 744 .gpiomask = 0x1800, /* 0x8dfe00 */
714 .muxsel = { 2, 3, 1, 1}, 745 .muxsel = { 2, 3, 1, 1},
715 .audiomux = { 0, 0x0800, 0x1000, 0x1000, 0x1800, 0 }, 746 .audiomux = { 0, 0x0800, 0x1000, 0x1000, 0x1800, 0 },
716 .pll = PLL_28, 747 .pll = PLL_28,
717 .tuner_type = -1, 748 .tuner_type = -1,
749 .tuner_addr = ADDR_UNSET,
718},{ 750},{
719 .name = "Formac iProTV, Formac ProTV I (bt848)", 751 .name = "Formac iProTV, Formac ProTV I (bt848)",
720 .video_inputs = 4, 752 .video_inputs = 4,
@@ -726,6 +758,7 @@ struct tvcard bttv_tvcards[] = {
726 .audiomux = { 1, 0, 0, 0, 0 }, 758 .audiomux = { 1, 0, 0, 0, 0 },
727 .pll = PLL_28, 759 .pll = PLL_28,
728 .tuner_type = TUNER_PHILIPS_PAL, 760 .tuner_type = TUNER_PHILIPS_PAL,
761 .tuner_addr = ADDR_UNSET,
729},{ 762},{
730 763
731/* ---- card 0x20 ---------------------------------- */ 764/* ---- card 0x20 ---------------------------------- */
@@ -739,6 +772,7 @@ struct tvcard bttv_tvcards[] = {
739 .audiomux = { 0 }, 772 .audiomux = { 0 },
740 .needs_tvaudio = 0, 773 .needs_tvaudio = 0,
741 .tuner_type = 4, 774 .tuner_type = 4,
775 .tuner_addr = ADDR_UNSET,
742},{ 776},{
743 .name = "Terratec TerraTValue Version Bt878", 777 .name = "Terratec TerraTValue Version Bt878",
744 .video_inputs = 3, 778 .video_inputs = 3,
@@ -751,31 +785,33 @@ struct tvcard bttv_tvcards[] = {
751 .needs_tvaudio = 1, 785 .needs_tvaudio = 1,
752 .pll = PLL_28, 786 .pll = PLL_28,
753 .tuner_type = TUNER_PHILIPS_PAL, 787 .tuner_type = TUNER_PHILIPS_PAL,
788 .tuner_addr = ADDR_UNSET,
754},{ 789},{
755 .name = "Leadtek WinFast 2000/ WinFast 2000 XP", 790 .name = "Leadtek WinFast 2000/ WinFast 2000 XP",
756 .video_inputs = 4, 791 .video_inputs = 4,
757 .audio_inputs = 1, 792 .audio_inputs = 1,
758 .tuner = 0, 793 .tuner = 0,
759 .svhs = 2, 794 .svhs = 2,
760 .muxsel = { 2, 3, 1, 1, 0}, // TV, CVid, SVid, CVid over SVid connector 795 .muxsel = { 2, 3, 1, 1, 0}, /* TV, CVid, SVid, CVid over SVid connector */
761 /* Alexander Varakin <avarakin@hotmail.com> [stereo version] */ 796 /* Alexander Varakin <avarakin@hotmail.com> [stereo version] */
762 .gpiomask = 0xb33000, 797 .gpiomask = 0xb33000,
763 .audiomux = { 0x122000,0x1000,0x0000,0x620000,0x800000 }, 798 .audiomux = { 0x122000,0x1000,0x0000,0x620000,0x800000 },
764 /* Audio Routing for "WinFast 2000 XP" (no tv stereo !) 799 /* Audio Routing for "WinFast 2000 XP" (no tv stereo !)
765 gpio23 -- hef4052:nEnable (0x800000) 800 gpio23 -- hef4052:nEnable (0x800000)
766 gpio12 -- hef4052:A1 801 gpio12 -- hef4052:A1
767 gpio13 -- hef4052:A0 802 gpio13 -- hef4052:A0
768 0x0000: external audio 803 0x0000: external audio
769 0x1000: FM 804 0x1000: FM
770 0x2000: TV 805 0x2000: TV
771 0x3000: n.c. 806 0x3000: n.c.
772 Note: There exists another variant "Winfast 2000" with tv stereo !? 807 Note: There exists another variant "Winfast 2000" with tv stereo !?
773 Note: eeprom only contains FF and pci subsystem id 107d:6606 808 Note: eeprom only contains FF and pci subsystem id 107d:6606
774 */ 809 */
775 .needs_tvaudio = 0, 810 .needs_tvaudio = 0,
776 .pll = PLL_28, 811 .pll = PLL_28,
777 .has_radio = 1, 812 .has_radio = 1,
778 .tuner_type = 5, // default for now, gpio reads BFFF06 for Pal bg+dk 813 .tuner_type = 5, /* default for now, gpio reads BFFF06 for Pal bg+dk */
814 .tuner_addr = ADDR_UNSET,
779 .audio_hook = winfast2000_audio, 815 .audio_hook = winfast2000_audio,
780 .has_remote = 1, 816 .has_remote = 1,
781},{ 817},{
@@ -789,6 +825,7 @@ struct tvcard bttv_tvcards[] = {
789 .audiomux = { 0, 0x800, 0x1000, 0x1000, 0x1800}, 825 .audiomux = { 0, 0x800, 0x1000, 0x1000, 0x1800},
790 .pll = PLL_28, 826 .pll = PLL_28,
791 .tuner_type = -1, 827 .tuner_type = -1,
828 .tuner_addr = ADDR_UNSET,
792},{ 829},{
793 830
794/* ---- card 0x24 ---------------------------------- */ 831/* ---- card 0x24 ---------------------------------- */
@@ -802,6 +839,7 @@ struct tvcard bttv_tvcards[] = {
802 .audiomux = { 0, 0x800, 0x1000, 0x1000, 0x1800, 0 }, 839 .audiomux = { 0, 0x800, 0x1000, 0x1000, 0x1800, 0 },
803 .pll = PLL_28, 840 .pll = PLL_28,
804 .tuner_type = -1, 841 .tuner_type = -1,
842 .tuner_addr = ADDR_UNSET,
805 .has_radio = 1, 843 .has_radio = 1,
806},{ 844},{
807 .name = "Prolink PixelView PlayTV pro", 845 .name = "Prolink PixelView PlayTV pro",
@@ -815,6 +853,7 @@ struct tvcard bttv_tvcards[] = {
815 .no_msp34xx = 1, 853 .no_msp34xx = 1,
816 .pll = PLL_28, 854 .pll = PLL_28,
817 .tuner_type = -1, 855 .tuner_type = -1,
856 .tuner_addr = ADDR_UNSET,
818},{ 857},{
819 .name = "Askey CPH06X TView99", 858 .name = "Askey CPH06X TView99",
820 .video_inputs = 4, 859 .video_inputs = 4,
@@ -827,6 +866,7 @@ struct tvcard bttv_tvcards[] = {
827 .needs_tvaudio = 1, 866 .needs_tvaudio = 1,
828 .pll = PLL_28, 867 .pll = PLL_28,
829 .tuner_type = 1, 868 .tuner_type = 1,
869 .tuner_addr = ADDR_UNSET,
830 .has_remote = 1, 870 .has_remote = 1,
831},{ 871},{
832 .name = "Pinnacle PCTV Studio/Rave", 872 .name = "Pinnacle PCTV Studio/Rave",
@@ -840,6 +880,7 @@ struct tvcard bttv_tvcards[] = {
840 .needs_tvaudio = 0, 880 .needs_tvaudio = 0,
841 .pll = PLL_28, 881 .pll = PLL_28,
842 .tuner_type = -1, 882 .tuner_type = -1,
883 .tuner_addr = ADDR_UNSET,
843},{ 884},{
844 885
845/* ---- card 0x28 ---------------------------------- */ 886/* ---- card 0x28 ---------------------------------- */
@@ -854,6 +895,7 @@ struct tvcard bttv_tvcards[] = {
854 .no_msp34xx = 1, 895 .no_msp34xx = 1,
855 .needs_tvaudio = 1, 896 .needs_tvaudio = 1,
856 .tuner_type = TUNER_PHILIPS_NTSC, 897 .tuner_type = TUNER_PHILIPS_NTSC,
898 .tuner_addr = ADDR_UNSET,
857 .pll = PLL_28, 899 .pll = PLL_28,
858 .has_radio = 1, 900 .has_radio = 1,
859},{ 901},{
@@ -868,6 +910,7 @@ struct tvcard bttv_tvcards[] = {
868 .needs_tvaudio = 1, 910 .needs_tvaudio = 1,
869 .pll = PLL_28, 911 .pll = PLL_28,
870 .tuner_type = -1, 912 .tuner_type = -1,
913 .tuner_addr = ADDR_UNSET,
871 .has_radio = 1, 914 .has_radio = 1,
872 .audio_hook = avermedia_tvphone_audio, 915 .audio_hook = avermedia_tvphone_audio,
873},{ 916},{
@@ -883,6 +926,7 @@ struct tvcard bttv_tvcards[] = {
883 .no_msp34xx = 1, 926 .no_msp34xx = 1,
884 .pll = PLL_28, 927 .pll = PLL_28,
885 .tuner_type = 1, 928 .tuner_type = 1,
929 .tuner_addr = ADDR_UNSET,
886},{ 930},{
887 .name = "Little OnAir TV", 931 .name = "Little OnAir TV",
888 .video_inputs = 3, 932 .video_inputs = 3,
@@ -894,6 +938,7 @@ struct tvcard bttv_tvcards[] = {
894 .audiomux = {0xff9ff6, 0xff9ff6, 0xff1ff7, 0, 0xff3ffc}, 938 .audiomux = {0xff9ff6, 0xff9ff6, 0xff1ff7, 0, 0xff3ffc},
895 .no_msp34xx = 1, 939 .no_msp34xx = 1,
896 .tuner_type = -1, 940 .tuner_type = -1,
941 .tuner_addr = ADDR_UNSET,
897},{ 942},{
898 943
899/* ---- card 0x2c ---------------------------------- */ 944/* ---- card 0x2c ---------------------------------- */
@@ -908,6 +953,7 @@ struct tvcard bttv_tvcards[] = {
908 .no_msp34xx = 1, 953 .no_msp34xx = 1,
909 .pll = PLL_NONE, 954 .pll = PLL_NONE,
910 .tuner_type = -1, 955 .tuner_type = -1,
956 .tuner_addr = ADDR_UNSET,
911},{ 957},{
912 .name = "MATRIX-Vision MV-Delta 2", 958 .name = "MATRIX-Vision MV-Delta 2",
913 .video_inputs = 5, 959 .video_inputs = 5,
@@ -920,6 +966,7 @@ struct tvcard bttv_tvcards[] = {
920 .no_msp34xx = 1, 966 .no_msp34xx = 1,
921 .pll = PLL_28, 967 .pll = PLL_28,
922 .tuner_type = -1, 968 .tuner_type = -1,
969 .tuner_addr = ADDR_UNSET,
923},{ 970},{
924 .name = "Zoltrix Genie TV/FM", 971 .name = "Zoltrix Genie TV/FM",
925 .video_inputs = 3, 972 .video_inputs = 3,
@@ -932,6 +979,7 @@ struct tvcard bttv_tvcards[] = {
932 .no_msp34xx = 1, 979 .no_msp34xx = 1,
933 .pll = PLL_28, 980 .pll = PLL_28,
934 .tuner_type = 21, 981 .tuner_type = 21,
982 .tuner_addr = ADDR_UNSET,
935},{ 983},{
936 .name = "Terratec TV/Radio+", 984 .name = "Terratec TV/Radio+",
937 .video_inputs = 3, 985 .video_inputs = 3,
@@ -945,6 +993,7 @@ struct tvcard bttv_tvcards[] = {
945 .no_msp34xx = 1, 993 .no_msp34xx = 1,
946 .pll = PLL_35, 994 .pll = PLL_35,
947 .tuner_type = 1, 995 .tuner_type = 1,
996 .tuner_addr = ADDR_UNSET,
948 .has_radio = 1, 997 .has_radio = 1,
949},{ 998},{
950 999
@@ -960,6 +1009,7 @@ struct tvcard bttv_tvcards[] = {
960 .needs_tvaudio = 1, 1009 .needs_tvaudio = 1,
961 .pll = PLL_28, 1010 .pll = PLL_28,
962 .tuner_type = -1, 1011 .tuner_type = -1,
1012 .tuner_addr = ADDR_UNSET,
963},{ 1013},{
964 .name = "IODATA GV-BCTV3/PCI", 1014 .name = "IODATA GV-BCTV3/PCI",
965 .video_inputs = 3, 1015 .video_inputs = 3,
@@ -972,6 +1022,7 @@ struct tvcard bttv_tvcards[] = {
972 .no_msp34xx = 1, 1022 .no_msp34xx = 1,
973 .pll = PLL_28, 1023 .pll = PLL_28,
974 .tuner_type = TUNER_ALPS_TSHC6_NTSC, 1024 .tuner_type = TUNER_ALPS_TSHC6_NTSC,
1025 .tuner_addr = ADDR_UNSET,
975 .audio_hook = gvbctv3pci_audio, 1026 .audio_hook = gvbctv3pci_audio,
976},{ 1027},{
977 .name = "Prolink PV-BT878P+4E / PixelView PlayTV PAK / Lenco MXTV-9578 CP", 1028 .name = "Prolink PV-BT878P+4E / PixelView PlayTV PAK / Lenco MXTV-9578 CP",
@@ -986,6 +1037,7 @@ struct tvcard bttv_tvcards[] = {
986 .no_msp34xx = 1, 1037 .no_msp34xx = 1,
987 .pll = PLL_28, 1038 .pll = PLL_28,
988 .tuner_type = TUNER_PHILIPS_PAL_I, 1039 .tuner_type = TUNER_PHILIPS_PAL_I,
1040 .tuner_addr = ADDR_UNSET,
989 .has_remote = 1, 1041 .has_remote = 1,
990 /* GPIO wiring: (different from Rev.4C !) 1042 /* GPIO wiring: (different from Rev.4C !)
991 GPIO17: U4.A0 (first hef4052bt) 1043 GPIO17: U4.A0 (first hef4052bt)
@@ -994,8 +1046,8 @@ struct tvcard bttv_tvcards[] = {
994 GPIO21: U4.nEN 1046 GPIO21: U4.nEN
995 GPIO22: BT832 Reset Line 1047 GPIO22: BT832 Reset Line
996 GPIO23: A5,A0, U5,nEN 1048 GPIO23: A5,A0, U5,nEN
997 Note: At i2c=0x8a is a Bt832 chip, which changes to 0x88 after being reset via GPIO22 1049 Note: At i2c=0x8a is a Bt832 chip, which changes to 0x88 after being reset via GPIO22
998 */ 1050 */
999},{ 1051},{
1000 .name = "Eagle Wireless Capricorn2 (bt878A)", 1052 .name = "Eagle Wireless Capricorn2 (bt878A)",
1001 .video_inputs = 4, 1053 .video_inputs = 4,
@@ -1007,6 +1059,7 @@ struct tvcard bttv_tvcards[] = {
1007 .audiomux = { 0, 1, 2, 3, 4}, 1059 .audiomux = { 0, 1, 2, 3, 4},
1008 .pll = PLL_28, 1060 .pll = PLL_28,
1009 .tuner_type = -1 /* TUNER_ALPS_TMDH2_NTSC */, 1061 .tuner_type = -1 /* TUNER_ALPS_TMDH2_NTSC */,
1062 .tuner_addr = ADDR_UNSET,
1010},{ 1063},{
1011 1064
1012/* ---- card 0x34 ---------------------------------- */ 1065/* ---- card 0x34 ---------------------------------- */
@@ -1020,20 +1073,21 @@ struct tvcard bttv_tvcards[] = {
1020 .muxsel = { 2, 3, 1, 1}, 1073 .muxsel = { 2, 3, 1, 1},
1021 .audiomux = { 1, 0xd0001, 0, 0, 10}, 1074 .audiomux = { 1, 0xd0001, 0, 0, 10},
1022 /* sound path (5 sources): 1075 /* sound path (5 sources):
1023 MUX1 (mask 0x03), Enable Pin 0x08 (0=enable, 1=disable) 1076 MUX1 (mask 0x03), Enable Pin 0x08 (0=enable, 1=disable)
1024 0= ext. Audio IN 1077 0= ext. Audio IN
1025 1= from MUX2 1078 1= from MUX2
1026 2= Mono TV sound from Tuner 1079 2= Mono TV sound from Tuner
1027 3= not connected 1080 3= not connected
1028 MUX2 (mask 0x30000): 1081 MUX2 (mask 0x30000):
1029 0,2,3= from MSP34xx 1082 0,2,3= from MSP34xx
1030 1= FM stereo Radio from Tuner */ 1083 1= FM stereo Radio from Tuner */
1031 .needs_tvaudio = 0, 1084 .needs_tvaudio = 0,
1032 .pll = PLL_28, 1085 .pll = PLL_28,
1033 .tuner_type = -1, 1086 .tuner_type = -1,
1087 .tuner_addr = ADDR_UNSET,
1034},{ 1088},{
1035 /* Claas Langbehn <claas@bigfoot.com>, 1089 /* Claas Langbehn <claas@bigfoot.com>,
1036 Sven Grothklags <sven@upb.de> */ 1090 Sven Grothklags <sven@upb.de> */
1037 .name = "Typhoon TView RDS + FM Stereo / KNC1 TV Station RDS", 1091 .name = "Typhoon TView RDS + FM Stereo / KNC1 TV Station RDS",
1038 .video_inputs = 4, 1092 .video_inputs = 4,
1039 .audio_inputs = 3, 1093 .audio_inputs = 3,
@@ -1045,10 +1099,11 @@ struct tvcard bttv_tvcards[] = {
1045 .needs_tvaudio = 1, 1099 .needs_tvaudio = 1,
1046 .pll = PLL_28, 1100 .pll = PLL_28,
1047 .tuner_type = TUNER_PHILIPS_PAL, 1101 .tuner_type = TUNER_PHILIPS_PAL,
1102 .tuner_addr = ADDR_UNSET,
1048 .has_radio = 1, 1103 .has_radio = 1,
1049},{ 1104},{
1050 /* Tim Röstermundt <rosterm@uni-muenster.de> 1105 /* Tim Röstermundt <rosterm@uni-muenster.de>
1051 in de.comp.os.unix.linux.hardware: 1106 in de.comp.os.unix.linux.hardware:
1052 options bttv card=0 pll=1 radio=1 gpiomask=0x18e0 1107 options bttv card=0 pll=1 radio=1 gpiomask=0x18e0
1053 audiomux=0x44c71f,0x44d71f,0,0x44d71f,0x44dfff 1108 audiomux=0x44c71f,0x44d71f,0,0x44d71f,0x44dfff
1054 options tuner type=5 */ 1109 options tuner type=5 */
@@ -1060,15 +1115,16 @@ struct tvcard bttv_tvcards[] = {
1060 .gpiomask = 0x18e0, 1115 .gpiomask = 0x18e0,
1061 .muxsel = { 2, 3, 1, 1}, 1116 .muxsel = { 2, 3, 1, 1},
1062 .audiomux = { 0x0000,0x0800,0x1000,0x1000,0x18e0 }, 1117 .audiomux = { 0x0000,0x0800,0x1000,0x1000,0x18e0 },
1063 /* For cards with tda9820/tda9821: 1118 /* For cards with tda9820/tda9821:
1064 0x0000: Tuner normal stereo 1119 0x0000: Tuner normal stereo
1065 0x0080: Tuner A2 SAP (second audio program = Zweikanalton) 1120 0x0080: Tuner A2 SAP (second audio program = Zweikanalton)
1066 0x0880: Tuner A2 stereo */ 1121 0x0880: Tuner A2 stereo */
1067 .pll = PLL_28, 1122 .pll = PLL_28,
1068 .tuner_type = -1, 1123 .tuner_type = -1,
1124 .tuner_addr = ADDR_UNSET,
1069},{ 1125},{
1070 /* Miguel Angel Alvarez <maacruz@navegalia.com> 1126 /* Miguel Angel Alvarez <maacruz@navegalia.com>
1071 old Easy TV BT848 version (model CPH031) */ 1127 old Easy TV BT848 version (model CPH031) */
1072 .name = "Askey CPH031/ BESTBUY Easy TV", 1128 .name = "Askey CPH031/ BESTBUY Easy TV",
1073 .video_inputs = 4, 1129 .video_inputs = 4,
1074 .audio_inputs = 1, 1130 .audio_inputs = 1,
@@ -1080,6 +1136,7 @@ struct tvcard bttv_tvcards[] = {
1080 .needs_tvaudio = 0, 1136 .needs_tvaudio = 0,
1081 .pll = PLL_28, 1137 .pll = PLL_28,
1082 .tuner_type = TUNER_TEMIC_PAL, 1138 .tuner_type = TUNER_TEMIC_PAL,
1139 .tuner_addr = ADDR_UNSET,
1083},{ 1140},{
1084 1141
1085/* ---- card 0x38 ---------------------------------- */ 1142/* ---- card 0x38 ---------------------------------- */
@@ -1094,10 +1151,11 @@ struct tvcard bttv_tvcards[] = {
1094 .audiomux = { 0, 0x800, 0x1000, 0x1000, 0x1800, 0 }, 1151 .audiomux = { 0, 0x800, 0x1000, 0x1000, 0x1800, 0 },
1095 .pll = PLL_28, 1152 .pll = PLL_28,
1096 .tuner_type = 5, 1153 .tuner_type = 5,
1154 .tuner_addr = ADDR_UNSET,
1097},{ 1155},{
1098 /* This is the ultimate cheapo capture card 1156 /* This is the ultimate cheapo capture card
1099 * just a BT848A on a small PCB! 1157 * just a BT848A on a small PCB!
1100 * Steve Hosgood <steve@equiinet.com> */ 1158 * Steve Hosgood <steve@equiinet.com> */
1101 .name = "GrandTec 'Grand Video Capture' (Bt848)", 1159 .name = "GrandTec 'Grand Video Capture' (Bt848)",
1102 .video_inputs = 2, 1160 .video_inputs = 2,
1103 .audio_inputs = 0, 1161 .audio_inputs = 0,
@@ -1110,19 +1168,21 @@ struct tvcard bttv_tvcards[] = {
1110 .no_msp34xx = 1, 1168 .no_msp34xx = 1,
1111 .pll = PLL_35, 1169 .pll = PLL_35,
1112 .tuner_type = -1, 1170 .tuner_type = -1,
1171 .tuner_addr = ADDR_UNSET,
1113},{ 1172},{
1114 /* Daniel Herrington <daniel.herrington@home.com> */ 1173 /* Daniel Herrington <daniel.herrington@home.com> */
1115 .name = "Askey CPH060/ Phoebe TV Master Only (No FM)", 1174 .name = "Askey CPH060/ Phoebe TV Master Only (No FM)",
1116 .video_inputs = 3, 1175 .video_inputs = 3,
1117 .audio_inputs = 1, 1176 .audio_inputs = 1,
1118 .tuner = 0, 1177 .tuner = 0,
1119 .svhs = 2, 1178 .svhs = 2,
1120 .gpiomask = 0xe00, 1179 .gpiomask = 0xe00,
1121 .muxsel = { 2, 3, 1, 1}, 1180 .muxsel = { 2, 3, 1, 1},
1122 .audiomux = { 0x400, 0x400, 0x400, 0x400, 0x800, 0x400 }, 1181 .audiomux = { 0x400, 0x400, 0x400, 0x400, 0x800, 0x400 },
1123 .needs_tvaudio = 1, 1182 .needs_tvaudio = 1,
1124 .pll = PLL_28, 1183 .pll = PLL_28,
1125 .tuner_type = TUNER_TEMIC_4036FY5_NTSC, 1184 .tuner_type = TUNER_TEMIC_4036FY5_NTSC,
1185 .tuner_addr = ADDR_UNSET,
1126},{ 1186},{
1127 /* Matti Mottus <mottus@physic.ut.ee> */ 1187 /* Matti Mottus <mottus@physic.ut.ee> */
1128 .name = "Askey CPH03x TV Capturer", 1188 .name = "Askey CPH03x TV Capturer",
@@ -1130,11 +1190,12 @@ struct tvcard bttv_tvcards[] = {
1130 .audio_inputs = 1, 1190 .audio_inputs = 1,
1131 .tuner = 0, 1191 .tuner = 0,
1132 .svhs = 2, 1192 .svhs = 2,
1133 .gpiomask = 0x03000F, 1193 .gpiomask = 0x03000F,
1134 .muxsel = { 2, 3, 1, 0}, 1194 .muxsel = { 2, 3, 1, 0},
1135 .audiomux = { 2,0,0,0,1 }, 1195 .audiomux = { 2,0,0,0,1 },
1136 .pll = PLL_28, 1196 .pll = PLL_28,
1137 .tuner_type = 0, 1197 .tuner_type = 0,
1198 .tuner_addr = ADDR_UNSET,
1138},{ 1199},{
1139 1200
1140/* ---- card 0x3c ---------------------------------- */ 1201/* ---- card 0x3c ---------------------------------- */
@@ -1149,7 +1210,7 @@ struct tvcard bttv_tvcards[] = {
1149 .audiomux = { 2, 0, 0, 1, 8}, 1210 .audiomux = { 2, 0, 0, 1, 8},
1150 .pll = PLL_35, 1211 .pll = PLL_35,
1151 .tuner_type = TUNER_TEMIC_PAL, 1212 .tuner_type = TUNER_TEMIC_PAL,
1152 1213 .tuner_addr = ADDR_UNSET,
1153},{ 1214},{
1154 /* Adrian Cox <adrian@humboldt.co.uk */ 1215 /* Adrian Cox <adrian@humboldt.co.uk */
1155 .name = "AG Electronics GMV1", 1216 .name = "AG Electronics GMV1",
@@ -1164,10 +1225,11 @@ struct tvcard bttv_tvcards[] = {
1164 .needs_tvaudio = 0, 1225 .needs_tvaudio = 0,
1165 .pll = PLL_28, 1226 .pll = PLL_28,
1166 .tuner_type = -1, 1227 .tuner_type = -1,
1228 .tuner_addr = ADDR_UNSET,
1167},{ 1229},{
1168 /* Miguel Angel Alvarez <maacruz@navegalia.com> 1230 /* Miguel Angel Alvarez <maacruz@navegalia.com>
1169 new Easy TV BT878 version (model CPH061) 1231 new Easy TV BT878 version (model CPH061)
1170 special thanks to Informatica Mieres for providing the card */ 1232 special thanks to Informatica Mieres for providing the card */
1171 .name = "Askey CPH061/ BESTBUY Easy TV (bt878)", 1233 .name = "Askey CPH061/ BESTBUY Easy TV (bt878)",
1172 .video_inputs = 3, 1234 .video_inputs = 3,
1173 .audio_inputs = 2, 1235 .audio_inputs = 2,
@@ -1179,6 +1241,7 @@ struct tvcard bttv_tvcards[] = {
1179 .needs_tvaudio = 0, 1241 .needs_tvaudio = 0,
1180 .pll = PLL_28, 1242 .pll = PLL_28,
1181 .tuner_type = TUNER_PHILIPS_PAL, 1243 .tuner_type = TUNER_PHILIPS_PAL,
1244 .tuner_addr = ADDR_UNSET,
1182},{ 1245},{
1183 /* Lukas Gebauer <geby@volny.cz> */ 1246 /* Lukas Gebauer <geby@volny.cz> */
1184 .name = "ATI TV-Wonder", 1247 .name = "ATI TV-Wonder",
@@ -1191,6 +1254,7 @@ struct tvcard bttv_tvcards[] = {
1191 .audiomux = { 0xbffe, 0, 0xbfff, 0, 0xbffe}, 1254 .audiomux = { 0xbffe, 0, 0xbfff, 0, 0xbffe},
1192 .pll = PLL_28, 1255 .pll = PLL_28,
1193 .tuner_type = TUNER_TEMIC_4006FN5_MULTI_PAL, 1256 .tuner_type = TUNER_TEMIC_4006FN5_MULTI_PAL,
1257 .tuner_addr = ADDR_UNSET,
1194},{ 1258},{
1195 1259
1196/* ---- card 0x40 ---------------------------------- */ 1260/* ---- card 0x40 ---------------------------------- */
@@ -1206,6 +1270,7 @@ struct tvcard bttv_tvcards[] = {
1206 .no_msp34xx = 1, 1270 .no_msp34xx = 1,
1207 .pll = PLL_28, 1271 .pll = PLL_28,
1208 .tuner_type = TUNER_TEMIC_4006FN5_MULTI_PAL, 1272 .tuner_type = TUNER_TEMIC_4006FN5_MULTI_PAL,
1273 .tuner_addr = ADDR_UNSET,
1209},{ 1274},{
1210 /* DeeJay <deejay@westel900.net (2000S) */ 1275 /* DeeJay <deejay@westel900.net (2000S) */
1211 .name = "Lifeview FlyVideo 2000S LR90", 1276 .name = "Lifeview FlyVideo 2000S LR90",
@@ -1216,7 +1281,7 @@ struct tvcard bttv_tvcards[] = {
1216 .gpiomask = 0x18e0, 1281 .gpiomask = 0x18e0,
1217 .muxsel = { 2, 3, 0, 1}, 1282 .muxsel = { 2, 3, 0, 1},
1218 /* Radio changed from 1e80 to 0x800 to make 1283 /* Radio changed from 1e80 to 0x800 to make
1219 FlyVideo2000S in .hu happy (gm)*/ 1284 FlyVideo2000S in .hu happy (gm)*/
1220 /* -dk-???: set mute=0x1800 for tda9874h daughterboard */ 1285 /* -dk-???: set mute=0x1800 for tda9874h daughterboard */
1221 .audiomux = { 0x0000,0x0800,0x1000,0x1000,0x1800, 0x1080 }, 1286 .audiomux = { 0x0000,0x0800,0x1000,0x1000,0x1800, 0x1080 },
1222 .audio_hook = fv2000s_audio, 1287 .audio_hook = fv2000s_audio,
@@ -1225,6 +1290,7 @@ struct tvcard bttv_tvcards[] = {
1225 .needs_tvaudio = 1, 1290 .needs_tvaudio = 1,
1226 .pll = PLL_28, 1291 .pll = PLL_28,
1227 .tuner_type = 5, 1292 .tuner_type = 5,
1293 .tuner_addr = ADDR_UNSET,
1228},{ 1294},{
1229 .name = "Terratec TValueRadio", 1295 .name = "Terratec TValueRadio",
1230 .video_inputs = 3, 1296 .video_inputs = 3,
@@ -1237,6 +1303,7 @@ struct tvcard bttv_tvcards[] = {
1237 .needs_tvaudio = 1, 1303 .needs_tvaudio = 1,
1238 .pll = PLL_28, 1304 .pll = PLL_28,
1239 .tuner_type = TUNER_PHILIPS_PAL, 1305 .tuner_type = TUNER_PHILIPS_PAL,
1306 .tuner_addr = ADDR_UNSET,
1240 .has_radio = 1, 1307 .has_radio = 1,
1241},{ 1308},{
1242 /* TANAKA Kei <peg00625@nifty.com> */ 1309 /* TANAKA Kei <peg00625@nifty.com> */
@@ -1251,25 +1318,27 @@ struct tvcard bttv_tvcards[] = {
1251 .no_msp34xx = 1, 1318 .no_msp34xx = 1,
1252 .pll = PLL_28, 1319 .pll = PLL_28,
1253 .tuner_type = TUNER_SHARP_2U5JF5540_NTSC, 1320 .tuner_type = TUNER_SHARP_2U5JF5540_NTSC,
1321 .tuner_addr = ADDR_UNSET,
1254 .audio_hook = gvbctv3pci_audio, 1322 .audio_hook = gvbctv3pci_audio,
1255},{ 1323},{
1256 1324
1257/* ---- card 0x44 ---------------------------------- */ 1325/* ---- card 0x44 ---------------------------------- */
1258 .name = "3Dfx VoodooTV FM (Euro), VoodooTV 200 (USA)", 1326 .name = "3Dfx VoodooTV FM (Euro), VoodooTV 200 (USA)",
1259 // try "insmod msp3400 simple=0" if you have 1327 /* try "insmod msp3400 simple=0" if you have
1260 // sound problems with this card. 1328 * sound problems with this card. */
1261 .video_inputs = 4, 1329 .video_inputs = 4,
1262 .audio_inputs = 1, 1330 .audio_inputs = 1,
1263 .tuner = 0, 1331 .tuner = 0,
1264 .svhs = -1, 1332 .svhs = -1,
1265 .gpiomask = 0x4f8a00, 1333 .gpiomask = 0x4f8a00,
1266 // 0x100000: 1=MSP enabled (0=disable again) 1334 /* 0x100000: 1=MSP enabled (0=disable again)
1267 // 0x010000: Connected to "S0" on tda9880 (0=Pal/BG, 1=NTSC) 1335 * 0x010000: Connected to "S0" on tda9880 (0=Pal/BG, 1=NTSC) */
1268 .audiomux = {0x947fff, 0x987fff,0x947fff,0x947fff, 0x947fff}, 1336 .audiomux = {0x947fff, 0x987fff,0x947fff,0x947fff, 0x947fff},
1269 // tvtuner, radio, external,internal, mute, stereo 1337 /* tvtuner, radio, external,internal, mute, stereo
1270 /* tuner, Composit, SVid, Composit-on-Svid-adapter*/ 1338 * tuner, Composit, SVid, Composit-on-Svid-adapter */
1271 .muxsel = { 2, 3 ,0 ,1}, 1339 .muxsel = { 2, 3 ,0 ,1},
1272 .tuner_type = TUNER_MT2032, 1340 .tuner_type = TUNER_MT2032,
1341 .tuner_addr = ADDR_UNSET,
1273 .pll = PLL_28, 1342 .pll = PLL_28,
1274 .has_radio = 1, 1343 .has_radio = 1,
1275},{ 1344},{
@@ -1279,22 +1348,24 @@ struct tvcard bttv_tvcards[] = {
1279 .audio_inputs = 0, 1348 .audio_inputs = 0,
1280 .tuner = -1, 1349 .tuner = -1,
1281 .tuner_type = -1, 1350 .tuner_type = -1,
1351 .tuner_addr = ADDR_UNSET,
1282 .pll = PLL_28, 1352 .pll = PLL_28,
1283 .muxsel = { 2 }, 1353 .muxsel = { 2 },
1284 .gpiomask = 0 1354 .gpiomask = 0
1285},{ 1355},{
1286 /* Tomasz Pyra <hellfire@sedez.iq.pl> */ 1356 /* Tomasz Pyra <hellfire@sedez.iq.pl> */
1287 .name = "Prolink Pixelview PV-BT878P+ (Rev.4C,8E)", 1357 .name = "Prolink Pixelview PV-BT878P+ (Rev.4C,8E)",
1288 .video_inputs = 3, 1358 .video_inputs = 3,
1289 .audio_inputs = 4, 1359 .audio_inputs = 4,
1290 .tuner = 0, 1360 .tuner = 0,
1291 .svhs = 2, 1361 .svhs = 2,
1292 .gpiomask = 15, 1362 .gpiomask = 15,
1293 .muxsel = { 2, 3, 1, 1}, 1363 .muxsel = { 2, 3, 1, 1},
1294 .audiomux = { 0, 0, 11, 7, 13, 0}, // TV and Radio with same GPIO ! 1364 .audiomux = { 0, 0, 11, 7, 13, 0}, /* TV and Radio with same GPIO ! */
1295 .needs_tvaudio = 1, 1365 .needs_tvaudio = 1,
1296 .pll = PLL_28, 1366 .pll = PLL_28,
1297 .tuner_type = 25, 1367 .tuner_type = 25,
1368 .tuner_addr = ADDR_UNSET,
1298 .has_remote = 1, 1369 .has_remote = 1,
1299 /* GPIO wiring: 1370 /* GPIO wiring:
1300 GPIO0: U4.A0 (hef4052bt) 1371 GPIO0: U4.A0 (hef4052bt)
@@ -1302,16 +1373,18 @@ struct tvcard bttv_tvcards[] = {
1302 GPIO2: U4.A1 (second hef4052bt) 1373 GPIO2: U4.A1 (second hef4052bt)
1303 GPIO3: U4.nEN, U5.A0, A5.nEN 1374 GPIO3: U4.nEN, U5.A0, A5.nEN
1304 GPIO8-15: vrd866b ? 1375 GPIO8-15: vrd866b ?
1305 */ 1376 */
1306},{ 1377},{
1307 .name = "Lifeview FlyVideo 98EZ (capture only) LR51", 1378 .name = "Lifeview FlyVideo 98EZ (capture only) LR51",
1308 .video_inputs = 4, 1379 .video_inputs = 4,
1309 .audio_inputs = 0, 1380 .audio_inputs = 0,
1310 .tuner = -1, 1381 .tuner = -1,
1311 .svhs = 2, 1382 .svhs = 2,
1312 .muxsel = { 2, 3, 1, 1}, // AV1, AV2, SVHS, CVid adapter on SVHS 1383 .muxsel = { 2, 3, 1, 1}, /* AV1, AV2, SVHS, CVid adapter on SVHS */
1313 .pll = PLL_28, 1384 .pll = PLL_28,
1314 .no_msp34xx = 1, 1385 .no_msp34xx = 1,
1386 .tuner_type = UNSET,
1387 .tuner_addr = ADDR_UNSET,
1315},{ 1388},{
1316 1389
1317/* ---- card 0x48 ---------------------------------- */ 1390/* ---- card 0x48 ---------------------------------- */
@@ -1329,8 +1402,9 @@ struct tvcard bttv_tvcards[] = {
1329 .no_tda9875 = 1, 1402 .no_tda9875 = 1,
1330 .pll = PLL_28, 1403 .pll = PLL_28,
1331 .tuner_type = 5, 1404 .tuner_type = 5,
1332 .audio_hook = pvbt878p9b_audio, // Note: not all cards have stereo 1405 .tuner_addr = ADDR_UNSET,
1333 .has_radio = 1, // Note: not all cards have radio 1406 .audio_hook = pvbt878p9b_audio, /* Note: not all cards have stereo */
1407 .has_radio = 1, /* Note: not all cards have radio */
1334 .has_remote = 1, 1408 .has_remote = 1,
1335 /* GPIO wiring: 1409 /* GPIO wiring:
1336 GPIO0: A0 hef4052 1410 GPIO0: A0 hef4052
@@ -1338,7 +1412,7 @@ struct tvcard bttv_tvcards[] = {
1338 GPIO3: nEN hef4052 1412 GPIO3: nEN hef4052
1339 GPIO8-15: vrd866b 1413 GPIO8-15: vrd866b
1340 GPIO20,22,23: R30,R29,R28 1414 GPIO20,22,23: R30,R29,R28
1341 */ 1415 */
1342},{ 1416},{
1343 /* Clay Kunz <ckunz@mail.arc.nasa.gov> */ 1417 /* Clay Kunz <ckunz@mail.arc.nasa.gov> */
1344 /* you must jumper JP5 for the card to work */ 1418 /* you must jumper JP5 for the card to work */
@@ -1352,6 +1426,7 @@ struct tvcard bttv_tvcards[] = {
1352 .audiomux = { 0 }, 1426 .audiomux = { 0 },
1353 .needs_tvaudio = 0, 1427 .needs_tvaudio = 0,
1354 .tuner_type = -1, 1428 .tuner_type = -1,
1429 .tuner_addr = ADDR_UNSET,
1355},{ 1430},{
1356 /* Miguel Freitas <miguel@cetuc.puc-rio.br> */ 1431 /* Miguel Freitas <miguel@cetuc.puc-rio.br> */
1357 .name = "RemoteVision MX (RV605)", 1432 .name = "RemoteVision MX (RV605)",
@@ -1362,71 +1437,78 @@ struct tvcard bttv_tvcards[] = {
1362 .gpiomask = 0x00, 1437 .gpiomask = 0x00,
1363 .gpiomask2 = 0x07ff, 1438 .gpiomask2 = 0x07ff,
1364 .muxsel = { 0x33, 0x13, 0x23, 0x43, 0xf3, 0x73, 0xe3, 0x03, 1439 .muxsel = { 0x33, 0x13, 0x23, 0x43, 0xf3, 0x73, 0xe3, 0x03,
1365 0xd3, 0xb3, 0xc3, 0x63, 0x93, 0x53, 0x83, 0xa3 }, 1440 0xd3, 0xb3, 0xc3, 0x63, 0x93, 0x53, 0x83, 0xa3 },
1366 .no_msp34xx = 1, 1441 .no_msp34xx = 1,
1367 .no_tda9875 = 1, 1442 .no_tda9875 = 1,
1368 .tuner_type = -1, 1443 .tuner_type = -1,
1444 .tuner_addr = ADDR_UNSET,
1369 .muxsel_hook = rv605_muxsel, 1445 .muxsel_hook = rv605_muxsel,
1370},{ 1446},{
1371 .name = "Powercolor MTV878/ MTV878R/ MTV878F", 1447 .name = "Powercolor MTV878/ MTV878R/ MTV878F",
1372 .video_inputs = 3, 1448 .video_inputs = 3,
1373 .audio_inputs = 2, 1449 .audio_inputs = 2,
1374 .tuner = 0, 1450 .tuner = 0,
1375 .svhs = 2, 1451 .svhs = 2,
1376 .gpiomask = 0x1C800F, // Bit0-2: Audio select, 8-12:remote control 14:remote valid 15:remote reset 1452 .gpiomask = 0x1C800F, /* Bit0-2: Audio select, 8-12:remote control 14:remote valid 15:remote reset */
1377 .muxsel = { 2, 1, 1, }, 1453 .muxsel = { 2, 1, 1, },
1378 .audiomux = { 0, 1, 2, 2, 4 }, 1454 .audiomux = { 0, 1, 2, 2, 4 },
1379 .needs_tvaudio = 0, 1455 .needs_tvaudio = 0,
1380 .tuner_type = TUNER_PHILIPS_PAL, 1456 .tuner_type = TUNER_PHILIPS_PAL,
1457 .tuner_addr = ADDR_UNSET,
1381 .pll = PLL_28, 1458 .pll = PLL_28,
1382 .has_radio = 1, 1459 .has_radio = 1,
1383},{ 1460},{
1384 1461
1385/* ---- card 0x4c ---------------------------------- */ 1462/* ---- card 0x4c ---------------------------------- */
1386 /* Masaki Suzuki <masaki@btree.org> */ 1463 /* Masaki Suzuki <masaki@btree.org> */
1387 .name = "Canopus WinDVR PCI (COMPAQ Presario 3524JP, 5112JP)", 1464 .name = "Canopus WinDVR PCI (COMPAQ Presario 3524JP, 5112JP)",
1388 .video_inputs = 3, 1465 .video_inputs = 3,
1389 .audio_inputs = 1, 1466 .audio_inputs = 1,
1390 .tuner = 0, 1467 .tuner = 0,
1391 .svhs = 2, 1468 .svhs = 2,
1392 .gpiomask = 0x140007, 1469 .gpiomask = 0x140007,
1393 .muxsel = { 2, 3, 1, 1 }, 1470 .muxsel = { 2, 3, 1, 1 },
1394 .audiomux = { 0, 1, 2, 3, 4, 0 }, 1471 .audiomux = { 0, 1, 2, 3, 4, 0 },
1395 .tuner_type = TUNER_PHILIPS_NTSC, 1472 .tuner_type = TUNER_PHILIPS_NTSC,
1396 .audio_hook = windvr_audio, 1473 .tuner_addr = ADDR_UNSET,
1397},{ 1474 .audio_hook = windvr_audio,
1398 .name = "GrandTec Multi Capture Card (Bt878)", 1475},{
1399 .video_inputs = 4, 1476 .name = "GrandTec Multi Capture Card (Bt878)",
1400 .audio_inputs = 0, 1477 .video_inputs = 4,
1401 .tuner = -1, 1478 .audio_inputs = 0,
1402 .svhs = -1, 1479 .tuner = -1,
1403 .gpiomask = 0, 1480 .svhs = -1,
1404 .muxsel = { 2, 3, 1, 0 }, 1481 .gpiomask = 0,
1405 .audiomux = { 0 }, 1482 .muxsel = { 2, 3, 1, 0 },
1406 .needs_tvaudio = 0, 1483 .audiomux = { 0 },
1407 .no_msp34xx = 1, 1484 .needs_tvaudio = 0,
1408 .pll = PLL_28, 1485 .no_msp34xx = 1,
1409 .tuner_type = -1, 1486 .pll = PLL_28,
1410},{ 1487 .tuner_type = -1,
1411 .name = "Jetway TV/Capture JW-TV878-FBK, Kworld KW-TV878RF", 1488 .tuner_addr = ADDR_UNSET,
1412 .video_inputs = 4, 1489},{
1413 .audio_inputs = 3, 1490 .name = "Jetway TV/Capture JW-TV878-FBK, Kworld KW-TV878RF",
1414 .tuner = 0, 1491 .video_inputs = 4,
1415 .svhs = 2, 1492 .audio_inputs = 3,
1416 .gpiomask = 7, 1493 .tuner = 0,
1417 .muxsel = { 2, 3, 1, 1 }, // Tuner, SVid, SVHS, SVid to SVHS connector 1494 .svhs = 2,
1418 .audiomux = { 0 ,0 ,4, 4,4,4},// Yes, this tuner uses the same audio output for TV and FM radio! 1495 .gpiomask = 7,
1419 // This card lacks external Audio In, so we mute it on Ext. & Int. 1496 .muxsel = { 2, 3, 1, 1 }, /* Tuner, SVid, SVHS, SVid to SVHS connector */
1420 // The PCB can take a sbx1637/sbx1673, wiring unknown. 1497 .audiomux = { 0 ,0 ,4, 4,4,4},/* Yes, this tuner uses the same audio output for TV and FM radio!
1421 // This card lacks PCI subsystem ID, sigh. 1498 * This card lacks external Audio In, so we mute it on Ext. & Int.
1422 // audiomux=1: lower volume, 2+3: mute 1499 * The PCB can take a sbx1637/sbx1673, wiring unknown.
1423 // btwincap uses 0x80000/0x80003 1500 * This card lacks PCI subsystem ID, sigh.
1424 .needs_tvaudio = 0, 1501 * audiomux=1: lower volume, 2+3: mute
1425 .no_msp34xx = 1, 1502 * btwincap uses 0x80000/0x80003
1426 .pll = PLL_28, 1503 */
1427 .tuner_type = 5, // Samsung TCPA9095PC27A (BG+DK), philips compatible, w/FM, stereo and 1504 .needs_tvaudio = 0,
1428 // radio signal strength indicators work fine. 1505 .no_msp34xx = 1,
1429 .has_radio = 1, 1506 .pll = PLL_28,
1507 .tuner_type = 5,
1508 .tuner_addr = ADDR_UNSET,
1509 /* Samsung TCPA9095PC27A (BG+DK), philips compatible, w/FM, stereo and
1510 radio signal strength indicators work fine. */
1511 .has_radio = 1,
1430 /* GPIO Info: 1512 /* GPIO Info:
1431 GPIO0,1: HEF4052 A0,A1 1513 GPIO0,1: HEF4052 A0,A1
1432 GPIO2: HEF4052 nENABLE 1514 GPIO2: HEF4052 nENABLE
@@ -1437,25 +1519,27 @@ struct tvcard bttv_tvcards[] = {
1437 GPIO22,23: ?? 1519 GPIO22,23: ??
1438 ?? : mtu8b56ep microcontroller for IR (GPIO wiring unknown)*/ 1520 ?? : mtu8b56ep microcontroller for IR (GPIO wiring unknown)*/
1439},{ 1521},{
1440 /* Arthur Tetzlaff-Deas, DSP Design Ltd <software@dspdesign.com> */ 1522 /* Arthur Tetzlaff-Deas, DSP Design Ltd <software@dspdesign.com> */
1441 .name = "DSP Design TCVIDEO", 1523 .name = "DSP Design TCVIDEO",
1442 .video_inputs = 4, 1524 .video_inputs = 4,
1443 .svhs = -1, 1525 .svhs = -1,
1444 .muxsel = { 2, 3, 1, 0}, 1526 .muxsel = { 2, 3, 1, 0},
1445 .pll = PLL_28, 1527 .pll = PLL_28,
1446 .tuner_type = -1, 1528 .tuner_type = -1,
1529 .tuner_addr = ADDR_UNSET,
1447},{ 1530},{
1448 1531
1449 /* ---- card 0x50 ---------------------------------- */ 1532 /* ---- card 0x50 ---------------------------------- */
1450 .name = "Hauppauge WinTV PVR", 1533 .name = "Hauppauge WinTV PVR",
1451 .video_inputs = 4, 1534 .video_inputs = 4,
1452 .audio_inputs = 1, 1535 .audio_inputs = 1,
1453 .tuner = 0, 1536 .tuner = 0,
1454 .svhs = 2, 1537 .svhs = 2,
1455 .muxsel = { 2, 0, 1, 1}, 1538 .muxsel = { 2, 0, 1, 1},
1456 .needs_tvaudio = 1, 1539 .needs_tvaudio = 1,
1457 .pll = PLL_28, 1540 .pll = PLL_28,
1458 .tuner_type = -1, 1541 .tuner_type = -1,
1542 .tuner_addr = ADDR_UNSET,
1459 1543
1460 .gpiomask = 7, 1544 .gpiomask = 7,
1461 .audiomux = {7}, 1545 .audiomux = {7},
@@ -1471,6 +1555,7 @@ struct tvcard bttv_tvcards[] = {
1471 .no_msp34xx = 1, 1555 .no_msp34xx = 1,
1472 .pll = PLL_28, 1556 .pll = PLL_28,
1473 .tuner_type = TUNER_PHILIPS_NTSC_M, 1557 .tuner_type = TUNER_PHILIPS_NTSC_M,
1558 .tuner_addr = ADDR_UNSET,
1474 .audio_hook = gvbctv5pci_audio, 1559 .audio_hook = gvbctv5pci_audio,
1475 .has_radio = 1, 1560 .has_radio = 1,
1476},{ 1561},{
@@ -1482,9 +1567,10 @@ struct tvcard bttv_tvcards[] = {
1482 .muxsel = { 3, 2, 0, 1 }, 1567 .muxsel = { 3, 2, 0, 1 },
1483 .pll = PLL_28, 1568 .pll = PLL_28,
1484 .tuner_type = -1, 1569 .tuner_type = -1,
1485 .no_msp34xx = 1, 1570 .tuner_addr = ADDR_UNSET,
1486 .no_tda9875 = 1, 1571 .no_msp34xx = 1,
1487 .no_tda7432 = 1, 1572 .no_tda9875 = 1,
1573 .no_tda7432 = 1,
1488},{ 1574},{
1489 .name = "Osprey 100/150 (848)", /* 0x04-54C0-C1 & older boards */ 1575 .name = "Osprey 100/150 (848)", /* 0x04-54C0-C1 & older boards */
1490 .video_inputs = 3, 1576 .video_inputs = 3,
@@ -1494,9 +1580,10 @@ struct tvcard bttv_tvcards[] = {
1494 .muxsel = { 2, 3, 1 }, 1580 .muxsel = { 2, 3, 1 },
1495 .pll = PLL_28, 1581 .pll = PLL_28,
1496 .tuner_type = -1, 1582 .tuner_type = -1,
1497 .no_msp34xx = 1, 1583 .tuner_addr = ADDR_UNSET,
1498 .no_tda9875 = 1, 1584 .no_msp34xx = 1,
1499 .no_tda7432 = 1, 1585 .no_tda9875 = 1,
1586 .no_tda7432 = 1,
1500},{ 1587},{
1501 1588
1502 /* ---- card 0x54 ---------------------------------- */ 1589 /* ---- card 0x54 ---------------------------------- */
@@ -1508,9 +1595,10 @@ struct tvcard bttv_tvcards[] = {
1508 .muxsel = { 3, 1 }, 1595 .muxsel = { 3, 1 },
1509 .pll = PLL_28, 1596 .pll = PLL_28,
1510 .tuner_type = -1, 1597 .tuner_type = -1,
1511 .no_msp34xx = 1, 1598 .tuner_addr = ADDR_UNSET,
1512 .no_tda9875 = 1, 1599 .no_msp34xx = 1,
1513 .no_tda7432 = 1, 1600 .no_tda9875 = 1,
1601 .no_tda7432 = 1,
1514},{ 1602},{
1515 .name = "Osprey 101/151", /* 0x1(4|5)-0004-C4 */ 1603 .name = "Osprey 101/151", /* 0x1(4|5)-0004-C4 */
1516 .video_inputs = 1, 1604 .video_inputs = 1,
@@ -1520,9 +1608,10 @@ struct tvcard bttv_tvcards[] = {
1520 .muxsel = { 0 }, 1608 .muxsel = { 0 },
1521 .pll = PLL_28, 1609 .pll = PLL_28,
1522 .tuner_type = -1, 1610 .tuner_type = -1,
1523 .no_msp34xx = 1, 1611 .tuner_addr = ADDR_UNSET,
1524 .no_tda9875 = 1, 1612 .no_msp34xx = 1,
1525 .no_tda7432 = 1, 1613 .no_tda9875 = 1,
1614 .no_tda7432 = 1,
1526},{ 1615},{
1527 .name = "Osprey 101/151 w/ svid", /* 0x(16|17|20)-00C4-C1 */ 1616 .name = "Osprey 101/151 w/ svid", /* 0x(16|17|20)-00C4-C1 */
1528 .video_inputs = 2, 1617 .video_inputs = 2,
@@ -1532,9 +1621,10 @@ struct tvcard bttv_tvcards[] = {
1532 .muxsel = { 0, 1 }, 1621 .muxsel = { 0, 1 },
1533 .pll = PLL_28, 1622 .pll = PLL_28,
1534 .tuner_type = -1, 1623 .tuner_type = -1,
1535 .no_msp34xx = 1, 1624 .tuner_addr = ADDR_UNSET,
1536 .no_tda9875 = 1, 1625 .no_msp34xx = 1,
1537 .no_tda7432 = 1, 1626 .no_tda9875 = 1,
1627 .no_tda7432 = 1,
1538},{ 1628},{
1539 .name = "Osprey 200/201/250/251", /* 0x1(8|9|E|F)-0004-C4 */ 1629 .name = "Osprey 200/201/250/251", /* 0x1(8|9|E|F)-0004-C4 */
1540 .video_inputs = 1, 1630 .video_inputs = 1,
@@ -1543,10 +1633,11 @@ struct tvcard bttv_tvcards[] = {
1543 .svhs = -1, 1633 .svhs = -1,
1544 .muxsel = { 0 }, 1634 .muxsel = { 0 },
1545 .pll = PLL_28, 1635 .pll = PLL_28,
1546 .tuner_type = -1, 1636 .tuner_type = UNSET,
1547 .no_msp34xx = 1, 1637 .tuner_addr = ADDR_UNSET,
1548 .no_tda9875 = 1, 1638 .no_msp34xx = 1,
1549 .no_tda7432 = 1, 1639 .no_tda9875 = 1,
1640 .no_tda7432 = 1,
1550},{ 1641},{
1551 1642
1552 /* ---- card 0x58 ---------------------------------- */ 1643 /* ---- card 0x58 ---------------------------------- */
@@ -1557,10 +1648,11 @@ struct tvcard bttv_tvcards[] = {
1557 .svhs = 1, 1648 .svhs = 1,
1558 .muxsel = { 0, 1 }, 1649 .muxsel = { 0, 1 },
1559 .pll = PLL_28, 1650 .pll = PLL_28,
1560 .tuner_type = -1, 1651 .tuner_type = UNSET,
1561 .no_msp34xx = 1, 1652 .tuner_addr = ADDR_UNSET,
1562 .no_tda9875 = 1, 1653 .no_msp34xx = 1,
1563 .no_tda7432 = 1, 1654 .no_tda9875 = 1,
1655 .no_tda7432 = 1,
1564},{ 1656},{
1565 .name = "Osprey 210/220", /* 0x1(A|B)-04C0-C1 */ 1657 .name = "Osprey 210/220", /* 0x1(A|B)-04C0-C1 */
1566 .video_inputs = 2, 1658 .video_inputs = 2,
@@ -1569,10 +1661,11 @@ struct tvcard bttv_tvcards[] = {
1569 .svhs = 1, 1661 .svhs = 1,
1570 .muxsel = { 2, 3 }, 1662 .muxsel = { 2, 3 },
1571 .pll = PLL_28, 1663 .pll = PLL_28,
1572 .tuner_type = -1, 1664 .tuner_type = UNSET,
1573 .no_msp34xx = 1, 1665 .tuner_addr = ADDR_UNSET,
1574 .no_tda9875 = 1, 1666 .no_msp34xx = 1,
1575 .no_tda7432 = 1, 1667 .no_tda9875 = 1,
1668 .no_tda7432 = 1,
1576},{ 1669},{
1577 .name = "Osprey 500", /* 500 */ 1670 .name = "Osprey 500", /* 500 */
1578 .video_inputs = 2, 1671 .video_inputs = 2,
@@ -1582,19 +1675,21 @@ struct tvcard bttv_tvcards[] = {
1582 .muxsel = { 2, 3 }, 1675 .muxsel = { 2, 3 },
1583 .pll = PLL_28, 1676 .pll = PLL_28,
1584 .tuner_type = -1, 1677 .tuner_type = -1,
1585 .no_msp34xx = 1, 1678 .tuner_addr = ADDR_UNSET,
1586 .no_tda9875 = 1, 1679 .no_msp34xx = 1,
1587 .no_tda7432 = 1, 1680 .no_tda9875 = 1,
1681 .no_tda7432 = 1,
1588},{ 1682},{
1589 .name = "Osprey 540", /* 540 */ 1683 .name = "Osprey 540", /* 540 */
1590 .video_inputs = 4, 1684 .video_inputs = 4,
1591 .audio_inputs = 1, 1685 .audio_inputs = 1,
1592 .tuner = -1, 1686 .tuner = -1,
1593 .pll = PLL_28, 1687 .pll = PLL_28,
1594 .tuner_type = -1, 1688 .tuner_type = -1,
1595 .no_msp34xx = 1, 1689 .tuner_addr = ADDR_UNSET,
1596 .no_tda9875 = 1, 1690 .no_msp34xx = 1,
1597 .no_tda7432 = 1, 1691 .no_tda9875 = 1,
1692 .no_tda7432 = 1,
1598},{ 1693},{
1599 1694
1600 /* ---- card 0x5C ---------------------------------- */ 1695 /* ---- card 0x5C ---------------------------------- */
@@ -1605,10 +1700,11 @@ struct tvcard bttv_tvcards[] = {
1605 .svhs = 1, 1700 .svhs = 1,
1606 .muxsel = { 2, 3 }, 1701 .muxsel = { 2, 3 },
1607 .pll = PLL_28, 1702 .pll = PLL_28,
1608 .tuner_type = -1, 1703 .tuner_type = UNSET,
1609 .no_msp34xx = 1, 1704 .tuner_addr = ADDR_UNSET,
1610 .no_tda9875 = 1, 1705 .no_msp34xx = 1,
1611 .no_tda7432 = 1, /* must avoid, conflicts with the bt860 */ 1706 .no_tda9875 = 1,
1707 .no_tda7432 = 1, /* must avoid, conflicts with the bt860 */
1612},{ 1708},{
1613 /* M G Berberich <berberic@forwiss.uni-passau.de> */ 1709 /* M G Berberich <berberic@forwiss.uni-passau.de> */
1614 .name = "IDS Eagle", 1710 .name = "IDS Eagle",
@@ -1616,6 +1712,7 @@ struct tvcard bttv_tvcards[] = {
1616 .audio_inputs = 0, 1712 .audio_inputs = 0,
1617 .tuner = -1, 1713 .tuner = -1,
1618 .tuner_type = -1, 1714 .tuner_type = -1,
1715 .tuner_addr = ADDR_UNSET,
1619 .svhs = -1, 1716 .svhs = -1,
1620 .gpiomask = 0, 1717 .gpiomask = 0,
1621 .muxsel = { 0, 1, 2, 3 }, 1718 .muxsel = { 0, 1, 2, 3 },
@@ -1630,6 +1727,7 @@ struct tvcard bttv_tvcards[] = {
1630 .svhs = 1, 1727 .svhs = 1,
1631 .tuner = -1, 1728 .tuner = -1,
1632 .tuner_type = -1, 1729 .tuner_type = -1,
1730 .tuner_addr = ADDR_UNSET,
1633 .no_msp34xx = 1, 1731 .no_msp34xx = 1,
1634 .no_tda9875 = 1, 1732 .no_tda9875 = 1,
1635 .no_tda7432 = 1, 1733 .no_tda7432 = 1,
@@ -1641,38 +1739,40 @@ struct tvcard bttv_tvcards[] = {
1641 .no_gpioirq = 1, 1739 .no_gpioirq = 1,
1642 .has_dvb = 1, 1740 .has_dvb = 1,
1643},{ 1741},{
1644 .name = "Formac ProTV II (bt878)", 1742 .name = "Formac ProTV II (bt878)",
1645 .video_inputs = 4, 1743 .video_inputs = 4,
1646 .audio_inputs = 1, 1744 .audio_inputs = 1,
1647 .tuner = 0, 1745 .tuner = 0,
1648 .svhs = 3, 1746 .svhs = 3,
1649 .gpiomask = 2, 1747 .gpiomask = 2,
1650 // TV, Comp1, Composite over SVID con, SVID 1748 /* TV, Comp1, Composite over SVID con, SVID */
1651 .muxsel = { 2, 3, 1, 1}, 1749 .muxsel = { 2, 3, 1, 1},
1652 .audiomux = { 2, 2, 0, 0, 0 }, 1750 .audiomux = { 2, 2, 0, 0, 0 },
1653 .pll = PLL_28, 1751 .pll = PLL_28,
1654 .has_radio = 1, 1752 .has_radio = 1,
1655 .tuner_type = TUNER_PHILIPS_PAL, 1753 .tuner_type = TUNER_PHILIPS_PAL,
1656 /* sound routing: 1754 .tuner_addr = ADDR_UNSET,
1657 GPIO=0x00,0x01,0x03: mute (?) 1755/* sound routing:
1658 0x02: both TV and radio (tuner: FM1216/I) 1756 GPIO=0x00,0x01,0x03: mute (?)
1659 The card has onboard audio connectors labeled "cdrom" and "board", 1757 0x02: both TV and radio (tuner: FM1216/I)
1660 not soldered here, though unknown wiring. 1758 The card has onboard audio connectors labeled "cdrom" and "board",
1661 Card lacks: external audio in, pci subsystem id. 1759 not soldered here, though unknown wiring.
1662 */ 1760 Card lacks: external audio in, pci subsystem id.
1761*/
1663},{ 1762},{
1664 1763
1665 /* ---- card 0x60 ---------------------------------- */ 1764 /* ---- card 0x60 ---------------------------------- */
1666 .name = "MachTV", 1765 .name = "MachTV",
1667 .video_inputs = 3, 1766 .video_inputs = 3,
1668 .audio_inputs = 1, 1767 .audio_inputs = 1,
1669 .tuner = 0, 1768 .tuner = 0,
1670 .svhs = -1, 1769 .svhs = -1,
1671 .gpiomask = 7, 1770 .gpiomask = 7,
1672 .muxsel = { 2, 3, 1, 1}, 1771 .muxsel = { 2, 3, 1, 1},
1673 .audiomux = { 0, 1, 2, 3, 4}, 1772 .audiomux = { 0, 1, 2, 3, 4},
1674 .needs_tvaudio = 1, 1773 .needs_tvaudio = 1,
1675 .tuner_type = 5, 1774 .tuner_type = 5,
1775 .tuner_addr = ADDR_UNSET,
1676 .pll = 1, 1776 .pll = 1,
1677},{ 1777},{
1678 .name = "Euresys Picolo", 1778 .name = "Euresys Picolo",
@@ -1686,6 +1786,8 @@ struct tvcard bttv_tvcards[] = {
1686 .no_tda7432 = 1, 1786 .no_tda7432 = 1,
1687 .muxsel = { 2, 0, 1}, 1787 .muxsel = { 2, 0, 1},
1688 .pll = PLL_28, 1788 .pll = PLL_28,
1789 .tuner_type = UNSET,
1790 .tuner_addr = ADDR_UNSET,
1689},{ 1791},{
1690 /* Luc Van Hoeylandt <luc@e-magic.be> */ 1792 /* Luc Van Hoeylandt <luc@e-magic.be> */
1691 .name = "ProVideo PV150", /* 0x4f */ 1793 .name = "ProVideo PV150", /* 0x4f */
@@ -1699,7 +1801,8 @@ struct tvcard bttv_tvcards[] = {
1699 .needs_tvaudio = 0, 1801 .needs_tvaudio = 0,
1700 .no_msp34xx = 1, 1802 .no_msp34xx = 1,
1701 .pll = PLL_28, 1803 .pll = PLL_28,
1702 .tuner_type = -1, 1804 .tuner_type = UNSET,
1805 .tuner_addr = ADDR_UNSET,
1703},{ 1806},{
1704 /* Hiroshi Takekawa <sian@big.or.jp> */ 1807 /* Hiroshi Takekawa <sian@big.or.jp> */
1705 /* This card lacks subsystem ID */ 1808 /* This card lacks subsystem ID */
@@ -1716,78 +1819,85 @@ struct tvcard bttv_tvcards[] = {
1716 .no_msp34xx = 1, 1819 .no_msp34xx = 1,
1717 .pll = PLL_28, 1820 .pll = PLL_28,
1718 .tuner_type = 2, 1821 .tuner_type = 2,
1822 .tuner_addr = ADDR_UNSET,
1719 .audio_hook = adtvk503_audio, 1823 .audio_hook = adtvk503_audio,
1720},{ 1824},{
1721 1825
1722 /* ---- card 0x64 ---------------------------------- */ 1826 /* ---- card 0x64 ---------------------------------- */
1723 .name = "Hercules Smart TV Stereo", 1827 .name = "Hercules Smart TV Stereo",
1724 .video_inputs = 4, 1828 .video_inputs = 4,
1725 .audio_inputs = 1, 1829 .audio_inputs = 1,
1726 .tuner = 0, 1830 .tuner = 0,
1727 .svhs = 2, 1831 .svhs = 2,
1728 .gpiomask = 0x00, 1832 .gpiomask = 0x00,
1729 .muxsel = { 2, 3, 1, 1 }, 1833 .muxsel = { 2, 3, 1, 1 },
1730 .needs_tvaudio = 1, 1834 .needs_tvaudio = 1,
1731 .no_msp34xx = 1, 1835 .no_msp34xx = 1,
1732 .pll = PLL_28, 1836 .pll = PLL_28,
1733 .tuner_type = 5, 1837 .tuner_type = 5,
1838 .tuner_addr = ADDR_UNSET,
1734 /* Notes: 1839 /* Notes:
1735 - card lacks subsystem ID 1840 - card lacks subsystem ID
1736 - stereo variant w/ daughter board with tda9874a @0xb0 1841 - stereo variant w/ daughter board with tda9874a @0xb0
1737 - Audio Routing: 1842 - Audio Routing:
1738 always from tda9874 independent of GPIO (?) 1843 always from tda9874 independent of GPIO (?)
1739 external line in: unknown 1844 external line in: unknown
1740 - Other chips: em78p156elp @ 0x96 (probably IR remote control) 1845 - Other chips: em78p156elp @ 0x96 (probably IR remote control)
1741 hef4053 (instead 4052) for unknown function 1846 hef4053 (instead 4052) for unknown function
1847 */
1848},{
1849 .name = "Pace TV & Radio Card",
1850 .video_inputs = 4,
1851 .audio_inputs = 1,
1852 .tuner = 0,
1853 .svhs = 2,
1854 .muxsel = { 2, 3, 1, 1}, /* Tuner, CVid, SVid, CVid over SVid connector */
1855 .gpiomask = 0,
1856 .no_tda9875 = 1,
1857 .no_tda7432 = 1,
1858 .tuner_type = 1,
1859 .tuner_addr = ADDR_UNSET,
1860 .has_radio = 1,
1861 .pll = PLL_28,
1862 /* Bt878, Bt832, FI1246 tuner; no pci subsystem id
1863 only internal line out: (4pin header) RGGL
1864 Radio must be decoded by msp3410d (not routed through)*/
1865 /*
1866 .digital_mode = DIGITAL_MODE_CAMERA, todo!
1742 */ 1867 */
1743},{ 1868},{
1744 .name = "Pace TV & Radio Card", 1869 /* Chris Willing <chris@vislab.usyd.edu.au> */
1745 .video_inputs = 4, 1870 .name = "IVC-200",
1746 .audio_inputs = 1, 1871 .video_inputs = 1,
1747 .tuner = 0, 1872 .audio_inputs = 0,
1748 .svhs = 2, 1873 .tuner = -1,
1749 .muxsel = { 2, 3, 1, 1}, // Tuner, CVid, SVid, CVid over SVid connector 1874 .tuner_type = -1,
1750 .gpiomask = 0, 1875 .tuner_addr = ADDR_UNSET,
1751 .no_tda9875 = 1, 1876 .svhs = -1,
1752 .no_tda7432 = 1, 1877 .gpiomask = 0xdf,
1753 .tuner_type = 1, 1878 .muxsel = { 2 },
1754 .has_radio = 1, 1879 .pll = PLL_28,
1755 .pll = PLL_28,
1756 /* Bt878, Bt832, FI1246 tuner; no pci subsystem id
1757 only internal line out: (4pin header) RGGL
1758 Radio must be decoded by msp3410d (not routed through)*/
1759 // .digital_mode = DIGITAL_MODE_CAMERA, // todo!
1760},{
1761 /* Chris Willing <chris@vislab.usyd.edu.au> */
1762 .name = "IVC-200",
1763 .video_inputs = 1,
1764 .audio_inputs = 0,
1765 .tuner = -1,
1766 .tuner_type = -1,
1767 .svhs = -1,
1768 .gpiomask = 0xdf,
1769 .muxsel = { 2 },
1770 .pll = PLL_28,
1771},{ 1880},{
1772 .name = "Grand X-Guard / Trust 814PCI", 1881 .name = "Grand X-Guard / Trust 814PCI",
1773 .video_inputs = 16, 1882 .video_inputs = 16,
1774 .audio_inputs = 0, 1883 .audio_inputs = 0,
1775 .tuner = -1, 1884 .tuner = -1,
1776 .svhs = -1, 1885 .svhs = -1,
1777 .tuner_type = 4, 1886 .tuner_type = 4,
1778 .gpiomask2 = 0xff, 1887 .tuner_addr = ADDR_UNSET,
1888 .gpiomask2 = 0xff,
1779 .muxsel = { 2,2,2,2, 3,3,3,3, 1,1,1,1, 0,0,0,0 }, 1889 .muxsel = { 2,2,2,2, 3,3,3,3, 1,1,1,1, 0,0,0,0 },
1780 .muxsel_hook = xguard_muxsel, 1890 .muxsel_hook = xguard_muxsel,
1781 .no_msp34xx = 1, 1891 .no_msp34xx = 1,
1782 .no_tda9875 = 1, 1892 .no_tda9875 = 1,
1783 .no_tda7432 = 1, 1893 .no_tda7432 = 1,
1784 .pll = PLL_28, 1894 .pll = PLL_28,
1785},{ 1895},{
1786 1896
1787 /* ---- card 0x68 ---------------------------------- */ 1897 /* ---- card 0x68 ---------------------------------- */
1788 .name = "Nebula Electronics DigiTV", 1898 .name = "Nebula Electronics DigiTV",
1789 .video_inputs = 1, 1899 .video_inputs = 1,
1790 .tuner = -1, 1900 .tuner = -1,
1791 .svhs = -1, 1901 .svhs = -1,
1792 .muxsel = { 2, 3, 1, 0}, 1902 .muxsel = { 2, 3, 1, 0},
1793 .no_msp34xx = 1, 1903 .no_msp34xx = 1,
@@ -1795,22 +1905,24 @@ struct tvcard bttv_tvcards[] = {
1795 .no_tda7432 = 1, 1905 .no_tda7432 = 1,
1796 .pll = PLL_28, 1906 .pll = PLL_28,
1797 .tuner_type = -1, 1907 .tuner_type = -1,
1908 .tuner_addr = ADDR_UNSET,
1798 .has_dvb = 1, 1909 .has_dvb = 1,
1799 .no_gpioirq = 1, 1910 .no_gpioirq = 1,
1800},{ 1911},{
1801 /* Jorge Boncompte - DTI2 <jorge@dti2.net> */ 1912 /* Jorge Boncompte - DTI2 <jorge@dti2.net> */
1802 .name = "ProVideo PV143", 1913 .name = "ProVideo PV143",
1803 .video_inputs = 4, 1914 .video_inputs = 4,
1804 .audio_inputs = 0, 1915 .audio_inputs = 0,
1805 .tuner = -1, 1916 .tuner = -1,
1806 .svhs = -1, 1917 .svhs = -1,
1807 .gpiomask = 0, 1918 .gpiomask = 0,
1808 .muxsel = { 2, 3, 1, 0 }, 1919 .muxsel = { 2, 3, 1, 0 },
1809 .audiomux = { 0 }, 1920 .audiomux = { 0 },
1810 .needs_tvaudio = 0, 1921 .needs_tvaudio = 0,
1811 .no_msp34xx = 1, 1922 .no_msp34xx = 1,
1812 .pll = PLL_28, 1923 .pll = PLL_28,
1813 .tuner_type = -1, 1924 .tuner_type = -1,
1925 .tuner_addr = ADDR_UNSET,
1814},{ 1926},{
1815 /* M.Klahr@phytec.de */ 1927 /* M.Klahr@phytec.de */
1816 .name = "PHYTEC VD-009-X1 MiniDIN (bt878)", 1928 .name = "PHYTEC VD-009-X1 MiniDIN (bt878)",
@@ -1824,6 +1936,7 @@ struct tvcard bttv_tvcards[] = {
1824 .needs_tvaudio = 1, 1936 .needs_tvaudio = 1,
1825 .pll = PLL_28, 1937 .pll = PLL_28,
1826 .tuner_type = -1, 1938 .tuner_type = -1,
1939 .tuner_addr = ADDR_UNSET,
1827},{ 1940},{
1828 .name = "PHYTEC VD-009-X1 Combi (bt878)", 1941 .name = "PHYTEC VD-009-X1 Combi (bt878)",
1829 .video_inputs = 4, 1942 .video_inputs = 4,
@@ -1836,6 +1949,7 @@ struct tvcard bttv_tvcards[] = {
1836 .needs_tvaudio = 1, 1949 .needs_tvaudio = 1,
1837 .pll = PLL_28, 1950 .pll = PLL_28,
1838 .tuner_type = -1, 1951 .tuner_type = -1,
1952 .tuner_addr = ADDR_UNSET,
1839},{ 1953},{
1840 1954
1841 /* ---- card 0x6c ---------------------------------- */ 1955 /* ---- card 0x6c ---------------------------------- */
@@ -1846,13 +1960,14 @@ struct tvcard bttv_tvcards[] = {
1846 .svhs = 9, 1960 .svhs = 9,
1847 .gpiomask = 0x00, 1961 .gpiomask = 0x00,
1848 .gpiomask2 = 0x03, /* gpiomask2 defines the bits used to switch audio 1962 .gpiomask2 = 0x03, /* gpiomask2 defines the bits used to switch audio
1849 via the upper nibble of muxsel. here: used for 1963 via the upper nibble of muxsel. here: used for
1850 xternal video-mux */ 1964 xternal video-mux */
1851 .muxsel = { 0x02, 0x12, 0x22, 0x32, 0x03, 0x13, 0x23, 0x33, 0x01, 0x00 }, 1965 .muxsel = { 0x02, 0x12, 0x22, 0x32, 0x03, 0x13, 0x23, 0x33, 0x01, 0x00 },
1852 .audiomux = { 0, 0, 0, 0, 0, 0 }, /* card has no audio */ 1966 .audiomux = { 0, 0, 0, 0, 0, 0 }, /* card has no audio */
1853 .needs_tvaudio = 1, 1967 .needs_tvaudio = 1,
1854 .pll = PLL_28, 1968 .pll = PLL_28,
1855 .tuner_type = -1, 1969 .tuner_type = -1,
1970 .tuner_addr = ADDR_UNSET,
1856},{ 1971},{
1857 .name = "PHYTEC VD-009 Combi (bt878)", 1972 .name = "PHYTEC VD-009 Combi (bt878)",
1858 .video_inputs = 10, 1973 .video_inputs = 10,
@@ -1861,23 +1976,25 @@ struct tvcard bttv_tvcards[] = {
1861 .svhs = 9, 1976 .svhs = 9,
1862 .gpiomask = 0x00, 1977 .gpiomask = 0x00,
1863 .gpiomask2 = 0x03, /* gpiomask2 defines the bits used to switch audio 1978 .gpiomask2 = 0x03, /* gpiomask2 defines the bits used to switch audio
1864 via the upper nibble of muxsel. here: used for 1979 via the upper nibble of muxsel. here: used for
1865 xternal video-mux */ 1980 xternal video-mux */
1866 .muxsel = { 0x02, 0x12, 0x22, 0x32, 0x03, 0x13, 0x23, 0x33, 0x01, 0x01 }, 1981 .muxsel = { 0x02, 0x12, 0x22, 0x32, 0x03, 0x13, 0x23, 0x33, 0x01, 0x01 },
1867 .audiomux = { 0, 0, 0, 0, 0, 0 }, /* card has no audio */ 1982 .audiomux = { 0, 0, 0, 0, 0, 0 }, /* card has no audio */
1868 .needs_tvaudio = 1, 1983 .needs_tvaudio = 1,
1869 .pll = PLL_28, 1984 .pll = PLL_28,
1870 .tuner_type = -1, 1985 .tuner_type = -1,
1986 .tuner_addr = ADDR_UNSET,
1871},{ 1987},{
1872 .name = "IVC-100", 1988 .name = "IVC-100",
1873 .video_inputs = 4, 1989 .video_inputs = 4,
1874 .audio_inputs = 0, 1990 .audio_inputs = 0,
1875 .tuner = -1, 1991 .tuner = -1,
1876 .tuner_type = -1, 1992 .tuner_type = -1,
1877 .svhs = -1, 1993 .tuner_addr = ADDR_UNSET,
1878 .gpiomask = 0xdf, 1994 .svhs = -1,
1879 .muxsel = { 2, 3, 1, 0 }, 1995 .gpiomask = 0xdf,
1880 .pll = PLL_28, 1996 .muxsel = { 2, 3, 1, 0 },
1997 .pll = PLL_28,
1881},{ 1998},{
1882 /* IVC-120G - Alan Garfield <alan@fromorbit.com> */ 1999 /* IVC-120G - Alan Garfield <alan@fromorbit.com> */
1883 .name = "IVC-120G", 2000 .name = "IVC-120G",
@@ -1885,6 +2002,7 @@ struct tvcard bttv_tvcards[] = {
1885 .audio_inputs = 0, /* card has no audio */ 2002 .audio_inputs = 0, /* card has no audio */
1886 .tuner = -1, /* card has no tuner */ 2003 .tuner = -1, /* card has no tuner */
1887 .tuner_type = -1, 2004 .tuner_type = -1,
2005 .tuner_addr = ADDR_UNSET,
1888 .svhs = -1, /* card has no svhs */ 2006 .svhs = -1, /* card has no svhs */
1889 .needs_tvaudio = 0, 2007 .needs_tvaudio = 0,
1890 .no_msp34xx = 1, 2008 .no_msp34xx = 1,
@@ -1892,7 +2010,7 @@ struct tvcard bttv_tvcards[] = {
1892 .no_tda7432 = 1, 2010 .no_tda7432 = 1,
1893 .gpiomask = 0x00, 2011 .gpiomask = 0x00,
1894 .muxsel = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 2012 .muxsel = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
1895 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10 }, 2013 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10 },
1896 .muxsel_hook = ivc120_muxsel, 2014 .muxsel_hook = ivc120_muxsel,
1897 .pll = PLL_28, 2015 .pll = PLL_28,
1898},{ 2016},{
@@ -1905,6 +2023,7 @@ struct tvcard bttv_tvcards[] = {
1905 .svhs = 2, 2023 .svhs = 2,
1906 .muxsel = { 2, 3, 1, 0}, 2024 .muxsel = { 2, 3, 1, 0},
1907 .tuner_type = TUNER_PHILIPS_ATSC, 2025 .tuner_type = TUNER_PHILIPS_ATSC,
2026 .tuner_addr = ADDR_UNSET,
1908 .has_dvb = 1, 2027 .has_dvb = 1,
1909},{ 2028},{
1910 .name = "Twinhan DST + clones", 2029 .name = "Twinhan DST + clones",
@@ -1912,19 +2031,21 @@ struct tvcard bttv_tvcards[] = {
1912 .no_tda9875 = 1, 2031 .no_tda9875 = 1,
1913 .no_tda7432 = 1, 2032 .no_tda7432 = 1,
1914 .tuner_type = TUNER_ABSENT, 2033 .tuner_type = TUNER_ABSENT,
2034 .tuner_addr = ADDR_UNSET,
1915 .no_video = 1, 2035 .no_video = 1,
1916 .has_dvb = 1, 2036 .has_dvb = 1,
1917},{ 2037},{
1918 .name = "Winfast VC100", 2038 .name = "Winfast VC100",
1919 .video_inputs = 3, 2039 .video_inputs = 3,
1920 .audio_inputs = 0, 2040 .audio_inputs = 0,
1921 .svhs = 1, 2041 .svhs = 1,
1922 .tuner = -1, // no tuner 2042 .tuner = -1,
1923 .muxsel = { 3, 1, 1, 3}, // Vid In, SVid In, Vid over SVid in connector 2043 .muxsel = { 3, 1, 1, 3}, /* Vid In, SVid In, Vid over SVid in connector */
1924 .no_msp34xx = 1, 2044 .no_msp34xx = 1,
1925 .no_tda9875 = 1, 2045 .no_tda9875 = 1,
1926 .no_tda7432 = 1, 2046 .no_tda7432 = 1,
1927 .tuner_type = TUNER_ABSENT, 2047 .tuner_type = TUNER_ABSENT,
2048 .tuner_addr = ADDR_UNSET,
1928 .pll = PLL_28, 2049 .pll = PLL_28,
1929},{ 2050},{
1930 .name = "Teppro TEV-560/InterVision IV-560", 2051 .name = "Teppro TEV-560/InterVision IV-560",
@@ -1937,44 +2058,49 @@ struct tvcard bttv_tvcards[] = {
1937 .audiomux = { 1, 1, 1, 1, 0}, 2058 .audiomux = { 1, 1, 1, 1, 0},
1938 .needs_tvaudio = 1, 2059 .needs_tvaudio = 1,
1939 .tuner_type = TUNER_PHILIPS_PAL, 2060 .tuner_type = TUNER_PHILIPS_PAL,
2061 .tuner_addr = ADDR_UNSET,
1940 .pll = PLL_35, 2062 .pll = PLL_35,
1941},{ 2063},{
1942 2064
1943 /* ---- card 0x74 ---------------------------------- */ 2065 /* ---- card 0x74 ---------------------------------- */
1944 .name = "SIMUS GVC1100", 2066 .name = "SIMUS GVC1100",
1945 .video_inputs = 4, 2067 .video_inputs = 4,
1946 .audio_inputs = 0, 2068 .audio_inputs = 0,
1947 .tuner = -1, 2069 .tuner = -1,
1948 .svhs = -1, 2070 .svhs = -1,
1949 .tuner_type = -1, 2071 .tuner_type = -1,
1950 .pll = PLL_28, 2072 .tuner_addr = ADDR_UNSET,
1951 .muxsel = { 2, 2, 2, 2}, 2073 .pll = PLL_28,
1952 .gpiomask = 0x3F, 2074 .muxsel = { 2, 2, 2, 2},
2075 .gpiomask = 0x3F,
1953 .muxsel_hook = gvc1100_muxsel, 2076 .muxsel_hook = gvc1100_muxsel,
1954},{ 2077},{
1955 /* Carlos Silva r3pek@r3pek.homelinux.org || card 0x75 */ 2078 /* Carlos Silva r3pek@r3pek.homelinux.org || card 0x75 */
1956 .name = "NGS NGSTV+", 2079 .name = "NGS NGSTV+",
1957 .video_inputs = 3, 2080 .video_inputs = 3,
1958 .tuner = 0, 2081 .tuner = 0,
1959 .svhs = 2, 2082 .svhs = 2,
1960 .gpiomask = 0x008007, 2083 .gpiomask = 0x008007,
1961 .muxsel = {2, 3, 0, 0}, 2084 .muxsel = {2, 3, 0, 0},
1962 .audiomux = {0, 0, 0, 0, 0x000003, 0}, 2085 .audiomux = {0, 0, 0, 0, 0x000003, 0},
1963 .pll = PLL_28, 2086 .pll = PLL_28,
1964 .tuner_type = TUNER_PHILIPS_PAL, 2087 .tuner_type = TUNER_PHILIPS_PAL,
1965 .has_remote = 1, 2088 .tuner_addr = ADDR_UNSET,
1966},{ 2089 .has_remote = 1,
1967 /* http://linuxmedialabs.com */ 2090},{
1968 .name = "LMLBT4", 2091 /* http://linuxmedialabs.com */
1969 .video_inputs = 4, /* IN1,IN2,IN3,IN4 */ 2092 .name = "LMLBT4",
1970 .audio_inputs = 0, 2093 .video_inputs = 4, /* IN1,IN2,IN3,IN4 */
1971 .tuner = -1, 2094 .audio_inputs = 0,
1972 .svhs = -1, 2095 .tuner = -1,
1973 .muxsel = { 2, 3, 1, 0 }, 2096 .svhs = -1,
1974 .no_msp34xx = 1, 2097 .muxsel = { 2, 3, 1, 0 },
1975 .no_tda9875 = 1, 2098 .no_msp34xx = 1,
1976 .no_tda7432 = 1, 2099 .no_tda9875 = 1,
1977 .needs_tvaudio = 0, 2100 .no_tda7432 = 1,
2101 .needs_tvaudio = 0,
2102 .tuner_type = -1,
2103 .tuner_addr = ADDR_UNSET,
1978},{ 2104},{
1979 /* Helmroos Harri <harri.helmroos@pp.inet.fi> */ 2105 /* Helmroos Harri <harri.helmroos@pp.inet.fi> */
1980 .name = "Tekram M205 PRO", 2106 .name = "Tekram M205 PRO",
@@ -1982,6 +2108,7 @@ struct tvcard bttv_tvcards[] = {
1982 .audio_inputs = 1, 2108 .audio_inputs = 1,
1983 .tuner = 0, 2109 .tuner = 0,
1984 .tuner_type = TUNER_PHILIPS_PAL, 2110 .tuner_type = TUNER_PHILIPS_PAL,
2111 .tuner_addr = ADDR_UNSET,
1985 .svhs = 2, 2112 .svhs = 2,
1986 .needs_tvaudio = 0, 2113 .needs_tvaudio = 0,
1987 .gpiomask = 0x68, 2114 .gpiomask = 0x68,
@@ -2004,6 +2131,7 @@ struct tvcard bttv_tvcards[] = {
2004 .needs_tvaudio = 0, 2131 .needs_tvaudio = 0,
2005 .pll = PLL_28, 2132 .pll = PLL_28,
2006 .tuner_type = TUNER_PHILIPS_PAL, 2133 .tuner_type = TUNER_PHILIPS_PAL,
2134 .tuner_addr = ADDR_UNSET,
2007 .has_remote = 1, 2135 .has_remote = 1,
2008 .has_radio = 1, 2136 .has_radio = 1,
2009},{ 2137},{
@@ -2026,6 +2154,8 @@ struct tvcard bttv_tvcards[] = {
2026 .pll = PLL_28, 2154 .pll = PLL_28,
2027 .needs_tvaudio = 0, 2155 .needs_tvaudio = 0,
2028 .muxsel_hook = picolo_tetra_muxsel,/*Required as it doesn't follow the classic input selection policy*/ 2156 .muxsel_hook = picolo_tetra_muxsel,/*Required as it doesn't follow the classic input selection policy*/
2157 .tuner_type = -1,
2158 .tuner_addr = ADDR_UNSET,
2029},{ 2159},{
2030 /* Spirit TV Tuner from http://spiritmodems.com.au */ 2160 /* Spirit TV Tuner from http://spiritmodems.com.au */
2031 /* Stafford Goodsell <surge@goliath.homeunix.org> */ 2161 /* Stafford Goodsell <surge@goliath.homeunix.org> */
@@ -2038,23 +2168,25 @@ struct tvcard bttv_tvcards[] = {
2038 .muxsel = { 2, 1, 1 }, 2168 .muxsel = { 2, 1, 1 },
2039 .audiomux = { 0x02, 0x00, 0x00, 0x00, 0x00}, 2169 .audiomux = { 0x02, 0x00, 0x00, 0x00, 0x00},
2040 .tuner_type = TUNER_TEMIC_PAL, 2170 .tuner_type = TUNER_TEMIC_PAL,
2171 .tuner_addr = ADDR_UNSET,
2041 .no_msp34xx = 1, 2172 .no_msp34xx = 1,
2042 .no_tda9875 = 1, 2173 .no_tda9875 = 1,
2043},{ 2174},{
2044 /* Wolfram Joost <wojo@frokaschwei.de> */ 2175 /* Wolfram Joost <wojo@frokaschwei.de> */
2045 .name = "AVerMedia AVerTV DVB-T 771", 2176 .name = "AVerMedia AVerTV DVB-T 771",
2046 .video_inputs = 2, 2177 .video_inputs = 2,
2047 .svhs = 1, 2178 .svhs = 1,
2048 .tuner = -1, 2179 .tuner = -1,
2049 .tuner_type = TUNER_ABSENT, 2180 .tuner_type = TUNER_ABSENT,
2050 .muxsel = { 3 , 3 }, 2181 .tuner_addr = ADDR_UNSET,
2051 .no_msp34xx = 1, 2182 .muxsel = { 3 , 3 },
2052 .no_tda9875 = 1, 2183 .no_msp34xx = 1,
2053 .no_tda7432 = 1, 2184 .no_tda9875 = 1,
2054 .pll = PLL_28, 2185 .no_tda7432 = 1,
2055 .has_dvb = 1, 2186 .pll = PLL_28,
2056 .no_gpioirq = 1, 2187 .has_dvb = 1,
2057 .has_remote = 1, 2188 .no_gpioirq = 1,
2189 .has_remote = 1,
2058},{ 2190},{
2059 /* ---- card 0x7c ---------------------------------- */ 2191 /* ---- card 0x7c ---------------------------------- */
2060 /* Matt Jesson <dvb@jesson.eclipse.co.uk> */ 2192 /* Matt Jesson <dvb@jesson.eclipse.co.uk> */
@@ -2069,6 +2201,7 @@ struct tvcard bttv_tvcards[] = {
2069 .no_tda7432 = 1, 2201 .no_tda7432 = 1,
2070 .pll = PLL_28, 2202 .pll = PLL_28,
2071 .tuner_type = -1, 2203 .tuner_type = -1,
2204 .tuner_addr = ADDR_UNSET,
2072 .has_dvb = 1, 2205 .has_dvb = 1,
2073 .no_gpioirq = 1, 2206 .no_gpioirq = 1,
2074 .has_remote = 1, 2207 .has_remote = 1,
@@ -2081,12 +2214,13 @@ struct tvcard bttv_tvcards[] = {
2081 .svhs = -1, 2214 .svhs = -1,
2082 .gpiomask = 0x0, 2215 .gpiomask = 0x0,
2083 .muxsel = { 2, 2, 2, 2, 2, 2, 2, 2, 2216 .muxsel = { 2, 2, 2, 2, 2, 2, 2, 2,
2084 3, 3, 3, 3, 3, 3, 3, 3 }, 2217 3, 3, 3, 3, 3, 3, 3, 3 },
2085 .muxsel_hook = sigmaSQ_muxsel, 2218 .muxsel_hook = sigmaSQ_muxsel,
2086 .audiomux = { 0 }, 2219 .audiomux = { 0 },
2087 .no_msp34xx = 1, 2220 .no_msp34xx = 1,
2088 .pll = PLL_28, 2221 .pll = PLL_28,
2089 .tuner_type = -1, 2222 .tuner_type = -1,
2223 .tuner_addr = ADDR_UNSET,
2090},{ 2224},{
2091 /* andre.schwarz@matrix-vision.de */ 2225 /* andre.schwarz@matrix-vision.de */
2092 .name = "MATRIX Vision Sigma-SLC", 2226 .name = "MATRIX Vision Sigma-SLC",
@@ -2101,6 +2235,7 @@ struct tvcard bttv_tvcards[] = {
2101 .no_msp34xx = 1, 2235 .no_msp34xx = 1,
2102 .pll = PLL_28, 2236 .pll = PLL_28,
2103 .tuner_type = -1, 2237 .tuner_type = -1,
2238 .tuner_addr = ADDR_UNSET,
2104},{ 2239},{
2105 /* BTTV_APAC_VIEWCOMP */ 2240 /* BTTV_APAC_VIEWCOMP */
2106 /* Attila Kondoros <attila.kondoros@chello.hu> */ 2241 /* Attila Kondoros <attila.kondoros@chello.hu> */
@@ -2116,13 +2251,14 @@ struct tvcard bttv_tvcards[] = {
2116 .needs_tvaudio = 0, 2251 .needs_tvaudio = 0,
2117 .pll = PLL_28, 2252 .pll = PLL_28,
2118 .tuner_type = TUNER_PHILIPS_PAL, 2253 .tuner_type = TUNER_PHILIPS_PAL,
2254 .tuner_addr = ADDR_UNSET,
2119 .has_remote = 1, /* miniremote works, see ir-kbd-gpio.c */ 2255 .has_remote = 1, /* miniremote works, see ir-kbd-gpio.c */
2120 .has_radio = 1, /* not every card has radio */ 2256 .has_radio = 1, /* not every card has radio */
2121},{ 2257},{
2122 2258
2123 /* ---- card 0x80 ---------------------------------- */ 2259 /* ---- card 0x80 ---------------------------------- */
2124 /* Chris Pascoe <c.pascoe@itee.uq.edu.au> */ 2260 /* Chris Pascoe <c.pascoe@itee.uq.edu.au> */
2125 .name = "DVICO FusionHDTV DVB-T Lite", 2261 .name = "DViCO FusionHDTV DVB-T Lite",
2126 .tuner = -1, 2262 .tuner = -1,
2127 .no_msp34xx = 1, 2263 .no_msp34xx = 1,
2128 .no_tda9875 = 1, 2264 .no_tda9875 = 1,
@@ -2131,6 +2267,7 @@ struct tvcard bttv_tvcards[] = {
2131 .no_video = 1, 2267 .no_video = 1,
2132 .has_dvb = 1, 2268 .has_dvb = 1,
2133 .tuner_type = -1, 2269 .tuner_type = -1,
2270 .tuner_addr = ADDR_UNSET,
2134},{ 2271},{
2135 /* Steven <photon38@pchome.com.tw> */ 2272 /* Steven <photon38@pchome.com.tw> */
2136 .name = "V-Gear MyVCD", 2273 .name = "V-Gear MyVCD",
@@ -2144,62 +2281,65 @@ struct tvcard bttv_tvcards[] = {
2144 .no_msp34xx = 1, 2281 .no_msp34xx = 1,
2145 .pll = PLL_28, 2282 .pll = PLL_28,
2146 .tuner_type = TUNER_PHILIPS_NTSC_M, 2283 .tuner_type = TUNER_PHILIPS_NTSC_M,
2284 .tuner_addr = ADDR_UNSET,
2147 .has_radio = 0, 2285 .has_radio = 0,
2148 // .has_remote = 1,
2149},{ 2286},{
2150 /* Rick C <cryptdragoon@gmail.com> */ 2287 /* Rick C <cryptdragoon@gmail.com> */
2151 .name = "Super TV Tuner", 2288 .name = "Super TV Tuner",
2152 .video_inputs = 4, 2289 .video_inputs = 4,
2153 .audio_inputs = 1, 2290 .audio_inputs = 1,
2154 .tuner = 0, 2291 .tuner = 0,
2155 .svhs = 2, 2292 .svhs = 2,
2156 .muxsel = { 2, 3, 1, 0}, 2293 .muxsel = { 2, 3, 1, 0},
2157 .tuner_type = TUNER_PHILIPS_NTSC, 2294 .tuner_type = TUNER_PHILIPS_NTSC,
2158 .gpiomask = 0x008007, 2295 .tuner_addr = ADDR_UNSET,
2159 .audiomux = { 0, 0x000001,0,0, 0}, 2296 .gpiomask = 0x008007,
2160 .needs_tvaudio = 1, 2297 .audiomux = { 0, 0x000001,0,0, 0},
2161 .has_radio = 1, 2298 .needs_tvaudio = 1,
2162},{ 2299 .has_radio = 1,
2163 /* Chris Fanning <video4linux@haydon.net> */ 2300},{
2164 .name = "Tibet Systems 'Progress DVR' CS16", 2301 /* Chris Fanning <video4linux@haydon.net> */
2165 .video_inputs = 16, 2302 .name = "Tibet Systems 'Progress DVR' CS16",
2166 .audio_inputs = 0, 2303 .video_inputs = 16,
2167 .tuner = -1, 2304 .audio_inputs = 0,
2168 .svhs = -1, 2305 .tuner = -1,
2169 .muxsel = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }, 2306 .svhs = -1,
2170 .pll = PLL_28, 2307 .muxsel = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
2171 .no_msp34xx = 1, 2308 .pll = PLL_28,
2172 .no_tda9875 = 1, 2309 .no_msp34xx = 1,
2173 .no_tda7432 = 1, 2310 .no_tda9875 = 1,
2174 .tuner_type = -1, 2311 .no_tda7432 = 1,
2175 .muxsel_hook = tibetCS16_muxsel, 2312 .tuner_type = -1,
2313 .tuner_addr = ADDR_UNSET,
2314 .muxsel_hook = tibetCS16_muxsel,
2176}, 2315},
2177{ 2316{
2178 /* Bill Brack <wbrack@mmm.com.hk> */ 2317 /* Bill Brack <wbrack@mmm.com.hk> */
2179 /* 2318 /*
2180 * Note that, because of the card's wiring, the "master" 2319 * Note that, because of the card's wiring, the "master"
2181 * BT878A chip (i.e. the one which controls the analog switch 2320 * BT878A chip (i.e. the one which controls the analog switch
2182 * and must use this card type) is the 2nd one detected. The 2321 * and must use this card type) is the 2nd one detected. The
2183 * other 3 chips should use card type 0x85, whose description 2322 * other 3 chips should use card type 0x85, whose description
2184 * follows this one. There is a EEPROM on the card (which is 2323 * follows this one. There is a EEPROM on the card (which is
2185 * connected to the I2C of one of those other chips), but is 2324 * connected to the I2C of one of those other chips), but is
2186 * not currently handled. There is also a facility for a 2325 * not currently handled. There is also a facility for a
2187 * "monitor", which is also not currently implemented. 2326 * "monitor", which is also not currently implemented.
2188 */ 2327 */
2189 .name = "Kodicom 4400R (master)", 2328 .name = "Kodicom 4400R (master)",
2190 .video_inputs = 16, 2329 .video_inputs = 16,
2191 .audio_inputs = 0, 2330 .audio_inputs = 0,
2192 .tuner = -1, 2331 .tuner = -1,
2193 .tuner_type = -1, 2332 .tuner_type = -1,
2333 .tuner_addr = ADDR_UNSET,
2194 .svhs = -1, 2334 .svhs = -1,
2195 /* GPIO bits 0-9 used for analog switch: 2335 /* GPIO bits 0-9 used for analog switch:
2196 * 00 - 03: camera selector 2336 * 00 - 03: camera selector
2197 * 04 - 06: channel (controller) selector 2337 * 04 - 06: channel (controller) selector
2198 * 07: data (1->on, 0->off) 2338 * 07: data (1->on, 0->off)
2199 * 08: strobe 2339 * 08: strobe
2200 * 09: reset 2340 * 09: reset
2201 * bit 16 is input from sync separator for the channel 2341 * bit 16 is input from sync separator for the channel
2202 */ 2342 */
2203 .gpiomask = 0x0003ff, 2343 .gpiomask = 0x0003ff,
2204 .no_gpioirq = 1, 2344 .no_gpioirq = 1,
2205 .muxsel = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }, 2345 .muxsel = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
@@ -2212,15 +2352,16 @@ struct tvcard bttv_tvcards[] = {
2212{ 2352{
2213 /* Bill Brack <wbrack@mmm.com.hk> */ 2353 /* Bill Brack <wbrack@mmm.com.hk> */
2214 /* Note that, for reasons unknown, the "master" BT878A chip (i.e. the 2354 /* Note that, for reasons unknown, the "master" BT878A chip (i.e. the
2215 * one which controls the analog switch, and must use the card type) 2355 * one which controls the analog switch, and must use the card type)
2216 * is the 2nd one detected. The other 3 chips should use this card 2356 * is the 2nd one detected. The other 3 chips should use this card
2217 * type 2357 * type
2218 */ 2358 */
2219 .name = "Kodicom 4400R (slave)", 2359 .name = "Kodicom 4400R (slave)",
2220 .video_inputs = 16, 2360 .video_inputs = 16,
2221 .audio_inputs = 0, 2361 .audio_inputs = 0,
2222 .tuner = -1, 2362 .tuner = -1,
2223 .tuner_type = -1, 2363 .tuner_type = -1,
2364 .tuner_addr = ADDR_UNSET,
2224 .svhs = -1, 2365 .svhs = -1,
2225 .gpiomask = 0x010000, 2366 .gpiomask = 0x010000,
2226 .no_gpioirq = 1, 2367 .no_gpioirq = 1,
@@ -2232,18 +2373,51 @@ struct tvcard bttv_tvcards[] = {
2232 .muxsel_hook = kodicom4400r_muxsel, 2373 .muxsel_hook = kodicom4400r_muxsel,
2233}, 2374},
2234{ 2375{
2235 /* ---- card 0x85---------------------------------- */ 2376 /* ---- card 0x86---------------------------------- */
2236 /* Michael Henson <mhenson@clarityvi.com> */ 2377 /* Michael Henson <mhenson@clarityvi.com> */
2237 /* Adlink RTV24 with special unlock codes */ 2378 /* Adlink RTV24 with special unlock codes */
2238 .name = "Adlink RTV24", 2379 .name = "Adlink RTV24",
2239 .video_inputs = 4, 2380 .video_inputs = 4,
2240 .audio_inputs = 1, 2381 .audio_inputs = 1,
2241 .tuner = 0, 2382 .tuner = 0,
2242 .svhs = 2, 2383 .svhs = 2,
2243 .muxsel = { 2, 3, 1, 0}, 2384 .muxsel = { 2, 3, 1, 0},
2244 .tuner_type = -1, 2385 .tuner_type = -1,
2245 .pll = PLL_28, 2386 .tuner_addr = ADDR_UNSET,
2246 2387 .pll = PLL_28,
2388},
2389{
2390 /* ---- card 0x87---------------------------------- */
2391 /* Michael Krufky <mkrufky@m1k.net> */
2392 .name = "DViCO FusionHDTV 5 Lite",
2393 .tuner = 0,
2394 .tuner_type = TUNER_LG_TDVS_H062F,
2395 .tuner_addr = ADDR_UNSET,
2396 .video_inputs = 2,
2397 .audio_inputs = 1,
2398 .svhs = 2,
2399 .muxsel = { 2, 3 },
2400 .gpiomask = 0x00e00007,
2401 .audiomux = { 0x00400005, 0, 0, 0, 0, 0 },
2402 .no_msp34xx = 1,
2403 .no_tda9875 = 1,
2404 .no_tda7432 = 1,
2405},{
2406 /* ---- card 0x88---------------------------------- */
2407 /* Mauro Carvalho Chehab <mchehab@brturbo.com.br> */
2408 .name = "Acorp Y878F",
2409 .video_inputs = 3,
2410 .audio_inputs = 1,
2411 .tuner = 0,
2412 .svhs = 2,
2413 .gpiomask = 0x01fe00,
2414 .muxsel = { 2, 3, 1, 1},
2415 .audiomux = { 0x001e00, 0, 0x018000, 0x014000, 0x002000, 0 },
2416 .needs_tvaudio = 1,
2417 .pll = PLL_28,
2418 .tuner_type = TUNER_YMEC_TVF66T5_B_DFF,
2419 .tuner_addr = 0xc1 >>1,
2420 .has_radio = 1,
2247}}; 2421}};
2248 2422
2249static const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards); 2423static const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards);
@@ -2355,32 +2529,32 @@ static void flyvideo_gpio(struct bttv *btv)
2355 int tuner=-1,ttype; 2529 int tuner=-1,ttype;
2356 2530
2357 gpio_inout(0xffffff, 0); 2531 gpio_inout(0xffffff, 0);
2358 udelay(8); // without this we would see the 0x1800 mask 2532 udelay(8); /* without this we would see the 0x1800 mask */
2359 gpio = gpio_read(); 2533 gpio = gpio_read();
2360 /* FIXME: must restore OUR_EN ??? */ 2534 /* FIXME: must restore OUR_EN ??? */
2361 2535
2362 // all cards provide GPIO info, some have an additional eeprom 2536 /* all cards provide GPIO info, some have an additional eeprom
2363 // LR50: GPIO coding can be found lower right CP1 .. CP9 2537 * LR50: GPIO coding can be found lower right CP1 .. CP9
2364 // CP9=GPIO23 .. CP1=GPIO15; when OPEN, the corresponding GPIO reads 1. 2538 * CP9=GPIO23 .. CP1=GPIO15; when OPEN, the corresponding GPIO reads 1.
2365 // GPIO14-12: n.c. 2539 * GPIO14-12: n.c.
2366 // LR90: GP9=GPIO23 .. GP1=GPIO15 (right above the bt878) 2540 * LR90: GP9=GPIO23 .. GP1=GPIO15 (right above the bt878)
2367
2368 // lowest 3 bytes are remote control codes (no handshake needed)
2369 // xxxFFF: No remote control chip soldered
2370 // xxxF00(LR26/LR50), xxxFE0(LR90): Remote control chip (LVA001 or CF45) soldered
2371 // Note: Some bits are Audio_Mask !
2372 2541
2542 * lowest 3 bytes are remote control codes (no handshake needed)
2543 * xxxFFF: No remote control chip soldered
2544 * xxxF00(LR26/LR50), xxxFE0(LR90): Remote control chip (LVA001 or CF45) soldered
2545 * Note: Some bits are Audio_Mask !
2546 */
2373 ttype=(gpio&0x0f0000)>>16; 2547 ttype=(gpio&0x0f0000)>>16;
2374 switch(ttype) { 2548 switch(ttype) {
2375 case 0x0: tuner=2; // NTSC, e.g. TPI8NSR11P 2549 case 0x0: tuner=2; /* NTSC, e.g. TPI8NSR11P */
2376 break; 2550 break;
2377 case 0x2: tuner=39;// LG NTSC (newer TAPC series) TAPC-H701P 2551 case 0x2: tuner=39;/* LG NTSC (newer TAPC series) TAPC-H701P */
2378 break; 2552 break;
2379 case 0x4: tuner=5; // Philips PAL TPI8PSB02P, TPI8PSB12P, TPI8PSB12D or FI1216, FM1216 2553 case 0x4: tuner=5; /* Philips PAL TPI8PSB02P, TPI8PSB12P, TPI8PSB12D or FI1216, FM1216 */
2380 break; 2554 break;
2381 case 0x6: tuner=37; // LG PAL (newer TAPC series) TAPC-G702P 2555 case 0x6: tuner=37;/* LG PAL (newer TAPC series) TAPC-G702P */
2382 break; 2556 break;
2383 case 0xC: tuner=3; // Philips SECAM(+PAL) FQ1216ME or FI1216MF 2557 case 0xC: tuner=3; /* Philips SECAM(+PAL) FQ1216ME or FI1216MF */
2384 break; 2558 break;
2385 default: 2559 default:
2386 printk(KERN_INFO "bttv%d: FlyVideo_gpio: unknown tuner type.\n", btv->c.nr); 2560 printk(KERN_INFO "bttv%d: FlyVideo_gpio: unknown tuner type.\n", btv->c.nr);
@@ -2388,15 +2562,16 @@ static void flyvideo_gpio(struct bttv *btv)
2388 2562
2389 has_remote = gpio & 0x800000; 2563 has_remote = gpio & 0x800000;
2390 has_radio = gpio & 0x400000; 2564 has_radio = gpio & 0x400000;
2391 // unknown 0x200000; 2565 /* unknown 0x200000;
2392 // unknown2 0x100000; 2566 * unknown2 0x100000; */
2393 is_capture_only = !(gpio & 0x008000); //GPIO15 2567 is_capture_only = !(gpio & 0x008000); /* GPIO15 */
2394 has_tda9820_tda9821 = !(gpio & 0x004000); 2568 has_tda9820_tda9821 = !(gpio & 0x004000);
2395 is_lr90 = !(gpio & 0x002000); // else LR26/LR50 (LR38/LR51 f. capture only) 2569 is_lr90 = !(gpio & 0x002000); /* else LR26/LR50 (LR38/LR51 f. capture only) */
2396 // gpio & 0x001000 // output bit for audio routing 2570 /*
2571 * gpio & 0x001000 output bit for audio routing */
2397 2572
2398 if(is_capture_only) 2573 if(is_capture_only)
2399 tuner=4; // No tuner present 2574 tuner=4; /* No tuner present */
2400 2575
2401 printk(KERN_INFO "bttv%d: FlyVideo Radio=%s RemoteControl=%s Tuner=%d gpio=0x%06x\n", 2576 printk(KERN_INFO "bttv%d: FlyVideo Radio=%s RemoteControl=%s Tuner=%d gpio=0x%06x\n",
2402 btv->c.nr, has_radio? "yes":"no ", has_remote? "yes":"no ", tuner, gpio); 2577 btv->c.nr, has_radio? "yes":"no ", has_remote? "yes":"no ", tuner, gpio);
@@ -2404,15 +2579,15 @@ static void flyvideo_gpio(struct bttv *btv)
2404 btv->c.nr, is_lr90?"yes":"no ", has_tda9820_tda9821?"yes":"no ", 2579 btv->c.nr, is_lr90?"yes":"no ", has_tda9820_tda9821?"yes":"no ",
2405 is_capture_only?"yes":"no "); 2580 is_capture_only?"yes":"no ");
2406 2581
2407 if(tuner!= -1) // only set if known tuner autodetected, else let insmod option through 2582 if(tuner!= -1) /* only set if known tuner autodetected, else let insmod option through */
2408 btv->tuner_type = tuner; 2583 btv->tuner_type = tuner;
2409 btv->has_radio = has_radio; 2584 btv->has_radio = has_radio;
2410 2585
2411 // LR90 Audio Routing is done by 2 hef4052, so Audio_Mask has 4 bits: 0x001c80 2586 /* LR90 Audio Routing is done by 2 hef4052, so Audio_Mask has 4 bits: 0x001c80
2412 // LR26/LR50 only has 1 hef4052, Audio_Mask 0x000c00 2587 * LR26/LR50 only has 1 hef4052, Audio_Mask 0x000c00
2413 // Audio options: from tuner, from tda9821/tda9821(mono,stereo,sap), from tda9874, ext., mute 2588 * Audio options: from tuner, from tda9821/tda9821(mono,stereo,sap), from tda9874, ext., mute */
2414 if(has_tda9820_tda9821) btv->audio_hook = lt9415_audio; 2589 if(has_tda9820_tda9821) btv->audio_hook = lt9415_audio;
2415 //todo: if(has_tda9874) btv->audio_hook = fv2000s_audio; 2590 /* todo: if(has_tda9874) btv->audio_hook = fv2000s_audio; */
2416} 2591}
2417 2592
2418static int miro_tunermap[] = { 0,6,2,3, 4,5,6,0, 3,0,4,5, 5,2,16,1, 2593static int miro_tunermap[] = { 0,6,2,3, 4,5,6,0, 3,0,4,5, 5,2,16,1,
@@ -2633,6 +2808,8 @@ void __devinit bttv_init_card1(struct bttv *btv)
2633void __devinit bttv_init_card2(struct bttv *btv) 2808void __devinit bttv_init_card2(struct bttv *btv)
2634{ 2809{
2635 int tda9887; 2810 int tda9887;
2811 int addr=ADDR_UNSET;
2812
2636 btv->tuner_type = -1; 2813 btv->tuner_type = -1;
2637 2814
2638 if (BTTV_UNKNOWN == btv->c.type) { 2815 if (BTTV_UNKNOWN == btv->c.type) {
@@ -2773,9 +2950,12 @@ void __devinit bttv_init_card2(struct bttv *btv)
2773 btv->pll.pll_current = -1; 2950 btv->pll.pll_current = -1;
2774 2951
2775 /* tuner configuration (from card list / autodetect / insmod option) */ 2952 /* tuner configuration (from card list / autodetect / insmod option) */
2776 if (UNSET != bttv_tvcards[btv->c.type].tuner_type) 2953 if (ADDR_UNSET != bttv_tvcards[btv->c.type].tuner_addr)
2954 addr = bttv_tvcards[btv->c.type].tuner_addr;
2955
2956 if (UNSET != bttv_tvcards[btv->c.type].tuner_type)
2777 if(UNSET == btv->tuner_type) 2957 if(UNSET == btv->tuner_type)
2778 btv->tuner_type = bttv_tvcards[btv->c.type].tuner_type; 2958 btv->tuner_type = bttv_tvcards[btv->c.type].tuner_type;
2779 if (UNSET != tuner[btv->c.nr]) 2959 if (UNSET != tuner[btv->c.nr])
2780 btv->tuner_type = tuner[btv->c.nr]; 2960 btv->tuner_type = tuner[btv->c.nr];
2781 printk("bttv%d: using tuner=%d\n",btv->c.nr,btv->tuner_type); 2961 printk("bttv%d: using tuner=%d\n",btv->c.nr,btv->tuner_type);
@@ -2787,7 +2967,7 @@ void __devinit bttv_init_card2(struct bttv *btv)
2787 2967
2788 tun_setup.mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV; 2968 tun_setup.mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
2789 tun_setup.type = btv->tuner_type; 2969 tun_setup.type = btv->tuner_type;
2790 tun_setup.addr = ADDR_UNSET; 2970 tun_setup.addr = addr;
2791 2971
2792 bttv_call_i2c_clients(btv, TUNER_SET_TYPE_ADDR, &tun_setup); 2972 bttv_call_i2c_clients(btv, TUNER_SET_TYPE_ADDR, &tun_setup);
2793 } 2973 }
@@ -2880,7 +3060,7 @@ static void __devinit hauppauge_eeprom(struct bttv *btv)
2880{ 3060{
2881 struct tveeprom tv; 3061 struct tveeprom tv;
2882 3062
2883 tveeprom_hauppauge_analog(&tv, eeprom_data); 3063 tveeprom_hauppauge_analog(&btv->i2c_client, &tv, eeprom_data);
2884 btv->tuner_type = tv.tuner_type; 3064 btv->tuner_type = tv.tuner_type;
2885 btv->has_radio = tv.has_radio; 3065 btv->has_radio = tv.has_radio;
2886} 3066}
@@ -2902,7 +3082,7 @@ static int terratec_active_radio_upgrade(struct bttv *btv)
2902 btv->mbox_csel = 1 << 10; 3082 btv->mbox_csel = 1 << 10;
2903 3083
2904 freq=88000/62.5; 3084 freq=88000/62.5;
2905 tea5757_write(btv, 5 * freq + 0x358); // write 0x1ed8 3085 tea5757_write(btv, 5 * freq + 0x358); /* write 0x1ed8 */
2906 if (0x1ed8 == tea5757_read(btv)) { 3086 if (0x1ed8 == tea5757_read(btv)) {
2907 printk("bttv%d: Terratec Active Radio Upgrade found.\n", 3087 printk("bttv%d: Terratec Active Radio Upgrade found.\n",
2908 btv->c.nr); 3088 btv->c.nr);
@@ -3073,7 +3253,7 @@ static void __devinit osprey_eeprom(struct bttv *btv)
3073 case 0x0060: 3253 case 0x0060:
3074 case 0x0070: 3254 case 0x0070:
3075 btv->c.type = BTTV_OSPREY2x0; 3255 btv->c.type = BTTV_OSPREY2x0;
3076 //enable output on select control lines 3256 /* enable output on select control lines */
3077 gpio_inout(0xffffff,0x000303); 3257 gpio_inout(0xffffff,0x000303);
3078 break; 3258 break;
3079 default: 3259 default:
@@ -3105,7 +3285,7 @@ static int tuner_1_table[] = {
3105 TUNER_TEMIC_NTSC, TUNER_TEMIC_PAL, 3285 TUNER_TEMIC_NTSC, TUNER_TEMIC_PAL,
3106 TUNER_TEMIC_PAL, TUNER_TEMIC_PAL, 3286 TUNER_TEMIC_PAL, TUNER_TEMIC_PAL,
3107 TUNER_TEMIC_PAL, TUNER_TEMIC_PAL, 3287 TUNER_TEMIC_PAL, TUNER_TEMIC_PAL,
3108 TUNER_TEMIC_4012FY5, TUNER_TEMIC_4012FY5, //TUNER_TEMIC_SECAM 3288 TUNER_TEMIC_4012FY5, TUNER_TEMIC_4012FY5, /* TUNER_TEMIC_SECAM */
3109 TUNER_TEMIC_4012FY5, TUNER_TEMIC_PAL}; 3289 TUNER_TEMIC_4012FY5, TUNER_TEMIC_PAL};
3110 3290
3111static void __devinit avermedia_eeprom(struct bttv *btv) 3291static void __devinit avermedia_eeprom(struct bttv *btv)
@@ -3126,7 +3306,7 @@ static void __devinit avermedia_eeprom(struct bttv *btv)
3126 3306
3127 if (tuner_make == 4) 3307 if (tuner_make == 4)
3128 if(tuner_format == 0x09) 3308 if(tuner_format == 0x09)
3129 tuner = TUNER_LG_NTSC_NEW_TAPC; // TAPC-G702P 3309 tuner = TUNER_LG_NTSC_NEW_TAPC; /* TAPC-G702P */
3130 3310
3131 printk(KERN_INFO "bttv%d: Avermedia eeprom[0x%02x%02x]: tuner=", 3311 printk(KERN_INFO "bttv%d: Avermedia eeprom[0x%02x%02x]: tuner=",
3132 btv->c.nr,eeprom_data[0x41],eeprom_data[0x42]); 3312 btv->c.nr,eeprom_data[0x41],eeprom_data[0x42]);
@@ -3143,7 +3323,7 @@ static void __devinit avermedia_eeprom(struct bttv *btv)
3143/* used on Voodoo TV/FM (Voodoo 200), S0 wired to 0x10000 */ 3323/* used on Voodoo TV/FM (Voodoo 200), S0 wired to 0x10000 */
3144void bttv_tda9880_setnorm(struct bttv *btv, int norm) 3324void bttv_tda9880_setnorm(struct bttv *btv, int norm)
3145{ 3325{
3146 // fix up our card entry 3326 /* fix up our card entry */
3147 if(norm==VIDEO_MODE_NTSC) { 3327 if(norm==VIDEO_MODE_NTSC) {
3148 bttv_tvcards[BTTV_VOODOOTV_FM].audiomux[0]=0x957fff; 3328 bttv_tvcards[BTTV_VOODOOTV_FM].audiomux[0]=0x957fff;
3149 bttv_tvcards[BTTV_VOODOOTV_FM].audiomux[4]=0x957fff; 3329 bttv_tvcards[BTTV_VOODOOTV_FM].audiomux[4]=0x957fff;
@@ -3154,7 +3334,7 @@ void bttv_tda9880_setnorm(struct bttv *btv, int norm)
3154 bttv_tvcards[BTTV_VOODOOTV_FM].audiomux[4]=0x947fff; 3334 bttv_tvcards[BTTV_VOODOOTV_FM].audiomux[4]=0x947fff;
3155 dprintk("bttv_tda9880_setnorm to PAL\n"); 3335 dprintk("bttv_tda9880_setnorm to PAL\n");
3156 } 3336 }
3157 // set GPIO according 3337 /* set GPIO according */
3158 gpio_bits(bttv_tvcards[btv->c.type].gpiomask, 3338 gpio_bits(bttv_tvcards[btv->c.type].gpiomask,
3159 bttv_tvcards[btv->c.type].audiomux[btv->audio]); 3339 bttv_tvcards[btv->c.type].audiomux[btv->audio]);
3160} 3340}
@@ -3447,7 +3627,7 @@ static int tea5757_read(struct bttv *btv)
3447 udelay(10); 3627 udelay(10);
3448 timeout= jiffies + HZ; 3628 timeout= jiffies + HZ;
3449 3629
3450 // wait for DATA line to go low; error if it doesn't 3630 /* wait for DATA line to go low; error if it doesn't */
3451 while (bus_in(btv,btv->mbox_data) && time_before(jiffies, timeout)) 3631 while (bus_in(btv,btv->mbox_data) && time_before(jiffies, timeout))
3452 schedule(); 3632 schedule();
3453 if (bus_in(btv,btv->mbox_data)) { 3633 if (bus_in(btv,btv->mbox_data)) {
@@ -3574,8 +3754,8 @@ gvbctv3pci_audio(struct bttv *btv, struct video_audio *v, int set)
3574 con = 0x300; 3754 con = 0x300;
3575 if (v->mode & VIDEO_SOUND_STEREO) 3755 if (v->mode & VIDEO_SOUND_STEREO)
3576 con = 0x200; 3756 con = 0x200;
3577// if (v->mode & VIDEO_SOUND_MONO) 3757/* if (v->mode & VIDEO_SOUND_MONO)
3578// con = 0x100; 3758 * con = 0x100; */
3579 gpio_bits(0x300, con); 3759 gpio_bits(0x300, con);
3580 } else { 3760 } else {
3581 v->mode = VIDEO_SOUND_STEREO | 3761 v->mode = VIDEO_SOUND_STEREO |
@@ -3718,7 +3898,7 @@ lt9415_audio(struct bttv *btv, struct video_audio *v, int set)
3718 } 3898 }
3719} 3899}
3720 3900
3721// TDA9821 on TerraTV+ Bt848, Bt878 3901/* TDA9821 on TerraTV+ Bt848, Bt878 */
3722static void 3902static void
3723terratv_audio(struct bttv *btv, struct video_audio *v, int set) 3903terratv_audio(struct bttv *btv, struct video_audio *v, int set)
3724{ 3904{
@@ -3818,7 +3998,7 @@ fv2000s_audio(struct bttv *btv, struct video_audio *v, int set)
3818 } 3998 }
3819 if ((v->mode & (VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2)) 3999 if ((v->mode & (VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2))
3820 || (v->mode & VIDEO_SOUND_STEREO)) { 4000 || (v->mode & VIDEO_SOUND_STEREO)) {
3821 val = 0x1080; //-dk-???: 0x0880, 0x0080, 0x1800 ... 4001 val = 0x1080; /*-dk-???: 0x0880, 0x0080, 0x1800 ... */
3822 } 4002 }
3823 if (val != 0xffff) { 4003 if (val != 0xffff) {
3824 gpio_bits(0x1800, val); 4004 gpio_bits(0x1800, val);
@@ -3869,10 +4049,10 @@ adtvk503_audio(struct bttv *btv, struct video_audio *v, int set)
3869{ 4049{
3870 unsigned int con = 0xffffff; 4050 unsigned int con = 0xffffff;
3871 4051
3872 //btaor(0x1e0000, ~0x1e0000, BT848_GPIO_OUT_EN); 4052 /* btaor(0x1e0000, ~0x1e0000, BT848_GPIO_OUT_EN); */
3873 4053
3874 if (set) { 4054 if (set) {
3875 //btor(***, BT848_GPIO_OUT_EN); 4055 /* btor(***, BT848_GPIO_OUT_EN); */
3876 if (v->mode & VIDEO_SOUND_LANG1) 4056 if (v->mode & VIDEO_SOUND_LANG1)
3877 con = 0x00000000; 4057 con = 0x00000000;
3878 if (v->mode & VIDEO_SOUND_LANG2) 4058 if (v->mode & VIDEO_SOUND_LANG2)
@@ -4079,14 +4259,14 @@ static void kodicom4400r_init(struct bttv *btv)
4079 master[btv->c.nr+2] = btv; 4259 master[btv->c.nr+2] = btv;
4080} 4260}
4081 4261
4082// The Grandtec X-Guard framegrabber card uses two Dual 4-channel 4262/* The Grandtec X-Guard framegrabber card uses two Dual 4-channel
4083// video multiplexers to provide up to 16 video inputs. These 4263 * video multiplexers to provide up to 16 video inputs. These
4084// multiplexers are controlled by the lower 8 GPIO pins of the 4264 * multiplexers are controlled by the lower 8 GPIO pins of the
4085// bt878. The multiplexers probably Pericom PI5V331Q or similar. 4265 * bt878. The multiplexers probably Pericom PI5V331Q or similar.
4086
4087// xxx0 is pin xxx of multiplexer U5,
4088// yyy1 is pin yyy of multiplexer U2
4089 4266
4267 * xxx0 is pin xxx of multiplexer U5,
4268 * yyy1 is pin yyy of multiplexer U2
4269 */
4090#define ENA0 0x01 4270#define ENA0 0x01
4091#define ENB0 0x02 4271#define ENB0 0x02
4092#define ENA1 0x04 4272#define ENA1 0x04
@@ -4157,14 +4337,14 @@ static void picolo_tetra_muxsel (struct bttv* btv, unsigned int input)
4157 4337
4158static void ivc120_muxsel(struct bttv *btv, unsigned int input) 4338static void ivc120_muxsel(struct bttv *btv, unsigned int input)
4159{ 4339{
4160 // Simple maths 4340 /* Simple maths */
4161 int key = input % 4; 4341 int key = input % 4;
4162 int matrix = input / 4; 4342 int matrix = input / 4;
4163 4343
4164 dprintk("bttv%d: ivc120_muxsel: Input - %02d | TDA - %02d | In - %02d\n", 4344 dprintk("bttv%d: ivc120_muxsel: Input - %02d | TDA - %02d | In - %02d\n",
4165 btv->c.nr, input, matrix, key); 4345 btv->c.nr, input, matrix, key);
4166 4346
4167 // Handles the input selection on the TDA8540's 4347 /* Handles the input selection on the TDA8540's */
4168 bttv_I2CWrite(btv, I2C_TDA8540_ALT3, 0x00, 4348 bttv_I2CWrite(btv, I2C_TDA8540_ALT3, 0x00,
4169 ((matrix == 3) ? (key | key << 2) : 0x00), 1); 4349 ((matrix == 3) ? (key | key << 2) : 0x00), 1);
4170 bttv_I2CWrite(btv, I2C_TDA8540_ALT4, 0x00, 4350 bttv_I2CWrite(btv, I2C_TDA8540_ALT4, 0x00,
@@ -4174,17 +4354,17 @@ static void ivc120_muxsel(struct bttv *btv, unsigned int input)
4174 bttv_I2CWrite(btv, I2C_TDA8540_ALT6, 0x00, 4354 bttv_I2CWrite(btv, I2C_TDA8540_ALT6, 0x00,
4175 ((matrix == 2) ? (key | key << 2) : 0x00), 1); 4355 ((matrix == 2) ? (key | key << 2) : 0x00), 1);
4176 4356
4177 // Handles the output enables on the TDA8540's 4357 /* Handles the output enables on the TDA8540's */
4178 bttv_I2CWrite(btv, I2C_TDA8540_ALT3, 0x02, 4358 bttv_I2CWrite(btv, I2C_TDA8540_ALT3, 0x02,
4179 ((matrix == 3) ? 0x03 : 0x00), 1); // 13 - 16 4359 ((matrix == 3) ? 0x03 : 0x00), 1); /* 13 - 16 */
4180 bttv_I2CWrite(btv, I2C_TDA8540_ALT4, 0x02, 4360 bttv_I2CWrite(btv, I2C_TDA8540_ALT4, 0x02,
4181 ((matrix == 0) ? 0x03 : 0x00), 1); // 1-4 4361 ((matrix == 0) ? 0x03 : 0x00), 1); /* 1-4 */
4182 bttv_I2CWrite(btv, I2C_TDA8540_ALT5, 0x02, 4362 bttv_I2CWrite(btv, I2C_TDA8540_ALT5, 0x02,
4183 ((matrix == 1) ? 0x03 : 0x00), 1); // 5-8 4363 ((matrix == 1) ? 0x03 : 0x00), 1); /* 5-8 */
4184 bttv_I2CWrite(btv, I2C_TDA8540_ALT6, 0x02, 4364 bttv_I2CWrite(btv, I2C_TDA8540_ALT6, 0x02,
4185 ((matrix == 2) ? 0x03 : 0x00), 1); // 9-12 4365 ((matrix == 2) ? 0x03 : 0x00), 1); /* 9-12 */
4186 4366
4187 // Selects MUX0 for input on the 878 4367 /* Selects MUX0 for input on the 878 */
4188 btaor((0)<<5, ~(3<<5), BT848_IFORM); 4368 btaor((0)<<5, ~(3<<5), BT848_IFORM);
4189} 4369}
4190 4370
diff --git a/drivers/media/video/bttv-driver.c b/drivers/media/video/bttv-driver.c
index 087efb4dea..a564321db2 100644
--- a/drivers/media/video/bttv-driver.c
+++ b/drivers/media/video/bttv-driver.c
@@ -1,5 +1,4 @@
1/* 1/*
2 $Id: bttv-driver.c,v 1.52 2005/08/04 00:55:16 mchehab Exp $
3 2
4 bttv - Bt848 frame grabber driver 3 bttv - Bt848 frame grabber driver
5 4
@@ -42,6 +41,9 @@
42 41
43#include "bttvp.h" 42#include "bttvp.h"
44 43
44#include "rds.h"
45
46
45unsigned int bttv_num; /* number of Bt848s in use */ 47unsigned int bttv_num; /* number of Bt848s in use */
46struct bttv bttvs[BTTV_MAX]; 48struct bttv bttvs[BTTV_MAX];
47 49
@@ -3128,15 +3130,12 @@ static int radio_open(struct inode *inode, struct file *file)
3128 3130
3129 dprintk("bttv%d: open called (radio)\n",btv->c.nr); 3131 dprintk("bttv%d: open called (radio)\n",btv->c.nr);
3130 down(&btv->lock); 3132 down(&btv->lock);
3131 if (btv->radio_user) { 3133
3132 up(&btv->lock);
3133 return -EBUSY;
3134 }
3135 btv->radio_user++; 3134 btv->radio_user++;
3135
3136 file->private_data = btv; 3136 file->private_data = btv;
3137 3137
3138 i2c_vidiocschan(btv); 3138 bttv_call_i2c_clients(btv,AUDC_SET_RADIO,&btv->tuner_type);
3139 bttv_call_i2c_clients(btv,AUDC_SET_RADIO,&btv->tuner_type);
3140 audio_mux(btv,AUDIO_RADIO); 3139 audio_mux(btv,AUDIO_RADIO);
3141 3140
3142 up(&btv->lock); 3141 up(&btv->lock);
@@ -3145,9 +3144,13 @@ static int radio_open(struct inode *inode, struct file *file)
3145 3144
3146static int radio_release(struct inode *inode, struct file *file) 3145static int radio_release(struct inode *inode, struct file *file)
3147{ 3146{
3148 struct bttv *btv = file->private_data; 3147 struct bttv *btv = file->private_data;
3148 struct rds_command cmd;
3149 3149
3150 btv->radio_user--; 3150 btv->radio_user--;
3151
3152 bttv_call_i2c_clients(btv, RDS_CMD_CLOSE, &cmd);
3153
3151 return 0; 3154 return 0;
3152} 3155}
3153 3156
@@ -3203,13 +3206,42 @@ static int radio_ioctl(struct inode *inode, struct file *file,
3203 return video_usercopy(inode, file, cmd, arg, radio_do_ioctl); 3206 return video_usercopy(inode, file, cmd, arg, radio_do_ioctl);
3204} 3207}
3205 3208
3209static ssize_t radio_read(struct file *file, char __user *data,
3210 size_t count, loff_t *ppos)
3211{
3212 struct bttv *btv = file->private_data;
3213 struct rds_command cmd;
3214 cmd.block_count = count/3;
3215 cmd.buffer = data;
3216 cmd.instance = file;
3217 cmd.result = -ENODEV;
3218
3219 bttv_call_i2c_clients(btv, RDS_CMD_READ, &cmd);
3220
3221 return cmd.result;
3222}
3223
3224static unsigned int radio_poll(struct file *file, poll_table *wait)
3225{
3226 struct bttv *btv = file->private_data;
3227 struct rds_command cmd;
3228 cmd.instance = file;
3229 cmd.event_list = wait;
3230 cmd.result = -ENODEV;
3231 bttv_call_i2c_clients(btv, RDS_CMD_POLL, &cmd);
3232
3233 return cmd.result;
3234}
3235
3206static struct file_operations radio_fops = 3236static struct file_operations radio_fops =
3207{ 3237{
3208 .owner = THIS_MODULE, 3238 .owner = THIS_MODULE,
3209 .open = radio_open, 3239 .open = radio_open,
3240 .read = radio_read,
3210 .release = radio_release, 3241 .release = radio_release,
3211 .ioctl = radio_ioctl, 3242 .ioctl = radio_ioctl,
3212 .llseek = no_llseek, 3243 .llseek = no_llseek,
3244 .poll = radio_poll,
3213}; 3245};
3214 3246
3215static struct video_device radio_template = 3247static struct video_device radio_template =
@@ -4047,6 +4079,7 @@ static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state)
4047 struct bttv_buffer_set idle; 4079 struct bttv_buffer_set idle;
4048 unsigned long flags; 4080 unsigned long flags;
4049 4081
4082 dprintk("bttv%d: suspend %d\n", btv->c.nr, state.event);
4050 4083
4051 /* stop dma + irqs */ 4084 /* stop dma + irqs */
4052 spin_lock_irqsave(&btv->s_lock,flags); 4085 spin_lock_irqsave(&btv->s_lock,flags);
@@ -4079,15 +4112,29 @@ static int bttv_resume(struct pci_dev *pci_dev)
4079{ 4112{
4080 struct bttv *btv = pci_get_drvdata(pci_dev); 4113 struct bttv *btv = pci_get_drvdata(pci_dev);
4081 unsigned long flags; 4114 unsigned long flags;
4115 int err;
4082 4116
4083 dprintk("bttv%d: resume\n", btv->c.nr); 4117 dprintk("bttv%d: resume\n", btv->c.nr);
4084 4118
4085 /* restore pci state */ 4119 /* restore pci state */
4086 if (btv->state.disabled) { 4120 if (btv->state.disabled) {
4087 pci_enable_device(pci_dev); 4121 err=pci_enable_device(pci_dev);
4122 if (err) {
4123 printk(KERN_WARNING "bttv%d: Can't enable device.\n",
4124 btv->c.nr);
4125 return err;
4126 }
4088 btv->state.disabled = 0; 4127 btv->state.disabled = 0;
4089 } 4128 }
4090 pci_set_power_state(pci_dev, PCI_D0); 4129 err=pci_set_power_state(pci_dev, PCI_D0);
4130 if (err) {
4131 pci_disable_device(pci_dev);
4132 printk(KERN_WARNING "bttv%d: Can't enable device.\n",
4133 btv->c.nr);
4134 btv->state.disabled = 1;
4135 return err;
4136 }
4137
4091 pci_restore_state(pci_dev); 4138 pci_restore_state(pci_dev);
4092 4139
4093 /* restore bt878 state */ 4140 /* restore bt878 state */
diff --git a/drivers/media/video/bttv-gpio.c b/drivers/media/video/bttv-gpio.c
index 77320cdf20..6b280c03e3 100644
--- a/drivers/media/video/bttv-gpio.c
+++ b/drivers/media/video/bttv-gpio.c
@@ -1,5 +1,4 @@
1/* 1/*
2 $Id: bttv-gpio.c,v 1.7 2005/02/16 12:14:10 kraxel Exp $
3 2
4 bttv-gpio.c -- gpio sub drivers 3 bttv-gpio.c -- gpio sub drivers
5 4
diff --git a/drivers/media/video/bttv-i2c.c b/drivers/media/video/bttv-i2c.c
index 706dc48df9..e684df37eb 100644
--- a/drivers/media/video/bttv-i2c.c
+++ b/drivers/media/video/bttv-i2c.c
@@ -1,5 +1,4 @@
1/* 1/*
2 $Id: bttv-i2c.c,v 1.25 2005/07/05 17:37:35 nsh Exp $
3 2
4 bttv-i2c.c -- all the i2c code is here 3 bttv-i2c.c -- all the i2c code is here
5 4
@@ -381,6 +380,7 @@ void __devinit bttv_readee(struct bttv *btv, unsigned char *eedata, int addr)
381} 380}
382 381
383static char *i2c_devs[128] = { 382static char *i2c_devs[128] = {
383 [ 0x1c >> 1 ] = "lgdt330x",
384 [ 0x30 >> 1 ] = "IR (hauppauge)", 384 [ 0x30 >> 1 ] = "IR (hauppauge)",
385 [ 0x80 >> 1 ] = "msp34xx", 385 [ 0x80 >> 1 ] = "msp34xx",
386 [ 0x86 >> 1 ] = "tda9887", 386 [ 0x86 >> 1 ] = "tda9887",
diff --git a/drivers/media/video/bttv-if.c b/drivers/media/video/bttv-if.c
index f7b5543a96..e8aada772b 100644
--- a/drivers/media/video/bttv-if.c
+++ b/drivers/media/video/bttv-if.c
@@ -1,5 +1,4 @@
1/* 1/*
2 $Id: bttv-if.c,v 1.4 2004/11/17 18:47:47 kraxel Exp $
3 2
4 bttv-if.c -- old gpio interface to other kernel modules 3 bttv-if.c -- old gpio interface to other kernel modules
5 don't use in new code, will go away in 2.7 4 don't use in new code, will go away in 2.7
diff --git a/drivers/media/video/bttv-risc.c b/drivers/media/video/bttv-risc.c
index 9ed21fd190..a5ed99b894 100644
--- a/drivers/media/video/bttv-risc.c
+++ b/drivers/media/video/bttv-risc.c
@@ -1,5 +1,4 @@
1/* 1/*
2 $Id: bttv-risc.c,v 1.10 2004/11/19 18:07:12 kraxel Exp $
3 2
4 bttv-risc.c -- interfaces to other kernel modules 3 bttv-risc.c -- interfaces to other kernel modules
5 4
diff --git a/drivers/media/video/bttv-vbi.c b/drivers/media/video/bttv-vbi.c
index 06f3e62b3e..f4f58c60f1 100644
--- a/drivers/media/video/bttv-vbi.c
+++ b/drivers/media/video/bttv-vbi.c
@@ -1,5 +1,4 @@
1/* 1/*
2 $Id: bttv-vbi.c,v 1.9 2005/01/13 17:22:33 kraxel Exp $
3 2
4 bttv - Bt848 frame grabber driver 3 bttv - Bt848 frame grabber driver
5 vbi interface 4 vbi interface
diff --git a/drivers/media/video/bttv.h b/drivers/media/video/bttv.h
index f2af9e1454..d254e90e3b 100644
--- a/drivers/media/video/bttv.h
+++ b/drivers/media/video/bttv.h
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: bttv.h,v 1.22 2005/07/28 18:41:21 mchehab Exp $
3 * 2 *
4 * bttv - Bt848 frame grabber driver 3 * bttv - Bt848 frame grabber driver
5 * 4 *
@@ -218,6 +217,8 @@ struct tvcard
218#define PLL_35 2 217#define PLL_35 2
219 218
220 unsigned int tuner_type; 219 unsigned int tuner_type;
220 unsigned int tuner_addr;
221
221 unsigned int has_radio; 222 unsigned int has_radio;
222 void (*audio_hook)(struct bttv *btv, struct video_audio *v, int set); 223 void (*audio_hook)(struct bttv *btv, struct video_audio *v, int set);
223 void (*muxsel_hook)(struct bttv *btv, unsigned int input); 224 void (*muxsel_hook)(struct bttv *btv, unsigned int input);
diff --git a/drivers/media/video/bttvp.h b/drivers/media/video/bttvp.h
index aab094bc24..9b0b7ca035 100644
--- a/drivers/media/video/bttvp.h
+++ b/drivers/media/video/bttvp.h
@@ -1,5 +1,4 @@
1/* 1/*
2 $Id: bttvp.h,v 1.21 2005/07/15 21:44:14 mchehab Exp $
3 2
4 bttv - Bt848 frame grabber driver 3 bttv - Bt848 frame grabber driver
5 4
diff --git a/drivers/media/video/cpia_usb.c b/drivers/media/video/cpia_usb.c
index cdda423386..9774e94d1e 100644
--- a/drivers/media/video/cpia_usb.c
+++ b/drivers/media/video/cpia_usb.c
@@ -445,10 +445,8 @@ static void cpia_usb_free_resources(struct usb_cpia *ucpia, int try)
445 ucpia->sbuf[1].urb = NULL; 445 ucpia->sbuf[1].urb = NULL;
446 } 446 }
447 447
448 if (ucpia->sbuf[1].data) { 448 kfree(ucpia->sbuf[1].data);
449 kfree(ucpia->sbuf[1].data); 449 ucpia->sbuf[1].data = NULL;
450 ucpia->sbuf[1].data = NULL;
451 }
452 450
453 if (ucpia->sbuf[0].urb) { 451 if (ucpia->sbuf[0].urb) {
454 usb_kill_urb(ucpia->sbuf[0].urb); 452 usb_kill_urb(ucpia->sbuf[0].urb);
@@ -456,10 +454,8 @@ static void cpia_usb_free_resources(struct usb_cpia *ucpia, int try)
456 ucpia->sbuf[0].urb = NULL; 454 ucpia->sbuf[0].urb = NULL;
457 } 455 }
458 456
459 if (ucpia->sbuf[0].data) { 457 kfree(ucpia->sbuf[0].data);
460 kfree(ucpia->sbuf[0].data); 458 ucpia->sbuf[0].data = NULL;
461 ucpia->sbuf[0].data = NULL;
462 }
463} 459}
464 460
465static int cpia_usb_close(void *privdata) 461static int cpia_usb_close(void *privdata)
@@ -623,20 +619,14 @@ static void cpia_disconnect(struct usb_interface *intf)
623 619
624 ucpia->curbuff = ucpia->workbuff = NULL; 620 ucpia->curbuff = ucpia->workbuff = NULL;
625 621
626 if (ucpia->buffers[2]) { 622 vfree(ucpia->buffers[2]);
627 vfree(ucpia->buffers[2]); 623 ucpia->buffers[2] = NULL;
628 ucpia->buffers[2] = NULL;
629 }
630 624
631 if (ucpia->buffers[1]) { 625 vfree(ucpia->buffers[1]);
632 vfree(ucpia->buffers[1]); 626 ucpia->buffers[1] = NULL;
633 ucpia->buffers[1] = NULL;
634 }
635 627
636 if (ucpia->buffers[0]) { 628 vfree(ucpia->buffers[0]);
637 vfree(ucpia->buffers[0]); 629 ucpia->buffers[0] = NULL;
638 ucpia->buffers[0] = NULL;
639 }
640 630
641 cam->lowlevel_data = NULL; 631 cam->lowlevel_data = NULL;
642 kfree(ucpia); 632 kfree(ucpia);
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index 4f39688f78..0c0c59e947 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: cx88-blackbird.c,v 1.27 2005/06/03 13:31:50 mchehab Exp $
3 * 2 *
4 * Support for a cx23416 mpeg encoder via cx2388x host port. 3 * Support for a cx23416 mpeg encoder via cx2388x host port.
5 * "blackbird" reference design. 4 * "blackbird" reference design.
@@ -62,7 +61,6 @@ static LIST_HEAD(cx8802_devlist);
62#define IVTV_CMD_HW_BLOCKS_RST 0xFFFFFFFF 61#define IVTV_CMD_HW_BLOCKS_RST 0xFFFFFFFF
63 62
64/* Firmware API commands */ 63/* Firmware API commands */
65/* #define IVTV_API_STD_TIMEOUT 0x00010000 // 65536, units?? */
66#define IVTV_API_STD_TIMEOUT 500 64#define IVTV_API_STD_TIMEOUT 500
67 65
68#define BLACKBIRD_API_PING 0x80 66#define BLACKBIRD_API_PING 0x80
@@ -696,7 +694,6 @@ static void blackbird_codec_settings(struct cx8802_dev *dev)
696 694
697 /* assign stream type */ 695 /* assign stream type */
698 blackbird_api_cmd(dev, BLACKBIRD_API_SET_STREAM_TYPE, 1, 0, BLACKBIRD_STREAM_PROGRAM); 696 blackbird_api_cmd(dev, BLACKBIRD_API_SET_STREAM_TYPE, 1, 0, BLACKBIRD_STREAM_PROGRAM);
699 /* blackbird_api_cmd(dev, BLACKBIRD_API_SET_STREAM_TYPE, 1, 0, BLACKBIRD_STREAM_TRANSPORT); */
700 697
701 /* assign output port */ 698 /* assign output port */
702 blackbird_api_cmd(dev, BLACKBIRD_API_SET_OUTPUT_PORT, 1, 0, BLACKBIRD_OUTPUT_PORT_STREAMING); /* Host */ 699 blackbird_api_cmd(dev, BLACKBIRD_API_SET_OUTPUT_PORT, 1, 0, BLACKBIRD_OUTPUT_PORT_STREAMING); /* Host */
@@ -824,7 +821,8 @@ static int blackbird_initialize_codec(struct cx8802_dev *dev)
824 BLACKBIRD_CUSTOM_EXTENSION_USR_DATA, 821 BLACKBIRD_CUSTOM_EXTENSION_USR_DATA,
825 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 822 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
826 823
827 blackbird_api_cmd(dev, BLACKBIRD_API_INIT_VIDEO_INPUT, 0, 0); /* initialize the video input */ 824 /* initialize the video input */
825 blackbird_api_cmd(dev, BLACKBIRD_API_INIT_VIDEO_INPUT, 0, 0);
828 826
829 msleep(1); 827 msleep(1);
830 828
@@ -833,11 +831,12 @@ static int blackbird_initialize_codec(struct cx8802_dev *dev)
833 blackbird_api_cmd(dev, BLACKBIRD_API_MUTE_AUDIO, 1, 0, BLACKBIRD_UNMUTE); 831 blackbird_api_cmd(dev, BLACKBIRD_API_MUTE_AUDIO, 1, 0, BLACKBIRD_UNMUTE);
834 msleep(1); 832 msleep(1);
835 833
836 /* blackbird_api_cmd(dev, BLACKBIRD_API_BEGIN_CAPTURE, 2, 0, 0, 0x13); // start capturing to the host interface */ 834 /* start capturing to the host interface */
835 /* blackbird_api_cmd(dev, BLACKBIRD_API_BEGIN_CAPTURE, 2, 0, 0, 0x13); */
837 blackbird_api_cmd(dev, BLACKBIRD_API_BEGIN_CAPTURE, 2, 0, 836 blackbird_api_cmd(dev, BLACKBIRD_API_BEGIN_CAPTURE, 2, 0,
838 BLACKBIRD_MPEG_CAPTURE, 837 BLACKBIRD_MPEG_CAPTURE,
839 BLACKBIRD_RAW_BITS_NONE 838 BLACKBIRD_RAW_BITS_NONE
840 ); /* start capturing to the host interface */ 839 );
841 msleep(10); 840 msleep(10);
842 841
843 blackbird_api_cmd(dev, BLACKBIRD_API_REFRESH_INPUT, 0,0); 842 blackbird_api_cmd(dev, BLACKBIRD_API_REFRESH_INPUT, 0,0);
@@ -851,8 +850,8 @@ static int bb_buf_setup(struct videobuf_queue *q,
851{ 850{
852 struct cx8802_fh *fh = q->priv_data; 851 struct cx8802_fh *fh = q->priv_data;
853 852
854 fh->dev->ts_packet_size = 512; 853 fh->dev->ts_packet_size = 188 * 4; /* was: 512 */
855 fh->dev->ts_packet_count = 100; 854 fh->dev->ts_packet_count = 32; /* was: 100 */
856 855
857 *size = fh->dev->ts_packet_size * fh->dev->ts_packet_count; 856 *size = fh->dev->ts_packet_size * fh->dev->ts_packet_count;
858 if (0 == *count) 857 if (0 == *count)
@@ -900,12 +899,36 @@ static int mpeg_do_ioctl(struct inode *inode, struct file *file,
900{ 899{
901 struct cx8802_fh *fh = file->private_data; 900 struct cx8802_fh *fh = file->private_data;
902 struct cx8802_dev *dev = fh->dev; 901 struct cx8802_dev *dev = fh->dev;
902 struct cx88_core *core = dev->core;
903 903
904 if (debug > 1) 904 if (debug > 1)
905 cx88_print_ioctl(dev->core->name,cmd); 905 cx88_print_ioctl(core->name,cmd);
906 906
907 switch (cmd) { 907 switch (cmd) {
908 908
909 /* --- capabilities ------------------------------------------ */
910 case VIDIOC_QUERYCAP:
911 {
912 struct v4l2_capability *cap = arg;
913
914 memset(cap,0,sizeof(*cap));
915 strcpy(cap->driver, "cx88_blackbird");
916 strlcpy(cap->card, cx88_boards[core->board].name,sizeof(cap->card));
917 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
918 cap->version = CX88_VERSION_CODE;
919 cap->capabilities =
920 V4L2_CAP_VIDEO_CAPTURE |
921 V4L2_CAP_READWRITE |
922 V4L2_CAP_STREAMING |
923 V4L2_CAP_VBI_CAPTURE |
924 V4L2_CAP_VIDEO_OVERLAY |
925 0;
926 if (UNSET != core->tuner_type)
927 cap->capabilities |= V4L2_CAP_TUNER;
928
929 return 0;
930 }
931
909 /* --- capture ioctls ---------------------------------------- */ 932 /* --- capture ioctls ---------------------------------------- */
910 case VIDIOC_ENUM_FMT: 933 case VIDIOC_ENUM_FMT:
911 { 934 {
@@ -935,7 +958,11 @@ static int mpeg_do_ioctl(struct inode *inode, struct file *file,
935 f->fmt.pix.width = dev->width; 958 f->fmt.pix.width = dev->width;
936 f->fmt.pix.height = dev->height; 959 f->fmt.pix.height = dev->height;
937 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 960 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
938 f->fmt.pix.sizeimage = 1024 * 512 /* FIXME: BUFFER_SIZE */; 961 f->fmt.pix.field = V4L2_FIELD_NONE;
962 f->fmt.pix.bytesperline = 0;
963 f->fmt.pix.sizeimage = 188 * 4 * 1024; /* 1024 * 512 */ /* FIXME: BUFFER_SIZE */;
964 f->fmt.pix.colorspace = 0;
965 return 0;
939 } 966 }
940 967
941 /* --- streaming capture ------------------------------------- */ 968 /* --- streaming capture ------------------------------------- */
@@ -959,15 +986,25 @@ static int mpeg_do_ioctl(struct inode *inode, struct file *file,
959 return videobuf_streamoff(&fh->mpegq); 986 return videobuf_streamoff(&fh->mpegq);
960 987
961 default: 988 default:
962 return -EINVAL; 989 return cx88_do_ioctl( inode, file, 0, dev->core, cmd, arg, cx88_ioctl_hook );
963 } 990 }
964 return 0; 991 return 0;
965} 992}
966 993
994int (*cx88_ioctl_hook)(struct inode *inode, struct file *file,
995 unsigned int cmd, void *arg);
996unsigned int (*cx88_ioctl_translator)(unsigned int cmd);
997
998static unsigned int mpeg_translate_ioctl(unsigned int cmd)
999{
1000 return cmd;
1001}
1002
967static int mpeg_ioctl(struct inode *inode, struct file *file, 1003static int mpeg_ioctl(struct inode *inode, struct file *file,
968 unsigned int cmd, unsigned long arg) 1004 unsigned int cmd, unsigned long arg)
969{ 1005{
970 return video_usercopy(inode, file, cmd, arg, mpeg_do_ioctl); 1006 cmd = cx88_ioctl_translator( cmd );
1007 return video_usercopy(inode, file, cmd, arg, cx88_ioctl_hook);
971} 1008}
972 1009
973static int mpeg_open(struct inode *inode, struct file *file) 1010static int mpeg_open(struct inode *inode, struct file *file)
@@ -1135,7 +1172,7 @@ static int __devinit blackbird_probe(struct pci_dev *pci_dev,
1135 dev->pci = pci_dev; 1172 dev->pci = pci_dev;
1136 dev->core = core; 1173 dev->core = core;
1137 dev->width = 720; 1174 dev->width = 720;
1138 dev->height = 480; 1175 dev->height = 576;
1139 1176
1140 err = cx8802_init_common(dev); 1177 err = cx8802_init_common(dev);
1141 if (0 != err) 1178 if (0 != err)
@@ -1148,6 +1185,9 @@ static int __devinit blackbird_probe(struct pci_dev *pci_dev,
1148 1185
1149 list_add_tail(&dev->devlist,&cx8802_devlist); 1186 list_add_tail(&dev->devlist,&cx8802_devlist);
1150 blackbird_register_video(dev); 1187 blackbird_register_video(dev);
1188
1189 /* initial device configuration: needed ? */
1190
1151 return 0; 1191 return 0;
1152 1192
1153 fail_free: 1193 fail_free:
@@ -1202,6 +1242,8 @@ static int blackbird_init(void)
1202 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n", 1242 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
1203 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100); 1243 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
1204#endif 1244#endif
1245 cx88_ioctl_hook = mpeg_do_ioctl;
1246 cx88_ioctl_translator = mpeg_translate_ioctl;
1205 return pci_register_driver(&blackbird_pci_driver); 1247 return pci_register_driver(&blackbird_pci_driver);
1206} 1248}
1207 1249
@@ -1213,6 +1255,9 @@ static void blackbird_fini(void)
1213module_init(blackbird_init); 1255module_init(blackbird_init);
1214module_exit(blackbird_fini); 1256module_exit(blackbird_fini);
1215 1257
1258EXPORT_SYMBOL(cx88_ioctl_hook);
1259EXPORT_SYMBOL(cx88_ioctl_translator);
1260
1216/* ----------------------------------------------------------- */ 1261/* ----------------------------------------------------------- */
1217/* 1262/*
1218 * Local variables: 1263 * Local variables:
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index ebf02a7f81..4da91d535a 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: cx88-cards.c,v 1.90 2005/07/28 02:47:42 mkrufky Exp $
3 * 2 *
4 * device driver for Conexant 2388x based TV cards 3 * device driver for Conexant 2388x based TV cards
5 * card-specific stuff. 4 * card-specific stuff.
@@ -499,9 +498,6 @@ struct cx88_board cx88_boards[] = {
499 .input = {{ 498 .input = {{
500 .type = CX88_VMUX_DVB, 499 .type = CX88_VMUX_DVB,
501 .vmux = 0, 500 .vmux = 0,
502 },{
503 .type = CX88_VMUX_SVIDEO,
504 .vmux = 2,
505 }}, 501 }},
506 .dvb = 1, 502 .dvb = 1,
507 }, 503 },
@@ -614,12 +610,12 @@ struct cx88_board cx88_boards[] = {
614 .input = {{ 610 .input = {{
615 .type = CX88_VMUX_TELEVISION, 611 .type = CX88_VMUX_TELEVISION,
616 .vmux = 0, 612 .vmux = 0,
617 .gpio0 = 0xed12, // internal decoder 613 .gpio0 = 0xed12, /* internal decoder */
618 .gpio2 = 0x00ff, 614 .gpio2 = 0x00ff,
619 },{ 615 },{
620 .type = CX88_VMUX_DEBUG, 616 .type = CX88_VMUX_DEBUG,
621 .vmux = 0, 617 .vmux = 0,
622 .gpio0 = 0xff01, // mono from tuner chip 618 .gpio0 = 0xff01, /* mono from tuner chip */
623 },{ 619 },{
624 .type = CX88_VMUX_COMPOSITE1, 620 .type = CX88_VMUX_COMPOSITE1,
625 .vmux = 1, 621 .vmux = 1,
@@ -715,19 +711,18 @@ struct cx88_board cx88_boards[] = {
715 .radio_type = UNSET, 711 .radio_type = UNSET,
716 .tuner_addr = ADDR_UNSET, 712 .tuner_addr = ADDR_UNSET,
717 .radio_addr = ADDR_UNSET, 713 .radio_addr = ADDR_UNSET,
718 /* See DViCO FusionHDTV 3 Gold-Q for GPIO documentation. */
719 .input = {{ 714 .input = {{
720 .type = CX88_VMUX_TELEVISION, 715 .type = CX88_VMUX_TELEVISION,
721 .vmux = 0, 716 .vmux = 0,
722 .gpio0 = 0x0f0d, 717 .gpio0 = 0x97ed,
723 },{ 718 },{
724 .type = CX88_VMUX_COMPOSITE1, 719 .type = CX88_VMUX_COMPOSITE1,
725 .vmux = 1, 720 .vmux = 1,
726 .gpio0 = 0x0f00, 721 .gpio0 = 0x97e9,
727 },{ 722 },{
728 .type = CX88_VMUX_SVIDEO, 723 .type = CX88_VMUX_SVIDEO,
729 .vmux = 2, 724 .vmux = 2,
730 .gpio0 = 0x0f00, 725 .gpio0 = 0x97e9,
731 }}, 726 }},
732 .dvb = 1, 727 .dvb = 1,
733 }, 728 },
@@ -765,20 +760,21 @@ struct cx88_board cx88_boards[] = {
765 .radio_type = UNSET, 760 .radio_type = UNSET,
766 .tuner_addr = ADDR_UNSET, 761 .tuner_addr = ADDR_UNSET,
767 .radio_addr = ADDR_UNSET, 762 .radio_addr = ADDR_UNSET,
768 /* See DViCO FusionHDTV 3 Gold-Q for GPIO documentation. */ 763 .tda9887_conf = TDA9887_PRESENT,
769 .input = {{ 764 .input = {{
770 .type = CX88_VMUX_TELEVISION, 765 .type = CX88_VMUX_TELEVISION,
771 .vmux = 0, 766 .vmux = 0,
772 .gpio0 = 0x0f0d, 767 .gpio0 = 0x87fd,
773 },{ 768 },{
774 .type = CX88_VMUX_COMPOSITE1, 769 .type = CX88_VMUX_COMPOSITE1,
775 .vmux = 1, 770 .vmux = 1,
776 .gpio0 = 0x0f00, 771 .gpio0 = 0x87f9,
777 },{ 772 },{
778 .type = CX88_VMUX_SVIDEO, 773 .type = CX88_VMUX_SVIDEO,
779 .vmux = 2, 774 .vmux = 2,
780 .gpio0 = 0x0f00, 775 .gpio0 = 0x87f9,
781 }}, 776 }},
777 .dvb = 1,
782 }, 778 },
783}; 779};
784const unsigned int cx88_bcount = ARRAY_SIZE(cx88_boards); 780const unsigned int cx88_bcount = ARRAY_SIZE(cx88_boards);
@@ -949,7 +945,7 @@ static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data)
949{ 945{
950 struct tveeprom tv; 946 struct tveeprom tv;
951 947
952 tveeprom_hauppauge_analog(&tv, eeprom_data); 948 tveeprom_hauppauge_analog(&core->i2c_client, &tv, eeprom_data);
953 core->tuner_type = tv.tuner_type; 949 core->tuner_type = tv.tuner_type;
954 core->has_radio = tv.has_radio; 950 core->has_radio = tv.has_radio;
955} 951}
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index 5e868f5cd0..dc5c5c1f34 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: cx88-core.c,v 1.33 2005/07/07 14:17:47 mchehab Exp $
3 * 2 *
4 * device driver for Conexant 2388x based TV cards 3 * device driver for Conexant 2388x based TV cards
5 * driver core 4 * driver core
@@ -876,7 +875,7 @@ static int set_tvaudio(struct cx88_core *core)
876 875
877 cx_andor(MO_AFECFG_IO, 0x1f, 0x0); 876 cx_andor(MO_AFECFG_IO, 0x1f, 0x0);
878 cx88_set_tvaudio(core); 877 cx88_set_tvaudio(core);
879 // cx88_set_stereo(dev,V4L2_TUNER_MODE_STEREO); 878 /* cx88_set_stereo(dev,V4L2_TUNER_MODE_STEREO); */
880 879
881 cx_write(MO_AUDD_LNGTH, 128); /* fifo size */ 880 cx_write(MO_AUDD_LNGTH, 128); /* fifo size */
882 cx_write(MO_AUDR_LNGTH, 128); /* fifo size */ 881 cx_write(MO_AUDR_LNGTH, 128); /* fifo size */
@@ -1087,10 +1086,17 @@ struct cx88_core* cx88_core_get(struct pci_dev *pci)
1087 core->pci_bus = pci->bus->number; 1086 core->pci_bus = pci->bus->number;
1088 core->pci_slot = PCI_SLOT(pci->devfn); 1087 core->pci_slot = PCI_SLOT(pci->devfn);
1089 core->pci_irqmask = 0x00fc00; 1088 core->pci_irqmask = 0x00fc00;
1089 init_MUTEX(&core->lock);
1090 1090
1091 core->nr = cx88_devcount++; 1091 core->nr = cx88_devcount++;
1092 sprintf(core->name,"cx88[%d]",core->nr); 1092 sprintf(core->name,"cx88[%d]",core->nr);
1093 if (0 != get_ressources(core,pci)) { 1093 if (0 != get_ressources(core,pci)) {
1094 printk(KERN_ERR "CORE %s No more PCI ressources for "
1095 "subsystem: %04x:%04x, board: %s\n",
1096 core->name,pci->subsystem_vendor,
1097 pci->subsystem_device,
1098 cx88_boards[core->board].name);
1099
1094 cx88_devcount--; 1100 cx88_devcount--;
1095 goto fail_free; 1101 goto fail_free;
1096 } 1102 }
@@ -1114,11 +1120,11 @@ struct cx88_core* cx88_core_get(struct pci_dev *pci)
1114 core->board = CX88_BOARD_UNKNOWN; 1120 core->board = CX88_BOARD_UNKNOWN;
1115 cx88_card_list(core,pci); 1121 cx88_card_list(core,pci);
1116 } 1122 }
1117 printk(KERN_INFO "%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n", 1123 printk(KERN_INFO "CORE %s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
1118 core->name,pci->subsystem_vendor, 1124 core->name,pci->subsystem_vendor,
1119 pci->subsystem_device,cx88_boards[core->board].name, 1125 pci->subsystem_device,cx88_boards[core->board].name,
1120 core->board, card[core->nr] == core->board ? 1126 core->board, card[core->nr] == core->board ?
1121 "insmod option" : "autodetected"); 1127 "insmod option" : "autodetected");
1122 1128
1123 core->tuner_type = tuner[core->nr]; 1129 core->tuner_type = tuner[core->nr];
1124 core->radio_type = radio[core->nr]; 1130 core->radio_type = radio[core->nr];
@@ -1202,4 +1208,5 @@ EXPORT_SYMBOL(cx88_core_put);
1202 * Local variables: 1208 * Local variables:
1203 * c-basic-offset: 8 1209 * c-basic-offset: 8
1204 * End: 1210 * End:
1211 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
1205 */ 1212 */
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index 78d223257a..c9106b1d79 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: cx88-dvb.c,v 1.58 2005/08/07 09:24:08 mkrufky Exp $
3 * 2 *
4 * device driver for Conexant 2388x based TV cards 3 * device driver for Conexant 2388x based TV cards
5 * MPEG Transport Stream (DVB) routines 4 * MPEG Transport Stream (DVB) routines
@@ -29,7 +28,7 @@
29#include <linux/kthread.h> 28#include <linux/kthread.h>
30#include <linux/file.h> 29#include <linux/file.h>
31#include <linux/suspend.h> 30#include <linux/suspend.h>
32#include <linux/config.h> 31
33 32
34#include "cx88.h" 33#include "cx88.h"
35#include "dvb-pll.h" 34#include "dvb-pll.h"
@@ -210,16 +209,26 @@ static struct or51132_config pchdtv_hd3000 = {
210static int lgdt330x_pll_set(struct dvb_frontend* fe, 209static int lgdt330x_pll_set(struct dvb_frontend* fe,
211 struct dvb_frontend_parameters* params) 210 struct dvb_frontend_parameters* params)
212{ 211{
212 /* FIXME make this routine use the tuner-simple code.
213 * It could probably be shared with a number of ATSC
214 * frontends. Many share the same tuner with analog TV. */
215
213 struct cx8802_dev *dev= fe->dvb->priv; 216 struct cx8802_dev *dev= fe->dvb->priv;
217 struct cx88_core *core = dev->core;
214 u8 buf[4]; 218 u8 buf[4];
215 struct i2c_msg msg = 219 struct i2c_msg msg =
216 { .addr = dev->core->pll_addr, .flags = 0, .buf = buf, .len = 4 }; 220 { .addr = dev->core->pll_addr, .flags = 0, .buf = buf, .len = 4 };
217 int err; 221 int err;
218 222
219 dvb_pll_configure(dev->core->pll_desc, buf, params->frequency, 0); 223 /* Put the analog decoder in standby to keep it quiet */
224 if (core->tda9887_conf) {
225 cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
226 }
227
228 dvb_pll_configure(core->pll_desc, buf, params->frequency, 0);
220 dprintk(1, "%s: tuner at 0x%02x bytes: 0x%02x 0x%02x 0x%02x 0x%02x\n", 229 dprintk(1, "%s: tuner at 0x%02x bytes: 0x%02x 0x%02x 0x%02x 0x%02x\n",
221 __FUNCTION__, msg.addr, buf[0],buf[1],buf[2],buf[3]); 230 __FUNCTION__, msg.addr, buf[0],buf[1],buf[2],buf[3]);
222 if ((err = i2c_transfer(&dev->core->i2c_adap, &msg, 1)) != 1) { 231 if ((err = i2c_transfer(&core->i2c_adap, &msg, 1)) != 1) {
223 printk(KERN_WARNING "cx88-dvb: %s error " 232 printk(KERN_WARNING "cx88-dvb: %s error "
224 "(addr %02x <- %02x, err = %i)\n", 233 "(addr %02x <- %02x, err = %i)\n",
225 __FUNCTION__, buf[0], buf[1], err); 234 __FUNCTION__, buf[0], buf[1], err);
@@ -228,6 +237,13 @@ static int lgdt330x_pll_set(struct dvb_frontend* fe,
228 else 237 else
229 return -EREMOTEIO; 238 return -EREMOTEIO;
230 } 239 }
240 if (core->tuner_type == TUNER_LG_TDVS_H062F) {
241 /* Set the Auxiliary Byte. */
242 buf[2] &= ~0x20;
243 buf[2] |= 0x18;
244 buf[3] = 0x50;
245 i2c_transfer(&core->i2c_adap, &msg, 1);
246 }
231 return 0; 247 return 0;
232} 248}
233 249
@@ -261,6 +277,14 @@ static struct lgdt330x_config fusionhdtv_3_gold = {
261 .pll_set = lgdt330x_pll_set, 277 .pll_set = lgdt330x_pll_set,
262 .set_ts_params = lgdt330x_set_ts_param, 278 .set_ts_params = lgdt330x_set_ts_param,
263}; 279};
280
281static struct lgdt330x_config fusionhdtv_5_gold = {
282 .demod_address = 0x0e,
283 .demod_chip = LGDT3303,
284 .serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
285 .pll_set = lgdt330x_pll_set,
286 .set_ts_params = lgdt330x_set_ts_param,
287};
264#endif 288#endif
265 289
266static int dvb_register(struct cx8802_dev *dev) 290static int dvb_register(struct cx8802_dev *dev)
@@ -346,6 +370,22 @@ static int dvb_register(struct cx8802_dev *dev)
346 &dev->core->i2c_adap); 370 &dev->core->i2c_adap);
347 } 371 }
348 break; 372 break;
373 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
374 dev->ts_gen_cntrl = 0x08;
375 {
376 /* Do a hardware reset of chip before using it. */
377 struct cx88_core *core = dev->core;
378
379 cx_clear(MO_GP0_IO, 1);
380 mdelay(100);
381 cx_set(MO_GP0_IO, 1);
382 mdelay(200);
383 dev->core->pll_addr = 0x61;
384 dev->core->pll_desc = &dvb_pll_tdvs_tua6034;
385 dev->dvb.frontend = lgdt330x_attach(&fusionhdtv_5_gold,
386 &dev->core->i2c_adap);
387 }
388 break;
349#endif 389#endif
350 default: 390 default:
351 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n", 391 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
@@ -362,11 +402,6 @@ static int dvb_register(struct cx8802_dev *dev)
362 dev->dvb.frontend->ops->info.frequency_max = dev->core->pll_desc->max; 402 dev->dvb.frontend->ops->info.frequency_max = dev->core->pll_desc->max;
363 } 403 }
364 404
365 /* Copy the board name into the DVB structure */
366 strlcpy(dev->dvb.frontend->ops->info.name,
367 cx88_boards[dev->core->board].name,
368 sizeof(dev->dvb.frontend->ops->info.name));
369
370 /* register everything */ 405 /* register everything */
371 return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev); 406 return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev);
372} 407}
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index 7f598039e0..761cebd40d 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -1,5 +1,4 @@
1/* 1/*
2 $Id: cx88-i2c.c,v 1.30 2005/07/25 05:10:13 mkrufky Exp $
3 2
4 cx88-i2c.c -- all the i2c code is here 3 cx88-i2c.c -- all the i2c code is here
5 4
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index 2148877981..d81b21d6e0 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: cx88-input.c,v 1.15 2005/07/07 13:58:38 mchehab Exp $
3 * 2 *
4 * Device driver for GPIO attached remote control interfaces 3 * Device driver for GPIO attached remote control interfaces
5 * on Conexant 2388x based TV/DVB cards. 4 * on Conexant 2388x based TV/DVB cards.
@@ -212,6 +211,53 @@ static IR_KEYTAB_TYPE ir_codes_msi_tvanywhere[IR_KEYTAB_SIZE] = {
212 211
213/* ---------------------------------------------------------------------- */ 212/* ---------------------------------------------------------------------- */
214 213
214/* Cinergy 1400 DVB-T */
215static IR_KEYTAB_TYPE ir_codes_cinergy_1400[IR_KEYTAB_SIZE] = {
216 [0x01] = KEY_POWER,
217 [0x02] = KEY_1,
218 [0x03] = KEY_2,
219 [0x04] = KEY_3,
220 [0x05] = KEY_4,
221 [0x06] = KEY_5,
222 [0x07] = KEY_6,
223 [0x08] = KEY_7,
224 [0x09] = KEY_8,
225 [0x0a] = KEY_9,
226 [0x0c] = KEY_0,
227
228 [0x0b] = KEY_VIDEO,
229 [0x0d] = KEY_REFRESH,
230 [0x0e] = KEY_SELECT,
231 [0x0f] = KEY_EPG,
232 [0x10] = KEY_UP,
233 [0x11] = KEY_LEFT,
234 [0x12] = KEY_OK,
235 [0x13] = KEY_RIGHT,
236 [0x14] = KEY_DOWN,
237 [0x15] = KEY_TEXT,
238 [0x16] = KEY_INFO,
239
240 [0x17] = KEY_RED,
241 [0x18] = KEY_GREEN,
242 [0x19] = KEY_YELLOW,
243 [0x1a] = KEY_BLUE,
244
245 [0x1b] = KEY_CHANNELUP,
246 [0x1c] = KEY_VOLUMEUP,
247 [0x1d] = KEY_MUTE,
248 [0x1e] = KEY_VOLUMEDOWN,
249 [0x1f] = KEY_CHANNELDOWN,
250
251 [0x40] = KEY_PAUSE,
252 [0x4c] = KEY_PLAY,
253 [0x58] = KEY_RECORD,
254 [0x54] = KEY_PREVIOUS,
255 [0x48] = KEY_STOP,
256 [0x5c] = KEY_NEXT,
257};
258
259/* ---------------------------------------------------------------------- */
260
215struct cx88_IR { 261struct cx88_IR {
216 struct cx88_core *core; 262 struct cx88_core *core;
217 struct input_dev input; 263 struct input_dev input;
@@ -241,7 +287,7 @@ module_param(ir_debug, int, 0644); /* debug level [IR] */
241MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]"); 287MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
242 288
243#define ir_dprintk(fmt, arg...) if (ir_debug) \ 289#define ir_dprintk(fmt, arg...) if (ir_debug) \
244 printk(KERN_DEBUG "%s IR: " fmt , ir->core->name, ## arg) 290 printk(KERN_DEBUG "%s IR: " fmt , ir->core->name , ##arg)
245 291
246/* ---------------------------------------------------------------------- */ 292/* ---------------------------------------------------------------------- */
247 293
@@ -329,6 +375,11 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
329 ir->mask_keyup = 0x60; 375 ir->mask_keyup = 0x60;
330 ir->polling = 50; /* ms */ 376 ir->polling = 50; /* ms */
331 break; 377 break;
378 case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
379 ir_codes = ir_codes_cinergy_1400;
380 ir_type = IR_TYPE_PD;
381 ir->sampling = 1;
382 break;
332 case CX88_BOARD_HAUPPAUGE: 383 case CX88_BOARD_HAUPPAUGE:
333 case CX88_BOARD_HAUPPAUGE_DVB_T1: 384 case CX88_BOARD_HAUPPAUGE_DVB_T1:
334 ir_codes = ir_codes_hauppauge_new; 385 ir_codes = ir_codes_hauppauge_new;
@@ -394,6 +445,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
394 ir->input.id.vendor = pci->vendor; 445 ir->input.id.vendor = pci->vendor;
395 ir->input.id.product = pci->device; 446 ir->input.id.product = pci->device;
396 } 447 }
448 ir->input.dev = &pci->dev;
397 449
398 /* record handles to ourself */ 450 /* record handles to ourself */
399 ir->core = core; 451 ir->core = core;
@@ -445,7 +497,7 @@ int cx88_ir_fini(struct cx88_core *core)
445void cx88_ir_irq(struct cx88_core *core) 497void cx88_ir_irq(struct cx88_core *core)
446{ 498{
447 struct cx88_IR *ir = core->ir; 499 struct cx88_IR *ir = core->ir;
448 u32 samples, rc5; 500 u32 samples, ircode;
449 int i; 501 int i;
450 502
451 if (NULL == ir) 503 if (NULL == ir)
@@ -477,13 +529,44 @@ void cx88_ir_irq(struct cx88_core *core)
477 529
478 /* decode it */ 530 /* decode it */
479 switch (core->board) { 531 switch (core->board) {
532 case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
533 ircode = ir_decode_pulsedistance(ir->samples, ir->scount, 1, 4);
534
535 if (ircode == 0xffffffff) { /* decoding error */
536 ir_dprintk("pulse distance decoding error\n");
537 break;
538 }
539
540 ir_dprintk("pulse distance decoded: %x\n", ircode);
541
542 if (ircode == 0) { /* key still pressed */
543 ir_dprintk("pulse distance decoded repeat code\n");
544 ir->release = jiffies + msecs_to_jiffies(120);
545 break;
546 }
547
548 if ((ircode & 0xffff) != 0xeb04) { /* wrong address */
549 ir_dprintk("pulse distance decoded wrong address\n");
550 break;
551 }
552
553 if (((~ircode >> 24) & 0xff) != ((ircode >> 16) & 0xff)) { /* wrong checksum */
554 ir_dprintk("pulse distance decoded wrong check sum\n");
555 break;
556 }
557
558 ir_dprintk("Key Code: %x\n", (ircode >> 16) & 0x7f);
559
560 ir_input_keydown(&ir->input, &ir->ir, (ircode >> 16) & 0x7f, (ircode >> 16) & 0xff);
561 ir->release = jiffies + msecs_to_jiffies(120);
562 break;
480 case CX88_BOARD_HAUPPAUGE: 563 case CX88_BOARD_HAUPPAUGE:
481 case CX88_BOARD_HAUPPAUGE_DVB_T1: 564 case CX88_BOARD_HAUPPAUGE_DVB_T1:
482 rc5 = ir_decode_biphase(ir->samples, ir->scount, 5, 7); 565 ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
483 ir_dprintk("biphase decoded: %x\n", rc5); 566 ir_dprintk("biphase decoded: %x\n", ircode);
484 if ((rc5 & 0xfffff000) != 0x3000) 567 if ((ircode & 0xfffff000) != 0x3000)
485 break; 568 break;
486 ir_input_keydown(&ir->input, &ir->ir, rc5 & 0x3f, rc5); 569 ir_input_keydown(&ir->input, &ir->ir, ircode & 0x3f, ircode);
487 ir->release = jiffies + msecs_to_jiffies(120); 570 ir->release = jiffies + msecs_to_jiffies(120);
488 break; 571 break;
489 } 572 }
diff --git a/drivers/media/video/cx88/cx88-mpeg.c b/drivers/media/video/cx88/cx88-mpeg.c
index fe2767c0ff..ee2300e1ae 100644
--- a/drivers/media/video/cx88/cx88-mpeg.c
+++ b/drivers/media/video/cx88/cx88-mpeg.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: cx88-mpeg.c,v 1.31 2005/07/07 14:17:47 mchehab Exp $
3 * 2 *
4 * Support for the mpeg transport stream transfers 3 * Support for the mpeg transport stream transfers
5 * PCI function #2 of the cx2388x. 4 * PCI function #2 of the cx2388x.
@@ -73,11 +72,15 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
73 udelay(100); 72 udelay(100);
74 cx_write(MO_PINMUX_IO, 0x00); 73 cx_write(MO_PINMUX_IO, 0x00);
75 cx_write(TS_HW_SOP_CNTRL,0x47<<16|188<<4|0x01); 74 cx_write(TS_HW_SOP_CNTRL,0x47<<16|188<<4|0x01);
76 if ((core->board == CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q) || 75 switch (core->board) {
77 (core->board == CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T)) { 76 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
77 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
78 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
78 cx_write(TS_SOP_STAT, 1<<13); 79 cx_write(TS_SOP_STAT, 1<<13);
79 } else { 80 break;
81 default:
80 cx_write(TS_SOP_STAT, 0x00); 82 cx_write(TS_SOP_STAT, 0x00);
83 break;
81 } 84 }
82 cx_write(TS_GEN_CNTRL, dev->ts_gen_cntrl); 85 cx_write(TS_GEN_CNTRL, dev->ts_gen_cntrl);
83 udelay(100); 86 udelay(100);
@@ -86,12 +89,10 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
86 if (cx88_boards[core->board].blackbird) { 89 if (cx88_boards[core->board].blackbird) {
87 cx_write(MO_PINMUX_IO, 0x88); /* enable MPEG parallel IO */ 90 cx_write(MO_PINMUX_IO, 0x88); /* enable MPEG parallel IO */
88 91
89 // cx_write(TS_F2_CMD_STAT_MM, 0x2900106); /* F2_CMD_STAT_MM defaults + master + memory space */
90 cx_write(TS_GEN_CNTRL, 0x46); /* punctured clock TS & posedge driven & software reset */ 92 cx_write(TS_GEN_CNTRL, 0x46); /* punctured clock TS & posedge driven & software reset */
91 udelay(100); 93 udelay(100);
92 94
93 cx_write(TS_HW_SOP_CNTRL, 0x408); /* mpeg start byte */ 95 cx_write(TS_HW_SOP_CNTRL, 0x408); /* mpeg start byte */
94 //cx_write(TS_HW_SOP_CNTRL, 0x2F0BC0); /* mpeg start byte ts: 0x2F0BC0 ? */
95 cx_write(TS_VALERR_CNTRL, 0x2000); 96 cx_write(TS_VALERR_CNTRL, 0x2000);
96 97
97 cx_write(TS_GEN_CNTRL, 0x06); /* punctured clock TS & posedge driven */ 98 cx_write(TS_GEN_CNTRL, 0x06); /* punctured clock TS & posedge driven */
@@ -106,7 +107,6 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
106 dprintk( 0, "setting the interrupt mask\n" ); 107 dprintk( 0, "setting the interrupt mask\n" );
107 cx_set(MO_PCI_INTMSK, core->pci_irqmask | 0x04); 108 cx_set(MO_PCI_INTMSK, core->pci_irqmask | 0x04);
108 cx_set(MO_TS_INTMSK, 0x1f0011); 109 cx_set(MO_TS_INTMSK, 0x1f0011);
109 //cx_write(MO_TS_INTMSK, 0x0f0011);
110 110
111 /* start dma */ 111 /* start dma */
112 cx_set(MO_DEV_CNTRL2, (1<<5)); 112 cx_set(MO_DEV_CNTRL2, (1<<5));
@@ -206,7 +206,6 @@ void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf)
206 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 206 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
207 dprintk(0,"[%p/%d] %s - first active\n", 207 dprintk(0,"[%p/%d] %s - first active\n",
208 buf, buf->vb.i, __FUNCTION__); 208 buf, buf->vb.i, __FUNCTION__);
209 //udelay(100);
210 209
211 } else { 210 } else {
212 dprintk( 1, "queue is not empty - append to active\n" ); 211 dprintk( 1, "queue is not empty - append to active\n" );
@@ -217,7 +216,6 @@ void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf)
217 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 216 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
218 dprintk( 1, "[%p/%d] %s - append to active\n", 217 dprintk( 1, "[%p/%d] %s - append to active\n",
219 buf, buf->vb.i, __FUNCTION__); 218 buf, buf->vb.i, __FUNCTION__);
220 //udelay(100);
221 } 219 }
222} 220}
223 221
@@ -387,7 +385,6 @@ int cx8802_init_common(struct cx8802_dev *dev)
387 dev->pci_lat,pci_resource_start(dev->pci,0)); 385 dev->pci_lat,pci_resource_start(dev->pci,0));
388 386
389 /* initialize driver struct */ 387 /* initialize driver struct */
390 init_MUTEX(&dev->lock);
391 spin_lock_init(&dev->slock); 388 spin_lock_init(&dev->slock);
392 389
393 /* init dma queue */ 390 /* init dma queue */
@@ -458,14 +455,28 @@ int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state)
458 455
459int cx8802_resume_common(struct pci_dev *pci_dev) 456int cx8802_resume_common(struct pci_dev *pci_dev)
460{ 457{
461 struct cx8802_dev *dev = pci_get_drvdata(pci_dev); 458 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
462 struct cx88_core *core = dev->core; 459 struct cx88_core *core = dev->core;
460 int err;
463 461
464 if (dev->state.disabled) { 462 if (dev->state.disabled) {
465 pci_enable_device(pci_dev); 463 err=pci_enable_device(pci_dev);
464 if (err) {
465 printk(KERN_ERR "%s: can't enable device\n",
466 dev->core->name);
467 return err;
468 }
466 dev->state.disabled = 0; 469 dev->state.disabled = 0;
467 } 470 }
468 pci_set_power_state(pci_dev, PCI_D0); 471 err=pci_set_power_state(pci_dev, PCI_D0);
472 if (err) {
473 printk(KERN_ERR "%s: can't enable device\n",
474 dev->core->name);
475 pci_disable_device(pci_dev);
476 dev->state.disabled = 1;
477
478 return err;
479 }
469 pci_restore_state(pci_dev); 480 pci_restore_state(pci_dev);
470 481
471 /* FIXME: re-initialize hardware */ 482 /* FIXME: re-initialize hardware */
diff --git a/drivers/media/video/cx88/cx88-reg.h b/drivers/media/video/cx88/cx88-reg.h
index 37f82662d2..0a3a62fc9b 100644
--- a/drivers/media/video/cx88/cx88-reg.h
+++ b/drivers/media/video/cx88/cx88-reg.h
@@ -1,5 +1,4 @@
1/* 1/*
2 $Id: cx88-reg.h,v 1.8 2005/07/07 13:58:38 mchehab Exp $
3 2
4 cx88x-hw.h - CX2388x register offsets 3 cx88x-hw.h - CX2388x register offsets
5 4
@@ -40,6 +39,29 @@
40#define CX88X_EN_TBFX 0x02 39#define CX88X_EN_TBFX 0x02
41#define CX88X_EN_VSFX 0x04 40#define CX88X_EN_VSFX 0x04
42 41
42/* ---------------------------------------------------------------------- */
43/* PCI controller registers */
44
45/* Command and Status Register */
46#define F0_CMD_STAT_MM 0x2f0004
47#define F1_CMD_STAT_MM 0x2f0104
48#define F2_CMD_STAT_MM 0x2f0204
49#define F3_CMD_STAT_MM 0x2f0304
50#define F4_CMD_STAT_MM 0x2f0404
51
52/* Device Control #1 */
53#define F0_DEV_CNTRL1_MM 0x2f0040
54#define F1_DEV_CNTRL1_MM 0x2f0140
55#define F2_DEV_CNTRL1_MM 0x2f0240
56#define F3_DEV_CNTRL1_MM 0x2f0340
57#define F4_DEV_CNTRL1_MM 0x2f0440
58
59/* Device Control #1 */
60#define F0_BAR0_MM 0x2f0010
61#define F1_BAR0_MM 0x2f0110
62#define F2_BAR0_MM 0x2f0210
63#define F3_BAR0_MM 0x2f0310
64#define F4_BAR0_MM 0x2f0410
43 65
44/* ---------------------------------------------------------------------- */ 66/* ---------------------------------------------------------------------- */
45/* DMA Controller registers */ 67/* DMA Controller registers */
diff --git a/drivers/media/video/cx88/cx88-tvaudio.c b/drivers/media/video/cx88/cx88-tvaudio.c
index 91207f10ba..2765acee02 100644
--- a/drivers/media/video/cx88/cx88-tvaudio.c
+++ b/drivers/media/video/cx88/cx88-tvaudio.c
@@ -1,5 +1,4 @@
1/* 1/*
2 $Id: cx88-tvaudio.c,v 1.37 2005/07/07 13:58:38 mchehab Exp $
3 2
4 cx88x-audio.c - Conexant CX23880/23881 audio downstream driver driver 3 cx88x-audio.c - Conexant CX23880/23881 audio downstream driver driver
5 4
@@ -121,25 +120,19 @@ static void set_audio_registers(struct cx88_core *core,
121} 120}
122 121
123static void set_audio_start(struct cx88_core *core, 122static void set_audio_start(struct cx88_core *core,
124 u32 mode, u32 ctl) 123 u32 mode)
125{ 124{
126 // mute 125 // mute
127 cx_write(AUD_VOL_CTL, (1 << 6)); 126 cx_write(AUD_VOL_CTL, (1 << 6));
128 127
129 // increase level of input by 12dB
130// cx_write(AUD_AFE_12DB_EN, 0x0001);
131 cx_write(AUD_AFE_12DB_EN, 0x0000);
132
133 // start programming 128 // start programming
134 cx_write(AUD_CTL, 0x0000); 129 cx_write(AUD_CTL, 0x0000);
135 cx_write(AUD_INIT, mode); 130 cx_write(AUD_INIT, mode);
136 cx_write(AUD_INIT_LD, 0x0001); 131 cx_write(AUD_INIT_LD, 0x0001);
137 cx_write(AUD_SOFT_RESET, 0x0001); 132 cx_write(AUD_SOFT_RESET, 0x0001);
138
139 cx_write(AUD_CTL, ctl);
140} 133}
141 134
142static void set_audio_finish(struct cx88_core *core) 135static void set_audio_finish(struct cx88_core *core, u32 ctl)
143{ 136{
144 u32 volume; 137 u32 volume;
145 138
@@ -154,25 +147,25 @@ static void set_audio_finish(struct cx88_core *core)
154 cx_write(AUD_I2SOUTPUTCNTL, 1); 147 cx_write(AUD_I2SOUTPUTCNTL, 1);
155 cx_write(AUD_I2SCNTL, 0); 148 cx_write(AUD_I2SCNTL, 0);
156 //cx_write(AUD_APB_IN_RATE_ADJ, 0); 149 //cx_write(AUD_APB_IN_RATE_ADJ, 0);
150 } else {
151 ctl |= EN_DAC_ENABLE;
152 cx_write(AUD_CTL, ctl);
157 } 153 }
158 154
159 // finish programming 155 /* finish programming */
160 cx_write(AUD_SOFT_RESET, 0x0000); 156 cx_write(AUD_SOFT_RESET, 0x0000);
161 157
162 // start audio processing 158 /* unmute */
163 cx_set(AUD_CTL, EN_DAC_ENABLE);
164
165 // unmute
166 volume = cx_sread(SHADOW_AUD_VOL_CTL); 159 volume = cx_sread(SHADOW_AUD_VOL_CTL);
167 cx_swrite(SHADOW_AUD_VOL_CTL, AUD_VOL_CTL, volume); 160 cx_swrite(SHADOW_AUD_VOL_CTL, AUD_VOL_CTL, volume);
168} 161}
169 162
170/* ----------------------------------------------------------- */ 163/* ----------------------------------------------------------- */
171 164
172static void set_audio_standard_BTSC(struct cx88_core *core, unsigned int sap) 165static void set_audio_standard_BTSC(struct cx88_core *core, unsigned int sap, u32 mode)
173{ 166{
174 static const struct rlist btsc[] = { 167 static const struct rlist btsc[] = {
175 /* from dscaler */ 168 { AUD_AFE_12DB_EN, 0x00000001 },
176 { AUD_OUT1_SEL, 0x00000013 }, 169 { AUD_OUT1_SEL, 0x00000013 },
177 { AUD_OUT1_SHIFT, 0x00000000 }, 170 { AUD_OUT1_SHIFT, 0x00000000 },
178 { AUD_POLY0_DDS_CONSTANT, 0x0012010c }, 171 { AUD_POLY0_DDS_CONSTANT, 0x0012010c },
@@ -206,9 +199,10 @@ static void set_audio_standard_BTSC(struct cx88_core *core, unsigned int sap)
206 { AUD_RDSI_SHIFT, 0x00000000 }, 199 { AUD_RDSI_SHIFT, 0x00000000 },
207 { AUD_RDSQ_SHIFT, 0x00000000 }, 200 { AUD_RDSQ_SHIFT, 0x00000000 },
208 { AUD_POLYPH80SCALEFAC, 0x00000003 }, 201 { AUD_POLYPH80SCALEFAC, 0x00000003 },
209 { /* end of list */ }, 202 { /* end of list */ },
210 }; 203 };
211 static const struct rlist btsc_sap[] = { 204 static const struct rlist btsc_sap[] = {
205 { AUD_AFE_12DB_EN, 0x00000001 },
212 { AUD_DBX_IN_GAIN, 0x00007200 }, 206 { AUD_DBX_IN_GAIN, 0x00007200 },
213 { AUD_DBX_WBE_GAIN, 0x00006200 }, 207 { AUD_DBX_WBE_GAIN, 0x00006200 },
214 { AUD_DBX_SE_GAIN, 0x00006200 }, 208 { AUD_DBX_SE_GAIN, 0x00006200 },
@@ -259,371 +253,400 @@ static void set_audio_standard_BTSC(struct cx88_core *core, unsigned int sap)
259 { AUD_RDSI_SHIFT, 0x00000000 }, 253 { AUD_RDSI_SHIFT, 0x00000000 },
260 { AUD_RDSQ_SHIFT, 0x00000000 }, 254 { AUD_RDSQ_SHIFT, 0x00000000 },
261 { AUD_POLYPH80SCALEFAC, 0x00000003 }, 255 { AUD_POLYPH80SCALEFAC, 0x00000003 },
262 { /* end of list */ }, 256 { /* end of list */ },
263 }; 257 };
264 258
265 // dscaler: exactly taken from driver, 259 mode |= EN_FMRADIO_EN_RDS;
266 // dscaler: don't know why to set EN_FMRADIO_EN_RDS 260
267 if (sap) { 261 if (sap) {
268 dprintk("%s SAP (status: unknown)\n",__FUNCTION__); 262 dprintk("%s SAP (status: unknown)\n",__FUNCTION__);
269 set_audio_start(core, 0x0001, 263 set_audio_start(core, SEL_SAP);
270 EN_FMRADIO_EN_RDS | EN_BTSC_FORCE_SAP);
271 set_audio_registers(core, btsc_sap); 264 set_audio_registers(core, btsc_sap);
265 set_audio_finish(core, mode);
272 } else { 266 } else {
273 dprintk("%s (status: known-good)\n",__FUNCTION__); 267 dprintk("%s (status: known-good)\n",__FUNCTION__);
274 set_audio_start(core, 0x0001, 268 set_audio_start(core, SEL_BTSC);
275 EN_FMRADIO_EN_RDS | EN_BTSC_AUTO_STEREO);
276 set_audio_registers(core, btsc); 269 set_audio_registers(core, btsc);
270 set_audio_finish(core, mode);
277 } 271 }
278 set_audio_finish(core);
279} 272}
280 273
281 274
282static void set_audio_standard_NICAM_L(struct cx88_core *core, int stereo) 275static void set_audio_standard_NICAM_L(struct cx88_core *core, int stereo)
283{ 276{
284 /* This is probably weird.. 277 /* This is probably weird..
285 * Let's operate and find out. */ 278 * Let's operate and find out. */
286 279
287 static const struct rlist nicam_l_mono[] = { 280 static const struct rlist nicam_l_mono[] = {
288 { AUD_ERRLOGPERIOD_R, 0x00000064 }, 281 { AUD_ERRLOGPERIOD_R, 0x00000064 },
289 { AUD_ERRINTRPTTHSHLD1_R, 0x00000FFF }, 282 { AUD_ERRINTRPTTHSHLD1_R, 0x00000FFF },
290 { AUD_ERRINTRPTTHSHLD2_R, 0x0000001F }, 283 { AUD_ERRINTRPTTHSHLD2_R, 0x0000001F },
291 { AUD_ERRINTRPTTHSHLD3_R, 0x0000000F }, 284 { AUD_ERRINTRPTTHSHLD3_R, 0x0000000F },
292 285
293 { AUD_PDF_DDS_CNST_BYTE2, 0x48 }, 286 { AUD_PDF_DDS_CNST_BYTE2, 0x48 },
294 { AUD_PDF_DDS_CNST_BYTE1, 0x3D }, 287 { AUD_PDF_DDS_CNST_BYTE1, 0x3D },
295 { AUD_QAM_MODE, 0x00 }, 288 { AUD_QAM_MODE, 0x00 },
296 { AUD_PDF_DDS_CNST_BYTE0, 0xf5 }, 289 { AUD_PDF_DDS_CNST_BYTE0, 0xf5 },
297 { AUD_PHACC_FREQ_8MSB, 0x3a }, 290 { AUD_PHACC_FREQ_8MSB, 0x3a },
298 { AUD_PHACC_FREQ_8LSB, 0x4a }, 291 { AUD_PHACC_FREQ_8LSB, 0x4a },
299 292
300 { AUD_DEEMPHGAIN_R, 0x6680 }, 293 { AUD_DEEMPHGAIN_R, 0x6680 },
301 { AUD_DEEMPHNUMER1_R, 0x353DE }, 294 { AUD_DEEMPHNUMER1_R, 0x353DE },
302 { AUD_DEEMPHNUMER2_R, 0x1B1 }, 295 { AUD_DEEMPHNUMER2_R, 0x1B1 },
303 { AUD_DEEMPHDENOM1_R, 0x0F3D0 }, 296 { AUD_DEEMPHDENOM1_R, 0x0F3D0 },
304 { AUD_DEEMPHDENOM2_R, 0x0 }, 297 { AUD_DEEMPHDENOM2_R, 0x0 },
305 { AUD_FM_MODE_ENABLE, 0x7 }, 298 { AUD_FM_MODE_ENABLE, 0x7 },
306 { AUD_POLYPH80SCALEFAC, 0x3 }, 299 { AUD_POLYPH80SCALEFAC, 0x3 },
307 { AUD_AFE_12DB_EN, 0x1 }, 300 { AUD_AFE_12DB_EN, 0x1 },
308 { AAGC_GAIN, 0x0 }, 301 { AAGC_GAIN, 0x0 },
309 { AAGC_HYST, 0x18 }, 302 { AAGC_HYST, 0x18 },
310 { AAGC_DEF, 0x20 }, 303 { AAGC_DEF, 0x20 },
311 { AUD_DN0_FREQ, 0x0 }, 304 { AUD_DN0_FREQ, 0x0 },
312 { AUD_POLY0_DDS_CONSTANT, 0x0E4DB2 }, 305 { AUD_POLY0_DDS_CONSTANT, 0x0E4DB2 },
313 { AUD_DCOC_0_SRC, 0x21 }, 306 { AUD_DCOC_0_SRC, 0x21 },
314 { AUD_IIR1_0_SEL, 0x0 }, 307 { AUD_IIR1_0_SEL, 0x0 },
315 { AUD_IIR1_0_SHIFT, 0x7 }, 308 { AUD_IIR1_0_SHIFT, 0x7 },
316 { AUD_IIR1_1_SEL, 0x2 }, 309 { AUD_IIR1_1_SEL, 0x2 },
317 { AUD_IIR1_1_SHIFT, 0x0 }, 310 { AUD_IIR1_1_SHIFT, 0x0 },
318 { AUD_DCOC_1_SRC, 0x3 }, 311 { AUD_DCOC_1_SRC, 0x3 },
319 { AUD_DCOC1_SHIFT, 0x0 }, 312 { AUD_DCOC1_SHIFT, 0x0 },
320 { AUD_DCOC_PASS_IN, 0x0 }, 313 { AUD_DCOC_PASS_IN, 0x0 },
321 { AUD_IIR1_2_SEL, 0x23 }, 314 { AUD_IIR1_2_SEL, 0x23 },
322 { AUD_IIR1_2_SHIFT, 0x0 }, 315 { AUD_IIR1_2_SHIFT, 0x0 },
323 { AUD_IIR1_3_SEL, 0x4 }, 316 { AUD_IIR1_3_SEL, 0x4 },
324 { AUD_IIR1_3_SHIFT, 0x7 }, 317 { AUD_IIR1_3_SHIFT, 0x7 },
325 { AUD_IIR1_4_SEL, 0x5 }, 318 { AUD_IIR1_4_SEL, 0x5 },
326 { AUD_IIR1_4_SHIFT, 0x7 }, 319 { AUD_IIR1_4_SHIFT, 0x7 },
327 { AUD_IIR3_0_SEL, 0x7 }, 320 { AUD_IIR3_0_SEL, 0x7 },
328 { AUD_IIR3_0_SHIFT, 0x0 }, 321 { AUD_IIR3_0_SHIFT, 0x0 },
329 { AUD_DEEMPH0_SRC_SEL, 0x11 }, 322 { AUD_DEEMPH0_SRC_SEL, 0x11 },
330 { AUD_DEEMPH0_SHIFT, 0x0 }, 323 { AUD_DEEMPH0_SHIFT, 0x0 },
331 { AUD_DEEMPH0_G0, 0x7000 }, 324 { AUD_DEEMPH0_G0, 0x7000 },
332 { AUD_DEEMPH0_A0, 0x0 }, 325 { AUD_DEEMPH0_A0, 0x0 },
333 { AUD_DEEMPH0_B0, 0x0 }, 326 { AUD_DEEMPH0_B0, 0x0 },
334 { AUD_DEEMPH0_A1, 0x0 }, 327 { AUD_DEEMPH0_A1, 0x0 },
335 { AUD_DEEMPH0_B1, 0x0 }, 328 { AUD_DEEMPH0_B1, 0x0 },
336 { AUD_DEEMPH1_SRC_SEL, 0x11 }, 329 { AUD_DEEMPH1_SRC_SEL, 0x11 },
337 { AUD_DEEMPH1_SHIFT, 0x0 }, 330 { AUD_DEEMPH1_SHIFT, 0x0 },
338 { AUD_DEEMPH1_G0, 0x7000 }, 331 { AUD_DEEMPH1_G0, 0x7000 },
339 { AUD_DEEMPH1_A0, 0x0 }, 332 { AUD_DEEMPH1_A0, 0x0 },
340 { AUD_DEEMPH1_B0, 0x0 }, 333 { AUD_DEEMPH1_B0, 0x0 },
341 { AUD_DEEMPH1_A1, 0x0 }, 334 { AUD_DEEMPH1_A1, 0x0 },
342 { AUD_DEEMPH1_B1, 0x0 }, 335 { AUD_DEEMPH1_B1, 0x0 },
343 { AUD_OUT0_SEL, 0x3F }, 336 { AUD_OUT0_SEL, 0x3F },
344 { AUD_OUT1_SEL, 0x3F }, 337 { AUD_OUT1_SEL, 0x3F },
345 { AUD_DMD_RA_DDS, 0x0F5C285 }, 338 { AUD_DMD_RA_DDS, 0x0F5C285 },
346 { AUD_PLL_INT, 0x1E }, 339 { AUD_PLL_INT, 0x1E },
347 { AUD_PLL_DDS, 0x0 }, 340 { AUD_PLL_DDS, 0x0 },
348 { AUD_PLL_FRAC, 0x0E542 }, 341 { AUD_PLL_FRAC, 0x0E542 },
349 342
350 // setup QAM registers 343 // setup QAM registers
351 { AUD_RATE_ADJ1, 0x00000100 }, 344 { AUD_RATE_ADJ1, 0x00000100 },
352 { AUD_RATE_ADJ2, 0x00000200 }, 345 { AUD_RATE_ADJ2, 0x00000200 },
353 { AUD_RATE_ADJ3, 0x00000300 }, 346 { AUD_RATE_ADJ3, 0x00000300 },
354 { AUD_RATE_ADJ4, 0x00000400 }, 347 { AUD_RATE_ADJ4, 0x00000400 },
355 { AUD_RATE_ADJ5, 0x00000500 }, 348 { AUD_RATE_ADJ5, 0x00000500 },
356 { AUD_RATE_THRES_DMD, 0x000000C0 }, 349 { AUD_RATE_THRES_DMD, 0x000000C0 },
357 { /* end of list */ }, 350 { /* end of list */ },
358 }; 351 };
359
360 static const struct rlist nicam_l[] = {
361 // setup QAM registers
362 { AUD_RATE_ADJ1, 0x00000060 },
363 { AUD_RATE_ADJ2, 0x000000F9 },
364 { AUD_RATE_ADJ3, 0x000001CC },
365 { AUD_RATE_ADJ4, 0x000002B3 },
366 { AUD_RATE_ADJ5, 0x00000726 },
367 { AUD_DEEMPHDENOM1_R, 0x0000F3D0 },
368 { AUD_DEEMPHDENOM2_R, 0x00000000 },
369 { AUD_ERRLOGPERIOD_R, 0x00000064 },
370 { AUD_ERRINTRPTTHSHLD1_R, 0x00000FFF },
371 { AUD_ERRINTRPTTHSHLD2_R, 0x0000001F },
372 { AUD_ERRINTRPTTHSHLD3_R, 0x0000000F },
373 { AUD_POLYPH80SCALEFAC, 0x00000003 },
374 { AUD_DMD_RA_DDS, 0x00C00000 },
375 { AUD_PLL_INT, 0x0000001E },
376 { AUD_PLL_DDS, 0x00000000 },
377 { AUD_PLL_FRAC, 0x0000E542 },
378 { AUD_START_TIMER, 0x00000000 },
379 { AUD_DEEMPHNUMER1_R, 0x000353DE },
380 { AUD_DEEMPHNUMER2_R, 0x000001B1 },
381 { AUD_PDF_DDS_CNST_BYTE2, 0x06 },
382 { AUD_PDF_DDS_CNST_BYTE1, 0x82 },
383 { AUD_QAM_MODE, 0x05 },
384 { AUD_PDF_DDS_CNST_BYTE0, 0x12 },
385 { AUD_PHACC_FREQ_8MSB, 0x34 },
386 { AUD_PHACC_FREQ_8LSB, 0x4C },
387 { AUD_DEEMPHGAIN_R, 0x00006680 },
388 { AUD_RATE_THRES_DMD, 0x000000C0 },
389 { /* end of list */ },
390 } ;
391 dprintk("%s (status: devel), stereo : %d\n",__FUNCTION__,stereo);
392
393 if (!stereo) {
394 /* AM mono sound */
395 set_audio_start(core, 0x0004,
396 0x100c /* FIXME again */);
397 set_audio_registers(core, nicam_l_mono);
398 } else {
399 set_audio_start(core, 0x0010,
400 0x1924 /* FIXME again */);
401 set_audio_registers(core, nicam_l);
402 }
403 set_audio_finish(core);
404 352
353 static const struct rlist nicam_l[] = {
354 // setup QAM registers
355 { AUD_RATE_ADJ1, 0x00000060 },
356 { AUD_RATE_ADJ2, 0x000000F9 },
357 { AUD_RATE_ADJ3, 0x000001CC },
358 { AUD_RATE_ADJ4, 0x000002B3 },
359 { AUD_RATE_ADJ5, 0x00000726 },
360 { AUD_DEEMPHDENOM1_R, 0x0000F3D0 },
361 { AUD_DEEMPHDENOM2_R, 0x00000000 },
362 { AUD_ERRLOGPERIOD_R, 0x00000064 },
363 { AUD_ERRINTRPTTHSHLD1_R, 0x00000FFF },
364 { AUD_ERRINTRPTTHSHLD2_R, 0x0000001F },
365 { AUD_ERRINTRPTTHSHLD3_R, 0x0000000F },
366 { AUD_POLYPH80SCALEFAC, 0x00000003 },
367 { AUD_DMD_RA_DDS, 0x00C00000 },
368 { AUD_PLL_INT, 0x0000001E },
369 { AUD_PLL_DDS, 0x00000000 },
370 { AUD_PLL_FRAC, 0x0000E542 },
371 { AUD_START_TIMER, 0x00000000 },
372 { AUD_DEEMPHNUMER1_R, 0x000353DE },
373 { AUD_DEEMPHNUMER2_R, 0x000001B1 },
374 { AUD_PDF_DDS_CNST_BYTE2, 0x06 },
375 { AUD_PDF_DDS_CNST_BYTE1, 0x82 },
376 { AUD_QAM_MODE, 0x05 },
377 { AUD_PDF_DDS_CNST_BYTE0, 0x12 },
378 { AUD_PHACC_FREQ_8MSB, 0x34 },
379 { AUD_PHACC_FREQ_8LSB, 0x4C },
380 { AUD_DEEMPHGAIN_R, 0x00006680 },
381 { AUD_RATE_THRES_DMD, 0x000000C0 },
382 { /* end of list */ },
383 } ;
384 dprintk("%s (status: devel), stereo : %d\n",__FUNCTION__,stereo);
385
386 if (!stereo) {
387 /* AM Mono */
388 set_audio_start(core, SEL_A2);
389 set_audio_registers(core, nicam_l_mono);
390 set_audio_finish(core, EN_A2_FORCE_MONO1);
391 } else {
392 /* Nicam Stereo */
393 set_audio_start(core, SEL_NICAM);
394 set_audio_registers(core, nicam_l);
395 set_audio_finish(core, 0x1924); /* FIXME */
396 }
405} 397}
406 398
407static void set_audio_standard_PAL_I(struct cx88_core *core, int stereo) 399static void set_audio_standard_PAL_I(struct cx88_core *core, int stereo)
408{ 400{
409 static const struct rlist pal_i_fm_mono[] = { 401 static const struct rlist pal_i_fm_mono[] = {
410 {AUD_ERRLOGPERIOD_R, 0x00000064}, 402 {AUD_ERRLOGPERIOD_R, 0x00000064},
411 {AUD_ERRINTRPTTHSHLD1_R, 0x00000fff}, 403 {AUD_ERRINTRPTTHSHLD1_R, 0x00000fff},
412 {AUD_ERRINTRPTTHSHLD2_R, 0x0000001f}, 404 {AUD_ERRINTRPTTHSHLD2_R, 0x0000001f},
413 {AUD_ERRINTRPTTHSHLD3_R, 0x0000000f}, 405 {AUD_ERRINTRPTTHSHLD3_R, 0x0000000f},
414 {AUD_PDF_DDS_CNST_BYTE2, 0x06}, 406 {AUD_PDF_DDS_CNST_BYTE2, 0x06},
415 {AUD_PDF_DDS_CNST_BYTE1, 0x82}, 407 {AUD_PDF_DDS_CNST_BYTE1, 0x82},
416 {AUD_PDF_DDS_CNST_BYTE0, 0x12}, 408 {AUD_PDF_DDS_CNST_BYTE0, 0x12},
417 {AUD_QAM_MODE, 0x05}, 409 {AUD_QAM_MODE, 0x05},
418 {AUD_PHACC_FREQ_8MSB, 0x3a}, 410 {AUD_PHACC_FREQ_8MSB, 0x3a},
419 {AUD_PHACC_FREQ_8LSB, 0x93}, 411 {AUD_PHACC_FREQ_8LSB, 0x93},
420 {AUD_DMD_RA_DDS, 0x002a4f2f}, 412 {AUD_DMD_RA_DDS, 0x002a4f2f},
421 {AUD_PLL_INT, 0x0000001e}, 413 {AUD_PLL_INT, 0x0000001e},
422 {AUD_PLL_DDS, 0x00000004}, 414 {AUD_PLL_DDS, 0x00000004},
423 {AUD_PLL_FRAC, 0x0000e542}, 415 {AUD_PLL_FRAC, 0x0000e542},
424 {AUD_RATE_ADJ1, 0x00000100}, 416 {AUD_RATE_ADJ1, 0x00000100},
425 {AUD_RATE_ADJ2, 0x00000200}, 417 {AUD_RATE_ADJ2, 0x00000200},
426 {AUD_RATE_ADJ3, 0x00000300}, 418 {AUD_RATE_ADJ3, 0x00000300},
427 {AUD_RATE_ADJ4, 0x00000400}, 419 {AUD_RATE_ADJ4, 0x00000400},
428 {AUD_RATE_ADJ5, 0x00000500}, 420 {AUD_RATE_ADJ5, 0x00000500},
429 {AUD_THR_FR, 0x00000000}, 421 {AUD_THR_FR, 0x00000000},
430 {AUD_PILOT_BQD_1_K0, 0x0000755b}, 422 {AUD_PILOT_BQD_1_K0, 0x0000755b},
431 {AUD_PILOT_BQD_1_K1, 0x00551340}, 423 {AUD_PILOT_BQD_1_K1, 0x00551340},
432 {AUD_PILOT_BQD_1_K2, 0x006d30be}, 424 {AUD_PILOT_BQD_1_K2, 0x006d30be},
433 {AUD_PILOT_BQD_1_K3, 0xffd394af}, 425 {AUD_PILOT_BQD_1_K3, 0xffd394af},
434 {AUD_PILOT_BQD_1_K4, 0x00400000}, 426 {AUD_PILOT_BQD_1_K4, 0x00400000},
435 {AUD_PILOT_BQD_2_K0, 0x00040000}, 427 {AUD_PILOT_BQD_2_K0, 0x00040000},
436 {AUD_PILOT_BQD_2_K1, 0x002a4841}, 428 {AUD_PILOT_BQD_2_K1, 0x002a4841},
437 {AUD_PILOT_BQD_2_K2, 0x00400000}, 429 {AUD_PILOT_BQD_2_K2, 0x00400000},
438 {AUD_PILOT_BQD_2_K3, 0x00000000}, 430 {AUD_PILOT_BQD_2_K3, 0x00000000},
439 {AUD_PILOT_BQD_2_K4, 0x00000000}, 431 {AUD_PILOT_BQD_2_K4, 0x00000000},
440 {AUD_MODE_CHG_TIMER, 0x00000060}, 432 {AUD_MODE_CHG_TIMER, 0x00000060},
441 {AUD_AFE_12DB_EN, 0x00000001}, 433 {AUD_AFE_12DB_EN, 0x00000001},
442 {AAGC_HYST, 0x0000000a}, 434 {AAGC_HYST, 0x0000000a},
443 {AUD_CORDIC_SHIFT_0, 0x00000007}, 435 {AUD_CORDIC_SHIFT_0, 0x00000007},
444 {AUD_CORDIC_SHIFT_1, 0x00000007}, 436 {AUD_CORDIC_SHIFT_1, 0x00000007},
445 {AUD_C1_UP_THR, 0x00007000}, 437 {AUD_C1_UP_THR, 0x00007000},
446 {AUD_C1_LO_THR, 0x00005400}, 438 {AUD_C1_LO_THR, 0x00005400},
447 {AUD_C2_UP_THR, 0x00005400}, 439 {AUD_C2_UP_THR, 0x00005400},
448 {AUD_C2_LO_THR, 0x00003000}, 440 {AUD_C2_LO_THR, 0x00003000},
449 {AUD_DCOC_0_SRC, 0x0000001a}, 441 {AUD_DCOC_0_SRC, 0x0000001a},
450 {AUD_DCOC0_SHIFT, 0x00000000}, 442 {AUD_DCOC0_SHIFT, 0x00000000},
451 {AUD_DCOC_0_SHIFT_IN0, 0x0000000a}, 443 {AUD_DCOC_0_SHIFT_IN0, 0x0000000a},
452 {AUD_DCOC_0_SHIFT_IN1, 0x00000008}, 444 {AUD_DCOC_0_SHIFT_IN1, 0x00000008},
453 {AUD_DCOC_PASS_IN, 0x00000003}, 445 {AUD_DCOC_PASS_IN, 0x00000003},
454 {AUD_IIR3_0_SEL, 0x00000021}, 446 {AUD_IIR3_0_SEL, 0x00000021},
455 {AUD_DN2_AFC, 0x00000002}, 447 {AUD_DN2_AFC, 0x00000002},
456 {AUD_DCOC_1_SRC, 0x0000001b}, 448 {AUD_DCOC_1_SRC, 0x0000001b},
457 {AUD_DCOC1_SHIFT, 0x00000000}, 449 {AUD_DCOC1_SHIFT, 0x00000000},
458 {AUD_DCOC_1_SHIFT_IN0, 0x0000000a}, 450 {AUD_DCOC_1_SHIFT_IN0, 0x0000000a},
459 {AUD_DCOC_1_SHIFT_IN1, 0x00000008}, 451 {AUD_DCOC_1_SHIFT_IN1, 0x00000008},
460 {AUD_IIR3_1_SEL, 0x00000023}, 452 {AUD_IIR3_1_SEL, 0x00000023},
461 {AUD_DN0_FREQ, 0x000035a3}, 453 {AUD_DN0_FREQ, 0x000035a3},
462 {AUD_DN2_FREQ, 0x000029c7}, 454 {AUD_DN2_FREQ, 0x000029c7},
463 {AUD_CRDC0_SRC_SEL, 0x00000511}, 455 {AUD_CRDC0_SRC_SEL, 0x00000511},
464 {AUD_IIR1_0_SEL, 0x00000001}, 456 {AUD_IIR1_0_SEL, 0x00000001},
465 {AUD_IIR1_1_SEL, 0x00000000}, 457 {AUD_IIR1_1_SEL, 0x00000000},
466 {AUD_IIR3_2_SEL, 0x00000003}, 458 {AUD_IIR3_2_SEL, 0x00000003},
467 {AUD_IIR3_2_SHIFT, 0x00000000}, 459 {AUD_IIR3_2_SHIFT, 0x00000000},
468 {AUD_IIR3_0_SEL, 0x00000002}, 460 {AUD_IIR3_0_SEL, 0x00000002},
469 {AUD_IIR2_0_SEL, 0x00000021}, 461 {AUD_IIR2_0_SEL, 0x00000021},
470 {AUD_IIR2_0_SHIFT, 0x00000002}, 462 {AUD_IIR2_0_SHIFT, 0x00000002},
471 {AUD_DEEMPH0_SRC_SEL, 0x0000000b}, 463 {AUD_DEEMPH0_SRC_SEL, 0x0000000b},
472 {AUD_DEEMPH1_SRC_SEL, 0x0000000b}, 464 {AUD_DEEMPH1_SRC_SEL, 0x0000000b},
473 {AUD_POLYPH80SCALEFAC, 0x00000001}, 465 {AUD_POLYPH80SCALEFAC, 0x00000001},
474 {AUD_START_TIMER, 0x00000000}, 466 {AUD_START_TIMER, 0x00000000},
475 { /* end of list */ }, 467 { /* end of list */ },
476 }; 468 };
477 469
478 static const struct rlist pal_i_nicam[] = { 470 static const struct rlist pal_i_nicam[] = {
479 { AUD_RATE_ADJ1, 0x00000010 }, 471 { AUD_RATE_ADJ1, 0x00000010 },
480 { AUD_RATE_ADJ2, 0x00000040 }, 472 { AUD_RATE_ADJ2, 0x00000040 },
481 { AUD_RATE_ADJ3, 0x00000100 }, 473 { AUD_RATE_ADJ3, 0x00000100 },
482 { AUD_RATE_ADJ4, 0x00000400 }, 474 { AUD_RATE_ADJ4, 0x00000400 },
483 { AUD_RATE_ADJ5, 0x00001000 }, 475 { AUD_RATE_ADJ5, 0x00001000 },
484 // { AUD_DMD_RA_DDS, 0x00c0d5ce }, 476 // { AUD_DMD_RA_DDS, 0x00c0d5ce },
485 { AUD_DEEMPHGAIN_R, 0x000023c2 }, 477 { AUD_DEEMPHGAIN_R, 0x000023c2 },
486 { AUD_DEEMPHNUMER1_R, 0x0002a7bc }, 478 { AUD_DEEMPHNUMER1_R, 0x0002a7bc },
487 { AUD_DEEMPHNUMER2_R, 0x0003023e }, 479 { AUD_DEEMPHNUMER2_R, 0x0003023e },
488 { AUD_DEEMPHDENOM1_R, 0x0000f3d0 }, 480 { AUD_DEEMPHDENOM1_R, 0x0000f3d0 },
489 { AUD_DEEMPHDENOM2_R, 0x00000000 }, 481 { AUD_DEEMPHDENOM2_R, 0x00000000 },
490 { AUD_DEEMPHDENOM2_R, 0x00000000 }, 482 { AUD_DEEMPHDENOM2_R, 0x00000000 },
491 { AUD_ERRLOGPERIOD_R, 0x00000fff }, 483 { AUD_ERRLOGPERIOD_R, 0x00000fff },
492 { AUD_ERRINTRPTTHSHLD1_R, 0x000003ff }, 484 { AUD_ERRINTRPTTHSHLD1_R, 0x000003ff },
493 { AUD_ERRINTRPTTHSHLD2_R, 0x000000ff }, 485 { AUD_ERRINTRPTTHSHLD2_R, 0x000000ff },
494 { AUD_ERRINTRPTTHSHLD3_R, 0x0000003f }, 486 { AUD_ERRINTRPTTHSHLD3_R, 0x0000003f },
495 { AUD_POLYPH80SCALEFAC, 0x00000003 }, 487 { AUD_POLYPH80SCALEFAC, 0x00000003 },
496 { AUD_PDF_DDS_CNST_BYTE2, 0x06 }, 488 { AUD_PDF_DDS_CNST_BYTE2, 0x06 },
497 { AUD_PDF_DDS_CNST_BYTE1, 0x82 }, 489 { AUD_PDF_DDS_CNST_BYTE1, 0x82 },
498 { AUD_PDF_DDS_CNST_BYTE0, 0x16 }, 490 { AUD_PDF_DDS_CNST_BYTE0, 0x16 },
499 { AUD_QAM_MODE, 0x05 }, 491 { AUD_QAM_MODE, 0x05 },
500 { AUD_PDF_DDS_CNST_BYTE0, 0x12 }, 492 { AUD_PDF_DDS_CNST_BYTE0, 0x12 },
501 { AUD_PHACC_FREQ_8MSB, 0x3a }, 493 { AUD_PHACC_FREQ_8MSB, 0x3a },
502 { AUD_PHACC_FREQ_8LSB, 0x93 }, 494 { AUD_PHACC_FREQ_8LSB, 0x93 },
503 { /* end of list */ }, 495 { /* end of list */ },
504 }; 496 };
505 497
506 dprintk("%s (status: devel), stereo : %d\n",__FUNCTION__,stereo); 498 dprintk("%s (status: devel), stereo : %d\n",__FUNCTION__,stereo);
507 499
508 if (!stereo) { 500 if (!stereo) {
509 // FM mono 501 /* FM Mono */
510 set_audio_start(core, 0x0004, EN_DMTRX_SUMDIFF | EN_A2_FORCE_MONO1); 502 set_audio_start(core, SEL_A2);
511 set_audio_registers(core, pal_i_fm_mono); 503 set_audio_registers(core, pal_i_fm_mono);
512 } else { 504 set_audio_finish(core, EN_DMTRX_SUMDIFF | EN_A2_FORCE_MONO1);
513 // Nicam Stereo 505 } else {
514 set_audio_start(core, 0x0010, EN_DMTRX_LR | EN_DMTRX_BYPASS | EN_NICAM_AUTO_STEREO); 506 /* Nicam Stereo */
507 set_audio_start(core, SEL_NICAM);
515 set_audio_registers(core, pal_i_nicam); 508 set_audio_registers(core, pal_i_nicam);
516 } 509 set_audio_finish(core, EN_DMTRX_LR | EN_DMTRX_BYPASS | EN_NICAM_AUTO_STEREO);
517 set_audio_finish(core); 510 }
518} 511}
519 512
520static void set_audio_standard_A2(struct cx88_core *core) 513static void set_audio_standard_A2(struct cx88_core *core, u32 mode)
521{ 514{
522 /* from dscaler cvs */
523 static const struct rlist a2_common[] = { 515 static const struct rlist a2_common[] = {
524 { AUD_PDF_DDS_CNST_BYTE2, 0x06 }, 516 {AUD_ERRLOGPERIOD_R, 0x00000064},
525 { AUD_PDF_DDS_CNST_BYTE1, 0x82 }, 517 {AUD_ERRINTRPTTHSHLD1_R, 0x00000fff},
526 { AUD_PDF_DDS_CNST_BYTE0, 0x12 }, 518 {AUD_ERRINTRPTTHSHLD2_R, 0x0000001f},
527 { AUD_QAM_MODE, 0x05 }, 519 {AUD_ERRINTRPTTHSHLD3_R, 0x0000000f},
528 { AUD_PHACC_FREQ_8MSB, 0x34 }, 520 {AUD_PDF_DDS_CNST_BYTE2, 0x06},
529 { AUD_PHACC_FREQ_8LSB, 0x4c }, 521 {AUD_PDF_DDS_CNST_BYTE1, 0x82},
530 522 {AUD_PDF_DDS_CNST_BYTE0, 0x12},
531 { AUD_RATE_ADJ1, 0x00001000 }, 523 {AUD_QAM_MODE, 0x05},
532 { AUD_RATE_ADJ2, 0x00002000 }, 524 {AUD_PHACC_FREQ_8MSB, 0x34},
533 { AUD_RATE_ADJ3, 0x00003000 }, 525 {AUD_PHACC_FREQ_8LSB, 0x4c},
534 { AUD_RATE_ADJ4, 0x00004000 }, 526 {AUD_RATE_ADJ1, 0x00000100},
535 { AUD_RATE_ADJ5, 0x00005000 }, 527 {AUD_RATE_ADJ2, 0x00000200},
536 { AUD_THR_FR, 0x00000000 }, 528 {AUD_RATE_ADJ3, 0x00000300},
537 { AAGC_HYST, 0x0000001a }, 529 {AUD_RATE_ADJ4, 0x00000400},
538 { AUD_PILOT_BQD_1_K0, 0x0000755b }, 530 {AUD_RATE_ADJ5, 0x00000500},
539 { AUD_PILOT_BQD_1_K1, 0x00551340 }, 531 {AUD_THR_FR, 0x00000000},
540 { AUD_PILOT_BQD_1_K2, 0x006d30be }, 532 {AAGC_HYST, 0x0000001a},
541 { AUD_PILOT_BQD_1_K3, 0xffd394af }, 533 {AUD_PILOT_BQD_1_K0, 0x0000755b},
542 { AUD_PILOT_BQD_1_K4, 0x00400000 }, 534 {AUD_PILOT_BQD_1_K1, 0x00551340},
543 { AUD_PILOT_BQD_2_K0, 0x00040000 }, 535 {AUD_PILOT_BQD_1_K2, 0x006d30be},
544 { AUD_PILOT_BQD_2_K1, 0x002a4841 }, 536 {AUD_PILOT_BQD_1_K3, 0xffd394af},
545 { AUD_PILOT_BQD_2_K2, 0x00400000 }, 537 {AUD_PILOT_BQD_1_K4, 0x00400000},
546 { AUD_PILOT_BQD_2_K3, 0x00000000 }, 538 {AUD_PILOT_BQD_2_K0, 0x00040000},
547 { AUD_PILOT_BQD_2_K4, 0x00000000 }, 539 {AUD_PILOT_BQD_2_K1, 0x002a4841},
548 { AUD_MODE_CHG_TIMER, 0x00000040 }, 540 {AUD_PILOT_BQD_2_K2, 0x00400000},
549 { AUD_START_TIMER, 0x00000200 }, 541 {AUD_PILOT_BQD_2_K3, 0x00000000},
550 { AUD_AFE_12DB_EN, 0x00000000 }, 542 {AUD_PILOT_BQD_2_K4, 0x00000000},
551 { AUD_CORDIC_SHIFT_0, 0x00000007 }, 543 {AUD_MODE_CHG_TIMER, 0x00000040},
552 { AUD_CORDIC_SHIFT_1, 0x00000007 }, 544 {AUD_AFE_12DB_EN, 0x00000001},
553 { AUD_DEEMPH0_G0, 0x00000380 }, 545 {AUD_CORDIC_SHIFT_0, 0x00000007},
554 { AUD_DEEMPH1_G0, 0x00000380 }, 546 {AUD_CORDIC_SHIFT_1, 0x00000007},
555 { AUD_DCOC_0_SRC, 0x0000001a }, 547 {AUD_DEEMPH0_G0, 0x00000380},
556 { AUD_DCOC0_SHIFT, 0x00000000 }, 548 {AUD_DEEMPH1_G0, 0x00000380},
557 { AUD_DCOC_0_SHIFT_IN0, 0x0000000a }, 549 {AUD_DCOC_0_SRC, 0x0000001a},
558 { AUD_DCOC_0_SHIFT_IN1, 0x00000008 }, 550 {AUD_DCOC0_SHIFT, 0x00000000},
559 { AUD_DCOC_PASS_IN, 0x00000003 }, 551 {AUD_DCOC_0_SHIFT_IN0, 0x0000000a},
560 { AUD_IIR3_0_SEL, 0x00000021 }, 552 {AUD_DCOC_0_SHIFT_IN1, 0x00000008},
561 { AUD_DN2_AFC, 0x00000002 }, 553 {AUD_DCOC_PASS_IN, 0x00000003},
562 { AUD_DCOC_1_SRC, 0x0000001b }, 554 {AUD_IIR3_0_SEL, 0x00000021},
563 { AUD_DCOC1_SHIFT, 0x00000000 }, 555 {AUD_DN2_AFC, 0x00000002},
564 { AUD_DCOC_1_SHIFT_IN0, 0x0000000a }, 556 {AUD_DCOC_1_SRC, 0x0000001b},
565 { AUD_DCOC_1_SHIFT_IN1, 0x00000008 }, 557 {AUD_DCOC1_SHIFT, 0x00000000},
566 { AUD_IIR3_1_SEL, 0x00000023 }, 558 {AUD_DCOC_1_SHIFT_IN0, 0x0000000a},
567 { AUD_RDSI_SEL, 0x00000017 }, 559 {AUD_DCOC_1_SHIFT_IN1, 0x00000008},
568 { AUD_RDSI_SHIFT, 0x00000000 }, 560 {AUD_IIR3_1_SEL, 0x00000023},
569 { AUD_RDSQ_SEL, 0x00000017 }, 561 {AUD_RDSI_SEL, 0x00000017},
570 { AUD_RDSQ_SHIFT, 0x00000000 }, 562 {AUD_RDSI_SHIFT, 0x00000000},
571 { AUD_POLYPH80SCALEFAC, 0x00000001 }, 563 {AUD_RDSQ_SEL, 0x00000017},
564 {AUD_RDSQ_SHIFT, 0x00000000},
565 {AUD_PLL_INT, 0x0000001e},
566 {AUD_PLL_DDS, 0x00000000},
567 {AUD_PLL_FRAC, 0x0000e542},
568 {AUD_POLYPH80SCALEFAC, 0x00000001},
569 {AUD_START_TIMER, 0x00000000},
570 { /* end of list */ },
571 };
572 572
573 static const struct rlist a2_bg[] = {
574 {AUD_DMD_RA_DDS, 0x002a4f2f},
575 {AUD_C1_UP_THR, 0x00007000},
576 {AUD_C1_LO_THR, 0x00005400},
577 {AUD_C2_UP_THR, 0x00005400},
578 {AUD_C2_LO_THR, 0x00003000},
573 { /* end of list */ }, 579 { /* end of list */ },
574 }; 580 };
575 581
576 static const struct rlist a2_table1[] = { 582 static const struct rlist a2_dk[] = {
577 // PAL-BG 583 {AUD_DMD_RA_DDS, 0x002a4f2f},
578 { AUD_DMD_RA_DDS, 0x002a73bd }, 584 {AUD_C1_UP_THR, 0x00007000},
579 { AUD_C1_UP_THR, 0x00007000 }, 585 {AUD_C1_LO_THR, 0x00005400},
580 { AUD_C1_LO_THR, 0x00005400 }, 586 {AUD_C2_UP_THR, 0x00005400},
581 { AUD_C2_UP_THR, 0x00005400 }, 587 {AUD_C2_LO_THR, 0x00003000},
582 { AUD_C2_LO_THR, 0x00003000 }, 588 {AUD_DN0_FREQ, 0x00003a1c},
589 {AUD_DN2_FREQ, 0x0000d2e0},
583 { /* end of list */ }, 590 { /* end of list */ },
584 }; 591 };
585 static const struct rlist a2_table2[] = { 592/* unknown, probably NTSC-M */
586 // PAL-DK 593 static const struct rlist a2_m[] = {
587 { AUD_DMD_RA_DDS, 0x002a73bd }, 594 {AUD_DMD_RA_DDS, 0x002a0425},
588 { AUD_C1_UP_THR, 0x00007000 }, 595 {AUD_C1_UP_THR, 0x00003c00},
589 { AUD_C1_LO_THR, 0x00005400 }, 596 {AUD_C1_LO_THR, 0x00003000},
590 { AUD_C2_UP_THR, 0x00005400 }, 597 {AUD_C2_UP_THR, 0x00006000},
591 { AUD_C2_LO_THR, 0x00003000 }, 598 {AUD_C2_LO_THR, 0x00003c00},
592 { AUD_DN0_FREQ, 0x00003a1c }, 599 {AUD_DEEMPH0_A0, 0x00007a80},
593 { AUD_DN2_FREQ, 0x0000d2e0 }, 600 {AUD_DEEMPH1_A0, 0x00007a80},
601 {AUD_DEEMPH0_G0, 0x00001200},
602 {AUD_DEEMPH1_G0, 0x00001200},
603 {AUD_DN0_FREQ, 0x0000283b},
604 {AUD_DN1_FREQ, 0x00003418},
605 {AUD_DN2_FREQ, 0x000029c7},
606 {AUD_POLY0_DDS_CONSTANT, 0x000a7540},
594 { /* end of list */ }, 607 { /* end of list */ },
595 }; 608 };
596 static const struct rlist a2_table3[] = { 609
597 // unknown, probably NTSC-M 610 static const struct rlist a2_deemph50[] = {
598 { AUD_DMD_RA_DDS, 0x002a2873 }, 611 {AUD_DEEMPH0_G0, 0x00000380},
599 { AUD_C1_UP_THR, 0x00003c00 }, 612 {AUD_DEEMPH1_G0, 0x00000380},
600 { AUD_C1_LO_THR, 0x00003000 }, 613 {AUD_DEEMPHGAIN_R, 0x000011e1},
601 { AUD_C2_UP_THR, 0x00006000 }, 614 {AUD_DEEMPHNUMER1_R, 0x0002a7bc},
602 { AUD_C2_LO_THR, 0x00003c00 }, 615 {AUD_DEEMPHNUMER2_R, 0x0003023c},
603 { AUD_DN0_FREQ, 0x00002836 }, 616 { /* end of list */ },
604 { AUD_DN1_FREQ, 0x00003418 }, 617 };
605 { AUD_DN2_FREQ, 0x000029c7 }, 618
606 { AUD_POLY0_DDS_CONSTANT, 0x000a7540 }, 619 static const struct rlist a2_deemph75[] = {
620 {AUD_DEEMPH0_G0, 0x00000480},
621 {AUD_DEEMPH1_G0, 0x00000480},
622 {AUD_DEEMPHGAIN_R, 0x00009000},
623 {AUD_DEEMPHNUMER1_R, 0x000353de},
624 {AUD_DEEMPHNUMER2_R, 0x000001b1},
607 { /* end of list */ }, 625 { /* end of list */ },
608 }; 626 };
609 627
610 set_audio_start(core, 0x0004, EN_DMTRX_SUMDIFF | EN_A2_AUTO_STEREO); 628 set_audio_start(core, SEL_A2);
611 set_audio_registers(core, a2_common); 629 set_audio_registers(core, a2_common);
612 switch (core->tvaudio) { 630 switch (core->tvaudio) {
613 case WW_A2_BG: 631 case WW_A2_BG:
614 dprintk("%s PAL-BG A2 (status: known-good)\n",__FUNCTION__); 632 dprintk("%s PAL-BG A2 (status: known-good)\n",__FUNCTION__);
615 set_audio_registers(core, a2_table1); 633 set_audio_registers(core, a2_bg);
634 set_audio_registers(core, a2_deemph50);
616 break; 635 break;
617 case WW_A2_DK: 636 case WW_A2_DK:
618 dprintk("%s PAL-DK A2 (status: known-good)\n",__FUNCTION__); 637 dprintk("%s PAL-DK A2 (status: known-good)\n",__FUNCTION__);
619 set_audio_registers(core, a2_table2); 638 set_audio_registers(core, a2_dk);
639 set_audio_registers(core, a2_deemph50);
620 break; 640 break;
621 case WW_A2_M: 641 case WW_A2_M:
622 dprintk("%s NTSC-M A2 (status: unknown)\n",__FUNCTION__); 642 dprintk("%s NTSC-M A2 (status: unknown)\n",__FUNCTION__);
623 set_audio_registers(core, a2_table3); 643 set_audio_registers(core, a2_m);
644 set_audio_registers(core, a2_deemph75);
624 break; 645 break;
625 }; 646 };
626 set_audio_finish(core); 647
648 mode |= EN_FMRADIO_EN_RDS | EN_DMTRX_SUMDIFF;
649 set_audio_finish(core, mode);
627} 650}
628 651
629static void set_audio_standard_EIAJ(struct cx88_core *core) 652static void set_audio_standard_EIAJ(struct cx88_core *core)
@@ -635,9 +658,9 @@ static void set_audio_standard_EIAJ(struct cx88_core *core)
635 }; 658 };
636 dprintk("%s (status: unknown)\n",__FUNCTION__); 659 dprintk("%s (status: unknown)\n",__FUNCTION__);
637 660
638 set_audio_start(core, 0x0002, EN_EIAJ_AUTO_STEREO); 661 set_audio_start(core, SEL_EIAJ);
639 set_audio_registers(core, eiaj); 662 set_audio_registers(core, eiaj);
640 set_audio_finish(core); 663 set_audio_finish(core, EN_EIAJ_AUTO_STEREO);
641} 664}
642 665
643static void set_audio_standard_FM(struct cx88_core *core, enum cx88_deemph_type deemph) 666static void set_audio_standard_FM(struct cx88_core *core, enum cx88_deemph_type deemph)
@@ -683,7 +706,7 @@ static void set_audio_standard_FM(struct cx88_core *core, enum cx88_deemph_type
683 }; 706 };
684 707
685 dprintk("%s (status: unknown)\n",__FUNCTION__); 708 dprintk("%s (status: unknown)\n",__FUNCTION__);
686 set_audio_start(core, 0x0020, EN_FMRADIO_AUTO_STEREO); 709 set_audio_start(core, SEL_FMRADIO);
687 710
688 switch (deemph) 711 switch (deemph)
689 { 712 {
@@ -700,7 +723,7 @@ static void set_audio_standard_FM(struct cx88_core *core, enum cx88_deemph_type
700 break; 723 break;
701 } 724 }
702 725
703 set_audio_finish(core); 726 set_audio_finish(core, EN_FMRADIO_AUTO_STEREO);
704} 727}
705 728
706/* ----------------------------------------------------------- */ 729/* ----------------------------------------------------------- */
@@ -709,7 +732,7 @@ void cx88_set_tvaudio(struct cx88_core *core)
709{ 732{
710 switch (core->tvaudio) { 733 switch (core->tvaudio) {
711 case WW_BTSC: 734 case WW_BTSC:
712 set_audio_standard_BTSC(core,0); 735 set_audio_standard_BTSC(core, 0, EN_BTSC_AUTO_STEREO);
713 break; 736 break;
714 case WW_NICAM_BGDKL: 737 case WW_NICAM_BGDKL:
715 set_audio_standard_NICAM_L(core,0); 738 set_audio_standard_NICAM_L(core,0);
@@ -720,7 +743,7 @@ void cx88_set_tvaudio(struct cx88_core *core)
720 case WW_A2_BG: 743 case WW_A2_BG:
721 case WW_A2_DK: 744 case WW_A2_DK:
722 case WW_A2_M: 745 case WW_A2_M:
723 set_audio_standard_A2(core); 746 set_audio_standard_A2(core, EN_A2_FORCE_MONO1);
724 break; 747 break;
725 case WW_EIAJ: 748 case WW_EIAJ:
726 set_audio_standard_EIAJ(core); 749 set_audio_standard_EIAJ(core);
@@ -734,7 +757,7 @@ void cx88_set_tvaudio(struct cx88_core *core)
734 case WW_NONE: 757 case WW_NONE:
735 default: 758 default:
736 printk("%s/0: unknown tv audio mode [%d]\n", 759 printk("%s/0: unknown tv audio mode [%d]\n",
737 core->name, core->tvaudio); 760 core->name, core->tvaudio);
738 break; 761 break;
739 } 762 }
740 return; 763 return;
@@ -769,6 +792,13 @@ void cx88_get_stereo(struct cx88_core *core, struct v4l2_tuner *t)
769 aud_ctl_names[cx_read(AUD_CTL) & 63]); 792 aud_ctl_names[cx_read(AUD_CTL) & 63]);
770 core->astat = reg; 793 core->astat = reg;
771 794
795/* TODO
796 Reading from AUD_STATUS is not enough
797 for auto-detecting sap/dual-fm/nicam.
798 Add some code here later.
799*/
800
801# if 0
772 t->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_SAP | 802 t->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_SAP |
773 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2; 803 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
774 t->rxsubchans = V4L2_TUNER_SUB_MONO; 804 t->rxsubchans = V4L2_TUNER_SUB_MONO;
@@ -779,7 +809,7 @@ void cx88_get_stereo(struct cx88_core *core, struct v4l2_tuner *t)
779 t->capability = V4L2_TUNER_CAP_STEREO | 809 t->capability = V4L2_TUNER_CAP_STEREO |
780 V4L2_TUNER_CAP_SAP; 810 V4L2_TUNER_CAP_SAP;
781 t->rxsubchans = V4L2_TUNER_SUB_STEREO; 811 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
782 if (1 == pilot) { 812 if (1 == pilot) {
783 /* SAP */ 813 /* SAP */
784 t->rxsubchans |= V4L2_TUNER_SUB_SAP; 814 t->rxsubchans |= V4L2_TUNER_SUB_SAP;
785 } 815 }
@@ -787,13 +817,13 @@ void cx88_get_stereo(struct cx88_core *core, struct v4l2_tuner *t)
787 case WW_A2_BG: 817 case WW_A2_BG:
788 case WW_A2_DK: 818 case WW_A2_DK:
789 case WW_A2_M: 819 case WW_A2_M:
790 if (1 == pilot) { 820 if (1 == pilot) {
791 /* stereo */ 821 /* stereo */
792 t->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO; 822 t->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
793 if (0 == mode) 823 if (0 == mode)
794 t->audmode = V4L2_TUNER_MODE_STEREO; 824 t->audmode = V4L2_TUNER_MODE_STEREO;
795 } 825 }
796 if (2 == pilot) { 826 if (2 == pilot) {
797 /* dual language -- FIXME */ 827 /* dual language -- FIXME */
798 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; 828 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
799 t->audmode = V4L2_TUNER_MODE_LANG1; 829 t->audmode = V4L2_TUNER_MODE_LANG1;
@@ -805,16 +835,17 @@ void cx88_get_stereo(struct cx88_core *core, struct v4l2_tuner *t)
805 t->rxsubchans |= V4L2_TUNER_SUB_STEREO; 835 t->rxsubchans |= V4L2_TUNER_SUB_STEREO;
806 } 836 }
807 break; 837 break;
808 case WW_SYSTEM_L_AM: 838 case WW_SYSTEM_L_AM:
809 if (0x0 == mode && !(cx_read(AUD_INIT) & 0x04)) { 839 if (0x0 == mode && !(cx_read(AUD_INIT) & 0x04)) {
810 t->audmode = V4L2_TUNER_MODE_STEREO; 840 t->audmode = V4L2_TUNER_MODE_STEREO;
811 t->rxsubchans |= V4L2_TUNER_SUB_STEREO; 841 t->rxsubchans |= V4L2_TUNER_SUB_STEREO;
812 } 842 }
813 break ; 843 break ;
814 default: 844 default:
815 /* nothing */ 845 /* nothing */
816 break; 846 break;
817 } 847 }
848# endif
818 return; 849 return;
819} 850}
820 851
@@ -835,16 +866,16 @@ void cx88_set_stereo(struct cx88_core *core, u32 mode, int manual)
835 case WW_BTSC: 866 case WW_BTSC:
836 switch (mode) { 867 switch (mode) {
837 case V4L2_TUNER_MODE_MONO: 868 case V4L2_TUNER_MODE_MONO:
838 ctl = EN_BTSC_FORCE_MONO; 869 set_audio_standard_BTSC(core, 0, EN_BTSC_FORCE_MONO);
839 mask = 0x3f;
840 break; 870 break;
841 case V4L2_TUNER_MODE_SAP: 871 case V4L2_TUNER_MODE_LANG1:
842 ctl = EN_BTSC_FORCE_SAP; 872 set_audio_standard_BTSC(core, 0, EN_BTSC_AUTO_STEREO);
843 mask = 0x3f; 873 break;
874 case V4L2_TUNER_MODE_LANG2:
875 set_audio_standard_BTSC(core, 1, EN_BTSC_FORCE_SAP);
844 break; 876 break;
845 case V4L2_TUNER_MODE_STEREO: 877 case V4L2_TUNER_MODE_STEREO:
846 ctl = EN_BTSC_AUTO_STEREO; 878 set_audio_standard_BTSC(core, 0, EN_BTSC_FORCE_STEREO);
847 mask = 0x3f;
848 break; 879 break;
849 } 880 }
850 break; 881 break;
@@ -854,16 +885,13 @@ void cx88_set_stereo(struct cx88_core *core, u32 mode, int manual)
854 switch (mode) { 885 switch (mode) {
855 case V4L2_TUNER_MODE_MONO: 886 case V4L2_TUNER_MODE_MONO:
856 case V4L2_TUNER_MODE_LANG1: 887 case V4L2_TUNER_MODE_LANG1:
857 ctl = EN_A2_FORCE_MONO1; 888 set_audio_standard_A2(core, EN_A2_FORCE_MONO1);
858 mask = 0x3f;
859 break; 889 break;
860 case V4L2_TUNER_MODE_LANG2: 890 case V4L2_TUNER_MODE_LANG2:
861 ctl = EN_A2_AUTO_MONO2; 891 set_audio_standard_A2(core, EN_A2_FORCE_MONO2);
862 mask = 0x3f;
863 break; 892 break;
864 case V4L2_TUNER_MODE_STEREO: 893 case V4L2_TUNER_MODE_STEREO:
865 ctl = EN_A2_AUTO_STEREO | EN_DMTRX_SUMR; 894 set_audio_standard_A2(core, EN_A2_FORCE_STEREO);
866 mask = 0x8bf;
867 break; 895 break;
868 } 896 }
869 break; 897 break;
diff --git a/drivers/media/video/cx88/cx88-vbi.c b/drivers/media/video/cx88/cx88-vbi.c
index 320d57888b..9bc6c89955 100644
--- a/drivers/media/video/cx88/cx88-vbi.c
+++ b/drivers/media/video/cx88/cx88-vbi.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: cx88-vbi.c,v 1.17 2005/06/12 04:19:19 mchehab Exp $
3 */ 2 */
4#include <linux/kernel.h> 3#include <linux/kernel.h>
5#include <linux/module.h> 4#include <linux/module.h>
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index 5f58c10319..3dbc074fb5 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: cx88-video.c,v 1.82 2005/07/22 05:13:34 mkrufky Exp $
3 * 2 *
4 * device driver for Conexant 2388x based TV cards 3 * device driver for Conexant 2388x based TV cards
5 * video4linux video interface 4 * video4linux video interface
@@ -66,7 +65,7 @@ module_param(vid_limit,int,0644);
66MODULE_PARM_DESC(vid_limit,"capture memory limit in megabytes"); 65MODULE_PARM_DESC(vid_limit,"capture memory limit in megabytes");
67 66
68#define dprintk(level,fmt, arg...) if (video_debug >= level) \ 67#define dprintk(level,fmt, arg...) if (video_debug >= level) \
69 printk(KERN_DEBUG "%s/0: " fmt, dev->core->name , ## arg) 68 printk(KERN_DEBUG "%s/0: " fmt, core->name , ## arg)
70 69
71/* ------------------------------------------------------------------ */ 70/* ------------------------------------------------------------------ */
72 71
@@ -326,22 +325,23 @@ static const int CX8800_CTLS = ARRAY_SIZE(cx8800_ctls);
326 325
327static int res_get(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bit) 326static int res_get(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bit)
328{ 327{
328 struct cx88_core *core = dev->core;
329 if (fh->resources & bit) 329 if (fh->resources & bit)
330 /* have it already allocated */ 330 /* have it already allocated */
331 return 1; 331 return 1;
332 332
333 /* is it free? */ 333 /* is it free? */
334 down(&dev->lock); 334 down(&core->lock);
335 if (dev->resources & bit) { 335 if (dev->resources & bit) {
336 /* no, someone else uses it */ 336 /* no, someone else uses it */
337 up(&dev->lock); 337 up(&core->lock);
338 return 0; 338 return 0;
339 } 339 }
340 /* it's free, grab it */ 340 /* it's free, grab it */
341 fh->resources |= bit; 341 fh->resources |= bit;
342 dev->resources |= bit; 342 dev->resources |= bit;
343 dprintk(1,"res: get %d\n",bit); 343 dprintk(1,"res: get %d\n",bit);
344 up(&dev->lock); 344 up(&core->lock);
345 return 1; 345 return 1;
346} 346}
347 347
@@ -360,27 +360,29 @@ int res_locked(struct cx8800_dev *dev, unsigned int bit)
360static 360static
361void res_free(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bits) 361void res_free(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bits)
362{ 362{
363 struct cx88_core *core = dev->core;
363 if ((fh->resources & bits) != bits) 364 if ((fh->resources & bits) != bits)
364 BUG(); 365 BUG();
365 366
366 down(&dev->lock); 367 down(&core->lock);
367 fh->resources &= ~bits; 368 fh->resources &= ~bits;
368 dev->resources &= ~bits; 369 dev->resources &= ~bits;
369 dprintk(1,"res: put %d\n",bits); 370 dprintk(1,"res: put %d\n",bits);
370 up(&dev->lock); 371 up(&core->lock);
371} 372}
372 373
373/* ------------------------------------------------------------------ */ 374/* ------------------------------------------------------------------ */
374 375
375static int video_mux(struct cx8800_dev *dev, unsigned int input) 376/* static int video_mux(struct cx8800_dev *dev, unsigned int input) */
377static int video_mux(struct cx88_core *core, unsigned int input)
376{ 378{
377 struct cx88_core *core = dev->core; 379 /* struct cx88_core *core = dev->core; */
378 380
379 dprintk(1,"video_mux: %d [vmux=%d,gpio=0x%x,0x%x,0x%x,0x%x]\n", 381 dprintk(1,"video_mux: %d [vmux=%d,gpio=0x%x,0x%x,0x%x,0x%x]\n",
380 input, INPUT(input)->vmux, 382 input, INPUT(input)->vmux,
381 INPUT(input)->gpio0,INPUT(input)->gpio1, 383 INPUT(input)->gpio0,INPUT(input)->gpio1,
382 INPUT(input)->gpio2,INPUT(input)->gpio3); 384 INPUT(input)->gpio2,INPUT(input)->gpio3);
383 dev->core->input = input; 385 core->input = input;
384 cx_andor(MO_INPUT_FORMAT, 0x03 << 14, INPUT(input)->vmux << 14); 386 cx_andor(MO_INPUT_FORMAT, 0x03 << 14, INPUT(input)->vmux << 14);
385 cx_write(MO_GP3_IO, INPUT(input)->gpio3); 387 cx_write(MO_GP3_IO, INPUT(input)->gpio3);
386 cx_write(MO_GP0_IO, INPUT(input)->gpio0); 388 cx_write(MO_GP0_IO, INPUT(input)->gpio0);
@@ -413,9 +415,9 @@ static int start_video_dma(struct cx8800_dev *dev,
413 struct cx88_core *core = dev->core; 415 struct cx88_core *core = dev->core;
414 416
415 /* setup fifo + format */ 417 /* setup fifo + format */
416 cx88_sram_channel_setup(dev->core, &cx88_sram_channels[SRAM_CH21], 418 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH21],
417 buf->bpl, buf->risc.dma); 419 buf->bpl, buf->risc.dma);
418 cx88_set_scale(dev->core, buf->vb.width, buf->vb.height, buf->vb.field); 420 cx88_set_scale(core, buf->vb.width, buf->vb.height, buf->vb.field);
419 cx_write(MO_COLOR_CTRL, buf->fmt->cxformat | ColorFormatGamma); 421 cx_write(MO_COLOR_CTRL, buf->fmt->cxformat | ColorFormatGamma);
420 422
421 /* reset counter */ 423 /* reset counter */
@@ -424,6 +426,14 @@ static int start_video_dma(struct cx8800_dev *dev,
424 426
425 /* enable irqs */ 427 /* enable irqs */
426 cx_set(MO_PCI_INTMSK, core->pci_irqmask | 0x01); 428 cx_set(MO_PCI_INTMSK, core->pci_irqmask | 0x01);
429
430 /* Enables corresponding bits at PCI_INT_STAT:
431 bits 0 to 4: video, audio, transport stream, VIP, Host
432 bit 7: timer
433 bits 8 and 9: DMA complete for: SRC, DST
434 bits 10 and 11: BERR signal asserted for RISC: RD, WR
435 bits 12 to 15: BERR signal asserted for: BRDG, SRC, DST, IPB
436 */
427 cx_set(MO_VID_INTMSK, 0x0f0011); 437 cx_set(MO_VID_INTMSK, 0x0f0011);
428 438
429 /* enable capture */ 439 /* enable capture */
@@ -431,7 +441,7 @@ static int start_video_dma(struct cx8800_dev *dev,
431 441
432 /* start dma */ 442 /* start dma */
433 cx_set(MO_DEV_CNTRL2, (1<<5)); 443 cx_set(MO_DEV_CNTRL2, (1<<5));
434 cx_set(MO_VID_DMACNTRL, 0x11); 444 cx_set(MO_VID_DMACNTRL, 0x11); /* Planar Y and packed FIFO and RISC enable */
435 445
436 return 0; 446 return 0;
437} 447}
@@ -455,6 +465,7 @@ static int stop_video_dma(struct cx8800_dev *dev)
455static int restart_video_queue(struct cx8800_dev *dev, 465static int restart_video_queue(struct cx8800_dev *dev,
456 struct cx88_dmaqueue *q) 466 struct cx88_dmaqueue *q)
457{ 467{
468 struct cx88_core *core = dev->core;
458 struct cx88_buffer *buf, *prev; 469 struct cx88_buffer *buf, *prev;
459 struct list_head *item; 470 struct list_head *item;
460 471
@@ -524,12 +535,13 @@ buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
524{ 535{
525 struct cx8800_fh *fh = q->priv_data; 536 struct cx8800_fh *fh = q->priv_data;
526 struct cx8800_dev *dev = fh->dev; 537 struct cx8800_dev *dev = fh->dev;
538 struct cx88_core *core = dev->core;
527 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); 539 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
528 int rc, init_buffer = 0; 540 int rc, init_buffer = 0;
529 541
530 BUG_ON(NULL == fh->fmt); 542 BUG_ON(NULL == fh->fmt);
531 if (fh->width < 48 || fh->width > norm_maxw(dev->core->tvnorm) || 543 if (fh->width < 48 || fh->width > norm_maxw(core->tvnorm) ||
532 fh->height < 32 || fh->height > norm_maxh(dev->core->tvnorm)) 544 fh->height < 32 || fh->height > norm_maxh(core->tvnorm))
533 return -EINVAL; 545 return -EINVAL;
534 buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3; 546 buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3;
535 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) 547 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
@@ -609,6 +621,7 @@ buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
609 struct cx88_buffer *prev; 621 struct cx88_buffer *prev;
610 struct cx8800_fh *fh = vq->priv_data; 622 struct cx8800_fh *fh = vq->priv_data;
611 struct cx8800_dev *dev = fh->dev; 623 struct cx8800_dev *dev = fh->dev;
624 struct cx88_core *core = dev->core;
612 struct cx88_dmaqueue *q = &dev->vidq; 625 struct cx88_dmaqueue *q = &dev->vidq;
613 626
614 /* add jump to stopper */ 627 /* add jump to stopper */
@@ -701,6 +714,7 @@ static int video_open(struct inode *inode, struct file *file)
701{ 714{
702 int minor = iminor(inode); 715 int minor = iminor(inode);
703 struct cx8800_dev *h,*dev = NULL; 716 struct cx8800_dev *h,*dev = NULL;
717 struct cx88_core *core;
704 struct cx8800_fh *fh; 718 struct cx8800_fh *fh;
705 struct list_head *list; 719 struct list_head *list;
706 enum v4l2_buf_type type = 0; 720 enum v4l2_buf_type type = 0;
@@ -725,6 +739,8 @@ static int video_open(struct inode *inode, struct file *file)
725 if (NULL == dev) 739 if (NULL == dev)
726 return -ENODEV; 740 return -ENODEV;
727 741
742 core = dev->core;
743
728 dprintk(1,"open minor=%d radio=%d type=%s\n", 744 dprintk(1,"open minor=%d radio=%d type=%s\n",
729 minor,radio,v4l2_type_names[type]); 745 minor,radio,v4l2_type_names[type]);
730 746
@@ -755,17 +771,16 @@ static int video_open(struct inode *inode, struct file *file)
755 fh); 771 fh);
756 772
757 if (fh->radio) { 773 if (fh->radio) {
758 struct cx88_core *core = dev->core;
759 int board = core->board; 774 int board = core->board;
760 dprintk(1,"video_open: setting radio device\n"); 775 dprintk(1,"video_open: setting radio device\n");
761 cx_write(MO_GP3_IO, cx88_boards[board].radio.gpio3); 776 cx_write(MO_GP3_IO, cx88_boards[board].radio.gpio3);
762 cx_write(MO_GP0_IO, cx88_boards[board].radio.gpio0); 777 cx_write(MO_GP0_IO, cx88_boards[board].radio.gpio0);
763 cx_write(MO_GP1_IO, cx88_boards[board].radio.gpio1); 778 cx_write(MO_GP1_IO, cx88_boards[board].radio.gpio1);
764 cx_write(MO_GP2_IO, cx88_boards[board].radio.gpio2); 779 cx_write(MO_GP2_IO, cx88_boards[board].radio.gpio2);
765 dev->core->tvaudio = WW_FM; 780 core->tvaudio = WW_FM;
766 cx88_set_tvaudio(core); 781 cx88_set_tvaudio(core);
767 cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1); 782 cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1);
768 cx88_call_i2c_clients(dev->core,AUDC_SET_RADIO,NULL); 783 cx88_call_i2c_clients(core,AUDC_SET_RADIO,NULL);
769 } 784 }
770 785
771 return 0; 786 return 0;
@@ -857,6 +872,9 @@ static int video_release(struct inode *inode, struct file *file)
857 videobuf_mmap_free(&fh->vbiq); 872 videobuf_mmap_free(&fh->vbiq);
858 file->private_data = NULL; 873 file->private_data = NULL;
859 kfree(fh); 874 kfree(fh);
875
876 cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
877
860 return 0; 878 return 0;
861} 879}
862 880
@@ -870,9 +888,10 @@ video_mmap(struct file *file, struct vm_area_struct * vma)
870 888
871/* ------------------------------------------------------------------ */ 889/* ------------------------------------------------------------------ */
872 890
873static int get_control(struct cx8800_dev *dev, struct v4l2_control *ctl) 891/* static int get_control(struct cx8800_dev *dev, struct v4l2_control *ctl) */
892static int get_control(struct cx88_core *core, struct v4l2_control *ctl)
874{ 893{
875 struct cx88_core *core = dev->core; 894 /* struct cx88_core *core = dev->core; */
876 struct cx88_ctrl *c = NULL; 895 struct cx88_ctrl *c = NULL;
877 u32 value; 896 u32 value;
878 int i; 897 int i;
@@ -898,9 +917,10 @@ static int get_control(struct cx8800_dev *dev, struct v4l2_control *ctl)
898 return 0; 917 return 0;
899} 918}
900 919
901static int set_control(struct cx8800_dev *dev, struct v4l2_control *ctl) 920/* static int set_control(struct cx8800_dev *dev, struct v4l2_control *ctl) */
921static int set_control(struct cx88_core *core, struct v4l2_control *ctl)
902{ 922{
903 struct cx88_core *core = dev->core; 923 /* struct cx88_core *core = dev->core; */
904 struct cx88_ctrl *c = NULL; 924 struct cx88_ctrl *c = NULL;
905 u32 v_sat_value; 925 u32 v_sat_value;
906 u32 value; 926 u32 value;
@@ -913,9 +933,9 @@ static int set_control(struct cx8800_dev *dev, struct v4l2_control *ctl)
913 return -EINVAL; 933 return -EINVAL;
914 934
915 if (ctl->value < c->v.minimum) 935 if (ctl->value < c->v.minimum)
916 return -ERANGE; 936 ctl->value = c->v.minimum;
917 if (ctl->value > c->v.maximum) 937 if (ctl->value > c->v.maximum)
918 return -ERANGE; 938 ctl->value = c->v.maximum;
919 switch (ctl->id) { 939 switch (ctl->id) {
920 case V4L2_CID_AUDIO_BALANCE: 940 case V4L2_CID_AUDIO_BALANCE:
921 value = (ctl->value < 0x40) ? (0x40 - ctl->value) : ctl->value; 941 value = (ctl->value < 0x40) ? (0x40 - ctl->value) : ctl->value;
@@ -946,7 +966,8 @@ static int set_control(struct cx8800_dev *dev, struct v4l2_control *ctl)
946 return 0; 966 return 0;
947} 967}
948 968
949static void init_controls(struct cx8800_dev *dev) 969/* static void init_controls(struct cx8800_dev *dev) */
970static void init_controls(struct cx88_core *core)
950{ 971{
951 static struct v4l2_control mute = { 972 static struct v4l2_control mute = {
952 .id = V4L2_CID_AUDIO_MUTE, 973 .id = V4L2_CID_AUDIO_MUTE,
@@ -969,11 +990,11 @@ static void init_controls(struct cx8800_dev *dev)
969 .value = 0x80, 990 .value = 0x80,
970 }; 991 };
971 992
972 set_control(dev,&mute); 993 set_control(core,&mute);
973 set_control(dev,&volume); 994 set_control(core,&volume);
974 set_control(dev,&hue); 995 set_control(core,&hue);
975 set_control(dev,&contrast); 996 set_control(core,&contrast);
976 set_control(dev,&brightness); 997 set_control(core,&brightness);
977} 998}
978 999
979/* ------------------------------------------------------------------ */ 1000/* ------------------------------------------------------------------ */
@@ -1004,6 +1025,8 @@ static int cx8800_g_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh,
1004static int cx8800_try_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh, 1025static int cx8800_try_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh,
1005 struct v4l2_format *f) 1026 struct v4l2_format *f)
1006{ 1027{
1028 struct cx88_core *core = dev->core;
1029
1007 switch (f->type) { 1030 switch (f->type) {
1008 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 1031 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1009 { 1032 {
@@ -1016,8 +1039,8 @@ static int cx8800_try_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh,
1016 return -EINVAL; 1039 return -EINVAL;
1017 1040
1018 field = f->fmt.pix.field; 1041 field = f->fmt.pix.field;
1019 maxw = norm_maxw(dev->core->tvnorm); 1042 maxw = norm_maxw(core->tvnorm);
1020 maxh = norm_maxh(dev->core->tvnorm); 1043 maxh = norm_maxh(core->tvnorm);
1021 1044
1022 if (V4L2_FIELD_ANY == field) { 1045 if (V4L2_FIELD_ANY == field) {
1023 field = (f->fmt.pix.height > maxh/2) 1046 field = (f->fmt.pix.height > maxh/2)
@@ -1101,12 +1124,14 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1101 if (video_debug > 1) 1124 if (video_debug > 1)
1102 cx88_print_ioctl(core->name,cmd); 1125 cx88_print_ioctl(core->name,cmd);
1103 switch (cmd) { 1126 switch (cmd) {
1127
1128 /* --- capabilities ------------------------------------------ */
1104 case VIDIOC_QUERYCAP: 1129 case VIDIOC_QUERYCAP:
1105 { 1130 {
1106 struct v4l2_capability *cap = arg; 1131 struct v4l2_capability *cap = arg;
1107 1132
1108 memset(cap,0,sizeof(*cap)); 1133 memset(cap,0,sizeof(*cap));
1109 strcpy(cap->driver, "cx8800"); 1134 strcpy(cap->driver, "cx8800");
1110 strlcpy(cap->card, cx88_boards[core->board].name, 1135 strlcpy(cap->card, cx88_boards[core->board].name,
1111 sizeof(cap->card)); 1136 sizeof(cap->card));
1112 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci)); 1137 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
@@ -1116,12 +1141,128 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1116 V4L2_CAP_READWRITE | 1141 V4L2_CAP_READWRITE |
1117 V4L2_CAP_STREAMING | 1142 V4L2_CAP_STREAMING |
1118 V4L2_CAP_VBI_CAPTURE | 1143 V4L2_CAP_VBI_CAPTURE |
1144 V4L2_CAP_VIDEO_OVERLAY |
1119 0; 1145 0;
1120 if (UNSET != core->tuner_type) 1146 if (UNSET != core->tuner_type)
1121 cap->capabilities |= V4L2_CAP_TUNER; 1147 cap->capabilities |= V4L2_CAP_TUNER;
1122 return 0; 1148 return 0;
1123 } 1149 }
1124 1150
1151 /* --- capture ioctls ---------------------------------------- */
1152 case VIDIOC_ENUM_FMT:
1153 {
1154 struct v4l2_fmtdesc *f = arg;
1155 enum v4l2_buf_type type;
1156 unsigned int index;
1157
1158 index = f->index;
1159 type = f->type;
1160 switch (type) {
1161 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1162 if (index >= ARRAY_SIZE(formats))
1163 return -EINVAL;
1164 memset(f,0,sizeof(*f));
1165 f->index = index;
1166 f->type = type;
1167 strlcpy(f->description,formats[index].name,sizeof(f->description));
1168 f->pixelformat = formats[index].fourcc;
1169 break;
1170 default:
1171 return -EINVAL;
1172 }
1173 return 0;
1174 }
1175 case VIDIOC_G_FMT:
1176 {
1177 struct v4l2_format *f = arg;
1178 return cx8800_g_fmt(dev,fh,f);
1179 }
1180 case VIDIOC_S_FMT:
1181 {
1182 struct v4l2_format *f = arg;
1183 return cx8800_s_fmt(dev,fh,f);
1184 }
1185 case VIDIOC_TRY_FMT:
1186 {
1187 struct v4l2_format *f = arg;
1188 return cx8800_try_fmt(dev,fh,f);
1189 }
1190
1191 /* --- streaming capture ------------------------------------- */
1192 case VIDIOCGMBUF:
1193 {
1194 struct video_mbuf *mbuf = arg;
1195 struct videobuf_queue *q;
1196 struct v4l2_requestbuffers req;
1197 unsigned int i;
1198
1199 q = get_queue(fh);
1200 memset(&req,0,sizeof(req));
1201 req.type = q->type;
1202 req.count = 8;
1203 req.memory = V4L2_MEMORY_MMAP;
1204 err = videobuf_reqbufs(q,&req);
1205 if (err < 0)
1206 return err;
1207 memset(mbuf,0,sizeof(*mbuf));
1208 mbuf->frames = req.count;
1209 mbuf->size = 0;
1210 for (i = 0; i < mbuf->frames; i++) {
1211 mbuf->offsets[i] = q->bufs[i]->boff;
1212 mbuf->size += q->bufs[i]->bsize;
1213 }
1214 return 0;
1215 }
1216 case VIDIOC_REQBUFS:
1217 return videobuf_reqbufs(get_queue(fh), arg);
1218
1219 case VIDIOC_QUERYBUF:
1220 return videobuf_querybuf(get_queue(fh), arg);
1221
1222 case VIDIOC_QBUF:
1223 return videobuf_qbuf(get_queue(fh), arg);
1224
1225 case VIDIOC_DQBUF:
1226 return videobuf_dqbuf(get_queue(fh), arg,
1227 file->f_flags & O_NONBLOCK);
1228
1229 case VIDIOC_STREAMON:
1230 {
1231 int res = get_ressource(fh);
1232
1233 if (!res_get(dev,fh,res))
1234 return -EBUSY;
1235 return videobuf_streamon(get_queue(fh));
1236 }
1237 case VIDIOC_STREAMOFF:
1238 {
1239 int res = get_ressource(fh);
1240
1241 err = videobuf_streamoff(get_queue(fh));
1242 if (err < 0)
1243 return err;
1244 res_free(dev,fh,res);
1245 return 0;
1246 }
1247
1248 default:
1249 return cx88_do_ioctl( inode, file, fh->radio, core, cmd, arg, video_do_ioctl );
1250 }
1251 return 0;
1252}
1253
1254int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
1255 struct cx88_core *core, unsigned int cmd, void *arg, v4l2_kioctl driver_ioctl)
1256{
1257 int err;
1258
1259 if (video_debug > 1)
1260 cx88_print_ioctl(core->name,cmd);
1261 printk( KERN_INFO "CORE IOCTL: 0x%x\n", cmd );
1262 cx88_print_ioctl(core->name,cmd);
1263 dprintk( 1, "CORE IOCTL: 0x%x\n", cmd );
1264
1265 switch (cmd) {
1125 /* ---------- tv norms ---------- */ 1266 /* ---------- tv norms ---------- */
1126 case VIDIOC_ENUMSTD: 1267 case VIDIOC_ENUMSTD:
1127 { 1268 {
@@ -1156,9 +1297,9 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1156 if (i == ARRAY_SIZE(tvnorms)) 1297 if (i == ARRAY_SIZE(tvnorms))
1157 return -EINVAL; 1298 return -EINVAL;
1158 1299
1159 down(&dev->lock); 1300 down(&core->lock);
1160 cx88_set_tvnorm(dev->core,&tvnorms[i]); 1301 cx88_set_tvnorm(core,&tvnorms[i]);
1161 up(&dev->lock); 1302 up(&core->lock);
1162 return 0; 1303 return 0;
1163 } 1304 }
1164 1305
@@ -1199,7 +1340,7 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1199 { 1340 {
1200 unsigned int *i = arg; 1341 unsigned int *i = arg;
1201 1342
1202 *i = dev->core->input; 1343 *i = core->input;
1203 return 0; 1344 return 0;
1204 } 1345 }
1205 case VIDIOC_S_INPUT: 1346 case VIDIOC_S_INPUT:
@@ -1208,55 +1349,15 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1208 1349
1209 if (*i >= 4) 1350 if (*i >= 4)
1210 return -EINVAL; 1351 return -EINVAL;
1211 down(&dev->lock); 1352 down(&core->lock);
1212 cx88_newstation(core); 1353 cx88_newstation(core);
1213 video_mux(dev,*i); 1354 video_mux(core,*i);
1214 up(&dev->lock); 1355 up(&core->lock);
1215 return 0; 1356 return 0;
1216 } 1357 }
1217 1358
1218 1359
1219 1360
1220 /* --- capture ioctls ---------------------------------------- */
1221 case VIDIOC_ENUM_FMT:
1222 {
1223 struct v4l2_fmtdesc *f = arg;
1224 enum v4l2_buf_type type;
1225 unsigned int index;
1226
1227 index = f->index;
1228 type = f->type;
1229 switch (type) {
1230 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1231 if (index >= ARRAY_SIZE(formats))
1232 return -EINVAL;
1233 memset(f,0,sizeof(*f));
1234 f->index = index;
1235 f->type = type;
1236 strlcpy(f->description,formats[index].name,sizeof(f->description));
1237 f->pixelformat = formats[index].fourcc;
1238 break;
1239 default:
1240 return -EINVAL;
1241 }
1242 return 0;
1243 }
1244 case VIDIOC_G_FMT:
1245 {
1246 struct v4l2_format *f = arg;
1247 return cx8800_g_fmt(dev,fh,f);
1248 }
1249 case VIDIOC_S_FMT:
1250 {
1251 struct v4l2_format *f = arg;
1252 return cx8800_s_fmt(dev,fh,f);
1253 }
1254 case VIDIOC_TRY_FMT:
1255 {
1256 struct v4l2_format *f = arg;
1257 return cx8800_try_fmt(dev,fh,f);
1258 }
1259
1260 /* --- controls ---------------------------------------------- */ 1361 /* --- controls ---------------------------------------------- */
1261 case VIDIOC_QUERYCTRL: 1362 case VIDIOC_QUERYCTRL:
1262 { 1363 {
@@ -1277,9 +1378,9 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1277 return 0; 1378 return 0;
1278 } 1379 }
1279 case VIDIOC_G_CTRL: 1380 case VIDIOC_G_CTRL:
1280 return get_control(dev,arg); 1381 return get_control(core,arg);
1281 case VIDIOC_S_CTRL: 1382 case VIDIOC_S_CTRL:
1282 return set_control(dev,arg); 1383 return set_control(core,arg);
1283 1384
1284 /* --- tuner ioctls ------------------------------------------ */ 1385 /* --- tuner ioctls ------------------------------------------ */
1285 case VIDIOC_G_TUNER: 1386 case VIDIOC_G_TUNER:
@@ -1323,10 +1424,11 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1323 if (UNSET == core->tuner_type) 1424 if (UNSET == core->tuner_type)
1324 return -EINVAL; 1425 return -EINVAL;
1325 1426
1326 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 1427 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
1327 f->frequency = dev->freq; 1428 f->type = radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1429 f->frequency = core->freq;
1328 1430
1329 cx88_call_i2c_clients(dev->core,VIDIOC_G_FREQUENCY,f); 1431 cx88_call_i2c_clients(core,VIDIOC_G_FREQUENCY,f);
1330 1432
1331 return 0; 1433 return 0;
1332 } 1434 }
@@ -1338,83 +1440,26 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1338 return -EINVAL; 1440 return -EINVAL;
1339 if (f->tuner != 0) 1441 if (f->tuner != 0)
1340 return -EINVAL; 1442 return -EINVAL;
1341 if (0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV) 1443 if (0 == radio && f->type != V4L2_TUNER_ANALOG_TV)
1342 return -EINVAL; 1444 return -EINVAL;
1343 if (1 == fh->radio && f->type != V4L2_TUNER_RADIO) 1445 if (1 == radio && f->type != V4L2_TUNER_RADIO)
1344 return -EINVAL; 1446 return -EINVAL;
1345 down(&dev->lock); 1447 down(&core->lock);
1346 dev->freq = f->frequency; 1448 core->freq = f->frequency;
1347 cx88_newstation(core); 1449 cx88_newstation(core);
1348 cx88_call_i2c_clients(dev->core,VIDIOC_S_FREQUENCY,f); 1450 cx88_call_i2c_clients(core,VIDIOC_S_FREQUENCY,f);
1349 1451
1350 /* When changing channels it is required to reset TVAUDIO */ 1452 /* When changing channels it is required to reset TVAUDIO */
1351 msleep (10); 1453 msleep (10);
1352 cx88_set_tvaudio(core); 1454 cx88_set_tvaudio(core);
1353 1455
1354 up(&dev->lock); 1456 up(&core->lock);
1355 return 0;
1356 }
1357
1358 /* --- streaming capture ------------------------------------- */
1359 case VIDIOCGMBUF:
1360 {
1361 struct video_mbuf *mbuf = arg;
1362 struct videobuf_queue *q;
1363 struct v4l2_requestbuffers req;
1364 unsigned int i;
1365
1366 q = get_queue(fh);
1367 memset(&req,0,sizeof(req));
1368 req.type = q->type;
1369 req.count = 8;
1370 req.memory = V4L2_MEMORY_MMAP;
1371 err = videobuf_reqbufs(q,&req);
1372 if (err < 0)
1373 return err;
1374 memset(mbuf,0,sizeof(*mbuf));
1375 mbuf->frames = req.count;
1376 mbuf->size = 0;
1377 for (i = 0; i < mbuf->frames; i++) {
1378 mbuf->offsets[i] = q->bufs[i]->boff;
1379 mbuf->size += q->bufs[i]->bsize;
1380 }
1381 return 0;
1382 }
1383 case VIDIOC_REQBUFS:
1384 return videobuf_reqbufs(get_queue(fh), arg);
1385
1386 case VIDIOC_QUERYBUF:
1387 return videobuf_querybuf(get_queue(fh), arg);
1388
1389 case VIDIOC_QBUF:
1390 return videobuf_qbuf(get_queue(fh), arg);
1391
1392 case VIDIOC_DQBUF:
1393 return videobuf_dqbuf(get_queue(fh), arg,
1394 file->f_flags & O_NONBLOCK);
1395
1396 case VIDIOC_STREAMON:
1397 {
1398 int res = get_ressource(fh);
1399
1400 if (!res_get(dev,fh,res))
1401 return -EBUSY;
1402 return videobuf_streamon(get_queue(fh));
1403 }
1404 case VIDIOC_STREAMOFF:
1405 {
1406 int res = get_ressource(fh);
1407
1408 err = videobuf_streamoff(get_queue(fh));
1409 if (err < 0)
1410 return err;
1411 res_free(dev,fh,res);
1412 return 0; 1457 return 0;
1413 } 1458 }
1414 1459
1415 default: 1460 default:
1416 return v4l_compat_translate_ioctl(inode,file,cmd,arg, 1461 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
1417 video_do_ioctl); 1462 driver_ioctl);
1418 } 1463 }
1419 return 0; 1464 return 0;
1420} 1465}
@@ -1461,7 +1506,7 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
1461 memset(t,0,sizeof(*t)); 1506 memset(t,0,sizeof(*t));
1462 strcpy(t->name, "Radio"); 1507 strcpy(t->name, "Radio");
1463 1508
1464 cx88_call_i2c_clients(dev->core,VIDIOC_G_TUNER,t); 1509 cx88_call_i2c_clients(core,VIDIOC_G_TUNER,t);
1465 return 0; 1510 return 0;
1466 } 1511 }
1467 case VIDIOC_ENUMINPUT: 1512 case VIDIOC_ENUMINPUT:
@@ -1501,8 +1546,8 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
1501 if (v->tuner) /* Only tuner 0 */ 1546 if (v->tuner) /* Only tuner 0 */
1502 return -EINVAL; 1547 return -EINVAL;
1503 1548
1504 cx88_call_i2c_clients(dev->core,VIDIOCSTUNER,v); 1549 cx88_call_i2c_clients(core,VIDIOCSTUNER,v);
1505 return 0; 1550 return 0;
1506 } 1551 }
1507 case VIDIOC_S_TUNER: 1552 case VIDIOC_S_TUNER:
1508 { 1553 {
@@ -1511,7 +1556,7 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
1511 if (0 != t->index) 1556 if (0 != t->index)
1512 return -EINVAL; 1557 return -EINVAL;
1513 1558
1514 cx88_call_i2c_clients(dev->core,VIDIOC_S_TUNER,t); 1559 cx88_call_i2c_clients(core,VIDIOC_S_TUNER,t);
1515 1560
1516 return 0; 1561 return 0;
1517 } 1562 }
@@ -1569,7 +1614,7 @@ static void cx8800_vid_timeout(unsigned long data)
1569 struct cx88_buffer *buf; 1614 struct cx88_buffer *buf;
1570 unsigned long flags; 1615 unsigned long flags;
1571 1616
1572 cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH21]); 1617 cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH21]);
1573 1618
1574 cx_clear(MO_VID_DMACNTRL, 0x11); 1619 cx_clear(MO_VID_DMACNTRL, 0x11);
1575 cx_clear(VID_CAPTURE_CONTROL, 0x06); 1620 cx_clear(VID_CAPTURE_CONTROL, 0x06);
@@ -1614,14 +1659,14 @@ static void cx8800_vid_irq(struct cx8800_dev *dev)
1614 printk(KERN_WARNING "%s/0: video risc op code error\n",core->name); 1659 printk(KERN_WARNING "%s/0: video risc op code error\n",core->name);
1615 cx_clear(MO_VID_DMACNTRL, 0x11); 1660 cx_clear(MO_VID_DMACNTRL, 0x11);
1616 cx_clear(VID_CAPTURE_CONTROL, 0x06); 1661 cx_clear(VID_CAPTURE_CONTROL, 0x06);
1617 cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH21]); 1662 cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH21]);
1618 } 1663 }
1619 1664
1620 /* risc1 y */ 1665 /* risc1 y */
1621 if (status & 0x01) { 1666 if (status & 0x01) {
1622 spin_lock(&dev->slock); 1667 spin_lock(&dev->slock);
1623 count = cx_read(MO_VIDY_GPCNT); 1668 count = cx_read(MO_VIDY_GPCNT);
1624 cx88_wakeup(dev->core, &dev->vidq, count); 1669 cx88_wakeup(core, &dev->vidq, count);
1625 spin_unlock(&dev->slock); 1670 spin_unlock(&dev->slock);
1626 } 1671 }
1627 1672
@@ -1629,7 +1674,7 @@ static void cx8800_vid_irq(struct cx8800_dev *dev)
1629 if (status & 0x08) { 1674 if (status & 0x08) {
1630 spin_lock(&dev->slock); 1675 spin_lock(&dev->slock);
1631 count = cx_read(MO_VBI_GPCNT); 1676 count = cx_read(MO_VBI_GPCNT);
1632 cx88_wakeup(dev->core, &dev->vbiq, count); 1677 cx88_wakeup(core, &dev->vbiq, count);
1633 spin_unlock(&dev->slock); 1678 spin_unlock(&dev->slock);
1634 } 1679 }
1635 1680
@@ -1798,7 +1843,6 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1798 } 1843 }
1799 1844
1800 /* initialize driver struct */ 1845 /* initialize driver struct */
1801 init_MUTEX(&dev->lock);
1802 spin_lock_init(&dev->slock); 1846 spin_lock_init(&dev->slock);
1803 core->tvnorm = tvnorms; 1847 core->tvnorm = tvnorms;
1804 1848
@@ -1835,6 +1879,7 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1835 request_module("tuner"); 1879 request_module("tuner");
1836 if (core->tda9887_conf) 1880 if (core->tda9887_conf)
1837 request_module("tda9887"); 1881 request_module("tda9887");
1882
1838 /* register v4l devices */ 1883 /* register v4l devices */
1839 dev->video_dev = cx88_vdev_init(core,dev->pci, 1884 dev->video_dev = cx88_vdev_init(core,dev->pci,
1840 &cx8800_video_template,"video"); 1885 &cx8800_video_template,"video");
@@ -1878,11 +1923,11 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1878 pci_set_drvdata(pci_dev,dev); 1923 pci_set_drvdata(pci_dev,dev);
1879 1924
1880 /* initial device configuration */ 1925 /* initial device configuration */
1881 down(&dev->lock); 1926 down(&core->lock);
1882 init_controls(dev); 1927 init_controls(core);
1883 cx88_set_tvnorm(dev->core,tvnorms); 1928 cx88_set_tvnorm(core,tvnorms);
1884 video_mux(dev,0); 1929 video_mux(core,0);
1885 up(&dev->lock); 1930 up(&core->lock);
1886 1931
1887 /* start tvaudio thread */ 1932 /* start tvaudio thread */
1888 if (core->tuner_type != TUNER_ABSENT) 1933 if (core->tuner_type != TUNER_ABSENT)
@@ -1902,14 +1947,15 @@ fail_free:
1902static void __devexit cx8800_finidev(struct pci_dev *pci_dev) 1947static void __devexit cx8800_finidev(struct pci_dev *pci_dev)
1903{ 1948{
1904 struct cx8800_dev *dev = pci_get_drvdata(pci_dev); 1949 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
1950 struct cx88_core *core = dev->core;
1905 1951
1906 /* stop thread */ 1952 /* stop thread */
1907 if (dev->core->kthread) { 1953 if (core->kthread) {
1908 kthread_stop(dev->core->kthread); 1954 kthread_stop(core->kthread);
1909 dev->core->kthread = NULL; 1955 core->kthread = NULL;
1910 } 1956 }
1911 1957
1912 cx88_shutdown(dev->core); /* FIXME */ 1958 cx88_shutdown(core); /* FIXME */
1913 pci_disable_device(pci_dev); 1959 pci_disable_device(pci_dev);
1914 1960
1915 /* unregister stuff */ 1961 /* unregister stuff */
@@ -1921,7 +1967,7 @@ static void __devexit cx8800_finidev(struct pci_dev *pci_dev)
1921 /* free memory */ 1967 /* free memory */
1922 btcx_riscmem_free(dev->pci,&dev->vidq.stopper); 1968 btcx_riscmem_free(dev->pci,&dev->vidq.stopper);
1923 list_del(&dev->devlist); 1969 list_del(&dev->devlist);
1924 cx88_core_put(dev->core,dev->pci); 1970 cx88_core_put(core,dev->pci);
1925 kfree(dev); 1971 kfree(dev);
1926} 1972}
1927 1973
@@ -1945,7 +1991,7 @@ static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
1945 spin_unlock(&dev->slock); 1991 spin_unlock(&dev->slock);
1946 1992
1947 /* FIXME -- shutdown device */ 1993 /* FIXME -- shutdown device */
1948 cx88_shutdown(dev->core); 1994 cx88_shutdown(core);
1949 1995
1950 pci_save_state(pci_dev); 1996 pci_save_state(pci_dev);
1951 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) { 1997 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) {
@@ -1959,16 +2005,32 @@ static int cx8800_resume(struct pci_dev *pci_dev)
1959{ 2005{
1960 struct cx8800_dev *dev = pci_get_drvdata(pci_dev); 2006 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
1961 struct cx88_core *core = dev->core; 2007 struct cx88_core *core = dev->core;
2008 int err;
1962 2009
1963 if (dev->state.disabled) { 2010 if (dev->state.disabled) {
1964 pci_enable_device(pci_dev); 2011 err=pci_enable_device(pci_dev);
2012 if (err) {
2013 printk(KERN_ERR "%s: can't enable device\n",
2014 core->name);
2015 return err;
2016 }
2017
1965 dev->state.disabled = 0; 2018 dev->state.disabled = 0;
1966 } 2019 }
1967 pci_set_power_state(pci_dev, PCI_D0); 2020 err= pci_set_power_state(pci_dev, PCI_D0);
2021 if (err) {
2022 printk(KERN_ERR "%s: can't enable device\n",
2023 core->name);
2024
2025 pci_disable_device(pci_dev);
2026 dev->state.disabled = 1;
2027
2028 return err;
2029 }
1968 pci_restore_state(pci_dev); 2030 pci_restore_state(pci_dev);
1969 2031
1970 /* FIXME: re-initialize hardware */ 2032 /* FIXME: re-initialize hardware */
1971 cx88_reset(dev->core); 2033 cx88_reset(core);
1972 2034
1973 /* restart video+vbi capture */ 2035 /* restart video+vbi capture */
1974 spin_lock(&dev->slock); 2036 spin_lock(&dev->slock);
@@ -2030,6 +2092,8 @@ static void cx8800_fini(void)
2030module_init(cx8800_init); 2092module_init(cx8800_init);
2031module_exit(cx8800_fini); 2093module_exit(cx8800_fini);
2032 2094
2095EXPORT_SYMBOL(cx88_do_ioctl);
2096
2033/* ----------------------------------------------------------- */ 2097/* ----------------------------------------------------------- */
2034/* 2098/*
2035 * Local variables: 2099 * Local variables:
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index da65dc9278..f48dd43535 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: cx88.h,v 1.70 2005/07/24 17:44:09 mkrufky Exp $
3 * 2 *
4 * v4l2 device driver for cx2388x based TV cards 3 * v4l2 device driver for cx2388x based TV cards
5 * 4 *
@@ -35,7 +34,7 @@
35#include "btcx-risc.h" 34#include "btcx-risc.h"
36#include "cx88-reg.h" 35#include "cx88-reg.h"
37 36
38#include <linux/utsname.h> 37#include <linux/version.h>
39#define CX88_VERSION_CODE KERNEL_VERSION(0,0,5) 38#define CX88_VERSION_CODE KERNEL_VERSION(0,0,5)
40 39
41#ifndef TRUE 40#ifndef TRUE
@@ -48,6 +47,9 @@
48 47
49#define CX88_MAXBOARDS 8 48#define CX88_MAXBOARDS 8
50 49
50/* Max number of inputs by card */
51#define MAX_CX88_INPUT 8
52
51/* ----------------------------------------------------------- */ 53/* ----------------------------------------------------------- */
52/* defines and enums */ 54/* defines and enums */
53 55
@@ -199,7 +201,7 @@ struct cx88_board {
199 unsigned char tuner_addr; 201 unsigned char tuner_addr;
200 unsigned char radio_addr; 202 unsigned char radio_addr;
201 int tda9887_conf; 203 int tda9887_conf;
202 struct cx88_input input[8]; 204 struct cx88_input input[MAX_CX88_INPUT];
203 struct cx88_input radio; 205 struct cx88_input radio;
204 int blackbird:1; 206 int blackbird:1;
205 int dvb:1; 207 int dvb:1;
@@ -288,6 +290,11 @@ struct cx88_core {
288 290
289 /* IR remote control state */ 291 /* IR remote control state */
290 struct cx88_IR *ir; 292 struct cx88_IR *ir;
293
294 struct semaphore lock;
295
296 /* various v4l controls */
297 u32 freq;
291}; 298};
292 299
293struct cx8800_dev; 300struct cx8800_dev;
@@ -323,8 +330,7 @@ struct cx8800_suspend_state {
323struct cx8800_dev { 330struct cx8800_dev {
324 struct cx88_core *core; 331 struct cx88_core *core;
325 struct list_head devlist; 332 struct list_head devlist;
326 struct semaphore lock; 333 spinlock_t slock;
327 spinlock_t slock;
328 334
329 /* various device info */ 335 /* various device info */
330 unsigned int resources; 336 unsigned int resources;
@@ -342,7 +348,6 @@ struct cx8800_dev {
342 struct cx88_dmaqueue vbiq; 348 struct cx88_dmaqueue vbiq;
343 349
344 /* various v4l controls */ 350 /* various v4l controls */
345 u32 freq;
346 351
347 /* other global state info */ 352 /* other global state info */
348 struct cx8800_suspend_state state; 353 struct cx8800_suspend_state state;
@@ -350,14 +355,8 @@ struct cx8800_dev {
350 355
351/* ----------------------------------------------------------- */ 356/* ----------------------------------------------------------- */
352/* function 1: audio/alsa stuff */ 357/* function 1: audio/alsa stuff */
358/* =============> moved to cx88-alsa.c <====================== */
353 359
354struct cx8801_dev {
355 struct cx88_core *core;
356
357 /* pci i/o */
358 struct pci_dev *pci;
359 unsigned char pci_rev,pci_lat;
360};
361 360
362/* ----------------------------------------------------------- */ 361/* ----------------------------------------------------------- */
363/* function 2: mpeg stuff */ 362/* function 2: mpeg stuff */
@@ -373,8 +372,7 @@ struct cx8802_suspend_state {
373 372
374struct cx8802_dev { 373struct cx8802_dev {
375 struct cx88_core *core; 374 struct cx88_core *core;
376 struct semaphore lock; 375 spinlock_t slock;
377 spinlock_t slock;
378 376
379 /* pci i/o */ 377 /* pci i/o */
380 struct pci_dev *pci; 378 struct pci_dev *pci;
@@ -553,8 +551,21 @@ void cx8802_fini_common(struct cx8802_dev *dev);
553int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state); 551int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state);
554int cx8802_resume_common(struct pci_dev *pci_dev); 552int cx8802_resume_common(struct pci_dev *pci_dev);
555 553
554/* ----------------------------------------------------------- */
555/* cx88-video.c */
556extern int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
557 struct cx88_core *core, unsigned int cmd,
558 void *arg, v4l2_kioctl driver_ioctl);
559
560/* ----------------------------------------------------------- */
561/* cx88-blackbird.c */
562extern int (*cx88_ioctl_hook)(struct inode *inode, struct file *file,
563 unsigned int cmd, void *arg);
564extern unsigned int (*cx88_ioctl_translator)(unsigned int cmd);
565
556/* 566/*
557 * Local variables: 567 * Local variables:
558 * c-basic-offset: 8 568 * c-basic-offset: 8
559 * End: 569 * End:
570 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
560 */ 571 */
diff --git a/drivers/media/video/ir-kbd-gpio.c b/drivers/media/video/ir-kbd-gpio.c
index a565823330..cf292da8fd 100644
--- a/drivers/media/video/ir-kbd-gpio.c
+++ b/drivers/media/video/ir-kbd-gpio.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: ir-kbd-gpio.c,v 1.13 2005/05/15 19:01:26 mchehab Exp $
3 * 2 *
4 * Copyright (c) 2003 Gerd Knorr 3 * Copyright (c) 2003 Gerd Knorr
5 * Copyright (c) 2003 Pavel Machek 4 * Copyright (c) 2003 Pavel Machek
@@ -354,6 +353,7 @@ static int ir_probe(struct device *dev)
354 ir->input.id.vendor = sub->core->pci->vendor; 353 ir->input.id.vendor = sub->core->pci->vendor;
355 ir->input.id.product = sub->core->pci->device; 354 ir->input.id.product = sub->core->pci->device;
356 } 355 }
356 ir->input.dev = &sub->core->pci->dev;
357 357
358 if (ir->polling) { 358 if (ir->polling) {
359 INIT_WORK(&ir->work, ir_work, ir); 359 INIT_WORK(&ir->work, ir_work, ir);
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index 1e273ff3f9..67105b9804 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: ir-kbd-i2c.c,v 1.11 2005/07/07 16:42:11 mchehab Exp $
3 * 2 *
4 * keyboard input driver for i2c IR remote controls 3 * keyboard input driver for i2c IR remote controls
5 * 4 *
diff --git a/drivers/media/video/msp3400.c b/drivers/media/video/msp3400.c
index ca02f6f14b..f0d43fc263 100644
--- a/drivers/media/video/msp3400.c
+++ b/drivers/media/video/msp3400.c
@@ -124,10 +124,14 @@ module_param(standard, int, 0644);
124module_param(amsound, int, 0644); 124module_param(amsound, int, 0644);
125module_param(dolby, int, 0644); 125module_param(dolby, int, 0644);
126 126
127MODULE_PARM_DESC(opmode, "Forces a MSP3400 opmode. 0=Manual, 1=Simple, 2=Simpler");
127MODULE_PARM_DESC(once, "No continuous stereo monitoring"); 128MODULE_PARM_DESC(once, "No continuous stereo monitoring");
128MODULE_PARM_DESC(debug, "Enable debug messages"); 129MODULE_PARM_DESC(debug, "Enable debug messages");
130MODULE_PARM_DESC(stereo_threshold, "Sets signal threshold to activate stereo");
129MODULE_PARM_DESC(standard, "Specify audio standard: 32 = NTSC, 64 = radio, Default: Autodetect"); 131MODULE_PARM_DESC(standard, "Specify audio standard: 32 = NTSC, 64 = radio, Default: Autodetect");
130MODULE_PARM_DESC(amsound, "Hardwire AM sound at 6.5Hz (France), FM can autoscan"); 132MODULE_PARM_DESC(amsound, "Hardwire AM sound at 6.5Hz (France), FM can autoscan");
133MODULE_PARM_DESC(dolby, "Activates Dolby processsing");
134
131 135
132MODULE_DESCRIPTION("device driver for msp34xx TV sound processor"); 136MODULE_DESCRIPTION("device driver for msp34xx TV sound processor");
133MODULE_AUTHOR("Gerd Knorr"); 137MODULE_AUTHOR("Gerd Knorr");
@@ -1452,7 +1456,7 @@ static int msp_attach(struct i2c_adapter *adap, int addr, int kind)
1452 client_template.addr = addr; 1456 client_template.addr = addr;
1453 1457
1454 if (-1 == msp3400c_reset(&client_template)) { 1458 if (-1 == msp3400c_reset(&client_template)) {
1455 dprintk("msp3400: no chip found\n"); 1459 dprintk("msp34xx: no chip found\n");
1456 return -1; 1460 return -1;
1457 } 1461 }
1458 1462
@@ -1478,7 +1482,7 @@ static int msp_attach(struct i2c_adapter *adap, int addr, int kind)
1478 if (-1 == msp3400c_reset(c)) { 1482 if (-1 == msp3400c_reset(c)) {
1479 kfree(msp); 1483 kfree(msp);
1480 kfree(c); 1484 kfree(c);
1481 dprintk("msp3400: no chip found\n"); 1485 dprintk("msp34xx: no chip found\n");
1482 return -1; 1486 return -1;
1483 } 1487 }
1484 1488
@@ -1488,7 +1492,7 @@ static int msp_attach(struct i2c_adapter *adap, int addr, int kind)
1488 if ((-1 == msp->rev1) || (0 == msp->rev1 && 0 == msp->rev2)) { 1492 if ((-1 == msp->rev1) || (0 == msp->rev1 && 0 == msp->rev2)) {
1489 kfree(msp); 1493 kfree(msp);
1490 kfree(c); 1494 kfree(c);
1491 printk("msp3400: error while reading chip version\n"); 1495 dprintk("msp34xx: error while reading chip version\n");
1492 return -1; 1496 return -1;
1493 } 1497 }
1494 1498
diff --git a/drivers/media/video/msp3400.h b/drivers/media/video/msp3400.h
index 023f33056a..2d9ff40f0b 100644
--- a/drivers/media/video/msp3400.h
+++ b/drivers/media/video/msp3400.h
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: msp3400.h,v 1.3 2005/06/12 04:19:19 mchehab Exp $
3 */ 2 */
4 3
5#ifndef MSP3400_H 4#ifndef MSP3400_H
diff --git a/drivers/media/video/mt20xx.c b/drivers/media/video/mt20xx.c
index 2fb7c2d178..972aa5e0ae 100644
--- a/drivers/media/video/mt20xx.c
+++ b/drivers/media/video/mt20xx.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: mt20xx.c,v 1.5 2005/06/16 08:29:49 nsh Exp $
3 * 2 *
4 * i2c tv tuner chip device driver 3 * i2c tv tuner chip device driver
5 * controls microtune tuners, mt2032 + mt2050 at the moment. 4 * controls microtune tuners, mt2032 + mt2050 at the moment.
@@ -494,6 +493,7 @@ int microtune_init(struct i2c_client *c)
494 memset(buf,0,sizeof(buf)); 493 memset(buf,0,sizeof(buf));
495 t->tv_freq = NULL; 494 t->tv_freq = NULL;
496 t->radio_freq = NULL; 495 t->radio_freq = NULL;
496 t->standby = NULL;
497 name = "unknown"; 497 name = "unknown";
498 498
499 i2c_master_send(c,buf,1); 499 i2c_master_send(c,buf,1);
diff --git a/drivers/media/video/rds.h b/drivers/media/video/rds.h
new file mode 100644
index 0000000000..30337d0f1a
--- /dev/null
+++ b/drivers/media/video/rds.h
@@ -0,0 +1,48 @@
1/*
2
3 Types and defines needed for RDS. This is included by
4 saa6588.c and every driver (e.g. bttv-driver.c) that wants
5 to use the saa6588 module.
6
7 Instead of having a seperate rds.h, I'd prefer to include
8 this stuff in one of the already existing files like tuner.h
9
10 (c) 2005 by Hans J. Koch
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25
26*/
27
28#ifndef _RDS_H
29#define _RDS_H
30
31struct rds_command {
32 unsigned int block_count;
33 int result;
34 unsigned char *buffer;
35 struct file *instance;
36 poll_table *event_list;
37};
38
39#define RDS_CMD_OPEN _IOW('R',1,int)
40#define RDS_CMD_CLOSE _IOW('R',2,int)
41#define RDS_CMD_READ _IOR('R',3,int)
42#define RDS_CMD_POLL _IOR('R',4,int)
43
44#endif
45
46
47
48
diff --git a/drivers/media/video/saa6588.c b/drivers/media/video/saa6588.c
new file mode 100644
index 0000000000..1a657a70ff
--- /dev/null
+++ b/drivers/media/video/saa6588.c
@@ -0,0 +1,534 @@
1/*
2 Driver for SAA6588 RDS decoder
3
4 (c) 2005 Hans J. Koch
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/i2c.h>
25#include <linux/types.h>
26#include <linux/videodev.h>
27#include <linux/init.h>
28#include <linux/errno.h>
29#include <linux/slab.h>
30#include <linux/poll.h>
31#include <linux/wait.h>
32#include <asm/uaccess.h>
33
34#include <media/id.h>
35
36#include "rds.h"
37
38/* Addresses to scan */
39static unsigned short normal_i2c[] = {
40 0x20 >> 1,
41 0x22 >> 1,
42 I2C_CLIENT_END,
43};
44
45I2C_CLIENT_INSMOD;
46
47/* insmod options */
48static unsigned int debug = 0;
49static unsigned int xtal = 0;
50static unsigned int rbds = 0;
51static unsigned int plvl = 0;
52static unsigned int bufblocks = 100;
53
54MODULE_PARM(debug, "i");
55MODULE_PARM_DESC(debug, "enable debug messages");
56MODULE_PARM(xtal, "i");
57MODULE_PARM_DESC(xtal, "select oscillator frequency (0..3), default 0");
58MODULE_PARM(rbds, "i");
59MODULE_PARM_DESC(rbds, "select mode, 0=RDS, 1=RBDS, default 0");
60MODULE_PARM(plvl, "i");
61MODULE_PARM_DESC(plvl, "select pause level (0..3), default 0");
62MODULE_PARM(bufblocks, "i");
63MODULE_PARM_DESC(bufblocks, "number of buffered blocks, default 100");
64
65MODULE_DESCRIPTION("v4l2 driver module for SAA6588 RDS decoder");
66MODULE_AUTHOR("Hans J. Koch <koch@hjk-az.de>");
67
68MODULE_LICENSE("GPL");
69
70/* ---------------------------------------------------------------------- */
71
72#define UNSET (-1U)
73#define PREFIX "saa6588: "
74#define dprintk if (debug) printk
75
76struct saa6588 {
77 struct i2c_client client;
78 struct work_struct work;
79 struct timer_list timer;
80 spinlock_t lock;
81 unsigned char *buffer;
82 unsigned int buf_size;
83 unsigned int rd_index;
84 unsigned int wr_index;
85 unsigned int block_count;
86 unsigned char last_blocknum;
87 wait_queue_head_t read_queue;
88 int data_available_for_read;
89};
90
91static struct i2c_driver driver;
92static struct i2c_client client_template;
93
94/* ---------------------------------------------------------------------- */
95
96/*
97 * SAA6588 defines
98 */
99
100/* Initialization and mode control byte (0w) */
101
102/* bit 0+1 (DAC0/DAC1) */
103#define cModeStandard 0x00
104#define cModeFastPI 0x01
105#define cModeReducedRequest 0x02
106#define cModeInvalid 0x03
107
108/* bit 2 (RBDS) */
109#define cProcessingModeRDS 0x00
110#define cProcessingModeRBDS 0x04
111
112/* bit 3+4 (SYM0/SYM1) */
113#define cErrCorrectionNone 0x00
114#define cErrCorrection2Bits 0x08
115#define cErrCorrection5Bits 0x10
116#define cErrCorrectionNoneRBDS 0x18
117
118/* bit 5 (NWSY) */
119#define cSyncNormal 0x00
120#define cSyncRestart 0x20
121
122/* bit 6 (TSQD) */
123#define cSigQualityDetectOFF 0x00
124#define cSigQualityDetectON 0x40
125
126/* bit 7 (SQCM) */
127#define cSigQualityTriggered 0x00
128#define cSigQualityContinous 0x80
129
130/* Pause level and flywheel control byte (1w) */
131
132/* bits 0..5 (FEB0..FEB5) */
133#define cFlywheelMaxBlocksMask 0x3F
134#define cFlywheelDefault 0x20
135
136/* bits 6+7 (PL0/PL1) */
137#define cPauseLevel_11mV 0x00
138#define cPauseLevel_17mV 0x40
139#define cPauseLevel_27mV 0x80
140#define cPauseLevel_43mV 0xC0
141
142/* Pause time/oscillator frequency/quality detector control byte (1w) */
143
144/* bits 0..4 (SQS0..SQS4) */
145#define cQualityDetectSensMask 0x1F
146#define cQualityDetectDefault 0x0F
147
148/* bit 5 (SOSC) */
149#define cSelectOscFreqOFF 0x00
150#define cSelectOscFreqON 0x20
151
152/* bit 6+7 (PTF0/PTF1) */
153#define cOscFreq_4332kHz 0x00
154#define cOscFreq_8664kHz 0x40
155#define cOscFreq_12996kHz 0x80
156#define cOscFreq_17328kHz 0xC0
157
158/* ---------------------------------------------------------------------- */
159
160static int block_to_user_buf(struct saa6588 *s, unsigned char *user_buf)
161{
162 int i;
163
164 if (s->rd_index == s->wr_index) {
165 if (debug > 2)
166 dprintk(PREFIX "Read: buffer empty.\n");
167 return 0;
168 }
169
170 if (debug > 2) {
171 dprintk(PREFIX "Read: ");
172 for (i = s->rd_index; i < s->rd_index + 3; i++)
173 dprintk("0x%02x ", s->buffer[i]);
174 }
175
176 if (copy_to_user(user_buf, &s->buffer[s->rd_index], 3))
177 return -EFAULT;
178
179 s->rd_index += 3;
180 if (s->rd_index >= s->buf_size)
181 s->rd_index = 0;
182 s->block_count--;
183
184 if (debug > 2)
185 dprintk("%d blocks total.\n", s->block_count);
186
187 return 1;
188}
189
190static void read_from_buf(struct saa6588 *s, struct rds_command *a)
191{
192 unsigned long flags;
193
194 unsigned char *buf_ptr = a->buffer; /* This is a user space buffer! */
195 unsigned int i;
196 unsigned int rd_blocks;
197
198 a->result = 0;
199 if (!a->buffer)
200 return;
201
202 while (!s->data_available_for_read) {
203 int ret = wait_event_interruptible(s->read_queue,
204 s->data_available_for_read);
205 if (ret == -ERESTARTSYS) {
206 a->result = -EINTR;
207 return;
208 }
209 }
210
211 spin_lock_irqsave(&s->lock, flags);
212 rd_blocks = a->block_count;
213 if (rd_blocks > s->block_count)
214 rd_blocks = s->block_count;
215
216 if (!rd_blocks)
217 return;
218
219 for (i = 0; i < rd_blocks; i++) {
220 if (block_to_user_buf(s, buf_ptr)) {
221 buf_ptr += 3;
222 a->result++;
223 } else
224 break;
225 }
226 a->result *= 3;
227 s->data_available_for_read = (s->block_count > 0);
228 spin_unlock_irqrestore(&s->lock, flags);
229}
230
231static void block_to_buf(struct saa6588 *s, unsigned char *blockbuf)
232{
233 unsigned int i;
234
235 if (debug > 3)
236 dprintk(PREFIX "New block: ");
237
238 for (i = 0; i < 3; ++i) {
239 if (debug > 3)
240 dprintk("0x%02x ", blockbuf[i]);
241 s->buffer[s->wr_index] = blockbuf[i];
242 s->wr_index++;
243 }
244
245 if (s->wr_index >= s->buf_size)
246 s->wr_index = 0;
247
248 if (s->wr_index == s->rd_index) {
249 s->rd_index++;
250 if (s->rd_index >= s->buf_size)
251 s->rd_index = 0;
252 } else
253 s->block_count++;
254
255 if (debug > 3)
256 dprintk("%d blocks total.\n", s->block_count);
257}
258
259static void saa6588_i2c_poll(struct saa6588 *s)
260{
261 unsigned long flags;
262 unsigned char tmpbuf[6];
263 unsigned char blocknum;
264 unsigned char tmp;
265
266 /* Although we only need 3 bytes, we have to read at least 6.
267 SAA6588 returns garbage otherwise */
268 if (6 != i2c_master_recv(&s->client, &tmpbuf[0], 6)) {
269 if (debug > 1)
270 dprintk(PREFIX "read error!\n");
271 return;
272 }
273
274 blocknum = tmpbuf[0] >> 5;
275 if (blocknum == s->last_blocknum) {
276 if (debug > 3)
277 dprintk("Saw block %d again.\n", blocknum);
278 return;
279 }
280
281 s->last_blocknum = blocknum;
282
283 /*
284 Byte order according to v4l2 specification:
285
286 Byte 0: Least Significant Byte of RDS Block
287 Byte 1: Most Significant Byte of RDS Block
288 Byte 2 Bit 7: Error bit. Indicates that an uncorrectable error
289 occurred during reception of this block.
290 Bit 6: Corrected bit. Indicates that an error was
291 corrected for this data block.
292 Bits 5-3: Received Offset. Indicates the offset received
293 by the sync system.
294 Bits 2-0: Offset Name. Indicates the offset applied to this data.
295
296 SAA6588 byte order is Status-MSB-LSB, so we have to swap the
297 first and the last of the 3 bytes block.
298 */
299
300 tmp = tmpbuf[2];
301 tmpbuf[2] = tmpbuf[0];
302 tmpbuf[0] = tmp;
303
304 tmp = blocknum;
305 tmp |= blocknum << 3; /* Received offset == Offset Name (OK ?) */
306 if ((tmpbuf[2] & 0x03) == 0x03)
307 tmp |= 0x80; /* uncorrectable error */
308 else if ((tmpbuf[2] & 0x03) != 0x00)
309 tmp |= 0x40; /* corrected error */
310 tmpbuf[2] = tmp; /* Is this enough ? Should we also check other bits ? */
311
312 spin_lock_irqsave(&s->lock, flags);
313 block_to_buf(s, tmpbuf);
314 spin_unlock_irqrestore(&s->lock, flags);
315 s->data_available_for_read = 1;
316 wake_up_interruptible(&s->read_queue);
317}
318
319static void saa6588_timer(unsigned long data)
320{
321 struct saa6588 *s = (struct saa6588 *)data;
322
323 schedule_work(&s->work);
324}
325
326static void saa6588_work(void *data)
327{
328 struct saa6588 *s = (struct saa6588 *)data;
329
330 saa6588_i2c_poll(s);
331 mod_timer(&s->timer, jiffies + HZ / 50); /* 20 msec */
332}
333
334static int saa6588_configure(struct saa6588 *s)
335{
336 unsigned char buf[3];
337 int rc;
338
339 buf[0] = cSyncRestart;
340 if (rbds)
341 buf[0] |= cProcessingModeRBDS;
342
343 buf[1] = cFlywheelDefault;
344 switch (plvl) {
345 case 0:
346 buf[1] |= cPauseLevel_11mV;
347 break;
348 case 1:
349 buf[1] |= cPauseLevel_17mV;
350 break;
351 case 2:
352 buf[1] |= cPauseLevel_27mV;
353 break;
354 case 3:
355 buf[1] |= cPauseLevel_43mV;
356 break;
357 default: /* nothing */
358 break;
359 }
360
361 buf[2] = cQualityDetectDefault | cSelectOscFreqON;
362
363 switch (xtal) {
364 case 0:
365 buf[2] |= cOscFreq_4332kHz;
366 break;
367 case 1:
368 buf[2] |= cOscFreq_8664kHz;
369 break;
370 case 2:
371 buf[2] |= cOscFreq_12996kHz;
372 break;
373 case 3:
374 buf[2] |= cOscFreq_17328kHz;
375 break;
376 default: /* nothing */
377 break;
378 }
379
380 dprintk(PREFIX "writing: 0w=0x%02x 1w=0x%02x 2w=0x%02x\n",
381 buf[0], buf[1], buf[2]);
382
383 if (3 != (rc = i2c_master_send(&s->client, buf, 3)))
384 printk(PREFIX "i2c i/o error: rc == %d (should be 3)\n", rc);
385
386 return 0;
387}
388
389/* ---------------------------------------------------------------------- */
390
391static int saa6588_attach(struct i2c_adapter *adap, int addr, int kind)
392{
393 struct saa6588 *s;
394 client_template.adapter = adap;
395 client_template.addr = addr;
396
397 printk(PREFIX "chip found @ 0x%x\n", addr << 1);
398
399 if (NULL == (s = kmalloc(sizeof(*s), GFP_KERNEL)))
400 return -ENOMEM;
401
402 s->buf_size = bufblocks * 3;
403
404 if (NULL == (s->buffer = kmalloc(s->buf_size, GFP_KERNEL))) {
405 kfree(s);
406 return -ENOMEM;
407 }
408 s->client = client_template;
409 s->block_count = 0;
410 s->wr_index = 0;
411 s->rd_index = 0;
412 s->last_blocknum = 0xff;
413 init_waitqueue_head(&s->read_queue);
414 s->data_available_for_read = 0;
415 i2c_set_clientdata(&s->client, s);
416 i2c_attach_client(&s->client);
417
418 saa6588_configure(s);
419
420 /* start polling via eventd */
421 INIT_WORK(&s->work, saa6588_work, s);
422 init_timer(&s->timer);
423 s->timer.function = saa6588_timer;
424 s->timer.data = (unsigned long)s;
425 schedule_work(&s->work);
426
427 return 0;
428}
429
430static int saa6588_probe(struct i2c_adapter *adap)
431{
432#ifdef I2C_CLASS_TV_ANALOG
433 if (adap->class & I2C_CLASS_TV_ANALOG)
434 return i2c_probe(adap, &addr_data, saa6588_attach);
435#else
436 switch (adap->id) {
437 case I2C_ALGO_BIT | I2C_HW_B_BT848:
438 case I2C_ALGO_BIT | I2C_HW_B_RIVA:
439 case I2C_ALGO_SAA7134:
440 return i2c_probe(adap, &addr_data, saa6588_attach);
441 break;
442 }
443#endif
444 return 0;
445}
446
447static int saa6588_detach(struct i2c_client *client)
448{
449 struct saa6588 *s = i2c_get_clientdata(client);
450
451 del_timer_sync(&s->timer);
452 flush_scheduled_work();
453
454 i2c_detach_client(client);
455 kfree(s->buffer);
456 kfree(s);
457 return 0;
458}
459
460static int saa6588_command(struct i2c_client *client, unsigned int cmd,
461 void *arg)
462{
463 struct saa6588 *s = i2c_get_clientdata(client);
464 struct rds_command *a = (struct rds_command *)arg;
465
466 switch (cmd) {
467 /* --- open() for /dev/radio --- */
468 case RDS_CMD_OPEN:
469 a->result = 0; /* return error if chip doesn't work ??? */
470 break;
471 /* --- close() for /dev/radio --- */
472 case RDS_CMD_CLOSE:
473 s->data_available_for_read = 1;
474 wake_up_interruptible(&s->read_queue);
475 a->result = 0;
476 break;
477 /* --- read() for /dev/radio --- */
478 case RDS_CMD_READ:
479 read_from_buf(s, a);
480 break;
481 /* --- poll() for /dev/radio --- */
482 case RDS_CMD_POLL:
483 a->result = 0;
484 if (s->data_available_for_read) {
485 a->result |= POLLIN | POLLRDNORM;
486 }
487 poll_wait(a->instance, &s->read_queue, a->event_list);
488 break;
489
490 default:
491 /* nothing */
492 break;
493 }
494 return 0;
495}
496
497/* ----------------------------------------------------------------------- */
498
499static struct i2c_driver driver = {
500 .owner = THIS_MODULE,
501 .name = "i2c saa6588 driver",
502 .id = -1, /* FIXME */
503 .flags = I2C_DF_NOTIFY,
504 .attach_adapter = saa6588_probe,
505 .detach_client = saa6588_detach,
506 .command = saa6588_command,
507};
508
509static struct i2c_client client_template = {
510 .name = "saa6588",
511 .flags = I2C_CLIENT_ALLOW_USE,
512 .driver = &driver,
513};
514
515static int __init saa6588_init_module(void)
516{
517 return i2c_add_driver(&driver);
518}
519
520static void __exit saa6588_cleanup_module(void)
521{
522 i2c_del_driver(&driver);
523}
524
525module_init(saa6588_init_module);
526module_exit(saa6588_cleanup_module);
527
528/*
529 * Overrides for Emacs so that we follow Linus's tabbing style.
530 * ---------------------------------------------------------------------------
531 * Local variables:
532 * c-basic-offset: 8
533 * End:
534 */
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 88b71a20b6..acc7a4335e 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: saa7134-cards.c,v 1.80 2005/07/07 01:49:30 mkrufky Exp $
3 * 2 *
4 * device driver for philips saa7134 based TV cards 3 * device driver for philips saa7134 based TV cards
5 * card-specific stuff. 4 * card-specific stuff.
@@ -1373,7 +1372,7 @@ struct saa7134_board saa7134_boards[] = {
1373 .inputs = {{ 1372 .inputs = {{
1374 .name = name_comp1, 1373 .name = name_comp1,
1375 .vmux = 1, 1374 .vmux = 1,
1376 .amux = LINE2, 1375 .amux = LINE1,
1377 },{ 1376 },{
1378 .name = name_tv, 1377 .name = name_tv,
1379 .vmux = 3, 1378 .vmux = 3,
@@ -1382,7 +1381,7 @@ struct saa7134_board saa7134_boards[] = {
1382 },{ 1381 },{
1383 .name = name_svideo, 1382 .name = name_svideo,
1384 .vmux = 8, 1383 .vmux = 8,
1385 .amux = LINE2, 1384 .amux = LINE1,
1386 }}, 1385 }},
1387 .radio = { 1386 .radio = {
1388 .name = name_radio, 1387 .name = name_radio,
@@ -2001,6 +2000,115 @@ struct saa7134_board saa7134_boards[] = {
2001 .gpio = 0x000, 2000 .gpio = 0x000,
2002 }, 2001 },
2003 }, 2002 },
2003 [SAA7134_BOARD_FLYTV_DIGIMATRIX] = {
2004 .name = "FlyTV mini Asus Digimatrix",
2005 .audio_clock = 0x00200000,
2006 .tuner_type = TUNER_LG_NTSC_TALN_MINI,
2007 .radio_type = UNSET,
2008 .tuner_addr = ADDR_UNSET,
2009 .radio_addr = ADDR_UNSET,
2010 .inputs = {{
2011 .name = name_tv,
2012 .vmux = 1,
2013 .amux = TV,
2014 .tv = 1,
2015 },{
2016 .name = name_tv_mono,
2017 .vmux = 1,
2018 .amux = LINE2,
2019 .tv = 1,
2020 },{
2021 .name = name_comp1,
2022 .vmux = 0,
2023 .amux = LINE2,
2024 },{
2025 .name = name_comp2,
2026 .vmux = 3,
2027 .amux = LINE2,
2028 },{
2029 .name = name_svideo,
2030 .vmux = 8,
2031 .amux = LINE2,
2032 }},
2033 .radio = {
2034 .name = name_radio, /* radio unconfirmed */
2035 .amux = LINE2,
2036 },
2037 },
2038 [SAA7134_BOARD_KWORLD_TERMINATOR] = {
2039 /* Kworld V-Stream Studio TV Terminator */
2040 /* "James Webb <jrwebb@qwest.net> */
2041 .name = "V-Stream Studio TV Terminator",
2042 .audio_clock = 0x00187de7,
2043 .tuner_type = TUNER_PHILIPS_TDA8290,
2044 .radio_type = UNSET,
2045 .tuner_addr = ADDR_UNSET,
2046 .radio_addr = ADDR_UNSET,
2047 .gpiomask = 1 << 21,
2048 .inputs = {{
2049 .name = name_tv,
2050 .vmux = 1,
2051 .amux = TV,
2052 .gpio = 0x0000000,
2053 .tv = 1,
2054 },{
2055 .name = name_comp1, /* Composite input */
2056 .vmux = 3,
2057 .amux = LINE2,
2058 .gpio = 0x0000000,
2059 },{
2060 .name = name_svideo, /* S-Video input */
2061 .vmux = 8,
2062 .amux = LINE2,
2063 .gpio = 0x0000000,
2064 }},
2065 .radio = {
2066 .name = name_radio,
2067 .amux = TV,
2068 .gpio = 0x0200000,
2069 },
2070 },
2071 [SAA7134_BOARD_YUAN_TUN900] = {
2072 /* FIXME:
2073 * S-Video and composite sources untested.
2074 * Radio not working.
2075 * Remote control not yet implemented.
2076 * From : codemaster@webgeeks.be */
2077 .name = "Yuan TUN-900 (saa7135)",
2078 .audio_clock = 0x00187de7,
2079 .tuner_type = TUNER_PHILIPS_TDA8290,
2080 .radio_type = UNSET,
2081 .tuner_addr= ADDR_UNSET,
2082 .radio_addr= ADDR_UNSET,
2083 .gpiomask = 0x00010003,
2084 .inputs = {{
2085 .name = name_tv,
2086 .vmux = 1,
2087 .amux = TV,
2088 .tv = 1,
2089 .gpio = 0x01,
2090 },{
2091 .name = name_comp1,
2092 .vmux = 0,
2093 .amux = LINE2,
2094 .gpio = 0x02,
2095 },{
2096 .name = name_svideo,
2097 .vmux = 6,
2098 .amux = LINE2,
2099 .gpio = 0x02,
2100 }},
2101 .radio = {
2102 .name = name_radio,
2103 .amux = LINE1,
2104 .gpio = 0x00010003,
2105 },
2106 .mute = {
2107 .name = name_mute,
2108 .amux = TV,
2109 .gpio = 0x01,
2110 },
2111 },
2004}; 2112};
2005 2113
2006 2114
@@ -2272,12 +2380,6 @@ struct pci_device_id saa7134_pci_tbl[] = {
2272 .driver_data = SAA7134_BOARD_VIDEOMATE_TV_PVR, 2380 .driver_data = SAA7134_BOARD_VIDEOMATE_TV_PVR,
2273 },{ 2381 },{
2274 .vendor = PCI_VENDOR_ID_PHILIPS, 2382 .vendor = PCI_VENDOR_ID_PHILIPS,
2275 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
2276 .subvendor = 0x1131,
2277 .subdevice = 0,
2278 .driver_data = SAA7134_BOARD_SABRENT_SBTTVFM,
2279 },{
2280 .vendor = PCI_VENDOR_ID_PHILIPS,
2281 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2383 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
2282 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 2384 .subvendor = 0x1461, /* Avermedia Technologies Inc */
2283 .subdevice = 0x9715, 2385 .subdevice = 0x9715,
@@ -2346,6 +2448,18 @@ struct pci_device_id saa7134_pci_tbl[] = {
2346 .subvendor = 0x4e42, 2448 .subvendor = 0x4e42,
2347 .subdevice = 0x0502, 2449 .subdevice = 0x0502,
2348 .driver_data = SAA7134_BOARD_THYPHOON_DVBT_DUO_CARDBUS, 2450 .driver_data = SAA7134_BOARD_THYPHOON_DVBT_DUO_CARDBUS,
2451 },{
2452 .vendor = PCI_VENDOR_ID_PHILIPS,
2453 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
2454 .subvendor = 0x1043,
2455 .subdevice = 0x0210, /* mini pci NTSC version */
2456 .driver_data = SAA7134_BOARD_FLYTV_DIGIMATRIX,
2457 },{
2458 .vendor = PCI_VENDOR_ID_PHILIPS,
2459 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
2460 .subvendor = 0x1043,
2461 .subdevice = 0x0210, /* mini pci PAL/SECAM version */
2462 .driver_data = SAA7134_BOARD_FLYTV_DIGIMATRIX,
2349 2463
2350 },{ 2464 },{
2351 /* --- boards without eeprom + subsystem ID --- */ 2465 /* --- boards without eeprom + subsystem ID --- */
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index 1dbe61755e..e5e36f3c62 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: saa7134-core.c,v 1.39 2005/07/05 17:37:35 nsh Exp $
3 * 2 *
4 * device driver for philips saa7134 based TV cards 3 * device driver for philips saa7134 based TV cards
5 * driver core 4 * driver core
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index 8be6a90358..639ae51a05 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: saa7134-dvb.c,v 1.23 2005/07/24 22:12:47 mkrufky Exp $
3 * 2 *
4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] 3 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
5 * 4 *
@@ -29,7 +28,6 @@
29#include <linux/delay.h> 28#include <linux/delay.h>
30#include <linux/kthread.h> 29#include <linux/kthread.h>
31#include <linux/suspend.h> 30#include <linux/suspend.h>
32#include <linux/config.h>
33 31
34 32
35#include "saa7134-reg.h" 33#include "saa7134-reg.h"
diff --git a/drivers/media/video/saa7134/saa7134-empress.c b/drivers/media/video/saa7134/saa7134-empress.c
index c85348d023..77b627eb64 100644
--- a/drivers/media/video/saa7134/saa7134-empress.c
+++ b/drivers/media/video/saa7134/saa7134-empress.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: saa7134-empress.c,v 1.11 2005/05/22 19:23:39 nsh Exp $
3 * 2 *
4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] 3 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
5 * 4 *
diff --git a/drivers/media/video/saa7134/saa7134-i2c.c b/drivers/media/video/saa7134/saa7134-i2c.c
index eae6b52971..711aa8e85f 100644
--- a/drivers/media/video/saa7134/saa7134-i2c.c
+++ b/drivers/media/video/saa7134/saa7134-i2c.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: saa7134-i2c.c,v 1.22 2005/07/22 04:09:41 mkrufky Exp $
3 * 2 *
4 * device driver for philips saa7134 based TV cards 3 * device driver for philips saa7134 based TV cards
5 * i2c interface support 4 * i2c interface support
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index 213740122f..1f456c4d76 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: saa7134-input.c,v 1.21 2005/06/22 23:37:34 nsh Exp $
3 * 2 *
4 * handle saa7134 IR remotes via linux kernel input layer. 3 * handle saa7134 IR remotes via linux kernel input layer.
5 * 4 *
@@ -565,6 +564,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
565 ir->dev.id.vendor = dev->pci->vendor; 564 ir->dev.id.vendor = dev->pci->vendor;
566 ir->dev.id.product = dev->pci->device; 565 ir->dev.id.product = dev->pci->device;
567 } 566 }
567 ir->dev.dev = &dev->pci->dev;
568 568
569 /* all done */ 569 /* all done */
570 dev->remote = ir; 570 dev->remote = ir;
diff --git a/drivers/media/video/saa7134/saa7134-oss.c b/drivers/media/video/saa7134/saa7134-oss.c
index b5bede95db..c20630c82f 100644
--- a/drivers/media/video/saa7134/saa7134-oss.c
+++ b/drivers/media/video/saa7134/saa7134-oss.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: saa7134-oss.c,v 1.17 2005/06/28 23:41:47 mkrufky Exp $
3 * 2 *
4 * device driver for philips saa7134 based TV cards 3 * device driver for philips saa7134 based TV cards
5 * oss dsp interface 4 * oss dsp interface
diff --git a/drivers/media/video/saa7134/saa7134-reg.h b/drivers/media/video/saa7134/saa7134-reg.h
index 87734f22af..ae0c7a1653 100644
--- a/drivers/media/video/saa7134/saa7134-reg.h
+++ b/drivers/media/video/saa7134/saa7134-reg.h
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: saa7134-reg.h,v 1.2 2004/09/15 16:15:24 kraxel Exp $
3 * 2 *
4 * philips saa7134 registers 3 * philips saa7134 registers
5 */ 4 */
diff --git a/drivers/media/video/saa7134/saa7134-ts.c b/drivers/media/video/saa7134/saa7134-ts.c
index 4dd9f1b239..463885601a 100644
--- a/drivers/media/video/saa7134/saa7134-ts.c
+++ b/drivers/media/video/saa7134/saa7134-ts.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: saa7134-ts.c,v 1.15 2005/06/14 22:48:18 hhackmann Exp $
3 * 2 *
4 * device driver for philips saa7134 based TV cards 3 * device driver for philips saa7134 based TV cards
5 * video4linux video interface 4 * video4linux video interface
diff --git a/drivers/media/video/saa7134/saa7134-tvaudio.c b/drivers/media/video/saa7134/saa7134-tvaudio.c
index eeafa5a71d..badf2f9e30 100644
--- a/drivers/media/video/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/video/saa7134/saa7134-tvaudio.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: saa7134-tvaudio.c,v 1.30 2005/06/28 23:41:47 mkrufky Exp $
3 * 2 *
4 * device driver for philips saa7134 based TV cards 3 * device driver for philips saa7134 based TV cards
5 * tv audio decoder (fm stereo, nicam, ...) 4 * tv audio decoder (fm stereo, nicam, ...)
diff --git a/drivers/media/video/saa7134/saa7134-vbi.c b/drivers/media/video/saa7134/saa7134-vbi.c
index 29e51cad2a..f4aee0af80 100644
--- a/drivers/media/video/saa7134/saa7134-vbi.c
+++ b/drivers/media/video/saa7134/saa7134-vbi.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: saa7134-vbi.c,v 1.7 2005/05/24 23:13:06 nsh Exp $
3 * 2 *
4 * device driver for philips saa7134 based TV cards 3 * device driver for philips saa7134 based TV cards
5 * video4linux video interface 4 * video4linux video interface
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index a4c2f751d0..35e5e85f66 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: saa7134-video.c,v 1.36 2005/06/28 23:41:47 mkrufky Exp $
3 * 2 *
4 * device driver for philips saa7134 based TV cards 3 * device driver for philips saa7134 based TV cards
5 * video4linux video interface 4 * video4linux video interface
@@ -1368,29 +1367,7 @@ static int video_release(struct inode *inode, struct file *file)
1368 saa_andorb(SAA7134_OFMT_DATA_A, 0x1f, 0); 1367 saa_andorb(SAA7134_OFMT_DATA_A, 0x1f, 0);
1369 saa_andorb(SAA7134_OFMT_DATA_B, 0x1f, 0); 1368 saa_andorb(SAA7134_OFMT_DATA_B, 0x1f, 0);
1370 1369
1371 if (dev->tuner_type == TUNER_PHILIPS_TDA8290) { 1370 saa7134_i2c_call_clients(dev, TUNER_SET_STANDBY, NULL);
1372 u8 data[2];
1373 int ret;
1374 struct i2c_msg msg = {.addr=I2C_ADDR_TDA8290, .flags=0, .buf=data, .len = 2};
1375 data[0] = 0x21;
1376 data[1] = 0xc0;
1377 ret = i2c_transfer(&dev->i2c_adap, &msg, 1);
1378 if (ret != 1)
1379 printk(KERN_ERR "TDA8290 access failure\n");
1380 msg.addr = I2C_ADDR_TDA8275;
1381 data[0] = 0x30;
1382 data[1] = 0xd0;
1383 ret = i2c_transfer(&dev->i2c_adap, &msg, 1);
1384 if (ret != 1)
1385 printk(KERN_ERR "TDA8275 access failure\n");
1386 msg.addr = I2C_ADDR_TDA8290;
1387 data[0] = 0x21;
1388 data[1] = 0x80;
1389 i2c_transfer(&dev->i2c_adap, &msg, 1);
1390 data[0] = 0x00;
1391 data[1] = 0x02;
1392 i2c_transfer(&dev->i2c_adap, &msg, 1);
1393 }
1394 1371
1395 /* free stuff */ 1372 /* free stuff */
1396 videobuf_mmap_free(&fh->cap); 1373 videobuf_mmap_free(&fh->cap);
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index 2af0cb2a73..3ea09142ec 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: saa7134.h,v 1.49 2005/07/13 17:25:25 mchehab Exp $
3 * 2 *
4 * v4l2 device driver for philips saa7134 based TV cards 3 * v4l2 device driver for philips saa7134 based TV cards
5 * 4 *
@@ -185,6 +184,9 @@ struct saa7134_format {
185#define SAA7134_BOARD_PHILIPS_TOUGH 61 184#define SAA7134_BOARD_PHILIPS_TOUGH 61
186#define SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII 62 185#define SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII 62
187#define SAA7134_BOARD_KWORLD_XPERT 63 186#define SAA7134_BOARD_KWORLD_XPERT 63
187#define SAA7134_BOARD_FLYTV_DIGIMATRIX 64
188#define SAA7134_BOARD_KWORLD_TERMINATOR 65
189#define SAA7134_BOARD_YUAN_TUN900 66
188 190
189#define SAA7134_MAXBOARDS 8 191#define SAA7134_MAXBOARDS 8
190#define SAA7134_INPUT_MAX 8 192#define SAA7134_INPUT_MAX 8
diff --git a/drivers/media/video/stradis.c b/drivers/media/video/stradis.c
index b577435710..d4497dbae0 100644
--- a/drivers/media/video/stradis.c
+++ b/drivers/media/video/stradis.c
@@ -2184,30 +2184,18 @@ static void release_saa(void)
2184 vfree(saa->vidbuf); 2184 vfree(saa->vidbuf);
2185 vfree(saa->audbuf); 2185 vfree(saa->audbuf);
2186 vfree(saa->osdbuf); 2186 vfree(saa->osdbuf);
2187 if (saa->dmavid2) 2187 kfree(saa->dmavid2);
2188 kfree((void *) saa->dmavid2);
2189 saa->audbuf = saa->vidbuf = saa->osdbuf = NULL; 2188 saa->audbuf = saa->vidbuf = saa->osdbuf = NULL;
2190 saa->dmavid2 = NULL; 2189 saa->dmavid2 = NULL;
2191 if (saa->dmadebi) 2190 kfree(saa->dmadebi);
2192 kfree((void *) saa->dmadebi); 2191 kfree(saa->dmavid1);
2193 if (saa->dmavid1) 2192 kfree(saa->dmavid3);
2194 kfree((void *) saa->dmavid1); 2193 kfree(saa->dmaa1in);
2195 if (saa->dmavid2) 2194 kfree(saa->dmaa1out);
2196 kfree((void *) saa->dmavid2); 2195 kfree(saa->dmaa2in);
2197 if (saa->dmavid3) 2196 kfree(saa->dmaa2out);
2198 kfree((void *) saa->dmavid3); 2197 kfree(saa->dmaRPS1);
2199 if (saa->dmaa1in) 2198 kfree(saa->dmaRPS2);
2200 kfree((void *) saa->dmaa1in);
2201 if (saa->dmaa1out)
2202 kfree((void *) saa->dmaa1out);
2203 if (saa->dmaa2in)
2204 kfree((void *) saa->dmaa2in);
2205 if (saa->dmaa2out)
2206 kfree((void *) saa->dmaa2out);
2207 if (saa->dmaRPS1)
2208 kfree((void *) saa->dmaRPS1);
2209 if (saa->dmaRPS2)
2210 kfree((void *) saa->dmaRPS2);
2211 free_irq(saa->irq, saa); 2199 free_irq(saa->irq, saa);
2212 if (saa->saa7146_mem) 2200 if (saa->saa7146_mem)
2213 iounmap(saa->saa7146_mem); 2201 iounmap(saa->saa7146_mem);
diff --git a/drivers/media/video/tda8290.c b/drivers/media/video/tda8290.c
index a8b6a8df51..c65f0c7680 100644
--- a/drivers/media/video/tda8290.c
+++ b/drivers/media/video/tda8290.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: tda8290.c,v 1.15 2005/07/08 20:21:33 mchehab Exp $
3 * 2 *
4 * i2c tv tuner chip device driver 3 * i2c tv tuner chip device driver
5 * controls the philips tda8290+75 tuner chip combo. 4 * controls the philips tda8290+75 tuner chip combo.
@@ -9,6 +8,9 @@
9#include <linux/delay.h> 8#include <linux/delay.h>
10#include <media/tuner.h> 9#include <media/tuner.h>
11 10
11#define I2C_ADDR_TDA8290 0x4b
12#define I2C_ADDR_TDA8275 0x61
13
12/* ---------------------------------------------------------------------- */ 14/* ---------------------------------------------------------------------- */
13 15
14struct freq_entry { 16struct freq_entry {
@@ -75,10 +77,12 @@ static unsigned char i2c_init_tda8275[14] = { 0x00, 0x00, 0x00, 0x00,
75static unsigned char i2c_set_VS[2] = { 0x30, 0x6F }; 77static unsigned char i2c_set_VS[2] = { 0x30, 0x6F };
76static unsigned char i2c_set_GP01_CF[2] = { 0x20, 0x0B }; 78static unsigned char i2c_set_GP01_CF[2] = { 0x20, 0x0B };
77static unsigned char i2c_tda8290_reset[2] = { 0x00, 0x00 }; 79static unsigned char i2c_tda8290_reset[2] = { 0x00, 0x00 };
80static unsigned char i2c_tda8290_standby[2] = { 0x00, 0x02 };
78static unsigned char i2c_gainset_off[2] = { 0x28, 0x14 }; 81static unsigned char i2c_gainset_off[2] = { 0x28, 0x14 };
79static unsigned char i2c_gainset_on[2] = { 0x28, 0x54 }; 82static unsigned char i2c_gainset_on[2] = { 0x28, 0x54 };
80static unsigned char i2c_agc3_00[2] = { 0x80, 0x00 }; 83static unsigned char i2c_agc3_00[2] = { 0x80, 0x00 };
81static unsigned char i2c_agc2_BF[2] = { 0x60, 0xBF }; 84static unsigned char i2c_agc2_BF[2] = { 0x60, 0xBF };
85static unsigned char i2c_cb1_D0[2] = { 0x30, 0xD0 };
82static unsigned char i2c_cb1_D2[2] = { 0x30, 0xD2 }; 86static unsigned char i2c_cb1_D2[2] = { 0x30, 0xD2 };
83static unsigned char i2c_cb1_56[2] = { 0x30, 0x56 }; 87static unsigned char i2c_cb1_56[2] = { 0x30, 0x56 };
84static unsigned char i2c_cb1_52[2] = { 0x30, 0x52 }; 88static unsigned char i2c_cb1_52[2] = { 0x30, 0x52 };
@@ -117,6 +121,13 @@ static struct i2c_msg i2c_msg_epilog[] = {
117 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_gainset_on), i2c_gainset_on }, 121 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_gainset_on), i2c_gainset_on },
118}; 122};
119 123
124static struct i2c_msg i2c_msg_standby[] = {
125 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_enable_bridge), i2c_enable_bridge },
126 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_D0), i2c_cb1_D0 },
127 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_disable_bridge), i2c_disable_bridge },
128 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_tda8290_standby), i2c_tda8290_standby },
129};
130
120static int tda8290_tune(struct i2c_client *c) 131static int tda8290_tune(struct i2c_client *c)
121{ 132{
122 struct tuner *t = i2c_get_clientdata(c); 133 struct tuner *t = i2c_get_clientdata(c);
@@ -205,6 +216,11 @@ static int has_signal(struct i2c_client *c)
205 return (afc & 0x80)? 65535:0; 216 return (afc & 0x80)? 65535:0;
206} 217}
207 218
219static void standby(struct i2c_client *c)
220{
221 i2c_transfer(c->adapter, i2c_msg_standby, ARRAY_SIZE(i2c_msg_standby));
222}
223
208int tda8290_init(struct i2c_client *c) 224int tda8290_init(struct i2c_client *c)
209{ 225{
210 struct tuner *t = i2c_get_clientdata(c); 226 struct tuner *t = i2c_get_clientdata(c);
@@ -214,6 +230,7 @@ int tda8290_init(struct i2c_client *c)
214 t->tv_freq = set_tv_freq; 230 t->tv_freq = set_tv_freq;
215 t->radio_freq = set_radio_freq; 231 t->radio_freq = set_radio_freq;
216 t->has_signal = has_signal; 232 t->has_signal = has_signal;
233 t->standby = standby;
217 234
218 i2c_master_send(c, i2c_enable_bridge, ARRAY_SIZE(i2c_enable_bridge)); 235 i2c_master_send(c, i2c_enable_bridge, ARRAY_SIZE(i2c_enable_bridge));
219 i2c_transfer(c->adapter, i2c_msg_init, ARRAY_SIZE(i2c_msg_init)); 236 i2c_transfer(c->adapter, i2c_msg_init, ARRAY_SIZE(i2c_msg_init));
diff --git a/drivers/media/video/tda9887.c b/drivers/media/video/tda9887.c
index d60fc562ae..0456dda262 100644
--- a/drivers/media/video/tda9887.c
+++ b/drivers/media/video/tda9887.c
@@ -23,6 +23,7 @@
23 TDA9887 (world), TDA9885 (USA) 23 TDA9887 (world), TDA9885 (USA)
24 Note: OP2 of tda988x must be set to 1, else MT2032 is disabled! 24 Note: OP2 of tda988x must be set to 1, else MT2032 is disabled!
25 - KNC One TV-Station RDS (saa7134) 25 - KNC One TV-Station RDS (saa7134)
26 - Hauppauge PVR-150/500 (possibly more)
26*/ 27*/
27 28
28 29
@@ -49,7 +50,7 @@ MODULE_LICENSE("GPL");
49struct tda9887 { 50struct tda9887 {
50 struct i2c_client client; 51 struct i2c_client client;
51 v4l2_std_id std; 52 v4l2_std_id std;
52 unsigned int radio; 53 enum tuner_mode mode;
53 unsigned int config; 54 unsigned int config;
54 unsigned int pinnacle_id; 55 unsigned int pinnacle_id;
55 unsigned int using_v4l2; 56 unsigned int using_v4l2;
@@ -196,7 +197,7 @@ static struct tvnorm tvnorms[] = {
196 .b = ( cNegativeFmTV | 197 .b = ( cNegativeFmTV |
197 cQSS ), 198 cQSS ),
198 .c = ( cDeemphasisON | 199 .c = ( cDeemphasisON |
199 cDeemphasis50 ), 200 cDeemphasis75 ),
200 .e = ( cGating_36 | 201 .e = ( cGating_36 |
201 cAudioIF_4_5 | 202 cAudioIF_4_5 |
202 cVideoIF_45_75 ), 203 cVideoIF_45_75 ),
@@ -364,7 +365,7 @@ static int tda9887_set_tvnorm(struct tda9887 *t, char *buf)
364 struct tvnorm *norm = NULL; 365 struct tvnorm *norm = NULL;
365 int i; 366 int i;
366 367
367 if (t->radio) { 368 if (t->mode == T_RADIO) {
368 if (t->radio_mode == V4L2_TUNER_MODE_MONO) 369 if (t->radio_mode == V4L2_TUNER_MODE_MONO)
369 norm = &radio_mono; 370 norm = &radio_mono;
370 else 371 else
@@ -378,7 +379,7 @@ static int tda9887_set_tvnorm(struct tda9887 *t, char *buf)
378 } 379 }
379 } 380 }
380 if (NULL == norm) { 381 if (NULL == norm) {
381 dprintk(PREFIX "Oops: no tvnorm entry found\n"); 382 dprintk(PREFIX "Unsupported tvnorm entry - audio muted\n");
382 return -1; 383 return -1;
383 } 384 }
384 385
@@ -519,6 +520,12 @@ static int tda9887_fixup_std(struct tda9887 *t)
519 dprintk(PREFIX "insmod fixup: PAL => PAL-DK\n"); 520 dprintk(PREFIX "insmod fixup: PAL => PAL-DK\n");
520 t->std = V4L2_STD_PAL_DK; 521 t->std = V4L2_STD_PAL_DK;
521 break; 522 break;
523 case '-':
524 /* default parameter, do nothing */
525 break;
526 default:
527 printk(PREFIX "pal= argument not recognised\n");
528 break;
522 } 529 }
523 } 530 }
524 if ((t->std & V4L2_STD_SECAM) == V4L2_STD_SECAM) { 531 if ((t->std & V4L2_STD_SECAM) == V4L2_STD_SECAM) {
@@ -535,6 +542,12 @@ static int tda9887_fixup_std(struct tda9887 *t)
535 dprintk(PREFIX "insmod fixup: SECAM => SECAM-L\n"); 542 dprintk(PREFIX "insmod fixup: SECAM => SECAM-L\n");
536 t->std = V4L2_STD_SECAM_L; 543 t->std = V4L2_STD_SECAM_L;
537 break; 544 break;
545 case '-':
546 /* default parameter, do nothing */
547 break;
548 default:
549 printk(PREFIX "secam= argument not recognised\n");
550 break;
538 } 551 }
539 } 552 }
540 return 0; 553 return 0;
@@ -569,6 +582,10 @@ static int tda9887_configure(struct tda9887 *t)
569 tda9887_set_config(t,buf); 582 tda9887_set_config(t,buf);
570 tda9887_set_insmod(t,buf); 583 tda9887_set_insmod(t,buf);
571 584
585 if (t->mode == T_STANDBY) {
586 buf[1] |= cForcedMuteAudioON;
587 }
588
572 589
573 dprintk(PREFIX "writing: b=0x%02x c=0x%02x e=0x%02x\n", 590 dprintk(PREFIX "writing: b=0x%02x c=0x%02x e=0x%02x\n",
574 buf[1],buf[2],buf[3]); 591 buf[1],buf[2],buf[3]);
@@ -653,10 +670,17 @@ tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg)
653 670
654 /* --- configuration --- */ 671 /* --- configuration --- */
655 case AUDC_SET_RADIO: 672 case AUDC_SET_RADIO:
656 t->radio = 1; 673 {
674 t->mode = T_RADIO;
657 tda9887_configure(t); 675 tda9887_configure(t);
658 break; 676 break;
659 677 }
678 case TUNER_SET_STANDBY:
679 {
680 t->mode = T_STANDBY;
681 tda9887_configure(t);
682 break;
683 }
660 case AUDC_CONFIG_PINNACLE: 684 case AUDC_CONFIG_PINNACLE:
661 { 685 {
662 int *i = arg; 686 int *i = arg;
@@ -689,7 +713,7 @@ tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg)
689 struct video_channel *vc = arg; 713 struct video_channel *vc = arg;
690 714
691 CHECK_V4L2; 715 CHECK_V4L2;
692 t->radio = 0; 716 t->mode = T_ANALOG_TV;
693 if (vc->norm < ARRAY_SIZE(map)) 717 if (vc->norm < ARRAY_SIZE(map))
694 t->std = map[vc->norm]; 718 t->std = map[vc->norm];
695 tda9887_fixup_std(t); 719 tda9887_fixup_std(t);
@@ -701,7 +725,7 @@ tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg)
701 v4l2_std_id *id = arg; 725 v4l2_std_id *id = arg;
702 726
703 SWITCH_V4L2; 727 SWITCH_V4L2;
704 t->radio = 0; 728 t->mode = T_ANALOG_TV;
705 t->std = *id; 729 t->std = *id;
706 tda9887_fixup_std(t); 730 tda9887_fixup_std(t);
707 tda9887_configure(t); 731 tda9887_configure(t);
@@ -713,14 +737,14 @@ tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg)
713 737
714 SWITCH_V4L2; 738 SWITCH_V4L2;
715 if (V4L2_TUNER_ANALOG_TV == f->type) { 739 if (V4L2_TUNER_ANALOG_TV == f->type) {
716 if (t->radio == 0) 740 if (t->mode == T_ANALOG_TV)
717 return 0; 741 return 0;
718 t->radio = 0; 742 t->mode = T_ANALOG_TV;
719 } 743 }
720 if (V4L2_TUNER_RADIO == f->type) { 744 if (V4L2_TUNER_RADIO == f->type) {
721 if (t->radio == 1) 745 if (t->mode == T_RADIO)
722 return 0; 746 return 0;
723 t->radio = 1; 747 t->mode = T_RADIO;
724 } 748 }
725 tda9887_configure(t); 749 tda9887_configure(t);
726 break; 750 break;
@@ -735,7 +759,7 @@ tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg)
735 }; 759 };
736 struct v4l2_tuner* tuner = arg; 760 struct v4l2_tuner* tuner = arg;
737 761
738 if (t->radio) { 762 if (t->mode == T_RADIO) {
739 __u8 reg = 0; 763 __u8 reg = 0;
740 tuner->afc=0; 764 tuner->afc=0;
741 if (1 == i2c_master_recv(&t->client,&reg,1)) 765 if (1 == i2c_master_recv(&t->client,&reg,1))
@@ -747,7 +771,7 @@ tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg)
747 { 771 {
748 struct v4l2_tuner* tuner = arg; 772 struct v4l2_tuner* tuner = arg;
749 773
750 if (t->radio) { 774 if (t->mode == T_RADIO) {
751 t->radio_mode = tuner->audmode; 775 t->radio_mode = tuner->audmode;
752 tda9887_configure (t); 776 tda9887_configure (t);
753 } 777 }
diff --git a/drivers/media/video/tea5767.c b/drivers/media/video/tea5767.c
index cebcc1fa68..38bf509437 100644
--- a/drivers/media/video/tea5767.c
+++ b/drivers/media/video/tea5767.c
@@ -2,7 +2,6 @@
2 * For Philips TEA5767 FM Chip used on some TV Cards like Prolink Pixelview 2 * For Philips TEA5767 FM Chip used on some TV Cards like Prolink Pixelview
3 * I2C address is allways 0xC0. 3 * I2C address is allways 0xC0.
4 * 4 *
5 * $Id: tea5767.c,v 1.27 2005/07/31 12:10:56 mchehab Exp $
6 * 5 *
7 * Copyright (c) 2005 Mauro Carvalho Chehab (mchehab@brturbo.com.br) 6 * Copyright (c) 2005 Mauro Carvalho Chehab (mchehab@brturbo.com.br)
8 * This code is placed under the terms of the GNU General Public License 7 * This code is placed under the terms of the GNU General Public License
@@ -205,11 +204,6 @@ static void set_radio_freq(struct i2c_client *c, unsigned int frq)
205 TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND; 204 TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND;
206 buffer[4] = 0; 205 buffer[4] = 0;
207 206
208 if (t->mode == T_STANDBY) {
209 tuner_dbg("TEA5767 set to standby mode\n");
210 buffer[3] |= TEA5767_STDBY;
211 }
212
213 if (t->audmode == V4L2_TUNER_MODE_MONO) { 207 if (t->audmode == V4L2_TUNER_MODE_MONO) {
214 tuner_dbg("TEA5767 set to mono\n"); 208 tuner_dbg("TEA5767 set to mono\n");
215 buffer[2] |= TEA5767_MONO; 209 buffer[2] |= TEA5767_MONO;
@@ -290,13 +284,31 @@ static int tea5767_stereo(struct i2c_client *c)
290 return ((buffer[2] & TEA5767_STEREO_MASK) ? V4L2_TUNER_SUB_STEREO : 0); 284 return ((buffer[2] & TEA5767_STEREO_MASK) ? V4L2_TUNER_SUB_STEREO : 0);
291} 285}
292 286
287static void tea5767_standby(struct i2c_client *c)
288{
289 unsigned char buffer[5];
290 struct tuner *t = i2c_get_clientdata(c);
291 unsigned div, rc;
292
293 div = (87500 * 4 + 700 + 225 + 25) / 50; /* Set frequency to 87.5 MHz */
294 buffer[0] = (div >> 8) & 0x3f;
295 buffer[1] = div & 0xff;
296 buffer[2] = TEA5767_PORT1_HIGH;
297 buffer[3] = TEA5767_PORT2_HIGH | TEA5767_HIGH_CUT_CTRL |
298 TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND | TEA5767_STDBY;
299 buffer[4] = 0;
300
301 if (5 != (rc = i2c_master_send(c, buffer, 5)))
302 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
303}
304
293int tea5767_autodetection(struct i2c_client *c) 305int tea5767_autodetection(struct i2c_client *c)
294{ 306{
295 unsigned char buffer[7] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 307 unsigned char buffer[7] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
296 int rc; 308 int rc;
297 struct tuner *t = i2c_get_clientdata(c); 309 struct tuner *t = i2c_get_clientdata(c);
298 310
299 if (7 != (rc = i2c_master_recv(c, buffer, 7))) { 311 if ((rc = i2c_master_recv(c, buffer, 7))< 5) {
300 tuner_warn("It is not a TEA5767. Received %i bytes.\n", rc); 312 tuner_warn("It is not a TEA5767. Received %i bytes.\n", rc);
301 return EINVAL; 313 return EINVAL;
302 } 314 }
@@ -313,15 +325,10 @@ int tea5767_autodetection(struct i2c_client *c)
313 * bit 0 : internally set to 0 325 * bit 0 : internally set to 0
314 * Byte 5: bit 7:0 : == 0 326 * Byte 5: bit 7:0 : == 0
315 */ 327 */
316 if (!((buffer[3] & 0x0f) == 0x00) && (buffer[4] == 0x00)) { 328 if (((buffer[3] & 0x0f) != 0x00) || (buffer[4] != 0x00)) {
317 tuner_warn("Chip ID is not zero. It is not a TEA5767\n"); 329 tuner_warn("Chip ID is not zero. It is not a TEA5767\n");
318 return EINVAL; 330 return EINVAL;
319 } 331 }
320 /* It seems that tea5767 returns 0xff after the 5th byte */
321 if ((buffer[5] != 0xff) || (buffer[6] != 0xff)) {
322 tuner_warn("Returned more than 5 bytes. It is not a TEA5767\n");
323 return EINVAL;
324 }
325 332
326 /* It seems that tea5767 returns 0xff after the 5th byte */ 333 /* It seems that tea5767 returns 0xff after the 5th byte */
327 if ((buffer[5] != 0xff) || (buffer[6] != 0xff)) { 334 if ((buffer[5] != 0xff) || (buffer[6] != 0xff)) {
@@ -337,14 +344,14 @@ int tea5767_tuner_init(struct i2c_client *c)
337{ 344{
338 struct tuner *t = i2c_get_clientdata(c); 345 struct tuner *t = i2c_get_clientdata(c);
339 346
340 tuner_info("type set to %d (%s)\n", t->type, 347 tuner_info("type set to %d (%s)\n", t->type, "Philips TEA5767HN FM Radio");
341 "Philips TEA5767HN FM Radio");
342 strlcpy(c->name, "tea5767", sizeof(c->name)); 348 strlcpy(c->name, "tea5767", sizeof(c->name));
343 349
344 t->tv_freq = set_tv_freq; 350 t->tv_freq = set_tv_freq;
345 t->radio_freq = set_radio_freq; 351 t->radio_freq = set_radio_freq;
346 t->has_signal = tea5767_signal; 352 t->has_signal = tea5767_signal;
347 t->is_stereo = tea5767_stereo; 353 t->is_stereo = tea5767_stereo;
354 t->standby = tea5767_standby;
348 355
349 return (0); 356 return (0);
350} 357}
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 3b1893c2ae..05572020af 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: tuner-core.c,v 1.63 2005/07/28 18:19:55 mchehab Exp $
3 * 2 *
4 * i2c tv tuner chip device driver 3 * i2c tv tuner chip device driver
5 * core core, i.e. kernel interfaces, registering and so on 4 * core core, i.e. kernel interfaces, registering and so on
@@ -182,6 +181,14 @@ static void set_type(struct i2c_client *c, unsigned int type,
182 i2c_master_send(c, buffer, 4); 181 i2c_master_send(c, buffer, 4);
183 default_tuner_init(c); 182 default_tuner_init(c);
184 break; 183 break;
184 case TUNER_LG_TDVS_H062F:
185 /* Set the Auxiliary Byte. */
186 buffer[2] &= ~0x20;
187 buffer[2] |= 0x18;
188 buffer[3] = 0x20;
189 i2c_master_send(c, buffer, 4);
190 default_tuner_init(c);
191 break;
185 default: 192 default:
186 default_tuner_init(c); 193 default_tuner_init(c);
187 break; 194 break;
@@ -208,31 +215,31 @@ static void set_addr(struct i2c_client *c, struct tuner_setup *tun_setup)
208{ 215{
209 struct tuner *t = i2c_get_clientdata(c); 216 struct tuner *t = i2c_get_clientdata(c);
210 217
211 if (tun_setup->addr == ADDR_UNSET) { 218 if ((tun_setup->addr == ADDR_UNSET &&
212 if (t->mode_mask & tun_setup->mode_mask) 219 (t->mode_mask & tun_setup->mode_mask)) ||
220 tun_setup->addr == c->addr) {
213 set_type(c, tun_setup->type, tun_setup->mode_mask); 221 set_type(c, tun_setup->type, tun_setup->mode_mask);
214 } else if (tun_setup->addr == c->addr) {
215 set_type(c, tun_setup->type, tun_setup->mode_mask);
216 } 222 }
217} 223}
218 224
219static inline int check_mode(struct tuner *t, char *cmd) 225static inline int check_mode(struct tuner *t, char *cmd)
220{ 226{
221 if (1 << t->mode & t->mode_mask) { 227 if ((1 << t->mode & t->mode_mask) == 0) {
222 switch (t->mode) { 228 return EINVAL;
223 case V4L2_TUNER_RADIO: 229 }
224 tuner_dbg("Cmd %s accepted for radio\n", cmd); 230
225 break; 231 switch (t->mode) {
226 case V4L2_TUNER_ANALOG_TV: 232 case V4L2_TUNER_RADIO:
227 tuner_dbg("Cmd %s accepted for analog TV\n", cmd); 233 tuner_dbg("Cmd %s accepted for radio\n", cmd);
228 break; 234 break;
229 case V4L2_TUNER_DIGITAL_TV: 235 case V4L2_TUNER_ANALOG_TV:
230 tuner_dbg("Cmd %s accepted for digital TV\n", cmd); 236 tuner_dbg("Cmd %s accepted for analog TV\n", cmd);
231 break; 237 break;
232 } 238 case V4L2_TUNER_DIGITAL_TV:
233 return 0; 239 tuner_dbg("Cmd %s accepted for digital TV\n", cmd);
240 break;
234 } 241 }
235 return EINVAL; 242 return 0;
236} 243}
237 244
238static char pal[] = "-"; 245static char pal[] = "-";
@@ -274,6 +281,12 @@ static int tuner_fixup_std(struct tuner *t)
274 tuner_dbg ("insmod fixup: PAL => PAL-N\n"); 281 tuner_dbg ("insmod fixup: PAL => PAL-N\n");
275 t->std = V4L2_STD_PAL_N; 282 t->std = V4L2_STD_PAL_N;
276 break; 283 break;
284 case '-':
285 /* default parameter, do nothing */
286 break;
287 default:
288 tuner_warn ("pal= argument not recognised\n");
289 break;
277 } 290 }
278 } 291 }
279 if ((t->std & V4L2_STD_SECAM) == V4L2_STD_SECAM) { 292 if ((t->std & V4L2_STD_SECAM) == V4L2_STD_SECAM) {
@@ -290,6 +303,12 @@ static int tuner_fixup_std(struct tuner *t)
290 tuner_dbg ("insmod fixup: SECAM => SECAM-L\n"); 303 tuner_dbg ("insmod fixup: SECAM => SECAM-L\n");
291 t->std = V4L2_STD_SECAM_L; 304 t->std = V4L2_STD_SECAM_L;
292 break; 305 break;
306 case '-':
307 /* default parameter, do nothing */
308 break;
309 default:
310 tuner_warn ("secam= argument not recognised\n");
311 break;
293 } 312 }
294 } 313 }
295 314
@@ -406,20 +425,18 @@ static int tuner_detach(struct i2c_client *client)
406 425
407static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode, char *cmd) 426static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode, char *cmd)
408{ 427{
409 if (mode != t->mode) { 428 if (mode == t->mode)
410 429 return 0;
411 t->mode = mode; 430
412 if (check_mode(t, cmd) == EINVAL) { 431 t->mode = mode;
413 t->mode = T_STANDBY; 432
414 if (V4L2_TUNER_RADIO == mode) { 433 if (check_mode(t, cmd) == EINVAL) {
415 set_tv_freq(client, 400 * 16); 434 t->mode = T_STANDBY;
416 } else { 435 if (t->standby)
417 set_radio_freq(client, 87.5 * 16000); 436 t->standby (client);
418 } 437 return EINVAL;
419 return EINVAL; 438 }
420 } 439 return 0;
421 }
422 return 0;
423} 440}
424 441
425#define switch_v4l2() if (!t->using_v4l2) \ 442#define switch_v4l2() if (!t->using_v4l2) \
@@ -453,6 +470,14 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
453 case AUDC_SET_RADIO: 470 case AUDC_SET_RADIO:
454 set_mode(client,t,V4L2_TUNER_RADIO, "AUDC_SET_RADIO"); 471 set_mode(client,t,V4L2_TUNER_RADIO, "AUDC_SET_RADIO");
455 break; 472 break;
473 case TUNER_SET_STANDBY:
474 {
475 if (check_mode(t, "TUNER_SET_STANDBY") == EINVAL)
476 return 0;
477 if (t->standby)
478 t->standby (client);
479 break;
480 }
456 case AUDC_CONFIG_PINNACLE: 481 case AUDC_CONFIG_PINNACLE:
457 if (check_mode(t, "AUDC_CONFIG_PINNACLE") == EINVAL) 482 if (check_mode(t, "AUDC_CONFIG_PINNACLE") == EINVAL)
458 return 0; 483 return 0;
diff --git a/drivers/media/video/tuner-simple.c b/drivers/media/video/tuner-simple.c
index de0c93aeb7..8edd73abe1 100644
--- a/drivers/media/video/tuner-simple.c
+++ b/drivers/media/video/tuner-simple.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: tuner-simple.c,v 1.43 2005/07/28 18:41:21 mchehab Exp $
3 * 2 *
4 * i2c tv tuner chip device driver 3 * i2c tv tuner chip device driver
5 * controls all those simple 4-control-bytes style tuners. 4 * controls all those simple 4-control-bytes style tuners.
@@ -102,6 +101,7 @@ struct tunertype
102 * "no float in kernel" rule. 101 * "no float in kernel" rule.
103 */ 102 */
104static struct tunertype tuners[] = { 103static struct tunertype tuners[] = {
104 /* 0-9 */
105 { "Temic PAL (4002 FH5)", TEMIC, PAL, 105 { "Temic PAL (4002 FH5)", TEMIC, PAL,
106 16*140.25,16*463.25,0x02,0x04,0x01,0x8e,623}, 106 16*140.25,16*463.25,0x02,0x04,0x01,0x8e,623},
107 { "Philips PAL_I (FI1246 and compatibles)", Philips, PAL_I, 107 { "Philips PAL_I (FI1246 and compatibles)", Philips, PAL_I,
@@ -110,7 +110,6 @@ static struct tunertype tuners[] = {
110 16*157.25,16*451.25,0xA0,0x90,0x30,0x8e,732}, 110 16*157.25,16*451.25,0xA0,0x90,0x30,0x8e,732},
111 { "Philips (SECAM+PAL_BG) (FI1216MF, FM1216MF, FR1216MF)", Philips, SECAM, 111 { "Philips (SECAM+PAL_BG) (FI1216MF, FM1216MF, FR1216MF)", Philips, SECAM,
112 16*168.25,16*447.25,0xA7,0x97,0x37,0x8e,623}, 112 16*168.25,16*447.25,0xA7,0x97,0x37,0x8e,623},
113
114 { "NoTuner", NoTuner, NOTUNER, 113 { "NoTuner", NoTuner, NOTUNER,
115 0,0,0x00,0x00,0x00,0x00,0x00}, 114 0,0,0x00,0x00,0x00,0x00,0x00},
116 { "Philips PAL_BG (FI1216 and compatibles)", Philips, PAL, 115 { "Philips PAL_BG (FI1216 and compatibles)", Philips, PAL,
@@ -119,34 +118,34 @@ static struct tunertype tuners[] = {
119 16*157.25,16*463.25,0x02,0x04,0x01,0x8e,732}, 118 16*157.25,16*463.25,0x02,0x04,0x01,0x8e,732},
120 { "Temic PAL_I (4062 FY5)", TEMIC, PAL_I, 119 { "Temic PAL_I (4062 FY5)", TEMIC, PAL_I,
121 16*170.00,16*450.00,0x02,0x04,0x01,0x8e,623}, 120 16*170.00,16*450.00,0x02,0x04,0x01,0x8e,623},
122
123 { "Temic NTSC (4036 FY5)", TEMIC, NTSC, 121 { "Temic NTSC (4036 FY5)", TEMIC, NTSC,
124 16*157.25,16*463.25,0xa0,0x90,0x30,0x8e,732}, 122 16*157.25,16*463.25,0xa0,0x90,0x30,0x8e,732},
125 { "Alps HSBH1", TEMIC, NTSC, 123 { "Alps HSBH1", TEMIC, NTSC,
126 16*137.25,16*385.25,0x01,0x02,0x08,0x8e,732}, 124 16*137.25,16*385.25,0x01,0x02,0x08,0x8e,732},
127 { "Alps TSBE1",TEMIC,PAL, 125
126 /* 10-19 */
127 { "Alps TSBE1", TEMIC, PAL,
128 16*137.25,16*385.25,0x01,0x02,0x08,0x8e,732}, 128 16*137.25,16*385.25,0x01,0x02,0x08,0x8e,732},
129 { "Alps TSBB5", Alps, PAL_I, /* tested (UK UHF) with Modulartech MM205 */ 129 { "Alps TSBB5", Alps, PAL_I, /* tested (UK UHF) with Modulartech MM205 */
130 16*133.25,16*351.25,0x01,0x02,0x08,0x8e,632}, 130 16*133.25,16*351.25,0x01,0x02,0x08,0x8e,632},
131
132 { "Alps TSBE5", Alps, PAL, /* untested - data sheet guess. Only IF differs. */ 131 { "Alps TSBE5", Alps, PAL, /* untested - data sheet guess. Only IF differs. */
133 16*133.25,16*351.25,0x01,0x02,0x08,0x8e,622}, 132 16*133.25,16*351.25,0x01,0x02,0x08,0x8e,622},
134 { "Alps TSBC5", Alps, PAL, /* untested - data sheet guess. Only IF differs. */ 133 { "Alps TSBC5", Alps, PAL, /* untested - data sheet guess. Only IF differs. */
135 16*133.25,16*351.25,0x01,0x02,0x08,0x8e,608}, 134 16*133.25,16*351.25,0x01,0x02,0x08,0x8e,608},
136 { "Temic PAL_BG (4006FH5)", TEMIC, PAL, 135 { "Temic PAL_BG (4006FH5)", TEMIC, PAL,
137 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623}, 136 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623},
138 { "Alps TSCH6",Alps,NTSC, 137 { "Alps TSCH6", Alps, NTSC,
139 16*137.25,16*385.25,0x14,0x12,0x11,0x8e,732}, 138 16*137.25,16*385.25,0x14,0x12,0x11,0x8e,732},
140 139 { "Temic PAL_DK (4016 FY5)", TEMIC, PAL,
141 { "Temic PAL_DK (4016 FY5)",TEMIC,PAL,
142 16*168.25,16*456.25,0xa0,0x90,0x30,0x8e,623}, 140 16*168.25,16*456.25,0xa0,0x90,0x30,0x8e,623},
143 { "Philips NTSC_M (MK2)",Philips,NTSC, 141 { "Philips NTSC_M (MK2)", Philips, NTSC,
144 16*160.00,16*454.00,0xa0,0x90,0x30,0x8e,732}, 142 16*160.00,16*454.00,0xa0,0x90,0x30,0x8e,732},
145 { "Temic PAL_I (4066 FY5)", TEMIC, PAL_I, 143 { "Temic PAL_I (4066 FY5)", TEMIC, PAL_I,
146 16*169.00, 16*454.00, 0xa0,0x90,0x30,0x8e,623}, 144 16*169.00, 16*454.00, 0xa0,0x90,0x30,0x8e,623},
147 { "Temic PAL* auto (4006 FN5)", TEMIC, PAL, 145 { "Temic PAL* auto (4006 FN5)", TEMIC, PAL,
148 16*169.00, 16*454.00, 0xa0,0x90,0x30,0x8e,623}, 146 16*169.00, 16*454.00, 0xa0,0x90,0x30,0x8e,623},
149 147
148 /* 20-29 */
150 { "Temic PAL_BG (4009 FR5) or PAL_I (4069 FR5)", TEMIC, PAL, 149 { "Temic PAL_BG (4009 FR5) or PAL_I (4069 FR5)", TEMIC, PAL,
151 16*141.00, 16*464.00, 0xa0,0x90,0x30,0x8e,623}, 150 16*141.00, 16*464.00, 0xa0,0x90,0x30,0x8e,623},
152 { "Temic NTSC (4039 FR5)", TEMIC, NTSC, 151 { "Temic NTSC (4039 FR5)", TEMIC, NTSC,
@@ -155,7 +154,6 @@ static struct tunertype tuners[] = {
155 16*169.00, 16*454.00, 0xa0,0x90,0x30,0x8e,623}, 154 16*169.00, 16*454.00, 0xa0,0x90,0x30,0x8e,623},
156 { "Philips PAL_DK (FI1256 and compatibles)", Philips, PAL, 155 { "Philips PAL_DK (FI1256 and compatibles)", Philips, PAL,
157 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623}, 156 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623},
158
159 { "Philips PAL/SECAM multi (FQ1216ME)", Philips, PAL, 157 { "Philips PAL/SECAM multi (FQ1216ME)", Philips, PAL,
160 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623}, 158 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623},
161 { "LG PAL_I+FM (TAPC-I001D)", LGINNOTEK, PAL_I, 159 { "LG PAL_I+FM (TAPC-I001D)", LGINNOTEK, PAL_I,
@@ -164,25 +162,24 @@ static struct tunertype tuners[] = {
164 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623}, 162 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623},
165 { "LG NTSC+FM (TPI8NSR01F)", LGINNOTEK, NTSC, 163 { "LG NTSC+FM (TPI8NSR01F)", LGINNOTEK, NTSC,
166 16*210.00,16*497.00,0xa0,0x90,0x30,0x8e,732}, 164 16*210.00,16*497.00,0xa0,0x90,0x30,0x8e,732},
167
168 { "LG PAL_BG+FM (TPI8PSB01D)", LGINNOTEK, PAL, 165 { "LG PAL_BG+FM (TPI8PSB01D)", LGINNOTEK, PAL,
169 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623}, 166 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623},
170 { "LG PAL_BG (TPI8PSB11D)", LGINNOTEK, PAL, 167 { "LG PAL_BG (TPI8PSB11D)", LGINNOTEK, PAL,
171 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623}, 168 16*170.00,16*450.00,0xa0,0x90,0x30,0x8e,623},
169
170 /* 30-39 */
172 { "Temic PAL* auto + FM (4009 FN5)", TEMIC, PAL, 171 { "Temic PAL* auto + FM (4009 FN5)", TEMIC, PAL,
173 16*141.00, 16*464.00, 0xa0,0x90,0x30,0x8e,623}, 172 16*141.00, 16*464.00, 0xa0,0x90,0x30,0x8e,623},
174 { "SHARP NTSC_JP (2U5JF5540)", SHARP, NTSC, /* 940=16*58.75 NTSC@Japan */ 173 { "SHARP NTSC_JP (2U5JF5540)", SHARP, NTSC, /* 940=16*58.75 NTSC@Japan */
175 16*137.25,16*317.25,0x01,0x02,0x08,0x8e,940 }, 174 16*137.25,16*317.25,0x01,0x02,0x08,0x8e,940 },
176 175 { "Samsung PAL TCPM9091PD27", Samsung, PAL, /* from sourceforge v3tv */
177 { "Samsung PAL TCPM9091PD27", Samsung, PAL, /* from sourceforge v3tv */
178 16*169,16*464,0xA0,0x90,0x30,0x8e,623}, 176 16*169,16*464,0xA0,0x90,0x30,0x8e,623},
179 { "MT20xx universal", Microtune,PAL|NTSC, 177 { "MT20xx universal", Microtune, PAL|NTSC,
180 /* see mt20xx.c for details */ }, 178 /* see mt20xx.c for details */ },
181 { "Temic PAL_BG (4106 FH5)", TEMIC, PAL, 179 { "Temic PAL_BG (4106 FH5)", TEMIC, PAL,
182 16*141.00, 16*464.00, 0xa0,0x90,0x30,0x8e,623}, 180 16*141.00, 16*464.00, 0xa0,0x90,0x30,0x8e,623},
183 { "Temic PAL_DK/SECAM_L (4012 FY5)", TEMIC, PAL, 181 { "Temic PAL_DK/SECAM_L (4012 FY5)", TEMIC, PAL,
184 16*140.25, 16*463.25, 0x02,0x04,0x01,0x8e,623}, 182 16*140.25, 16*463.25, 0x02,0x04,0x01,0x8e,623},
185
186 { "Temic NTSC (4136 FY5)", TEMIC, NTSC, 183 { "Temic NTSC (4136 FY5)", TEMIC, NTSC,
187 16*158.00, 16*453.00, 0xa0,0x90,0x30,0x8e,732}, 184 16*158.00, 16*453.00, 0xa0,0x90,0x30,0x8e,732},
188 { "LG PAL (newer TAPC series)", LGINNOTEK, PAL, 185 { "LG PAL (newer TAPC series)", LGINNOTEK, PAL,
@@ -192,42 +189,41 @@ static struct tunertype tuners[] = {
192 { "LG NTSC (newer TAPC series)", LGINNOTEK, NTSC, 189 { "LG NTSC (newer TAPC series)", LGINNOTEK, NTSC,
193 16*170.00, 16*450.00, 0x01,0x02,0x08,0x8e,732}, 190 16*170.00, 16*450.00, 0x01,0x02,0x08,0x8e,732},
194 191
192 /* 40-49 */
195 { "HITACHI V7-J180AT", HITACHI, NTSC, 193 { "HITACHI V7-J180AT", HITACHI, NTSC,
196 16*170.00, 16*450.00, 0x01,0x02,0x08,0x8e,940 }, 194 16*170.00, 16*450.00, 0x01,0x02,0x08,0x8e,940 },
197 { "Philips PAL_MK (FI1216 MK)", Philips, PAL, 195 { "Philips PAL_MK (FI1216 MK)", Philips, PAL,
198 16*140.25,16*463.25,0x01,0xc2,0xcf,0x8e,623}, 196 16*140.25,16*463.25,0x01,0xc2,0xcf,0x8e,623},
199 { "Philips 1236D ATSC/NTSC daul in",Philips,ATSC, 197 { "Philips 1236D ATSC/NTSC daul in", Philips, ATSC,
200 16*157.25,16*454.00,0xa0,0x90,0x30,0x8e,732}, 198 16*157.25,16*454.00,0xa0,0x90,0x30,0x8e,732},
201 { "Philips NTSC MK3 (FM1236MK3 or FM1236/F)", Philips, NTSC, 199 { "Philips NTSC MK3 (FM1236MK3 or FM1236/F)", Philips, NTSC,
202 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,732}, 200 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,732},
203
204 { "Philips 4 in 1 (ATI TV Wonder Pro/Conexant)", Philips, NTSC, 201 { "Philips 4 in 1 (ATI TV Wonder Pro/Conexant)", Philips, NTSC,
205 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,732}, 202 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,732},
206 { "Microtune 4049 FM5",Microtune,PAL, 203 { "Microtune 4049 FM5", Microtune, PAL,
207 16*141.00,16*464.00,0xa0,0x90,0x30,0x8e,623}, 204 16*141.00,16*464.00,0xa0,0x90,0x30,0x8e,623},
208 { "Panasonic VP27s/ENGE4324D", Panasonic, NTSC, 205 { "Panasonic VP27s/ENGE4324D", Panasonic, NTSC,
209 16*160.00,16*454.00,0x01,0x02,0x08,0xce,940}, 206 16*160.00,16*454.00,0x01,0x02,0x08,0xce,940},
210 { "LG NTSC (TAPE series)", LGINNOTEK, NTSC, 207 { "LG NTSC (TAPE series)", LGINNOTEK, NTSC,
211 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,732 }, 208 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,732 },
212
213 { "Tenna TNF 8831 BGFF)", Philips, PAL, 209 { "Tenna TNF 8831 BGFF)", Philips, PAL,
214 16*161.25,16*463.25,0xa0,0x90,0x30,0x8e,623}, 210 16*161.25,16*463.25,0xa0,0x90,0x30,0x8e,623},
215 { "Microtune 4042 FI5 ATSC/NTSC dual in", Microtune, NTSC, 211 { "Microtune 4042 FI5 ATSC/NTSC dual in", Microtune, NTSC,
216 16*162.00,16*457.00,0xa2,0x94,0x31,0x8e,732}, 212 16*162.00,16*457.00,0xa2,0x94,0x31,0x8e,732},
213
214 /* 50-59 */
217 { "TCL 2002N", TCL, NTSC, 215 { "TCL 2002N", TCL, NTSC,
218 16*172.00,16*448.00,0x01,0x02,0x08,0x8e,732}, 216 16*172.00,16*448.00,0x01,0x02,0x08,0x8e,732},
219 { "Philips PAL/SECAM_D (FM 1256 I-H3)", Philips, PAL, 217 { "Philips PAL/SECAM_D (FM 1256 I-H3)", Philips, PAL,
220 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,623 }, 218 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,623 },
221
222 { "Thomson DDT 7610 (ATSC/NTSC)", THOMSON, ATSC, 219 { "Thomson DDT 7610 (ATSC/NTSC)", THOMSON, ATSC,
223 16*157.25,16*454.00,0x39,0x3a,0x3c,0x8e,732}, 220 16*157.25,16*454.00,0x39,0x3a,0x3c,0x8e,732},
224 { "Philips FQ1286", Philips, NTSC, 221 { "Philips FQ1286", Philips, NTSC,
225 16*160.00,16*454.00,0x41,0x42,0x04,0x8e,940}, // UHF band untested 222 16*160.00,16*454.00,0x41,0x42,0x04,0x8e,940}, /* UHF band untested */
226 { "tda8290+75", Philips,PAL|NTSC, 223 { "tda8290+75", Philips, PAL|NTSC,
227 /* see tda8290.c for details */ }, 224 /* see tda8290.c for details */ },
228 { "LG PAL (TAPE series)", LGINNOTEK, PAL, 225 { "LG PAL (TAPE series)", LGINNOTEK, PAL,
229 16*170.00, 16*450.00, 0x01,0x02,0x08,0xce,623}, 226 16*170.00, 16*450.00, 0x01,0x02,0x08,0xce,623},
230
231 { "Philips PAL/SECAM multi (FQ1216AME MK4)", Philips, PAL, 227 { "Philips PAL/SECAM multi (FQ1216AME MK4)", Philips, PAL,
232 16*160.00,16*442.00,0x01,0x02,0x04,0xce,623 }, 228 16*160.00,16*442.00,0x01,0x02,0x04,0xce,623 },
233 { "Philips FQ1236A MK4", Philips, NTSC, 229 { "Philips FQ1236A MK4", Philips, NTSC,
@@ -237,6 +233,7 @@ static struct tunertype tuners[] = {
237 { "Ymec TVision TVF-5533MF", Philips, NTSC, 233 { "Ymec TVision TVF-5533MF", Philips, NTSC,
238 16*160.00,16*454.00,0x01,0x02,0x04,0x8e,732}, 234 16*160.00,16*454.00,0x01,0x02,0x04,0x8e,732},
239 235
236 /* 60-66 */
240 { "Thomson DDT 7611 (ATSC/NTSC)", THOMSON, ATSC, 237 { "Thomson DDT 7611 (ATSC/NTSC)", THOMSON, ATSC,
241 16*157.25,16*454.00,0x39,0x3a,0x3c,0x8e,732}, 238 16*157.25,16*454.00,0x39,0x3a,0x3c,0x8e,732},
242 { "Tena TNF9533-D/IF/TNF9533-B/DF", Philips, PAL, 239 { "Tena TNF9533-D/IF/TNF9533-B/DF", Philips, PAL,
@@ -245,12 +242,12 @@ static struct tunertype tuners[] = {
245 /* see tea5767.c for details */}, 242 /* see tea5767.c for details */},
246 { "Philips FMD1216ME MK3 Hybrid Tuner", Philips, PAL, 243 { "Philips FMD1216ME MK3 Hybrid Tuner", Philips, PAL,
247 16*160.00,16*442.00,0x51,0x52,0x54,0x86,623 }, 244 16*160.00,16*442.00,0x51,0x52,0x54,0x86,623 },
248 245 { "LG TDVS-H062F/TUA6034", LGINNOTEK, ATSC,
249 { "LG TDVS-H062F/TUA6034", LGINNOTEK, NTSC,
250 16*160.00,16*455.00,0x01,0x02,0x04,0x8e,732}, 246 16*160.00,16*455.00,0x01,0x02,0x04,0x8e,732},
251
252 { "Ymec TVF66T5-B/DFF", Philips, PAL, 247 { "Ymec TVF66T5-B/DFF", Philips, PAL,
253 16*160.25,16*464.25,0x01,0x02,0x08,0x8e,623}, 248 16*160.25,16*464.25,0x01,0x02,0x08,0x8e,623},
249 { "LG NTSC (TALN mini series)", LGINNOTEK, NTSC,
250 16*137.25,16*373.25,0x01,0x02,0x08,0x8e,732 },
254}; 251};
255 252
256unsigned const int tuner_count = ARRAY_SIZE(tuners); 253unsigned const int tuner_count = ARRAY_SIZE(tuners);
@@ -471,6 +468,10 @@ static void default_set_radio_freq(struct i2c_client *c, unsigned int freq)
471 case TUNER_LG_PAL_FM: 468 case TUNER_LG_PAL_FM:
472 buffer[3] = 0xa5; 469 buffer[3] = 0xa5;
473 break; 470 break;
471 case TUNER_MICROTUNE_4049FM5:
472 div = (20 * freq) / 16000 + (int)(33.3 * 20); /* IF 33.3 MHz */
473 buffer[3] = 0xa4;
474 break;
474 default: 475 default:
475 buffer[3] = 0xa4; 476 buffer[3] = 0xa4;
476 break; 477 break;
@@ -497,6 +498,7 @@ int default_tuner_init(struct i2c_client *c)
497 t->radio_freq = default_set_radio_freq; 498 t->radio_freq = default_set_radio_freq;
498 t->has_signal = tuner_signal; 499 t->has_signal = tuner_signal;
499 t->is_stereo = tuner_stereo; 500 t->is_stereo = tuner_stereo;
501 t->standby = NULL;
500 502
501 return 0; 503 return 0;
502} 504}
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index 258724b2d6..1c31ef52f8 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -46,7 +46,17 @@ MODULE_AUTHOR("Eric Sandeen, Steve VanDeBogart, Greg Alexander, Gerd Knorr");
46MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
47 47
48#define UNSET (-1U) 48#define UNSET (-1U)
49#define dprintk if (debug) printk 49
50#define tvaudio_info(fmt, arg...) do {\
51 printk(KERN_INFO "tvaudio %d-%04x: " fmt, \
52 chip->c.adapter->nr, chip->c.addr , ##arg); } while (0)
53#define tvaudio_warn(fmt, arg...) do {\
54 printk(KERN_WARNING "tvaudio %d-%04x: " fmt, \
55 chip->c.adapter->nr, chip->c.addr , ##arg); } while (0)
56#define tvaudio_dbg(fmt, arg...) do {\
57 if (debug) \
58 printk(KERN_INFO "tvaudio %d-%04x: " fmt, \
59 chip->c.adapter->nr, chip->c.addr , ##arg); } while (0)
50 60
51/* ---------------------------------------------------------------------- */ 61/* ---------------------------------------------------------------------- */
52/* our structs */ 62/* our structs */
@@ -162,23 +172,24 @@ static int chip_write(struct CHIPSTATE *chip, int subaddr, int val)
162 unsigned char buffer[2]; 172 unsigned char buffer[2];
163 173
164 if (-1 == subaddr) { 174 if (-1 == subaddr) {
165 dprintk("%s: chip_write: 0x%x\n", chip->c.name, val); 175 tvaudio_dbg("%s: chip_write: 0x%x\n",
176 chip->c.name, val);
166 chip->shadow.bytes[1] = val; 177 chip->shadow.bytes[1] = val;
167 buffer[0] = val; 178 buffer[0] = val;
168 if (1 != i2c_master_send(&chip->c,buffer,1)) { 179 if (1 != i2c_master_send(&chip->c,buffer,1)) {
169 printk(KERN_WARNING "%s: I/O error (write 0x%x)\n", 180 tvaudio_warn("%s: I/O error (write 0x%x)\n",
170 chip->c.name, val); 181 chip->c.name, val);
171 return -1; 182 return -1;
172 } 183 }
173 } else { 184 } else {
174 dprintk("%s: chip_write: reg%d=0x%x\n", 185 tvaudio_dbg("%s: chip_write: reg%d=0x%x\n",
175 chip->c.name, subaddr, val); 186 chip->c.name, subaddr, val);
176 chip->shadow.bytes[subaddr+1] = val; 187 chip->shadow.bytes[subaddr+1] = val;
177 buffer[0] = subaddr; 188 buffer[0] = subaddr;
178 buffer[1] = val; 189 buffer[1] = val;
179 if (2 != i2c_master_send(&chip->c,buffer,2)) { 190 if (2 != i2c_master_send(&chip->c,buffer,2)) {
180 printk(KERN_WARNING "%s: I/O error (write reg%d=0x%x)\n", 191 tvaudio_warn("%s: I/O error (write reg%d=0x%x)\n",
181 chip->c.name, subaddr, val); 192 chip->c.name, subaddr, val);
182 return -1; 193 return -1;
183 } 194 }
184 } 195 }
@@ -202,29 +213,30 @@ static int chip_read(struct CHIPSTATE *chip)
202 unsigned char buffer; 213 unsigned char buffer;
203 214
204 if (1 != i2c_master_recv(&chip->c,&buffer,1)) { 215 if (1 != i2c_master_recv(&chip->c,&buffer,1)) {
205 printk(KERN_WARNING "%s: I/O error (read)\n", chip->c.name); 216 tvaudio_warn("%s: I/O error (read)\n",
217 chip->c.name);
206 return -1; 218 return -1;
207 } 219 }
208 dprintk("%s: chip_read: 0x%x\n", chip->c.name, buffer); 220 tvaudio_dbg("%s: chip_read: 0x%x\n",chip->c.name,buffer);
209 return buffer; 221 return buffer;
210} 222}
211 223
212static int chip_read2(struct CHIPSTATE *chip, int subaddr) 224static int chip_read2(struct CHIPSTATE *chip, int subaddr)
213{ 225{
214 unsigned char write[1]; 226 unsigned char write[1];
215 unsigned char read[1]; 227 unsigned char read[1];
216 struct i2c_msg msgs[2] = { 228 struct i2c_msg msgs[2] = {
217 { chip->c.addr, 0, 1, write }, 229 { chip->c.addr, 0, 1, write },
218 { chip->c.addr, I2C_M_RD, 1, read } 230 { chip->c.addr, I2C_M_RD, 1, read }
219 }; 231 };
220 write[0] = subaddr; 232 write[0] = subaddr;
221 233
222 if (2 != i2c_transfer(chip->c.adapter,msgs,2)) { 234 if (2 != i2c_transfer(chip->c.adapter,msgs,2)) {
223 printk(KERN_WARNING "%s: I/O error (read2)\n", chip->c.name); 235 tvaudio_warn("%s: I/O error (read2)\n", chip->c.name);
224 return -1; 236 return -1;
225 } 237 }
226 dprintk("%s: chip_read2: reg%d=0x%x\n", 238 tvaudio_dbg("%s: chip_read2: reg%d=0x%x\n",
227 chip->c.name, subaddr, read[0]); 239 chip->c.name,subaddr,read[0]);
228 return read[0]; 240 return read[0];
229} 241}
230 242
@@ -236,17 +248,19 @@ static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd)
236 return 0; 248 return 0;
237 249
238 /* update our shadow register set; print bytes if (debug > 0) */ 250 /* update our shadow register set; print bytes if (debug > 0) */
239 dprintk("%s: chip_cmd(%s): reg=%d, data:", 251 tvaudio_dbg("%s: chip_cmd(%s): reg=%d, data:",
240 chip->c.name, name, cmd->bytes[0]); 252 chip->c.name,name,cmd->bytes[0]);
241 for (i = 1; i < cmd->count; i++) { 253 for (i = 1; i < cmd->count; i++) {
242 dprintk(" 0x%x",cmd->bytes[i]); 254 if (debug)
255 printk(" 0x%x",cmd->bytes[i]);
243 chip->shadow.bytes[i+cmd->bytes[0]] = cmd->bytes[i]; 256 chip->shadow.bytes[i+cmd->bytes[0]] = cmd->bytes[i];
244 } 257 }
245 dprintk("\n"); 258 if (debug)
259 printk("\n");
246 260
247 /* send data to the chip */ 261 /* send data to the chip */
248 if (cmd->count != i2c_master_send(&chip->c,cmd->bytes,cmd->count)) { 262 if (cmd->count != i2c_master_send(&chip->c,cmd->bytes,cmd->count)) {
249 printk(KERN_WARNING "%s: I/O error (%s)\n", chip->c.name, name); 263 tvaudio_warn("%s: I/O error (%s)\n", chip->c.name, name);
250 return -1; 264 return -1;
251 } 265 }
252 return 0; 266 return 0;
@@ -261,19 +275,19 @@ static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd)
261 275
262static void chip_thread_wake(unsigned long data) 276static void chip_thread_wake(unsigned long data)
263{ 277{
264 struct CHIPSTATE *chip = (struct CHIPSTATE*)data; 278 struct CHIPSTATE *chip = (struct CHIPSTATE*)data;
265 wake_up_interruptible(&chip->wq); 279 wake_up_interruptible(&chip->wq);
266} 280}
267 281
268static int chip_thread(void *data) 282static int chip_thread(void *data)
269{ 283{
270 DECLARE_WAITQUEUE(wait, current); 284 DECLARE_WAITQUEUE(wait, current);
271 struct CHIPSTATE *chip = data; 285 struct CHIPSTATE *chip = data;
272 struct CHIPDESC *desc = chiplist + chip->type; 286 struct CHIPDESC *desc = chiplist + chip->type;
273 287
274 daemonize("%s", chip->c.name); 288 daemonize("%s", chip->c.name);
275 allow_signal(SIGTERM); 289 allow_signal(SIGTERM);
276 dprintk("%s: thread started\n", chip->c.name); 290 tvaudio_dbg("%s: thread started\n", chip->c.name);
277 291
278 for (;;) { 292 for (;;) {
279 add_wait_queue(&chip->wq, &wait); 293 add_wait_queue(&chip->wq, &wait);
@@ -285,7 +299,7 @@ static int chip_thread(void *data)
285 try_to_freeze(); 299 try_to_freeze();
286 if (chip->done || signal_pending(current)) 300 if (chip->done || signal_pending(current))
287 break; 301 break;
288 dprintk("%s: thread wakeup\n", chip->c.name); 302 tvaudio_dbg("%s: thread wakeup\n", chip->c.name);
289 303
290 /* don't do anything for radio or if mode != auto */ 304 /* don't do anything for radio or if mode != auto */
291 if (chip->norm == VIDEO_MODE_RADIO || chip->mode != 0) 305 if (chip->norm == VIDEO_MODE_RADIO || chip->mode != 0)
@@ -298,8 +312,8 @@ static int chip_thread(void *data)
298 mod_timer(&chip->wt, jiffies+2*HZ); 312 mod_timer(&chip->wt, jiffies+2*HZ);
299 } 313 }
300 314
301 dprintk("%s: thread exiting\n", chip->c.name); 315 tvaudio_dbg("%s: thread exiting\n", chip->c.name);
302 complete_and_exit(&chip->texit, 0); 316 complete_and_exit(&chip->texit, 0);
303 return 0; 317 return 0;
304} 318}
305 319
@@ -309,9 +323,9 @@ static void generic_checkmode(struct CHIPSTATE *chip)
309 int mode = desc->getmode(chip); 323 int mode = desc->getmode(chip);
310 324
311 if (mode == chip->prevmode) 325 if (mode == chip->prevmode)
312 return; 326 return;
313 327
314 dprintk("%s: thread checkmode\n", chip->c.name); 328 tvaudio_dbg("%s: thread checkmode\n", chip->c.name);
315 chip->prevmode = mode; 329 chip->prevmode = mode;
316 330
317 if (mode & VIDEO_SOUND_STEREO) 331 if (mode & VIDEO_SOUND_STEREO)
@@ -358,8 +372,8 @@ static int tda9840_getmode(struct CHIPSTATE *chip)
358 if (val & TDA9840_ST_STEREO) 372 if (val & TDA9840_ST_STEREO)
359 mode |= VIDEO_SOUND_STEREO; 373 mode |= VIDEO_SOUND_STEREO;
360 374
361 dprintk ("tda9840_getmode(): raw chip read: %d, return: %d\n", 375 tvaudio_dbg ("tda9840_getmode(): raw chip read: %d, return: %d\n",
362 val, mode); 376 val, mode);
363 return mode; 377 return mode;
364} 378}
365 379
@@ -654,8 +668,8 @@ static int tda9873_getmode(struct CHIPSTATE *chip)
654 mode |= VIDEO_SOUND_STEREO; 668 mode |= VIDEO_SOUND_STEREO;
655 if (val & TDA9873_DUAL) 669 if (val & TDA9873_DUAL)
656 mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2; 670 mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
657 dprintk ("tda9873_getmode(): raw chip read: %d, return: %d\n", 671 tvaudio_dbg ("tda9873_getmode(): raw chip read: %d, return: %d\n",
658 val, mode); 672 val, mode);
659 return mode; 673 return mode;
660} 674}
661 675
@@ -665,12 +679,12 @@ static void tda9873_setmode(struct CHIPSTATE *chip, int mode)
665 /* int adj_data = chip->shadow.bytes[TDA9873_AD+1] ; */ 679 /* int adj_data = chip->shadow.bytes[TDA9873_AD+1] ; */
666 680
667 if ((sw_data & TDA9873_INP_MASK) != TDA9873_INTERNAL) { 681 if ((sw_data & TDA9873_INP_MASK) != TDA9873_INTERNAL) {
668 dprintk("tda9873_setmode(): external input\n"); 682 tvaudio_dbg("tda9873_setmode(): external input\n");
669 return; 683 return;
670 } 684 }
671 685
672 dprintk("tda9873_setmode(): chip->shadow.bytes[%d] = %d\n", TDA9873_SW+1, chip->shadow.bytes[TDA9873_SW+1]); 686 tvaudio_dbg("tda9873_setmode(): chip->shadow.bytes[%d] = %d\n", TDA9873_SW+1, chip->shadow.bytes[TDA9873_SW+1]);
673 dprintk("tda9873_setmode(): sw_data = %d\n", sw_data); 687 tvaudio_dbg("tda9873_setmode(): sw_data = %d\n", sw_data);
674 688
675 switch (mode) { 689 switch (mode) {
676 case VIDEO_SOUND_MONO: 690 case VIDEO_SOUND_MONO:
@@ -691,7 +705,7 @@ static void tda9873_setmode(struct CHIPSTATE *chip, int mode)
691 } 705 }
692 706
693 chip_write(chip, TDA9873_SW, sw_data); 707 chip_write(chip, TDA9873_SW, sw_data);
694 dprintk("tda9873_setmode(): req. mode %d; chip_write: %d\n", 708 tvaudio_dbg("tda9873_setmode(): req. mode %d; chip_write: %d\n",
695 mode, sw_data); 709 mode, sw_data);
696} 710}
697 711
@@ -828,9 +842,9 @@ static int tda9874a_setup(struct CHIPSTATE *chip)
828 } else { /* dic == 0x07 */ 842 } else { /* dic == 0x07 */
829 chip_write(chip, TDA9874A_AMCONR, 0xfb); 843 chip_write(chip, TDA9874A_AMCONR, 0xfb);
830 chip_write(chip, TDA9874A_SDACOSR, (tda9874a_mode) ? 0x81:0x80); 844 chip_write(chip, TDA9874A_SDACOSR, (tda9874a_mode) ? 0x81:0x80);
831 chip_write(chip, TDA9874A_AOSR, 0x00); // or 0x10 845 chip_write(chip, TDA9874A_AOSR, 0x00); /* or 0x10 */
832 } 846 }
833 dprintk("tda9874a_setup(): %s [0x%02X].\n", 847 tvaudio_dbg("tda9874a_setup(): %s [0x%02X].\n",
834 tda9874a_modelist[tda9874a_STD].name,tda9874a_STD); 848 tda9874a_modelist[tda9874a_STD].name,tda9874a_STD);
835 return 1; 849 return 1;
836} 850}
@@ -873,7 +887,7 @@ static int tda9874a_getmode(struct CHIPSTATE *chip)
873 mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2; 887 mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
874 } 888 }
875 889
876 dprintk("tda9874a_getmode(): DSR=0x%X, NSR=0x%X, NECR=0x%X, return: %d.\n", 890 tvaudio_dbg("tda9874a_getmode(): DSR=0x%X, NSR=0x%X, NECR=0x%X, return: %d.\n",
877 dsr, nsr, necr, mode); 891 dsr, nsr, necr, mode);
878 return mode; 892 return mode;
879} 893}
@@ -919,7 +933,7 @@ static void tda9874a_setmode(struct CHIPSTATE *chip, int mode)
919 chip_write(chip, TDA9874A_AOSR, aosr); 933 chip_write(chip, TDA9874A_AOSR, aosr);
920 chip_write(chip, TDA9874A_MDACOSR, mdacosr); 934 chip_write(chip, TDA9874A_MDACOSR, mdacosr);
921 935
922 dprintk("tda9874a_setmode(): req. mode %d; AOSR=0x%X, MDACOSR=0x%X.\n", 936 tvaudio_dbg("tda9874a_setmode(): req. mode %d; AOSR=0x%X, MDACOSR=0x%X.\n",
923 mode, aosr, mdacosr); 937 mode, aosr, mdacosr);
924 938
925 } else { /* dic == 0x07 */ 939 } else { /* dic == 0x07 */
@@ -954,7 +968,7 @@ static void tda9874a_setmode(struct CHIPSTATE *chip, int mode)
954 chip_write(chip, TDA9874A_FMMR, fmmr); 968 chip_write(chip, TDA9874A_FMMR, fmmr);
955 chip_write(chip, TDA9874A_AOSR, aosr); 969 chip_write(chip, TDA9874A_AOSR, aosr);
956 970
957 dprintk("tda9874a_setmode(): req. mode %d; FMMR=0x%X, AOSR=0x%X.\n", 971 tvaudio_dbg("tda9874a_setmode(): req. mode %d; FMMR=0x%X, AOSR=0x%X.\n",
958 mode, fmmr, aosr); 972 mode, fmmr, aosr);
959 } 973 }
960} 974}
@@ -968,10 +982,10 @@ static int tda9874a_checkit(struct CHIPSTATE *chip)
968 if(-1 == (sic = chip_read2(chip,TDA9874A_SIC))) 982 if(-1 == (sic = chip_read2(chip,TDA9874A_SIC)))
969 return 0; 983 return 0;
970 984
971 dprintk("tda9874a_checkit(): DIC=0x%X, SIC=0x%X.\n", dic, sic); 985 tvaudio_dbg("tda9874a_checkit(): DIC=0x%X, SIC=0x%X.\n", dic, sic);
972 986
973 if((dic == 0x11)||(dic == 0x07)) { 987 if((dic == 0x11)||(dic == 0x07)) {
974 printk("tvaudio: found tda9874%s.\n", (dic == 0x11) ? "a":"h"); 988 tvaudio_info("found tda9874%s.\n", (dic == 0x11) ? "a":"h");
975 tda9874a_dic = dic; /* remember device id. */ 989 tda9874a_dic = dic; /* remember device id. */
976 return 1; 990 return 1;
977 } 991 }
@@ -1146,7 +1160,7 @@ static void tda8425_setmode(struct CHIPSTATE *chip, int mode)
1146/* ---------------------------------------------------------------------- */ 1160/* ---------------------------------------------------------------------- */
1147/* audio chip descriptions - defines+functions for TA8874Z */ 1161/* audio chip descriptions - defines+functions for TA8874Z */
1148 1162
1149// write 1st byte 1163/* write 1st byte */
1150#define TA8874Z_LED_STE 0x80 1164#define TA8874Z_LED_STE 0x80
1151#define TA8874Z_LED_BIL 0x40 1165#define TA8874Z_LED_BIL 0x40
1152#define TA8874Z_LED_EXT 0x20 1166#define TA8874Z_LED_EXT 0x20
@@ -1156,21 +1170,22 @@ static void tda8425_setmode(struct CHIPSTATE *chip, int mode)
1156#define TA8874Z_MODE_SUB 0x02 1170#define TA8874Z_MODE_SUB 0x02
1157#define TA8874Z_MODE_MAIN 0x01 1171#define TA8874Z_MODE_MAIN 0x01
1158 1172
1159// write 2nd byte 1173/* write 2nd byte */
1160//#define TA8874Z_TI 0x80 // test mode 1174/*#define TA8874Z_TI 0x80 */ /* test mode */
1161#define TA8874Z_SEPARATION 0x3f 1175#define TA8874Z_SEPARATION 0x3f
1162#define TA8874Z_SEPARATION_DEFAULT 0x10 1176#define TA8874Z_SEPARATION_DEFAULT 0x10
1163 1177
1164// read 1178/* read */
1165#define TA8874Z_B1 0x80 1179#define TA8874Z_B1 0x80
1166#define TA8874Z_B0 0x40 1180#define TA8874Z_B0 0x40
1167#define TA8874Z_CHAG_FLAG 0x20 1181#define TA8874Z_CHAG_FLAG 0x20
1168 1182
1169// B1 B0 1183/*
1170// mono L H 1184 * B1 B0
1171// stereo L L 1185 * mono L H
1172// BIL H L 1186 * stereo L L
1173 1187 * BIL H L
1188 */
1174static int ta8874z_getmode(struct CHIPSTATE *chip) 1189static int ta8874z_getmode(struct CHIPSTATE *chip)
1175{ 1190{
1176 int val, mode; 1191 int val, mode;
@@ -1182,7 +1197,7 @@ static int ta8874z_getmode(struct CHIPSTATE *chip)
1182 }else if (!(val & TA8874Z_B0)){ 1197 }else if (!(val & TA8874Z_B0)){
1183 mode |= VIDEO_SOUND_STEREO; 1198 mode |= VIDEO_SOUND_STEREO;
1184 } 1199 }
1185 //dprintk ("ta8874z_getmode(): raw chip read: 0x%02x, return: 0x%02x\n", val, mode); 1200 /* tvaudio_dbg ("ta8874z_getmode(): raw chip read: 0x%02x, return: 0x%02x\n", val, mode); */
1186 return mode; 1201 return mode;
1187} 1202}
1188 1203
@@ -1195,7 +1210,7 @@ static void ta8874z_setmode(struct CHIPSTATE *chip, int mode)
1195{ 1210{
1196 int update = 1; 1211 int update = 1;
1197 audiocmd *t = NULL; 1212 audiocmd *t = NULL;
1198 dprintk("ta8874z_setmode(): mode: 0x%02x\n", mode); 1213 tvaudio_dbg("ta8874z_setmode(): mode: 0x%02x\n", mode);
1199 1214
1200 switch(mode){ 1215 switch(mode){
1201 case VIDEO_SOUND_MONO: 1216 case VIDEO_SOUND_MONO:
@@ -1235,11 +1250,11 @@ static int tda9850 = 1;
1235static int tda9855 = 1; 1250static int tda9855 = 1;
1236static int tda9873 = 1; 1251static int tda9873 = 1;
1237static int tda9874a = 1; 1252static int tda9874a = 1;
1238static int tea6300 = 0; // address clash with msp34xx 1253static int tea6300 = 0; /* address clash with msp34xx */
1239static int tea6320 = 0; // address clash with msp34xx 1254static int tea6320 = 0; /* address clash with msp34xx */
1240static int tea6420 = 1; 1255static int tea6420 = 1;
1241static int pic16c54 = 1; 1256static int pic16c54 = 1;
1242static int ta8874z = 0; // address clash with tda9840 1257static int ta8874z = 0; /* address clash with tda9840 */
1243 1258
1244module_param(tda8425, int, 0444); 1259module_param(tda8425, int, 0444);
1245module_param(tda9840, int, 0444); 1260module_param(tda9840, int, 0444);
@@ -1441,7 +1456,7 @@ static struct CHIPDESC chiplist[] = {
1441 { 1456 {
1442 .name = "ta8874z", 1457 .name = "ta8874z",
1443 .id = -1, 1458 .id = -1,
1444 //.id = I2C_DRIVERID_TA8874Z, 1459 /*.id = I2C_DRIVERID_TA8874Z, */
1445 .checkit = ta8874z_checkit, 1460 .checkit = ta8874z_checkit,
1446 .insmodopt = &ta8874z, 1461 .insmodopt = &ta8874z,
1447 .addr_lo = I2C_TDA9840 >> 1, 1462 .addr_lo = I2C_TDA9840 >> 1,
@@ -1476,7 +1491,7 @@ static int chip_attach(struct i2c_adapter *adap, int addr, int kind)
1476 i2c_set_clientdata(&chip->c, chip); 1491 i2c_set_clientdata(&chip->c, chip);
1477 1492
1478 /* find description for the chip */ 1493 /* find description for the chip */
1479 dprintk("tvaudio: chip found @ i2c-addr=0x%x\n", addr<<1); 1494 tvaudio_dbg("chip found @ 0x%x\n", addr<<1);
1480 for (desc = chiplist; desc->name != NULL; desc++) { 1495 for (desc = chiplist; desc->name != NULL; desc++) {
1481 if (0 == *(desc->insmodopt)) 1496 if (0 == *(desc->insmodopt))
1482 continue; 1497 continue;
@@ -1488,17 +1503,19 @@ static int chip_attach(struct i2c_adapter *adap, int addr, int kind)
1488 break; 1503 break;
1489 } 1504 }
1490 if (desc->name == NULL) { 1505 if (desc->name == NULL) {
1491 dprintk("tvaudio: no matching chip description found\n"); 1506 tvaudio_dbg("no matching chip description found\n");
1492 return -EIO; 1507 return -EIO;
1493 } 1508 }
1494 printk("tvaudio: found %s @ 0x%x\n", desc->name, addr<<1); 1509 tvaudio_info("%s found @ 0x%x (%s)\n", desc->name, addr<<1, adap->name);
1495 dprintk("tvaudio: matches:%s%s%s.\n", 1510 if (desc->flags) {
1496 (desc->flags & CHIP_HAS_VOLUME) ? " volume" : "", 1511 tvaudio_dbg("matches:%s%s%s.\n",
1497 (desc->flags & CHIP_HAS_BASSTREBLE) ? " bass/treble" : "", 1512 (desc->flags & CHIP_HAS_VOLUME) ? " volume" : "",
1498 (desc->flags & CHIP_HAS_INPUTSEL) ? " audiomux" : ""); 1513 (desc->flags & CHIP_HAS_BASSTREBLE) ? " bass/treble" : "",
1514 (desc->flags & CHIP_HAS_INPUTSEL) ? " audiomux" : "");
1515 }
1499 1516
1500 /* fill required data structures */ 1517 /* fill required data structures */
1501 strcpy(chip->c.name, desc->name); 1518 strcpy(chip->c.name,desc->name);
1502 chip->type = desc-chiplist; 1519 chip->type = desc-chiplist;
1503 chip->shadow.count = desc->registers+1; 1520 chip->shadow.count = desc->registers+1;
1504 chip->prevmode = -1; 1521 chip->prevmode = -1;
@@ -1534,7 +1551,7 @@ static int chip_attach(struct i2c_adapter *adap, int addr, int kind)
1534 init_completion(&chip->texit); 1551 init_completion(&chip->texit);
1535 chip->tpid = kernel_thread(chip_thread,(void *)chip,0); 1552 chip->tpid = kernel_thread(chip_thread,(void *)chip,0);
1536 if (chip->tpid < 0) 1553 if (chip->tpid < 0)
1537 printk(KERN_WARNING "%s: kernel_thread() failed\n", 1554 tvaudio_warn("%s: kernel_thread() failed\n",
1538 chip->c.name); 1555 chip->c.name);
1539 wake_up_interruptible(&chip->wq); 1556 wake_up_interruptible(&chip->wq);
1540 } 1557 }
@@ -1545,7 +1562,7 @@ static int chip_probe(struct i2c_adapter *adap)
1545{ 1562{
1546 /* don't attach on saa7146 based cards, 1563 /* don't attach on saa7146 based cards,
1547 because dedicated drivers are used */ 1564 because dedicated drivers are used */
1548 if (adap->id == I2C_HW_SAA7146) 1565 if ((adap->id == I2C_HW_SAA7146))
1549 return 0; 1566 return 0;
1550#ifdef I2C_CLASS_TV_ANALOG 1567#ifdef I2C_CLASS_TV_ANALOG
1551 if (adap->class & I2C_CLASS_TV_ANALOG) 1568 if (adap->class & I2C_CLASS_TV_ANALOG)
@@ -1584,11 +1601,11 @@ static int chip_detach(struct i2c_client *client)
1584static int chip_command(struct i2c_client *client, 1601static int chip_command(struct i2c_client *client,
1585 unsigned int cmd, void *arg) 1602 unsigned int cmd, void *arg)
1586{ 1603{
1587 __u16 *sarg = arg; 1604 __u16 *sarg = arg;
1588 struct CHIPSTATE *chip = i2c_get_clientdata(client); 1605 struct CHIPSTATE *chip = i2c_get_clientdata(client);
1589 struct CHIPDESC *desc = chiplist + chip->type; 1606 struct CHIPDESC *desc = chiplist + chip->type;
1590 1607
1591 dprintk("%s: chip_command 0x%x\n", chip->c.name, cmd); 1608 tvaudio_dbg("%s: chip_command 0x%x\n",chip->c.name,cmd);
1592 1609
1593 switch (cmd) { 1610 switch (cmd) {
1594 case AUDC_SET_INPUT: 1611 case AUDC_SET_INPUT:
@@ -1601,7 +1618,6 @@ static int chip_command(struct i2c_client *client,
1601 break; 1618 break;
1602 1619
1603 case AUDC_SET_RADIO: 1620 case AUDC_SET_RADIO:
1604 dprintk(KERN_DEBUG "tvaudio: AUDC_SET_RADIO\n");
1605 chip->norm = VIDEO_MODE_RADIO; 1621 chip->norm = VIDEO_MODE_RADIO;
1606 chip->watch_stereo = 0; 1622 chip->watch_stereo = 0;
1607 /* del_timer(&chip->wt); */ 1623 /* del_timer(&chip->wt); */
@@ -1609,7 +1625,7 @@ static int chip_command(struct i2c_client *client,
1609 1625
1610 /* --- v4l ioctls --- */ 1626 /* --- v4l ioctls --- */
1611 /* take care: bttv does userspace copying, we'll get a 1627 /* take care: bttv does userspace copying, we'll get a
1612 kernel pointer here... */ 1628 kernel pointer here... */
1613 case VIDIOCGAUDIO: 1629 case VIDIOCGAUDIO:
1614 { 1630 {
1615 struct video_audio *va = arg; 1631 struct video_audio *va = arg;
@@ -1643,9 +1659,9 @@ static int chip_command(struct i2c_client *client,
1643 1659
1644 if (desc->flags & CHIP_HAS_VOLUME) { 1660 if (desc->flags & CHIP_HAS_VOLUME) {
1645 chip->left = (min(65536 - va->balance,32768) * 1661 chip->left = (min(65536 - va->balance,32768) *
1646 va->volume) / 32768; 1662 va->volume) / 32768;
1647 chip->right = (min(va->balance,(__u16)32768) * 1663 chip->right = (min(va->balance,(__u16)32768) *
1648 va->volume) / 32768; 1664 va->volume) / 32768;
1649 chip_write(chip,desc->leftreg,desc->volfunc(chip->left)); 1665 chip_write(chip,desc->leftreg,desc->volfunc(chip->left));
1650 chip_write(chip,desc->rightreg,desc->volfunc(chip->right)); 1666 chip_write(chip,desc->rightreg,desc->volfunc(chip->right));
1651 } 1667 }
@@ -1667,17 +1683,16 @@ static int chip_command(struct i2c_client *client,
1667 { 1683 {
1668 struct video_channel *vc = arg; 1684 struct video_channel *vc = arg;
1669 1685
1670 dprintk(KERN_DEBUG "tvaudio: VIDIOCSCHAN\n");
1671 chip->norm = vc->norm; 1686 chip->norm = vc->norm;
1672 break; 1687 break;
1673 } 1688 }
1674 case VIDIOCSFREQ: 1689 case VIDIOCSFREQ:
1675 { 1690 {
1676 chip->mode = 0; /* automatic */ 1691 chip->mode = 0; /* automatic */
1677 if (desc->checkmode) { 1692 if (desc->checkmode) {
1678 desc->setmode(chip,VIDEO_SOUND_MONO); 1693 desc->setmode(chip,VIDEO_SOUND_MONO);
1679 if (chip->prevmode != VIDEO_SOUND_MONO) 1694 if (chip->prevmode != VIDEO_SOUND_MONO)
1680 chip->prevmode = -1; /* reset previous mode */ 1695 chip->prevmode = -1; /* reset previous mode */
1681 mod_timer(&chip->wt, jiffies+2*HZ); 1696 mod_timer(&chip->wt, jiffies+2*HZ);
1682 /* the thread will call checkmode() later */ 1697 /* the thread will call checkmode() later */
1683 } 1698 }
@@ -1689,29 +1704,32 @@ static int chip_command(struct i2c_client *client,
1689 1704
1690static struct i2c_driver driver = { 1705static struct i2c_driver driver = {
1691 .owner = THIS_MODULE, 1706 .owner = THIS_MODULE,
1692 .name = "generic i2c audio driver", 1707 .name = "generic i2c audio driver",
1693 .id = I2C_DRIVERID_TVAUDIO, 1708 .id = I2C_DRIVERID_TVAUDIO,
1694 .flags = I2C_DF_NOTIFY, 1709 .flags = I2C_DF_NOTIFY,
1695 .attach_adapter = chip_probe, 1710 .attach_adapter = chip_probe,
1696 .detach_client = chip_detach, 1711 .detach_client = chip_detach,
1697 .command = chip_command, 1712 .command = chip_command,
1698}; 1713};
1699 1714
1700static struct i2c_client client_template = 1715static struct i2c_client client_template =
1701{ 1716{
1702 .name = "(unset)", 1717 .name = "(unset)",
1703 .flags = I2C_CLIENT_ALLOW_USE, 1718 .flags = I2C_CLIENT_ALLOW_USE,
1704 .driver = &driver, 1719 .driver = &driver,
1705}; 1720};
1706 1721
1707static int __init audiochip_init_module(void) 1722static int __init audiochip_init_module(void)
1708{ 1723{
1709 struct CHIPDESC *desc; 1724 struct CHIPDESC *desc;
1710 printk(KERN_INFO "tvaudio: TV audio decoder + audio/video mux driver\n"); 1725
1711 printk(KERN_INFO "tvaudio: known chips: "); 1726 if (debug) {
1712 for (desc = chiplist; desc->name != NULL; desc++) 1727 printk(KERN_INFO "tvaudio: TV audio decoder + audio/video mux driver\n");
1713 printk("%s%s", (desc == chiplist) ? "" : ",",desc->name); 1728 printk(KERN_INFO "tvaudio: known chips: ");
1714 printk("\n"); 1729 for (desc = chiplist; desc->name != NULL; desc++)
1730 printk("%s%s", (desc == chiplist) ? "" : ", ", desc->name);
1731 printk("\n");
1732 }
1715 1733
1716 return i2c_add_driver(&driver); 1734 return i2c_add_driver(&driver);
1717} 1735}
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index 3c3356a01c..5344d55921 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -47,18 +47,21 @@ MODULE_LICENSE("GPL");
47 47
48static int debug = 0; 48static int debug = 0;
49module_param(debug, int, 0644); 49module_param(debug, int, 0644);
50MODULE_PARM_DESC(debug, "Debug level (0-2)"); 50MODULE_PARM_DESC(debug, "Debug level (0-1)");
51 51
52#define STRM(array,i) (i < sizeof(array)/sizeof(char*) ? array[i] : "unknown") 52#define STRM(array,i) (i < sizeof(array)/sizeof(char*) ? array[i] : "unknown")
53 53
54#define dprintk(num, args...) \ 54#define tveeprom_info(fmt, arg...) do {\
55 do { \ 55 printk(KERN_INFO "tveeprom %d-%04x: " fmt, \
56 if (debug >= num) \ 56 c->adapter->nr, c->addr , ##arg); } while (0)
57 printk(KERN_INFO "tveeprom: " args); \ 57#define tveeprom_warn(fmt, arg...) do {\
58 } while (0) 58 printk(KERN_WARNING "tveeprom %d-%04x: " fmt, \
59 c->adapter->nr, c->addr , ##arg); } while (0)
60#define tveeprom_dbg(fmt, arg...) do {\
61 if (debug) \
62 printk(KERN_INFO "tveeprom %d-%04x: " fmt, \
63 c->adapter->nr, c->addr , ##arg); } while (0)
59 64
60#define TVEEPROM_KERN_ERR(args...) printk(KERN_ERR "tveeprom: " args);
61#define TVEEPROM_KERN_INFO(args...) printk(KERN_INFO "tveeprom: " args);
62 65
63/* ----------------------------------------------------------------------- */ 66/* ----------------------------------------------------------------------- */
64/* some hauppauge specific stuff */ 67/* some hauppauge specific stuff */
@@ -70,14 +73,14 @@ static struct HAUPPAUGE_TUNER_FMT
70} 73}
71hauppauge_tuner_fmt[] = 74hauppauge_tuner_fmt[] =
72{ 75{
73 { 0x00000000, "unknown1" }, 76 { 0x00000000, " unknown1" },
74 { 0x00000000, "unknown2" }, 77 { 0x00000000, " unknown2" },
75 { 0x00000007, "PAL(B/G)" }, 78 { 0x00000007, " PAL(B/G)" },
76 { 0x00001000, "NTSC(M)" }, 79 { 0x00001000, " NTSC(M)" },
77 { 0x00000010, "PAL(I)" }, 80 { 0x00000010, " PAL(I)" },
78 { 0x00400000, "SECAM(L/L´)" }, 81 { 0x00400000, " SECAM(L/L')" },
79 { 0x00000e00, "PAL(D/K)" }, 82 { 0x00000e00, " PAL(D/K)" },
80 { 0x03000000, "ATSC Digital" }, 83 { 0x03000000, " ATSC Digital" },
81}; 84};
82 85
83/* This is the full list of possible tuners. Many thanks to Hauppauge for 86/* This is the full list of possible tuners. Many thanks to Hauppauge for
@@ -152,13 +155,13 @@ hauppauge_tuner[] =
152 { TUNER_MICROTUNE_4049FM5, "Microtune 4049 FM5"}, 155 { TUNER_MICROTUNE_4049FM5, "Microtune 4049 FM5"},
153 { TUNER_ABSENT, "LG TPI8NSR11F"}, 156 { TUNER_ABSENT, "LG TPI8NSR11F"},
154 { TUNER_ABSENT, "Microtune 4049 FM5 Alt I2C"}, 157 { TUNER_ABSENT, "Microtune 4049 FM5 Alt I2C"},
155 { TUNER_ABSENT, "Philips FQ1216ME MK3"}, 158 { TUNER_PHILIPS_FM1216ME_MK3, "Philips FQ1216ME MK3"},
156 { TUNER_ABSENT, "Philips FI1236 MK3"}, 159 { TUNER_ABSENT, "Philips FI1236 MK3"},
157 { TUNER_PHILIPS_FM1216ME_MK3, "Philips FM1216 ME MK3"}, 160 { TUNER_PHILIPS_FM1216ME_MK3, "Philips FM1216 ME MK3"},
158 { TUNER_ABSENT, "Philips FM1236 MK3"}, 161 { TUNER_PHILIPS_FM1236_MK3, "Philips FM1236 MK3"},
159 { TUNER_ABSENT, "Philips FM1216MP MK3"}, 162 { TUNER_ABSENT, "Philips FM1216MP MK3"},
160 /* 60-69 */ 163 /* 60-69 */
161 { TUNER_ABSENT, "LG S001D MK3"}, 164 { TUNER_PHILIPS_FM1216ME_MK3, "LG S001D MK3"},
162 { TUNER_ABSENT, "LG M001D MK3"}, 165 { TUNER_ABSENT, "LG M001D MK3"},
163 { TUNER_ABSENT, "LG S701D MK3"}, 166 { TUNER_ABSENT, "LG S701D MK3"},
164 { TUNER_ABSENT, "LG M701D MK3"}, 167 { TUNER_ABSENT, "LG M701D MK3"},
@@ -167,7 +170,7 @@ hauppauge_tuner[] =
167 { TUNER_ABSENT, "Temic 4106FH5"}, 170 { TUNER_ABSENT, "Temic 4106FH5"},
168 { TUNER_ABSENT, "Philips FQ1216LMP MK3"}, 171 { TUNER_ABSENT, "Philips FQ1216LMP MK3"},
169 { TUNER_LG_NTSC_TAPE, "LG TAPE H001F MK3"}, 172 { TUNER_LG_NTSC_TAPE, "LG TAPE H001F MK3"},
170 { TUNER_ABSENT, "LG TAPE H701F MK3"}, 173 { TUNER_LG_NTSC_TAPE, "LG TAPE H701F MK3"},
171 /* 70-79 */ 174 /* 70-79 */
172 { TUNER_ABSENT, "LG TALN H200T"}, 175 { TUNER_ABSENT, "LG TALN H200T"},
173 { TUNER_ABSENT, "LG TALN H250T"}, 176 { TUNER_ABSENT, "LG TALN H250T"},
@@ -183,8 +186,8 @@ hauppauge_tuner[] =
183 { TUNER_ABSENT, "Philips FQ1216LME MK3"}, 186 { TUNER_ABSENT, "Philips FQ1216LME MK3"},
184 { TUNER_ABSENT, "LG TAPC G701D"}, 187 { TUNER_ABSENT, "LG TAPC G701D"},
185 { TUNER_LG_NTSC_NEW_TAPC, "LG TAPC H791F"}, 188 { TUNER_LG_NTSC_NEW_TAPC, "LG TAPC H791F"},
186 { TUNER_ABSENT, "TCL 2002MB 3"}, 189 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MB 3"},
187 { TUNER_ABSENT, "TCL 2002MI 3"}, 190 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MI 3"},
188 { TUNER_TCL_2002N, "TCL 2002N 6A"}, 191 { TUNER_TCL_2002N, "TCL 2002N 6A"},
189 { TUNER_ABSENT, "Philips FQ1236 MK3"}, 192 { TUNER_ABSENT, "Philips FQ1236 MK3"},
190 { TUNER_ABSENT, "Samsung TCPN 2121P30A"}, 193 { TUNER_ABSENT, "Samsung TCPN 2121P30A"},
@@ -199,17 +202,51 @@ hauppauge_tuner[] =
199 { TUNER_ABSENT, "Philips FQ1236 MK5"}, 202 { TUNER_ABSENT, "Philips FQ1236 MK5"},
200 { TUNER_ABSENT, "Unspecified"}, 203 { TUNER_ABSENT, "Unspecified"},
201 { TUNER_LG_PAL_TAPE, "LG PAL (TAPE Series)"}, 204 { TUNER_LG_PAL_TAPE, "LG PAL (TAPE Series)"},
205 { TUNER_ABSENT, "Unspecified"},
206 { TUNER_TCL_2002N, "TCL 2002N 5H"},
207 /* 100-103 */
208 { TUNER_ABSENT, "Unspecified"},
209 { TUNER_TEA5767, "Philips TEA5767HN FM Radio"},
210 { TUNER_ABSENT, "Unspecified"},
211 { TUNER_PHILIPS_FM1236_MK3, "TCL MFNM05 4"},
202}; 212};
203 213
204static char *sndtype[] = { 214/* This list is supplied by Hauppauge. Thanks! */
205 "None", "TEA6300", "TEA6320", "TDA9850", "MSP3400C", "MSP3410D", 215static const char *audioIC[] = {
206 "MSP3415", "MSP3430", "MSP3438", "CS5331", "MSP3435", "MSP3440", 216 /* 0-4 */
207 "MSP3445", "MSP3411", "MSP3416", "MSP3425", 217 "None", "TEA6300", "TEA6320", "TDA9850", "MSP3400C",
218 /* 5-9 */
219 "MSP3410D", "MSP3415", "MSP3430", "MSP3438", "CS5331",
220 /* 10-14 */
221 "MSP3435", "MSP3440", "MSP3445", "MSP3411", "MSP3416",
222 /* 15-19 */
223 "MSP3425", "MSP3451", "MSP3418", "Type 0x12", "OKI7716",
224 /* 20-24 */
225 "MSP4410", "MSP4420", "MSP4440", "MSP4450", "MSP4408",
226 /* 25-29 */
227 "MSP4418", "MSP4428", "MSP4448", "MSP4458", "Type 0x1d",
228 /* 30-34 */
229 "CX880", "CX881", "CX883", "CX882", "CX25840",
230 /* 35-38 */
231 "CX25841", "CX25842", "CX25843", "CX23418",
232};
208 233
209 "Type 0x10","Type 0x11","Type 0x12","Type 0x13", 234/* This list is supplied by Hauppauge. Thanks! */
210 "Type 0x14","Type 0x15","Type 0x16","Type 0x17", 235static const char *decoderIC[] = {
211 "Type 0x18","MSP4418","Type 0x1a","MSP4448", 236 /* 0-4 */
212 "Type 0x1c","Type 0x1d","Type 0x1e","Type 0x1f", 237 "None", "BT815", "BT817", "BT819", "BT815A",
238 /* 5-9 */
239 "BT817A", "BT819A", "BT827", "BT829", "BT848",
240 /* 10-14 */
241 "BT848A", "BT849A", "BT829A", "BT827A", "BT878",
242 /* 15-19 */
243 "BT879", "BT880", "VPX3226E", "SAA7114", "SAA7115",
244 /* 20-24 */
245 "CX880", "CX881", "CX883", "SAA7111", "SAA7113",
246 /* 25-29 */
247 "CX882", "TVP5150A", "CX25840", "CX25841", "CX25842",
248 /* 30-31 */
249 "CX25843", "CX23418",
213}; 250};
214 251
215static int hasRadioTuner(int tunerType) 252static int hasRadioTuner(int tunerType)
@@ -250,7 +287,8 @@ static int hasRadioTuner(int tunerType)
250 return 0; 287 return 0;
251} 288}
252 289
253void tveeprom_hauppauge_analog(struct tveeprom *tvee, unsigned char *eeprom_data) 290void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
291 unsigned char *eeprom_data)
254{ 292{
255 /* ---------------------------------------------- 293 /* ----------------------------------------------
256 ** The hauppauge eeprom format is tagged 294 ** The hauppauge eeprom format is tagged
@@ -260,10 +298,11 @@ void tveeprom_hauppauge_analog(struct tveeprom *tvee, unsigned char *eeprom_data
260 ** if packet[0] & f8 == f8, then EOD and packet[1] == checksum 298 ** if packet[0] & f8 == f8, then EOD and packet[1] == checksum
261 ** 299 **
262 ** In our (ivtv) case we're interested in the following: 300 ** In our (ivtv) case we're interested in the following:
263 ** tuner type: tag [00].05 or [0a].01 (index into hauppauge_tuner) 301 ** tuner type: tag [00].05 or [0a].01 (index into hauppauge_tuner)
264 ** tuner fmts: tag [00].04 or [0a].00 (bitmask index into hauppauge_tuner_fmt) 302 ** tuner fmts: tag [00].04 or [0a].00 (bitmask index into hauppauge_tuner_fmt)
265 ** radio: tag [00].{last} or [0e].00 (bitmask. bit2=FM) 303 ** radio: tag [00].{last} or [0e].00 (bitmask. bit2=FM)
266 ** audio proc: tag [02].01 or [05].00 (lower nibble indexes lut?) 304 ** audio proc: tag [02].01 or [05].00 (mask with 0x7f)
305 ** decoder proc: tag [09].01)
267 306
268 ** Fun info: 307 ** Fun info:
269 ** model: tag [00].07-08 or [06].00-01 308 ** model: tag [00].07-08 or [06].00-01
@@ -273,20 +312,24 @@ void tveeprom_hauppauge_analog(struct tveeprom *tvee, unsigned char *eeprom_data
273 ** # of inputs/outputs ??? 312 ** # of inputs/outputs ???
274 */ 313 */
275 314
276 int i, j, len, done, beenhere, tag, tuner = 0, t_format = 0; 315 int i, j, len, done, beenhere, tag;
277 char *t_name = NULL, *t_fmt_name = NULL;
278 316
279 dprintk(1, "%s\n",__FUNCTION__); 317 int tuner1 = 0, t_format1 = 0;
280 tvee->revision = done = len = beenhere = 0; 318 char *t_name1 = NULL;
281 for (i = 0; !done && i < 256; i += len) { 319 const char *t_fmt_name1[8] = { " none", "", "", "", "", "", "", "" };
282 dprintk(2, "processing pos = %02x (%02x, %02x)\n",
283 i, eeprom_data[i], eeprom_data[i + 1]);
284 320
321 int tuner2 = 0, t_format2 = 0;
322 char *t_name2 = NULL;
323 const char *t_fmt_name2[8] = { " none", "", "", "", "", "", "", "" };
324
325 memset(tvee, 0, sizeof(*tvee));
326 done = len = beenhere = 0;
327 for (i = 0; !done && i < 256; i += len) {
285 if (eeprom_data[i] == 0x84) { 328 if (eeprom_data[i] == 0x84) {
286 len = eeprom_data[i + 1] + (eeprom_data[i + 2] << 8); 329 len = eeprom_data[i + 1] + (eeprom_data[i + 2] << 8);
287 i+=3; 330 i += 3;
288 } else if ((eeprom_data[i] & 0xf0) == 0x70) { 331 } else if ((eeprom_data[i] & 0xf0) == 0x70) {
289 if ((eeprom_data[i] & 0x08)) { 332 if (eeprom_data[i] & 0x08) {
290 /* verify checksum! */ 333 /* verify checksum! */
291 done = 1; 334 done = 1;
292 break; 335 break;
@@ -294,24 +337,30 @@ void tveeprom_hauppauge_analog(struct tveeprom *tvee, unsigned char *eeprom_data
294 len = eeprom_data[i] & 0x07; 337 len = eeprom_data[i] & 0x07;
295 ++i; 338 ++i;
296 } else { 339 } else {
297 TVEEPROM_KERN_ERR("Encountered bad packet header [%02x]. " 340 tveeprom_warn("Encountered bad packet header [%02x]. "
298 "Corrupt or not a Hauppauge eeprom.\n", eeprom_data[i]); 341 "Corrupt or not a Hauppauge eeprom.\n", eeprom_data[i]);
299 return; 342 return;
300 } 343 }
301 344
302 dprintk(1, "%3d [%02x] ", len, eeprom_data[i]); 345 if (debug) {
303 for(j = 1; j < len; j++) { 346 tveeprom_info("Tag [%02x] + %d bytes:", eeprom_data[i], len - 1);
304 dprintk(1, "%02x ", eeprom_data[i + j]); 347 for(j = 1; j < len; j++) {
305 } 348 printk(" %02x", eeprom_data[i + j]);
306 dprintk(1, "\n"); 349 }
350 printk("\n");
351 }
307 352
308 /* process by tag */ 353 /* process by tag */
309 tag = eeprom_data[i]; 354 tag = eeprom_data[i];
310 switch (tag) { 355 switch (tag) {
311 case 0x00: 356 case 0x00:
312 tuner = eeprom_data[i+6]; 357 /* tag: 'Comprehensive' */
313 t_format = eeprom_data[i+5]; 358 tuner1 = eeprom_data[i+6];
359 t_format1 = eeprom_data[i+5];
314 tvee->has_radio = eeprom_data[i+len-1]; 360 tvee->has_radio = eeprom_data[i+len-1];
361 /* old style tag, don't know how to detect
362 IR presence, mark as unknown. */
363 tvee->has_ir = 2;
315 tvee->model = 364 tvee->model =
316 eeprom_data[i+8] + 365 eeprom_data[i+8] +
317 (eeprom_data[i+9] << 8); 366 (eeprom_data[i+9] << 8);
@@ -319,25 +368,43 @@ void tveeprom_hauppauge_analog(struct tveeprom *tvee, unsigned char *eeprom_data
319 (eeprom_data[i+11] << 8) + 368 (eeprom_data[i+11] << 8) +
320 (eeprom_data[i+12] << 16); 369 (eeprom_data[i+12] << 16);
321 break; 370 break;
371
322 case 0x01: 372 case 0x01:
373 /* tag: 'SerialID' */
323 tvee->serial_number = 374 tvee->serial_number =
324 eeprom_data[i+6] + 375 eeprom_data[i+6] +
325 (eeprom_data[i+7] << 8) + 376 (eeprom_data[i+7] << 8) +
326 (eeprom_data[i+8] << 16); 377 (eeprom_data[i+8] << 16);
327 break; 378 break;
379
328 case 0x02: 380 case 0x02:
329 tvee->audio_processor = eeprom_data[i+2] & 0x0f; 381 /* tag 'AudioInfo'
382 Note mask with 0x7F, high bit used on some older models
383 to indicate 4052 mux was removed in favor of using MSP
384 inputs directly. */
385 tvee->audio_processor = eeprom_data[i+2] & 0x7f;
330 break; 386 break;
387
388 /* case 0x03: tag 'EEInfo' */
389
331 case 0x04: 390 case 0x04:
391 /* tag 'SerialID2' */
332 tvee->serial_number = 392 tvee->serial_number =
333 eeprom_data[i+5] + 393 eeprom_data[i+5] +
334 (eeprom_data[i+6] << 8) + 394 (eeprom_data[i+6] << 8) +
335 (eeprom_data[i+7] << 16); 395 (eeprom_data[i+7] << 16);
336 break; 396 break;
397
337 case 0x05: 398 case 0x05:
338 tvee->audio_processor = eeprom_data[i+1] & 0x0f; 399 /* tag 'Audio2'
400 Note mask with 0x7F, high bit used on some older models
401 to indicate 4052 mux was removed in favor of using MSP
402 inputs directly. */
403 tvee->audio_processor = eeprom_data[i+1] & 0x7f;
339 break; 404 break;
405
340 case 0x06: 406 case 0x06:
407 /* tag 'ModelRev' */
341 tvee->model = 408 tvee->model =
342 eeprom_data[i+1] + 409 eeprom_data[i+1] +
343 (eeprom_data[i+2] << 8); 410 (eeprom_data[i+2] << 8);
@@ -345,27 +412,66 @@ void tveeprom_hauppauge_analog(struct tveeprom *tvee, unsigned char *eeprom_data
345 (eeprom_data[i+6] << 8) + 412 (eeprom_data[i+6] << 8) +
346 (eeprom_data[i+7] << 16); 413 (eeprom_data[i+7] << 16);
347 break; 414 break;
415
416 case 0x07:
417 /* tag 'Details': according to Hauppauge not interesting
418 on any PCI-era or later boards. */
419 break;
420
421 /* there is no tag 0x08 defined */
422
423 case 0x09:
424 /* tag 'Video' */
425 tvee->decoder_processor = eeprom_data[i + 1];
426 break;
427
348 case 0x0a: 428 case 0x0a:
349 if(beenhere == 0) { 429 /* tag 'Tuner' */
350 tuner = eeprom_data[i+2]; 430 if (beenhere == 0) {
351 t_format = eeprom_data[i+1]; 431 tuner1 = eeprom_data[i+2];
432 t_format1 = eeprom_data[i+1];
352 beenhere = 1; 433 beenhere = 1;
353 break;
354 } else { 434 } else {
355 break; 435 /* a second (radio) tuner may be present */
356 } 436 tuner2 = eeprom_data[i+2];
437 t_format2 = eeprom_data[i+1];
438 if (t_format2 == 0) { /* not a TV tuner? */
439 tvee->has_radio = 1; /* must be radio */
440 }
441 }
442 break;
443
444 case 0x0b:
445 /* tag 'Inputs': according to Hauppauge this is specific
446 to each driver family, so no good assumptions can be
447 made. */
448 break;
449
450 /* case 0x0c: tag 'Balun' */
451 /* case 0x0d: tag 'Teletext' */
452
357 case 0x0e: 453 case 0x0e:
454 /* tag: 'Radio' */
358 tvee->has_radio = eeprom_data[i+1]; 455 tvee->has_radio = eeprom_data[i+1];
359 break; 456 break;
457
458 case 0x0f:
459 /* tag 'IRInfo' */
460 tvee->has_ir = eeprom_data[i+1];
461 break;
462
463 /* case 0x10: tag 'VBIInfo' */
464 /* case 0x11: tag 'QCInfo' */
465 /* case 0x12: tag 'InfoBits' */
466
360 default: 467 default:
361 dprintk(1, "Not sure what to do with tag [%02x]\n", tag); 468 tveeprom_dbg("Not sure what to do with tag [%02x]\n", tag);
362 /* dump the rest of the packet? */ 469 /* dump the rest of the packet? */
363 } 470 }
364
365 } 471 }
366 472
367 if (!done) { 473 if (!done) {
368 TVEEPROM_KERN_ERR("Ran out of data!\n"); 474 tveeprom_warn("Ran out of data!\n");
369 return; 475 return;
370 } 476 }
371 477
@@ -377,47 +483,72 @@ void tveeprom_hauppauge_analog(struct tveeprom *tvee, unsigned char *eeprom_data
377 tvee->rev_str[4] = 0; 483 tvee->rev_str[4] = 0;
378 } 484 }
379 485
380 if (hasRadioTuner(tuner) && !tvee->has_radio) { 486 if (hasRadioTuner(tuner1) && !tvee->has_radio) {
381 TVEEPROM_KERN_INFO("The eeprom says no radio is present, but the tuner type\n"); 487 tveeprom_info("The eeprom says no radio is present, but the tuner type\n");
382 TVEEPROM_KERN_INFO("indicates otherwise. I will assume that radio is present.\n"); 488 tveeprom_info("indicates otherwise. I will assume that radio is present.\n");
383 tvee->has_radio = 1; 489 tvee->has_radio = 1;
384 } 490 }
385 491
386 if (tuner < sizeof(hauppauge_tuner)/sizeof(struct HAUPPAUGE_TUNER)) { 492 if (tuner1 < sizeof(hauppauge_tuner)/sizeof(struct HAUPPAUGE_TUNER)) {
387 tvee->tuner_type = hauppauge_tuner[tuner].id; 493 tvee->tuner_type = hauppauge_tuner[tuner1].id;
388 t_name = hauppauge_tuner[tuner].name; 494 t_name1 = hauppauge_tuner[tuner1].name;
389 } else { 495 } else {
390 t_name = "<unknown>"; 496 t_name1 = "unknown";
497 }
498
499 if (tuner2 < sizeof(hauppauge_tuner)/sizeof(struct HAUPPAUGE_TUNER)) {
500 tvee->tuner2_type = hauppauge_tuner[tuner2].id;
501 t_name2 = hauppauge_tuner[tuner2].name;
502 } else {
503 t_name2 = "unknown";
391 } 504 }
392 505
393 tvee->tuner_formats = 0; 506 tvee->tuner_formats = 0;
394 t_fmt_name = "<none>"; 507 tvee->tuner2_formats = 0;
395 for (i = 0; i < 8; i++) { 508 for (i = j = 0; i < 8; i++) {
396 if (t_format & (1<<i)) { 509 if (t_format1 & (1 << i)) {
397 tvee->tuner_formats |= hauppauge_tuner_fmt[i].id; 510 tvee->tuner_formats |= hauppauge_tuner_fmt[i].id;
398 /* yuck */ 511 t_fmt_name1[j++] = hauppauge_tuner_fmt[i].name;
399 t_fmt_name = hauppauge_tuner_fmt[i].name;
400 } 512 }
513 if (t_format2 & (1 << i)) {
514 tvee->tuner2_formats |= hauppauge_tuner_fmt[i].id;
515 t_fmt_name2[j++] = hauppauge_tuner_fmt[i].name;
516 }
401 } 517 }
402 518
403 519 tveeprom_info("Hauppauge model %d, rev %s, serial# %d\n",
404 TVEEPROM_KERN_INFO("Hauppauge: model = %d, rev = %s, serial# = %d\n", 520 tvee->model, tvee->rev_str, tvee->serial_number);
405 tvee->model, 521 tveeprom_info("tuner model is %s (idx %d, type %d)\n",
406 tvee->rev_str, 522 t_name1, tuner1, tvee->tuner_type);
407 tvee->serial_number); 523 tveeprom_info("TV standards%s%s%s%s%s%s%s%s (eeprom 0x%02x)\n",
408 TVEEPROM_KERN_INFO("tuner = %s (idx = %d, type = %d)\n", 524 t_fmt_name1[0], t_fmt_name1[1], t_fmt_name1[2], t_fmt_name1[3],
409 t_name, 525 t_fmt_name1[4], t_fmt_name1[5], t_fmt_name1[6], t_fmt_name1[7],
410 tuner, 526 t_format1);
411 tvee->tuner_type); 527 if (tuner2) {
412 TVEEPROM_KERN_INFO("tuner fmt = %s (eeprom = 0x%02x, v4l2 = 0x%08x)\n", 528 tveeprom_info("second tuner model is %s (idx %d, type %d)\n",
413 t_fmt_name, 529 t_name2, tuner2, tvee->tuner2_type);
414 t_format, 530 }
415 tvee->tuner_formats); 531 if (t_format2) {
416 532 tveeprom_info("TV standards%s%s%s%s%s%s%s%s (eeprom 0x%02x)\n",
417 TVEEPROM_KERN_INFO("audio_processor = %s (type = %d)\n", 533 t_fmt_name2[0], t_fmt_name2[1], t_fmt_name2[2], t_fmt_name2[3],
418 STRM(sndtype,tvee->audio_processor), 534 t_fmt_name2[4], t_fmt_name2[5], t_fmt_name2[6], t_fmt_name2[7],
535 t_format2);
536 }
537 tveeprom_info("audio processor is %s (idx %d)\n",
538 STRM(audioIC, tvee->audio_processor),
419 tvee->audio_processor); 539 tvee->audio_processor);
420 540 if (tvee->decoder_processor) {
541 tveeprom_info("decoder processor is %s (idx %d)\n",
542 STRM(decoderIC, tvee->decoder_processor),
543 tvee->decoder_processor);
544 }
545 if (tvee->has_ir == 2)
546 tveeprom_info("has %sradio\n",
547 tvee->has_radio ? "" : "no ");
548 else
549 tveeprom_info("has %sradio, has %sIR remote\n",
550 tvee->has_radio ? "" : "no ",
551 tvee->has_ir ? "" : "no ");
421} 552}
422EXPORT_SYMBOL(tveeprom_hauppauge_analog); 553EXPORT_SYMBOL(tveeprom_hauppauge_analog);
423 554
@@ -429,40 +560,31 @@ int tveeprom_read(struct i2c_client *c, unsigned char *eedata, int len)
429 unsigned char buf; 560 unsigned char buf;
430 int err; 561 int err;
431 562
432 dprintk(1, "%s\n",__FUNCTION__);
433 buf = 0; 563 buf = 0;
434 if (1 != (err = i2c_master_send(c,&buf,1))) { 564 if (1 != (err = i2c_master_send(c, &buf, 1))) {
435 printk(KERN_INFO "tveeprom(%s): Huh, no eeprom present (err=%d)?\n", 565 tveeprom_info("Huh, no eeprom present (err=%d)?\n", err);
436 c->name,err);
437 return -1; 566 return -1;
438 } 567 }
439 if (len != (err = i2c_master_recv(c,eedata,len))) { 568 if (len != (err = i2c_master_recv(c, eedata, len))) {
440 printk(KERN_WARNING "tveeprom(%s): i2c eeprom read error (err=%d)\n", 569 tveeprom_warn("i2c eeprom read error (err=%d)\n", err);
441 c->name,err);
442 return -1; 570 return -1;
443 } 571 }
572 if (debug) {
573 int i;
574
575 tveeprom_info("full 256-byte eeprom dump:\n");
576 for (i = 0; i < len; i++) {
577 if (0 == (i % 16))
578 tveeprom_info("%02x:", i);
579 printk(" %02x", eedata[i]);
580 if (15 == (i % 16))
581 printk("\n");
582 }
583 }
444 return 0; 584 return 0;
445} 585}
446EXPORT_SYMBOL(tveeprom_read); 586EXPORT_SYMBOL(tveeprom_read);
447 587
448#if 0
449int tveeprom_dump(unsigned char *eedata, int len)
450{
451 int i;
452
453 dprintk(1, "%s\n",__FUNCTION__);
454 for (i = 0; i < len; i++) {
455 if (0 == (i % 16))
456 printk(KERN_INFO "tveeprom: %02x:",i);
457 printk(" %02x",eedata[i]);
458 if (15 == (i % 16))
459 printk("\n");
460 }
461 return 0;
462}
463EXPORT_SYMBOL(tveeprom_dump);
464#endif /* 0 */
465
466/* ----------------------------------------------------------------------- */ 588/* ----------------------------------------------------------------------- */
467/* needed for ivtv.sf.net at the moment. Should go away in the long */ 589/* needed for ivtv.sf.net at the moment. Should go away in the long */
468/* run, just call the exported tveeprom_* directly, there is no point in */ 590/* run, just call the exported tveeprom_* directly, there is no point in */
@@ -495,12 +617,13 @@ tveeprom_command(struct i2c_client *client,
495 buf = kmalloc(256,GFP_KERNEL); 617 buf = kmalloc(256,GFP_KERNEL);
496 memset(buf,0,256); 618 memset(buf,0,256);
497 tveeprom_read(client,buf,256); 619 tveeprom_read(client,buf,256);
498 tveeprom_hauppauge_analog(&eeprom,buf); 620 tveeprom_hauppauge_analog(client, &eeprom,buf);
499 kfree(buf); 621 kfree(buf);
500 eeprom_props[0] = eeprom.tuner_type; 622 eeprom_props[0] = eeprom.tuner_type;
501 eeprom_props[1] = eeprom.tuner_formats; 623 eeprom_props[1] = eeprom.tuner_formats;
502 eeprom_props[2] = eeprom.model; 624 eeprom_props[2] = eeprom.model;
503 eeprom_props[3] = eeprom.revision; 625 eeprom_props[3] = eeprom.revision;
626 eeprom_props[4] = eeprom.has_radio;
504 break; 627 break;
505 default: 628 default:
506 return -EINVAL; 629 return -EINVAL;
@@ -515,8 +638,6 @@ tveeprom_detect_client(struct i2c_adapter *adapter,
515{ 638{
516 struct i2c_client *client; 639 struct i2c_client *client;
517 640
518 dprintk(1,"%s: id 0x%x @ 0x%x\n",__FUNCTION__,
519 adapter->id, address << 1);
520 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); 641 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
521 if (NULL == client) 642 if (NULL == client)
522 return -ENOMEM; 643 return -ENOMEM;
@@ -533,7 +654,6 @@ tveeprom_detect_client(struct i2c_adapter *adapter,
533static int 654static int
534tveeprom_attach_adapter (struct i2c_adapter *adapter) 655tveeprom_attach_adapter (struct i2c_adapter *adapter)
535{ 656{
536 dprintk(1,"%s: id 0x%x\n",__FUNCTION__,adapter->id);
537 if (adapter->id != I2C_HW_B_BT848) 657 if (adapter->id != I2C_HW_B_BT848)
538 return 0; 658 return 0;
539 return i2c_probe(adapter, &addr_data, tveeprom_detect_client); 659 return i2c_probe(adapter, &addr_data, tveeprom_detect_client);
diff --git a/drivers/media/video/tvmixer.c b/drivers/media/video/tvmixer.c
index a43301a154..d86e08ebdd 100644
--- a/drivers/media/video/tvmixer.c
+++ b/drivers/media/video/tvmixer.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: tvmixer.c,v 1.8 2005/06/12 04:19:19 mchehab Exp $
3 */ 2 */
4 3
5#include <linux/module.h> 4#include <linux/module.h>
diff --git a/drivers/media/video/v4l1-compat.c b/drivers/media/video/v4l1-compat.c
index 70ecbdb802..59bb71381a 100644
--- a/drivers/media/video/v4l1-compat.c
+++ b/drivers/media/video/v4l1-compat.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: v4l1-compat.c,v 1.9 2005/06/12 04:19:19 mchehab Exp $
3 * 2 *
4 * Video for Linux Two 3 * Video for Linux Two
5 * Backward Compatibility Layer 4 * Backward Compatibility Layer
@@ -604,9 +603,6 @@ v4l_compat_translate_ioctl(struct inode *inode,
604 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n",err); 603 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n",err);
605 break; 604 break;
606 } 605 }
607#if 0 /* FIXME */
608 pict->depth = fmt2->fmt.pix.depth;
609#endif
610 pict->palette = pixelformat_to_palette( 606 pict->palette = pixelformat_to_palette(
611 fmt2->fmt.pix.pixelformat); 607 fmt2->fmt.pix.pixelformat);
612 break; 608 break;
@@ -707,13 +703,7 @@ v4l_compat_translate_ioctl(struct inode *inode,
707 } 703 }
708 case VIDIOCSTUNER: /* select a tuner input */ 704 case VIDIOCSTUNER: /* select a tuner input */
709 { 705 {
710#if 0 /* FIXME */
711 err = drv(inode, file, VIDIOC_S_INPUT, &i);
712 if (err < 0)
713 dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %d\n",err);
714#else
715 err = 0; 706 err = 0;
716#endif
717 break; 707 break;
718 } 708 }
719 case VIDIOCGFREQ: /* get frequency */ 709 case VIDIOCGFREQ: /* get frequency */
@@ -852,12 +842,6 @@ v4l_compat_translate_ioctl(struct inode *inode,
852 err = 0; 842 err = 0;
853 break; 843 break;
854 } 844 }
855#if 0
856 case VIDIOCGMBUF:
857 /* v4l2 drivers must implement that themself. The
858 mmap() differences can't be translated fully
859 transparent, thus there is no point to try that */
860#endif
861 case VIDIOCMCAPTURE: /* capture a frame */ 845 case VIDIOCMCAPTURE: /* capture a frame */
862 { 846 {
863 struct video_mmap *mm = arg; 847 struct video_mmap *mm = arg;
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index b5e0cf3448..597b8db35a 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -84,20 +84,6 @@ MODULE_LICENSE("GPL");
84 * Video Standard Operations (contributed by Michael Schimek) 84 * Video Standard Operations (contributed by Michael Schimek)
85 */ 85 */
86 86
87#if 0 /* seems to have no users */
88/* This is the recommended method to deal with the framerate fields. More
89 sophisticated drivers will access the fields directly. */
90unsigned int
91v4l2_video_std_fps(struct v4l2_standard *vs)
92{
93 if (vs->frameperiod.numerator > 0)
94 return (((vs->frameperiod.denominator << 8) /
95 vs->frameperiod.numerator) +
96 (1 << 7)) / (1 << 8);
97 return 0;
98}
99EXPORT_SYMBOL(v4l2_video_std_fps);
100#endif
101 87
102/* Fill in the fields of a v4l2_standard structure according to the 88/* Fill in the fields of a v4l2_standard structure according to the
103 'id' and 'transmission' parameters. Returns negative on error. */ 89 'id' and 'transmission' parameters. Returns negative on error. */
@@ -213,10 +199,6 @@ char *v4l2_ioctl_names[256] = {
213 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT", 199 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
214 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT", 200 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
215 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT", 201 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
216#if 0
217 [_IOC_NR(VIDIOC_G_COMP)] = "VIDIOC_G_COMP",
218 [_IOC_NR(VIDIOC_S_COMP)] = "VIDIOC_S_COMP",
219#endif
220 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS", 202 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
221 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF", 203 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
222 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF", 204 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
diff --git a/drivers/media/video/video-buf-dvb.c b/drivers/media/video/video-buf-dvb.c
index 15f5bb4869..55f129e964 100644
--- a/drivers/media/video/video-buf-dvb.c
+++ b/drivers/media/video/video-buf-dvb.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: video-buf-dvb.c,v 1.7 2004/12/09 12:51:35 kraxel Exp $
3 * 2 *
4 * some helper function for simple DVB cards which simply DMA the 3 * some helper function for simple DVB cards which simply DMA the
5 * complete transport stream and let the computer sort everything else 4 * complete transport stream and let the computer sort everything else
diff --git a/drivers/media/video/video-buf.c b/drivers/media/video/video-buf.c
index 5afdc78526..574b8e36f3 100644
--- a/drivers/media/video/video-buf.c
+++ b/drivers/media/video/video-buf.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: video-buf.c,v 1.18 2005/02/24 13:32:30 kraxel Exp $
3 * 2 *
4 * generic helper functions for video4linux capture buffers, to handle 3 * generic helper functions for video4linux capture buffers, to handle
5 * memory management and PCI DMA. Right now bttv + saa7134 use it. 4 * memory management and PCI DMA. Right now bttv + saa7134 use it.
@@ -268,10 +267,10 @@ int videobuf_dma_free(struct videobuf_dmabuf *dma)
268 kfree(dma->pages); 267 kfree(dma->pages);
269 dma->pages = NULL; 268 dma->pages = NULL;
270 } 269 }
271 if (dma->vmalloc) { 270
272 vfree(dma->vmalloc); 271 vfree(dma->vmalloc);
273 dma->vmalloc = NULL; 272 dma->vmalloc = NULL;
274 } 273
275 if (dma->bus_addr) { 274 if (dma->bus_addr) {
276 dma->bus_addr = 0; 275 dma->bus_addr = 0;
277 } 276 }
diff --git a/drivers/media/video/zoran_driver.c b/drivers/media/video/zoran_driver.c
index ba838a42ec..53adeb70f2 100644
--- a/drivers/media/video/zoran_driver.c
+++ b/drivers/media/video/zoran_driver.c
@@ -650,7 +650,7 @@ jpg_fbuffer_free (struct file *file)
650 off += PAGE_SIZE) 650 off += PAGE_SIZE)
651 ClearPageReserved(MAP_NR 651 ClearPageReserved(MAP_NR
652 (mem + off)); 652 (mem + off));
653 kfree((void *) mem); 653 kfree(mem);
654 fh->jpg_buffers.buffer[i].frag_tab[0] = 0; 654 fh->jpg_buffers.buffer[i].frag_tab[0] = 0;
655 fh->jpg_buffers.buffer[i].frag_tab[1] = 0; 655 fh->jpg_buffers.buffer[i].frag_tab[1] = 0;
656 } 656 }
diff --git a/drivers/media/video/zr36120.c b/drivers/media/video/zr36120.c
index c33533155c..07286816d7 100644
--- a/drivers/media/video/zr36120.c
+++ b/drivers/media/video/zr36120.c
@@ -820,11 +820,9 @@ void zoran_close(struct video_device* dev)
820 msleep(100); /* Wait 1/10th of a second */ 820 msleep(100); /* Wait 1/10th of a second */
821 821
822 /* free the allocated framebuffer */ 822 /* free the allocated framebuffer */
823 if (ztv->fbuffer) 823 bfree(ztv->fbuffer, ZORAN_MAX_FBUFSIZE);
824 bfree( ztv->fbuffer, ZORAN_MAX_FBUFSIZE );
825 ztv->fbuffer = 0; 824 ztv->fbuffer = 0;
826 if (ztv->overinfo.overlay) 825 kfree(ztv->overinfo.overlay);
827 kfree( ztv->overinfo.overlay );
828 ztv->overinfo.overlay = 0; 826 ztv->overinfo.overlay = 0;
829 827
830} 828}
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 1588a59e37..550f297448 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -13,4 +13,13 @@ config MCP_SA11X0
13 depends on ARCH_SA1100 13 depends on ARCH_SA1100
14 select MCP 14 select MCP
15 15
16# Chip drivers
17config MCP_UCB1200
18 tristate "Support for UCB1200 / UCB1300"
19 depends on MCP
20
21config MCP_UCB1200_TS
22 tristate "Touchscreen interface support"
23 depends on MCP_UCB1200 && INPUT
24
16endmenu 25endmenu
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 98bdd6a421..adb29b5368 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -4,3 +4,9 @@
4 4
5obj-$(CONFIG_MCP) += mcp-core.o 5obj-$(CONFIG_MCP) += mcp-core.o
6obj-$(CONFIG_MCP_SA11X0) += mcp-sa11x0.o 6obj-$(CONFIG_MCP_SA11X0) += mcp-sa11x0.o
7obj-$(CONFIG_MCP_UCB1200) += ucb1x00-core.o
8obj-$(CONFIG_MCP_UCB1200_TS) += ucb1x00-ts.o
9
10ifeq ($(CONFIG_SA1100_ASSABET),y)
11obj-$(CONFIG_MCP_UCB1200) += ucb1x00-assabet.o
12endif
diff --git a/drivers/mfd/ucb1x00-assabet.c b/drivers/mfd/ucb1x00-assabet.c
new file mode 100644
index 0000000000..e325fa71f3
--- /dev/null
+++ b/drivers/mfd/ucb1x00-assabet.c
@@ -0,0 +1,73 @@
1/*
2 * linux/drivers/mfd/ucb1x00-assabet.c
3 *
4 * Copyright (C) 2001-2003 Russell King, All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License.
9 *
10 * We handle the machine-specific bits of the UCB1x00 driver here.
11 */
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/fs.h>
15#include <linux/proc_fs.h>
16#include <linux/device.h>
17
18#include <asm/dma.h>
19
20#include "ucb1x00.h"
21
22#define UCB1X00_ATTR(name,input)\
23static ssize_t name##_show(struct class_device *dev, char *buf) \
24{ \
25 struct ucb1x00 *ucb = classdev_to_ucb1x00(dev); \
26 int val; \
27 ucb1x00_adc_enable(ucb); \
28 val = ucb1x00_adc_read(ucb, input, UCB_NOSYNC); \
29 ucb1x00_adc_disable(ucb); \
30 return sprintf(buf, "%d\n", val); \
31} \
32static CLASS_DEVICE_ATTR(name,0444,name##_show,NULL)
33
34UCB1X00_ATTR(vbatt, UCB_ADC_INP_AD1);
35UCB1X00_ATTR(vcharger, UCB_ADC_INP_AD0);
36UCB1X00_ATTR(batt_temp, UCB_ADC_INP_AD2);
37
38static int ucb1x00_assabet_add(struct ucb1x00_dev *dev)
39{
40 class_device_create_file(&dev->ucb->cdev, &class_device_attr_vbatt);
41 class_device_create_file(&dev->ucb->cdev, &class_device_attr_vcharger);
42 class_device_create_file(&dev->ucb->cdev, &class_device_attr_batt_temp);
43 return 0;
44}
45
46static void ucb1x00_assabet_remove(struct ucb1x00_dev *dev)
47{
48 class_device_remove_file(&dev->ucb->cdev, &class_device_attr_batt_temp);
49 class_device_remove_file(&dev->ucb->cdev, &class_device_attr_vcharger);
50 class_device_remove_file(&dev->ucb->cdev, &class_device_attr_vbatt);
51}
52
53static struct ucb1x00_driver ucb1x00_assabet_driver = {
54 .add = ucb1x00_assabet_add,
55 .remove = ucb1x00_assabet_remove,
56};
57
58static int __init ucb1x00_assabet_init(void)
59{
60 return ucb1x00_register_driver(&ucb1x00_assabet_driver);
61}
62
63static void __exit ucb1x00_assabet_exit(void)
64{
65 ucb1x00_unregister_driver(&ucb1x00_assabet_driver);
66}
67
68module_init(ucb1x00_assabet_init);
69module_exit(ucb1x00_assabet_exit);
70
71MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
72MODULE_DESCRIPTION("Assabet noddy testing only example ADC driver");
73MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/ucb1x00-core.c b/drivers/mfd/ucb1x00-core.c
new file mode 100644
index 0000000000..10f6ce1bc0
--- /dev/null
+++ b/drivers/mfd/ucb1x00-core.c
@@ -0,0 +1,665 @@
1/*
2 * linux/drivers/mfd/ucb1x00-core.c
3 *
4 * Copyright (C) 2001 Russell King, All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License.
9 *
10 * The UCB1x00 core driver provides basic services for handling IO,
11 * the ADC, interrupts, and accessing registers. It is designed
12 * such that everything goes through this layer, thereby providing
13 * a consistent locking methodology, as well as allowing the drivers
14 * to be used on other non-MCP-enabled hardware platforms.
15 *
16 * Note that all locks are private to this file. Nothing else may
17 * touch them.
18 */
19#include <linux/config.h>
20#include <linux/module.h>
21#include <linux/kernel.h>
22#include <linux/slab.h>
23#include <linux/init.h>
24#include <linux/errno.h>
25#include <linux/interrupt.h>
26#include <linux/device.h>
27
28#include <asm/dma.h>
29#include <asm/hardware.h>
30#include <asm/irq.h>
31
32#include "ucb1x00.h"
33
34static DECLARE_MUTEX(ucb1x00_sem);
35static LIST_HEAD(ucb1x00_drivers);
36static LIST_HEAD(ucb1x00_devices);
37
38/**
39 * ucb1x00_io_set_dir - set IO direction
40 * @ucb: UCB1x00 structure describing chip
41 * @in: bitfield of IO pins to be set as inputs
42 * @out: bitfield of IO pins to be set as outputs
43 *
44 * Set the IO direction of the ten general purpose IO pins on
45 * the UCB1x00 chip. The @in bitfield has priority over the
46 * @out bitfield, in that if you specify a pin as both input
47 * and output, it will end up as an input.
48 *
49 * ucb1x00_enable must have been called to enable the comms
50 * before using this function.
51 *
52 * This function takes a spinlock, disabling interrupts.
53 */
54void ucb1x00_io_set_dir(struct ucb1x00 *ucb, unsigned int in, unsigned int out)
55{
56 unsigned long flags;
57
58 spin_lock_irqsave(&ucb->io_lock, flags);
59 ucb->io_dir |= out;
60 ucb->io_dir &= ~in;
61
62 ucb1x00_reg_write(ucb, UCB_IO_DIR, ucb->io_dir);
63 spin_unlock_irqrestore(&ucb->io_lock, flags);
64}
65
66/**
67 * ucb1x00_io_write - set or clear IO outputs
68 * @ucb: UCB1x00 structure describing chip
69 * @set: bitfield of IO pins to set to logic '1'
70 * @clear: bitfield of IO pins to set to logic '0'
71 *
72 * Set the IO output state of the specified IO pins. The value
73 * is retained if the pins are subsequently configured as inputs.
74 * The @clear bitfield has priority over the @set bitfield -
75 * outputs will be cleared.
76 *
77 * ucb1x00_enable must have been called to enable the comms
78 * before using this function.
79 *
80 * This function takes a spinlock, disabling interrupts.
81 */
82void ucb1x00_io_write(struct ucb1x00 *ucb, unsigned int set, unsigned int clear)
83{
84 unsigned long flags;
85
86 spin_lock_irqsave(&ucb->io_lock, flags);
87 ucb->io_out |= set;
88 ucb->io_out &= ~clear;
89
90 ucb1x00_reg_write(ucb, UCB_IO_DATA, ucb->io_out);
91 spin_unlock_irqrestore(&ucb->io_lock, flags);
92}
93
94/**
95 * ucb1x00_io_read - read the current state of the IO pins
96 * @ucb: UCB1x00 structure describing chip
97 *
98 * Return a bitfield describing the logic state of the ten
99 * general purpose IO pins.
100 *
101 * ucb1x00_enable must have been called to enable the comms
102 * before using this function.
103 *
104 * This function does not take any semaphores or spinlocks.
105 */
106unsigned int ucb1x00_io_read(struct ucb1x00 *ucb)
107{
108 return ucb1x00_reg_read(ucb, UCB_IO_DATA);
109}
110
111/*
112 * UCB1300 data sheet says we must:
113 * 1. enable ADC => 5us (including reference startup time)
114 * 2. select input => 51*tsibclk => 4.3us
115 * 3. start conversion => 102*tsibclk => 8.5us
116 * (tsibclk = 1/11981000)
117 * Period between SIB 128-bit frames = 10.7us
118 */
119
120/**
121 * ucb1x00_adc_enable - enable the ADC converter
122 * @ucb: UCB1x00 structure describing chip
123 *
124 * Enable the ucb1x00 and ADC converter on the UCB1x00 for use.
125 * Any code wishing to use the ADC converter must call this
126 * function prior to using it.
127 *
128 * This function takes the ADC semaphore to prevent two or more
129 * concurrent uses, and therefore may sleep. As a result, it
130 * can only be called from process context, not interrupt
131 * context.
132 *
133 * You should release the ADC as soon as possible using
134 * ucb1x00_adc_disable.
135 */
136void ucb1x00_adc_enable(struct ucb1x00 *ucb)
137{
138 down(&ucb->adc_sem);
139
140 ucb->adc_cr |= UCB_ADC_ENA;
141
142 ucb1x00_enable(ucb);
143 ucb1x00_reg_write(ucb, UCB_ADC_CR, ucb->adc_cr);
144}
145
146/**
147 * ucb1x00_adc_read - read the specified ADC channel
148 * @ucb: UCB1x00 structure describing chip
149 * @adc_channel: ADC channel mask
150 * @sync: wait for syncronisation pulse.
151 *
152 * Start an ADC conversion and wait for the result. Note that
153 * synchronised ADC conversions (via the ADCSYNC pin) must wait
154 * until the trigger is asserted and the conversion is finished.
155 *
156 * This function currently spins waiting for the conversion to
157 * complete (2 frames max without sync).
158 *
159 * If called for a synchronised ADC conversion, it may sleep
160 * with the ADC semaphore held.
161 */
162unsigned int ucb1x00_adc_read(struct ucb1x00 *ucb, int adc_channel, int sync)
163{
164 unsigned int val;
165
166 if (sync)
167 adc_channel |= UCB_ADC_SYNC_ENA;
168
169 ucb1x00_reg_write(ucb, UCB_ADC_CR, ucb->adc_cr | adc_channel);
170 ucb1x00_reg_write(ucb, UCB_ADC_CR, ucb->adc_cr | adc_channel | UCB_ADC_START);
171
172 for (;;) {
173 val = ucb1x00_reg_read(ucb, UCB_ADC_DATA);
174 if (val & UCB_ADC_DAT_VAL)
175 break;
176 /* yield to other processes */
177 set_current_state(TASK_INTERRUPTIBLE);
178 schedule_timeout(1);
179 }
180
181 return UCB_ADC_DAT(val);
182}
183
184/**
185 * ucb1x00_adc_disable - disable the ADC converter
186 * @ucb: UCB1x00 structure describing chip
187 *
188 * Disable the ADC converter and release the ADC semaphore.
189 */
190void ucb1x00_adc_disable(struct ucb1x00 *ucb)
191{
192 ucb->adc_cr &= ~UCB_ADC_ENA;
193 ucb1x00_reg_write(ucb, UCB_ADC_CR, ucb->adc_cr);
194 ucb1x00_disable(ucb);
195
196 up(&ucb->adc_sem);
197}
198
199/*
200 * UCB1x00 Interrupt handling.
201 *
202 * The UCB1x00 can generate interrupts when the SIBCLK is stopped.
203 * Since we need to read an internal register, we must re-enable
204 * SIBCLK to talk to the chip. We leave the clock running until
205 * we have finished processing all interrupts from the chip.
206 */
207static irqreturn_t ucb1x00_irq(int irqnr, void *devid, struct pt_regs *regs)
208{
209 struct ucb1x00 *ucb = devid;
210 struct ucb1x00_irq *irq;
211 unsigned int isr, i;
212
213 ucb1x00_enable(ucb);
214 isr = ucb1x00_reg_read(ucb, UCB_IE_STATUS);
215 ucb1x00_reg_write(ucb, UCB_IE_CLEAR, isr);
216 ucb1x00_reg_write(ucb, UCB_IE_CLEAR, 0);
217
218 for (i = 0, irq = ucb->irq_handler; i < 16 && isr; i++, isr >>= 1, irq++)
219 if (isr & 1 && irq->fn)
220 irq->fn(i, irq->devid);
221 ucb1x00_disable(ucb);
222
223 return IRQ_HANDLED;
224}
225
226/**
227 * ucb1x00_hook_irq - hook a UCB1x00 interrupt
228 * @ucb: UCB1x00 structure describing chip
229 * @idx: interrupt index
230 * @fn: function to call when interrupt is triggered
231 * @devid: device id to pass to interrupt handler
232 *
233 * Hook the specified interrupt. You can only register one handler
234 * for each interrupt source. The interrupt source is not enabled
235 * by this function; use ucb1x00_enable_irq instead.
236 *
237 * Interrupt handlers will be called with other interrupts enabled.
238 *
239 * Returns zero on success, or one of the following errors:
240 * -EINVAL if the interrupt index is invalid
241 * -EBUSY if the interrupt has already been hooked
242 */
243int ucb1x00_hook_irq(struct ucb1x00 *ucb, unsigned int idx, void (*fn)(int, void *), void *devid)
244{
245 struct ucb1x00_irq *irq;
246 int ret = -EINVAL;
247
248 if (idx < 16) {
249 irq = ucb->irq_handler + idx;
250 ret = -EBUSY;
251
252 spin_lock_irq(&ucb->lock);
253 if (irq->fn == NULL) {
254 irq->devid = devid;
255 irq->fn = fn;
256 ret = 0;
257 }
258 spin_unlock_irq(&ucb->lock);
259 }
260 return ret;
261}
262
263/**
264 * ucb1x00_enable_irq - enable an UCB1x00 interrupt source
265 * @ucb: UCB1x00 structure describing chip
266 * @idx: interrupt index
267 * @edges: interrupt edges to enable
268 *
269 * Enable the specified interrupt to trigger on %UCB_RISING,
270 * %UCB_FALLING or both edges. The interrupt should have been
271 * hooked by ucb1x00_hook_irq.
272 */
273void ucb1x00_enable_irq(struct ucb1x00 *ucb, unsigned int idx, int edges)
274{
275 unsigned long flags;
276
277 if (idx < 16) {
278 spin_lock_irqsave(&ucb->lock, flags);
279
280 ucb1x00_enable(ucb);
281 if (edges & UCB_RISING) {
282 ucb->irq_ris_enbl |= 1 << idx;
283 ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl);
284 }
285 if (edges & UCB_FALLING) {
286 ucb->irq_fal_enbl |= 1 << idx;
287 ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl);
288 }
289 ucb1x00_disable(ucb);
290 spin_unlock_irqrestore(&ucb->lock, flags);
291 }
292}
293
294/**
295 * ucb1x00_disable_irq - disable an UCB1x00 interrupt source
296 * @ucb: UCB1x00 structure describing chip
297 * @edges: interrupt edges to disable
298 *
299 * Disable the specified interrupt triggering on the specified
300 * (%UCB_RISING, %UCB_FALLING or both) edges.
301 */
302void ucb1x00_disable_irq(struct ucb1x00 *ucb, unsigned int idx, int edges)
303{
304 unsigned long flags;
305
306 if (idx < 16) {
307 spin_lock_irqsave(&ucb->lock, flags);
308
309 ucb1x00_enable(ucb);
310 if (edges & UCB_RISING) {
311 ucb->irq_ris_enbl &= ~(1 << idx);
312 ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl);
313 }
314 if (edges & UCB_FALLING) {
315 ucb->irq_fal_enbl &= ~(1 << idx);
316 ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl);
317 }
318 ucb1x00_disable(ucb);
319 spin_unlock_irqrestore(&ucb->lock, flags);
320 }
321}
322
323/**
324 * ucb1x00_free_irq - disable and free the specified UCB1x00 interrupt
325 * @ucb: UCB1x00 structure describing chip
326 * @idx: interrupt index
327 * @devid: device id.
328 *
329 * Disable the interrupt source and remove the handler. devid must
330 * match the devid passed when hooking the interrupt.
331 *
332 * Returns zero on success, or one of the following errors:
333 * -EINVAL if the interrupt index is invalid
334 * -ENOENT if devid does not match
335 */
336int ucb1x00_free_irq(struct ucb1x00 *ucb, unsigned int idx, void *devid)
337{
338 struct ucb1x00_irq *irq;
339 int ret;
340
341 if (idx >= 16)
342 goto bad;
343
344 irq = ucb->irq_handler + idx;
345 ret = -ENOENT;
346
347 spin_lock_irq(&ucb->lock);
348 if (irq->devid == devid) {
349 ucb->irq_ris_enbl &= ~(1 << idx);
350 ucb->irq_fal_enbl &= ~(1 << idx);
351
352 ucb1x00_enable(ucb);
353 ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl);
354 ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl);
355 ucb1x00_disable(ucb);
356
357 irq->fn = NULL;
358 irq->devid = NULL;
359 ret = 0;
360 }
361 spin_unlock_irq(&ucb->lock);
362 return ret;
363
364bad:
365 printk(KERN_ERR "Freeing bad UCB1x00 irq %d\n", idx);
366 return -EINVAL;
367}
368
369static int ucb1x00_add_dev(struct ucb1x00 *ucb, struct ucb1x00_driver *drv)
370{
371 struct ucb1x00_dev *dev;
372 int ret = -ENOMEM;
373
374 dev = kmalloc(sizeof(struct ucb1x00_dev), GFP_KERNEL);
375 if (dev) {
376 dev->ucb = ucb;
377 dev->drv = drv;
378
379 ret = drv->add(dev);
380
381 if (ret == 0) {
382 list_add(&dev->dev_node, &ucb->devs);
383 list_add(&dev->drv_node, &drv->devs);
384 } else {
385 kfree(dev);
386 }
387 }
388 return ret;
389}
390
391static void ucb1x00_remove_dev(struct ucb1x00_dev *dev)
392{
393 dev->drv->remove(dev);
394 list_del(&dev->dev_node);
395 list_del(&dev->drv_node);
396 kfree(dev);
397}
398
399/*
400 * Try to probe our interrupt, rather than relying on lots of
401 * hard-coded machine dependencies. For reference, the expected
402 * IRQ mappings are:
403 *
404 * Machine Default IRQ
405 * adsbitsy IRQ_GPCIN4
406 * cerf IRQ_GPIO_UCB1200_IRQ
407 * flexanet IRQ_GPIO_GUI
408 * freebird IRQ_GPIO_FREEBIRD_UCB1300_IRQ
409 * graphicsclient ADS_EXT_IRQ(8)
410 * graphicsmaster ADS_EXT_IRQ(8)
411 * lart LART_IRQ_UCB1200
412 * omnimeter IRQ_GPIO23
413 * pfs168 IRQ_GPIO_UCB1300_IRQ
414 * simpad IRQ_GPIO_UCB1300_IRQ
415 * shannon SHANNON_IRQ_GPIO_IRQ_CODEC
416 * yopy IRQ_GPIO_UCB1200_IRQ
417 */
418static int ucb1x00_detect_irq(struct ucb1x00 *ucb)
419{
420 unsigned long mask;
421
422 mask = probe_irq_on();
423 if (!mask)
424 return NO_IRQ;
425
426 /*
427 * Enable the ADC interrupt.
428 */
429 ucb1x00_reg_write(ucb, UCB_IE_RIS, UCB_IE_ADC);
430 ucb1x00_reg_write(ucb, UCB_IE_FAL, UCB_IE_ADC);
431 ucb1x00_reg_write(ucb, UCB_IE_CLEAR, 0xffff);
432 ucb1x00_reg_write(ucb, UCB_IE_CLEAR, 0);
433
434 /*
435 * Cause an ADC interrupt.
436 */
437 ucb1x00_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA);
438 ucb1x00_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA | UCB_ADC_START);
439
440 /*
441 * Wait for the conversion to complete.
442 */
443 while ((ucb1x00_reg_read(ucb, UCB_ADC_DATA) & UCB_ADC_DAT_VAL) == 0);
444 ucb1x00_reg_write(ucb, UCB_ADC_CR, 0);
445
446 /*
447 * Disable and clear interrupt.
448 */
449 ucb1x00_reg_write(ucb, UCB_IE_RIS, 0);
450 ucb1x00_reg_write(ucb, UCB_IE_FAL, 0);
451 ucb1x00_reg_write(ucb, UCB_IE_CLEAR, 0xffff);
452 ucb1x00_reg_write(ucb, UCB_IE_CLEAR, 0);
453
454 /*
455 * Read triggered interrupt.
456 */
457 return probe_irq_off(mask);
458}
459
460static int ucb1x00_probe(struct mcp *mcp)
461{
462 struct ucb1x00 *ucb;
463 struct ucb1x00_driver *drv;
464 unsigned int id;
465 int ret = -ENODEV;
466
467 mcp_enable(mcp);
468 id = mcp_reg_read(mcp, UCB_ID);
469
470 if (id != UCB_ID_1200 && id != UCB_ID_1300) {
471 printk(KERN_WARNING "UCB1x00 ID not found: %04x\n", id);
472 goto err_disable;
473 }
474
475 ucb = kmalloc(sizeof(struct ucb1x00), GFP_KERNEL);
476 ret = -ENOMEM;
477 if (!ucb)
478 goto err_disable;
479
480 memset(ucb, 0, sizeof(struct ucb1x00));
481
482 ucb->cdev.class = &ucb1x00_class;
483 ucb->cdev.dev = &mcp->attached_device;
484 strlcpy(ucb->cdev.class_id, "ucb1x00", sizeof(ucb->cdev.class_id));
485
486 spin_lock_init(&ucb->lock);
487 spin_lock_init(&ucb->io_lock);
488 sema_init(&ucb->adc_sem, 1);
489
490 ucb->id = id;
491 ucb->mcp = mcp;
492 ucb->irq = ucb1x00_detect_irq(ucb);
493 if (ucb->irq == NO_IRQ) {
494 printk(KERN_ERR "UCB1x00: IRQ probe failed\n");
495 ret = -ENODEV;
496 goto err_free;
497 }
498
499 ret = request_irq(ucb->irq, ucb1x00_irq, 0, "UCB1x00", ucb);
500 if (ret) {
501 printk(KERN_ERR "ucb1x00: unable to grab irq%d: %d\n",
502 ucb->irq, ret);
503 goto err_free;
504 }
505
506 set_irq_type(ucb->irq, IRQT_RISING);
507 mcp_set_drvdata(mcp, ucb);
508
509 ret = class_device_register(&ucb->cdev);
510 if (ret)
511 goto err_irq;
512
513 INIT_LIST_HEAD(&ucb->devs);
514 down(&ucb1x00_sem);
515 list_add(&ucb->node, &ucb1x00_devices);
516 list_for_each_entry(drv, &ucb1x00_drivers, node) {
517 ucb1x00_add_dev(ucb, drv);
518 }
519 up(&ucb1x00_sem);
520 goto out;
521
522 err_irq:
523 free_irq(ucb->irq, ucb);
524 err_free:
525 kfree(ucb);
526 err_disable:
527 mcp_disable(mcp);
528 out:
529 return ret;
530}
531
532static void ucb1x00_remove(struct mcp *mcp)
533{
534 struct ucb1x00 *ucb = mcp_get_drvdata(mcp);
535 struct list_head *l, *n;
536
537 down(&ucb1x00_sem);
538 list_del(&ucb->node);
539 list_for_each_safe(l, n, &ucb->devs) {
540 struct ucb1x00_dev *dev = list_entry(l, struct ucb1x00_dev, dev_node);
541 ucb1x00_remove_dev(dev);
542 }
543 up(&ucb1x00_sem);
544
545 free_irq(ucb->irq, ucb);
546 class_device_unregister(&ucb->cdev);
547}
548
549static void ucb1x00_release(struct class_device *dev)
550{
551 struct ucb1x00 *ucb = classdev_to_ucb1x00(dev);
552 kfree(ucb);
553}
554
555static struct class ucb1x00_class = {
556 .name = "ucb1x00",
557 .release = ucb1x00_release,
558};
559
560int ucb1x00_register_driver(struct ucb1x00_driver *drv)
561{
562 struct ucb1x00 *ucb;
563
564 INIT_LIST_HEAD(&drv->devs);
565 down(&ucb1x00_sem);
566 list_add(&drv->node, &ucb1x00_drivers);
567 list_for_each_entry(ucb, &ucb1x00_devices, node) {
568 ucb1x00_add_dev(ucb, drv);
569 }
570 up(&ucb1x00_sem);
571 return 0;
572}
573
574void ucb1x00_unregister_driver(struct ucb1x00_driver *drv)
575{
576 struct list_head *n, *l;
577
578 down(&ucb1x00_sem);
579 list_del(&drv->node);
580 list_for_each_safe(l, n, &drv->devs) {
581 struct ucb1x00_dev *dev = list_entry(l, struct ucb1x00_dev, drv_node);
582 ucb1x00_remove_dev(dev);
583 }
584 up(&ucb1x00_sem);
585}
586
587static int ucb1x00_suspend(struct mcp *mcp, pm_message_t state)
588{
589 struct ucb1x00 *ucb = mcp_get_drvdata(mcp);
590 struct ucb1x00_dev *dev;
591
592 down(&ucb1x00_sem);
593 list_for_each_entry(dev, &ucb->devs, dev_node) {
594 if (dev->drv->suspend)
595 dev->drv->suspend(dev, state);
596 }
597 up(&ucb1x00_sem);
598 return 0;
599}
600
601static int ucb1x00_resume(struct mcp *mcp)
602{
603 struct ucb1x00 *ucb = mcp_get_drvdata(mcp);
604 struct ucb1x00_dev *dev;
605
606 down(&ucb1x00_sem);
607 list_for_each_entry(dev, &ucb->devs, dev_node) {
608 if (dev->drv->resume)
609 dev->drv->resume(dev);
610 }
611 up(&ucb1x00_sem);
612 return 0;
613}
614
615static struct mcp_driver ucb1x00_driver = {
616 .drv = {
617 .name = "ucb1x00",
618 },
619 .probe = ucb1x00_probe,
620 .remove = ucb1x00_remove,
621 .suspend = ucb1x00_suspend,
622 .resume = ucb1x00_resume,
623};
624
625static int __init ucb1x00_init(void)
626{
627 int ret = class_register(&ucb1x00_class);
628 if (ret == 0) {
629 ret = mcp_driver_register(&ucb1x00_driver);
630 if (ret)
631 class_unregister(&ucb1x00_class);
632 }
633 return ret;
634}
635
636static void __exit ucb1x00_exit(void)
637{
638 mcp_driver_unregister(&ucb1x00_driver);
639 class_unregister(&ucb1x00_class);
640}
641
642module_init(ucb1x00_init);
643module_exit(ucb1x00_exit);
644
645EXPORT_SYMBOL(ucb1x00_class);
646
647EXPORT_SYMBOL(ucb1x00_io_set_dir);
648EXPORT_SYMBOL(ucb1x00_io_write);
649EXPORT_SYMBOL(ucb1x00_io_read);
650
651EXPORT_SYMBOL(ucb1x00_adc_enable);
652EXPORT_SYMBOL(ucb1x00_adc_read);
653EXPORT_SYMBOL(ucb1x00_adc_disable);
654
655EXPORT_SYMBOL(ucb1x00_hook_irq);
656EXPORT_SYMBOL(ucb1x00_free_irq);
657EXPORT_SYMBOL(ucb1x00_enable_irq);
658EXPORT_SYMBOL(ucb1x00_disable_irq);
659
660EXPORT_SYMBOL(ucb1x00_register_driver);
661EXPORT_SYMBOL(ucb1x00_unregister_driver);
662
663MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
664MODULE_DESCRIPTION("UCB1x00 core driver");
665MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/ucb1x00-ts.c b/drivers/mfd/ucb1x00-ts.c
new file mode 100644
index 0000000000..a851d65c7c
--- /dev/null
+++ b/drivers/mfd/ucb1x00-ts.c
@@ -0,0 +1,399 @@
1/*
2 * Touchscreen driver for UCB1x00-based touchscreens
3 *
4 * Copyright (C) 2001 Russell King, All Rights Reserved.
5 * Copyright (C) 2005 Pavel Machek
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * 21-Jan-2002 <jco@ict.es> :
12 *
13 * Added support for synchronous A/D mode. This mode is useful to
14 * avoid noise induced in the touchpanel by the LCD, provided that
15 * the UCB1x00 has a valid LCD sync signal routed to its ADCSYNC pin.
16 * It is important to note that the signal connected to the ADCSYNC
17 * pin should provide pulses even when the LCD is blanked, otherwise
18 * a pen touch needed to unblank the LCD will never be read.
19 */
20#include <linux/config.h>
21#include <linux/module.h>
22#include <linux/moduleparam.h>
23#include <linux/init.h>
24#include <linux/smp.h>
25#include <linux/smp_lock.h>
26#include <linux/sched.h>
27#include <linux/completion.h>
28#include <linux/delay.h>
29#include <linux/string.h>
30#include <linux/input.h>
31#include <linux/device.h>
32#include <linux/suspend.h>
33#include <linux/slab.h>
34#include <linux/kthread.h>
35
36#include <asm/dma.h>
37#include <asm/semaphore.h>
38
39#include "ucb1x00.h"
40
41
42struct ucb1x00_ts {
43 struct input_dev idev;
44 struct ucb1x00 *ucb;
45
46 wait_queue_head_t irq_wait;
47 struct task_struct *rtask;
48 u16 x_res;
49 u16 y_res;
50
51 int restart:1;
52 int adcsync:1;
53};
54
55static int adcsync;
56
57static inline void ucb1x00_ts_evt_add(struct ucb1x00_ts *ts, u16 pressure, u16 x, u16 y)
58{
59 input_report_abs(&ts->idev, ABS_X, x);
60 input_report_abs(&ts->idev, ABS_Y, y);
61 input_report_abs(&ts->idev, ABS_PRESSURE, pressure);
62 input_sync(&ts->idev);
63}
64
65static inline void ucb1x00_ts_event_release(struct ucb1x00_ts *ts)
66{
67 input_report_abs(&ts->idev, ABS_PRESSURE, 0);
68 input_sync(&ts->idev);
69}
70
71/*
72 * Switch to interrupt mode.
73 */
74static inline void ucb1x00_ts_mode_int(struct ucb1x00_ts *ts)
75{
76 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
77 UCB_TS_CR_TSMX_POW | UCB_TS_CR_TSPX_POW |
78 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_GND |
79 UCB_TS_CR_MODE_INT);
80}
81
82/*
83 * Switch to pressure mode, and read pressure. We don't need to wait
84 * here, since both plates are being driven.
85 */
86static inline unsigned int ucb1x00_ts_read_pressure(struct ucb1x00_ts *ts)
87{
88 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
89 UCB_TS_CR_TSMX_POW | UCB_TS_CR_TSPX_POW |
90 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_GND |
91 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
92
93 return ucb1x00_adc_read(ts->ucb, UCB_ADC_INP_TSPY, ts->adcsync);
94}
95
96/*
97 * Switch to X position mode and measure Y plate. We switch the plate
98 * configuration in pressure mode, then switch to position mode. This
99 * gives a faster response time. Even so, we need to wait about 55us
100 * for things to stabilise.
101 */
102static inline unsigned int ucb1x00_ts_read_xpos(struct ucb1x00_ts *ts)
103{
104 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
105 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
106 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
107 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
108 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
109 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
110 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
111 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
112 UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA);
113
114 udelay(55);
115
116 return ucb1x00_adc_read(ts->ucb, UCB_ADC_INP_TSPY, ts->adcsync);
117}
118
119/*
120 * Switch to Y position mode and measure X plate. We switch the plate
121 * configuration in pressure mode, then switch to position mode. This
122 * gives a faster response time. Even so, we need to wait about 55us
123 * for things to stabilise.
124 */
125static inline unsigned int ucb1x00_ts_read_ypos(struct ucb1x00_ts *ts)
126{
127 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
128 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW |
129 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
130 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
131 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW |
132 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
133 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
134 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW |
135 UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA);
136
137 udelay(55);
138
139 return ucb1x00_adc_read(ts->ucb, UCB_ADC_INP_TSPX, ts->adcsync);
140}
141
142/*
143 * Switch to X plate resistance mode. Set MX to ground, PX to
144 * supply. Measure current.
145 */
146static inline unsigned int ucb1x00_ts_read_xres(struct ucb1x00_ts *ts)
147{
148 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
149 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
150 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
151 return ucb1x00_adc_read(ts->ucb, 0, ts->adcsync);
152}
153
154/*
155 * Switch to Y plate resistance mode. Set MY to ground, PY to
156 * supply. Measure current.
157 */
158static inline unsigned int ucb1x00_ts_read_yres(struct ucb1x00_ts *ts)
159{
160 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
161 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW |
162 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
163 return ucb1x00_adc_read(ts->ucb, 0, ts->adcsync);
164}
165
166/*
167 * This is a RT kernel thread that handles the ADC accesses
168 * (mainly so we can use semaphores in the UCB1200 core code
169 * to serialise accesses to the ADC).
170 */
171static int ucb1x00_thread(void *_ts)
172{
173 struct ucb1x00_ts *ts = _ts;
174 struct task_struct *tsk = current;
175 DECLARE_WAITQUEUE(wait, tsk);
176 int valid;
177
178 /*
179 * We could run as a real-time thread. However, thus far
180 * this doesn't seem to be necessary.
181 */
182// tsk->policy = SCHED_FIFO;
183// tsk->rt_priority = 1;
184
185 valid = 0;
186
187 add_wait_queue(&ts->irq_wait, &wait);
188 while (!kthread_should_stop()) {
189 unsigned int x, y, p, val;
190 signed long timeout;
191
192 ts->restart = 0;
193
194 ucb1x00_adc_enable(ts->ucb);
195
196 x = ucb1x00_ts_read_xpos(ts);
197 y = ucb1x00_ts_read_ypos(ts);
198 p = ucb1x00_ts_read_pressure(ts);
199
200 /*
201 * Switch back to interrupt mode.
202 */
203 ucb1x00_ts_mode_int(ts);
204 ucb1x00_adc_disable(ts->ucb);
205
206 msleep(10);
207
208 ucb1x00_enable(ts->ucb);
209 val = ucb1x00_reg_read(ts->ucb, UCB_TS_CR);
210
211 if (val & (UCB_TS_CR_TSPX_LOW | UCB_TS_CR_TSMX_LOW)) {
212 set_task_state(tsk, TASK_INTERRUPTIBLE);
213
214 ucb1x00_enable_irq(ts->ucb, UCB_IRQ_TSPX, UCB_FALLING);
215 ucb1x00_disable(ts->ucb);
216
217 /*
218 * If we spat out a valid sample set last time,
219 * spit out a "pen off" sample here.
220 */
221 if (valid) {
222 ucb1x00_ts_event_release(ts);
223 valid = 0;
224 }
225
226 timeout = MAX_SCHEDULE_TIMEOUT;
227 } else {
228 ucb1x00_disable(ts->ucb);
229
230 /*
231 * Filtering is policy. Policy belongs in user
232 * space. We therefore leave it to user space
233 * to do any filtering they please.
234 */
235 if (!ts->restart) {
236 ucb1x00_ts_evt_add(ts, p, x, y);
237 valid = 1;
238 }
239
240 set_task_state(tsk, TASK_INTERRUPTIBLE);
241 timeout = HZ / 100;
242 }
243
244 try_to_freeze();
245
246 schedule_timeout(timeout);
247 }
248
249 remove_wait_queue(&ts->irq_wait, &wait);
250
251 ts->rtask = NULL;
252 return 0;
253}
254
255/*
256 * We only detect touch screen _touches_ with this interrupt
257 * handler, and even then we just schedule our task.
258 */
259static void ucb1x00_ts_irq(int idx, void *id)
260{
261 struct ucb1x00_ts *ts = id;
262 ucb1x00_disable_irq(ts->ucb, UCB_IRQ_TSPX, UCB_FALLING);
263 wake_up(&ts->irq_wait);
264}
265
266static int ucb1x00_ts_open(struct input_dev *idev)
267{
268 struct ucb1x00_ts *ts = (struct ucb1x00_ts *)idev;
269 int ret = 0;
270
271 BUG_ON(ts->rtask);
272
273 init_waitqueue_head(&ts->irq_wait);
274 ret = ucb1x00_hook_irq(ts->ucb, UCB_IRQ_TSPX, ucb1x00_ts_irq, ts);
275 if (ret < 0)
276 goto out;
277
278 /*
279 * If we do this at all, we should allow the user to
280 * measure and read the X and Y resistance at any time.
281 */
282 ucb1x00_adc_enable(ts->ucb);
283 ts->x_res = ucb1x00_ts_read_xres(ts);
284 ts->y_res = ucb1x00_ts_read_yres(ts);
285 ucb1x00_adc_disable(ts->ucb);
286
287 ts->rtask = kthread_run(ucb1x00_thread, ts, "ktsd");
288 if (!IS_ERR(ts->rtask)) {
289 ret = 0;
290 } else {
291 ucb1x00_free_irq(ts->ucb, UCB_IRQ_TSPX, ts);
292 ts->rtask = NULL;
293 ret = -EFAULT;
294 }
295
296 out:
297 return ret;
298}
299
300/*
301 * Release touchscreen resources. Disable IRQs.
302 */
303static void ucb1x00_ts_close(struct input_dev *idev)
304{
305 struct ucb1x00_ts *ts = (struct ucb1x00_ts *)idev;
306
307 if (ts->rtask)
308 kthread_stop(ts->rtask);
309
310 ucb1x00_enable(ts->ucb);
311 ucb1x00_free_irq(ts->ucb, UCB_IRQ_TSPX, ts);
312 ucb1x00_reg_write(ts->ucb, UCB_TS_CR, 0);
313 ucb1x00_disable(ts->ucb);
314}
315
316#ifdef CONFIG_PM
317static int ucb1x00_ts_resume(struct ucb1x00_dev *dev)
318{
319 struct ucb1x00_ts *ts = dev->priv;
320
321 if (ts->rtask != NULL) {
322 /*
323 * Restart the TS thread to ensure the
324 * TS interrupt mode is set up again
325 * after sleep.
326 */
327 ts->restart = 1;
328 wake_up(&ts->irq_wait);
329 }
330 return 0;
331}
332#else
333#define ucb1x00_ts_resume NULL
334#endif
335
336
337/*
338 * Initialisation.
339 */
340static int ucb1x00_ts_add(struct ucb1x00_dev *dev)
341{
342 struct ucb1x00_ts *ts;
343
344 ts = kmalloc(sizeof(struct ucb1x00_ts), GFP_KERNEL);
345 if (!ts)
346 return -ENOMEM;
347
348 memset(ts, 0, sizeof(struct ucb1x00_ts));
349
350 ts->ucb = dev->ucb;
351 ts->adcsync = adcsync ? UCB_SYNC : UCB_NOSYNC;
352
353 ts->idev.name = "Touchscreen panel";
354 ts->idev.id.product = ts->ucb->id;
355 ts->idev.open = ucb1x00_ts_open;
356 ts->idev.close = ucb1x00_ts_close;
357
358 __set_bit(EV_ABS, ts->idev.evbit);
359 __set_bit(ABS_X, ts->idev.absbit);
360 __set_bit(ABS_Y, ts->idev.absbit);
361 __set_bit(ABS_PRESSURE, ts->idev.absbit);
362
363 input_register_device(&ts->idev);
364
365 dev->priv = ts;
366
367 return 0;
368}
369
370static void ucb1x00_ts_remove(struct ucb1x00_dev *dev)
371{
372 struct ucb1x00_ts *ts = dev->priv;
373 input_unregister_device(&ts->idev);
374 kfree(ts);
375}
376
377static struct ucb1x00_driver ucb1x00_ts_driver = {
378 .add = ucb1x00_ts_add,
379 .remove = ucb1x00_ts_remove,
380 .resume = ucb1x00_ts_resume,
381};
382
383static int __init ucb1x00_ts_init(void)
384{
385 return ucb1x00_register_driver(&ucb1x00_ts_driver);
386}
387
388static void __exit ucb1x00_ts_exit(void)
389{
390 ucb1x00_unregister_driver(&ucb1x00_ts_driver);
391}
392
393module_param(adcsync, int, 0444);
394module_init(ucb1x00_ts_init);
395module_exit(ucb1x00_ts_exit);
396
397MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
398MODULE_DESCRIPTION("UCB1x00 touchscreen driver");
399MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/ucb1x00.h b/drivers/mfd/ucb1x00.h
new file mode 100644
index 0000000000..6b632644f5
--- /dev/null
+++ b/drivers/mfd/ucb1x00.h
@@ -0,0 +1,256 @@
1/*
2 * linux/drivers/mfd/ucb1x00.h
3 *
4 * Copyright (C) 2001 Russell King, All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License.
9 */
10#ifndef UCB1200_H
11#define UCB1200_H
12
13#define UCB_IO_DATA 0x00
14#define UCB_IO_DIR 0x01
15
16#define UCB_IO_0 (1 << 0)
17#define UCB_IO_1 (1 << 1)
18#define UCB_IO_2 (1 << 2)
19#define UCB_IO_3 (1 << 3)
20#define UCB_IO_4 (1 << 4)
21#define UCB_IO_5 (1 << 5)
22#define UCB_IO_6 (1 << 6)
23#define UCB_IO_7 (1 << 7)
24#define UCB_IO_8 (1 << 8)
25#define UCB_IO_9 (1 << 9)
26
27#define UCB_IE_RIS 0x02
28#define UCB_IE_FAL 0x03
29#define UCB_IE_STATUS 0x04
30#define UCB_IE_CLEAR 0x04
31#define UCB_IE_ADC (1 << 11)
32#define UCB_IE_TSPX (1 << 12)
33#define UCB_IE_TSMX (1 << 13)
34#define UCB_IE_TCLIP (1 << 14)
35#define UCB_IE_ACLIP (1 << 15)
36
37#define UCB_IRQ_TSPX 12
38
39#define UCB_TC_A 0x05
40#define UCB_TC_A_LOOP (1 << 7) /* UCB1200 */
41#define UCB_TC_A_AMPL (1 << 7) /* UCB1300 */
42
43#define UCB_TC_B 0x06
44#define UCB_TC_B_VOICE_ENA (1 << 3)
45#define UCB_TC_B_CLIP (1 << 4)
46#define UCB_TC_B_ATT (1 << 6)
47#define UCB_TC_B_SIDE_ENA (1 << 11)
48#define UCB_TC_B_MUTE (1 << 13)
49#define UCB_TC_B_IN_ENA (1 << 14)
50#define UCB_TC_B_OUT_ENA (1 << 15)
51
52#define UCB_AC_A 0x07
53#define UCB_AC_B 0x08
54#define UCB_AC_B_LOOP (1 << 8)
55#define UCB_AC_B_MUTE (1 << 13)
56#define UCB_AC_B_IN_ENA (1 << 14)
57#define UCB_AC_B_OUT_ENA (1 << 15)
58
59#define UCB_TS_CR 0x09
60#define UCB_TS_CR_TSMX_POW (1 << 0)
61#define UCB_TS_CR_TSPX_POW (1 << 1)
62#define UCB_TS_CR_TSMY_POW (1 << 2)
63#define UCB_TS_CR_TSPY_POW (1 << 3)
64#define UCB_TS_CR_TSMX_GND (1 << 4)
65#define UCB_TS_CR_TSPX_GND (1 << 5)
66#define UCB_TS_CR_TSMY_GND (1 << 6)
67#define UCB_TS_CR_TSPY_GND (1 << 7)
68#define UCB_TS_CR_MODE_INT (0 << 8)
69#define UCB_TS_CR_MODE_PRES (1 << 8)
70#define UCB_TS_CR_MODE_POS (2 << 8)
71#define UCB_TS_CR_BIAS_ENA (1 << 11)
72#define UCB_TS_CR_TSPX_LOW (1 << 12)
73#define UCB_TS_CR_TSMX_LOW (1 << 13)
74
75#define UCB_ADC_CR 0x0a
76#define UCB_ADC_SYNC_ENA (1 << 0)
77#define UCB_ADC_VREFBYP_CON (1 << 1)
78#define UCB_ADC_INP_TSPX (0 << 2)
79#define UCB_ADC_INP_TSMX (1 << 2)
80#define UCB_ADC_INP_TSPY (2 << 2)
81#define UCB_ADC_INP_TSMY (3 << 2)
82#define UCB_ADC_INP_AD0 (4 << 2)
83#define UCB_ADC_INP_AD1 (5 << 2)
84#define UCB_ADC_INP_AD2 (6 << 2)
85#define UCB_ADC_INP_AD3 (7 << 2)
86#define UCB_ADC_EXT_REF (1 << 5)
87#define UCB_ADC_START (1 << 7)
88#define UCB_ADC_ENA (1 << 15)
89
90#define UCB_ADC_DATA 0x0b
91#define UCB_ADC_DAT_VAL (1 << 15)
92#define UCB_ADC_DAT(x) (((x) & 0x7fe0) >> 5)
93
94#define UCB_ID 0x0c
95#define UCB_ID_1200 0x1004
96#define UCB_ID_1300 0x1005
97
98#define UCB_MODE 0x0d
99#define UCB_MODE_DYN_VFLAG_ENA (1 << 12)
100#define UCB_MODE_AUD_OFF_CAN (1 << 13)
101
102#include "mcp.h"
103
104struct ucb1x00_irq {
105 void *devid;
106 void (*fn)(int, void *);
107};
108
109extern struct class ucb1x00_class;
110
111struct ucb1x00 {
112 spinlock_t lock;
113 struct mcp *mcp;
114 unsigned int irq;
115 struct semaphore adc_sem;
116 spinlock_t io_lock;
117 u16 id;
118 u16 io_dir;
119 u16 io_out;
120 u16 adc_cr;
121 u16 irq_fal_enbl;
122 u16 irq_ris_enbl;
123 struct ucb1x00_irq irq_handler[16];
124 struct class_device cdev;
125 struct list_head node;
126 struct list_head devs;
127};
128
129struct ucb1x00_driver;
130
131struct ucb1x00_dev {
132 struct list_head dev_node;
133 struct list_head drv_node;
134 struct ucb1x00 *ucb;
135 struct ucb1x00_driver *drv;
136 void *priv;
137};
138
139struct ucb1x00_driver {
140 struct list_head node;
141 struct list_head devs;
142 int (*add)(struct ucb1x00_dev *dev);
143 void (*remove)(struct ucb1x00_dev *dev);
144 int (*suspend)(struct ucb1x00_dev *dev, pm_message_t state);
145 int (*resume)(struct ucb1x00_dev *dev);
146};
147
148#define classdev_to_ucb1x00(cd) container_of(cd, struct ucb1x00, cdev)
149
150int ucb1x00_register_driver(struct ucb1x00_driver *);
151void ucb1x00_unregister_driver(struct ucb1x00_driver *);
152
153/**
154 * ucb1x00_clkrate - return the UCB1x00 SIB clock rate
155 * @ucb: UCB1x00 structure describing chip
156 *
157 * Return the SIB clock rate in Hz.
158 */
159static inline unsigned int ucb1x00_clkrate(struct ucb1x00 *ucb)
160{
161 return mcp_get_sclk_rate(ucb->mcp);
162}
163
164/**
165 * ucb1x00_enable - enable the UCB1x00 SIB clock
166 * @ucb: UCB1x00 structure describing chip
167 *
168 * Enable the SIB clock. This can be called multiple times.
169 */
170static inline void ucb1x00_enable(struct ucb1x00 *ucb)
171{
172 mcp_enable(ucb->mcp);
173}
174
175/**
176 * ucb1x00_disable - disable the UCB1x00 SIB clock
177 * @ucb: UCB1x00 structure describing chip
178 *
179 * Disable the SIB clock. The SIB clock will only be disabled
180 * when the number of ucb1x00_enable calls match the number of
181 * ucb1x00_disable calls.
182 */
183static inline void ucb1x00_disable(struct ucb1x00 *ucb)
184{
185 mcp_disable(ucb->mcp);
186}
187
188/**
189 * ucb1x00_reg_write - write a UCB1x00 register
190 * @ucb: UCB1x00 structure describing chip
191 * @reg: UCB1x00 4-bit register index to write
192 * @val: UCB1x00 16-bit value to write
193 *
194 * Write the UCB1x00 register @reg with value @val. The SIB
195 * clock must be running for this function to return.
196 */
197static inline void ucb1x00_reg_write(struct ucb1x00 *ucb, unsigned int reg, unsigned int val)
198{
199 mcp_reg_write(ucb->mcp, reg, val);
200}
201
202/**
203 * ucb1x00_reg_read - read a UCB1x00 register
204 * @ucb: UCB1x00 structure describing chip
205 * @reg: UCB1x00 4-bit register index to write
206 *
207 * Read the UCB1x00 register @reg and return its value. The SIB
208 * clock must be running for this function to return.
209 */
210static inline unsigned int ucb1x00_reg_read(struct ucb1x00 *ucb, unsigned int reg)
211{
212 return mcp_reg_read(ucb->mcp, reg);
213}
214/**
215 * ucb1x00_set_audio_divisor -
216 * @ucb: UCB1x00 structure describing chip
217 * @div: SIB clock divisor
218 */
219static inline void ucb1x00_set_audio_divisor(struct ucb1x00 *ucb, unsigned int div)
220{
221 mcp_set_audio_divisor(ucb->mcp, div);
222}
223
224/**
225 * ucb1x00_set_telecom_divisor -
226 * @ucb: UCB1x00 structure describing chip
227 * @div: SIB clock divisor
228 */
229static inline void ucb1x00_set_telecom_divisor(struct ucb1x00 *ucb, unsigned int div)
230{
231 mcp_set_telecom_divisor(ucb->mcp, div);
232}
233
234void ucb1x00_io_set_dir(struct ucb1x00 *ucb, unsigned int, unsigned int);
235void ucb1x00_io_write(struct ucb1x00 *ucb, unsigned int, unsigned int);
236unsigned int ucb1x00_io_read(struct ucb1x00 *ucb);
237
238#define UCB_NOSYNC (0)
239#define UCB_SYNC (1)
240
241unsigned int ucb1x00_adc_read(struct ucb1x00 *ucb, int adc_channel, int sync);
242void ucb1x00_adc_enable(struct ucb1x00 *ucb);
243void ucb1x00_adc_disable(struct ucb1x00 *ucb);
244
245/*
246 * Which edges of the IRQ do you want to control today?
247 */
248#define UCB_RISING (1 << 0)
249#define UCB_FALLING (1 << 1)
250
251int ucb1x00_hook_irq(struct ucb1x00 *ucb, unsigned int idx, void (*fn)(int, void *), void *devid);
252void ucb1x00_enable_irq(struct ucb1x00 *ucb, unsigned int idx, int edges);
253void ucb1x00_disable_irq(struct ucb1x00 *ucb, unsigned int idx, int edges);
254int ucb1x00_free_irq(struct ucb1x00 *ucb, unsigned int idx, void *devid);
255
256#endif
diff --git a/drivers/misc/hdpuftrs/hdpu_cpustate.c b/drivers/misc/hdpuftrs/hdpu_cpustate.c
index 7501fab349..46de5c9405 100644
--- a/drivers/misc/hdpuftrs/hdpu_cpustate.c
+++ b/drivers/misc/hdpuftrs/hdpu_cpustate.c
@@ -192,22 +192,37 @@ static int hdpu_cpustate_probe(struct device *ddev)
192{ 192{
193 struct platform_device *pdev = to_platform_device(ddev); 193 struct platform_device *pdev = to_platform_device(ddev);
194 struct resource *res; 194 struct resource *res;
195 struct proc_dir_entry *proc_de;
196 int ret;
195 197
196 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 198 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
197 cpustate.set_addr = (unsigned long *)res->start; 199 cpustate.set_addr = (unsigned long *)res->start;
198 cpustate.clr_addr = (unsigned long *)res->end - 1; 200 cpustate.clr_addr = (unsigned long *)res->end - 1;
199 201
200 misc_register(&cpustate_dev); 202 ret = misc_register(&cpustate_dev);
201 create_proc_read_entry("sky_cpustate", 0, 0, cpustate_read_proc, NULL); 203 if (ret) {
204 printk(KERN_WARNING "sky_cpustate: Unable to register misc "
205 "device.\n");
206 cpustate.set_addr = NULL;
207 cpustate.clr_addr = NULL;
208 return ret;
209 }
210
211 proc_de = create_proc_read_entry("sky_cpustate", 0, 0,
212 cpustate_read_proc, NULL);
213 if (proc_de == NULL)
214 printk(KERN_WARNING "sky_cpustate: Unable to create proc "
215 "dir entry\n");
202 216
203 printk(KERN_INFO "Sky CPU State Driver v" SKY_CPUSTATE_VERSION "\n"); 217 printk(KERN_INFO "Sky CPU State Driver v" SKY_CPUSTATE_VERSION "\n");
204 return 0; 218 return 0;
205} 219}
220
206static int hdpu_cpustate_remove(struct device *ddev) 221static int hdpu_cpustate_remove(struct device *ddev)
207{ 222{
208 223
209 cpustate.set_addr = 0; 224 cpustate.set_addr = NULL;
210 cpustate.clr_addr = 0; 225 cpustate.clr_addr = NULL;
211 226
212 remove_proc_entry("sky_cpustate", NULL); 227 remove_proc_entry("sky_cpustate", NULL);
213 misc_deregister(&cpustate_dev); 228 misc_deregister(&cpustate_dev);
diff --git a/drivers/mmc/wbsd.c b/drivers/mmc/wbsd.c
index a62c86fef5..e11e55dc89 100644
--- a/drivers/mmc/wbsd.c
+++ b/drivers/mmc/wbsd.c
@@ -1112,20 +1112,6 @@ static void wbsd_reset_ignore(unsigned long data)
1112} 1112}
1113 1113
1114/* 1114/*
1115 * Helper function for card detection
1116 */
1117static void wbsd_detect_card(unsigned long data)
1118{
1119 struct wbsd_host *host = (struct wbsd_host*)data;
1120
1121 BUG_ON(host == NULL);
1122
1123 DBG("Executing card detection\n");
1124
1125 mmc_detect_change(host->mmc, 0);
1126}
1127
1128/*
1129 * Tasklets 1115 * Tasklets
1130 */ 1116 */
1131 1117
@@ -1169,14 +1155,16 @@ static void wbsd_tasklet_card(unsigned long param)
1169 DBG("Card inserted\n"); 1155 DBG("Card inserted\n");
1170 host->flags |= WBSD_FCARD_PRESENT; 1156 host->flags |= WBSD_FCARD_PRESENT;
1171 1157
1158 spin_unlock(&host->lock);
1159
1172 /* 1160 /*
1173 * Delay card detection to allow electrical connections 1161 * Delay card detection to allow electrical connections
1174 * to stabilise. 1162 * to stabilise.
1175 */ 1163 */
1176 mod_timer(&host->detect_timer, jiffies + HZ/2); 1164 mmc_detect_change(host->mmc, msecs_to_jiffies(500));
1177 } 1165 }
1178 1166 else
1179 spin_unlock(&host->lock); 1167 spin_unlock(&host->lock);
1180 } 1168 }
1181 else if (host->flags & WBSD_FCARD_PRESENT) 1169 else if (host->flags & WBSD_FCARD_PRESENT)
1182 { 1170 {
@@ -1409,10 +1397,6 @@ static int __devinit wbsd_alloc_mmc(struct device* dev)
1409 /* 1397 /*
1410 * Set up timers 1398 * Set up timers
1411 */ 1399 */
1412 init_timer(&host->detect_timer);
1413 host->detect_timer.data = (unsigned long)host;
1414 host->detect_timer.function = wbsd_detect_card;
1415
1416 init_timer(&host->ignore_timer); 1400 init_timer(&host->ignore_timer);
1417 host->ignore_timer.data = (unsigned long)host; 1401 host->ignore_timer.data = (unsigned long)host;
1418 host->ignore_timer.function = wbsd_reset_ignore; 1402 host->ignore_timer.function = wbsd_reset_ignore;
@@ -1454,7 +1438,6 @@ static void __devexit wbsd_free_mmc(struct device* dev)
1454 BUG_ON(host == NULL); 1438 BUG_ON(host == NULL);
1455 1439
1456 del_timer_sync(&host->ignore_timer); 1440 del_timer_sync(&host->ignore_timer);
1457 del_timer_sync(&host->detect_timer);
1458 1441
1459 mmc_free_host(mmc); 1442 mmc_free_host(mmc);
1460 1443
diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
index bb713fed2f..1443117fd8 100644
--- a/drivers/mtd/devices/mtdram.c
+++ b/drivers/mtd/devices/mtdram.c
@@ -91,8 +91,7 @@ static void __exit cleanup_mtdram(void)
91{ 91{
92 if (mtd_info) { 92 if (mtd_info) {
93 del_mtd_device(mtd_info); 93 del_mtd_device(mtd_info);
94 if (mtd_info->priv) 94 vfree(mtd_info->priv);
95 vfree(mtd_info->priv);
96 kfree(mtd_info); 95 kfree(mtd_info);
97 } 96 }
98} 97}
diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
index d9ab60b36f..d32c1b3a8c 100644
--- a/drivers/mtd/ftl.c
+++ b/drivers/mtd/ftl.c
@@ -1017,27 +1017,16 @@ static int ftl_writesect(struct mtd_blktrans_dev *dev,
1017 1017
1018void ftl_freepart(partition_t *part) 1018void ftl_freepart(partition_t *part)
1019{ 1019{
1020 if (part->VirtualBlockMap) {
1021 vfree(part->VirtualBlockMap); 1020 vfree(part->VirtualBlockMap);
1022 part->VirtualBlockMap = NULL; 1021 part->VirtualBlockMap = NULL;
1023 }
1024 if (part->VirtualPageMap) {
1025 kfree(part->VirtualPageMap); 1022 kfree(part->VirtualPageMap);
1026 part->VirtualPageMap = NULL; 1023 part->VirtualPageMap = NULL;
1027 }
1028 if (part->EUNInfo) {
1029 kfree(part->EUNInfo); 1024 kfree(part->EUNInfo);
1030 part->EUNInfo = NULL; 1025 part->EUNInfo = NULL;
1031 }
1032 if (part->XferInfo) {
1033 kfree(part->XferInfo); 1026 kfree(part->XferInfo);
1034 part->XferInfo = NULL; 1027 part->XferInfo = NULL;
1035 }
1036 if (part->bam_cache) {
1037 kfree(part->bam_cache); 1028 kfree(part->bam_cache);
1038 part->bam_cache = NULL; 1029 part->bam_cache = NULL;
1039 }
1040
1041} /* ftl_freepart */ 1030} /* ftl_freepart */
1042 1031
1043static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) 1032static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
diff --git a/drivers/mtd/maps/uclinux.c b/drivers/mtd/maps/uclinux.c
index 811d92e5f5..cc372136e8 100644
--- a/drivers/mtd/maps/uclinux.c
+++ b/drivers/mtd/maps/uclinux.c
@@ -25,9 +25,6 @@
25 25
26/****************************************************************************/ 26/****************************************************************************/
27 27
28
29/****************************************************************************/
30
31struct map_info uclinux_ram_map = { 28struct map_info uclinux_ram_map = {
32 .name = "RAM", 29 .name = "RAM",
33}; 30};
@@ -60,14 +57,15 @@ int __init uclinux_mtd_init(void)
60 struct mtd_info *mtd; 57 struct mtd_info *mtd;
61 struct map_info *mapp; 58 struct map_info *mapp;
62 extern char _ebss; 59 extern char _ebss;
60 unsigned long addr = (unsigned long) &_ebss;
63 61
64 mapp = &uclinux_ram_map; 62 mapp = &uclinux_ram_map;
65 mapp->phys = (unsigned long) &_ebss; 63 mapp->phys = addr;
66 mapp->size = PAGE_ALIGN(*((unsigned long *)((&_ebss) + 8))); 64 mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(addr + 8))));
67 mapp->bankwidth = 4; 65 mapp->bankwidth = 4;
68 66
69 printk("uclinux[mtd]: RAM probe address=0x%x size=0x%x\n", 67 printk("uclinux[mtd]: RAM probe address=0x%x size=0x%x\n",
70 (int) mapp->map_priv_2, (int) mapp->size); 68 (int) mapp->phys, (int) mapp->size);
71 69
72 mapp->virt = ioremap_nocache(mapp->phys, mapp->size); 70 mapp->virt = ioremap_nocache(mapp->phys, mapp->size);
73 71
@@ -95,7 +93,6 @@ int __init uclinux_mtd_init(void)
95 printk("uclinux[mtd]: set %s to be root filesystem\n", 93 printk("uclinux[mtd]: set %s to be root filesystem\n",
96 uclinux_romfs[0].name); 94 uclinux_romfs[0].name);
97 ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, 0); 95 ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, 0);
98 put_mtd_device(mtd);
99 96
100 return(0); 97 return(0);
101} 98}
@@ -109,7 +106,7 @@ void __exit uclinux_mtd_cleanup(void)
109 map_destroy(uclinux_ram_mtdinfo); 106 map_destroy(uclinux_ram_mtdinfo);
110 uclinux_ram_mtdinfo = NULL; 107 uclinux_ram_mtdinfo = NULL;
111 } 108 }
112 if (uclinux_ram_map.map_priv_1) { 109 if (uclinux_ram_map.virt) {
113 iounmap((void *) uclinux_ram_map.virt); 110 iounmap((void *) uclinux_ram_map.virt);
114 uclinux_ram_map.virt = 0; 111 uclinux_ram_map.virt = 0;
115 } 112 }
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 6bb9232514..54fff9c2e8 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -1738,11 +1738,18 @@ config 68360_ENET
1738 the Motorola 68360 processor. 1738 the Motorola 68360 processor.
1739 1739
1740config FEC 1740config FEC
1741 bool "FEC ethernet controller (of ColdFire 5272)" 1741 bool "FEC ethernet controller (of ColdFire CPUs)"
1742 depends on M5272 || M5282 1742 depends on M523x || M527x || M5272 || M528x
1743 help 1743 help
1744 Say Y here if you want to use the built-in 10/100 Fast ethernet 1744 Say Y here if you want to use the built-in 10/100 Fast ethernet
1745 controller on the Motorola ColdFire 5272 processor. 1745 controller on some Motorola ColdFire processors.
1746
1747config FEC2
1748 bool "Second FEC ethernet controller (on some ColdFire CPUs)"
1749 depends on FEC
1750 help
1751 Say Y here if you want to use the second built-in 10/100 Fast
1752 ethernet controller on some Motorola ColdFire processors.
1746 1753
1747config NE_H8300 1754config NE_H8300
1748 tristate "NE2000 compatible support for H8/300" 1755 tristate "NE2000 compatible support for H8/300"
diff --git a/drivers/net/atari_bionet.c b/drivers/net/atari_bionet.c
index 1798ce7262..0095384ff4 100644
--- a/drivers/net/atari_bionet.c
+++ b/drivers/net/atari_bionet.c
@@ -155,7 +155,7 @@ static int bionet_close(struct net_device *dev);
155static struct net_device_stats *net_get_stats(struct net_device *dev); 155static struct net_device_stats *net_get_stats(struct net_device *dev);
156static void bionet_tick(unsigned long); 156static void bionet_tick(unsigned long);
157 157
158static struct timer_list bionet_timer = TIMER_INITIALIZER(bionet_tick, 0, 0); 158static DEFINE_TIMER(bionet_timer, bionet_tick, 0, 0);
159 159
160#define STRAM_ADDR(a) (((a) & 0xff000000) == 0) 160#define STRAM_ADDR(a) (((a) & 0xff000000) == 0)
161 161
diff --git a/drivers/net/atari_pamsnet.c b/drivers/net/atari_pamsnet.c
index 81c362c8cb..8b997809f9 100644
--- a/drivers/net/atari_pamsnet.c
+++ b/drivers/net/atari_pamsnet.c
@@ -165,7 +165,7 @@ static void pamsnet_tick(unsigned long);
165 165
166static irqreturn_t pamsnet_intr(int irq, void *data, struct pt_regs *fp); 166static irqreturn_t pamsnet_intr(int irq, void *data, struct pt_regs *fp);
167 167
168static struct timer_list pamsnet_timer = TIMER_INITIALIZER(pamsnet_tick, 0, 0); 168static DEFINE_TIMER(pamsnet_timer, pamsnet_tick, 0, 0);
169 169
170#define STRAM_ADDR(a) (((a) & 0xff000000) == 0) 170#define STRAM_ADDR(a) (((a) & 0xff000000) == 0)
171 171
diff --git a/drivers/net/bsd_comp.c b/drivers/net/bsd_comp.c
index 3d88ad622b..fb4098ed46 100644
--- a/drivers/net/bsd_comp.c
+++ b/drivers/net/bsd_comp.c
@@ -323,33 +323,27 @@ static void bsd_reset (void *state)
323 */ 323 */
324 324
325static void bsd_free (void *state) 325static void bsd_free (void *state)
326 { 326{
327 struct bsd_db *db = (struct bsd_db *) state; 327 struct bsd_db *db = state;
328 328
329 if (db) 329 if (!db)
330 { 330 return;
331
331/* 332/*
332 * Release the dictionary 333 * Release the dictionary
333 */ 334 */
334 if (db->dict) 335 vfree(db->dict);
335 { 336 db->dict = NULL;
336 vfree (db->dict);
337 db->dict = NULL;
338 }
339/* 337/*
340 * Release the string buffer 338 * Release the string buffer
341 */ 339 */
342 if (db->lens) 340 vfree(db->lens);
343 { 341 db->lens = NULL;
344 vfree (db->lens);
345 db->lens = NULL;
346 }
347/* 342/*
348 * Finally release the structure itself. 343 * Finally release the structure itself.
349 */ 344 */
350 kfree (db); 345 kfree(db);
351 } 346}
352 }
353 347
354/* 348/*
355 * Allocate space for a (de) compressor. 349 * Allocate space for a (de) compressor.
diff --git a/drivers/net/cris/eth_v10.c b/drivers/net/cris/eth_v10.c
index 442670860f..b68b9cad76 100644
--- a/drivers/net/cris/eth_v10.c
+++ b/drivers/net/cris/eth_v10.c
@@ -384,8 +384,8 @@ static unsigned int mdio_phy_addr; /* Transciever address */
384static unsigned int network_tr_ctrl_shadow = 0; 384static unsigned int network_tr_ctrl_shadow = 0;
385 385
386/* Network speed indication. */ 386/* Network speed indication. */
387static struct timer_list speed_timer = TIMER_INITIALIZER(NULL, 0, 0); 387static DEFINE_TIMER(speed_timer, NULL, 0, 0);
388static struct timer_list clear_led_timer = TIMER_INITIALIZER(NULL, 0, 0); 388static DEFINE_TIMER(clear_led_timer, NULL, 0, 0);
389static int current_speed; /* Speed read from transceiver */ 389static int current_speed; /* Speed read from transceiver */
390static int current_speed_selection; /* Speed selected by user */ 390static int current_speed_selection; /* Speed selected by user */
391static unsigned long led_next_time; 391static unsigned long led_next_time;
@@ -393,7 +393,7 @@ static int led_active;
393static int rx_queue_len; 393static int rx_queue_len;
394 394
395/* Duplex */ 395/* Duplex */
396static struct timer_list duplex_timer = TIMER_INITIALIZER(NULL, 0, 0); 396static DEFINE_TIMER(duplex_timer, NULL, 0, 0);
397static int full_duplex; 397static int full_duplex;
398static enum duplex current_duplex; 398static enum duplex current_duplex;
399 399
diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c
index b780307093..cdc07ccd73 100644
--- a/drivers/net/cs89x0.c
+++ b/drivers/net/cs89x0.c
@@ -247,6 +247,9 @@ static int get_eeprom_data(struct net_device *dev, int off, int len, int *buffer
247static int get_eeprom_cksum(int off, int len, int *buffer); 247static int get_eeprom_cksum(int off, int len, int *buffer);
248static int set_mac_address(struct net_device *dev, void *addr); 248static int set_mac_address(struct net_device *dev, void *addr);
249static void count_rx_errors(int status, struct net_local *lp); 249static void count_rx_errors(int status, struct net_local *lp);
250#ifdef CONFIG_NET_POLL_CONTROLLER
251static void net_poll_controller(struct net_device *dev);
252#endif
250#if ALLOW_DMA 253#if ALLOW_DMA
251static void get_dma_channel(struct net_device *dev); 254static void get_dma_channel(struct net_device *dev);
252static void release_dma_buff(struct net_local *lp); 255static void release_dma_buff(struct net_local *lp);
@@ -405,6 +408,19 @@ get_eeprom_cksum(int off, int len, int *buffer)
405 return -1; 408 return -1;
406} 409}
407 410
411#ifdef CONFIG_NET_POLL_CONTROLLER
412/*
413 * Polling receive - used by netconsole and other diagnostic tools
414 * to allow network i/o with interrupts disabled.
415 */
416static void net_poll_controller(struct net_device *dev)
417{
418 disable_irq(dev->irq);
419 net_interrupt(dev->irq, dev, NULL);
420 enable_irq(dev->irq);
421}
422#endif
423
408/* This is the real probe routine. Linux has a history of friendly device 424/* This is the real probe routine. Linux has a history of friendly device
409 probes on the ISA bus. A good device probes avoids doing writes, and 425 probes on the ISA bus. A good device probes avoids doing writes, and
410 verifies that the correct device exists and functions. 426 verifies that the correct device exists and functions.
@@ -760,6 +776,9 @@ cs89x0_probe1(struct net_device *dev, int ioaddr, int modular)
760 dev->get_stats = net_get_stats; 776 dev->get_stats = net_get_stats;
761 dev->set_multicast_list = set_multicast_list; 777 dev->set_multicast_list = set_multicast_list;
762 dev->set_mac_address = set_mac_address; 778 dev->set_mac_address = set_mac_address;
779#ifdef CONFIG_NET_POLL_CONTROLLER
780 dev->poll_controller = net_poll_controller;
781#endif
763 782
764 printk("\n"); 783 printk("\n");
765 if (net_debug) 784 if (net_debug)
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index 2c70084913..85504fb900 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -8,7 +8,7 @@
8 * describes connections using the internal parallel port I/O, which 8 * describes connections using the internal parallel port I/O, which
9 * is basically all of Port D. 9 * is basically all of Port D.
10 * 10 *
11 * Right now, I am very watseful with the buffers. I allocate memory 11 * Right now, I am very wasteful with the buffers. I allocate memory
12 * pages and then divide them into 2K frame buffers. This way I know I 12 * pages and then divide them into 2K frame buffers. This way I know I
13 * have buffers large enough to hold one frame within one buffer descriptor. 13 * have buffers large enough to hold one frame within one buffer descriptor.
14 * Once I get this working, I will use 64 or 128 byte CPM buffers, which 14 * Once I get this working, I will use 64 or 128 byte CPM buffers, which
@@ -19,7 +19,10 @@
19 * Copyright (c) 2000 Ericsson Radio Systems AB. 19 * Copyright (c) 2000 Ericsson Radio Systems AB.
20 * 20 *
21 * Support for FEC controller of ColdFire/5270/5271/5272/5274/5275/5280/5282. 21 * Support for FEC controller of ColdFire/5270/5271/5272/5274/5275/5280/5282.
22 * Copyrught (c) 2001-2004 Greg Ungerer (gerg@snapgear.com) 22 * Copyright (c) 2001-2004 Greg Ungerer (gerg@snapgear.com)
23 *
24 * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
25 * Copyright (c) 2004-2005 Macq Electronique SA.
23 */ 26 */
24 27
25#include <linux/config.h> 28#include <linux/config.h>
@@ -46,7 +49,8 @@
46#include <asm/io.h> 49#include <asm/io.h>
47#include <asm/pgtable.h> 50#include <asm/pgtable.h>
48 51
49#if defined(CONFIG_M527x) || defined(CONFIG_M5272) || defined(CONFIG_M528x) 52#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || \
53 defined(CONFIG_M5272) || defined(CONFIG_M528x)
50#include <asm/coldfire.h> 54#include <asm/coldfire.h>
51#include <asm/mcfsim.h> 55#include <asm/mcfsim.h>
52#include "fec.h" 56#include "fec.h"
@@ -71,7 +75,7 @@ static unsigned int fec_hw[] = {
71#elif defined(CONFIG_M527x) 75#elif defined(CONFIG_M527x)
72 (MCF_MBAR + 0x1000), 76 (MCF_MBAR + 0x1000),
73 (MCF_MBAR + 0x1800), 77 (MCF_MBAR + 0x1800),
74#elif defined(CONFIG_M528x) 78#elif defined(CONFIG_M523x) || defined(CONFIG_M528x)
75 (MCF_MBAR + 0x1000), 79 (MCF_MBAR + 0x1000),
76#else 80#else
77 &(((immap_t *)IMAP_ADDR)->im_cpm.cp_fec), 81 &(((immap_t *)IMAP_ADDR)->im_cpm.cp_fec),
@@ -94,12 +98,14 @@ static unsigned char fec_mac_default[] = {
94#define FEC_FLASHMAC 0xffe04000 98#define FEC_FLASHMAC 0xffe04000
95#elif defined(CONFIG_CANCam) 99#elif defined(CONFIG_CANCam)
96#define FEC_FLASHMAC 0xf0020000 100#define FEC_FLASHMAC 0xf0020000
101#elif defined (CONFIG_M5272C3)
102#define FEC_FLASHMAC (0xffe04000 + 4)
103#elif defined(CONFIG_MOD5272)
104#define FEC_FLASHMAC 0xffc0406b
97#else 105#else
98#define FEC_FLASHMAC 0 106#define FEC_FLASHMAC 0
99#endif 107#endif
100 108
101unsigned char *fec_flashmac = (unsigned char *) FEC_FLASHMAC;
102
103/* Forward declarations of some structures to support different PHYs 109/* Forward declarations of some structures to support different PHYs
104*/ 110*/
105 111
@@ -158,7 +164,7 @@ typedef struct {
158 * size bits. Other FEC hardware does not, so we need to take that into 164 * size bits. Other FEC hardware does not, so we need to take that into
159 * account when setting it. 165 * account when setting it.
160 */ 166 */
161#if defined(CONFIG_M527x) || defined(CONFIG_M528x) 167#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
162#define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16) 168#define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16)
163#else 169#else
164#define OPT_FRAME_SIZE 0 170#define OPT_FRAME_SIZE 0
@@ -196,7 +202,7 @@ struct fec_enet_private {
196 uint phy_id_done; 202 uint phy_id_done;
197 uint phy_status; 203 uint phy_status;
198 uint phy_speed; 204 uint phy_speed;
199 phy_info_t *phy; 205 phy_info_t const *phy;
200 struct work_struct phy_task; 206 struct work_struct phy_task;
201 207
202 uint sequence_done; 208 uint sequence_done;
@@ -209,7 +215,6 @@ struct fec_enet_private {
209 int link; 215 int link;
210 int old_link; 216 int old_link;
211 int full_duplex; 217 int full_duplex;
212 unsigned char mac_addr[ETH_ALEN];
213}; 218};
214 219
215static int fec_enet_open(struct net_device *dev); 220static int fec_enet_open(struct net_device *dev);
@@ -237,10 +242,10 @@ typedef struct mii_list {
237} mii_list_t; 242} mii_list_t;
238 243
239#define NMII 20 244#define NMII 20
240mii_list_t mii_cmds[NMII]; 245static mii_list_t mii_cmds[NMII];
241mii_list_t *mii_free; 246static mii_list_t *mii_free;
242mii_list_t *mii_head; 247static mii_list_t *mii_head;
243mii_list_t *mii_tail; 248static mii_list_t *mii_tail;
244 249
245static int mii_queue(struct net_device *dev, int request, 250static int mii_queue(struct net_device *dev, int request,
246 void (*func)(uint, struct net_device *)); 251 void (*func)(uint, struct net_device *));
@@ -425,7 +430,7 @@ fec_timeout(struct net_device *dev)
425 } 430 }
426 } 431 }
427#endif 432#endif
428 fec_restart(dev, 0); 433 fec_restart(dev, fep->full_duplex);
429 netif_wake_queue(dev); 434 netif_wake_queue(dev);
430} 435}
431 436
@@ -757,45 +762,52 @@ static void mii_parse_sr(uint mii_reg, struct net_device *dev)
757{ 762{
758 struct fec_enet_private *fep = netdev_priv(dev); 763 struct fec_enet_private *fep = netdev_priv(dev);
759 volatile uint *s = &(fep->phy_status); 764 volatile uint *s = &(fep->phy_status);
765 uint status;
760 766
761 *s &= ~(PHY_STAT_LINK | PHY_STAT_FAULT | PHY_STAT_ANC); 767 status = *s & ~(PHY_STAT_LINK | PHY_STAT_FAULT | PHY_STAT_ANC);
762 768
763 if (mii_reg & 0x0004) 769 if (mii_reg & 0x0004)
764 *s |= PHY_STAT_LINK; 770 status |= PHY_STAT_LINK;
765 if (mii_reg & 0x0010) 771 if (mii_reg & 0x0010)
766 *s |= PHY_STAT_FAULT; 772 status |= PHY_STAT_FAULT;
767 if (mii_reg & 0x0020) 773 if (mii_reg & 0x0020)
768 *s |= PHY_STAT_ANC; 774 status |= PHY_STAT_ANC;
775
776 *s = status;
769} 777}
770 778
771static void mii_parse_cr(uint mii_reg, struct net_device *dev) 779static void mii_parse_cr(uint mii_reg, struct net_device *dev)
772{ 780{
773 struct fec_enet_private *fep = netdev_priv(dev); 781 struct fec_enet_private *fep = netdev_priv(dev);
774 volatile uint *s = &(fep->phy_status); 782 volatile uint *s = &(fep->phy_status);
783 uint status;
775 784
776 *s &= ~(PHY_CONF_ANE | PHY_CONF_LOOP); 785 status = *s & ~(PHY_CONF_ANE | PHY_CONF_LOOP);
777 786
778 if (mii_reg & 0x1000) 787 if (mii_reg & 0x1000)
779 *s |= PHY_CONF_ANE; 788 status |= PHY_CONF_ANE;
780 if (mii_reg & 0x4000) 789 if (mii_reg & 0x4000)
781 *s |= PHY_CONF_LOOP; 790 status |= PHY_CONF_LOOP;
791 *s = status;
782} 792}
783 793
784static void mii_parse_anar(uint mii_reg, struct net_device *dev) 794static void mii_parse_anar(uint mii_reg, struct net_device *dev)
785{ 795{
786 struct fec_enet_private *fep = netdev_priv(dev); 796 struct fec_enet_private *fep = netdev_priv(dev);
787 volatile uint *s = &(fep->phy_status); 797 volatile uint *s = &(fep->phy_status);
798 uint status;
788 799
789 *s &= ~(PHY_CONF_SPMASK); 800 status = *s & ~(PHY_CONF_SPMASK);
790 801
791 if (mii_reg & 0x0020) 802 if (mii_reg & 0x0020)
792 *s |= PHY_CONF_10HDX; 803 status |= PHY_CONF_10HDX;
793 if (mii_reg & 0x0040) 804 if (mii_reg & 0x0040)
794 *s |= PHY_CONF_10FDX; 805 status |= PHY_CONF_10FDX;
795 if (mii_reg & 0x0080) 806 if (mii_reg & 0x0080)
796 *s |= PHY_CONF_100HDX; 807 status |= PHY_CONF_100HDX;
797 if (mii_reg & 0x00100) 808 if (mii_reg & 0x00100)
798 *s |= PHY_CONF_100FDX; 809 status |= PHY_CONF_100FDX;
810 *s = status;
799} 811}
800 812
801/* ------------------------------------------------------------------------- */ 813/* ------------------------------------------------------------------------- */
@@ -811,37 +823,34 @@ static void mii_parse_lxt970_csr(uint mii_reg, struct net_device *dev)
811{ 823{
812 struct fec_enet_private *fep = netdev_priv(dev); 824 struct fec_enet_private *fep = netdev_priv(dev);
813 volatile uint *s = &(fep->phy_status); 825 volatile uint *s = &(fep->phy_status);
826 uint status;
814 827
815 *s &= ~(PHY_STAT_SPMASK); 828 status = *s & ~(PHY_STAT_SPMASK);
816
817 if (mii_reg & 0x0800) { 829 if (mii_reg & 0x0800) {
818 if (mii_reg & 0x1000) 830 if (mii_reg & 0x1000)
819 *s |= PHY_STAT_100FDX; 831 status |= PHY_STAT_100FDX;
820 else 832 else
821 *s |= PHY_STAT_100HDX; 833 status |= PHY_STAT_100HDX;
822 } else { 834 } else {
823 if (mii_reg & 0x1000) 835 if (mii_reg & 0x1000)
824 *s |= PHY_STAT_10FDX; 836 status |= PHY_STAT_10FDX;
825 else 837 else
826 *s |= PHY_STAT_10HDX; 838 status |= PHY_STAT_10HDX;
827 } 839 }
840 *s = status;
828} 841}
829 842
830static phy_info_t phy_info_lxt970 = { 843static phy_cmd_t const phy_cmd_lxt970_config[] = {
831 0x07810000,
832 "LXT970",
833
834 (const phy_cmd_t []) { /* config */
835 { mk_mii_read(MII_REG_CR), mii_parse_cr }, 844 { mk_mii_read(MII_REG_CR), mii_parse_cr },
836 { mk_mii_read(MII_REG_ANAR), mii_parse_anar }, 845 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
837 { mk_mii_end, } 846 { mk_mii_end, }
838 }, 847 };
839 (const phy_cmd_t []) { /* startup - enable interrupts */ 848static phy_cmd_t const phy_cmd_lxt970_startup[] = { /* enable interrupts */
840 { mk_mii_write(MII_LXT970_IER, 0x0002), NULL }, 849 { mk_mii_write(MII_LXT970_IER, 0x0002), NULL },
841 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */ 850 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
842 { mk_mii_end, } 851 { mk_mii_end, }
843 }, 852 };
844 (const phy_cmd_t []) { /* ack_int */ 853static phy_cmd_t const phy_cmd_lxt970_ack_int[] = {
845 /* read SR and ISR to acknowledge */ 854 /* read SR and ISR to acknowledge */
846 { mk_mii_read(MII_REG_SR), mii_parse_sr }, 855 { mk_mii_read(MII_REG_SR), mii_parse_sr },
847 { mk_mii_read(MII_LXT970_ISR), NULL }, 856 { mk_mii_read(MII_LXT970_ISR), NULL },
@@ -849,11 +858,18 @@ static phy_info_t phy_info_lxt970 = {
849 /* find out the current status */ 858 /* find out the current status */
850 { mk_mii_read(MII_LXT970_CSR), mii_parse_lxt970_csr }, 859 { mk_mii_read(MII_LXT970_CSR), mii_parse_lxt970_csr },
851 { mk_mii_end, } 860 { mk_mii_end, }
852 }, 861 };
853 (const phy_cmd_t []) { /* shutdown - disable interrupts */ 862static phy_cmd_t const phy_cmd_lxt970_shutdown[] = { /* disable interrupts */
854 { mk_mii_write(MII_LXT970_IER, 0x0000), NULL }, 863 { mk_mii_write(MII_LXT970_IER, 0x0000), NULL },
855 { mk_mii_end, } 864 { mk_mii_end, }
856 }, 865 };
866static phy_info_t const phy_info_lxt970 = {
867 .id = 0x07810000,
868 .name = "LXT970",
869 .config = phy_cmd_lxt970_config,
870 .startup = phy_cmd_lxt970_startup,
871 .ack_int = phy_cmd_lxt970_ack_int,
872 .shutdown = phy_cmd_lxt970_shutdown
857}; 873};
858 874
859/* ------------------------------------------------------------------------- */ 875/* ------------------------------------------------------------------------- */
@@ -878,45 +894,44 @@ static void mii_parse_lxt971_sr2(uint mii_reg, struct net_device *dev)
878{ 894{
879 struct fec_enet_private *fep = netdev_priv(dev); 895 struct fec_enet_private *fep = netdev_priv(dev);
880 volatile uint *s = &(fep->phy_status); 896 volatile uint *s = &(fep->phy_status);
897 uint status;
881 898
882 *s &= ~(PHY_STAT_SPMASK | PHY_STAT_LINK | PHY_STAT_ANC); 899 status = *s & ~(PHY_STAT_SPMASK | PHY_STAT_LINK | PHY_STAT_ANC);
883 900
884 if (mii_reg & 0x0400) { 901 if (mii_reg & 0x0400) {
885 fep->link = 1; 902 fep->link = 1;
886 *s |= PHY_STAT_LINK; 903 status |= PHY_STAT_LINK;
887 } else { 904 } else {
888 fep->link = 0; 905 fep->link = 0;
889 } 906 }
890 if (mii_reg & 0x0080) 907 if (mii_reg & 0x0080)
891 *s |= PHY_STAT_ANC; 908 status |= PHY_STAT_ANC;
892 if (mii_reg & 0x4000) { 909 if (mii_reg & 0x4000) {
893 if (mii_reg & 0x0200) 910 if (mii_reg & 0x0200)
894 *s |= PHY_STAT_100FDX; 911 status |= PHY_STAT_100FDX;
895 else 912 else
896 *s |= PHY_STAT_100HDX; 913 status |= PHY_STAT_100HDX;
897 } else { 914 } else {
898 if (mii_reg & 0x0200) 915 if (mii_reg & 0x0200)
899 *s |= PHY_STAT_10FDX; 916 status |= PHY_STAT_10FDX;
900 else 917 else
901 *s |= PHY_STAT_10HDX; 918 status |= PHY_STAT_10HDX;
902 } 919 }
903 if (mii_reg & 0x0008) 920 if (mii_reg & 0x0008)
904 *s |= PHY_STAT_FAULT; 921 status |= PHY_STAT_FAULT;
905}
906 922
907static phy_info_t phy_info_lxt971 = { 923 *s = status;
908 0x0001378e, 924}
909 "LXT971",
910 925
911 (const phy_cmd_t []) { /* config */ 926static phy_cmd_t const phy_cmd_lxt971_config[] = {
912 /* limit to 10MBit because my protorype board 927 /* limit to 10MBit because my prototype board
913 * doesn't work with 100. */ 928 * doesn't work with 100. */
914 { mk_mii_read(MII_REG_CR), mii_parse_cr }, 929 { mk_mii_read(MII_REG_CR), mii_parse_cr },
915 { mk_mii_read(MII_REG_ANAR), mii_parse_anar }, 930 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
916 { mk_mii_read(MII_LXT971_SR2), mii_parse_lxt971_sr2 }, 931 { mk_mii_read(MII_LXT971_SR2), mii_parse_lxt971_sr2 },
917 { mk_mii_end, } 932 { mk_mii_end, }
918 }, 933 };
919 (const phy_cmd_t []) { /* startup - enable interrupts */ 934static phy_cmd_t const phy_cmd_lxt971_startup[] = { /* enable interrupts */
920 { mk_mii_write(MII_LXT971_IER, 0x00f2), NULL }, 935 { mk_mii_write(MII_LXT971_IER, 0x00f2), NULL },
921 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */ 936 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
922 { mk_mii_write(MII_LXT971_LCR, 0xd422), NULL }, /* LED config */ 937 { mk_mii_write(MII_LXT971_LCR, 0xd422), NULL }, /* LED config */
@@ -925,19 +940,26 @@ static phy_info_t phy_info_lxt971 = {
925 * read here to get a valid value in ack_int */ 940 * read here to get a valid value in ack_int */
926 { mk_mii_read(MII_REG_SR), mii_parse_sr }, 941 { mk_mii_read(MII_REG_SR), mii_parse_sr },
927 { mk_mii_end, } 942 { mk_mii_end, }
928 }, 943 };
929 (const phy_cmd_t []) { /* ack_int */ 944static phy_cmd_t const phy_cmd_lxt971_ack_int[] = {
945 /* acknowledge the int before reading status ! */
946 { mk_mii_read(MII_LXT971_ISR), NULL },
930 /* find out the current status */ 947 /* find out the current status */
931 { mk_mii_read(MII_REG_SR), mii_parse_sr }, 948 { mk_mii_read(MII_REG_SR), mii_parse_sr },
932 { mk_mii_read(MII_LXT971_SR2), mii_parse_lxt971_sr2 }, 949 { mk_mii_read(MII_LXT971_SR2), mii_parse_lxt971_sr2 },
933 /* we only need to read ISR to acknowledge */
934 { mk_mii_read(MII_LXT971_ISR), NULL },
935 { mk_mii_end, } 950 { mk_mii_end, }
936 }, 951 };
937 (const phy_cmd_t []) { /* shutdown - disable interrupts */ 952static phy_cmd_t const phy_cmd_lxt971_shutdown[] = { /* disable interrupts */
938 { mk_mii_write(MII_LXT971_IER, 0x0000), NULL }, 953 { mk_mii_write(MII_LXT971_IER, 0x0000), NULL },
939 { mk_mii_end, } 954 { mk_mii_end, }
940 }, 955 };
956static phy_info_t const phy_info_lxt971 = {
957 .id = 0x0001378e,
958 .name = "LXT971",
959 .config = phy_cmd_lxt971_config,
960 .startup = phy_cmd_lxt971_startup,
961 .ack_int = phy_cmd_lxt971_ack_int,
962 .shutdown = phy_cmd_lxt971_shutdown
941}; 963};
942 964
943/* ------------------------------------------------------------------------- */ 965/* ------------------------------------------------------------------------- */
@@ -956,22 +978,21 @@ static void mii_parse_qs6612_pcr(uint mii_reg, struct net_device *dev)
956{ 978{
957 struct fec_enet_private *fep = netdev_priv(dev); 979 struct fec_enet_private *fep = netdev_priv(dev);
958 volatile uint *s = &(fep->phy_status); 980 volatile uint *s = &(fep->phy_status);
981 uint status;
959 982
960 *s &= ~(PHY_STAT_SPMASK); 983 status = *s & ~(PHY_STAT_SPMASK);
961 984
962 switch((mii_reg >> 2) & 7) { 985 switch((mii_reg >> 2) & 7) {
963 case 1: *s |= PHY_STAT_10HDX; break; 986 case 1: status |= PHY_STAT_10HDX; break;
964 case 2: *s |= PHY_STAT_100HDX; break; 987 case 2: status |= PHY_STAT_100HDX; break;
965 case 5: *s |= PHY_STAT_10FDX; break; 988 case 5: status |= PHY_STAT_10FDX; break;
966 case 6: *s |= PHY_STAT_100FDX; break; 989 case 6: status |= PHY_STAT_100FDX; break;
967 }
968} 990}
969 991
970static phy_info_t phy_info_qs6612 = { 992 *s = status;
971 0x00181440, 993}
972 "QS6612", 994
973 995static phy_cmd_t const phy_cmd_qs6612_config[] = {
974 (const phy_cmd_t []) { /* config */
975 /* The PHY powers up isolated on the RPX, 996 /* The PHY powers up isolated on the RPX,
976 * so send a command to allow operation. 997 * so send a command to allow operation.
977 */ 998 */
@@ -981,13 +1002,13 @@ static phy_info_t phy_info_qs6612 = {
981 { mk_mii_read(MII_REG_CR), mii_parse_cr }, 1002 { mk_mii_read(MII_REG_CR), mii_parse_cr },
982 { mk_mii_read(MII_REG_ANAR), mii_parse_anar }, 1003 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
983 { mk_mii_end, } 1004 { mk_mii_end, }
984 }, 1005 };
985 (const phy_cmd_t []) { /* startup - enable interrupts */ 1006static phy_cmd_t const phy_cmd_qs6612_startup[] = { /* enable interrupts */
986 { mk_mii_write(MII_QS6612_IMR, 0x003a), NULL }, 1007 { mk_mii_write(MII_QS6612_IMR, 0x003a), NULL },
987 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */ 1008 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
988 { mk_mii_end, } 1009 { mk_mii_end, }
989 }, 1010 };
990 (const phy_cmd_t []) { /* ack_int */ 1011static phy_cmd_t const phy_cmd_qs6612_ack_int[] = {
991 /* we need to read ISR, SR and ANER to acknowledge */ 1012 /* we need to read ISR, SR and ANER to acknowledge */
992 { mk_mii_read(MII_QS6612_ISR), NULL }, 1013 { mk_mii_read(MII_QS6612_ISR), NULL },
993 { mk_mii_read(MII_REG_SR), mii_parse_sr }, 1014 { mk_mii_read(MII_REG_SR), mii_parse_sr },
@@ -996,11 +1017,18 @@ static phy_info_t phy_info_qs6612 = {
996 /* read pcr to get info */ 1017 /* read pcr to get info */
997 { mk_mii_read(MII_QS6612_PCR), mii_parse_qs6612_pcr }, 1018 { mk_mii_read(MII_QS6612_PCR), mii_parse_qs6612_pcr },
998 { mk_mii_end, } 1019 { mk_mii_end, }
999 }, 1020 };
1000 (const phy_cmd_t []) { /* shutdown - disable interrupts */ 1021static phy_cmd_t const phy_cmd_qs6612_shutdown[] = { /* disable interrupts */
1001 { mk_mii_write(MII_QS6612_IMR, 0x0000), NULL }, 1022 { mk_mii_write(MII_QS6612_IMR, 0x0000), NULL },
1002 { mk_mii_end, } 1023 { mk_mii_end, }
1003 }, 1024 };
1025static phy_info_t const phy_info_qs6612 = {
1026 .id = 0x00181440,
1027 .name = "QS6612",
1028 .config = phy_cmd_qs6612_config,
1029 .startup = phy_cmd_qs6612_startup,
1030 .ack_int = phy_cmd_qs6612_ack_int,
1031 .shutdown = phy_cmd_qs6612_shutdown
1004}; 1032};
1005 1033
1006/* ------------------------------------------------------------------------- */ 1034/* ------------------------------------------------------------------------- */
@@ -1020,49 +1048,54 @@ static void mii_parse_am79c874_dr(uint mii_reg, struct net_device *dev)
1020{ 1048{
1021 struct fec_enet_private *fep = netdev_priv(dev); 1049 struct fec_enet_private *fep = netdev_priv(dev);
1022 volatile uint *s = &(fep->phy_status); 1050 volatile uint *s = &(fep->phy_status);
1051 uint status;
1023 1052
1024 *s &= ~(PHY_STAT_SPMASK | PHY_STAT_ANC); 1053 status = *s & ~(PHY_STAT_SPMASK | PHY_STAT_ANC);
1025 1054
1026 if (mii_reg & 0x0080) 1055 if (mii_reg & 0x0080)
1027 *s |= PHY_STAT_ANC; 1056 status |= PHY_STAT_ANC;
1028 if (mii_reg & 0x0400) 1057 if (mii_reg & 0x0400)
1029 *s |= ((mii_reg & 0x0800) ? PHY_STAT_100FDX : PHY_STAT_100HDX); 1058 status |= ((mii_reg & 0x0800) ? PHY_STAT_100FDX : PHY_STAT_100HDX);
1030 else 1059 else
1031 *s |= ((mii_reg & 0x0800) ? PHY_STAT_10FDX : PHY_STAT_10HDX); 1060 status |= ((mii_reg & 0x0800) ? PHY_STAT_10FDX : PHY_STAT_10HDX);
1061
1062 *s = status;
1032} 1063}
1033 1064
1034static phy_info_t phy_info_am79c874 = { 1065static phy_cmd_t const phy_cmd_am79c874_config[] = {
1035 0x00022561,
1036 "AM79C874",
1037
1038 (const phy_cmd_t []) { /* config */
1039 /* limit to 10MBit because my protorype board
1040 * doesn't work with 100. */
1041 { mk_mii_read(MII_REG_CR), mii_parse_cr }, 1066 { mk_mii_read(MII_REG_CR), mii_parse_cr },
1042 { mk_mii_read(MII_REG_ANAR), mii_parse_anar }, 1067 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
1043 { mk_mii_read(MII_AM79C874_DR), mii_parse_am79c874_dr }, 1068 { mk_mii_read(MII_AM79C874_DR), mii_parse_am79c874_dr },
1044 { mk_mii_end, } 1069 { mk_mii_end, }
1045 }, 1070 };
1046 (const phy_cmd_t []) { /* startup - enable interrupts */ 1071static phy_cmd_t const phy_cmd_am79c874_startup[] = { /* enable interrupts */
1047 { mk_mii_write(MII_AM79C874_ICSR, 0xff00), NULL }, 1072 { mk_mii_write(MII_AM79C874_ICSR, 0xff00), NULL },
1048 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */ 1073 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
1049 { mk_mii_read(MII_REG_SR), mii_parse_sr }, 1074 { mk_mii_read(MII_REG_SR), mii_parse_sr },
1050 { mk_mii_end, } 1075 { mk_mii_end, }
1051 }, 1076 };
1052 (const phy_cmd_t []) { /* ack_int */ 1077static phy_cmd_t const phy_cmd_am79c874_ack_int[] = {
1053 /* find out the current status */ 1078 /* find out the current status */
1054 { mk_mii_read(MII_REG_SR), mii_parse_sr }, 1079 { mk_mii_read(MII_REG_SR), mii_parse_sr },
1055 { mk_mii_read(MII_AM79C874_DR), mii_parse_am79c874_dr }, 1080 { mk_mii_read(MII_AM79C874_DR), mii_parse_am79c874_dr },
1056 /* we only need to read ISR to acknowledge */ 1081 /* we only need to read ISR to acknowledge */
1057 { mk_mii_read(MII_AM79C874_ICSR), NULL }, 1082 { mk_mii_read(MII_AM79C874_ICSR), NULL },
1058 { mk_mii_end, } 1083 { mk_mii_end, }
1059 }, 1084 };
1060 (const phy_cmd_t []) { /* shutdown - disable interrupts */ 1085static phy_cmd_t const phy_cmd_am79c874_shutdown[] = { /* disable interrupts */
1061 { mk_mii_write(MII_AM79C874_ICSR, 0x0000), NULL }, 1086 { mk_mii_write(MII_AM79C874_ICSR, 0x0000), NULL },
1062 { mk_mii_end, } 1087 { mk_mii_end, }
1063 }, 1088 };
1089static phy_info_t const phy_info_am79c874 = {
1090 .id = 0x00022561,
1091 .name = "AM79C874",
1092 .config = phy_cmd_am79c874_config,
1093 .startup = phy_cmd_am79c874_startup,
1094 .ack_int = phy_cmd_am79c874_ack_int,
1095 .shutdown = phy_cmd_am79c874_shutdown
1064}; 1096};
1065 1097
1098
1066/* ------------------------------------------------------------------------- */ 1099/* ------------------------------------------------------------------------- */
1067/* Kendin KS8721BL phy */ 1100/* Kendin KS8721BL phy */
1068 1101
@@ -1072,37 +1105,40 @@ static phy_info_t phy_info_am79c874 = {
1072#define MII_KS8721BL_ICSR 22 1105#define MII_KS8721BL_ICSR 22
1073#define MII_KS8721BL_PHYCR 31 1106#define MII_KS8721BL_PHYCR 31
1074 1107
1075static phy_info_t phy_info_ks8721bl = { 1108static phy_cmd_t const phy_cmd_ks8721bl_config[] = {
1076 0x00022161,
1077 "KS8721BL",
1078
1079 (const phy_cmd_t []) { /* config */
1080 { mk_mii_read(MII_REG_CR), mii_parse_cr }, 1109 { mk_mii_read(MII_REG_CR), mii_parse_cr },
1081 { mk_mii_read(MII_REG_ANAR), mii_parse_anar }, 1110 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
1082 { mk_mii_end, } 1111 { mk_mii_end, }
1083 }, 1112 };
1084 (const phy_cmd_t []) { /* startup */ 1113static phy_cmd_t const phy_cmd_ks8721bl_startup[] = { /* enable interrupts */
1085 { mk_mii_write(MII_KS8721BL_ICSR, 0xff00), NULL }, 1114 { mk_mii_write(MII_KS8721BL_ICSR, 0xff00), NULL },
1086 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */ 1115 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
1087 { mk_mii_read(MII_REG_SR), mii_parse_sr }, 1116 { mk_mii_read(MII_REG_SR), mii_parse_sr },
1088 { mk_mii_end, } 1117 { mk_mii_end, }
1089 }, 1118 };
1090 (const phy_cmd_t []) { /* ack_int */ 1119static phy_cmd_t const phy_cmd_ks8721bl_ack_int[] = {
1091 /* find out the current status */ 1120 /* find out the current status */
1092 { mk_mii_read(MII_REG_SR), mii_parse_sr }, 1121 { mk_mii_read(MII_REG_SR), mii_parse_sr },
1093 /* we only need to read ISR to acknowledge */ 1122 /* we only need to read ISR to acknowledge */
1094 { mk_mii_read(MII_KS8721BL_ICSR), NULL }, 1123 { mk_mii_read(MII_KS8721BL_ICSR), NULL },
1095 { mk_mii_end, } 1124 { mk_mii_end, }
1096 }, 1125 };
1097 (const phy_cmd_t []) { /* shutdown */ 1126static phy_cmd_t const phy_cmd_ks8721bl_shutdown[] = { /* disable interrupts */
1098 { mk_mii_write(MII_KS8721BL_ICSR, 0x0000), NULL }, 1127 { mk_mii_write(MII_KS8721BL_ICSR, 0x0000), NULL },
1099 { mk_mii_end, } 1128 { mk_mii_end, }
1100 }, 1129 };
1130static phy_info_t const phy_info_ks8721bl = {
1131 .id = 0x00022161,
1132 .name = "KS8721BL",
1133 .config = phy_cmd_ks8721bl_config,
1134 .startup = phy_cmd_ks8721bl_startup,
1135 .ack_int = phy_cmd_ks8721bl_ack_int,
1136 .shutdown = phy_cmd_ks8721bl_shutdown
1101}; 1137};
1102 1138
1103/* ------------------------------------------------------------------------- */ 1139/* ------------------------------------------------------------------------- */
1104 1140
1105static phy_info_t *phy_info[] = { 1141static phy_info_t const * const phy_info[] = {
1106 &phy_info_lxt970, 1142 &phy_info_lxt970,
1107 &phy_info_lxt971, 1143 &phy_info_lxt971,
1108 &phy_info_qs6612, 1144 &phy_info_qs6612,
@@ -1129,16 +1165,23 @@ mii_link_interrupt(int irq, void * dev_id, struct pt_regs * regs);
1129static void __inline__ fec_request_intrs(struct net_device *dev) 1165static void __inline__ fec_request_intrs(struct net_device *dev)
1130{ 1166{
1131 volatile unsigned long *icrp; 1167 volatile unsigned long *icrp;
1168 static const struct idesc {
1169 char *name;
1170 unsigned short irq;
1171 irqreturn_t (*handler)(int, void *, struct pt_regs *);
1172 } *idp, id[] = {
1173 { "fec(RX)", 86, fec_enet_interrupt },
1174 { "fec(TX)", 87, fec_enet_interrupt },
1175 { "fec(OTHER)", 88, fec_enet_interrupt },
1176 { "fec(MII)", 66, mii_link_interrupt },
1177 { NULL },
1178 };
1132 1179
1133 /* Setup interrupt handlers. */ 1180 /* Setup interrupt handlers. */
1134 if (request_irq(86, fec_enet_interrupt, 0, "fec(RX)", dev) != 0) 1181 for (idp = id; idp->name; idp++) {
1135 printk("FEC: Could not allocate FEC(RC) IRQ(86)!\n"); 1182 if (request_irq(idp->irq, idp->handler, 0, idp->name, dev) != 0)
1136 if (request_irq(87, fec_enet_interrupt, 0, "fec(TX)", dev) != 0) 1183 printk("FEC: Could not allocate %s IRQ(%d)!\n", idp->name, idp->irq);
1137 printk("FEC: Could not allocate FEC(RC) IRQ(87)!\n"); 1184 }
1138 if (request_irq(88, fec_enet_interrupt, 0, "fec(OTHER)", dev) != 0)
1139 printk("FEC: Could not allocate FEC(OTHER) IRQ(88)!\n");
1140 if (request_irq(66, mii_link_interrupt, 0, "fec(MII)", dev) != 0)
1141 printk("FEC: Could not allocate MII IRQ(66)!\n");
1142 1185
1143 /* Unmask interrupt at ColdFire 5272 SIM */ 1186 /* Unmask interrupt at ColdFire 5272 SIM */
1144 icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR3); 1187 icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR3);
@@ -1169,17 +1212,16 @@ static void __inline__ fec_get_mac(struct net_device *dev)
1169{ 1212{
1170 struct fec_enet_private *fep = netdev_priv(dev); 1213 struct fec_enet_private *fep = netdev_priv(dev);
1171 volatile fec_t *fecp; 1214 volatile fec_t *fecp;
1172 unsigned char *iap, tmpaddr[6]; 1215 unsigned char *iap, tmpaddr[ETH_ALEN];
1173 int i;
1174 1216
1175 fecp = fep->hwp; 1217 fecp = fep->hwp;
1176 1218
1177 if (fec_flashmac) { 1219 if (FEC_FLASHMAC) {
1178 /* 1220 /*
1179 * Get MAC address from FLASH. 1221 * Get MAC address from FLASH.
1180 * If it is all 1's or 0's, use the default. 1222 * If it is all 1's or 0's, use the default.
1181 */ 1223 */
1182 iap = fec_flashmac; 1224 iap = (unsigned char *)FEC_FLASHMAC;
1183 if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) && 1225 if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
1184 (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0)) 1226 (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
1185 iap = fec_mac_default; 1227 iap = fec_mac_default;
@@ -1192,14 +1234,11 @@ static void __inline__ fec_get_mac(struct net_device *dev)
1192 iap = &tmpaddr[0]; 1234 iap = &tmpaddr[0];
1193 } 1235 }
1194 1236
1195 for (i=0; i<ETH_ALEN; i++) 1237 memcpy(dev->dev_addr, iap, ETH_ALEN);
1196 dev->dev_addr[i] = fep->mac_addr[i] = *iap++;
1197 1238
1198 /* Adjust MAC if using default MAC address */ 1239 /* Adjust MAC if using default MAC address */
1199 if (iap == fec_mac_default) { 1240 if (iap == fec_mac_default)
1200 dev->dev_addr[ETH_ALEN-1] = fep->mac_addr[ETH_ALEN-1] = 1241 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
1201 iap[ETH_ALEN-1] + fep->index;
1202 }
1203} 1242}
1204 1243
1205static void __inline__ fec_enable_phy_intr(void) 1244static void __inline__ fec_enable_phy_intr(void)
@@ -1234,48 +1273,44 @@ static void __inline__ fec_uncache(unsigned long addr)
1234 1273
1235/* ------------------------------------------------------------------------- */ 1274/* ------------------------------------------------------------------------- */
1236 1275
1237#elif defined(CONFIG_M527x) || defined(CONFIG_M528x) 1276#elif defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
1238 1277
1239/* 1278/*
1240 * Code specific to Coldfire 5270/5271/5274/5275 and 5280/5282 setups. 1279 * Code specific to Coldfire 5230/5231/5232/5234/5235,
1280 * the 5270/5271/5274/5275 and 5280/5282 setups.
1241 */ 1281 */
1242static void __inline__ fec_request_intrs(struct net_device *dev) 1282static void __inline__ fec_request_intrs(struct net_device *dev)
1243{ 1283{
1244 struct fec_enet_private *fep; 1284 struct fec_enet_private *fep;
1245 int b; 1285 int b;
1286 static const struct idesc {
1287 char *name;
1288 unsigned short irq;
1289 } *idp, id[] = {
1290 { "fec(TXF)", 23 },
1291 { "fec(TXB)", 24 },
1292 { "fec(TXFIFO)", 25 },
1293 { "fec(TXCR)", 26 },
1294 { "fec(RXF)", 27 },
1295 { "fec(RXB)", 28 },
1296 { "fec(MII)", 29 },
1297 { "fec(LC)", 30 },
1298 { "fec(HBERR)", 31 },
1299 { "fec(GRA)", 32 },
1300 { "fec(EBERR)", 33 },
1301 { "fec(BABT)", 34 },
1302 { "fec(BABR)", 35 },
1303 { NULL },
1304 };
1246 1305
1247 fep = netdev_priv(dev); 1306 fep = netdev_priv(dev);
1248 b = (fep->index) ? 128 : 64; 1307 b = (fep->index) ? 128 : 64;
1249 1308
1250 /* Setup interrupt handlers. */ 1309 /* Setup interrupt handlers. */
1251 if (request_irq(b+23, fec_enet_interrupt, 0, "fec(TXF)", dev) != 0) 1310 for (idp = id; idp->name; idp++) {
1252 printk("FEC: Could not allocate FEC(TXF) IRQ(%d+23)!\n", b); 1311 if (request_irq(b+idp->irq, fec_enet_interrupt, 0, idp->name, dev) != 0)
1253 if (request_irq(b+24, fec_enet_interrupt, 0, "fec(TXB)", dev) != 0) 1312 printk("FEC: Could not allocate %s IRQ(%d)!\n", idp->name, b+idp->irq);
1254 printk("FEC: Could not allocate FEC(TXB) IRQ(%d+24)!\n", b); 1313 }
1255 if (request_irq(b+25, fec_enet_interrupt, 0, "fec(TXFIFO)", dev) != 0)
1256 printk("FEC: Could not allocate FEC(TXFIFO) IRQ(%d+25)!\n", b);
1257 if (request_irq(b+26, fec_enet_interrupt, 0, "fec(TXCR)", dev) != 0)
1258 printk("FEC: Could not allocate FEC(TXCR) IRQ(%d+26)!\n", b);
1259
1260 if (request_irq(b+27, fec_enet_interrupt, 0, "fec(RXF)", dev) != 0)
1261 printk("FEC: Could not allocate FEC(RXF) IRQ(%d+27)!\n", b);
1262 if (request_irq(b+28, fec_enet_interrupt, 0, "fec(RXB)", dev) != 0)
1263 printk("FEC: Could not allocate FEC(RXB) IRQ(%d+28)!\n", b);
1264
1265 if (request_irq(b+29, fec_enet_interrupt, 0, "fec(MII)", dev) != 0)
1266 printk("FEC: Could not allocate FEC(MII) IRQ(%d+29)!\n", b);
1267 if (request_irq(b+30, fec_enet_interrupt, 0, "fec(LC)", dev) != 0)
1268 printk("FEC: Could not allocate FEC(LC) IRQ(%d+30)!\n", b);
1269 if (request_irq(b+31, fec_enet_interrupt, 0, "fec(HBERR)", dev) != 0)
1270 printk("FEC: Could not allocate FEC(HBERR) IRQ(%d+31)!\n", b);
1271 if (request_irq(b+32, fec_enet_interrupt, 0, "fec(GRA)", dev) != 0)
1272 printk("FEC: Could not allocate FEC(GRA) IRQ(%d+32)!\n", b);
1273 if (request_irq(b+33, fec_enet_interrupt, 0, "fec(EBERR)", dev) != 0)
1274 printk("FEC: Could not allocate FEC(EBERR) IRQ(%d+33)!\n", b);
1275 if (request_irq(b+34, fec_enet_interrupt, 0, "fec(BABT)", dev) != 0)
1276 printk("FEC: Could not allocate FEC(BABT) IRQ(%d+34)!\n", b);
1277 if (request_irq(b+35, fec_enet_interrupt, 0, "fec(BABR)", dev) != 0)
1278 printk("FEC: Could not allocate FEC(BABR) IRQ(%d+35)!\n", b);
1279 1314
1280 /* Unmask interrupts at ColdFire 5280/5282 interrupt controller */ 1315 /* Unmask interrupts at ColdFire 5280/5282 interrupt controller */
1281 { 1316 {
@@ -1300,11 +1335,13 @@ static void __inline__ fec_request_intrs(struct net_device *dev)
1300#if defined(CONFIG_M528x) 1335#if defined(CONFIG_M528x)
1301 /* Set up gpio outputs for MII lines */ 1336 /* Set up gpio outputs for MII lines */
1302 { 1337 {
1303 volatile unsigned short *gpio_paspar; 1338 volatile u16 *gpio_paspar;
1339 volatile u8 *gpio_pehlpar;
1304 1340
1305 gpio_paspar = (volatile unsigned short *) (MCF_IPSBAR + 1341 gpio_paspar = (volatile u16 *) (MCF_IPSBAR + 0x100056);
1306 0x100056); 1342 gpio_pehlpar = (volatile u16 *) (MCF_IPSBAR + 0x100058);
1307 *gpio_paspar = 0x0f00; 1343 *gpio_paspar |= 0x0f00;
1344 *gpio_pehlpar = 0xc0;
1308 } 1345 }
1309#endif 1346#endif
1310} 1347}
@@ -1331,17 +1368,16 @@ static void __inline__ fec_get_mac(struct net_device *dev)
1331{ 1368{
1332 struct fec_enet_private *fep = netdev_priv(dev); 1369 struct fec_enet_private *fep = netdev_priv(dev);
1333 volatile fec_t *fecp; 1370 volatile fec_t *fecp;
1334 unsigned char *iap, tmpaddr[6]; 1371 unsigned char *iap, tmpaddr[ETH_ALEN];
1335 int i;
1336 1372
1337 fecp = fep->hwp; 1373 fecp = fep->hwp;
1338 1374
1339 if (fec_flashmac) { 1375 if (FEC_FLASHMAC) {
1340 /* 1376 /*
1341 * Get MAC address from FLASH. 1377 * Get MAC address from FLASH.
1342 * If it is all 1's or 0's, use the default. 1378 * If it is all 1's or 0's, use the default.
1343 */ 1379 */
1344 iap = fec_flashmac; 1380 iap = FEC_FLASHMAC;
1345 if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) && 1381 if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
1346 (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0)) 1382 (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
1347 iap = fec_mac_default; 1383 iap = fec_mac_default;
@@ -1354,14 +1390,11 @@ static void __inline__ fec_get_mac(struct net_device *dev)
1354 iap = &tmpaddr[0]; 1390 iap = &tmpaddr[0];
1355 } 1391 }
1356 1392
1357 for (i=0; i<ETH_ALEN; i++) 1393 memcpy(dev->dev_addr, iap, ETH_ALEN);
1358 dev->dev_addr[i] = fep->mac_addr[i] = *iap++;
1359 1394
1360 /* Adjust MAC if using default MAC address */ 1395 /* Adjust MAC if using default MAC address */
1361 if (iap == fec_mac_default) { 1396 if (iap == fec_mac_default)
1362 dev->dev_addr[ETH_ALEN-1] = fep->mac_addr[ETH_ALEN-1] = 1397 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
1363 iap[ETH_ALEN-1] + fep->index;
1364 }
1365} 1398}
1366 1399
1367static void __inline__ fec_enable_phy_intr(void) 1400static void __inline__ fec_enable_phy_intr(void)
@@ -1392,7 +1425,7 @@ static void __inline__ fec_uncache(unsigned long addr)
1392#else 1425#else
1393 1426
1394/* 1427/*
1395 * Code sepcific to the MPC860T setup. 1428 * Code specific to the MPC860T setup.
1396 */ 1429 */
1397static void __inline__ fec_request_intrs(struct net_device *dev) 1430static void __inline__ fec_request_intrs(struct net_device *dev)
1398{ 1431{
@@ -1424,13 +1457,10 @@ static void __inline__ fec_request_intrs(struct net_device *dev)
1424 1457
1425static void __inline__ fec_get_mac(struct net_device *dev) 1458static void __inline__ fec_get_mac(struct net_device *dev)
1426{ 1459{
1427 struct fec_enet_private *fep = netdev_priv(dev);
1428 unsigned char *iap, tmpaddr[6];
1429 bd_t *bd; 1460 bd_t *bd;
1430 int i;
1431 1461
1432 iap = bd->bi_enetaddr;
1433 bd = (bd_t *)__res; 1462 bd = (bd_t *)__res;
1463 memcpy(dev->dev_addr, bd->bi_enetaddr, ETH_ALEN);
1434 1464
1435#ifdef CONFIG_RPXCLASSIC 1465#ifdef CONFIG_RPXCLASSIC
1436 /* The Embedded Planet boards have only one MAC address in 1466 /* The Embedded Planet boards have only one MAC address in
@@ -1439,14 +1469,8 @@ static void __inline__ fec_get_mac(struct net_device *dev)
1439 * the address bits above something that would have (up to 1469 * the address bits above something that would have (up to
1440 * now) been allocated. 1470 * now) been allocated.
1441 */ 1471 */
1442 for (i=0; i<6; i++) 1472 dev->dev_adrd[3] |= 0x80;
1443 tmpaddr[i] = *iap++;
1444 tmpaddr[3] |= 0x80;
1445 iap = tmpaddr;
1446#endif 1473#endif
1447
1448 for (i=0; i<6; i++)
1449 dev->dev_addr[i] = fep->mac_addr[i] = *iap++;
1450} 1474}
1451 1475
1452static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep) 1476static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
@@ -1556,7 +1580,7 @@ static void mii_display_status(struct net_device *dev)
1556static void mii_display_config(struct net_device *dev) 1580static void mii_display_config(struct net_device *dev)
1557{ 1581{
1558 struct fec_enet_private *fep = netdev_priv(dev); 1582 struct fec_enet_private *fep = netdev_priv(dev);
1559 volatile uint *s = &(fep->phy_status); 1583 uint status = fep->phy_status;
1560 1584
1561 /* 1585 /*
1562 ** When we get here, phy_task is already removed from 1586 ** When we get here, phy_task is already removed from
@@ -1565,23 +1589,23 @@ static void mii_display_config(struct net_device *dev)
1565 fep->mii_phy_task_queued = 0; 1589 fep->mii_phy_task_queued = 0;
1566 printk("%s: config: auto-negotiation ", dev->name); 1590 printk("%s: config: auto-negotiation ", dev->name);
1567 1591
1568 if (*s & PHY_CONF_ANE) 1592 if (status & PHY_CONF_ANE)
1569 printk("on"); 1593 printk("on");
1570 else 1594 else
1571 printk("off"); 1595 printk("off");
1572 1596
1573 if (*s & PHY_CONF_100FDX) 1597 if (status & PHY_CONF_100FDX)
1574 printk(", 100FDX"); 1598 printk(", 100FDX");
1575 if (*s & PHY_CONF_100HDX) 1599 if (status & PHY_CONF_100HDX)
1576 printk(", 100HDX"); 1600 printk(", 100HDX");
1577 if (*s & PHY_CONF_10FDX) 1601 if (status & PHY_CONF_10FDX)
1578 printk(", 10FDX"); 1602 printk(", 10FDX");
1579 if (*s & PHY_CONF_10HDX) 1603 if (status & PHY_CONF_10HDX)
1580 printk(", 10HDX"); 1604 printk(", 10HDX");
1581 if (!(*s & PHY_CONF_SPMASK)) 1605 if (!(status & PHY_CONF_SPMASK))
1582 printk(", No speed/duplex selected?"); 1606 printk(", No speed/duplex selected?");
1583 1607
1584 if (*s & PHY_CONF_LOOP) 1608 if (status & PHY_CONF_LOOP)
1585 printk(", loopback enabled"); 1609 printk(", loopback enabled");
1586 1610
1587 printk(".\n"); 1611 printk(".\n");
@@ -1639,7 +1663,7 @@ static void mii_queue_relink(uint mii_reg, struct net_device *dev)
1639 schedule_work(&fep->phy_task); 1663 schedule_work(&fep->phy_task);
1640} 1664}
1641 1665
1642/* mii_queue_config is called in user context from fec_enet_open */ 1666/* mii_queue_config is called in interrupt context from fec_enet_mii */
1643static void mii_queue_config(uint mii_reg, struct net_device *dev) 1667static void mii_queue_config(uint mii_reg, struct net_device *dev)
1644{ 1668{
1645 struct fec_enet_private *fep = netdev_priv(dev); 1669 struct fec_enet_private *fep = netdev_priv(dev);
@@ -1652,14 +1676,14 @@ static void mii_queue_config(uint mii_reg, struct net_device *dev)
1652 schedule_work(&fep->phy_task); 1676 schedule_work(&fep->phy_task);
1653} 1677}
1654 1678
1655 1679phy_cmd_t const phy_cmd_relink[] = {
1656 1680 { mk_mii_read(MII_REG_CR), mii_queue_relink },
1657phy_cmd_t phy_cmd_relink[] = { { mk_mii_read(MII_REG_CR), mii_queue_relink }, 1681 { mk_mii_end, }
1658 { mk_mii_end, } }; 1682 };
1659phy_cmd_t phy_cmd_config[] = { { mk_mii_read(MII_REG_CR), mii_queue_config }, 1683phy_cmd_t const phy_cmd_config[] = {
1660 { mk_mii_end, } }; 1684 { mk_mii_read(MII_REG_CR), mii_queue_config },
1661 1685 { mk_mii_end, }
1662 1686 };
1663 1687
1664/* Read remainder of PHY ID. 1688/* Read remainder of PHY ID.
1665*/ 1689*/
@@ -1897,17 +1921,15 @@ static void set_multicast_list(struct net_device *dev)
1897static void 1921static void
1898fec_set_mac_address(struct net_device *dev) 1922fec_set_mac_address(struct net_device *dev)
1899{ 1923{
1900 struct fec_enet_private *fep;
1901 volatile fec_t *fecp; 1924 volatile fec_t *fecp;
1902 1925
1903 fep = netdev_priv(dev); 1926 fecp = ((struct fec_enet_private *)netdev_priv(dev))->hwp;
1904 fecp = fep->hwp;
1905 1927
1906 /* Set station address. */ 1928 /* Set station address. */
1907 fecp->fec_addr_low = fep->mac_addr[3] | (fep->mac_addr[2] << 8) | 1929 fecp->fec_addr_low = dev->dev_addr[3] | (dev->dev_addr[2] << 8) |
1908 (fep->mac_addr[1] << 16) | (fep->mac_addr[0] << 24); 1930 (dev->dev_addr[1] << 16) | (dev->dev_addr[0] << 24);
1909 fecp->fec_addr_high = (fep->mac_addr[5] << 16) | 1931 fecp->fec_addr_high = (dev->dev_addr[5] << 16) |
1910 (fep->mac_addr[4] << 24); 1932 (dev->dev_addr[4] << 24);
1911 1933
1912} 1934}
1913 1935
@@ -1943,7 +1965,7 @@ int __init fec_enet_init(struct net_device *dev)
1943 udelay(10); 1965 udelay(10);
1944 1966
1945 /* Clear and enable interrupts */ 1967 /* Clear and enable interrupts */
1946 fecp->fec_ievent = 0xffc0; 1968 fecp->fec_ievent = 0xffc00000;
1947 fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_TXB | 1969 fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_TXB |
1948 FEC_ENET_RXF | FEC_ENET_RXB | FEC_ENET_MII); 1970 FEC_ENET_RXF | FEC_ENET_RXB | FEC_ENET_MII);
1949 fecp->fec_hash_table_high = 0; 1971 fecp->fec_hash_table_high = 0;
@@ -2063,11 +2085,6 @@ int __init fec_enet_init(struct net_device *dev)
2063 /* setup MII interface */ 2085 /* setup MII interface */
2064 fec_set_mii(dev, fep); 2086 fec_set_mii(dev, fep);
2065 2087
2066 printk("%s: FEC ENET Version 0.2, ", dev->name);
2067 for (i=0; i<5; i++)
2068 printk("%02x:", dev->dev_addr[i]);
2069 printk("%02x\n", dev->dev_addr[5]);
2070
2071 /* Queue up command to detect the PHY and initialize the 2088 /* Queue up command to detect the PHY and initialize the
2072 * remainder of the interface. 2089 * remainder of the interface.
2073 */ 2090 */
@@ -2106,18 +2123,12 @@ fec_restart(struct net_device *dev, int duplex)
2106 2123
2107 /* Clear any outstanding interrupt. 2124 /* Clear any outstanding interrupt.
2108 */ 2125 */
2109 fecp->fec_ievent = 0xffc0; 2126 fecp->fec_ievent = 0xffc00000;
2110 fec_enable_phy_intr(); 2127 fec_enable_phy_intr();
2111 2128
2112 /* Set station address. 2129 /* Set station address.
2113 */ 2130 */
2114 fecp->fec_addr_low = fep->mac_addr[3] | (fep->mac_addr[2] << 8) | 2131 fec_set_mac_address(dev);
2115 (fep->mac_addr[1] << 16) | (fep->mac_addr[0] << 24);
2116 fecp->fec_addr_high = (fep->mac_addr[5] << 16) |
2117 (fep->mac_addr[4] << 24);
2118
2119 for (i=0; i<ETH_ALEN; i++)
2120 dev->dev_addr[i] = fep->mac_addr[i];
2121 2132
2122 /* Reset all multicast. 2133 /* Reset all multicast.
2123 */ 2134 */
@@ -2215,7 +2226,7 @@ fec_stop(struct net_device *dev)
2215 2226
2216 fecp->fec_x_cntrl = 0x01; /* Graceful transmit stop */ 2227 fecp->fec_x_cntrl = 0x01; /* Graceful transmit stop */
2217 2228
2218 while(!(fecp->fec_ievent & 0x10000000)); 2229 while(!(fecp->fec_ievent & FEC_ENET_GRA));
2219 2230
2220 /* Whack a reset. We should wait for this. 2231 /* Whack a reset. We should wait for this.
2221 */ 2232 */
@@ -2234,7 +2245,9 @@ fec_stop(struct net_device *dev)
2234static int __init fec_enet_module_init(void) 2245static int __init fec_enet_module_init(void)
2235{ 2246{
2236 struct net_device *dev; 2247 struct net_device *dev;
2237 int i, err; 2248 int i, j, err;
2249
2250 printk("FEC ENET Version 0.2\n");
2238 2251
2239 for (i = 0; (i < FEC_MAX_PORTS); i++) { 2252 for (i = 0; (i < FEC_MAX_PORTS); i++) {
2240 dev = alloc_etherdev(sizeof(struct fec_enet_private)); 2253 dev = alloc_etherdev(sizeof(struct fec_enet_private));
@@ -2250,6 +2263,11 @@ static int __init fec_enet_module_init(void)
2250 free_netdev(dev); 2263 free_netdev(dev);
2251 return -EIO; 2264 return -EIO;
2252 } 2265 }
2266
2267 printk("%s: ethernet ", dev->name);
2268 for (j = 0; (j < 5); j++)
2269 printk("%02x:", dev->dev_addr[j]);
2270 printk("%02x\n", dev->dev_addr[5]);
2253 } 2271 }
2254 return 0; 2272 return 0;
2255} 2273}
diff --git a/drivers/net/fec.h b/drivers/net/fec.h
index c6e4f979ff..045761b8a6 100644
--- a/drivers/net/fec.h
+++ b/drivers/net/fec.h
@@ -1,8 +1,9 @@
1/****************************************************************************/ 1/****************************************************************************/
2 2
3/* 3/*
4 * fec.h -- Fast Ethernet Controller for Motorola ColdFire 5270, 4 * fec.h -- Fast Ethernet Controller for Motorola ColdFire 5230,
5 5271, 5272, 5274, 5275, 5280 and 5282. 5 * 5231, 5232, 5234, 5235, 5270, 5271, 5272, 5274, 5275,
6 * 5280 and 5282.
6 * 7 *
7 * (C) Copyright 2000-2003, Greg Ungerer (gerg@snapgear.com) 8 * (C) Copyright 2000-2003, Greg Ungerer (gerg@snapgear.com)
8 * (C) Copyright 2000-2001, Lineo (www.lineo.com) 9 * (C) Copyright 2000-2001, Lineo (www.lineo.com)
@@ -13,7 +14,7 @@
13#define FEC_H 14#define FEC_H
14/****************************************************************************/ 15/****************************************************************************/
15 16
16#if defined(CONFIG_M527x) || defined(CONFIG_M528x) 17#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
17/* 18/*
18 * Just figures, Motorola would have to change the offsets for 19 * Just figures, Motorola would have to change the offsets for
19 * registers in the same peripheral device on different models 20 * registers in the same peripheral device on different models
diff --git a/drivers/net/hamradio/yam.c b/drivers/net/hamradio/yam.c
index 41213ef602..f52ee3162c 100644
--- a/drivers/net/hamradio/yam.c
+++ b/drivers/net/hamradio/yam.c
@@ -170,7 +170,7 @@ static char ax25_bcast[7] =
170static char ax25_test[7] = 170static char ax25_test[7] =
171{'L' << 1, 'I' << 1, 'N' << 1, 'U' << 1, 'X' << 1, ' ' << 1, '1' << 1}; 171{'L' << 1, 'I' << 1, 'N' << 1, 'U' << 1, 'X' << 1, ' ' << 1, '1' << 1};
172 172
173static struct timer_list yam_timer = TIMER_INITIALIZER(NULL, 0, 0); 173static DEFINE_TIMER(yam_timer, NULL, 0, 0);
174 174
175/* --------------------------------------------------------------------- */ 175/* --------------------------------------------------------------------- */
176 176
diff --git a/drivers/net/mv643xx_eth.c b/drivers/net/mv643xx_eth.c
index 7c9dbc8c94..25c9a99c37 100644
--- a/drivers/net/mv643xx_eth.c
+++ b/drivers/net/mv643xx_eth.c
@@ -94,7 +94,7 @@ static char mv643xx_driver_version[] = "1.0";
94static void __iomem *mv643xx_eth_shared_base; 94static void __iomem *mv643xx_eth_shared_base;
95 95
96/* used to protect MV643XX_ETH_SMI_REG, which is shared across ports */ 96/* used to protect MV643XX_ETH_SMI_REG, which is shared across ports */
97static spinlock_t mv643xx_eth_phy_lock = SPIN_LOCK_UNLOCKED; 97static DEFINE_SPINLOCK(mv643xx_eth_phy_lock);
98 98
99static inline u32 mv_read(int offset) 99static inline u32 mv_read(int offset)
100{ 100{
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index bb71638a7c..0df7e92b0b 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -1232,9 +1232,7 @@ static int ppp_mp_explode(struct ppp *ppp, struct sk_buff *skb)
1232 navail = 0; /* total # of usable channels (not deregistered) */ 1232 navail = 0; /* total # of usable channels (not deregistered) */
1233 hdrlen = (ppp->flags & SC_MP_XSHORTSEQ)? MPHDRLEN_SSN: MPHDRLEN; 1233 hdrlen = (ppp->flags & SC_MP_XSHORTSEQ)? MPHDRLEN_SSN: MPHDRLEN;
1234 i = 0; 1234 i = 0;
1235 list = &ppp->channels; 1235 list_for_each_entry(pch, &ppp->channels, clist) {
1236 while ((list = list->next) != &ppp->channels) {
1237 pch = list_entry(list, struct channel, clist);
1238 navail += pch->avail = (pch->chan != NULL); 1236 navail += pch->avail = (pch->chan != NULL);
1239 if (pch->avail) { 1237 if (pch->avail) {
1240 if (skb_queue_empty(&pch->file.xq) || 1238 if (skb_queue_empty(&pch->file.xq) ||
@@ -1280,6 +1278,7 @@ static int ppp_mp_explode(struct ppp *ppp, struct sk_buff *skb)
1280 1278
1281 /* skip to the channel after the one we last used 1279 /* skip to the channel after the one we last used
1282 and start at that one */ 1280 and start at that one */
1281 list = &ppp->channels;
1283 for (i = 0; i < ppp->nxchan; ++i) { 1282 for (i = 0; i < ppp->nxchan; ++i) {
1284 list = list->next; 1283 list = list->next;
1285 if (list == &ppp->channels) { 1284 if (list == &ppp->channels) {
@@ -1730,7 +1729,7 @@ static void
1730ppp_receive_mp_frame(struct ppp *ppp, struct sk_buff *skb, struct channel *pch) 1729ppp_receive_mp_frame(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
1731{ 1730{
1732 u32 mask, seq; 1731 u32 mask, seq;
1733 struct list_head *l; 1732 struct channel *ch;
1734 int mphdrlen = (ppp->flags & SC_MP_SHORTSEQ)? MPHDRLEN_SSN: MPHDRLEN; 1733 int mphdrlen = (ppp->flags & SC_MP_SHORTSEQ)? MPHDRLEN_SSN: MPHDRLEN;
1735 1734
1736 if (!pskb_may_pull(skb, mphdrlen) || ppp->mrru == 0) 1735 if (!pskb_may_pull(skb, mphdrlen) || ppp->mrru == 0)
@@ -1784,8 +1783,7 @@ ppp_receive_mp_frame(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
1784 * The list of channels can't change because we have the receive 1783 * The list of channels can't change because we have the receive
1785 * side of the ppp unit locked. 1784 * side of the ppp unit locked.
1786 */ 1785 */
1787 for (l = ppp->channels.next; l != &ppp->channels; l = l->next) { 1786 list_for_each_entry(ch, &ppp->channels, clist) {
1788 struct channel *ch = list_entry(l, struct channel, clist);
1789 if (seq_before(ch->lastseq, seq)) 1787 if (seq_before(ch->lastseq, seq))
1790 seq = ch->lastseq; 1788 seq = ch->lastseq;
1791 } 1789 }
@@ -2271,10 +2269,8 @@ static struct compressor_entry *
2271find_comp_entry(int proto) 2269find_comp_entry(int proto)
2272{ 2270{
2273 struct compressor_entry *ce; 2271 struct compressor_entry *ce;
2274 struct list_head *list = &compressor_list;
2275 2272
2276 while ((list = list->next) != &compressor_list) { 2273 list_for_each_entry(ce, &compressor_list, list) {
2277 ce = list_entry(list, struct compressor_entry, list);
2278 if (ce->comp->compress_proto == proto) 2274 if (ce->comp->compress_proto == proto)
2279 return ce; 2275 return ce;
2280 } 2276 }
@@ -2540,20 +2536,15 @@ static struct channel *
2540ppp_find_channel(int unit) 2536ppp_find_channel(int unit)
2541{ 2537{
2542 struct channel *pch; 2538 struct channel *pch;
2543 struct list_head *list;
2544 2539
2545 list = &new_channels; 2540 list_for_each_entry(pch, &new_channels, list) {
2546 while ((list = list->next) != &new_channels) {
2547 pch = list_entry(list, struct channel, list);
2548 if (pch->file.index == unit) { 2541 if (pch->file.index == unit) {
2549 list_del(&pch->list); 2542 list_del(&pch->list);
2550 list_add(&pch->list, &all_channels); 2543 list_add(&pch->list, &all_channels);
2551 return pch; 2544 return pch;
2552 } 2545 }
2553 } 2546 }
2554 list = &all_channels; 2547 list_for_each_entry(pch, &all_channels, list) {
2555 while ((list = list->next) != &all_channels) {
2556 pch = list_entry(list, struct channel, list);
2557 if (pch->file.index == unit) 2548 if (pch->file.index == unit)
2558 return pch; 2549 return pch;
2559 } 2550 }
diff --git a/drivers/net/sungem.c b/drivers/net/sungem.c
index 3f67a42e85..de399563a9 100644
--- a/drivers/net/sungem.c
+++ b/drivers/net/sungem.c
@@ -2817,7 +2817,7 @@ static int gem_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2817 2817
2818#if (!defined(__sparc__) && !defined(CONFIG_PPC_PMAC)) 2818#if (!defined(__sparc__) && !defined(CONFIG_PPC_PMAC))
2819/* Fetch MAC address from vital product data of PCI ROM. */ 2819/* Fetch MAC address from vital product data of PCI ROM. */
2820static void find_eth_addr_in_vpd(void __iomem *rom_base, int len, unsigned char *dev_addr) 2820static int find_eth_addr_in_vpd(void __iomem *rom_base, int len, unsigned char *dev_addr)
2821{ 2821{
2822 int this_offset; 2822 int this_offset;
2823 2823
@@ -2838,35 +2838,27 @@ static void find_eth_addr_in_vpd(void __iomem *rom_base, int len, unsigned char
2838 2838
2839 for (i = 0; i < 6; i++) 2839 for (i = 0; i < 6; i++)
2840 dev_addr[i] = readb(p + i); 2840 dev_addr[i] = readb(p + i);
2841 break; 2841 return 1;
2842 } 2842 }
2843 return 0;
2843} 2844}
2844 2845
2845static void get_gem_mac_nonobp(struct pci_dev *pdev, unsigned char *dev_addr) 2846static void get_gem_mac_nonobp(struct pci_dev *pdev, unsigned char *dev_addr)
2846{ 2847{
2847 u32 rom_reg_orig; 2848 size_t size;
2848 void __iomem *p; 2849 void __iomem *p = pci_map_rom(pdev, &size);
2849
2850 if (pdev->resource[PCI_ROM_RESOURCE].parent == NULL) {
2851 if (pci_assign_resource(pdev, PCI_ROM_RESOURCE) < 0)
2852 goto use_random;
2853 }
2854 2850
2855 pci_read_config_dword(pdev, pdev->rom_base_reg, &rom_reg_orig); 2851 if (p) {
2856 pci_write_config_dword(pdev, pdev->rom_base_reg, 2852 int found;
2857 rom_reg_orig | PCI_ROM_ADDRESS_ENABLE);
2858 2853
2859 p = ioremap(pci_resource_start(pdev, PCI_ROM_RESOURCE), (64 * 1024)); 2854 found = readb(p) == 0x55 &&
2860 if (p != NULL && readb(p) == 0x55 && readb(p + 1) == 0xaa) 2855 readb(p + 1) == 0xaa &&
2861 find_eth_addr_in_vpd(p, (64 * 1024), dev_addr); 2856 find_eth_addr_in_vpd(p, (64 * 1024), dev_addr);
2862 2857 pci_unmap_rom(pdev, p);
2863 if (p != NULL) 2858 if (found)
2864 iounmap(p); 2859 return;
2865 2860 }
2866 pci_write_config_dword(pdev, pdev->rom_base_reg, rom_reg_orig);
2867 return;
2868 2861
2869use_random:
2870 /* Sun MAC prefix then 3 random bytes. */ 2862 /* Sun MAC prefix then 3 random bytes. */
2871 dev_addr[0] = 0x08; 2863 dev_addr[0] = 0x08;
2872 dev_addr[1] = 0x00; 2864 dev_addr[1] = 0x00;
diff --git a/drivers/net/sunhme.c b/drivers/net/sunhme.c
index f02fe4119b..9f046cae2f 100644
--- a/drivers/net/sunhme.c
+++ b/drivers/net/sunhme.c
@@ -2954,7 +2954,7 @@ static int is_quattro_p(struct pci_dev *pdev)
2954} 2954}
2955 2955
2956/* Fetch MAC address from vital product data of PCI ROM. */ 2956/* Fetch MAC address from vital product data of PCI ROM. */
2957static void find_eth_addr_in_vpd(void __iomem *rom_base, int len, int index, unsigned char *dev_addr) 2957static int find_eth_addr_in_vpd(void __iomem *rom_base, int len, int index, unsigned char *dev_addr)
2958{ 2958{
2959 int this_offset; 2959 int this_offset;
2960 2960
@@ -2977,42 +2977,33 @@ static void find_eth_addr_in_vpd(void __iomem *rom_base, int len, int index, uns
2977 2977
2978 for (i = 0; i < 6; i++) 2978 for (i = 0; i < 6; i++)
2979 dev_addr[i] = readb(p + i); 2979 dev_addr[i] = readb(p + i);
2980 break; 2980 return 1;
2981 } 2981 }
2982 index--; 2982 index--;
2983 } 2983 }
2984 return 0;
2984} 2985}
2985 2986
2986static void get_hme_mac_nonsparc(struct pci_dev *pdev, unsigned char *dev_addr) 2987static void get_hme_mac_nonsparc(struct pci_dev *pdev, unsigned char *dev_addr)
2987{ 2988{
2988 u32 rom_reg_orig; 2989 size_t size;
2989 void __iomem *p; 2990 void __iomem *p = pci_map_rom(pdev, &size);
2990 int index;
2991 2991
2992 index = 0; 2992 if (p) {
2993 if (is_quattro_p(pdev)) 2993 int index = 0;
2994 index = PCI_SLOT(pdev->devfn); 2994 int found;
2995
2996 if (pdev->resource[PCI_ROM_RESOURCE].parent == NULL) {
2997 if (pci_assign_resource(pdev, PCI_ROM_RESOURCE) < 0)
2998 goto use_random;
2999 }
3000 2995
3001 pci_read_config_dword(pdev, pdev->rom_base_reg, &rom_reg_orig); 2996 if (is_quattro_p(pdev))
3002 pci_write_config_dword(pdev, pdev->rom_base_reg, 2997 index = PCI_SLOT(pdev->devfn);
3003 rom_reg_orig | PCI_ROM_ADDRESS_ENABLE);
3004 2998
3005 p = ioremap(pci_resource_start(pdev, PCI_ROM_RESOURCE), (64 * 1024)); 2999 found = readb(p) == 0x55 &&
3006 if (p != NULL && readb(p) == 0x55 && readb(p + 1) == 0xaa) 3000 readb(p + 1) == 0xaa &&
3007 find_eth_addr_in_vpd(p, (64 * 1024), index, dev_addr); 3001 find_eth_addr_in_vpd(p, (64 * 1024), index, dev_addr);
3008 3002 pci_unmap_rom(pdev, p);
3009 if (p != NULL) 3003 if (found)
3010 iounmap(p); 3004 return;
3011 3005 }
3012 pci_write_config_dword(pdev, pdev->rom_base_reg, rom_reg_orig);
3013 return;
3014 3006
3015use_random:
3016 /* Sun MAC prefix then 3 random bytes. */ 3007 /* Sun MAC prefix then 3 random bytes. */
3017 dev_addr[0] = 0x08; 3008 dev_addr[0] = 0x08;
3018 dev_addr[1] = 0x00; 3009 dev_addr[1] = 0x00;
diff --git a/drivers/net/tulip/de4x5.c b/drivers/net/tulip/de4x5.c
index 93800c126e..ee48bfd673 100644
--- a/drivers/net/tulip/de4x5.c
+++ b/drivers/net/tulip/de4x5.c
@@ -2144,9 +2144,9 @@ srom_search(struct net_device *dev, struct pci_dev *pdev)
2144 u_long iobase = 0; /* Clear upper 32 bits in Alphas */ 2144 u_long iobase = 0; /* Clear upper 32 bits in Alphas */
2145 int i, j, cfrv; 2145 int i, j, cfrv;
2146 struct de4x5_private *lp = netdev_priv(dev); 2146 struct de4x5_private *lp = netdev_priv(dev);
2147 struct list_head *walk = &pdev->bus_list; 2147 struct list_head *walk;
2148 2148
2149 for (walk = walk->next; walk != &pdev->bus_list; walk = walk->next) { 2149 list_for_each(walk, &pdev->bus_list) {
2150 struct pci_dev *this_dev = pci_dev_b(walk); 2150 struct pci_dev *this_dev = pci_dev_b(walk);
2151 2151
2152 /* Skip the pci_bus list entry */ 2152 /* Skip the pci_bus list entry */
diff --git a/drivers/parisc/iosapic.c b/drivers/parisc/iosapic.c
index 91df0bf181..7a57c1b837 100644
--- a/drivers/parisc/iosapic.c
+++ b/drivers/parisc/iosapic.c
@@ -215,7 +215,7 @@ static inline void iosapic_write(void __iomem *iosapic, unsigned int reg, u32 va
215#define IOSAPIC_IRDT_ID_EID_SHIFT 0x10 215#define IOSAPIC_IRDT_ID_EID_SHIFT 0x10
216 216
217 217
218static spinlock_t iosapic_lock = SPIN_LOCK_UNLOCKED; 218static DEFINE_SPINLOCK(iosapic_lock);
219 219
220static inline void iosapic_eoi(void __iomem *addr, unsigned int data) 220static inline void iosapic_eoi(void __iomem *addr, unsigned int data)
221{ 221{
diff --git a/drivers/parisc/lasi.c b/drivers/parisc/lasi.c
index 7318550533..cb84a4e84a 100644
--- a/drivers/parisc/lasi.c
+++ b/drivers/parisc/lasi.c
@@ -20,7 +20,6 @@
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/pm.h> 22#include <linux/pm.h>
23#include <linux/slab.h>
24#include <linux/types.h> 23#include <linux/types.h>
25 24
26#include <asm/io.h> 25#include <asm/io.h>
diff --git a/drivers/parport/ieee1284.c b/drivers/parport/ieee1284.c
index 694bae162f..5b887ba5aa 100644
--- a/drivers/parport/ieee1284.c
+++ b/drivers/parport/ieee1284.c
@@ -196,7 +196,7 @@ int parport_wait_peripheral(struct parport *port,
196 return 1; 196 return 1;
197 197
198 /* 40ms of slow polling. */ 198 /* 40ms of slow polling. */
199 deadline = jiffies + (HZ + 24) / 25; 199 deadline = jiffies + msecs_to_jiffies(40);
200 while (time_before (jiffies, deadline)) { 200 while (time_before (jiffies, deadline)) {
201 int ret; 201 int ret;
202 202
@@ -205,7 +205,7 @@ int parport_wait_peripheral(struct parport *port,
205 205
206 /* Wait for 10ms (or until an interrupt occurs if 206 /* Wait for 10ms (or until an interrupt occurs if
207 * the handler is set) */ 207 * the handler is set) */
208 if ((ret = parport_wait_event (port, (HZ + 99) / 100)) < 0) 208 if ((ret = parport_wait_event (port, msecs_to_jiffies(10))) < 0)
209 return ret; 209 return ret;
210 210
211 status = parport_read_status (port); 211 status = parport_read_status (port);
@@ -216,8 +216,7 @@ int parport_wait_peripheral(struct parport *port,
216 /* parport_wait_event didn't time out, but the 216 /* parport_wait_event didn't time out, but the
217 * peripheral wasn't actually ready either. 217 * peripheral wasn't actually ready either.
218 * Wait for another 10ms. */ 218 * Wait for another 10ms. */
219 __set_current_state (TASK_INTERRUPTIBLE); 219 schedule_timeout_interruptible(msecs_to_jiffies(10));
220 schedule_timeout ((HZ+ 99) / 100);
221 } 220 }
222 } 221 }
223 222
diff --git a/drivers/parport/ieee1284_ops.c b/drivers/parport/ieee1284_ops.c
index 6624278c6e..ce1e2aad8b 100644
--- a/drivers/parport/ieee1284_ops.c
+++ b/drivers/parport/ieee1284_ops.c
@@ -60,7 +60,7 @@ size_t parport_ieee1284_write_compat (struct parport *port,
60 parport_data_forward (port); 60 parport_data_forward (port);
61 while (count < len) { 61 while (count < len) {
62 unsigned long expire = jiffies + dev->timeout; 62 unsigned long expire = jiffies + dev->timeout;
63 long wait = (HZ + 99) / 100; 63 long wait = msecs_to_jiffies(10);
64 unsigned char mask = (PARPORT_STATUS_ERROR 64 unsigned char mask = (PARPORT_STATUS_ERROR
65 | PARPORT_STATUS_BUSY); 65 | PARPORT_STATUS_BUSY);
66 unsigned char val = (PARPORT_STATUS_ERROR 66 unsigned char val = (PARPORT_STATUS_ERROR
@@ -97,8 +97,7 @@ size_t parport_ieee1284_write_compat (struct parport *port,
97 our interrupt handler called. */ 97 our interrupt handler called. */
98 if (count && no_irq) { 98 if (count && no_irq) {
99 parport_release (dev); 99 parport_release (dev);
100 __set_current_state (TASK_INTERRUPTIBLE); 100 schedule_timeout_interruptible(wait);
101 schedule_timeout (wait);
102 parport_claim_or_block (dev); 101 parport_claim_or_block (dev);
103 } 102 }
104 else 103 else
@@ -542,13 +541,12 @@ size_t parport_ieee1284_ecp_read_data (struct parport *port,
542 /* Yield the port for a while. */ 541 /* Yield the port for a while. */
543 if (count && dev->port->irq != PARPORT_IRQ_NONE) { 542 if (count && dev->port->irq != PARPORT_IRQ_NONE) {
544 parport_release (dev); 543 parport_release (dev);
545 __set_current_state (TASK_INTERRUPTIBLE); 544 schedule_timeout_interruptible(msecs_to_jiffies(40));
546 schedule_timeout ((HZ + 24) / 25);
547 parport_claim_or_block (dev); 545 parport_claim_or_block (dev);
548 } 546 }
549 else 547 else
550 /* We must have the device claimed here. */ 548 /* We must have the device claimed here. */
551 parport_wait_event (port, (HZ + 24) / 25); 549 parport_wait_event (port, msecs_to_jiffies(40));
552 550
553 /* Is there a signal pending? */ 551 /* Is there a signal pending? */
554 if (signal_pending (current)) 552 if (signal_pending (current))
diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c
index 1b938bb9be..c6493ad7c0 100644
--- a/drivers/parport/parport_pc.c
+++ b/drivers/parport/parport_pc.c
@@ -173,8 +173,7 @@ static int change_mode(struct parport *p, int m)
173 if (time_after_eq (jiffies, expire)) 173 if (time_after_eq (jiffies, expire))
174 /* The FIFO is stuck. */ 174 /* The FIFO is stuck. */
175 return -EBUSY; 175 return -EBUSY;
176 __set_current_state (TASK_INTERRUPTIBLE); 176 schedule_timeout_interruptible(msecs_to_jiffies(10));
177 schedule_timeout ((HZ + 99) / 100);
178 if (signal_pending (current)) 177 if (signal_pending (current))
179 break; 178 break;
180 } 179 }
diff --git a/drivers/pci/hotplug.c b/drivers/pci/hotplug.c
index b844bc9723..10444988a1 100644
--- a/drivers/pci/hotplug.c
+++ b/drivers/pci/hotplug.c
@@ -20,46 +20,35 @@ int pci_hotplug (struct device *dev, char **envp, int num_envp,
20 20
21 scratch = buffer; 21 scratch = buffer;
22 22
23 /* stuff we want to pass to /sbin/hotplug */ 23
24 envp[i++] = scratch; 24 if (add_hotplug_env_var(envp, num_envp, &i,
25 length += scnprintf (scratch, buffer_size - length, "PCI_CLASS=%04X", 25 buffer, buffer_size, &length,
26 pdev->class); 26 "PCI_CLASS=%04X", pdev->class))
27 if ((buffer_size - length <= 0) || (i >= num_envp))
28 return -ENOMEM; 27 return -ENOMEM;
29 ++length;
30 scratch += length;
31 28
32 envp[i++] = scratch; 29 if (add_hotplug_env_var(envp, num_envp, &i,
33 length += scnprintf (scratch, buffer_size - length, "PCI_ID=%04X:%04X", 30 buffer, buffer_size, &length,
34 pdev->vendor, pdev->device); 31 "PCI_ID=%04X:%04X", pdev->vendor, pdev->device))
35 if ((buffer_size - length <= 0) || (i >= num_envp))
36 return -ENOMEM; 32 return -ENOMEM;
37 ++length;
38 scratch += length;
39 33
40 envp[i++] = scratch; 34 if (add_hotplug_env_var(envp, num_envp, &i,
41 length += scnprintf (scratch, buffer_size - length, 35 buffer, buffer_size, &length,
42 "PCI_SUBSYS_ID=%04X:%04X", pdev->subsystem_vendor, 36 "PCI_SUBSYS_ID=%04X:%04X", pdev->subsystem_vendor,
43 pdev->subsystem_device); 37 pdev->subsystem_device))
44 if ((buffer_size - length <= 0) || (i >= num_envp))
45 return -ENOMEM; 38 return -ENOMEM;
46 ++length;
47 scratch += length;
48 39
49 envp[i++] = scratch; 40 if (add_hotplug_env_var(envp, num_envp, &i,
50 length += scnprintf (scratch, buffer_size - length, "PCI_SLOT_NAME=%s", 41 buffer, buffer_size, &length,
51 pci_name(pdev)); 42 "PCI_SLOT_NAME=%s", pci_name(pdev)))
52 if ((buffer_size - length <= 0) || (i >= num_envp))
53 return -ENOMEM; 43 return -ENOMEM;
54 44
55 envp[i++] = scratch; 45 if (add_hotplug_env_var(envp, num_envp, &i,
56 length += scnprintf (scratch, buffer_size - length, 46 buffer, buffer_size, &length,
57 "MODALIAS=pci:v%08Xd%08Xsv%08Xsd%08Xbc%02Xsc%02Xi%02x", 47 "MODALIAS=pci:v%08Xd%08Xsv%08Xsd%08Xbc%02Xsc%02Xi%02x",
58 pdev->vendor, pdev->device, 48 pdev->vendor, pdev->device,
59 pdev->subsystem_vendor, pdev->subsystem_device, 49 pdev->subsystem_vendor, pdev->subsystem_device,
60 (u8)(pdev->class >> 16), (u8)(pdev->class >> 8), 50 (u8)(pdev->class >> 16), (u8)(pdev->class >> 8),
61 (u8)(pdev->class)); 51 (u8)(pdev->class)))
62 if ((buffer_size - length <= 0) || (i >= num_envp))
63 return -ENOMEM; 52 return -ENOMEM;
64 53
65 envp[i] = NULL; 54 envp[i] = NULL;
diff --git a/drivers/pci/hotplug/pciehprm_acpi.c b/drivers/pci/hotplug/pciehprm_acpi.c
index 305b47ec2f..1406db35b0 100644
--- a/drivers/pci/hotplug/pciehprm_acpi.c
+++ b/drivers/pci/hotplug/pciehprm_acpi.c
@@ -1696,15 +1696,15 @@ void pciehprm_enable_card(
1696 pci_bus->number = func->bus; 1696 pci_bus->number = func->bus;
1697 devfn = PCI_DEVFN(func->device, func->function); 1697 devfn = PCI_DEVFN(func->device, func->function);
1698 1698
1699 rc = pci_bus_read_config_word(pci_bus, devfn, PCI_COMMAND, &command); 1699 rc = pci_bus_read_config_word(pci_bus, devfn, PCI_COMMAND, &cmd);
1700 1700
1701 if (card_type == PCI_HEADER_TYPE_BRIDGE) { 1701 if (card_type == PCI_HEADER_TYPE_BRIDGE) {
1702 rc = pci_bus_read_config_word(pci_bus, devfn, PCI_BRIDGE_CONTROL, &bcommand); 1702 rc = pci_bus_read_config_word(pci_bus, devfn, PCI_BRIDGE_CONTROL, &bcmd);
1703 } 1703 }
1704 1704
1705 cmd = command = command | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE 1705 command = cmd | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE
1706 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY; 1706 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY;
1707 bcmd = bcommand = bcommand | PCI_BRIDGE_CTL_NO_ISA; 1707 bcommand = bcmd | PCI_BRIDGE_CTL_NO_ISA;
1708 1708
1709 ab = find_acpi_bridge_by_bus(acpi_bridges_head, ctrl->seg, ctrl->bus); 1709 ab = find_acpi_bridge_by_bus(acpi_bridges_head, ctrl->seg, ctrl->bus);
1710 if (ab) { 1710 if (ab) {
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index cc9d65388e..56a3b397ef 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -44,10 +44,14 @@ pci_config_attr(subsystem_device, "0x%04x\n");
44pci_config_attr(class, "0x%06x\n"); 44pci_config_attr(class, "0x%06x\n");
45pci_config_attr(irq, "%u\n"); 45pci_config_attr(irq, "%u\n");
46 46
47static ssize_t local_cpus_show(struct device *dev, struct device_attribute *attr, char *buf) 47static ssize_t local_cpus_show(struct device *dev,
48 struct device_attribute *attr, char *buf)
48{ 49{
49 cpumask_t mask = pcibus_to_cpumask(to_pci_dev(dev)->bus); 50 cpumask_t mask;
50 int len = cpumask_scnprintf(buf, PAGE_SIZE-2, mask); 51 int len;
52
53 mask = pcibus_to_cpumask(to_pci_dev(dev)->bus);
54 len = cpumask_scnprintf(buf, PAGE_SIZE-2, mask);
51 strcat(buf,"\n"); 55 strcat(buf,"\n");
52 return 1+len; 56 return 1+len;
53} 57}
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index d00168b1f6..d3f3dd4224 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -29,7 +29,6 @@ static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; }
29#endif 29#endif
30 30
31/* Functions for PCI Hotplug drivers to use */ 31/* Functions for PCI Hotplug drivers to use */
32extern struct pci_bus * pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int busnr);
33extern unsigned int pci_do_scan_bus(struct pci_bus *bus); 32extern unsigned int pci_do_scan_bus(struct pci_bus *bus);
34extern int pci_remove_device_safe(struct pci_dev *dev); 33extern int pci_remove_device_safe(struct pci_dev *dev);
35extern unsigned char pci_max_busnr(void); 34extern unsigned char pci_max_busnr(void);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index b9c9b03919..26a55d08b5 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -72,11 +72,13 @@ void pci_remove_legacy_files(struct pci_bus *bus) { return; }
72/* 72/*
73 * PCI Bus Class Devices 73 * PCI Bus Class Devices
74 */ 74 */
75static ssize_t pci_bus_show_cpuaffinity(struct class_device *class_dev, char *buf) 75static ssize_t pci_bus_show_cpuaffinity(struct class_device *class_dev,
76 char *buf)
76{ 77{
77 cpumask_t cpumask = pcibus_to_cpumask(to_pci_bus(class_dev));
78 int ret; 78 int ret;
79 cpumask_t cpumask;
79 80
81 cpumask = pcibus_to_cpumask(to_pci_bus(class_dev));
80 ret = cpumask_scnprintf(buf, PAGE_SIZE, cpumask); 82 ret = cpumask_scnprintf(buf, PAGE_SIZE, cpumask);
81 if (ret < PAGE_SIZE) 83 if (ret < PAGE_SIZE)
82 buf[ret++] = '\n'; 84 buf[ret++] = '\n';
@@ -753,27 +755,19 @@ pci_scan_device(struct pci_bus *bus, int devfn)
753 kfree(dev); 755 kfree(dev);
754 return NULL; 756 return NULL;
755 } 757 }
756 device_initialize(&dev->dev);
757 dev->dev.release = pci_release_dev;
758 pci_dev_get(dev);
759
760 dev->dev.dma_mask = &dev->dma_mask;
761 dev->dev.coherent_dma_mask = 0xffffffffull;
762 758
763 return dev; 759 return dev;
764} 760}
765 761
766struct pci_dev * __devinit 762void __devinit pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
767pci_scan_single_device(struct pci_bus *bus, int devfn)
768{ 763{
769 struct pci_dev *dev; 764 device_initialize(&dev->dev);
765 dev->dev.release = pci_release_dev;
766 pci_dev_get(dev);
770 767
771 dev = pci_scan_device(bus, devfn); 768 dev->dev.dma_mask = &dev->dma_mask;
772 pci_scan_msi_device(dev); 769 dev->dev.coherent_dma_mask = 0xffffffffull;
773 770
774 if (!dev)
775 return NULL;
776
777 /* Fix up broken headers */ 771 /* Fix up broken headers */
778 pci_fixup_device(pci_fixup_header, dev); 772 pci_fixup_device(pci_fixup_header, dev);
779 773
@@ -785,6 +779,19 @@ pci_scan_single_device(struct pci_bus *bus, int devfn)
785 spin_lock(&pci_bus_lock); 779 spin_lock(&pci_bus_lock);
786 list_add_tail(&dev->bus_list, &bus->devices); 780 list_add_tail(&dev->bus_list, &bus->devices);
787 spin_unlock(&pci_bus_lock); 781 spin_unlock(&pci_bus_lock);
782}
783
784struct pci_dev * __devinit
785pci_scan_single_device(struct pci_bus *bus, int devfn)
786{
787 struct pci_dev *dev;
788
789 dev = pci_scan_device(bus, devfn);
790 if (!dev)
791 return NULL;
792
793 pci_device_add(dev, bus);
794 pci_scan_msi_device(dev);
788 795
789 return dev; 796 return dev;
790} 797}
@@ -881,7 +888,8 @@ unsigned int __devinit pci_do_scan_bus(struct pci_bus *bus)
881 return max; 888 return max;
882} 889}
883 890
884struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent, int bus, struct pci_ops *ops, void *sysdata) 891struct pci_bus * __devinit pci_create_bus(struct device *parent,
892 int bus, struct pci_ops *ops, void *sysdata)
885{ 893{
886 int error; 894 int error;
887 struct pci_bus *b; 895 struct pci_bus *b;
@@ -938,8 +946,6 @@ struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent, int bus,
938 b->resource[0] = &ioport_resource; 946 b->resource[0] = &ioport_resource;
939 b->resource[1] = &iomem_resource; 947 b->resource[1] = &iomem_resource;
940 948
941 b->subordinate = pci_scan_child_bus(b);
942
943 return b; 949 return b;
944 950
945sys_create_link_err: 951sys_create_link_err:
@@ -957,6 +963,18 @@ err_out:
957 kfree(b); 963 kfree(b);
958 return NULL; 964 return NULL;
959} 965}
966EXPORT_SYMBOL_GPL(pci_create_bus);
967
968struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent,
969 int bus, struct pci_ops *ops, void *sysdata)
970{
971 struct pci_bus *b;
972
973 b = pci_create_bus(parent, bus, ops, sysdata);
974 if (b)
975 b->subordinate = pci_scan_child_bus(b);
976 return b;
977}
960EXPORT_SYMBOL(pci_scan_bus_parented); 978EXPORT_SYMBOL(pci_scan_bus_parented);
961 979
962#ifdef CONFIG_HOTPLUG 980#ifdef CONFIG_HOTPLUG
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 4f0c1bd367..11ca44387c 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -876,6 +876,12 @@ static void __init asus_hides_smbus_hostbridge(struct pci_dev *dev)
876 case 0xC00C: /* Samsung P35 notebook */ 876 case 0xC00C: /* Samsung P35 notebook */
877 asus_hides_smbus = 1; 877 asus_hides_smbus = 1;
878 } 878 }
879 } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_COMPAQ)) {
880 if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB)
881 switch(dev->subsystem_device) {
882 case 0x0058: /* Compaq Evo N620c */
883 asus_hides_smbus = 1;
884 }
879 } 885 }
880} 886}
881DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845_HB, asus_hides_smbus_hostbridge ); 887DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845_HB, asus_hides_smbus_hostbridge );
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 6b0e6464eb..657be948ba 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -77,8 +77,7 @@ pbus_assign_resources_sorted(struct pci_bus *bus)
77 } 77 }
78} 78}
79 79
80static void __devinit 80void pci_setup_cardbus(struct pci_bus *bus)
81pci_setup_cardbus(struct pci_bus *bus)
82{ 81{
83 struct pci_dev *bridge = bus->self; 82 struct pci_dev *bridge = bus->self;
84 struct pci_bus_region region; 83 struct pci_bus_region region;
@@ -130,6 +129,7 @@ pci_setup_cardbus(struct pci_bus *bus)
130 region.end); 129 region.end);
131 } 130 }
132} 131}
132EXPORT_SYMBOL(pci_setup_cardbus);
133 133
134/* Initialize bridges with base/limit values we have collected. 134/* Initialize bridges with base/limit values we have collected.
135 PCI-to-PCI Bridge Architecture Specification rev. 1.1 (1998) 135 PCI-to-PCI Bridge Architecture Specification rev. 1.1 (1998)
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig
index 6485f75d2f..ddc741e6ec 100644
--- a/drivers/pcmcia/Kconfig
+++ b/drivers/pcmcia/Kconfig
@@ -221,6 +221,13 @@ config PCMCIA_VRC4173
221 tristate "NEC VRC4173 CARDU support" 221 tristate "NEC VRC4173 CARDU support"
222 depends on CPU_VR41XX && PCI && PCMCIA 222 depends on CPU_VR41XX && PCI && PCMCIA
223 223
224config OMAP_CF
225 tristate "OMAP CompactFlash Controller"
226 depends on PCMCIA && ARCH_OMAP16XX
227 help
228 Say Y here to support the CompactFlash controller on OMAP.
229 Note that this doesn't support "True IDE" mode.
230
224config PCCARD_NONSTATIC 231config PCCARD_NONSTATIC
225 tristate 232 tristate
226 233
diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile
index ef694c74df..a41fbb38fd 100644
--- a/drivers/pcmcia/Makefile
+++ b/drivers/pcmcia/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_M32R_CFC) += m32r_cfc.o
34obj-$(CONFIG_PCMCIA_AU1X00) += au1x00_ss.o 34obj-$(CONFIG_PCMCIA_AU1X00) += au1x00_ss.o
35obj-$(CONFIG_PCMCIA_VRC4171) += vrc4171_card.o 35obj-$(CONFIG_PCMCIA_VRC4171) += vrc4171_card.o
36obj-$(CONFIG_PCMCIA_VRC4173) += vrc4173_cardu.o 36obj-$(CONFIG_PCMCIA_VRC4173) += vrc4173_cardu.o
37obj-$(CONFIG_OMAP_CF) += omap_cf.o
37 38
38sa11xx_core-y += soc_common.o sa11xx_base.o 39sa11xx_core-y += soc_common.o sa11xx_base.o
39pxa2xx_core-y += soc_common.o pxa2xx_base.o 40pxa2xx_core-y += soc_common.o pxa2xx_base.o
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c
index e39178fc59..fabd3529ce 100644
--- a/drivers/pcmcia/cs.c
+++ b/drivers/pcmcia/cs.c
@@ -654,9 +654,10 @@ static int pccardd(void *__skt)
654 skt->thread = NULL; 654 skt->thread = NULL;
655 complete_and_exit(&skt->thread_done, 0); 655 complete_and_exit(&skt->thread_done, 0);
656 } 656 }
657 complete(&skt->thread_done);
658 657
659 add_wait_queue(&skt->thread_wait, &wait); 658 add_wait_queue(&skt->thread_wait, &wait);
659 complete(&skt->thread_done);
660
660 for (;;) { 661 for (;;) {
661 unsigned long flags; 662 unsigned long flags;
662 unsigned int events; 663 unsigned int events;
@@ -682,11 +683,11 @@ static int pccardd(void *__skt)
682 continue; 683 continue;
683 } 684 }
684 685
685 schedule();
686 try_to_freeze();
687
688 if (!skt->thread) 686 if (!skt->thread)
689 break; 687 break;
688
689 schedule();
690 try_to_freeze();
690 } 691 }
691 remove_wait_queue(&skt->thread_wait, &wait); 692 remove_wait_queue(&skt->thread_wait, &wait);
692 693
diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h
index 6bbfbd0e02..55867bc7f1 100644
--- a/drivers/pcmcia/cs_internal.h
+++ b/drivers/pcmcia/cs_internal.h
@@ -17,9 +17,6 @@
17 17
18#include <linux/config.h> 18#include <linux/config.h>
19 19
20#define CLIENT_MAGIC 0x51E6
21typedef struct client_t client_t;
22
23/* Flags in client state */ 20/* Flags in client state */
24#define CLIENT_CONFIG_LOCKED 0x0001 21#define CLIENT_CONFIG_LOCKED 0x0001
25#define CLIENT_IRQ_REQ 0x0002 22#define CLIENT_IRQ_REQ 0x0002
@@ -45,7 +42,6 @@ typedef struct region_t {
45typedef struct config_t { 42typedef struct config_t {
46 u_int state; 43 u_int state;
47 u_int Attributes; 44 u_int Attributes;
48 u_int Vcc, Vpp1, Vpp2;
49 u_int IntType; 45 u_int IntType;
50 u_int ConfigBase; 46 u_int ConfigBase;
51 u_char Status, Pin, Copy, Option, ExtStatus; 47 u_char Status, Pin, Copy, Option, ExtStatus;
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c
index 43da2e92d5..080608c738 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -354,6 +354,7 @@ static void pcmcia_release_dev(struct device *dev)
354 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 354 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
355 ds_dbg(1, "releasing dev %p\n", p_dev); 355 ds_dbg(1, "releasing dev %p\n", p_dev);
356 pcmcia_put_socket(p_dev->socket); 356 pcmcia_put_socket(p_dev->socket);
357 kfree(p_dev->devname);
357 kfree(p_dev); 358 kfree(p_dev);
358} 359}
359 360
@@ -424,9 +425,13 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev)
424{ 425{
425 cistpl_manfid_t manf_id; 426 cistpl_manfid_t manf_id;
426 cistpl_funcid_t func_id; 427 cistpl_funcid_t func_id;
427 cistpl_vers_1_t vers1; 428 cistpl_vers_1_t *vers1;
428 unsigned int i; 429 unsigned int i;
429 430
431 vers1 = kmalloc(sizeof(*vers1), GFP_KERNEL);
432 if (!vers1)
433 return -ENOMEM;
434
430 if (!pccard_read_tuple(p_dev->socket, p_dev->func, 435 if (!pccard_read_tuple(p_dev->socket, p_dev->func,
431 CISTPL_MANFID, &manf_id)) { 436 CISTPL_MANFID, &manf_id)) {
432 p_dev->manf_id = manf_id.manf; 437 p_dev->manf_id = manf_id.manf;
@@ -443,23 +448,30 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev)
443 /* rule of thumb: cards with no FUNCID, but with 448 /* rule of thumb: cards with no FUNCID, but with
444 * common memory device geometry information, are 449 * common memory device geometry information, are
445 * probably memory cards (from pcmcia-cs) */ 450 * probably memory cards (from pcmcia-cs) */
446 cistpl_device_geo_t devgeo; 451 cistpl_device_geo_t *devgeo;
452
453 devgeo = kmalloc(sizeof(*devgeo), GFP_KERNEL);
454 if (!devgeo) {
455 kfree(vers1);
456 return -ENOMEM;
457 }
447 if (!pccard_read_tuple(p_dev->socket, p_dev->func, 458 if (!pccard_read_tuple(p_dev->socket, p_dev->func,
448 CISTPL_DEVICE_GEO, &devgeo)) { 459 CISTPL_DEVICE_GEO, devgeo)) {
449 ds_dbg(0, "mem device geometry probably means " 460 ds_dbg(0, "mem device geometry probably means "
450 "FUNCID_MEMORY\n"); 461 "FUNCID_MEMORY\n");
451 p_dev->func_id = CISTPL_FUNCID_MEMORY; 462 p_dev->func_id = CISTPL_FUNCID_MEMORY;
452 p_dev->has_func_id = 1; 463 p_dev->has_func_id = 1;
453 } 464 }
465 kfree(devgeo);
454 } 466 }
455 467
456 if (!pccard_read_tuple(p_dev->socket, p_dev->func, CISTPL_VERS_1, 468 if (!pccard_read_tuple(p_dev->socket, p_dev->func, CISTPL_VERS_1,
457 &vers1)) { 469 vers1)) {
458 for (i=0; i < vers1.ns; i++) { 470 for (i=0; i < vers1->ns; i++) {
459 char *tmp; 471 char *tmp;
460 unsigned int length; 472 unsigned int length;
461 473
462 tmp = vers1.str + vers1.ofs[i]; 474 tmp = vers1->str + vers1->ofs[i];
463 475
464 length = strlen(tmp) + 1; 476 length = strlen(tmp) + 1;
465 if ((length < 3) || (length > 255)) 477 if ((length < 3) || (length > 255))
@@ -475,6 +487,7 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev)
475 } 487 }
476 } 488 }
477 489
490 kfree(vers1);
478 return 0; 491 return 0;
479} 492}
480 493
@@ -492,6 +505,7 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
492{ 505{
493 struct pcmcia_device *p_dev; 506 struct pcmcia_device *p_dev;
494 unsigned long flags; 507 unsigned long flags;
508 int bus_id_len;
495 509
496 s = pcmcia_get_socket(s); 510 s = pcmcia_get_socket(s);
497 if (!s) 511 if (!s)
@@ -515,7 +529,12 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
515 p_dev->dev.bus = &pcmcia_bus_type; 529 p_dev->dev.bus = &pcmcia_bus_type;
516 p_dev->dev.parent = s->dev.dev; 530 p_dev->dev.parent = s->dev.dev;
517 p_dev->dev.release = pcmcia_release_dev; 531 p_dev->dev.release = pcmcia_release_dev;
518 sprintf (p_dev->dev.bus_id, "%d.%d", p_dev->socket->sock, p_dev->device_no); 532 bus_id_len = sprintf (p_dev->dev.bus_id, "%d.%d", p_dev->socket->sock, p_dev->device_no);
533
534 p_dev->devname = kmalloc(6 + bus_id_len + 1, GFP_KERNEL);
535 if (!p_dev->devname)
536 goto err_free;
537 sprintf (p_dev->devname, "pcmcia%s", p_dev->dev.bus_id);
519 538
520 /* compat */ 539 /* compat */
521 p_dev->state = CLIENT_UNBOUND; 540 p_dev->state = CLIENT_UNBOUND;
@@ -540,6 +559,7 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
540 return p_dev; 559 return p_dev;
541 560
542 err_free: 561 err_free:
562 kfree(p_dev->devname);
543 kfree(p_dev); 563 kfree(p_dev);
544 s->device_count--; 564 s->device_count--;
545 err_put: 565 err_put:
diff --git a/drivers/pcmcia/omap_cf.c b/drivers/pcmcia/omap_cf.c
new file mode 100644
index 0000000000..08d1c92882
--- /dev/null
+++ b/drivers/pcmcia/omap_cf.c
@@ -0,0 +1,373 @@
1/*
2 * omap_cf.c -- OMAP 16xx CompactFlash controller driver
3 *
4 * Copyright (c) 2005 David Brownell
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
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/sched.h>
15#include <linux/device.h>
16#include <linux/errno.h>
17#include <linux/init.h>
18#include <linux/delay.h>
19#include <linux/interrupt.h>
20
21#include <pcmcia/ss.h>
22
23#include <asm/hardware.h>
24#include <asm/io.h>
25#include <asm/mach-types.h>
26#include <asm/sizes.h>
27
28#include <asm/arch/mux.h>
29#include <asm/arch/tc.h>
30
31
32/* NOTE: don't expect this to support many I/O cards. The 16xx chips have
33 * hard-wired timings to support Compact Flash memory cards; they won't work
34 * with various other devices (like WLAN adapters) without some external
35 * logic to help out.
36 *
37 * NOTE: CF controller docs disagree with address space docs as to where
38 * CF_BASE really lives; this is a doc erratum.
39 */
40#define CF_BASE 0xfffe2800
41
42/* status; read after IRQ */
43#define CF_STATUS_REG __REG16(CF_BASE + 0x00)
44# define CF_STATUS_BAD_READ (1 << 2)
45# define CF_STATUS_BAD_WRITE (1 << 1)
46# define CF_STATUS_CARD_DETECT (1 << 0)
47
48/* which chipselect (CS0..CS3) is used for CF (active low) */
49#define CF_CFG_REG __REG16(CF_BASE + 0x02)
50
51/* card reset */
52#define CF_CONTROL_REG __REG16(CF_BASE + 0x04)
53# define CF_CONTROL_RESET (1 << 0)
54
55#define omap_cf_present() (!(CF_STATUS_REG & CF_STATUS_CARD_DETECT))
56
57/*--------------------------------------------------------------------------*/
58
59static const char driver_name[] = "omap_cf";
60
61struct omap_cf_socket {
62 struct pcmcia_socket socket;
63
64 struct timer_list timer;
65 unsigned present:1;
66 unsigned active:1;
67
68 struct platform_device *pdev;
69 unsigned long phys_cf;
70 u_int irq;
71};
72
73#define POLL_INTERVAL (2 * HZ)
74
75#define SZ_2K (2 * SZ_1K)
76
77/*--------------------------------------------------------------------------*/
78
79static int omap_cf_ss_init(struct pcmcia_socket *s)
80{
81 return 0;
82}
83
84/* the timer is primarily to kick this socket's pccardd */
85static void omap_cf_timer(unsigned long _cf)
86{
87 struct omap_cf_socket *cf = (void *) _cf;
88 unsigned present = omap_cf_present();
89
90 if (present != cf->present) {
91 cf->present = present;
92 pr_debug("%s: card %s\n", driver_name,
93 present ? "present" : "gone");
94 pcmcia_parse_events(&cf->socket, SS_DETECT);
95 }
96
97 if (cf->active)
98 mod_timer(&cf->timer, jiffies + POLL_INTERVAL);
99}
100
101/* This irq handler prevents "irqNNN: nobody cared" messages as drivers
102 * claim the card's IRQ. It may also detect some card insertions, but
103 * not removals; it can't always eliminate timer irqs.
104 */
105static irqreturn_t omap_cf_irq(int irq, void *_cf, struct pt_regs *r)
106{
107 omap_cf_timer((unsigned long)_cf);
108 return IRQ_HANDLED;
109}
110
111static int omap_cf_get_status(struct pcmcia_socket *s, u_int *sp)
112{
113 if (!sp)
114 return -EINVAL;
115
116 /* FIXME power management should probably be board-specific:
117 * - 3VCARD vs XVCARD (OSK only handles 3VCARD)
118 * - POWERON (switched on/off by set_socket)
119 */
120 if (omap_cf_present()) {
121 struct omap_cf_socket *cf;
122
123 *sp = SS_READY | SS_DETECT | SS_POWERON | SS_3VCARD;
124 cf = container_of(s, struct omap_cf_socket, socket);
125 s->irq.AssignedIRQ = cf->irq;
126 } else
127 *sp = 0;
128 return 0;
129}
130
131static int
132omap_cf_set_socket(struct pcmcia_socket *sock, struct socket_state_t *s)
133{
134 u16 control;
135
136 /* FIXME some non-OSK boards will support power switching */
137 switch (s->Vcc) {
138 case 0:
139 case 33:
140 break;
141 default:
142 return -EINVAL;
143 }
144
145 control = CF_CONTROL_REG;
146 if (s->flags & SS_RESET)
147 CF_CONTROL_REG = CF_CONTROL_RESET;
148 else
149 CF_CONTROL_REG = 0;
150
151 pr_debug("%s: Vcc %d, io_irq %d, flags %04x csc %04x\n",
152 driver_name, s->Vcc, s->io_irq, s->flags, s->csc_mask);
153
154 return 0;
155}
156
157static int omap_cf_ss_suspend(struct pcmcia_socket *s)
158{
159 pr_debug("%s: %s\n", driver_name, __FUNCTION__);
160 return omap_cf_set_socket(s, &dead_socket);
161}
162
163/* regions are 2K each: mem, attrib, io (and reserved-for-ide) */
164
165static int
166omap_cf_set_io_map(struct pcmcia_socket *s, struct pccard_io_map *io)
167{
168 struct omap_cf_socket *cf;
169
170 cf = container_of(s, struct omap_cf_socket, socket);
171 io->flags &= MAP_ACTIVE|MAP_ATTRIB|MAP_16BIT;
172 io->start = cf->phys_cf + SZ_4K;
173 io->stop = io->start + SZ_2K - 1;
174 return 0;
175}
176
177static int
178omap_cf_set_mem_map(struct pcmcia_socket *s, struct pccard_mem_map *map)
179{
180 struct omap_cf_socket *cf;
181
182 if (map->card_start)
183 return -EINVAL;
184 cf = container_of(s, struct omap_cf_socket, socket);
185 map->static_start = cf->phys_cf;
186 map->flags &= MAP_ACTIVE|MAP_ATTRIB|MAP_16BIT;
187 if (map->flags & MAP_ATTRIB)
188 map->static_start += SZ_2K;
189 return 0;
190}
191
192static struct pccard_operations omap_cf_ops = {
193 .init = omap_cf_ss_init,
194 .suspend = omap_cf_ss_suspend,
195 .get_status = omap_cf_get_status,
196 .set_socket = omap_cf_set_socket,
197 .set_io_map = omap_cf_set_io_map,
198 .set_mem_map = omap_cf_set_mem_map,
199};
200
201/*--------------------------------------------------------------------------*/
202
203/*
204 * NOTE: right now the only board-specific platform_data is
205 * "what chipselect is used". Boards could want more.
206 */
207
208static int __init omap_cf_probe(struct device *dev)
209{
210 unsigned seg;
211 struct omap_cf_socket *cf;
212 struct platform_device *pdev = to_platform_device(dev);
213 int irq;
214 int status;
215
216 seg = (int) dev->platform_data;
217 if (seg == 0 || seg > 3)
218 return -ENODEV;
219
220 /* either CFLASH.IREQ (INT_1610_CF) or some GPIO */
221 irq = platform_get_irq(pdev, 0);
222 if (!irq)
223 return -EINVAL;
224
225 cf = kcalloc(1, sizeof *cf, GFP_KERNEL);
226 if (!cf)
227 return -ENOMEM;
228 init_timer(&cf->timer);
229 cf->timer.function = omap_cf_timer;
230 cf->timer.data = (unsigned long) cf;
231
232 cf->pdev = pdev;
233 dev_set_drvdata(dev, cf);
234
235 /* this primarily just shuts up irq handling noise */
236 status = request_irq(irq, omap_cf_irq, SA_SHIRQ,
237 driver_name, cf);
238 if (status < 0)
239 goto fail0;
240 cf->irq = irq;
241 cf->socket.pci_irq = irq;
242
243 switch (seg) {
244 /* NOTE: CS0 could be configured too ... */
245 case 1:
246 cf->phys_cf = OMAP_CS1_PHYS;
247 break;
248 case 2:
249 cf->phys_cf = OMAP_CS2_PHYS;
250 break;
251 case 3:
252 cf->phys_cf = omap_cs3_phys();
253 break;
254 default:
255 goto fail1;
256 }
257
258 /* pcmcia layer only remaps "real" memory */
259 cf->socket.io_offset = (unsigned long)
260 ioremap(cf->phys_cf + SZ_4K, SZ_2K);
261 if (!cf->socket.io_offset)
262 goto fail1;
263
264 if (!request_mem_region(cf->phys_cf, SZ_8K, driver_name))
265 goto fail1;
266
267 /* NOTE: CF conflicts with MMC1 */
268 omap_cfg_reg(W11_1610_CF_CD1);
269 omap_cfg_reg(P11_1610_CF_CD2);
270 omap_cfg_reg(R11_1610_CF_IOIS16);
271 omap_cfg_reg(V10_1610_CF_IREQ);
272 omap_cfg_reg(W10_1610_CF_RESET);
273
274 CF_CFG_REG = ~(1 << seg);
275
276 pr_info("%s: cs%d on irq %d\n", driver_name, seg, irq);
277
278 /* NOTE: better EMIFS setup might support more cards; but the
279 * TRM only shows how to affect regular flash signals, not their
280 * CF/PCMCIA variants...
281 */
282 pr_debug("%s: cs%d, previous ccs %08x acs %08x\n", driver_name,
283 seg, EMIFS_CCS(seg), EMIFS_ACS(seg));
284 EMIFS_CCS(seg) = 0x0004a1b3; /* synch mode 4 etc */
285 EMIFS_ACS(seg) = 0x00000000; /* OE hold/setup */
286
287 /* CF uses armxor_ck, which is "always" available */
288
289 pr_debug("%s: sts %04x cfg %04x control %04x %s\n", driver_name,
290 CF_STATUS_REG, CF_CFG_REG, CF_CONTROL_REG,
291 omap_cf_present() ? "present" : "(not present)");
292
293 cf->socket.owner = THIS_MODULE;
294 cf->socket.dev.dev = dev;
295 cf->socket.ops = &omap_cf_ops;
296 cf->socket.resource_ops = &pccard_static_ops;
297 cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP
298 | SS_CAP_MEM_ALIGN;
299 cf->socket.map_size = SZ_2K;
300
301 status = pcmcia_register_socket(&cf->socket);
302 if (status < 0)
303 goto fail2;
304
305 cf->active = 1;
306 mod_timer(&cf->timer, jiffies + POLL_INTERVAL);
307 return 0;
308
309fail2:
310 iounmap((void __iomem *) cf->socket.io_offset);
311 release_mem_region(cf->phys_cf, SZ_8K);
312fail1:
313 free_irq(irq, cf);
314fail0:
315 kfree(cf);
316 return status;
317}
318
319static int __devexit omap_cf_remove(struct device *dev)
320{
321 struct omap_cf_socket *cf = dev_get_drvdata(dev);
322
323 cf->active = 0;
324 pcmcia_unregister_socket(&cf->socket);
325 del_timer_sync(&cf->timer);
326 iounmap((void __iomem *) cf->socket.io_offset);
327 release_mem_region(cf->phys_cf, SZ_8K);
328 free_irq(cf->irq, cf);
329 kfree(cf);
330 return 0;
331}
332
333static int omap_cf_suspend(struct device *dev, pm_message_t mesg, u32 level)
334{
335 if (level != SUSPEND_SAVE_STATE)
336 return 0;
337 return pcmcia_socket_dev_suspend(dev, mesg);
338}
339
340static int omap_cf_resume(struct device *dev, u32 level)
341{
342 if (level != RESUME_RESTORE_STATE)
343 return 0;
344 return pcmcia_socket_dev_resume(dev);
345}
346
347static struct device_driver omap_cf_driver = {
348 .name = (char *) driver_name,
349 .bus = &platform_bus_type,
350 .probe = omap_cf_probe,
351 .remove = __devexit_p(omap_cf_remove),
352 .suspend = omap_cf_suspend,
353 .resume = omap_cf_resume,
354};
355
356static int __init omap_cf_init(void)
357{
358 if (cpu_is_omap16xx())
359 driver_register(&omap_cf_driver);
360 return 0;
361}
362
363static void __exit omap_cf_exit(void)
364{
365 if (cpu_is_omap16xx())
366 driver_unregister(&omap_cf_driver);
367}
368
369module_init(omap_cf_init);
370module_exit(omap_cf_exit);
371
372MODULE_DESCRIPTION("OMAP CF Driver");
373MODULE_LICENSE("GPL");
diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c
index 599b116d97..89022ad5b5 100644
--- a/drivers/pcmcia/pcmcia_resource.c
+++ b/drivers/pcmcia/pcmcia_resource.c
@@ -447,7 +447,7 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
447 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { 447 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
448 if (mod->Vpp1 != mod->Vpp2) 448 if (mod->Vpp1 != mod->Vpp2)
449 return CS_BAD_VPP; 449 return CS_BAD_VPP;
450 c->Vpp1 = c->Vpp2 = s->socket.Vpp = mod->Vpp1; 450 s->socket.Vpp = mod->Vpp1;
451 if (s->ops->set_socket(s, &s->socket)) 451 if (s->ops->set_socket(s, &s->socket))
452 return CS_BAD_VPP; 452 return CS_BAD_VPP;
453 } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) || 453 } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) ||
@@ -623,8 +623,6 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
623 if (s->ops->set_socket(s, &s->socket)) 623 if (s->ops->set_socket(s, &s->socket))
624 return CS_BAD_VPP; 624 return CS_BAD_VPP;
625 625
626 c->Vcc = req->Vcc; c->Vpp1 = c->Vpp2 = req->Vpp1;
627
628 /* Pick memory or I/O card, DMA mode, interrupt */ 626 /* Pick memory or I/O card, DMA mode, interrupt */
629 c->IntType = req->IntType; 627 c->IntType = req->IntType;
630 c->Attributes = req->Attributes; 628 c->Attributes = req->Attributes;
@@ -822,7 +820,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
822 ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) || 820 ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) ||
823 (s->functions > 1) || 821 (s->functions > 1) ||
824 (irq == s->pci_irq)) ? SA_SHIRQ : 0, 822 (irq == s->pci_irq)) ? SA_SHIRQ : 0,
825 p_dev->dev.bus_id, 823 p_dev->devname,
826 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Instance : data); 824 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Instance : data);
827 if (!ret) { 825 if (!ret) {
828 if (!(req->Attributes & IRQ_HANDLE_PRESENT)) 826 if (!(req->Attributes & IRQ_HANDLE_PRESENT))
@@ -832,7 +830,8 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
832 } 830 }
833 } 831 }
834#endif 832#endif
835 if (ret) { 833 /* only assign PCI irq if no IRQ already assigned */
834 if (ret && !s->irq.AssignedIRQ) {
836 if (!s->pci_irq) 835 if (!s->pci_irq)
837 return ret; 836 return ret;
838 irq = s->pci_irq; 837 irq = s->pci_irq;
@@ -843,7 +842,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
843 ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) || 842 ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) ||
844 (s->functions > 1) || 843 (s->functions > 1) ||
845 (irq == s->pci_irq)) ? SA_SHIRQ : 0, 844 (irq == s->pci_irq)) ? SA_SHIRQ : 0,
846 p_dev->dev.bus_id, req->Instance)) 845 p_dev->devname, req->Instance))
847 return CS_IN_USE; 846 return CS_IN_USE;
848 } 847 }
849 848
diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c
index 0347a29f29..f0997c36c9 100644
--- a/drivers/pcmcia/yenta_socket.c
+++ b/drivers/pcmcia/yenta_socket.c
@@ -72,6 +72,7 @@ static inline void cb_writel(struct yenta_socket *socket, unsigned reg, u32 val)
72{ 72{
73 debug("%p %04x %08x\n", socket, reg, val); 73 debug("%p %04x %08x\n", socket, reg, val);
74 writel(val, socket->base + reg); 74 writel(val, socket->base + reg);
75 readl(socket->base + reg); /* avoid problems with PCI write posting */
75} 76}
76 77
77static inline u8 config_readb(struct yenta_socket *socket, unsigned offset) 78static inline u8 config_readb(struct yenta_socket *socket, unsigned offset)
@@ -136,6 +137,7 @@ static inline void exca_writeb(struct yenta_socket *socket, unsigned reg, u8 val
136{ 137{
137 debug("%p %04x %02x\n", socket, reg, val); 138 debug("%p %04x %02x\n", socket, reg, val);
138 writeb(val, socket->base + 0x800 + reg); 139 writeb(val, socket->base + 0x800 + reg);
140 readb(socket->base + 0x800 + reg); /* PCI write posting... */
139} 141}
140 142
141static void exca_writew(struct yenta_socket *socket, unsigned reg, u16 val) 143static void exca_writew(struct yenta_socket *socket, unsigned reg, u16 val)
@@ -143,6 +145,10 @@ static void exca_writew(struct yenta_socket *socket, unsigned reg, u16 val)
143 debug("%p %04x %04x\n", socket, reg, val); 145 debug("%p %04x %04x\n", socket, reg, val);
144 writeb(val, socket->base + 0x800 + reg); 146 writeb(val, socket->base + 0x800 + reg);
145 writeb(val >> 8, socket->base + 0x800 + reg + 1); 147 writeb(val >> 8, socket->base + 0x800 + reg + 1);
148
149 /* PCI write posting... */
150 readb(socket->base + 0x800 + reg);
151 readb(socket->base + 0x800 + reg + 1);
146} 152}
147 153
148/* 154/*
@@ -667,7 +673,7 @@ static int yenta_search_res(struct yenta_socket *socket, struct resource *res,
667 return 0; 673 return 0;
668} 674}
669 675
670static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type, int addr_start, int addr_end) 676static int yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type, int addr_start, int addr_end)
671{ 677{
672 struct resource *root, *res; 678 struct resource *root, *res;
673 struct pci_bus_region region; 679 struct pci_bus_region region;
@@ -676,7 +682,7 @@ static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned typ
676 res = socket->dev->resource + PCI_BRIDGE_RESOURCES + nr; 682 res = socket->dev->resource + PCI_BRIDGE_RESOURCES + nr;
677 /* Already allocated? */ 683 /* Already allocated? */
678 if (res->parent) 684 if (res->parent)
679 return; 685 return 0;
680 686
681 /* The granularity of the memory limit is 4kB, on IO it's 4 bytes */ 687 /* The granularity of the memory limit is 4kB, on IO it's 4 bytes */
682 mask = ~0xfff; 688 mask = ~0xfff;
@@ -692,7 +698,7 @@ static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned typ
692 pcibios_bus_to_resource(socket->dev, res, &region); 698 pcibios_bus_to_resource(socket->dev, res, &region);
693 root = pci_find_parent_resource(socket->dev, res); 699 root = pci_find_parent_resource(socket->dev, res);
694 if (root && (request_resource(root, res) == 0)) 700 if (root && (request_resource(root, res) == 0))
695 return; 701 return 0;
696 printk(KERN_INFO "yenta %s: Preassigned resource %d busy or not available, reconfiguring...\n", 702 printk(KERN_INFO "yenta %s: Preassigned resource %d busy or not available, reconfiguring...\n",
697 pci_name(socket->dev), nr); 703 pci_name(socket->dev), nr);
698 } 704 }
@@ -700,35 +706,27 @@ static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned typ
700 if (type & IORESOURCE_IO) { 706 if (type & IORESOURCE_IO) {
701 if ((yenta_search_res(socket, res, BRIDGE_IO_MAX)) || 707 if ((yenta_search_res(socket, res, BRIDGE_IO_MAX)) ||
702 (yenta_search_res(socket, res, BRIDGE_IO_ACC)) || 708 (yenta_search_res(socket, res, BRIDGE_IO_ACC)) ||
703 (yenta_search_res(socket, res, BRIDGE_IO_MIN))) { 709 (yenta_search_res(socket, res, BRIDGE_IO_MIN)))
704 config_writel(socket, addr_start, res->start); 710 return 1;
705 config_writel(socket, addr_end, res->end);
706 return;
707 }
708 } else { 711 } else {
709 if (type & IORESOURCE_PREFETCH) { 712 if (type & IORESOURCE_PREFETCH) {
710 if ((yenta_search_res(socket, res, BRIDGE_MEM_MAX)) || 713 if ((yenta_search_res(socket, res, BRIDGE_MEM_MAX)) ||
711 (yenta_search_res(socket, res, BRIDGE_MEM_ACC)) || 714 (yenta_search_res(socket, res, BRIDGE_MEM_ACC)) ||
712 (yenta_search_res(socket, res, BRIDGE_MEM_MIN))) { 715 (yenta_search_res(socket, res, BRIDGE_MEM_MIN)))
713 config_writel(socket, addr_start, res->start); 716 return 1;
714 config_writel(socket, addr_end, res->end);
715 return;
716 }
717 /* Approximating prefetchable by non-prefetchable */ 717 /* Approximating prefetchable by non-prefetchable */
718 res->flags = IORESOURCE_MEM; 718 res->flags = IORESOURCE_MEM;
719 } 719 }
720 if ((yenta_search_res(socket, res, BRIDGE_MEM_MAX)) || 720 if ((yenta_search_res(socket, res, BRIDGE_MEM_MAX)) ||
721 (yenta_search_res(socket, res, BRIDGE_MEM_ACC)) || 721 (yenta_search_res(socket, res, BRIDGE_MEM_ACC)) ||
722 (yenta_search_res(socket, res, BRIDGE_MEM_MIN))) { 722 (yenta_search_res(socket, res, BRIDGE_MEM_MIN)))
723 config_writel(socket, addr_start, res->start); 723 return 1;
724 config_writel(socket, addr_end, res->end);
725 return;
726 }
727 } 724 }
728 725
729 printk(KERN_INFO "yenta %s: no resource of type %x available, trying to continue...\n", 726 printk(KERN_INFO "yenta %s: no resource of type %x available, trying to continue...\n",
730 pci_name(socket->dev), type); 727 pci_name(socket->dev), type);
731 res->start = res->end = res->flags = 0; 728 res->start = res->end = res->flags = 0;
729 return 0;
732} 730}
733 731
734/* 732/*
@@ -736,14 +734,17 @@ static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned typ
736 */ 734 */
737static void yenta_allocate_resources(struct yenta_socket *socket) 735static void yenta_allocate_resources(struct yenta_socket *socket)
738{ 736{
739 yenta_allocate_res(socket, 0, IORESOURCE_IO, 737 int program = 0;
738 program += yenta_allocate_res(socket, 0, IORESOURCE_IO,
740 PCI_CB_IO_BASE_0, PCI_CB_IO_LIMIT_0); 739 PCI_CB_IO_BASE_0, PCI_CB_IO_LIMIT_0);
741 yenta_allocate_res(socket, 1, IORESOURCE_IO, 740 program += yenta_allocate_res(socket, 1, IORESOURCE_IO,
742 PCI_CB_IO_BASE_1, PCI_CB_IO_LIMIT_1); 741 PCI_CB_IO_BASE_1, PCI_CB_IO_LIMIT_1);
743 yenta_allocate_res(socket, 2, IORESOURCE_MEM|IORESOURCE_PREFETCH, 742 program += yenta_allocate_res(socket, 2, IORESOURCE_MEM|IORESOURCE_PREFETCH,
744 PCI_CB_MEMORY_BASE_0, PCI_CB_MEMORY_LIMIT_0); 743 PCI_CB_MEMORY_BASE_0, PCI_CB_MEMORY_LIMIT_0);
745 yenta_allocate_res(socket, 3, IORESOURCE_MEM, 744 program += yenta_allocate_res(socket, 3, IORESOURCE_MEM,
746 PCI_CB_MEMORY_BASE_1, PCI_CB_MEMORY_LIMIT_1); 745 PCI_CB_MEMORY_BASE_1, PCI_CB_MEMORY_LIMIT_1);
746 if (program)
747 pci_setup_cardbus(socket->dev->subordinate);
747} 748}
748 749
749 750
@@ -758,7 +759,7 @@ static void yenta_free_resources(struct yenta_socket *socket)
758 res = socket->dev->resource + PCI_BRIDGE_RESOURCES + i; 759 res = socket->dev->resource + PCI_BRIDGE_RESOURCES + i;
759 if (res->start != 0 && res->end != 0) 760 if (res->start != 0 && res->end != 0)
760 release_resource(res); 761 release_resource(res);
761 res->start = res->end = 0; 762 res->start = res->end = res->flags = 0;
762 } 763 }
763} 764}
764 765
diff --git a/drivers/sbus/char/aurora.c b/drivers/sbus/char/aurora.c
index d96cc47de5..672f9f2b21 100644
--- a/drivers/sbus/char/aurora.c
+++ b/drivers/sbus/char/aurora.c
@@ -871,8 +871,7 @@ static irqreturn_t aurora_interrupt(int irq, void * dev_id, struct pt_regs * reg
871#ifdef AURORA_INT_DEBUG 871#ifdef AURORA_INT_DEBUG
872static void aurora_timer (unsigned long ignored); 872static void aurora_timer (unsigned long ignored);
873 873
874static struct timer_list aurora_poll_timer = 874static DEFINE_TIMER(aurora_poll_timer, aurora_timer, 0, 0);
875 TIMER_INITIALIZER(aurora_timer, 0, 0);
876 875
877static void 876static void
878aurora_timer (unsigned long ignored) 877aurora_timer (unsigned long ignored)
diff --git a/drivers/sbus/char/bbc_envctrl.c b/drivers/sbus/char/bbc_envctrl.c
index d44205d52b..d89f83f769 100644
--- a/drivers/sbus/char/bbc_envctrl.c
+++ b/drivers/sbus/char/bbc_envctrl.c
@@ -5,6 +5,7 @@
5 */ 5 */
6 6
7#define __KERNEL_SYSCALLS__ 7#define __KERNEL_SYSCALLS__
8static int errno;
8 9
9#include <linux/kernel.h> 10#include <linux/kernel.h>
10#include <linux/kthread.h> 11#include <linux/kthread.h>
@@ -13,8 +14,6 @@
13#include <linux/delay.h> 14#include <linux/delay.h>
14#include <asm/oplib.h> 15#include <asm/oplib.h>
15#include <asm/ebus.h> 16#include <asm/ebus.h>
16static int errno;
17#include <asm/unistd.h>
18 17
19#include "bbc_i2c.h" 18#include "bbc_i2c.h"
20#include "max1617.h" 19#include "max1617.h"
diff --git a/drivers/sbus/char/envctrl.c b/drivers/sbus/char/envctrl.c
index d765cc1bf0..b0cc3c2588 100644
--- a/drivers/sbus/char/envctrl.c
+++ b/drivers/sbus/char/envctrl.c
@@ -20,6 +20,7 @@
20 */ 20 */
21 21
22#define __KERNEL_SYSCALLS__ 22#define __KERNEL_SYSCALLS__
23static int errno;
23 24
24#include <linux/config.h> 25#include <linux/config.h>
25#include <linux/module.h> 26#include <linux/module.h>
@@ -38,9 +39,6 @@
38#include <asm/uaccess.h> 39#include <asm/uaccess.h>
39#include <asm/envctrl.h> 40#include <asm/envctrl.h>
40 41
41static int errno;
42#include <asm/unistd.h>
43
44#define ENVCTRL_MINOR 162 42#define ENVCTRL_MINOR 162
45 43
46#define PCF8584_ADDRESS 0x55 44#define PCF8584_ADDRESS 0x55
diff --git a/drivers/scsi/53c7xx.c b/drivers/scsi/53c7xx.c
index 2341d27cee..7a33c708f5 100644
--- a/drivers/scsi/53c7xx.c
+++ b/drivers/scsi/53c7xx.c
@@ -6090,8 +6090,8 @@ NCR53c7x0_release(struct Scsi_Host *host) {
6090 if (hostdata->num_cmds) 6090 if (hostdata->num_cmds)
6091 printk ("scsi%d : leaked %d NCR53c7x0_cmd structures\n", 6091 printk ("scsi%d : leaked %d NCR53c7x0_cmd structures\n",
6092 host->host_no, hostdata->num_cmds); 6092 host->host_no, hostdata->num_cmds);
6093 if (hostdata->events) 6093
6094 vfree ((void *)hostdata->events); 6094 vfree(hostdata->events);
6095 6095
6096 /* XXX This assumes default cache mode to be IOMAP_FULL_CACHING, which 6096 /* XXX This assumes default cache mode to be IOMAP_FULL_CACHING, which
6097 * XXX may be invalid (CONFIG_060_WRITETHROUGH) 6097 * XXX may be invalid (CONFIG_060_WRITETHROUGH)
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index bd0e1b6be1..da6e51c7fe 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -116,7 +116,7 @@ typedef struct {
116} scsi_changer; 116} scsi_changer;
117 117
118static LIST_HEAD(ch_devlist); 118static LIST_HEAD(ch_devlist);
119static spinlock_t ch_devlist_lock = SPIN_LOCK_UNLOCKED; 119static DEFINE_SPINLOCK(ch_devlist_lock);
120static int ch_devcount; 120static int ch_devcount;
121 121
122static struct scsi_driver ch_template = 122static struct scsi_driver ch_template =
@@ -560,7 +560,7 @@ ch_set_voltag(scsi_changer *ch, u_int elem,
560 return result; 560 return result;
561} 561}
562 562
563static int ch_gstatus(scsi_changer *ch, int type, unsigned char *dest) 563static int ch_gstatus(scsi_changer *ch, int type, unsigned char __user *dest)
564{ 564{
565 int retval = 0; 565 int retval = 0;
566 u_char data[16]; 566 u_char data[16];
@@ -634,6 +634,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
634{ 634{
635 scsi_changer *ch = file->private_data; 635 scsi_changer *ch = file->private_data;
636 int retval; 636 int retval;
637 void __user *argp = (void __user *)arg;
637 638
638 switch (cmd) { 639 switch (cmd) {
639 case CHIOGPARAMS: 640 case CHIOGPARAMS:
@@ -646,7 +647,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
646 params.cp_nportals = ch->counts[CHET_IE]; 647 params.cp_nportals = ch->counts[CHET_IE];
647 params.cp_ndrives = ch->counts[CHET_DT]; 648 params.cp_ndrives = ch->counts[CHET_DT];
648 649
649 if (copy_to_user((void *) arg, &params, sizeof(params))) 650 if (copy_to_user(argp, &params, sizeof(params)))
650 return -EFAULT; 651 return -EFAULT;
651 return 0; 652 return 0;
652 } 653 }
@@ -671,7 +672,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
671 vparams.cvp_n4 = ch->counts[CHET_V4]; 672 vparams.cvp_n4 = ch->counts[CHET_V4];
672 strncpy(vparams.cvp_label4,vendor_labels[3],16); 673 strncpy(vparams.cvp_label4,vendor_labels[3],16);
673 } 674 }
674 if (copy_to_user((void *) arg, &vparams, sizeof(vparams))) 675 if (copy_to_user(argp, &vparams, sizeof(vparams)))
675 return -EFAULT; 676 return -EFAULT;
676 return 0; 677 return 0;
677 } 678 }
@@ -680,7 +681,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
680 { 681 {
681 struct changer_position pos; 682 struct changer_position pos;
682 683
683 if (copy_from_user(&pos, (void*)arg, sizeof (pos))) 684 if (copy_from_user(&pos, argp, sizeof (pos)))
684 return -EFAULT; 685 return -EFAULT;
685 686
686 if (0 != ch_checkrange(ch, pos.cp_type, pos.cp_unit)) { 687 if (0 != ch_checkrange(ch, pos.cp_type, pos.cp_unit)) {
@@ -699,7 +700,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
699 { 700 {
700 struct changer_move mv; 701 struct changer_move mv;
701 702
702 if (copy_from_user(&mv, (void*)arg, sizeof (mv))) 703 if (copy_from_user(&mv, argp, sizeof (mv)))
703 return -EFAULT; 704 return -EFAULT;
704 705
705 if (0 != ch_checkrange(ch, mv.cm_fromtype, mv.cm_fromunit) || 706 if (0 != ch_checkrange(ch, mv.cm_fromtype, mv.cm_fromunit) ||
@@ -721,7 +722,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
721 { 722 {
722 struct changer_exchange mv; 723 struct changer_exchange mv;
723 724
724 if (copy_from_user(&mv, (void*)arg, sizeof (mv))) 725 if (copy_from_user(&mv, argp, sizeof (mv)))
725 return -EFAULT; 726 return -EFAULT;
726 727
727 if (0 != ch_checkrange(ch, mv.ce_srctype, mv.ce_srcunit ) || 728 if (0 != ch_checkrange(ch, mv.ce_srctype, mv.ce_srcunit ) ||
@@ -746,7 +747,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
746 { 747 {
747 struct changer_element_status ces; 748 struct changer_element_status ces;
748 749
749 if (copy_from_user(&ces, (void*)arg, sizeof (ces))) 750 if (copy_from_user(&ces, argp, sizeof (ces)))
750 return -EFAULT; 751 return -EFAULT;
751 if (ces.ces_type < 0 || ces.ces_type >= CH_TYPES) 752 if (ces.ces_type < 0 || ces.ces_type >= CH_TYPES)
752 return -EINVAL; 753 return -EINVAL;
@@ -762,7 +763,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
762 unsigned int elem; 763 unsigned int elem;
763 int result,i; 764 int result,i;
764 765
765 if (copy_from_user(&cge, (void*)arg, sizeof (cge))) 766 if (copy_from_user(&cge, argp, sizeof (cge)))
766 return -EFAULT; 767 return -EFAULT;
767 768
768 if (0 != ch_checkrange(ch, cge.cge_type, cge.cge_unit)) 769 if (0 != ch_checkrange(ch, cge.cge_type, cge.cge_unit))
@@ -825,7 +826,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
825 kfree(buffer); 826 kfree(buffer);
826 up(&ch->lock); 827 up(&ch->lock);
827 828
828 if (copy_to_user((void*)arg, &cge, sizeof (cge))) 829 if (copy_to_user(argp, &cge, sizeof (cge)))
829 return -EFAULT; 830 return -EFAULT;
830 return result; 831 return result;
831 } 832 }
@@ -843,7 +844,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
843 struct changer_set_voltag csv; 844 struct changer_set_voltag csv;
844 int elem; 845 int elem;
845 846
846 if (copy_from_user(&csv, (void*)arg, sizeof(csv))) 847 if (copy_from_user(&csv, argp, sizeof(csv)))
847 return -EFAULT; 848 return -EFAULT;
848 849
849 if (0 != ch_checkrange(ch, csv.csv_type, csv.csv_unit)) { 850 if (0 != ch_checkrange(ch, csv.csv_type, csv.csv_unit)) {
@@ -861,7 +862,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
861 } 862 }
862 863
863 default: 864 default:
864 return scsi_ioctl(ch->device, cmd, (void*)arg); 865 return scsi_ioctl(ch->device, cmd, argp);
865 866
866 } 867 }
867} 868}
@@ -894,9 +895,9 @@ static long ch_ioctl_compat(struct file * file,
894 case CHIOGSTATUS32: 895 case CHIOGSTATUS32:
895 { 896 {
896 struct changer_element_status32 ces32; 897 struct changer_element_status32 ces32;
897 unsigned char *data; 898 unsigned char __user *data;
898 899
899 if (copy_from_user(&ces32, (void*)arg, sizeof (ces32))) 900 if (copy_from_user(&ces32, (void __user *)arg, sizeof (ces32)))
900 return -EFAULT; 901 return -EFAULT;
901 if (ces32.ces_type < 0 || ces32.ces_type >= CH_TYPES) 902 if (ces32.ces_type < 0 || ces32.ces_type >= CH_TYPES)
902 return -EINVAL; 903 return -EINVAL;
diff --git a/drivers/scsi/cpqfcTSinit.c b/drivers/scsi/cpqfcTSinit.c
index d72be0ce89..3fda8d455c 100644
--- a/drivers/scsi/cpqfcTSinit.c
+++ b/drivers/scsi/cpqfcTSinit.c
@@ -691,8 +691,7 @@ int cpqfcTS_ioctl( struct scsi_device *ScsiDev, int Cmnd, void *arg)
691 if( copy_to_user( vendor_cmd->bufp, buf, vendor_cmd->len)) 691 if( copy_to_user( vendor_cmd->bufp, buf, vendor_cmd->len))
692 result = -EFAULT; 692 result = -EFAULT;
693 693
694 if( buf) 694 kfree(buf);
695 kfree( buf);
696 695
697 return result; 696 return result;
698 } 697 }
diff --git a/drivers/scsi/ibmmca.c b/drivers/scsi/ibmmca.c
index b5dc353555..6e54c7d9b3 100644
--- a/drivers/scsi/ibmmca.c
+++ b/drivers/scsi/ibmmca.c
@@ -36,7 +36,6 @@
36#include <linux/proc_fs.h> 36#include <linux/proc_fs.h>
37#include <linux/stat.h> 37#include <linux/stat.h>
38#include <linux/mca.h> 38#include <linux/mca.h>
39#include <linux/string.h>
40#include <linux/spinlock.h> 39#include <linux/spinlock.h>
41#include <linux/init.h> 40#include <linux/init.h>
42#include <linux/mca-legacy.h> 41#include <linux/mca-legacy.h>
diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
index 89a4a0615c..3f2f2464fa 100644
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -1377,7 +1377,7 @@ static int osst_read_back_buffer_and_rewrite(struct osst_tape * STp, struct scsi
1377 1377
1378 if ((STp->buffer)->syscall_result || !SRpnt) { 1378 if ((STp->buffer)->syscall_result || !SRpnt) {
1379 printk(KERN_ERR "%s:E: Failed to read frame back from OnStream buffer\n", name); 1379 printk(KERN_ERR "%s:E: Failed to read frame back from OnStream buffer\n", name);
1380 vfree((void *)buffer); 1380 vfree(buffer);
1381 *aSRpnt = SRpnt; 1381 *aSRpnt = SRpnt;
1382 return (-EIO); 1382 return (-EIO);
1383 } 1383 }
@@ -1419,7 +1419,7 @@ static int osst_read_back_buffer_and_rewrite(struct osst_tape * STp, struct scsi
1419 1419
1420 if (new_frame > frame + 1000) { 1420 if (new_frame > frame + 1000) {
1421 printk(KERN_ERR "%s:E: Failed to find writable tape media\n", name); 1421 printk(KERN_ERR "%s:E: Failed to find writable tape media\n", name);
1422 vfree((void *)buffer); 1422 vfree(buffer);
1423 return (-EIO); 1423 return (-EIO);
1424 } 1424 }
1425 if ( i >= nframes + pending ) break; 1425 if ( i >= nframes + pending ) break;
@@ -1500,7 +1500,7 @@ static int osst_read_back_buffer_and_rewrite(struct osst_tape * STp, struct scsi
1500 SRpnt->sr_sense_buffer[12] == 0 && 1500 SRpnt->sr_sense_buffer[12] == 0 &&
1501 SRpnt->sr_sense_buffer[13] == 2) { 1501 SRpnt->sr_sense_buffer[13] == 2) {
1502 printk(KERN_ERR "%s:E: Volume overflow in write error recovery\n", name); 1502 printk(KERN_ERR "%s:E: Volume overflow in write error recovery\n", name);
1503 vfree((void *)buffer); 1503 vfree(buffer);
1504 return (-EIO); /* hit end of tape = fail */ 1504 return (-EIO); /* hit end of tape = fail */
1505 } 1505 }
1506 i = ((SRpnt->sr_sense_buffer[3] << 24) | 1506 i = ((SRpnt->sr_sense_buffer[3] << 24) |
@@ -1525,7 +1525,7 @@ static int osst_read_back_buffer_and_rewrite(struct osst_tape * STp, struct scsi
1525 } 1525 }
1526 if (!pending) 1526 if (!pending)
1527 osst_copy_to_buffer(STp->buffer, p); /* so buffer content == at entry in all cases */ 1527 osst_copy_to_buffer(STp->buffer, p); /* so buffer content == at entry in all cases */
1528 vfree((void *)buffer); 1528 vfree(buffer);
1529 return 0; 1529 return 0;
1530} 1530}
1531 1531
@@ -5852,7 +5852,7 @@ static int osst_remove(struct device *dev)
5852 os_scsi_tapes[i] = NULL; 5852 os_scsi_tapes[i] = NULL;
5853 osst_nr_dev--; 5853 osst_nr_dev--;
5854 write_unlock(&os_scsi_tapes_lock); 5854 write_unlock(&os_scsi_tapes_lock);
5855 if (tpnt->header_cache != NULL) vfree(tpnt->header_cache); 5855 vfree(tpnt->header_cache);
5856 if (tpnt->buffer) { 5856 if (tpnt->buffer) {
5857 normalize_buffer(tpnt->buffer); 5857 normalize_buffer(tpnt->buffer);
5858 kfree(tpnt->buffer); 5858 kfree(tpnt->buffer);
@@ -5896,8 +5896,7 @@ static void __exit exit_osst (void)
5896 for (i=0; i < osst_max_dev; ++i) { 5896 for (i=0; i < osst_max_dev; ++i) {
5897 if (!(STp = os_scsi_tapes[i])) continue; 5897 if (!(STp = os_scsi_tapes[i])) continue;
5898 /* This is defensive, supposed to happen during detach */ 5898 /* This is defensive, supposed to happen during detach */
5899 if (STp->header_cache) 5899 vfree(STp->header_cache);
5900 vfree(STp->header_cache);
5901 if (STp->buffer) { 5900 if (STp->buffer) {
5902 normalize_buffer(STp->buffer); 5901 normalize_buffer(STp->buffer);
5903 kfree(STp->buffer); 5902 kfree(STp->buffer);
diff --git a/drivers/scsi/pluto.c b/drivers/scsi/pluto.c
index 623082d3a8..c89da7d5b6 100644
--- a/drivers/scsi/pluto.c
+++ b/drivers/scsi/pluto.c
@@ -95,8 +95,7 @@ int __init pluto_detect(Scsi_Host_Template *tpnt)
95 int i, retry, nplutos; 95 int i, retry, nplutos;
96 fc_channel *fc; 96 fc_channel *fc;
97 Scsi_Device dev; 97 Scsi_Device dev;
98 struct timer_list fc_timer = 98 DEFINE_TIMER(fc_timer, pluto_detect_timeout, 0, 0);
99 TIMER_INITIALIZER(pluto_detect_timeout, 0, 0);
100 99
101 tpnt->proc_name = "pluto"; 100 tpnt->proc_name = "pluto";
102 fcscount = 0; 101 fcscount = 0;
diff --git a/drivers/scsi/qla2xxx/qla_dbg.c b/drivers/scsi/qla2xxx/qla_dbg.c
index 72bbaa91dc..9791496fa7 100644
--- a/drivers/scsi/qla2xxx/qla_dbg.c
+++ b/drivers/scsi/qla2xxx/qla_dbg.c
@@ -1334,7 +1334,7 @@ qla24xx_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
1334 1334
1335 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0); 1335 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0);
1336 WRT_REG_DWORD(dmp_reg, 0xB0200000); 1336 WRT_REG_DWORD(dmp_reg, 0xB0200000);
1337 dmp_reg = (uint32_t *)((uint8_t *)reg + 0xFC); 1337 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC);
1338 fw->shadow_reg[2] = RD_REG_DWORD(dmp_reg); 1338 fw->shadow_reg[2] = RD_REG_DWORD(dmp_reg);
1339 1339
1340 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0); 1340 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0);
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 5b65e20889..4d75cdfa0a 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -864,7 +864,7 @@ static void autoconfig(struct uart_8250_port *up, unsigned int probeflags)
864 /* 864 /*
865 * We're pretty sure there's a port here. Lets find out what 865 * We're pretty sure there's a port here. Lets find out what
866 * type of port it is. The IIR top two bits allows us to find 866 * type of port it is. The IIR top two bits allows us to find
867 * out if its 8250 or 16450, 16550, 16550A or later. This 867 * out if it's 8250 or 16450, 16550, 16550A or later. This
868 * determines what we test for next. 868 * determines what we test for next.
869 * 869 *
870 * We also initialise the EFR (if any) to zero for later. The 870 * We also initialise the EFR (if any) to zero for later. The
diff --git a/drivers/serial/mcfserial.c b/drivers/serial/mcfserial.c
index 43b03c55f4..e2ebdcad55 100644
--- a/drivers/serial/mcfserial.c
+++ b/drivers/serial/mcfserial.c
@@ -63,8 +63,13 @@ struct timer_list mcfrs_timer_struct;
63#endif 63#endif
64 64
65#if defined(CONFIG_HW_FEITH) 65#if defined(CONFIG_HW_FEITH)
66 #define CONSOLE_BAUD_RATE 38400 66#define CONSOLE_BAUD_RATE 38400
67 #define DEFAULT_CBAUD B38400 67#define DEFAULT_CBAUD B38400
68#endif
69
70#if defined(CONFIG_MOD5272)
71#define CONSOLE_BAUD_RATE 115200
72#define DEFAULT_CBAUD B115200
68#endif 73#endif
69 74
70#ifndef CONSOLE_BAUD_RATE 75#ifndef CONSOLE_BAUD_RATE
@@ -90,7 +95,7 @@ static struct tty_driver *mcfrs_serial_driver;
90#undef SERIAL_DEBUG_OPEN 95#undef SERIAL_DEBUG_OPEN
91#undef SERIAL_DEBUG_FLOW 96#undef SERIAL_DEBUG_FLOW
92 97
93#if defined(CONFIG_M527x) || defined(CONFIG_M528x) 98#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
94#define IRQBASE (MCFINT_VECBASE+MCFINT_UART0) 99#define IRQBASE (MCFINT_VECBASE+MCFINT_UART0)
95#else 100#else
96#define IRQBASE 73 101#define IRQBASE 73
@@ -1510,7 +1515,7 @@ static void mcfrs_irqinit(struct mcf_serial *info)
1510 *portp = (*portp & ~0x000000ff) | 0x00000055; 1515 *portp = (*portp & ~0x000000ff) | 0x00000055;
1511 portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PDCNT); 1516 portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PDCNT);
1512 *portp = (*portp & ~0x000003fc) | 0x000002a8; 1517 *portp = (*portp & ~0x000003fc) | 0x000002a8;
1513#elif defined(CONFIG_M527x) || defined(CONFIG_M528x) 1518#elif defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
1514 volatile unsigned char *icrp, *uartp; 1519 volatile unsigned char *icrp, *uartp;
1515 volatile unsigned long *imrp; 1520 volatile unsigned long *imrp;
1516 1521
diff --git a/drivers/serial/serial_txx9.c b/drivers/serial/serial_txx9.c
index 49afadbe46..f10c86d60b 100644
--- a/drivers/serial/serial_txx9.c
+++ b/drivers/serial/serial_txx9.c
@@ -31,6 +31,8 @@
31 * 1.01 Set fifosize to make tx_empry called properly. 31 * 1.01 Set fifosize to make tx_empry called properly.
32 * Use standard uart_get_divisor. 32 * Use standard uart_get_divisor.
33 * 1.02 Cleanup. (import 8250.c changes) 33 * 1.02 Cleanup. (import 8250.c changes)
34 * 1.03 Fix low-latency mode. (import 8250.c changes)
35 * 1.04 Remove usage of deprecated functions, cleanup.
34 */ 36 */
35#include <linux/config.h> 37#include <linux/config.h>
36 38
@@ -54,7 +56,7 @@
54#include <asm/io.h> 56#include <asm/io.h>
55#include <asm/irq.h> 57#include <asm/irq.h>
56 58
57static char *serial_version = "1.02"; 59static char *serial_version = "1.04";
58static char *serial_name = "TX39/49 Serial driver"; 60static char *serial_name = "TX39/49 Serial driver";
59 61
60#define PASS_LIMIT 256 62#define PASS_LIMIT 256
@@ -86,9 +88,9 @@ static char *serial_name = "TX39/49 Serial driver";
86 */ 88 */
87#ifdef ENABLE_SERIAL_TXX9_PCI 89#ifdef ENABLE_SERIAL_TXX9_PCI
88#define NR_PCI_BOARDS 4 90#define NR_PCI_BOARDS 4
89#define UART_NR (2 + NR_PCI_BOARDS) 91#define UART_NR (4 + NR_PCI_BOARDS)
90#else 92#else
91#define UART_NR 2 93#define UART_NR 4
92#endif 94#endif
93 95
94struct uart_txx9_port { 96struct uart_txx9_port {
@@ -304,8 +306,11 @@ receive_chars(struct uart_txx9_port *up, unsigned int *status, struct pt_regs *r
304 /* The following is not allowed by the tty layer and 306 /* The following is not allowed by the tty layer and
305 unsafe. It should be fixed ASAP */ 307 unsafe. It should be fixed ASAP */
306 if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) { 308 if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
307 if(tty->low_latency) 309 if (tty->low_latency) {
310 spin_unlock(&up->port.lock);
308 tty_flip_buffer_push(tty); 311 tty_flip_buffer_push(tty);
312 spin_lock(&up->port.lock);
313 }
309 /* If this failed then we will throw away the 314 /* If this failed then we will throw away the
310 bytes but must do so to clear interrupts */ 315 bytes but must do so to clear interrupts */
311 } 316 }
@@ -356,7 +361,9 @@ receive_chars(struct uart_txx9_port *up, unsigned int *status, struct pt_regs *r
356 ignore_char: 361 ignore_char:
357 disr = sio_in(up, TXX9_SIDISR); 362 disr = sio_in(up, TXX9_SIDISR);
358 } while (!(disr & TXX9_SIDISR_UVALID) && (max_count-- > 0)); 363 } while (!(disr & TXX9_SIDISR_UVALID) && (max_count-- > 0));
364 spin_unlock(&up->port.lock);
359 tty_flip_buffer_push(tty); 365 tty_flip_buffer_push(tty);
366 spin_lock(&up->port.lock);
360 *status = disr; 367 *status = disr;
361} 368}
362 369
@@ -667,17 +674,8 @@ serial_txx9_pm(struct uart_port *port, unsigned int state,
667 unsigned int oldstate) 674 unsigned int oldstate)
668{ 675{
669 struct uart_txx9_port *up = (struct uart_txx9_port *)port; 676 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
670 if (state) { 677 if (up->pm)
671 /* sleep */ 678 up->pm(port, state, oldstate);
672
673 if (up->pm)
674 up->pm(port, state, oldstate);
675 } else {
676 /* wake */
677
678 if (up->pm)
679 up->pm(port, state, oldstate);
680 }
681} 679}
682 680
683static int serial_txx9_request_resource(struct uart_txx9_port *up) 681static int serial_txx9_request_resource(struct uart_txx9_port *up)
@@ -979,14 +977,6 @@ static int __init serial_txx9_console_init(void)
979} 977}
980console_initcall(serial_txx9_console_init); 978console_initcall(serial_txx9_console_init);
981 979
982static int __init serial_txx9_late_console_init(void)
983{
984 if (!(serial_txx9_console.flags & CON_ENABLED))
985 register_console(&serial_txx9_console);
986 return 0;
987}
988late_initcall(serial_txx9_late_console_init);
989
990#define SERIAL_TXX9_CONSOLE &serial_txx9_console 980#define SERIAL_TXX9_CONSOLE &serial_txx9_console
991#else 981#else
992#define SERIAL_TXX9_CONSOLE NULL 982#define SERIAL_TXX9_CONSOLE NULL
@@ -1039,6 +1029,73 @@ static void serial_txx9_resume_port(int line)
1039 uart_resume_port(&serial_txx9_reg, &serial_txx9_ports[line].port); 1029 uart_resume_port(&serial_txx9_reg, &serial_txx9_ports[line].port);
1040} 1030}
1041 1031
1032static DECLARE_MUTEX(serial_txx9_sem);
1033
1034/**
1035 * serial_txx9_register_port - register a serial port
1036 * @port: serial port template
1037 *
1038 * Configure the serial port specified by the request.
1039 *
1040 * The port is then probed and if necessary the IRQ is autodetected
1041 * If this fails an error is returned.
1042 *
1043 * On success the port is ready to use and the line number is returned.
1044 */
1045static int __devinit serial_txx9_register_port(struct uart_port *port)
1046{
1047 int i;
1048 struct uart_txx9_port *uart;
1049 int ret = -ENOSPC;
1050
1051 down(&serial_txx9_sem);
1052 for (i = 0; i < UART_NR; i++) {
1053 uart = &serial_txx9_ports[i];
1054 if (uart->port.type == PORT_UNKNOWN)
1055 break;
1056 }
1057 if (i < UART_NR) {
1058 uart_remove_one_port(&serial_txx9_reg, &uart->port);
1059 uart->port.iobase = port->iobase;
1060 uart->port.membase = port->membase;
1061 uart->port.irq = port->irq;
1062 uart->port.uartclk = port->uartclk;
1063 uart->port.iotype = port->iotype;
1064 uart->port.flags = port->flags | UPF_BOOT_AUTOCONF;
1065 uart->port.mapbase = port->mapbase;
1066 if (port->dev)
1067 uart->port.dev = port->dev;
1068 ret = uart_add_one_port(&serial_txx9_reg, &uart->port);
1069 if (ret == 0)
1070 ret = uart->port.line;
1071 }
1072 up(&serial_txx9_sem);
1073 return ret;
1074}
1075
1076/**
1077 * serial_txx9_unregister_port - remove a txx9 serial port at runtime
1078 * @line: serial line number
1079 *
1080 * Remove one serial port. This may not be called from interrupt
1081 * context. We hand the port back to the our control.
1082 */
1083static void __devexit serial_txx9_unregister_port(int line)
1084{
1085 struct uart_txx9_port *uart = &serial_txx9_ports[line];
1086
1087 down(&serial_txx9_sem);
1088 uart_remove_one_port(&serial_txx9_reg, &uart->port);
1089 uart->port.flags = 0;
1090 uart->port.type = PORT_UNKNOWN;
1091 uart->port.iobase = 0;
1092 uart->port.mapbase = 0;
1093 uart->port.membase = 0;
1094 uart->port.dev = NULL;
1095 uart_add_one_port(&serial_txx9_reg, &uart->port);
1096 up(&serial_txx9_sem);
1097}
1098
1042/* 1099/*
1043 * Probe one serial board. Unfortunately, there is no rhyme nor reason 1100 * Probe one serial board. Unfortunately, there is no rhyme nor reason
1044 * to the arrangement of serial ports on a PCI card. 1101 * to the arrangement of serial ports on a PCI card.
@@ -1056,13 +1113,13 @@ pciserial_txx9_init_one(struct pci_dev *dev, const struct pci_device_id *ent)
1056 1113
1057 memset(&port, 0, sizeof(port)); 1114 memset(&port, 0, sizeof(port));
1058 port.ops = &serial_txx9_pops; 1115 port.ops = &serial_txx9_pops;
1059 port.flags |= UPF_BOOT_AUTOCONF; /* uart_ops.config_port will be called */
1060 port.flags |= UPF_TXX9_HAVE_CTS_LINE; 1116 port.flags |= UPF_TXX9_HAVE_CTS_LINE;
1061 port.uartclk = 66670000; 1117 port.uartclk = 66670000;
1062 port.irq = dev->irq; 1118 port.irq = dev->irq;
1063 port.iotype = UPIO_PORT; 1119 port.iotype = UPIO_PORT;
1064 port.iobase = pci_resource_start(dev, 1); 1120 port.iobase = pci_resource_start(dev, 1);
1065 line = uart_register_port(&serial_txx9_reg, &port); 1121 port.dev = &dev->dev;
1122 line = serial_txx9_register_port(&port);
1066 if (line < 0) { 1123 if (line < 0) {
1067 printk(KERN_WARNING "Couldn't register serial port %s: %d\n", pci_name(dev), line); 1124 printk(KERN_WARNING "Couldn't register serial port %s: %d\n", pci_name(dev), line);
1068 } 1125 }
@@ -1078,7 +1135,7 @@ static void __devexit pciserial_txx9_remove_one(struct pci_dev *dev)
1078 pci_set_drvdata(dev, NULL); 1135 pci_set_drvdata(dev, NULL);
1079 1136
1080 if (line) { 1137 if (line) {
1081 uart_unregister_port(&serial_txx9_reg, line); 1138 serial_txx9_unregister_port(line);
1082 pci_disable_device(dev); 1139 pci_disable_device(dev);
1083 } 1140 }
1084} 1141}
@@ -1089,6 +1146,8 @@ static int pciserial_txx9_suspend_one(struct pci_dev *dev, pm_message_t state)
1089 1146
1090 if (line) 1147 if (line)
1091 serial_txx9_suspend_port(line); 1148 serial_txx9_suspend_port(line);
1149 pci_save_state(dev);
1150 pci_set_power_state(dev, pci_choose_state(dev, state));
1092 return 0; 1151 return 0;
1093} 1152}
1094 1153
@@ -1096,8 +1155,13 @@ static int pciserial_txx9_resume_one(struct pci_dev *dev)
1096{ 1155{
1097 int line = (int)(long)pci_get_drvdata(dev); 1156 int line = (int)(long)pci_get_drvdata(dev);
1098 1157
1099 if (line) 1158 pci_set_power_state(dev, PCI_D0);
1159 pci_restore_state(dev);
1160
1161 if (line) {
1162 pci_enable_device(dev);
1100 serial_txx9_resume_port(line); 1163 serial_txx9_resume_port(line);
1164 }
1101 return 0; 1165 return 0;
1102} 1166}
1103 1167
diff --git a/drivers/telephony/ixj.c b/drivers/telephony/ixj.c
index f2c9fa423d..f6704688ee 100644
--- a/drivers/telephony/ixj.c
+++ b/drivers/telephony/ixj.c
@@ -774,10 +774,7 @@ static int ixj_wink(IXJ *j)
774 j->pots_winkstart = jiffies; 774 j->pots_winkstart = jiffies;
775 SLIC_SetState(PLD_SLIC_STATE_OC, j); 775 SLIC_SetState(PLD_SLIC_STATE_OC, j);
776 776
777 while (time_before(jiffies, j->pots_winkstart + j->winktime)) { 777 msleep(jiffies_to_msecs(j->winktime));
778 set_current_state(TASK_INTERRUPTIBLE);
779 schedule_timeout(1);
780 }
781 778
782 SLIC_SetState(slicnow, j); 779 SLIC_SetState(slicnow, j);
783 return 0; 780 return 0;
@@ -1912,7 +1909,6 @@ static int ixj_pcmcia_cable_check(IXJ *j)
1912 1909
1913static int ixj_hookstate(IXJ *j) 1910static int ixj_hookstate(IXJ *j)
1914{ 1911{
1915 unsigned long det;
1916 int fOffHook = 0; 1912 int fOffHook = 0;
1917 1913
1918 switch (j->cardtype) { 1914 switch (j->cardtype) {
@@ -1943,11 +1939,7 @@ static int ixj_hookstate(IXJ *j)
1943 j->pld_slicr.bits.state == PLD_SLIC_STATE_STANDBY) { 1939 j->pld_slicr.bits.state == PLD_SLIC_STATE_STANDBY) {
1944 if (j->flags.ringing || j->flags.cringing) { 1940 if (j->flags.ringing || j->flags.cringing) {
1945 if (!in_interrupt()) { 1941 if (!in_interrupt()) {
1946 det = jiffies + (hertz / 50); 1942 msleep(20);
1947 while (time_before(jiffies, det)) {
1948 set_current_state(TASK_INTERRUPTIBLE);
1949 schedule_timeout(1);
1950 }
1951 } 1943 }
1952 SLIC_GetState(j); 1944 SLIC_GetState(j);
1953 if (j->pld_slicr.bits.state == PLD_SLIC_STATE_RINGING) { 1945 if (j->pld_slicr.bits.state == PLD_SLIC_STATE_RINGING) {
@@ -2062,7 +2054,7 @@ static void ixj_ring_start(IXJ *j)
2062static int ixj_ring(IXJ *j) 2054static int ixj_ring(IXJ *j)
2063{ 2055{
2064 char cntr; 2056 char cntr;
2065 unsigned long jif, det; 2057 unsigned long jif;
2066 2058
2067 j->flags.ringing = 1; 2059 j->flags.ringing = 1;
2068 if (ixj_hookstate(j) & 1) { 2060 if (ixj_hookstate(j) & 1) {
@@ -2070,7 +2062,6 @@ static int ixj_ring(IXJ *j)
2070 j->flags.ringing = 0; 2062 j->flags.ringing = 0;
2071 return 1; 2063 return 1;
2072 } 2064 }
2073 det = 0;
2074 for (cntr = 0; cntr < j->maxrings; cntr++) { 2065 for (cntr = 0; cntr < j->maxrings; cntr++) {
2075 jif = jiffies + (1 * hertz); 2066 jif = jiffies + (1 * hertz);
2076 ixj_ring_on(j); 2067 ixj_ring_on(j);
@@ -2080,8 +2071,7 @@ static int ixj_ring(IXJ *j)
2080 j->flags.ringing = 0; 2071 j->flags.ringing = 0;
2081 return 1; 2072 return 1;
2082 } 2073 }
2083 set_current_state(TASK_INTERRUPTIBLE); 2074 schedule_timeout_interruptible(1);
2084 schedule_timeout(1);
2085 if (signal_pending(current)) 2075 if (signal_pending(current))
2086 break; 2076 break;
2087 } 2077 }
@@ -2089,20 +2079,13 @@ static int ixj_ring(IXJ *j)
2089 ixj_ring_off(j); 2079 ixj_ring_off(j);
2090 while (time_before(jiffies, jif)) { 2080 while (time_before(jiffies, jif)) {
2091 if (ixj_hookstate(j) & 1) { 2081 if (ixj_hookstate(j) & 1) {
2092 det = jiffies + (hertz / 100); 2082 msleep(10);
2093 while (time_before(jiffies, det)) {
2094 set_current_state(TASK_INTERRUPTIBLE);
2095 schedule_timeout(1);
2096 if (signal_pending(current))
2097 break;
2098 }
2099 if (ixj_hookstate(j) & 1) { 2083 if (ixj_hookstate(j) & 1) {
2100 j->flags.ringing = 0; 2084 j->flags.ringing = 0;
2101 return 1; 2085 return 1;
2102 } 2086 }
2103 } 2087 }
2104 set_current_state(TASK_INTERRUPTIBLE); 2088 schedule_timeout_interruptible(1);
2105 schedule_timeout(1);
2106 if (signal_pending(current)) 2089 if (signal_pending(current))
2107 break; 2090 break;
2108 } 2091 }
@@ -2168,10 +2151,8 @@ static int ixj_release(struct inode *inode, struct file *file_p)
2168 * Set up locks to ensure that only one process is talking to the DSP at a time. 2151 * Set up locks to ensure that only one process is talking to the DSP at a time.
2169 * This is necessary to keep the DSP from locking up. 2152 * This is necessary to keep the DSP from locking up.
2170 */ 2153 */
2171 while(test_and_set_bit(board, (void *)&j->busyflags) != 0) { 2154 while(test_and_set_bit(board, (void *)&j->busyflags) != 0)
2172 set_current_state(TASK_INTERRUPTIBLE); 2155 schedule_timeout_interruptible(1);
2173 schedule_timeout(1);
2174 }
2175 if (ixjdebug & 0x0002) 2156 if (ixjdebug & 0x0002)
2176 printk(KERN_INFO "Closing board %d\n", NUM(inode)); 2157 printk(KERN_INFO "Closing board %d\n", NUM(inode));
2177 2158
@@ -3301,14 +3282,10 @@ static void ixj_write_cidcw(IXJ *j)
3301 ixj_play_tone(j, 23); 3282 ixj_play_tone(j, 23);
3302 3283
3303 clear_bit(j->board, &j->busyflags); 3284 clear_bit(j->board, &j->busyflags);
3304 while(j->tone_state) { 3285 while(j->tone_state)
3305 set_current_state(TASK_INTERRUPTIBLE); 3286 schedule_timeout_interruptible(1);
3306 schedule_timeout(1); 3287 while(test_and_set_bit(j->board, (void *)&j->busyflags) != 0)
3307 } 3288 schedule_timeout_interruptible(1);
3308 while(test_and_set_bit(j->board, (void *)&j->busyflags) != 0) {
3309 set_current_state(TASK_INTERRUPTIBLE);
3310 schedule_timeout(1);
3311 }
3312 if(ixjdebug & 0x0200) { 3289 if(ixjdebug & 0x0200) {
3313 printk("IXJ cidcw phone%d first tone end at %ld\n", j->board, jiffies); 3290 printk("IXJ cidcw phone%d first tone end at %ld\n", j->board, jiffies);
3314 } 3291 }
@@ -3328,14 +3305,10 @@ static void ixj_write_cidcw(IXJ *j)
3328 ixj_play_tone(j, 24); 3305 ixj_play_tone(j, 24);
3329 3306
3330 clear_bit(j->board, &j->busyflags); 3307 clear_bit(j->board, &j->busyflags);
3331 while(j->tone_state) { 3308 while(j->tone_state)
3332 set_current_state(TASK_INTERRUPTIBLE); 3309 schedule_timeout_interruptible(1);
3333 schedule_timeout(1); 3310 while(test_and_set_bit(j->board, (void *)&j->busyflags) != 0)
3334 } 3311 schedule_timeout_interruptible(1);
3335 while(test_and_set_bit(j->board, (void *)&j->busyflags) != 0) {
3336 set_current_state(TASK_INTERRUPTIBLE);
3337 schedule_timeout(1);
3338 }
3339 if(ixjdebug & 0x0200) { 3312 if(ixjdebug & 0x0200) {
3340 printk("IXJ cidcw phone%d sent second tone at %ld\n", j->board, jiffies); 3313 printk("IXJ cidcw phone%d sent second tone at %ld\n", j->board, jiffies);
3341 } 3314 }
@@ -3343,14 +3316,10 @@ static void ixj_write_cidcw(IXJ *j)
3343 j->cidcw_wait = jiffies + ((50 * hertz) / 100); 3316 j->cidcw_wait = jiffies + ((50 * hertz) / 100);
3344 3317
3345 clear_bit(j->board, &j->busyflags); 3318 clear_bit(j->board, &j->busyflags);
3346 while(!j->flags.cidcw_ack && time_before(jiffies, j->cidcw_wait)) { 3319 while(!j->flags.cidcw_ack && time_before(jiffies, j->cidcw_wait))
3347 set_current_state(TASK_INTERRUPTIBLE); 3320 schedule_timeout_interruptible(1);
3348 schedule_timeout(1); 3321 while(test_and_set_bit(j->board, (void *)&j->busyflags) != 0)
3349 } 3322 schedule_timeout_interruptible(1);
3350 while(test_and_set_bit(j->board, (void *)&j->busyflags) != 0) {
3351 set_current_state(TASK_INTERRUPTIBLE);
3352 schedule_timeout(1);
3353 }
3354 j->cidcw_wait = 0; 3323 j->cidcw_wait = 0;
3355 if(!j->flags.cidcw_ack) { 3324 if(!j->flags.cidcw_ack) {
3356 if(ixjdebug & 0x0200) { 3325 if(ixjdebug & 0x0200) {
@@ -6125,10 +6094,8 @@ static int ixj_ioctl(struct inode *inode, struct file *file_p, unsigned int cmd,
6125 * Set up locks to ensure that only one process is talking to the DSP at a time. 6094 * Set up locks to ensure that only one process is talking to the DSP at a time.
6126 * This is necessary to keep the DSP from locking up. 6095 * This is necessary to keep the DSP from locking up.
6127 */ 6096 */
6128 while(test_and_set_bit(board, (void *)&j->busyflags) != 0) { 6097 while(test_and_set_bit(board, (void *)&j->busyflags) != 0)
6129 set_current_state(TASK_INTERRUPTIBLE); 6098 schedule_timeout_interruptible(1);
6130 schedule_timeout(1);
6131 }
6132 if (ixjdebug & 0x0040) 6099 if (ixjdebug & 0x0040)
6133 printk("phone%d ioctl, cmd: 0x%x, arg: 0x%lx\n", minor, cmd, arg); 6100 printk("phone%d ioctl, cmd: 0x%x, arg: 0x%lx\n", minor, cmd, arg);
6134 if (minor >= IXJMAX) { 6101 if (minor >= IXJMAX) {
@@ -6694,8 +6661,6 @@ static struct file_operations ixj_fops =
6694 6661
6695static int ixj_linetest(IXJ *j) 6662static int ixj_linetest(IXJ *j)
6696{ 6663{
6697 unsigned long jifwait;
6698
6699 j->flags.pstncheck = 1; /* Testing */ 6664 j->flags.pstncheck = 1; /* Testing */
6700 j->flags.pstn_present = 0; /* Assume the line is not there */ 6665 j->flags.pstn_present = 0; /* Assume the line is not there */
6701 6666
@@ -6726,11 +6691,7 @@ static int ixj_linetest(IXJ *j)
6726 6691
6727 outb_p(j->pld_scrw.byte, j->XILINXbase); 6692 outb_p(j->pld_scrw.byte, j->XILINXbase);
6728 daa_set_mode(j, SOP_PU_CONVERSATION); 6693 daa_set_mode(j, SOP_PU_CONVERSATION);
6729 jifwait = jiffies + hertz; 6694 msleep(1000);
6730 while (time_before(jiffies, jifwait)) {
6731 set_current_state(TASK_INTERRUPTIBLE);
6732 schedule_timeout(1);
6733 }
6734 daa_int_read(j); 6695 daa_int_read(j);
6735 daa_set_mode(j, SOP_PU_RESET); 6696 daa_set_mode(j, SOP_PU_RESET);
6736 if (j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK) { 6697 if (j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK) {
@@ -6750,11 +6711,7 @@ static int ixj_linetest(IXJ *j)
6750 j->pld_slicw.bits.rly3 = 0; 6711 j->pld_slicw.bits.rly3 = 0;
6751 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01); 6712 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
6752 daa_set_mode(j, SOP_PU_CONVERSATION); 6713 daa_set_mode(j, SOP_PU_CONVERSATION);
6753 jifwait = jiffies + hertz; 6714 msleep(1000);
6754 while (time_before(jiffies, jifwait)) {
6755 set_current_state(TASK_INTERRUPTIBLE);
6756 schedule_timeout(1);
6757 }
6758 daa_int_read(j); 6715 daa_int_read(j);
6759 daa_set_mode(j, SOP_PU_RESET); 6716 daa_set_mode(j, SOP_PU_RESET);
6760 if (j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK) { 6717 if (j->m_DAAShadowRegs.XOP_REGS.XOP.xr0.bitreg.VDD_OK) {
@@ -6783,7 +6740,6 @@ static int ixj_linetest(IXJ *j)
6783static int ixj_selfprobe(IXJ *j) 6740static int ixj_selfprobe(IXJ *j)
6784{ 6741{
6785 unsigned short cmd; 6742 unsigned short cmd;
6786 unsigned long jif;
6787 int cnt; 6743 int cnt;
6788 BYTES bytes; 6744 BYTES bytes;
6789 6745
@@ -6933,29 +6889,13 @@ static int ixj_selfprobe(IXJ *j)
6933 } else { 6889 } else {
6934 if (j->cardtype == QTI_LINEJACK) { 6890 if (j->cardtype == QTI_LINEJACK) {
6935 LED_SetState(0x1, j); 6891 LED_SetState(0x1, j);
6936 jif = jiffies + (hertz / 10); 6892 msleep(100);
6937 while (time_before(jiffies, jif)) {
6938 set_current_state(TASK_INTERRUPTIBLE);
6939 schedule_timeout(1);
6940 }
6941 LED_SetState(0x2, j); 6893 LED_SetState(0x2, j);
6942 jif = jiffies + (hertz / 10); 6894 msleep(100);
6943 while (time_before(jiffies, jif)) {
6944 set_current_state(TASK_INTERRUPTIBLE);
6945 schedule_timeout(1);
6946 }
6947 LED_SetState(0x4, j); 6895 LED_SetState(0x4, j);
6948 jif = jiffies + (hertz / 10); 6896 msleep(100);
6949 while (time_before(jiffies, jif)) {
6950 set_current_state(TASK_INTERRUPTIBLE);
6951 schedule_timeout(1);
6952 }
6953 LED_SetState(0x8, j); 6897 LED_SetState(0x8, j);
6954 jif = jiffies + (hertz / 10); 6898 msleep(100);
6955 while (time_before(jiffies, jif)) {
6956 set_current_state(TASK_INTERRUPTIBLE);
6957 schedule_timeout(1);
6958 }
6959 LED_SetState(0x0, j); 6899 LED_SetState(0x0, j);
6960 daa_get_version(j); 6900 daa_get_version(j);
6961 if (ixjdebug & 0x0002) 6901 if (ixjdebug & 0x0002)
diff --git a/drivers/usb/host/hc_crisv10.c b/drivers/usb/host/hc_crisv10.c
index 81f8f6b7fd..a8267cf17d 100644
--- a/drivers/usb/host/hc_crisv10.c
+++ b/drivers/usb/host/hc_crisv10.c
@@ -178,8 +178,8 @@ static __u8 root_hub_hub_des[] =
178 0xff /* __u8 PortPwrCtrlMask; *** 7 ports max *** */ 178 0xff /* __u8 PortPwrCtrlMask; *** 7 ports max *** */
179}; 179};
180 180
181static struct timer_list bulk_start_timer = TIMER_INITIALIZER(NULL, 0, 0); 181static DEFINE_TIMER(bulk_start_timer, NULL, 0, 0);
182static struct timer_list bulk_eot_timer = TIMER_INITIALIZER(NULL, 0, 0); 182static DEFINE_TIMER(bulk_eot_timer, NULL, 0, 0);
183 183
184/* We want the start timer to expire before the eot timer, because the former might start 184/* We want the start timer to expire before the eot timer, because the former might start
185 traffic, thus making it unnecessary for the latter to time out. */ 185 traffic, thus making it unnecessary for the latter to time out. */
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 1ab95d24c5..e108e0a36b 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -2,7 +2,8 @@
2 * USB HID support for Linux 2 * USB HID support for Linux
3 * 3 *
4 * Copyright (c) 1999 Andreas Gal 4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2001 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
6 */ 7 */
7 8
8/* 9/*
@@ -38,7 +39,7 @@
38 * Version Information 39 * Version Information
39 */ 40 */
40 41
41#define DRIVER_VERSION "v2.01" 42#define DRIVER_VERSION "v2.6"
42#define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik" 43#define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik"
43#define DRIVER_DESC "USB HID core driver" 44#define DRIVER_DESC "USB HID core driver"
44#define DRIVER_LICENSE "GPL" 45#define DRIVER_LICENSE "GPL"
@@ -1058,8 +1059,8 @@ static int hid_submit_ctrl(struct hid_device *hid)
1058 if (maxpacket > 0) { 1059 if (maxpacket > 0) {
1059 padlen = (len + maxpacket - 1) / maxpacket; 1060 padlen = (len + maxpacket - 1) / maxpacket;
1060 padlen *= maxpacket; 1061 padlen *= maxpacket;
1061 if (padlen > HID_BUFFER_SIZE) 1062 if (padlen > hid->bufsize)
1062 padlen = HID_BUFFER_SIZE; 1063 padlen = hid->bufsize;
1063 } else 1064 } else
1064 padlen = 0; 1065 padlen = 0;
1065 hid->urbctrl->transfer_buffer_length = padlen; 1066 hid->urbctrl->transfer_buffer_length = padlen;
@@ -1096,6 +1097,7 @@ static void hid_irq_out(struct urb *urb, struct pt_regs *regs)
1096 1097
1097 switch (urb->status) { 1098 switch (urb->status) {
1098 case 0: /* success */ 1099 case 0: /* success */
1100 break;
1099 case -ESHUTDOWN: /* unplug */ 1101 case -ESHUTDOWN: /* unplug */
1100 case -EILSEQ: /* unplug timeout on uhci */ 1102 case -EILSEQ: /* unplug timeout on uhci */
1101 unplug = 1; 1103 unplug = 1;
@@ -1143,6 +1145,7 @@ static void hid_ctrl(struct urb *urb, struct pt_regs *regs)
1143 case 0: /* success */ 1145 case 0: /* success */
1144 if (hid->ctrl[hid->ctrltail].dir == USB_DIR_IN) 1146 if (hid->ctrl[hid->ctrltail].dir == USB_DIR_IN)
1145 hid_input_report(hid->ctrl[hid->ctrltail].report->type, urb, 0, regs); 1147 hid_input_report(hid->ctrl[hid->ctrltail].report->type, urb, 0, regs);
1148 break;
1146 case -ESHUTDOWN: /* unplug */ 1149 case -ESHUTDOWN: /* unplug */
1147 case -EILSEQ: /* unplug timectrl on uhci */ 1150 case -EILSEQ: /* unplug timectrl on uhci */
1148 unplug = 1; 1151 unplug = 1;
@@ -1284,13 +1287,8 @@ void hid_init_reports(struct hid_device *hid)
1284 struct hid_report *report; 1287 struct hid_report *report;
1285 int err, ret; 1288 int err, ret;
1286 1289
1287 list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list) { 1290 list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list)
1288 int size = ((report->size - 1) >> 3) + 1 + hid->report_enum[HID_INPUT_REPORT].numbered;
1289 if (size > HID_BUFFER_SIZE) size = HID_BUFFER_SIZE;
1290 if (size > hid->urbin->transfer_buffer_length)
1291 hid->urbin->transfer_buffer_length = size;
1292 hid_submit_report(hid, report, USB_DIR_IN); 1291 hid_submit_report(hid, report, USB_DIR_IN);
1293 }
1294 1292
1295 list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list) 1293 list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list)
1296 hid_submit_report(hid, report, USB_DIR_IN); 1294 hid_submit_report(hid, report, USB_DIR_IN);
@@ -1372,12 +1370,14 @@ void hid_init_reports(struct hid_device *hid)
1372#define USB_VENDOR_ID_A4TECH 0x09da 1370#define USB_VENDOR_ID_A4TECH 0x09da
1373#define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006 1371#define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006
1374 1372
1375#define USB_VENDOR_ID_AASHIMA 0x06D6 1373#define USB_VENDOR_ID_AASHIMA 0x06d6
1376#define USB_DEVICE_ID_AASHIMA_GAMEPAD 0x0025 1374#define USB_DEVICE_ID_AASHIMA_GAMEPAD 0x0025
1375#define USB_DEVICE_ID_AASHIMA_PREDATOR 0x0026
1377 1376
1378#define USB_VENDOR_ID_CYPRESS 0x04b4 1377#define USB_VENDOR_ID_CYPRESS 0x04b4
1379#define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001 1378#define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001
1380#define USB_DEVICE_ID_CYPRESS_HIDCOM 0x5500 1379#define USB_DEVICE_ID_CYPRESS_HIDCOM 0x5500
1380#define USB_DEVICE_ID_CYPRESS_ULTRAMOUSE 0x7417
1381 1381
1382#define USB_VENDOR_ID_BERKSHIRE 0x0c98 1382#define USB_VENDOR_ID_BERKSHIRE 0x0c98
1383#define USB_DEVICE_ID_BERKSHIRE_PCWD 0x1140 1383#define USB_DEVICE_ID_BERKSHIRE_PCWD 0x1140
@@ -1432,7 +1432,7 @@ void hid_init_reports(struct hid_device *hid)
1432#define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004 1432#define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004
1433 1433
1434#define USB_VENDOR_ID_LD 0x0f11 1434#define USB_VENDOR_ID_LD 0x0f11
1435#define USB_DEVICE_ID_CASSY 0x1000 1435#define USB_DEVICE_ID_CASSY 0x1000
1436#define USB_DEVICE_ID_POCKETCASSY 0x1010 1436#define USB_DEVICE_ID_POCKETCASSY 0x1010
1437#define USB_DEVICE_ID_MOBILECASSY 0x1020 1437#define USB_DEVICE_ID_MOBILECASSY 0x1020
1438#define USB_DEVICE_ID_JWM 0x1080 1438#define USB_DEVICE_ID_JWM 0x1080
@@ -1445,7 +1445,8 @@ void hid_init_reports(struct hid_device *hid)
1445#define USB_DEVICE_ID_POWERCONTROL 0x2030 1445#define USB_DEVICE_ID_POWERCONTROL 0x2030
1446 1446
1447#define USB_VENDOR_ID_APPLE 0x05ac 1447#define USB_VENDOR_ID_APPLE 0x05ac
1448#define USB_DEVICE_ID_APPLE_BLUETOOTH 0x1000 1448#define USB_DEVICE_ID_APPLE_POWERMOUSE 0x0304
1449#define USB_DEVICE_ID_APPLE_BLUETOOTH 0x1000
1449 1450
1450/* 1451/*
1451 * Alphabetically sorted blacklist by quirk type. 1452 * Alphabetically sorted blacklist by quirk type.
@@ -1471,6 +1472,7 @@ static struct hid_blacklist {
1471 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW48, HID_QUIRK_IGNORE }, 1472 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW48, HID_QUIRK_IGNORE },
1472 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW28, HID_QUIRK_IGNORE }, 1473 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW28, HID_QUIRK_IGNORE },
1473 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM, HID_QUIRK_IGNORE }, 1474 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM, HID_QUIRK_IGNORE },
1475 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE, HID_QUIRK_IGNORE },
1474 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE, HID_QUIRK_IGNORE }, 1476 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE, HID_QUIRK_IGNORE },
1475 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20, HID_QUIRK_IGNORE }, 1477 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20, HID_QUIRK_IGNORE },
1476 { USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5, HID_QUIRK_IGNORE }, 1478 { USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5, HID_QUIRK_IGNORE },
@@ -1551,10 +1553,12 @@ static struct hid_blacklist {
1551 { USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_USBHUB_KB, HID_QUIRK_NOGET}, 1553 { USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_USBHUB_KB, HID_QUIRK_NOGET},
1552 { USB_VENDOR_ID_TANGTOP, USB_DEVICE_ID_TANGTOP_USBPS2, HID_QUIRK_NOGET }, 1554 { USB_VENDOR_ID_TANGTOP, USB_DEVICE_ID_TANGTOP_USBPS2, HID_QUIRK_NOGET },
1553 1555
1556 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_POWERMOUSE, HID_QUIRK_2WHEEL_POWERMOUSE },
1554 { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 }, 1557 { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 },
1555 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE, HID_QUIRK_2WHEEL_MOUSE_HACK_5 }, 1558 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE, HID_QUIRK_2WHEEL_MOUSE_HACK_5 },
1556 1559
1557 { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_GAMEPAD, HID_QUIRK_BADPAD }, 1560 { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_GAMEPAD, HID_QUIRK_BADPAD },
1561 { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_PREDATOR, HID_QUIRK_BADPAD },
1558 { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD }, 1562 { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD },
1559 { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD }, 1563 { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD },
1560 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, 1564 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
@@ -1567,15 +1571,32 @@ static struct hid_blacklist {
1567 { 0, 0 } 1571 { 0, 0 }
1568}; 1572};
1569 1573
1574/*
1575 * Traverse the supplied list of reports and find the longest
1576 */
1577static void hid_find_max_report(struct hid_device *hid, unsigned int type, int *max)
1578{
1579 struct hid_report *report;
1580 int size;
1581
1582 list_for_each_entry(report, &hid->report_enum[type].report_list, list) {
1583 size = ((report->size - 1) >> 3) + 1;
1584 if (type == HID_INPUT_REPORT && hid->report_enum[type].numbered)
1585 size++;
1586 if (*max < size)
1587 *max = size;
1588 }
1589}
1590
1570static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid) 1591static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid)
1571{ 1592{
1572 if (!(hid->inbuf = usb_buffer_alloc(dev, HID_BUFFER_SIZE, SLAB_ATOMIC, &hid->inbuf_dma))) 1593 if (!(hid->inbuf = usb_buffer_alloc(dev, hid->bufsize, SLAB_ATOMIC, &hid->inbuf_dma)))
1573 return -1; 1594 return -1;
1574 if (!(hid->outbuf = usb_buffer_alloc(dev, HID_BUFFER_SIZE, SLAB_ATOMIC, &hid->outbuf_dma))) 1595 if (!(hid->outbuf = usb_buffer_alloc(dev, hid->bufsize, SLAB_ATOMIC, &hid->outbuf_dma)))
1575 return -1; 1596 return -1;
1576 if (!(hid->cr = usb_buffer_alloc(dev, sizeof(*(hid->cr)), SLAB_ATOMIC, &hid->cr_dma))) 1597 if (!(hid->cr = usb_buffer_alloc(dev, sizeof(*(hid->cr)), SLAB_ATOMIC, &hid->cr_dma)))
1577 return -1; 1598 return -1;
1578 if (!(hid->ctrlbuf = usb_buffer_alloc(dev, HID_BUFFER_SIZE, SLAB_ATOMIC, &hid->ctrlbuf_dma))) 1599 if (!(hid->ctrlbuf = usb_buffer_alloc(dev, hid->bufsize, SLAB_ATOMIC, &hid->ctrlbuf_dma)))
1579 return -1; 1600 return -1;
1580 1601
1581 return 0; 1602 return 0;
@@ -1584,13 +1605,13 @@ static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid)
1584static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid) 1605static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid)
1585{ 1606{
1586 if (hid->inbuf) 1607 if (hid->inbuf)
1587 usb_buffer_free(dev, HID_BUFFER_SIZE, hid->inbuf, hid->inbuf_dma); 1608 usb_buffer_free(dev, hid->bufsize, hid->inbuf, hid->inbuf_dma);
1588 if (hid->outbuf) 1609 if (hid->outbuf)
1589 usb_buffer_free(dev, HID_BUFFER_SIZE, hid->outbuf, hid->outbuf_dma); 1610 usb_buffer_free(dev, hid->bufsize, hid->outbuf, hid->outbuf_dma);
1590 if (hid->cr) 1611 if (hid->cr)
1591 usb_buffer_free(dev, sizeof(*(hid->cr)), hid->cr, hid->cr_dma); 1612 usb_buffer_free(dev, sizeof(*(hid->cr)), hid->cr, hid->cr_dma);
1592 if (hid->ctrlbuf) 1613 if (hid->ctrlbuf)
1593 usb_buffer_free(dev, HID_BUFFER_SIZE, hid->ctrlbuf, hid->ctrlbuf_dma); 1614 usb_buffer_free(dev, hid->bufsize, hid->ctrlbuf, hid->ctrlbuf_dma);
1594} 1615}
1595 1616
1596static struct hid_device *usb_hid_configure(struct usb_interface *intf) 1617static struct hid_device *usb_hid_configure(struct usb_interface *intf)
@@ -1601,7 +1622,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1601 struct hid_device *hid; 1622 struct hid_device *hid;
1602 unsigned quirks = 0, rsize = 0; 1623 unsigned quirks = 0, rsize = 0;
1603 char *buf, *rdesc; 1624 char *buf, *rdesc;
1604 int n; 1625 int n, insize = 0;
1605 1626
1606 for (n = 0; hid_blacklist[n].idVendor; n++) 1627 for (n = 0; hid_blacklist[n].idVendor; n++)
1607 if ((hid_blacklist[n].idVendor == le16_to_cpu(dev->descriptor.idVendor)) && 1628 if ((hid_blacklist[n].idVendor == le16_to_cpu(dev->descriptor.idVendor)) &&
@@ -1655,6 +1676,19 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1655 kfree(rdesc); 1676 kfree(rdesc);
1656 hid->quirks = quirks; 1677 hid->quirks = quirks;
1657 1678
1679 hid->bufsize = HID_MIN_BUFFER_SIZE;
1680 hid_find_max_report(hid, HID_INPUT_REPORT, &hid->bufsize);
1681 hid_find_max_report(hid, HID_OUTPUT_REPORT, &hid->bufsize);
1682 hid_find_max_report(hid, HID_FEATURE_REPORT, &hid->bufsize);
1683
1684 if (hid->bufsize > HID_MAX_BUFFER_SIZE)
1685 hid->bufsize = HID_MAX_BUFFER_SIZE;
1686
1687 hid_find_max_report(hid, HID_INPUT_REPORT, &insize);
1688
1689 if (insize > HID_MAX_BUFFER_SIZE)
1690 insize = HID_MAX_BUFFER_SIZE;
1691
1658 if (hid_alloc_buffers(dev, hid)) { 1692 if (hid_alloc_buffers(dev, hid)) {
1659 hid_free_buffers(dev, hid); 1693 hid_free_buffers(dev, hid);
1660 goto fail; 1694 goto fail;
@@ -1685,7 +1719,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1685 if (!(hid->urbin = usb_alloc_urb(0, GFP_KERNEL))) 1719 if (!(hid->urbin = usb_alloc_urb(0, GFP_KERNEL)))
1686 goto fail; 1720 goto fail;
1687 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); 1721 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
1688 usb_fill_int_urb(hid->urbin, dev, pipe, hid->inbuf, 0, 1722 usb_fill_int_urb(hid->urbin, dev, pipe, hid->inbuf, insize,
1689 hid_irq_in, hid, interval); 1723 hid_irq_in, hid, interval);
1690 hid->urbin->transfer_dma = hid->inbuf_dma; 1724 hid->urbin->transfer_dma = hid->inbuf_dma;
1691 hid->urbin->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 1725 hid->urbin->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
diff --git a/drivers/usb/input/hid-debug.h b/drivers/usb/input/hid-debug.h
index 52437e5e2e..ceebab99ef 100644
--- a/drivers/usb/input/hid-debug.h
+++ b/drivers/usb/input/hid-debug.h
@@ -85,6 +85,23 @@ static const struct hid_usage_entry hid_usage_table[] = {
85 {0, 0x91, "D-PadDown"}, 85 {0, 0x91, "D-PadDown"},
86 {0, 0x92, "D-PadRight"}, 86 {0, 0x92, "D-PadRight"},
87 {0, 0x93, "D-PadLeft"}, 87 {0, 0x93, "D-PadLeft"},
88 { 2, 0, "Simulation" },
89 {0, 0xb0, "Aileron"},
90 {0, 0xb1, "AileronTrim"},
91 {0, 0xb2, "Anti-Torque"},
92 {0, 0xb3, "Autopilot"},
93 {0, 0xb4, "Chaff"},
94 {0, 0xb5, "Collective"},
95 {0, 0xb6, "DiveBrake"},
96 {0, 0xb7, "ElectronicCountermeasures"},
97 {0, 0xb8, "Elevator"},
98 {0, 0xb9, "ElevatorTrim"},
99 {0, 0xba, "Rudder"},
100 {0, 0xbb, "Throttle"},
101 {0, 0xbc, "FlightCommunications"},
102 {0, 0xbd, "FlareRelease"},
103 {0, 0xbe, "LandingGear"},
104 {0, 0xbf, "ToeBrake"},
88 { 7, 0, "Keyboard" }, 105 { 7, 0, "Keyboard" },
89 { 8, 0, "LED" }, 106 { 8, 0, "LED" },
90 {0, 0x01, "NumLock"}, 107 {0, 0x01, "NumLock"},
@@ -92,6 +109,7 @@ static const struct hid_usage_entry hid_usage_table[] = {
92 {0, 0x03, "ScrollLock"}, 109 {0, 0x03, "ScrollLock"},
93 {0, 0x04, "Compose"}, 110 {0, 0x04, "Compose"},
94 {0, 0x05, "Kana"}, 111 {0, 0x05, "Kana"},
112 {0, 0x4b, "GenericIndicator"},
95 { 9, 0, "Button" }, 113 { 9, 0, "Button" },
96 { 10, 0, "Ordinal" }, 114 { 10, 0, "Ordinal" },
97 { 12, 0, "Consumer" }, 115 { 12, 0, "Consumer" },
@@ -574,7 +592,8 @@ static char *keys[KEY_MAX + 1] = {
574 [KEY_EXIT] = "Exit", [KEY_MOVE] = "Move", 592 [KEY_EXIT] = "Exit", [KEY_MOVE] = "Move",
575 [KEY_EDIT] = "Edit", [KEY_SCROLLUP] = "ScrollUp", 593 [KEY_EDIT] = "Edit", [KEY_SCROLLUP] = "ScrollUp",
576 [KEY_SCROLLDOWN] = "ScrollDown", [KEY_KPLEFTPAREN] = "KPLeftParenthesis", 594 [KEY_SCROLLDOWN] = "ScrollDown", [KEY_KPLEFTPAREN] = "KPLeftParenthesis",
577 [KEY_KPRIGHTPAREN] = "KPRightParenthesis", [KEY_F13] = "F13", 595 [KEY_KPRIGHTPAREN] = "KPRightParenthesis", [KEY_NEW] = "New",
596 [KEY_REDO] = "Redo", [KEY_F13] = "F13",
578 [KEY_F14] = "F14", [KEY_F15] = "F15", 597 [KEY_F14] = "F14", [KEY_F15] = "F15",
579 [KEY_F16] = "F16", [KEY_F17] = "F17", 598 [KEY_F16] = "F16", [KEY_F17] = "F17",
580 [KEY_F18] = "F18", [KEY_F19] = "F19", 599 [KEY_F18] = "F18", [KEY_F19] = "F19",
@@ -584,15 +603,15 @@ static char *keys[KEY_MAX + 1] = {
584 [KEY_PAUSECD] = "PauseCD", [KEY_PROG3] = "Prog3", 603 [KEY_PAUSECD] = "PauseCD", [KEY_PROG3] = "Prog3",
585 [KEY_PROG4] = "Prog4", [KEY_SUSPEND] = "Suspend", 604 [KEY_PROG4] = "Prog4", [KEY_SUSPEND] = "Suspend",
586 [KEY_CLOSE] = "Close", [KEY_PLAY] = "Play", 605 [KEY_CLOSE] = "Close", [KEY_PLAY] = "Play",
587 [KEY_FASTFORWARD] = "Fast Forward", [KEY_BASSBOOST] = "Bass Boost", 606 [KEY_FASTFORWARD] = "FastForward", [KEY_BASSBOOST] = "BassBoost",
588 [KEY_PRINT] = "Print", [KEY_HP] = "HP", 607 [KEY_PRINT] = "Print", [KEY_HP] = "HP",
589 [KEY_CAMERA] = "Camera", [KEY_SOUND] = "Sound", 608 [KEY_CAMERA] = "Camera", [KEY_SOUND] = "Sound",
590 [KEY_QUESTION] = "Question", [KEY_EMAIL] = "Email", 609 [KEY_QUESTION] = "Question", [KEY_EMAIL] = "Email",
591 [KEY_CHAT] = "Chat", [KEY_SEARCH] = "Search", 610 [KEY_CHAT] = "Chat", [KEY_SEARCH] = "Search",
592 [KEY_CONNECT] = "Connect", [KEY_FINANCE] = "Finance", 611 [KEY_CONNECT] = "Connect", [KEY_FINANCE] = "Finance",
593 [KEY_SPORT] = "Sport", [KEY_SHOP] = "Shop", 612 [KEY_SPORT] = "Sport", [KEY_SHOP] = "Shop",
594 [KEY_ALTERASE] = "Alternate Erase", [KEY_CANCEL] = "Cancel", 613 [KEY_ALTERASE] = "AlternateErase", [KEY_CANCEL] = "Cancel",
595 [KEY_BRIGHTNESSDOWN] = "Brightness down", [KEY_BRIGHTNESSUP] = "Brightness up", 614 [KEY_BRIGHTNESSDOWN] = "BrightnessDown", [KEY_BRIGHTNESSUP] = "BrightnessUp",
596 [KEY_MEDIA] = "Media", [KEY_UNKNOWN] = "Unknown", 615 [KEY_MEDIA] = "Media", [KEY_UNKNOWN] = "Unknown",
597 [BTN_0] = "Btn0", [BTN_1] = "Btn1", 616 [BTN_0] = "Btn0", [BTN_1] = "Btn1",
598 [BTN_2] = "Btn2", [BTN_3] = "Btn3", 617 [BTN_2] = "Btn2", [BTN_3] = "Btn3",
@@ -622,8 +641,8 @@ static char *keys[KEY_MAX + 1] = {
622 [BTN_TOOL_AIRBRUSH] = "ToolAirbrush", [BTN_TOOL_FINGER] = "ToolFinger", 641 [BTN_TOOL_AIRBRUSH] = "ToolAirbrush", [BTN_TOOL_FINGER] = "ToolFinger",
623 [BTN_TOOL_MOUSE] = "ToolMouse", [BTN_TOOL_LENS] = "ToolLens", 642 [BTN_TOOL_MOUSE] = "ToolMouse", [BTN_TOOL_LENS] = "ToolLens",
624 [BTN_TOUCH] = "Touch", [BTN_STYLUS] = "Stylus", 643 [BTN_TOUCH] = "Touch", [BTN_STYLUS] = "Stylus",
625 [BTN_STYLUS2] = "Stylus2", [BTN_TOOL_DOUBLETAP] = "Tool Doubletap", 644 [BTN_STYLUS2] = "Stylus2", [BTN_TOOL_DOUBLETAP] = "ToolDoubleTap",
626 [BTN_TOOL_TRIPLETAP] = "Tool Tripletap", [BTN_GEAR_DOWN] = "WheelBtn", 645 [BTN_TOOL_TRIPLETAP] = "ToolTripleTap", [BTN_GEAR_DOWN] = "WheelBtn",
627 [BTN_GEAR_UP] = "Gear up", [KEY_OK] = "Ok", 646 [BTN_GEAR_UP] = "Gear up", [KEY_OK] = "Ok",
628 [KEY_SELECT] = "Select", [KEY_GOTO] = "Goto", 647 [KEY_SELECT] = "Select", [KEY_GOTO] = "Goto",
629 [KEY_CLEAR] = "Clear", [KEY_POWER2] = "Power2", 648 [KEY_CLEAR] = "Clear", [KEY_POWER2] = "Power2",
@@ -659,6 +678,9 @@ static char *keys[KEY_MAX + 1] = {
659 [KEY_TWEN] = "TWEN", [KEY_DEL_EOL] = "DeleteEOL", 678 [KEY_TWEN] = "TWEN", [KEY_DEL_EOL] = "DeleteEOL",
660 [KEY_DEL_EOS] = "DeleteEOS", [KEY_INS_LINE] = "InsertLine", 679 [KEY_DEL_EOS] = "DeleteEOS", [KEY_INS_LINE] = "InsertLine",
661 [KEY_DEL_LINE] = "DeleteLine", 680 [KEY_DEL_LINE] = "DeleteLine",
681 [KEY_SEND] = "Send", [KEY_REPLY] = "Reply",
682 [KEY_FORWARDMAIL] = "ForwardMail", [KEY_SAVE] = "Save",
683 [KEY_DOCUMENTS] = "Documents",
662}; 684};
663 685
664static char *relatives[REL_MAX + 1] = { 686static char *relatives[REL_MAX + 1] = {
diff --git a/drivers/usb/input/hid-input.c b/drivers/usb/input/hid-input.c
index 63a4db721f..0b6452248a 100644
--- a/drivers/usb/input/hid-input.c
+++ b/drivers/usb/input/hid-input.c
@@ -78,8 +78,8 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
78{ 78{
79 struct input_dev *input = &hidinput->input; 79 struct input_dev *input = &hidinput->input;
80 struct hid_device *device = hidinput->input.private; 80 struct hid_device *device = hidinput->input.private;
81 int max, code; 81 int max = 0, code;
82 unsigned long *bit; 82 unsigned long *bit = NULL;
83 83
84 field->hidinput = hidinput; 84 field->hidinput = hidinput;
85 85
@@ -131,6 +131,15 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
131 map_key(code); 131 map_key(code);
132 break; 132 break;
133 133
134
135 case HID_UP_SIMULATION:
136
137 switch (usage->hid & 0xffff) {
138 case 0xba: map_abs(ABS_RUDDER); break;
139 case 0xbb: map_abs(ABS_THROTTLE); break;
140 }
141 break;
142
134 case HID_UP_GENDESK: 143 case HID_UP_GENDESK:
135 144
136 if ((usage->hid & 0xf0) == 0x80) { /* SystemControl */ 145 if ((usage->hid & 0xf0) == 0x80) { /* SystemControl */
@@ -238,8 +247,12 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
238 case 0x000: goto ignore; 247 case 0x000: goto ignore;
239 case 0x034: map_key_clear(KEY_SLEEP); break; 248 case 0x034: map_key_clear(KEY_SLEEP); break;
240 case 0x036: map_key_clear(BTN_MISC); break; 249 case 0x036: map_key_clear(BTN_MISC); break;
250 case 0x045: map_key_clear(KEY_RADIO); break;
241 case 0x08a: map_key_clear(KEY_WWW); break; 251 case 0x08a: map_key_clear(KEY_WWW); break;
252 case 0x08d: map_key_clear(KEY_PROGRAM); break;
242 case 0x095: map_key_clear(KEY_HELP); break; 253 case 0x095: map_key_clear(KEY_HELP); break;
254 case 0x09c: map_key_clear(KEY_CHANNELUP); break;
255 case 0x09d: map_key_clear(KEY_CHANNELDOWN); break;
243 case 0x0b0: map_key_clear(KEY_PLAY); break; 256 case 0x0b0: map_key_clear(KEY_PLAY); break;
244 case 0x0b1: map_key_clear(KEY_PAUSE); break; 257 case 0x0b1: map_key_clear(KEY_PAUSE); break;
245 case 0x0b2: map_key_clear(KEY_RECORD); break; 258 case 0x0b2: map_key_clear(KEY_RECORD); break;
@@ -259,6 +272,11 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
259 case 0x18a: map_key_clear(KEY_MAIL); break; 272 case 0x18a: map_key_clear(KEY_MAIL); break;
260 case 0x192: map_key_clear(KEY_CALC); break; 273 case 0x192: map_key_clear(KEY_CALC); break;
261 case 0x194: map_key_clear(KEY_FILE); break; 274 case 0x194: map_key_clear(KEY_FILE); break;
275 case 0x1a7: map_key_clear(KEY_DOCUMENTS); break;
276 case 0x201: map_key_clear(KEY_NEW); break;
277 case 0x207: map_key_clear(KEY_SAVE); break;
278 case 0x208: map_key_clear(KEY_PRINT); break;
279 case 0x209: map_key_clear(KEY_PROPS); break;
262 case 0x21a: map_key_clear(KEY_UNDO); break; 280 case 0x21a: map_key_clear(KEY_UNDO); break;
263 case 0x21b: map_key_clear(KEY_COPY); break; 281 case 0x21b: map_key_clear(KEY_COPY); break;
264 case 0x21c: map_key_clear(KEY_CUT); break; 282 case 0x21c: map_key_clear(KEY_CUT); break;
@@ -271,7 +289,11 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
271 case 0x227: map_key_clear(KEY_REFRESH); break; 289 case 0x227: map_key_clear(KEY_REFRESH); break;
272 case 0x22a: map_key_clear(KEY_BOOKMARKS); break; 290 case 0x22a: map_key_clear(KEY_BOOKMARKS); break;
273 case 0x238: map_rel(REL_HWHEEL); break; 291 case 0x238: map_rel(REL_HWHEEL); break;
274 default: goto unknown; 292 case 0x279: map_key_clear(KEY_REDO); break;
293 case 0x289: map_key_clear(KEY_REPLY); break;
294 case 0x28b: map_key_clear(KEY_FORWARDMAIL); break;
295 case 0x28c: map_key_clear(KEY_SEND); break;
296 default: goto ignore;
275 } 297 }
276 break; 298 break;
277 299
@@ -296,9 +318,42 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
296 break; 318 break;
297 319
298 case HID_UP_MSVENDOR: 320 case HID_UP_MSVENDOR:
299
300 goto ignore; 321 goto ignore;
301 322
323 case HID_UP_CUSTOM: /* Reported on Logitech and Powerbook USB keyboards */
324
325 set_bit(EV_REP, input->evbit);
326 switch(usage->hid & HID_USAGE) {
327 case 0x003: map_key_clear(KEY_FN); break;
328 default: goto ignore;
329 }
330 break;
331
332 case HID_UP_LOGIVENDOR: /* Reported on Logitech Ultra X Media Remote */
333
334 set_bit(EV_REP, input->evbit);
335 switch(usage->hid & HID_USAGE) {
336 case 0x004: map_key_clear(KEY_AGAIN); break;
337 case 0x00d: map_key_clear(KEY_HOME); break;
338 case 0x024: map_key_clear(KEY_SHUFFLE); break;
339 case 0x025: map_key_clear(KEY_TV); break;
340 case 0x026: map_key_clear(KEY_MENU); break;
341 case 0x031: map_key_clear(KEY_AUDIO); break;
342 case 0x032: map_key_clear(KEY_SUBTITLE); break;
343 case 0x033: map_key_clear(KEY_LAST); break;
344 case 0x047: map_key_clear(KEY_MP3); break;
345 case 0x048: map_key_clear(KEY_DVD); break;
346 case 0x049: map_key_clear(KEY_MEDIA); break;
347 case 0x04a: map_key_clear(KEY_VIDEO); break;
348 case 0x04b: map_key_clear(KEY_ANGLE); break;
349 case 0x04c: map_key_clear(KEY_LANGUAGE); break;
350 case 0x04d: map_key_clear(KEY_SUBTITLE); break;
351 case 0x051: map_key_clear(KEY_RED); break;
352 case 0x052: map_key_clear(KEY_CLOSE); break;
353 default: goto ignore;
354 }
355 break;
356
302 case HID_UP_PID: 357 case HID_UP_PID:
303 358
304 set_bit(EV_FF, input->evbit); 359 set_bit(EV_FF, input->evbit);
@@ -349,6 +404,9 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
349 if (usage->code > max) 404 if (usage->code > max)
350 goto ignore; 405 goto ignore;
351 406
407 if (((device->quirks & (HID_QUIRK_2WHEEL_POWERMOUSE)) && (usage->hid == 0x00010032)))
408 map_rel(REL_HWHEEL);
409
352 if ((device->quirks & (HID_QUIRK_2WHEEL_MOUSE_HACK_7 | HID_QUIRK_2WHEEL_MOUSE_HACK_5)) && 410 if ((device->quirks & (HID_QUIRK_2WHEEL_MOUSE_HACK_7 | HID_QUIRK_2WHEEL_MOUSE_HACK_5)) &&
353 (usage->type == EV_REL) && (usage->code == REL_WHEEL)) 411 (usage->type == EV_REL) && (usage->code == REL_WHEEL))
354 set_bit(REL_HWHEEL, bit); 412 set_bit(REL_HWHEEL, bit);
diff --git a/drivers/usb/input/hid.h b/drivers/usb/input/hid.h
index c1b6b69bc4..ec2412c42f 100644
--- a/drivers/usb/input/hid.h
+++ b/drivers/usb/input/hid.h
@@ -173,6 +173,7 @@ struct hid_item {
173 173
174#define HID_UP_UNDEFINED 0x00000000 174#define HID_UP_UNDEFINED 0x00000000
175#define HID_UP_GENDESK 0x00010000 175#define HID_UP_GENDESK 0x00010000
176#define HID_UP_SIMULATION 0x00020000
176#define HID_UP_KEYBOARD 0x00070000 177#define HID_UP_KEYBOARD 0x00070000
177#define HID_UP_LED 0x00080000 178#define HID_UP_LED 0x00080000
178#define HID_UP_BUTTON 0x00090000 179#define HID_UP_BUTTON 0x00090000
@@ -182,6 +183,8 @@ struct hid_item {
182#define HID_UP_PID 0x000f0000 183#define HID_UP_PID 0x000f0000
183#define HID_UP_HPVENDOR 0xff7f0000 184#define HID_UP_HPVENDOR 0xff7f0000
184#define HID_UP_MSVENDOR 0xff000000 185#define HID_UP_MSVENDOR 0xff000000
186#define HID_UP_CUSTOM 0x00ff0000
187#define HID_UP_LOGIVENDOR 0xffbc0000
185 188
186#define HID_USAGE 0x0000ffff 189#define HID_USAGE 0x0000ffff
187 190
@@ -242,6 +245,7 @@ struct hid_item {
242#define HID_QUIRK_2WHEEL_MOUSE_HACK_7 0x080 245#define HID_QUIRK_2WHEEL_MOUSE_HACK_7 0x080
243#define HID_QUIRK_2WHEEL_MOUSE_HACK_5 0x100 246#define HID_QUIRK_2WHEEL_MOUSE_HACK_5 0x100
244#define HID_QUIRK_2WHEEL_MOUSE_HACK_ON 0x200 247#define HID_QUIRK_2WHEEL_MOUSE_HACK_ON 0x200
248#define HID_QUIRK_2WHEEL_POWERMOUSE 0x400
245 249
246/* 250/*
247 * This is the global environment of the parser. This information is 251 * This is the global environment of the parser. This information is
@@ -348,7 +352,8 @@ struct hid_report_enum {
348 352
349#define HID_REPORT_TYPES 3 353#define HID_REPORT_TYPES 3
350 354
351#define HID_BUFFER_SIZE 64 /* use 64 for compatibility with all possible packetlen */ 355#define HID_MIN_BUFFER_SIZE 64 /* make sure there is at least a packet size of space */
356#define HID_MAX_BUFFER_SIZE 4096 /* 4kb */
352#define HID_CONTROL_FIFO_SIZE 256 /* to init devices with >100 reports */ 357#define HID_CONTROL_FIFO_SIZE 256 /* to init devices with >100 reports */
353#define HID_OUTPUT_FIFO_SIZE 64 358#define HID_OUTPUT_FIFO_SIZE 64
354 359
@@ -386,6 +391,8 @@ struct hid_device { /* device report descriptor */
386 391
387 unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */ 392 unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
388 393
394 unsigned int bufsize; /* URB buffer size */
395
389 struct urb *urbin; /* Input URB */ 396 struct urb *urbin; /* Input URB */
390 char *inbuf; /* Input buffer */ 397 char *inbuf; /* Input buffer */
391 dma_addr_t inbuf_dma; /* Input buffer dma */ 398 dma_addr_t inbuf_dma; /* Input buffer dma */
diff --git a/drivers/usb/input/hiddev.c b/drivers/usb/input/hiddev.c
index 4c13331b5f..d32427818a 100644
--- a/drivers/usb/input/hiddev.c
+++ b/drivers/usb/input/hiddev.c
@@ -507,6 +507,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
507 return -EINVAL; 507 return -EINVAL;
508 508
509 hid_submit_report(hid, report, USB_DIR_OUT); 509 hid_submit_report(hid, report, USB_DIR_OUT);
510 hid_wait_io(hid);
510 511
511 return 0; 512 return 0;
512 513
diff --git a/drivers/usb/media/stv680.c b/drivers/usb/media/stv680.c
index 7398a7f19c..0fd0fa9fec 100644
--- a/drivers/usb/media/stv680.c
+++ b/drivers/usb/media/stv680.c
@@ -260,7 +260,7 @@ static int stv_stop_video (struct usb_stv *dev)
260 PDEBUG (0, "STV(i): Camera set to original resolution"); 260 PDEBUG (0, "STV(i): Camera set to original resolution");
261 } 261 }
262 /* origMode */ 262 /* origMode */
263 kfree (buf); 263 kfree(buf);
264 return i; 264 return i;
265} 265}
266 266
@@ -276,7 +276,7 @@ static int stv_set_video_mode (struct usb_stv *dev)
276 } 276 }
277 277
278 if ((i = stv_set_config (dev, 1, 0, 0)) < 0) { 278 if ((i = stv_set_config (dev, 1, 0, 0)) < 0) {
279 kfree (buf); 279 kfree(buf);
280 return i; 280 return i;
281 } 281 }
282 282
@@ -301,13 +301,13 @@ static int stv_set_video_mode (struct usb_stv *dev)
301 goto exit; 301 goto exit;
302 302
303error: 303error:
304 kfree (buf); 304 kfree(buf);
305 if (stop_video == 1) 305 if (stop_video == 1)
306 stv_stop_video (dev); 306 stv_stop_video (dev);
307 return -1; 307 return -1;
308 308
309exit: 309exit:
310 kfree (buf); 310 kfree(buf);
311 return 0; 311 return 0;
312} 312}
313 313
@@ -327,7 +327,7 @@ static int stv_init (struct usb_stv *stv680)
327 327
328 /* set config 1, interface 0, alternate 0 */ 328 /* set config 1, interface 0, alternate 0 */
329 if ((i = stv_set_config (stv680, 1, 0, 0)) < 0) { 329 if ((i = stv_set_config (stv680, 1, 0, 0)) < 0) {
330 kfree (buffer); 330 kfree(buffer);
331 PDEBUG (0, "STV(e): set config 1,0,0 failed"); 331 PDEBUG (0, "STV(e): set config 1,0,0 failed");
332 return -1; 332 return -1;
333 } 333 }
@@ -435,11 +435,11 @@ static int stv_init (struct usb_stv *stv680)
435error: 435error:
436 i = stv_sndctrl (0, stv680, 0x80, 0, buffer, 0x02); /* Get Last Error */ 436 i = stv_sndctrl (0, stv680, 0x80, 0, buffer, 0x02); /* Get Last Error */
437 PDEBUG (1, "STV(i): last error: %i, command = 0x%x", buffer[0], buffer[1]); 437 PDEBUG (1, "STV(i): last error: %i, command = 0x%x", buffer[0], buffer[1]);
438 kfree (buffer); 438 kfree(buffer);
439 return -1; 439 return -1;
440 440
441exit: 441exit:
442 kfree (buffer); 442 kfree(buffer);
443 443
444 /* video = 320x240, 352x288 */ 444 /* video = 320x240, 352x288 */
445 if (stv680->CIF == 1) { 445 if (stv680->CIF == 1) {
@@ -708,10 +708,10 @@ static int stv680_stop_stream (struct usb_stv *stv680)
708 usb_kill_urb (stv680->urb[i]); 708 usb_kill_urb (stv680->urb[i]);
709 usb_free_urb (stv680->urb[i]); 709 usb_free_urb (stv680->urb[i]);
710 stv680->urb[i] = NULL; 710 stv680->urb[i] = NULL;
711 kfree (stv680->sbuf[i].data); 711 kfree(stv680->sbuf[i].data);
712 } 712 }
713 for (i = 0; i < STV680_NUMSCRATCH; i++) { 713 for (i = 0; i < STV680_NUMSCRATCH; i++) {
714 kfree (stv680->scratch[i].data); 714 kfree(stv680->scratch[i].data);
715 stv680->scratch[i].data = NULL; 715 stv680->scratch[i].data = NULL;
716 } 716 }
717 717
@@ -1068,7 +1068,7 @@ static int stv_close (struct inode *inode, struct file *file)
1068 stv680->user = 0; 1068 stv680->user = 0;
1069 1069
1070 if (stv680->removed) { 1070 if (stv680->removed) {
1071 kfree (stv680); 1071 kfree(stv680);
1072 stv680 = NULL; 1072 stv680 = NULL;
1073 PDEBUG (0, "STV(i): device unregistered"); 1073 PDEBUG (0, "STV(i): device unregistered");
1074 } 1074 }
@@ -1445,14 +1445,14 @@ static inline void usb_stv680_remove_disconnected (struct usb_stv *stv680)
1445 usb_kill_urb (stv680->urb[i]); 1445 usb_kill_urb (stv680->urb[i]);
1446 usb_free_urb (stv680->urb[i]); 1446 usb_free_urb (stv680->urb[i]);
1447 stv680->urb[i] = NULL; 1447 stv680->urb[i] = NULL;
1448 kfree (stv680->sbuf[i].data); 1448 kfree(stv680->sbuf[i].data);
1449 } 1449 }
1450 for (i = 0; i < STV680_NUMSCRATCH; i++) 1450 for (i = 0; i < STV680_NUMSCRATCH; i++)
1451 kfree (stv680->scratch[i].data); 1451 kfree(stv680->scratch[i].data);
1452 PDEBUG (0, "STV(i): %s disconnected", stv680->camera_name); 1452 PDEBUG (0, "STV(i): %s disconnected", stv680->camera_name);
1453 1453
1454 /* Free the memory */ 1454 /* Free the memory */
1455 kfree (stv680); 1455 kfree(stv680);
1456} 1456}
1457 1457
1458static void stv680_disconnect (struct usb_interface *intf) 1458static void stv680_disconnect (struct usb_interface *intf)
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index cde0ed097a..615874e03c 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -650,7 +650,6 @@ config FB_NVIDIA
650 select FB_CFB_FILLRECT 650 select FB_CFB_FILLRECT
651 select FB_CFB_COPYAREA 651 select FB_CFB_COPYAREA
652 select FB_CFB_IMAGEBLIT 652 select FB_CFB_IMAGEBLIT
653 select FB_SOFT_CURSOR
654 help 653 help
655 This driver supports graphics boards with the nVidia chips, TNT 654 This driver supports graphics boards with the nVidia chips, TNT
656 and newer. For very old chipsets, such as the RIVA128, then use 655 and newer. For very old chipsets, such as the RIVA128, then use
@@ -681,7 +680,6 @@ config FB_RIVA
681 select FB_CFB_FILLRECT 680 select FB_CFB_FILLRECT
682 select FB_CFB_COPYAREA 681 select FB_CFB_COPYAREA
683 select FB_CFB_IMAGEBLIT 682 select FB_CFB_IMAGEBLIT
684 select FB_SOFT_CURSOR
685 help 683 help
686 This driver supports graphics boards with the nVidia Riva/Geforce 684 This driver supports graphics boards with the nVidia Riva/Geforce
687 chips. 685 chips.
@@ -720,7 +718,6 @@ config FB_I810
720 select FB_CFB_FILLRECT 718 select FB_CFB_FILLRECT
721 select FB_CFB_COPYAREA 719 select FB_CFB_COPYAREA
722 select FB_CFB_IMAGEBLIT 720 select FB_CFB_IMAGEBLIT
723 select FB_SOFT_CURSOR
724 help 721 help
725 This driver supports the on-board graphics built in to the Intel 810 722 This driver supports the on-board graphics built in to the Intel 810
726 and 815 chipsets. Say Y if you have and plan to use such a board. 723 and 815 chipsets. Say Y if you have and plan to use such a board.
@@ -754,6 +751,12 @@ config FB_I810_GTF
754 751
755 If unsure, say N. 752 If unsure, say N.
756 753
754config FB_I810_I2C
755 bool "Enable DDC Support"
756 depends on FB_I810 && I2C && FB_I810_GTF
757 select I2C_ALGOBIT
758 help
759
757config FB_INTEL 760config FB_INTEL
758 tristate "Intel 830M/845G/852GM/855GM/865G support (EXPERIMENTAL)" 761 tristate "Intel 830M/845G/852GM/855GM/865G support (EXPERIMENTAL)"
759 depends on FB && EXPERIMENTAL && PCI && X86 && !X86_64 762 depends on FB && EXPERIMENTAL && PCI && X86 && !X86_64
@@ -763,7 +766,6 @@ config FB_INTEL
763 select FB_CFB_FILLRECT 766 select FB_CFB_FILLRECT
764 select FB_CFB_COPYAREA 767 select FB_CFB_COPYAREA
765 select FB_CFB_IMAGEBLIT 768 select FB_CFB_IMAGEBLIT
766 select FB_SOFT_CURSOR
767 help 769 help
768 This driver supports the on-board graphics built in to the Intel 770 This driver supports the on-board graphics built in to the Intel
769 830M/845G/852GM/855GM/865G chipsets. 771 830M/845G/852GM/855GM/865G chipsets.
@@ -960,8 +962,7 @@ config FB_RADEON
960 can be build either as modules or built-in. 962 can be build either as modules or built-in.
961 963
962 There is a product page at 964 There is a product page at
963 <http://www.ati.com/na/pages/products/pc/radeon32/index.html>. 965 http://apps.ati.com/ATIcompare/
964
965config FB_RADEON_I2C 966config FB_RADEON_I2C
966 bool "DDC/I2C for ATI Radeon support" 967 bool "DDC/I2C for ATI Radeon support"
967 depends on FB_RADEON 968 depends on FB_RADEON
@@ -1084,15 +1085,16 @@ config FB_SAVAGE_ACCEL
1084 choose N here. 1085 choose N here.
1085 1086
1086config FB_SIS 1087config FB_SIS
1087 tristate "SiS acceleration" 1088 tristate "SiS/XGI display support"
1088 depends on FB && PCI 1089 depends on FB && PCI
1089 select FB_CFB_FILLRECT 1090 select FB_CFB_FILLRECT
1090 select FB_CFB_COPYAREA 1091 select FB_CFB_COPYAREA
1091 select FB_CFB_IMAGEBLIT 1092 select FB_CFB_IMAGEBLIT
1092 select FB_SOFT_CURSOR 1093 select FB_SOFT_CURSOR
1093 help 1094 help
1094 This is the frame buffer device driver for the SiS 300, 315 and 1095 This is the frame buffer device driver for the SiS 300, 315, 330
1095 330 series VGA chipsets. Specs available at <http://www.sis.com> 1096 and 340 series as well as XGI V3XT, V5, V8, Z7 graphics chipsets.
1097 Specs available at <http://www.sis.com> and <http://www.xgitech.com>.
1096 1098
1097 To compile this driver as a module, choose M here; the module 1099 To compile this driver as a module, choose M here; the module
1098 will be called sisfb. 1100 will be called sisfb.
@@ -1104,11 +1106,12 @@ config FB_SIS_300
1104 Say Y here to support use of the SiS 300/305, 540, 630 and 730. 1106 Say Y here to support use of the SiS 300/305, 540, 630 and 730.
1105 1107
1106config FB_SIS_315 1108config FB_SIS_315
1107 bool "SiS 315/330 series support" 1109 bool "SiS 315/330/340 series and XGI support"
1108 depends on FB_SIS 1110 depends on FB_SIS
1109 help 1111 help
1110 Say Y here to support use of the SiS 315 and 330 series 1112 Say Y here to support use of the SiS 315, 330 and 340 series
1111 (315/H/PRO, 55x, 650, 651, 740, 330, 661, 741, 760). 1113 (315/H/PRO, 55x, 650, 651, 740, 330, 661, 741, 760, 761) as well
1114 as XGI V3XT, V5, V8 and Z7.
1112 1115
1113config FB_NEOMAGIC 1116config FB_NEOMAGIC
1114 tristate "NeoMagic display support" 1117 tristate "NeoMagic display support"
@@ -1180,6 +1183,32 @@ config FB_VOODOO1
1180 Please read the <file:Documentation/fb/README-sstfb.txt> for supported 1183 Please read the <file:Documentation/fb/README-sstfb.txt> for supported
1181 options and other important info support. 1184 options and other important info support.
1182 1185
1186config FB_CYBLA
1187 tristate "Cyberblade/i1 support"
1188 depends on FB && PCI
1189 select FB_CFB_IMAGEBLIT
1190 select FB_SOFT_CURSOR
1191 select VIDEO_SELECT
1192 ---help---
1193 This driver is supposed to support the Trident Cyberblade/i1
1194 graphics core integrated in the VIA VT8601A North Bridge,
1195 also known as VIA Apollo PLE133.
1196
1197 Status:
1198 - Developed, tested and working on EPIA 5000 and EPIA 800.
1199 - Does work reliable on all systems with CRT/LCD connected to
1200 normal VGA ports.
1201 - Should work on systems that do use the internal LCD port, but
1202 this is absolutely not tested.
1203
1204 Character imageblit, copyarea and rectangle fill are hw accelerated,
1205 ypan scrolling is used by default.
1206
1207 Please do read <file:Documentation/fb/cyblafb/*>.
1208
1209 To compile this driver as a module, choose M here: the
1210 module will be called cyblafb.
1211
1183config FB_TRIDENT 1212config FB_TRIDENT
1184 tristate "Trident support" 1213 tristate "Trident support"
1185 depends on FB && PCI 1214 depends on FB && PCI
@@ -1193,8 +1222,12 @@ config FB_TRIDENT
1193 but also on some motherboards. For more information, read 1222 but also on some motherboards. For more information, read
1194 <file:Documentation/fb/tridentfb.txt> 1223 <file:Documentation/fb/tridentfb.txt>
1195 1224
1225 Cyberblade/i1 support will be removed soon, use the cyblafb driver
1226 instead.
1227
1196 Say Y if you have such a graphics board. 1228 Say Y if you have such a graphics board.
1197 1229
1230
1198 To compile this driver as a module, choose M here: the 1231 To compile this driver as a module, choose M here: the
1199 module will be called tridentfb. 1232 module will be called tridentfb.
1200 1233
@@ -1205,7 +1238,6 @@ config FB_TRIDENT_ACCEL
1205 This will compile the Trident frame buffer device with 1238 This will compile the Trident frame buffer device with
1206 acceleration functions. 1239 acceleration functions.
1207 1240
1208
1209config FB_PM3 1241config FB_PM3
1210 tristate "Permedia3 support" 1242 tristate "Permedia3 support"
1211 depends on FB && PCI && BROKEN 1243 depends on FB && PCI && BROKEN
@@ -1484,6 +1516,30 @@ config FB_S1D13XXX
1484 working with S1D13806). Product specs at 1516 working with S1D13806). Product specs at
1485 <http://www.erd.epson.com/vdc/html/legacy_13xxx.htm> 1517 <http://www.erd.epson.com/vdc/html/legacy_13xxx.htm>
1486 1518
1519config FB_S3C2410
1520 tristate "S3C2410 LCD framebuffer support"
1521 depends on FB && ARCH_S3C2410
1522 select FB_CFB_FILLRECT
1523 select FB_CFB_COPYAREA
1524 select FB_CFB_IMAGEBLIT
1525 select FB_SOFT_CURSOR
1526 ---help---
1527 Frame buffer driver for the built-in LCD controller in the Samsung
1528 S3C2410 processor.
1529
1530 This driver is also available as a module ( = code which can be
1531 inserted and removed from the running kernel whenever you want). The
1532 module will be called s3c2410fb. If you want to compile it as a module,
1533 say M here and read <file:Documentation/modules.txt>.
1534
1535 If unsure, say N.
1536config FB_S3C2410_DEBUG
1537 bool "S3C2410 lcd debug messages"
1538 depends on FB_S3C2410
1539 help
1540 Turn on debugging messages. Note that you can set/unset at run time
1541 through sysfs
1542
1487config FB_VIRTUAL 1543config FB_VIRTUAL
1488 tristate "Virtual Frame Buffer support (ONLY FOR TESTING!)" 1544 tristate "Virtual Frame Buffer support (ONLY FOR TESTING!)"
1489 depends on FB 1545 depends on FB
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index b018df4e95..1fff29f48c 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -9,7 +9,8 @@ obj-$(CONFIG_LOGO) += logo/
9obj-$(CONFIG_SYSFS) += backlight/ 9obj-$(CONFIG_SYSFS) += backlight/
10 10
11obj-$(CONFIG_FB) += fb.o 11obj-$(CONFIG_FB) += fb.o
12fb-y := fbmem.o fbmon.o fbcmap.o fbsysfs.o modedb.o 12fb-y := fbmem.o fbmon.o fbcmap.o fbsysfs.o \
13 modedb.o fbcvt.o
13fb-objs := $(fb-y) 14fb-objs := $(fb-y)
14 15
15obj-$(CONFIG_FB_CFB_FILLRECT) += cfbfillrect.o 16obj-$(CONFIG_FB_CFB_FILLRECT) += cfbfillrect.o
@@ -50,7 +51,8 @@ obj-$(CONFIG_FB_CT65550) += chipsfb.o
50obj-$(CONFIG_FB_IMSTT) += imsttfb.o 51obj-$(CONFIG_FB_IMSTT) += imsttfb.o
51obj-$(CONFIG_FB_S3TRIO) += S3triofb.o 52obj-$(CONFIG_FB_S3TRIO) += S3triofb.o
52obj-$(CONFIG_FB_FM2) += fm2fb.o 53obj-$(CONFIG_FB_FM2) += fm2fb.o
53obj-$(CONFIG_FB_TRIDENT) += tridentfb.o 54obj-$(CONFIG_FB_CYBLA) += cyblafb.o
55obj-$(CONFIG_FB_TRIDENT) += tridentfb.o
54obj-$(CONFIG_FB_STI) += stifb.o 56obj-$(CONFIG_FB_STI) += stifb.o
55obj-$(CONFIG_FB_FFB) += ffb.o sbuslib.o 57obj-$(CONFIG_FB_FFB) += ffb.o sbuslib.o
56obj-$(CONFIG_FB_CG6) += cg6.o sbuslib.o 58obj-$(CONFIG_FB_CG6) += cg6.o sbuslib.o
@@ -92,6 +94,7 @@ obj-$(CONFIG_FB_MAXINE) += maxinefb.o
92obj-$(CONFIG_FB_TX3912) += tx3912fb.o 94obj-$(CONFIG_FB_TX3912) += tx3912fb.o
93obj-$(CONFIG_FB_S1D13XXX) += s1d13xxxfb.o 95obj-$(CONFIG_FB_S1D13XXX) += s1d13xxxfb.o
94obj-$(CONFIG_FB_IMX) += imxfb.o 96obj-$(CONFIG_FB_IMX) += imxfb.o
97obj-$(CONFIG_FB_S3C2410) += s3c2410fb.o
95 98
96# Platform or fallback drivers go here 99# Platform or fallback drivers go here
97obj-$(CONFIG_FB_VESA) += vesafb.o 100obj-$(CONFIG_FB_VESA) += vesafb.o
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index b0eba3ac64..e380ee8b02 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -806,8 +806,8 @@ static void __iomem * __init aty128_map_ROM(const struct aty128fb_par *par, stru
806 806
807 /* Very simple test to make sure it appeared */ 807 /* Very simple test to make sure it appeared */
808 if (BIOS_IN16(0) != 0xaa55) { 808 if (BIOS_IN16(0) != 0xaa55) {
809 printk(KERN_ERR "aty128fb: Invalid ROM signature %x should be 0xaa55\n", 809 printk(KERN_DEBUG "aty128fb: Invalid ROM signature %x should "
810 BIOS_IN16(0)); 810 " be 0xaa55\n", BIOS_IN16(0));
811 goto failed; 811 goto failed;
812 } 812 }
813 813
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index 3e10bd837d..037fe9d32f 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -911,20 +911,6 @@ static int aty_var_to_crtc(const struct fb_info *info,
911 vdisplay = par->lcd_height; 911 vdisplay = par->lcd_height;
912#endif 912#endif
913 913
914 if(vdisplay < 400) {
915 h_sync_pol = 1;
916 v_sync_pol = 0;
917 } else if(vdisplay < 480) {
918 h_sync_pol = 0;
919 v_sync_pol = 1;
920 } else if(vdisplay < 768) {
921 h_sync_pol = 0;
922 v_sync_pol = 0;
923 } else {
924 h_sync_pol = 1;
925 v_sync_pol = 1;
926 }
927
928 v_disp--; 914 v_disp--;
929 v_sync_strt--; 915 v_sync_strt--;
930 v_sync_end--; 916 v_sync_end--;
diff --git a/drivers/video/aty/radeon_base.c b/drivers/video/aty/radeon_base.c
index e7e8b52014..046b478602 100644
--- a/drivers/video/aty/radeon_base.c
+++ b/drivers/video/aty/radeon_base.c
@@ -329,8 +329,9 @@ static int __devinit radeon_map_ROM(struct radeonfb_info *rinfo, struct pci_dev
329 329
330 /* Very simple test to make sure it appeared */ 330 /* Very simple test to make sure it appeared */
331 if (BIOS_IN16(0) != 0xaa55) { 331 if (BIOS_IN16(0) != 0xaa55) {
332 printk(KERN_ERR "radeonfb (%s): Invalid ROM signature %x should be" 332 printk(KERN_DEBUG "radeonfb (%s): Invalid ROM signature %x "
333 "0xaa55\n", pci_name(rinfo->pdev), BIOS_IN16(0)); 333 "should be 0xaa55\n",
334 pci_name(rinfo->pdev), BIOS_IN16(0));
334 goto failed; 335 goto failed;
335 } 336 }
336 /* Look for the PCI data to check the ROM type */ 337 /* Look for the PCI data to check the ROM type */
@@ -2312,19 +2313,27 @@ static int radeonfb_pci_register (struct pci_dev *pdev,
2312 rinfo->mmio_base_phys = pci_resource_start (pdev, 2); 2313 rinfo->mmio_base_phys = pci_resource_start (pdev, 2);
2313 2314
2314 /* request the mem regions */ 2315 /* request the mem regions */
2315 ret = pci_request_regions(pdev, "radeonfb"); 2316 ret = pci_request_region(pdev, 0, "radeonfb framebuffer");
2316 if (ret < 0) { 2317 if (ret < 0) {
2317 printk( KERN_ERR "radeonfb (%s): cannot reserve PCI regions." 2318 printk( KERN_ERR "radeonfb (%s): cannot request region 0.\n",
2318 " Someone already got them?\n", pci_name(rinfo->pdev)); 2319 pci_name(rinfo->pdev));
2319 goto err_release_fb; 2320 goto err_release_fb;
2320 } 2321 }
2321 2322
2323 ret = pci_request_region(pdev, 2, "radeonfb mmio");
2324 if (ret < 0) {
2325 printk( KERN_ERR "radeonfb (%s): cannot request region 2.\n",
2326 pci_name(rinfo->pdev));
2327 goto err_release_pci0;
2328 }
2329
2322 /* map the regions */ 2330 /* map the regions */
2323 rinfo->mmio_base = ioremap(rinfo->mmio_base_phys, RADEON_REGSIZE); 2331 rinfo->mmio_base = ioremap(rinfo->mmio_base_phys, RADEON_REGSIZE);
2324 if (!rinfo->mmio_base) { 2332 if (!rinfo->mmio_base) {
2325 printk(KERN_ERR "radeonfb (%s): cannot map MMIO\n", pci_name(rinfo->pdev)); 2333 printk(KERN_ERR "radeonfb (%s): cannot map MMIO\n",
2334 pci_name(rinfo->pdev));
2326 ret = -EIO; 2335 ret = -EIO;
2327 goto err_release_pci; 2336 goto err_release_pci2;
2328 } 2337 }
2329 2338
2330 rinfo->fb_local_base = INREG(MC_FB_LOCATION) << 16; 2339 rinfo->fb_local_base = INREG(MC_FB_LOCATION) << 16;
@@ -2499,10 +2508,12 @@ err_unmap_rom:
2499 if (rinfo->bios_seg) 2508 if (rinfo->bios_seg)
2500 radeon_unmap_ROM(rinfo, pdev); 2509 radeon_unmap_ROM(rinfo, pdev);
2501 iounmap(rinfo->mmio_base); 2510 iounmap(rinfo->mmio_base);
2502err_release_pci: 2511err_release_pci2:
2503 pci_release_regions(pdev); 2512 pci_release_region(pdev, 2);
2513err_release_pci0:
2514 pci_release_region(pdev, 0);
2504err_release_fb: 2515err_release_fb:
2505 framebuffer_release(info); 2516 framebuffer_release(info);
2506err_disable: 2517err_disable:
2507 pci_disable_device(pdev); 2518 pci_disable_device(pdev);
2508err_out: 2519err_out:
@@ -2548,7 +2559,8 @@ static void __devexit radeonfb_pci_unregister (struct pci_dev *pdev)
2548 iounmap(rinfo->mmio_base); 2559 iounmap(rinfo->mmio_base);
2549 iounmap(rinfo->fb_base); 2560 iounmap(rinfo->fb_base);
2550 2561
2551 pci_release_regions(pdev); 2562 pci_release_region(pdev, 2);
2563 pci_release_region(pdev, 0);
2552 2564
2553 kfree(rinfo->mon1_EDID); 2565 kfree(rinfo->mon1_EDID);
2554 kfree(rinfo->mon2_EDID); 2566 kfree(rinfo->mon2_EDID);
diff --git a/drivers/video/console/bitblit.c b/drivers/video/console/bitblit.c
index 3c731577fe..9f70e512b8 100644
--- a/drivers/video/console/bitblit.c
+++ b/drivers/video/console/bitblit.c
@@ -39,7 +39,7 @@ static inline int get_attribute(struct fb_info *info, u16 c)
39{ 39{
40 int attribute = 0; 40 int attribute = 0;
41 41
42 if (fb_get_color_depth(&info->var) == 1) { 42 if (fb_get_color_depth(&info->var, &info->fix) == 1) {
43 if (attr_underline(c)) 43 if (attr_underline(c))
44 attribute |= FBCON_ATTRIBUTE_UNDERLINE; 44 attribute |= FBCON_ATTRIBUTE_UNDERLINE;
45 if (attr_reverse(c)) 45 if (attr_reverse(c))
@@ -103,42 +103,104 @@ static void bit_clear(struct vc_data *vc, struct fb_info *info, int sy,
103 info->fbops->fb_fillrect(info, &region); 103 info->fbops->fb_fillrect(info, &region);
104} 104}
105 105
106static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info,
107 const u16 *s, u32 attr, u32 cnt,
108 u32 d_pitch, u32 s_pitch, u32 cellsize,
109 struct fb_image *image, u8 *buf, u8 *dst)
110{
111 u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
112 u32 idx = vc->vc_font.width >> 3;
113 u8 *src;
114
115 while (cnt--) {
116 src = vc->vc_font.data + (scr_readw(s++)&
117 charmask)*cellsize;
118
119 if (attr) {
120 update_attr(buf, src, attr, vc);
121 src = buf;
122 }
123
124 if (likely(idx == 1))
125 __fb_pad_aligned_buffer(dst, d_pitch, src, idx,
126 image->height);
127 else
128 fb_pad_aligned_buffer(dst, d_pitch, src, idx,
129 image->height);
130
131 dst += s_pitch;
132 }
133
134 info->fbops->fb_imageblit(info, image);
135}
136
137static inline void bit_putcs_unaligned(struct vc_data *vc,
138 struct fb_info *info, const u16 *s,
139 u32 attr, u32 cnt, u32 d_pitch,
140 u32 s_pitch, u32 cellsize,
141 struct fb_image *image, u8 *buf,
142 u8 *dst)
143{
144 u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
145 u32 shift_low = 0, mod = vc->vc_font.width % 8;
146 u32 shift_high = 8;
147 u32 idx = vc->vc_font.width >> 3;
148 u8 *src;
149
150 while (cnt--) {
151 src = vc->vc_font.data + (scr_readw(s++)&
152 charmask)*cellsize;
153
154 if (attr) {
155 update_attr(buf, src, attr, vc);
156 src = buf;
157 }
158
159 fb_pad_unaligned_buffer(dst, d_pitch, src, idx,
160 image->height, shift_high,
161 shift_low, mod);
162 shift_low += mod;
163 dst += (shift_low >= 8) ? s_pitch : s_pitch - 1;
164 shift_low &= 7;
165 shift_high = 8 - shift_low;
166 }
167
168 info->fbops->fb_imageblit(info, image);
169
170}
171
106static void bit_putcs(struct vc_data *vc, struct fb_info *info, 172static void bit_putcs(struct vc_data *vc, struct fb_info *info,
107 const unsigned short *s, int count, int yy, int xx, 173 const unsigned short *s, int count, int yy, int xx,
108 int fg, int bg) 174 int fg, int bg)
109{ 175{
110 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
111 unsigned int width = (vc->vc_font.width + 7) >> 3;
112 unsigned int cellsize = vc->vc_font.height * width;
113 unsigned int maxcnt = info->pixmap.size/cellsize;
114 unsigned int scan_align = info->pixmap.scan_align - 1;
115 unsigned int buf_align = info->pixmap.buf_align - 1;
116 unsigned int shift_low = 0, mod = vc->vc_font.width % 8;
117 unsigned int shift_high = 8, pitch, cnt, size, k;
118 unsigned int idx = vc->vc_font.width >> 3;
119 unsigned int attribute = get_attribute(info, scr_readw(s));
120 struct fb_image image; 176 struct fb_image image;
121 u8 *src, *dst, *buf = NULL; 177 u32 width = (vc->vc_font.width + 7)/8;
122 178 u32 cellsize = width * vc->vc_font.height;
123 if (attribute) { 179 u32 maxcnt = info->pixmap.size/cellsize;
124 buf = kmalloc(cellsize, GFP_KERNEL); 180 u32 scan_align = info->pixmap.scan_align - 1;
125 if (!buf) 181 u32 buf_align = info->pixmap.buf_align - 1;
126 return; 182 u32 mod = vc->vc_font.width % 8, cnt, pitch, size;
127 } 183 u32 attribute = get_attribute(info, scr_readw(s));
184 u8 *dst, *buf = NULL;
128 185
129 image.fg_color = fg; 186 image.fg_color = fg;
130 image.bg_color = bg; 187 image.bg_color = bg;
131
132 image.dx = xx * vc->vc_font.width; 188 image.dx = xx * vc->vc_font.width;
133 image.dy = yy * vc->vc_font.height; 189 image.dy = yy * vc->vc_font.height;
134 image.height = vc->vc_font.height; 190 image.height = vc->vc_font.height;
135 image.depth = 1; 191 image.depth = 1;
136 192
193 if (attribute) {
194 buf = kmalloc(cellsize, GFP_KERNEL);
195 if (!buf)
196 return;
197 }
198
137 while (count) { 199 while (count) {
138 if (count > maxcnt) 200 if (count > maxcnt)
139 cnt = k = maxcnt; 201 cnt = maxcnt;
140 else 202 else
141 cnt = k = count; 203 cnt = count;
142 204
143 image.width = vc->vc_font.width * cnt; 205 image.width = vc->vc_font.width * cnt;
144 pitch = ((image.width + 7) >> 3) + scan_align; 206 pitch = ((image.width + 7) >> 3) + scan_align;
@@ -147,41 +209,18 @@ static void bit_putcs(struct vc_data *vc, struct fb_info *info,
147 size &= ~buf_align; 209 size &= ~buf_align;
148 dst = fb_get_buffer_offset(info, &info->pixmap, size); 210 dst = fb_get_buffer_offset(info, &info->pixmap, size);
149 image.data = dst; 211 image.data = dst;
150 if (mod) { 212
151 while (k--) { 213 if (!mod)
152 src = vc->vc_font.data + (scr_readw(s++)& 214 bit_putcs_aligned(vc, info, s, attribute, cnt, pitch,
153 charmask)*cellsize; 215 width, cellsize, &image, buf, dst);
154 216 else
155 if (attribute) { 217 bit_putcs_unaligned(vc, info, s, attribute, cnt,
156 update_attr(buf, src, attribute, vc); 218 pitch, width, cellsize, &image,
157 src = buf; 219 buf, dst);
158 } 220
159
160 fb_pad_unaligned_buffer(dst, pitch, src, idx,
161 image.height, shift_high,
162 shift_low, mod);
163 shift_low += mod;
164 dst += (shift_low >= 8) ? width : width - 1;
165 shift_low &= 7;
166 shift_high = 8 - shift_low;
167 }
168 } else {
169 while (k--) {
170 src = vc->vc_font.data + (scr_readw(s++)&
171 charmask)*cellsize;
172
173 if (attribute) {
174 update_attr(buf, src, attribute, vc);
175 src = buf;
176 }
177
178 fb_pad_aligned_buffer(dst, pitch, src, idx, image.height);
179 dst += width;
180 }
181 }
182 info->fbops->fb_imageblit(info, &image);
183 image.dx += cnt * vc->vc_font.width; 221 image.dx += cnt * vc->vc_font.width;
184 count -= cnt; 222 count -= cnt;
223 s += cnt;
185 } 224 }
186 225
187 /* buf is always NULL except when in monochrome mode, so in this case 226 /* buf is always NULL except when in monochrome mode, so in this case
@@ -189,6 +228,7 @@ static void bit_putcs(struct vc_data *vc, struct fb_info *info,
189 NULL pointers just fine */ 228 NULL pointers just fine */
190 if (unlikely(buf)) 229 if (unlikely(buf))
191 kfree(buf); 230 kfree(buf);
231
192} 232}
193 233
194static void bit_clear_margins(struct vc_data *vc, struct fb_info *info, 234static void bit_clear_margins(struct vc_data *vc, struct fb_info *info,
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index 35c88bd7ba..2e93224d2d 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -214,7 +214,7 @@ static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
214static inline int get_color(struct vc_data *vc, struct fb_info *info, 214static inline int get_color(struct vc_data *vc, struct fb_info *info,
215 u16 c, int is_fg) 215 u16 c, int is_fg)
216{ 216{
217 int depth = fb_get_color_depth(&info->var); 217 int depth = fb_get_color_depth(&info->var, &info->fix);
218 int color = 0; 218 int color = 0;
219 219
220 if (console_blanked) { 220 if (console_blanked) {
@@ -230,9 +230,13 @@ static inline int get_color(struct vc_data *vc, struct fb_info *info,
230 switch (depth) { 230 switch (depth) {
231 case 1: 231 case 1:
232 { 232 {
233 int col = ~(0xfff << (max(info->var.green.length,
234 max(info->var.red.length,
235 info->var.blue.length)))) & 0xff;
236
233 /* 0 or 1 */ 237 /* 0 or 1 */
234 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? 1 : 0; 238 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
235 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : 1; 239 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
236 240
237 if (console_blanked) 241 if (console_blanked)
238 fg = bg; 242 fg = bg;
@@ -243,9 +247,25 @@ static inline int get_color(struct vc_data *vc, struct fb_info *info,
243 case 2: 247 case 2:
244 /* 248 /*
245 * Scale down 16-colors to 4 colors. Default 4-color palette 249 * Scale down 16-colors to 4 colors. Default 4-color palette
246 * is grayscale. 250 * is grayscale. However, simply dividing the values by 4
251 * will not work, as colors 1, 2 and 3 will be scaled-down
252 * to zero rendering them invisible. So empirically convert
253 * colors to a sane 4-level grayscale.
247 */ 254 */
248 color /= 4; 255 switch (color) {
256 case 0:
257 color = 0; /* black */
258 break;
259 case 1 ... 6:
260 color = 2; /* white */
261 break;
262 case 7 ... 8:
263 color = 1; /* gray */
264 break;
265 default:
266 color = 3; /* intense white */
267 break;
268 }
249 break; 269 break;
250 case 3: 270 case 3:
251 /* 271 /*
@@ -311,6 +331,35 @@ static void cursor_timer_handler(unsigned long dev_addr)
311 mod_timer(&ops->cursor_timer, jiffies + HZ/5); 331 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
312} 332}
313 333
334static void fbcon_add_cursor_timer(struct fb_info *info)
335{
336 struct fbcon_ops *ops = info->fbcon_par;
337
338 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
339 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER)) {
340 if (!info->queue.func)
341 INIT_WORK(&info->queue, fb_flashcursor, info);
342
343 init_timer(&ops->cursor_timer);
344 ops->cursor_timer.function = cursor_timer_handler;
345 ops->cursor_timer.expires = jiffies + HZ / 5;
346 ops->cursor_timer.data = (unsigned long ) info;
347 add_timer(&ops->cursor_timer);
348 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
349 }
350}
351
352static void fbcon_del_cursor_timer(struct fb_info *info)
353{
354 struct fbcon_ops *ops = info->fbcon_par;
355
356 if (info->queue.func == fb_flashcursor &&
357 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
358 del_timer_sync(&ops->cursor_timer);
359 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
360 }
361}
362
314#ifndef MODULE 363#ifndef MODULE
315static int __init fb_console_setup(char *this_opt) 364static int __init fb_console_setup(char *this_opt)
316{ 365{
@@ -426,7 +475,7 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
426 * remove underline attribute from erase character 475 * remove underline attribute from erase character
427 * if black and white framebuffer. 476 * if black and white framebuffer.
428 */ 477 */
429 if (fb_get_color_depth(&info->var) == 1) 478 if (fb_get_color_depth(&info->var, &info->fix) == 1)
430 erase &= ~0x400; 479 erase &= ~0x400;
431 logo_height = fb_prepare_logo(info); 480 logo_height = fb_prepare_logo(info);
432 logo_lines = (logo_height + vc->vc_font.height - 1) / 481 logo_lines = (logo_height + vc->vc_font.height - 1) /
@@ -563,9 +612,7 @@ static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
563 } 612 }
564 613
565 if (!err) { 614 if (!err) {
566 if (oldinfo->queue.func == fb_flashcursor) 615 fbcon_del_cursor_timer(oldinfo);
567 del_timer_sync(&ops->cursor_timer);
568
569 kfree(ops->cursor_state.mask); 616 kfree(ops->cursor_state.mask);
570 kfree(ops->cursor_data); 617 kfree(ops->cursor_data);
571 kfree(oldinfo->fbcon_par); 618 kfree(oldinfo->fbcon_par);
@@ -576,22 +623,6 @@ static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
576 return err; 623 return err;
577} 624}
578 625
579static void con2fb_init_newinfo(struct fb_info *info)
580{
581 if (!info->queue.func || info->queue.func == fb_flashcursor) {
582 struct fbcon_ops *ops = info->fbcon_par;
583
584 if (!info->queue.func)
585 INIT_WORK(&info->queue, fb_flashcursor, info);
586
587 init_timer(&ops->cursor_timer);
588 ops->cursor_timer.function = cursor_timer_handler;
589 ops->cursor_timer.expires = jiffies + HZ / 5;
590 ops->cursor_timer.data = (unsigned long ) info;
591 add_timer(&ops->cursor_timer);
592 }
593}
594
595static void con2fb_init_display(struct vc_data *vc, struct fb_info *info, 626static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
596 int unit, int show_logo) 627 int unit, int show_logo)
597{ 628{
@@ -675,7 +706,7 @@ static int set_con2fb_map(int unit, int newidx, int user)
675 logo_shown != FBCON_LOGO_DONTSHOW); 706 logo_shown != FBCON_LOGO_DONTSHOW);
676 707
677 if (!found) 708 if (!found)
678 con2fb_init_newinfo(info); 709 fbcon_add_cursor_timer(info);
679 con2fb_map_boot[unit] = newidx; 710 con2fb_map_boot[unit] = newidx;
680 con2fb_init_display(vc, info, unit, show_logo); 711 con2fb_init_display(vc, info, unit, show_logo);
681 } 712 }
@@ -878,18 +909,7 @@ static const char *fbcon_startup(void)
878 } 909 }
879#endif /* CONFIG_MAC */ 910#endif /* CONFIG_MAC */
880 911
881 /* Initialize the work queue. If the driver provides its 912 fbcon_add_cursor_timer(info);
882 * own work queue this means it will use something besides
883 * default timer to flash the cursor. */
884 if (!info->queue.func) {
885 INIT_WORK(&info->queue, fb_flashcursor, info);
886
887 init_timer(&ops->cursor_timer);
888 ops->cursor_timer.function = cursor_timer_handler;
889 ops->cursor_timer.expires = jiffies + HZ / 5;
890 ops->cursor_timer.data = (unsigned long ) info;
891 add_timer(&ops->cursor_timer);
892 }
893 return display_desc; 913 return display_desc;
894} 914}
895 915
@@ -930,7 +950,7 @@ static void fbcon_init(struct vc_data *vc, int init)
930 } 950 }
931 if (p->userfont) 951 if (p->userfont)
932 charcnt = FNTCHARCNT(p->fontdata); 952 charcnt = FNTCHARCNT(p->fontdata);
933 vc->vc_can_do_color = (fb_get_color_depth(&info->var) != 1); 953 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
934 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800; 954 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
935 if (charcnt == 256) { 955 if (charcnt == 256) {
936 vc->vc_hi_font_mask = 0; 956 vc->vc_hi_font_mask = 0;
@@ -1178,7 +1198,12 @@ static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1178 if (p->userfont) 1198 if (p->userfont)
1179 charcnt = FNTCHARCNT(p->fontdata); 1199 charcnt = FNTCHARCNT(p->fontdata);
1180 1200
1181 vc->vc_can_do_color = (fb_get_color_depth(var) != 1); 1201 var->activate = FB_ACTIVATE_NOW;
1202 info->var.activate = var->activate;
1203 info->var.yoffset = info->var.xoffset = 0;
1204 fb_set_var(info, var);
1205
1206 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1182 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800; 1207 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1183 if (charcnt == 256) { 1208 if (charcnt == 256) {
1184 vc->vc_hi_font_mask = 0; 1209 vc->vc_hi_font_mask = 0;
@@ -1898,7 +1923,7 @@ static int fbcon_resize(struct vc_data *vc, unsigned int width,
1898 1923
1899static int fbcon_switch(struct vc_data *vc) 1924static int fbcon_switch(struct vc_data *vc)
1900{ 1925{
1901 struct fb_info *info; 1926 struct fb_info *info, *old_info = NULL;
1902 struct display *p = &fb_display[vc->vc_num]; 1927 struct display *p = &fb_display[vc->vc_num];
1903 struct fb_var_screeninfo var; 1928 struct fb_var_screeninfo var;
1904 int i, prev_console; 1929 int i, prev_console;
@@ -1931,7 +1956,8 @@ static int fbcon_switch(struct vc_data *vc)
1931 } 1956 }
1932 1957
1933 prev_console = ((struct fbcon_ops *)info->fbcon_par)->currcon; 1958 prev_console = ((struct fbcon_ops *)info->fbcon_par)->currcon;
1934 1959 if (prev_console != -1)
1960 old_info = registered_fb[con2fb_map[prev_console]];
1935 /* 1961 /*
1936 * FIXME: If we have multiple fbdev's loaded, we need to 1962 * FIXME: If we have multiple fbdev's loaded, we need to
1937 * update all info->currcon. Perhaps, we can place this 1963 * update all info->currcon. Perhaps, we can place this
@@ -1959,15 +1985,17 @@ static int fbcon_switch(struct vc_data *vc)
1959 info->var.yoffset = info->var.xoffset = p->yscroll = 0; 1985 info->var.yoffset = info->var.xoffset = p->yscroll = 0;
1960 fb_set_var(info, &var); 1986 fb_set_var(info, &var);
1961 1987
1962 if (prev_console != -1 && 1988 if (old_info != NULL && old_info != info) {
1963 registered_fb[con2fb_map[prev_console]] != info && 1989 if (info->fbops->fb_set_par)
1964 info->fbops->fb_set_par) 1990 info->fbops->fb_set_par(info);
1965 info->fbops->fb_set_par(info); 1991 fbcon_del_cursor_timer(old_info);
1992 fbcon_add_cursor_timer(info);
1993 }
1966 1994
1967 set_blitting_type(vc, info, p); 1995 set_blitting_type(vc, info, p);
1968 ((struct fbcon_ops *)info->fbcon_par)->cursor_reset = 1; 1996 ((struct fbcon_ops *)info->fbcon_par)->cursor_reset = 1;
1969 1997
1970 vc->vc_can_do_color = (fb_get_color_depth(&info->var) != 1); 1998 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1971 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800; 1999 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1972 updatescrollmode(p, info, vc); 2000 updatescrollmode(p, info, vc);
1973 2001
@@ -2048,11 +2076,16 @@ static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2048 fbcon_generic_blank(vc, info, blank); 2076 fbcon_generic_blank(vc, info, blank);
2049 } 2077 }
2050 2078
2051 if (!blank) 2079 if (!blank)
2052 update_screen(vc); 2080 update_screen(vc);
2053 } 2081 }
2054 2082
2055 return 0; 2083 if (!blank)
2084 fbcon_add_cursor_timer(info);
2085 else
2086 fbcon_del_cursor_timer(info);
2087
2088 return 0;
2056} 2089}
2057 2090
2058static void fbcon_free_font(struct display *p) 2091static void fbcon_free_font(struct display *p)
@@ -2332,7 +2365,7 @@ static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2332 if (!CON_IS_VISIBLE(vc)) 2365 if (!CON_IS_VISIBLE(vc))
2333 return 0; 2366 return 0;
2334 2367
2335 depth = fb_get_color_depth(&info->var); 2368 depth = fb_get_color_depth(&info->var, &info->fix);
2336 if (depth > 3) { 2369 if (depth > 3) {
2337 for (i = j = 0; i < 16; i++) { 2370 for (i = j = 0; i < 16; i++) {
2338 k = table[i]; 2371 k = table[i];
@@ -2593,6 +2626,51 @@ static void fbcon_modechanged(struct fb_info *info)
2593 } 2626 }
2594} 2627}
2595 2628
2629static void fbcon_set_all_vcs(struct fb_info *info)
2630{
2631 struct fbcon_ops *ops = info->fbcon_par;
2632 struct vc_data *vc;
2633 struct display *p;
2634 int i, rows, cols;
2635
2636 if (!ops || ops->currcon < 0)
2637 return;
2638
2639 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2640 vc = vc_cons[i].d;
2641 if (!vc || vc->vc_mode != KD_TEXT ||
2642 registered_fb[con2fb_map[i]] != info)
2643 continue;
2644
2645 p = &fb_display[vc->vc_num];
2646
2647 info->var.xoffset = info->var.yoffset = p->yscroll = 0;
2648 var_to_display(p, &info->var, info);
2649 cols = info->var.xres / vc->vc_font.width;
2650 rows = info->var.yres / vc->vc_font.height;
2651 vc_resize(vc, cols, rows);
2652
2653 if (CON_IS_VISIBLE(vc)) {
2654 updatescrollmode(p, info, vc);
2655 scrollback_max = 0;
2656 scrollback_current = 0;
2657 update_var(vc->vc_num, info);
2658 fbcon_set_palette(vc, color_table);
2659 update_screen(vc);
2660 if (softback_buf) {
2661 int l = fbcon_softback_size / vc->vc_size_row;
2662 if (l > 5)
2663 softback_end = softback_buf + l * vc->vc_size_row;
2664 else {
2665 /* Smaller scrollback makes no sense, and 0
2666 would screw the operation totally */
2667 softback_top = 0;
2668 }
2669 }
2670 }
2671 }
2672}
2673
2596static int fbcon_mode_deleted(struct fb_info *info, 2674static int fbcon_mode_deleted(struct fb_info *info,
2597 struct fb_videomode *mode) 2675 struct fb_videomode *mode)
2598{ 2676{
@@ -2708,6 +2786,9 @@ static int fbcon_event_notify(struct notifier_block *self,
2708 case FB_EVENT_MODE_CHANGE: 2786 case FB_EVENT_MODE_CHANGE:
2709 fbcon_modechanged(info); 2787 fbcon_modechanged(info);
2710 break; 2788 break;
2789 case FB_EVENT_MODE_CHANGE_ALL:
2790 fbcon_set_all_vcs(info);
2791 break;
2711 case FB_EVENT_MODE_DELETE: 2792 case FB_EVENT_MODE_DELETE:
2712 mode = event->data; 2793 mode = event->data;
2713 ret = fbcon_mode_deleted(info, mode); 2794 ret = fbcon_mode_deleted(info, mode);
diff --git a/drivers/video/console/fbcon.h b/drivers/video/console/fbcon.h
index 5d377860bc..08befafe11 100644
--- a/drivers/video/console/fbcon.h
+++ b/drivers/video/console/fbcon.h
@@ -18,7 +18,8 @@
18 18
19#include <asm/io.h> 19#include <asm/io.h>
20 20
21#define FBCON_FLAGS_INIT 1 21#define FBCON_FLAGS_INIT 1
22#define FBCON_FLAGS_CURSOR_TIMER 2
22 23
23 /* 24 /*
24 * This is the interface between the low-level console driver and the 25 * This is the interface between the low-level console driver and the
diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c
index d27fa91e58..0705cd7414 100644
--- a/drivers/video/console/vgacon.c
+++ b/drivers/video/console/vgacon.c
@@ -497,6 +497,57 @@ static void vgacon_cursor(struct vc_data *c, int mode)
497 } 497 }
498} 498}
499 499
500static int vgacon_doresize(struct vc_data *c,
501 unsigned int width, unsigned int height)
502{
503 unsigned long flags;
504 unsigned int scanlines = height * c->vc_font.height;
505 u8 scanlines_lo, r7, vsync_end, mode;
506
507 spin_lock_irqsave(&vga_lock, flags);
508
509 outb_p(VGA_CRTC_MODE, vga_video_port_reg);
510 mode = inb_p(vga_video_port_val);
511
512 if (mode & 0x04)
513 scanlines >>= 1;
514
515 scanlines -= 1;
516 scanlines_lo = scanlines & 0xff;
517
518 outb_p(VGA_CRTC_OVERFLOW, vga_video_port_reg);
519 r7 = inb_p(vga_video_port_val) & ~0x42;
520
521 if (scanlines & 0x100)
522 r7 |= 0x02;
523 if (scanlines & 0x200)
524 r7 |= 0x40;
525
526 /* deprotect registers */
527 outb_p(VGA_CRTC_V_SYNC_END, vga_video_port_reg);
528 vsync_end = inb_p(vga_video_port_val);
529 outb_p(VGA_CRTC_V_SYNC_END, vga_video_port_reg);
530 outb_p(vsync_end & ~0x80, vga_video_port_val);
531
532 outb_p(VGA_CRTC_H_DISP, vga_video_port_reg);
533 outb_p(width - 1, vga_video_port_val);
534 outb_p(VGA_CRTC_OFFSET, vga_video_port_reg);
535 outb_p(width >> 1, vga_video_port_val);
536
537 outb_p(VGA_CRTC_V_DISP_END, vga_video_port_reg);
538 outb_p(scanlines_lo, vga_video_port_val);
539 outb_p(VGA_CRTC_OVERFLOW, vga_video_port_reg);
540 outb_p(r7,vga_video_port_val);
541
542 /* reprotect registers */
543 outb_p(VGA_CRTC_V_SYNC_END, vga_video_port_reg);
544 outb_p(vsync_end, vga_video_port_val);
545
546 spin_unlock_irqrestore(&vga_lock, flags);
547
548 return 0;
549}
550
500static int vgacon_switch(struct vc_data *c) 551static int vgacon_switch(struct vc_data *c)
501{ 552{
502 /* 553 /*
@@ -510,9 +561,13 @@ static int vgacon_switch(struct vc_data *c)
510 /* We can only copy out the size of the video buffer here, 561 /* We can only copy out the size of the video buffer here,
511 * otherwise we get into VGA BIOS */ 562 * otherwise we get into VGA BIOS */
512 563
513 if (!vga_is_gfx) 564 if (!vga_is_gfx) {
514 scr_memcpyw((u16 *) c->vc_origin, (u16 *) c->vc_screenbuf, 565 scr_memcpyw((u16 *) c->vc_origin, (u16 *) c->vc_screenbuf,
515 c->vc_screenbuf_size > vga_vram_size ? vga_vram_size : c->vc_screenbuf_size); 566 c->vc_screenbuf_size > vga_vram_size ?
567 vga_vram_size : c->vc_screenbuf_size);
568 vgacon_doresize(c, c->vc_cols, c->vc_rows);
569 }
570
516 return 0; /* Redrawing not needed */ 571 return 0; /* Redrawing not needed */
517} 572}
518 573
@@ -962,6 +1017,17 @@ static int vgacon_font_get(struct vc_data *c, struct console_font *font)
962 1017
963#endif 1018#endif
964 1019
1020static int vgacon_resize(struct vc_data *c, unsigned int width,
1021 unsigned int height)
1022{
1023 if (width % 2 || width > ORIG_VIDEO_COLS || height > ORIG_VIDEO_LINES)
1024 return -EINVAL;
1025
1026 if (CON_IS_VISIBLE(c) && !vga_is_gfx) /* who knows */
1027 vgacon_doresize(c, width, height);
1028 return 0;
1029}
1030
965static int vgacon_scrolldelta(struct vc_data *c, int lines) 1031static int vgacon_scrolldelta(struct vc_data *c, int lines)
966{ 1032{
967 if (!lines) /* Turn scrollback off */ 1033 if (!lines) /* Turn scrollback off */
@@ -1103,6 +1169,7 @@ const struct consw vga_con = {
1103 .con_blank = vgacon_blank, 1169 .con_blank = vgacon_blank,
1104 .con_font_set = vgacon_font_set, 1170 .con_font_set = vgacon_font_set,
1105 .con_font_get = vgacon_font_get, 1171 .con_font_get = vgacon_font_get,
1172 .con_resize = vgacon_resize,
1106 .con_set_palette = vgacon_set_palette, 1173 .con_set_palette = vgacon_set_palette,
1107 .con_scrolldelta = vgacon_scrolldelta, 1174 .con_scrolldelta = vgacon_scrolldelta,
1108 .con_set_origin = vgacon_set_origin, 1175 .con_set_origin = vgacon_set_origin,
diff --git a/drivers/video/cyblafb.c b/drivers/video/cyblafb.c
new file mode 100644
index 0000000000..ae2762cb56
--- /dev/null
+++ b/drivers/video/cyblafb.c
@@ -0,0 +1,1456 @@
1/*
2 * Frame buffer driver for Trident Cyberblade/i1 graphics core
3 *
4 * Copyright 2005 Knut Petersen <Knut_Petersen@t-online.de>
5 *
6 * CREDITS:
7 * tridentfb.c by Jani Monoses
8 * see files above for further credits
9 *
10 * TODO:
11 *
12 */
13
14#define CYBLAFB_DEBUG 0
15
16#include <linux/config.h>
17#include <linux/module.h>
18#include <linux/string.h>
19#include <linux/fb.h>
20#include <linux/init.h>
21#include <linux/pci.h>
22#include <asm/types.h>
23#include <video/cyblafb.h>
24
25#define VERSION "0.54"
26
27struct cyblafb_par {
28 u32 pseudo_pal[16];
29 struct fb_ops ops;
30};
31
32static struct fb_fix_screeninfo cyblafb_fix __devinitdata = {
33 .id = "CyBla",
34 .type = FB_TYPE_PACKED_PIXELS,
35 .ypanstep = 1,
36 .visual = FB_VISUAL_PSEUDOCOLOR,
37 .accel = FB_ACCEL_NONE,
38};
39
40static char *mode __devinitdata = NULL;
41static int bpp __devinitdata = 8;
42static int ref __devinitdata = 75;
43static int fp __devinitdata;
44static int crt __devinitdata;
45static int memsize __devinitdata;
46static int vesafb __devinitdata;
47
48static int nativex;
49static int center;
50static int stretch;
51static int pciwb = 1;
52static int pcirb = 1;
53static int pciwr = 1;
54static int pcirr = 1;
55static int verbosity;
56static int displaytype;
57
58static void __iomem * io_virt; // iospace virtual memory address
59
60module_param(mode,charp,0);
61module_param(bpp,int,0);
62module_param(ref,int,0);
63module_param(fp,int,0);
64module_param(crt,int,0);
65module_param(nativex,int,0);
66module_param(center,int,0);
67module_param(stretch,int,0);
68module_param(pciwb,int,0);
69module_param(pcirb,int,0);
70module_param(pciwr,int,0);
71module_param(pcirr,int,0);
72module_param(memsize,int,0);
73module_param(verbosity,int,0);
74module_param(vesafb,int,0);
75
76//=========================================
77//
78// Port access macros for memory mapped io
79//
80//=========================================
81
82#define out8(r,v) writeb(v,io_virt+r)
83#define out32(r,v) writel(v,io_virt+r)
84#define in8(r) readb(io_virt+r)
85#define in32(r) readl(io_virt+r)
86
87//======================================
88//
89// Hardware access inline functions
90//
91//======================================
92
93static inline unsigned char read3X4(int reg)
94{
95 out8(0x3D4,reg);
96 return in8(0x3D5);
97}
98
99static inline unsigned char read3C4(int reg)
100{
101 out8(0x3C4,reg);
102 return in8(0x3C5);
103}
104
105static inline unsigned char read3CE(int reg)
106{
107 out8(0x3CE,reg);
108 return in8(0x3CF);
109}
110
111static inline void write3X4(int reg,unsigned char val)
112{
113 out8(0x3D4,reg);
114 out8(0x3D5,val);
115}
116
117static inline void write3C4(int reg,unsigned char val)
118{
119 out8(0x3C4,reg);
120 out8(0x3C5,val);
121}
122
123static inline void write3CE(int reg,unsigned char val)
124{
125 out8(0x3CE,reg);
126 out8(0x3CF,val);
127}
128
129static inline void write3C0(int reg,unsigned char val)
130{
131 in8(0x3DA); // read to reset index
132 out8(0x3C0,reg);
133 out8(0x3C0,val);
134}
135
136//=================================================
137//
138// Enable memory mapped io and unprotect registers
139//
140//=================================================
141
142static inline void enable_mmio(void)
143{
144 int tmp;
145
146 outb(0x0B,0x3C4);
147 inb(0x3C5); // Set NEW mode
148 outb(SR0E,0x3C4); // write enable a lot of extended ports
149 outb(0x80,0x3C5);
150
151 outb(SR11,0x3C4); // write enable those extended ports that
152 outb(0x87,0x3C5); // are not affected by SR0E_New
153
154 outb(CR1E,0x3d4); // clear write protect bit for port 0x3c2
155 tmp=inb(0x3d5) & 0xBF;
156 outb(CR1E,0x3d4);
157 outb(tmp,0x3d5);
158
159 outb(CR39,0x3D4);
160 outb(inb(0x3D5)|0x01,0x3D5); // Enable mmio, everything else untouched
161}
162
163//=================================================
164//
165// Set pixel clock VCLK1
166// - multipliers set elswhere
167// - freq in units of 0.01 MHz
168//
169//=================================================
170
171static void set_vclk(struct cyblafb_par *par, int freq)
172{
173 u32 m,n,k;
174 int f,fi,d,di;
175 u8 lo=0,hi=0;
176
177 d = 2000;
178 k = freq >= 10000 ? 0 : freq >= 5000 ? 1 : freq >= 2500 ? 2 : 3;
179 for(m = 0;m<64;m++)
180 for(n = 0;n<250;n++) { // max 249 is a hardware limit for cybla/i1 !
181 fi = (int)(((5864727*(n+8))/((m+2)*(1<<k)))>>12);
182 if ((di = abs(fi - freq)) < d) {
183 d = di;
184 f = fi;
185 lo = (u8) n;
186 hi = (u8) ((k<<6) | m);
187 }
188 }
189 write3C4(SR19,hi);
190 write3C4(SR18,lo);
191 if(verbosity > 1)
192 output("pixclock = %d.%02d MHz, k/m/n %x %x %x\n",
193 freq/100,freq%100,(hi&0xc0)>>6,hi&0x3f,lo);
194}
195
196//================================================
197//
198// Cyberblade specific Graphics Engine (GE) setup
199//
200//================================================
201
202static void cyblafb_setup_GE(int pitch,int bpp)
203{
204 int base = (pitch>>3)<<20;
205
206 switch (bpp) {
207 case 8: base |= (0<<29); break;
208 case 15: base |= (5<<29); break;
209 case 16: base |= (1<<29); break;
210 case 24:
211 case 32: base |= (2<<29); break;
212 }
213
214 write3X4(CR36,0x90); // reset GE
215 write3X4(CR36,0x80); // enable GE
216
217 out32(GE24,1<<7); // reset all GE pointers
218 out32(GE24,0);
219
220 write3X4(CR2D,0x00); // GE Timinigs, no delays
221
222 out32(GEB8,base); // Destination Stride / Buffer Base 0, p 133
223 out32(GEBC,base); // Destination Stride / Buffer Base 1, p 133
224 out32(GEC0,base); // Destination Stride / Buffer Base 2, p 133
225 out32(GEC4,base); // Destination Stride / Buffer Base 3, p 133
226 out32(GEC8,base); // Source Stride / Buffer Base 0, p 133
227 out32(GECC,base); // Source Stride / Buffer Base 1, p 133
228 out32(GED0,base); // Source Stride / Buffer Base 2, p 133
229 out32(GED4,base); // Source Stride / Buffer Base 3, p 133
230 out32(GE6C,0); // Pattern and Style, p 129, ok
231}
232
233//=====================================================================
234//
235// Although this is a .fb_sync function that could be enabled in
236// cyblafb_ops, we do not include it there. We sync immediately before
237// new GE operations to improve performance.
238//
239//=====================================================================
240
241static int cyblafb_sync(struct fb_info *info)
242{
243 int status, i=100000;
244 while( ((status=in32(GE20)) & 0xFA800000) && i != 0)
245 i--;
246
247 if (i == 0) {
248 // The timeout might be caused by disabled mmio.
249 // Cause:
250 // - bit CR39 & 1 == 0 upon return, X trident driver bug
251 // - kdm bug (KD_GRAPHICS not set on first switch)
252 // - kernel design flaw (it believes in the correctness
253 // of kdm/X
254 // So we make sure that mmio is enabled first ...
255 enable_mmio();
256// show_trace(NULL,&status);
257 i=1000000;
258 while( ((status=in32(GE20)) & 0xFA800000) && i != 0)
259 i--;
260 if (i == 0) {
261 output("GE Timeout, status: %x\n",status);
262 if(status & 0x80000000)
263 output("Bresenham Engine : Busy\n");
264 if(status & 0x40000000)
265 output("Setup Engine : Busy\n");
266 if(status & 0x20000000)
267 output("SP / DPE : Busy\n");
268 if(status & 0x10000000)
269 output("Memory Interface : Busy\n");
270 if(status & 0x08000000)
271 output("Com Lst Proc : Busy\n");
272 if(status & 0x04000000)
273 output("Block Write : Busy\n");
274 if(status & 0x02000000)
275 output("Command Buffer : Full\n");
276 if(status & 0x01000000)
277 output("RESERVED : Busy\n");
278 if(status & 0x00800000)
279 output("PCI Write Buffer : Busy\n");
280 cyblafb_setup_GE(info->var.xres,
281 info->var.bits_per_pixel);
282 }
283 }
284
285 return 0;
286}
287
288//==============================
289//
290// Cyberblade specific fillrect
291//
292//==============================
293
294static void cyblafb_fillrect(struct fb_info * info,
295 const struct fb_fillrect *fr)
296{
297 int bpp = info->var.bits_per_pixel;
298 int col;
299
300 switch (bpp) {
301 default:
302 case 8: col = fr->color;
303 col |= col <<8;
304 col |= col <<16;
305 break;
306 case 16: col = ((u32 *)(info->pseudo_palette))[fr->color];
307 col |= col <<16;
308 break;
309 case 32: col = ((u32 *)(info->pseudo_palette))[fr->color];
310 break;
311 }
312
313 cyblafb_sync(info);
314
315 out32(GE60,col);
316 out32(GE48,fr->rop ? 0x66:ROP_S);
317 out32(GE44,0x20000000|1<<19|1<<4|2<<2);
318 out32(GE08,point(fr->dx,fr->dy));
319 out32(GE0C,point(fr->dx+fr->width-1,fr->dy+fr->height-1));
320
321}
322
323//==============================
324//
325// Cyberblade specific copyarea
326//
327//==============================
328
329static void cyblafb_copyarea(struct fb_info *info,
330 const struct fb_copyarea *ca)
331{
332 __u32 s1,s2,d1,d2;
333 int direction;
334
335 s1 = point(ca->sx,ca->sy);
336 s2 = point(ca->sx+ca->width-1,ca->sy+ca->height-1);
337 d1 = point(ca->dx,ca->dy);
338 d2 = point(ca->dx+ca->width-1,ca->dy+ca->height-1);
339 if ((ca->sy > ca->dy) || ((ca->sy == ca->dy) && (ca->sx > ca->dx)))
340 direction = 0;
341 else
342 direction = 2;
343
344 cyblafb_sync(info);
345
346 out32(GE44,0xa0000000|1<<19|1<<2|direction);
347 out32(GE00,direction?s2:s1);
348 out32(GE04,direction?s1:s2);
349 out32(GE08,direction?d2:d1);
350 out32(GE0C,direction?d1:d2);
351
352}
353
354//=======================================================================
355//
356// Cyberblade specific imageblit
357//
358// Accelerated for the most usual case, blitting 1-bit deep character
359// character images. Everything else is passed to the generic imageblit.
360//
361//=======================================================================
362
363static void cyblafb_imageblit(struct fb_info *info,
364 const struct fb_image *image)
365{
366
367 u32 fgcol, bgcol;
368
369 int i;
370 int bpp = info->var.bits_per_pixel;
371 int index = 0;
372 int index_end=image->height * image->width / 8;
373 int width_dds=image->width / 32;
374 int width_dbs=image->width % 32;
375
376 if (image->depth != 1 || bpp < 8 || bpp > 32 || bpp % 8 != 0 ||
377 image->width % 8 != 0 || image->width == 0 || image->height == 0) {
378 cfb_imageblit(info,image);
379 return;
380 }
381
382 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
383 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
384 fgcol = ((u32*)(info->pseudo_palette))[image->fg_color];
385 bgcol = ((u32*)(info->pseudo_palette))[image->bg_color];
386 } else {
387 fgcol = image->fg_color;
388 bgcol = image->bg_color;
389 }
390
391 switch (bpp) {
392 case 8:
393 fgcol |= fgcol <<8; fgcol |= fgcol <<16;
394 bgcol |= bgcol <<8; bgcol |= bgcol <<16;
395 break;
396 case 16:
397 fgcol |= fgcol <<16;
398 bgcol |= bgcol <<16;
399 break;
400 default:
401 break;
402 }
403
404 cyblafb_sync(info);
405
406 out32(GE60,fgcol);
407 out32(GE64,bgcol);
408 out32(GE44,0xa0000000 | 1<<20 | 1<<19);
409 out32(GE08,point(image->dx,image->dy));
410 out32(GE0C,point(image->dx+image->width-1,image->dy+image->height-1));
411
412 while(index < index_end) {
413 for(i=0;i<width_dds;i++) {
414 out32(GE9C,*((u32*) ((u32)image->data + index)));
415 index+=4;
416 }
417 switch(width_dbs) {
418 case 0: break;
419 case 8: out32(GE9C,*((u8*)((u32)image->data+index)));
420 index+=1;
421 break;
422 case 16: out32(GE9C,*((u16*)((u32)image->data+index)));
423 index+=2;
424 break;
425 case 24: out32(GE9C,(u32)(*((u16*)((u32)image->data+index))) |
426 (u32)(*((u8*)((u32)image->data+index+2)))<<16);
427 index+=3;
428 break;
429 }
430 }
431}
432
433//==========================================================
434//
435// Check if video mode is acceptable. We change var->??? if
436// video mode is slightly off or return error otherwise.
437// info->??? must not be changed!
438//
439//==========================================================
440
441static int cyblafb_check_var(struct fb_var_screeninfo *var,
442 struct fb_info *info)
443{
444 int bpp = var->bits_per_pixel;
445 int s,t,maxvyres;
446
447 //
448 // we try to support 8, 16, 24 and 32 bpp modes,
449 // default to 8
450 //
451 // there is a 24 bpp mode, but for now we change requests to 32 bpp
452 // (This is what tridentfb does ... will be changed in the future)
453 //
454 //
455 if ( bpp % 8 != 0 || bpp < 8 || bpp >32)
456 bpp = 8;
457 if (bpp == 24 )
458 bpp = var->bits_per_pixel = 32;
459
460 //
461 // interlaced modes are broken, fail if one is requested
462 //
463 if (var->vmode & FB_VMODE_INTERLACED)
464 return -EINVAL;
465
466 //
467 // fail if requested resolution is higher than physical
468 // flatpanel resolution
469 //
470 if ((displaytype == DISPLAY_FP) && nativex && var->xres > nativex)
471 return -EINVAL;
472
473 //
474 // xres != xres_virtual is broken, fail if such an
475 // unusual mode is requested
476 //
477 if (var->xres != var->xres_virtual)
478 return -EINVAL;
479
480 //
481 // we do not allow vclk to exceed 230 MHz
482 //
483 if ((bpp==32 ? 200000000 : 100000000) / var->pixclock > 23000)
484 return -EINVAL;
485
486 //
487 // calc max yres_virtual that would fit in memory
488 // and max yres_virtual that could be used for scrolling
489 // and use minimum of the results as maxvyres
490 //
491 // adjust vyres_virtual to maxvyres if necessary
492 // fail if requested yres is bigger than maxvyres
493 //
494 s = (0x1fffff / (var->xres * bpp/8)) + var->yres;
495 t = info->fix.smem_len / (var->xres * bpp/8);
496 maxvyres = t < s ? t : s;
497 if (maxvyres < var->yres_virtual)
498 var->yres_virtual=maxvyres;
499 if (maxvyres < var->yres)
500 return -EINVAL;
501
502 switch (bpp) {
503 case 8:
504 var->red.offset = 0;
505 var->green.offset = 0;
506 var->blue.offset = 0;
507 var->red.length = 6;
508 var->green.length = 6;
509 var->blue.length = 6;
510 break;
511 case 16:
512 var->red.offset = 11;
513 var->green.offset = 5;
514 var->blue.offset = 0;
515 var->red.length = 5;
516 var->green.length = 6;
517 var->blue.length = 5;
518 break;
519 case 32:
520 var->red.offset = 16;
521 var->green.offset = 8;
522 var->blue.offset = 0;
523 var->red.length = 8;
524 var->green.length = 8;
525 var->blue.length = 8;
526 break;
527 default:
528 return -EINVAL;
529 }
530
531 return 0;
532
533}
534
535//=====================================================================
536//
537// Pan the display
538//
539// The datasheets defines crt start address to be 20 bits wide and
540// to be programmed to CR0C, CR0D, CR1E and CR27. Actually there is
541// CR2B[5] as an undocumented extension bit. Epia BIOS 2.07 does use
542// it, so it is also safe to be used here. BTW: datasheet CR0E on page
543// 90 really is CR1E, the real CRE is documented on page 72.
544//
545//=====================================================================
546
547static int cyblafb_pan_display(struct fb_var_screeninfo *var,
548 struct fb_info *info)
549{
550 unsigned int offset;
551
552 offset=(var->xoffset+(var->yoffset*var->xres))*var->bits_per_pixel/32;
553 info->var.xoffset = var->xoffset;
554 info->var.yoffset = var->yoffset;
555
556 write3X4(CR0D,offset & 0xFF);
557 write3X4(CR0C,(offset & 0xFF00) >> 8);
558 write3X4(CR1E,(read3X4(CR1E) & 0xDF) | ((offset & 0x10000) >> 11));
559 write3X4(CR27,(read3X4(CR27) & 0xF8) | ((offset & 0xE0000) >> 17));
560 write3X4(CR2B,(read3X4(CR2B) & 0xDF) | ((offset & 0x100000) >> 15));
561
562 return 0;
563}
564
565//============================================
566//
567// This will really help in case of a bug ...
568// dump most gaphics core registers.
569//
570//============================================
571
572static void regdump(struct cyblafb_par *par)
573{
574 int i;
575
576 if (verbosity < 2)
577 return;
578
579 printk("\n");
580 for(i=0; i<=0xff; i++) {
581 outb(i,0x3d4);
582 printk("CR%02x=%02x ",i,inb(0x3d5));
583 if (i%16==15)
584 printk("\n");
585 }
586
587 outb(0x30,0x3ce);
588 outb(inb(0x3cf) | 0x40,0x3cf);
589 for(i=0; i<=0x1f; i++) {
590 if (i==0 || (i>2 && i<8) || i==0x10 || i==0x11 || i==0x16) {
591 outb(i,0x3d4);
592 printk("CR%02x=%02x ",i,inb(0x3d5));
593 } else
594 printk("------- ");
595 if (i%16==15)
596 printk("\n");
597 }
598 outb(0x30,0x3ce);
599 outb(inb(0x3cf) & 0xbf,0x3cf);
600
601 printk("\n");
602 for(i=0; i<=0x7f; i++) {
603 outb(i,0x3ce);
604 printk("GR%02x=%02x ",i,inb(0x3cf));
605 if (i%16==15)
606 printk("\n");
607 }
608
609 printk("\n");
610 for(i=0; i<=0xff; i++) {
611 outb(i,0x3c4);
612 printk("SR%02x=%02x ",i,inb(0x3c5));
613 if (i%16==15)
614 printk("\n");
615 }
616
617 printk("\n");
618 for(i=0; i <= 0x1F; i++) {
619 inb(0x3da); // next access is index!
620 outb(i,0x3c0);
621 printk("AR%02x=%02x ",i,inb(0x3c1));
622 if (i%16==15)
623 printk("\n");
624 }
625 printk("\n");
626
627 inb(0x3DA); // reset internal flag to 3c0 index
628 outb(0x20,0x3C0); // enable attr
629
630 return;
631}
632
633//======================================
634//
635// Set hardware to requested video mode
636//
637//======================================
638
639static int cyblafb_set_par(struct fb_info *info)
640{
641 struct cyblafb_par *par = info->par;
642 u32
643 htotal,hdispend,hsyncstart,hsyncend,hblankstart,hblankend,preendfetch,
644 vtotal,vdispend,vsyncstart,vsyncend,vblankstart,vblankend;
645 struct fb_var_screeninfo *var = &info->var;
646 int bpp = var->bits_per_pixel;
647 int i;
648
649 if (verbosity > 0)
650 output("Switching to new mode: "
651 "fbset -g %d %d %d %d %d -t %d %d %d %d %d %d %d\n",
652 var->xres,var->yres,var->xres_virtual,
653 var->yres_virtual,var->bits_per_pixel,var->pixclock,
654 var->left_margin,var->right_margin,var->upper_margin,
655 var->lower_margin,var->hsync_len,var->vsync_len);
656
657 htotal = (var->xres + var->left_margin + var->right_margin +
658 var->hsync_len) / 8 - 5;
659 hdispend = var->xres/8 - 1;
660 hsyncstart = (var->xres + var->right_margin)/8;
661 hsyncend = var->hsync_len/8;
662 hblankstart = hdispend + 1;
663 hblankend = htotal + 3; // should be htotal + 5, bios does it this way
664 preendfetch = ((var->xres >> 3) + 1) * ((bpp+1) >> 3);
665
666 vtotal = var->yres + var->upper_margin + var->lower_margin +
667 var->vsync_len - 2;
668 vdispend = var->yres - 1;
669 vsyncstart = var->yres + var->lower_margin;
670 vblankstart = var->yres;
671 vblankend = vtotal; // should be vtotal + 2, but bios does it this way
672 vsyncend = var->vsync_len;
673
674 enable_mmio(); // necessary! ... check X ...
675
676 write3X4(CR11,read3X4(CR11) & 0x7F); // unlock cr00 .. cr07
677
678 write3CE(GR30,8);
679
680 if ((displaytype == DISPLAY_FP) && var->xres < nativex) {
681
682 // stretch or center ?
683
684 out8(0x3C2,0xEB);
685
686 write3CE(GR30,read3CE(GR30) | 0x81); // shadow mode on
687
688 if (center) {
689 write3CE(GR52,(read3CE(GR52) & 0x7C) | 0x80);
690 write3CE(GR53,(read3CE(GR53) & 0x7C) | 0x80);
691 }
692 else if (stretch) {
693 write3CE(GR5D,0);
694 write3CE(GR52,(read3CE(GR52) & 0x7C) | 1);
695 write3CE(GR53,(read3CE(GR53) & 0x7C) | 1);
696 }
697
698 } else {
699 out8(0x3C2,0x2B);
700 write3CE(GR30,8);
701 }
702
703 //
704 // Setup CRxx regs
705 //
706
707 write3X4(CR00,htotal & 0xFF);
708 write3X4(CR01,hdispend & 0xFF);
709 write3X4(CR02,hblankstart & 0xFF);
710 write3X4(CR03,hblankend & 0x1F);
711 write3X4(CR04,hsyncstart & 0xFF);
712 write3X4(CR05,(hsyncend & 0x1F) | ((hblankend & 0x20)<<2));
713 write3X4(CR06,vtotal & 0xFF);
714 write3X4(CR07,(vtotal & 0x100) >> 8 |
715 (vdispend & 0x100) >> 7 |
716 (vsyncstart & 0x100) >> 6 |
717 (vblankstart & 0x100) >> 5 |
718 0x10 |
719 (vtotal & 0x200) >> 4 |
720 (vdispend & 0x200) >> 3 |
721 (vsyncstart & 0x200) >> 2);
722 write3X4(CR08,0);
723 write3X4(CR09,(vblankstart & 0x200) >> 4 | 0x40 | // FIX !!!
724 ((info->var.vmode & FB_VMODE_DOUBLE) ? 0x80 : 0));
725 write3X4(CR0A,0); // Init to some reasonable default
726 write3X4(CR0B,0); // Init to some reasonable default
727 write3X4(CR0C,0); // Offset 0
728 write3X4(CR0D,0); // Offset 0
729 write3X4(CR0E,0); // Init to some reasonable default
730 write3X4(CR0F,0); // Init to some reasonable default
731 write3X4(CR10,vsyncstart & 0xFF);
732 write3X4(CR11,(vsyncend & 0x0F));
733 write3X4(CR12,vdispend & 0xFF);
734 write3X4(CR13,((info->var.xres * bpp)/(4*16)) & 0xFF);
735 write3X4(CR14,0x40); // double word mode
736 write3X4(CR15,vblankstart & 0xFF);
737 write3X4(CR16,vblankend & 0xFF);
738 write3X4(CR17,0xC3);
739 write3X4(CR18,0xFF);
740 // CR19: needed for interlaced modes ... ignore it for now
741 write3X4(CR1A,0x07); // Arbitration Control Counter 1
742 write3X4(CR1B,0x07); // Arbitration Control Counter 2
743 write3X4(CR1C,0x07); // Arbitration Control Counter 3
744 write3X4(CR1D,0x00); // Don't know, doesn't hurt ;-)
745 write3X4(CR1E,(info->var.vmode & FB_VMODE_INTERLACED) ? 0x84 : 0x80);
746 // CR1F: do not set, contains BIOS info about memsize
747 write3X4(CR20,0x20); // enabe wr buf, disable 16bit planar mode
748 write3X4(CR21,0x20); // enable linear memory access
749 // CR22: RO cpu latch readback
750 // CR23: ???
751 // CR24: RO AR flag state
752 // CR25: RAMDAC rw timing, pclk buffer tristate control ????
753 // CR26: ???
754 write3X4(CR27,(vdispend & 0x400) >> 6 |
755 (vsyncstart & 0x400) >> 5 |
756 (vblankstart & 0x400) >> 4 |
757 (vtotal & 0x400) >> 3 |
758 0x8);
759 // CR28: ???
760 write3X4(CR29,(read3X4(CR29) & 0xCF) |
761 ((((info->var.xres * bpp) / (4*16)) & 0x300) >>4));
762 write3X4(CR2A,read3X4(CR2A) | 0x40);
763 write3X4(CR2B,(htotal & 0x100) >> 8 |
764 (hdispend & 0x100) >> 7 |
765 // (0x00 & 0x100) >> 6 | hinterlace para bit 8 ???
766 (hsyncstart & 0x100) >> 5 |
767 (hblankstart & 0x100) >> 4);
768 // CR2C: ???
769 // CR2D: initialized in cyblafb_setup_GE()
770 write3X4(CR2F,0x92); // conservative, better signal quality
771 // CR30: reserved
772 // CR31: reserved
773 // CR32: reserved
774 // CR33: reserved
775 // CR34: disabled in CR36
776 // CR35: disabled in CR36
777 // CR36: initialized in cyblafb_setup_GE
778 // CR37: i2c, ignore for now
779 write3X4(CR38,(bpp == 8) ? 0x00 : //
780 (bpp == 16) ? 0x05 : // highcolor
781 (bpp == 24) ? 0x29 : // packed 24bit truecolor
782 (bpp == 32) ? 0x09 : 0); // truecolor, 16 bit pixelbus
783 write3X4(CR39,0x01 | // MMIO enable
784 (pcirb ? 0x02 : 0) | // pci read burst enable
785 (pciwb ? 0x04 : 0)); // pci write burst enable
786 write3X4(CR55,0x1F | // pci clocks * 2 for STOP# during 1st data phase
787 (pcirr ? 0x40 : 0) | // pci read retry enable
788 (pciwr ? 0x80 : 0)); // pci write retry enable
789 write3X4(CR56,preendfetch >> 8 < 2 ? (preendfetch >> 8 & 0x01)|2 : 0);
790 write3X4(CR57,preendfetch >> 8 < 2 ? preendfetch & 0xff : 0);
791 write3X4(CR58,0x82); // Bios does this .... don't know more
792 //
793 // Setup SRxx regs
794 //
795 write3C4(SR00,3);
796 write3C4(SR01,1); //set char clock 8 dots wide
797 write3C4(SR02,0x0F); //enable 4 maps needed in chain4 mode
798 write3C4(SR03,0); //no character map select
799 write3C4(SR04,0x0E); //memory mode: ext mem, even, chain4
800
801 out8(0x3C4,0x0b);
802 in8(0x3C5); // Set NEW mode
803 write3C4(SR0D,0x00); // test ... check
804
805 set_vclk(par,(bpp==32 ? 200000000 : 100000000)/
806 info->var.pixclock); //SR18,SR19
807
808 //
809 // Setup GRxx regs
810 //
811 write3CE(GR00,0x00); // test ... check
812 write3CE(GR01,0x00); // test ... check
813 write3CE(GR02,0x00); // test ... check
814 write3CE(GR03,0x00); // test ... check
815 write3CE(GR04,0x00); // test ... check
816 write3CE(GR05,0x40); // no CGA compat,allow 256 col
817 write3CE(GR06,0x05); // graphics mode
818 write3CE(GR07,0x0F); // planes?
819 write3CE(GR08,0xFF); // test ... check
820 write3CE(GR0F,(bpp==32)?0x1A:0x12); // div vclk by 2 if 32bpp, chain4
821 write3CE(GR20,0xC0); // test ... check
822 write3CE(GR2F,0xA0); // PCLK = VCLK, no skew,
823
824 //
825 // Setup ARxx regs
826 //
827 for(i = 0;i < 0x10;i++) // set AR00 .. AR0f
828 write3C0(i,i);
829 write3C0(AR10,0x41); // graphics mode and support 256 color modes
830 write3C0(AR12,0x0F); // planes
831 write3C0(AR13,0); // horizontal pel panning
832 in8(0x3DA); // reset internal flag to 3c0 index
833 out8(0x3C0,0x20); // enable attr
834
835 //
836 // Setup hidden RAMDAC command register
837 //
838 in8(0x3C8); // these reads are
839 in8(0x3C6); // necessary to
840 in8(0x3C6); // unmask the RAMDAC
841 in8(0x3C6); // command reg, otherwise
842 in8(0x3C6); // we would write the pixelmask reg!
843 out8(0x3C6,(bpp == 8) ? 0x00 : // 256 colors
844 (bpp == 15) ? 0x10 : //
845 (bpp == 16) ? 0x30 : // hicolor
846 (bpp == 24) ? 0xD0 : // truecolor
847 (bpp == 32) ? 0xD0 : 0); // truecolor
848 in8(0x3C8);
849
850 //
851 // GR31 is not mentioned in the datasheet
852 //
853 if (displaytype == DISPLAY_FP)
854 write3CE(GR31,(read3CE(GR31) & 0x8F) |
855 ((info->var.yres > 1024) ? 0x50 :
856 (info->var.yres > 768) ? 0x30 :
857 (info->var.yres > 600) ? 0x20 :
858 (info->var.yres > 480) ? 0x10 : 0));
859
860 info->fix.visual = (bpp == 8) ? FB_VISUAL_PSEUDOCOLOR
861 : FB_VISUAL_TRUECOLOR;
862 info->fix.line_length = info->var.xres * (bpp >> 3);
863 info->cmap.len = (bpp == 8) ? 256: 16;
864
865 //
866 // init acceleration engine
867 //
868 cyblafb_setup_GE(info->var.xres,info->var.bits_per_pixel);
869
870 regdump(par);
871
872 return 0;
873}
874
875//========================
876//
877// Set one color register
878//
879//========================
880
881static int cyblafb_setcolreg(unsigned regno, unsigned red, unsigned green,
882 unsigned blue, unsigned transp,
883 struct fb_info *info)
884{
885 int bpp = info->var.bits_per_pixel;
886
887 if (regno >= info->cmap.len)
888 return 1;
889
890 if (bpp == 8) {
891 out8(0x3C6,0xFF);
892 out8(0x3C8,regno);
893 out8(0x3C9,red>>10);
894 out8(0x3C9,green>>10);
895 out8(0x3C9,blue>>10);
896
897 } else if (bpp == 16) // RGB 565
898 ((u32*)info->pseudo_palette)[regno] =
899 (red & 0xF800) |
900 ((green & 0xFC00) >> 5) |
901 ((blue & 0xF800) >> 11);
902 else if (bpp == 32) // ARGB 8888
903 ((u32*)info->pseudo_palette)[regno] =
904 ((transp & 0xFF00) <<16) |
905 ((red & 0xFF00) << 8) |
906 ((green & 0xFF00)) |
907 ((blue & 0xFF00)>>8);
908
909 return 0;
910}
911
912//==========================================================
913//
914// Try blanking the screen. For flat panels it does nothing
915//
916//==========================================================
917
918static int cyblafb_blank(int blank_mode, struct fb_info *info)
919{
920 unsigned char PMCont,DPMSCont;
921
922 if (displaytype == DISPLAY_FP)
923 return 0;
924
925 out8(0x83C8,0x04); // DPMS Control
926 PMCont = in8(0x83C6) & 0xFC;
927
928 DPMSCont = read3CE(GR23) & 0xFC;
929
930 switch (blank_mode)
931 {
932 case FB_BLANK_UNBLANK: // Screen: On, HSync: On, VSync: On
933 case FB_BLANK_NORMAL: // Screen: Off, HSync: On, VSync: On
934 PMCont |= 0x03;
935 DPMSCont |= 0x00;
936 break;
937 case FB_BLANK_HSYNC_SUSPEND: // Screen: Off, HSync: Off, VSync: On
938 PMCont |= 0x02;
939 DPMSCont |= 0x01;
940 break;
941 case FB_BLANK_VSYNC_SUSPEND: // Screen: Off, HSync: On, VSync: Off
942 PMCont |= 0x02;
943 DPMSCont |= 0x02;
944 break;
945 case FB_BLANK_POWERDOWN: // Screen: Off, HSync: Off, VSync: Off
946 PMCont |= 0x00;
947 DPMSCont |= 0x03;
948 break;
949 }
950
951 write3CE(GR23,DPMSCont);
952 out8(0x83C8,4);
953 out8(0x83C6,PMCont);
954 //
955 // let fbcon do a softblank for us
956 //
957 return (blank_mode == FB_BLANK_NORMAL) ? 1 : 0;
958}
959
960static struct fb_ops cyblafb_ops __devinitdata = {
961 .owner = THIS_MODULE,
962 .fb_setcolreg = cyblafb_setcolreg,
963 .fb_pan_display = cyblafb_pan_display,
964 .fb_blank = cyblafb_blank,
965 .fb_check_var = cyblafb_check_var,
966 .fb_set_par = cyblafb_set_par,
967 .fb_fillrect = cyblafb_fillrect,
968 .fb_copyarea= cyblafb_copyarea,
969 .fb_imageblit = cyblafb_imageblit,
970 .fb_cursor = soft_cursor,
971};
972
973//==========================================================================
974//
975// getstartupmode() decides about the inital video mode
976//
977// There is no reason to use modedb, a lot of video modes there would
978// need altered timings to display correctly. So I decided that it is much
979// better to provide a limited optimized set of modes plus the option of
980// using the mode in effect at startup time (might be selected using the
981// vga=??? paramter). After that the user might use fbset to select any
982// mode he likes, check_var will not try to alter geometry parameters as
983// it would be necessary otherwise.
984//
985//==========================================================================
986
987static int __devinit getstartupmode(struct fb_info *info)
988{
989 u32 htotal,hdispend,hsyncstart,hsyncend,hblankstart,hblankend,
990 vtotal,vdispend,vsyncstart,vsyncend,vblankstart,vblankend,
991 cr00,cr01,cr02,cr03,cr04,cr05,cr2b,
992 cr06,cr07,cr09,cr10,cr11,cr12,cr15,cr16,cr27,
993 cr38,
994 sr0d,sr18,sr19,
995 gr0f,
996 fi,pxclkdiv,vclkdiv,tmp,i;
997
998 struct modus {
999 int xres; int yres; int vyres; int bpp; int pxclk;
1000 int left_margin; int right_margin; int upper_margin;
1001 int lower_margin; int hsync_len; int vsync_len;
1002 } modedb[5] = {
1003 { 0, 0, 8000, 0, 0, 0, 0, 0, 0, 0, 0},
1004 { 640, 480, 3756, 0, 0, -40, 24, 17, 0, 216, 3},
1005 { 800, 600, 3221, 0, 0, 96, 24, 14, 0, 136, 11},
1006 {1024, 768, 2815, 0, 0, 144, 24, 29, 0, 120, 3},
1007 {1280, 1024, 2662, 0, 0, 232, 16, 39, 0, 160, 3}
1008 };
1009
1010 outb(0x00,0x3d4); cr00=inb(0x3d5); outb(0x01,0x3d4); cr01=inb(0x3d5);
1011 outb(0x02,0x3d4); cr02=inb(0x3d5); outb(0x03,0x3d4); cr03=inb(0x3d5);
1012 outb(0x04,0x3d4); cr04=inb(0x3d5); outb(0x05,0x3d4); cr05=inb(0x3d5);
1013 outb(0x06,0x3d4); cr06=inb(0x3d5); outb(0x07,0x3d4); cr07=inb(0x3d5);
1014 outb(0x09,0x3d4); cr09=inb(0x3d5); outb(0x10,0x3d4); cr10=inb(0x3d5);
1015 outb(0x11,0x3d4); cr11=inb(0x3d5); outb(0x12,0x3d4); cr12=inb(0x3d5);
1016 outb(0x15,0x3d4); cr15=inb(0x3d5); outb(0x16,0x3d4); cr16=inb(0x3d5);
1017 outb(0x27,0x3d4); cr27=inb(0x3d5); outb(0x2b,0x3d4); cr2b=inb(0x3d5);
1018 outb(0x38,0x3d4); cr38=inb(0x3d5); outb(0x0b,0x3c4); inb(0x3c5);
1019 outb(0x0d,0x3c4); sr0d=inb(0x3c5); outb(0x18,0x3c4); sr18=inb(0x3c5);
1020 outb(0x19,0x3c4); sr19=inb(0x3c5); outb(0x0f,0x3ce); gr0f=inb(0x3cf);
1021
1022 htotal = cr00 | (cr2b & 0x01) << 8;
1023 hdispend = cr01 | (cr2b & 0x02) << 7;
1024 hblankstart = cr02 | (cr2b & 0x10) << 4;
1025 hblankend = (cr03 & 0x1f) | (cr05 & 0x80) >> 2;
1026 hsyncstart = cr04 | (cr2b & 0x08) << 5;
1027 hsyncend = cr05 & 0x1f;
1028
1029 modedb[0].xres = hblankstart * 8;
1030 modedb[0].hsync_len = hsyncend * 8;
1031 modedb[0].right_margin = hsyncstart * 8 - modedb[0].xres;
1032 modedb[0].left_margin = (htotal + 5) * 8 - modedb[0].xres -
1033 modedb[0].right_margin - modedb[0].hsync_len;
1034
1035 vtotal = cr06 | (cr07 & 0x01) << 8 | (cr07 & 0x20) << 4
1036 | (cr27 & 0x80) << 3;
1037 vdispend = cr12 | (cr07 & 0x02) << 7 | (cr07 & 0x40) << 3
1038 | (cr27 & 0x10) << 6;
1039 vsyncstart = cr10 | (cr07 & 0x04) << 6 | (cr07 & 0x80) << 2
1040 | (cr27 & 0x20) << 5;
1041 vsyncend = cr11 & 0x0f;
1042 vblankstart = cr15 | (cr07 & 0x08) << 5 | (cr09 & 0x20) << 4
1043 | (cr27 & 0x40) << 4;
1044 vblankend = cr16;
1045
1046 modedb[0].yres = vdispend + 1;
1047 modedb[0].vsync_len = vsyncend;
1048 modedb[0].lower_margin = vsyncstart - modedb[0].yres;
1049 modedb[0].upper_margin = vtotal - modedb[0].yres -
1050 modedb[0].lower_margin - modedb[0].vsync_len + 2;
1051
1052 tmp = cr38 & 0x3c;
1053 modedb[0].bpp = tmp == 0 ? 8 : tmp == 4 ? 16 : tmp == 28 ? 24 :
1054 tmp == 8 ? 32 : 8;
1055
1056 fi = ((5864727*(sr18+8))/(((sr19&0x3f)+2)*(1<<((sr19&0xc0)>>6))))>>12;
1057 pxclkdiv = ((gr0f & 0x08) >> 3 | (gr0f & 0x40) >> 5) + 1;
1058 tmp = sr0d & 0x06;
1059 vclkdiv = tmp == 0 ? 2 : tmp == 2 ? 4 : tmp == 4 ? 8 : 3; // * 2 !
1060 modedb[0].pxclk = ((100000000 * pxclkdiv * vclkdiv) >> 1) / fi;
1061
1062 if (verbosity > 0)
1063 output("detected startup mode: "
1064 "fbset -g %d %d %d ??? %d -t %d %d %d %d %d %d %d\n",
1065 modedb[0].xres,modedb[0].yres,modedb[0].xres,
1066 modedb[0].bpp,modedb[0].pxclk,modedb[0].left_margin,
1067 modedb[0].right_margin,modedb[0].upper_margin,
1068 modedb[0].lower_margin,modedb[0].hsync_len,
1069 modedb[0].vsync_len);
1070
1071 //
1072 // We use this goto target in case of a failed check_var. No, I really
1073 // do not want to do it in another way!
1074 //
1075
1076 tryagain:
1077
1078 i = (mode == NULL) ? 0 :
1079 !strncmp(mode,"640x480",7) ? 1 :
1080 !strncmp(mode,"800x600",7) ? 2 :
1081 !strncmp(mode,"1024x768",8) ? 3 :
1082 !strncmp(mode,"1280x1024",9) ? 4 : 0;
1083
1084 ref = (ref < 50) ? 50 : (ref > 85) ? 85 : ref;
1085
1086 if(i==0) {
1087 info->var.pixclock = modedb[i].pxclk;
1088 info->var.bits_per_pixel = modedb[i].bpp;
1089 } else {
1090 info->var.pixclock = (100000000 /
1091 ((modedb[i].left_margin + modedb[i].xres +
1092 modedb[i].right_margin + modedb[i].hsync_len
1093 ) * (
1094 modedb[i].upper_margin + modedb[i].yres +
1095 modedb[i].lower_margin + modedb[i].vsync_len
1096 ) *
1097 ref / 10000
1098 ));
1099 info->var.bits_per_pixel = bpp;
1100 }
1101
1102 info->var.left_margin = modedb[i].left_margin;
1103 info->var.right_margin = modedb[i].right_margin;
1104 info->var.xres = modedb[i].xres;
1105 info->var.xres_virtual = modedb[i].xres;
1106 info->var.xoffset = 0;
1107 info->var.hsync_len = modedb[i].hsync_len;
1108 info->var.upper_margin = modedb[i].upper_margin;
1109 info->var.yres = modedb[i].yres;
1110 info->var.yres_virtual = modedb[i].vyres;
1111 info->var.yoffset = 0;
1112 info->var.lower_margin = modedb[i].lower_margin;
1113 info->var.vsync_len = modedb[i].vsync_len;
1114 info->var.sync = 0;
1115 info->var.vmode = FB_VMODE_NONINTERLACED;
1116
1117 if(cyblafb_check_var(&info->var,info)) {
1118 // 640x480-8@75 should really never fail. One case would
1119 // be fp == 1 and nativex < 640 ... give up then
1120 if(i==1 && bpp == 8 && ref == 75){
1121 output("Can't find a valid mode :-(\n");
1122 return -EINVAL;
1123 }
1124 // Our detected mode is unlikely to fail. If it does,
1125 // try 640x480-8@75 ...
1126 if(i==0) {
1127 mode="640x480";
1128 bpp=8;
1129 ref=75;
1130 output("Detected mode failed check_var! "
1131 "Trying 640x480-8@75\n");
1132 goto tryagain;
1133 }
1134 // A specified video mode failed for some reason.
1135 // Try the startup mode first
1136 output("Specified mode '%s' failed check! "
1137 "Falling back to startup mode.\n",mode);
1138 mode=NULL;
1139 goto tryagain;
1140 }
1141
1142 return 0;
1143
1144}
1145
1146//========================================================
1147//
1148// Detect activated memory size. Undefined values require
1149// memsize parameter.
1150//
1151//========================================================
1152
1153static unsigned int __devinit get_memsize(void)
1154{
1155 unsigned char tmp;
1156 unsigned int k;
1157
1158 if (memsize)
1159 k = memsize * Kb;
1160 else {
1161 tmp = read3X4(CR1F) & 0x0F;
1162 switch (tmp) {
1163 case 0x03: k = 1 * Mb; break;
1164 case 0x07: k = 2 * Mb; break;
1165 case 0x0F: k = 4 * Mb; break;
1166 case 0x04: k = 8 * Mb; break;
1167 default:
1168 k = 1 * Mb;
1169 output("Unknown memory size code %x in CR1F."
1170 " We default to 1 Mb for now, please"
1171 " do provide a memsize parameter!\n",
1172 tmp);
1173 }
1174 }
1175
1176 if (verbosity > 0)
1177 output("framebuffer size = %d Kb\n",k/Kb);
1178 return k;
1179}
1180
1181//=========================================================
1182//
1183// Detect if a flat panel monitor connected to the special
1184// interface is active. Override is possible by fp and crt
1185// parameters.
1186//
1187//=========================================================
1188
1189static unsigned int __devinit get_displaytype(void)
1190{
1191 if (fp)
1192 return DISPLAY_FP;
1193 if (crt)
1194 return DISPLAY_CRT;
1195 return (read3CE(GR33) & 0x10)?DISPLAY_FP:DISPLAY_CRT;
1196}
1197
1198//=====================================
1199//
1200// Get native resolution of flat panel
1201//
1202//=====================================
1203
1204static int __devinit get_nativex(void)
1205{
1206 int x,y,tmp;
1207
1208 if (nativex)
1209 return nativex;
1210
1211 tmp = (read3CE(GR52) >> 4) & 3;
1212
1213 switch (tmp) {
1214 case 0: x = 1280; y = 1024; break;
1215 case 2: x = 1024; y = 768; break;
1216 case 3: x = 800; y = 600; break;
1217 case 4: x = 1400; y = 1050; break;
1218 case 1:
1219 default: x = 640; y = 480; break;
1220 }
1221
1222 if (verbosity > 0)
1223 output("%dx%d flat panel found\n",x,y);
1224 return x;
1225}
1226
1227static int __devinit cybla_pci_probe(struct pci_dev * dev,
1228 const struct pci_device_id * id)
1229{
1230 struct fb_info *info;
1231 struct cyblafb_par *par;
1232
1233 info = framebuffer_alloc(sizeof(struct cyblafb_par),&dev->dev);
1234
1235 if (!info)
1236 goto errout_alloc;
1237
1238 par = info->par;
1239 par->ops = cyblafb_ops;
1240
1241 info->fix = cyblafb_fix;
1242 info->fbops = &par->ops;
1243 info->fix = cyblafb_fix;
1244
1245 if (pci_enable_device(dev)) {
1246 output("could not enable device!\n");
1247 goto errout_enable;
1248 }
1249
1250 // might already be requested by vga console or vesafb,
1251 // so we do care about success
1252 request_region(0x3c0,32,"cyblafb");
1253
1254 //
1255 // Graphics Engine Registers
1256 //
1257 request_region(GEBase,0x100,"cyblafb");
1258
1259 regdump(par);
1260
1261 enable_mmio();
1262
1263 // setup MMIO region
1264 info->fix.mmio_start = pci_resource_start(dev,1);
1265 info->fix.mmio_len = 0x20000;
1266
1267 if (!request_mem_region(info->fix.mmio_start,
1268 info->fix.mmio_len,"cyblafb")) {
1269 output("request_mem_region failed for mmio region!\n");
1270 goto errout_mmio_reqmem;
1271 }
1272
1273 io_virt = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
1274
1275 if (!io_virt) {
1276 output("ioremap failed for mmio region\n");
1277 goto errout_mmio_remap;
1278 }
1279
1280 // setup framebuffer memory ... might already be requested
1281 // by vesafb. Not to fail in case of an unsuccessful request
1282 // is useful for the development cycle
1283 info->fix.smem_start = pci_resource_start(dev,0);
1284 info->fix.smem_len = get_memsize();
1285
1286 if (!request_mem_region(info->fix.smem_start,
1287 info->fix.smem_len,"cyblafb")) {
1288 output("request_mem_region failed for smem region!\n");
1289 if (!vesafb)
1290 goto errout_smem_req;
1291 }
1292
1293 info->screen_base = ioremap_nocache(info->fix.smem_start,
1294 info->fix.smem_len);
1295
1296 if (!info->screen_base) {
1297 output("ioremap failed for smem region\n");
1298 goto errout_smem_remap;
1299 }
1300
1301 displaytype = get_displaytype();
1302
1303 if(displaytype == DISPLAY_FP)
1304 nativex = get_nativex();
1305
1306 //
1307 // FBINFO_HWACCEL_YWRAP .... does not work (could be made to work?)
1308 // FBINFO_PARTIAL_PAN_OK .... is not ok
1309 // FBINFO_READS_FAST .... is necessary for optimal scrolling
1310 //
1311 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN
1312 | FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT
1313 | FBINFO_HWACCEL_IMAGEBLIT | FBINFO_READS_FAST;
1314
1315 info->pseudo_palette = par->pseudo_pal;
1316
1317 if(getstartupmode(info))
1318 goto errout_findmode;
1319
1320 fb_alloc_cmap(&info->cmap,256,0);
1321
1322 if (register_framebuffer(info)) {
1323 output("Could not register CyBla framebuffer\n");
1324 goto errout_register;
1325 }
1326
1327 pci_set_drvdata(dev,info);
1328
1329 //
1330 // normal exit and error paths
1331 //
1332
1333 return 0;
1334
1335 errout_register:
1336 errout_findmode:
1337 iounmap(info->screen_base);
1338 errout_smem_remap:
1339 release_mem_region(info->fix.smem_start,
1340 info->fix.smem_len);
1341 errout_smem_req:
1342 iounmap(io_virt);
1343 errout_mmio_remap:
1344 release_mem_region(info->fix.mmio_start,
1345 info->fix.mmio_len);
1346 errout_mmio_reqmem:
1347// release_region(0x3c0,32);
1348 errout_enable:
1349 framebuffer_release(info);
1350 errout_alloc:
1351 output("CyblaFB version %s aborting init.\n",VERSION);
1352 return -ENODEV;
1353}
1354
1355static void __devexit cybla_pci_remove(struct pci_dev *dev)
1356{
1357 struct fb_info *info = pci_get_drvdata(dev);
1358
1359 unregister_framebuffer(info);
1360 iounmap(io_virt);
1361 iounmap(info->screen_base);
1362 release_mem_region(info->fix.smem_start,info->fix.smem_len);
1363 release_mem_region(info->fix.mmio_start,info->fix.mmio_len);
1364 fb_dealloc_cmap(&info->cmap);
1365 framebuffer_release(info);
1366 output("CyblaFB version %s normal exit.\n",VERSION);
1367}
1368
1369//
1370// List of boards that we are trying to support
1371//
1372static struct pci_device_id cybla_devices[] = {
1373 {PCI_VENDOR_ID_TRIDENT,CYBERBLADEi1,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
1374 {0,}
1375};
1376
1377MODULE_DEVICE_TABLE(pci,cybla_devices);
1378
1379static struct pci_driver cyblafb_pci_driver = {
1380 .name = "cyblafb",
1381 .id_table = cybla_devices,
1382 .probe = cybla_pci_probe,
1383 .remove = __devexit_p(cybla_pci_remove)
1384};
1385
1386//=============================================================
1387//
1388// kernel command line example:
1389//
1390// video=cyblafb:1280x1024,bpp=16,ref=50 ...
1391//
1392// modprobe command line example:
1393//
1394// modprobe cyblafb mode=1280x1024 bpp=16 ref=50 ...
1395//
1396//=============================================================
1397
1398static int __devinit cyblafb_init(void)
1399{
1400#ifndef MODULE
1401 char *options = NULL;
1402 char *opt;
1403
1404 if (fb_get_options("cyblafb",&options))
1405 return -ENODEV;
1406
1407 if (options && *options)
1408 while((opt = strsep(&options,",")) != NULL ) {
1409 if (!*opt) continue;
1410 else if (!strncmp(opt,"bpp=",4))
1411 bpp = simple_strtoul(opt+4,NULL,0);
1412 else if (!strncmp(opt,"ref=",4))
1413 ref = simple_strtoul(opt+4,NULL,0);
1414 else if (!strncmp(opt,"fp",2))
1415 displaytype = DISPLAY_FP;
1416 else if (!strncmp(opt,"crt",3))
1417 displaytype = DISPLAY_CRT;
1418 else if (!strncmp(opt,"nativex=",8))
1419 nativex = simple_strtoul(opt+8,NULL,0);
1420 else if (!strncmp(opt,"center",6))
1421 center = 1;
1422 else if (!strncmp(opt,"stretch",7))
1423 stretch = 1;
1424 else if (!strncmp(opt,"pciwb=",6))
1425 pciwb = simple_strtoul(opt+6,NULL,0);
1426 else if (!strncmp(opt,"pcirb=",6))
1427 pcirb = simple_strtoul(opt+6,NULL,0);
1428 else if (!strncmp(opt,"pciwr=",6))
1429 pciwr = simple_strtoul(opt+6,NULL,0);
1430 else if (!strncmp(opt,"pcirr=",6))
1431 pcirr = simple_strtoul(opt+6,NULL,0);
1432 else if (!strncmp(opt,"memsize=",8))
1433 memsize = simple_strtoul(opt+8,NULL,0);
1434 else if (!strncmp(opt,"verbosity=",10))
1435 verbosity = simple_strtoul(opt+10,NULL,0);
1436 else if (!strncmp(opt,"vesafb",6))
1437 vesafb = 1;
1438 else
1439 mode = opt;
1440 }
1441#endif
1442 output("CyblaFB version %s initializing\n",VERSION);
1443 return pci_module_init(&cyblafb_pci_driver);
1444}
1445
1446static void __exit cyblafb_exit(void)
1447{
1448 pci_unregister_driver(&cyblafb_pci_driver);
1449}
1450
1451module_init(cyblafb_init);
1452module_exit(cyblafb_exit);
1453
1454MODULE_AUTHOR("Knut Petersen <knut_petersen@t-online.de>");
1455MODULE_DESCRIPTION("Framebuffer driver for Cyberblade/i1 graphics core");
1456MODULE_LICENSE("GPL");
diff --git a/drivers/video/fbcvt.c b/drivers/video/fbcvt.c
new file mode 100644
index 0000000000..cfa61b512d
--- /dev/null
+++ b/drivers/video/fbcvt.c
@@ -0,0 +1,380 @@
1/*
2 * linux/drivers/video/fbcvt.c - VESA(TM) Coordinated Video Timings
3 *
4 * Copyright (C) 2005 Antonino Daplas <adaplas@pol.net>
5 *
6 * Based from the VESA(TM) Coordinated Video Timing Generator by
7 * Graham Loveridge April 9, 2003 available at
8 * http://www.vesa.org/public/CVT/CVTd6r1.xls
9 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file COPYING in the main directory of this archive
12 * for more details.
13 *
14 */
15#include <linux/fb.h>
16
17#define FB_CVT_CELLSIZE 8
18#define FB_CVT_GTF_C 40
19#define FB_CVT_GTF_J 20
20#define FB_CVT_GTF_K 128
21#define FB_CVT_GTF_M 600
22#define FB_CVT_MIN_VSYNC_BP 550
23#define FB_CVT_MIN_VPORCH 3
24#define FB_CVT_MIN_BPORCH 6
25
26#define FB_CVT_RB_MIN_VBLANK 460
27#define FB_CVT_RB_HBLANK 160
28#define FB_CVT_RB_V_FPORCH 3
29
30#define FB_CVT_FLAG_REDUCED_BLANK 1
31#define FB_CVT_FLAG_MARGINS 2
32#define FB_CVT_FLAG_INTERLACED 4
33
34struct fb_cvt_data {
35 u32 xres;
36 u32 yres;
37 u32 refresh;
38 u32 f_refresh;
39 u32 pixclock;
40 u32 hperiod;
41 u32 hblank;
42 u32 hfreq;
43 u32 htotal;
44 u32 vtotal;
45 u32 vsync;
46 u32 hsync;
47 u32 h_front_porch;
48 u32 h_back_porch;
49 u32 v_front_porch;
50 u32 v_back_porch;
51 u32 h_margin;
52 u32 v_margin;
53 u32 interlace;
54 u32 aspect_ratio;
55 u32 active_pixels;
56 u32 flags;
57 u32 status;
58};
59
60static int fb_cvt_vbi_tab[] = {
61 4, /* 4:3 */
62 5, /* 16:9 */
63 6, /* 16:10 */
64 7, /* 5:4 */
65 7, /* 15:9 */
66 8, /* reserved */
67 9, /* reserved */
68 10 /* custom */
69};
70
71/* returns hperiod * 1000 */
72static u32 fb_cvt_hperiod(struct fb_cvt_data *cvt)
73{
74 u32 num = 1000000000/cvt->f_refresh;
75 u32 den;
76
77 if (cvt->flags & FB_CVT_FLAG_REDUCED_BLANK) {
78 num -= FB_CVT_RB_MIN_VBLANK * 1000;
79 den = 2 * (cvt->yres/cvt->interlace + 2 * cvt->v_margin);
80 } else {
81 num -= FB_CVT_MIN_VSYNC_BP * 1000;
82 den = 2 * (cvt->yres/cvt->interlace + cvt->v_margin * 2
83 + FB_CVT_MIN_VPORCH + cvt->interlace/2);
84 }
85
86 return 2 * (num/den);
87}
88
89/* returns ideal duty cycle * 1000 */
90static u32 fb_cvt_ideal_duty_cycle(struct fb_cvt_data *cvt)
91{
92 u32 c_prime = (FB_CVT_GTF_C - FB_CVT_GTF_J) *
93 (FB_CVT_GTF_K) + 256 * FB_CVT_GTF_J;
94 u32 m_prime = (FB_CVT_GTF_K * FB_CVT_GTF_M);
95 u32 h_period_est = cvt->hperiod;
96
97 return (1000 * c_prime - ((m_prime * h_period_est)/1000))/256;
98}
99
100static u32 fb_cvt_hblank(struct fb_cvt_data *cvt)
101{
102 u32 hblank = 0;
103
104 if (cvt->flags & FB_CVT_FLAG_REDUCED_BLANK)
105 hblank = FB_CVT_RB_HBLANK;
106 else {
107 u32 ideal_duty_cycle = fb_cvt_ideal_duty_cycle(cvt);
108 u32 active_pixels = cvt->active_pixels;
109
110 if (ideal_duty_cycle < 20000)
111 hblank = (active_pixels * 20000)/
112 (100000 - 20000);
113 else {
114 hblank = (active_pixels * ideal_duty_cycle)/
115 (100000 - ideal_duty_cycle);
116 }
117 }
118
119 hblank &= ~((2 * FB_CVT_CELLSIZE) - 1);
120
121 return hblank;
122}
123
124static u32 fb_cvt_hsync(struct fb_cvt_data *cvt)
125{
126 u32 hsync;
127
128 if (cvt->flags & FB_CVT_FLAG_REDUCED_BLANK)
129 hsync = 32;
130 else
131 hsync = (FB_CVT_CELLSIZE * cvt->htotal)/100;
132
133 hsync &= ~(FB_CVT_CELLSIZE - 1);
134 return hsync;
135}
136
137static u32 fb_cvt_vbi_lines(struct fb_cvt_data *cvt)
138{
139 u32 vbi_lines, min_vbi_lines, act_vbi_lines;
140
141 if (cvt->flags & FB_CVT_FLAG_REDUCED_BLANK) {
142 vbi_lines = (1000 * FB_CVT_RB_MIN_VBLANK)/cvt->hperiod + 1;
143 min_vbi_lines = FB_CVT_RB_V_FPORCH + cvt->vsync +
144 FB_CVT_MIN_BPORCH;
145
146 } else {
147 vbi_lines = (FB_CVT_MIN_VSYNC_BP * 1000)/cvt->hperiod + 1 +
148 FB_CVT_MIN_VPORCH;
149 min_vbi_lines = cvt->vsync + FB_CVT_MIN_BPORCH +
150 FB_CVT_MIN_VPORCH;
151 }
152
153 if (vbi_lines < min_vbi_lines)
154 act_vbi_lines = min_vbi_lines;
155 else
156 act_vbi_lines = vbi_lines;
157
158 return act_vbi_lines;
159}
160
161static u32 fb_cvt_vtotal(struct fb_cvt_data *cvt)
162{
163 u32 vtotal = cvt->yres/cvt->interlace;
164
165 vtotal += 2 * cvt->v_margin + cvt->interlace/2 + fb_cvt_vbi_lines(cvt);
166 vtotal |= cvt->interlace/2;
167
168 return vtotal;
169}
170
171static u32 fb_cvt_pixclock(struct fb_cvt_data *cvt)
172{
173 u32 pixclock;
174
175 if (cvt->flags & FB_CVT_FLAG_REDUCED_BLANK)
176 pixclock = (cvt->f_refresh * cvt->vtotal * cvt->htotal)/1000;
177 else
178 pixclock = (cvt->htotal * 1000000)/cvt->hperiod;
179
180 pixclock /= 250;
181 pixclock *= 250;
182 pixclock *= 1000;
183
184 return pixclock;
185}
186
187static u32 fb_cvt_aspect_ratio(struct fb_cvt_data *cvt)
188{
189 u32 xres = cvt->xres;
190 u32 yres = cvt->yres;
191 u32 aspect = -1;
192
193 if (xres == (yres * 4)/3 && !((yres * 4) % 3))
194 aspect = 0;
195 else if (xres == (yres * 16)/9 && !((yres * 16) % 9))
196 aspect = 1;
197 else if (xres == (yres * 16)/10 && !((yres * 16) % 10))
198 aspect = 2;
199 else if (xres == (yres * 5)/4 && !((yres * 5) % 4))
200 aspect = 3;
201 else if (xres == (yres * 15)/9 && !((yres * 15) % 9))
202 aspect = 4;
203 else {
204 printk(KERN_INFO "fbcvt: Aspect ratio not CVT "
205 "standard\n");
206 aspect = 7;
207 cvt->status = 1;
208 }
209
210 return aspect;
211}
212
213static void fb_cvt_print_name(struct fb_cvt_data *cvt)
214{
215 u32 pixcount, pixcount_mod;
216 int cnt = 255, offset = 0, read = 0;
217 u8 *buf = kmalloc(256, GFP_KERNEL);
218
219 if (!buf)
220 return;
221
222 memset(buf, 0, 256);
223 pixcount = (cvt->xres * (cvt->yres/cvt->interlace))/1000000;
224 pixcount_mod = (cvt->xres * (cvt->yres/cvt->interlace)) % 1000000;
225 pixcount_mod /= 1000;
226
227 read = snprintf(buf+offset, cnt, "fbcvt: %dx%d@%d: CVT Name - ",
228 cvt->xres, cvt->yres, cvt->refresh);
229 offset += read;
230 cnt -= read;
231
232 if (cvt->status)
233 snprintf(buf+offset, cnt, "Not a CVT standard - %d.%03d Mega "
234 "Pixel Image\n", pixcount, pixcount_mod);
235 else {
236 if (pixcount) {
237 read = snprintf(buf+offset, cnt, "%d", pixcount);
238 cnt -= read;
239 offset += read;
240 }
241
242 read = snprintf(buf+offset, cnt, ".%03dM", pixcount_mod);
243 cnt -= read;
244 offset += read;
245
246 if (cvt->aspect_ratio == 0)
247 read = snprintf(buf+offset, cnt, "3");
248 else if (cvt->aspect_ratio == 3)
249 read = snprintf(buf+offset, cnt, "4");
250 else if (cvt->aspect_ratio == 1 || cvt->aspect_ratio == 4)
251 read = snprintf(buf+offset, cnt, "9");
252 else if (cvt->aspect_ratio == 2)
253 read = snprintf(buf+offset, cnt, "A");
254 else
255 read = 0;
256 cnt -= read;
257 offset += read;
258
259 if (cvt->flags & FB_CVT_FLAG_REDUCED_BLANK) {
260 read = snprintf(buf+offset, cnt, "-R");
261 cnt -= read;
262 offset += read;
263 }
264 }
265
266 printk(KERN_INFO "%s\n", buf);
267 kfree(buf);
268}
269
270static void fb_cvt_convert_to_mode(struct fb_cvt_data *cvt,
271 struct fb_videomode *mode)
272{
273 mode->refresh = cvt->f_refresh;
274 mode->pixclock = KHZ2PICOS(cvt->pixclock/1000);
275 mode->left_margin = cvt->h_front_porch;
276 mode->right_margin = cvt->h_back_porch;
277 mode->hsync_len = cvt->hsync;
278 mode->upper_margin = cvt->v_front_porch;
279 mode->lower_margin = cvt->v_back_porch;
280 mode->vsync_len = cvt->vsync;
281
282 mode->sync &= ~(FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT);
283
284 if (cvt->flags & FB_CVT_FLAG_REDUCED_BLANK)
285 mode->sync |= FB_SYNC_HOR_HIGH_ACT;
286 else
287 mode->sync |= FB_SYNC_VERT_HIGH_ACT;
288}
289
290/*
291 * fb_find_mode_cvt - calculate mode using VESA(TM) CVT
292 * @mode: pointer to fb_videomode; xres, yres, refresh and vmode must be
293 * pre-filled with the desired values
294 * @margins: add margin to calculation (1.8% of xres and yres)
295 * @rb: compute with reduced blanking (for flatpanels)
296 *
297 * RETURNS:
298 * 0 for success
299 * @mode is filled with computed values. If interlaced, the refresh field
300 * will be filled with the field rate (2x the frame rate)
301 *
302 * DESCRIPTION:
303 * Computes video timings using VESA(TM) Coordinated Video Timings
304 */
305int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb)
306{
307 struct fb_cvt_data cvt;
308
309 memset(&cvt, 0, sizeof(cvt));
310
311 if (margins)
312 cvt.flags |= FB_CVT_FLAG_MARGINS;
313
314 if (rb)
315 cvt.flags |= FB_CVT_FLAG_REDUCED_BLANK;
316
317 if (mode->vmode & FB_VMODE_INTERLACED)
318 cvt.flags |= FB_CVT_FLAG_INTERLACED;
319
320 cvt.xres = mode->xres;
321 cvt.yres = mode->yres;
322 cvt.refresh = mode->refresh;
323 cvt.f_refresh = cvt.refresh;
324 cvt.interlace = 1;
325
326 if (!cvt.xres || !cvt.yres || !cvt.refresh) {
327 printk(KERN_INFO "fbcvt: Invalid input parameters\n");
328 return 1;
329 }
330
331 if (!(cvt.refresh == 50 || cvt.refresh == 60 || cvt.refresh == 70 ||
332 cvt.refresh == 85)) {
333 printk(KERN_INFO "fbcvt: Refresh rate not CVT "
334 "standard\n");
335 cvt.status = 1;
336 }
337
338 cvt.xres &= ~(FB_CVT_CELLSIZE - 1);
339
340 if (cvt.flags & FB_CVT_FLAG_INTERLACED) {
341 cvt.interlace = 2;
342 cvt.f_refresh *= 2;
343 }
344
345 if (cvt.flags & FB_CVT_FLAG_REDUCED_BLANK) {
346 if (cvt.refresh != 60) {
347 printk(KERN_INFO "fbcvt: 60Hz refresh rate "
348 "advised for reduced blanking\n");
349 cvt.status = 1;
350 }
351 }
352
353 if (cvt.flags & FB_CVT_FLAG_MARGINS) {
354 cvt.h_margin = (cvt.xres * 18)/1000;
355 cvt.h_margin &= ~(FB_CVT_CELLSIZE - 1);
356 cvt.v_margin = ((cvt.yres/cvt.interlace)* 18)/1000;
357 }
358
359 cvt.aspect_ratio = fb_cvt_aspect_ratio(&cvt);
360 cvt.active_pixels = cvt.xres + 2 * cvt.h_margin;
361 cvt.hperiod = fb_cvt_hperiod(&cvt);
362 cvt.vsync = fb_cvt_vbi_tab[cvt.aspect_ratio];
363 cvt.vtotal = fb_cvt_vtotal(&cvt);
364 cvt.hblank = fb_cvt_hblank(&cvt);
365 cvt.htotal = cvt.active_pixels + cvt.hblank;
366 cvt.hsync = fb_cvt_hsync(&cvt);
367 cvt.pixclock = fb_cvt_pixclock(&cvt);
368 cvt.hfreq = cvt.pixclock/cvt.htotal;
369 cvt.h_back_porch = cvt.hblank/2 + cvt.h_margin;
370 cvt.h_front_porch = cvt.hblank - cvt.hsync - cvt.h_back_porch +
371 2 * cvt.h_margin;
372 cvt.v_back_porch = 3 + cvt.v_margin;
373 cvt.v_front_porch = cvt.vtotal - cvt.yres/cvt.interlace -
374 cvt.v_back_porch - cvt.vsync;
375 fb_cvt_print_name(&cvt);
376 fb_cvt_convert_to_mode(&cvt, mode);
377
378 return 0;
379}
380EXPORT_SYMBOL(fb_find_mode_cvt);
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index 4ff853fbe0..70be7009f8 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -62,16 +62,26 @@ int num_registered_fb;
62 * Helpers 62 * Helpers
63 */ 63 */
64 64
65int fb_get_color_depth(struct fb_var_screeninfo *var) 65int fb_get_color_depth(struct fb_var_screeninfo *var,
66 struct fb_fix_screeninfo *fix)
66{ 67{
67 if (var->green.length == var->blue.length && 68 int depth = 0;
68 var->green.length == var->red.length && 69
69 !var->green.offset && !var->blue.offset && 70 if (fix->visual == FB_VISUAL_MONO01 ||
70 !var->red.offset) 71 fix->visual == FB_VISUAL_MONO10)
71 return var->green.length; 72 depth = 1;
72 else 73 else {
73 return (var->green.length + var->red.length + 74 if (var->green.length == var->blue.length &&
74 var->blue.length); 75 var->green.length == var->red.length &&
76 var->green.offset == var->blue.offset &&
77 var->green.offset == var->red.offset)
78 depth = var->green.length;
79 else
80 depth = var->green.length + var->red.length +
81 var->blue.length;
82 }
83
84 return depth;
75} 85}
76EXPORT_SYMBOL(fb_get_color_depth); 86EXPORT_SYMBOL(fb_get_color_depth);
77 87
@@ -80,15 +90,7 @@ EXPORT_SYMBOL(fb_get_color_depth);
80 */ 90 */
81void fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, u32 height) 91void fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, u32 height)
82{ 92{
83 int i, j; 93 __fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, height);
84
85 for (i = height; i--; ) {
86 /* s_pitch is a few bytes at the most, memcpy is suboptimal */
87 for (j = 0; j < s_pitch; j++)
88 dst[j] = src[j];
89 src += s_pitch;
90 dst += d_pitch;
91 }
92} 94}
93EXPORT_SYMBOL(fb_pad_aligned_buffer); 95EXPORT_SYMBOL(fb_pad_aligned_buffer);
94 96
@@ -249,13 +251,18 @@ static void fb_set_logo(struct fb_info *info,
249 const struct linux_logo *logo, u8 *dst, 251 const struct linux_logo *logo, u8 *dst,
250 int depth) 252 int depth)
251{ 253{
252 int i, j, k, fg = 1; 254 int i, j, k;
253 const u8 *src = logo->data; 255 const u8 *src = logo->data;
254 u8 d, xor = (info->fix.visual == FB_VISUAL_MONO01) ? 0xff : 0; 256 u8 xor = (info->fix.visual == FB_VISUAL_MONO01) ? 0xff : 0;
257 u8 fg = 1, d;
255 258
256 if (fb_get_color_depth(&info->var) == 3) 259 if (fb_get_color_depth(&info->var, &info->fix) == 3)
257 fg = 7; 260 fg = 7;
258 261
262 if (info->fix.visual == FB_VISUAL_MONO01 ||
263 info->fix.visual == FB_VISUAL_MONO10)
264 fg = ~((u8) (0xfff << info->var.green.length));
265
259 switch (depth) { 266 switch (depth) {
260 case 4: 267 case 4:
261 for (i = 0; i < logo->height; i++) 268 for (i = 0; i < logo->height; i++)
@@ -318,7 +325,7 @@ static struct logo_data {
318 325
319int fb_prepare_logo(struct fb_info *info) 326int fb_prepare_logo(struct fb_info *info)
320{ 327{
321 int depth = fb_get_color_depth(&info->var); 328 int depth = fb_get_color_depth(&info->var, &info->fix);
322 329
323 memset(&fb_logo, 0, sizeof(struct logo_data)); 330 memset(&fb_logo, 0, sizeof(struct logo_data));
324 331
@@ -684,11 +691,13 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
684 691
685 if (!err && (flags & FBINFO_MISC_USEREVENT)) { 692 if (!err && (flags & FBINFO_MISC_USEREVENT)) {
686 struct fb_event event; 693 struct fb_event event;
694 int evnt = (var->activate & FB_ACTIVATE_ALL) ?
695 FB_EVENT_MODE_CHANGE_ALL :
696 FB_EVENT_MODE_CHANGE;
687 697
688 info->flags &= ~FBINFO_MISC_USEREVENT; 698 info->flags &= ~FBINFO_MISC_USEREVENT;
689 event.info = info; 699 event.info = info;
690 notifier_call_chain(&fb_notifier_list, 700 notifier_call_chain(&fb_notifier_list, evnt,
691 FB_EVENT_MODE_CHANGE,
692 &event); 701 &event);
693 } 702 }
694 } 703 }
@@ -1012,6 +1021,7 @@ register_framebuffer(struct fb_info *fb_info)
1012{ 1021{
1013 int i; 1022 int i;
1014 struct fb_event event; 1023 struct fb_event event;
1024 struct fb_videomode mode;
1015 1025
1016 if (num_registered_fb == FB_MAX) 1026 if (num_registered_fb == FB_MAX)
1017 return -ENXIO; 1027 return -ENXIO;
@@ -1042,16 +1052,11 @@ register_framebuffer(struct fb_info *fb_info)
1042 } 1052 }
1043 fb_info->pixmap.offset = 0; 1053 fb_info->pixmap.offset = 0;
1044 1054
1045 if (!fb_info->modelist.prev || 1055 if (!fb_info->modelist.prev || !fb_info->modelist.next)
1046 !fb_info->modelist.next ||
1047 list_empty(&fb_info->modelist)) {
1048 struct fb_videomode mode;
1049
1050 INIT_LIST_HEAD(&fb_info->modelist); 1056 INIT_LIST_HEAD(&fb_info->modelist);
1051 fb_var_to_videomode(&mode, &fb_info->var);
1052 fb_add_videomode(&mode, &fb_info->modelist);
1053 }
1054 1057
1058 fb_var_to_videomode(&mode, &fb_info->var);
1059 fb_add_videomode(&mode, &fb_info->modelist);
1055 registered_fb[i] = fb_info; 1060 registered_fb[i] = fb_info;
1056 1061
1057 devfs_mk_cdev(MKDEV(FB_MAJOR, i), 1062 devfs_mk_cdev(MKDEV(FB_MAJOR, i),
diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index c2718bb949..713226cdf3 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -29,6 +29,7 @@
29#include <linux/tty.h> 29#include <linux/tty.h>
30#include <linux/fb.h> 30#include <linux/fb.h>
31#include <linux/module.h> 31#include <linux/module.h>
32#include <video/edid.h>
32#ifdef CONFIG_PPC_OF 33#ifdef CONFIG_PPC_OF
33#include <linux/pci.h> 34#include <linux/pci.h>
34#include <asm/prom.h> 35#include <asm/prom.h>
@@ -313,11 +314,13 @@ static int edid_is_monitor_block(unsigned char *block)
313 return 0; 314 return 0;
314} 315}
315 316
316static void calc_mode_timings(int xres, int yres, int refresh, struct fb_videomode *mode) 317static void calc_mode_timings(int xres, int yres, int refresh,
318 struct fb_videomode *mode)
317{ 319{
318 struct fb_var_screeninfo var; 320 struct fb_var_screeninfo var;
319 struct fb_info info; 321 struct fb_info info;
320 322
323 memset(&var, 0, sizeof(struct fb_var_screeninfo));
321 var.xres = xres; 324 var.xres = xres;
322 var.yres = yres; 325 var.yres = yres;
323 fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 326 fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON,
@@ -1251,9 +1254,41 @@ int fb_validate_mode(const struct fb_var_screeninfo *var, struct fb_info *info)
1251 -EINVAL : 0; 1254 -EINVAL : 0;
1252} 1255}
1253 1256
1257#if defined(__i386__)
1258#include <linux/pci.h>
1259
1260/*
1261 * We need to ensure that the EDID block is only returned for
1262 * the primary graphics adapter.
1263 */
1264
1265const unsigned char *fb_firmware_edid(struct device *device)
1266{
1267 struct pci_dev *dev = NULL;
1268 struct resource *res = NULL;
1269 unsigned char *edid = NULL;
1270
1271 if (device)
1272 dev = to_pci_dev(device);
1273
1274 if (dev)
1275 res = &dev->resource[PCI_ROM_RESOURCE];
1276
1277 if (res && res->flags & IORESOURCE_ROM_SHADOW)
1278 edid = edid_info.dummy;
1279
1280 return edid;
1281}
1282#else
1283const unsigned char *fb_firmware_edid(struct device *device)
1284{
1285 return NULL;
1286}
1287#endif /* _i386_ */
1288
1254EXPORT_SYMBOL(fb_parse_edid); 1289EXPORT_SYMBOL(fb_parse_edid);
1255EXPORT_SYMBOL(fb_edid_to_monspecs); 1290EXPORT_SYMBOL(fb_edid_to_monspecs);
1256 1291EXPORT_SYMBOL(fb_firmware_edid);
1257EXPORT_SYMBOL(fb_get_mode); 1292EXPORT_SYMBOL(fb_get_mode);
1258EXPORT_SYMBOL(fb_validate_mode); 1293EXPORT_SYMBOL(fb_validate_mode);
1259EXPORT_SYMBOL(fb_destroy_modedb); 1294EXPORT_SYMBOL(fb_destroy_modedb);
diff --git a/drivers/video/geode/Kconfig b/drivers/video/geode/Kconfig
index b075fd02de..5a9b89c383 100644
--- a/drivers/video/geode/Kconfig
+++ b/drivers/video/geode/Kconfig
@@ -3,15 +3,13 @@
3# 3#
4config FB_GEODE 4config FB_GEODE
5 bool "AMD Geode family framebuffer support (EXPERIMENTAL)" 5 bool "AMD Geode family framebuffer support (EXPERIMENTAL)"
6 default n 6 depends on FB && PCI && EXPERIMENTAL && X86
7 depends on FB && EXPERIMENTAL && X86
8 ---help--- 7 ---help---
9 Say 'Y' here to allow you to select framebuffer drivers for 8 Say 'Y' here to allow you to select framebuffer drivers for
10 the AMD Geode family of processors. 9 the AMD Geode family of processors.
11 10
12config FB_GEODE_GX1 11config FB_GEODE_GX1
13 tristate "AMD Geode GX1 framebuffer support (EXPERIMENTAL)" 12 tristate "AMD Geode GX1 framebuffer support (EXPERIMENTAL)"
14 default n
15 depends on FB_GEODE && EXPERIMENTAL 13 depends on FB_GEODE && EXPERIMENTAL
16 select FB_CFB_FILLRECT 14 select FB_CFB_FILLRECT
17 select FB_CFB_COPYAREA 15 select FB_CFB_COPYAREA
@@ -21,9 +19,7 @@ config FB_GEODE_GX1
21 Framebuffer driver for the display controller integrated into the 19 Framebuffer driver for the display controller integrated into the
22 AMD Geode GX1 processor. 20 AMD Geode GX1 processor.
23 21
24 This driver is also available as a module ( = code which can be 22 To compile this driver as a module, choose M here: the module will be
25 inserted and removed from the running kernel whenever you want). The 23 called gx1fb.
26 module will be called gx1fb. If you want to compile it as a module,
27 say M here and read <file:Documentation/modules.txt>.
28 24
29 If unsure, say N. 25 If unsure, say N.
diff --git a/drivers/video/geode/display_gx1.c b/drivers/video/geode/display_gx1.c
index f4983879fc..926d53eeb5 100644
--- a/drivers/video/geode/display_gx1.c
+++ b/drivers/video/geode/display_gx1.c
@@ -22,7 +22,7 @@
22#include "geodefb.h" 22#include "geodefb.h"
23#include "display_gx1.h" 23#include "display_gx1.h"
24 24
25static spinlock_t gx1_conf_reg_lock = SPIN_LOCK_UNLOCKED; 25static DEFINE_SPINLOCK(gx1_conf_reg_lock);
26 26
27static u8 gx1_read_conf_reg(u8 reg) 27static u8 gx1_read_conf_reg(u8 reg)
28{ 28{
diff --git a/drivers/video/geode/geodefb.h b/drivers/video/geode/geodefb.h
index b7bac0a526..ae04820e0c 100644
--- a/drivers/video/geode/geodefb.h
+++ b/drivers/video/geode/geodefb.h
@@ -29,7 +29,6 @@ struct geodefb_par {
29 int enable_crt; 29 int enable_crt;
30 int panel_x; /* dimensions of an attached flat panel, non-zero => enable panel */ 30 int panel_x; /* dimensions of an attached flat panel, non-zero => enable panel */
31 int panel_y; 31 int panel_y;
32 struct pci_dev *vid_dev;
33 void __iomem *dc_regs; 32 void __iomem *dc_regs;
34 void __iomem *vid_regs; 33 void __iomem *vid_regs;
35 struct geode_dc_ops *dc_ops; 34 struct geode_dc_ops *dc_ops;
diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
index 83830d24bc..74a5fca86b 100644
--- a/drivers/video/geode/gx1fb_core.c
+++ b/drivers/video/geode/gx1fb_core.c
@@ -30,6 +30,62 @@ static char mode_option[32] = "640x480-16@60";
30static int crt_option = 1; 30static int crt_option = 1;
31static char panel_option[32] = ""; 31static char panel_option[32] = "";
32 32
33/* Modes relevant to the GX1 (taken from modedb.c) */
34static const struct fb_videomode __initdata gx1_modedb[] = {
35 /* 640x480-60 VESA */
36 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
37 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38 /* 640x480-75 VESA */
39 { NULL, 75, 640, 480, 31746, 120, 16, 16, 01, 64, 3,
40 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
41 /* 640x480-85 VESA */
42 { NULL, 85, 640, 480, 27777, 80, 56, 25, 01, 56, 3,
43 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
44 /* 800x600-60 VESA */
45 { NULL, 60, 800, 600, 25000, 88, 40, 23, 01, 128, 4,
46 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
47 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
48 /* 800x600-75 VESA */
49 { NULL, 75, 800, 600, 20202, 160, 16, 21, 01, 80, 3,
50 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
51 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
52 /* 800x600-85 VESA */
53 { NULL, 85, 800, 600, 17761, 152, 32, 27, 01, 64, 3,
54 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
55 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
56 /* 1024x768-60 VESA */
57 { NULL, 60, 1024, 768, 15384, 160, 24, 29, 3, 136, 6,
58 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
59 /* 1024x768-75 VESA */
60 { NULL, 75, 1024, 768, 12690, 176, 16, 28, 1, 96, 3,
61 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
62 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
63 /* 1024x768-85 VESA */
64 { NULL, 85, 1024, 768, 10582, 208, 48, 36, 1, 96, 3,
65 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
66 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
67 /* 1280x960-60 VESA */
68 { NULL, 60, 1280, 960, 9259, 312, 96, 36, 1, 112, 3,
69 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
70 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
71 /* 1280x960-85 VESA */
72 { NULL, 85, 1280, 960, 6734, 224, 64, 47, 1, 160, 3,
73 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
74 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
75 /* 1280x1024-60 VESA */
76 { NULL, 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3,
77 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
78 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
79 /* 1280x1024-75 VESA */
80 { NULL, 75, 1280, 1024, 7407, 248, 16, 38, 1, 144, 3,
81 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
82 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
83 /* 1280x1024-85 VESA */
84 { NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
85 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
86 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
87};
88
33static int gx1_line_delta(int xres, int bpp) 89static int gx1_line_delta(int xres, int bpp)
34{ 90{
35 int line_delta = xres * (bpp >> 3); 91 int line_delta = xres * (bpp >> 3);
@@ -47,8 +103,6 @@ static int gx1fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
47{ 103{
48 struct geodefb_par *par = info->par; 104 struct geodefb_par *par = info->par;
49 105
50 printk(KERN_DEBUG "%s()\n", __FUNCTION__);
51
52 /* Maximum resolution is 1280x1024. */ 106 /* Maximum resolution is 1280x1024. */
53 if (var->xres > 1280 || var->yres > 1024) 107 if (var->xres > 1280 || var->yres > 1024)
54 return -EINVAL; 108 return -EINVAL;
@@ -146,40 +200,48 @@ static int gx1fb_blank(int blank_mode, struct fb_info *info)
146 return par->vid_ops->blank_display(info, blank_mode); 200 return par->vid_ops->blank_display(info, blank_mode);
147} 201}
148 202
149static int __init gx1fb_map_video_memory(struct fb_info *info) 203static int __init gx1fb_map_video_memory(struct fb_info *info, struct pci_dev *dev)
150{ 204{
151 struct geodefb_par *par = info->par; 205 struct geodefb_par *par = info->par;
152 unsigned gx_base; 206 unsigned gx_base;
153 int fb_len; 207 int fb_len;
208 int ret;
154 209
155 gx_base = gx1_gx_base(); 210 gx_base = gx1_gx_base();
156 if (!gx_base) 211 if (!gx_base)
157 return -ENODEV; 212 return -ENODEV;
158 213
159 par->vid_dev = pci_get_device(PCI_VENDOR_ID_CYRIX, 214 ret = pci_enable_device(dev);
160 PCI_DEVICE_ID_CYRIX_5530_VIDEO, NULL); 215 if (ret < 0)
161 if (!par->vid_dev) 216 return ret;
162 return -ENODEV;
163 217
164 par->vid_regs = ioremap(pci_resource_start(par->vid_dev, 1), 218 ret = pci_request_region(dev, 1, "gx1fb (video)");
165 pci_resource_len(par->vid_dev, 1)); 219 if (ret < 0)
220 return ret;
221 par->vid_regs = ioremap(pci_resource_start(dev, 1),
222 pci_resource_len(dev, 1));
166 if (!par->vid_regs) 223 if (!par->vid_regs)
167 return -ENOMEM; 224 return -ENOMEM;
168 225
226 if (!request_mem_region(gx_base + 0x8300, 0x100, "gx1fb (display controller)"))
227 return -EBUSY;
169 par->dc_regs = ioremap(gx_base + 0x8300, 0x100); 228 par->dc_regs = ioremap(gx_base + 0x8300, 0x100);
170 if (!par->dc_regs) 229 if (!par->dc_regs)
171 return -ENOMEM; 230 return -ENOMEM;
172 231
173 info->fix.smem_start = gx_base + 0x800000; 232 ret = pci_request_region(dev, 0, "gx1fb (frame buffer)");
233 if (ret < 0 )
234 return -EBUSY;
174 if ((fb_len = gx1_frame_buffer_size()) < 0) 235 if ((fb_len = gx1_frame_buffer_size()) < 0)
175 return -ENOMEM; 236 return -ENOMEM;
237 info->fix.smem_start = pci_resource_start(dev, 0);
176 info->fix.smem_len = fb_len; 238 info->fix.smem_len = fb_len;
177 info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len); 239 info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
178 if (!info->screen_base) 240 if (!info->screen_base)
179 return -ENOMEM; 241 return -ENOMEM;
180 242
181 printk(KERN_INFO "%s: %d Kibyte of video memory at 0x%lx\n", 243 dev_info(&dev->dev, "%d Kibyte of video memory at 0x%lx\n",
182 info->fix.id, info->fix.smem_len / 1024, info->fix.smem_start); 244 info->fix.smem_len / 1024, info->fix.smem_start);
183 245
184 return 0; 246 return 0;
185} 247}
@@ -216,13 +278,13 @@ static struct fb_ops gx1fb_ops = {
216 .fb_cursor = soft_cursor, 278 .fb_cursor = soft_cursor,
217}; 279};
218 280
219static struct fb_info * __init gx1fb_init_fbinfo(void) 281static struct fb_info * __init gx1fb_init_fbinfo(struct device *dev)
220{ 282{
221 struct fb_info *info;
222 struct geodefb_par *par; 283 struct geodefb_par *par;
284 struct fb_info *info;
223 285
224 /* Alloc enough space for the pseudo palette. */ 286 /* Alloc enough space for the pseudo palette. */
225 info = framebuffer_alloc(sizeof(struct geodefb_par) + sizeof(u32) * 16, NULL); 287 info = framebuffer_alloc(sizeof(struct geodefb_par) + sizeof(u32) * 16, dev);
226 if (!info) 288 if (!info)
227 return NULL; 289 return NULL;
228 290
@@ -255,47 +317,37 @@ static struct fb_info * __init gx1fb_init_fbinfo(void)
255 /* CRT and panel options */ 317 /* CRT and panel options */
256 par->enable_crt = crt_option; 318 par->enable_crt = crt_option;
257 if (parse_panel_option(info) < 0) 319 if (parse_panel_option(info) < 0)
258 printk(KERN_WARNING "%s: invalid 'panel' option -- disabling flat panel\n", 320 printk(KERN_WARNING "gx1fb: invalid 'panel' option -- disabling flat panel\n");
259 info->fix.id);
260 if (!par->panel_x) 321 if (!par->panel_x)
261 par->enable_crt = 1; /* fall back to CRT if no panel is specified */ 322 par->enable_crt = 1; /* fall back to CRT if no panel is specified */
262 323
263 return info; 324 return info;
264} 325}
265 326
266 327static int __init gx1fb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
267static struct fb_info *gx1fb_info;
268
269static int __init gx1fb_init(void)
270{ 328{
329 struct geodefb_par *par;
271 struct fb_info *info; 330 struct fb_info *info;
272 struct geodefb_par *par;
273 int ret; 331 int ret;
274 332
275#ifndef MODULE 333 info = gx1fb_init_fbinfo(&pdev->dev);
276 if (fb_get_options("gx1fb", NULL))
277 return -ENODEV;
278#endif
279
280 info = gx1fb_init_fbinfo();
281 if (!info) 334 if (!info)
282 return -ENOMEM; 335 return -ENOMEM;
283 gx1fb_info = info;
284
285 par = info->par; 336 par = info->par;
286 337
287 /* GX1 display controller and CS5530 video device */ 338 /* GX1 display controller and CS5530 video device */
288 par->dc_ops = &gx1_dc_ops; 339 par->dc_ops = &gx1_dc_ops;
289 par->vid_ops = &cs5530_vid_ops; 340 par->vid_ops = &cs5530_vid_ops;
290 341
291 if ((ret = gx1fb_map_video_memory(info)) < 0) { 342 if ((ret = gx1fb_map_video_memory(info, pdev)) < 0) {
292 printk(KERN_ERR "%s: gx1fb_map_video_memory() failed\n", info->fix.id); 343 dev_err(&pdev->dev, "failed to map frame buffer or controller registers\n");
293 goto err; 344 goto err;
294 } 345 }
295 346
296 ret = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 16); 347 ret = fb_find_mode(&info->var, info, mode_option,
348 gx1_modedb, ARRAY_SIZE(gx1_modedb), NULL, 16);
297 if (ret == 0 || ret == 4) { 349 if (ret == 0 || ret == 4) {
298 printk(KERN_ERR "%s: could not find valid video mode\n", info->fix.id); 350 dev_err(&pdev->dev, "could not find valid video mode\n");
299 ret = -EINVAL; 351 ret = -EINVAL;
300 goto err; 352 goto err;
301 } 353 }
@@ -310,39 +362,83 @@ static int __init gx1fb_init(void)
310 ret = -EINVAL; 362 ret = -EINVAL;
311 goto err; 363 goto err;
312 } 364 }
365 pci_set_drvdata(pdev, info);
313 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node, info->fix.id); 366 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node, info->fix.id);
314 return 0; 367 return 0;
315 368
316 err: 369 err:
317 if (info->screen_base) 370 if (info->screen_base) {
318 iounmap(info->screen_base); 371 iounmap(info->screen_base);
319 if (par->vid_regs) 372 pci_release_region(pdev, 0);
373 }
374 if (par->vid_regs) {
320 iounmap(par->vid_regs); 375 iounmap(par->vid_regs);
321 if (par->dc_regs) 376 pci_release_region(pdev, 1);
377 }
378 if (par->dc_regs) {
322 iounmap(par->dc_regs); 379 iounmap(par->dc_regs);
323 if (par->vid_dev) 380 release_mem_region(gx1_gx_base() + 0x8300, 0x100);
324 pci_dev_put(par->vid_dev); 381 }
382
383 pci_disable_device(pdev);
384
325 if (info) 385 if (info)
326 framebuffer_release(info); 386 framebuffer_release(info);
327 return ret; 387 return ret;
328} 388}
329 389
330static void __exit gx1fb_cleanup(void) 390static void gx1fb_remove(struct pci_dev *pdev)
331{ 391{
332 struct fb_info *info = gx1fb_info; 392 struct fb_info *info = pci_get_drvdata(pdev);
333 struct geodefb_par *par = gx1fb_info->par; 393 struct geodefb_par *par = info->par;
334 394
335 unregister_framebuffer(info); 395 unregister_framebuffer(info);
336 396
337 iounmap((void __iomem *)info->screen_base); 397 iounmap((void __iomem *)info->screen_base);
398 pci_release_region(pdev, 0);
399
338 iounmap(par->vid_regs); 400 iounmap(par->vid_regs);
401 pci_release_region(pdev, 1);
402
339 iounmap(par->dc_regs); 403 iounmap(par->dc_regs);
404 release_mem_region(gx1_gx_base() + 0x8300, 0x100);
340 405
341 pci_dev_put(par->vid_dev); 406 pci_disable_device(pdev);
407 pci_set_drvdata(pdev, NULL);
342 408
343 framebuffer_release(info); 409 framebuffer_release(info);
344} 410}
345 411
412static struct pci_device_id gx1fb_id_table[] = {
413 { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_VIDEO,
414 PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16,
415 0xff0000, 0 },
416 { 0, }
417};
418
419MODULE_DEVICE_TABLE(pci, gx1fb_id_table);
420
421static struct pci_driver gx1fb_driver = {
422 .name = "gx1fb",
423 .id_table = gx1fb_id_table,
424 .probe = gx1fb_probe,
425 .remove = gx1fb_remove,
426};
427
428static int __init gx1fb_init(void)
429{
430#ifndef MODULE
431 if (fb_get_options("gx1fb", NULL))
432 return -ENODEV;
433#endif
434 return pci_register_driver(&gx1fb_driver);
435}
436
437static void __exit gx1fb_cleanup(void)
438{
439 pci_unregister_driver(&gx1fb_driver);
440}
441
346module_init(gx1fb_init); 442module_init(gx1fb_init);
347module_exit(gx1fb_cleanup); 443module_exit(gx1fb_cleanup);
348 444
diff --git a/drivers/video/geode/video_cs5530.c b/drivers/video/geode/video_cs5530.c
index d3764acf84..649c3943d4 100644
--- a/drivers/video/geode/video_cs5530.c
+++ b/drivers/video/geode/video_cs5530.c
@@ -69,8 +69,6 @@ static const struct cs5530_pll_entry cs5530_pll_table[] = {
69 { 4310, 0x2FB1B802, }, /* 232.0000 */ 69 { 4310, 0x2FB1B802, }, /* 232.0000 */
70}; 70};
71 71
72#define NUM_CS5530_FREQUENCIES sizeof(cs5530_pll_table)/sizeof(struct cs5530_pll_entry)
73
74static void cs5530_set_dclk_frequency(struct fb_info *info) 72static void cs5530_set_dclk_frequency(struct fb_info *info)
75{ 73{
76 struct geodefb_par *par = info->par; 74 struct geodefb_par *par = info->par;
@@ -82,7 +80,7 @@ static void cs5530_set_dclk_frequency(struct fb_info *info)
82 value = cs5530_pll_table[0].pll_value; 80 value = cs5530_pll_table[0].pll_value;
83 min = cs5530_pll_table[0].pixclock - info->var.pixclock; 81 min = cs5530_pll_table[0].pixclock - info->var.pixclock;
84 if (min < 0) min = -min; 82 if (min < 0) min = -min;
85 for (i = 1; i < NUM_CS5530_FREQUENCIES; i++) { 83 for (i = 1; i < ARRAY_SIZE(cs5530_pll_table); i++) {
86 diff = cs5530_pll_table[i].pixclock - info->var.pixclock; 84 diff = cs5530_pll_table[i].pixclock - info->var.pixclock;
87 if (diff < 0L) diff = -diff; 85 if (diff < 0L) diff = -diff;
88 if (diff < min) { 86 if (diff < min) {
diff --git a/drivers/video/i810/Makefile b/drivers/video/i810/Makefile
index 794ae76c7c..96e08c8ded 100644
--- a/drivers/video/i810/Makefile
+++ b/drivers/video/i810/Makefile
@@ -4,7 +4,6 @@
4 4
5obj-$(CONFIG_FB_I810) += i810fb.o 5obj-$(CONFIG_FB_I810) += i810fb.o
6 6
7
8i810fb-objs := i810_main.o i810_accel.o 7i810fb-objs := i810_main.o i810_accel.o
9 8
10ifdef CONFIG_FB_I810_GTF 9ifdef CONFIG_FB_I810_GTF
@@ -12,3 +11,7 @@ i810fb-objs += i810_gtf.o
12else 11else
13i810fb-objs += i810_dvt.o 12i810fb-objs += i810_dvt.o
14endif 13endif
14
15ifdef CONFIG_FB_I810_I2C
16i810fb-objs += i810-i2c.o
17endif
diff --git a/drivers/video/i810/i810-i2c.c b/drivers/video/i810/i810-i2c.c
new file mode 100644
index 0000000000..fda53aac1f
--- /dev/null
+++ b/drivers/video/i810/i810-i2c.c
@@ -0,0 +1,257 @@
1 /*-*- linux-c -*-
2 * linux/drivers/video/i810-i2c.c -- Intel 810/815 I2C support
3 *
4 * Copyright (C) 2004 Antonino Daplas<adaplas@pol.net>
5 * All Rights Reserved
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive for
9 * more details.
10 */
11#include <linux/config.h>
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/sched.h>
15#include <linux/delay.h>
16#include <linux/pci.h>
17#include <linux/fb.h>
18#include "i810.h"
19#include "i810_regs.h"
20#include "../edid.h"
21
22#define I810_DDC 0x50
23/* bit locations in the registers */
24#define SCL_DIR_MASK 0x0001
25#define SCL_DIR 0x0002
26#define SCL_VAL_MASK 0x0004
27#define SCL_VAL_OUT 0x0008
28#define SCL_VAL_IN 0x0010
29#define SDA_DIR_MASK 0x0100
30#define SDA_DIR 0x0200
31#define SDA_VAL_MASK 0x0400
32#define SDA_VAL_OUT 0x0800
33#define SDA_VAL_IN 0x1000
34
35#define DEBUG /* define this for verbose EDID parsing output */
36
37#ifdef DEBUG
38#define DPRINTK(fmt, args...) printk(fmt,## args)
39#else
40#define DPRINTK(fmt, args...)
41#endif
42
43static void i810i2c_setscl(void *data, int state)
44{
45 struct i810fb_i2c_chan *chan = (struct i810fb_i2c_chan *)data;
46 struct i810fb_par *par = chan->par;
47 u8 *mmio = par->mmio_start_virtual;
48
49 i810_writel(mmio, GPIOB, (state ? SCL_VAL_OUT : 0) | SCL_DIR |
50 SCL_DIR_MASK | SCL_VAL_MASK);
51 i810_readl(mmio, GPIOB); /* flush posted write */
52}
53
54static void i810i2c_setsda(void *data, int state)
55{
56 struct i810fb_i2c_chan *chan = (struct i810fb_i2c_chan *)data;
57 struct i810fb_par *par = chan->par;
58 u8 *mmio = par->mmio_start_virtual;
59
60 i810_writel(mmio, GPIOB, (state ? SDA_VAL_OUT : 0) | SDA_DIR |
61 SDA_DIR_MASK | SDA_VAL_MASK);
62 i810_readl(mmio, GPIOB); /* flush posted write */
63}
64
65static int i810i2c_getscl(void *data)
66{
67 struct i810fb_i2c_chan *chan = (struct i810fb_i2c_chan *)data;
68 struct i810fb_par *par = chan->par;
69 u8 *mmio = par->mmio_start_virtual;
70
71 i810_writel(mmio, GPIOB, SCL_DIR_MASK);
72 i810_writel(mmio, GPIOB, 0);
73 return (0 != (i810_readl(mmio, GPIOB) & SCL_VAL_IN));
74}
75
76static int i810i2c_getsda(void *data)
77{
78 struct i810fb_i2c_chan *chan = (struct i810fb_i2c_chan *)data;
79 struct i810fb_par *par = chan->par;
80 u8 *mmio = par->mmio_start_virtual;
81
82 i810_writel(mmio, GPIOB, SDA_DIR_MASK);
83 i810_writel(mmio, GPIOB, 0);
84 return (0 != (i810_readl(mmio, GPIOB) & SDA_VAL_IN));
85}
86
87static void i810ddc_setscl(void *data, int state)
88{
89 struct i810fb_i2c_chan *chan = (struct i810fb_i2c_chan *)data;
90 struct i810fb_par *par = chan->par;
91 u8 *mmio = par->mmio_start_virtual;
92
93 i810_writel(mmio, GPIOA, (state ? SCL_VAL_OUT : 0) | SCL_DIR |
94 SCL_DIR_MASK | SCL_VAL_MASK);
95 i810_readl(mmio, GPIOA); /* flush posted write */
96}
97
98static void i810ddc_setsda(void *data, int state)
99{
100 struct i810fb_i2c_chan *chan = (struct i810fb_i2c_chan *)data;
101 struct i810fb_par *par = chan->par;
102 u8 *mmio = par->mmio_start_virtual;
103
104 i810_writel(mmio, GPIOA, (state ? SDA_VAL_OUT : 0) | SDA_DIR |
105 SDA_DIR_MASK | SDA_VAL_MASK);
106 i810_readl(mmio, GPIOA); /* flush posted write */
107}
108
109static int i810ddc_getscl(void *data)
110{
111 struct i810fb_i2c_chan *chan = (struct i810fb_i2c_chan *)data;
112 struct i810fb_par *par = chan->par;
113 u8 *mmio = par->mmio_start_virtual;
114
115 i810_writel(mmio, GPIOA, SCL_DIR_MASK);
116 i810_writel(mmio, GPIOA, 0);
117 return (0 != (i810_readl(mmio, GPIOA) & SCL_VAL_IN));
118}
119
120static int i810ddc_getsda(void *data)
121{
122 struct i810fb_i2c_chan *chan = (struct i810fb_i2c_chan *)data;
123 struct i810fb_par *par = chan->par;
124 u8 *mmio = par->mmio_start_virtual;
125
126 i810_writel(mmio, GPIOA, SDA_DIR_MASK);
127 i810_writel(mmio, GPIOA, 0);
128 return (0 != (i810_readl(mmio, GPIOA) & SDA_VAL_IN));
129}
130
131#define I2C_ALGO_DDC_I810 0x0e0000
132#define I2C_ALGO_I2C_I810 0x0f0000
133static int i810_setup_i2c_bus(struct i810fb_i2c_chan *chan, const char *name,
134 int conn)
135{
136 int rc;
137
138 strcpy(chan->adapter.name, name);
139 chan->adapter.owner = THIS_MODULE;
140 chan->adapter.algo_data = &chan->algo;
141 chan->adapter.dev.parent = &chan->par->dev->dev;
142 switch (conn) {
143 case 1:
144 chan->adapter.id = I2C_ALGO_DDC_I810;
145 chan->algo.setsda = i810ddc_setsda;
146 chan->algo.setscl = i810ddc_setscl;
147 chan->algo.getsda = i810ddc_getsda;
148 chan->algo.getscl = i810ddc_getscl;
149 break;
150 case 2:
151 chan->adapter.id = I2C_ALGO_I2C_I810;
152 chan->algo.setsda = i810i2c_setsda;
153 chan->algo.setscl = i810i2c_setscl;
154 chan->algo.getsda = i810i2c_getsda;
155 chan->algo.getscl = i810i2c_getscl;
156 break;
157 }
158 chan->algo.udelay = 10;
159 chan->algo.mdelay = 10;
160 chan->algo.timeout = (HZ/2);
161 chan->algo.data = chan;
162
163 i2c_set_adapdata(&chan->adapter, chan);
164
165 /* Raise SCL and SDA */
166 chan->algo.setsda(chan, 1);
167 chan->algo.setscl(chan, 1);
168 udelay(20);
169
170 rc = i2c_bit_add_bus(&chan->adapter);
171 if (rc == 0)
172 dev_dbg(&chan->par->dev->dev, "I2C bus %s registered.\n",name);
173 else
174 dev_warn(&chan->par->dev->dev, "Failed to register I2C bus "
175 "%s.\n", name);
176 return rc;
177}
178
179void i810_create_i2c_busses(struct i810fb_par *par)
180{
181 par->chan[0].par = par;
182 par->chan[1].par = par;
183 i810_setup_i2c_bus(&par->chan[0], "I810-DDC", 1);
184 i810_setup_i2c_bus(&par->chan[1], "I810-I2C", 2);
185}
186
187void i810_delete_i2c_busses(struct i810fb_par *par)
188{
189 if (par->chan[0].par)
190 i2c_bit_del_bus(&par->chan[0].adapter);
191 par->chan[0].par = NULL;
192 if (par->chan[1].par)
193 i2c_bit_del_bus(&par->chan[1].adapter);
194 par->chan[1].par = NULL;
195}
196
197static u8 *i810_do_probe_i2c_edid(struct i810fb_i2c_chan *chan)
198{
199 u8 start = 0x0;
200 struct i2c_msg msgs[] = {
201 {
202 .addr = I810_DDC,
203 .len = 1,
204 .buf = &start,
205 }, {
206 .addr = I810_DDC,
207 .flags = I2C_M_RD,
208 .len = EDID_LENGTH,
209 },
210 };
211 u8 *buf;
212
213 buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
214 if (!buf) {
215 DPRINTK("i810-i2c: Failed to allocate memory\n");
216 return NULL;
217 }
218 msgs[1].buf = buf;
219
220 if (i2c_transfer(&chan->adapter, msgs, 2) == 2) {
221 DPRINTK("i810-i2c: I2C Transfer successful\n");
222 return buf;
223 }
224 DPRINTK("i810-i2c: Unable to read EDID block.\n");
225 kfree(buf);
226 return NULL;
227}
228
229int i810_probe_i2c_connector(struct fb_info *info, u8 **out_edid, int conn)
230{
231 struct i810fb_par *par = info->par;
232 u8 *edid = NULL;
233 int i;
234
235 DPRINTK("i810-i2c: Probe DDC%i Bus\n", conn);
236 if (conn < 3) {
237 for (i = 0; i < 3; i++) {
238 /* Do the real work */
239 edid = i810_do_probe_i2c_edid(&par->chan[conn-1]);
240 if (edid)
241 break;
242 }
243 } else {
244 DPRINTK("i810-i2c: Getting EDID from BIOS\n");
245 edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
246 if (edid)
247 memcpy(edid, fb_firmware_edid(info->device),
248 EDID_LENGTH);
249 }
250
251 if (out_edid)
252 *out_edid = edid;
253
254 return (edid) ? 0 : 1;
255}
256
257
diff --git a/drivers/video/i810/i810.h b/drivers/video/i810/i810.h
index fe3b757947..d48949ceaa 100644
--- a/drivers/video/i810/i810.h
+++ b/drivers/video/i810/i810.h
@@ -16,6 +16,9 @@
16#include <linux/list.h> 16#include <linux/list.h>
17#include <linux/agp_backend.h> 17#include <linux/agp_backend.h>
18#include <linux/fb.h> 18#include <linux/fb.h>
19#include <linux/i2c.h>
20#include <linux/i2c-id.h>
21#include <linux/i2c-algo-bit.h>
19#include <video/vga.h> 22#include <video/vga.h>
20 23
21/* Fence */ 24/* Fence */
@@ -201,7 +204,6 @@
201#define HAS_ACCELERATION 2 204#define HAS_ACCELERATION 2
202#define ALWAYS_SYNC 4 205#define ALWAYS_SYNC 4
203#define LOCKUP 8 206#define LOCKUP 8
204#define USE_HWCUR 16
205 207
206struct gtt_data { 208struct gtt_data {
207 struct agp_memory *i810_fb_memory; 209 struct agp_memory *i810_fb_memory;
@@ -241,6 +243,14 @@ struct state_registers {
241 u8 cr39, cr41, cr70, sr01, msr; 243 u8 cr39, cr41, cr70, sr01, msr;
242}; 244};
243 245
246struct i810fb_par;
247
248struct i810fb_i2c_chan {
249 struct i810fb_par *par;
250 struct i2c_adapter adapter;
251 struct i2c_algo_bit_data algo;
252};
253
244struct i810fb_par { 254struct i810fb_par {
245 struct mode_registers regs; 255 struct mode_registers regs;
246 struct state_registers hw_state; 256 struct state_registers hw_state;
@@ -252,10 +262,12 @@ struct i810fb_par {
252 struct heap_data iring; 262 struct heap_data iring;
253 struct heap_data cursor_heap; 263 struct heap_data cursor_heap;
254 struct vgastate state; 264 struct vgastate state;
265 struct i810fb_i2c_chan chan[2];
255 atomic_t use_count; 266 atomic_t use_count;
256 u32 pseudo_palette[17]; 267 u32 pseudo_palette[17];
257 unsigned long mmio_start_phys; 268 unsigned long mmio_start_phys;
258 u8 __iomem *mmio_start_virtual; 269 u8 __iomem *mmio_start_virtual;
270 u8 *edid;
259 u32 pitch; 271 u32 pitch;
260 u32 pixconf; 272 u32 pixconf;
261 u32 watermark; 273 u32 watermark;
diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
index 6db183462b..0dbc9ddb67 100644
--- a/drivers/video/i810/i810_main.c
+++ b/drivers/video/i810/i810_main.c
@@ -92,20 +92,21 @@ static struct pci_driver i810fb_driver = {
92 .resume = i810fb_resume, 92 .resume = i810fb_resume,
93}; 93};
94 94
95static int vram __initdata = 4; 95static char *mode_option __devinitdata = NULL;
96static int bpp __initdata = 8; 96static int vram __devinitdata = 4;
97static int mtrr __initdata = 0; 97static int bpp __devinitdata = 8;
98static int accel __initdata = 0; 98static int mtrr __devinitdata;
99static int hsync1 __initdata = 0; 99static int accel __devinitdata;
100static int hsync2 __initdata = 0; 100static int hsync1 __devinitdata;
101static int vsync1 __initdata = 0; 101static int hsync2 __devinitdata;
102static int vsync2 __initdata = 0; 102static int vsync1 __devinitdata;
103static int xres __initdata = 640; 103static int vsync2 __devinitdata;
104static int yres __initdata = 480; 104static int xres __devinitdata;
105static int vyres __initdata = 0; 105static int yres __devinitdata;
106static int sync __initdata = 0; 106static int vyres __devinitdata;
107static int ext_vga __initdata = 0; 107static int sync __devinitdata;
108static int dcolor __initdata = 0; 108static int extvga __devinitdata;
109static int dcolor __devinitdata;
109 110
110/*------------------------------------------------------------*/ 111/*------------------------------------------------------------*/
111 112
@@ -310,6 +311,8 @@ static void i810_hires(u8 __iomem *mmio)
310 val = i810_readb(CR_DATA_CGA, mmio); 311 val = i810_readb(CR_DATA_CGA, mmio);
311 i810_writeb(CR_INDEX_CGA, mmio, CR80); 312 i810_writeb(CR_INDEX_CGA, mmio, CR80);
312 i810_writeb(CR_DATA_CGA, mmio, val | 1); 313 i810_writeb(CR_DATA_CGA, mmio, val | 1);
314 /* Stop LCD displays from flickering */
315 i810_writel(MEM_MODE, mmio, i810_readl(MEM_MODE, mmio) | 4);
313} 316}
314 317
315/** 318/**
@@ -947,31 +950,24 @@ static int i810_check_params(struct fb_var_screeninfo *var,
947 struct fb_info *info) 950 struct fb_info *info)
948{ 951{
949 struct i810fb_par *par = (struct i810fb_par *) info->par; 952 struct i810fb_par *par = (struct i810fb_par *) info->par;
950 int line_length, vidmem; 953 int line_length, vidmem, mode_valid = 0, retval = 0;
951 u32 xres, yres, vxres, vyres; 954 u32 vyres = var->yres_virtual, vxres = var->xres_virtual;
952
953 xres = var->xres;
954 yres = var->yres;
955 vxres = var->xres_virtual;
956 vyres = var->yres_virtual;
957
958 /* 955 /*
959 * Memory limit 956 * Memory limit
960 */ 957 */
961 line_length = get_line_length(par, vxres, 958 line_length = get_line_length(par, vxres, var->bits_per_pixel);
962 var->bits_per_pixel);
963
964 vidmem = line_length*vyres; 959 vidmem = line_length*vyres;
960
965 if (vidmem > par->fb.size) { 961 if (vidmem > par->fb.size) {
966 vyres = par->fb.size/line_length; 962 vyres = par->fb.size/line_length;
967 if (vyres < yres) { 963 if (vyres < var->yres) {
968 vyres = yres; 964 vyres = yres;
969 vxres = par->fb.size/vyres; 965 vxres = par->fb.size/vyres;
970 vxres /= var->bits_per_pixel >> 3; 966 vxres /= var->bits_per_pixel >> 3;
971 line_length = get_line_length(par, vxres, 967 line_length = get_line_length(par, vxres,
972 var->bits_per_pixel); 968 var->bits_per_pixel);
973 vidmem = line_length * yres; 969 vidmem = line_length * yres;
974 if (vxres < xres) { 970 if (vxres < var->xres) {
975 printk("i810fb: required video memory, " 971 printk("i810fb: required video memory, "
976 "%d bytes, for %dx%d-%d (virtual) " 972 "%d bytes, for %dx%d-%d (virtual) "
977 "is out of range\n", 973 "is out of range\n",
@@ -981,6 +977,10 @@ static int i810_check_params(struct fb_var_screeninfo *var,
981 } 977 }
982 } 978 }
983 } 979 }
980
981 var->xres_virtual = vxres;
982 var->yres_virtual = vyres;
983
984 /* 984 /*
985 * Monitor limit 985 * Monitor limit
986 */ 986 */
@@ -996,26 +996,41 @@ static int i810_check_params(struct fb_var_screeninfo *var,
996 info->monspecs.dclkmax = 204000000; 996 info->monspecs.dclkmax = 204000000;
997 break; 997 break;
998 } 998 }
999
999 info->monspecs.dclkmin = 15000000; 1000 info->monspecs.dclkmin = 15000000;
1000 1001
1001 if (fb_validate_mode(var, info)) { 1002 if (!fb_validate_mode(var, info))
1003 mode_valid = 1;
1004
1005#ifdef CONFIG_FB_I810_I2C
1006 if (!mode_valid && info->monspecs.gtf &&
1007 !fb_get_mode(FB_MAXTIMINGS, 0, var, info))
1008 mode_valid = 1;
1009
1010 if (!mode_valid && info->monspecs.modedb_len) {
1011 struct fb_videomode *mode;
1012
1013 mode = fb_find_best_mode(var, &info->modelist);
1014 if (mode) {
1015 fb_videomode_to_var(var, mode);
1016 mode_valid = 1;
1017 }
1018 }
1019#endif
1020 if (!mode_valid && info->monspecs.modedb_len == 0) {
1002 if (fb_get_mode(FB_MAXTIMINGS, 0, var, info)) { 1021 if (fb_get_mode(FB_MAXTIMINGS, 0, var, info)) {
1003 int default_sync = (info->monspecs.hfmin-HFMIN) 1022 int default_sync = (info->monspecs.hfmin-HFMIN)
1004 |(info->monspecs.hfmax-HFMAX) 1023 |(info->monspecs.hfmax-HFMAX)
1005 |(info->monspecs.vfmin-VFMIN) 1024 |(info->monspecs.vfmin-VFMIN)
1006 |(info->monspecs.vfmax-VFMAX); 1025 |(info->monspecs.vfmax-VFMAX);
1007 printk("i810fb: invalid video mode%s\n", 1026 printk("i810fb: invalid video mode%s\n",
1008 default_sync ? "" : 1027 default_sync ? "" : ". Specifying "
1009 ". Specifying vsyncN/hsyncN parameters may help"); 1028 "vsyncN/hsyncN parameters may help");
1010 return -EINVAL; 1029 retval = -EINVAL;
1011 } 1030 }
1012 } 1031 }
1013 1032
1014 var->xres = xres; 1033 return retval;
1015 var->yres = yres;
1016 var->xres_virtual = vxres;
1017 var->yres_virtual = vyres;
1018 return 0;
1019} 1034}
1020 1035
1021/** 1036/**
@@ -1375,7 +1390,6 @@ static int i810fb_set_par(struct fb_info *info)
1375 decode_var(&info->var, par); 1390 decode_var(&info->var, par);
1376 i810_load_regs(par); 1391 i810_load_regs(par);
1377 i810_init_cursor(par); 1392 i810_init_cursor(par);
1378
1379 encode_fix(&info->fix, info); 1393 encode_fix(&info->fix, info);
1380 1394
1381 if (info->var.accel_flags && !(par->dev_flags & LOCKUP)) { 1395 if (info->var.accel_flags && !(par->dev_flags & LOCKUP)) {
@@ -1418,9 +1432,8 @@ static int i810fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1418 struct i810fb_par *par = (struct i810fb_par *)info->par; 1432 struct i810fb_par *par = (struct i810fb_par *)info->par;
1419 u8 __iomem *mmio = par->mmio_start_virtual; 1433 u8 __iomem *mmio = par->mmio_start_virtual;
1420 1434
1421 if (!(par->dev_flags & USE_HWCUR) || !info->var.accel_flags || 1435 if (!par->dev_flags & LOCKUP)
1422 par->dev_flags & LOCKUP) 1436 return -ENXIO;
1423 return soft_cursor(info, cursor);
1424 1437
1425 if (cursor->image.width > 64 || cursor->image.height > 64) 1438 if (cursor->image.width > 64 || cursor->image.height > 64)
1426 return -ENXIO; 1439 return -ENXIO;
@@ -1712,12 +1725,21 @@ static void __devinit i810_init_defaults(struct i810fb_par *par,
1712 if (bpp < 8) 1725 if (bpp < 8)
1713 bpp = 8; 1726 bpp = 8;
1714 1727
1728 par->i810fb_ops = i810fb_ops;
1729
1730 if (xres)
1731 info->var.xres = xres;
1732 else
1733 info->var.xres = 640;
1734
1735 if (yres)
1736 info->var.yres = yres;
1737 else
1738 info->var.yres = 480;
1739
1715 if (!vyres) 1740 if (!vyres)
1716 vyres = (vram << 20)/(xres*bpp >> 3); 1741 vyres = (vram << 20)/(info->var.xres*bpp >> 3);
1717 1742
1718 par->i810fb_ops = i810fb_ops;
1719 info->var.xres = xres;
1720 info->var.yres = yres;
1721 info->var.yres_virtual = vyres; 1743 info->var.yres_virtual = vyres;
1722 info->var.bits_per_pixel = bpp; 1744 info->var.bits_per_pixel = bpp;
1723 1745
@@ -1744,7 +1766,7 @@ static void __devinit i810_init_device(struct i810fb_par *par)
1744 i810_init_cursor(par); 1766 i810_init_cursor(par);
1745 1767
1746 /* mvo: enable external vga-connector (for laptops) */ 1768 /* mvo: enable external vga-connector (for laptops) */
1747 if (ext_vga) { 1769 if (extvga) {
1748 i810_writel(HVSYNC, mmio, 0); 1770 i810_writel(HVSYNC, mmio, 0);
1749 i810_writel(PWR_CLKC, mmio, 3); 1771 i810_writel(PWR_CLKC, mmio, 3);
1750 } 1772 }
@@ -1814,8 +1836,80 @@ i810_allocate_pci_resource(struct i810fb_par *par,
1814 return 0; 1836 return 0;
1815} 1837}
1816 1838
1839static void __devinit i810fb_find_init_mode(struct fb_info *info)
1840{
1841 struct fb_videomode mode;
1842 struct fb_var_screeninfo var;
1843 struct fb_monspecs *specs = &info->monspecs;
1844 int found = 0;
1845#ifdef CONFIG_FB_I810_I2C
1846 int i;
1847 int err;
1848 struct i810fb_par *par = info->par;
1849#endif
1850
1851 INIT_LIST_HEAD(&info->modelist);
1852 memset(&mode, 0, sizeof(struct fb_videomode));
1853 var = info->var;
1854#ifdef CONFIG_FB_I810_I2C
1855 i810_create_i2c_busses(par);
1856
1857 for (i = 0; i < 3; i++) {
1858 err = i810_probe_i2c_connector(info, &par->edid, i+1);
1859 if (!err)
1860 break;
1861 }
1862
1863 if (!err)
1864 printk("i810fb_init_pci: DDC probe successful\n");
1865
1866 fb_edid_to_monspecs(par->edid, specs);
1867
1868 if (specs->modedb == NULL)
1869 printk("i810fb_init_pci: Unable to get Mode Database\n");
1870
1871 fb_videomode_to_modelist(specs->modedb, specs->modedb_len,
1872 &info->modelist);
1873 if (specs->modedb != NULL) {
1874 if (xres && yres) {
1875 struct fb_videomode *m;
1876
1877 if ((m = fb_find_best_mode(&var, &info->modelist))) {
1878 mode = *m;
1879 found = 1;
1880 }
1881 }
1882
1883 if (!found && specs->misc & FB_MISC_1ST_DETAIL) {
1884 for (i = 0; i < specs->modedb_len; i++) {
1885 if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
1886 mode = specs->modedb[i];
1887 found = 1;
1888 break;
1889 }
1890 }
1891 }
1892
1893 if (!found) {
1894 mode = specs->modedb[0];
1895 found = 1;
1896 }
1897
1898 fb_videomode_to_var(&var, &mode);
1899 }
1900#endif
1901 if (mode_option)
1902 fb_find_mode(&var, info, mode_option, specs->modedb,
1903 specs->modedb_len, (found) ? &mode : NULL,
1904 info->var.bits_per_pixel);
1905
1906 info->var = var;
1907 fb_destroy_modedb(specs->modedb);
1908 specs->modedb = NULL;
1909}
1910
1817#ifndef MODULE 1911#ifndef MODULE
1818static int __init i810fb_setup(char *options) 1912static int __devinit i810fb_setup(char *options)
1819{ 1913{
1820 char *this_opt, *suffix = NULL; 1914 char *this_opt, *suffix = NULL;
1821 1915
@@ -1827,8 +1921,8 @@ static int __init i810fb_setup(char *options)
1827 mtrr = 1; 1921 mtrr = 1;
1828 else if (!strncmp(this_opt, "accel", 5)) 1922 else if (!strncmp(this_opt, "accel", 5))
1829 accel = 1; 1923 accel = 1;
1830 else if (!strncmp(this_opt, "ext_vga", 7)) 1924 else if (!strncmp(this_opt, "extvga", 6))
1831 ext_vga = 1; 1925 extvga = 1;
1832 else if (!strncmp(this_opt, "sync", 4)) 1926 else if (!strncmp(this_opt, "sync", 4))
1833 sync = 1; 1927 sync = 1;
1834 else if (!strncmp(this_opt, "vram:", 5)) 1928 else if (!strncmp(this_opt, "vram:", 5))
@@ -1857,6 +1951,8 @@ static int __init i810fb_setup(char *options)
1857 vsync2 = simple_strtoul(this_opt+7, NULL, 0); 1951 vsync2 = simple_strtoul(this_opt+7, NULL, 0);
1858 else if (!strncmp(this_opt, "dcolor", 6)) 1952 else if (!strncmp(this_opt, "dcolor", 6))
1859 dcolor = 1; 1953 dcolor = 1;
1954 else
1955 mode_option = this_opt;
1860 } 1956 }
1861 return 0; 1957 return 0;
1862} 1958}
@@ -1867,6 +1963,7 @@ static int __devinit i810fb_init_pci (struct pci_dev *dev,
1867{ 1963{
1868 struct fb_info *info; 1964 struct fb_info *info;
1869 struct i810fb_par *par = NULL; 1965 struct i810fb_par *par = NULL;
1966 struct fb_videomode mode;
1870 int i, err = -1, vfreq, hfreq, pixclock; 1967 int i, err = -1, vfreq, hfreq, pixclock;
1871 1968
1872 i = 0; 1969 i = 0;
@@ -1875,7 +1972,7 @@ static int __devinit i810fb_init_pci (struct pci_dev *dev,
1875 if (!info) 1972 if (!info)
1876 return -ENOMEM; 1973 return -ENOMEM;
1877 1974
1878 par = (struct i810fb_par *) info->par; 1975 par = info->par;
1879 par->dev = dev; 1976 par->dev = dev;
1880 1977
1881 if (!(info->pixmap.addr = kmalloc(8*1024, GFP_KERNEL))) { 1978 if (!(info->pixmap.addr = kmalloc(8*1024, GFP_KERNEL))) {
@@ -1906,15 +2003,20 @@ static int __devinit i810fb_init_pci (struct pci_dev *dev,
1906 info->fbops = &par->i810fb_ops; 2003 info->fbops = &par->i810fb_ops;
1907 info->pseudo_palette = par->pseudo_palette; 2004 info->pseudo_palette = par->pseudo_palette;
1908 fb_alloc_cmap(&info->cmap, 256, 0); 2005 fb_alloc_cmap(&info->cmap, 256, 0);
2006 i810fb_find_init_mode(info);
1909 2007
1910 if ((err = info->fbops->fb_check_var(&info->var, info))) { 2008 if ((err = info->fbops->fb_check_var(&info->var, info))) {
1911 i810fb_release_resource(info, par); 2009 i810fb_release_resource(info, par);
1912 return err; 2010 return err;
1913 } 2011 }
2012
2013 fb_var_to_videomode(&mode, &info->var);
2014 fb_add_videomode(&mode, &info->modelist);
1914 encode_fix(&info->fix, info); 2015 encode_fix(&info->fix, info);
1915 2016
1916 i810fb_init_ringbuffer(info); 2017 i810fb_init_ringbuffer(info);
1917 err = register_framebuffer(info); 2018 err = register_framebuffer(info);
2019
1918 if (err < 0) { 2020 if (err < 0) {
1919 i810fb_release_resource(info, par); 2021 i810fb_release_resource(info, par);
1920 printk("i810fb_init: cannot register framebuffer device\n"); 2022 printk("i810fb_init: cannot register framebuffer device\n");
@@ -1953,6 +2055,8 @@ static void i810fb_release_resource(struct fb_info *info,
1953 struct gtt_data *gtt = &par->i810_gtt; 2055 struct gtt_data *gtt = &par->i810_gtt;
1954 unset_mtrr(par); 2056 unset_mtrr(par);
1955 2057
2058 i810_delete_i2c_busses(par);
2059
1956 if (par->i810_gtt.i810_cursor_memory) 2060 if (par->i810_gtt.i810_cursor_memory)
1957 agp_free_memory(gtt->i810_cursor_memory); 2061 agp_free_memory(gtt->i810_cursor_memory);
1958 if (par->i810_gtt.i810_fb_memory) 2062 if (par->i810_gtt.i810_fb_memory)
@@ -1962,7 +2066,8 @@ static void i810fb_release_resource(struct fb_info *info,
1962 iounmap(par->mmio_start_virtual); 2066 iounmap(par->mmio_start_virtual);
1963 if (par->aperture.virtual) 2067 if (par->aperture.virtual)
1964 iounmap(par->aperture.virtual); 2068 iounmap(par->aperture.virtual);
1965 2069 if (par->edid)
2070 kfree(par->edid);
1966 if (par->res_flags & FRAMEBUFFER_REQ) 2071 if (par->res_flags & FRAMEBUFFER_REQ)
1967 release_mem_region(par->aperture.physical, 2072 release_mem_region(par->aperture.physical,
1968 par->aperture.size); 2073 par->aperture.size);
@@ -1988,7 +2093,7 @@ static void __exit i810fb_remove_pci(struct pci_dev *dev)
1988} 2093}
1989 2094
1990#ifndef MODULE 2095#ifndef MODULE
1991static int __init i810fb_init(void) 2096static int __devinit i810fb_init(void)
1992{ 2097{
1993 char *option = NULL; 2098 char *option = NULL;
1994 2099
@@ -2006,7 +2111,7 @@ static int __init i810fb_init(void)
2006 2111
2007#ifdef MODULE 2112#ifdef MODULE
2008 2113
2009static int __init i810fb_init(void) 2114static int __devinit i810fb_init(void)
2010{ 2115{
2011 hsync1 *= 1000; 2116 hsync1 *= 1000;
2012 hsync2 *= 1000; 2117 hsync2 *= 1000;
@@ -2046,14 +2151,16 @@ module_param(accel, bool, 0);
2046MODULE_PARM_DESC(accel, "Use Acceleration (BLIT) engine (default = 0)"); 2151MODULE_PARM_DESC(accel, "Use Acceleration (BLIT) engine (default = 0)");
2047module_param(mtrr, bool, 0); 2152module_param(mtrr, bool, 0);
2048MODULE_PARM_DESC(mtrr, "Use MTRR (default = 0)"); 2153MODULE_PARM_DESC(mtrr, "Use MTRR (default = 0)");
2049module_param(ext_vga, bool, 0); 2154module_param(extvga, bool, 0);
2050MODULE_PARM_DESC(ext_vga, "Enable external VGA connector (default = 0)"); 2155MODULE_PARM_DESC(extvga, "Enable external VGA connector (default = 0)");
2051module_param(sync, bool, 0); 2156module_param(sync, bool, 0);
2052MODULE_PARM_DESC(sync, "wait for accel engine to finish drawing" 2157MODULE_PARM_DESC(sync, "wait for accel engine to finish drawing"
2053 " (default = 0)"); 2158 " (default = 0)");
2054module_param(dcolor, bool, 0); 2159module_param(dcolor, bool, 0);
2055MODULE_PARM_DESC(dcolor, "use DirectColor visuals" 2160MODULE_PARM_DESC(dcolor, "use DirectColor visuals"
2056 " (default = 0 = TrueColor)"); 2161 " (default = 0 = TrueColor)");
2162module_param(mode_option, charp, 0);
2163MODULE_PARM_DESC(mode_option, "Specify initial video mode");
2057 2164
2058MODULE_AUTHOR("Tony A. Daplas"); 2165MODULE_AUTHOR("Tony A. Daplas");
2059MODULE_DESCRIPTION("Framebuffer device for the Intel 810/815 and" 2166MODULE_DESCRIPTION("Framebuffer device for the Intel 810/815 and"
diff --git a/drivers/video/i810/i810_main.h b/drivers/video/i810/i810_main.h
index 43b4297b4d..06072a6466 100644
--- a/drivers/video/i810/i810_main.h
+++ b/drivers/video/i810/i810_main.h
@@ -83,6 +83,22 @@ extern int i810fb_sync (struct fb_info *p);
83extern void i810fb_init_ringbuffer(struct fb_info *info); 83extern void i810fb_init_ringbuffer(struct fb_info *info);
84extern void i810fb_load_front (u32 offset, struct fb_info *info); 84extern void i810fb_load_front (u32 offset, struct fb_info *info);
85 85
86#ifdef CONFIG_FB_I810_I2C
87/* I2C */
88extern int i810_probe_i2c_connector(struct fb_info *info, u8 **out_edid,
89 int conn);
90extern void i810_create_i2c_busses(struct i810fb_par *par);
91extern void i810_delete_i2c_busses(struct i810fb_par *par);
92#else
93static inline int i810_probe_i2c_connector(struct fb_info *info, u8 **out_edid,
94 int conn)
95{
96 return 1;
97}
98static inline void i810_create_i2c_busses(struct i810fb_par *par) { }
99static inline void i810_delete_i2c_busses(struct i810fb_par *par) { }
100#endif
101
86/* Conditionals */ 102/* Conditionals */
87#ifdef CONFIG_X86 103#ifdef CONFIG_X86
88inline void flush_cache(void) 104inline void flush_cache(void)
diff --git a/drivers/video/intelfb/intelfb.h b/drivers/video/intelfb/intelfb.h
index 6680ec9ba6..011e116265 100644
--- a/drivers/video/intelfb/intelfb.h
+++ b/drivers/video/intelfb/intelfb.h
@@ -234,7 +234,6 @@ struct intelfb_info {
234 234
235 /* palette */ 235 /* palette */
236 u32 pseudo_palette[17]; 236 u32 pseudo_palette[17];
237 struct { u8 red, green, blue, pad; } palette[256];
238 237
239 /* chip info */ 238 /* chip info */
240 int pci_chipset; 239 int pci_chipset;
diff --git a/drivers/video/intelfb/intelfbdrv.c b/drivers/video/intelfb/intelfbdrv.c
index a112a17868..bf62e6ed03 100644
--- a/drivers/video/intelfb/intelfbdrv.c
+++ b/drivers/video/intelfb/intelfbdrv.c
@@ -117,14 +117,10 @@
117#include <linux/slab.h> 117#include <linux/slab.h>
118#include <linux/delay.h> 118#include <linux/delay.h>
119#include <linux/fb.h> 119#include <linux/fb.h>
120#include <linux/console.h>
121#include <linux/selection.h>
122#include <linux/ioport.h> 120#include <linux/ioport.h>
123#include <linux/init.h> 121#include <linux/init.h>
124#include <linux/pci.h> 122#include <linux/pci.h>
125#include <linux/vmalloc.h> 123#include <linux/vmalloc.h>
126#include <linux/kd.h>
127#include <linux/vt_kern.h>
128#include <linux/pagemap.h> 124#include <linux/pagemap.h>
129#include <linux/version.h> 125#include <linux/version.h>
130 126
@@ -242,7 +238,7 @@ static int voffset = 48;
242static char *mode = NULL; 238static char *mode = NULL;
243 239
244module_param(accel, bool, S_IRUGO); 240module_param(accel, bool, S_IRUGO);
245MODULE_PARM_DESC(accel, "Enable console acceleration"); 241MODULE_PARM_DESC(accel, "Enable hardware acceleration");
246module_param(vram, int, S_IRUGO); 242module_param(vram, int, S_IRUGO);
247MODULE_PARM_DESC(vram, "System RAM to allocate to framebuffer in MiB"); 243MODULE_PARM_DESC(vram, "System RAM to allocate to framebuffer in MiB");
248module_param(voffset, int, S_IRUGO); 244module_param(voffset, int, S_IRUGO);
@@ -498,7 +494,7 @@ intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
498{ 494{
499 struct fb_info *info; 495 struct fb_info *info;
500 struct intelfb_info *dinfo; 496 struct intelfb_info *dinfo;
501 int i, j, err, dvo; 497 int i, err, dvo;
502 int aperture_size, stolen_size; 498 int aperture_size, stolen_size;
503 struct agp_kern_info gtt_info; 499 struct agp_kern_info gtt_info;
504 int agp_memtype; 500 int agp_memtype;
@@ -845,13 +841,6 @@ intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
845 if (bailearly == 5) 841 if (bailearly == 5)
846 bailout(dinfo); 842 bailout(dinfo);
847 843
848 for (i = 0; i < 16; i++) {
849 j = color_table[i];
850 dinfo->palette[i].red = default_red[j];
851 dinfo->palette[i].green = default_grn[j];
852 dinfo->palette[i].blue = default_blu[j];
853 }
854
855 if (bailearly == 6) 844 if (bailearly == 6)
856 bailout(dinfo); 845 bailout(dinfo);
857 846
@@ -1363,10 +1352,6 @@ intelfb_setcolreg(unsigned regno, unsigned red, unsigned green,
1363 green >>= 8; 1352 green >>= 8;
1364 blue >>= 8; 1353 blue >>= 8;
1365 1354
1366 dinfo->palette[regno].red = red;
1367 dinfo->palette[regno].green = green;
1368 dinfo->palette[regno].blue = blue;
1369
1370 intelfbhw_setcolreg(dinfo, regno, red, green, blue, 1355 intelfbhw_setcolreg(dinfo, regno, red, green, blue,
1371 transp); 1356 transp);
1372 } 1357 }
@@ -1499,7 +1484,7 @@ intelfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1499#endif 1484#endif
1500 1485
1501 if (!dinfo->hwcursor) 1486 if (!dinfo->hwcursor)
1502 return soft_cursor(info, cursor); 1487 return -ENXIO;
1503 1488
1504 intelfbhw_cursor_hide(dinfo); 1489 intelfbhw_cursor_hide(dinfo);
1505 1490
diff --git a/drivers/video/intelfb/intelfbhw.c b/drivers/video/intelfb/intelfbhw.c
index f5bed581dc..5bafc3c54d 100644
--- a/drivers/video/intelfb/intelfbhw.c
+++ b/drivers/video/intelfb/intelfbhw.c
@@ -29,14 +29,10 @@
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/fb.h> 31#include <linux/fb.h>
32#include <linux/console.h>
33#include <linux/selection.h>
34#include <linux/ioport.h> 32#include <linux/ioport.h>
35#include <linux/init.h> 33#include <linux/init.h>
36#include <linux/pci.h> 34#include <linux/pci.h>
37#include <linux/vmalloc.h> 35#include <linux/vmalloc.h>
38#include <linux/kd.h>
39#include <linux/vt_kern.h>
40#include <linux/pagemap.h> 36#include <linux/pagemap.h>
41#include <linux/version.h> 37#include <linux/version.h>
42 38
diff --git a/drivers/video/matrox/matroxfb_misc.c b/drivers/video/matrox/matroxfb_misc.c
index a18dd024fc..d9d3e9f6c0 100644
--- a/drivers/video/matrox/matroxfb_misc.c
+++ b/drivers/video/matrox/matroxfb_misc.c
@@ -68,6 +68,9 @@
68 * "David C. Hansen" <haveblue@us.ibm.com> 68 * "David C. Hansen" <haveblue@us.ibm.com>
69 * Fixes 69 * Fixes
70 * 70 *
71 * "Ian Romanick" <idr@us.ibm.com>
72 * Find PInS data in BIOS on PowerPC systems.
73 *
71 * (following author is not in any relation with this code, but his code 74 * (following author is not in any relation with this code, but his code
72 * is included in this driver) 75 * is included in this driver)
73 * 76 *
@@ -496,10 +499,35 @@ static void parse_bios(unsigned char __iomem* vbios, struct matrox_bios* bd) {
496 get_bios_version(vbios, bd); 499 get_bios_version(vbios, bd);
497 get_bios_output(vbios, bd); 500 get_bios_output(vbios, bd);
498 get_bios_tvout(vbios, bd); 501 get_bios_tvout(vbios, bd);
502#if defined(__powerpc__)
503 /* On PowerPC cards, the PInS offset isn't stored at the end of the
504 * BIOS image. Instead, you must search the entire BIOS image for
505 * the magic PInS signature.
506 *
507 * This actually applies to all OpenFirmware base cards. Since these
508 * cards could be put in a MIPS or SPARC system, should the condition
509 * be something different?
510 */
511 for ( pins_offset = 0 ; pins_offset <= 0xFF80 ; pins_offset++ ) {
512 unsigned char header[3];
513
514 header[0] = readb(vbios + pins_offset);
515 header[1] = readb(vbios + pins_offset + 1);
516 header[2] = readb(vbios + pins_offset + 2);
517 if ( (header[0] == 0x2E) && (header[1] == 0x41)
518 && ((header[2] == 0x40) || (header[2] == 0x80)) ) {
519 printk(KERN_INFO "PInS data found at offset %u\n",
520 pins_offset);
521 get_pins(vbios + pins_offset, bd);
522 break;
523 }
524 }
525#else
499 pins_offset = readb(vbios + 0x7FFC) | (readb(vbios + 0x7FFD) << 8); 526 pins_offset = readb(vbios + 0x7FFC) | (readb(vbios + 0x7FFD) << 8);
500 if (pins_offset <= 0xFF80) { 527 if (pins_offset <= 0xFF80) {
501 get_pins(vbios + pins_offset, bd); 528 get_pins(vbios + pins_offset, bd);
502 } 529 }
530#endif
503} 531}
504 532
505#define get_u16(x) (le16_to_cpu(get_unaligned((__u16*)(x)))) 533#define get_u16(x) (le16_to_cpu(get_unaligned((__u16*)(x))))
@@ -755,6 +783,8 @@ void matroxfb_read_pins(WPMINFO2) {
755 } 783 }
756#endif 784#endif
757 matroxfb_set_limits(PMINFO &ACCESS_FBINFO(bios)); 785 matroxfb_set_limits(PMINFO &ACCESS_FBINFO(bios));
786 printk(KERN_INFO "PInS memtype = %u\n",
787 (ACCESS_FBINFO(values).reg.opt & 0x1C00) >> 10);
758} 788}
759 789
760EXPORT_SYMBOL(matroxfb_DAC_in); 790EXPORT_SYMBOL(matroxfb_DAC_in);
diff --git a/drivers/video/modedb.c b/drivers/video/modedb.c
index 3edc9f4934..47516c44a3 100644
--- a/drivers/video/modedb.c
+++ b/drivers/video/modedb.c
@@ -456,12 +456,22 @@ static int fb_try_mode(struct fb_var_screeninfo *var, struct fb_info *info,
456 * 456 *
457 * Valid mode specifiers for @mode_option: 457 * Valid mode specifiers for @mode_option:
458 * 458 *
459 * <xres>x<yres>[-<bpp>][@<refresh>] or 459 * <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m] or
460 * <name>[-<bpp>][@<refresh>] 460 * <name>[-<bpp>][@<refresh>]
461 * 461 *
462 * with <xres>, <yres>, <bpp> and <refresh> decimal numbers and 462 * with <xres>, <yres>, <bpp> and <refresh> decimal numbers and
463 * <name> a string. 463 * <name> a string.
464 * 464 *
465 * If 'M' is present after yres (and before refresh/bpp if present),
466 * the function will compute the timings using VESA(tm) Coordinated
467 * Video Timings (CVT). If 'R' is present after 'M', will compute with
468 * reduced blanking (for flatpanels). If 'i' is present, compute
469 * interlaced mode. If 'm' is present, add margins equal to 1.8%
470 * of xres rounded down to 8 pixels, and 1.8% of yres. The char
471 * 'i' and 'm' must be after 'M' and 'R'. Example:
472 *
473 * 1024x768MR-8@60m - Reduced blank with margins at 60Hz.
474 *
465 * NOTE: The passed struct @var is _not_ cleared! This allows you 475 * NOTE: The passed struct @var is _not_ cleared! This allows you
466 * to supply values for e.g. the grayscale and accel_flags fields. 476 * to supply values for e.g. the grayscale and accel_flags fields.
467 * 477 *
@@ -495,7 +505,7 @@ int fb_find_mode(struct fb_var_screeninfo *var,
495 unsigned int namelen = strlen(name); 505 unsigned int namelen = strlen(name);
496 int res_specified = 0, bpp_specified = 0, refresh_specified = 0; 506 int res_specified = 0, bpp_specified = 0, refresh_specified = 0;
497 unsigned int xres = 0, yres = 0, bpp = default_bpp, refresh = 0; 507 unsigned int xres = 0, yres = 0, bpp = default_bpp, refresh = 0;
498 int yres_specified = 0; 508 int yres_specified = 0, cvt = 0, rb = 0, interlace = 0, margins = 0;
499 u32 best, diff; 509 u32 best, diff;
500 510
501 for (i = namelen-1; i >= 0; i--) { 511 for (i = namelen-1; i >= 0; i--) {
@@ -506,6 +516,8 @@ int fb_find_mode(struct fb_var_screeninfo *var,
506 !yres_specified) { 516 !yres_specified) {
507 refresh = my_atoi(&name[i+1]); 517 refresh = my_atoi(&name[i+1]);
508 refresh_specified = 1; 518 refresh_specified = 1;
519 if (cvt || rb)
520 cvt = 0;
509 } else 521 } else
510 goto done; 522 goto done;
511 break; 523 break;
@@ -514,6 +526,8 @@ int fb_find_mode(struct fb_var_screeninfo *var,
514 if (!bpp_specified && !yres_specified) { 526 if (!bpp_specified && !yres_specified) {
515 bpp = my_atoi(&name[i+1]); 527 bpp = my_atoi(&name[i+1]);
516 bpp_specified = 1; 528 bpp_specified = 1;
529 if (cvt || rb)
530 cvt = 0;
517 } else 531 } else
518 goto done; 532 goto done;
519 break; 533 break;
@@ -526,6 +540,22 @@ int fb_find_mode(struct fb_var_screeninfo *var,
526 break; 540 break;
527 case '0'...'9': 541 case '0'...'9':
528 break; 542 break;
543 case 'M':
544 if (!yres_specified)
545 cvt = 1;
546 break;
547 case 'R':
548 if (!cvt)
549 rb = 1;
550 break;
551 case 'm':
552 if (!cvt)
553 margins = 1;
554 break;
555 case 'i':
556 if (!cvt)
557 interlace = 1;
558 break;
529 default: 559 default:
530 goto done; 560 goto done;
531 } 561 }
@@ -535,6 +565,34 @@ int fb_find_mode(struct fb_var_screeninfo *var,
535 res_specified = 1; 565 res_specified = 1;
536 } 566 }
537done: 567done:
568 if (cvt) {
569 struct fb_videomode cvt_mode;
570 int ret;
571
572 DPRINTK("CVT mode %dx%d@%dHz%s%s%s\n", xres, yres,
573 (refresh) ? refresh : 60, (rb) ? " reduced blanking" :
574 "", (margins) ? " with margins" : "", (interlace) ?
575 " interlaced" : "");
576
577 cvt_mode.xres = xres;
578 cvt_mode.yres = yres;
579 cvt_mode.refresh = (refresh) ? refresh : 60;
580
581 if (interlace)
582 cvt_mode.vmode |= FB_VMODE_INTERLACED;
583 else
584 cvt_mode.vmode &= ~FB_VMODE_INTERLACED;
585
586 ret = fb_find_mode_cvt(&cvt_mode, margins, rb);
587
588 if (!ret && !fb_try_mode(var, info, &cvt_mode, bpp)) {
589 DPRINTK("modedb CVT: CVT mode ok\n");
590 return 1;
591 }
592
593 DPRINTK("CVT mode invalid, getting mode from database\n");
594 }
595
538 DPRINTK("Trying specified video mode%s %ix%i\n", 596 DPRINTK("Trying specified video mode%s %ix%i\n",
539 refresh_specified ? "" : " (ignoring refresh rate)", xres, yres); 597 refresh_specified ? "" : " (ignoring refresh rate)", xres, yres);
540 598
diff --git a/drivers/video/nvidia/nv_i2c.c b/drivers/video/nvidia/nv_i2c.c
index 1a91bffdda..ace484fa61 100644
--- a/drivers/video/nvidia/nv_i2c.c
+++ b/drivers/video/nvidia/nv_i2c.c
@@ -194,8 +194,9 @@ static u8 *nvidia_do_probe_i2c_edid(struct nvidia_i2c_chan *chan)
194 return NULL; 194 return NULL;
195} 195}
196 196
197int nvidia_probe_i2c_connector(struct nvidia_par *par, int conn, u8 **out_edid) 197int nvidia_probe_i2c_connector(struct fb_info *info, int conn, u8 **out_edid)
198{ 198{
199 struct nvidia_par *par = info->par;
199 u8 *edid = NULL; 200 u8 *edid = NULL;
200 int i; 201 int i;
201 202
@@ -205,10 +206,17 @@ int nvidia_probe_i2c_connector(struct nvidia_par *par, int conn, u8 **out_edid)
205 if (edid) 206 if (edid)
206 break; 207 break;
207 } 208 }
209
210 if (!edid && conn == 1) {
211 /* try to get from firmware */
212 edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
213 if (edid)
214 memcpy(edid, fb_firmware_edid(info->device),
215 EDID_LENGTH);
216 }
217
208 if (out_edid) 218 if (out_edid)
209 *out_edid = edid; 219 *out_edid = edid;
210 if (!edid)
211 return 1;
212 220
213 return 0; 221 return (edid) ? 0 : 1;
214} 222}
diff --git a/drivers/video/nvidia/nv_local.h b/drivers/video/nvidia/nv_local.h
index 9da320986f..afee284fc7 100644
--- a/drivers/video/nvidia/nv_local.h
+++ b/drivers/video/nvidia/nv_local.h
@@ -95,6 +95,7 @@
95 95
96#define READ_GET(par) (NV_RD32(&(par)->FIFO[0x0011], 0) >> 2) 96#define READ_GET(par) (NV_RD32(&(par)->FIFO[0x0011], 0) >> 2)
97 97
98#ifdef __LITTLE_ENDIAN
98#define reverse_order(l) \ 99#define reverse_order(l) \
99do { \ 100do { \
100 u8 *a = (u8 *)(l); \ 101 u8 *a = (u8 *)(l); \
@@ -103,5 +104,8 @@ do { \
103 *a = byte_rev[*a], a++; \ 104 *a = byte_rev[*a], a++; \
104 *a = byte_rev[*a]; \ 105 *a = byte_rev[*a]; \
105} while(0) 106} while(0)
107#else
108#define reverse_order(l)
109#endif /* __LITTLE_ENDIAN */
106 110
107#endif /* __NV_LOCAL_H__ */ 111#endif /* __NV_LOCAL_H__ */
diff --git a/drivers/video/nvidia/nv_of.c b/drivers/video/nvidia/nv_of.c
index 7d12eb8531..4fa2cf9a8a 100644
--- a/drivers/video/nvidia/nv_of.c
+++ b/drivers/video/nvidia/nv_of.c
@@ -30,8 +30,9 @@
30void nvidia_create_i2c_busses(struct nvidia_par *par) {} 30void nvidia_create_i2c_busses(struct nvidia_par *par) {}
31void nvidia_delete_i2c_busses(struct nvidia_par *par) {} 31void nvidia_delete_i2c_busses(struct nvidia_par *par) {}
32 32
33int nvidia_probe_i2c_connector(struct nvidia_par *par, int conn, u8 **out_edid) 33int nvidia_probe_i2c_connector(struct fb_info *info, int conn, u8 **out_edid)
34{ 34{
35 struct nvidia_par *par = info->par;
35 struct device_node *dp; 36 struct device_node *dp;
36 unsigned char *pedid = NULL; 37 unsigned char *pedid = NULL;
37 unsigned char *disptype = NULL; 38 unsigned char *disptype = NULL;
diff --git a/drivers/video/nvidia/nv_proto.h b/drivers/video/nvidia/nv_proto.h
index 42847ce1b8..cac44fc7f5 100644
--- a/drivers/video/nvidia/nv_proto.h
+++ b/drivers/video/nvidia/nv_proto.h
@@ -34,7 +34,7 @@ void NVLockUnlock(struct nvidia_par *par, int);
34#if defined(CONFIG_FB_NVIDIA_I2C) || defined (CONFIG_PPC_OF) 34#if defined(CONFIG_FB_NVIDIA_I2C) || defined (CONFIG_PPC_OF)
35void nvidia_create_i2c_busses(struct nvidia_par *par); 35void nvidia_create_i2c_busses(struct nvidia_par *par);
36void nvidia_delete_i2c_busses(struct nvidia_par *par); 36void nvidia_delete_i2c_busses(struct nvidia_par *par);
37int nvidia_probe_i2c_connector(struct nvidia_par *par, int conn, 37int nvidia_probe_i2c_connector(struct fb_info *info, int conn,
38 u8 ** out_edid); 38 u8 ** out_edid);
39#else 39#else
40#define nvidia_create_i2c_busses(...) 40#define nvidia_create_i2c_busses(...)
diff --git a/drivers/video/nvidia/nv_setup.c b/drivers/video/nvidia/nv_setup.c
index 0bbdca2e0f..11c84178f4 100644
--- a/drivers/video/nvidia/nv_setup.c
+++ b/drivers/video/nvidia/nv_setup.c
@@ -401,7 +401,7 @@ void NVCommonSetup(struct fb_info *info)
401 nvidia_create_i2c_busses(par); 401 nvidia_create_i2c_busses(par);
402 if (!par->twoHeads) { 402 if (!par->twoHeads) {
403 par->CRTCnumber = 0; 403 par->CRTCnumber = 0;
404 nvidia_probe_i2c_connector(par, 1, &edidA); 404 nvidia_probe_i2c_connector(info, 1, &edidA);
405 if (edidA && !fb_parse_edid(edidA, &var)) { 405 if (edidA && !fb_parse_edid(edidA, &var)) {
406 printk("nvidiafb: EDID found from BUS1\n"); 406 printk("nvidiafb: EDID found from BUS1\n");
407 monA = &monitorA; 407 monA = &monitorA;
@@ -488,14 +488,14 @@ void NVCommonSetup(struct fb_info *info)
488 oldhead = NV_RD32(par->PCRTC0, 0x00000860); 488 oldhead = NV_RD32(par->PCRTC0, 0x00000860);
489 NV_WR32(par->PCRTC0, 0x00000860, oldhead | 0x00000010); 489 NV_WR32(par->PCRTC0, 0x00000860, oldhead | 0x00000010);
490 490
491 nvidia_probe_i2c_connector(par, 1, &edidA); 491 nvidia_probe_i2c_connector(info, 1, &edidA);
492 if (edidA && !fb_parse_edid(edidA, &var)) { 492 if (edidA && !fb_parse_edid(edidA, &var)) {
493 printk("nvidiafb: EDID found from BUS1\n"); 493 printk("nvidiafb: EDID found from BUS1\n");
494 monA = &monitorA; 494 monA = &monitorA;
495 fb_edid_to_monspecs(edidA, monA); 495 fb_edid_to_monspecs(edidA, monA);
496 } 496 }
497 497
498 nvidia_probe_i2c_connector(par, 2, &edidB); 498 nvidia_probe_i2c_connector(info, 2, &edidB);
499 if (edidB && !fb_parse_edid(edidB, &var)) { 499 if (edidB && !fb_parse_edid(edidB, &var)) {
500 printk("nvidiafb: EDID found from BUS2\n"); 500 printk("nvidiafb: EDID found from BUS2\n");
501 monB = &monitorB; 501 monB = &monitorB;
diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
index 30f80c23f9..3620de0f25 100644
--- a/drivers/video/nvidia/nvidia.c
+++ b/drivers/video/nvidia/nvidia.c
@@ -658,7 +658,7 @@ static int nvidia_calc_regs(struct fb_info *info)
658{ 658{
659 struct nvidia_par *par = info->par; 659 struct nvidia_par *par = info->par;
660 struct _riva_hw_state *state = &par->ModeReg; 660 struct _riva_hw_state *state = &par->ModeReg;
661 int i, depth = fb_get_color_depth(&info->var); 661 int i, depth = fb_get_color_depth(&info->var, &info->fix);
662 int h_display = info->var.xres / 8 - 1; 662 int h_display = info->var.xres / 8 - 1;
663 int h_start = (info->var.xres + info->var.right_margin) / 8 - 1; 663 int h_start = (info->var.xres + info->var.right_margin) / 8 - 1;
664 int h_end = (info->var.xres + info->var.right_margin + 664 int h_end = (info->var.xres + info->var.right_margin +
@@ -893,7 +893,7 @@ static int nvidiafb_cursor(struct fb_info *info, struct fb_cursor *cursor)
893 int i, set = cursor->set; 893 int i, set = cursor->set;
894 u16 fg, bg; 894 u16 fg, bg;
895 895
896 if (cursor->image.width > MAX_CURS || cursor->image.height > MAX_CURS) 896 if (!hwcur || cursor->image.width > MAX_CURS || cursor->image.height > MAX_CURS)
897 return -ENXIO; 897 return -ENXIO;
898 898
899 NVShowHideCursor(par, 0); 899 NVShowHideCursor(par, 0);
@@ -978,6 +978,9 @@ static int nvidiafb_set_par(struct fb_info *info)
978 !par->twoHeads) 978 !par->twoHeads)
979 par->FPDither = 0; 979 par->FPDither = 0;
980 980
981 info->fix.visual = (info->var.bits_per_pixel == 8) ?
982 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
983
981 nvidia_init_vga(info); 984 nvidia_init_vga(info);
982 nvidia_calc_regs(info); 985 nvidia_calc_regs(info);
983 nvidia_write_regs(par); 986 nvidia_write_regs(par);
@@ -992,9 +995,6 @@ static int nvidiafb_set_par(struct fb_info *info)
992 NVWriteCrtc(par, 0x11, 0x00); 995 NVWriteCrtc(par, 0x11, 0x00);
993 info->fix.line_length = (info->var.xres_virtual * 996 info->fix.line_length = (info->var.xres_virtual *
994 info->var.bits_per_pixel) >> 3; 997 info->var.bits_per_pixel) >> 3;
995 info->fix.visual = (info->var.bits_per_pixel == 8) ?
996 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
997
998 if (info->var.accel_flags) { 998 if (info->var.accel_flags) {
999 info->fbops->fb_imageblit = nvidiafb_imageblit; 999 info->fbops->fb_imageblit = nvidiafb_imageblit;
1000 info->fbops->fb_fillrect = nvidiafb_fillrect; 1000 info->fbops->fb_fillrect = nvidiafb_fillrect;
@@ -1328,7 +1328,7 @@ static int __devinit nvidia_set_fbinfo(struct fb_info *info)
1328 char buf[16]; 1328 char buf[16];
1329 1329
1330 memset(buf, 0, 16); 1330 memset(buf, 0, 16);
1331 snprintf(buf, 15, "%dx%d", par->fpWidth, par->fpHeight); 1331 snprintf(buf, 15, "%dx%dMR", par->fpWidth, par->fpHeight);
1332 fb_find_mode(&nvidiafb_default_var, info, buf, specs->modedb, 1332 fb_find_mode(&nvidiafb_default_var, info, buf, specs->modedb,
1333 specs->modedb_len, &modedb, 8); 1333 specs->modedb_len, &modedb, 8);
1334 } 1334 }
@@ -1356,8 +1356,6 @@ static int __devinit nvidia_set_fbinfo(struct fb_info *info)
1356 info->pixmap.size = 8 * 1024; 1356 info->pixmap.size = 8 * 1024;
1357 info->pixmap.flags = FB_PIXMAP_SYSTEM; 1357 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1358 1358
1359 if (!hwcur)
1360 info->fbops->fb_cursor = soft_cursor;
1361 info->var.accel_flags = (!noaccel); 1359 info->var.accel_flags = (!noaccel);
1362 1360
1363 switch (par->Architecture) { 1361 switch (par->Architecture) {
diff --git a/drivers/video/pxafb.c b/drivers/video/pxafb.c
index 3011281642..34d4dcc032 100644
--- a/drivers/video/pxafb.c
+++ b/drivers/video/pxafb.c
@@ -468,6 +468,36 @@ static inline unsigned int get_pcd(unsigned int pixclock)
468} 468}
469 469
470/* 470/*
471 * Some touchscreens need hsync information from the video driver to
472 * function correctly. We export it here.
473 */
474static inline void set_hsync_time(struct pxafb_info *fbi, unsigned int pcd)
475{
476 unsigned long long htime;
477
478 if ((pcd == 0) || (fbi->fb.var.hsync_len == 0)) {
479 fbi->hsync_time=0;
480 return;
481 }
482
483 htime = (unsigned long long)get_lcdclk_frequency_10khz() * 10000;
484 do_div(htime, pcd * fbi->fb.var.hsync_len);
485 fbi->hsync_time = htime;
486}
487
488unsigned long pxafb_get_hsync_time(struct device *dev)
489{
490 struct pxafb_info *fbi = dev_get_drvdata(dev);
491
492 /* If display is blanked/suspended, hsync isn't active */
493 if (!fbi || (fbi->state != C_ENABLE))
494 return 0;
495
496 return fbi->hsync_time;
497}
498EXPORT_SYMBOL(pxafb_get_hsync_time);
499
500/*
471 * pxafb_activate_var(): 501 * pxafb_activate_var():
472 * Configures LCD Controller based on entries in var parameter. Settings are 502 * Configures LCD Controller based on entries in var parameter. Settings are
473 * only written to the controller if changes were made. 503 * only written to the controller if changes were made.
@@ -631,6 +661,7 @@ static int pxafb_activate_var(struct fb_var_screeninfo *var, struct pxafb_info *
631 fbi->reg_lccr1 = new_regs.lccr1; 661 fbi->reg_lccr1 = new_regs.lccr1;
632 fbi->reg_lccr2 = new_regs.lccr2; 662 fbi->reg_lccr2 = new_regs.lccr2;
633 fbi->reg_lccr3 = new_regs.lccr3; 663 fbi->reg_lccr3 = new_regs.lccr3;
664 set_hsync_time(fbi, pcd);
634 local_irq_restore(flags); 665 local_irq_restore(flags);
635 666
636 /* 667 /*
@@ -907,6 +938,7 @@ pxafb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
907 938
908 case CPUFREQ_POSTCHANGE: 939 case CPUFREQ_POSTCHANGE:
909 pcd = get_pcd(fbi->fb.var.pixclock); 940 pcd = get_pcd(fbi->fb.var.pixclock);
941 set_hsync_time(fbi, pcd);
910 fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) | LCCR3_PixClkDiv(pcd); 942 fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) | LCCR3_PixClkDiv(pcd);
911 set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE); 943 set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
912 break; 944 break;
diff --git a/drivers/video/pxafb.h b/drivers/video/pxafb.h
index de15fec5f8..22c00be786 100644
--- a/drivers/video/pxafb.h
+++ b/drivers/video/pxafb.h
@@ -83,6 +83,8 @@ struct pxafb_info {
83 u_int reg_lccr2; 83 u_int reg_lccr2;
84 u_int reg_lccr3; 84 u_int reg_lccr3;
85 85
86 unsigned long hsync_time;
87
86 volatile u_char state; 88 volatile u_char state;
87 volatile u_char task_state; 89 volatile u_char task_state;
88 struct semaphore ctrlr_sem; 90 struct semaphore ctrlr_sem;
diff --git a/drivers/video/s3c2410fb.c b/drivers/video/s3c2410fb.c
new file mode 100644
index 0000000000..00c0223a35
--- /dev/null
+++ b/drivers/video/s3c2410fb.c
@@ -0,0 +1,915 @@
1/*
2 * linux/drivers/video/s3c2410fb.c
3 * Copyright (c) Arnaud Patard, Ben Dooks
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file COPYING in the main directory of this archive for
7 * more details.
8 *
9 * S3C2410 LCD Controller Frame Buffer Driver
10 * based on skeletonfb.c, sa1100fb.c and others
11 *
12 * ChangeLog
13 * 2005-04-07: Arnaud Patard <arnaud.patard@rtp-net.org>
14 * - u32 state -> pm_message_t state
15 * - S3C2410_{VA,SZ}_LCD -> S3C24XX
16 *
17 * 2005-03-15: Arnaud Patard <arnaud.patard@rtp-net.org>
18 * - Removed the ioctl
19 * - use readl/writel instead of __raw_writel/__raw_readl
20 *
21 * 2004-12-04: Arnaud Patard <arnaud.patard@rtp-net.org>
22 * - Added the possibility to set on or off the
23 * debugging mesaages
24 * - Replaced 0 and 1 by on or off when reading the
25 * /sys files
26 *
27 * 2005-03-23: Ben Dooks <ben-linux@fluff.org>
28 * - added non 16bpp modes
29 * - updated platform information for range of x/y/bpp
30 * - add code to ensure palette is written correctly
31 * - add pixel clock divisor control
32 *
33 * 2004-11-11: Arnaud Patard <arnaud.patard@rtp-net.org>
34 * - Removed the use of currcon as it no more exist
35 * - Added LCD power sysfs interface
36 *
37 * 2004-11-03: Ben Dooks <ben-linux@fluff.org>
38 * - minor cleanups
39 * - add suspend/resume support
40 * - s3c2410fb_setcolreg() not valid in >8bpp modes
41 * - removed last CONFIG_FB_S3C2410_FIXED
42 * - ensure lcd controller stopped before cleanup
43 * - added sysfs interface for backlight power
44 * - added mask for gpio configuration
45 * - ensured IRQs disabled during GPIO configuration
46 * - disable TPAL before enabling video
47 *
48 * 2004-09-20: Arnaud Patard <arnaud.patard@rtp-net.org>
49 * - Suppress command line options
50 *
51 * 2004-09-15: Arnaud Patard <arnaud.patard@rtp-net.org>
52 * - code cleanup
53 *
54 * 2004-09-07: Arnaud Patard <arnaud.patard@rtp-net.org>
55 * - Renamed from h1940fb.c to s3c2410fb.c
56 * - Add support for different devices
57 * - Backlight support
58 *
59 * 2004-09-05: Herbert Pötzl <herbert@13thfloor.at>
60 * - added clock (de-)allocation code
61 * - added fixem fbmem option
62 *
63 * 2004-07-27: Arnaud Patard <arnaud.patard@rtp-net.org>
64 * - code cleanup
65 * - added a forgotten return in h1940fb_init
66 *
67 * 2004-07-19: Herbert Pötzl <herbert@13thfloor.at>
68 * - code cleanup and extended debugging
69 *
70 * 2004-07-15: Arnaud Patard <arnaud.patard@rtp-net.org>
71 * - First version
72 */
73
74#include <linux/module.h>
75#include <linux/kernel.h>
76#include <linux/errno.h>
77#include <linux/string.h>
78#include <linux/mm.h>
79#include <linux/tty.h>
80#include <linux/slab.h>
81#include <linux/delay.h>
82#include <linux/fb.h>
83#include <linux/init.h>
84#include <linux/dma-mapping.h>
85#include <linux/string.h>
86#include <linux/interrupt.h>
87#include <linux/workqueue.h>
88#include <linux/wait.h>
89
90#include <asm/io.h>
91#include <asm/uaccess.h>
92#include <asm/div64.h>
93
94#include <asm/mach/map.h>
95#include <asm/arch/regs-lcd.h>
96#include <asm/arch/regs-gpio.h>
97#include <asm/arch/fb.h>
98#include <asm/hardware/clock.h>
99
100#ifdef CONFIG_PM
101#include <linux/pm.h>
102#endif
103
104#include "s3c2410fb.h"
105
106
107static struct s3c2410fb_mach_info *mach_info;
108
109/* Debugging stuff */
110#ifdef CONFIG_FB_S3C2410_DEBUG
111static int debug = 1;
112#else
113static int debug = 0;
114#endif
115
116#define dprintk(msg...) if (debug) { printk(KERN_DEBUG "s3c2410fb: " msg); }
117
118/* useful functions */
119
120/* s3c2410fb_set_lcdaddr
121 *
122 * initialise lcd controller address pointers
123*/
124
125static void s3c2410fb_set_lcdaddr(struct s3c2410fb_info *fbi)
126{
127 struct fb_var_screeninfo *var = &fbi->fb->var;
128 unsigned long saddr1, saddr2, saddr3;
129
130 saddr1 = fbi->fb->fix.smem_start >> 1;
131 saddr2 = fbi->fb->fix.smem_start;
132 saddr2 += (var->xres * var->yres * var->bits_per_pixel)/8;
133 saddr2>>= 1;
134
135 saddr3 = S3C2410_OFFSIZE(0) | S3C2410_PAGEWIDTH(var->xres);
136
137 dprintk("LCDSADDR1 = 0x%08lx\n", saddr1);
138 dprintk("LCDSADDR2 = 0x%08lx\n", saddr2);
139 dprintk("LCDSADDR3 = 0x%08lx\n", saddr3);
140
141 writel(saddr1, S3C2410_LCDSADDR1);
142 writel(saddr2, S3C2410_LCDSADDR2);
143 writel(saddr3, S3C2410_LCDSADDR3);
144}
145
146/* s3c2410fb_calc_pixclk()
147 *
148 * calculate divisor for clk->pixclk
149*/
150
151static unsigned int s3c2410fb_calc_pixclk(struct s3c2410fb_info *fbi,
152 unsigned long pixclk)
153{
154 unsigned long clk = clk_get_rate(fbi->clk);
155 unsigned long long div;
156
157 /* pixclk is in picoseoncds, our clock is in Hz
158 *
159 * Hz -> picoseconds is / 10^-12
160 */
161
162 div = (unsigned long long)clk * pixclk;
163 do_div(div,1000000UL);
164 do_div(div,1000000UL);
165
166 dprintk("pixclk %ld, divisor is %ld\n", pixclk, (long)div);
167 return div;
168}
169
170/*
171 * s3c2410fb_check_var():
172 * Get the video params out of 'var'. If a value doesn't fit, round it up,
173 * if it's too big, return -EINVAL.
174 *
175 */
176static int s3c2410fb_check_var(struct fb_var_screeninfo *var,
177 struct fb_info *info)
178{
179 struct s3c2410fb_info *fbi = info->par;
180
181 dprintk("check_var(var=%p, info=%p)\n", var, info);
182
183 /* validate x/y resolution */
184
185 if (var->yres > fbi->mach_info->yres.max)
186 var->yres = fbi->mach_info->yres.max;
187 else if (var->yres < fbi->mach_info->yres.min)
188 var->yres = fbi->mach_info->yres.min;
189
190 if (var->xres > fbi->mach_info->xres.max)
191 var->yres = fbi->mach_info->xres.max;
192 else if (var->xres < fbi->mach_info->xres.min)
193 var->xres = fbi->mach_info->xres.min;
194
195 /* validate bpp */
196
197 if (var->bits_per_pixel > fbi->mach_info->bpp.max)
198 var->bits_per_pixel = fbi->mach_info->bpp.max;
199 else if (var->bits_per_pixel < fbi->mach_info->bpp.min)
200 var->bits_per_pixel = fbi->mach_info->bpp.min;
201
202 /* set r/g/b positions */
203
204 if (var->bits_per_pixel == 16) {
205 var->red.offset = 11;
206 var->green.offset = 5;
207 var->blue.offset = 0;
208 var->red.length = 5;
209 var->green.length = 6;
210 var->blue.length = 5;
211 var->transp.length = 0;
212 } else {
213 var->red.length = var->bits_per_pixel;
214 var->red.offset = 0;
215 var->green.length = var->bits_per_pixel;
216 var->green.offset = 0;
217 var->blue.length = var->bits_per_pixel;
218 var->blue.offset = 0;
219 var->transp.length = 0;
220 }
221
222 return 0;
223}
224
225/* s3c2410fb_activate_var
226 *
227 * activate (set) the controller from the given framebuffer
228 * information
229*/
230
231static int s3c2410fb_activate_var(struct s3c2410fb_info *fbi,
232 struct fb_var_screeninfo *var)
233{
234 fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_MODEMASK;
235
236 dprintk("%s: var->xres = %d\n", __FUNCTION__, var->xres);
237 dprintk("%s: var->yres = %d\n", __FUNCTION__, var->yres);
238 dprintk("%s: var->bpp = %d\n", __FUNCTION__, var->bits_per_pixel);
239
240 switch (var->bits_per_pixel) {
241 case 1:
242 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT1BPP;
243 break;
244 case 2:
245 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT2BPP;
246 break;
247 case 4:
248 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT4BPP;
249 break;
250 case 8:
251 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT8BPP;
252 break;
253 case 16:
254 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT16BPP;
255 break;
256 }
257
258 /* check to see if we need to update sync/borders */
259
260 if (!fbi->mach_info->fixed_syncs) {
261 dprintk("setting vert: up=%d, low=%d, sync=%d\n",
262 var->upper_margin, var->lower_margin,
263 var->vsync_len);
264
265 dprintk("setting horz: lft=%d, rt=%d, sync=%d\n",
266 var->left_margin, var->right_margin,
267 var->hsync_len);
268
269 fbi->regs.lcdcon2 =
270 S3C2410_LCDCON2_VBPD(var->upper_margin - 1) |
271 S3C2410_LCDCON2_VFPD(var->lower_margin - 1) |
272 S3C2410_LCDCON2_VSPW(var->vsync_len - 1);
273
274 fbi->regs.lcdcon3 =
275 S3C2410_LCDCON3_HBPD(var->right_margin - 1) |
276 S3C2410_LCDCON3_HFPD(var->left_margin - 1);
277
278 fbi->regs.lcdcon4 &= ~S3C2410_LCDCON4_HSPW(0xff);
279 fbi->regs.lcdcon4 |= S3C2410_LCDCON4_HSPW(var->hsync_len - 1);
280 }
281
282 /* update X/Y info */
283
284 fbi->regs.lcdcon2 &= ~S3C2410_LCDCON2_LINEVAL(0x3ff);
285 fbi->regs.lcdcon2 |= S3C2410_LCDCON2_LINEVAL(var->yres - 1);
286
287 fbi->regs.lcdcon3 &= ~S3C2410_LCDCON3_HOZVAL(0x7ff);
288 fbi->regs.lcdcon3 |= S3C2410_LCDCON3_HOZVAL(var->xres - 1);
289
290 if (var->pixclock > 0) {
291 int clkdiv = s3c2410fb_calc_pixclk(fbi, var->pixclock);
292
293 clkdiv = (clkdiv / 2) -1;
294 if (clkdiv < 0)
295 clkdiv = 0;
296
297 fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_CLKVAL(0x3ff);
298 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_CLKVAL(clkdiv);
299 }
300
301 /* write new registers */
302
303 dprintk("new register set:\n");
304 dprintk("lcdcon[1] = 0x%08lx\n", fbi->regs.lcdcon1);
305 dprintk("lcdcon[2] = 0x%08lx\n", fbi->regs.lcdcon2);
306 dprintk("lcdcon[3] = 0x%08lx\n", fbi->regs.lcdcon3);
307 dprintk("lcdcon[4] = 0x%08lx\n", fbi->regs.lcdcon4);
308 dprintk("lcdcon[5] = 0x%08lx\n", fbi->regs.lcdcon5);
309
310 writel(fbi->regs.lcdcon1 & ~S3C2410_LCDCON1_ENVID, S3C2410_LCDCON1);
311 writel(fbi->regs.lcdcon2, S3C2410_LCDCON2);
312 writel(fbi->regs.lcdcon3, S3C2410_LCDCON3);
313 writel(fbi->regs.lcdcon4, S3C2410_LCDCON4);
314 writel(fbi->regs.lcdcon5, S3C2410_LCDCON5);
315
316 /* set lcd address pointers */
317 s3c2410fb_set_lcdaddr(fbi);
318
319 writel(fbi->regs.lcdcon1, S3C2410_LCDCON1);
320}
321
322
323/*
324 * s3c2410fb_set_par - Optional function. Alters the hardware state.
325 * @info: frame buffer structure that represents a single frame buffer
326 *
327 */
328static int s3c2410fb_set_par(struct fb_info *info)
329{
330 struct s3c2410fb_info *fbi = info->par;
331 struct fb_var_screeninfo *var = &info->var;
332
333 if (var->bits_per_pixel == 16)
334 fbi->fb->fix.visual = FB_VISUAL_TRUECOLOR;
335 else
336 fbi->fb->fix.visual = FB_VISUAL_PSEUDOCOLOR;
337
338 fbi->fb->fix.line_length = (var->width*var->bits_per_pixel)/8;
339
340 /* activate this new configuration */
341
342 s3c2410fb_activate_var(fbi, var);
343 return 0;
344}
345
346static void schedule_palette_update(struct s3c2410fb_info *fbi,
347 unsigned int regno, unsigned int val)
348{
349 unsigned long flags;
350 unsigned long irqen;
351
352 local_irq_save(flags);
353
354 fbi->palette_buffer[regno] = val;
355
356 if (!fbi->palette_ready) {
357 fbi->palette_ready = 1;
358
359 /* enable IRQ */
360 irqen = readl(S3C2410_LCDINTMSK);
361 irqen &= ~S3C2410_LCDINT_FRSYNC;
362 writel(irqen, S3C2410_LCDINTMSK);
363 }
364
365 local_irq_restore(flags);
366}
367
368/* from pxafb.c */
369static inline unsigned int chan_to_field(unsigned int chan, struct fb_bitfield *bf)
370{
371 chan &= 0xffff;
372 chan >>= 16 - bf->length;
373 return chan << bf->offset;
374}
375
376static int s3c2410fb_setcolreg(unsigned regno,
377 unsigned red, unsigned green, unsigned blue,
378 unsigned transp, struct fb_info *info)
379{
380 struct s3c2410fb_info *fbi = info->par;
381 unsigned int val;
382
383 /* dprintk("setcol: regno=%d, rgb=%d,%d,%d\n", regno, red, green, blue); */
384
385 switch (fbi->fb->fix.visual) {
386 case FB_VISUAL_TRUECOLOR:
387 /* true-colour, use pseuo-palette */
388
389 if (regno < 16) {
390 u32 *pal = fbi->fb->pseudo_palette;
391
392 val = chan_to_field(red, &fbi->fb->var.red);
393 val |= chan_to_field(green, &fbi->fb->var.green);
394 val |= chan_to_field(blue, &fbi->fb->var.blue);
395
396 pal[regno] = val;
397 }
398 break;
399
400 case FB_VISUAL_PSEUDOCOLOR:
401 if (regno < 256) {
402 /* currently assume RGB 5-6-5 mode */
403
404 val = ((red >> 0) & 0xf800);
405 val |= ((green >> 5) & 0x07e0);
406 val |= ((blue >> 11) & 0x001f);
407
408 writel(val, S3C2410_TFTPAL(regno));
409 schedule_palette_update(fbi, regno, val);
410 }
411
412 break;
413
414 default:
415 return 1; /* unknown type */
416 }
417
418 return 0;
419}
420
421
422/**
423 * s3c2410fb_blank
424 * @blank_mode: the blank mode we want.
425 * @info: frame buffer structure that represents a single frame buffer
426 *
427 * Blank the screen if blank_mode != 0, else unblank. Return 0 if
428 * blanking succeeded, != 0 if un-/blanking failed due to e.g. a
429 * video mode which doesn't support it. Implements VESA suspend
430 * and powerdown modes on hardware that supports disabling hsync/vsync:
431 * blank_mode == 2: suspend vsync
432 * blank_mode == 3: suspend hsync
433 * blank_mode == 4: powerdown
434 *
435 * Returns negative errno on error, or zero on success.
436 *
437 */
438static int s3c2410fb_blank(int blank_mode, struct fb_info *info)
439{
440 dprintk("blank(mode=%d, info=%p)\n", blank_mode, info);
441
442 if (mach_info == NULL)
443 return -EINVAL;
444
445 if (blank_mode == FB_BLANK_UNBLANK)
446 writel(0x0, S3C2410_TPAL);
447 else {
448 dprintk("setting TPAL to output 0x000000\n");
449 writel(S3C2410_TPAL_EN, S3C2410_TPAL);
450 }
451
452 return 0;
453}
454
455static int s3c2410fb_debug_show(struct device *dev, struct device_attribute *attr, char *buf)
456{
457 return snprintf(buf, PAGE_SIZE, "%s\n", debug ? "on" : "off");
458}
459static int s3c2410fb_debug_store(struct device *dev, struct device_attribute *attr,
460 const char *buf, size_t len)
461{
462 if (mach_info == NULL)
463 return -EINVAL;
464
465 if (len < 1)
466 return -EINVAL;
467
468 if (strnicmp(buf, "on", 2) == 0 ||
469 strnicmp(buf, "1", 1) == 0) {
470 debug = 1;
471 printk(KERN_DEBUG "s3c2410fb: Debug On");
472 } else if (strnicmp(buf, "off", 3) == 0 ||
473 strnicmp(buf, "0", 1) == 0) {
474 debug = 0;
475 printk(KERN_DEBUG "s3c2410fb: Debug Off");
476 } else {
477 return -EINVAL;
478 }
479
480 return len;
481}
482
483
484static DEVICE_ATTR(debug, 0666,
485 s3c2410fb_debug_show,
486 s3c2410fb_debug_store);
487
488static struct fb_ops s3c2410fb_ops = {
489 .owner = THIS_MODULE,
490 .fb_check_var = s3c2410fb_check_var,
491 .fb_set_par = s3c2410fb_set_par,
492 .fb_blank = s3c2410fb_blank,
493 .fb_setcolreg = s3c2410fb_setcolreg,
494 .fb_fillrect = cfb_fillrect,
495 .fb_copyarea = cfb_copyarea,
496 .fb_imageblit = cfb_imageblit,
497 .fb_cursor = soft_cursor,
498};
499
500
501/*
502 * s3c2410fb_map_video_memory():
503 * Allocates the DRAM memory for the frame buffer. This buffer is
504 * remapped into a non-cached, non-buffered, memory region to
505 * allow palette and pixel writes to occur without flushing the
506 * cache. Once this area is remapped, all virtual memory
507 * access to the video memory should occur at the new region.
508 */
509static int __init s3c2410fb_map_video_memory(struct s3c2410fb_info *fbi)
510{
511 dprintk("map_video_memory(fbi=%p)\n", fbi);
512
513 fbi->map_size = PAGE_ALIGN(fbi->fb->fix.smem_len + PAGE_SIZE);
514 fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
515 &fbi->map_dma, GFP_KERNEL);
516
517 fbi->map_size = fbi->fb->fix.smem_len;
518
519 if (fbi->map_cpu) {
520 /* prevent initial garbage on screen */
521 dprintk("map_video_memory: clear %p:%08x\n",
522 fbi->map_cpu, fbi->map_size);
523 memset(fbi->map_cpu, 0xf0, fbi->map_size);
524
525 fbi->screen_dma = fbi->map_dma;
526 fbi->fb->screen_base = fbi->map_cpu;
527 fbi->fb->fix.smem_start = fbi->screen_dma;
528
529 dprintk("map_video_memory: dma=%08x cpu=%p size=%08x\n",
530 fbi->map_dma, fbi->map_cpu, fbi->fb->fix.smem_len);
531 }
532
533 return fbi->map_cpu ? 0 : -ENOMEM;
534}
535
536static inline void s3c2410fb_unmap_video_memory(struct s3c2410fb_info *fbi)
537{
538 dma_free_writecombine(fbi->dev,fbi->map_size,fbi->map_cpu, fbi->map_dma);
539}
540
541static inline void modify_gpio(void __iomem *reg,
542 unsigned long set, unsigned long mask)
543{
544 unsigned long tmp;
545
546 tmp = readl(reg) & ~mask;
547 writel(tmp | set, reg);
548}
549
550
551/*
552 * s3c2410fb_init_registers - Initialise all LCD-related registers
553 */
554
555int s3c2410fb_init_registers(struct s3c2410fb_info *fbi)
556{
557 unsigned long flags;
558
559 /* Initialise LCD with values from haret */
560
561 local_irq_save(flags);
562
563 /* modify the gpio(s) with interrupts set (bjd) */
564
565 modify_gpio(S3C2410_GPCUP, mach_info->gpcup, mach_info->gpcup_mask);
566 modify_gpio(S3C2410_GPCCON, mach_info->gpccon, mach_info->gpccon_mask);
567 modify_gpio(S3C2410_GPDUP, mach_info->gpdup, mach_info->gpdup_mask);
568 modify_gpio(S3C2410_GPDCON, mach_info->gpdcon, mach_info->gpdcon_mask);
569
570 local_irq_restore(flags);
571
572 writel(fbi->regs.lcdcon1, S3C2410_LCDCON1);
573 writel(fbi->regs.lcdcon2, S3C2410_LCDCON2);
574 writel(fbi->regs.lcdcon3, S3C2410_LCDCON3);
575 writel(fbi->regs.lcdcon4, S3C2410_LCDCON4);
576 writel(fbi->regs.lcdcon5, S3C2410_LCDCON5);
577
578 s3c2410fb_set_lcdaddr(fbi);
579
580 dprintk("LPCSEL = 0x%08lx\n", mach_info->lpcsel);
581 writel(mach_info->lpcsel, S3C2410_LPCSEL);
582
583 dprintk("replacing TPAL %08x\n", readl(S3C2410_TPAL));
584
585 /* ensure temporary palette disabled */
586 writel(0x00, S3C2410_TPAL);
587
588 /* Enable video by setting the ENVID bit to 1 */
589 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_ENVID;
590 writel(fbi->regs.lcdcon1, S3C2410_LCDCON1);
591 return 0;
592}
593
594static void s3c2410fb_write_palette(struct s3c2410fb_info *fbi)
595{
596 unsigned int i;
597 unsigned long ent;
598
599 fbi->palette_ready = 0;
600
601 for (i = 0; i < 256; i++) {
602 if ((ent = fbi->palette_buffer[i]) == PALETTE_BUFF_CLEAR)
603 continue;
604
605 writel(ent, S3C2410_TFTPAL(i));
606
607 /* it seems the only way to know exactly
608 * if the palette wrote ok, is to check
609 * to see if the value verifies ok
610 */
611
612 if (readw(S3C2410_TFTPAL(i)) == ent)
613 fbi->palette_buffer[i] = PALETTE_BUFF_CLEAR;
614 else
615 fbi->palette_ready = 1; /* retry */
616 }
617}
618
619static irqreturn_t s3c2410fb_irq(int irq, void *dev_id, struct pt_regs *r)
620{
621 struct s3c2410fb_info *fbi = dev_id;
622 unsigned long lcdirq = readl(S3C2410_LCDINTPND);
623
624 if (lcdirq & S3C2410_LCDINT_FRSYNC) {
625 if (fbi->palette_ready)
626 s3c2410fb_write_palette(fbi);
627
628 writel(S3C2410_LCDINT_FRSYNC, S3C2410_LCDINTPND);
629 writel(S3C2410_LCDINT_FRSYNC, S3C2410_LCDSRCPND);
630 }
631
632 return IRQ_HANDLED;
633}
634
635static char driver_name[]="s3c2410fb";
636
637int __init s3c2410fb_probe(struct device *dev)
638{
639 struct s3c2410fb_info *info;
640 struct fb_info *fbinfo;
641 struct platform_device *pdev = to_platform_device(dev);
642 struct s3c2410fb_hw *mregs;
643 int ret;
644 int irq;
645 int i;
646
647 mach_info = dev->platform_data;
648 if (mach_info == NULL) {
649 dev_err(dev,"no platform data for lcd, cannot attach\n");
650 return -EINVAL;
651 }
652
653 mregs = &mach_info->regs;
654
655 irq = platform_get_irq(pdev, 0);
656 if (irq < 0) {
657 dev_err(dev, "no irq for device\n");
658 return -ENOENT;
659 }
660
661 fbinfo = framebuffer_alloc(sizeof(struct s3c2410fb_info), dev);
662 if (!fbinfo) {
663 return -ENOMEM;
664 }
665
666
667 info = fbinfo->par;
668 info->fb = fbinfo;
669 dev_set_drvdata(dev, fbinfo);
670
671 s3c2410fb_init_registers(info);
672
673 dprintk("devinit\n");
674
675 strcpy(fbinfo->fix.id, driver_name);
676
677 memcpy(&info->regs, &mach_info->regs, sizeof(info->regs));
678
679 info->mach_info = dev->platform_data;
680
681 fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
682 fbinfo->fix.type_aux = 0;
683 fbinfo->fix.xpanstep = 0;
684 fbinfo->fix.ypanstep = 0;
685 fbinfo->fix.ywrapstep = 0;
686 fbinfo->fix.accel = FB_ACCEL_NONE;
687
688 fbinfo->var.nonstd = 0;
689 fbinfo->var.activate = FB_ACTIVATE_NOW;
690 fbinfo->var.height = mach_info->height;
691 fbinfo->var.width = mach_info->width;
692 fbinfo->var.accel_flags = 0;
693 fbinfo->var.vmode = FB_VMODE_NONINTERLACED;
694
695 fbinfo->fbops = &s3c2410fb_ops;
696 fbinfo->flags = FBINFO_FLAG_DEFAULT;
697 fbinfo->pseudo_palette = &info->pseudo_pal;
698
699 fbinfo->var.xres = mach_info->xres.defval;
700 fbinfo->var.xres_virtual = mach_info->xres.defval;
701 fbinfo->var.yres = mach_info->yres.defval;
702 fbinfo->var.yres_virtual = mach_info->yres.defval;
703 fbinfo->var.bits_per_pixel = mach_info->bpp.defval;
704
705 fbinfo->var.upper_margin = S3C2410_LCDCON2_GET_VBPD(mregs->lcdcon2) +1;
706 fbinfo->var.lower_margin = S3C2410_LCDCON2_GET_VFPD(mregs->lcdcon2) +1;
707 fbinfo->var.vsync_len = S3C2410_LCDCON2_GET_VSPW(mregs->lcdcon2) + 1;
708
709 fbinfo->var.left_margin = S3C2410_LCDCON3_GET_HFPD(mregs->lcdcon3) + 1;
710 fbinfo->var.right_margin = S3C2410_LCDCON3_GET_HBPD(mregs->lcdcon3) + 1;
711 fbinfo->var.hsync_len = S3C2410_LCDCON4_GET_HSPW(mregs->lcdcon4) + 1;
712
713 fbinfo->var.red.offset = 11;
714 fbinfo->var.green.offset = 5;
715 fbinfo->var.blue.offset = 0;
716 fbinfo->var.transp.offset = 0;
717 fbinfo->var.red.length = 5;
718 fbinfo->var.green.length = 6;
719 fbinfo->var.blue.length = 5;
720 fbinfo->var.transp.length = 0;
721 fbinfo->fix.smem_len = mach_info->xres.max *
722 mach_info->yres.max *
723 mach_info->bpp.max / 8;
724
725 for (i = 0; i < 256; i++)
726 info->palette_buffer[i] = PALETTE_BUFF_CLEAR;
727
728 if (!request_mem_region((unsigned long)S3C24XX_VA_LCD, SZ_1M, "s3c2410-lcd")) {
729 ret = -EBUSY;
730 goto dealloc_fb;
731 }
732
733
734 dprintk("got LCD region\n");
735
736 ret = request_irq(irq, s3c2410fb_irq, SA_INTERRUPT, pdev->name, info);
737 if (ret) {
738 dev_err(dev, "cannot get irq %d - err %d\n", irq, ret);
739 ret = -EBUSY;
740 goto release_mem;
741 }
742
743 info->clk = clk_get(NULL, "lcd");
744 if (!info->clk || IS_ERR(info->clk)) {
745 printk(KERN_ERR "failed to get lcd clock source\n");
746 ret = -ENOENT;
747 goto release_irq;
748 }
749
750 clk_use(info->clk);
751 clk_enable(info->clk);
752 dprintk("got and enabled clock\n");
753
754 msleep(1);
755
756 /* Initialize video memory */
757 ret = s3c2410fb_map_video_memory(info);
758 if (ret) {
759 printk( KERN_ERR "Failed to allocate video RAM: %d\n", ret);
760 ret = -ENOMEM;
761 goto release_clock;
762 }
763 dprintk("got video memory\n");
764
765 ret = s3c2410fb_init_registers(info);
766
767 ret = s3c2410fb_check_var(&fbinfo->var, fbinfo);
768
769 ret = register_framebuffer(fbinfo);
770 if (ret < 0) {
771 printk(KERN_ERR "Failed to register framebuffer device: %d\n", ret);
772 goto free_video_memory;
773 }
774
775 /* create device files */
776 device_create_file(dev, &dev_attr_debug);
777
778 printk(KERN_INFO "fb%d: %s frame buffer device\n",
779 fbinfo->node, fbinfo->fix.id);
780
781 return 0;
782
783free_video_memory:
784 s3c2410fb_unmap_video_memory(info);
785release_clock:
786 clk_disable(info->clk);
787 clk_unuse(info->clk);
788 clk_put(info->clk);
789release_irq:
790 free_irq(irq,info);
791release_mem:
792 release_mem_region((unsigned long)S3C24XX_VA_LCD, S3C24XX_SZ_LCD);
793dealloc_fb:
794 framebuffer_release(fbinfo);
795 return ret;
796}
797
798/* s3c2410fb_stop_lcd
799 *
800 * shutdown the lcd controller
801*/
802
803static void s3c2410fb_stop_lcd(void)
804{
805 unsigned long flags;
806 unsigned long tmp;
807
808 local_irq_save(flags);
809
810 tmp = readl(S3C2410_LCDCON1);
811 writel(tmp & ~S3C2410_LCDCON1_ENVID, S3C2410_LCDCON1);
812
813 local_irq_restore(flags);
814}
815
816/*
817 * Cleanup
818 */
819static int s3c2410fb_remove(struct device *dev)
820{
821 struct platform_device *pdev = to_platform_device(dev);
822 struct fb_info *fbinfo = dev_get_drvdata(dev);
823 struct s3c2410fb_info *info = fbinfo->par;
824 int irq;
825
826 s3c2410fb_stop_lcd();
827 msleep(1);
828
829 s3c2410fb_unmap_video_memory(info);
830
831 if (info->clk) {
832 clk_disable(info->clk);
833 clk_unuse(info->clk);
834 clk_put(info->clk);
835 info->clk = NULL;
836 }
837
838 irq = platform_get_irq(pdev, 0);
839 free_irq(irq,info);
840 release_mem_region((unsigned long)S3C24XX_VA_LCD, S3C24XX_SZ_LCD);
841 unregister_framebuffer(fbinfo);
842
843 return 0;
844}
845
846#ifdef CONFIG_PM
847
848/* suspend and resume support for the lcd controller */
849
850static int s3c2410fb_suspend(struct device *dev, pm_message_t state, u32 level)
851{
852 struct fb_info *fbinfo = dev_get_drvdata(dev);
853 struct s3c2410fb_info *info = fbinfo->par;
854
855 if (level == SUSPEND_DISABLE || level == SUSPEND_POWER_DOWN) {
856 s3c2410fb_stop_lcd();
857
858 /* sleep before disabling the clock, we need to ensure
859 * the LCD DMA engine is not going to get back on the bus
860 * before the clock goes off again (bjd) */
861
862 msleep(1);
863 clk_disable(info->clk);
864 }
865
866 return 0;
867}
868
869static int s3c2410fb_resume(struct device *dev, u32 level)
870{
871 struct fb_info *fbinfo = dev_get_drvdata(dev);
872 struct s3c2410fb_info *info = fbinfo->par;
873
874 if (level == RESUME_ENABLE) {
875 clk_enable(info->clk);
876 msleep(1);
877
878 s3c2410fb_init_registers(info);
879
880 }
881
882 return 0;
883}
884
885#else
886#define s3c2410fb_suspend NULL
887#define s3c2410fb_resume NULL
888#endif
889
890static struct device_driver s3c2410fb_driver = {
891 .name = "s3c2410-lcd",
892 .bus = &platform_bus_type,
893 .probe = s3c2410fb_probe,
894 .suspend = s3c2410fb_suspend,
895 .resume = s3c2410fb_resume,
896 .remove = s3c2410fb_remove
897};
898
899int __devinit s3c2410fb_init(void)
900{
901 return driver_register(&s3c2410fb_driver);
902}
903
904static void __exit s3c2410fb_cleanup(void)
905{
906 driver_unregister(&s3c2410fb_driver);
907}
908
909
910module_init(s3c2410fb_init);
911module_exit(s3c2410fb_cleanup);
912
913MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>, Ben Dooks <ben-linux@fluff.org>");
914MODULE_DESCRIPTION("Framebuffer driver for the s3c2410");
915MODULE_LICENSE("GPL");
diff --git a/drivers/video/s3c2410fb.h b/drivers/video/s3c2410fb.h
new file mode 100644
index 0000000000..be40968f89
--- /dev/null
+++ b/drivers/video/s3c2410fb.h
@@ -0,0 +1,56 @@
1/*
2 * linux/drivers/s3c2410fb.h
3 * Copyright (c) Arnaud Patard
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file COPYING in the main directory of this archive for
7 * more details.
8 *
9 * S3C2410 LCD Controller Frame Buffer Driver
10 * based on skeletonfb.c, sa1100fb.h
11 *
12 * ChangeLog
13 *
14 * 2004-12-04: Arnaud Patard <arnaud.patard@rtp-net.org>
15 * - Moved dprintk to s3c2410fb.c
16 *
17 * 2004-09-07: Arnaud Patard <arnaud.patard@rtp-net.org>
18 * - Renamed from h1940fb.h to s3c2410fb.h
19 * - Chenged h1940 to s3c2410
20 *
21 * 2004-07-15: Arnaud Patard <arnaud.patard@rtp-net.org>
22 * - First version
23 */
24
25#ifndef __S3C2410FB_H
26#define __S3C2410FB_H
27
28struct s3c2410fb_info {
29 struct fb_info *fb;
30 struct device *dev;
31 struct clk *clk;
32
33 struct s3c2410fb_mach_info *mach_info;
34
35 /* raw memory addresses */
36 dma_addr_t map_dma; /* physical */
37 u_char * map_cpu; /* virtual */
38 u_int map_size;
39
40 struct s3c2410fb_hw regs;
41
42 /* addresses of pieces placed in raw buffer */
43 u_char * screen_cpu; /* virtual address of buffer */
44 dma_addr_t screen_dma; /* physical address of buffer */
45 unsigned int palette_ready;
46
47 /* keep these registers in case we need to re-write palette */
48 u32 palette_buffer[256];
49 u32 pseudo_pal[16];
50};
51
52#define PALETTE_BUFF_CLEAR (0x80000000) /* entry is clear/invalid */
53
54int s3c2410fb_init(void);
55
56#endif
diff --git a/drivers/video/savage/savagefb-i2c.c b/drivers/video/savage/savagefb-i2c.c
index 847698b5cf..959404ad68 100644
--- a/drivers/video/savage/savagefb-i2c.c
+++ b/drivers/video/savage/savagefb-i2c.c
@@ -259,8 +259,9 @@ static u8 *savage_do_probe_i2c_edid(struct savagefb_i2c_chan *chan)
259 return buf; 259 return buf;
260} 260}
261 261
262int savagefb_probe_i2c_connector(struct savagefb_par *par, u8 **out_edid) 262int savagefb_probe_i2c_connector(struct fb_info *info, u8 **out_edid)
263{ 263{
264 struct savagefb_par *par = info->par;
264 u8 *edid = NULL; 265 u8 *edid = NULL;
265 int i; 266 int i;
266 267
@@ -270,12 +271,19 @@ int savagefb_probe_i2c_connector(struct savagefb_par *par, u8 **out_edid)
270 if (edid) 271 if (edid)
271 break; 272 break;
272 } 273 }
274
275 if (!edid) {
276 /* try to get from firmware */
277 edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
278 if (edid)
279 memcpy(edid, fb_firmware_edid(info->device),
280 EDID_LENGTH);
281 }
282
273 if (out_edid) 283 if (out_edid)
274 *out_edid = edid; 284 *out_edid = edid;
275 if (!edid)
276 return 1;
277 285
278 return 0; 286 return (edid) ? 0 : 1;
279} 287}
280 288
281MODULE_LICENSE("GPL"); 289MODULE_LICENSE("GPL");
diff --git a/drivers/video/savage/savagefb.h b/drivers/video/savage/savagefb.h
index 8594b1e42d..d6f94742c9 100644
--- a/drivers/video/savage/savagefb.h
+++ b/drivers/video/savage/savagefb.h
@@ -60,6 +60,7 @@
60 60
61#define S3_SAVAGE_SERIES(chip) ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE2000)) 61#define S3_SAVAGE_SERIES(chip) ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE2000))
62 62
63#define S3_MOBILE_TWISTER_SERIES(chip) ((chip==S3_TWISTER) || (chip == S3_PROSAVAGEDDR))
63 64
64/* Chip tags. These are used to group the adapters into 65/* Chip tags. These are used to group the adapters into
65 * related families. 66 * related families.
@@ -73,6 +74,8 @@ typedef enum {
73 S3_PROSAVAGE, 74 S3_PROSAVAGE,
74 S3_SUPERSAVAGE, 75 S3_SUPERSAVAGE,
75 S3_SAVAGE2000, 76 S3_SAVAGE2000,
77 S3_PROSAVAGEDDR,
78 S3_TWISTER,
76 S3_LAST 79 S3_LAST
77} savage_chipset; 80} savage_chipset;
78 81
@@ -128,6 +131,10 @@ typedef enum {
128#define BCI_CMD_SET_ROP(cmd, rop) ((cmd) |= ((rop & 0xFF) << 16)) 131#define BCI_CMD_SET_ROP(cmd, rop) ((cmd) |= ((rop & 0xFF) << 16))
129#define BCI_CMD_SEND_COLOR 0x00008000 132#define BCI_CMD_SEND_COLOR 0x00008000
130 133
134#define DISP_CRT 1
135#define DISP_LCD 2
136#define DISP_DFP 3
137
131struct xtimings { 138struct xtimings {
132 unsigned int Clock; 139 unsigned int Clock;
133 unsigned int HDisplay; 140 unsigned int HDisplay;
@@ -166,6 +173,10 @@ struct savagefb_par {
166 struct savagefb_i2c_chan chan; 173 struct savagefb_i2c_chan chan;
167 unsigned char *edid; 174 unsigned char *edid;
168 u32 pseudo_palette[16]; 175 u32 pseudo_palette[16];
176 int pm_state;
177 int display_type;
178 int dvi;
179 int crtonly;
169 int dacSpeedBpp; 180 int dacSpeedBpp;
170 int maxClock; 181 int maxClock;
171 int minClock; 182 int minClock;
@@ -338,7 +349,7 @@ do { \
338 } \ 349 } \
339} 350}
340 351
341extern int savagefb_probe_i2c_connector(struct savagefb_par *par, 352extern int savagefb_probe_i2c_connector(struct fb_info *info,
342 u8 **out_edid); 353 u8 **out_edid);
343extern void savagefb_create_i2c_busses(struct fb_info *info); 354extern void savagefb_create_i2c_busses(struct fb_info *info);
344extern void savagefb_delete_i2c_busses(struct fb_info *info); 355extern void savagefb_delete_i2c_busses(struct fb_info *info);
diff --git a/drivers/video/savage/savagefb_driver.c b/drivers/video/savage/savagefb_driver.c
index 117ad42f12..b5ca3ef827 100644
--- a/drivers/video/savage/savagefb_driver.c
+++ b/drivers/video/savage/savagefb_driver.c
@@ -1400,6 +1400,58 @@ static int savagefb_pan_display (struct fb_var_screeninfo *var,
1400 return 0; 1400 return 0;
1401} 1401}
1402 1402
1403static int savagefb_blank(int blank, struct fb_info *info)
1404{
1405 struct savagefb_par *par = info->par;
1406 u8 sr8 = 0, srd = 0;
1407
1408 if (par->display_type == DISP_CRT) {
1409 vga_out8(0x3c4, 0x08);
1410 sr8 = vga_in8(0x3c5);
1411 sr8 |= 0x06;
1412 vga_out8(0x3c5, sr8);
1413 vga_out8(0x3c4, 0x0d);
1414 srd = vga_in8(0x3c5);
1415 srd &= 0x03;
1416
1417 switch (blank) {
1418 case FB_BLANK_UNBLANK:
1419 case FB_BLANK_NORMAL:
1420 break;
1421 case FB_BLANK_VSYNC_SUSPEND:
1422 srd |= 0x10;
1423 break;
1424 case FB_BLANK_HSYNC_SUSPEND:
1425 srd |= 0x40;
1426 break;
1427 case FB_BLANK_POWERDOWN:
1428 srd |= 0x50;
1429 break;
1430 }
1431
1432 vga_out8(0x3c4, 0x0d);
1433 vga_out8(0x3c5, srd);
1434 }
1435
1436 if (par->display_type == DISP_LCD ||
1437 par->display_type == DISP_DFP) {
1438 switch(blank) {
1439 case FB_BLANK_UNBLANK:
1440 case FB_BLANK_NORMAL:
1441 vga_out8(0x3c4, 0x31); /* SR31 bit 4 - FP enable */
1442 vga_out8(0x3c5, vga_in8(0x3c5) | 0x10);
1443 break;
1444 case FB_BLANK_VSYNC_SUSPEND:
1445 case FB_BLANK_HSYNC_SUSPEND:
1446 case FB_BLANK_POWERDOWN:
1447 vga_out8(0x3c4, 0x31); /* SR31 bit 4 - FP enable */
1448 vga_out8(0x3c5, vga_in8(0x3c5) & ~0x10);
1449 break;
1450 }
1451 }
1452
1453 return (blank == FB_BLANK_NORMAL) ? 1 : 0;
1454}
1403 1455
1404static struct fb_ops savagefb_ops = { 1456static struct fb_ops savagefb_ops = {
1405 .owner = THIS_MODULE, 1457 .owner = THIS_MODULE,
@@ -1407,6 +1459,7 @@ static struct fb_ops savagefb_ops = {
1407 .fb_set_par = savagefb_set_par, 1459 .fb_set_par = savagefb_set_par,
1408 .fb_setcolreg = savagefb_setcolreg, 1460 .fb_setcolreg = savagefb_setcolreg,
1409 .fb_pan_display = savagefb_pan_display, 1461 .fb_pan_display = savagefb_pan_display,
1462 .fb_blank = savagefb_blank,
1410#if defined(CONFIG_FB_SAVAGE_ACCEL) 1463#if defined(CONFIG_FB_SAVAGE_ACCEL)
1411 .fb_fillrect = savagefb_fillrect, 1464 .fb_fillrect = savagefb_fillrect,
1412 .fb_copyarea = savagefb_copyarea, 1465 .fb_copyarea = savagefb_copyarea,
@@ -1583,8 +1636,7 @@ static int __devinit savage_init_hw (struct savagefb_par *par)
1583 static unsigned char RamSavage4[] = { 2, 4, 8, 12, 16, 32, 64, 32 }; 1636 static unsigned char RamSavage4[] = { 2, 4, 8, 12, 16, 32, 64, 32 };
1584 static unsigned char RamSavageMX[] = { 2, 8, 4, 16, 8, 16, 4, 16 }; 1637 static unsigned char RamSavageMX[] = { 2, 8, 4, 16, 8, 16, 4, 16 };
1585 static unsigned char RamSavageNB[] = { 0, 2, 4, 8, 16, 32, 2, 2 }; 1638 static unsigned char RamSavageNB[] = { 0, 2, 4, 8, 16, 32, 2, 2 };
1586 1639 int videoRam, videoRambytes, dvi;
1587 int videoRam, videoRambytes;
1588 1640
1589 DBG("savage_init_hw"); 1641 DBG("savage_init_hw");
1590 1642
@@ -1705,6 +1757,30 @@ static int __devinit savage_init_hw (struct savagefb_par *par)
1705 printk (KERN_INFO "savagefb: Detected current MCLK value of %d kHz\n", 1757 printk (KERN_INFO "savagefb: Detected current MCLK value of %d kHz\n",
1706 par->MCLK); 1758 par->MCLK);
1707 1759
1760 /* check for DVI/flat panel */
1761 dvi = 0;
1762
1763 if (par->chip == S3_SAVAGE4) {
1764 unsigned char sr30 = 0x00;
1765
1766 vga_out8(0x3c4, 0x30);
1767 /* clear bit 1 */
1768 vga_out8(0x3c5, vga_in8(0x3c5) & ~0x02);
1769 sr30 = vga_in8(0x3c5);
1770 if (sr30 & 0x02 /*0x04 */) {
1771 dvi = 1;
1772 printk("savagefb: Digital Flat Panel Detected\n");
1773 }
1774 }
1775
1776 if (S3_SAVAGE_MOBILE_SERIES(par->chip) ||
1777 (S3_MOBILE_TWISTER_SERIES(par->chip) && !par->crtonly))
1778 par->display_type = DISP_LCD;
1779 else if (dvi || (par->chip == S3_SAVAGE4 && par->dvi))
1780 par->display_type = DISP_DFP;
1781 else
1782 par->display_type = DISP_CRT;
1783
1708 /* Check LCD panel parrmation */ 1784 /* Check LCD panel parrmation */
1709 1785
1710 if (par->chip == S3_SAVAGE_MX) { 1786 if (par->chip == S3_SAVAGE_MX) {
@@ -1759,7 +1835,8 @@ static int __devinit savage_init_hw (struct savagefb_par *par)
1759 par->SavagePanelWidth = panelX; 1835 par->SavagePanelWidth = panelX;
1760 par->SavagePanelHeight = panelY; 1836 par->SavagePanelHeight = panelY;
1761 1837
1762 } 1838 } else
1839 par->display_type = DISP_CRT;
1763 } 1840 }
1764 1841
1765 savage_get_default_par (par); 1842 savage_get_default_par (par);
@@ -1845,15 +1922,15 @@ static int __devinit savage_init_fb_info (struct fb_info *info,
1845 snprintf (info->fix.id, 16, "ProSavageKM"); 1922 snprintf (info->fix.id, 16, "ProSavageKM");
1846 break; 1923 break;
1847 case FB_ACCEL_S3TWISTER_P: 1924 case FB_ACCEL_S3TWISTER_P:
1848 par->chip = S3_PROSAVAGE; 1925 par->chip = S3_TWISTER;
1849 snprintf (info->fix.id, 16, "TwisterP"); 1926 snprintf (info->fix.id, 16, "TwisterP");
1850 break; 1927 break;
1851 case FB_ACCEL_S3TWISTER_K: 1928 case FB_ACCEL_S3TWISTER_K:
1852 par->chip = S3_PROSAVAGE; 1929 par->chip = S3_TWISTER;
1853 snprintf (info->fix.id, 16, "TwisterK"); 1930 snprintf (info->fix.id, 16, "TwisterK");
1854 break; 1931 break;
1855 case FB_ACCEL_PROSAVAGE_DDR: 1932 case FB_ACCEL_PROSAVAGE_DDR:
1856 par->chip = S3_PROSAVAGE; 1933 par->chip = S3_PROSAVAGEDDR;
1857 snprintf (info->fix.id, 16, "ProSavageDDR"); 1934 snprintf (info->fix.id, 16, "ProSavageDDR");
1858 break; 1935 break;
1859 case FB_ACCEL_PROSAVAGE_DDRK: 1936 case FB_ACCEL_PROSAVAGE_DDRK:
@@ -1899,12 +1976,11 @@ static int __devinit savage_init_fb_info (struct fb_info *info,
1899 info->pixmap.buf_align = 4; 1976 info->pixmap.buf_align = 4;
1900 info->pixmap.access_align = 32; 1977 info->pixmap.access_align = 32;
1901 1978
1902 fb_alloc_cmap (&info->cmap, NR_PALETTE, 0); 1979 err = fb_alloc_cmap (&info->cmap, NR_PALETTE, 0);
1980 if (!err)
1903 info->flags |= FBINFO_HWACCEL_COPYAREA | 1981 info->flags |= FBINFO_HWACCEL_COPYAREA |
1904 FBINFO_HWACCEL_FILLRECT | 1982 FBINFO_HWACCEL_FILLRECT |
1905 FBINFO_HWACCEL_IMAGEBLIT; 1983 FBINFO_HWACCEL_IMAGEBLIT;
1906
1907 err = 0;
1908 } 1984 }
1909#endif 1985#endif
1910 return err; 1986 return err;
@@ -1932,14 +2008,14 @@ static int __devinit savagefb_probe (struct pci_dev* dev,
1932 if (err) 2008 if (err)
1933 goto failed_enable; 2009 goto failed_enable;
1934 2010
1935 if (pci_request_regions(dev, "savagefb")) { 2011 if ((err = pci_request_regions(dev, "savagefb"))) {
1936 printk(KERN_ERR "cannot request PCI regions\n"); 2012 printk(KERN_ERR "cannot request PCI regions\n");
1937 goto failed_enable; 2013 goto failed_enable;
1938 } 2014 }
1939 2015
1940 err = -ENOMEM; 2016 err = -ENOMEM;
1941 2017
1942 if (savage_init_fb_info(info, dev, id)) 2018 if ((err = savage_init_fb_info(info, dev, id)))
1943 goto failed_init; 2019 goto failed_init;
1944 2020
1945 err = savage_map_mmio(info); 2021 err = savage_map_mmio(info);
@@ -1947,6 +2023,7 @@ static int __devinit savagefb_probe (struct pci_dev* dev,
1947 goto failed_mmio; 2023 goto failed_mmio;
1948 2024
1949 video_len = savage_init_hw(par); 2025 video_len = savage_init_hw(par);
2026 /* FIXME: cant be negative */
1950 if (video_len < 0) { 2027 if (video_len < 0) {
1951 err = video_len; 2028 err = video_len;
1952 goto failed_mmio; 2029 goto failed_mmio;
@@ -1959,7 +2036,8 @@ static int __devinit savagefb_probe (struct pci_dev* dev,
1959 INIT_LIST_HEAD(&info->modelist); 2036 INIT_LIST_HEAD(&info->modelist);
1960#if defined(CONFIG_FB_SAVAGE_I2C) 2037#if defined(CONFIG_FB_SAVAGE_I2C)
1961 savagefb_create_i2c_busses(info); 2038 savagefb_create_i2c_busses(info);
1962 savagefb_probe_i2c_connector(par, &par->edid); 2039 savagefb_probe_i2c_connector(info, &par->edid);
2040 kfree(par->edid);
1963 fb_edid_to_monspecs(par->edid, &info->monspecs); 2041 fb_edid_to_monspecs(par->edid, &info->monspecs);
1964 fb_videomode_to_modelist(info->monspecs.modedb, 2042 fb_videomode_to_modelist(info->monspecs.modedb,
1965 info->monspecs.modedb_len, 2043 info->monspecs.modedb_len,
@@ -2111,13 +2189,30 @@ static int savagefb_suspend (struct pci_dev* dev, pm_message_t state)
2111 2189
2112 DBG("savagefb_suspend"); 2190 DBG("savagefb_suspend");
2113 2191
2192
2193 par->pm_state = state.event;
2194
2195 /*
2196 * For PM_EVENT_FREEZE, do not power down so the console
2197 * can remain active.
2198 */
2199 if (state.event == PM_EVENT_FREEZE) {
2200 dev->dev.power.power_state = state;
2201 return 0;
2202 }
2203
2114 acquire_console_sem(); 2204 acquire_console_sem();
2115 fb_set_suspend(info, pci_choose_state(dev, state)); 2205 fb_set_suspend(info, 1);
2116 savage_disable_mmio(par);
2117 release_console_sem();
2118 2206
2207 if (info->fbops->fb_sync)
2208 info->fbops->fb_sync(info);
2209
2210 savagefb_blank(FB_BLANK_POWERDOWN, info);
2211 savage_disable_mmio(par);
2212 pci_save_state(dev);
2119 pci_disable_device(dev); 2213 pci_disable_device(dev);
2120 pci_set_power_state(dev, pci_choose_state(dev, state)); 2214 pci_set_power_state(dev, pci_choose_state(dev, state));
2215 release_console_sem();
2121 2216
2122 return 0; 2217 return 0;
2123} 2218}
@@ -2127,22 +2222,34 @@ static int savagefb_resume (struct pci_dev* dev)
2127 struct fb_info *info = 2222 struct fb_info *info =
2128 (struct fb_info *)pci_get_drvdata(dev); 2223 (struct fb_info *)pci_get_drvdata(dev);
2129 struct savagefb_par *par = (struct savagefb_par *)info->par; 2224 struct savagefb_par *par = (struct savagefb_par *)info->par;
2225 int cur_state = par->pm_state;
2130 2226
2131 DBG("savage_resume"); 2227 DBG("savage_resume");
2132 2228
2133 pci_set_power_state(dev, 0); 2229 par->pm_state = PM_EVENT_ON;
2134 pci_restore_state(dev);
2135 if(pci_enable_device(dev))
2136 DBG("err");
2137 2230
2138 SavagePrintRegs(); 2231 /*
2232 * The adapter was not powered down coming back from a
2233 * PM_EVENT_FREEZE.
2234 */
2235 if (cur_state == PM_EVENT_FREEZE) {
2236 pci_set_power_state(dev, PCI_D0);
2237 return 0;
2238 }
2139 2239
2140 acquire_console_sem(); 2240 acquire_console_sem();
2141 2241
2242 pci_set_power_state(dev, PCI_D0);
2243 pci_restore_state(dev);
2244
2245 if(pci_enable_device(dev))
2246 DBG("err");
2247
2248 pci_set_master(dev);
2142 savage_enable_mmio(par); 2249 savage_enable_mmio(par);
2143 savage_init_hw(par); 2250 savage_init_hw(par);
2144 savagefb_set_par (info); 2251 savagefb_set_par (info);
2145 2252 savagefb_blank(FB_BLANK_UNBLANK, info);
2146 fb_set_suspend (info, 0); 2253 fb_set_suspend (info, 0);
2147 release_console_sem(); 2254 release_console_sem();
2148 2255
@@ -2276,3 +2383,6 @@ static int __init savagefb_init(void)
2276 2383
2277module_init(savagefb_init); 2384module_init(savagefb_init);
2278module_exit(savage_done); 2385module_exit(savage_done);
2386
2387module_param(mode_option, charp, 0);
2388MODULE_PARM_DESC(mode_option, "Specify initial video mode");
diff --git a/drivers/video/sis/300vtbl.h b/drivers/video/sis/300vtbl.h
index b6d5c71b25..e4b4a2626d 100644
--- a/drivers/video/sis/300vtbl.h
+++ b/drivers/video/sis/300vtbl.h
@@ -3,7 +3,7 @@
3/* 3/*
4 * Register settings for SiS 300 series 4 * Register settings for SiS 300 series
5 * 5 *
6 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria 6 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
7 * 7 *
8 * If distributed as part of the Linux kernel, the following license terms 8 * If distributed as part of the Linux kernel, the following license terms
9 * apply: 9 * apply:
@@ -50,31 +50,7 @@
50 * 50 *
51 */ 51 */
52 52
53static const SiS_StStruct SiS300_SModeIDTable[] = 53static const struct SiS_Ext SiS300_EModeIDTable[] =
54{
55 {0x01,0x9208,0x01,0x00,0x00,0x00,0x00,0x00, 0},
56 {0x01,0x1210,0x14,0x01,0x01,0x00,0x00,0x00, 0},
57 {0x01,0x1010,0x17,0x02,0x02,0x00,0x00,0x00, 0},
58 {0x03,0x8208,0x03,0x00,0x00,0x00,0x00,0x00, 0},
59 {0x03,0x0210,0x16,0x01,0x01,0x00,0x00,0x00, 0},
60 {0x03,0x0010,0x18,0x02,0x02,0x00,0x00,0x00, 0},
61 {0x05,0x9209,0x05,0x00,0x00,0x00,0x00,0x00, 0},
62 {0x06,0x8209,0x06,0x00,0x00,0x00,0x00,0x00, 0},
63 {0x07,0x0000,0x07,0x03,0x03,0x00,0x00,0x00, 0},
64 {0x07,0x0000,0x19,0x02,0x02,0x00,0x00,0x00, 0},
65 {0x0d,0x920a,0x0d,0x00,0x00,0x00,0x00,0x00, 0},
66 {0x0e,0x820a,0x0e,0x00,0x00,0x00,0x00,0x00, 0},
67 {0x0f,0x0202,0x11,0x01,0x01,0x00,0x00,0x00, 0},
68 {0x10,0x0212,0x12,0x01,0x01,0x00,0x00,0x00, 0},
69 {0x11,0x0212,0x1a,0x04,0x04,0x00,0x00,0x00, 0},
70 {0x12,0x0212,0x1b,0x04,0x04,0x00,0x00,0x00, 0},
71 {0x13,0x021b,0x1c,0x00,0x00,0x00,0x00,0x00, 0},
72 {0x12,0x0010,0x18,0x02,0x02,0x00,0x00,0x00, 0},
73 {0x12,0x0210,0x18,0x01,0x01,0x00,0x00,0x00, 0},
74 {0xff, 0, 0, 0, 0, 0, 0, 0, 0}
75};
76
77static const SiS_ExtStruct SiS300_EModeIDTable[] =
78{ 54{
79 {0x6a,0x2212,0x0102,SIS_RI_800x600, 0x00,0x00,0x00,0x00,0x00,-1}, /* 800x600x? */ 55 {0x6a,0x2212,0x0102,SIS_RI_800x600, 0x00,0x00,0x00,0x00,0x00,-1}, /* 800x600x? */
80 {0x2e,0x0a1b,0x0101,SIS_RI_640x480, 0x00,0x00,0x00,0x00,0x08,-1}, 56 {0x2e,0x0a1b,0x0101,SIS_RI_640x480, 0x00,0x00,0x00,0x00,0x08,-1},
@@ -110,7 +86,7 @@ static const SiS_ExtStruct SiS300_EModeIDTable[] =
110 {0x59,0x921b,0x0138,SIS_RI_320x200, 0x00,0x00,0x00,0x00,0x23,-1}, /* 320x200x8 */ 86 {0x59,0x921b,0x0138,SIS_RI_320x200, 0x00,0x00,0x00,0x00,0x23,-1}, /* 320x200x8 */
111 {0x5c,0x921f,0x0000,SIS_RI_512x384, 0x00,0x00,0x00,0x00,0x26,-1}, /* 512x384x32 */ 87 {0x5c,0x921f,0x0000,SIS_RI_512x384, 0x00,0x00,0x00,0x00,0x26,-1}, /* 512x384x32 */
112 {0x5d,0x021d,0x0139,SIS_RI_640x400, 0x00,0x00,0x00,0x00,0x10,-1}, /* 640x400x16 */ 88 {0x5d,0x021d,0x0139,SIS_RI_640x400, 0x00,0x00,0x00,0x00,0x10,-1}, /* 640x400x16 */
113 {0x5e,0x021f,0x0000,SIS_RI_640x400, 0x00,0x00,0x00,0x00,0x10,-1}, /* 640x400x32 */ 89 {0x5e,0x021f,0x0000,SIS_RI_640x400, 0x00,0x00,0x00,0x00,0x10,-1}, /* 640x400x32 */
114 {0x62,0x0a3f,0x013a,SIS_RI_640x480, 0x00,0x00,0x00,0x00,0x08,-1}, 90 {0x62,0x0a3f,0x013a,SIS_RI_640x480, 0x00,0x00,0x00,0x00,0x08,-1},
115 {0x63,0x2a3f,0x013b,SIS_RI_800x600, 0x00,0x00,0x00,0x00,0x00,-1}, /* 800x600x32 */ 91 {0x63,0x2a3f,0x013b,SIS_RI_800x600, 0x00,0x00,0x00,0x00,0x00,-1}, /* 800x600x32 */
116 {0x64,0x0a7f,0x013c,SIS_RI_1024x768, 0x00,0x00,0x00,0x00,0x13,-1}, 92 {0x64,0x0a7f,0x013c,SIS_RI_1024x768, 0x00,0x00,0x00,0x00,0x13,-1},
@@ -119,8 +95,8 @@ static const SiS_ExtStruct SiS300_EModeIDTable[] =
119 {0x68,0x067b,0x013f,SIS_RI_1920x1440,0x00,0x00,0x00,0x00,0x27,-1}, 95 {0x68,0x067b,0x013f,SIS_RI_1920x1440,0x00,0x00,0x00,0x00,0x27,-1},
120 {0x69,0x06fd,0x0140,SIS_RI_1920x1440,0x00,0x00,0x00,0x00,0x27,-1}, 96 {0x69,0x06fd,0x0140,SIS_RI_1920x1440,0x00,0x00,0x00,0x00,0x27,-1},
121 {0x6b,0x07ff,0x0000,SIS_RI_1920x1440,0x00,0x00,0x00,0x00,0x27,-1}, 97 {0x6b,0x07ff,0x0000,SIS_RI_1920x1440,0x00,0x00,0x00,0x00,0x27,-1},
122 {0x6c,0x067b,0x0000,SIS_RI_2048x1536,0x00,0x00,0x00,0x00,0x28,-1}, /* 2048x1536x8 - not in BIOS! */ 98 {0x6c,0x067b,0x0000,SIS_RI_2048x1536,0x00,0x00,0x00,0x00,0x28,-1}, /* 2048x1536x8 */
123 {0x6d,0x06fd,0x0000,SIS_RI_2048x1536,0x00,0x00,0x00,0x00,0x28,-1}, /* 2048x1536x16 - not in BIOS! */ 99 {0x6d,0x06fd,0x0000,SIS_RI_2048x1536,0x00,0x00,0x00,0x00,0x28,-1}, /* 2048x1536x16 */
124 {0x70,0x6a1b,0x0000,SIS_RI_800x480, 0x00,0x00,0x07,0x00,0x2d,-1}, /* 800x480x8 */ 100 {0x70,0x6a1b,0x0000,SIS_RI_800x480, 0x00,0x00,0x07,0x00,0x2d,-1}, /* 800x480x8 */
125 {0x71,0x4a1b,0x0000,SIS_RI_1024x576, 0x00,0x00,0x00,0x00,0x30,-1}, /* 1024x576x8 */ 101 {0x71,0x4a1b,0x0000,SIS_RI_1024x576, 0x00,0x00,0x00,0x00,0x30,-1}, /* 1024x576x8 */
126 {0x74,0x4a1d,0x0000,SIS_RI_1024x576, 0x00,0x00,0x00,0x00,0x30,-1}, /* 1024x576x16 */ 102 {0x74,0x4a1d,0x0000,SIS_RI_1024x576, 0x00,0x00,0x00,0x00,0x30,-1}, /* 1024x576x16 */
@@ -166,77 +142,77 @@ static const SiS_ExtStruct SiS300_EModeIDTable[] =
166 {0xff,0x0000,0xffff,0, 0x00,0x00,0x00,0x00,0x00} 142 {0xff,0x0000,0xffff,0, 0x00,0x00,0x00,0x00,0x00}
167}; 143};
168 144
169static const SiS_Ext2Struct SiS300_RefIndex[] = 145static const struct SiS_Ext2 SiS300_RefIndex[] =
170{ 146{
171 {0x085f,0x0d,0x03,0x05,0x05,0x6a, 800, 600, 0}, /* 00 */ 147 {0x085f,0x0d,0x03,0x05,0x05,0x6a, 800, 600, 0, 0x00, 0x00}, /* 00 */
172 {0x0467,0x0e,0x44,0x05,0x05,0x6a, 800, 600, 0}, /* 01 */ 148 {0x0467,0x0e,0x04,0x05,0x05,0x6a, 800, 600, 0, 0x00, 0x00}, /* 01 */
173 {0x0067,0x0f,0x07,0x48,0x05,0x6a, 800, 600, 0}, /* 02 - CRT1CRTC was 0x4f */ 149 {0x0067,0x0f,0x07,0x48,0x05,0x6a, 800, 600, 0, 0x00, 0x00}, /* 02 - CRT1CRTC was 0x4f */
174 {0x0067,0x10,0x06,0x8b,0x05,0x6a, 800, 600, 0}, /* 03 */ 150 {0x0067,0x10,0x06,0x8b,0x05,0x6a, 800, 600, 0, 0x00, 0x00}, /* 03 */
175 {0x0147,0x11,0x08,0x00,0x05,0x6a, 800, 600, 0}, /* 04 */ 151 {0x0147,0x11,0x08,0x00,0x05,0x6a, 800, 600, 0, 0x00, 0x00}, /* 04 */
176 {0x0147,0x12,0x0c,0x00,0x05,0x6a, 800, 600, 0}, /* 05 */ 152 {0x0147,0x12,0x0c,0x00,0x05,0x6a, 800, 600, 0, 0x00, 0x00}, /* 05 */
177 {0x0047,0x11,0x4e,0x00,0x05,0x6a, 800, 600, 0}, /* 06 - CRT1CRTC was 0x51 */ 153 {0x0047,0x11,0x0e,0x00,0x05,0x6a, 800, 600, 0, 0x00, 0x00}, /* 06 - CRT1CRTC was 0x51 */
178 {0x0047,0x11,0x13,0x00,0x05,0x6a, 800, 600, 0}, /* 07 */ 154 {0x0047,0x11,0x13,0x00,0x05,0x6a, 800, 600, 0, 0x00, 0x00}, /* 07 */
179 {0xc85f,0x05,0x00,0x04,0x04,0x2e, 640, 480, 0}, /* 08 */ 155 {0xc85f,0x05,0x00,0x04,0x04,0x2e, 640, 480, 0, 0x00, 0x00}, /* 08 */
180 {0xc067,0x06,0x02,0x04,0x04,0x2e, 640, 480, 0}, /* 09 */ 156 {0xc067,0x06,0x02,0x04,0x04,0x2e, 640, 480, 0, 0x00, 0x00}, /* 09 */
181 {0xc067,0x07,0x02,0x47,0x04,0x2e, 640, 480, 0}, /* 0a */ 157 {0xc067,0x07,0x02,0x47,0x04,0x2e, 640, 480, 0, 0x00, 0x00}, /* 0a */
182 {0xc067,0x08,0x03,0x8a,0x04,0x2e, 640, 480, 0}, /* 0b */ 158 {0xc067,0x08,0x03,0x8a,0x04,0x2e, 640, 480, 0, 0x00, 0x00}, /* 0b */
183 {0xc047,0x09,0x05,0x00,0x04,0x2e, 640, 480, 0}, /* 0c */ 159 {0xc047,0x09,0x05,0x00,0x04,0x2e, 640, 480, 0, 0x00, 0x00}, /* 0c */
184 {0xc047,0x0a,0x08,0x00,0x04,0x2e, 640, 480, 0}, /* 0d */ 160 {0xc047,0x0a,0x08,0x00,0x04,0x2e, 640, 480, 0, 0x00, 0x00}, /* 0d */
185 {0xc047,0x0b,0x0a,0x00,0x04,0x2e, 640, 480, 0}, /* 0e */ 161 {0xc047,0x0b,0x0a,0x00,0x04,0x2e, 640, 480, 0, 0x00, 0x00}, /* 0e */
186 {0xc047,0x0c,0x10,0x00,0x04,0x2e, 640, 480, 0}, /* 0f */ 162 {0xc047,0x0c,0x10,0x00,0x04,0x2e, 640, 480, 0, 0x00, 0x00}, /* 0f */
187 {0x487f,0x04,0x00,0x00,0x00,0x2f, 640, 400, 0}, /* 10 */ 163 {0x487f,0x04,0x00,0x00,0x00,0x2f, 640, 400, 0, 0x4a, 0x49}, /* 10 */
188 {0xc06f,0x31,0x01,0x06,0x13,0x31, 720, 480, 0}, /* 11 */ 164 {0xc06f,0x31,0x01,0x06,0x13,0x31, 720, 480, 0, 0x00, 0x00}, /* 11 */
189 {0x006f,0x32,0x03,0x06,0x14,0x32, 720, 576, 0}, /* 12 */ 165 {0x006f,0x32,0x4a,0x06,0x14,0x32, 720, 576, 0, 0x00, 0x00}, /* 12 */ /* 4a was 03 */
190 {0x0187,0x15,0x05,0x00,0x06,0x37,1024, 768, 0}, /* 13 */ 166 {0x0187,0x15,0x05,0x00,0x06,0x37,1024, 768, 0, 0x00, 0x00}, /* 13 */
191 {0xc877,0x16,0x09,0x06,0x06,0x37,1024, 768, 0}, /* 14 */ 167 {0xc877,0x16,0x09,0x06,0x06,0x37,1024, 768, 0, 0x00, 0x00}, /* 14 */
192 {0xc067,0x17,0x0b,0x49,0x06,0x37,1024, 768, 0}, /* 15 - CRT1CRTC was 0x97 */ 168 {0xc067,0x17,0x0b,0x49,0x06,0x37,1024, 768, 0, 0x00, 0x00}, /* 15 - CRT1CRTC was 0x97 */
193 {0x0267,0x18,0x0d,0x00,0x06,0x37,1024, 768, 0}, /* 16 */ 169 {0x0267,0x18,0x0d,0x00,0x06,0x37,1024, 768, 0, 0x00, 0x00}, /* 16 */
194 {0x0047,0x19,0x11,0x8c,0x06,0x37,1024, 768, 0}, /* 17 - CRT1CRTC was 0x59 */ 170 {0x0047,0x19,0x11,0x8c,0x06,0x37,1024, 768, 0, 0x00, 0x00}, /* 17 - CRT1CRTC was 0x59 */
195 {0x0047,0x1a,0x52,0x00,0x06,0x37,1024, 768, 0}, /* 18 */ 171 {0x0047,0x1a,0x12,0x00,0x06,0x37,1024, 768, 0, 0x00, 0x00}, /* 18 */
196 {0x0007,0x1b,0x16,0x00,0x06,0x37,1024, 768, 0}, /* 19 - CRT1CRTC was 0x5b */ 172 {0x0007,0x1b,0x16,0x00,0x06,0x37,1024, 768, 0, 0x00, 0x00}, /* 19 - CRT1CRTC was 0x5b */
197 {0x0387,0x1c,0x4d,0x00,0x07,0x3a,1280,1024, 0}, /* 1a - CRT1CRTC was 0x5c */ 173 {0x0387,0x1c,0x0d,0x00,0x07,0x3a,1280,1024, 0, 0x00, 0x00}, /* 1a - CRT1CRTC was 0x5c */
198 {0x0077,0x1d,0x14,0x07,0x07,0x3a,1280,1024, 0}, /* 1b */ 174 {0x0077,0x1d,0x14,0x07,0x07,0x3a,1280,1024, 0, 0x00, 0x00}, /* 1b */
199 {0x0047,0x1e,0x17,0x00,0x07,0x3a,1280,1024, 0}, /* 1c */ 175 {0x0047,0x1e,0x17,0x00,0x07,0x3a,1280,1024, 0, 0x00, 0x00}, /* 1c */
200 {0x0007,0x1f,0x98,0x00,0x07,0x3a,1280,1024, 0}, /* 1d */ 176 {0x0007,0x1f,0x18,0x00,0x07,0x3a,1280,1024, 0, 0x00, 0x00}, /* 1d */
201 {0x0007,0x20,0x59,0x00,0x00,0x3c,1600,1200, 0}, /* 1e - CRT1CRTC was 0x60 */ 177 {0x0007,0x20,0x19,0x00,0x00,0x3c,1600,1200, 0, 0x00, 0x00}, /* 1e - CRT1CRTC was 0x60 */
202 {0x0007,0x21,0x5a,0x00,0x00,0x3c,1600,1200, 0}, /* 1f */ 178 {0x0007,0x21,0x1a,0x00,0x00,0x3c,1600,1200, 0, 0x00, 0x00}, /* 1f */
203 {0x0007,0x22,0x1b,0x00,0x00,0x3c,1600,1200, 0}, /* 20 */ 179 {0x0007,0x22,0x1b,0x00,0x00,0x3c,1600,1200, 0, 0x00, 0x00}, /* 20 */
204 {0x0007,0x23,0x1d,0x00,0x00,0x3c,1600,1200, 0}, /* 21 - CRT1CRTC was 0x63 */ 180 {0x0007,0x23,0x1d,0x00,0x00,0x3c,1600,1200, 0, 0x00, 0x00}, /* 21 - CRT1CRTC was 0x63 */
205 {0x0007,0x24,0x1e,0x00,0x00,0x3c,1600,1200, 0}, /* 22 */ 181 {0x0007,0x24,0x1e,0x00,0x00,0x3c,1600,1200, 0, 0x00, 0x00}, /* 22 */
206 {0x407f,0x00,0x00,0x00,0x00,0x40, 320, 200, 0}, /* 23 */ 182 {0x407f,0x00,0x00,0x00,0x00,0x40, 320, 200, 0, 0x4b, 0x4b}, /* 23 */
207 {0xc07f,0x01,0x00,0x04,0x04,0x50, 320, 240, 0}, /* 24 */ 183 {0xc07f,0x01,0x00,0x04,0x04,0x50, 320, 240, 0, 0x00, 0x00}, /* 24 */
208 {0x0077,0x02,0x04,0x05,0x05,0x51, 400, 300, 0}, /* 25 */ 184 {0x0077,0x02,0x04,0x05,0x05,0x51, 400, 300, 0, 0x00, 0x00}, /* 25 */
209 {0xc877,0x03,0x09,0x06,0x06,0x52, 512, 384, 0}, /* 26 */ /* was c077 */ 185 {0xc877,0x03,0x09,0x06,0x06,0x52, 512, 384, 0, 0x00, 0x00}, /* 26 */ /* was c077 */
210 {0x8207,0x25,0x1f,0x00,0x00,0x68,1920,1440, 0}, /* 27 */ 186 {0x8207,0x25,0x1f,0x00,0x00,0x68,1920,1440, 0, 0x00, 0x00}, /* 27 */
211 {0x0007,0x26,0x20,0x00,0x00,0x6c,2048,1536, 0}, /* 28 */ 187 {0x0007,0x26,0x20,0x00,0x00,0x6c,2048,1536, 0, 0x00, 0x00}, /* 28 */
212 {0x0067,0x27,0x14,0x08,0x0a,0x6e,1280, 960, 0}, /* 29 - 1280x960-60 */ 188 {0x0067,0x27,0x14,0x08,0x0a,0x6e,1280, 960, 0, 0x00, 0x00}, /* 29 - 1280x960-60 */
213 {0x0027,0x45,0x3c,0x08,0x0a,0x6e,1280, 960, 0}, /* 2a - 1280x960-85 */ 189 {0x0027,0x45,0x3c,0x08,0x0a,0x6e,1280, 960, 0, 0x00, 0x00}, /* 2a - 1280x960-85 */
214 {0xc077,0x33,0x09,0x06,0x00,0x20,1024, 600, 0}, /* 2b */ 190 {0xc077,0x33,0x09,0x06,0x00,0x20,1024, 600, 0, 0x00, 0x00}, /* 2b */
215 {0xc077,0x34,0x0b,0x06,0x00,0x23,1152, 768, 0}, /* 2c */ /* VCLK 0x09 */ 191 {0xc077,0x34,0x0b,0x06,0x00,0x23,1152, 768, 0, 0x00, 0x00}, /* 2c */ /* VCLK 0x09 */
216 {0x0077,0x35,0x27,0x08,0x18,0x70, 800, 480, 0}, /* 2d */ 192 {0x0077,0x35,0x27,0x08,0x18,0x70, 800, 480, 0, 0x00, 0x00}, /* 2d */
217 {0x0047,0x36,0x37,0x08,0x18,0x70, 800, 480, 0}, /* 2e */ 193 {0x0047,0x36,0x37,0x08,0x18,0x70, 800, 480, 0, 0x00, 0x00}, /* 2e */
218 {0x0047,0x37,0x08,0x08,0x18,0x70, 800, 480, 0}, /* 2f */ 194 {0x0047,0x37,0x08,0x08,0x18,0x70, 800, 480, 0, 0x00, 0x00}, /* 2f */
219 {0x0077,0x38,0x09,0x09,0x19,0x71,1024, 576, 0}, /* 30 */ 195 {0x0077,0x38,0x09,0x09,0x19,0x71,1024, 576, 0, 0x00, 0x00}, /* 30 */
220 {0x0047,0x39,0x38,0x09,0x19,0x71,1024, 576, 0}, /* 31 */ 196 {0x0047,0x39,0x38,0x09,0x19,0x71,1024, 576, 0, 0x00, 0x00}, /* 31 */
221 {0x0047,0x3a,0x11,0x09,0x19,0x71,1024, 576, 0}, /* 32 */ 197 {0x0047,0x3a,0x11,0x09,0x19,0x71,1024, 576, 0, 0x00, 0x00}, /* 32 */
222 {0x0077,0x3b,0x39,0x0a,0x0c,0x75,1280, 720, 0}, /* 33 */ 198 {0x0077,0x3b,0x39,0x0a,0x0c,0x75,1280, 720, 0, 0x00, 0x00}, /* 33 */
223 {0x0047,0x3c,0x3a,0x0a,0x0c,0x75,1280, 720, 0}, /* 34 */ 199 {0x0047,0x3c,0x3a,0x0a,0x0c,0x75,1280, 720, 0, 0x00, 0x00}, /* 34 */
224 {0x0007,0x3d,0x3b,0x0a,0x0c,0x75,1280, 720, 0}, /* 35 */ 200 {0x0007,0x3d,0x3b,0x0a,0x0c,0x75,1280, 720, 0, 0x00, 0x00}, /* 35 */
225 {0x0067,0x49,0x35,0x06,0x1a,0x29,1152, 864, 0}, /* 36 1152x864-60Hz */ 201 {0x0067,0x49,0x35,0x06,0x1a,0x29,1152, 864, 0, 0x00, 0x00}, /* 36 1152x864-60Hz */
226 {0x0067,0x3e,0x34,0x06,0x1a,0x29,1152, 864, 0}, /* 37 1152x864-75Hz */ 202 {0x0067,0x3e,0x34,0x06,0x1a,0x29,1152, 864, 0, 0x00, 0x00}, /* 37 1152x864-75Hz */
227 {0x0047,0x44,0x3a,0x06,0x1a,0x29,1152, 864, 0}, /* 38 1152x864-85Hz */ 203 {0x0047,0x44,0x3a,0x06,0x1a,0x29,1152, 864, 0, 0x00, 0x00}, /* 38 1152x864-85Hz */
228 {0x00c7,0x3f,0x28,0x00,0x16,0x39, 848, 480, 0}, /* 39 848x480-38Hzi */ 204 {0x00c7,0x3f,0x28,0x00,0x16,0x39, 848, 480, 0, 0x00, 0x00}, /* 39 848x480-38Hzi */
229 {0xc067,0x40,0x3d,0x0b,0x16,0x39, 848, 480, 0}, /* 3a 848x480-60Hz */ 205 {0xc067,0x40,0x3d,0x0b,0x16,0x39, 848, 480, 0, 0x00, 0x00}, /* 3a 848x480-60Hz */
230 {0x00c7,0x41,0x28,0x00,0x17,0x3f, 856, 480, 0}, /* 3b 856x480-38Hzi */ 206 {0x00c7,0x41,0x28,0x00,0x17,0x3f, 856, 480, 0, 0x00, 0x00}, /* 3b 856x480-38Hzi */
231 {0xc047,0x42,0x28,0x00,0x17,0x3f, 856, 480, 0}, /* 3c 856x480-60Hz */ 207 {0xc067,0x42,0x28,0x0c,0x17,0x3f, 856, 480, 0, 0x00, 0x00}, /* 3c 856x480-60Hz */
232 {0x0067,0x43,0x3e,0x0c,0x1b,0x48,1360, 768, 0}, /* 3d 1360x768-60Hz */ 208 {0x0067,0x43,0x3e,0x0d,0x1b,0x48,1360, 768, 0, 0x00, 0x00}, /* 3d 1360x768-60Hz */
233 {0x0077,0x46,0x3f,0x08,0x08,0x55,1280, 768, 0}, /* 3e 1280x768-60Hz */ 209 {0x0077,0x46,0x3f,0x08,0x08,0x55,1280, 768, 0, 0x00, 0x00}, /* 3e 1280x768-60Hz */
234 {0x006f,0x47,0x03,0x06,0x15,0x5f, 768, 576, 0}, /* 3f 768x576 */ 210 {0x006f,0x47,0x4c,0x06,0x15,0x5f, 768, 576, 0, 0x00, 0x00}, /* 3f 768x576 */
235 {0x0027,0x48,0x13,0x08,0x00,0x67,1360,1024, 0}, /* 40 1360x1024-59Hz (BARCO1366 only) */ 211 {0x0027,0x48,0x13,0x08,0x00,0x67,1360,1024, 0, 0x00, 0x00}, /* 40 1360x1024-59Hz (BARCO1366 only) */
236 {0xffff, 0, 0, 0, 0, 0, 0, 0, 0} 212 {0xffff, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0x00}
237}; 213};
238 214
239static const SiS_VBModeStruct SiS300_VBModeIDTable[] = 215static const struct SiS_VBMode SiS300_VBModeIDTable[] =
240{ 216{
241 {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 217 {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
242 {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01}, 218 {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
@@ -303,53 +279,26 @@ static const SiS_VBModeStruct SiS300_VBModeIDTable[] =
303 {0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00} 279 {0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
304}; 280};
305 281
306static const SiS_CRT1TableStruct SiS300_CRT1Table[] = 282static const struct SiS_CRT1Table SiS300_CRT1Table[] =
307{ 283{
308#if 1
309 {{0x2d,0x27,0x28,0x90,0x2c,0x80,0xbf,0x1f, /* 0x00 - 320x200 */ 284 {{0x2d,0x27,0x28,0x90,0x2c,0x80,0xbf,0x1f, /* 0x00 - 320x200 */
310 0x9c,0x8e,0x8f,0x96,0xb9,0x30,0x00,0x00, /* HRE [4],[15] is invalid - but correcting it does not work */ 285 0x9c,0x8e,0x8f,0x96,0xb9,0x30,0x00,0x00, /* HRE [4],[15] is invalid - but correcting it does not work */
311 0x00}}, 286 0x00}},
312#endif
313#if 0
314 {{0x2d,0x27,0x27,0x91,0x2c,0x92,0xbf,0x1f, /* 0x00 - corrected 320x200-72 - does not work */
315 0x9c,0x8e,0x8f,0x96,0xb9,0x30,0x00,0x04,
316 0x00}},
317#endif
318 {{0x2d,0x27,0x28,0x90,0x2c,0x80,0x0b,0x3e, /* 0x01 */ 287 {{0x2d,0x27,0x28,0x90,0x2c,0x80,0x0b,0x3e, /* 0x01 */
319 0xe9,0x8b,0xdf,0xe7,0x04,0x00,0x00,0x00, /* HRE [4],[15] is invalid - but correcting it does not work */ 288 0xe9,0x8b,0xdf,0xe7,0x04,0x00,0x00,0x00, /* HRE [4],[15] is invalid - but correcting it does not work */
320 0x00}}, 289 0x00}},
321#if 0
322 {{0x2d,0x27,0x27,0x91,0x2c,0x92,0x0b,0x3e, /* 0x01 - corrected 320x240-60 - does not work */
323 0xe9,0x8b,0xdf,0xe7,0x04,0x00,0x00,0x04,
324 0x00}},
325#endif
326 {{0x3d,0x31,0x31,0x81,0x37,0x1f,0x72,0xf0, /* 0x02 */ 290 {{0x3d,0x31,0x31,0x81,0x37,0x1f,0x72,0xf0, /* 0x02 */
327 0x58,0x8c,0x57,0x57,0x73,0x20,0x00,0x05, 291 0x58,0x8c,0x57,0x57,0x73,0x20,0x00,0x05,
328 0x01}}, 292 0x01}},
329#if 0
330 {{0x3d,0x31,0x31,0x81,0x37,0x1f,0x72,0xf0, /* 0x02 - corrected 400x300-60 */
331 0x58,0x8c,0x57,0x57,0x73,0x20,0x00,0x05,
332 0x01}},
333#endif
334 {{0x4f,0x3f,0x3f,0x93,0x45,0x0d,0x24,0xf5, 293 {{0x4f,0x3f,0x3f,0x93,0x45,0x0d,0x24,0xf5,
335 0x02,0x88,0xff,0xff,0x25,0x10,0x00,0x01, 294 0x02,0x88,0xff,0xff,0x25,0x10,0x00,0x01,
336 0x01}}, 295 0x01}},
337 {{0x5f,0x4f,0x50,0x82,0x55,0x81,0xbf,0x1f, 296 {{0x5f,0x4f,0x50,0x82,0x55,0x81,0xbf,0x1f,
338 0x9c,0x8e,0x8f,0x96,0xb9,0x30,0x00,0x05, 297 0x9c,0x8e,0x8f,0x96,0xb9,0x30,0x00,0x05,
339 0x00}}, 298 0x00}},
340#if 0
341 {{0x5f,0x4f,0x50,0x82,0x55,0x81,0x0b,0x3e, /* 0x05 */
342 0xe9,0x8b,0xdf,0xe7,0x04,0x00,0x00,0x05,
343 0x00}},
344#endif
345 {{0x5f,0x4f,0x4f,0x83,0x55,0x81,0x0b,0x3e, /* 0x05 - corrected 640x480-60 */ 299 {{0x5f,0x4f,0x4f,0x83,0x55,0x81,0x0b,0x3e, /* 0x05 - corrected 640x480-60 */
346 0xe9,0x8b,0xdf,0xe8,0x0c,0x00,0x00,0x05, 300 0xe9,0x8b,0xdf,0xe8,0x0c,0x00,0x00,0x05,
347 0x00}}, 301 0x00}},
348#if 0
349 {{0x63,0x4f,0x50,0x86,0x56,0x9b,0x06,0x3e, /* 0x06 */
350 0xe8,0x8b,0xdf,0xe7,0xff,0x10,0x00,0x01,
351 0x00}},
352#endif
353 {{0x63,0x4f,0x4f,0x87,0x56,0x9b,0x06,0x3e, /* 0x06 - corrected 640x480-72 */ 302 {{0x63,0x4f,0x4f,0x87,0x56,0x9b,0x06,0x3e, /* 0x06 - corrected 640x480-72 */
354 0xe8,0x8a,0xdf,0xe7,0x07,0x00,0x00,0x01, 303 0xe8,0x8a,0xdf,0xe7,0x07,0x00,0x00,0x01,
355 0x00}}, 304 0x00}},
@@ -359,19 +308,9 @@ static const SiS_CRT1TableStruct SiS300_CRT1Table[] =
359 {{0x63,0x4f,0x4f,0x87,0x5a,0x81,0xfb,0x1f, 308 {{0x63,0x4f,0x4f,0x87,0x5a,0x81,0xfb,0x1f,
360 0xe0,0x83,0xdf,0xdf,0xfc,0x10,0x00,0x05, 309 0xe0,0x83,0xdf,0xdf,0xfc,0x10,0x00,0x05,
361 0x00}}, 310 0x00}},
362#if 0
363 {{0x66,0x4f,0x4f,0x86,0x56,0x9e,0x03,0x3e, /* 0x09 */
364 0xe4,0x87,0xdf,0xdf,0x04,0x00,0x00,0x01,
365 0x00}},
366#endif
367 {{0x67,0x4f,0x4f,0x8b,0x57,0x83,0x10,0x3e, /* 0x09 - corrected 640x480-100 */ 311 {{0x67,0x4f,0x4f,0x8b,0x57,0x83,0x10,0x3e, /* 0x09 - corrected 640x480-100 */
368 0xe7,0x8d,0xdf,0xe6,0x11,0x00,0x00,0x05, 312 0xe7,0x8d,0xdf,0xe6,0x11,0x00,0x00,0x05,
369 0x00}}, 313 0x00}},
370#if 0
371 {{0x6c,0x4f,0x4f,0x83,0x59,0x9e,0x00,0x3e, /* 0x0a */
372 0xe5,0x8d,0xdf,0xdf,0x01,0x00,0x00,0x01,
373 0x00}},
374#endif
375 {{0x67,0x4f,0x4f,0x8b,0x57,0x83,0x10,0x3e, /* 0x0a - corrected 640x480-120 */ 314 {{0x67,0x4f,0x4f,0x8b,0x57,0x83,0x10,0x3e, /* 0x0a - corrected 640x480-120 */
376 0xe7,0x8d,0xdf,0xe6,0x11,0x00,0x00,0x05, 315 0xe7,0x8d,0xdf,0xe6,0x11,0x00,0x00,0x05,
377 0x00}}, 316 0x00}},
@@ -459,11 +398,6 @@ static const SiS_CRT1TableStruct SiS300_CRT1Table[] =
459 {{0x55,0xff,0xff,0x99,0x0d,0x0c,0x3e,0xba, 398 {{0x55,0xff,0xff,0x99,0x0d,0x0c,0x3e,0xba,
460 0x00,0x84,0xff,0xff,0x3f,0x0f,0x41,0x05, 399 0x00,0x84,0xff,0xff,0x3f,0x0f,0x41,0x05,
461 0x00}}, 400 0x00}},
462#if 0
463 {{0xdc,0x9f,0x9f,0x00,0xab,0x19,0xe6,0xef, /* 0x27: 1280x960-70 - invalid! */
464 0xc0,0xc3,0xbf,0xbf,0xe7,0x10,0x00,0x07,
465 0x01}},
466#endif
467 {{0xdc,0x9f,0x9f,0x80,0xaf,0x9d,0xe6,0xff, /* 0x27: 1280x960-60 - correct */ 401 {{0xdc,0x9f,0x9f,0x80,0xaf,0x9d,0xe6,0xff, /* 0x27: 1280x960-60 - correct */
468 0xc0,0x83,0xbf,0xbf,0xe7,0x10,0x00,0x07, 402 0xc0,0x83,0xbf,0xbf,0xe7,0x10,0x00,0x07,
469 0x01}}, 403 0x01}},
@@ -497,9 +431,9 @@ static const SiS_CRT1TableStruct SiS300_CRT1Table[] =
497 {{0x6b,0x59,0x59,0x8f,0x5e,0x8c,0x0b,0x3e, 431 {{0x6b,0x59,0x59,0x8f,0x5e,0x8c,0x0b,0x3e,
498 0xe9,0x8b,0xdf,0xe7,0x04,0x00,0x00,0x05, 432 0xe9,0x8b,0xdf,0xe7,0x04,0x00,0x00,0x05,
499 0x00}}, 433 0x00}},
500 {{0x7b,0x59,0x63,0x9f,0x6a,0x93,0x6f,0xf0, /* 0x32 */ 434 {{0x6d,0x59,0x59,0x91,0x60,0x89,0x53,0xf0, /* 0x32: 720x576, corrected to 60Hz */
501 0x58,0x8a,0x3f,0x57,0x70,0x20,0x00,0x05, 435 0x41,0x84,0x3f,0x3f,0x54,0x00,0x00,0x05,
502 0x01}}, 436 0x41}},
503 {{0xa3,0x7f,0x7f,0x87,0x86,0x97,0x1e,0xf1, /* 0x33 - 1024x600 */ 437 {{0xa3,0x7f,0x7f,0x87,0x86,0x97,0x1e,0xf1, /* 0x33 - 1024x600 */
504 0xae,0x85,0x57,0x57,0x1f,0x30,0x00,0x02, 438 0xae,0x85,0x57,0x57,0x1f,0x30,0x00,0x02,
505 0x01}}, 439 0x01}},
@@ -560,18 +494,24 @@ static const SiS_CRT1TableStruct SiS300_CRT1Table[] =
560 {{0xce,0x9f,0x9f,0x92,0xa9,0x17,0x20,0xf5, /* 1280x768-60 */ 494 {{0xce,0x9f,0x9f,0x92,0xa9,0x17,0x20,0xf5, /* 1280x768-60 */
561 0x03,0x88,0xff,0xff,0x21,0x10,0x00,0x07, 495 0x03,0x88,0xff,0xff,0x21,0x10,0x00,0x07,
562 0x01}}, /* 0x46 */ 496 0x01}}, /* 0x46 */
563 {{0x7b,0x5f,0x63,0x9f,0x6a,0x93,0x6f,0xf0, /* 768x576 */ 497 {{0x75,0x5f,0x5f,0x99,0x66,0x90,0x53,0xf0, /* 768x576, corrected to 60Hz */
564 0x58,0x8a,0x3f,0x57,0x70,0x20,0x00,0x05, 498 0x41,0x84,0x3f,0x3f,0x54,0x00,0x00,0x05,
565 0x01}}, /* 0x47 */ 499 0x41}}, /* 0x47 */
566 {{0xce,0xa9,0xa9,0x92,0xb1,0x07,0x28,0x52, /* 1360x1024 (Barco iQ Pro R300) */ 500 {{0xce,0xa9,0xa9,0x92,0xb1,0x07,0x28,0x52, /* 1360x1024 (Barco iQ Pro R300) */
567 0x02,0x8e,0xff,0x00,0x29,0x0d,0x00,0x03, 501 0x02,0x8e,0xff,0x00,0x29,0x0d,0x00,0x03,
568 0x00}}, /* 0x48 */ 502 0x00}}, /* 0x48 */
569 {{0xcd,0x8f,0x8f,0x91,0x9b,0x1b,0x7a,0xff, /* 1152x864-60 */ 503 {{0xcd,0x8f,0x8f,0x91,0x9b,0x1b,0x7a,0xff, /* 1152x864-60 */
570 0x64,0x8c,0x5f,0x62,0x7b,0x10,0x00,0x07, 504 0x64,0x8c,0x5f,0x62,0x7b,0x10,0x00,0x07,
571 0x41}} /* 0x49 */ 505 0x41}}, /* 0x49 */
506 {{0x5c,0x4f,0x4f,0x80,0x57,0x80,0xa3,0x1f, /* fake 640x400@60Hz (for LCD and TV, not actually used) */
507 0x98,0x8c,0x8f,0x96,0xa4,0x30,0x00,0x05,
508 0x40}}, /* 0x4a */
509 {{0x2c,0x27,0x27,0x90,0x2d,0x92,0xa4,0x1f, /* fake 320x200@60Hz (for LCD and TV, not actually used) */
510 0x98,0x8c,0x8f,0x96,0xa5,0x30,0x00,0x04,
511 0x00}} /* 0x4b */
572}; 512};
573 513
574static const SiS_MCLKDataStruct SiS300_MCLKData_630[] = 514static const struct SiS_MCLKData SiS300_MCLKData_630[] =
575{ 515{
576 { 0x5a,0x64,0x80, 66}, 516 { 0x5a,0x64,0x80, 66},
577 { 0xb3,0x45,0x80, 83}, 517 { 0xb3,0x45,0x80, 83},
@@ -583,7 +523,7 @@ static const SiS_MCLKDataStruct SiS300_MCLKData_630[] =
583 { 0x37,0x61,0x80,100} 523 { 0x37,0x61,0x80,100}
584}; 524};
585 525
586static const SiS_MCLKDataStruct SiS300_MCLKData_300[] = 526static const struct SiS_MCLKData SiS300_MCLKData_300[] =
587{ 527{
588 { 0x68,0x43,0x80,125}, 528 { 0x68,0x43,0x80,125},
589 { 0x68,0x43,0x80,125}, 529 { 0x68,0x43,0x80,125},
@@ -595,7 +535,7 @@ static const SiS_MCLKDataStruct SiS300_MCLKData_300[] =
595 { 0x37,0x61,0x80,100} 535 { 0x37,0x61,0x80,100}
596}; 536};
597 537
598static SiS_VCLKDataStruct SiS300_VCLKData[] = 538static struct SiS_VCLKData SiS300_VCLKData[] =
599{ 539{
600 { 0x1b,0xe1, 25}, /* 0x00 */ 540 { 0x1b,0xe1, 25}, /* 0x00 */
601 { 0x4e,0xe4, 28}, /* 0x01 */ 541 { 0x4e,0xe4, 28}, /* 0x01 */
@@ -669,53 +609,26 @@ static SiS_VCLKDataStruct SiS300_VCLKData[] =
669 { 0xe2,0x46,135}, /* 0x45 */ /* 1280x1024-75, better clock for VGA2 */ 609 { 0xe2,0x46,135}, /* 0x45 */ /* 1280x1024-75, better clock for VGA2 */
670 { 0x70,0x29, 81}, /* 0x46 */ /* unused */ 610 { 0x70,0x29, 81}, /* 0x46 */ /* unused */
671 { 0, 0, 0}, /* 0x47 custom (will be filled out) */ 611 { 0, 0, 0}, /* 0x47 custom (will be filled out) */
672 { 0xce,0x25,189} /* 0x48 */ /* Replacement for index 0x1b for 730 (and 540?) */ 612 { 0xce,0x25,189}, /* 0x48 */ /* Replacement for index 0x1b for 730 (and 540?) */
613 { 0x15,0xe1, 20}, /* 0x49 */ /* 640x400@60 (fake, not actually used) */
614 { 0x5f,0xc6, 33}, /* 0x4a */ /* 720x576@60 */
615 { 0x37,0x5a, 10}, /* 0x4b */ /* 320x200@60 (fake, not actually used) */
616 { 0x2b,0xc2, 35} /* 0x4c */ /* 768@576@60 */
673}; 617};
674 618
675#ifdef LINUX_KERNEL 619static const unsigned char SiS300_SR15[4 * 8] =
676static UCHAR SiS300_SR07 = 0x10;
677#endif
678
679static const DRAM4Type SiS300_SR15[8] =
680{ 620{
681 {0x01,0x09,0xa3,0x00}, 621 0x01,0x09,0xa3,0x00,
682 {0x43,0x43,0x43,0x00}, 622 0x43,0x43,0x43,0x00,
683 {0x1e,0x1e,0x1e,0x00}, 623 0x1e,0x1e,0x1e,0x00,
684 {0x2a,0x2a,0x2a,0x00}, 624 0x2a,0x2a,0x2a,0x00,
685 {0x06,0x06,0x06,0x00}, 625 0x06,0x06,0x06,0x00,
686 {0x00,0x00,0x00,0x00}, 626 0x00,0x00,0x00,0x00,
687 {0x00,0x00,0x00,0x00}, 627 0x00,0x00,0x00,0x00,
688 {0x00,0x00,0x00,0x00} 628 0x00,0x00,0x00,0x00
689}; 629};
690 630
691#ifdef LINUX_KERNEL 631static const struct SiS_PanelDelayTbl SiS300_PanelDelayTbl[] =
692static UCHAR SiS300_SR1F = 0x00;
693static UCHAR SiS300_SR21 = 0x16;
694static UCHAR SiS300_SR22 = 0xb2;
695static UCHAR SiS300_SR23 = 0xf6;
696static UCHAR SiS300_SR24 = 0x0d;
697static UCHAR SiS300_SR25[] = {0x0,0x0};
698static UCHAR SiS300_SR31 = 0x00;
699static UCHAR SiS300_SR32 = 0x11;
700static UCHAR SiS300_SR33 = 0x00;
701static UCHAR SiS300_CRT2Data_1_2 = 0x40;
702static UCHAR SiS300_CRT2Data_4_D = 0x00;
703static UCHAR SiS300_CRT2Data_4_E = 0x00;
704static UCHAR SiS300_CRT2Data_4_10 = 0x80;
705
706static const USHORT SiS300_RGBSenseData = 0xd1;
707static const USHORT SiS300_VideoSenseData = 0xb3;
708static const USHORT SiS300_YCSenseData = 0xb9;
709static const USHORT SiS300_RGBSenseData2 = 0x0190;
710static const USHORT SiS300_VideoSenseData2 = 0x0174;
711static const USHORT SiS300_YCSenseData2 = 0x016b;
712
713static const DRAM4Type SiS300_CR40[5];
714
715static UCHAR SiS300_CR49[2];
716#endif
717
718static const SiS_PanelDelayTblStruct SiS300_PanelDelayTbl[] =
719{ 632{
720 {{0x05,0xaa}}, 633 {{0x05,0xaa}},
721 {{0x05,0x14}}, 634 {{0x05,0x14}},
@@ -735,33 +648,11 @@ static const SiS_PanelDelayTblStruct SiS300_PanelDelayTbl[] =
735 {{0x05,0x60}} 648 {{0x05,0x60}}
736}; 649};
737 650
738#if 0
739static const SiS_PanelDelayTblStruct SiS300_PanelDelayTblLVDS[] =
740{
741 {{0x05,0xaa}},
742 {{0x05,0x14}},
743 {{0x05,0x36}},
744 {{0x05,0x14}},
745 {{0x05,0x14}},
746 {{0x05,0x14}},
747 {{0x05,0x90}},
748 {{0x05,0x90}},
749 {{0x05,0x14}},
750 {{0x05,0x14}},
751 {{0x05,0x14}},
752 {{0x05,0x14}}, /* 2.07a (JVC): 14,96 */
753 {{0x05,0x28}}, /* 2.04.5c: 20, 80 - Clevo (2.04.2c): 05, 28 */
754 {{0x05,0x14}},
755 {{0x05,0x14}}, /* Some BIOSes: 05, 40 */
756 {{0x05,0x60}}
757};
758#endif
759
760/**************************************************************/ 651/**************************************************************/
761/* SIS VIDEO BRIDGE ----------------------------------------- */ 652/* SIS VIDEO BRIDGE ----------------------------------------- */
762/**************************************************************/ 653/**************************************************************/
763 654
764static const SiS_LCDDataStruct SiS300_St2LCD1024x768Data[] = 655static const struct SiS_LCDData SiS300_St2LCD1024x768Data[] =
765{ 656{
766 { 62, 25, 800, 546,1344, 806}, 657 { 62, 25, 800, 546,1344, 806},
767 { 32, 15, 930, 546,1344, 806}, 658 { 32, 15, 930, 546,1344, 806},
@@ -772,7 +663,7 @@ static const SiS_LCDDataStruct SiS300_St2LCD1024x768Data[] =
772 { 1, 1,1344, 806,1344, 806} 663 { 1, 1,1344, 806,1344, 806}
773}; 664};
774 665
775static const SiS_LCDDataStruct SiS300_ExtLCD1024x768Data[] = 666static const struct SiS_LCDData SiS300_ExtLCD1024x768Data[] =
776{ 667{
777 { 12, 5, 896, 512,1344, 806}, 668 { 12, 5, 896, 512,1344, 806},
778 { 12, 5, 896, 510,1344, 806}, 669 { 12, 5, 896, 510,1344, 806},
@@ -789,7 +680,7 @@ static const SiS_LCDDataStruct SiS300_ExtLCD1024x768Data[] =
789 { 1, 1,1344, 806,1344, 806} 680 { 1, 1,1344, 806,1344, 806}
790}; 681};
791 682
792static const SiS_LCDDataStruct SiS300_St2LCD1280x1024Data[] = 683static const struct SiS_LCDData SiS300_St2LCD1280x1024Data[] =
793{ 684{
794 { 22, 5, 800, 510,1650,1088}, 685 { 22, 5, 800, 510,1650,1088},
795 { 22, 5, 800, 510,1650,1088}, 686 { 22, 5, 800, 510,1650,1088},
@@ -801,7 +692,7 @@ static const SiS_LCDDataStruct SiS300_St2LCD1280x1024Data[] =
801 { 1, 1,1688,1066,1688,1066} 692 { 1, 1,1688,1066,1688,1066}
802}; 693};
803 694
804static const SiS_LCDDataStruct SiS300_ExtLCD1280x1024Data[] = 695static const struct SiS_LCDData SiS300_ExtLCD1280x1024Data[] =
805{ 696{
806 { 211, 60,1024, 501,1688,1066}, 697 { 211, 60,1024, 501,1688,1066},
807 { 211, 60,1024, 508,1688,1066}, 698 { 211, 60,1024, 508,1688,1066},
@@ -813,53 +704,116 @@ static const SiS_LCDDataStruct SiS300_ExtLCD1280x1024Data[] =
813 { 1, 1,1688,1066,1688,1066} 704 { 1, 1,1688,1066,1688,1066}
814}; 705};
815 706
816static const SiS_Part2PortTblStruct SiS300_CRT2Part2_1024x768_1[] = 707static const struct SiS_Part2PortTbl SiS300_CRT2Part2_1024x768_1[] =
817{ /* VESA Timing */ 708{ /* VESA Timing */
818 {{0x21,0x12,0xbf,0xe4,0xc0,0x21,0x45,0x09,0x00,0xa9,0x09,0x04}}, 709 {{0x21,0x12,0xbf,0xe4,0xc0,0x21,0x45,0x09,0x00,0xa9,0x09,0x04}},
819 {{0x2c,0x12,0x9a,0xae,0x88,0x21,0x45,0x09,0x00,0xa9,0x09,0x04}}, 710 {{0x2c,0x12,0x9a,0xae,0x88,0x21,0x45,0x09,0x00,0xa9,0x09,0x04}},
820 {{0x21,0x12,0xbf,0xe4,0xc0,0x21,0x45,0x09,0x00,0xa9,0x09,0x04}}, 711 {{0x21,0x12,0xbf,0xe4,0xc0,0x21,0x45,0x09,0x00,0xa9,0x09,0x04}},
821 {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, 712 {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
822 {{0x22,0x13,0xfe,0x25,0xff,0x21,0x45,0x0a,0x00,0xa9,0x0d,0x04}}, 713 {{0x22,0x13,0xfe,0x25,0xff,0x21,0x45,0x0a,0x00,0xa9,0x0d,0x04}},
823 {{0x22,0x13,0xfe,0x25,0xff,0x21,0x45,0x0a,0x00,0xa9,0x0d,0x04}}, 714 {{0x22,0x13,0xfe,0x25,0xff,0x21,0x45,0x0a,0x00,0xa9,0x0d,0x04}},
824 {{0x22,0x13,0xfe,0x25,0xff,0x21,0x45,0x0a,0x00,0xa9,0x0d,0x04}} 715 {{0x22,0x13,0xfe,0x25,0xff,0x21,0x45,0x0a,0x00,0xa9,0x0d,0x04}}
825}; 716};
826 717
827static const SiS_Part2PortTblStruct SiS300_CRT2Part2_1024x768_2[] = 718static const struct SiS_Part2PortTbl SiS300_CRT2Part2_1024x768_2[] =
828{ /* Non-VESA */ 719{ /* Non-VESA */
829 {{0x28,0x12,0xa3,0xd0,0xaa,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}}, 720 {{0x28,0x12,0xa3,0xd0,0xaa,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}},
830 {{0x2c,0x12,0x9a,0xae,0x88,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}}, 721 {{0x2c,0x12,0x9a,0xae,0x88,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}},
831 {{0x28,0x12,0xa3,0xd0,0xaa,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}}, 722 {{0x28,0x12,0xa3,0xd0,0xaa,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}},
832 {{0x2c,0x12,0x9a,0xae,0x88,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}}, 723 {{0x2c,0x12,0x9a,0xae,0x88,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}},
833 {{0x28,0x13,0xe7,0x0b,0xe8,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}}, 724 {{0x28,0x13,0xe7,0x0b,0xe8,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}},
834 {{0x38,0x18,0x16,0x00,0x00,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}}, 725 {{0x38,0x18,0x16,0x00,0x00,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}},
835 {{0x36,0x13,0x13,0x25,0xff,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}} 726 {{0x36,0x13,0x13,0x25,0xff,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}}
836};
837
838static const SiS_Part2PortTblStruct SiS300_CRT2Part2_1024x768_3[] =
839{
840 {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}
841};
842
843static const SiS_Part2PortTblStruct SiS300_CRT2Part2_1280x1024_1[] =
844{
845 {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}
846};
847
848static const SiS_Part2PortTblStruct SiS300_CRT2Part2_1280x1024_2[] =
849{
850 {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}
851}; 727};
852 728
853static const SiS_Part2PortTblStruct SiS300_CRT2Part2_1280x1024_3[] = 729static const struct SiS_Part2PortTbl SiS300_CRT2Part2_1024x768_3[] =
854{ 730{
855 {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}} 731 {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}
856}; 732};
857 733
858/**************************************************************/ 734/**************************************************************/
859/* LVDS/Chrontel -------------------------------------------- */ 735/* LVDS/Chrontel -------------------------------------------- */
860/**************************************************************/ 736/**************************************************************/
861 737
862static const SiS_LVDSDataStruct SiS300_CHTVUPALData[] = 738/* Custom data for Barco iQ R series */
739static const struct SiS_LVDSData SiS300_LVDSBARCO1366Data_1[]=
740{
741 { 832, 438,1331, 806},
742 { 832, 388,1331, 806},
743 { 832, 438,1331, 806},
744 { 832, 388,1331, 806},
745 { 832, 518,1331, 806},
746 {1050, 638,1344, 806},
747 {1344, 806,1344, 806},
748 {1688,1066,1688,1066},
749 {1688,1066,1688,1066} /* 1360x1024 */
750};
751
752/* Custom data for Barco iQ R series */
753static const struct SiS_LVDSData SiS300_LVDSBARCO1366Data_2[]=
754{
755 {1344, 806,1344, 806},
756 {1344, 806,1344, 806},
757 {1344, 806,1344, 806},
758 {1344, 806,1344, 806},
759 {1344, 806,1344, 806},
760 {1344, 806,1344, 806},
761 {1344, 806,1344, 806},
762 {1688,1066,1688,1066},
763 {1688,1066,1688,1066} /* 1360x1024 */
764};
765
766/* Custom data for Barco iQ G series */
767static const struct SiS_LVDSData SiS300_LVDSBARCO1024Data_1[]=
768{
769 { 832, 438,1331, 806},
770 { 832, 409,1331, 806},
771 { 832, 438,1331, 806},
772 { 832, 409,1331, 806},
773 { 832, 518,1331, 806}, /* 640x480 */
774 {1050, 638,1344, 806}, /* 800x600 */
775 {1344, 806,1344, 806}, /* 1024x768 */
776};
777
778/* Custom data for 848x480 and 856x480 parallel LVDS panels */
779static const struct SiS_LVDSData SiS300_LVDS848x480Data_1[]=
780{
781 { 0, 0, 0, 0},
782 { 0, 0, 0, 0},
783 { 0, 0, 0, 0},
784 { 0, 0, 0, 0},
785 {1088, 525,1088, 525}, /* 640x480 TODO */
786 {1088, 525,1088, 525}, /* 800x600 TODO */
787 {1088, 525,1088, 525}, /* 1024x768 TODO */
788 { 0, 0, 0, 0},
789 { 0, 0, 0, 0},
790 { 0, 0, 0, 0},
791 { 0, 0, 0, 0},
792 {1088, 525,1088, 525}, /* 848x480 */
793 {1088, 525,1088, 525}, /* 856x480 */
794 {1088, 525,1088, 525} /* 1360x768 TODO */
795};
796
797/* Custom data for 848x480 parallel panel */
798static const struct SiS_LVDSData SiS300_LVDS848x480Data_2[]=
799{
800 { 0, 0, 0, 0},
801 { 0, 0, 0, 0},
802 { 0, 0, 0, 0},
803 { 0, 0, 0, 0},
804 {1088, 525,1088, 525}, /* 640x480 */
805 {1088, 525,1088, 525}, /* 800x600 */
806 {1088, 525,1088, 525}, /* 1024x768 */
807 { 0, 0, 0, 0},
808 { 0, 0, 0, 0},
809 { 0, 0, 0, 0},
810 { 0, 0, 0, 0},
811 {1088, 525,1088, 525}, /* 848x480 */
812 {1088, 525,1088, 525}, /* 856x480 */
813 {1088, 525,1088, 525} /* 1360x768 TODO */
814};
815
816static const struct SiS_LVDSData SiS300_CHTVUPALData[] =
863{ 817{
864 {1008, 625,1008, 625}, 818 {1008, 625,1008, 625},
865 {1008, 625,1008, 625}, 819 {1008, 625,1008, 625},
@@ -869,7 +823,7 @@ static const SiS_LVDSDataStruct SiS300_CHTVUPALData[] =
869 { 936, 836, 936, 836} 823 { 936, 836, 936, 836}
870}; 824};
871 825
872static const SiS_LVDSDataStruct SiS300_CHTVOPALData[] = 826static const struct SiS_LVDSData SiS300_CHTVOPALData[] =
873{ 827{
874 {1008, 625,1008, 625}, 828 {1008, 625,1008, 625},
875 {1008, 625,1008, 625}, 829 {1008, 625,1008, 625},
@@ -879,7 +833,7 @@ static const SiS_LVDSDataStruct SiS300_CHTVOPALData[] =
879 { 960, 750, 960, 750} 833 { 960, 750, 960, 750}
880}; 834};
881 835
882static const SiS_LVDSDataStruct SiS300_CHTVSOPALData[] = 836static const struct SiS_LVDSData SiS300_CHTVSOPALData[] =
883{ 837{
884 {1008, 625,1008, 625}, 838 {1008, 625,1008, 625},
885 {1008, 625,1008, 625}, 839 {1008, 625,1008, 625},
@@ -889,486 +843,8 @@ static const SiS_LVDSDataStruct SiS300_CHTVSOPALData[] =
889 { 944, 625, 944, 625} 843 { 944, 625, 944, 625}
890}; 844};
891 845
892 846/* Custom des data for Barco iQ R200/300/400 (BIOS 2.00.07) */
893static const SiS_LVDSDesStruct SiS300_PanelType00_1[] = 847static const struct SiS_LVDSDes SiS300_PanelType04_1a[] = /* 1280x1024 (1366x1024) */
894{
895 { 1059, 626 }, /* 2.08 */
896 { 1059, 624 },
897 { 1059, 626 },
898 { 1059, 624 },
899 { 1059, 624 },
900 { 0, 627 },
901 { 0, 627 },
902 { 0, 0 },
903 { 0, 0 }
904#if 0
905 {0, 626},
906 {0, 624},
907 {0, 626},
908 {0, 624},
909 {0, 624},
910 {0, 627},
911 {0, 627},
912 {0, 0},
913 {0, 0}
914#endif
915};
916
917static const SiS_LVDSDesStruct SiS300_PanelType01_1[] =
918{
919 { 0, 0 }, /* 2.08 */
920 { 0, 0 },
921 { 0, 0 },
922 { 0, 0 },
923 { 0, 0 },
924 { 0, 0 },
925 { 0, 0 },
926 { 0, 0 },
927 { 0, 0 }
928#if 0
929 {1343, 798},
930 {1343, 794},
931 {1343, 798},
932 {1343, 794},
933 {1343, 0},
934 {1343, 0},
935 { 0, 805},
936 { 0, 794},
937 { 0, 0}
938#endif
939};
940
941static const SiS_LVDSDesStruct SiS300_PanelType02_1[] =
942{
943 { 1059, 626 }, /* 2.08 */
944 { 1059, 624 },
945 { 1059, 626 },
946 { 1059, 624 },
947 { 1059, 624 },
948 { 0, 627 },
949 { 0, 627 },
950 { 0, 0 },
951 { 0, 0 }
952#if 0
953 {0, 626},
954 {0, 624},
955 {0, 626},
956 {0, 624},
957 {0, 624},
958 {0, 627},
959 {0, 627},
960 {0, 0},
961 {0, 0}
962#endif
963};
964
965static const SiS_LVDSDesStruct SiS300_PanelType03_1[] =
966{
967 { 8, 436},
968 { 8, 440},
969 { 8, 436},
970 { 8, 440},
971 { 8, 512},
972 {1343, 798},
973 {1343, 794},
974 {1343, 798},
975 {1343, 794}
976};
977
978static const SiS_LVDSDesStruct SiS300_PanelType04_1[] = /* 1280x1024 */
979{
980 {1343, 798},
981 {1343, 794},
982 {1343, 798},
983 {1343, 794},
984 {1343, 0},
985 {1343, 0},
986 { 0, 805},
987 { 0, 794},
988 { 0, 0}
989};
990
991static const SiS_LVDSDesStruct SiS300_PanelType05_1[] =
992{
993 {1343, 798},
994 {1343, 794},
995 {1343, 798},
996 {1343, 794},
997 {1343, 0},
998 {1343, 0},
999 { 0, 805},
1000 { 0, 794},
1001 { 0, 0}
1002};
1003
1004static const SiS_LVDSDesStruct SiS300_PanelType06_1[] = /* Clevo Trumpion 1024x768 */
1005{
1006 {1343, 798},
1007 {1343, 794},
1008 {1343, 798},
1009 {1343, 794},
1010 {1343, 0},
1011 {1343, 0},
1012 { 0, 805},
1013 { 0, 794},
1014 { 0, 0}
1015};
1016
1017static const SiS_LVDSDesStruct SiS300_PanelType07_1[] =
1018{
1019 {1343, 798},
1020 {1343, 794},
1021 {1343, 798},
1022 {1343, 794},
1023 {1343, 0},
1024 {1343, 0},
1025 { 0, 805},
1026 { 0, 794},
1027 { 0, 0}
1028};
1029
1030static const SiS_LVDSDesStruct SiS300_PanelType08_1[] =
1031{
1032 {1059, 626},
1033 {1059, 624},
1034 {1059, 626},
1035 {1059, 624},
1036 {1059, 624},
1037 { 0, 627},
1038 { 0, 627},
1039 { 0, 0},
1040 { 0, 0}
1041};
1042
1043static const SiS_LVDSDesStruct SiS300_PanelType09_1[] =
1044{
1045 {1343, 798},
1046 {1343, 794},
1047 {1343, 798},
1048 {1343, 794},
1049 {1343, 0},
1050 {1343, 0},
1051 { 0, 805},
1052 { 0, 794},
1053 { 0, 0}
1054};
1055
1056static const SiS_LVDSDesStruct SiS300_PanelType0a_1[] =
1057{
1058 {1059, 626},
1059 {1059, 624},
1060 {1059, 626},
1061 {1059, 624},
1062 {1059, 624},
1063 { 0, 627},
1064 { 0, 627},
1065 { 0, 0},
1066 { 0, 0}
1067};
1068
1069static const SiS_LVDSDesStruct SiS300_PanelType0b_1[] =
1070{
1071 {1343, 0},
1072 {1343, 0},
1073 {1343, 0},
1074 {1343, 0},
1075 {1343, 0},
1076 {1343, 0},
1077 { 0, 799},
1078 { 0, 0},
1079 { 0, 0}
1080};
1081
1082static const SiS_LVDSDesStruct SiS300_PanelType0c_1[] =
1083{
1084 {1343, 798},
1085 {1343, 794},
1086 {1343, 798},
1087 {1343, 794},
1088 {1343, 0},
1089 {1343, 0},
1090 { 0, 805},
1091 { 0, 794},
1092 { 0, 0}
1093};
1094
1095static const SiS_LVDSDesStruct SiS300_PanelType0d_1[] =
1096{
1097 {1343, 798},
1098 {1343, 794},
1099 {1343, 798},
1100 {1343, 794},
1101 {1343, 0},
1102 {1343, 0},
1103 { 0, 805},
1104 { 0, 794},
1105 { 0, 0}
1106};
1107
1108static const SiS_LVDSDesStruct SiS300_PanelType0e_1[] =
1109{
1110 {1343, 798},
1111 {1343, 794},
1112 {1343, 798},
1113 {1343, 794},
1114 {1343, 0}, /* 640x480 */
1115 {1343, 0}, /* 800x600 */
1116 { 0, 805}, /* 1024x768 */
1117 { 0, 794}, /* 1280x1024 */
1118 { 0, 0} /* 1280x960 - not applicable */
1119};
1120
1121static const SiS_LVDSDesStruct SiS300_PanelType0f_1[] =
1122{
1123 {1343, 798},
1124 {1343, 794},
1125 {1343, 798},
1126 {1343, 794},
1127 {1343, 0},
1128 {1343, 0},
1129 { 0, 805},
1130 { 0, 794},
1131 { 0, 0}
1132};
1133
1134static const SiS_LVDSDesStruct SiS300_PanelType00_2[] =
1135{
1136 {976, 527},
1137 {976, 502},
1138 {976, 527},
1139 {976, 502},
1140 {976, 567},
1141 { 0, 627},
1142 { 0, 627},
1143 { 0, 0},
1144 { 0, 0}
1145};
1146
1147static const SiS_LVDSDesStruct SiS300_PanelType01_2[] =
1148{
1149 {1152, 622},
1150 {1152, 597},
1151 {1152, 622},
1152 {1152, 597},
1153 {1152, 662},
1154 {1232, 722},
1155 { 0, 805},
1156 { 0, 794},
1157 { 0, 0}
1158};
1159
1160static const SiS_LVDSDesStruct SiS300_PanelType02_2[] =
1161{
1162 {976, 527},
1163 {976, 502},
1164 {976, 527},
1165 {976, 502},
1166 {976, 567},
1167 { 0, 627},
1168 { 0, 627},
1169 { 0, 0},
1170 { 0, 0}
1171};
1172
1173static const SiS_LVDSDesStruct SiS300_PanelType03_2[] =
1174{
1175 {1152, 622},
1176 {1152, 597},
1177 {1152, 622},
1178 {1152, 597},
1179 {1152, 662},
1180 {1232, 722},
1181 { 0, 805},
1182 {1152, 622},
1183 {1152, 597}
1184};
1185
1186static const SiS_LVDSDesStruct SiS300_PanelType04_2[] =
1187{
1188 {1152, 622},
1189 {1152, 597},
1190 {1152, 622},
1191 {1152, 597},
1192 {1152, 662},
1193 {1232, 722},
1194 { 0, 805},
1195 { 0, 794},
1196 { 0, 0}
1197};
1198
1199static const SiS_LVDSDesStruct SiS300_PanelType05_2[] =
1200{
1201 {1152, 622},
1202 {1152, 597},
1203 {1152, 622},
1204 {1152, 597},
1205 {1152, 662},
1206 {1232, 722},
1207 { 0, 805},
1208 { 0, 794},
1209 { 0, 0}
1210};
1211
1212static const SiS_LVDSDesStruct SiS300_PanelType06_2[] =
1213{
1214 {1152, 622},
1215 {1152, 597},
1216 {1152, 622},
1217 {1152, 597},
1218 {1152, 662},
1219 {1232, 722},
1220 { 0, 805},
1221 { 0, 794},
1222 { 0, 0}
1223};
1224
1225static const SiS_LVDSDesStruct SiS300_PanelType07_2[] =
1226{
1227 {1152, 622},
1228 {1152, 597},
1229 {1152, 622},
1230 {1152, 597},
1231 {1152, 662},
1232 {1232, 722},
1233 { 0, 805},
1234 { 0, 794},
1235 { 0, 0}
1236};
1237
1238static const SiS_LVDSDesStruct SiS300_PanelType08_2[] =
1239{
1240 {976, 527},
1241 {976, 502},
1242 {976, 527},
1243 {976, 502},
1244 {976, 567},
1245 { 0, 627},
1246 { 0, 627},
1247 { 0, 0},
1248 { 0, 0}
1249};
1250
1251static const SiS_LVDSDesStruct SiS300_PanelType09_2[] =
1252{
1253 {1152, 622},
1254 {1152, 597},
1255 {1152, 622},
1256 {1152, 597},
1257 {1152, 662},
1258 {1232, 722},
1259 { 0, 805},
1260 { 0, 794},
1261 { 0, 0}
1262};
1263
1264static const SiS_LVDSDesStruct SiS300_PanelType0a_2[] =
1265{
1266 {976, 527},
1267 {976, 502},
1268 {976, 527},
1269 {976, 502},
1270 {976, 567},
1271 { 0, 627},
1272 { 0, 627},
1273 { 0, 0},
1274 { 0, 0}
1275};
1276
1277static const SiS_LVDSDesStruct SiS300_PanelType0b_2[] =
1278{
1279 { 1152, 700},
1280 { 1152, 675},
1281 { 1152, 700},
1282 { 1152, 675},
1283 { 1152, 740},
1284 { 1232, 799},
1285 { 0, 799},
1286 { 0, 0},
1287 { 0, 0}
1288};
1289
1290static const SiS_LVDSDesStruct SiS300_PanelType0c_2[] =
1291{
1292 {1152, 622},
1293 {1152, 597},
1294 {1152, 622},
1295 {1152, 597},
1296 {1152, 662},
1297 {1232, 722},
1298 { 0, 805},
1299 { 0, 794},
1300 { 0, 0}
1301};
1302
1303static const SiS_LVDSDesStruct SiS300_PanelType0d_2[] =
1304{
1305 {1152, 622},
1306 {1152, 597},
1307 {1152, 622},
1308 {1152, 597},
1309 {1152, 662},
1310 {1232, 722},
1311 { 0, 805},
1312 { 0, 794},
1313 { 0, 0}
1314};
1315
1316static const SiS_LVDSDesStruct SiS300_PanelType0e_2[] =
1317{
1318 {1152, 622},
1319 {1152, 597},
1320 {1152, 622},
1321 {1152, 597},
1322 {1152, 662},
1323 {1232, 722},
1324 { 0, 805},
1325 { 0, 794},
1326 { 0, 0}
1327};
1328
1329static const SiS_LVDSDesStruct SiS300_PanelType0f_2[] =
1330{
1331 {1152, 622},
1332 {1152, 597},
1333 {1152, 622},
1334 {1152, 597},
1335 {1152, 662},
1336 {1232, 722},
1337 { 0, 805},
1338 { 0, 794},
1339 { 0, 0}
1340};
1341
1342static const SiS_LVDSDesStruct SiS300_PanelTypeNS_1[]=
1343{
1344 { 0, 0},
1345 { 0, 0},
1346 { 0, 0},
1347 { 0, 0},
1348 { 0, 0},
1349 { 0, 0},
1350 { 0, 805},
1351 { 0, 0},
1352 { 0, 0},
1353 { 0, 0}
1354};
1355
1356static const SiS_LVDSDesStruct SiS300_PanelTypeNS_2[] =
1357{
1358 { 0 , 0},
1359 { 0 , 0},
1360 { 0 , 0},
1361 { 0 , 0},
1362 { 0 , 0},
1363 { 0 , 0},
1364 { 0 , 0},
1365 { 0 , 0},
1366 { 0 , 0},
1367 { 0 , 0}
1368};
1369
1370/* Custom data for Barco iQ R200/300/400 (BIOS 2.00.07) */
1371static const SiS_LVDSDesStruct SiS300_PanelType04_1a[] = /* 1280x1024 (1366x1024) */
1372{ 848{
1373 {1330, 798}, /* 320x200 */ 849 {1330, 798}, /* 320x200 */
1374 {1330, 794}, 850 {1330, 794},
@@ -1381,7 +857,7 @@ static const SiS_LVDSDesStruct SiS300_PanelType04_1a[] = /* 1280x1024 (1366x102
1381 { 0, 0} /* 1360x1024 */ 857 { 0, 0} /* 1360x1024 */
1382}; 858};
1383 859
1384static const SiS_LVDSDesStruct SiS300_PanelType04_2a[] = 860static const struct SiS_LVDSDes SiS300_PanelType04_2a[] =
1385{ 861{
1386 {1152, 622}, 862 {1152, 622},
1387 {1152, 597}, 863 {1152, 597},
@@ -1394,8 +870,8 @@ static const SiS_LVDSDesStruct SiS300_PanelType04_2a[] =
1394 { 0, 0} 870 { 0, 0}
1395}; 871};
1396 872
1397/* Custom data for Barco iQ G200/300/400 (BIOS 2.00.07) */ 873/* Custom des data for Barco iQ G200/300/400 (BIOS 2.00.07) */
1398static const SiS_LVDSDesStruct SiS300_PanelType04_1b[] = /* 1024x768 */ 874static const struct SiS_LVDSDes SiS300_PanelType04_1b[] = /* 1024x768 */
1399{ 875{
1400 {1330, 798}, /* 320x200 */ 876 {1330, 798}, /* 320x200 */
1401 {1330, 794}, 877 {1330, 794},
@@ -1406,7 +882,7 @@ static const SiS_LVDSDesStruct SiS300_PanelType04_1b[] = /* 1024x768 */
1406 { 0, 805} /* 1024x768 / 512x384 */ 882 { 0, 805} /* 1024x768 / 512x384 */
1407}; 883};
1408 884
1409static const SiS_LVDSDesStruct SiS300_PanelType04_2b[] = 885static const struct SiS_LVDSDes SiS300_PanelType04_2b[] =
1410{ 886{
1411 {1152, 622}, 887 {1152, 622},
1412 {1152, 597}, 888 {1152, 597},
@@ -1419,376 +895,7 @@ static const SiS_LVDSDesStruct SiS300_PanelType04_2b[] =
1419 895
1420/* CRT1 CRTC for slave modes */ 896/* CRT1 CRTC for slave modes */
1421 897
1422static const SiS_LVDSCRT1DataStruct SiS300_LVDSCRT1800x600_1[] = 898static const struct SiS_LVDSCRT1Data SiS300_CHTVCRT1UNTSC[] =
1423{
1424 {{0x65,0x4f,0x89,0x56,0x83,0xaf,0x1f,
1425 0x90,0x85,0x8f,0xab,0x30,0x00,0x05,
1426 0x00 }},
1427 {{0x65,0x4f,0x89,0x56,0x83,0x83,0x1f,
1428 0x5e,0x83,0x5d,0x79,0x10,0x00,0x05,
1429 0x00 }},
1430 {{0x65,0x4f,0x89,0x56,0x83,0xaf,0x1f,
1431 0x90,0x85,0x8f,0xab,0x30,0x00,0x05,
1432 0x00 }},
1433 {{0x65,0x4f,0x89,0x56,0x83,0x83,0x1f,
1434 0x5e,0x83,0x5d,0x79,0x10,0x00,0x05,
1435 0x00 }},
1436 {{0x65,0x4f,0x89,0x56,0x83,0x04,0x3e,
1437 0xe0,0x85,0xdf,0xfb,0x10,0x00,0x05,
1438 0x00 }},
1439 {{0x7f,0x63,0x83,0x6c,0x1c,0x72,0xf0,
1440 0x58,0x8c,0x57,0x73,0x20,0x00,0x06,
1441 0x01 }}
1442};
1443
1444static const SiS_LVDSCRT1DataStruct SiS300_LVDSCRT1800x600_1_H[] =
1445{
1446 {{0x30,0x27,0x94,0x2c,0x92,0xaf,0x1f,
1447 0x90,0x85,0x8f,0xab,0x30,0x00,0x04,
1448 0x00 }},
1449 {{0x30,0x27,0x94,0x2c,0x92,0x83,0x1f,
1450 0x5e,0x83,0x5d,0x79,0x10,0x00,0x04,
1451 0x00 }},
1452 {{0x30,0x27,0x94,0x2c,0x92,0xaf,0x1f,
1453 0x90,0x85,0x8f,0xab,0x30,0x00,0x04,
1454 0x00 }},
1455 {{0x30,0x27,0x94,0x2c,0x92,0x83,0x1f,
1456 0x5e,0x83,0x5d,0x79,0x10,0x00,0x04,
1457 0x00 }},
1458 {{0x30,0x27,0x94,0x2c,0x92,0x04,0x3e,
1459 0xe0,0x85,0xdf,0xfb,0x10,0x00,0x04,
1460 0x00 }},
1461 {{0x3d,0x31,0x81,0x37,0x1f,0x72,0xf0,
1462 0x58,0x8c,0x57,0x73,0x20,0x00,0x05,
1463 0x01 }}
1464};
1465
1466static const SiS_LVDSCRT1DataStruct SiS300_LVDSCRT11024x768_1[] =
1467{
1468 {{0x64,0x4f,0x88,0x54,0x9f,0xc4,0x1f,
1469 0x92,0x89,0x8f,0xb5,0x30,0x00,0x01,
1470 0x00}},
1471 {{0x64,0x4f,0x88,0x54,0x9f,0x97,0x1f,
1472 0x60,0x87,0x5d,0x83,0x10,0x00,0x01,
1473 0x00}},
1474 {{0x64,0x4f,0x88,0x54,0x9f,0xc4,0x1f,
1475 0x92,0x89,0x8f,0xb5,0x30,0x00,0x01,
1476 0x00}},
1477 {{0x64,0x4f,0x88,0x54,0x9f,0x97,0x1f,
1478 0x60,0x87,0x5d,0x83,0x10,0x00,0x01,
1479 0x00}},
1480 {{0x64,0x4f,0x88,0x54,0x9f,0x04,0x3e,
1481 0xe2,0x89,0xdf,0x05,0x00,0x00,0x01,
1482 0x00}},
1483 {{0x7e,0x63,0x82,0x68,0x15,0x7c,0xf0,
1484 0x5a,0x8f,0x57,0x7d,0x20,0x00,0x26,
1485 0x01}},
1486 {{0xa3,0x7f,0x87,0x86,0x97,0x24,0xf5,
1487 0x02,0x88,0xff,0x25,0x10,0x00,0x02,
1488 0x01}}
1489};
1490
1491static const SiS_LVDSCRT1DataStruct SiS300_LVDSCRT11024x768_1_H[] =
1492{
1493 {{0x2f,0x27,0x93,0x2b,0x90,0xc4,0x1f,
1494 0x92,0x89,0x8f,0xb5,0x30,0x00,0x44,
1495 0x00 }},
1496 {{0x2f,0x27,0x93,0x2b,0x90,0x97,0x1f,
1497 0x60,0x87,0x5D,0x83,0x10,0x00,0x44,
1498 0x00}},
1499 {{0x2f,0x27,0x93,0x2b,0x90,0xc4,0x1f,
1500 0x92,0x89,0x8f,0xb5,0x30,0x00,0x44,
1501 0x00}},
1502 {{0x2f,0x27,0x93,0x2b,0x90,0x97,0x1f,
1503 0x60,0x87,0x5D,0x83,0x10,0x00,0x44,
1504 0x00}},
1505 {{0x2f,0x27,0x93,0x2b,0x90,0x04,0x3e,
1506 0xE2,0x89,0xdf,0x05,0x00,0x00,0x44,
1507 0x00}},
1508 {{0x3c,0x31,0x80,0x35,0x1c,0x7c,0xf0,
1509 0x5A,0x8F,0x57,0x7D,0x20,0x00,0x55,
1510 0x01}},
1511 {{0x4f,0x3F,0x93,0x45,0x0D,0x24,0xf5,
1512 0x02,0x88,0xff,0x25,0x10,0x00,0x01,
1513 0x01 }}
1514
1515#if 0
1516 {{0x37,0x27,0x9B,0x2b,0x94,0xc4,0x1f,
1517 0x92,0x89,0x8f,0xb5,0x30,0x00,0x44,
1518 0x00 }},
1519 {{0x37,0x27,0x9B,0x2b,0x94,0x97,0x1f,
1520 0x60,0x87,0x5D,0x83,0x01,0x00,0x44,
1521 0x00}},
1522 {{0x37,0x27,0x9B,0x2b,0x94,0xc4,0x1f,
1523 0x92,0x89,0x8f,0xb5,0x30,0x00,0x44,
1524 0x00}},
1525 {{0x37,0x27,0x9B,0x2b,0x94,0x97,0x1f,
1526 0x60,0x87,0x5D,0x83,0x01,0x00,0x44,
1527 0x00}},
1528 {{0x37,0x27,0x9B,0x2b,0x94,0x04,0x3e,
1529 0xE2,0x89,0xDf,0x05,0x00,0x00,0x44,
1530 0x00}},
1531 {{0x41,0x31,0x85,0x35,0x1d,0x7c,0xf0,
1532 0x5A,0x8F,0x57,0x7D,0x20,0x00,0x55,
1533 0x01}},
1534 {{0x4f,0x3F,0x93,0x45,0x0D,0x24,0xf5,
1535 0x02,0x88,0xFf,0x25,0x10,0x00,0x01,
1536 0x01 }}
1537#endif
1538};
1539
1540static const SiS_LVDSCRT1DataStruct SiS300_LVDSCRT11280x1024_1[] =
1541{
1542 {{0x63,0x4f,0x87,0x54,0x9f,0xb4,0x1f,
1543 0x92,0x89,0x8f,0xb5,0x30,0x00,0x01,
1544 0x00 }},
1545 {{0x63,0x4f,0x87,0x54,0x9f,0x82,0x1f,
1546 0x60,0x87,0x5d,0x83,0x10,0x00,0x01,
1547 0x00 }},
1548 {{0x63,0x4f,0x87,0x54,0x9f,0xb4,0x1f,
1549 0x92,0x89,0x8f,0xb5,0x30,0x00,0x01,
1550 0x00 }},
1551 {{0x63,0x4f,0x87,0x54,0x9f,0x82,0x1f,
1552 0x60,0x87,0x5d,0x83,0x10,0x00,0x01,
1553 0x00 }},
1554 {{0x63,0x4f,0x87,0x54,0x9f,0x04,0x3e,
1555 0xe2,0x89,0xdf,0x05,0x00,0x00,0x01,
1556 0x00 }},
1557 {{0x7e,0x63,0x82,0x68,0x15,0x7c,0xf0,
1558 0x5a,0x8f,0x57,0x7d,0x20,0x00,0x26,
1559 0x01 }},
1560 {{0xa3,0x7f,0x87,0x86,0x97,0x24,0xf5,
1561 0x02,0x88,0xff,0x25,0x10,0x00,0x02,
1562 0x01 }}
1563};
1564
1565static const SiS_LVDSCRT1DataStruct SiS300_LVDSCRT11280x1024_1_H[] =
1566{
1567 {{0x2f,0x27,0x93,0x2b,0x90,0xb4,0x1f,
1568 0x92,0x89,0x8f,0xb5,0x30,0x00,0x04,
1569 0x00 }},
1570 {{0x2f,0x27,0x93,0x2b,0x90,0x82,0x1f,
1571 0x60,0x87,0x5d,0x83,0x10,0x00,0x04,
1572 0x00 }},
1573 {{0x2f,0x27,0x93,0x2b,0x90,0xb4,0x1f,
1574 0x92,0x89,0x8f,0xb5,0x30,0x00,0x04,
1575 0x00 }},
1576 {{0x2f,0x27,0x93,0x2b,0x90,0x82,0x1f,
1577 0x60,0x87,0x5d,0x83,0x10,0x00,0x04,
1578 0x00 }},
1579 {{0x2f,0x27,0x93,0x2b,0x90,0x04,0x3e,
1580 0xe2,0x89,0xdf,0x05,0x00,0x00,0x04,
1581 0x00 }},
1582 {{0x3c,0x31,0x80,0x35,0x1c,0x7c,0xf0,
1583 0x5a,0x8f,0x57,0x7d,0x20,0x00,0x55,
1584 0x01 }},
1585 {{0x4f,0x3f,0x93,0x45,0x0d,0x24,0xf5,
1586 0x02,0x88,0xff,0x25,0x10,0x00,0x01,
1587 0x01 }}
1588};
1589
1590static const SiS_LVDSCRT1DataStruct SiS300_LVDSCRT1800x600_2[] =
1591{
1592 {{0x7f,0x4f,0x83,0x62,0x12,0x72,0x3e,
1593 0xf4,0x88,0x8f,0x73,0x20,0x00,0x06,
1594 0x00 }},
1595 {{0x7f,0x4f,0x83,0x62,0x12,0x72,0x3e,
1596 0xdb,0x8f,0x5d,0x73,0x20,0x00,0x06,
1597 0x00 }},
1598 {{0x7f,0x4f,0x83,0x62,0x12,0x72,0x3e,
1599 0xf4,0x88,0x8f,0x73,0x20,0x00,0x06,
1600 0x00 }},
1601 {{0x7f,0x4f,0x83,0x62,0x12,0x72,0x3e,
1602 0xdb,0x8f,0x5d,0x73,0x20,0x00,0x06,
1603 0x00 }},
1604 {{0x7f,0x4f,0x83,0x62,0x12,0x72,0xba,
1605 0x1c,0x80,0xdf,0x73,0x00,0x00,0x06,
1606 0x00 }},
1607 {{0x7f,0x63,0x83,0x6c,0x1c,0x72,0xf0,
1608 0x58,0x8c,0x57,0x73,0x20,0x00,0x06,
1609 0x01 }}
1610};
1611
1612static const SiS_LVDSCRT1DataStruct SiS300_LVDSCRT1800x600_2_H[] =
1613{
1614 {{0x3d,0x27,0x81,0x32,0x1a,0x72,0x3e,
1615 0xf4,0x88,0x8f,0x73,0x20,0x00,0x05,
1616 0x00 }},
1617 {{0x3d,0x27,0x81,0x32,0x1a,0x72,0x3e,
1618 0xdb,0x8f,0x5d,0x73,0x20,0x00,0x05,
1619 0x00 }},
1620 {{0x3d,0x27,0x81,0x32,0x1a,0x72,0x3e,
1621 0xf4,0x88,0x8f,0x73,0x20,0x00,0x05,
1622 0x00 }},
1623 {{0x3d,0x27,0x81,0x3a,0x1a,0x72,0x3e,
1624 0xdb,0x8f,0x5d,0x73,0x20,0x00,0x05,
1625 0x00 }},
1626 {{0x3d,0x27,0x81,0x32,0x1a,0x72,0xba,
1627 0x1c,0x80,0xdf,0x73,0x00,0x00,0x05,
1628 0x00 }},
1629 {{0x3d,0x31,0x81,0x37,0x1f,0x72,0xf0,
1630 0x58,0x8c,0x57,0x73,0x20,0x00,0x05,
1631 0x01 }}
1632};
1633
1634static const SiS_LVDSCRT1DataStruct SiS300_LVDSCRT11024x768_2[] =
1635{
1636 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1637 0x4a,0x80,0x8f,0x25,0x30,0x00,0x06,
1638 0x00 }},
1639 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1640 0x31,0x87,0x5d,0x25,0x30,0x00,0x06,
1641 0x00 }},
1642 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1643 0x4a,0x80,0x8f,0x25,0x30,0x00,0x06,
1644 0x00 }},
1645 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1646 0x31,0x87,0x5d,0x25,0x30,0x00,0x06,
1647 0x00 }},
1648 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1649 0x72,0x88,0xdf,0x25,0x30,0x00,0x06,
1650 0x00 }},
1651 {{0xa3,0x63,0x87,0x78,0x89,0x24,0xf1,
1652 0xae,0x84,0x57,0x25,0x30,0x00,0x02,
1653 0x01 }},
1654 {{0xa3,0x7f,0x87,0x86,0x97,0x24,0xf5,
1655 0x02,0x88,0xff,0x25,0x10,0x00,0x02,
1656 0x01 }}
1657};
1658
1659static const SiS_LVDSCRT1DataStruct SiS300_LVDSCRT11024x768_2_H[] =
1660{
1661 {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
1662 0x4a,0x80,0x8f,0x25,0x30,0x00,0x01,
1663 0x00 }},
1664 {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
1665 0x31,0x87,0x5d,0x25,0x30,0x00,0x01,
1666 0x00 }},
1667 {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
1668 0x4a,0x80,0x8f,0x25,0x30,0x00,0x01,
1669 0x00 }},
1670 {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
1671 0x31,0x87,0x5d,0x25,0x30,0x00,0x01,
1672 0x00 }},
1673 {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
1674 0x72,0x88,0xdf,0x25,0x30,0x00,0x01,
1675 0x00 }},
1676 {{0x4f,0x31,0x93,0x3e,0x06,0x24,0xf1,
1677 0xae,0x84,0x57,0x25,0x30,0x00,0x01,
1678 0x01 }},
1679 {{0x4f,0x3f,0x93,0x45,0x0d,0x24,0xf5,
1680 0x02,0x88,0xff,0x25,0x10,0x00,0x01,
1681 0x01 }}
1682};
1683
1684static const SiS_LVDSCRT1DataStruct SiS300_LVDSCRT11280x1024_2[] =
1685{
1686 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1687 0x4a,0x80,0x8f,0x25,0x30,0x00,0x06,
1688 0x00 }},
1689 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1690 0x31,0x87,0x5d,0x25,0x30,0x00,0x06,
1691 0x00 }},
1692 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1693 0x4a,0x80,0x8f,0x25,0x30,0x00,0x06,
1694 0x00 }},
1695 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1696 0x31,0x87,0x5d,0x25,0x30,0x00,0x06,
1697 0x00 }},
1698 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1699 0x72,0x88,0xdf,0x25,0x30,0x00,0x06,
1700 0x00 }},
1701 {{0xa3,0x63,0x87,0x78,0x89,0x24,0xf1,
1702 0xae,0x84,0x57,0x25,0x30,0x00,0x02,
1703 0x01 }},
1704 {{0xa3,0x7f,0x87,0x86,0x97,0x24,0xf5,
1705 0x02,0x88,0xff,0x25,0x10,0x00,0x02,
1706 0x01 }}
1707};
1708
1709static const SiS_LVDSCRT1DataStruct SiS300_LVDSCRT11280x1024_2_H[] =
1710{
1711 {{0x4f,0x27,0x93,0x39,0x81,0x24,0xbb,
1712 0x4a,0x80,0x8f,0x25,0x30,0x00,0x01,
1713 0x00 }},
1714 {{0x4f,0x27,0x93,0x39,0x81,0x24,0xbb,
1715 0x31,0x87,0x5d,0x25,0x30,0x00,0x01,
1716 0x00 }},
1717 {{0x4f,0x27,0x93,0x39,0x81,0x24,0xbb,
1718 0x4a,0x80,0x8f,0x25,0x30,0x00,0x01,
1719 0x00 }},
1720 {{0x4f,0x27,0x93,0x39,0x81,0x24,0xbb,
1721 0x31,0x87,0x5d,0x25,0x30,0x00,0x01,
1722 0x00 }},
1723 {{0x4f,0x27,0x93,0x39,0x81,0x24,0xbb,
1724 0x72,0x88,0xdf,0x25,0x30,0x00,0x01,
1725 0x00 }},
1726 {{0x4f,0x31,0x93,0x3e,0x86,0x24,0xf1,
1727 0xae,0x84,0x57,0x25,0x30,0x00,0x01,
1728 0x01 }},
1729 {{0x4f,0x3f,0x93,0x45,0x0d,0x24,0xf5,
1730 0x02,0x88,0xff,0x25,0x10,0x00,0x01,
1731 0x01}}
1732};
1733
1734static const SiS_LVDSCRT1DataStruct SiS300_LVDSCRT1XXXxXXX_1[] =
1735{
1736 {{0x5f,0x4f,0x82,0x55,0x81,0xbf,0x1f,
1737 0x9c,0x8e,0x96,0xb9,0x30,0x00,0x05,
1738 0x00}},
1739 {{0x5f,0x4f,0x82,0x55,0x81,0xbf,0x1f,
1740 0x9c,0x8e,0x96,0xb9,0x30,0x00,0x05,
1741 0x00}},
1742 {{0x5f,0x4f,0x82,0x55,0x81,0xbf,0x1f,
1743 0x9c,0x8e,0x96,0xb9,0x30,0x00,0x05,
1744 0x00}},
1745 {{0x5f,0x4f,0x82,0x55,0x81,0xbf,0x1f,
1746 0x9c,0x8e,0x96,0xb9,0x30,0x00,0x05,
1747 0x00}},
1748 {{0x5f,0x4f,0x82,0x55,0x81,0x0b,0x3e,
1749 0xe9,0x8b,0xe7,0x04,0x00,0x00,0x05,
1750 0x00}},
1751 {{0x7f,0x63,0x83,0x6c,0x1c,0x72,0xf0,
1752 0x58,0x8c,0x57,0x73,0x20,0x00,0x06,
1753 0x01}},
1754 {{0xa3,0x7f,0x87,0x86,0x97,0x24,0xf5,
1755 0x02,0x88,0xff,0x25,0x10,0x00,0x02,
1756 0x01}},
1757 {{0xce,0x9f,0x92,0xa8,0x14,0x28,0x5a,
1758 0x00,0x84,0xff,0x29,0x09,0x00,0x07,
1759 0x01}},
1760 {{0xce,0x9f,0x92,0xa9,0x17,0x24,0xf5,
1761 0x02,0x88,0xff,0x25,0x10,0x00,0x07,
1762 0x01}}
1763};
1764
1765static const SiS_LVDSCRT1DataStruct SiS300_LVDSCRT1XXXxXXX_1_H[] =
1766{
1767 {{0x38,0x27,0x9c,0x2c,0x80,0xbf,0x1f,
1768 0x9c,0x8e,0x96,0xb9,0x30,0x00,0x00,
1769 0x00}},
1770 {{0x38,0x27,0x9c,0x2c,0x80,0xbf,0x1f,
1771 0x9c,0x8e,0x96,0xb9,0x30,0x00,0x00,
1772 0x00}},
1773 {{0x38,0x27,0x9c,0x2c,0x80,0xbf,0x1f,
1774 0x9c,0x8e,0x96,0xb9,0x30,0x00,0x00,
1775 0x00}},
1776 {{0x38,0x27,0x9c,0x2c,0x80,0xbf,0x1f,
1777 0x9c,0x8e,0x96,0xb9,0x30,0x00,0x00,
1778 0x00}},
1779 {{0x38,0x27,0x9c,0x2c,0x80,0x0b,0x3e,
1780 0xe9,0x8b,0xe7,0x04,0x00,0x00,0x00,
1781 0x00}},
1782 {{0x4d,0x31,0x91,0x3b,0x03,0x72,0xf0,
1783 0x58,0x8c,0x57,0x73,0x20,0x00,0x01,
1784 0x01}},
1785 {{0x63,0x3f,0x87,0x4a,0x92,0x24,0xf5,
1786 0x02,0x88,0xff,0x25,0x10,0x00,0x01,
1787 0x01}}
1788};
1789
1790
1791static const SiS_LVDSCRT1DataStruct SiS300_CHTVCRT1UNTSC[] =
1792{ 899{
1793 {{0x64,0x4f,0x88,0x56,0x9f,0x56,0x3e, 900 {{0x64,0x4f,0x88,0x56,0x9f,0x56,0x3e,
1794 0xe8,0x84,0x8f,0x57,0x20,0x00,0x01, 901 0xe8,0x84,0x8f,0x57,0x20,0x00,0x01,
@@ -1810,7 +917,7 @@ static const SiS_LVDSCRT1DataStruct SiS300_CHTVCRT1UNTSC[] =
1810 0x01 }} 917 0x01 }}
1811}; 918};
1812 919
1813static const SiS_LVDSCRT1DataStruct SiS300_CHTVCRT1ONTSC[] = 920static const struct SiS_LVDSCRT1Data SiS300_CHTVCRT1ONTSC[] =
1814{ 921{
1815 {{0x64,0x4f,0x88,0x5a,0x9f,0x0b,0x3e, 922 {{0x64,0x4f,0x88,0x5a,0x9f,0x0b,0x3e,
1816 0xc0,0x84,0x8f,0x0c,0x20,0x00,0x01, 923 0xc0,0x84,0x8f,0x0c,0x20,0x00,0x01,
@@ -1832,7 +939,7 @@ static const SiS_LVDSCRT1DataStruct SiS300_CHTVCRT1ONTSC[] =
1832 0x01 }} 939 0x01 }}
1833}; 940};
1834 941
1835static const SiS_LVDSCRT1DataStruct SiS300_CHTVCRT1UPAL[] = 942static const struct SiS_LVDSCRT1Data SiS300_CHTVCRT1UPAL[] =
1836{ 943{
1837 {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e, 944 {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
1838 0xf8,0x83,0x8f,0x70,0x20,0x00,0x05, 945 0xf8,0x83,0x8f,0x70,0x20,0x00,0x05,
@@ -1854,7 +961,7 @@ static const SiS_LVDSCRT1DataStruct SiS300_CHTVCRT1UPAL[] =
1854 0x01 }} 961 0x01 }}
1855}; 962};
1856 963
1857static const SiS_LVDSCRT1DataStruct SiS300_CHTVCRT1OPAL[] = 964static const struct SiS_LVDSCRT1Data SiS300_CHTVCRT1OPAL[] =
1858{ 965{
1859 {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e, 966 {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
1860 0xf0,0x83,0x8f,0x70,0x20,0x00,0x05, 967 0xf0,0x83,0x8f,0x70,0x20,0x00,0x05,
@@ -1876,7 +983,7 @@ static const SiS_LVDSCRT1DataStruct SiS300_CHTVCRT1OPAL[] =
1876 0x01 }} 983 0x01 }}
1877}; 984};
1878 985
1879static const SiS_LVDSCRT1DataStruct SiS300_CHTVCRT1SOPAL[] = 986static const struct SiS_LVDSCRT1Data SiS300_CHTVCRT1SOPAL[] =
1880{ 987{
1881 {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e, 988 {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
1882 0xf0,0x83,0x8f,0x70,0x20,0x00,0x05, 989 0xf0,0x83,0x8f,0x70,0x20,0x00,0x05,
@@ -1898,7 +1005,7 @@ static const SiS_LVDSCRT1DataStruct SiS300_CHTVCRT1SOPAL[] =
1898 0x01 }} 1005 0x01 }}
1899}; 1006};
1900 1007
1901static const SiS_CHTVRegDataStruct SiS300_CHTVReg_UNTSC[] = 1008static const struct SiS_CHTVRegData SiS300_CHTVReg_UNTSC[] =
1902{ 1009{
1903 {{0x4a,0x94,0x00,0x48,0xfe,0,0,0,0,0,0,0,0,0,0,0}}, 1010 {{0x4a,0x94,0x00,0x48,0xfe,0,0,0,0,0,0,0,0,0,0,0}},
1904 {{0x4a,0x94,0x00,0x48,0xfe,0,0,0,0,0,0,0,0,0,0,0}}, 1011 {{0x4a,0x94,0x00,0x48,0xfe,0,0,0,0,0,0,0,0,0,0,0}},
@@ -1908,7 +1015,7 @@ static const SiS_CHTVRegDataStruct SiS300_CHTVReg_UNTSC[] =
1908 {{0x8d,0xc4,0x00,0x3b,0xfb,0,0,0,0,0,0,0,0,0,0,0}} /* Mode 24: 800x600 NTSC 7/10 */ 1015 {{0x8d,0xc4,0x00,0x3b,0xfb,0,0,0,0,0,0,0,0,0,0,0}} /* Mode 24: 800x600 NTSC 7/10 */
1909}; 1016};
1910 1017
1911static const SiS_CHTVRegDataStruct SiS300_CHTVReg_ONTSC[] = 1018static const struct SiS_CHTVRegData SiS300_CHTVReg_ONTSC[] =
1912{ 1019{
1913 {{0x49,0x94,0x00,0x34,0xfe,0,0,0,0,0,0,0,0,0,0,0}}, 1020 {{0x49,0x94,0x00,0x34,0xfe,0,0,0,0,0,0,0,0,0,0,0}},
1914 {{0x49,0x94,0x00,0x34,0xfe,0,0,0,0,0,0,0,0,0,0,0}}, 1021 {{0x49,0x94,0x00,0x34,0xfe,0,0,0,0,0,0,0,0,0,0,0}},
@@ -1918,7 +1025,7 @@ static const SiS_CHTVRegDataStruct SiS300_CHTVReg_ONTSC[] =
1918 {{0x8c,0xb4,0x00,0x32,0xf9,0,0,0,0,0,0,0,0,0,0,0}} /* Mode 23: 800x600 NTSC 3/4 */ 1025 {{0x8c,0xb4,0x00,0x32,0xf9,0,0,0,0,0,0,0,0,0,0,0}} /* Mode 23: 800x600 NTSC 3/4 */
1919}; 1026};
1920 1027
1921static const SiS_CHTVRegDataStruct SiS300_CHTVReg_UPAL[] = 1028static const struct SiS_CHTVRegData SiS300_CHTVReg_UPAL[] =
1922{ 1029{
1923 {{0x41,0x12,0x01,0x50,0x34,0,0,0,0,0,0,0,0,0,0,0}}, 1030 {{0x41,0x12,0x01,0x50,0x34,0,0,0,0,0,0,0,0,0,0,0}},
1924 {{0x41,0x12,0x00,0x50,0x00,0,0,0,0,0,0,0,0,0,0,0}}, 1031 {{0x41,0x12,0x00,0x50,0x00,0,0,0,0,0,0,0,0,0,0,0}},
@@ -1929,7 +1036,7 @@ static const SiS_CHTVRegDataStruct SiS300_CHTVReg_UPAL[] =
1929 1036
1930}; 1037};
1931 1038
1932static const SiS_CHTVRegDataStruct SiS300_CHTVReg_OPAL[] = 1039static const struct SiS_CHTVRegData SiS300_CHTVReg_OPAL[] =
1933{ 1040{
1934 {{0x41,0x12,0x01,0x50,0x34,0,0,0,0,0,0,0,0,0,0,0}}, /* Mode 9: 640x400 PAL 1/1 */ 1041 {{0x41,0x12,0x01,0x50,0x34,0,0,0,0,0,0,0,0,0,0,0}}, /* Mode 9: 640x400 PAL 1/1 */
1935 {{0x41,0x12,0x00,0x50,0x00,0,0,0,0,0,0,0,0,0,0,0}}, 1042 {{0x41,0x12,0x00,0x50,0x00,0,0,0,0,0,0,0,0,0,0,0}},
@@ -1940,26 +1047,26 @@ static const SiS_CHTVRegDataStruct SiS300_CHTVReg_OPAL[] =
1940 1047
1941}; 1048};
1942 1049
1943static const SiS_CHTVRegDataStruct SiS300_CHTVReg_SOPAL[] = 1050static const struct SiS_CHTVRegData SiS300_CHTVReg_SOPAL[] =
1944{ 1051{
1945 {{0x41,0x12,0x01,0x50,0x34,0,0,0,0,0,0,0,0,0,0,0}}, /* Mode 9: 640x400 PAL 1/1 */ 1052 {{0x41,0x12,0x01,0x50,0x34,0,0,0,0,0,0,0,0,0,0,0}}, /* Mode 9: 640x400 PAL 1/1 */
1946 {{0x41,0x12,0x00,0x50,0x00,0,0,0,0,0,0,0,0,0,0,0}}, 1053 {{0x41,0x12,0x00,0x50,0x00,0,0,0,0,0,0,0,0,0,0,0}},
1947 {{0x41,0x12,0x01,0x50,0x34,0,0,0,0,0,0,0,0,0,0,0}}, 1054 {{0x41,0x12,0x01,0x50,0x34,0,0,0,0,0,0,0,0,0,0,0}},
1948 {{0x41,0x12,0x00,0x50,0x00,0,0,0,0,0,0,0,0,0,0,0}}, 1055 {{0x41,0x12,0x00,0x50,0x00,0,0,0,0,0,0,0,0,0,0,0}},
1949 {{0x60,0x30,0x00,0x10,0x00,0,0,0,0,0,0,0,0,0,0,0}}, /* TW: Mode 13: 640x480 PAL 5/4 */ 1056 {{0x60,0x30,0x00,0x10,0x00,0,0,0,0,0,0,0,0,0,0,0}}, /* Mode 13: 640x480 PAL 5/4 */
1950 {{0x81,0x50,0x00,0x1b,0x00,0,0,0,0,0,0,0,0,0,0,0}} /* TW: Mode 19: 800x600 PAL 1/1 */ 1057 {{0x81,0x50,0x00,0x1b,0x00,0,0,0,0,0,0,0,0,0,0,0}} /* Mode 19: 800x600 PAL 1/1 */
1951}; 1058};
1952 1059
1953static const UCHAR SiS300_CHTVVCLKUNTSC[] = {0x29,0x29,0x29,0x29,0x2a,0x2e}; 1060static const unsigned char SiS300_CHTVVCLKUNTSC[] = { 0x29,0x29,0x29,0x29,0x2a,0x2e };
1954 1061
1955static const UCHAR SiS300_CHTVVCLKONTSC[] = {0x2c,0x2c,0x2c,0x2c,0x2d,0x2b}; 1062static const unsigned char SiS300_CHTVVCLKONTSC[] = { 0x2c,0x2c,0x2c,0x2c,0x2d,0x2b };
1956 1063
1957static const UCHAR SiS300_CHTVVCLKSONTSC[] = {0x2c,0x2c,0x2c,0x2c,0x2d,0x2b}; 1064static const unsigned char SiS300_CHTVVCLKSONTSC[] = { 0x2c,0x2c,0x2c,0x2c,0x2d,0x2b };
1958 1065
1959static const UCHAR SiS300_CHTVVCLKUPAL[] = {0x2f,0x2f,0x2f,0x2f,0x2f,0x31}; 1066static const unsigned char SiS300_CHTVVCLKUPAL[] = { 0x2f,0x2f,0x2f,0x2f,0x2f,0x31 };
1960 1067
1961static const UCHAR SiS300_CHTVVCLKOPAL[] = {0x2f,0x2f,0x2f,0x2f,0x30,0x32}; 1068static const unsigned char SiS300_CHTVVCLKOPAL[] = { 0x2f,0x2f,0x2f,0x2f,0x30,0x32 };
1962 1069
1963static const UCHAR SiS300_CHTVVCLKSOPAL[] = {0x2f,0x2f,0x2f,0x2f,0x36,0x29}; 1070static const unsigned char SiS300_CHTVVCLKSOPAL[] = { 0x2f,0x2f,0x2f,0x2f,0x36,0x29 };
1964 1071
1965 1072
diff --git a/drivers/video/sis/310vtbl.h b/drivers/video/sis/310vtbl.h
index 2c71d048f7..54fcbbf4ef 100644
--- a/drivers/video/sis/310vtbl.h
+++ b/drivers/video/sis/310vtbl.h
@@ -1,9 +1,9 @@
1/* $XFree86$ */ 1/* $XFree86$ */
2/* $XdotOrg$ */ 2/* $XdotOrg$ */
3/* 3/*
4 * Register settings for SiS 315/330 series 4 * Register settings for SiS 315/330/340 series
5 * 5 *
6 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria 6 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
7 * 7 *
8 * If distributed as part of the Linux kernel, the following license terms 8 * If distributed as part of the Linux kernel, the following license terms
9 * apply: 9 * apply:
@@ -50,37 +50,13 @@
50 * 50 *
51 */ 51 */
52 52
53static const SiS_StStruct SiS310_SModeIDTable[]= 53static const struct SiS_Ext SiS310_EModeIDTable[] =
54{
55 {0x01,0x9208,0x01,0x00,0x00,0x00,0x01,0x00, 0x40},
56 {0x01,0x1210,0x14,0x01,0x01,0x00,0x01,0x00, 0x40},
57 {0x01,0x1010,0x17,0x02,0x02,0x00,0x01,0x01, 0x40},
58 {0x03,0x8208,0x03,0x00,0x00,0x00,0x01,0x02, 0x40},
59 {0x03,0x0210,0x16,0x01,0x01,0x00,0x01,0x02, 0x40},
60 {0x03,0x0010,0x18,0x02,0x02,0x00,0x01,0x03, 0x40},
61 {0x05,0x9209,0x05,0x00,0x00,0x00,0x00,0x04, 0x40},
62 {0x06,0x8209,0x06,0x00,0x00,0x00,0x00,0x05, 0x40},
63 {0x07,0x0000,0x07,0x03,0x03,0x00,0x01,0x03, 0x40},
64 {0x07,0x0000,0x19,0x02,0x02,0x00,0x01,0x03, 0x40},
65 {0x0d,0x920a,0x0d,0x00,0x00,0x00,0x00,0x04, 0x40},
66 {0x0e,0x820a,0x0e,0x00,0x00,0x00,0x00,0x05, 0x40},
67 {0x0f,0x0202,0x11,0x01,0x01,0x00,0x00,0x05, 0x40},
68 {0x10,0x0212,0x12,0x01,0x01,0x00,0x00,0x05, 0x40},
69 {0x11,0x0212,0x1a,0x04,0x04,0x00,0x00,0x05, 0x40},
70 {0x12,0x0212,0x1b,0x04,0x04,0x00,0x00,0x05, 0x40},
71 {0x13,0x021b,0x1c,0x00,0x00,0x00,0x00,0x04, 0x40},
72 {0x12,0x0010,0x18,0x02,0x02,0x00,0x00,0x05, 0x40},
73 {0x12,0x0210,0x18,0x01,0x01,0x00,0x00,0x05, 0x40},
74 {0xff,0x0000,0x00,0x00,0x00,0x00,0x00,0x00, 0x40}
75};
76
77static const SiS_ExtStruct SiS310_EModeIDTable[]=
78{ 54{
79 {0x6a,0x2212,0x0102,SIS_RI_800x600, 0x00,0x00,0x07,0x06,0x00, 3}, /* 800x600x? */ 55 {0x6a,0x2212,0x0102,SIS_RI_800x600, 0x00,0x00,0x07,0x06,0x00, 3}, /* 800x600x? */
80 {0x2e,0x0a1b,0x0101,SIS_RI_640x480, 0x00,0x00,0x05,0x05,0x08, 2}, /* 640x480x8 */ 56 {0x2e,0x0a1b,0x0101,SIS_RI_640x480, 0x00,0x00,0x05,0x05,0x08, 2}, /* 640x480x8 */
81 {0x2f,0x0a1b,0x0100,SIS_RI_640x400, 0x00,0x00,0x05,0x05,0x10, 0}, /* 640x400x8 */ 57 {0x2f,0x0a1b,0x0100,SIS_RI_640x400, 0x00,0x00,0x05,0x05,0x10, 0}, /* 640x400x8 */
82 {0x30,0x2a1b,0x0103,SIS_RI_800x600, 0x00,0x00,0x07,0x06,0x00, 3}, /* 800x600x8 */ 58 {0x30,0x2a1b,0x0103,SIS_RI_800x600, 0x00,0x00,0x07,0x06,0x00, 3}, /* 800x600x8 */
83 {0x31,0x4a1b,0x0000,SIS_RI_720x480, 0x00,0x00,0x06,0x06,0x11,-1}, /* 720x480x8 */ 59 {0x31,0x4a1b,0x0000,SIS_RI_720x480, 0x00,0x00,0x06,0x06,0x11,-1}, /* 720x480x8 */
84 {0x32,0x4a1b,0x0000,SIS_RI_720x576, 0x00,0x00,0x06,0x06,0x12,-1}, /* 720x576x8 */ 60 {0x32,0x4a1b,0x0000,SIS_RI_720x576, 0x00,0x00,0x06,0x06,0x12,-1}, /* 720x576x8 */
85 {0x33,0x4a1d,0x0000,SIS_RI_720x480, 0x00,0x00,0x06,0x06,0x11,-1}, /* 720x480x16 */ 61 {0x33,0x4a1d,0x0000,SIS_RI_720x480, 0x00,0x00,0x06,0x06,0x11,-1}, /* 720x480x16 */
86 {0x34,0x6a1d,0x0000,SIS_RI_720x576, 0x00,0x00,0x06,0x06,0x12,-1}, /* 720x576x16 */ 62 {0x34,0x6a1d,0x0000,SIS_RI_720x576, 0x00,0x00,0x06,0x06,0x12,-1}, /* 720x576x16 */
@@ -103,10 +79,10 @@ static const SiS_ExtStruct SiS310_EModeIDTable[]=
103 {0x4d,0x0e7d,0x011a,SIS_RI_1280x1024,0x00,0x00,0x00,0x00,0x1a, 8}, /* 1280x1024x16 */ 79 {0x4d,0x0e7d,0x011a,SIS_RI_1280x1024,0x00,0x00,0x00,0x00,0x1a, 8}, /* 1280x1024x16 */
104 {0x50,0x9a1b,0x0132,SIS_RI_320x240, 0x00,0x00,0x04,0x04,0x26, 2}, /* 320x240x8 */ 80 {0x50,0x9a1b,0x0132,SIS_RI_320x240, 0x00,0x00,0x04,0x04,0x26, 2}, /* 320x240x8 */
105 {0x51,0xba1b,0x0133,SIS_RI_400x300, 0x00,0x00,0x07,0x07,0x27, 3}, /* 400x300x8 */ 81 {0x51,0xba1b,0x0133,SIS_RI_400x300, 0x00,0x00,0x07,0x07,0x27, 3}, /* 400x300x8 */
106 {0x52,0xba1b,0x0134,SIS_RI_512x384, 0x00,0x00,0x00,0x00,0x28, 4}, /* 512x384x8 */ 82 {0x52,0xba1b,0x0134,SIS_RI_512x384, 0x00,0x00,0x00,0x00,0x28, 4}, /* 512x384x8 */
107 {0x56,0x9a1d,0x0135,SIS_RI_320x240, 0x00,0x00,0x04,0x04,0x26, 2}, /* 320x240x16 */ 83 {0x56,0x9a1d,0x0135,SIS_RI_320x240, 0x00,0x00,0x04,0x04,0x26, 2}, /* 320x240x16 */
108 {0x57,0xba1d,0x0136,SIS_RI_400x300, 0x00,0x00,0x07,0x07,0x27, 3}, /* 400x300x16 */ 84 {0x57,0xba1d,0x0136,SIS_RI_400x300, 0x00,0x00,0x07,0x07,0x27, 3}, /* 400x300x16 */
109 {0x58,0xba1d,0x0137,SIS_RI_512x384, 0x00,0x00,0x00,0x00,0x28, 4}, /* 512x384x16 */ 85 {0x58,0xba1d,0x0137,SIS_RI_512x384, 0x00,0x00,0x00,0x00,0x28, 4}, /* 512x384x16 */
110 {0x59,0x9a1b,0x0138,SIS_RI_320x200, 0x00,0x00,0x04,0x04,0x25, 0}, /* 320x200x8 */ 86 {0x59,0x9a1b,0x0138,SIS_RI_320x200, 0x00,0x00,0x04,0x04,0x25, 0}, /* 320x200x8 */
111 {0x5a,0x021b,0x0138,SIS_RI_320x240, 0x00,0x00,0x00,0x00,0x3f, 2}, /* 320x240x8 fstn */ 87 {0x5a,0x021b,0x0138,SIS_RI_320x240, 0x00,0x00,0x00,0x00,0x3f, 2}, /* 320x240x8 fstn */
112 {0x5b,0x0a1d,0x0135,SIS_RI_320x240, 0x00,0x00,0x00,0x00,0x3f, 2}, /* 320x240x16 fstn */ 88 {0x5b,0x0a1d,0x0135,SIS_RI_320x240, 0x00,0x00,0x00,0x00,0x3f, 2}, /* 320x240x16 fstn */
@@ -139,406 +115,335 @@ static const SiS_ExtStruct SiS310_EModeIDTable[]=
139 {0x23,0x0e3b,0x0000,SIS_RI_1280x768, 0x00,0x00,0x00,0x00,0x40, 6}, /* 1280x768x8 */ 115 {0x23,0x0e3b,0x0000,SIS_RI_1280x768, 0x00,0x00,0x00,0x00,0x40, 6}, /* 1280x768x8 */
140 {0x24,0x0e7d,0x0000,SIS_RI_1280x768, 0x00,0x00,0x00,0x00,0x40, 6}, /* 1280x768x16 */ 116 {0x24,0x0e7d,0x0000,SIS_RI_1280x768, 0x00,0x00,0x00,0x00,0x40, 6}, /* 1280x768x16 */
141 {0x25,0x0eff,0x0000,SIS_RI_1280x768, 0x00,0x00,0x00,0x00,0x40, 6}, /* 1280x768x32 */ 117 {0x25,0x0eff,0x0000,SIS_RI_1280x768, 0x00,0x00,0x00,0x00,0x40, 6}, /* 1280x768x32 */
142 {0x26,0x0e3b,0x0000,SIS_RI_1400x1050,0x00,0x00,0x00,0x00,0x41, 9}, /* 1400x1050x8 */ 118 {0x26,0x0e3b,0x0000,SIS_RI_1400x1050,0x00,0x00,0x00,0x00,0x43, 9}, /* 1400x1050x8 */
143 {0x27,0x0e7d,0x0000,SIS_RI_1400x1050,0x00,0x00,0x00,0x00,0x41, 9}, /* 1400x1050x16 */ 119 {0x27,0x0e7d,0x0000,SIS_RI_1400x1050,0x00,0x00,0x00,0x00,0x43, 9}, /* 1400x1050x16 */
144 {0x28,0x0eff,0x0000,SIS_RI_1400x1050,0x00,0x00,0x00,0x00,0x41, 9}, /* 1400x1050x32*/ 120 {0x28,0x0eff,0x0000,SIS_RI_1400x1050,0x00,0x00,0x00,0x00,0x43, 9}, /* 1400x1050x32*/
145 {0x29,0x4e1b,0x0000,SIS_RI_1152x864, 0x00,0x00,0x00,0x00,0x43,-1}, /* 1152x864 */ 121 {0x29,0x4e1b,0x0000,SIS_RI_1152x864, 0x00,0x00,0x00,0x00,0x45,-1}, /* 1152x864 */
146 {0x2a,0x4e3d,0x0000,SIS_RI_1152x864, 0x00,0x00,0x00,0x00,0x43,-1}, 122 {0x2a,0x4e3d,0x0000,SIS_RI_1152x864, 0x00,0x00,0x00,0x00,0x45,-1},
147 {0x2b,0x4e7f,0x0000,SIS_RI_1152x864, 0x00,0x00,0x00,0x00,0x43,-1}, 123 {0x2b,0x4e7f,0x0000,SIS_RI_1152x864, 0x00,0x00,0x00,0x00,0x45,-1},
148 {0x39,0x6a1b,0x0000,SIS_RI_848x480, 0x00,0x00,0x00,0x00,0x46,-1}, /* 848x480 */ 124 {0x39,0x6a1b,0x0000,SIS_RI_848x480, 0x00,0x00,0x00,0x00,0x48,-1}, /* 848x480 */
149 {0x3b,0x6a3d,0x0000,SIS_RI_848x480, 0x00,0x00,0x00,0x00,0x46,-1}, 125 {0x3b,0x6a3d,0x0000,SIS_RI_848x480, 0x00,0x00,0x00,0x00,0x48,-1},
150 {0x3e,0x6a7f,0x0000,SIS_RI_848x480, 0x00,0x00,0x00,0x00,0x46,-1}, 126 {0x3e,0x6a7f,0x0000,SIS_RI_848x480, 0x00,0x00,0x00,0x00,0x48,-1},
151 {0x3f,0x6a1b,0x0000,SIS_RI_856x480, 0x00,0x00,0x00,0x00,0x48,-1}, /* 856x480 */ 127 {0x3f,0x6a1b,0x0000,SIS_RI_856x480, 0x00,0x00,0x00,0x00,0x4a,-1}, /* 856x480 */
152 {0x42,0x6a3d,0x0000,SIS_RI_856x480, 0x00,0x00,0x00,0x00,0x48,-1}, 128 {0x42,0x6a3d,0x0000,SIS_RI_856x480, 0x00,0x00,0x00,0x00,0x4a,-1},
153 {0x45,0x6a7f,0x0000,SIS_RI_856x480, 0x00,0x00,0x00,0x00,0x48,-1}, 129 {0x45,0x6a7f,0x0000,SIS_RI_856x480, 0x00,0x00,0x00,0x00,0x4a,-1},
154 {0x48,0x6a3b,0x0000,SIS_RI_1360x768, 0x00,0x00,0x00,0x00,0x4a,-1}, /* 1360x768 */ 130 {0x48,0x6a3b,0x0000,SIS_RI_1360x768, 0x00,0x00,0x00,0x00,0x4c,-1}, /* 1360x768 */
155 {0x4b,0x6a7d,0x0000,SIS_RI_1360x768, 0x00,0x00,0x00,0x00,0x4a,-1}, 131 {0x4b,0x6a7d,0x0000,SIS_RI_1360x768, 0x00,0x00,0x00,0x00,0x4c,-1},
156 {0x4e,0x6aff,0x0000,SIS_RI_1360x768, 0x00,0x00,0x00,0x00,0x4a,-1}, 132 {0x4e,0x6aff,0x0000,SIS_RI_1360x768, 0x00,0x00,0x00,0x00,0x4c,-1},
157 {0x4f,0x9a1f,0x0000,SIS_RI_320x200, 0x00,0x00,0x04,0x04,0x25, 0}, /* 320x200x32 */ 133 {0x4f,0x9a1f,0x0000,SIS_RI_320x200, 0x00,0x00,0x04,0x04,0x25, 0}, /* 320x200x32 */
158 {0x53,0x9a1f,0x0000,SIS_RI_320x240, 0x00,0x00,0x04,0x04,0x26, 2}, /* 320x240x32 */ 134 {0x53,0x9a1f,0x0000,SIS_RI_320x240, 0x00,0x00,0x04,0x04,0x26, 2}, /* 320x240x32 */
159 {0x54,0xba1f,0x0000,SIS_RI_400x300, 0x00,0x00,0x07,0x07,0x27, 3}, /* 400x300x32 */ 135 {0x54,0xba1f,0x0000,SIS_RI_400x300, 0x00,0x00,0x07,0x07,0x27, 3}, /* 400x300x32 */
160 {0x5f,0x6a1b,0x0000,SIS_RI_768x576, 0x00,0x00,0x06,0x06,0x4b,-1}, /* 768x576 */ 136 {0x5f,0x6a1b,0x0000,SIS_RI_768x576, 0x00,0x00,0x06,0x06,0x4d,-1}, /* 768x576 */
161 {0x60,0x6a1d,0x0000,SIS_RI_768x576, 0x00,0x00,0x06,0x06,0x4b,-1}, 137 {0x60,0x6a1d,0x0000,SIS_RI_768x576, 0x00,0x00,0x06,0x06,0x4d,-1},
162 {0x61,0x6a3f,0x0000,SIS_RI_768x576, 0x00,0x00,0x06,0x06,0x4b,-1}, 138 {0x61,0x6a3f,0x0000,SIS_RI_768x576, 0x00,0x00,0x06,0x06,0x4d,-1},
163 {0x14,0x0e3b,0x0000,SIS_RI_1280x800, 0x00,0x00,0x00,0x00,0x4c, 7}, /* 1280x800 */ 139 {0x14,0x0e3b,0x0000,SIS_RI_1280x800, 0x00,0x00,0x00,0x00,0x4e, 7}, /* 1280x800 */
164 {0x15,0x0e7d,0x0000,SIS_RI_1280x800, 0x00,0x00,0x00,0x00,0x4c, 7}, 140 {0x15,0x0e7d,0x0000,SIS_RI_1280x800, 0x00,0x00,0x00,0x00,0x4e, 7},
165 {0x16,0x0eff,0x0000,SIS_RI_1280x800, 0x00,0x00,0x00,0x00,0x4c, 7}, 141 {0x16,0x0eff,0x0000,SIS_RI_1280x800, 0x00,0x00,0x00,0x00,0x4e, 7},
166 {0x17,0x0e3b,0x0000,SIS_RI_1680x1050,0x00,0x00,0x00,0x00,0x4d, 9}, /* 1680x1050 */ 142 {0x17,0x0e3b,0x0000,SIS_RI_1680x1050,0x00,0x00,0x00,0x00,0x51, 9}, /* 1680x1050 */
167 {0x18,0x0e7d,0x0000,SIS_RI_1680x1050,0x00,0x00,0x00,0x00,0x4d, 9}, 143 {0x18,0x0e7d,0x0000,SIS_RI_1680x1050,0x00,0x00,0x00,0x00,0x51, 9},
168 {0x19,0x0eff,0x0000,SIS_RI_1680x1050,0x00,0x00,0x00,0x00,0x4d, 9}, 144 {0x19,0x0eff,0x0000,SIS_RI_1680x1050,0x00,0x00,0x00,0x00,0x51, 9},
169 {0x2c,0x267b,0x0000,SIS_RI_1920x1080,0x00,0x00,0x00,0x00,0x4e,-1}, /* 1920x1080(i) */ 145 {0x2c,0x267b,0x0000,SIS_RI_1920x1080,0x00,0x00,0x00,0x00,0x52,-1}, /* 1920x1080(i) */
170 {0x2d,0x26fd,0x0000,SIS_RI_1920x1080,0x00,0x00,0x00,0x00,0x4e,-1}, 146 {0x2d,0x26fd,0x0000,SIS_RI_1920x1080,0x00,0x00,0x00,0x00,0x52,-1},
171 {0x73,0x27ff,0x0000,SIS_RI_1920x1080,0x00,0x00,0x00,0x00,0x4e,-1}, 147 {0x73,0x27ff,0x0000,SIS_RI_1920x1080,0x00,0x00,0x00,0x00,0x52,-1},
172 {0x1d,0x6a1b,0x0000,SIS_RI_960x540, 0x00,0x00,0x00,0x00,0x4f,-1}, /* 960x540 */ 148 {0x1d,0x6a1b,0x0000,SIS_RI_960x540, 0x00,0x00,0x00,0x00,0x53,-1}, /* 960x540 */
173 {0x1e,0x6a3d,0x0000,SIS_RI_960x540, 0x00,0x00,0x00,0x00,0x4f,-1}, 149 {0x1e,0x6a3d,0x0000,SIS_RI_960x540, 0x00,0x00,0x00,0x00,0x53,-1},
174 {0x1f,0x6a7f,0x0000,SIS_RI_960x540, 0x00,0x00,0x00,0x00,0x4f,-1}, 150 {0x1f,0x6a7f,0x0000,SIS_RI_960x540, 0x00,0x00,0x00,0x00,0x53,-1},
175 {0x20,0x6a1b,0x0000,SIS_RI_960x600, 0x00,0x00,0x00,0x00,0x50,-1}, /* 960x600 */ 151 {0x20,0x6a1b,0x0000,SIS_RI_960x600, 0x00,0x00,0x00,0x00,0x54,-1}, /* 960x600 */
176 {0x21,0x6a3d,0x0000,SIS_RI_960x600, 0x00,0x00,0x00,0x00,0x50,-1}, 152 {0x21,0x6a3d,0x0000,SIS_RI_960x600, 0x00,0x00,0x00,0x00,0x54,-1},
177 {0x22,0x6a7f,0x0000,SIS_RI_960x600, 0x00,0x00,0x00,0x00,0x50,-1}, 153 {0x22,0x6a7f,0x0000,SIS_RI_960x600, 0x00,0x00,0x00,0x00,0x54,-1},
154 {0x1a,0x0e3b,0x0000,SIS_RI_1280x854, 0x00,0x00,0x00,0x00,0x55, 8}, /* 1280x854 */
155 {0x1b,0x0e7d,0x0000,SIS_RI_1280x854, 0x00,0x00,0x00,0x00,0x55, 8},
156 {0x1c,0x0eff,0x0000,SIS_RI_1280x854, 0x00,0x00,0x00,0x00,0x55, 8},
178 {0xff,0x0000,0x0000,0, 0x00,0x00,0x00,0x00,0x00,-1} 157 {0xff,0x0000,0x0000,0, 0x00,0x00,0x00,0x00,0x00,-1}
179}; 158};
180 159
181static const SiS_Ext2Struct SiS310_RefIndex[]= 160static const struct SiS_Ext2 SiS310_RefIndex[] =
182{ 161{
183 {0x085f,0x0d,0x03,0x05,0x05,0x6a, 800, 600, 0x40}, /* 0x0 */ 162 {0x085f,0x0d,0x03,0x05,0x05,0x6a, 800, 600, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x0 */
184 {0x0067,0x0e,0x04,0x05,0x05,0x6a, 800, 600, 0x40}, /* 0x1 */ 163 {0x0067,0x0e,0x04,0x05,0x05,0x6a, 800, 600, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x1 */
185 {0x0067,0x0f,0x08,0x48,0x05,0x6a, 800, 600, 0x40}, /* 0x2 */ 164 {0x0067,0x0f,0x08,0x48,0x05,0x6a, 800, 600, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x2 */
186 {0x0067,0x10,0x07,0x8b,0x05,0x6a, 800, 600, 0x40}, /* 0x3 */ 165 {0x0067,0x10,0x07,0x8b,0x05,0x6a, 800, 600, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x3 */
187 {0x0047,0x11,0x0a,0x00,0x05,0x6a, 800, 600, 0x40}, /* 0x4 */ 166 {0x0047,0x11,0x0a,0x00,0x05,0x6a, 800, 600, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x4 */
188 {0x0047,0x12,0x0d,0x00,0x05,0x6a, 800, 600, 0x40}, /* 0x5 */ 167 {0x0047,0x12,0x0d,0x00,0x05,0x6a, 800, 600, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x5 */
189 {0x0047,0x13,0x13,0x00,0x05,0x6a, 800, 600, 0x20}, /* 0x6 */ 168 {0x0047,0x13,0x13,0x00,0x05,0x6a, 800, 600, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x6 */
190 {0x0107,0x14,0x1c,0x00,0x05,0x6a, 800, 600, 0x20}, /* 0x7 */ 169 {0x0107,0x14,0x1c,0x00,0x05,0x6a, 800, 600, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x7 */
191 {0xc85f,0x05,0x00,0x04,0x04,0x2e, 640, 480, 0x40}, /* 0x8 */ 170 {0xc85f,0x05,0x00,0x04,0x04,0x2e, 640, 480, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x8 */
192 {0xc067,0x06,0x02,0x04,0x04,0x2e, 640, 480, 0x40}, /* 0x9 */ 171 {0xc067,0x06,0x02,0x04,0x04,0x2e, 640, 480, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x9 */
193 {0xc067,0x07,0x02,0x47,0x04,0x2e, 640, 480, 0x40}, /* 0xa */ 172 {0xc067,0x07,0x02,0x47,0x04,0x2e, 640, 480, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0xa */
194 {0xc067,0x08,0x03,0x8a,0x04,0x2e, 640, 480, 0x40}, /* 0xb */ 173 {0xc067,0x08,0x03,0x8a,0x04,0x2e, 640, 480, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0xb */
195 {0xc047,0x09,0x05,0x00,0x04,0x2e, 640, 480, 0x40}, /* 0xc */ 174 {0xc047,0x09,0x05,0x00,0x04,0x2e, 640, 480, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0xc */
196 {0xc047,0x0a,0x09,0x00,0x04,0x2e, 640, 480, 0x40}, /* 0xd */ 175 {0xc047,0x0a,0x09,0x00,0x04,0x2e, 640, 480, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0xd */
197 {0xc047,0x0b,0x0e,0x00,0x04,0x2e, 640, 480, 0x40}, /* 0xe */ 176 {0xc047,0x0b,0x0e,0x00,0x04,0x2e, 640, 480, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0xe */
198 {0xc047,0x0c,0x15,0x00,0x04,0x2e, 640, 480, 0x40}, /* 0xf */ 177 {0xc047,0x0c,0x15,0x00,0x04,0x2e, 640, 480, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0xf */
199 {0x487f,0x04,0x00,0x00,0x00,0x2f, 640, 400, 0x30}, /* 0x10 */ 178 {0x487f,0x04,0x00,0x00,0x00,0x2f, 640, 400, 0x30, 0x55, 0x6e, 0x00, 0x00, 0x00, 0x00}, /* 0x10 */
200 {0xc06f,0x3c,0x01,0x06,0x13,0x31, 720, 480, 0x30}, /* 0x11 */ 179 {0xc06f,0x3c,0x01,0x06,0x13,0x31, 720, 480, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x11 */
201 {0x006f,0x3d,0x03,0x06,0x14,0x32, 720, 576, 0x30}, /* 0x12 */ 180 {0x006f,0x3d,0x6f,0x06,0x14,0x32, 720, 576, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x12 (6f was 03) */
202 {0x0087,0x15,0x06,0x00,0x06,0x37,1024, 768, 0x30}, /* 0x13 */ 181 {0x0087,0x15,0x06,0x00,0x06,0x37,1024, 768, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x13 */
203 {0xc877,0x16,0x0b,0x06,0x06,0x37,1024, 768, 0x20}, /* 0x14 */ 182 {0xc877,0x16,0x0b,0x06,0x06,0x37,1024, 768, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x14 */
204 {0xc067,0x17,0x0f,0x49,0x06,0x37,1024, 768, 0x20}, /* 0x15 */ 183 {0xc067,0x17,0x0f,0x49,0x06,0x37,1024, 768, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x15 */
205 {0x0067,0x18,0x11,0x00,0x06,0x37,1024, 768, 0x20}, /* 0x16 */ 184 {0x0067,0x18,0x11,0x00,0x06,0x37,1024, 768, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x16 */
206 {0x0047,0x19,0x16,0x8c,0x06,0x37,1024, 768, 0x20}, /* 0x17 */ 185 {0x0047,0x19,0x16,0x8c,0x06,0x37,1024, 768, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x17 */
207 {0x0107,0x1a,0x1b,0x00,0x06,0x37,1024, 768, 0x10}, /* 0x18 */ 186 {0x0107,0x1a,0x1b,0x00,0x06,0x37,1024, 768, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x18 */
208 {0x0107,0x1b,0x1f,0x00,0x06,0x37,1024, 768, 0x10}, /* 0x19 */ 187 {0x0107,0x1b,0x1f,0x00,0x06,0x37,1024, 768, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x19 */
209 {0x0087,0x1c,0x11,0x00,0x07,0x3a,1280,1024, 0x30}, /* 0x1a */ 188 {0x0087,0x1c,0x11,0x00,0x07,0x3a,1280,1024, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x1a */
210 {0x0137,0x1d,0x19,0x07,0x07,0x3a,1280,1024, 0x00}, /* 0x1b */ 189 {0x0137,0x1d,0x19,0x07,0x07,0x3a,1280,1024, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x1b */
211 {0x0107,0x1e,0x1e,0x00,0x07,0x3a,1280,1024, 0x00}, /* 0x1c */ 190 {0x0107,0x1e,0x1e,0x00,0x07,0x3a,1280,1024, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x1c */
212 {0x0207,0x1f,0x20,0x00,0x07,0x3a,1280,1024, 0x00}, /* 0x1d */ 191 {0x0207,0x1f,0x20,0x00,0x07,0x3a,1280,1024, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x1d */
213 {0x0227,0x20,0x21,0x09,0x09,0x3c,1600,1200, 0x00}, /* 0x1e */ 192 {0x0227,0x20,0x21,0x09,0x09,0x3c,1600,1200, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x1e */
214 {0x0407,0x21,0x22,0x00,0x09,0x3c,1600,1200, 0x00}, /* 0x1f */ 193 {0x0407,0x21,0x22,0x00,0x09,0x3c,1600,1200, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x1f */
215 {0x0407,0x22,0x23,0x00,0x09,0x3c,1600,1200, 0x00}, /* 0x20 */ 194 {0x0407,0x22,0x23,0x00,0x09,0x3c,1600,1200, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x20 */
216 {0x0407,0x23,0x25,0x00,0x09,0x3c,1600,1200, 0x00}, /* 0x21 */ 195 {0x0407,0x23,0x25,0x00,0x09,0x3c,1600,1200, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x21 */
217 {0x0007,0x24,0x26,0x00,0x09,0x3c,1600,1200, 0x00}, /* 0x22 */ 196 {0x0007,0x24,0x26,0x00,0x09,0x3c,1600,1200, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x22 */
218 {0x0007,0x25,0x2c,0x00,0x09,0x3c,1600,1200, 0x00}, /* 0x23 */ 197 {0x0007,0x25,0x2c,0x00,0x09,0x3c,1600,1200, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x23 */
219 {0x0007,0x26,0x34,0x00,0x09,0x3c,1600,1200, 0x00}, /* 0x24 */ 198 {0x0007,0x26,0x34,0x00,0x09,0x3c,1600,1200, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x24 */
220 {0x407f,0x00,0x00,0x00,0x00,0x40, 320, 200, 0x30}, /* 0x25 */ 199 {0x407f,0x00,0x00,0x00,0x00,0x40, 320, 200, 0x30, 0x56, 0x4e, 0x00, 0x00, 0x00, 0x00}, /* 0x25 */
221 {0xc07f,0x01,0x00,0x04,0x04,0x50, 320, 240, 0x30}, /* 0x26 */ 200 {0xc07f,0x01,0x00,0x04,0x04,0x50, 320, 240, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x26 */
222 {0x007f,0x02,0x04,0x05,0x05,0x51, 400, 300, 0x30}, /* 0x27 */ 201 {0x007f,0x02,0x04,0x05,0x05,0x51, 400, 300, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x27 */
223 {0xc077,0x03,0x0b,0x06,0x06,0x52, 512, 384, 0x30}, /* 0x28 */ 202 {0xc077,0x03,0x0b,0x06,0x06,0x52, 512, 384, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x28 */
224 {0x8007,0x27,0x27,0x00,0x00,0x68,1920,1440, 0x00}, /* 0x29 */ 203 {0x8007,0x27,0x27,0x00,0x00,0x68,1920,1440, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x29 */
225 {0x4007,0x28,0x29,0x00,0x00,0x68,1920,1440, 0x00}, /* 0x2a */ 204 {0x4007,0x28,0x29,0x00,0x00,0x68,1920,1440, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x2a */
226 {0x4007,0x29,0x2e,0x00,0x00,0x68,1920,1440, 0x00}, /* 0x2b */ 205 {0x4007,0x29,0x2e,0x00,0x00,0x68,1920,1440, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x2b */
227 {0x4007,0x2a,0x30,0x00,0x00,0x68,1920,1440, 0x00}, /* 0x2c */ 206 {0x4007,0x2a,0x30,0x00,0x00,0x68,1920,1440, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x2c */
228 {0x4007,0x2b,0x35,0x00,0x00,0x68,1920,1440, 0x00}, /* 0x2d */ 207 {0x4007,0x2b,0x35,0x00,0x00,0x68,1920,1440, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x2d */
229 {0x4005,0x2c,0x39,0x00,0x00,0x68,1920,1440, 0x00}, /* 0x2e */ 208 {0x4005,0x2c,0x39,0x00,0x00,0x68,1920,1440, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x2e */
230 {0x4007,0x2d,0x2b,0x00,0x00,0x6c,2048,1536, 0x00}, /* 0x2f */ 209 {0x4007,0x2d,0x2b,0x00,0x00,0x6c,2048,1536, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x2f */
231 {0x4007,0x2e,0x31,0x00,0x00,0x6c,2048,1536, 0x00}, /* 0x30 */ 210 {0x4007,0x2e,0x31,0x00,0x00,0x6c,2048,1536, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x30 */
232 {0x4007,0x2f,0x33,0x00,0x00,0x6c,2048,1536, 0x00}, /* 0x31 */ 211 {0x4007,0x2f,0x33,0x00,0x00,0x6c,2048,1536, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x31 */
233 {0x4007,0x30,0x37,0x00,0x00,0x6c,2048,1536, 0x00}, /* 0x32 */ 212 {0x4007,0x30,0x37,0x00,0x00,0x6c,2048,1536, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x32 */
234 {0x4005,0x31,0x38,0x00,0x00,0x6c,2048,1536, 0x00}, /* 0x33 */ 213 {0x4005,0x31,0x38,0x00,0x00,0x6c,2048,1536, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x33 */
235 {0x0077,0x32,0x40,0x08,0x18,0x70, 800, 480, 0x30}, /* 0x34 */ 214 {0x2077,0x32,0x40,0x08,0x18,0x70, 800, 480, 0x30, 0x00, 0x00, 0x32, 0x40, 0x5e, 0x73}, /* 0x34 */
236 {0x0047,0x33,0x07,0x08,0x18,0x70, 800, 480, 0x30}, /* 0x35 */ 215 {0x2047,0x33,0x07,0x08,0x18,0x70, 800, 480, 0x30, 0x00, 0x00, 0x33, 0x07, 0xff, 0xff}, /* 0x35 */
237 {0x0047,0x34,0x0a,0x08,0x18,0x70, 800, 480, 0x30}, /* 0x36 */ 216 {0x2047,0x34,0x0a,0x08,0x18,0x70, 800, 480, 0x30, 0x00, 0x00, 0x34, 0x0a, 0xff, 0xff}, /* 0x36 */
238 {0x0077,0x35,0x0b,0x09,0x19,0x71,1024, 576, 0x30}, /* 0x37 */ 217 {0x2077,0x35,0x0b,0x09,0x19,0x71,1024, 576, 0x30, 0x00, 0x00, 0x35, 0x0b, 0x5f, 0x74}, /* 0x37 */
239 {0x0047,0x36,0x11,0x09,0x19,0x71,1024, 576, 0x30}, /* 0x38 */ 218 {0x2047,0x36,0x11,0x09,0x19,0x71,1024, 576, 0x30, 0x00, 0x00, 0x36, 0x11, 0xff, 0xff}, /* 0x38 */
240 {0x0047,0x37,0x16,0x09,0x19,0x71,1024, 576, 0x30}, /* 0x39 */ 219 {0x2047,0x37,0x16,0x09,0x19,0x71,1024, 576, 0x30, 0x00, 0x00, 0x37, 0x16, 0xff, 0xff}, /* 0x39 */
241 {0x1137,0x38,0x19,0x0a,0x0c,0x75,1280, 720, 0x30}, /* 0x3a */ 220 {0x3137,0x38,0x19,0x0a,0x0c,0x75,1280, 720, 0x30, 0x00, 0x00, 0x38, 0x19, 0x60, 0x75}, /* 0x3a */
242 {0x1107,0x39,0x1e,0x0a,0x0c,0x75,1280, 720, 0x30}, /* 0x3b */ 221 {0x3107,0x39,0x1e,0x0a,0x0c,0x75,1280, 720, 0x30, 0x00, 0x00, 0x39, 0x1e, 0xff, 0xff}, /* 0x3b */
243 {0x1307,0x3a,0x20,0x0a,0x0c,0x75,1280, 720, 0x30}, /* 0x3c */ 222 {0x3307,0x3a,0x20,0x0a,0x0c,0x75,1280, 720, 0x30, 0x00, 0x00, 0x3a, 0x20, 0xff, 0xff}, /* 0x3c */
244 {0x0127,0x3b,0x19,0x08,0x0a,0x7c,1280, 960, 0x30}, /* 0x3d */ 223 {0x0127,0x3b,0x19,0x08,0x0a,0x7c,1280, 960, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x3d */
245 {0x0227,0x4c,0x59,0x08,0x0a,0x7c,1280, 960, 0x20}, /* 0x3e */ 224 {0x0227,0x4c,0x59,0x08,0x0a,0x7c,1280, 960, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x3e */
246 {0xc07f,0x4e,0x00,0x06,0x04,0x5a, 320, 240, 0x30}, /* 0x3f */ /* FSTN 320x240 */ 225 {0xc07f,0x4e,0x00,0x06,0x04,0x5a, 320, 240, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x3f */ /* FSTN 320x240 */
247 {0x0077,0x42,0x5b,0x08,0x11,0x23,1280, 768, 0x30}, /* 0x40 */ /* 0x5b was 0x12 */ 226 {0x2077,0x42,0x5b,0x08,0x11,0x23,1280, 768, 0x30, 0x00, 0x00, 0x58, 0x19, 0x42, 0x5b}, /* 0x40 */ /* 0x5b was 0x12 */
248 {0x0127,0x43,0x4d,0x08,0x0b,0x26,1400,1050, 0x30}, /* 0x41 */ 227 {0x2077,0x42,0x5b,0x08,0x11,0x23,1280, 768, 0x30, 0x00, 0x00, 0x59, 0x1e, 0xff, 0xff}, /* 0x41 */
249 {0x0207,0x4b,0x5a,0x08,0x0b,0x26,1400,1050, 0x30}, /* 0x42 1400x1050-75Hz */ 228 {0x2077,0x42,0x5b,0x08,0x11,0x23,1280, 768, 0x30, 0x00, 0x00, 0x5a, 0x20, 0xff, 0xff}, /* 0x42 */
250 {0x0127,0x54,0x6d,0x00,0x1a,0x29,1152, 864, 0x30}, /* 0x43 1152x864-60Hz */ 229 {0x0127,0x43,0x4d,0x08,0x0b,0x26,1400,1050, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x43 */
251 {0x0127,0x44,0x19,0x00,0x1a,0x29,1152, 864, 0x30}, /* 0x44 1152x864-75Hz */ 230 {0x0207,0x4b,0x5a,0x08,0x0b,0x26,1400,1050, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x44 1400x1050-75Hz */
252 {0x0127,0x4a,0x1e,0x00,0x1a,0x29,1152, 864, 0x30}, /* 0x45 1152x864-85Hz */ 231 {0x0127,0x54,0x6d,0x00,0x1a,0x29,1152, 864, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x45 1152x864-60Hz */
253 {0x0087,0x45,0x57,0x00,0x16,0x39, 848, 480, 0x30}, /* 0x46 848x480-38Hzi */ 232 {0x0127,0x44,0x19,0x00,0x1a,0x29,1152, 864, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x46 1152x864-75Hz */
254 {0xc067,0x46,0x55,0x0b,0x16,0x39, 848, 480, 0x30}, /* 0x47 848x480-60Hz */ 233 {0x0127,0x4a,0x1e,0x00,0x1a,0x29,1152, 864, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x47 1152x864-85Hz */
255 {0x0087,0x47,0x57,0x00,0x17,0x3f, 856, 480, 0x30}, /* 0x48 856x480-38Hzi */ 234 {0x0087,0x45,0x57,0x00,0x16,0x39, 848, 480, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x48 848x480-38Hzi */
256 {0xc067,0x48,0x57,0x00,0x17,0x3f, 856, 480, 0x30}, /* 0x49 856x480-60Hz */ 235 {0xc067,0x46,0x55,0x0b,0x16,0x39, 848, 480, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x49 848x480-60Hz */
257 {0x0067,0x49,0x58,0x0c,0x1b,0x48,1360, 768, 0x30}, /* 0x4a 1360x768-60Hz */ 236 {0x0087,0x47,0x57,0x00,0x17,0x3f, 856, 480, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x4a 856x480-38Hzi */
258 {0x006f,0x4d,0x03,0x06,0x15,0x5f, 768, 576, 0x30}, /* 0x4b 768x576-56Hz */ 237 {0xc067,0x48,0x57,0x00,0x17,0x3f, 856, 480, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x4b 856x480-60Hz */
259 {0x0067,0x4f,0x5c,0x08,0x0d,0x14,1280, 800, 0x30}, /* 0x4c 1280x800-60Hz */ 238 {0x0067,0x49,0x58,0x0c,0x1b,0x48,1360, 768, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x4c 1360x768-60Hz */
260 {0x0067,0x50,0x5d,0x0c,0x0e,0x17,1680,1050, 0x30}, /* 0x4d 1680x1050-60Hz */ 239 {0x006f,0x4d,0x71,0x06,0x15,0x5f, 768, 576, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x4d 768x576-56Hz */
261 {0x0087,0x51,0x69,0x00,0x00,0x2c,1920,1080, 0x30}, /* 0x4e 1920x1080 60Hzi */ 240 {0x2067,0x4f,0x5c,0x08,0x0d,0x14,1280, 800, 0x30, 0x00, 0x00, 0x5b, 0x19, 0x4f, 0x5c}, /* 0x4e 1280x800-60Hz */
262 {0x0067,0x52,0x6a,0x00,0x1c,0x1d, 960, 540, 0x30}, /* 0x4f 960x540 60Hz */ 241 {0x2067,0x4f,0x5c,0x08,0x0d,0x14,1280, 800, 0x30, 0x00, 0x00, 0x5c, 0x1e, 0xff, 0xff}, /* 0x4f 1280x800-75Hz */
263 {0x0077,0x53,0x6b,0x0b,0x1d,0x20, 960, 600, 0x30}, /* 0x50 960x600 60Hz */ 242 {0x2067,0x4f,0x5c,0x08,0x0d,0x14,1280, 800, 0x30, 0x00, 0x00, 0x5d, 0x20, 0xff, 0xff}, /* 0x50 1280x800-85Hz */
264 {0xffff,0x00,0x00,0x00,0x00,0x00, 0, 0, 0} 243 {0x0067,0x50,0x5d,0x0c,0x0e,0x17,1680,1050, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x51 1680x1050-60Hz */
265}; 244 {0x0087,0x51,0x69,0x00,0x00,0x2c,1920,1080, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x52 1920x1080 60Hzi */
266 245 {0x0067,0x52,0x6a,0x00,0x1c,0x1d, 960, 540, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x53 960x540 60Hz */
267#ifdef LINUX_XF86 246 {0x0077,0x53,0x6b,0x0b,0x1d,0x20, 960, 600, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0x54 960x600 60Hz */
268static const struct { 247 {0x2067,0x61,0x76,0x0d,0x22,0x1a,1280, 854, 0x30, 0x00, 0x00, 0x62, 0x19, 0x61, 0x76}, /* 0x55 1280x854-60Hz */
269 UCHAR Ext_ModeID; /* ModeID in new ROM */ 248 {0x2067,0x61,0x76,0x0d,0x22,0x1a,1280, 854, 0x30, 0x00, 0x00, 0x63, 0x1e, 0xff, 0xff}, /* 0x56 1280x854-75Hz */
270 UCHAR Ext_MyModeID; /* corresponding ModeID in my tables (0 = identical) */ 249 {0x2067,0x61,0x76,0x0d,0x22,0x1a,1280, 854, 0x30, 0x00, 0x00, 0x64, 0x20, 0xff, 0xff}, /* 0x57 1280x854-85Hz */
271 USHORT Ext_VESAID; /* corresponding VESA ID in new ROM */ 250 {0xffff,0x00,0x00,0x00,0x00,0x00, 0, 0, 0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
272} SiS_EModeIDTable661[] = { 251};
273 { 0x6a, 0x00, 0x0102 }, 252
274 { 0x1d, 0x20, 0x0000 }, 253static const struct SiS_CRT1Table SiS310_CRT1Table[] =
275 { 0x1e, 0x21, 0x0000 },
276 { 0x1f, 0x22, 0x0000 },
277 { 0x20, 0x29, 0x0000 },
278 { 0x21, 0x2a, 0x0000 },
279 { 0x22, 0x2b, 0x0000 },
280 { 0x23, 0x00, 0x011c },
281 { 0x24, 0x00, 0x011d },
282 { 0x25, 0x00, 0x011e },
283 { 0x26, 0x00, 0x011f },
284 { 0x27, 0x00, 0x0120 },
285 { 0x28, 0x00, 0x0121 },
286 { 0x2a, 0x14, 0x013d },
287 { 0x2b, 0x15, 0x013e },
288 { 0x2c, 0x16, 0x013f },
289 { 0x2e, 0x00, 0x0101 },
290 { 0x2f, 0x00, 0x0100 },
291 { 0x30, 0x00, 0x0103 },
292 { 0x37, 0x00, 0x0104 },
293 { 0x38, 0x00, 0x0105 },
294 { 0x3a, 0x00, 0x0107 },
295 { 0x3c, 0x00, 0x0125 },
296 { 0x3d, 0x00, 0x0126 },
297 { 0x40, 0x00, 0x010d },
298 { 0x41, 0x00, 0x010e },
299 { 0x43, 0x00, 0x0110 },
300 { 0x44, 0x00, 0x0111 },
301 { 0x46, 0x00, 0x0113 },
302 { 0x47, 0x00, 0x0114 },
303 { 0x49, 0x00, 0x0116 },
304 { 0x4a, 0x00, 0x0117 },
305 { 0x4c, 0x00, 0x0119 },
306 { 0x4d, 0x00, 0x011a },
307 { 0x50, 0x00, 0x0127 },
308 { 0x51, 0x00, 0x0128 },
309 { 0x52, 0x00, 0x0129 },
310 { 0x56, 0x00, 0x012a },
311 { 0x57, 0x00, 0x012b },
312 { 0x58, 0x00, 0x012c },
313 { 0x59, 0x00, 0x012d },
314 { 0x5a, 0x17, 0x012e },
315 { 0x5b, 0x18, 0x012f },
316 { 0x5c, 0x19, 0x0130 },
317 { 0x5d, 0x00, 0x0131 },
318 { 0x62, 0x00, 0x0112 },
319 { 0x63, 0x00, 0x0115 },
320 { 0x64, 0x00, 0x0118 },
321 { 0x65, 0x00, 0x011b },
322 { 0x66, 0x00, 0x0132 },
323 { 0x75, 0x00, 0x013a },
324 { 0x78, 0x00, 0x013b },
325 { 0x79, 0x00, 0x013c },
326 { 0x7b, 0x7c, 0x0136 },
327 { 0x7c, 0x7d, 0x0137 },
328 { 0x7d, 0x7e, 0x0138 },
329 { 0xff, 0xff, 0xffff }
330};
331#endif
332
333static const SiS_CRT1TableStruct SiS310_CRT1Table[]=
334{ 254{
335 {{0x2d,0x27,0x28,0x90,0x2c,0x80,0xbf,0x1f, 255 {{0x2d,0x27,0x28,0x90,0x2c,0x80,0xbf,0x1f,
336 0x9c,0x8e,0x8f,0x96,0xb9,0x30,0x00,0x00, 256 0x9c,0x8e,0x8f,0x96,0xb9,0x30,0x00,0x00,
337 0x00}}, /* 0x0 */ 257 0x00}}, /* 0x0 */
338 {{0x2d,0x27,0x28,0x90,0x2c,0x80,0x0b,0x3e, 258 {{0x2d,0x27,0x28,0x90,0x2c,0x80,0x0b,0x3e,
339 0xe9,0x8b,0xdf,0xe7,0x04,0x00,0x00,0x00, 259 0xe9,0x8b,0xdf,0xe7,0x04,0x00,0x00,0x00,
340 0x00}}, /* 0x1 */ 260 0x00}}, /* 0x1 */
341 {{0x3d,0x31,0x31,0x81,0x37,0x1f,0x72,0xf0, 261 {{0x3d,0x31,0x31,0x81,0x37,0x1f,0x72,0xf0,
342 0x58,0x8c,0x57,0x57,0x73,0x20,0x00,0x05, 262 0x58,0x8c,0x57,0x57,0x73,0x20,0x00,0x05,
343 0x01}}, /* 0x2 */ 263 0x01}}, /* 0x2 */
344 {{0x4f,0x3f,0x3f,0x93,0x45,0x0d,0x24,0xf5, 264 {{0x4f,0x3f,0x3f,0x93,0x45,0x0d,0x24,0xf5,
345 0x02,0x88,0xff,0xff,0x25,0x10,0x00,0x01, 265 0x02,0x88,0xff,0xff,0x25,0x10,0x00,0x01,
346 0x01}}, /* 0x3 */ 266 0x01}}, /* 0x3 */
347 {{0x5f,0x4f,0x50,0x82,0x55,0x81,0xbf,0x1f, 267 {{0x5f,0x4f,0x50,0x82,0x55,0x81,0xbf,0x1f,
348 0x9c,0x8e,0x8f,0x96,0xb9,0x30,0x00,0x05, 268 0x9c,0x8e,0x8f,0x96,0xb9,0x30,0x00,0x05,
349 0x00}}, /* 0x4 */ 269 0x00}}, /* 0x4 */
350#if 0 270 {{0x5f,0x4f,0x4f,0x83,0x55,0x81,0x0b,0x3e, /* corrected 640x480-60 */
351 {{0x5f,0x4f,0x50,0x82,0x55,0x81,0x0b,0x3e,
352 0xe9,0x8b,0xdf,0xe7,0x04,0x00,0x00,0x05,
353 0x00}}, /* 0x5 */
354#endif
355 {{0x5f,0x4f,0x4f,0x83,0x55,0x81,0x0b,0x3e, /* 0x05 - corrected 640x480-60 */
356 0xe9,0x8b,0xdf,0xe8,0x0c,0x00,0x00,0x05, 271 0xe9,0x8b,0xdf,0xe8,0x0c,0x00,0x00,0x05,
357 0x00}}, 272 0x00}}, /* 0x5 */
358#if 0 273 {{0x63,0x4f,0x4f,0x87,0x56,0x9b,0x06,0x3e, /* corrected 640x480-72 */
359 {{0x63,0x4f,0x50,0x86,0x56,0x9b,0x06,0x3e,
360 0xe8,0x8b,0xdf,0xe7,0xff,0x10,0x00,0x01,
361 0x00}}, /* 0x6 */
362#endif
363 {{0x63,0x4f,0x4f,0x87,0x56,0x9b,0x06,0x3e, /* 0x06 - corrected 640x480-72 */
364 0xe8,0x8a,0xdf,0xe7,0x07,0x00,0x00,0x01, 274 0xe8,0x8a,0xdf,0xe7,0x07,0x00,0x00,0x01,
365 0x00}}, 275 0x00}}, /* 0x6 */
366 {{0x64,0x4f,0x4f,0x88,0x55,0x9d,0xf2,0x1f, 276 {{0x64,0x4f,0x4f,0x88,0x55,0x9d,0xf2,0x1f,
367 0xe0,0x83,0xdf,0xdf,0xf3,0x10,0x00,0x01, 277 0xe0,0x83,0xdf,0xdf,0xf3,0x10,0x00,0x01,
368 0x00}}, /* 0x7 */ 278 0x00}}, /* 0x7 */
369 {{0x63,0x4f,0x4f,0x87,0x5a,0x81,0xfb,0x1f, 279 {{0x63,0x4f,0x4f,0x87,0x5a,0x81,0xfb,0x1f,
370 0xe0,0x83,0xdf,0xdf,0xfc,0x10,0x00,0x05, 280 0xe0,0x83,0xdf,0xdf,0xfc,0x10,0x00,0x05,
371 0x00}}, /* 0x8 */ 281 0x00}}, /* 0x8 */
372 {{0x65,0x4f,0x4f,0x89,0x58,0x80,0xfb,0x1f, 282 {{0x65,0x4f,0x4f,0x89,0x58,0x80,0xfb,0x1f,
373 0xe0,0x83,0xdf,0xdf,0xfc,0x10,0x00,0x05, /* Corrected VBE */ 283 0xe0,0x83,0xdf,0xdf,0xfc,0x10,0x00,0x05, /* Corrected VBE */
374 0x61}}, /* 0x9 */ 284 0x61}}, /* 0x9 */
375 {{0x65,0x4f,0x4f,0x89,0x58,0x80,0x01,0x3e, 285 {{0x65,0x4f,0x4f,0x89,0x58,0x80,0x01,0x3e,
376 0xe0,0x83,0xdf,0xdf,0x02,0x00,0x00,0x05, 286 0xe0,0x83,0xdf,0xdf,0x02,0x00,0x00,0x05,
377 0x61}}, /* 0xa */ 287 0x61}}, /* 0xa */
378 {{0x67,0x4f,0x4f,0x8b,0x58,0x81,0x0d,0x3e, 288 {{0x67,0x4f,0x4f,0x8b,0x58,0x81,0x0d,0x3e,
379 0xe0,0x83,0xdf,0xdf,0x0e,0x00,0x00,0x05, /* Corrected VBE */ 289 0xe0,0x83,0xdf,0xdf,0x0e,0x00,0x00,0x05, /* Corrected VBE */
380 0x61}}, /* 0xb */ 290 0x61}}, /* 0xb */
381 {{0x65,0x4f,0x4f,0x89,0x57,0x9f,0xfb,0x1f, 291 {{0x65,0x4f,0x4f,0x89,0x57,0x9f,0xfb,0x1f,
382 0xe6,0x8a,0xdf,0xdf,0xfc,0x10,0x00,0x01, /* Corrected VDE, VBE */ 292 0xe6,0x8a,0xdf,0xdf,0xfc,0x10,0x00,0x01, /* Corrected VDE, VBE */
383 0x00}}, /* 0xc */ 293 0x00}}, /* 0xc */
384 {{0x7b,0x63,0x63,0x9f,0x6a,0x93,0x6f,0xf0, 294 {{0x7b,0x63,0x63,0x9f,0x6a,0x93,0x6f,0xf0,
385 0x58,0x8a,0x57,0x57,0x70,0x20,0x00,0x05, 295 0x58,0x8a,0x57,0x57,0x70,0x20,0x00,0x05,
386 0x01}}, /* 0xd */ 296 0x01}}, /* 0xd */
387 {{0x7f,0x63,0x63,0x83,0x6c,0x1c,0x72,0xf0, 297 {{0x7f,0x63,0x63,0x83,0x6c,0x1c,0x72,0xf0,
388 0x58,0x8c,0x57,0x57,0x73,0x20,0x00,0x06, 298 0x58,0x8c,0x57,0x57,0x73,0x20,0x00,0x06,
389 0x01}}, /* 0xe */ 299 0x01}}, /* 0xe */
390 {{0x7d,0x63,0x63,0x81,0x6e,0x1d,0x98,0xf0, 300 {{0x7d,0x63,0x63,0x81,0x6e,0x1d,0x98,0xf0,
391 0x7c,0x82,0x57,0x57,0x99,0x00,0x00,0x06, 301 0x7c,0x82,0x57,0x57,0x99,0x00,0x00,0x06,
392 0x01}}, /* 0xf */ 302 0x01}}, /* 0xf */
393 {{0x7f,0x63,0x63,0x83,0x69,0x13,0x6f,0xf0, 303 {{0x7f,0x63,0x63,0x83,0x69,0x13,0x6f,0xf0,
394 0x58,0x8b,0x57,0x57,0x70,0x20,0x00,0x06, 304 0x58,0x8b,0x57,0x57,0x70,0x20,0x00,0x06,
395 0x01}}, /* 0x10 */ 305 0x01}}, /* 0x10 */
396 {{0x7e,0x63,0x63,0x82,0x6b,0x13,0x75,0xf0, 306 {{0x7e,0x63,0x63,0x82,0x6b,0x13,0x75,0xf0,
397 0x58,0x8b,0x57,0x57,0x76,0x20,0x00,0x06, 307 0x58,0x8b,0x57,0x57,0x76,0x20,0x00,0x06,
398 0x01}}, /* 0x11 */ 308 0x01}}, /* 0x11 */
399 {{0x81,0x63,0x63,0x85,0x6d,0x18,0x7a,0xf0, 309 {{0x81,0x63,0x63,0x85,0x6d,0x18,0x7a,0xf0,
400 0x58,0x8b,0x57,0x57,0x7b,0x20,0x00,0x06, 310 0x58,0x8b,0x57,0x57,0x7b,0x20,0x00,0x06,
401 0x61}}, /* 0x12 */ 311 0x61}}, /* 0x12 */
402 {{0x83,0x63,0x63,0x87,0x6e,0x19,0x81,0xf0, 312 {{0x83,0x63,0x63,0x87,0x6e,0x19,0x81,0xf0,
403 0x58,0x8b,0x57,0x57,0x82,0x20,0x00,0x06, 313 0x58,0x8b,0x57,0x57,0x82,0x20,0x00,0x06,
404 0x61}}, /* 0x13 */ 314 0x61}}, /* 0x13 */
405 {{0x85,0x63,0x63,0x89,0x6f,0x1a,0x91,0xf0, 315 {{0x85,0x63,0x63,0x89,0x6f,0x1a,0x91,0xf0,
406 0x58,0x8b,0x57,0x57,0x92,0x20,0x00,0x06, 316 0x58,0x8b,0x57,0x57,0x92,0x20,0x00,0x06,
407 0x61}}, /* 0x14 */ 317 0x61}}, /* 0x14 */
408 {{0x99,0x7f,0x7f,0x9d,0x84,0x1a,0x96,0x1f, 318 {{0x99,0x7f,0x7f,0x9d,0x84,0x1a,0x96,0x1f,
409 0x7f,0x83,0x7f,0x7f,0x97,0x10,0x00,0x02, 319 0x7f,0x83,0x7f,0x7f,0x97,0x10,0x00,0x02,
410 0x00}}, /* 0x15 */ 320 0x00}}, /* 0x15 */
411 {{0xa3,0x7f,0x7f,0x87,0x86,0x97,0x24,0xf5, 321 {{0xa3,0x7f,0x7f,0x87,0x86,0x97,0x24,0xf5,
412 0x02,0x88,0xff,0xff,0x25,0x10,0x00,0x02, 322 0x02,0x88,0xff,0xff,0x25,0x10,0x00,0x02,
413 0x01}}, /* 0x16 */ 323 0x01}}, /* 0x16 */
414 {{0xa1,0x7f,0x7f,0x85,0x86,0x97,0x24,0xf5, 324 {{0xa1,0x7f,0x7f,0x85,0x86,0x97,0x24,0xf5,
415 0x02,0x88,0xff,0xff,0x25,0x10,0x00,0x02, 325 0x02,0x88,0xff,0xff,0x25,0x10,0x00,0x02,
416 0x01}}, /* 0x17 */ 326 0x01}}, /* 0x17 */
417 {{0x9f,0x7f,0x7f,0x83,0x85,0x91,0x1e,0xf5, 327 {{0x9f,0x7f,0x7f,0x83,0x85,0x91,0x1e,0xf5,
418 0x00,0x83,0xff,0xff,0x1f,0x10,0x00,0x02, 328 0x00,0x83,0xff,0xff,0x1f,0x10,0x00,0x02,
419 0x01}}, /* 0x18 */ 329 0x01}}, /* 0x18 */
420 {{0xa7,0x7f,0x7f,0x8b,0x89,0x95,0x26,0xf5, 330 {{0xa7,0x7f,0x7f,0x8b,0x89,0x95,0x26,0xf5,
421 0x00,0x83,0xff,0xff,0x27,0x10,0x00,0x02, 331 0x00,0x83,0xff,0xff,0x27,0x10,0x00,0x02,
422 0x01}}, /* 0x19 */ 332 0x01}}, /* 0x19 */
423 {{0xa9,0x7f,0x7f,0x8d,0x8c,0x9a,0x2c,0xf5, 333 {{0xa9,0x7f,0x7f,0x8d,0x8c,0x9a,0x2c,0xf5,
424 0x00,0x83,0xff,0xff,0x2d,0x14,0x00,0x02, 334 0x00,0x83,0xff,0xff,0x2d,0x14,0x00,0x02,
425 0x62}}, /* 0x1a */ 335 0x62}}, /* 0x1a */
426 {{0xab,0x7f,0x7f,0x8f,0x8d,0x9b,0x35,0xf5, 336 {{0xab,0x7f,0x7f,0x8f,0x8d,0x9b,0x35,0xf5,
427 0x00,0x83,0xff,0xff,0x36,0x14,0x00,0x02, 337 0x00,0x83,0xff,0xff,0x36,0x14,0x00,0x02,
428 0x62}}, /* 0x1b */ 338 0x62}}, /* 0x1b */
429 {{0xcf,0x9f,0x9f,0x93,0xb2,0x01,0x14,0xba, 339 {{0xcf,0x9f,0x9f,0x93,0xb2,0x01,0x14,0xba,
430 0x00,0x83,0xff,0xff,0x15,0x00,0x00,0x03, 340 0x00,0x83,0xff,0xff,0x15,0x00,0x00,0x03,
431 0x00}}, /* 0x1c */ 341 0x00}}, /* 0x1c */
432 {{0xce,0x9f,0x9f,0x92,0xa9,0x17,0x28,0x5a, 342 {{0xce,0x9f,0x9f,0x92,0xa9,0x17,0x28,0x5a,
433 0x00,0x83,0xff,0xff,0x29,0x09,0x00,0x07, 343 0x00,0x83,0xff,0xff,0x29,0x09,0x00,0x07,
434 0x01}}, /* 0x1d */ 344 0x01}}, /* 0x1d */
435 {{0xce,0x9f,0x9f,0x92,0xa5,0x17,0x28,0x5a, 345 {{0xce,0x9f,0x9f,0x92,0xa5,0x17,0x28,0x5a,
436 0x00,0x83,0xff,0xff,0x29,0x09,0x00,0x07, 346 0x00,0x83,0xff,0xff,0x29,0x09,0x00,0x07,
437 0x01}}, /* 0x1e */ 347 0x01}}, /* 0x1e */
438 {{0xd3,0x9f,0x9f,0x97,0xab,0x1f,0x2e,0x5a, 348 {{0xd3,0x9f,0x9f,0x97,0xab,0x1f,0x2e,0x5a,
439 0x00,0x83,0xff,0xff,0x2f,0x09,0x00,0x07, 349 0x00,0x83,0xff,0xff,0x2f,0x09,0x00,0x07,
440 0x01}}, /* 0x1f */ 350 0x01}}, /* 0x1f */
441 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10, 351 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10,
442 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04, 352 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04,
443 0x00}}, /* 0x20 */ 353 0x00}}, /* 0x20 */
444 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10, 354 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10,
445 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04, 355 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04,
446 0x00}}, /* 0x21 @ 4084 */ 356 0x00}}, /* 0x21 */
447 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10, 357 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10,
448 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04, 358 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04,
449 0x00}}, /* 0x22 */ 359 0x00}}, /* 0x22 */
450 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10, 360 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10,
451 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04, 361 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04,
452 0x00}}, /* 0x23 */ 362 0x00}}, /* 0x23 */
453 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10, 363 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10,
454 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04, 364 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04,
455 0x00}}, /* 0x24 */ 365 0x00}}, /* 0x24 */
456 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10, 366 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10,
457 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04, 367 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04,
458 0x00}}, /* 0x25 */ 368 0x00}}, /* 0x25 */
459 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10, 369 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10,
460 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04, 370 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04,
461 0x00}}, /* 0x26 */ 371 0x00}}, /* 0x26 */
462 {{0x40,0xef,0xef,0x84,0x03,0x1d,0xda,0x1f, 372 {{0x40,0xef,0xef,0x84,0x03,0x1d,0xda,0x1f,
463 0xa0,0x83,0x9f,0x9f,0xdb,0x1f,0x41,0x01, 373 0xa0,0x83,0x9f,0x9f,0xdb,0x1f,0x41,0x01,
464 0x00}}, /* 0x27 */ 374 0x00}}, /* 0x27 */
465 {{0x43,0xef,0xef,0x87,0x06,0x00,0xd4,0x1f, 375 {{0x43,0xef,0xef,0x87,0x06,0x00,0xd4,0x1f,
466 0xa0,0x83,0x9f,0x9f,0xd5,0x1f,0x41,0x05, 376 0xa0,0x83,0x9f,0x9f,0xd5,0x1f,0x41,0x05,
467 0x63}}, /* 0x28 */ 377 0x63}}, /* 0x28 */
468 {{0x45,0xef,0xef,0x89,0x07,0x01,0xd9,0x1f, 378 {{0x45,0xef,0xef,0x89,0x07,0x01,0xd9,0x1f,
469 0xa0,0x83,0x9f,0x9f,0xda,0x1f,0x41,0x05, 379 0xa0,0x83,0x9f,0x9f,0xda,0x1f,0x41,0x05,
470 0x63}}, /* 0x29 */ 380 0x63}}, /* 0x29 */
471 {{0x40,0xef,0xef,0x84,0x03,0x1d,0xda,0x1f, 381 {{0x40,0xef,0xef,0x84,0x03,0x1d,0xda,0x1f,
472 0xa0,0x83,0x9f,0x9f,0xdb,0x1f,0x41,0x01, 382 0xa0,0x83,0x9f,0x9f,0xdb,0x1f,0x41,0x01,
473 0x00}}, /* 0x2a */ 383 0x00}}, /* 0x2a */
474 {{0x40,0xef,0xef,0x84,0x03,0x1d,0xda,0x1f, 384 {{0x40,0xef,0xef,0x84,0x03,0x1d,0xda,0x1f,
475 0xa0,0x83,0x9f,0x9f,0xdb,0x1f,0x41,0x01, 385 0xa0,0x83,0x9f,0x9f,0xdb,0x1f,0x41,0x01,
476 0x00}}, /* 0x2b */ 386 0x00}}, /* 0x2b */
477 {{0x40,0xef,0xef,0x84,0x03,0x1d,0xda,0x1f, 387 {{0x40,0xef,0xef,0x84,0x03,0x1d,0xda,0x1f,
478 0xa0,0x83,0x9f,0x9f,0xdb,0x1f,0x41,0x01, 388 0xa0,0x83,0x9f,0x9f,0xdb,0x1f,0x41,0x01,
479 0x00}}, /* 0x2c */ 389 0x00}}, /* 0x2c */
480 {{0x59,0xff,0xff,0x9d,0x17,0x13,0x33,0xba, 390 {{0x59,0xff,0xff,0x9d,0x17,0x13,0x33,0xba,
481 0x00,0x83,0xff,0xff,0x34,0x0f,0x41,0x05, 391 0x00,0x83,0xff,0xff,0x34,0x0f,0x41,0x05,
482 0x44}}, /* 0x2d */ 392 0x44}}, /* 0x2d */
483 {{0x5b,0xff,0xff,0x9f,0x18,0x14,0x38,0xba, 393 {{0x5b,0xff,0xff,0x9f,0x18,0x14,0x38,0xba,
484 0x00,0x83,0xff,0xff,0x39,0x0f,0x41,0x05, 394 0x00,0x83,0xff,0xff,0x39,0x0f,0x41,0x05,
485 0x44}}, /* 0x2e */ 395 0x44}}, /* 0x2e */
486 {{0x5b,0xff,0xff,0x9f,0x18,0x14,0x3d,0xba, 396 {{0x5b,0xff,0xff,0x9f,0x18,0x14,0x3d,0xba,
487 0x00,0x83,0xff,0xff,0x3e,0x0f,0x41,0x05, 397 0x00,0x83,0xff,0xff,0x3e,0x0f,0x41,0x05,
488 0x44}}, /* 0x2f */ 398 0x44}}, /* 0x2f */
489 {{0x5d,0xff,0xff,0x81,0x19,0x95,0x41,0xba, 399 {{0x5d,0xff,0xff,0x81,0x19,0x95,0x41,0xba,
490 0x00,0x84,0xff,0xff,0x42,0x0f,0x41,0x05, 400 0x00,0x84,0xff,0xff,0x42,0x0f,0x41,0x05,
491 0x44}}, /* 0x30 */ 401 0x44}}, /* 0x30 */
492 {{0x55,0xff,0xff,0x99,0x0d,0x0c,0x3e,0xba, 402 {{0x55,0xff,0xff,0x99,0x0d,0x0c,0x3e,0xba,
493 0x00,0x84,0xff,0xff,0x3f,0x0f,0x41,0x05, 403 0x00,0x84,0xff,0xff,0x3f,0x0f,0x41,0x05,
494 0x00}}, /* 0x31 */ 404 0x00}}, /* 0x31 */
495 {{0x7f,0x63,0x63,0x83,0x6c,0x1c,0x72,0xba, 405 {{0x7f,0x63,0x63,0x83,0x6c,0x1c,0x72,0xba,
496 0x27,0x8b,0xdf,0xdf,0x73,0x00,0x00,0x06, 406 0x27,0x8b,0xdf,0xdf,0x73,0x00,0x00,0x06,
497 0x01}}, /* 0x32 */ 407 0x01}}, /* 0x32 */
498 {{0x7f,0x63,0x63,0x83,0x69,0x13,0x6f,0xba, 408 {{0x7f,0x63,0x63,0x83,0x69,0x13,0x6f,0xba,
499 0x26,0x89,0xdf,0xdf,0x6f,0x00,0x00,0x06, 409 0x26,0x89,0xdf,0xdf,0x6f,0x00,0x00,0x06,
500 0x01}}, /* 0x33 */ 410 0x01}}, /* 0x33 */
501 {{0x7f,0x63,0x63,0x82,0x6b,0x13,0x75,0xba, 411 {{0x7f,0x63,0x63,0x82,0x6b,0x13,0x75,0xba,
502 0x29,0x8c,0xdf,0xdf,0x75,0x00,0x00,0x06, 412 0x29,0x8c,0xdf,0xdf,0x75,0x00,0x00,0x06,
503 0x01}}, /* 0x34 */ 413 0x01}}, /* 0x34 */
504 {{0xa3,0x7f,0x7f,0x87,0x86,0x97,0x24,0xf1, 414 {{0xa3,0x7f,0x7f,0x87,0x86,0x97,0x24,0xf1,
505 0xaf,0x85,0x3f,0x3f,0x25,0x30,0x00,0x02, 415 0xaf,0x85,0x3f,0x3f,0x25,0x30,0x00,0x02,
506 0x01}}, /* 0x35 */ 416 0x01}}, /* 0x35 */
507 {{0x9f,0x7f,0x7f,0x83,0x85,0x91,0x1e,0xf1, 417 {{0x9f,0x7f,0x7f,0x83,0x85,0x91,0x1e,0xf1,
508 0xad,0x81,0x3f,0x3f,0x1f,0x30,0x00,0x02, 418 0xad,0x81,0x3f,0x3f,0x1f,0x30,0x00,0x02,
509 0x01}}, /* 0x36 */ 419 0x01}}, /* 0x36 */
510 {{0xa7,0x7f,0x7f,0x88,0x89,0x95,0x26,0xf1, /* 95 was 15 - illegal HBE! */ 420 {{0xa7,0x7f,0x7f,0x88,0x89,0x95,0x26,0xf1, /* 95 was 15 - illegal HBE! */
511 0xb1,0x85,0x3f,0x3f,0x27,0x30,0x00,0x02, 421 0xb1,0x85,0x3f,0x3f,0x27,0x30,0x00,0x02,
512 0x01}}, /* 0x37 */ 422 0x01}}, /* 0x37 */
513 {{0xce,0x9f,0x9f,0x92,0xa9,0x17,0x28,0xc4, 423 {{0xce,0x9f,0x9f,0x92,0xa9,0x17,0x28,0xc4,
514 0x7a,0x8e,0xcf,0xcf,0x29,0x21,0x00,0x07, 424 0x7a,0x8e,0xcf,0xcf,0x29,0x21,0x00,0x07,
515 0x01}}, /* 0x38 */ 425 0x01}}, /* 0x38 */
516 {{0xce,0x9f,0x9f,0x92,0xa5,0x17,0x28,0xd4, 426 {{0xce,0x9f,0x9f,0x92,0xa5,0x17,0x28,0xd4,
517 0x7a,0x8e,0xcf,0xcf,0x29,0x21,0x00,0x07, 427 0x7a,0x8e,0xcf,0xcf,0x29,0x21,0x00,0x07,
518 0x01}}, /* 0x39 */ 428 0x01}}, /* 0x39 */
519 {{0xd3,0x9f,0x9f,0x97,0xab,0x1f,0x2e,0xd4, 429 {{0xd3,0x9f,0x9f,0x97,0xab,0x1f,0x2e,0xd4,
520 0x7d,0x81,0xcf,0xcf,0x2f,0x21,0x00,0x07, 430 0x7d,0x81,0xcf,0xcf,0x2f,0x21,0x00,0x07,
521 0x01}}, /* 0x3a */ 431 0x01}}, /* 0x3a */
522#if 0
523 {{0xdc,0x9f,0x9f,0x00,0xab,0x19,0xe6,0xef, /* 1280x960 - invalid */
524 0xc0,0xc3,0xbf,0xbf,0xe7,0x10,0x00,0x07,
525 0x01}}, /* 0x3b */
526#endif
527 {{0xdc,0x9f,0x9f,0x80,0xaf,0x9d,0xe6,0xff, /* 1280x960-60 - corrected */ 432 {{0xdc,0x9f,0x9f,0x80,0xaf,0x9d,0xe6,0xff, /* 1280x960-60 - corrected */
528 0xc0,0x83,0xbf,0xbf,0xe7,0x10,0x00,0x07, 433 0xc0,0x83,0xbf,0xbf,0xe7,0x10,0x00,0x07,
529 0x01}}, /* 0x3b */ 434 0x01}}, /* 0x3b */
530 {{0x6b,0x59,0x59,0x8f,0x5e,0x8c,0x0b,0x3e, 435 {{0x6b,0x59,0x59,0x8f,0x5e,0x8c,0x0b,0x3e,
531 0xe9,0x8b,0xdf,0xe7,0x04,0x00,0x00,0x05, 436 0xe9,0x8b,0xdf,0xe7,0x04,0x00,0x00,0x05,
532 0x00}}, /* 0x3c */ 437 0x00}}, /* 0x3c */
533 {{0x7b,0x59,0x63,0x9f,0x6a,0x93,0x6f,0xf0, 438 {{0x6d,0x59,0x59,0x91,0x60,0x89,0x53,0xf0, /* 720x576, corrected to 60Hz */
534 0x58,0x8a,0x3f,0x57,0x70,0x20,0x00,0x05, 439 0x41,0x84,0x3f,0x3f,0x54,0x00,0x00,0x05,
535 0x01}}, /* 0x3d */ 440 0x41}}, /* 0x3d */
536 {{0x86,0x6a,0x6a,0x8a,0x74,0x06,0x8c,0x15, 441 {{0x86,0x6a,0x6a,0x8a,0x74,0x06,0x8c,0x15,
537 0x4f,0x83,0xef,0xef,0x8d,0x30,0x00,0x02, 442 0x4f,0x83,0xef,0xef,0x8d,0x30,0x00,0x02,
538 0x00}}, /* 0x3e */ 443 0x00}}, /* 0x3e */
539 {{0x81,0x6a,0x6a,0x85,0x70,0x00,0x0f,0x3e, 444 {{0x81,0x6a,0x6a,0x85,0x70,0x00,0x0f,0x3e,
540 0xeb,0x8e,0xdf,0xdf,0x10,0x00,0x00,0x02, 445 0xeb,0x8e,0xdf,0xdf,0x10,0x00,0x00,0x02,
541 0x00}}, /* 0x3f */ 446 0x00}}, /* 0x3f */
542 {{0xa3,0x7f,0x7f,0x87,0x86,0x97,0x1e,0xf1, 447 {{0xa3,0x7f,0x7f,0x87,0x86,0x97,0x1e,0xf1,
543 0xae,0x85,0x57,0x57,0x1f,0x30,0x00,0x02, 448 0xae,0x85,0x57,0x57,0x1f,0x30,0x00,0x02,
544 0x01}}, /* 0x40 */ 449 0x01}}, /* 0x40 */
@@ -578,11 +483,11 @@ static const SiS_CRT1TableStruct SiS310_CRT1Table[]=
578 {{0xd3,0x9f,0x9f,0x97,0xab,0x1f,0xf1,0xff, /* 1280x960-85 */ 483 {{0xd3,0x9f,0x9f,0x97,0xab,0x1f,0xf1,0xff, /* 1280x960-85 */
579 0xc0,0x83,0xbf,0xbf,0xf2,0x10,0x00,0x07, 484 0xc0,0x83,0xbf,0xbf,0xf2,0x10,0x00,0x07,
580 0x01}}, /* 0x4c */ 485 0x01}}, /* 0x4c */
581 {{0x7b,0x5f,0x63,0x9f,0x6a,0x93,0x6f,0xf0, /* 768x576 */ 486 {{0x75,0x5f,0x5f,0x99,0x66,0x90,0x53,0xf0, /* 768x576, corrected to 60Hz */
582 0x58,0x8a,0x3f,0x57,0x70,0x20,0x00,0x05, 487 0x41,0x84,0x3f,0x3f,0x54,0x00,0x00,0x05,
583 0x01}}, /* 0x4d */ 488 0x41}}, /* 0x4d */
584 {{0x2d,0x27,0x28,0x90,0x2c,0x80,0x0b,0x3e, /* FSTN 320x480, TEMP - possibly invalid */ 489 {{0x5f,0x27,0x4f,0x83,0x55,0x81,0x0b,0x3e, /* FSTN 320x240 (working) */
585 0xe9,0x8b,0xdf,0xe7,0x04,0x00,0x00,0x00, 490 0xe9,0x8b,0xdf,0xe8,0x0c,0x00,0x00,0x05,
586 0x00}}, /* 0x4e */ 491 0x00}}, /* 0x4e */
587 {{0xcd,0x9f,0x9f,0x91,0xab,0x1c,0x3a,0xff, /* 1280x800-60 */ 492 {{0xcd,0x9f,0x9f,0x91,0xab,0x1c,0x3a,0xff, /* 1280x800-60 */
588 0x20,0x83,0x1f,0x1f,0x3b,0x10,0x00,0x07, 493 0x20,0x83,0x1f,0x1f,0x3b,0x10,0x00,0x07,
@@ -601,10 +506,58 @@ static const SiS_CRT1TableStruct SiS310_CRT1Table[]=
601 0x01}}, /* 0x53 */ 506 0x01}}, /* 0x53 */
602 {{0xcd,0x8f,0x8f,0x91,0x9b,0x1b,0x7a,0xff, /* 1152x864-60 */ 507 {{0xcd,0x8f,0x8f,0x91,0x9b,0x1b,0x7a,0xff, /* 1152x864-60 */
603 0x64,0x8c,0x5f,0x62,0x7b,0x10,0x00,0x07, 508 0x64,0x8c,0x5f,0x62,0x7b,0x10,0x00,0x07,
604 0x41}} /* 0x54 */ 509 0x41}}, /* 0x54 */
605}; 510 {{0x5c,0x4f,0x4f,0x80,0x57,0x80,0xa3,0x1f, /* fake 640x400@60Hz (for LCD and TV, not actually used) */
606 511 0x98,0x8c,0x8f,0x96,0xa4,0x30,0x00,0x05,
607static const SiS_MCLKDataStruct SiS310_MCLKData_0_315[] = 512 0x40}}, /* 0x55 */
513 {{0x2c,0x27,0x27,0x90,0x2d,0x92,0xa4,0x1f, /* fake 320x200@60Hz (for LCD and TV, not actually used) */
514 0x98,0x8c,0x8f,0x96,0xa5,0x30,0x00,0x04,
515 0x00}}, /* 0x56 */
516 {{0xd7,0xc7,0xc7,0x9b,0xd1,0x15,0xd1,0x10, /* 1600x1200 for LCDA */
517 0xb2,0x86,0xaf,0xb0,0xd2,0x2f,0x00,0x03,
518 0x00}}, /* 0x57 */
519 {{0xce,0x9f,0x9f,0x92,0xa9,0x17,0x28,0xdc, /* 1280x768 (1280x1024) 60 Hz */
520 0x92,0x86,0xff,0x91,0x29,0x21,0x00,0x07,
521 0x01}}, /* 0x58 */
522 {{0xce,0x9f,0x9f,0x92,0xa5,0x17,0x28,0xdc, /* 1280x768 (1280x1024) 75 Hz */
523 0x92,0x86,0xff,0x91,0x29,0x21,0x00,0x07,
524 0x01}}, /* 0x59 */
525 {{0xd3,0x9f,0x9f,0x97,0xab,0x1f,0x2e,0xdc, /* 1280x768 (1280x1024) 85 Hz */
526 0x95,0x89,0xff,0x94,0x2f,0x21,0x00,0x07,
527 0x01}}, /* 0x5a */
528 {{0xce,0x9f,0x9f,0x92,0xa9,0x17,0x28,0xde, /* 1280x800 (1280x1024) 60 Hz */
529 0xa2,0x86,0x1f,0xa1,0x29,0x01,0x00,0x07,
530 0x01}}, /* 0x5b */
531 {{0xce,0x9f,0x9f,0x92,0xa5,0x17,0x28,0xde, /* 1280x800 (1280x1024) 75 Hz */
532 0xa2,0x86,0x1f,0xa1,0x29,0x01,0x00,0x07,
533 0x01}}, /* 0x5c */
534 {{0xd3,0x9f,0x9f,0x97,0xab,0x1f,0x2e,0xde, /* 1280x800 (1280x1024) 85 Hz */
535 0xa5,0x89,0x1f,0xa4,0x2f,0x01,0x00,0x07,
536 0x01}}, /* 0x5d */
537 {{0x7f,0x63,0x63,0x83,0x6d,0x1d,0x0b,0x3e, /* 800x480 (wide) 60 Hz */
538 0xe9,0x8b,0xdf,0xe8,0x0c,0x00,0x00,0x06,
539 0x00}}, /* 0x5e */
540 {{0xa0,0x7f,0x7f,0x84,0x85,0x97,0x52,0xf0, /* 1024x576 (wide) 60 Hz */
541 0x41,0x85,0x3f,0x40,0x53,0x00,0x00,0x02,
542 0x01}}, /* 0x5f */
543 {{0xc9,0x9f,0x9f,0x8d,0xb0,0x15,0xec,0xf0, /* 1280x720 (wide) 60 Hz */
544 0xd4,0x89,0xcf,0xd3,0xed,0x20,0x00,0x07,
545 0x01}}, /* 0x60 */
546 {{0xcb,0x9f,0x9f,0x8f,0xa5,0x13,0x5b,0xff, /* 1280x854-60 wide */
547 0x56,0x89,0x55,0x55,0x5c,0x30,0x00,0x07,
548 0x01}}, /* 0x61 */
549 {{0xce,0x9f,0x9f,0x92,0xa9,0x17,0x28,0xde, /* 1280x854 (1280x1024) 60 Hz */
550 0xbd,0x81,0x55,0xbc,0x29,0x01,0x00,0x07,
551 0x41}}, /* 0x62 */
552 {{0xce,0x9f,0x9f,0x92,0xa5,0x17,0x28,0xde, /* 1280x854 (1280x1024) 75 Hz */
553 0xbd,0x81,0x55,0xbc,0x29,0x01,0x00,0x07,
554 0x41}}, /* 0x63 */
555 {{0xd3,0x9f,0x9f,0x97,0xab,0x1f,0x2e,0xde, /* 1280x854 (1280x1024) 85 Hz */
556 0xc0,0x84,0x55,0xbf,0x2f,0x01,0x00,0x07,
557 0x41}} /* 0x64 */
558};
559
560static const struct SiS_MCLKData SiS310_MCLKData_0_315[] =
608{ 561{
609 { 0x3b,0x22,0x01,143}, 562 { 0x3b,0x22,0x01,143},
610 { 0x5c,0x23,0x01,166}, 563 { 0x5c,0x23,0x01,166},
@@ -616,7 +569,7 @@ static const SiS_MCLKDataStruct SiS310_MCLKData_0_315[] =
616 { 0x5c,0x23,0x01,166} 569 { 0x5c,0x23,0x01,166}
617}; 570};
618 571
619static const SiS_MCLKDataStruct SiS310_MCLKData_0_650[] = 572static const struct SiS_MCLKData SiS310_MCLKData_0_650[] =
620{ 573{
621 { 0x5a,0x64,0x82, 66}, 574 { 0x5a,0x64,0x82, 66},
622 { 0xb3,0x45,0x82, 83}, 575 { 0xb3,0x45,0x82, 83},
@@ -628,7 +581,7 @@ static const SiS_MCLKDataStruct SiS310_MCLKData_0_650[] =
628 { 0x37,0x22,0x82,133} 581 { 0x37,0x22,0x82,133}
629}; 582};
630 583
631static const SiS_MCLKDataStruct SiS310_MCLKData_0_330[] = 584static const struct SiS_MCLKData SiS310_MCLKData_0_330[] =
632{ 585{
633 { 0x5c,0x23,0x01,166}, 586 { 0x5c,0x23,0x01,166},
634 { 0x5c,0x23,0x01,166}, 587 { 0x5c,0x23,0x01,166},
@@ -640,7 +593,7 @@ static const SiS_MCLKDataStruct SiS310_MCLKData_0_330[] =
640 { 0x79,0x06,0x01,250} 593 { 0x79,0x06,0x01,250}
641}; 594};
642 595
643static const SiS_MCLKDataStruct SiS310_MCLKData_0_660[] = 596static const struct SiS_MCLKData SiS310_MCLKData_0_660[] =
644{ 597{
645 { 0x5c,0x23,0x82,166}, 598 { 0x5c,0x23,0x82,166},
646 { 0x5c,0x23,0x82,166}, 599 { 0x5c,0x23,0x82,166},
@@ -652,7 +605,7 @@ static const SiS_MCLKDataStruct SiS310_MCLKData_0_660[] =
652 { 0x37,0x21,0x82,200} 605 { 0x37,0x21,0x82,200}
653}; 606};
654 607
655static const SiS_MCLKDataStruct SiS310_MCLKData_0_760[] = 608static const struct SiS_MCLKData SiS310_MCLKData_0_760[] =
656{ 609{
657 { 0x37,0x22,0x82,133}, 610 { 0x37,0x22,0x82,133},
658 { 0x5c,0x23,0x82,166}, 611 { 0x5c,0x23,0x82,166},
@@ -664,7 +617,7 @@ static const SiS_MCLKDataStruct SiS310_MCLKData_0_760[] =
664 { 0x37,0x21,0x82,200} 617 { 0x37,0x21,0x82,200}
665}; 618};
666 619
667static const SiS_MCLKDataStruct SiS310_MCLKData_0_761[] = 620static const struct SiS_MCLKData SiS310_MCLKData_0_761[] =
668{ 621{
669 { 0x37,0x22,0x82,133}, /* Preliminary */ 622 { 0x37,0x22,0x82,133}, /* Preliminary */
670 { 0x5c,0x23,0x82,166}, 623 { 0x5c,0x23,0x82,166},
@@ -676,7 +629,7 @@ static const SiS_MCLKDataStruct SiS310_MCLKData_0_761[] =
676 { 0x37,0x21,0x82,200} 629 { 0x37,0x21,0x82,200}
677}; 630};
678 631
679static const SiS_MCLKDataStruct SiS310_MCLKData_0_340[] = 632static const struct SiS_MCLKData SiS310_MCLKData_0_340[] =
680{ 633{
681 { 0x79,0x06,0x01,250}, 634 { 0x79,0x06,0x01,250},
682 { 0x7c,0x08,0x01,200}, 635 { 0x7c,0x08,0x01,200},
@@ -688,9 +641,9 @@ static const SiS_MCLKDataStruct SiS310_MCLKData_0_340[] =
688 { 0x29,0x01,0x81,300} 641 { 0x29,0x01,0x81,300}
689}; 642};
690 643
691static const SiS_MCLKDataStruct SiS310_MCLKData_1[] = /* ECLK */ 644static const struct SiS_MCLKData SiS310_MCLKData_1[] = /* ECLK */
692{ 645{
693 { 0x29,0x21,0x82,150}, 646 { 0x29,0x21,0x82,150},
694 { 0x5c,0x23,0x82,166}, 647 { 0x5c,0x23,0x82,166},
695 { 0x65,0x23,0x82,183}, 648 { 0x65,0x23,0x82,183},
696 { 0x37,0x21,0x82,200}, 649 { 0x37,0x21,0x82,200},
@@ -700,7 +653,7 @@ static const SiS_MCLKDataStruct SiS310_MCLKData_1[] = /* ECLK */
700 { 0x37,0x22,0x82,133} 653 { 0x37,0x22,0x82,133}
701}; 654};
702 655
703static const SiS_MCLKDataStruct SiS310_MCLKData_1_340[] = 656static const struct SiS_MCLKData SiS310_MCLKData_1_340[] =
704{ 657{
705 { 0x7c,0x08,0x01,200}, 658 { 0x7c,0x08,0x01,200},
706 { 0x7c,0x08,0x01,200}, 659 { 0x7c,0x08,0x01,200},
@@ -712,7 +665,7 @@ static const SiS_MCLKDataStruct SiS310_MCLKData_1_340[] =
712 { 0x29,0x01,0x81,300} 665 { 0x29,0x01,0x81,300}
713}; 666};
714 667
715static SiS_VCLKDataStruct SiS310_VCLKData[]= 668static struct SiS_VCLKData SiS310_VCLKData[] =
716{ 669{
717 { 0x1b,0xe1, 25}, /* 0x00 */ 670 { 0x1b,0xe1, 25}, /* 0x00 */
718 { 0x4e,0xe4, 28}, /* 0x01 */ 671 { 0x4e,0xe4, 28}, /* 0x01 */
@@ -805,7 +758,7 @@ static SiS_VCLKDataStruct SiS310_VCLKData[]=
805 { 0x30,0x23, 88}, /* 0x58 1360x768-62 (is 60Hz!) */ 758 { 0x30,0x23, 88}, /* 0x58 1360x768-62 (is 60Hz!) */
806 { 0x52,0x07,149}, /* 0x59 1280x960-85 */ 759 { 0x52,0x07,149}, /* 0x59 1280x960-85 */
807 { 0x56,0x07,156}, /* 0x5a 1400x1050-75 */ 760 { 0x56,0x07,156}, /* 0x5a 1400x1050-75 */
808 { 0x70,0x29, 81}, /* 0x5b 1280x768 LCD */ 761 { 0x70,0x29, 81}, /* 0x5b 1280x768 LCD */
809 { 0x45,0x25, 83}, /* 0x5c 1280x800 */ 762 { 0x45,0x25, 83}, /* 0x5c 1280x800 */
810 { 0x70,0x0a,147}, /* 0x5d 1680x1050 */ 763 { 0x70,0x0a,147}, /* 0x5d 1680x1050 */
811 { 0x70,0x24,162}, /* 0x5e 1600x1200 */ 764 { 0x70,0x24,162}, /* 0x5e 1600x1200 */
@@ -823,10 +776,19 @@ static SiS_VCLKDataStruct SiS310_VCLKData[]=
823 { 0x7c,0x6b, 38}, /* 0x6a 960x540@60 */ 776 { 0x7c,0x6b, 38}, /* 0x6a 960x540@60 */
824 { 0xe3,0x56, 41}, /* 0x6b 960x600@60 */ 777 { 0xe3,0x56, 41}, /* 0x6b 960x600@60 */
825 { 0x45,0x25, 83}, /* 0x6c 1280x800 */ 778 { 0x45,0x25, 83}, /* 0x6c 1280x800 */
826 { 0x70,0x28, 90} /* 0x6d 1152x864@60 */ 779 { 0x70,0x28, 90}, /* 0x6d 1152x864@60 */
780 { 0x15,0xe1, 20}, /* 0x6e 640x400@60 (fake, not actually used) */
781 { 0x5f,0xc6, 33}, /* 0x6f 720x576@60 */
782 { 0x37,0x5a, 10}, /* 0x70 320x200@60 (fake, not actually used) */
783 { 0x2b,0xc2, 35}, /* 0x71 768x576@60 */
784 { 0xa8,0x42,131}, /* 0x72 1600x1200@60 for LCDA */
785 { 0x1b,0xc1, 34}, /* 0x73 800x480 60Hz (wide) */
786 { 0x41,0x64, 48}, /* 0x74 1024x576 60Hz (wide) */
787 { 0x52,0x27, 75}, /* 0x75 1280x720 60Hz (wide) */
788 { 0x75,0x13, 84} /* 0x76 1280x854 60Hz (wide) */
827}; 789};
828 790
829static SiS_VBVCLKDataStruct SiS310_VBVCLKData[]= 791static struct SiS_VBVCLKData SiS310_VBVCLKData[] =
830{ 792{
831 { 0x1b,0xe1, 25}, /* 0x00 */ 793 { 0x1b,0xe1, 25}, /* 0x00 */
832 { 0x4e,0xe4, 28}, /* 0x01 */ 794 { 0x4e,0xe4, 28}, /* 0x01 */
@@ -858,12 +820,6 @@ static SiS_VBVCLKDataStruct SiS310_VBVCLKData[]=
858 { 0x5e,0x43,113}, /* 0x1b */ 820 { 0x5e,0x43,113}, /* 0x1b */
859 { 0xbc,0x44,116}, /* 0x1c */ 821 { 0xbc,0x44,116}, /* 0x1c */
860 { 0xe0,0x46,132}, /* 0x1d */ 822 { 0xe0,0x46,132}, /* 0x1d */
861#if 0
862 { 0xd4,0x28,135}, /* 0x1e */
863 { 0xea,0x2a,139}, /* 0x1f */
864 { 0x41,0x22,157}, /* 0x20 */
865 { 0x70,0x24,162}, /* 0x21 */
866#endif
867 { 0xe2,0x46,135}, /* 0x1e */ /* 1280x1024-75, better clock for VGA2 */ 823 { 0xe2,0x46,135}, /* 0x1e */ /* 1280x1024-75, better clock for VGA2 */
868 { 0xe5,0x46,139}, /* 0x1f */ /* 1024x768-120, better clock for VGA2 */ 824 { 0xe5,0x46,139}, /* 0x1f */ /* 1024x768-120, better clock for VGA2 */
869 { 0x15,0x01,157}, /* 0x20 */ /* 1280x1024-85, better clock for VGA2 */ 825 { 0x15,0x01,157}, /* 0x20 */ /* 1280x1024-85, better clock for VGA2 */
@@ -912,7 +868,7 @@ static SiS_VBVCLKDataStruct SiS310_VBVCLKData[]=
912 { 0x34,0x61, 95}, /* 0x4b UNUSED */ 868 { 0x34,0x61, 95}, /* 0x4b UNUSED */
913 { 0x78,0x27,108}, /* 0x4c UNUSED */ 869 { 0x78,0x27,108}, /* 0x4c UNUSED */
914 { 0x66,0x43,123}, /* 0x4d 1400x1050-60 */ 870 { 0x66,0x43,123}, /* 0x4d 1400x1050-60 */
915 { 0x41,0x4e, 21}, /* 0x4e UNUSED */ 871 { 0x41,0x4e, 21}, /* 0x4e */
916 { 0xa1,0x4a, 29}, /* 0x4f UNUSED */ 872 { 0xa1,0x4a, 29}, /* 0x4f UNUSED */
917 { 0x19,0x42, 42}, /* 0x50 UNUSED */ 873 { 0x19,0x42, 42}, /* 0x50 UNUSED */
918 { 0x54,0x46, 58}, /* 0x51 UNUSED */ 874 { 0x54,0x46, 58}, /* 0x51 UNUSED */
@@ -925,7 +881,7 @@ static SiS_VBVCLKDataStruct SiS310_VBVCLKData[]=
925 { 0x30,0x23, 88}, /* 0x58 1360x768-62 (is 60Hz!) TEMP, UNUSED */ 881 { 0x30,0x23, 88}, /* 0x58 1360x768-62 (is 60Hz!) TEMP, UNUSED */
926 { 0x52,0x07,149}, /* 0x59 1280x960-85 */ 882 { 0x52,0x07,149}, /* 0x59 1280x960-85 */
927 { 0x56,0x07,156}, /* 0x5a 1400x1050-75 */ 883 { 0x56,0x07,156}, /* 0x5a 1400x1050-75 */
928 { 0x70,0x29, 81}, /* 0x5b 1280x768 LCD (TMDS) */ 884 { 0x70,0x29, 81}, /* 0x5b 1280x768 LCD (TMDS) */
929 { 0xce,0x1e, 73}, /* 0x5c 1280x800_2 LCD (SiS LVDS) - (CRT1: 45 25 83) */ 885 { 0xce,0x1e, 73}, /* 0x5c 1280x800_2 LCD (SiS LVDS) - (CRT1: 45 25 83) */
930 { 0xbe,0x44,121}, /* 0x5d 1680x1050 LCD */ 886 { 0xbe,0x44,121}, /* 0x5d 1680x1050 LCD */
931 { 0x70,0x24,162}, /* 0x5e 1600x1200 LCD */ 887 { 0x70,0x24,162}, /* 0x5e 1600x1200 LCD */
@@ -943,57 +899,33 @@ static SiS_VBVCLKDataStruct SiS310_VBVCLKData[]=
943 { 0x7c,0x6b, 38}, /* 0x6a 960x540@60 */ 899 { 0x7c,0x6b, 38}, /* 0x6a 960x540@60 */
944 { 0xe3,0x56, 41}, /* 0x6b 960x600@60 */ 900 { 0xe3,0x56, 41}, /* 0x6b 960x600@60 */
945 { 0x9c,0x62, 69}, /* 0x6c 1280x800 (SiS TMDS) (special) */ 901 { 0x9c,0x62, 69}, /* 0x6c 1280x800 (SiS TMDS) (special) */
946 { 0x70,0x28, 90} /* 0x6d 1152x864@60 */ 902 { 0x70,0x28, 90}, /* 0x6d 1152x864@60 */
903 { 0x15,0xe1, 20}, /* 0x6e 640x400@60 (fake, not actually used) */
904 { 0x5f,0xc6, 33}, /* 0x6f 720x576@60 */
905 { 0x37,0x5a, 10}, /* 0x70 320x200@60 (fake, not actually used) */
906 { 0x2b,0xc2, 35}, /* 0x71 768@576@60 */
907 { 0xa8,0x42,131}, /* 0x72 1600x1200@60 for LCDA */
908 { 0x1b,0xc1, 34}, /* 0x73 800x480 60Hz (wide) */
909 { 0x41,0x64, 48}, /* 0x74 1024x576 60Hz (wide) */
910 { 0x52,0x27, 75}, /* 0x75 1280x720 60Hz (wide) */
911 { 0x75,0x13, 84} /* 0x76 1280x854 60Hz (SiS LVDS) LCD */
947}; 912};
948 913
949static const DRAM4Type SiS310_SR15[8] = { 914static const unsigned char SiS310_SR15[4 * 8] =
950 {0x00,0x04,0x60,0x60}, 915{
951 {0x0f,0x0f,0x0f,0x0f}, 916 0x00,0x04,0x60,0x60,
952 {0xba,0xba,0xba,0xba}, 917 0x0f,0x0f,0x0f,0x0f,
953 {0xa9,0xa9,0xac,0xac}, 918 0xba,0xba,0xba,0xba,
954 {0xa0,0xa0,0xa0,0xa8}, 919 0xa9,0xa9,0xac,0xac,
955 {0x00,0x00,0x02,0x02}, 920 0xa0,0xa0,0xa0,0xa8,
956 {0x30,0x30,0x40,0x40}, 921 0x00,0x00,0x02,0x02,
957 {0x00,0xa5,0xfb,0xf6} 922 0x30,0x30,0x40,0x40,
958}; 923 0x00,0xa5,0xfb,0xf6
959
960#ifdef LINUX_KERNEL
961
962static UCHAR SiS310_SR07 = 0x18;
963
964static const DRAM4Type SiS310_CR40[5] = {
965 {0x77,0x77,0x33,0x33},
966 {0x77,0x77,0x33,0x33},
967 {0x00,0x00,0x00,0x00},
968 {0x5b,0x5b,0x03,0x03},
969 {0x00,0x00,0xf0,0xf8}
970}; 924};
971 925
972static UCHAR SiS310_CR49[] = {0xaa,0x88}; 926static const struct SiS_PanelDelayTbl SiS310_PanelDelayTbl[] =
973static UCHAR SiS310_SR1F = 0x00;
974static UCHAR SiS310_SR21 = 0xa5;
975static UCHAR SiS310_SR22 = 0xfb;
976static UCHAR SiS310_SR23 = 0xf6;
977static UCHAR SiS310_SR24 = 0x0d;
978static UCHAR SiS310_SR25[] = {0x33,0x3};
979static UCHAR SiS310_SR31 = 0x00;
980static UCHAR SiS310_SR32 = 0x11;
981static UCHAR SiS310_SR33 = 0x00;
982static UCHAR SiS310_CRT2Data_1_2 = 0x00;
983static UCHAR SiS310_CRT2Data_4_D = 0x00;
984static UCHAR SiS310_CRT2Data_4_E = 0x00;
985static UCHAR SiS310_CRT2Data_4_10 = 0x80;
986static const USHORT SiS310_RGBSenseData = 0xd1;
987static const USHORT SiS310_VideoSenseData = 0xb9;
988static const USHORT SiS310_YCSenseData = 0xb3;
989static const USHORT SiS310_RGBSenseData2 = 0x0190;
990static const USHORT SiS310_VideoSenseData2 = 0x0174;
991static const USHORT SiS310_YCSenseData2 = 0x016b;
992#endif
993
994static const SiS_PanelDelayTblStruct SiS310_PanelDelayTbl[]=
995{ 927{
996 {{0x10,0x40}}, 928 {{0x10,0x40}},
997 {{0x10,0x40}}, 929 {{0x10,0x40}},
998 {{0x10,0x40}}, 930 {{0x10,0x40}},
999 {{0x10,0x40}}, 931 {{0x10,0x40}},
@@ -1011,7 +943,7 @@ static const SiS_PanelDelayTblStruct SiS310_PanelDelayTbl[]=
1011 {{0x10,0x40}} 943 {{0x10,0x40}}
1012}; 944};
1013 945
1014static const SiS_PanelDelayTblStruct SiS310_PanelDelayTblLVDS[]= 946static const struct SiS_PanelDelayTbl SiS310_PanelDelayTblLVDS[] =
1015{ 947{
1016 {{0x28,0xc8}}, 948 {{0x28,0xc8}},
1017 {{0x28,0xc8}}, 949 {{0x28,0xc8}},
@@ -1035,18 +967,18 @@ static const SiS_PanelDelayTblStruct SiS310_PanelDelayTblLVDS[]=
1035/* SIS VIDEO BRIDGE ----------------------------------------- */ 967/* SIS VIDEO BRIDGE ----------------------------------------- */
1036/**************************************************************/ 968/**************************************************************/
1037 969
1038static const SiS_LCDDataStruct SiS310_St2LCD1024x768Data[] = 970static const struct SiS_LCDData SiS310_St2LCD1024x768Data[] =
1039{ 971{
1040 { 62, 25, 800, 546,1344, 806}, 972 { 62, 25, 800, 546,1344, 806},
1041 { 32, 15, 930, 546,1344, 806}, 973 { 32, 15, 930, 546,1344, 806},
1042 { 62, 25, 800, 546,1344, 806}, 974 { 62, 25, 800, 546,1344, 806},
1043 { 104, 45, 945, 496,1344, 806}, 975 { 104, 45, 945, 496,1344, 806},
1044 { 62, 25, 800, 546,1344, 806}, 976 { 62, 25, 800, 546,1344, 806},
1045 { 31, 18,1008, 624,1344, 806}, 977 { 31, 18,1008, 624,1344, 806},
1046 { 1, 1,1344, 806,1344, 806} 978 { 1, 1,1344, 806,1344, 806}
1047}; 979};
1048 980
1049static const SiS_LCDDataStruct SiS310_ExtLCD1024x768Data[] = 981static const struct SiS_LCDData SiS310_ExtLCD1024x768Data[] =
1050{ 982{
1051 { 42, 25,1536, 419,1344, 806}, 983 { 42, 25,1536, 419,1344, 806},
1052 { 48, 25,1536, 369,1344, 806}, 984 { 48, 25,1536, 369,1344, 806},
@@ -1057,7 +989,7 @@ static const SiS_LCDDataStruct SiS310_ExtLCD1024x768Data[] =
1057 { 1, 1,1344, 806,1344, 806} 989 { 1, 1,1344, 806,1344, 806}
1058}; 990};
1059 991
1060static const SiS_LCDDataStruct SiS310_St2LCD1280x1024Data[] = 992static const struct SiS_LCDData SiS310_St2LCD1280x1024Data[] =
1061{ 993{
1062 { 22, 5, 800, 510,1650,1088}, 994 { 22, 5, 800, 510,1650,1088},
1063 { 22, 5, 800, 510,1650,1088}, 995 { 22, 5, 800, 510,1650,1088},
@@ -1069,7 +1001,7 @@ static const SiS_LCDDataStruct SiS310_St2LCD1280x1024Data[] =
1069 { 1, 1,1688,1066,1688,1066} 1001 { 1, 1,1688,1066,1688,1066}
1070}; 1002};
1071 1003
1072static const SiS_LCDDataStruct SiS310_ExtLCD1280x1024Data[] = 1004static const struct SiS_LCDData SiS310_ExtLCD1280x1024Data[] =
1073{ 1005{
1074 { 211, 60,1024, 501,1688,1066}, 1006 { 211, 60,1024, 501,1688,1066},
1075 { 211, 60,1024, 508,1688,1066}, 1007 { 211, 60,1024, 508,1688,1066},
@@ -1081,45 +1013,22 @@ static const SiS_LCDDataStruct SiS310_ExtLCD1280x1024Data[] =
1081 { 1, 1,1688,1066,1688,1066} 1013 { 1, 1,1688,1066,1688,1066}
1082}; 1014};
1083 1015
1084static const SiS_Part2PortTblStruct SiS310_CRT2Part2_1024x768_1[] = 1016static const struct SiS_Part2PortTbl SiS310_CRT2Part2_1024x768_1[] =
1085{ 1017{
1086 {{0x25,0x12,0xc9,0xdc,0xb6,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}}, 1018 {{0x25,0x12,0xc9,0xdc,0xb6,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}},
1087 {{0x2c,0x12,0x9a,0xae,0x88,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}}, 1019 {{0x2c,0x12,0x9a,0xae,0x88,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}},
1088 {{0x25,0x12,0xc9,0xdc,0xb6,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}}, 1020 {{0x25,0x12,0xc9,0xdc,0xb6,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}},
1089 {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, 1021 {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
1090 {{0x38,0x13,0x16,0x0c,0xe6,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}}, 1022 {{0x38,0x13,0x16,0x0c,0xe6,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}},
1091 {{0x38,0x18,0x16,0x00,0x00,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}}, 1023 {{0x38,0x18,0x16,0x00,0x00,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}},
1092 {{0x36,0x13,0x13,0x25,0xff,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}} 1024 {{0x36,0x13,0x13,0x25,0xff,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}}
1093}; 1025};
1094 1026
1095/* *** LCDA *** */
1096
1097#if 0
1098static const SiS_LVDSDataStruct SiS_LCDA1600x1200Data_1[]=
1099{ /* Clevo, 651+301C */
1100 {1200, 450, 2048,1250},
1101 {1200, 400, 2048,1250},
1102 {1280, 450, 2048,1250},
1103 {1280, 400, 2048,1250},
1104 {1200, 530, 2048,1250},
1105 {1360, 650, 2048,1250},
1106 {1584, 818, 2048,1250},
1107 {1688,1066, 2048,1250},
1108 {1688,1066, 2048,1250},
1109#if 0
1110 {2048,1250, 2048,1250} /* this should be correct */
1111#endif
1112#if 1
1113 {2160,1250, 2048,1250} /* ? */
1114#endif
1115};
1116#endif
1117
1118/**************************************************************/ 1027/**************************************************************/
1119/* LVDS, CHRONTEL ------------------------------------------- */ 1028/* LVDS, CHRONTEL ------------------------------------------- */
1120/**************************************************************/ 1029/**************************************************************/
1121 1030
1122static const SiS_LVDSDataStruct SiS310_CHTVUPALData[]= 1031static const struct SiS_LVDSData SiS310_CHTVUPALData[] =
1123{ 1032{
1124 {1008, 625,1008, 625}, 1033 {1008, 625,1008, 625},
1125 {1008, 625,1008, 625}, 1034 {1008, 625,1008, 625},
@@ -1130,7 +1039,7 @@ static const SiS_LVDSDataStruct SiS310_CHTVUPALData[]=
1130 {1400,1000,1400,1000} 1039 {1400,1000,1400,1000}
1131}; 1040};
1132 1041
1133static const SiS_LVDSDataStruct SiS310_CHTVOPALData[]= 1042static const struct SiS_LVDSData SiS310_CHTVOPALData[] =
1134{ 1043{
1135 {1008, 625,1008, 625}, 1044 {1008, 625,1008, 625},
1136 {1008, 625,1008, 625}, 1045 {1008, 625,1008, 625},
@@ -1138,10 +1047,10 @@ static const SiS_LVDSDataStruct SiS310_CHTVOPALData[]=
1138 {1008, 625,1008, 625}, 1047 {1008, 625,1008, 625},
1139 { 840, 625, 840, 625}, 1048 { 840, 625, 840, 625},
1140 { 944, 625, 944, 625}, 1049 { 944, 625, 944, 625},
1141 {1400, 875,1400, 875} 1050 {1400, 875,1400, 875}
1142}; 1051};
1143 1052
1144static const SiS_LVDSDataStruct SiS310_CHTVUPALMData[]= 1053static const struct SiS_LVDSData SiS310_CHTVUPALMData[] =
1145{ 1054{
1146 { 840, 600, 840, 600}, 1055 { 840, 600, 840, 600},
1147 { 840, 600, 840, 600}, 1056 { 840, 600, 840, 600},
@@ -1149,10 +1058,10 @@ static const SiS_LVDSDataStruct SiS310_CHTVUPALMData[]=
1149 { 840, 600, 840, 600}, 1058 { 840, 600, 840, 600},
1150 { 784, 600, 784, 600}, 1059 { 784, 600, 784, 600},
1151 {1064, 750,1064, 750}, 1060 {1064, 750,1064, 750},
1152 {1160, 945,1160, 945} 1061 {1160, 945,1160, 945}
1153}; 1062};
1154 1063
1155static const SiS_LVDSDataStruct SiS310_CHTVOPALMData[]= 1064static const struct SiS_LVDSData SiS310_CHTVOPALMData[] =
1156{ 1065{
1157 { 840, 525, 840, 525}, 1066 { 840, 525, 840, 525},
1158 { 840, 525, 840, 525}, 1067 { 840, 525, 840, 525},
@@ -1160,10 +1069,10 @@ static const SiS_LVDSDataStruct SiS310_CHTVOPALMData[]=
1160 { 840, 525, 840, 525}, 1069 { 840, 525, 840, 525},
1161 { 784, 525, 784, 525}, 1070 { 784, 525, 784, 525},
1162 {1040, 700,1040, 700}, 1071 {1040, 700,1040, 700},
1163 {1160, 840,1160, 840} 1072 {1160, 840,1160, 840}
1164}; 1073};
1165 1074
1166static const SiS_LVDSDataStruct SiS310_CHTVUPALNData[]= 1075static const struct SiS_LVDSData SiS310_CHTVUPALNData[] =
1167{ 1076{
1168 {1008, 625,1008, 625}, 1077 {1008, 625,1008, 625},
1169 {1008, 625,1008, 625}, 1078 {1008, 625,1008, 625},
@@ -1174,7 +1083,7 @@ static const SiS_LVDSDataStruct SiS310_CHTVUPALNData[]=
1174 {1400,1000,1400,1000} 1083 {1400,1000,1400,1000}
1175}; 1084};
1176 1085
1177static const SiS_LVDSDataStruct SiS310_CHTVOPALNData[]= 1086static const struct SiS_LVDSData SiS310_CHTVOPALNData[] =
1178{ 1087{
1179 {1008, 625,1008, 625}, 1088 {1008, 625,1008, 625},
1180 {1008, 625,1008, 625}, 1089 {1008, 625,1008, 625},
@@ -1182,10 +1091,10 @@ static const SiS_LVDSDataStruct SiS310_CHTVOPALNData[]=
1182 {1008, 625,1008, 625}, 1091 {1008, 625,1008, 625},
1183 { 840, 625, 840, 625}, 1092 { 840, 625, 840, 625},
1184 { 944, 625, 944, 625}, 1093 { 944, 625, 944, 625},
1185 {1400, 875,1400, 875} 1094 {1400, 875,1400, 875}
1186}; 1095};
1187 1096
1188static const SiS_LVDSDataStruct SiS310_CHTVSOPALData[]= /* (super overscan - no effect on 7019) */ 1097static const struct SiS_LVDSData SiS310_CHTVSOPALData[] = /* (super overscan - no effect on 7019) */
1189{ 1098{
1190 {1008, 625,1008, 625}, 1099 {1008, 625,1008, 625},
1191 {1008, 625,1008, 625}, 1100 {1008, 625,1008, 625},
@@ -1196,1333 +1105,10 @@ static const SiS_LVDSDataStruct SiS310_CHTVSOPALData[]= /* (super overscan -
1196 {1400, 875,1400, 875} 1105 {1400, 875,1400, 875}
1197}; 1106};
1198 1107
1199
1200static const SiS_LVDSDesStruct SiS310_PanelType00_1[]= /* 800x600 */
1201{
1202 { 0, 0},
1203 { 0, 0},
1204 { 0, 0},
1205 { 0, 0},
1206 { 0, 0},
1207 { 0, 0},
1208 { 0, 0},
1209 { 0, 0},
1210 { 0, 0}
1211};
1212
1213static const SiS_LVDSDesStruct SiS310_PanelType01_1[]= /* 1024x768 */
1214{
1215 { 0, 0},
1216 { 0, 0},
1217 { 0, 0},
1218 { 0, 0},
1219 { 0, 0},
1220 { 0, 0},
1221 { 0, 805},
1222 { 0, 0},
1223 { 0, 0}
1224};
1225
1226static const SiS_LVDSDesStruct SiS310_PanelType02_1[]= /* 1280x1024 */
1227{
1228 { 0, 0},
1229 { 0, 0},
1230 { 0, 0},
1231 { 0, 0},
1232 { 0, 0},
1233 { 0, 0},
1234 { 0, 0},
1235 { 0, 1065},
1236 { 0, 0},
1237 { 0, 0}
1238};
1239
1240
1241static const SiS_LVDSDesStruct SiS310_PanelType03_1[]=
1242{
1243 { 0, 0},
1244 { 0, 0},
1245 { 0, 0},
1246 { 0, 0},
1247 { 0, 0},
1248 { 0, 0},
1249 { 0, 0},
1250 { 0, 0},
1251 { 0, 0}
1252};
1253
1254static const SiS_LVDSDesStruct SiS310_PanelType04_1[]=
1255{
1256 {1343, 798},
1257 {1343, 794},
1258 {1343, 798},
1259 {1343, 794},
1260 {1343, 0},
1261 {1343, 0},
1262 { 0, 805},
1263 { 0, 794},
1264 { 0, 0}
1265};
1266
1267static const SiS_LVDSDesStruct SiS310_PanelType05_1[]=
1268{
1269 {1343, 798},
1270 {1343, 794},
1271 {1343, 798},
1272 {1343, 794},
1273 {1343, 0},
1274 {1343, 0},
1275 { 0, 805},
1276 { 0, 794},
1277 { 0, 0}
1278};
1279
1280static const SiS_LVDSDesStruct SiS310_PanelType06_1[]=
1281{
1282 {1343, 798},
1283 {1343, 794},
1284 {1343, 798},
1285 {1343, 794},
1286 {1343, 0},
1287 {1343, 0},
1288 { 0, 805},
1289 { 0, 794},
1290 { 0, 0}
1291};
1292
1293static const SiS_LVDSDesStruct SiS310_PanelType07_1[]=
1294{
1295 {1343, 798},
1296 {1343, 794},
1297 {1343, 798},
1298 {1343, 794},
1299 {1343, 0},
1300 {1343, 0},
1301 { 0, 805},
1302 { 0, 794},
1303 { 0, 0}
1304};
1305
1306static const SiS_LVDSDesStruct SiS310_PanelType08_1[]= /* 1400x1050 */
1307{
1308 { 0, 0},
1309 { 0, 0},
1310 { 0, 0},
1311 { 0, 0},
1312 { 0, 0},
1313 { 0, 0},
1314 { 0, 0},
1315 { 0, 0},
1316 { 0, 0},
1317 { 0, 0},
1318 { 0, 0}
1319};
1320
1321static const SiS_LVDSDesStruct SiS310_PanelType09_1[]= /* 1280x768 */
1322{
1323 { 0, 0},
1324 { 0, 0},
1325 { 0, 0},
1326 { 0, 0},
1327 { 0, 0},
1328 { 0, 0},
1329 { 0, 0},
1330 { 0, 0},
1331 { 0, 0},
1332 { 0, 0},
1333 { 0, 0}
1334};
1335
1336static const SiS_LVDSDesStruct SiS310_PanelType0a_1[]= /* 1600x1200 */
1337{
1338 { 0, 0},
1339 { 0, 0},
1340 { 0, 0},
1341 { 0, 0},
1342 { 0, 0},
1343 { 0, 0},
1344 { 0, 0},
1345 { 0, 0},
1346 { 0, 0},
1347 { 0, 0},
1348 { 0, 0}
1349};
1350
1351static const SiS_LVDSDesStruct SiS310_PanelType0b_1[]= /* 640x480_2 */
1352{
1353 { 0, 524},
1354 { 0, 524},
1355 { 0, 524},
1356 { 0, 524},
1357 { 0, 524},
1358 { 0, 524},
1359 { 8, 524},
1360 { 0, 524}
1361};
1362
1363static const SiS_LVDSDesStruct SiS310_PanelType0c_1[]= /* 640x480_3 */
1364{
1365 { 0, 524},
1366 { 0, 524},
1367 { 0, 524},
1368 { 0, 524},
1369 { 0, 524},
1370 { 0, 524},
1371 { 8, 524},
1372 { 0, 524}
1373};
1374
1375static const SiS_LVDSDesStruct SiS310_PanelType0d_1[]=
1376{
1377 {1343, 798},
1378 {1343, 794},
1379 {1343, 798},
1380 {1343, 794},
1381 {1343, 0},
1382 {1343, 0},
1383 { 0, 805},
1384 { 0, 794},
1385 { 0, 0}
1386};
1387
1388static const SiS_LVDSDesStruct SiS310_PanelType0e_1[]=
1389{
1390 {1343, 798},
1391 {1343, 794},
1392 {1343, 798},
1393 {1343, 794},
1394 {1343, 0},
1395 {1343, 0},
1396 { 0, 805},
1397 { 0, 794},
1398 { 0, 0}
1399};
1400
1401static const SiS_LVDSDesStruct SiS310_PanelType0f_1[]=
1402{
1403 {1343, 798},
1404 {1343, 794},
1405 {1343, 798},
1406 {1343, 794},
1407 {1343, 0},
1408 {1343, 0},
1409 { 0, 805},
1410 { 0, 794},
1411 { 0, 0}
1412};
1413
1414static const SiS_LVDSDesStruct SiS310_PanelType00_2[]=
1415{
1416 {980, 528},
1417 {980, 503},
1418 {980, 528},
1419 {980, 503},
1420 {980, 568},
1421 { 0, 628},
1422 { 0, 0},
1423 { 0, 0},
1424 { 0, 0}
1425};
1426
1427static const SiS_LVDSDesStruct SiS310_PanelType01_2[]=
1428{
1429 {1152, 622},
1430 {1152, 597},
1431 {1152, 622},
1432 {1152, 597},
1433 {1152, 662},
1434 {1232, 722},
1435 { 0, 806},
1436 { 0, 0},
1437 { 0, 0}
1438};
1439
1440static const SiS_LVDSDesStruct SiS310_PanelType02_2[]=
1441{
1442 {1368, 754},
1443 {1368, 729},
1444 {1368, 754},
1445 {1368, 729},
1446 {1368, 794},
1447 {1448, 854},
1448 {1560, 938},
1449 { 0,1066},
1450 { 0, 0},
1451 { 0, 0},
1452 { 0, 0}
1453};
1454
1455static const SiS_LVDSDesStruct SiS310_PanelType03_2[]=
1456{
1457 { 0, 0},
1458 { 0, 0},
1459 { 0, 0},
1460 { 0, 0},
1461 { 0, 0},
1462 { 0, 0},
1463 { 0, 0}
1464};
1465
1466static const SiS_LVDSDesStruct SiS310_PanelType04_2[]=
1467{
1468 { 0, 0},
1469 { 0, 0},
1470 { 0, 0},
1471 { 0, 0},
1472 { 0, 0},
1473 { 0, 0},
1474 { 0, 0},
1475 { 0, 0},
1476 { 0, 0}
1477};
1478
1479static const SiS_LVDSDesStruct SiS310_PanelType05_2[]=
1480{
1481 {1152, 622},
1482 {1152, 597},
1483 {1152, 622},
1484 {1152, 597},
1485 {1152, 662},
1486 {1232, 722},
1487 { 0, 805},
1488 { 0, 794},
1489 { 0, 0}
1490};
1491
1492static const SiS_LVDSDesStruct SiS310_PanelType06_2[]=
1493{
1494 {1152, 622},
1495 {1152, 597},
1496 {1152, 622},
1497 {1152, 597},
1498 {1152, 662},
1499 {1232, 722},
1500 { 0, 805},
1501 { 0, 794},
1502 { 0, 0}
1503};
1504
1505static const SiS_LVDSDesStruct SiS310_PanelType07_2[]=
1506{
1507 {1152, 622},
1508 {1152, 597},
1509 {1152, 622},
1510 {1152, 597},
1511 {1152, 662},
1512 {1232, 722},
1513 { 0, 805},
1514 { 0, 794},
1515 { 0, 0}
1516};
1517
1518static const SiS_LVDSDesStruct SiS310_PanelType08_2[]= /* 1400x1050 */
1519{
1520 {1308, 741},
1521 {1308, 716},
1522 {1308, 741},
1523 {1308, 716},
1524 {1308, 781},
1525 {1388, 841},
1526 {1500, 925},
1527 {1628,1053},
1528 { 0,1065},
1529 { 0, 0},
1530 { 0, 0}
1531};
1532
1533static const SiS_LVDSDesStruct SiS310_PanelType09_2[]= /* 1280x768 */
1534{
1535 {1083, 622},
1536 {1083, 597},
1537 {1083, 622},
1538 {1083, 597},
1539 {1083, 662},
1540 {1163, 722},
1541 {1286, 805},
1542 { 0, 794},
1543 { 0, 0}
1544};
1545
1546static const SiS_LVDSDesStruct SiS310_PanelType0a_2[]= /* 1600x1200 */
1547{
1548 {1568, 920},
1549 {1568, 895},
1550 {1568, 920},
1551 {1568, 895},
1552 {1568, 960},
1553 {1648,1020},
1554 {1760,1104},
1555 {1888,1232},
1556 {1948,1245},
1557 { 0, 0}
1558#if 0
1559 {1568, 850},
1560 {1568, 825},
1561 {1568, 850},
1562 {1568, 825},
1563 {1568, 890},
1564 {1648, 950},
1565 {1760,1034},
1566 {1888,1162},
1567 {1948,1175},
1568 { 0, 0}
1569#endif
1570};
1571
1572static const SiS_LVDSDesStruct SiS310_PanelType0b_2[]= /* 640x480_2 */
1573{
1574 {1152, 622},
1575 {1152, 597},
1576 {1152, 622},
1577 {1152, 597},
1578 {1152, 662},
1579 {1232, 722},
1580 { 0, 805},
1581 { 0, 794},
1582 { 0, 0}
1583};
1584
1585static const SiS_LVDSDesStruct SiS310_PanelType0c_2[]= /* 640x480_3 */
1586{
1587 {1152, 622},
1588 {1152, 597},
1589 {1152, 622},
1590 {1152, 597},
1591 {1152, 662},
1592 {1232, 722},
1593 { 0, 805},
1594 { 0, 794},
1595 { 0, 0}
1596};
1597
1598static const SiS_LVDSDesStruct SiS310_PanelType0d_2[]=
1599{
1600 {1152, 622},
1601 {1152, 597},
1602 {1152, 622},
1603 {1152, 597},
1604 {1152, 662},
1605 {1232, 722},
1606 { 0, 805},
1607 { 0, 794},
1608 { 0, 0}
1609};
1610
1611static const SiS_LVDSDesStruct SiS310_PanelType0e_2[]=
1612{
1613 {1152, 622},
1614 {1152, 597},
1615 {1152, 622},
1616 {1152, 597},
1617 {1152, 662},
1618 {1232, 722},
1619 { 0, 805},
1620 { 0, 794},
1621 { 0, 0}
1622};
1623
1624static const SiS_LVDSDesStruct SiS310_PanelType0f_2[] =
1625{
1626 {1152, 622},
1627 {1152, 597},
1628 {1152, 622},
1629 {1152, 597},
1630 {1152, 662},
1631 {1232, 722},
1632 { 0, 805},
1633 { 0, 794},
1634 { 0, 0}
1635};
1636
1637static const SiS_LVDSDesStruct SiS310_PanelTypeNS_1[]=
1638{
1639 { 8, 0},
1640 { 8, 0},
1641 { 8, 0},
1642 { 8, 0},
1643 { 8, 0},
1644 { 0, 0},
1645 { 0, 0},
1646 { 0, 0},
1647 { 0, 806},
1648 { 0, 0}
1649};
1650
1651static const SiS_LVDSDesStruct SiS310_PanelTypeNS_2[] =
1652{
1653 { 0 , 0},
1654 { 0 , 0},
1655 { 0 , 0},
1656 { 0 , 0},
1657 { 0 , 0},
1658 { 0 , 0},
1659 { 0 , 0},
1660 { 0 , 0},
1661 { 0 , 0},
1662 { 0 , 0}
1663};
1664
1665/* CRT1 CRTC for SlaveModes and LCDA */
1666
1667static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT1800x600_1[] =
1668{
1669 {{0x6b,0x4f,0x8f,0x55,0x85,0xaa,0x1f,
1670 0x90,0x85,0x8f,0xab,0x30,0x00,0x05,
1671 0x00 }},
1672 {{0x6b,0x4f,0x8f,0x55,0x85,0x78,0x1f,
1673 0x5e,0x83,0x5d,0x79,0x10,0x00,0x05,
1674 0x00 }},
1675 {{0x6b,0x4f,0x8f,0x55,0x85,0xaa,0x1f,
1676 0x90,0x85,0x8f,0xab,0x30,0x00,0x05,
1677 0x00 }},
1678 {{0x6b,0x4f,0x8f,0x55,0x85,0x78,0x1f,
1679 0x5e,0x83,0x5d,0x79,0x10,0x00,0x05,
1680 0x00 }},
1681 {{0x6b,0x4f,0x8f,0x55,0x85,0xfa,0x1f,
1682 0xe0,0x85,0xdf,0xfb,0x10,0x00,0x05,
1683 0x00 }},
1684 {{0x7f,0x63,0x83,0x69,0x19,0x72,0xf0,
1685 0x58,0x8c,0x57,0x73,0x20,0x00,0x06,
1686 0x01 }}
1687};
1688
1689static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT1800x600_1_H[] =
1690{
1691 {{0x43,0x27,0x87,0x2d,0x1d,0xaa,0x1f,
1692 0x90,0x85,0x8f,0xab,0x30,0x00,0x05,
1693 0x00 }},
1694 {{0x43,0x27,0x87,0x2d,0x1d,0x78,0x1f,
1695 0x5e,0x83,0x5d,0x79,0x10,0x00,0x05,
1696 0x00 }},
1697 {{0x43,0x27,0x87,0x2d,0x1d,0xfa,0x1f,
1698 0xe0,0x85,0xdf,0xfb,0x10,0x00,0x05,
1699 0x00 }},
1700 {{0x43,0x27,0x87,0x2d,0x1d,0x78,0x1f,
1701 0x5e,0x83,0x5d,0x79,0x10,0x00,0x05,
1702 0x00 }},
1703 {{0x43,0x27,0x87,0x2d,0x1d,0xfa,0x1f,
1704 0xe0,0x85,0xdf,0xfb,0x10,0x00,0x05,
1705 0x00 }},
1706 {{0x4d,0x31,0x91,0x37,0x07,0x72,0xf0,
1707 0x58,0x8d,0x57,0x73,0x20,0x00,0x01,
1708 0x01 }}
1709};
1710
1711static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT1800x600_2[]=
1712{
1713 {{0x7f,0x4f,0x83,0x62,0x12,0x72,0x3e,
1714 0xff,0x84,0x8f,0x73,0x00,0x00,0x06,
1715 0x00 }},
1716 {{0x7f,0x4f,0x83,0x62,0x12,0x72,0x3e,
1717 0xe6,0x8b,0x5d,0x73,0x00,0x00,0x06,
1718 0x00 }},
1719 {{0x7f,0x4f,0x83,0x62,0x12,0x72,0x3e,
1720 0xff,0x84,0x8f,0x73,0x00,0x00,0x06,
1721 0x00 }},
1722 {{0x7f,0x4f,0x83,0x62,0x12,0x72,0x3e,
1723 0xe6,0x8b,0x5d,0x73,0x00,0x00,0x06,
1724 0x00 }},
1725 {{0x7f,0x4f,0x83,0x62,0x12,0x72,0xba,
1726 0x27,0x8c,0xdf,0x73,0x00,0x00,0x06,
1727 0x00 }},
1728 {{0x7f,0x63,0x83,0x69,0x19,0x72,0xf0,
1729 0x58,0x8d,0x57,0x73,0x20,0x00,0x06,
1730 0x01 }}
1731};
1732
1733static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT1800x600_2_H[] =
1734{
1735 {{0x57,0x27,0x9b,0x3a,0x0a,0x72,0x3e,
1736 0xff,0x84,0x8f,0x73,0x00,0x00,0x01,
1737 0x00 }},
1738 {{0x57,0x27,0x9b,0x3a,0x0a,0x72,0x3e,
1739 0xd6,0x8b,0x5d,0x73,0x00,0x00,0x01,
1740 0x00 }},
1741 {{0x57,0x27,0x9b,0x3a,0x0a,0x72,0x3e,
1742 0xff,0x84,0x8f,0x73,0x00,0x00,0x01,
1743 0x00 }},
1744 {{0x57,0x27,0x9b,0x3a,0x0a,0x72,0x3e,
1745 0xd6,0x8b,0x5d,0x73,0x00,0x00,0x01,
1746 0x00 }},
1747 {{0x57,0x27,0x9b,0x3a,0x0a,0x72,0xba,
1748 0x27,0x8c,0xdf,0x73,0x00,0x00,0x01,
1749 0x00 }},
1750 {{0x4d,0x31,0x91,0x3a,0x0a,0x72,0xf0,
1751 0x63,0x88,0x57,0x73,0x00,0x00,0x01,
1752 0x01 }}
1753};
1754
1755static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT11024x768_1[] =
1756{
1757 {{0x73,0x4f,0x97,0x53,0x84,0xb4,0x1f,
1758 0x92,0x89,0x8f,0xb5,0x30,0x00,0x05,
1759 0x00}},
1760 {{0x73,0x4f,0x97,0x53,0x84,0x82,0x1f,
1761 0x60,0x87,0x5d,0x83,0x10,0x00,0x05,
1762 0x00}},
1763 {{0x73,0x4f,0x97,0x53,0x84,0xb4,0x1f,
1764 0x92,0x89,0x8f,0xb5,0x30,0x00,0x05,
1765 0x00}},
1766 {{0x73,0x4f,0x97,0x53,0x84,0x82,0x1f,
1767 0x60,0x87,0x5d,0x83,0x10,0x00,0x05,
1768 0x00}},
1769 {{0x73,0x4f,0x97,0x53,0x84,0x04,0x3e,
1770 0xE2,0x89,0xDf,0x05,0x00,0x00,0x05,
1771 0x00}},
1772 {{0x87,0x63,0x8B,0x67,0x18,0x7c,0xf0,
1773 0x5A,0x81,0x57,0x7D,0x00,0x00,0x06,
1774 0x01}},
1775 {{0xA3,0x7f,0x87,0x83,0x94,0x24,0xf5,
1776 0x02,0x89,0xFf,0x25,0x10,0x00,0x02,
1777 0x01}}
1778};
1779
1780static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT11024x768_1_H[] =
1781{
1782 {{0x4b,0x27,0x8f,0x2b,0x1c,0xb4,0x1f,
1783 0x92,0x89,0x8f,0xb5,0x30,0x00,0x05,
1784 0x00 }},
1785 {{0x4b,0x27,0x8f,0x2b,0x1c,0x82,0x1f,
1786 0x60,0x87,0x5D,0x83,0x01,0x00,0x05,
1787 0x00}},
1788 {{0x4b,0x27,0x8f,0x2b,0x1c,0xb4,0x1f,
1789 0x92,0x89,0x8f,0xb5,0x30,0x00,0x05,
1790 0x00}},
1791 {{0x4b,0x27,0x8f,0x2b,0x1c,0x82,0x1f,
1792 0x60,0x87,0x5D,0x83,0x01,0x00,0x05,
1793 0x00}},
1794 {{0x4b,0x27,0x8f,0x2b,0x1c,0x04,0x3e,
1795 0xE2,0x89,0xDf,0x05,0x00,0x00,0x05,
1796 0x00}},
1797 {{0x55,0x31,0x99,0x35,0x06,0x7c,0xf0,
1798 0x5A,0x81,0x57,0x7D,0x00,0x00,0x01,
1799 0x01}},
1800 {{0x63,0x3F,0x87,0x43,0x94,0x24,0xf5,
1801 0x02,0x89,0xFf,0x25,0x10,0x00,0x01,
1802 0x01 }}
1803};
1804
1805static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT11024x768_2[] =
1806{
1807 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1808 0x57,0x8e,0x8f,0x25,0x30,0x00,0x06,
1809 0x00 }},
1810 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1811 0x3e,0x85,0x5d,0x25,0x10,0x00,0x06,
1812 0x00 }},
1813 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1814 0x57,0x8e,0x8f,0x25,0x30,0x00,0x06,
1815 0x00 }},
1816 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1817 0x3e,0x85,0x5d,0x25,0x10,0x00,0x06,
1818 0x01 }},
1819 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1820 0x7f,0x86,0xdf,0x25,0x10,0x00,0x06,
1821 0x00 }},
1822 {{0xa3,0x63,0x87,0x78,0x89,0x24,0xf1,
1823 0xbb,0x82,0x57,0x25,0x10,0x00,0x02,
1824 0x01 }},
1825 {{0xa3,0x7f,0x87,0x83,0x94,0x24,0xf5,
1826 0x02,0x89,0xff,0x25,0x10,0x00,0x02,
1827 0x01 }}
1828};
1829
1830static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT11024x768_2_H[] =
1831{
1832 {{0x7b,0x27,0x9f,0x46,0x97,0x24,0xbb,
1833 0x57,0x8e,0x8f,0x25,0x30,0x00,0x01,
1834 0x00 }},
1835 {{0x7b,0x27,0x9f,0x46,0x97,0x24,0xbb,
1836 0x3e,0x85,0x5d,0x25,0x10,0x00,0x01,
1837 0x00 }},
1838 {{0x7b,0x27,0x9f,0x46,0x97,0x24,0xbb,
1839 0x57,0x8e,0x8f,0x25,0x30,0x00,0x01,
1840 0x00 }},
1841 {{0x7b,0x27,0x9f,0x46,0x97,0x24,0xbb,
1842 0x3e,0x85,0x5d,0x25,0x10,0x00,0x01,
1843 0x00 }},
1844 {{0x7b,0x27,0x9f,0x46,0x97,0x24,0xbb,
1845 0x7f,0x86,0xdf,0x25,0x10,0x00,0x01,
1846 0x00 }},
1847 {{0x71,0x31,0x95,0x46,0x97,0x24,0xf1,
1848 0xbb,0x82,0x57,0x25,0x10,0x00,0x01,
1849 0x01 }},
1850 {{0x63,0x3f,0x87,0x46,0x97,0x24,0xf5,
1851 0x0f,0x86,0xff,0x25,0x30,0x00,0x01,
1852 0x01 }}
1853};
1854
1855static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT11280x1024_1[] =
1856{
1857 {{0x7e,0x4f,0x82,0x58,0x04,0xb8,0x1f,
1858 0x90,0x84,0x8f,0xb9,0x30,0x00,0x06,
1859 0x00}},
1860 {{0x7e,0x4f,0x82,0x58,0x04,0x86,0x1f,
1861 0x5e,0x82,0x5d,0x87,0x10,0x00,0x06,
1862 0x00}},
1863 {{0x7e,0x4f,0x82,0x58,0x04,0xb8,0x1f,
1864 0x90,0x84,0x8f,0xb9,0x30,0x00,0x06,
1865 0x00}},
1866 {{0x7e,0x4f,0x82,0x58,0x04,0x86,0x1f,
1867 0x5e,0x82,0x5d,0x87,0x10,0x00,0x06,
1868 0x00}},
1869 {{0x7e,0x4f,0x82,0x58,0x04,0x08,0x3e,
1870 0xe0,0x84,0xdf,0x09,0x00,0x00,0x06,
1871 0x00}},
1872 {{0x92,0x63,0x96,0x6c,0x18,0x80,0xf0,
1873 0x58,0x8c,0x57,0x81,0x20,0x00,0x06,
1874 0x01}},
1875 {{0xae,0x7f,0x92,0x88,0x94,0x28,0xf5,
1876 0x00,0x84,0xff,0x29,0x10,0x00,0x02,
1877 0x01}},
1878 {{0xce,0x9f,0x92,0xa8,0x14,0x28,0x5a,
1879 0x00,0x84,0xff,0x29,0x09,0x00,0x07,
1880 0x01}}
1881};
1882
1883static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT11280x1024_1_H[] =
1884{
1885 {{0x56,0x27,0x9a,0x31,0x1c,0xb8,0x1f,
1886 0x90,0x84,0x8f,0xb9,0x30,0x00,0x05,
1887 0x00}},
1888 {{0x56,0x27,0x9a,0x31,0x1c,0x86,0x1f,
1889 0x5e,0x82,0x5d,0x87,0x10,0x00,0x05,
1890 0x00}},
1891 {{0x56,0x27,0x9a,0x31,0x1c,0xb8,0x1f,
1892 0x90,0x84,0x8f,0xb9,0x30,0x00,0x05,
1893 0x00}},
1894 {{0x56,0x27,0x9a,0x31,0x1c,0x86,0x1f,
1895 0x5e,0x82,0x5d,0x87,0x10,0x00,0x05,
1896 0x01}},
1897 {{0x56,0x27,0x9a,0x31,0x1c,0x08,0x3e,
1898 0xe0,0x84,0xdf,0x09,0x00,0x00,0x05,
1899 0x00}},
1900 {{0x60,0x31,0x84,0x3a,0x86,0x80,0xf0,
1901 0x58,0x8c,0x57,0x81,0x20,0x00,0x01,
1902 0x01}},
1903 {{0x6e,0x3f,0x92,0x48,0x94,0x28,0xf5,
1904 0x00,0x84,0xff,0x29,0x10,0x00,0x01,
1905 0x01}}
1906};
1907
1908static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT11280x1024_2[] =
1909{
1910 {{0xce,0x72,0x91,0x81,0x8f,0x28,0x92,
1911 0xc8,0x8c,0x5d,0x5c,0x01,0x00,0x02,
1912 0x01}},
1913 {{0xce,0x72,0x91,0x81,0x8f,0x28,0x92,
1914 0xaf,0x83,0x44,0x43,0x21,0x00,0x02,
1915 0x01}},
1916 {{0xce,0x72,0x91,0x81,0x8f,0x28,0x92,
1917 0xc8,0x8c,0x5d,0x5c,0x01,0x00,0x02,
1918 0x01}},
1919 {{0xce,0x72,0x91,0x81,0x8f,0x28,0x92,
1920 0xaf,0x83,0x44,0x43,0x21,0x00,0x02,
1921 0x01}},
1922 {{0xce,0x72,0x91,0x81,0x8f,0x28,0x92,
1923 0xf0,0x84,0x85,0x84,0x11,0x00,0x02,
1924 0x01}},
1925 {{0xce,0x63,0x92,0x8b,0x19,0x28,0xd4,
1926 0x3f,0x83,0x57,0x29,0x01,0x00,0x03,
1927 0x01}},
1928 {{0xce,0x7f,0x92,0x99,0x07,0x28,0xd4,
1929 0x93,0x87,0xff,0x29,0x21,0x00,0x07,
1930 0x01}},
1931 {{0xce,0x9f,0x92,0xa8,0x14,0x28,0x5a,
1932 0x00,0x84,0xff,0x29,0x09,0x00,0x07,
1933 0x01}}
1934};
1935
1936static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT11280x1024_2_H[] =
1937{
1938 {{0xa6,0x4a,0x89,0x59,0x07,0x28,0x92,
1939 0xc8,0x8c,0x5d,0x5c,0x01,0x00,0x06,
1940 0x01}},
1941 {{0xa6,0x4a,0x89,0x59,0x07,0x28,0x92,
1942 0xaf,0x83,0x44,0x43,0x21,0x00,0x06,
1943 0x01}},
1944 {{0xa6,0x4a,0x89,0x59,0x07,0x28,0x92,
1945 0xc8,0x8c,0x5d,0x5c,0x01,0x00,0x06,
1946 0x01}},
1947 {{0xa6,0x4a,0x89,0x59,0x07,0x28,0x92,
1948 0xfa,0x83,0x44,0x43,0x31,0x00,0x06,
1949 0x01}},
1950 {{0xa6,0x4a,0x89,0x59,0x07,0x28,0x92,
1951 0xf0,0x84,0x85,0x84,0x11,0x00,0x06,
1952 0x01}},
1953 {{0x9c,0x31,0x80,0x59,0x87,0x28,0xd4,
1954 0x3f,0x83,0x57,0x29,0x01,0x00,0x06,
1955 0x01}},
1956 {{0x8e,0x3f,0x92,0x59,0x07,0x28,0xd4,
1957 0x93,0x87,0xff,0x29,0x21,0x00,0x06,
1958 0x01}}
1959};
1960
1961static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT11400x1050_1[] =
1962{
1963 {{0x6f,0x4f,0x93,0x54,0x82,0x9e,0x1f,
1964 0x8f,0x81,0x8f,0x9f,0x30,0x00,0x05,
1965 0x00}},
1966 {{0x6f,0x4f,0x93,0x54,0x82,0x6c,0x1f,
1967 0x5e,0x81,0x5d,0x6d,0x10,0x00,0x05,
1968 0x00}},
1969 {{0x6f,0x4f,0x93,0x54,0x82,0x9e,0x1f,
1970 0x90,0x83,0x8f,0x9f,0x30,0x00,0x05,
1971 0x00}},
1972 {{0x6f,0x4f,0x93,0x54,0x82,0x6c,0x1f,
1973 0x60,0x84,0x5d,0x6d,0x10,0x00,0x05,
1974 0x00}},
1975 {{0x6f,0x4f,0x93,0x54,0x82,0xee,0x1f,
1976 0xdf,0x82,0xdf,0xef,0x10,0x00,0x05,
1977 0x00}},
1978 {{0x83,0x63,0x87,0x68,0x16,0x66,0xf0,
1979 0x57,0x8e,0x57,0x67,0x20,0x00,0x06,
1980 0x01}},
1981 {{0x9f,0x7f,0x83,0x84,0x92,0x0e,0xf1,
1982 0xff,0x86,0xff,0x0f,0x10,0x00,0x02,
1983 0x01,}},
1984 {{0xbf,0x9f,0x83,0xa4,0x12,0x0e,0xde,
1985 0xff,0x86,0xff,0x0f,0x01,0x00,0x07,
1986 0x01}},
1987 {{0xce,0xae,0x92,0xb3,0x01,0x28,0x10,
1988 0x19,0x80,0x19,0x29,0x0f,0x00,0x03,
1989 0x00}}
1990#if 0
1991 {{0x6f,0x4f,0x93,0x54,0x82,0x9e,0x1f,
1992 0x93,0x86,0x8f,0x9f,0x30,0x00,0x05,
1993 0x00}},
1994 {{0x6f,0x4f,0x93,0x54,0x82,0x6c,0x1f,
1995 0x60,0x84,0x5d,0x6d,0x10,0x00,0x05,
1996 0x00}},
1997 {{0x6f,0x4f,0x93,0x54,0x82,0x9e,0x1f,
1998 0x93,0x86,0x8f,0x9f,0x30,0x00,0x05,
1999 0x00}},
2000 {{0x6f,0x4f,0x93,0x54,0x82,0x6c,0x1f,
2001 0x60,0x84,0x5d,0x6d,0x10,0x00,0x05,
2002 0x00}},
2003 {{0x6f,0x4f,0x93,0x54,0x82,0xee,0x1f,
2004 0xe2,0x86,0xdf,0xef,0x10,0x00,0x05,
2005 0x00}},
2006 {{0x83,0x63,0x87,0x68,0x16,0x66,0xf0,
2007 0x5a,0x8e,0x57,0x67,0x20,0x00,0x06,
2008 0x01}},
2009 {{0x9f,0x7f,0x83,0x84,0x92,0x0e,0xf5,
2010 0x02,0x86,0xff,0x0f,0x10,0x00,0x02,
2011 0x01}},
2012 {{0xbf,0x9f,0x83,0xa4,0x12,0x0e,0x5a,
2013 0x02,0x86,0xff,0x0f,0x09,0x00,0x07,
2014 0x01}},
2015 {{0xce,0xae,0x92,0xb3,0x01,0x28,0x10,
2016 0x1a,0x80,0x19,0x29,0x0f,0x00,0x03,
2017 0x00}}
2018#endif
2019};
2020
2021static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT11400x1050_1_H[] =
2022{
2023 {{0x47,0x27,0x8b,0x2c,0x1a,0x9e,0x1f,
2024 0x8f,0x81,0x8f,0x9f,0x30,0x00,0x05,
2025 0x00}},
2026 {{0x47,0x27,0x8b,0x2c,0x1a,0x6c,0x1f,
2027 0x60,0x84,0x5d,0x6d,0x10,0x00,0x05,
2028 0x00}},
2029 {{0x47,0x27,0x8b,0x30,0x1e,0x9e,0x1f,
2030 0x90,0x83,0x8f,0x9f,0x30,0x00,0x05,
2031 0x00}},
2032 {{0x47,0x27,0x8b,0x2c,0x1a,0x6c,0x1f,
2033 0x60,0x84,0x5d,0x6d,0x10,0x00,0x05,
2034 0x00}},
2035 {{0x47,0x27,0x8b,0x2c,0x1a,0xee,0x1f,
2036 0xdf,0x86,0xdf,0xef,0x10,0x00,0x05,
2037 0x00}},
2038 {{0x51,0x31,0x95,0x36,0x04,0x66,0xf0,
2039 0x57,0x8e,0x57,0x67,0x20,0x00,0x01,
2040 0x01}},
2041 {{0x5f,0x3f,0x83,0x44,0x92,0x0e,0xf1,
2042 0xff,0x86,0xff,0x0f,0x10,0x00,0x01,
2043 0x01}},
2044 {{0x6f,0x4f,0x93,0x54,0x82,0x0e,0x5a,
2045 0x02,0x86,0xff,0x0f,0x09,0x00,0x05,
2046 0x01}},
2047 {{0x76,0x56,0x9a,0x5b,0x89,0x28,0x10,
2048 0x1c,0x80,0x19,0x29,0x0b,0x00,0x05,
2049 0x00}}
2050#if 0
2051 {{0x47,0x27,0x8b,0x2c,0x1a,0x9e,0x1f,
2052 0x93,0x86,0x8f,0x9f,0x30,0x00,0x05,
2053 0x00}},
2054 {{0x47,0x27,0x8b,0x2c,0x1a,0x6c,0x1f,
2055 0x60,0x84,0x5d,0x6d,0x10,0x00,0x05,
2056 0x00}},
2057 {{0x47,0x27,0x8b,0x30,0x1e,0x9e,0x1f,
2058 0x92,0x86,0x8f,0x9f,0x30,0x00,0x05,
2059 0x00}},
2060 {{0x47,0x27,0x8b,0x2c,0x1a,0x6c,0x1f,
2061 0x60,0x84,0x5d,0x6d,0x10,0x00,0x05,
2062 0x00}},
2063 {{0x47,0x27,0x8b,0x2c,0x1a,0xee,0x1f,
2064 0xe2,0x86,0xdf,0xef,0x10,0x00,0x05,
2065 0x00}},
2066 {{0x51,0x31,0x95,0x36,0x04,0x66,0xf0,
2067 0x5a,0x8e,0x57,0x67,0x20,0x00,0x01,
2068 0x01}},
2069 {{0x5f,0x3f,0x83,0x44,0x92,0x0e,0xf5,
2070 0x02,0x86,0xff,0x0f,0x10,0x00,0x01,
2071 0x01}},
2072 {{0x6f,0x4f,0x93,0x54,0x82,0x0e,0x5a,
2073 0x02,0x86,0xff,0x0f,0x09,0x00,0x05,
2074 0x01}},
2075 {{0x76,0x56,0x9a,0x5b,0x89,0x28,0x10,
2076 0x1c,0x80,0x19,0x29,0x0b,0x00,0x05,
2077 0x00}}
2078#endif
2079};
2080
2081static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT11400x1050_2[] =
2082{
2083 {{0xce,0x72,0x91,0x84,0x92,0x28,0x92,
2084 0xd7,0x8b,0x5d,0x5c,0x21,0x00,0x02,
2085 0x01}},
2086 {{0xce,0x72,0x91,0x84,0x92,0x28,0x92,
2087 0xbe,0x82,0x44,0x43,0x01,0x00,0x02,
2088 0x01}},
2089 {{0xce,0x72,0x91,0x84,0x92,0x28,0x92,
2090 0xd7,0x8b,0x5d,0x5c,0x21,0x00,0x02,
2091 0x01}},
2092 {{0xce,0x72,0x91,0x84,0x92,0x28,0x92,
2093 0xbe,0x82,0x44,0x43,0x01,0x00,0x02,
2094 0x01}},
2095 {{0xce,0x72,0x91,0x84,0x92,0x28,0x92,
2096 0xff,0x83,0x85,0x84,0x11,0x00,0x02,
2097 0x01}},
2098 {{0xce,0x63,0x92,0x8e,0x1c,0x28,0xd4,
2099 0x3f,0x83,0x57,0x29,0x01,0x00,0x03,
2100 0x01}},
2101 {{0xce,0x7f,0x92,0x9c,0x0a,0x28,0xd4,
2102 0x93,0x87,0xff,0x29,0x21,0x00,0x07,
2103 0x01}},
2104 {{0xce,0x9f,0x92,0xac,0x1a,0x28,0x5a,
2105 0x13,0x87,0xff,0x29,0x29,0x00,0x07,
2106 0x01}},
2107 {{0xce,0xae,0x92,0xbc,0x0a,0x28,0x10,
2108 0x20,0x84,0x19,0x29,0x0f,0x00,0x03,
2109 0x00}}
2110#if 0
2111 {{0xce,0x4f,0x92,0x8c,0x1a,0x28,0x9a,
2112 0xdb,0x8f,0x8f,0x29,0x21,0x00,0x03,
2113 0x00}},
2114 {{0xce,0x4f,0x92,0x8c,0x1a,0x28,0x9a,
2115 0xc2,0x86,0x5d,0x29,0x01,0x00,0x03,
2116 0x01}},
2117 {{0xce,0x4f,0x92,0x8c,0x1a,0x28,0x9a,
2118 0xdb,0x8f,0x8f,0x29,0x21,0x00,0x03,
2119 0x00}},
2120 {{0xce,0x4f,0x92,0x8c,0x1a,0x28,0x9a,
2121 0xc2,0x86,0x5d,0x29,0x01,0x00,0x03,
2122 0x00}},
2123 {{0xce,0x4f,0x92,0x8c,0x1a,0x28,0x9e,
2124 0x03,0x87,0xdf,0x29,0x01,0x00,0x03,
2125 0x00}},
2126 {{0xce,0x63,0x92,0x96,0x04,0x28,0xd4,
2127 0x3f,0x83,0x57,0x29,0x01,0x00,0x07,
2128 0x01}},
2129 {{0xce,0x7f,0x92,0xa4,0x12,0x28,0xd4,
2130 0x93,0x87,0xff,0x29,0x21,0x00,0x07,
2131 0x01}},
2132 {{0xce,0x9f,0x92,0xb4,0x02,0x28,0x5a,
2133 0x13,0x87,0xff,0x29,0x29,0x00,0x03,
2134 0x01}},
2135 {{0xce,0xae,0x92,0xbc,0x0a,0x28,0x10,
2136 0x20,0x84,0x19,0x29,0x0f,0x00,0x03,
2137 0x00}}
2138#endif
2139};
2140
2141static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT11400x1050_2_H[] =
2142{
2143 {{0xa6,0x4a,0x89,0x5c,0x0a,0x28,0x92,
2144 0xd7,0x8b,0x5d,0x5c,0x21,0x00,0x06,
2145 0x01}},
2146 {{0xa6,0x4a,0x89,0x5c,0x0a,0x28,0x92,
2147 0xbe,0x82,0x44,0x43,0x01,0x00,0x06,
2148 0x01}},
2149 {{0xa6,0x4a,0x89,0x5c,0x0a,0x28,0x92,
2150 0xd7,0x8b,0x5d,0x5c,0x21,0x00,0x06,
2151 0x01}},
2152 {{0xa6,0x4a,0x89,0x5c,0x0a,0x28,0x92,
2153 0xbe,0x82,0x44,0x43,0x01,0x00,0x06,
2154 0x01}},
2155 {{0xa6,0x4a,0x89,0x5c,0x0a,0x28,0x92,
2156 0xff,0x83,0x85,0x84,0x11,0x00,0x06,
2157 0x01}},
2158 {{0x9c,0x31,0x80,0x5c,0x8a,0x28,0xd4,
2159 0x3f,0x83,0x57,0x29,0x01,0x00,0x06,
2160 0x01}},
2161 {{0x8e,0x3f,0x92,0x5c,0x0a,0x28,0xd4,
2162 0x93,0x87,0xff,0x29,0x21,0x00,0x06,
2163 0x01}},
2164 {{0x7e,0x4f,0x82,0x5c,0x0a,0x28,0x5a,
2165 0x13,0x87,0xff,0x29,0x29,0x00,0x06,
2166 0x01}},
2167 {{0x76,0x56,0x9a,0x64,0x92,0x28,0x10,
2168 0x20,0x84,0x19,0x29,0x0f,0x00,0x05,
2169 0x00}}
2170#if 0
2171 {{0xa6,0x27,0x8a,0x64,0x92,0x28,0x9a,
2172 0xdb,0x8f,0x8f,0x29,0x21,0x00,0x06,
2173 0x00}},
2174 {{0xa6,0x27,0x8a,0x64,0x92,0x28,0x9a,
2175 0xc2,0x86,0x5d,0x29,0x01,0x00,0x06,
2176 0x00}},
2177 {{0xa6,0x27,0x8a,0x64,0x92,0x28,0x9a,
2178 0xdb,0x8f,0x8f,0x29,0x21,0x00,0x06,
2179 0x00}},
2180 {{0xa6,0x27,0x8a,0x64,0x92,0x28,0x9a,
2181 0xc2,0x86,0x5d,0x29,0x01,0x00,0x06,
2182 0x00}},
2183 {{0xa6,0x27,0x8a,0x64,0x92,0x28,0x9e,
2184 0x03,0x87,0xdf,0x29,0x01,0x00,0x06,
2185 0x00}},
2186 {{0x9c,0x31,0x80,0x64,0x92,0x28,0xd4,
2187 0x3f,0x83,0x57,0x29,0x01,0x00,0x06,
2188 0x01}},
2189 {{0x8e,0x3f,0x92,0x64,0x12,0x28,0xd4,
2190 0x93,0x87,0xff,0x29,0x21,0x00,0x06,
2191 0x01}},
2192 {{0x7e,0x4f,0x82,0x64,0x12,0x28,0x5a,
2193 0x13,0x87,0xff,0x29,0x29,0x00,0x06,
2194 0x01}},
2195 {{0x76,0x56,0x9a,0x64,0x92,0x28,0x10,
2196 0x20,0x84,0x19,0x29,0x0f,0x00,0x05,
2197 0x00}}
2198#endif
2199};
2200
2201static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT11600x1200_1[] =
2202{
2203 {{0x83,0x4F,0x87,0x5B,0x13,0x06,0x3E,
2204 0xB3,0x86,0x8F,0x07,0x20,0x00,0x06,
2205 0x00}},
2206 {{0x83,0x4F,0x87,0x5B,0x13,0xD4,0x1F,
2207 0x81,0x84,0x5D,0xD5,0x10,0x00,0x06,
2208 0x00}},
2209 {{0x83,0x4F,0x87,0x5B,0x13,0x06,0x3E,
2210 0xB3,0x86,0x8F,0x07,0x20,0x00,0x06,
2211 0x00}},
2212 {{0x83,0x4F,0x87,0x5B,0x13,0xD4,0x1F,
2213 0x81,0x84,0x5D,0xD5,0x10,0x00,0x06,
2214 0x00}},
2215 {{0x83,0x4F,0x87,0x5B,0x13,0x56,0xBA,
2216 0x03,0x86,0xDF,0x57,0x00,0x00,0x06,
2217 0x00}},
2218 {{0x97,0x63,0x9B,0x6F,0x07,0xCE,0xF0,
2219 0x7B,0x8E,0x57,0xCF,0x20,0x00,0x02,
2220 0x01}},
2221 {{0xB3,0x7F,0x97,0x8B,0x83,0x76,0xF5,
2222 0x23,0x86,0xFF,0x77,0x10,0x00,0x06,
2223 0x01}},
2224 {{0xD3,0x9F,0x97,0xAB,0x03,0x76,0x5A,
2225 0x23,0x86,0xFF,0x77,0x09,0x00,0x03,
2226 0x01}},
2227 {{0xE2,0xAE,0x86,0xBA,0x92,0x90,0x10,
2228 0x3D,0x80,0x19,0x91,0x0F,0x00,0x03,
2229 0x00}},
2230 {{0xFB,0xC7,0x9F,0xD3,0x8B,0x26,0x11,
2231 0xD3,0x86,0xAF,0x27,0x3F,0x00,0x07,
2232 0x00}}
2233#if 0
2234 {{0x83,0x4f,0x87,0x51,0x09,0xc0,0x1f,
2235 0x90,0x84,0x8f,0xc1,0x30,0x00,0x06,
2236 0x00}},
2237 {{0x83,0x4f,0x87,0x51,0x09,0x8e,0x1f,
2238 0x5e,0x82,0x5d,0x8f,0x10,0x00,0x06,
2239 0x00}},
2240 {{0x83,0x4f,0x87,0x51,0x09,0xc0,0x1f,
2241 0x90,0x84,0x8f,0xc1,0x30,0x00,0x06,
2242 0x00}},
2243 {{0x83,0x4f,0x87,0x51,0x09,0x8e,0x1f,
2244 0x5e,0x82,0x5d,0x8f,0x10,0x00,0x06,
2245 0x00}},
2246 {{0x83,0x4f,0x87,0x51,0x09,0x10,0x3e,
2247 0xe0,0x84,0xdf,0x11,0x00,0x00,0x06,
2248 0x00}},
2249 {{0x97,0x63,0x9b,0x65,0x1d,0x88,0xf0,
2250 0x58,0x8c,0x57,0x89,0x20,0x00,0x06,
2251 0x01}},
2252 {{0xb3,0x7f,0x97,0x81,0x99,0x30,0xf5,
2253 0x00,0x84,0xff,0x31,0x10,0x00,0x02,
2254 0x01}},
2255 {{0xd3,0x9f,0x97,0xa1,0x19,0x30,0x5a,
2256 0x00,0x84,0xff,0x31,0x09,0x00,0x07,
2257 0x01}},
2258 {{0xe2,0xae,0x86,0xb0,0x88,0x4a,0x10,
2259 0x1a,0x8e,0x19,0x4b,0x2f,0x00,0x03,
2260 0x00}},
2261 {{0xfb,0xc7,0x9f,0xc9,0x81,0xe0,0x10,
2262 0xb0,0x84,0xaf,0xe1,0x2f,0x00,0x07,
2263 0x00}}
2264#endif
2265};
2266
2267static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT11600x1200_1_H[] =
2268{
2269 {{0x5B,0x27,0x9F,0x33,0x0B,0x06,0x2E,
2270 0xB3,0x86,0x8F,0x07,0x20,0x00,0x01,
2271 0x00}},
2272 {{0x5B,0x27,0x9F,0x29,0x01,0x8E,0x1F,
2273 0x81,0x84,0x5D,0xD5,0x10,0x00,0x06,
2274 0x00}},
2275 {{0x5B,0x27,0x9F,0x33,0x0B,0x06,0x2E,
2276 0xB3,0x86,0x8F,0x07,0x20,0x00,0x01,
2277 0x00}},
2278 {{0x83,0x4F,0x87,0x5B,0x13,0xD4,0x1F,
2279 0x81,0x84,0x5D,0xD5,0x10,0x00,0x06,
2280 0x00}},
2281 {{0x5B,0x27,0x9F,0x33,0x0B,0x56,0xBA,
2282 0x03,0x86,0xDF,0x57,0x00,0x00,0x01,
2283 0x00}},
2284 {{0x65,0x31,0x89,0x3D,0x95,0xCE,0xF0,
2285 0x7B,0x8E,0x57,0xCF,0x20,0x00,0x01,
2286 0x01}},
2287 {{0x73,0x3F,0x97,0x4B,0x83,0x76,0xF5,
2288 0x23,0x86,0xFF,0x77,0x10,0x00,0x05,
2289 0x01}},
2290 {{0xD3,0x9F,0x97,0xAB,0x03,0x76,0x5A,
2291 0x23,0x86,0xFF,0x77,0x09,0x00,0x03,
2292 0x01}},
2293 {{0xE2,0xAE,0x86,0xBA,0x92,0x90,0x10,
2294 0x3D,0x80,0x19,0x91,0x0F,0x00,0x03,
2295 0x00}},
2296 {{0x97,0x63,0x9B,0x6F,0x07,0xE0,0x10,
2297 0xB0,0x84,0xAF,0xE1,0x2F,0x00,0x06,
2298 0x00}}
2299#if 0
2300 {{0x5b,0x27,0x9f,0x29,0x01,0xc0,0x1f,
2301 0x90,0x84,0x8f,0xc1,0x30,0x00,0x01,
2302 0x00}},
2303 {{0x5b,0x27,0x9f,0x29,0x01,0x8e,0x1f,
2304 0x5e,0x82,0x5d,0x8f,0x10,0x00,0x01,
2305 0x00}},
2306 {{0x5b,0x27,0x9f,0x29,0x01,0xc0,0x1f,
2307 0x90,0x84,0x8f,0xc1,0x30,0x00,0x01,
2308 0x00}},
2309 {{0x5b,0x27,0x9f,0x29,0x01,0x8e,0x1f,
2310 0x5e,0x82,0x5d,0x8f,0x10,0x00,0x01,
2311 0x00}},
2312 {{0x5b,0x27,0x9f,0x29,0x01,0x10,0x3e,
2313 0xe0,0x84,0xdf,0x11,0x00,0x00,0x01,
2314 0x00}},
2315 {{0x65,0x31,0x89,0x33,0x8b,0x88,0xf0,
2316 0x58,0x8c,0x57,0x89,0x20,0x00,0x01,
2317 0x01}},
2318 {{0x73,0x3f,0x97,0x41,0x99,0x30,0xf5,
2319 0x00,0x84,0xff,0x31,0x10,0x00,0x01,
2320 0x01}},
2321 {{0x83,0x4f,0x87,0x51,0x09,0x30,0x5a,
2322 0x00,0x84,0xff,0x31,0x09,0x00,0x06,
2323 0x01}},
2324 {{0x8a,0x56,0x8e,0x58,0x10,0x4a,0x10,
2325 0x1a,0x8e,0x19,0x4b,0x2f,0x00,0x06,
2326 0x00}},
2327 {{0x97,0x63,0x9b,0x65,0x1d,0xe0,0x10,
2328 0xb0,0x84,0xaf,0xe1,0x2f,0x00,0x06,
2329 0x00}}
2330#endif
2331};
2332
2333static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT11600x1200_2[] =
2334{
2335 {{0xFB,0x87,0x86,0x97,0x0F,0x26,0x97,
2336 0x43,0x86,0xDB,0xDA,0x11,0x00,0x07,
2337 0x01}},
2338 {{0xFB,0x87,0x86,0x97,0x0F,0x26,0x97,
2339 0x2A,0x8D,0xC2,0xC1,0x11,0x00,0x07,
2340 0x01}},
2341 {{0xFB,0x87,0x86,0x97,0x0F,0x26,0x97,
2342 0x43,0x86,0xDB,0xDA,0x11,0x00,0x07,
2343 0x01}},
2344 {{0xFB,0x87,0x86,0x97,0x0F,0x26,0x97,
2345 0x2A,0x8D,0xC2,0xC1,0x11,0x00,0x07,
2346 0x01}},
2347 {{0xFB,0x87,0x86,0x97,0x0F,0x26,0x9F,
2348 0x6B,0x8E,0x03,0x02,0x01,0x00,0x07,
2349 0x01}},
2350 {{0xFB,0x63,0x9F,0xA1,0x99,0x26,0xD5,
2351 0xA7,0x8A,0xBF,0xBE,0x01,0x00,0x07,
2352 0x01}},
2353 {{0xFB,0x7F,0x9F,0xAF,0x87,0x26,0xDD,
2354 0xFB,0x8E,0x13,0x12,0x31,0x00,0x03,
2355 0x01}},
2356 {{0xFB,0x9F,0x9F,0xBF,0x97,0x26,0x5B,
2357 0x7B,0x8E,0xFF,0x27,0x39,0x00,0x03,
2358 0x01}},
2359 {{0xFB,0xAE,0x9F,0xC6,0x9E,0x26,0x11,
2360 0x88,0x8B,0x19,0x27,0x1F,0x00,0x03,
2361 0x00}},
2362 {{0xFB,0xC7,0x9F,0xD3,0x8B,0x26,0x11,
2363 0xD3,0x86,0xAF,0x27,0x3F,0x00,0x07,
2364 0x00}}
2365#if 0
2366 {{0xfb,0x88,0x87,0x90,0x08,0xe0,0x96,
2367 0x20,0x84,0xb9,0xb8,0x01,0x00,0x07,
2368 0x01}},
2369 {{0xfb,0x88,0x87,0x90,0x08,0xe0,0x96,
2370 0x07,0x8b,0xa0,0x9f,0x01,0x00,0x07,
2371 0x01}},
2372 {{0xfb,0x88,0x87,0x90,0x08,0xe0,0x96,
2373 0x20,0x84,0xb9,0xb8,0x01,0x00,0x07,
2374 0x01}},
2375 {{0xfb,0x88,0x87,0x90,0x08,0xe0,0x96,
2376 0x07,0x8b,0xa0,0x9f,0x01,0x00,0x07,
2377 0x01}},
2378 {{0xfb,0x88,0x87,0x90,0x08,0xe0,0x96,
2379 0x48,0x8c,0xe1,0xe0,0x11,0x00,0x07,
2380 0x01}},
2381 {{0xfb,0x63,0x9f,0x9a,0x92,0xe0,0xd4,
2382 0x9b,0x8f,0x9d,0x9c,0x21,0x00,0x07,
2383 0x01}},
2384 {{0xfb,0x7f,0x9f,0xa8,0x80,0xe0,0xd4,
2385 0xef,0x83,0xff,0xe1,0x21,0x00,0x03,
2386 0x01}},
2387 {{0xfb,0x9f,0x9f,0xb8,0x90,0xe0,0x5a,
2388 0x6f,0x83,0xff,0xe1,0x29,0x00,0x03,
2389 0x01}},
2390 {{0xfb,0xae,0x9f,0xbf,0x97,0xe0,0x10,
2391 0x7c,0x80,0x19,0xe1,0x0f,0x00,0x03,
2392 0x00}},
2393 {{0xfb,0xc7,0x9f,0xc9,0x84,0xe0,0x10,
2394 0xc7,0x8b,0xaf,0xe1,0x0f,0x00,0x07,
2395 0x00}}
2396#endif
2397};
2398
2399static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT11600x1200_2_H[] =
2400{
2401 {{0xD3,0x5F,0x9E,0x6F,0x07,0x26,0x97,
2402 0x43,0x86,0xDB,0xDA,0x11,0x00,0x02,
2403 0x01}},
2404 {{0xD3,0x27,0x97,0x6F,0x07,0x26,0x97,
2405 0x6B,0x8E,0x83,0x82,0x01,0x00,0x03,
2406 0x01}},
2407 {{0xD3,0x5F,0x9E,0x6F,0x07,0x26,0x97,
2408 0x43,0x86,0xDB,0xDA,0x11,0x00,0x02,
2409 0x01}},
2410 {{0xD3,0x27,0x97,0x6F,0x07,0x26,0x97,
2411 0x07,0x8B,0xA0,0x9F,0x01,0x00,0x02,
2412 0x01}},
2413 {{0xD3,0x27,0x97,0x6F,0x07,0x26,0x97,
2414 0x6B,0x8E,0x83,0x82,0x01,0x00,0x03,
2415 0x01}},
2416 {{0xC9,0x31,0x8D,0x6F,0x07,0x26,0xD5,
2417 0xA7,0x8A,0xBF,0xBE,0x01,0x00,0x03,
2418 0x01}},
2419 {{0xBB,0x3F,0x9F,0x6F,0x87,0x26,0xDD,
2420 0xFB,0x8E,0x13,0x12,0x31,0x00,0x02,
2421 0x01}},
2422 {{0xAB,0x4F,0x8F,0x68,0x80,0xE0,0x5A,
2423 0x6F,0x83,0xFF,0xE1,0x29,0x00,0x02,
2424 0x01}},
2425 {{0xA3,0x56,0x87,0x67,0x9F,0xE0,0x10,
2426 0x7C,0x80,0x19,0xE1,0x0F,0x00,0x06,
2427 0x00}},
2428 {{0x97,0x63,0x9B,0x68,0x00,0xE0,0x10,
2429 0xC7,0x8B,0xAF,0xE1,0x0F,0x00,0x02,
2430 0x00}}
2431#if 0
2432 {{0xd3,0x60,0x9f,0x68,0x00,0xe0,0x96,
2433 0x20,0x84,0xb9,0xb8,0x01,0x00,0x02,
2434 0x01}},
2435 {{0xd3,0x60,0x9f,0x68,0x00,0xe0,0x96,
2436 0x07,0x8b,0xa0,0x9f,0x01,0x00,0x02,
2437 0x01}},
2438 {{0xd3,0x60,0x9f,0x68,0x00,0xe0,0x96,
2439 0x20,0x84,0xb9,0xb8,0x01,0x00,0x02,
2440 0x01}},
2441 {{0xd3,0x60,0x9f,0x68,0x00,0xe0,0x96,
2442 0x07,0x8b,0xa0,0x9f,0x01,0x00,0x02,
2443 0x01}},
2444 {{0xd3,0x60,0x9f,0x68,0x00,0xe0,0x96,
2445 0x48,0x8c,0xe1,0xe0,0x11,0x00,0x02,
2446 0x01}},
2447 {{0xc9,0x31,0x8d,0x68,0x00,0xe0,0xd4,
2448 0x9b,0x8f,0x9d,0x9c,0x21,0x00,0x03,
2449 0x01}},
2450 {{0xbb,0x3f,0x9f,0x68,0x80,0xe0,0xd4,
2451 0xef,0x83,0xff,0xe1,0x21,0x00,0x02,
2452 0x01}},
2453 {{0xab,0x4f,0x8f,0x68,0x80,0xe0,0x5a,
2454 0x6f,0x83,0xff,0xe1,0x29,0x00,0x02,
2455 0x01}},
2456 {{0xa3,0x56,0x87,0x67,0x9f,0xe0,0x10,
2457 0x7c,0x80,0x19,0xe1,0x0f,0x00,0x06,
2458 0x00}},
2459 {{0x97,0x63,0x9b,0x68,0x00,0xe0,0x10,
2460 0xc7,0x8b,0xaf,0xe1,0x0f,0x00,0x02,
2461 0x00}}
2462#endif
2463};
2464
2465static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT1XXXxXXX_1[] =
2466{
2467 {{0x5f,0x4f,0x82,0x55,0x81,0xbf,0x1f,
2468 0x9c,0x8e,0x96,0xb9,0x30,0x00,0x05,
2469 0x00}},
2470 {{0x5f,0x4f,0x82,0x55,0x81,0xbf,0x1f,
2471 0x9c,0x8e,0x96,0xb9,0x30,0x00,0x05,
2472 0x00}},
2473 {{0x5f,0x4f,0x82,0x55,0x81,0xbf,0x1f,
2474 0x9c,0x8e,0x96,0xb9,0x30,0x00,0x05,
2475 0x00}},
2476 {{0x5f,0x4f,0x82,0x55,0x81,0xbf,0x1f,
2477 0x9c,0x8e,0x96,0xb9,0x30,0x00,0x05,
2478 0x00}},
2479 {{0x5f,0x4f,0x82,0x55,0x81,0x0b,0x3e,
2480 0xe9,0x8b,0xe7,0x04,0x00,0x00,0x05,
2481 0x00}},
2482 {{0x7f,0x63,0x83,0x6c,0x1c,0x72,0xf0,
2483 0x58,0x8c,0x57,0x73,0x20,0x00,0x06,
2484 0x01}},
2485 {{0xa3,0x7f,0x87,0x86,0x97,0x24,0xf5,
2486 0x02,0x88,0xff,0x25,0x10,0x00,0x02,
2487 0x01}},
2488 {{0xce,0x9f,0x92,0xa8,0x14,0x28,0x5a,
2489 0x00,0x84,0xff,0x29,0x09,0x00,0x07,
2490 0x01}},
2491 {{0xce,0x9f,0x92,0xa9,0x17,0x24,0xf5,
2492 0x02,0x88,0xff,0x25,0x10,0x00,0x07,
2493 0x01}}
2494};
2495
2496static const SiS_LVDSCRT1DataStruct SiS310_LVDSCRT1XXXxXXX_1_H[] =
2497{
2498 {{0x38,0x27,0x9c,0x2c,0x80,0xbf,0x1f,
2499 0x9c,0x8e,0x96,0xb9,0x30,0x00,0x00,
2500 0x00}},
2501 {{0x38,0x27,0x9c,0x2c,0x80,0xbf,0x1f,
2502 0x9c,0x8e,0x96,0xb9,0x30,0x00,0x00,
2503 0x00}},
2504 {{0x38,0x27,0x9c,0x2c,0x80,0xbf,0x1f,
2505 0x9c,0x8e,0x96,0xb9,0x30,0x00,0x00,
2506 0x00}},
2507 {{0x38,0x27,0x9c,0x2c,0x80,0xbf,0x1f,
2508 0x9c,0x8e,0x96,0xb9,0x30,0x00,0x00,
2509 0x00}},
2510 {{0x38,0x27,0x9c,0x2c,0x80,0x0b,0x3e,
2511 0xe9,0x8b,0xe7,0x04,0x00,0x00,0x00,
2512 0x00}},
2513 {{0x4d,0x31,0x91,0x3b,0x03,0x72,0xf0,
2514 0x58,0x8c,0x57,0x73,0x20,0x00,0x01,
2515 0x01}},
2516 {{0x63,0x3f,0x87,0x4a,0x92,0x24,0xf5,
2517 0x02,0x88,0xff,0x25,0x10,0x00,0x01,
2518 0x01}}
2519};
2520
2521
2522/* CRT1 CRTC for Chrontel TV slave modes */ 1108/* CRT1 CRTC for Chrontel TV slave modes */
2523 1109
2524static const SiS_LVDSCRT1DataStruct SiS310_CHTVCRT1UNTSC[] = 1110static const struct SiS_LVDSCRT1Data SiS310_CHTVCRT1UNTSC[] =
2525{ 1111{
2526 {{0x64,0x4f,0x88,0x56,0x9f,0x56,0x3e, 1112 {{0x64,0x4f,0x88,0x56,0x9f,0x56,0x3e,
2527 0xe8,0x84,0x8f,0x57,0x20,0x00,0x01, 1113 0xe8,0x84,0x8f,0x57,0x20,0x00,0x01,
2528 0x00 }}, 1114 0x00 }},
@@ -2546,7 +1132,7 @@ static const SiS_LVDSCRT1DataStruct SiS310_CHTVCRT1UNTSC[] =
2546 0x01}} 1132 0x01}}
2547}; 1133};
2548 1134
2549static const SiS_LVDSCRT1DataStruct SiS310_CHTVCRT1ONTSC[] = 1135static const struct SiS_LVDSCRT1Data SiS310_CHTVCRT1ONTSC[] =
2550{ 1136{
2551 {{0x63,0x4f,0x87,0x5a,0x9f,0x0b,0x3e, 1137 {{0x63,0x4f,0x87,0x5a,0x9f,0x0b,0x3e,
2552 0xc0,0x84,0x8f,0x0c,0x20,0x00,0x01, 1138 0xc0,0x84,0x8f,0x0c,0x20,0x00,0x01,
@@ -2571,8 +1157,8 @@ static const SiS_LVDSCRT1DataStruct SiS310_CHTVCRT1ONTSC[] =
2571 0x01 }} 1157 0x01 }}
2572}; 1158};
2573 1159
2574static const SiS_LVDSCRT1DataStruct SiS310_CHTVCRT1UPAL[] = 1160static const struct SiS_LVDSCRT1Data SiS310_CHTVCRT1UPAL[] =
2575{ 1161{
2576 {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e, 1162 {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
2577 0xf8,0x83,0x8f,0x70,0x20,0x00,0x05, 1163 0xf8,0x83,0x8f,0x70,0x20,0x00,0x05,
2578 0x00 }}, 1164 0x00 }},
@@ -2596,7 +1182,7 @@ static const SiS_LVDSCRT1DataStruct SiS310_CHTVCRT1UPAL[] =
2596 0x01}} 1182 0x01}}
2597}; 1183};
2598 1184
2599static const SiS_LVDSCRT1DataStruct SiS310_CHTVCRT1OPAL[] = 1185static const struct SiS_LVDSCRT1Data SiS310_CHTVCRT1OPAL[] =
2600{ 1186{
2601 {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e, 1187 {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
2602 0xf0,0x83,0x8f,0x70,0x20,0x00,0x05, 1188 0xf0,0x83,0x8f,0x70,0x20,0x00,0x05,
@@ -2621,8 +1207,7 @@ static const SiS_LVDSCRT1DataStruct SiS310_CHTVCRT1OPAL[] =
2621 0x01 }} 1207 0x01 }}
2622}; 1208};
2623 1209
2624 1210static const struct SiS_CHTVRegData SiS310_CHTVReg_UNTSC[] =
2625static const SiS_CHTVRegDataStruct SiS310_CHTVReg_UNTSC[] =
2626{ 1211{
2627 {{0x4a,0x77,0xbb,0x94,0x84,0x48,0xfe,0x50,0x04,0x00,0x80,0x00,0x00,0x00,0x00,0x01}}, 1212 {{0x4a,0x77,0xbb,0x94,0x84,0x48,0xfe,0x50,0x04,0x00,0x80,0x00,0x00,0x00,0x00,0x01}},
2628 {{0x4a,0x77,0xbb,0x94,0x84,0x48,0xfe,0x50,0x04,0x00,0x80,0x00,0x00,0x00,0x00,0x01}}, 1213 {{0x4a,0x77,0xbb,0x94,0x84,0x48,0xfe,0x50,0x04,0x00,0x80,0x00,0x00,0x00,0x00,0x01}},
@@ -2642,7 +1227,7 @@ static const SiS_CHTVRegDataStruct SiS310_CHTVReg_UNTSC[] =
2642 for PAL-M and PAL-N all above is corrected. 1227 for PAL-M and PAL-N all above is corrected.
2643 */ 1228 */
2644 1229
2645static const SiS_CHTVRegDataStruct SiS310_CHTVReg_ONTSC[] = 1230static const struct SiS_CHTVRegData SiS310_CHTVReg_ONTSC[] =
2646{ 1231{
2647 {{0x49,0x77,0xbb,0x7b,0x84,0x34,0x00,0x50,0x04,0x00,0x80,0x00,0x00,0x00,0x00,0x01}}, 1232 {{0x49,0x77,0xbb,0x7b,0x84,0x34,0x00,0x50,0x04,0x00,0x80,0x00,0x00,0x00,0x00,0x01}},
2648 {{0x49,0x77,0xbb,0x7b,0x84,0x34,0x00,0x50,0x04,0x00,0x80,0x00,0x00,0x00,0x00,0x01}}, 1233 {{0x49,0x77,0xbb,0x7b,0x84,0x34,0x00,0x50,0x04,0x00,0x80,0x00,0x00,0x00,0x00,0x01}},
@@ -2653,7 +1238,7 @@ static const SiS_CHTVRegDataStruct SiS310_CHTVReg_ONTSC[] =
2653 {{0xed,0x77,0xbb,0x66,0x8c,0x21,0x02,0x5a,0x04,0x00,0x80,0x1f,0x9f,0xc1,0x0c,0x00}} 1238 {{0xed,0x77,0xbb,0x66,0x8c,0x21,0x02,0x5a,0x04,0x00,0x80,0x1f,0x9f,0xc1,0x0c,0x00}}
2654}; 1239};
2655 1240
2656static const SiS_CHTVRegDataStruct SiS310_CHTVReg_UPAL[] = 1241static const struct SiS_CHTVRegData SiS310_CHTVReg_UPAL[] =
2657{ 1242{
2658 {{0x41,0x7f,0xb7,0x34,0xad,0x50,0x34,0x83,0x05,0x00,0x80,0x00,0x00,0x00,0x00,0x01}}, 1243 {{0x41,0x7f,0xb7,0x34,0xad,0x50,0x34,0x83,0x05,0x00,0x80,0x00,0x00,0x00,0x00,0x01}},
2659 {{0x41,0x7f,0xb7,0x80,0x85,0x50,0x00,0x83,0x05,0x00,0x80,0x00,0x00,0x00,0x00,0x01}}, 1244 {{0x41,0x7f,0xb7,0x80,0x85,0x50,0x00,0x83,0x05,0x00,0x80,0x00,0x00,0x00,0x00,0x01}},
@@ -2664,7 +1249,7 @@ static const SiS_CHTVRegDataStruct SiS310_CHTVReg_UPAL[] =
2664 {{0xe5,0x7f,0xb7,0x1d,0xa7,0x3e,0x04,0x5a,0x05,0x00,0x80,0x20,0x3e,0xe4,0x22,0x00}} 1249 {{0xe5,0x7f,0xb7,0x1d,0xa7,0x3e,0x04,0x5a,0x05,0x00,0x80,0x20,0x3e,0xe4,0x22,0x00}}
2665}; 1250};
2666 1251
2667static const SiS_CHTVRegDataStruct SiS310_CHTVReg_OPAL[] = 1252static const struct SiS_CHTVRegData SiS310_CHTVReg_OPAL[] =
2668{ 1253{
2669 {{0x41,0x7f,0xb7,0x36,0xad,0x50,0x34,0x83,0x05,0x00,0x80,0x00,0x00,0x00,0x00,0x01}}, 1254 {{0x41,0x7f,0xb7,0x36,0xad,0x50,0x34,0x83,0x05,0x00,0x80,0x00,0x00,0x00,0x00,0x01}},
2670 {{0x41,0x7f,0xb7,0x86,0x85,0x50,0x00,0x83,0x05,0x00,0x80,0x00,0x00,0x00,0x00,0x01}}, 1255 {{0x41,0x7f,0xb7,0x86,0x85,0x50,0x00,0x83,0x05,0x00,0x80,0x00,0x00,0x00,0x00,0x01}},
@@ -2675,7 +1260,7 @@ static const SiS_CHTVRegDataStruct SiS310_CHTVReg_OPAL[] =
2675 {{0xe4,0x7f,0xb7,0x1e,0xaf,0x29,0x37,0x5a,0x05,0x00,0x80,0x25,0x8c,0xb2,0x2a,0x00}} 1260 {{0xe4,0x7f,0xb7,0x1e,0xaf,0x29,0x37,0x5a,0x05,0x00,0x80,0x25,0x8c,0xb2,0x2a,0x00}}
2676}; 1261};
2677 1262
2678static const SiS_CHTVRegDataStruct SiS310_CHTVReg_UPALM[] = 1263static const struct SiS_CHTVRegData SiS310_CHTVReg_UPALM[] =
2679{ 1264{
2680 {{0x52,0x77,0xbb,0x94,0x84,0x48,0xfe,0x83,0x04,0x00,0x80,0x00,0x00,0x00,0x00,0x01}}, 1265 {{0x52,0x77,0xbb,0x94,0x84,0x48,0xfe,0x83,0x04,0x00,0x80,0x00,0x00,0x00,0x00,0x01}},
2681 {{0x52,0x77,0xbb,0x94,0x84,0x48,0xfe,0x83,0x04,0x00,0x80,0x00,0x00,0x00,0x00,0x01}}, 1266 {{0x52,0x77,0xbb,0x94,0x84,0x48,0xfe,0x83,0x04,0x00,0x80,0x00,0x00,0x00,0x00,0x01}},
@@ -2691,7 +1276,7 @@ static const SiS_CHTVRegDataStruct SiS310_CHTVReg_UPALM[] =
2691#endif 1276#endif
2692}; 1277};
2693 1278
2694static const SiS_CHTVRegDataStruct SiS310_CHTVReg_OPALM[] = 1279static const struct SiS_CHTVRegData SiS310_CHTVReg_OPALM[] =
2695{ 1280{
2696 {{0x51,0x77,0xbb,0x7b,0x84,0x34,0x00,0x83,0x04,0x00,0x80,0x00,0x00,0x00,0x00,0x01}}, 1281 {{0x51,0x77,0xbb,0x7b,0x84,0x34,0x00,0x83,0x04,0x00,0x80,0x00,0x00,0x00,0x00,0x01}},
2697 {{0x51,0x77,0xbb,0x7b,0x84,0x34,0x00,0x83,0x04,0x00,0x80,0x00,0x00,0x00,0x00,0x01}}, 1282 {{0x51,0x77,0xbb,0x7b,0x84,0x34,0x00,0x83,0x04,0x00,0x80,0x00,0x00,0x00,0x00,0x01}},
@@ -2707,7 +1292,7 @@ static const SiS_CHTVRegDataStruct SiS310_CHTVReg_OPALM[] =
2707#endif 1292#endif
2708}; 1293};
2709 1294
2710static const SiS_CHTVRegDataStruct SiS310_CHTVReg_UPALN[] = 1295static const struct SiS_CHTVRegData SiS310_CHTVReg_UPALN[] =
2711{ 1296{
2712 {{0x41,0x7f,0xb7,0x34,0xad,0x50,0x34,0x6e,0x05,0x00,0x80,0x00,0x00,0x00,0x00,0x03}}, 1297 {{0x41,0x7f,0xb7,0x34,0xad,0x50,0x34,0x6e,0x05,0x00,0x80,0x00,0x00,0x00,0x00,0x03}},
2713 {{0x41,0x7f,0xb7,0x80,0x85,0x50,0x00,0x6e,0x05,0x00,0x80,0x00,0x00,0x00,0x00,0x03}}, 1298 {{0x41,0x7f,0xb7,0x80,0x85,0x50,0x00,0x6e,0x05,0x00,0x80,0x00,0x00,0x00,0x00,0x03}},
@@ -2723,7 +1308,7 @@ static const SiS_CHTVRegDataStruct SiS310_CHTVReg_UPALN[] =
2723#endif 1308#endif
2724}; 1309};
2725 1310
2726static const SiS_CHTVRegDataStruct SiS310_CHTVReg_OPALN[] = 1311static const struct SiS_CHTVRegData SiS310_CHTVReg_OPALN[] =
2727{ 1312{
2728 {{0x41,0x7f,0xb7,0x36,0xad,0x50,0x34,0x6e,0x05,0x00,0x80,0x00,0x00,0x00,0x00,0x03}}, 1313 {{0x41,0x7f,0xb7,0x36,0xad,0x50,0x34,0x6e,0x05,0x00,0x80,0x00,0x00,0x00,0x00,0x03}},
2729 {{0x41,0x7f,0xb7,0x86,0x85,0x50,0x00,0x6e,0x05,0x00,0x80,0x00,0x00,0x00,0x00,0x03}}, 1314 {{0x41,0x7f,0xb7,0x86,0x85,0x50,0x00,0x6e,0x05,0x00,0x80,0x00,0x00,0x00,0x00,0x03}},
@@ -2739,16 +1324,16 @@ static const SiS_CHTVRegDataStruct SiS310_CHTVReg_OPALN[] =
2739#endif 1324#endif
2740}; 1325};
2741 1326
2742static const UCHAR SiS310_CHTVVCLKUNTSC[] = {0x41,0x41,0x41,0x41,0x42,0x46,0x53}; 1327static const unsigned char SiS310_CHTVVCLKUNTSC[] = { 0x41,0x41,0x41,0x41,0x42,0x46,0x53 };
2743static const UCHAR SiS310_CHTVVCLKONTSC[] = {0x48,0x48,0x48,0x48,0x45,0x43,0x51}; 1328static const unsigned char SiS310_CHTVVCLKONTSC[] = { 0x48,0x48,0x48,0x48,0x45,0x43,0x51 };
2744 1329
2745static const UCHAR SiS310_CHTVVCLKUPAL[] = {0x47,0x47,0x47,0x47,0x48,0x4a,0x54}; 1330static const unsigned char SiS310_CHTVVCLKUPAL[] = { 0x47,0x47,0x47,0x47,0x48,0x4a,0x54 };
2746static const UCHAR SiS310_CHTVVCLKOPAL[] = {0x47,0x47,0x47,0x47,0x48,0x4f,0x52}; 1331static const unsigned char SiS310_CHTVVCLKOPAL[] = { 0x47,0x47,0x47,0x47,0x48,0x4f,0x52 };
2747 1332
2748static const UCHAR SiS310_CHTVVCLKUPALM[] = {0x41,0x41,0x41,0x41,0x42,0x46,0x53}; 1333static const unsigned char SiS310_CHTVVCLKUPALM[] = { 0x41,0x41,0x41,0x41,0x42,0x46,0x53 };
2749static const UCHAR SiS310_CHTVVCLKOPALM[] = {0x48,0x48,0x48,0x48,0x45,0x43,0x51}; 1334static const unsigned char SiS310_CHTVVCLKOPALM[] = { 0x48,0x48,0x48,0x48,0x45,0x43,0x51 };
2750 1335
2751static const UCHAR SiS310_CHTVVCLKUPALN[] = {0x47,0x47,0x47,0x47,0x48,0x4a,0x54}; 1336static const unsigned char SiS310_CHTVVCLKUPALN[] = { 0x47,0x47,0x47,0x47,0x48,0x4a,0x54 };
2752static const UCHAR SiS310_CHTVVCLKOPALN[] = {0x47,0x47,0x47,0x47,0x48,0x4f,0x52}; 1337static const unsigned char SiS310_CHTVVCLKOPALN[] = { 0x47,0x47,0x47,0x47,0x48,0x4f,0x52 };
2753 1338
2754 1339
diff --git a/drivers/video/sis/Makefile b/drivers/video/sis/Makefile
index aaed8c2b4a..f7c0046e5b 100644
--- a/drivers/video/sis/Makefile
+++ b/drivers/video/sis/Makefile
@@ -4,4 +4,4 @@
4 4
5obj-$(CONFIG_FB_SIS) += sisfb.o 5obj-$(CONFIG_FB_SIS) += sisfb.o
6 6
7sisfb-objs := sis_main.o sis_accel.o init.o init301.o 7sisfb-objs := sis_main.o sis_accel.o init.o init301.o initextlfb.o
diff --git a/drivers/video/sis/init.c b/drivers/video/sis/init.c
index ecfd72178d..2ab3868efd 100644
--- a/drivers/video/sis/init.c
+++ b/drivers/video/sis/init.c
@@ -2,11 +2,12 @@
2/* $XdotOrg$ */ 2/* $XdotOrg$ */
3/* 3/*
4 * Mode initializing code (CRT1 section) for 4 * Mode initializing code (CRT1 section) for
5 * for SiS 300/305/540/630/730 and 5 * for SiS 300/305/540/630/730,
6 * SiS 315/550/650/M650/651/661FX/M661FX/740/741(GX)/M741/330/660/M660/760/M760 6 * SiS 315/550/[M]650/651/[M]661[FGM]X/[M]74x[GX]/330/[M]76x[GX],
7 * (Universal module for Linux kernel framebuffer and XFree86 4.x) 7 * XGI Volari V3XT/V5/V8, Z7
8 * (Universal module for Linux kernel framebuffer and X.org/XFree86 4.x)
8 * 9 *
9 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria 10 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
10 * 11 *
11 * If distributed as part of the Linux kernel, the following license terms 12 * If distributed as part of the Linux kernel, the following license terms
12 * apply: 13 * apply:
@@ -53,17 +54,12 @@
53 * 54 *
54 * Formerly based on non-functional code-fragements for 300 series by SiS, Inc. 55 * Formerly based on non-functional code-fragements for 300 series by SiS, Inc.
55 * Used by permission. 56 * Used by permission.
56 *
57 * TW says: This code looks awful, I know. But please don't do anything about
58 * this otherwise debugging will be hell.
59 * The code is extremely fragile as regards the different chipsets, different
60 * video bridges and combinations thereof. If anything is changed, extreme
61 * care has to be taken that that change doesn't break it for other chipsets,
62 * bridges or combinations thereof.
63 * All comments in this file are by me, regardless if they are marked TW or not.
64 *
65 */ 57 */
66 58
59#ifdef HAVE_CONFIG_H
60#include "config.h"
61#endif
62
67#include "init.h" 63#include "init.h"
68 64
69#ifdef SIS300 65#ifdef SIS300
@@ -84,24 +80,13 @@
84 80
85#if defined(SIS300) || defined(SIS315H) 81#if defined(SIS300) || defined(SIS315H)
86static void 82static void
87InitCommonPointer(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 83InitCommonPointer(struct SiS_Private *SiS_Pr)
88{ 84{
85 SiS_Pr->SiS_SModeIDTable = SiS_SModeIDTable;
89 SiS_Pr->SiS_StResInfo = SiS_StResInfo; 86 SiS_Pr->SiS_StResInfo = SiS_StResInfo;
90 SiS_Pr->SiS_ModeResInfo = SiS_ModeResInfo; 87 SiS_Pr->SiS_ModeResInfo = SiS_ModeResInfo;
91 SiS_Pr->SiS_StandTable = SiS_StandTable; 88 SiS_Pr->SiS_StandTable = SiS_StandTable;
92 89
93 SiS_Pr->SiS_NTSCPhase = SiS_NTSCPhase;
94 SiS_Pr->SiS_PALPhase = SiS_PALPhase;
95 SiS_Pr->SiS_NTSCPhase2 = SiS_NTSCPhase2;
96 SiS_Pr->SiS_PALPhase2 = SiS_PALPhase2;
97 SiS_Pr->SiS_PALMPhase = SiS_PALMPhase;
98 SiS_Pr->SiS_PALNPhase = SiS_PALNPhase;
99 SiS_Pr->SiS_PALMPhase2 = SiS_PALMPhase2;
100 SiS_Pr->SiS_PALNPhase2 = SiS_PALNPhase2;
101 SiS_Pr->SiS_SpecialPhase = SiS_SpecialPhase;
102 SiS_Pr->SiS_SpecialPhaseM = SiS_SpecialPhaseM;
103 SiS_Pr->SiS_SpecialPhaseJ = SiS_SpecialPhaseJ;
104
105 SiS_Pr->SiS_NTSCTiming = SiS_NTSCTiming; 90 SiS_Pr->SiS_NTSCTiming = SiS_NTSCTiming;
106 SiS_Pr->SiS_PALTiming = SiS_PALTiming; 91 SiS_Pr->SiS_PALTiming = SiS_PALTiming;
107 SiS_Pr->SiS_HiTVSt1Timing = SiS_HiTVSt1Timing; 92 SiS_Pr->SiS_HiTVSt1Timing = SiS_HiTVSt1Timing;
@@ -137,6 +122,7 @@ InitCommonPointer(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
137 SiS_Pr->SiS_ExtLCD1280x768_2Data = SiS_ExtLCD1280x768_2Data; 122 SiS_Pr->SiS_ExtLCD1280x768_2Data = SiS_ExtLCD1280x768_2Data;
138 SiS_Pr->SiS_LCD1280x800Data = SiS_LCD1280x800Data; 123 SiS_Pr->SiS_LCD1280x800Data = SiS_LCD1280x800Data;
139 SiS_Pr->SiS_LCD1280x800_2Data = SiS_LCD1280x800_2Data; 124 SiS_Pr->SiS_LCD1280x800_2Data = SiS_LCD1280x800_2Data;
125 SiS_Pr->SiS_LCD1280x854Data = SiS_LCD1280x854Data;
140 SiS_Pr->SiS_LCD1280x960Data = SiS_LCD1280x960Data; 126 SiS_Pr->SiS_LCD1280x960Data = SiS_LCD1280x960Data;
141 SiS_Pr->SiS_StLCD1400x1050Data = SiS_StLCD1400x1050Data; 127 SiS_Pr->SiS_StLCD1400x1050Data = SiS_StLCD1400x1050Data;
142 SiS_Pr->SiS_ExtLCD1400x1050Data = SiS_ExtLCD1400x1050Data; 128 SiS_Pr->SiS_ExtLCD1400x1050Data = SiS_ExtLCD1400x1050Data;
@@ -145,67 +131,30 @@ InitCommonPointer(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
145 SiS_Pr->SiS_ExtLCD1600x1200Data = SiS_ExtLCD1600x1200Data; 131 SiS_Pr->SiS_ExtLCD1600x1200Data = SiS_ExtLCD1600x1200Data;
146 SiS_Pr->SiS_NoScaleData = SiS_NoScaleData; 132 SiS_Pr->SiS_NoScaleData = SiS_NoScaleData;
147 133
148 SiS_Pr->SiS_LVDS320x480Data_1 = SiS_LVDS320x480Data_1; 134 SiS_Pr->SiS_LVDS320x240Data_1 = SiS_LVDS320x240Data_1;
135 SiS_Pr->SiS_LVDS320x240Data_2 = SiS_LVDS320x240Data_2;
136 SiS_Pr->SiS_LVDS640x480Data_1 = SiS_LVDS640x480Data_1;
149 SiS_Pr->SiS_LVDS800x600Data_1 = SiS_LVDS800x600Data_1; 137 SiS_Pr->SiS_LVDS800x600Data_1 = SiS_LVDS800x600Data_1;
150 SiS_Pr->SiS_LVDS800x600Data_2 = SiS_LVDS800x600Data_2;
151 SiS_Pr->SiS_LVDS1024x768Data_1 = SiS_LVDS1024x768Data_1;
152 SiS_Pr->SiS_LVDS1024x768Data_2 = SiS_LVDS1024x768Data_2;
153 SiS_Pr->SiS_LVDS1280x1024Data_1 = SiS_LVDS1280x1024Data_1;
154 SiS_Pr->SiS_LVDS1280x1024Data_2 = SiS_LVDS1280x1024Data_2;
155 SiS_Pr->SiS_LVDS1400x1050Data_1 = SiS_LVDS1400x1050Data_1;
156 SiS_Pr->SiS_LVDS1400x1050Data_2 = SiS_LVDS1400x1050Data_2;
157 SiS_Pr->SiS_LVDS1600x1200Data_1 = SiS_LVDS1600x1200Data_1;
158 SiS_Pr->SiS_LVDS1600x1200Data_2 = SiS_LVDS1600x1200Data_2;
159 SiS_Pr->SiS_LVDS1280x768Data_1 = SiS_LVDS1280x768Data_1;
160 SiS_Pr->SiS_LVDS1280x768Data_2 = SiS_LVDS1280x768Data_2;
161 SiS_Pr->SiS_LVDS1024x600Data_1 = SiS_LVDS1024x600Data_1; 138 SiS_Pr->SiS_LVDS1024x600Data_1 = SiS_LVDS1024x600Data_1;
162 SiS_Pr->SiS_LVDS1024x600Data_2 = SiS_LVDS1024x600Data_2; 139 SiS_Pr->SiS_LVDS1024x768Data_1 = SiS_LVDS1024x768Data_1;
163 SiS_Pr->SiS_LVDS1152x768Data_1 = SiS_LVDS1152x768Data_1;
164 SiS_Pr->SiS_LVDS1152x768Data_2 = SiS_LVDS1152x768Data_2;
165 SiS_Pr->SiS_LVDSXXXxXXXData_1 = SiS_LVDSXXXxXXXData_1;
166 SiS_Pr->SiS_LVDS1280x960Data_1 = SiS_LVDS1280x960Data_1;
167 SiS_Pr->SiS_LVDS1280x960Data_2 = SiS_LVDS1280x960Data_2;
168 SiS_Pr->SiS_LVDS640x480Data_1 = SiS_LVDS640x480Data_1;
169 SiS_Pr->SiS_LVDS1280x960Data_1 = SiS_LVDS1280x1024Data_1;
170 SiS_Pr->SiS_LVDS1280x960Data_2 = SiS_LVDS1280x1024Data_2;
171 SiS_Pr->SiS_LVDS640x480Data_1 = SiS_LVDS640x480Data_1;
172 SiS_Pr->SiS_LVDS640x480Data_2 = SiS_LVDS640x480Data_2;
173
174 SiS_Pr->SiS_LVDS848x480Data_1 = SiS_LVDS848x480Data_1;
175 SiS_Pr->SiS_LVDS848x480Data_2 = SiS_LVDS848x480Data_2;
176 SiS_Pr->SiS_LVDSBARCO1024Data_1 = SiS_LVDSBARCO1024Data_1;
177 SiS_Pr->SiS_LVDSBARCO1024Data_2 = SiS_LVDSBARCO1024Data_2;
178 SiS_Pr->SiS_LVDSBARCO1366Data_1 = SiS_LVDSBARCO1366Data_1;
179 SiS_Pr->SiS_LVDSBARCO1366Data_2 = SiS_LVDSBARCO1366Data_2;
180 140
181 SiS_Pr->SiS_LVDSCRT11280x768_1 = SiS_LVDSCRT11280x768_1; 141 SiS_Pr->SiS_LVDSCRT1320x240_1 = SiS_LVDSCRT1320x240_1;
142 SiS_Pr->SiS_LVDSCRT1320x240_2 = SiS_LVDSCRT1320x240_2;
143 SiS_Pr->SiS_LVDSCRT1320x240_2_H = SiS_LVDSCRT1320x240_2_H;
144 SiS_Pr->SiS_LVDSCRT1320x240_3 = SiS_LVDSCRT1320x240_3;
145 SiS_Pr->SiS_LVDSCRT1320x240_3_H = SiS_LVDSCRT1320x240_3_H;
146 SiS_Pr->SiS_LVDSCRT1640x480_1 = SiS_LVDSCRT1640x480_1;
147 SiS_Pr->SiS_LVDSCRT1640x480_1_H = SiS_LVDSCRT1640x480_1_H;
148#if 0
182 SiS_Pr->SiS_LVDSCRT11024x600_1 = SiS_LVDSCRT11024x600_1; 149 SiS_Pr->SiS_LVDSCRT11024x600_1 = SiS_LVDSCRT11024x600_1;
183 SiS_Pr->SiS_LVDSCRT11152x768_1 = SiS_LVDSCRT11152x768_1;
184 SiS_Pr->SiS_LVDSCRT11280x768_1_H = SiS_LVDSCRT11280x768_1_H;
185 SiS_Pr->SiS_LVDSCRT11024x600_1_H = SiS_LVDSCRT11024x600_1_H; 150 SiS_Pr->SiS_LVDSCRT11024x600_1_H = SiS_LVDSCRT11024x600_1_H;
186 SiS_Pr->SiS_LVDSCRT11152x768_1_H = SiS_LVDSCRT11152x768_1_H;
187 SiS_Pr->SiS_LVDSCRT11280x768_2 = SiS_LVDSCRT11280x768_2;
188 SiS_Pr->SiS_LVDSCRT11024x600_2 = SiS_LVDSCRT11024x600_2; 151 SiS_Pr->SiS_LVDSCRT11024x600_2 = SiS_LVDSCRT11024x600_2;
189 SiS_Pr->SiS_LVDSCRT11152x768_2 = SiS_LVDSCRT11152x768_2;
190 SiS_Pr->SiS_LVDSCRT11280x768_2_H = SiS_LVDSCRT11280x768_2_H;
191 SiS_Pr->SiS_LVDSCRT11024x600_2_H = SiS_LVDSCRT11024x600_2_H; 152 SiS_Pr->SiS_LVDSCRT11024x600_2_H = SiS_LVDSCRT11024x600_2_H;
192 SiS_Pr->SiS_LVDSCRT11152x768_2_H = SiS_LVDSCRT11152x768_2_H; 153#endif
193 SiS_Pr->SiS_LVDSCRT1320x480_1 = SiS_LVDSCRT1320x480_1;
194 SiS_Pr->SiS_LVDSCRT1640x480_1 = SiS_LVDSCRT1640x480_1;
195 SiS_Pr->SiS_LVDSCRT1640x480_1_H = SiS_LVDSCRT1640x480_1_H;
196 SiS_Pr->SiS_LVDSCRT1640x480_2 = SiS_LVDSCRT1640x480_2;
197 SiS_Pr->SiS_LVDSCRT1640x480_2_H = SiS_LVDSCRT1640x480_2_H;
198 SiS_Pr->SiS_LVDSCRT1640x480_3 = SiS_LVDSCRT1640x480_3;
199 SiS_Pr->SiS_LVDSCRT1640x480_3_H = SiS_LVDSCRT1640x480_3_H;
200 154
201 SiS_Pr->SiS_CHTVUNTSCData = SiS_CHTVUNTSCData; 155 SiS_Pr->SiS_CHTVUNTSCData = SiS_CHTVUNTSCData;
202 SiS_Pr->SiS_CHTVONTSCData = SiS_CHTVONTSCData; 156 SiS_Pr->SiS_CHTVONTSCData = SiS_CHTVONTSCData;
203 157
204 SiS_Pr->SiS_CHTVUNTSCDesData = SiS_CHTVUNTSCDesData;
205 SiS_Pr->SiS_CHTVONTSCDesData = SiS_CHTVONTSCDesData;
206 SiS_Pr->SiS_CHTVUPALDesData = SiS_CHTVUPALDesData;
207 SiS_Pr->SiS_CHTVOPALDesData = SiS_CHTVOPALDesData;
208
209 SiS_Pr->SiS_PanelMinLVDS = Panel_800x600; /* lowest value LVDS/LCDA */ 158 SiS_Pr->SiS_PanelMinLVDS = Panel_800x600; /* lowest value LVDS/LCDA */
210 SiS_Pr->SiS_PanelMin301 = Panel_1024x768; /* lowest value 301 */ 159 SiS_Pr->SiS_PanelMin301 = Panel_1024x768; /* lowest value 301 */
211} 160}
@@ -213,50 +162,24 @@ InitCommonPointer(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
213 162
214#ifdef SIS300 163#ifdef SIS300
215static void 164static void
216InitTo300Pointer(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 165InitTo300Pointer(struct SiS_Private *SiS_Pr)
217{ 166{
218 InitCommonPointer(SiS_Pr, HwInfo); 167 InitCommonPointer(SiS_Pr);
219 168
220 SiS_Pr->SiS_SModeIDTable = SiS300_SModeIDTable;
221 SiS_Pr->SiS_VBModeIDTable = SiS300_VBModeIDTable; 169 SiS_Pr->SiS_VBModeIDTable = SiS300_VBModeIDTable;
222 SiS_Pr->SiS_EModeIDTable = SiS300_EModeIDTable; 170 SiS_Pr->SiS_EModeIDTable = SiS300_EModeIDTable;
223 SiS_Pr->SiS_RefIndex = SiS300_RefIndex; 171 SiS_Pr->SiS_RefIndex = SiS300_RefIndex;
224 SiS_Pr->SiS_CRT1Table = SiS300_CRT1Table; 172 SiS_Pr->SiS_CRT1Table = SiS300_CRT1Table;
225 if(HwInfo->jChipType == SIS_300) { 173 if(SiS_Pr->ChipType == SIS_300) {
226 SiS_Pr->SiS_MCLKData_0 = SiS300_MCLKData_300; /* 300 */ 174 SiS_Pr->SiS_MCLKData_0 = SiS300_MCLKData_300; /* 300 */
227 } else { 175 } else {
228 SiS_Pr->SiS_MCLKData_0 = SiS300_MCLKData_630; /* 630, 730 */ 176 SiS_Pr->SiS_MCLKData_0 = SiS300_MCLKData_630; /* 630, 730 */
229 } 177 }
230 SiS_Pr->SiS_VCLKData = SiS300_VCLKData; 178 SiS_Pr->SiS_VCLKData = SiS300_VCLKData;
231 SiS_Pr->SiS_VBVCLKData = (SiS_VBVCLKDataStruct *)SiS300_VCLKData; 179 SiS_Pr->SiS_VBVCLKData = (struct SiS_VBVCLKData *)SiS300_VCLKData;
232 180
233 SiS_Pr->SiS_SR15 = SiS300_SR15; 181 SiS_Pr->SiS_SR15 = SiS300_SR15;
234 182
235#ifdef LINUX_KERNEL
236 SiS_Pr->pSiS_SR07 = &SiS300_SR07;
237 SiS_Pr->SiS_CR40 = SiS300_CR40;
238 SiS_Pr->SiS_CR49 = SiS300_CR49;
239 SiS_Pr->pSiS_SR1F = &SiS300_SR1F;
240 SiS_Pr->pSiS_SR21 = &SiS300_SR21;
241 SiS_Pr->pSiS_SR22 = &SiS300_SR22;
242 SiS_Pr->pSiS_SR23 = &SiS300_SR23;
243 SiS_Pr->pSiS_SR24 = &SiS300_SR24;
244 SiS_Pr->SiS_SR25 = SiS300_SR25;
245 SiS_Pr->pSiS_SR31 = &SiS300_SR31;
246 SiS_Pr->pSiS_SR32 = &SiS300_SR32;
247 SiS_Pr->pSiS_SR33 = &SiS300_SR33;
248 SiS_Pr->pSiS_CRT2Data_1_2 = &SiS300_CRT2Data_1_2;
249 SiS_Pr->pSiS_CRT2Data_4_D = &SiS300_CRT2Data_4_D;
250 SiS_Pr->pSiS_CRT2Data_4_E = &SiS300_CRT2Data_4_E;
251 SiS_Pr->pSiS_CRT2Data_4_10 = &SiS300_CRT2Data_4_10;
252 SiS_Pr->pSiS_RGBSenseData = &SiS300_RGBSenseData;
253 SiS_Pr->pSiS_VideoSenseData = &SiS300_VideoSenseData;
254 SiS_Pr->pSiS_YCSenseData = &SiS300_YCSenseData;
255 SiS_Pr->pSiS_RGBSenseData2 = &SiS300_RGBSenseData2;
256 SiS_Pr->pSiS_VideoSenseData2 = &SiS300_VideoSenseData2;
257 SiS_Pr->pSiS_YCSenseData2 = &SiS300_YCSenseData2;
258#endif
259
260 SiS_Pr->SiS_PanelDelayTbl = SiS300_PanelDelayTbl; 183 SiS_Pr->SiS_PanelDelayTbl = SiS300_PanelDelayTbl;
261 SiS_Pr->SiS_PanelDelayTblLVDS = SiS300_PanelDelayTbl; 184 SiS_Pr->SiS_PanelDelayTblLVDS = SiS300_PanelDelayTbl;
262 185
@@ -266,11 +189,8 @@ InitTo300Pointer(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
266 SiS_Pr->SiS_St2LCD1280x1024Data = SiS300_St2LCD1280x1024Data; 189 SiS_Pr->SiS_St2LCD1280x1024Data = SiS300_St2LCD1280x1024Data;
267 190
268 SiS_Pr->SiS_CRT2Part2_1024x768_1 = SiS300_CRT2Part2_1024x768_1; 191 SiS_Pr->SiS_CRT2Part2_1024x768_1 = SiS300_CRT2Part2_1024x768_1;
269 SiS_Pr->SiS_CRT2Part2_1280x1024_1 = SiS300_CRT2Part2_1280x1024_1;
270 SiS_Pr->SiS_CRT2Part2_1024x768_2 = SiS300_CRT2Part2_1024x768_2; 192 SiS_Pr->SiS_CRT2Part2_1024x768_2 = SiS300_CRT2Part2_1024x768_2;
271 SiS_Pr->SiS_CRT2Part2_1280x1024_2 = SiS300_CRT2Part2_1280x1024_2;
272 SiS_Pr->SiS_CRT2Part2_1024x768_3 = SiS300_CRT2Part2_1024x768_3; 193 SiS_Pr->SiS_CRT2Part2_1024x768_3 = SiS300_CRT2Part2_1024x768_3;
273 SiS_Pr->SiS_CRT2Part2_1280x1024_3 = SiS300_CRT2Part2_1280x1024_3;
274 194
275 SiS_Pr->SiS_CHTVUPALData = SiS300_CHTVUPALData; 195 SiS_Pr->SiS_CHTVUPALData = SiS300_CHTVUPALData;
276 SiS_Pr->SiS_CHTVOPALData = SiS300_CHTVOPALData; 196 SiS_Pr->SiS_CHTVOPALData = SiS300_CHTVOPALData;
@@ -280,64 +200,16 @@ InitTo300Pointer(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
280 SiS_Pr->SiS_CHTVOPALNData = SiS300_CHTVOPALData; /* not supported on 300 series */ 200 SiS_Pr->SiS_CHTVOPALNData = SiS300_CHTVOPALData; /* not supported on 300 series */
281 SiS_Pr->SiS_CHTVSOPALData = SiS300_CHTVSOPALData; 201 SiS_Pr->SiS_CHTVSOPALData = SiS300_CHTVSOPALData;
282 202
283 SiS_Pr->SiS_PanelType00_1 = SiS300_PanelType00_1; 203 SiS_Pr->SiS_LVDS848x480Data_1 = SiS300_LVDS848x480Data_1;
284 SiS_Pr->SiS_PanelType01_1 = SiS300_PanelType01_1; 204 SiS_Pr->SiS_LVDS848x480Data_2 = SiS300_LVDS848x480Data_2;
285 SiS_Pr->SiS_PanelType02_1 = SiS300_PanelType02_1; 205 SiS_Pr->SiS_LVDSBARCO1024Data_1 = SiS300_LVDSBARCO1024Data_1;
286 SiS_Pr->SiS_PanelType03_1 = SiS300_PanelType03_1; 206 SiS_Pr->SiS_LVDSBARCO1366Data_1 = SiS300_LVDSBARCO1366Data_1;
287 SiS_Pr->SiS_PanelType04_1 = SiS300_PanelType04_1; 207 SiS_Pr->SiS_LVDSBARCO1366Data_2 = SiS300_LVDSBARCO1366Data_2;
288 SiS_Pr->SiS_PanelType05_1 = SiS300_PanelType05_1; 208
289 SiS_Pr->SiS_PanelType06_1 = SiS300_PanelType06_1; 209 SiS_Pr->SiS_PanelType04_1a = SiS300_PanelType04_1a;
290 SiS_Pr->SiS_PanelType07_1 = SiS300_PanelType07_1; 210 SiS_Pr->SiS_PanelType04_2a = SiS300_PanelType04_2a;
291 SiS_Pr->SiS_PanelType08_1 = SiS300_PanelType08_1; 211 SiS_Pr->SiS_PanelType04_1b = SiS300_PanelType04_1b;
292 SiS_Pr->SiS_PanelType09_1 = SiS300_PanelType09_1; 212 SiS_Pr->SiS_PanelType04_2b = SiS300_PanelType04_2b;
293 SiS_Pr->SiS_PanelType0a_1 = SiS300_PanelType0a_1;
294 SiS_Pr->SiS_PanelType0b_1 = SiS300_PanelType0b_1;
295 SiS_Pr->SiS_PanelType0c_1 = SiS300_PanelType0c_1;
296 SiS_Pr->SiS_PanelType0d_1 = SiS300_PanelType0d_1;
297 SiS_Pr->SiS_PanelType0e_1 = SiS300_PanelType0e_1;
298 SiS_Pr->SiS_PanelType0f_1 = SiS300_PanelType0f_1;
299 SiS_Pr->SiS_PanelType00_2 = SiS300_PanelType00_2;
300 SiS_Pr->SiS_PanelType01_2 = SiS300_PanelType01_2;
301 SiS_Pr->SiS_PanelType02_2 = SiS300_PanelType02_2;
302 SiS_Pr->SiS_PanelType03_2 = SiS300_PanelType03_2;
303 SiS_Pr->SiS_PanelType04_2 = SiS300_PanelType04_2;
304 SiS_Pr->SiS_PanelType05_2 = SiS300_PanelType05_2;
305 SiS_Pr->SiS_PanelType06_2 = SiS300_PanelType06_2;
306 SiS_Pr->SiS_PanelType07_2 = SiS300_PanelType07_2;
307 SiS_Pr->SiS_PanelType08_2 = SiS300_PanelType08_2;
308 SiS_Pr->SiS_PanelType09_2 = SiS300_PanelType09_2;
309 SiS_Pr->SiS_PanelType0a_2 = SiS300_PanelType0a_2;
310 SiS_Pr->SiS_PanelType0b_2 = SiS300_PanelType0b_2;
311 SiS_Pr->SiS_PanelType0c_2 = SiS300_PanelType0c_2;
312 SiS_Pr->SiS_PanelType0d_2 = SiS300_PanelType0d_2;
313 SiS_Pr->SiS_PanelType0e_2 = SiS300_PanelType0e_2;
314 SiS_Pr->SiS_PanelType0f_2 = SiS300_PanelType0f_2;
315 SiS_Pr->SiS_PanelTypeNS_1 = SiS300_PanelTypeNS_1;
316 SiS_Pr->SiS_PanelTypeNS_2 = SiS300_PanelTypeNS_2;
317
318 if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
319 SiS_Pr->SiS_PanelType04_1 = SiS300_PanelType04_1a;
320 SiS_Pr->SiS_PanelType04_2 = SiS300_PanelType04_2a;
321 }
322 if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
323 SiS_Pr->SiS_PanelType04_1 = SiS300_PanelType04_1b;
324 SiS_Pr->SiS_PanelType04_2 = SiS300_PanelType04_2b;
325 }
326
327 SiS_Pr->SiS_LVDSCRT1800x600_1 = SiS300_LVDSCRT1800x600_1;
328 SiS_Pr->SiS_LVDSCRT1800x600_1_H = SiS300_LVDSCRT1800x600_1_H;
329 SiS_Pr->SiS_LVDSCRT1800x600_2 = SiS300_LVDSCRT1800x600_2;
330 SiS_Pr->SiS_LVDSCRT1800x600_2_H = SiS300_LVDSCRT1800x600_2_H;
331 SiS_Pr->SiS_LVDSCRT11024x768_1 = SiS300_LVDSCRT11024x768_1;
332 SiS_Pr->SiS_LVDSCRT11024x768_1_H = SiS300_LVDSCRT11024x768_1_H;
333 SiS_Pr->SiS_LVDSCRT11024x768_2 = SiS300_LVDSCRT11024x768_2;
334 SiS_Pr->SiS_LVDSCRT11024x768_2_H = SiS300_LVDSCRT11024x768_2_H;
335 SiS_Pr->SiS_LVDSCRT11280x1024_1 = SiS300_LVDSCRT11280x1024_1;
336 SiS_Pr->SiS_LVDSCRT11280x1024_1_H = SiS300_LVDSCRT11280x1024_1_H;
337 SiS_Pr->SiS_LVDSCRT11280x1024_2 = SiS300_LVDSCRT11280x1024_2;
338 SiS_Pr->SiS_LVDSCRT11280x1024_2_H = SiS300_LVDSCRT11280x1024_2_H;
339 SiS_Pr->SiS_LVDSCRT1XXXxXXX_1 = SiS300_LVDSCRT1XXXxXXX_1;
340 SiS_Pr->SiS_LVDSCRT1XXXxXXX_1_H = SiS300_LVDSCRT1XXXxXXX_1_H;
341 213
342 SiS_Pr->SiS_CHTVCRT1UNTSC = SiS300_CHTVCRT1UNTSC; 214 SiS_Pr->SiS_CHTVCRT1UNTSC = SiS300_CHTVCRT1UNTSC;
343 SiS_Pr->SiS_CHTVCRT1ONTSC = SiS300_CHTVCRT1ONTSC; 215 SiS_Pr->SiS_CHTVCRT1ONTSC = SiS300_CHTVCRT1ONTSC;
@@ -367,64 +239,38 @@ InitTo300Pointer(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
367 239
368#ifdef SIS315H 240#ifdef SIS315H
369static void 241static void
370InitTo310Pointer(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 242InitTo310Pointer(struct SiS_Private *SiS_Pr)
371{ 243{
372 InitCommonPointer(SiS_Pr, HwInfo); 244 InitCommonPointer(SiS_Pr);
373 245
374 SiS_Pr->SiS_SModeIDTable = SiS310_SModeIDTable;
375 SiS_Pr->SiS_EModeIDTable = SiS310_EModeIDTable; 246 SiS_Pr->SiS_EModeIDTable = SiS310_EModeIDTable;
376 SiS_Pr->SiS_RefIndex = (SiS_Ext2Struct *)SiS310_RefIndex; 247 SiS_Pr->SiS_RefIndex = SiS310_RefIndex;
377 SiS_Pr->SiS_CRT1Table = SiS310_CRT1Table; 248 SiS_Pr->SiS_CRT1Table = SiS310_CRT1Table;
378 if(HwInfo->jChipType >= SIS_340) { 249 if(SiS_Pr->ChipType >= SIS_340) {
379 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_340; /* 340 */ 250 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_340; /* 340 + XGI */
380 } else if(HwInfo->jChipType >= SIS_761) { 251 } else if(SiS_Pr->ChipType >= SIS_761) {
381 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_761; /* 761 - preliminary */ 252 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_761; /* 761 - preliminary */
382 } else if(HwInfo->jChipType >= SIS_760) { 253 } else if(SiS_Pr->ChipType >= SIS_760) {
383 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_760; /* 760 */ 254 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_760; /* 760 */
384 } else if(HwInfo->jChipType >= SIS_661) { 255 } else if(SiS_Pr->ChipType >= SIS_661) {
385 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_660; /* 661/741 */ 256 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_660; /* 661/741 */
386 } else if(HwInfo->jChipType == SIS_330) { 257 } else if(SiS_Pr->ChipType == SIS_330) {
387 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_330; /* 330 */ 258 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_330; /* 330 */
388 } else if(HwInfo->jChipType > SIS_315PRO) { 259 } else if(SiS_Pr->ChipType > SIS_315PRO) {
389 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_650; /* 550, 650, 740 */ 260 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_650; /* 550, 650, 740 */
390 } else { 261 } else {
391 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_315; /* 315 */ 262 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_315; /* 315 */
392 } 263 }
393 if(HwInfo->jChipType >= SIS_340) { 264 if(SiS_Pr->ChipType >= SIS_340) {
394 SiS_Pr->SiS_MCLKData_1 = SiS310_MCLKData_1_340; 265 SiS_Pr->SiS_MCLKData_1 = SiS310_MCLKData_1_340;
395 } else { 266 } else {
396 SiS_Pr->SiS_MCLKData_1 = SiS310_MCLKData_1; 267 SiS_Pr->SiS_MCLKData_1 = SiS310_MCLKData_1;
397 } 268 }
398 SiS_Pr->SiS_VCLKData = SiS310_VCLKData; 269 SiS_Pr->SiS_VCLKData = SiS310_VCLKData;
399 SiS_Pr->SiS_VBVCLKData = SiS310_VBVCLKData; 270 SiS_Pr->SiS_VBVCLKData = SiS310_VBVCLKData;
400 271
401 SiS_Pr->SiS_SR15 = SiS310_SR15; 272 SiS_Pr->SiS_SR15 = SiS310_SR15;
402 273
403#ifdef LINUX_KERNEL
404 SiS_Pr->pSiS_SR07 = &SiS310_SR07;
405 SiS_Pr->SiS_CR40 = SiS310_CR40;
406 SiS_Pr->SiS_CR49 = SiS310_CR49;
407 SiS_Pr->pSiS_SR1F = &SiS310_SR1F;
408 SiS_Pr->pSiS_SR21 = &SiS310_SR21;
409 SiS_Pr->pSiS_SR22 = &SiS310_SR22;
410 SiS_Pr->pSiS_SR23 = &SiS310_SR23;
411 SiS_Pr->pSiS_SR24 = &SiS310_SR24;
412 SiS_Pr->SiS_SR25 = SiS310_SR25;
413 SiS_Pr->pSiS_SR31 = &SiS310_SR31;
414 SiS_Pr->pSiS_SR32 = &SiS310_SR32;
415 SiS_Pr->pSiS_SR33 = &SiS310_SR33;
416 SiS_Pr->pSiS_CRT2Data_1_2 = &SiS310_CRT2Data_1_2;
417 SiS_Pr->pSiS_CRT2Data_4_D = &SiS310_CRT2Data_4_D;
418 SiS_Pr->pSiS_CRT2Data_4_E = &SiS310_CRT2Data_4_E;
419 SiS_Pr->pSiS_CRT2Data_4_10 = &SiS310_CRT2Data_4_10;
420 SiS_Pr->pSiS_RGBSenseData = &SiS310_RGBSenseData;
421 SiS_Pr->pSiS_VideoSenseData = &SiS310_VideoSenseData;
422 SiS_Pr->pSiS_YCSenseData = &SiS310_YCSenseData;
423 SiS_Pr->pSiS_RGBSenseData2 = &SiS310_RGBSenseData2;
424 SiS_Pr->pSiS_VideoSenseData2 = &SiS310_VideoSenseData2;
425 SiS_Pr->pSiS_YCSenseData2 = &SiS310_YCSenseData2;
426#endif
427
428 SiS_Pr->SiS_PanelDelayTbl = SiS310_PanelDelayTbl; 274 SiS_Pr->SiS_PanelDelayTbl = SiS310_PanelDelayTbl;
429 SiS_Pr->SiS_PanelDelayTblLVDS = SiS310_PanelDelayTblLVDS; 275 SiS_Pr->SiS_PanelDelayTblLVDS = SiS310_PanelDelayTblLVDS;
430 276
@@ -435,41 +281,6 @@ InitTo310Pointer(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
435 281
436 SiS_Pr->SiS_CRT2Part2_1024x768_1 = SiS310_CRT2Part2_1024x768_1; 282 SiS_Pr->SiS_CRT2Part2_1024x768_1 = SiS310_CRT2Part2_1024x768_1;
437 283
438 SiS_Pr->SiS_PanelType00_1 = SiS310_PanelType00_1;
439 SiS_Pr->SiS_PanelType01_1 = SiS310_PanelType01_1;
440 SiS_Pr->SiS_PanelType02_1 = SiS310_PanelType02_1;
441 SiS_Pr->SiS_PanelType03_1 = SiS310_PanelType03_1;
442 SiS_Pr->SiS_PanelType04_1 = SiS310_PanelType04_1;
443 SiS_Pr->SiS_PanelType05_1 = SiS310_PanelType05_1;
444 SiS_Pr->SiS_PanelType06_1 = SiS310_PanelType06_1;
445 SiS_Pr->SiS_PanelType07_1 = SiS310_PanelType07_1;
446 SiS_Pr->SiS_PanelType08_1 = SiS310_PanelType08_1;
447 SiS_Pr->SiS_PanelType09_1 = SiS310_PanelType09_1;
448 SiS_Pr->SiS_PanelType0a_1 = SiS310_PanelType0a_1;
449 SiS_Pr->SiS_PanelType0b_1 = SiS310_PanelType0b_1;
450 SiS_Pr->SiS_PanelType0c_1 = SiS310_PanelType0c_1;
451 SiS_Pr->SiS_PanelType0d_1 = SiS310_PanelType0d_1;
452 SiS_Pr->SiS_PanelType0e_1 = SiS310_PanelType0e_1;
453 SiS_Pr->SiS_PanelType0f_1 = SiS310_PanelType0f_1;
454 SiS_Pr->SiS_PanelType00_2 = SiS310_PanelType00_2;
455 SiS_Pr->SiS_PanelType01_2 = SiS310_PanelType01_2;
456 SiS_Pr->SiS_PanelType02_2 = SiS310_PanelType02_2;
457 SiS_Pr->SiS_PanelType03_2 = SiS310_PanelType03_2;
458 SiS_Pr->SiS_PanelType04_2 = SiS310_PanelType04_2;
459 SiS_Pr->SiS_PanelType05_2 = SiS310_PanelType05_2;
460 SiS_Pr->SiS_PanelType06_2 = SiS310_PanelType06_2;
461 SiS_Pr->SiS_PanelType07_2 = SiS310_PanelType07_2;
462 SiS_Pr->SiS_PanelType08_2 = SiS310_PanelType08_2;
463 SiS_Pr->SiS_PanelType09_2 = SiS310_PanelType09_2;
464 SiS_Pr->SiS_PanelType0a_2 = SiS310_PanelType0a_2;
465 SiS_Pr->SiS_PanelType0b_2 = SiS310_PanelType0b_2;
466 SiS_Pr->SiS_PanelType0c_2 = SiS310_PanelType0c_2;
467 SiS_Pr->SiS_PanelType0d_2 = SiS310_PanelType0d_2;
468 SiS_Pr->SiS_PanelType0e_2 = SiS310_PanelType0e_2;
469 SiS_Pr->SiS_PanelType0f_2 = SiS310_PanelType0f_2;
470 SiS_Pr->SiS_PanelTypeNS_1 = SiS310_PanelTypeNS_1;
471 SiS_Pr->SiS_PanelTypeNS_2 = SiS310_PanelTypeNS_2;
472
473 SiS_Pr->SiS_CHTVUPALData = SiS310_CHTVUPALData; 284 SiS_Pr->SiS_CHTVUPALData = SiS310_CHTVUPALData;
474 SiS_Pr->SiS_CHTVOPALData = SiS310_CHTVOPALData; 285 SiS_Pr->SiS_CHTVOPALData = SiS310_CHTVOPALData;
475 SiS_Pr->SiS_CHTVUPALMData = SiS310_CHTVUPALMData; 286 SiS_Pr->SiS_CHTVUPALMData = SiS310_CHTVUPALMData;
@@ -478,33 +289,11 @@ InitTo310Pointer(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
478 SiS_Pr->SiS_CHTVOPALNData = SiS310_CHTVOPALNData; 289 SiS_Pr->SiS_CHTVOPALNData = SiS310_CHTVOPALNData;
479 SiS_Pr->SiS_CHTVSOPALData = SiS310_CHTVSOPALData; 290 SiS_Pr->SiS_CHTVSOPALData = SiS310_CHTVSOPALData;
480 291
481 SiS_Pr->SiS_LVDSCRT1800x600_1 = SiS310_LVDSCRT1800x600_1; 292 SiS_Pr->SiS_CHTVCRT1UNTSC = SiS310_CHTVCRT1UNTSC;
482 SiS_Pr->SiS_LVDSCRT11024x768_1 = SiS310_LVDSCRT11024x768_1; 293 SiS_Pr->SiS_CHTVCRT1ONTSC = SiS310_CHTVCRT1ONTSC;
483 SiS_Pr->SiS_LVDSCRT11280x1024_1 = SiS310_LVDSCRT11280x1024_1; 294 SiS_Pr->SiS_CHTVCRT1UPAL = SiS310_CHTVCRT1UPAL;
484 SiS_Pr->SiS_LVDSCRT11400x1050_1 = SiS310_LVDSCRT11400x1050_1; 295 SiS_Pr->SiS_CHTVCRT1OPAL = SiS310_CHTVCRT1OPAL;
485 SiS_Pr->SiS_LVDSCRT11600x1200_1 = SiS310_LVDSCRT11600x1200_1; 296 SiS_Pr->SiS_CHTVCRT1SOPAL = SiS310_CHTVCRT1OPAL;
486 SiS_Pr->SiS_LVDSCRT1800x600_1_H = SiS310_LVDSCRT1800x600_1_H;
487 SiS_Pr->SiS_LVDSCRT11024x768_1_H = SiS310_LVDSCRT11024x768_1_H;
488 SiS_Pr->SiS_LVDSCRT11280x1024_1_H = SiS310_LVDSCRT11280x1024_1_H;
489 SiS_Pr->SiS_LVDSCRT11400x1050_1_H = SiS310_LVDSCRT11400x1050_1_H;
490 SiS_Pr->SiS_LVDSCRT11600x1200_1_H = SiS310_LVDSCRT11600x1200_1_H;
491 SiS_Pr->SiS_LVDSCRT1800x600_2 = SiS310_LVDSCRT1800x600_2;
492 SiS_Pr->SiS_LVDSCRT11024x768_2 = SiS310_LVDSCRT11024x768_2;
493 SiS_Pr->SiS_LVDSCRT11280x1024_2 = SiS310_LVDSCRT11280x1024_2;
494 SiS_Pr->SiS_LVDSCRT11400x1050_2 = SiS310_LVDSCRT11400x1050_2;
495 SiS_Pr->SiS_LVDSCRT11600x1200_2 = SiS310_LVDSCRT11600x1200_2;
496 SiS_Pr->SiS_LVDSCRT1800x600_2_H = SiS310_LVDSCRT1800x600_2_H;
497 SiS_Pr->SiS_LVDSCRT11024x768_2_H = SiS310_LVDSCRT11024x768_2_H;
498 SiS_Pr->SiS_LVDSCRT11280x1024_2_H = SiS310_LVDSCRT11280x1024_2_H;
499 SiS_Pr->SiS_LVDSCRT11400x1050_2_H = SiS310_LVDSCRT11400x1050_2_H;
500 SiS_Pr->SiS_LVDSCRT11600x1200_2_H = SiS310_LVDSCRT11600x1200_2_H;
501 SiS_Pr->SiS_LVDSCRT1XXXxXXX_1 = SiS310_LVDSCRT1XXXxXXX_1;
502 SiS_Pr->SiS_LVDSCRT1XXXxXXX_1_H = SiS310_LVDSCRT1XXXxXXX_1_H;
503 SiS_Pr->SiS_CHTVCRT1UNTSC = SiS310_CHTVCRT1UNTSC;
504 SiS_Pr->SiS_CHTVCRT1ONTSC = SiS310_CHTVCRT1ONTSC;
505 SiS_Pr->SiS_CHTVCRT1UPAL = SiS310_CHTVCRT1UPAL;
506 SiS_Pr->SiS_CHTVCRT1OPAL = SiS310_CHTVCRT1OPAL;
507 SiS_Pr->SiS_CHTVCRT1SOPAL = SiS310_CHTVCRT1OPAL;
508 297
509 SiS_Pr->SiS_CHTVReg_UNTSC = SiS310_CHTVReg_UNTSC; 298 SiS_Pr->SiS_CHTVReg_UNTSC = SiS310_CHTVReg_UNTSC;
510 SiS_Pr->SiS_CHTVReg_ONTSC = SiS310_CHTVReg_ONTSC; 299 SiS_Pr->SiS_CHTVReg_ONTSC = SiS310_CHTVReg_ONTSC;
@@ -528,208 +317,203 @@ InitTo310Pointer(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
528} 317}
529#endif 318#endif
530 319
531static void 320BOOLEAN
532SiSInitPtr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 321SiSInitPtr(struct SiS_Private *SiS_Pr)
533{ 322{
534 switch(HwInfo->jChipType) { 323 if(SiS_Pr->ChipType < SIS_315H) {
535#ifdef SIS315H
536 case SIS_315H:
537 case SIS_315:
538 case SIS_315PRO:
539 case SIS_550:
540 case SIS_650:
541 case SIS_740:
542 case SIS_330:
543 case SIS_661:
544 case SIS_741:
545 case SIS_660:
546 case SIS_760:
547 case SIS_761:
548 case SIS_340:
549 InitTo310Pointer(SiS_Pr, HwInfo);
550 break;
551#endif
552#ifdef SIS300 324#ifdef SIS300
553 case SIS_300: 325 InitTo300Pointer(SiS_Pr);
554 case SIS_540: 326#else
555 case SIS_630: 327 return FALSE;
556 case SIS_730: 328#endif
557 InitTo300Pointer(SiS_Pr, HwInfo); 329 } else {
558 break; 330#ifdef SIS315H
331 InitTo310Pointer(SiS_Pr);
332#else
333 return FALSE;
559#endif 334#endif
560 default:
561 break;
562 } 335 }
336 return TRUE;
563} 337}
564 338
565/*********************************************/ 339/*********************************************/
566/* HELPER: Get ModeID */ 340/* HELPER: Get ModeID */
567/*********************************************/ 341/*********************************************/
568 342
569#ifdef LINUX_XF86 343#ifndef SIS_XORG_XF86
570USHORT 344static
571SiS_GetModeID(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, 345#endif
572 int Depth, BOOLEAN FSTN, int LCDwidth, int LCDheight) 346unsigned short
347SiS_GetModeID(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay,
348 int Depth, BOOLEAN FSTN, int LCDwidth, int LCDheight)
573{ 349{
574 USHORT ModeIndex = 0; 350 unsigned short ModeIndex = 0;
575 351
576 switch(HDisplay) 352 switch(HDisplay)
577 { 353 {
578 case 320: 354 case 320:
579 if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth]; 355 if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth];
580 else if(VDisplay == 240) { 356 else if(VDisplay == 240) {
581 if(FSTN) ModeIndex = ModeIndex_320x240_FSTN[Depth]; 357 if((VBFlags & CRT2_LCD) && (FSTN))
582 else ModeIndex = ModeIndex_320x240[Depth]; 358 ModeIndex = ModeIndex_320x240_FSTN[Depth];
583 } 359 else
584 break; 360 ModeIndex = ModeIndex_320x240[Depth];
585 case 400: 361 }
586 if((!(VBFlags & CRT1_LCDA)) || ((LCDwidth >= 800) && (LCDwidth >= 600))) { 362 break;
587 if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth]; 363 case 400:
588 } 364 if((!(VBFlags & CRT1_LCDA)) || ((LCDwidth >= 800) && (LCDwidth >= 600))) {
589 break; 365 if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
590 case 512: 366 }
591 if((!(VBFlags & CRT1_LCDA)) || ((LCDwidth >= 1024) && (LCDwidth >= 768))) { 367 break;
592 if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth]; 368 case 512:
593 } 369 if((!(VBFlags & CRT1_LCDA)) || ((LCDwidth >= 1024) && (LCDwidth >= 768))) {
594 break; 370 if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
595 case 640: 371 }
596 if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth]; 372 break;
597 else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth]; 373 case 640:
598 break; 374 if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
599 case 720: 375 else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
600 if(VDisplay == 480) ModeIndex = ModeIndex_720x480[Depth]; 376 break;
601 else if(VDisplay == 576) ModeIndex = ModeIndex_720x576[Depth]; 377 case 720:
602 break; 378 if(VDisplay == 480) ModeIndex = ModeIndex_720x480[Depth];
603 case 768: 379 else if(VDisplay == 576) ModeIndex = ModeIndex_720x576[Depth];
604 if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth]; 380 break;
605 break; 381 case 768:
606 case 800: 382 if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
607 if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth]; 383 break;
608 else if(VDisplay == 480) ModeIndex = ModeIndex_800x480[Depth]; 384 case 800:
609 break; 385 if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
610 case 848: 386 else if(VDisplay == 480) ModeIndex = ModeIndex_800x480[Depth];
611 if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth]; 387 break;
612 break; 388 case 848:
613 case 856: 389 if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
614 if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth]; 390 break;
615 break; 391 case 856:
616 case 960: 392 if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
617 if(VGAEngine == SIS_315_VGA) { 393 break;
618 if(VDisplay == 540) ModeIndex = ModeIndex_960x540[Depth]; 394 case 960:
619 else if(VDisplay == 600) ModeIndex = ModeIndex_960x600[Depth]; 395 if(VGAEngine == SIS_315_VGA) {
620 } 396 if(VDisplay == 540) ModeIndex = ModeIndex_960x540[Depth];
621 break; 397 else if(VDisplay == 600) ModeIndex = ModeIndex_960x600[Depth];
622 case 1024: 398 }
623 if(VDisplay == 576) ModeIndex = ModeIndex_1024x576[Depth]; 399 break;
624 else if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth]; 400 case 1024:
625 else if(VGAEngine == SIS_300_VGA) { 401 if(VDisplay == 576) ModeIndex = ModeIndex_1024x576[Depth];
626 if(VDisplay == 600) ModeIndex = ModeIndex_1024x600[Depth]; 402 else if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
627 } 403 else if(VGAEngine == SIS_300_VGA) {
628 break; 404 if(VDisplay == 600) ModeIndex = ModeIndex_1024x600[Depth];
629 case 1152: 405 }
630 if(VDisplay == 864) ModeIndex = ModeIndex_1152x864[Depth]; 406 break;
631 if(VGAEngine == SIS_300_VGA) { 407 case 1152:
632 if(VDisplay == 768) ModeIndex = ModeIndex_1152x768[Depth]; 408 if(VDisplay == 864) ModeIndex = ModeIndex_1152x864[Depth];
633 } 409 if(VGAEngine == SIS_300_VGA) {
634 break; 410 if(VDisplay == 768) ModeIndex = ModeIndex_1152x768[Depth];
635 case 1280: 411 }
636 switch(VDisplay) { 412 break;
637 case 720: 413 case 1280:
638 ModeIndex = ModeIndex_1280x720[Depth]; 414 switch(VDisplay) {
639 break; 415 case 720:
640 case 768: 416 ModeIndex = ModeIndex_1280x720[Depth];
641 if(VGAEngine == SIS_300_VGA) { 417 break;
642 ModeIndex = ModeIndex_300_1280x768[Depth]; 418 case 768:
643 } else { 419 if(VGAEngine == SIS_300_VGA) {
644 ModeIndex = ModeIndex_310_1280x768[Depth]; 420 ModeIndex = ModeIndex_300_1280x768[Depth];
645 } 421 } else {
646 break; 422 ModeIndex = ModeIndex_310_1280x768[Depth];
647 case 800: 423 }
648 if(VGAEngine == SIS_315_VGA) { 424 break;
649 ModeIndex = ModeIndex_1280x800[Depth]; 425 case 800:
650 } 426 if(VGAEngine == SIS_315_VGA) {
651 break; 427 ModeIndex = ModeIndex_1280x800[Depth];
652 case 960: 428 }
653 ModeIndex = ModeIndex_1280x960[Depth]; 429 break;
654 break; 430 case 854:
655 case 1024: 431 if(VGAEngine == SIS_315_VGA) {
656 ModeIndex = ModeIndex_1280x1024[Depth]; 432 ModeIndex = ModeIndex_1280x854[Depth];
657 break; 433 }
658 } 434 break;
659 break; 435 case 960:
660 case 1360: 436 ModeIndex = ModeIndex_1280x960[Depth];
661 if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth]; 437 break;
662 if(VGAEngine == SIS_300_VGA) { 438 case 1024:
663 if(VDisplay == 1024) ModeIndex = ModeIndex_300_1360x1024[Depth]; 439 ModeIndex = ModeIndex_1280x1024[Depth];
664 } 440 break;
665 break; 441 }
666 case 1400: 442 break;
667 if(VGAEngine == SIS_315_VGA) { 443 case 1360:
668 if(VDisplay == 1050) { 444 if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
669 ModeIndex = ModeIndex_1400x1050[Depth]; 445 if(VGAEngine == SIS_300_VGA) {
670 } 446 if(VDisplay == 1024) ModeIndex = ModeIndex_300_1360x1024[Depth];
671 } 447 }
672 break; 448 break;
673 case 1600: 449 case 1400:
674 if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth]; 450 if(VGAEngine == SIS_315_VGA) {
675 break; 451 if(VDisplay == 1050) {
676 case 1680: 452 ModeIndex = ModeIndex_1400x1050[Depth];
677 if(VGAEngine == SIS_315_VGA) { 453 }
678 if(VDisplay == 1050) ModeIndex = ModeIndex_1680x1050[Depth]; 454 }
679 } 455 break;
680 break; 456 case 1600:
681 case 1920: 457 if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
682 if(VDisplay == 1440) ModeIndex = ModeIndex_1920x1440[Depth]; 458 break;
683 else if(VGAEngine == SIS_315_VGA) { 459 case 1680:
684 if(VDisplay == 1080) ModeIndex = ModeIndex_1920x1080[Depth]; 460 if(VGAEngine == SIS_315_VGA) {
685 } 461 if(VDisplay == 1050) ModeIndex = ModeIndex_1680x1050[Depth];
686 break; 462 }
687 case 2048: 463 break;
688 if(VDisplay == 1536) { 464 case 1920:
689 if(VGAEngine == SIS_300_VGA) { 465 if(VDisplay == 1440) ModeIndex = ModeIndex_1920x1440[Depth];
690 ModeIndex = ModeIndex_300_2048x1536[Depth]; 466 else if(VGAEngine == SIS_315_VGA) {
691 } else { 467 if(VDisplay == 1080) ModeIndex = ModeIndex_1920x1080[Depth];
692 ModeIndex = ModeIndex_310_2048x1536[Depth]; 468 }
693 } 469 break;
694 } 470 case 2048:
695 break; 471 if(VDisplay == 1536) {
472 if(VGAEngine == SIS_300_VGA) {
473 ModeIndex = ModeIndex_300_2048x1536[Depth];
474 } else {
475 ModeIndex = ModeIndex_310_2048x1536[Depth];
476 }
477 }
478 break;
696 } 479 }
697 480
698 return(ModeIndex); 481 return ModeIndex;
699} 482}
700#endif
701 483
702USHORT 484unsigned short
703SiS_GetModeID_LCD(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, 485SiS_GetModeID_LCD(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay,
704 int Depth, BOOLEAN FSTN, USHORT CustomT, int LCDwidth, int LCDheight) 486 int Depth, BOOLEAN FSTN, unsigned short CustomT, int LCDwidth, int LCDheight,
487 unsigned int VBFlags2)
705{ 488{
706 USHORT ModeIndex = 0; 489 unsigned short ModeIndex = 0;
707 490
708 if(VBFlags & (VB_LVDS | VB_30xBDH)) { 491 if(VBFlags2 & (VB2_LVDS | VB2_30xBDH)) {
709 492
710 switch(HDisplay) 493 switch(HDisplay)
711 { 494 {
712 case 320: 495 case 320:
713 if(CustomT != CUT_PANEL848) { 496 if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856)) {
714 if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth]; 497 if(VDisplay == 200) {
715 else if(VDisplay == 240) { 498 if(!FSTN) ModeIndex = ModeIndex_320x200[Depth];
499 } else if(VDisplay == 240) {
716 if(!FSTN) ModeIndex = ModeIndex_320x240[Depth]; 500 if(!FSTN) ModeIndex = ModeIndex_320x240[Depth];
717 else if(VGAEngine == SIS_315_VGA) { 501 else if(VGAEngine == SIS_315_VGA) {
718 ModeIndex = ModeIndex_320x240_FSTN[Depth]; 502 ModeIndex = ModeIndex_320x240_FSTN[Depth];
719 } 503 }
720 } 504 }
721 } 505 }
722 break; 506 break;
723 case 400: 507 case 400:
724 if(CustomT != CUT_PANEL848) { 508 if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856)) {
725 if(!((VGAEngine == SIS_300_VGA) && (VBFlags & VB_TRUMPION))) { 509 if(!((VGAEngine == SIS_300_VGA) && (VBFlags2 & VB2_TRUMPION))) {
726 if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth]; 510 if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
727 } 511 }
728 } 512 }
729 break; 513 break;
730 case 512: 514 case 512:
731 if(CustomT != CUT_PANEL848) { 515 if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856)) {
732 if(!((VGAEngine == SIS_300_VGA) && (VBFlags & VB_TRUMPION))) { 516 if(!((VGAEngine == SIS_300_VGA) && (VBFlags2 & VB2_TRUMPION))) {
733 if(LCDwidth >= 1024 && LCDwidth != 1152 && LCDheight >= 768) { 517 if(LCDwidth >= 1024 && LCDwidth != 1152 && LCDheight >= 768) {
734 if(VDisplay == 384) { 518 if(VDisplay == 384) {
735 ModeIndex = ModeIndex_512x384[Depth]; 519 ModeIndex = ModeIndex_512x384[Depth];
@@ -739,9 +523,10 @@ SiS_GetModeID_LCD(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay,
739 } 523 }
740 break; 524 break;
741 case 640: 525 case 640:
742 if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth]; 526 if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
743 else if(VDisplay == 400) { 527 else if(VDisplay == 400) {
744 if(CustomT != CUT_PANEL848) ModeIndex = ModeIndex_640x400[Depth]; 528 if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856))
529 ModeIndex = ModeIndex_640x400[Depth];
745 } 530 }
746 break; 531 break;
747 case 800: 532 case 800:
@@ -752,6 +537,11 @@ SiS_GetModeID_LCD(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay,
752 if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth]; 537 if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
753 } 538 }
754 break; 539 break;
540 case 856:
541 if(CustomT == CUT_PANEL856) {
542 if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
543 }
544 break;
755 case 1024: 545 case 1024:
756 if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth]; 546 if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
757 else if(VGAEngine == SIS_300_VGA) { 547 else if(VGAEngine == SIS_300_VGA) {
@@ -762,7 +552,7 @@ SiS_GetModeID_LCD(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay,
762 break; 552 break;
763 case 1152: 553 case 1152:
764 if(VGAEngine == SIS_300_VGA) { 554 if(VGAEngine == SIS_300_VGA) {
765 if((VDisplay == 768) && (LCDheight == 768)) { 555 if((VDisplay == 768) && (LCDheight == 768)) {
766 ModeIndex = ModeIndex_1152x768[Depth]; 556 ModeIndex = ModeIndex_1152x768[Depth];
767 } 557 }
768 } 558 }
@@ -770,49 +560,49 @@ SiS_GetModeID_LCD(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay,
770 case 1280: 560 case 1280:
771 if(VDisplay == 1024) ModeIndex = ModeIndex_1280x1024[Depth]; 561 if(VDisplay == 1024) ModeIndex = ModeIndex_1280x1024[Depth];
772 else if(VGAEngine == SIS_315_VGA) { 562 else if(VGAEngine == SIS_315_VGA) {
773 if((VDisplay == 768) && (LCDheight == 768)) { 563 if((VDisplay == 768) && (LCDheight == 768)) {
774 ModeIndex = ModeIndex_310_1280x768[Depth]; 564 ModeIndex = ModeIndex_310_1280x768[Depth];
775 } 565 }
776 } 566 }
777 break; 567 break;
778 case 1360: 568 case 1360:
779 if(VGAEngine == SIS_300_VGA) { 569 if(VGAEngine == SIS_300_VGA) {
780 if(CustomT == CUT_BARCO1366) { 570 if(CustomT == CUT_BARCO1366) {
781 if(VDisplay == 1024) ModeIndex = ModeIndex_300_1360x1024[Depth]; 571 if(VDisplay == 1024) ModeIndex = ModeIndex_300_1360x1024[Depth];
782 } 572 }
783 } 573 }
784 if(CustomT == CUT_PANEL848) { 574 if(CustomT == CUT_PANEL848) {
785 if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth]; 575 if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
786 } 576 }
787 break; 577 break;
788 case 1400: 578 case 1400:
789 if(VGAEngine == SIS_315_VGA) { 579 if(VGAEngine == SIS_315_VGA) {
790 if(VDisplay == 1050) ModeIndex = ModeIndex_1400x1050[Depth]; 580 if(VDisplay == 1050) ModeIndex = ModeIndex_1400x1050[Depth];
791 } 581 }
792 break; 582 break;
793 case 1600: 583 case 1600:
794 if(VGAEngine == SIS_315_VGA) { 584 if(VGAEngine == SIS_315_VGA) {
795 if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth]; 585 if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
796 } 586 }
797 break; 587 break;
798 } 588 }
799 589
800 } else if(VBFlags & VB_SISBRIDGE) { 590 } else if(VBFlags2 & VB2_SISBRIDGE) {
801 591
802 switch(HDisplay) 592 switch(HDisplay)
803 { 593 {
804 case 320: 594 case 320:
805 if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth]; 595 if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth];
806 else if(VDisplay == 240) ModeIndex = ModeIndex_320x240[Depth]; 596 else if(VDisplay == 240) ModeIndex = ModeIndex_320x240[Depth];
807 break; 597 break;
808 case 400: 598 case 400:
809 if(LCDwidth >= 800 && LCDheight >= 600) { 599 if(LCDwidth >= 800 && LCDheight >= 600) {
810 if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth]; 600 if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
811 } 601 }
812 break; 602 break;
813 case 512: 603 case 512:
814 if(LCDwidth >= 1024 && LCDheight >= 768 && LCDwidth != 1152) { 604 if(LCDwidth >= 1024 && LCDheight >= 768 && LCDwidth != 1152) {
815 if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth]; 605 if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
816 } 606 }
817 break; 607 break;
818 case 640: 608 case 640:
@@ -821,96 +611,115 @@ SiS_GetModeID_LCD(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay,
821 break; 611 break;
822 case 720: 612 case 720:
823 if(VGAEngine == SIS_315_VGA) { 613 if(VGAEngine == SIS_315_VGA) {
824 if(VDisplay == 480) ModeIndex = ModeIndex_720x480[Depth]; 614 if(VDisplay == 480) ModeIndex = ModeIndex_720x480[Depth];
825 else if(VDisplay == 576) ModeIndex = ModeIndex_720x576[Depth]; 615 else if(VDisplay == 576) ModeIndex = ModeIndex_720x576[Depth];
826 } 616 }
827 break; 617 break;
828 case 768: 618 case 768:
829 if(VGAEngine == SIS_315_VGA) { 619 if(VGAEngine == SIS_315_VGA) {
830 if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth]; 620 if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
831 } 621 }
832 break; 622 break;
833 case 800: 623 case 800:
834 if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth]; 624 if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
835 if(VGAEngine == SIS_315_VGA) { 625 if(VGAEngine == SIS_315_VGA) {
836 if(VDisplay == 480) ModeIndex = ModeIndex_800x480[Depth]; 626 if(VDisplay == 480) ModeIndex = ModeIndex_800x480[Depth];
837 } 627 }
838 break; 628 break;
839 case 848: 629 case 848:
840 if(VGAEngine == SIS_315_VGA) { 630 if(VGAEngine == SIS_315_VGA) {
841 if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth]; 631 if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
842 } 632 }
843 break; 633 break;
844 case 856: 634 case 856:
845 if(VGAEngine == SIS_315_VGA) { 635 if(VGAEngine == SIS_315_VGA) {
846 if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth]; 636 if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
847 } 637 }
848 break; 638 break;
849 case 960: 639 case 960:
850 if(VGAEngine == SIS_315_VGA) { 640 if(VGAEngine == SIS_315_VGA) {
851 if(VDisplay == 540) ModeIndex = ModeIndex_960x540[Depth]; 641 if(VDisplay == 540) ModeIndex = ModeIndex_960x540[Depth];
852 else if(VDisplay == 600) ModeIndex = ModeIndex_960x600[Depth]; 642 else if(VDisplay == 600) ModeIndex = ModeIndex_960x600[Depth];
853 } 643 }
854 break; 644 break;
855 case 1024: 645 case 1024:
856 if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth]; 646 if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
857 if(VGAEngine == SIS_315_VGA) { 647 if(VGAEngine == SIS_315_VGA) {
858 if(VDisplay == 576) ModeIndex = ModeIndex_1024x576[Depth]; 648 if(VDisplay == 576) ModeIndex = ModeIndex_1024x576[Depth];
859 } 649 }
860 break; 650 break;
861 case 1152: 651 case 1152:
862 if(VGAEngine == SIS_315_VGA) { 652 if(VGAEngine == SIS_315_VGA) {
863 if(VDisplay == 864) ModeIndex = ModeIndex_1152x864[Depth]; 653 if(VDisplay == 864) ModeIndex = ModeIndex_1152x864[Depth];
864 } 654 }
865 break; 655 break;
866 case 1280: 656 case 1280:
867 switch(VDisplay) { 657 switch(VDisplay) {
868 case 720: 658 case 720:
869 ModeIndex = ModeIndex_1280x720[Depth]; 659 ModeIndex = ModeIndex_1280x720[Depth];
870 case 768: 660 case 768:
871 if(VGAEngine == SIS_300_VGA) { 661 if(VGAEngine == SIS_300_VGA) {
872 ModeIndex = ModeIndex_300_1280x768[Depth]; 662 ModeIndex = ModeIndex_300_1280x768[Depth];
873 } else { 663 } else {
874 ModeIndex = ModeIndex_310_1280x768[Depth]; 664 ModeIndex = ModeIndex_310_1280x768[Depth];
875 } 665 }
876 break; 666 break;
877 case 800: 667 case 800:
878 if(VGAEngine == SIS_315_VGA) { 668 if(VGAEngine == SIS_315_VGA) {
879 ModeIndex = ModeIndex_1280x800[Depth]; 669 ModeIndex = ModeIndex_1280x800[Depth];
880 } 670 }
881 break; 671 break;
672 case 854:
673 if(VGAEngine == SIS_315_VGA) {
674 ModeIndex = ModeIndex_1280x854[Depth];
675 }
676 break;
882 case 960: 677 case 960:
883 ModeIndex = ModeIndex_1280x960[Depth]; 678 ModeIndex = ModeIndex_1280x960[Depth];
884 break; 679 break;
885 case 1024: 680 case 1024:
886 ModeIndex = ModeIndex_1280x1024[Depth]; 681 ModeIndex = ModeIndex_1280x1024[Depth];
887 break; 682 break;
888 } 683 }
889 break; 684 break;
890 case 1360: 685 case 1360:
891 if(VGAEngine == SIS_315_VGA) { 686 if(VGAEngine == SIS_315_VGA) { /* OVER1280 only? */
892 if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth]; 687 if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
893 } 688 }
894 break; 689 break;
895 case 1400: 690 case 1400:
896 if(VGAEngine == SIS_315_VGA) { 691 if(VGAEngine == SIS_315_VGA) {
897 if(VBFlags & (VB_301C | VB_302LV | VB_302ELV)) { 692 if(VBFlags2 & VB2_LCDOVER1280BRIDGE) {
898 if(VDisplay == 1050) ModeIndex = ModeIndex_1400x1050[Depth]; 693 if(VDisplay == 1050) ModeIndex = ModeIndex_1400x1050[Depth];
899 } 694 }
900 } 695 }
901 break; 696 break;
902 case 1600: 697 case 1600:
903 if(VGAEngine == SIS_315_VGA) { 698 if(VGAEngine == SIS_315_VGA) {
904 if(VBFlags & (VB_301C | VB_302LV | VB_302ELV)) { 699 if(VBFlags2 & VB2_LCDOVER1280BRIDGE) {
905 if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth]; 700 if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
906 } 701 }
907 } 702 }
908 break; 703 break;
909#ifndef VB_FORBID_CRT2LCD_OVER_1600 704#ifndef VB_FORBID_CRT2LCD_OVER_1600
910 case 1680: 705 case 1680:
911 if(VGAEngine == SIS_315_VGA) { 706 if(VGAEngine == SIS_315_VGA) {
912 if(VBFlags & (VB_301C | VB_302LV | VB_302ELV)) { 707 if(VBFlags2 & VB2_LCDOVER1280BRIDGE) {
913 if(VDisplay == 1050) ModeIndex = ModeIndex_1680x1050[Depth]; 708 if(VDisplay == 1050) ModeIndex = ModeIndex_1680x1050[Depth];
709 }
710 }
711 break;
712 case 1920:
713 if(VGAEngine == SIS_315_VGA) {
714 if(VBFlags2 & VB2_LCDOVER1600BRIDGE) {
715 if(VDisplay == 1440) ModeIndex = ModeIndex_1920x1440[Depth];
716 }
717 }
718 break;
719 case 2048:
720 if(VGAEngine == SIS_315_VGA) {
721 if(VBFlags2 & VB2_LCDOVER1600BRIDGE) {
722 if(VDisplay == 1536) ModeIndex = ModeIndex_310_2048x1536[Depth];
914 } 723 }
915 } 724 }
916 break; 725 break;
@@ -921,16 +730,17 @@ SiS_GetModeID_LCD(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay,
921 return ModeIndex; 730 return ModeIndex;
922} 731}
923 732
924USHORT 733unsigned short
925SiS_GetModeID_TV(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int Depth) 734SiS_GetModeID_TV(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay, int Depth,
735 unsigned int VBFlags2)
926{ 736{
927 USHORT ModeIndex = 0; 737 unsigned short ModeIndex = 0;
928 738
929 if(VBFlags & VB_CHRONTEL) { 739 if(VBFlags2 & VB2_CHRONTEL) {
930 740
931 switch(HDisplay) 741 switch(HDisplay)
932 { 742 {
933 case 512: 743 case 512:
934 if(VGAEngine == SIS_315_VGA) { 744 if(VGAEngine == SIS_315_VGA) {
935 if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth]; 745 if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
936 } 746 }
@@ -944,27 +754,27 @@ SiS_GetModeID_TV(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int D
944 break; 754 break;
945 case 1024: 755 case 1024:
946 if(VGAEngine == SIS_315_VGA) { 756 if(VGAEngine == SIS_315_VGA) {
947 if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth]; 757 if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
948 } 758 }
949 break; 759 break;
950 } 760 }
951 761
952 } else if(VBFlags & VB_SISTVBRIDGE) { 762 } else if(VBFlags2 & VB2_SISTVBRIDGE) {
953 763
954 switch(HDisplay) 764 switch(HDisplay)
955 { 765 {
956 case 320: 766 case 320:
957 if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth]; 767 if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth];
958 else if(VDisplay == 240) ModeIndex = ModeIndex_320x240[Depth]; 768 else if(VDisplay == 240) ModeIndex = ModeIndex_320x240[Depth];
959 break; 769 break;
960 case 400: 770 case 400:
961 if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth]; 771 if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
962 break; 772 break;
963 case 512: 773 case 512:
964 if( ((VBFlags & TV_YPBPR) && (VBFlags & (TV_YPBPR750P | TV_YPBPR1080I))) || 774 if( ((VBFlags & TV_YPBPR) && (VBFlags & (TV_YPBPR750P | TV_YPBPR1080I))) ||
965 (VBFlags & TV_HIVISION) || 775 (VBFlags & TV_HIVISION) ||
966 ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) ) { 776 ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) ) {
967 if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth]; 777 if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
968 } 778 }
969 break; 779 break;
970 case 640: 780 case 640:
@@ -973,34 +783,34 @@ SiS_GetModeID_TV(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int D
973 break; 783 break;
974 case 720: 784 case 720:
975 if((!(VBFlags & TV_HIVISION)) && (!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)))) { 785 if((!(VBFlags & TV_HIVISION)) && (!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)))) {
976 if(VDisplay == 480) { 786 if(VDisplay == 480) {
977 ModeIndex = ModeIndex_720x480[Depth]; 787 ModeIndex = ModeIndex_720x480[Depth];
978 } else if(VDisplay == 576) { 788 } else if(VDisplay == 576) {
979 if( ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR750P)) || 789 if( ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR750P)) ||
980 ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) ) 790 ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) )
981 ModeIndex = ModeIndex_720x576[Depth]; 791 ModeIndex = ModeIndex_720x576[Depth];
982 } 792 }
983 } 793 }
984 break; 794 break;
985 case 768: 795 case 768:
986 if((!(VBFlags & TV_HIVISION)) && (!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)))) { 796 if((!(VBFlags & TV_HIVISION)) && (!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)))) {
987 if( ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR750P)) || 797 if( ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR750P)) ||
988 ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) ) { 798 ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) ) {
989 if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth]; 799 if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
990 } 800 }
991 } 801 }
992 break; 802 break;
993 case 800: 803 case 800:
994 if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth]; 804 if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
995 else if(VDisplay == 480) { 805 else if(VDisplay == 480) {
996 if((VBFlags & TV_HIVISION) || ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I))) { 806 if(!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR750P))) {
997 ModeIndex = ModeIndex_800x480[Depth]; 807 ModeIndex = ModeIndex_800x480[Depth];
998 } 808 }
999 } 809 }
1000 break; 810 break;
1001 case 960: 811 case 960:
1002 if(VGAEngine == SIS_315_VGA) { 812 if(VGAEngine == SIS_315_VGA) {
1003 if(VDisplay == 600) { 813 if(VDisplay == 600) {
1004 if((VBFlags & TV_HIVISION) || ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I))) { 814 if((VBFlags & TV_HIVISION) || ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I))) {
1005 ModeIndex = ModeIndex_960x600[Depth]; 815 ModeIndex = ModeIndex_960x600[Depth];
1006 } 816 }
@@ -1009,25 +819,28 @@ SiS_GetModeID_TV(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int D
1009 break; 819 break;
1010 case 1024: 820 case 1024:
1011 if(VDisplay == 768) { 821 if(VDisplay == 768) {
1012 if(VBFlags & (VB_301B|VB_301C|VB_302B|VB_301LV|VB_302LV|VB_302ELV)) { 822 if(VBFlags2 & VB2_30xBLV) {
1013 ModeIndex = ModeIndex_1024x768[Depth]; 823 ModeIndex = ModeIndex_1024x768[Depth];
1014 } 824 }
1015 } else if(VDisplay == 576) { 825 } else if(VDisplay == 576) {
1016 if((VBFlags & TV_HIVISION) || ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I))) { 826 if( (VBFlags & TV_HIVISION) ||
827 ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)) ||
828 ((VBFlags2 & VB2_30xBLV) &&
829 ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL))) ) {
1017 ModeIndex = ModeIndex_1024x576[Depth]; 830 ModeIndex = ModeIndex_1024x576[Depth];
1018 } 831 }
1019 } 832 }
1020 break; 833 break;
1021 case 1280: 834 case 1280:
1022 if(VDisplay == 720) { 835 if(VDisplay == 720) {
1023 if((VBFlags & TV_HIVISION) || 836 if((VBFlags & TV_HIVISION) ||
1024 ((VBFlags & TV_YPBPR) && (VBFlags & (TV_YPBPR1080I | TV_YPBPR750P)))) { 837 ((VBFlags & TV_YPBPR) && (VBFlags & (TV_YPBPR1080I | TV_YPBPR750P)))) {
1025 ModeIndex = ModeIndex_1280x720[Depth]; 838 ModeIndex = ModeIndex_1280x720[Depth];
1026 } 839 }
1027 } else if(VDisplay == 1024) { 840 } else if(VDisplay == 1024) {
1028 if((VBFlags & TV_HIVISION) || 841 if((VBFlags & TV_HIVISION) ||
1029 ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I))) { 842 ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I))) {
1030 ModeIndex = ModeIndex_1280x1024[Depth]; 843 ModeIndex = ModeIndex_1280x1024[Depth];
1031 } 844 }
1032 } 845 }
1033 break; 846 break;
@@ -1036,99 +849,31 @@ SiS_GetModeID_TV(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int D
1036 return ModeIndex; 849 return ModeIndex;
1037} 850}
1038 851
1039USHORT 852unsigned short
1040SiS_GetModeID_VGA2(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int Depth) 853SiS_GetModeID_VGA2(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay, int Depth,
854 unsigned int VBFlags2)
1041{ 855{
1042 USHORT ModeIndex = 0; 856 if(!(VBFlags2 & VB2_SISVGA2BRIDGE)) return 0;
1043 857
1044 if(!(VBFlags & (VB_301|VB_301B|VB_301C|VB_302B))) return 0; 858 if(HDisplay >= 1920) return 0;
1045 859
1046 switch(HDisplay) 860 switch(HDisplay)
1047 { 861 {
1048 case 320:
1049 if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth];
1050 else if(VDisplay == 240) ModeIndex = ModeIndex_320x240[Depth];
1051 break;
1052 case 400:
1053 if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
1054 break;
1055 case 512:
1056 if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
1057 break;
1058 case 640:
1059 if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
1060 else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
1061 break;
1062 case 720:
1063 if(VDisplay == 480) ModeIndex = ModeIndex_720x480[Depth];
1064 else if(VDisplay == 576) ModeIndex = ModeIndex_720x576[Depth];
1065 break;
1066 case 768:
1067 if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
1068 break;
1069 case 800:
1070 if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
1071 else if(VDisplay == 480) ModeIndex = ModeIndex_800x480[Depth];
1072 break;
1073 case 848:
1074 if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
1075 break;
1076 case 856:
1077 if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
1078 break;
1079 case 960:
1080 if(VGAEngine == SIS_315_VGA) {
1081 if(VDisplay == 540) ModeIndex = ModeIndex_960x540[Depth];
1082 else if(VDisplay == 600) ModeIndex = ModeIndex_960x600[Depth];
1083 }
1084 break;
1085 case 1024:
1086 if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
1087 else if(VDisplay == 576) ModeIndex = ModeIndex_1024x576[Depth];
1088 break;
1089 case 1152:
1090 if(VDisplay == 864) ModeIndex = ModeIndex_1152x864[Depth];
1091 else if(VGAEngine == SIS_300_VGA) {
1092 if(VDisplay == 768) ModeIndex = ModeIndex_1152x768[Depth];
1093 }
1094 break;
1095 case 1280:
1096 if(VDisplay == 768) {
1097 if(VGAEngine == SIS_300_VGA) {
1098 ModeIndex = ModeIndex_300_1280x768[Depth];
1099 } else {
1100 ModeIndex = ModeIndex_310_1280x768[Depth];
1101 }
1102 } else if(VDisplay == 1024) ModeIndex = ModeIndex_1280x1024[Depth];
1103 else if(VDisplay == 720) ModeIndex = ModeIndex_1280x720[Depth];
1104 else if(VDisplay == 800) ModeIndex = ModeIndex_1280x800[Depth];
1105 else if(VDisplay == 960) ModeIndex = ModeIndex_1280x960[Depth];
1106 break;
1107 case 1360:
1108 if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
1109 break;
1110 case 1400:
1111 if(VGAEngine == SIS_315_VGA) {
1112 if(VDisplay == 1050) ModeIndex = ModeIndex_1400x1050[Depth];
1113 }
1114 break;
1115 case 1600: 862 case 1600:
1116 if(VGAEngine == SIS_315_VGA) { 863 if(VDisplay == 1200) {
1117 if(VBFlags & (VB_301B|VB_301C|VB_302B)) { 864 if(VGAEngine != SIS_315_VGA) return 0;
1118 if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth]; 865 if(!(VBFlags2 & VB2_30xB)) return 0;
1119 }
1120 } 866 }
1121 break; 867 break;
1122 case 1680: 868 case 1680:
1123 if(VGAEngine == SIS_315_VGA) { 869 if(VDisplay == 1050) {
1124 if(VBFlags & (VB_301B|VB_301C|VB_302B)) { 870 if(VGAEngine != SIS_315_VGA) return 0;
1125 if(VDisplay == 1050) ModeIndex = ModeIndex_1680x1050[Depth]; 871 if(!(VBFlags2 & VB2_30xB)) return 0;
1126 }
1127 } 872 }
1128 break; 873 break;
1129 } 874 }
1130 875
1131 return ModeIndex; 876 return SiS_GetModeID(VGAEngine, 0, HDisplay, VDisplay, Depth, FALSE, 0, 0);
1132} 877}
1133 878
1134 879
@@ -1137,83 +882,83 @@ SiS_GetModeID_VGA2(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int
1137/*********************************************/ 882/*********************************************/
1138 883
1139void 884void
1140SiS_SetReg(SISIOADDRESS port, USHORT index, USHORT data) 885SiS_SetReg(SISIOADDRESS port, unsigned short index, unsigned short data)
1141{ 886{
1142 OutPortByte(port,index); 887 OutPortByte(port, index);
1143 OutPortByte(port + 1,data); 888 OutPortByte(port + 1, data);
1144} 889}
1145 890
1146void 891void
1147SiS_SetRegByte(SISIOADDRESS port, USHORT data) 892SiS_SetRegByte(SISIOADDRESS port, unsigned short data)
1148{ 893{
1149 OutPortByte(port,data); 894 OutPortByte(port, data);
1150} 895}
1151 896
1152void 897void
1153SiS_SetRegShort(SISIOADDRESS port, USHORT data) 898SiS_SetRegShort(SISIOADDRESS port, unsigned short data)
1154{ 899{
1155 OutPortWord(port,data); 900 OutPortWord(port, data);
1156} 901}
1157 902
1158void 903void
1159SiS_SetRegLong(SISIOADDRESS port, ULONG data) 904SiS_SetRegLong(SISIOADDRESS port, unsigned int data)
1160{ 905{
1161 OutPortLong(port,data); 906 OutPortLong(port, data);
1162} 907}
1163 908
1164UCHAR 909unsigned char
1165SiS_GetReg(SISIOADDRESS port, USHORT index) 910SiS_GetReg(SISIOADDRESS port, unsigned short index)
1166{ 911{
1167 OutPortByte(port,index); 912 OutPortByte(port, index);
1168 return(InPortByte(port + 1)); 913 return(InPortByte(port + 1));
1169} 914}
1170 915
1171UCHAR 916unsigned char
1172SiS_GetRegByte(SISIOADDRESS port) 917SiS_GetRegByte(SISIOADDRESS port)
1173{ 918{
1174 return(InPortByte(port)); 919 return(InPortByte(port));
1175} 920}
1176 921
1177USHORT 922unsigned short
1178SiS_GetRegShort(SISIOADDRESS port) 923SiS_GetRegShort(SISIOADDRESS port)
1179{ 924{
1180 return(InPortWord(port)); 925 return(InPortWord(port));
1181} 926}
1182 927
1183ULONG 928unsigned int
1184SiS_GetRegLong(SISIOADDRESS port) 929SiS_GetRegLong(SISIOADDRESS port)
1185{ 930{
1186 return(InPortLong(port)); 931 return(InPortLong(port));
1187} 932}
1188 933
1189void 934void
1190SiS_SetRegANDOR(SISIOADDRESS Port,USHORT Index,USHORT DataAND,USHORT DataOR) 935SiS_SetRegANDOR(SISIOADDRESS Port, unsigned short Index, unsigned short DataAND, unsigned short DataOR)
1191{ 936{
1192 USHORT temp; 937 unsigned short temp;
1193 938
1194 temp = SiS_GetReg(Port,Index); 939 temp = SiS_GetReg(Port, Index);
1195 temp = (temp & (DataAND)) | DataOR; 940 temp = (temp & (DataAND)) | DataOR;
1196 SiS_SetReg(Port,Index,temp); 941 SiS_SetReg(Port, Index, temp);
1197} 942}
1198 943
1199void 944void
1200SiS_SetRegAND(SISIOADDRESS Port,USHORT Index,USHORT DataAND) 945SiS_SetRegAND(SISIOADDRESS Port, unsigned short Index, unsigned short DataAND)
1201{ 946{
1202 USHORT temp; 947 unsigned short temp;
1203 948
1204 temp = SiS_GetReg(Port,Index); 949 temp = SiS_GetReg(Port, Index);
1205 temp &= DataAND; 950 temp &= DataAND;
1206 SiS_SetReg(Port,Index,temp); 951 SiS_SetReg(Port, Index, temp);
1207} 952}
1208 953
1209void 954void
1210SiS_SetRegOR(SISIOADDRESS Port,USHORT Index,USHORT DataOR) 955SiS_SetRegOR(SISIOADDRESS Port, unsigned short Index, unsigned short DataOR)
1211{ 956{
1212 USHORT temp; 957 unsigned short temp;
1213 958
1214 temp = SiS_GetReg(Port,Index); 959 temp = SiS_GetReg(Port, Index);
1215 temp |= DataOR; 960 temp |= DataOR;
1216 SiS_SetReg(Port,Index,temp); 961 SiS_SetReg(Port, Index, temp);
1217} 962}
1218 963
1219/*********************************************/ 964/*********************************************/
@@ -1221,13 +966,13 @@ SiS_SetRegOR(SISIOADDRESS Port,USHORT Index,USHORT DataOR)
1221/*********************************************/ 966/*********************************************/
1222 967
1223void 968void
1224SiS_DisplayOn(SiS_Private *SiS_Pr) 969SiS_DisplayOn(struct SiS_Private *SiS_Pr)
1225{ 970{
1226 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x01,0xDF); 971 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x01,0xDF);
1227} 972}
1228 973
1229void 974void
1230SiS_DisplayOff(SiS_Private *SiS_Pr) 975SiS_DisplayOff(struct SiS_Private *SiS_Pr)
1231{ 976{
1232 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x01,0x20); 977 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x01,0x20);
1233} 978}
@@ -1238,7 +983,7 @@ SiS_DisplayOff(SiS_Private *SiS_Pr)
1238/*********************************************/ 983/*********************************************/
1239 984
1240void 985void
1241SiSRegInit(SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr) 986SiSRegInit(struct SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr)
1242{ 987{
1243 SiS_Pr->SiS_P3c4 = BaseAddr + 0x14; 988 SiS_Pr->SiS_P3c4 = BaseAddr + 0x14;
1244 SiS_Pr->SiS_P3d4 = BaseAddr + 0x24; 989 SiS_Pr->SiS_P3d4 = BaseAddr + 0x24;
@@ -1251,16 +996,17 @@ SiSRegInit(SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr)
1251 SiS_Pr->SiS_P3c8 = BaseAddr + 0x18; 996 SiS_Pr->SiS_P3c8 = BaseAddr + 0x18;
1252 SiS_Pr->SiS_P3c9 = BaseAddr + 0x19; 997 SiS_Pr->SiS_P3c9 = BaseAddr + 0x19;
1253 SiS_Pr->SiS_P3cb = BaseAddr + 0x1b; 998 SiS_Pr->SiS_P3cb = BaseAddr + 0x1b;
999 SiS_Pr->SiS_P3cc = BaseAddr + 0x1c;
1254 SiS_Pr->SiS_P3cd = BaseAddr + 0x1d; 1000 SiS_Pr->SiS_P3cd = BaseAddr + 0x1d;
1255 SiS_Pr->SiS_P3da = BaseAddr + 0x2a; 1001 SiS_Pr->SiS_P3da = BaseAddr + 0x2a;
1256 SiS_Pr->SiS_Part1Port = BaseAddr + SIS_CRT2_PORT_04; /* Digital video interface registers (LCD) */ 1002 SiS_Pr->SiS_Part1Port = BaseAddr + SIS_CRT2_PORT_04;
1257 SiS_Pr->SiS_Part2Port = BaseAddr + SIS_CRT2_PORT_10; /* 301 TV Encoder registers */ 1003 SiS_Pr->SiS_Part2Port = BaseAddr + SIS_CRT2_PORT_10;
1258 SiS_Pr->SiS_Part3Port = BaseAddr + SIS_CRT2_PORT_12; /* 301 Macrovision registers */ 1004 SiS_Pr->SiS_Part3Port = BaseAddr + SIS_CRT2_PORT_12;
1259 SiS_Pr->SiS_Part4Port = BaseAddr + SIS_CRT2_PORT_14; /* 301 VGA2 (and LCD) registers */ 1005 SiS_Pr->SiS_Part4Port = BaseAddr + SIS_CRT2_PORT_14;
1260 SiS_Pr->SiS_Part5Port = BaseAddr + SIS_CRT2_PORT_14 + 2; /* 301 palette address port registers */ 1006 SiS_Pr->SiS_Part5Port = BaseAddr + SIS_CRT2_PORT_14 + 2;
1261 SiS_Pr->SiS_DDC_Port = BaseAddr + 0x14; /* DDC Port ( = P3C4, SR11/0A) */ 1007 SiS_Pr->SiS_DDC_Port = BaseAddr + 0x14;
1262 SiS_Pr->SiS_VidCapt = BaseAddr + SIS_VIDEO_CAPTURE; 1008 SiS_Pr->SiS_VidCapt = BaseAddr + SIS_VIDEO_CAPTURE;
1263 SiS_Pr->SiS_VidPlay = BaseAddr + SIS_VIDEO_PLAYBACK; 1009 SiS_Pr->SiS_VidPlay = BaseAddr + SIS_VIDEO_PLAYBACK;
1264} 1010}
1265 1011
1266/*********************************************/ 1012/*********************************************/
@@ -1268,7 +1014,7 @@ SiSRegInit(SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr)
1268/*********************************************/ 1014/*********************************************/
1269 1015
1270static void 1016static void
1271SiS_GetSysFlags(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 1017SiS_GetSysFlags(struct SiS_Private *SiS_Pr)
1272{ 1018{
1273 unsigned char cr5f, temp1, temp2; 1019 unsigned char cr5f, temp1, temp2;
1274 1020
@@ -1276,9 +1022,9 @@ SiS_GetSysFlags(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
1276 /* (SR11 is used for DDC and in enable/disablebridge) */ 1022 /* (SR11 is used for DDC and in enable/disablebridge) */
1277 SiS_Pr->SiS_SensibleSR11 = FALSE; 1023 SiS_Pr->SiS_SensibleSR11 = FALSE;
1278 SiS_Pr->SiS_MyCR63 = 0x63; 1024 SiS_Pr->SiS_MyCR63 = 0x63;
1279 if(HwInfo->jChipType >= SIS_330) { 1025 if(SiS_Pr->ChipType >= SIS_330) {
1280 SiS_Pr->SiS_MyCR63 = 0x53; 1026 SiS_Pr->SiS_MyCR63 = 0x53;
1281 if(HwInfo->jChipType >= SIS_661) { 1027 if(SiS_Pr->ChipType >= SIS_661) {
1282 SiS_Pr->SiS_SensibleSR11 = TRUE; 1028 SiS_Pr->SiS_SensibleSR11 = TRUE;
1283 } 1029 }
1284 } 1030 }
@@ -1286,43 +1032,52 @@ SiS_GetSysFlags(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
1286 /* You should use the macros, not these flags directly */ 1032 /* You should use the macros, not these flags directly */
1287 1033
1288 SiS_Pr->SiS_SysFlags = 0; 1034 SiS_Pr->SiS_SysFlags = 0;
1289 if(HwInfo->jChipType == SIS_650) { 1035 if(SiS_Pr->ChipType == SIS_650) {
1290 cr5f = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0; 1036 cr5f = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0;
1291 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x5c,0x07); 1037 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x5c,0x07);
1292 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8; 1038 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
1293 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x5c,0xf8); 1039 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x5c,0xf8);
1294 temp2 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8; 1040 temp2 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
1295 if((!temp1) || (temp2)) { 1041 if((!temp1) || (temp2)) {
1296 switch(cr5f) { 1042 switch(cr5f) {
1297 case 0x80: 1043 case 0x80:
1298 case 0x90: 1044 case 0x90:
1299 case 0xc0: 1045 case 0xc0:
1300 SiS_Pr->SiS_SysFlags |= SF_IsM650; break; 1046 SiS_Pr->SiS_SysFlags |= SF_IsM650;
1047 break;
1301 case 0xa0: 1048 case 0xa0:
1302 case 0xb0: 1049 case 0xb0:
1303 case 0xe0: 1050 case 0xe0:
1304 SiS_Pr->SiS_SysFlags |= SF_Is651; break; 1051 SiS_Pr->SiS_SysFlags |= SF_Is651;
1052 break;
1305 } 1053 }
1306 } else { 1054 } else {
1307 switch(cr5f) { 1055 switch(cr5f) {
1308 case 0x90: 1056 case 0x90:
1309 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8; 1057 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
1310 switch(temp1) { 1058 switch(temp1) {
1311 case 0x00: SiS_Pr->SiS_SysFlags |= SF_IsM652; break; 1059 case 0x00: SiS_Pr->SiS_SysFlags |= SF_IsM652; break;
1312 case 0x40: SiS_Pr->SiS_SysFlags |= SF_IsM653; break; 1060 case 0x40: SiS_Pr->SiS_SysFlags |= SF_IsM653; break;
1313 default: SiS_Pr->SiS_SysFlags |= SF_IsM650; break; 1061 default: SiS_Pr->SiS_SysFlags |= SF_IsM650; break;
1314 } 1062 }
1315 break; 1063 break;
1316 case 0xb0: 1064 case 0xb0:
1317 SiS_Pr->SiS_SysFlags |= SF_Is652; break; 1065 SiS_Pr->SiS_SysFlags |= SF_Is652;
1066 break;
1318 default: 1067 default:
1319 SiS_Pr->SiS_SysFlags |= SF_IsM650; break; 1068 SiS_Pr->SiS_SysFlags |= SF_IsM650;
1069 break;
1320 } 1070 }
1321 } 1071 }
1322 } 1072 }
1323 if(HwInfo->jChipType == SIS_760) { 1073
1324 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x78); 1074 if(SiS_Pr->ChipType >= SIS_760 && SiS_Pr->ChipType <= SIS_761) {
1325 if(temp1 & 0x30) SiS_Pr->SiS_SysFlags |= SF_760LFB; 1075 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x78) & 0x30) {
1076 SiS_Pr->SiS_SysFlags |= SF_760LFB;
1077 }
1078 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0xf0) {
1079 SiS_Pr->SiS_SysFlags |= SF_760UMA;
1080 }
1326 } 1081 }
1327} 1082}
1328 1083
@@ -1331,18 +1086,20 @@ SiS_GetSysFlags(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
1331/*********************************************/ 1086/*********************************************/
1332 1087
1333static void 1088static void
1334SiSInitPCIetc(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 1089SiSInitPCIetc(struct SiS_Private *SiS_Pr)
1335{ 1090{
1336 switch(HwInfo->jChipType) { 1091 switch(SiS_Pr->ChipType) {
1092#ifdef SIS300
1337 case SIS_300: 1093 case SIS_300:
1338 case SIS_540: 1094 case SIS_540:
1339 case SIS_630: 1095 case SIS_630:
1340 case SIS_730: 1096 case SIS_730:
1341 /* Set - PCI LINEAR ADDRESSING ENABLE (0x80) 1097 /* Set - PCI LINEAR ADDRESSING ENABLE (0x80)
1342 * - RELOCATED VGA IO (0x20) 1098 * - RELOCATED VGA IO ENABLED (0x20)
1343 * - MMIO ENABLE (0x1) 1099 * - MMIO ENABLED (0x01)
1100 * Leave other bits untouched.
1344 */ 1101 */
1345 SiS_SetReg(SiS_Pr->SiS_P3c4,0x20,0xa1); 1102 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x20,0xa1);
1346 /* - Enable 2D (0x40) 1103 /* - Enable 2D (0x40)
1347 * - Enable 3D (0x02) 1104 * - Enable 3D (0x02)
1348 * - Enable 3D Vertex command fetch (0x10) ? 1105 * - Enable 3D Vertex command fetch (0x10) ?
@@ -1350,6 +1107,8 @@ SiSInitPCIetc(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
1350 */ 1107 */
1351 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x5A); 1108 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x5A);
1352 break; 1109 break;
1110#endif
1111#ifdef SIS315H
1353 case SIS_315H: 1112 case SIS_315H:
1354 case SIS_315: 1113 case SIS_315:
1355 case SIS_315PRO: 1114 case SIS_315PRO:
@@ -1362,21 +1121,30 @@ SiSInitPCIetc(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
1362 case SIS_760: 1121 case SIS_760:
1363 case SIS_761: 1122 case SIS_761:
1364 case SIS_340: 1123 case SIS_340:
1365 SiS_SetReg(SiS_Pr->SiS_P3c4,0x20,0xa1); 1124 case XGI_40:
1366 /* - Enable 2D (0x40) 1125 /* See above */
1367 * - Enable 3D (0x02) 1126 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x20,0xa1);
1127 /* - Enable 3D G/L transformation engine (0x80)
1128 * - Enable 2D (0x40)
1368 * - Enable 3D vertex command fetch (0x10) 1129 * - Enable 3D vertex command fetch (0x10)
1369 * - Enable 3D command parser (0x08) 1130 * - Enable 3D command parser (0x08)
1370 * - Enable 3D G/L transformation engine (0x80) 1131 * - Enable 3D (0x02)
1371 */ 1132 */
1372 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0xDA); 1133 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0xDA);
1373 break; 1134 break;
1135 case XGI_20:
1374 case SIS_550: 1136 case SIS_550:
1375 SiS_SetReg(SiS_Pr->SiS_P3c4,0x20,0xa1); 1137 /* See above */
1138 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x20,0xa1);
1376 /* No 3D engine ! */ 1139 /* No 3D engine ! */
1377 /* - Enable 2D (0x40) 1140 /* - Enable 2D (0x40)
1141 * - disable 3D
1378 */ 1142 */
1379 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x40); 1143 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x1E,0x60,0x40);
1144 break;
1145#endif
1146 default:
1147 break;
1380 } 1148 }
1381} 1149}
1382 1150
@@ -1384,38 +1152,40 @@ SiSInitPCIetc(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
1384/* HELPER: SetLVDSetc */ 1152/* HELPER: SetLVDSetc */
1385/*********************************************/ 1153/*********************************************/
1386 1154
1387static void 1155#ifdef SIS_LINUX_KERNEL
1388SiSSetLVDSetc(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 1156static
1157#endif
1158void
1159SiSSetLVDSetc(struct SiS_Private *SiS_Pr)
1389{ 1160{
1390 USHORT temp; 1161 unsigned short temp;
1391 1162
1392 SiS_Pr->SiS_IF_DEF_LVDS = 0; 1163 SiS_Pr->SiS_IF_DEF_LVDS = 0;
1393 SiS_Pr->SiS_IF_DEF_TRUMPION = 0; 1164 SiS_Pr->SiS_IF_DEF_TRUMPION = 0;
1394 SiS_Pr->SiS_IF_DEF_CH70xx = 0; 1165 SiS_Pr->SiS_IF_DEF_CH70xx = 0;
1395 SiS_Pr->SiS_IF_DEF_DSTN = 0;
1396 SiS_Pr->SiS_IF_DEF_FSTN = 0;
1397 SiS_Pr->SiS_IF_DEF_CONEX = 0; 1166 SiS_Pr->SiS_IF_DEF_CONEX = 0;
1398 1167
1399 SiS_Pr->SiS_ChrontelInit = 0; 1168 SiS_Pr->SiS_ChrontelInit = 0;
1400 1169
1170 if(SiS_Pr->ChipType == XGI_20) return;
1171
1401 /* Check for SiS30x first */ 1172 /* Check for SiS30x first */
1402 temp = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00); 1173 temp = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
1403 if((temp == 1) || (temp == 2)) return; 1174 if((temp == 1) || (temp == 2)) return;
1404 1175
1405 switch(HwInfo->jChipType) { 1176 switch(SiS_Pr->ChipType) {
1406#ifdef SIS300 1177#ifdef SIS300
1407 case SIS_540: 1178 case SIS_540:
1408 case SIS_630: 1179 case SIS_630:
1409 case SIS_730: 1180 case SIS_730:
1410 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37); 1181 temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x37) & 0x0e) >> 1;
1411 temp = (temp & 0x0E) >> 1; 1182 if((temp >= 2) && (temp <= 5)) SiS_Pr->SiS_IF_DEF_LVDS = 1;
1412 if((temp >= 2) && (temp <= 5)) SiS_Pr->SiS_IF_DEF_LVDS = 1; 1183 if(temp == 3) SiS_Pr->SiS_IF_DEF_TRUMPION = 1;
1413 if(temp == 3) SiS_Pr->SiS_IF_DEF_TRUMPION = 1; 1184 if((temp == 4) || (temp == 5)) {
1414 if((temp == 4) || (temp == 5)) {
1415 /* Save power status (and error check) - UNUSED */ 1185 /* Save power status (and error check) - UNUSED */
1416 SiS_Pr->SiS_Backup70xx = SiS_GetCH700x(SiS_Pr, 0x0e); 1186 SiS_Pr->SiS_Backup70xx = SiS_GetCH700x(SiS_Pr, 0x0e);
1417 SiS_Pr->SiS_IF_DEF_CH70xx = 1; 1187 SiS_Pr->SiS_IF_DEF_CH70xx = 1;
1418 } 1188 }
1419 break; 1189 break;
1420#endif 1190#endif
1421#ifdef SIS315H 1191#ifdef SIS315H
@@ -1423,26 +1193,26 @@ SiSSetLVDSetc(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
1423 case SIS_650: 1193 case SIS_650:
1424 case SIS_740: 1194 case SIS_740:
1425 case SIS_330: 1195 case SIS_330:
1426 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37); 1196 temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x37) & 0x0e) >> 1;
1427 temp = (temp & 0x0E) >> 1; 1197 if((temp >= 2) && (temp <= 3)) SiS_Pr->SiS_IF_DEF_LVDS = 1;
1428 if((temp >= 2) && (temp <= 3)) SiS_Pr->SiS_IF_DEF_LVDS = 1; 1198 if(temp == 3) SiS_Pr->SiS_IF_DEF_CH70xx = 2;
1429 if(temp == 3) SiS_Pr->SiS_IF_DEF_CH70xx = 2; 1199 break;
1430 break;
1431 case SIS_661: 1200 case SIS_661:
1432 case SIS_741: 1201 case SIS_741:
1433 case SIS_660: 1202 case SIS_660:
1434 case SIS_760: 1203 case SIS_760:
1435 case SIS_761: 1204 case SIS_761:
1436 case SIS_340: 1205 case SIS_340:
1437 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 1206 case XGI_20:
1438 temp = (temp & 0xe0) >> 5; 1207 case XGI_40:
1439 if((temp >= 2) && (temp <= 3)) SiS_Pr->SiS_IF_DEF_LVDS = 1; 1208 temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & 0xe0) >> 5;
1440 if(temp == 3) SiS_Pr->SiS_IF_DEF_CH70xx = 2; 1209 if((temp >= 2) && (temp <= 3)) SiS_Pr->SiS_IF_DEF_LVDS = 1;
1441 if(temp == 4) SiS_Pr->SiS_IF_DEF_CONEX = 1; /* Not yet supported */ 1210 if(temp == 3) SiS_Pr->SiS_IF_DEF_CH70xx = 2;
1442 break; 1211 if(temp == 4) SiS_Pr->SiS_IF_DEF_CONEX = 1; /* Not yet supported */
1212 break;
1443#endif 1213#endif
1444 default: 1214 default:
1445 break; 1215 break;
1446 } 1216 }
1447} 1217}
1448 1218
@@ -1451,35 +1221,55 @@ SiSSetLVDSetc(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
1451/*********************************************/ 1221/*********************************************/
1452 1222
1453void 1223void
1454SiS_SetEnableDstn(SiS_Private *SiS_Pr, int enable) 1224SiS_SetEnableDstn(struct SiS_Private *SiS_Pr, int enable)
1455{ 1225{
1456 SiS_Pr->SiS_IF_DEF_DSTN = enable ? 1 : 0; 1226 SiS_Pr->SiS_IF_DEF_DSTN = enable ? 1 : 0;
1457} 1227}
1458 1228
1459void 1229void
1460SiS_SetEnableFstn(SiS_Private *SiS_Pr, int enable) 1230SiS_SetEnableFstn(struct SiS_Private *SiS_Pr, int enable)
1461{ 1231{
1462 SiS_Pr->SiS_IF_DEF_FSTN = enable ? 1 : 0; 1232 SiS_Pr->SiS_IF_DEF_FSTN = enable ? 1 : 0;
1463} 1233}
1464 1234
1465/*********************************************/ 1235/*********************************************/
1236/* HELPER: Get modeflag */
1237/*********************************************/
1238
1239unsigned short
1240SiS_GetModeFlag(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1241 unsigned short ModeIdIndex)
1242{
1243 if(SiS_Pr->UseCustomMode) {
1244 return SiS_Pr->CModeFlag;
1245 } else if(ModeNo <= 0x13) {
1246 return SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
1247 } else {
1248 return SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1249 }
1250}
1251
1252/*********************************************/
1466/* HELPER: Determine ROM usage */ 1253/* HELPER: Determine ROM usage */
1467/*********************************************/ 1254/*********************************************/
1468 1255
1469BOOLEAN 1256BOOLEAN
1470SiSDetermineROMLayout661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 1257SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr)
1471{ 1258{
1472 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 1259 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
1473 USHORT romversoffs, romvmaj = 1, romvmin = 0; 1260 unsigned short romversoffs, romvmaj = 1, romvmin = 0;
1474 1261
1475 if(HwInfo->jChipType >= SIS_761) { 1262 if(SiS_Pr->ChipType >= XGI_20) {
1476 /* I very much assume 761 and 340 will use new layout */ 1263 /* XGI ROMs don't qualify */
1264 return FALSE;
1265 } else if(SiS_Pr->ChipType >= SIS_761) {
1266 /* I very much assume 761, 340 and newer will use new layout */
1477 return TRUE; 1267 return TRUE;
1478 } else if(HwInfo->jChipType >= SIS_661) { 1268 } else if(SiS_Pr->ChipType >= SIS_661) {
1479 if((ROMAddr[0x1a] == 'N') && 1269 if((ROMAddr[0x1a] == 'N') &&
1480 (ROMAddr[0x1b] == 'e') && 1270 (ROMAddr[0x1b] == 'e') &&
1481 (ROMAddr[0x1c] == 'w') && 1271 (ROMAddr[0x1c] == 'w') &&
1482 (ROMAddr[0x1d] == 'V')) { 1272 (ROMAddr[0x1d] == 'V')) {
1483 return TRUE; 1273 return TRUE;
1484 } 1274 }
1485 romversoffs = ROMAddr[0x16] | (ROMAddr[0x17] << 8); 1275 romversoffs = ROMAddr[0x16] | (ROMAddr[0x17] << 8);
@@ -1494,9 +1284,9 @@ SiSDetermineROMLayout661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
1494 } 1284 }
1495 } else if(IS_SIS650740) { 1285 } else if(IS_SIS650740) {
1496 if((ROMAddr[0x1a] == 'N') && 1286 if((ROMAddr[0x1a] == 'N') &&
1497 (ROMAddr[0x1b] == 'e') && 1287 (ROMAddr[0x1b] == 'e') &&
1498 (ROMAddr[0x1c] == 'w') && 1288 (ROMAddr[0x1c] == 'w') &&
1499 (ROMAddr[0x1d] == 'V')) { 1289 (ROMAddr[0x1d] == 'V')) {
1500 return TRUE; 1290 return TRUE;
1501 } 1291 }
1502 } 1292 }
@@ -1504,45 +1294,50 @@ SiSDetermineROMLayout661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
1504} 1294}
1505 1295
1506static void 1296static void
1507SiSDetermineROMUsage(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 1297SiSDetermineROMUsage(struct SiS_Private *SiS_Pr)
1508{ 1298{
1509 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 1299 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
1510 USHORT romptr = 0; 1300 unsigned short romptr = 0;
1511 1301
1512 SiS_Pr->SiS_UseROM = FALSE; 1302 SiS_Pr->SiS_UseROM = FALSE;
1513 SiS_Pr->SiS_ROMNew = FALSE; 1303 SiS_Pr->SiS_ROMNew = FALSE;
1304 SiS_Pr->SiS_PWDOffset = 0;
1514 1305
1515 if((ROMAddr) && (HwInfo->UseROM)) { 1306 if(SiS_Pr->ChipType >= XGI_20) return;
1516 if(HwInfo->jChipType == SIS_300) { 1307
1517 /* 300: We check if the code starts below 0x220 by 1308 if((ROMAddr) && (SiS_Pr->UseROM)) {
1309 if(SiS_Pr->ChipType == SIS_300) {
1310 /* 300: We check if the code starts below 0x220 by
1518 * checking the jmp instruction at the beginning 1311 * checking the jmp instruction at the beginning
1519 * of the BIOS image. 1312 * of the BIOS image.
1520 */ 1313 */
1521 if((ROMAddr[3] == 0xe9) && ((ROMAddr[5] << 8) | ROMAddr[4]) > 0x21a) 1314 if((ROMAddr[3] == 0xe9) && ((ROMAddr[5] << 8) | ROMAddr[4]) > 0x21a)
1522 SiS_Pr->SiS_UseROM = TRUE; 1315 SiS_Pr->SiS_UseROM = TRUE;
1523 } else if(HwInfo->jChipType < SIS_315H) { 1316 } else if(SiS_Pr->ChipType < SIS_315H) {
1524 /* Sony's VAIO BIOS 1.09 follows the standard, so perhaps 1317 /* Sony's VAIO BIOS 1.09 follows the standard, so perhaps
1525 * the others do as well 1318 * the others do as well
1526 */ 1319 */
1527 SiS_Pr->SiS_UseROM = TRUE; 1320 SiS_Pr->SiS_UseROM = TRUE;
1528 } else { 1321 } else {
1529 /* 315/330 series stick to the standard(s) */ 1322 /* 315/330 series stick to the standard(s) */
1530 SiS_Pr->SiS_UseROM = TRUE; 1323 SiS_Pr->SiS_UseROM = TRUE;
1531 if((SiS_Pr->SiS_ROMNew = SiSDetermineROMLayout661(SiS_Pr, HwInfo))) { 1324 if((SiS_Pr->SiS_ROMNew = SiSDetermineROMLayout661(SiS_Pr))) {
1532 SiS_Pr->SiS_EMIOffset = 14; 1325 SiS_Pr->SiS_EMIOffset = 14;
1326 SiS_Pr->SiS_PWDOffset = 17;
1533 SiS_Pr->SiS661LCD2TableSize = 36; 1327 SiS_Pr->SiS661LCD2TableSize = 36;
1534 /* Find out about LCD data table entry size */ 1328 /* Find out about LCD data table entry size */
1535 if((romptr = SISGETROMW(0x0102))) { 1329 if((romptr = SISGETROMW(0x0102))) {
1536 if(ROMAddr[romptr + (32 * 16)] == 0xff) 1330 if(ROMAddr[romptr + (32 * 16)] == 0xff)
1537 SiS_Pr->SiS661LCD2TableSize = 32; 1331 SiS_Pr->SiS661LCD2TableSize = 32;
1538 else if(ROMAddr[romptr + (34 * 16)] == 0xff) 1332 else if(ROMAddr[romptr + (34 * 16)] == 0xff)
1539 SiS_Pr->SiS661LCD2TableSize = 34; 1333 SiS_Pr->SiS661LCD2TableSize = 34;
1540 else if(ROMAddr[romptr + (36 * 16)] == 0xff) /* 0.94 */ 1334 else if(ROMAddr[romptr + (36 * 16)] == 0xff) /* 0.94, 2.05.00+ */
1541 SiS_Pr->SiS661LCD2TableSize = 36; 1335 SiS_Pr->SiS661LCD2TableSize = 36;
1542 else if( (ROMAddr[romptr + (38 * 16)] == 0xff) || /* 2.00.00 - 2.02.00 */ 1336 else if( (ROMAddr[romptr + (38 * 16)] == 0xff) || /* 2.00.00 - 2.02.00 */
1543 (ROMAddr[0x6F] & 0x01) ) { /* 2.03.00+ */ 1337 (ROMAddr[0x6F] & 0x01) ) { /* 2.03.00 - <2.05.00 */
1544 SiS_Pr->SiS661LCD2TableSize = 38; 1338 SiS_Pr->SiS661LCD2TableSize = 38; /* UMC data layout abandoned at 2.05.00 */
1545 SiS_Pr->SiS_EMIOffset = 16; 1339 SiS_Pr->SiS_EMIOffset = 16;
1340 SiS_Pr->SiS_PWDOffset = 19;
1546 } 1341 }
1547 } 1342 }
1548 } 1343 }
@@ -1555,9 +1350,9 @@ SiSDetermineROMUsage(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
1555/*********************************************/ 1350/*********************************************/
1556 1351
1557static void 1352static void
1558SiS_SetSegRegLower(SiS_Private *SiS_Pr, USHORT value) 1353SiS_SetSegRegLower(struct SiS_Private *SiS_Pr, unsigned short value)
1559{ 1354{
1560 USHORT temp; 1355 unsigned short temp;
1561 1356
1562 value &= 0x00ff; 1357 value &= 0x00ff;
1563 temp = SiS_GetRegByte(SiS_Pr->SiS_P3cb) & 0xf0; 1358 temp = SiS_GetRegByte(SiS_Pr->SiS_P3cb) & 0xf0;
@@ -1569,9 +1364,9 @@ SiS_SetSegRegLower(SiS_Private *SiS_Pr, USHORT value)
1569} 1364}
1570 1365
1571static void 1366static void
1572SiS_SetSegRegUpper(SiS_Private *SiS_Pr, USHORT value) 1367SiS_SetSegRegUpper(struct SiS_Private *SiS_Pr, unsigned short value)
1573{ 1368{
1574 USHORT temp; 1369 unsigned short temp;
1575 1370
1576 value &= 0x00ff; 1371 value &= 0x00ff;
1577 temp = SiS_GetRegByte(SiS_Pr->SiS_P3cb) & 0x0f; 1372 temp = SiS_GetRegByte(SiS_Pr->SiS_P3cb) & 0x0f;
@@ -1583,22 +1378,22 @@ SiS_SetSegRegUpper(SiS_Private *SiS_Pr, USHORT value)
1583} 1378}
1584 1379
1585static void 1380static void
1586SiS_SetSegmentReg(SiS_Private *SiS_Pr, USHORT value) 1381SiS_SetSegmentReg(struct SiS_Private *SiS_Pr, unsigned short value)
1587{ 1382{
1588 SiS_SetSegRegLower(SiS_Pr, value); 1383 SiS_SetSegRegLower(SiS_Pr, value);
1589 SiS_SetSegRegUpper(SiS_Pr, value); 1384 SiS_SetSegRegUpper(SiS_Pr, value);
1590} 1385}
1591 1386
1592static void 1387static void
1593SiS_ResetSegmentReg(SiS_Private *SiS_Pr) 1388SiS_ResetSegmentReg(struct SiS_Private *SiS_Pr)
1594{ 1389{
1595 SiS_SetSegmentReg(SiS_Pr, 0); 1390 SiS_SetSegmentReg(SiS_Pr, 0);
1596} 1391}
1597 1392
1598static void 1393static void
1599SiS_SetSegmentRegOver(SiS_Private *SiS_Pr, USHORT value) 1394SiS_SetSegmentRegOver(struct SiS_Private *SiS_Pr, unsigned short value)
1600{ 1395{
1601 USHORT temp = value >> 8; 1396 unsigned short temp = value >> 8;
1602 1397
1603 temp &= 0x07; 1398 temp &= 0x07;
1604 temp |= (temp << 4); 1399 temp |= (temp << 4);
@@ -1607,15 +1402,15 @@ SiS_SetSegmentRegOver(SiS_Private *SiS_Pr, USHORT value)
1607} 1402}
1608 1403
1609static void 1404static void
1610SiS_ResetSegmentRegOver(SiS_Private *SiS_Pr) 1405SiS_ResetSegmentRegOver(struct SiS_Private *SiS_Pr)
1611{ 1406{
1612 SiS_SetSegmentRegOver(SiS_Pr, 0); 1407 SiS_SetSegmentRegOver(SiS_Pr, 0);
1613} 1408}
1614 1409
1615static void 1410static void
1616SiS_ResetSegmentRegisters(SiS_Private *SiS_Pr,PSIS_HW_INFO HwInfo) 1411SiS_ResetSegmentRegisters(struct SiS_Private *SiS_Pr)
1617{ 1412{
1618 if((IS_SIS65x) || (HwInfo->jChipType >= SIS_661)) { 1413 if((IS_SIS65x) || (SiS_Pr->ChipType >= SIS_661)) {
1619 SiS_ResetSegmentReg(SiS_Pr); 1414 SiS_ResetSegmentReg(SiS_Pr);
1620 SiS_ResetSegmentRegOver(SiS_Pr); 1415 SiS_ResetSegmentRegOver(SiS_Pr);
1621 } 1416 }
@@ -1625,89 +1420,86 @@ SiS_ResetSegmentRegisters(SiS_Private *SiS_Pr,PSIS_HW_INFO HwInfo)
1625/* HELPER: GetVBType */ 1420/* HELPER: GetVBType */
1626/*********************************************/ 1421/*********************************************/
1627 1422
1628static void 1423#ifdef SIS_LINUX_KERNEL
1629SiS_GetVBType(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 1424static
1425#endif
1426void
1427SiS_GetVBType(struct SiS_Private *SiS_Pr)
1630{ 1428{
1631 USHORT flag=0, rev=0, nolcd=0, p4_0f, p4_25, p4_27; 1429 unsigned short flag = 0, rev = 0, nolcd = 0;
1632 1430 unsigned short p4_0f, p4_25, p4_27;
1633 SiS_Pr->SiS_VBType = 0; 1431
1634 1432 SiS_Pr->SiS_VBType = 0;
1635 if((SiS_Pr->SiS_IF_DEF_LVDS) || (SiS_Pr->SiS_IF_DEF_CONEX)) 1433
1636 return; 1434 if((SiS_Pr->SiS_IF_DEF_LVDS) || (SiS_Pr->SiS_IF_DEF_CONEX))
1637 1435 return;
1638 flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00); 1436
1639 1437 if(SiS_Pr->ChipType == XGI_20)
1640 if(flag > 3) return; 1438 return;
1641 1439
1642 rev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01); 1440 flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
1643 1441
1644 if(flag >= 2) { 1442 if(flag > 3)
1645 SiS_Pr->SiS_VBType = VB_SIS302B; 1443 return;
1646 } else if(flag == 1) { 1444
1647 if(rev >= 0xC0) { 1445 rev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01);
1648 SiS_Pr->SiS_VBType = VB_SIS301C; 1446
1649 } else if(rev >= 0xB0) { 1447 if(flag >= 2) {
1650 SiS_Pr->SiS_VBType = VB_SIS301B; 1448 SiS_Pr->SiS_VBType = VB_SIS302B;
1651 /* Check if 30xB DH version (no LCD support, use Panel Link instead) */ 1449 } else if(flag == 1) {
1652 nolcd = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x23); 1450 if(rev >= 0xC0) {
1653 if(!(nolcd & 0x02)) SiS_Pr->SiS_VBType |= VB_NoLCD; 1451 SiS_Pr->SiS_VBType = VB_SIS301C;
1654 } else { 1452 } else if(rev >= 0xB0) {
1655 SiS_Pr->SiS_VBType = VB_SIS301; 1453 SiS_Pr->SiS_VBType = VB_SIS301B;
1656 } 1454 /* Check if 30xB DH version (no LCD support, use Panel Link instead) */
1657 } 1455 nolcd = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x23);
1658 if(SiS_Pr->SiS_VBType & (VB_SIS301B | VB_SIS301C | VB_SIS302B)) { 1456 if(!(nolcd & 0x02)) SiS_Pr->SiS_VBType |= VB_NoLCD;
1659 if(rev >= 0xE0) { 1457 } else {
1660 flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x39); 1458 SiS_Pr->SiS_VBType = VB_SIS301;
1661 if(flag == 0xff) SiS_Pr->SiS_VBType = VB_SIS302LV; 1459 }
1662 else SiS_Pr->SiS_VBType = VB_SIS301C; /* VB_SIS302ELV; */ 1460 }
1663 } else if(rev >= 0xD0) { 1461 if(SiS_Pr->SiS_VBType & (VB_SIS301B | VB_SIS301C | VB_SIS302B)) {
1664 SiS_Pr->SiS_VBType = VB_SIS301LV; 1462 if(rev >= 0xE0) {
1665 } 1463 flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x39);
1666 } 1464 if(flag == 0xff) SiS_Pr->SiS_VBType = VB_SIS302LV;
1667 if(SiS_Pr->SiS_VBType & (VB_301C | VB_301LV | VB_302LV | VB_302ELV)) { 1465 else SiS_Pr->SiS_VBType = VB_SIS301C; /* VB_SIS302ELV; */
1668 p4_0f = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x0f); 1466 } else if(rev >= 0xD0) {
1669 p4_25 = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x25); 1467 SiS_Pr->SiS_VBType = VB_SIS301LV;
1670 p4_27 = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x27); 1468 }
1671 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x0f,0x7f); 1469 }
1672 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x25,0x08); 1470 if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS301LV | VB_SIS302LV | VB_SIS302ELV)) {
1673 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,0xfd); 1471 p4_0f = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x0f);
1674 if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x08) { 1472 p4_25 = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x25);
1675 SiS_Pr->SiS_VBType |= VB_UMC; 1473 p4_27 = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x27);
1676 } 1474 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x0f,0x7f);
1677 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x27,p4_27); 1475 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x25,0x08);
1678 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x25,p4_25); 1476 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,0xfd);
1679 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0f,p4_0f); 1477 if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x08) {
1680 } 1478 SiS_Pr->SiS_VBType |= VB_UMC;
1479 }
1480 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x27,p4_27);
1481 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x25,p4_25);
1482 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0f,p4_0f);
1483 }
1681} 1484}
1682 1485
1683/*********************************************/ 1486/*********************************************/
1684/* HELPER: Check RAM size */ 1487/* HELPER: Check RAM size */
1685/*********************************************/ 1488/*********************************************/
1686 1489
1687#ifdef LINUX_KERNEL 1490#ifdef SIS_LINUX_KERNEL
1688static BOOLEAN 1491static BOOLEAN
1689SiS_CheckMemorySize(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 1492SiS_CheckMemorySize(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1690 USHORT ModeNo, USHORT ModeIdIndex) 1493 unsigned short ModeIdIndex)
1691{ 1494{
1692 USHORT AdapterMemSize = HwInfo->ulVideoMemorySize / (1024*1024); 1495 unsigned short AdapterMemSize = SiS_Pr->VideoMemorySize / (1024*1024);
1693 USHORT memorysize,modeflag; 1496 unsigned short modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
1694 1497 unsigned short memorysize = ((modeflag & MemoryInfoFlag) >> MemorySizeShift) + 1;
1695 if(SiS_Pr->UseCustomMode) { 1498
1696 modeflag = SiS_Pr->CModeFlag; 1499 if(!AdapterMemSize) return TRUE;
1697 } else { 1500
1698 if(ModeNo <= 0x13) { 1501 if(AdapterMemSize < memorysize) return FALSE;
1699 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; 1502 return TRUE;
1700 } else {
1701 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1702 }
1703 }
1704
1705 memorysize = modeflag & MemoryInfoFlag;
1706 memorysize >>= MemorySizeShift; /* Get required memory size */
1707 memorysize++;
1708
1709 if(AdapterMemSize < memorysize) return FALSE;
1710 return TRUE;
1711} 1503}
1712#endif 1504#endif
1713 1505
@@ -1716,63 +1508,65 @@ SiS_CheckMemorySize(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
1716/*********************************************/ 1508/*********************************************/
1717 1509
1718#ifdef SIS315H 1510#ifdef SIS315H
1719static UCHAR 1511static unsigned char
1720SiS_Get310DRAMType(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 1512SiS_Get310DRAMType(struct SiS_Private *SiS_Pr)
1721{ 1513{
1722 UCHAR data, temp; 1514 unsigned char data;
1723 1515
1724 if((*SiS_Pr->pSiS_SoftSetting) & SoftDRAMType) { 1516 if((*SiS_Pr->pSiS_SoftSetting) & SoftDRAMType) {
1725 data = (*SiS_Pr->pSiS_SoftSetting) & 0x03; 1517 data = (*SiS_Pr->pSiS_SoftSetting) & 0x03;
1726 } else { 1518 } else {
1727 if(HwInfo->jChipType >= SIS_340) { 1519 if(SiS_Pr->ChipType >= XGI_20) {
1728 /* TODO */ 1520 /* Do I need this? SR17 seems to be zero anyway... */
1729 data = 0; 1521 data = 0;
1730 } if(HwInfo->jChipType >= SIS_661) { 1522 } else if(SiS_Pr->ChipType >= SIS_340) {
1731 data = SiS_GetReg(SiS_Pr->SiS_P3d4,0x78) & 0x07; 1523 /* TODO */
1732 if(SiS_Pr->SiS_ROMNew) { 1524 data = 0;
1733 data = ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x78) & 0xc0) >> 6); 1525 } if(SiS_Pr->ChipType >= SIS_661) {
1734 } 1526 if(SiS_Pr->SiS_ROMNew) {
1735 } else if(IS_SIS550650740) { 1527 data = ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x78) & 0xc0) >> 6);
1736 data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x07; 1528 } else {
1737 } else { /* 315, 330 */ 1529 data = SiS_GetReg(SiS_Pr->SiS_P3d4,0x78) & 0x07;
1738 data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3a) & 0x03; 1530 }
1739 if(HwInfo->jChipType == SIS_330) { 1531 } else if(IS_SIS550650740) {
1740 if(data > 1) { 1532 data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x07;
1741 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0x30; 1533 } else { /* 315, 330 */
1742 switch(temp) { 1534 data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3a) & 0x03;
1743 case 0x00: data = 1; break; 1535 if(SiS_Pr->ChipType == SIS_330) {
1744 case 0x10: data = 3; break; 1536 if(data > 1) {
1745 case 0x20: data = 3; break; 1537 switch(SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0x30) {
1746 case 0x30: data = 2; break; 1538 case 0x00: data = 1; break;
1747 } 1539 case 0x10: data = 3; break;
1748 } else { 1540 case 0x20: data = 3; break;
1749 data = 0; 1541 case 0x30: data = 2; break;
1750 } 1542 }
1751 } 1543 } else {
1752 } 1544 data = 0;
1545 }
1546 }
1547 }
1753 } 1548 }
1754 1549
1755 return data; 1550 return data;
1756} 1551}
1757 1552
1758static USHORT 1553static unsigned short
1759SiS_GetMCLK(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 1554SiS_GetMCLK(struct SiS_Private *SiS_Pr)
1760{ 1555{
1761 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 1556 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
1762 USHORT index; 1557 unsigned short index;
1763 1558
1764 index = SiS_Get310DRAMType(SiS_Pr, HwInfo); 1559 index = SiS_Get310DRAMType(SiS_Pr);
1765 if(HwInfo->jChipType >= SIS_661) { 1560 if(SiS_Pr->ChipType >= SIS_661) {
1766 if(SiS_Pr->SiS_ROMNew) { 1561 if(SiS_Pr->SiS_ROMNew) {
1767 return((USHORT)(SISGETROMW((0x90 + (index * 5) + 3)))); 1562 return((unsigned short)(SISGETROMW((0x90 + (index * 5) + 3))));
1768 } 1563 }
1769 return(SiS_Pr->SiS_MCLKData_0[index].CLOCK); 1564 return(SiS_Pr->SiS_MCLKData_0[index].CLOCK);
1770 } else if(index >= 4) { 1565 } else if(index >= 4) {
1771 index -= 4; 1566 return(SiS_Pr->SiS_MCLKData_1[index - 4].CLOCK);
1772 return(SiS_Pr->SiS_MCLKData_1[index].CLOCK); 1567 } else {
1773 } else { 1568 return(SiS_Pr->SiS_MCLKData_0[index].CLOCK);
1774 return(SiS_Pr->SiS_MCLKData_0[index].CLOCK); 1569 }
1775 }
1776} 1570}
1777#endif 1571#endif
1778 1572
@@ -1780,30 +1574,30 @@ SiS_GetMCLK(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
1780/* HELPER: ClearBuffer */ 1574/* HELPER: ClearBuffer */
1781/*********************************************/ 1575/*********************************************/
1782 1576
1783#ifdef LINUX_KERNEL 1577#ifdef SIS_LINUX_KERNEL
1784static void 1578static void
1785SiS_ClearBuffer(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo) 1579SiS_ClearBuffer(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
1786{ 1580{
1787 UCHAR SISIOMEMTYPE *VideoMemoryAddress = HwInfo->pjVideoMemoryAddress; 1581 unsigned char SISIOMEMTYPE *memaddr = SiS_Pr->VideoMemoryAddress;
1788 ULONG AdapterMemorySize = HwInfo->ulVideoMemorySize; 1582 unsigned int memsize = SiS_Pr->VideoMemorySize;
1789 USHORT SISIOMEMTYPE *pBuffer; 1583 unsigned short SISIOMEMTYPE *pBuffer;
1790 int i; 1584 int i;
1791 1585
1792 if(SiS_Pr->SiS_ModeType >= ModeEGA) { 1586 if(!memaddr || !memsize) return;
1793 if(ModeNo > 0x13) { 1587
1794 SiS_SetMemory(VideoMemoryAddress, AdapterMemorySize, 0); 1588 if(SiS_Pr->SiS_ModeType >= ModeEGA) {
1795 } else { 1589 if(ModeNo > 0x13) {
1796 pBuffer = (USHORT SISIOMEMTYPE *)VideoMemoryAddress; 1590 SiS_SetMemory(memaddr, memsize, 0);
1797 for(i=0; i<0x4000; i++) writew(0x0000, &pBuffer[i]); 1591 } else {
1798 } 1592 pBuffer = (unsigned short SISIOMEMTYPE *)memaddr;
1799 } else { 1593 for(i = 0; i < 0x4000; i++) writew(0x0000, &pBuffer[i]);
1800 if(SiS_Pr->SiS_ModeType < ModeCGA) { 1594 }
1801 pBuffer = (USHORT SISIOMEMTYPE *)VideoMemoryAddress; 1595 } else if(SiS_Pr->SiS_ModeType < ModeCGA) {
1802 for(i=0; i<0x4000; i++) writew(0x0720, &pBuffer[i]); 1596 pBuffer = (unsigned short SISIOMEMTYPE *)memaddr;
1803 } else { 1597 for(i = 0; i < 0x4000; i++) writew(0x0720, &pBuffer[i]);
1804 SiS_SetMemory(VideoMemoryAddress, 0x8000, 0); 1598 } else {
1805 } 1599 SiS_SetMemory(memaddr, 0x8000, 0);
1806 } 1600 }
1807} 1601}
1808#endif 1602#endif
1809 1603
@@ -1812,35 +1606,36 @@ SiS_ClearBuffer(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
1812/*********************************************/ 1606/*********************************************/
1813 1607
1814BOOLEAN 1608BOOLEAN
1815SiS_SearchModeID(SiS_Private *SiS_Pr, USHORT *ModeNo, USHORT *ModeIdIndex) 1609SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo,
1610 unsigned short *ModeIdIndex)
1816{ 1611{
1817 UCHAR VGAINFO = SiS_Pr->SiS_VGAINFO; 1612 unsigned char VGAINFO = SiS_Pr->SiS_VGAINFO;
1818 1613
1819 if(*ModeNo <= 0x13) { 1614 if((*ModeNo) <= 0x13) {
1820 1615
1821 if((*ModeNo) <= 0x05) (*ModeNo) |= 0x01; 1616 if((*ModeNo) <= 0x05) (*ModeNo) |= 0x01;
1822 1617
1823 for(*ModeIdIndex = 0; ;(*ModeIdIndex)++) { 1618 for((*ModeIdIndex) = 0; ;(*ModeIdIndex)++) {
1824 if(SiS_Pr->SiS_SModeIDTable[*ModeIdIndex].St_ModeID == (*ModeNo)) break; 1619 if(SiS_Pr->SiS_SModeIDTable[(*ModeIdIndex)].St_ModeID == (*ModeNo)) break;
1825 if(SiS_Pr->SiS_SModeIDTable[*ModeIdIndex].St_ModeID == 0xFF) return FALSE; 1620 if(SiS_Pr->SiS_SModeIDTable[(*ModeIdIndex)].St_ModeID == 0xFF) return FALSE;
1826 } 1621 }
1827 1622
1828 if(*ModeNo == 0x07) { 1623 if((*ModeNo) == 0x07) {
1829 if(VGAINFO & 0x10) (*ModeIdIndex)++; /* 400 lines */ 1624 if(VGAINFO & 0x10) (*ModeIdIndex)++; /* 400 lines */
1830 /* else 350 lines */ 1625 /* else 350 lines */
1831 } 1626 }
1832 if(*ModeNo <= 0x03) { 1627 if((*ModeNo) <= 0x03) {
1833 if(!(VGAINFO & 0x80)) (*ModeIdIndex)++; 1628 if(!(VGAINFO & 0x80)) (*ModeIdIndex)++;
1834 if(VGAINFO & 0x10) (*ModeIdIndex)++; /* 400 lines */ 1629 if(VGAINFO & 0x10) (*ModeIdIndex)++; /* 400 lines */
1835 /* else 350 lines */ 1630 /* else 350 lines */
1836 } 1631 }
1837 /* else 200 lines */ 1632 /* else 200 lines */
1838 1633
1839 } else { 1634 } else {
1840 1635
1841 for(*ModeIdIndex = 0; ;(*ModeIdIndex)++) { 1636 for((*ModeIdIndex) = 0; ;(*ModeIdIndex)++) {
1842 if(SiS_Pr->SiS_EModeIDTable[*ModeIdIndex].Ext_ModeID == (*ModeNo)) break; 1637 if(SiS_Pr->SiS_EModeIDTable[(*ModeIdIndex)].Ext_ModeID == (*ModeNo)) break;
1843 if(SiS_Pr->SiS_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF) return FALSE; 1638 if(SiS_Pr->SiS_EModeIDTable[(*ModeIdIndex)].Ext_ModeID == 0xFF) return FALSE;
1844 } 1639 }
1845 1640
1846 } 1641 }
@@ -1851,10 +1646,10 @@ SiS_SearchModeID(SiS_Private *SiS_Pr, USHORT *ModeNo, USHORT *ModeIdIndex)
1851/* HELPER: GetModePtr */ 1646/* HELPER: GetModePtr */
1852/*********************************************/ 1647/*********************************************/
1853 1648
1854UCHAR 1649unsigned short
1855SiS_GetModePtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex) 1650SiS_GetModePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
1856{ 1651{
1857 UCHAR index; 1652 unsigned short index;
1858 1653
1859 if(ModeNo <= 0x13) { 1654 if(ModeNo <= 0x13) {
1860 index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_StTableIndex; 1655 index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_StTableIndex;
@@ -1866,79 +1661,125 @@ SiS_GetModePtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex)
1866} 1661}
1867 1662
1868/*********************************************/ 1663/*********************************************/
1664/* HELPERS: Get some indices */
1665/*********************************************/
1666
1667unsigned short
1668SiS_GetRefCRTVCLK(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide)
1669{
1670 if(SiS_Pr->SiS_RefIndex[Index].Ext_InfoFlag & HaveWideTiming) {
1671 if(UseWide == 1) {
1672 return SiS_Pr->SiS_RefIndex[Index].Ext_CRTVCLK_WIDE;
1673 } else {
1674 return SiS_Pr->SiS_RefIndex[Index].Ext_CRTVCLK_NORM;
1675 }
1676 } else {
1677 return SiS_Pr->SiS_RefIndex[Index].Ext_CRTVCLK;
1678 }
1679}
1680
1681unsigned short
1682SiS_GetRefCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide)
1683{
1684 if(SiS_Pr->SiS_RefIndex[Index].Ext_InfoFlag & HaveWideTiming) {
1685 if(UseWide == 1) {
1686 return SiS_Pr->SiS_RefIndex[Index].Ext_CRT1CRTC_WIDE;
1687 } else {
1688 return SiS_Pr->SiS_RefIndex[Index].Ext_CRT1CRTC_NORM;
1689 }
1690 } else {
1691 return SiS_Pr->SiS_RefIndex[Index].Ext_CRT1CRTC;
1692 }
1693}
1694
1695/*********************************************/
1869/* HELPER: LowModeTests */ 1696/* HELPER: LowModeTests */
1870/*********************************************/ 1697/*********************************************/
1871 1698
1872static BOOLEAN 1699static BOOLEAN
1873SiS_DoLowModeTest(SiS_Private *SiS_Pr, USHORT ModeNo, PSIS_HW_INFO HwInfo) 1700SiS_DoLowModeTest(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
1874{ 1701{
1875 USHORT temp,temp1,temp2; 1702 unsigned short temp, temp1, temp2;
1876 1703
1877 if((ModeNo != 0x03) && (ModeNo != 0x10) && (ModeNo != 0x12)) 1704 if((ModeNo != 0x03) && (ModeNo != 0x10) && (ModeNo != 0x12))
1878 return(TRUE); 1705 return TRUE;
1879 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x11); 1706 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x11);
1880 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x11,0x80); 1707 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x11,0x80);
1881 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x00); 1708 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x00);
1882 SiS_SetReg(SiS_Pr->SiS_P3d4,0x00,0x55); 1709 SiS_SetReg(SiS_Pr->SiS_P3d4,0x00,0x55);
1883 temp2 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x00); 1710 temp2 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x00);
1884 SiS_SetReg(SiS_Pr->SiS_P3d4,0x00,temp1); 1711 SiS_SetReg(SiS_Pr->SiS_P3d4,0x00,temp1);
1885 SiS_SetReg(SiS_Pr->SiS_P3d4,0x11,temp); 1712 SiS_SetReg(SiS_Pr->SiS_P3d4,0x11,temp);
1886 if((HwInfo->jChipType >= SIS_315H) || 1713 if((SiS_Pr->ChipType >= SIS_315H) ||
1887 (HwInfo->jChipType == SIS_300)) { 1714 (SiS_Pr->ChipType == SIS_300)) {
1888 if(temp2 == 0x55) return(FALSE); 1715 if(temp2 == 0x55) return FALSE;
1889 else return(TRUE); 1716 else return TRUE;
1890 } else { 1717 } else {
1891 if(temp2 != 0x55) return(TRUE); 1718 if(temp2 != 0x55) return TRUE;
1892 else { 1719 else {
1893 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01); 1720 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01);
1894 return(FALSE); 1721 return FALSE;
1895 } 1722 }
1896 } 1723 }
1897} 1724}
1898 1725
1899static void 1726static void
1900SiS_SetLowModeTest(SiS_Private *SiS_Pr, USHORT ModeNo, PSIS_HW_INFO HwInfo) 1727SiS_SetLowModeTest(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
1901{ 1728{
1902 if(SiS_DoLowModeTest(SiS_Pr, ModeNo, HwInfo)) { 1729 if(SiS_DoLowModeTest(SiS_Pr, ModeNo)) {
1903 SiS_Pr->SiS_SetFlag |= LowModeTests; 1730 SiS_Pr->SiS_SetFlag |= LowModeTests;
1904 } 1731 }
1905} 1732}
1906 1733
1907/*********************************************/ 1734/*********************************************/
1908/* HELPER: ENABLE CRT1 */ 1735/* HELPER: OPEN/CLOSE CRT1 CRTC */
1909/*********************************************/ 1736/*********************************************/
1910 1737
1911static void 1738static void
1912SiS_SetupCR5x(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 1739SiS_OpenCRTC(struct SiS_Private *SiS_Pr)
1740{
1741 if(IS_SIS650) {
1742 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x51,0x1f);
1743 if(IS_SIS651) SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x51,0x20);
1744 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x56,0xe7);
1745 } else if(IS_SIS661741660760) {
1746 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x61,0xf7);
1747 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x51,0x1f);
1748 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x56,0xe7);
1749 if(!SiS_Pr->SiS_ROMNew) {
1750 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x3a,0xef);
1751 }
1752 }
1753}
1754
1755static void
1756SiS_CloseCRTC(struct SiS_Private *SiS_Pr)
1913{ 1757{
1914 if(IS_SIS650) { 1758#if 0 /* This locks some CRTC registers. We don't want that. */
1915 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 1759 unsigned short temp1 = 0, temp2 = 0;
1916 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x51,0x1f); 1760
1917 if(IS_SIS651) SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x51,0x20); 1761 if(IS_SIS661741660760) {
1918 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x56,0xe7); 1762 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
1919 } 1763 temp1 = 0xa0; temp2 = 0x08;
1920 } else if(IS_SIS661741660760) { 1764 }
1921 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x61,0xf7); 1765 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x51,0x1f,temp1);
1922 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x51,0x1f); 1766 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x56,0xe7,temp2);
1923 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x56,0xe7); 1767 }
1924 if(!SiS_Pr->SiS_ROMNew) { 1768#endif
1925 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x3a,0xef);
1926 }
1927 }
1928} 1769}
1929 1770
1930static void 1771static void
1931SiS_HandleCRT1(SiS_Private *SiS_Pr) 1772SiS_HandleCRT1(struct SiS_Private *SiS_Pr)
1932{ 1773{
1933 /* Enable CRT1 gating */ 1774 /* Enable CRT1 gating */
1934 SiS_SetRegAND(SiS_Pr->SiS_P3d4,SiS_Pr->SiS_MyCR63,0xbf); 1775 SiS_SetRegAND(SiS_Pr->SiS_P3d4,SiS_Pr->SiS_MyCR63,0xbf);
1935#if 0 1776#if 0
1936 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x15) & 0x01)) { 1777 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x15) & 0x01)) {
1937 if((SiS_GetReg(SiS_Pr->SiS_P3c4,0x15) & 0x0a) || 1778 if((SiS_GetReg(SiS_Pr->SiS_P3c4,0x15) & 0x0a) ||
1938 (SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x01)) { 1779 (SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x01)) {
1939 SiS_SetRegOR(SiS_Pr->SiS_P3d4,SiS_Pr->SiS_MyCR63,0x40); 1780 SiS_SetRegOR(SiS_Pr->SiS_P3d4,SiS_Pr->SiS_MyCR63,0x40);
1940 } 1781 }
1941 } 1782 }
1942#endif 1783#endif
1943} 1784}
1944 1785
@@ -1946,57 +1787,54 @@ SiS_HandleCRT1(SiS_Private *SiS_Pr)
1946/* HELPER: GetColorDepth */ 1787/* HELPER: GetColorDepth */
1947/*********************************************/ 1788/*********************************************/
1948 1789
1949USHORT 1790unsigned short
1950SiS_GetColorDepth(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex) 1791SiS_GetColorDepth(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1792 unsigned short ModeIdIndex)
1951{ 1793{
1952 USHORT ColorDepth[6] = { 1, 2, 4, 4, 6, 8}; 1794 static const unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
1953 SHORT index; 1795 unsigned short modeflag;
1954 USHORT modeflag; 1796 short index;
1955 1797
1956 /* Do NOT check UseCustomMode, will skrew up FIFO */ 1798 /* Do NOT check UseCustomMode, will skrew up FIFO */
1957 if(ModeNo == 0xfe) { 1799 if(ModeNo == 0xfe) {
1958 modeflag = SiS_Pr->CModeFlag; 1800 modeflag = SiS_Pr->CModeFlag;
1959 } else { 1801 } else if(ModeNo <= 0x13) {
1960 if(ModeNo <= 0x13) 1802 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
1961 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; 1803 } else {
1962 else 1804 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1963 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 1805 }
1964 } 1806
1965 1807 index = (modeflag & ModeTypeMask) - ModeEGA;
1966 index = (modeflag & ModeTypeMask) - ModeEGA; 1808 if(index < 0) index = 0;
1967 if(index < 0) index = 0; 1809 return ColorDepth[index];
1968 return(ColorDepth[index]);
1969} 1810}
1970 1811
1971/*********************************************/ 1812/*********************************************/
1972/* HELPER: GetOffset */ 1813/* HELPER: GetOffset */
1973/*********************************************/ 1814/*********************************************/
1974 1815
1975USHORT 1816unsigned short
1976SiS_GetOffset(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex, 1817SiS_GetOffset(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1977 USHORT RefreshRateTableIndex,PSIS_HW_INFO HwInfo) 1818 unsigned short ModeIdIndex, unsigned short RRTI)
1978{ 1819{
1979 USHORT xres, temp, colordepth, infoflag; 1820 unsigned short xres, temp, colordepth, infoflag;
1980 1821
1981 if(SiS_Pr->UseCustomMode) { 1822 if(SiS_Pr->UseCustomMode) {
1982 infoflag = SiS_Pr->CInfoFlag; 1823 infoflag = SiS_Pr->CInfoFlag;
1983 xres = SiS_Pr->CHDisplay; 1824 xres = SiS_Pr->CHDisplay;
1984 } else { 1825 } else {
1985 infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag; 1826 infoflag = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag;
1986 xres = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].XRes; 1827 xres = SiS_Pr->SiS_RefIndex[RRTI].XRes;
1987 } 1828 }
1988 1829
1989 colordepth = SiS_GetColorDepth(SiS_Pr,ModeNo,ModeIdIndex); 1830 colordepth = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex);
1990 1831
1991 temp = xres / 16; 1832 temp = xres / 16;
1992 if(infoflag & InterlaceMode) temp <<= 1; 1833 if(infoflag & InterlaceMode) temp <<= 1;
1993 temp *= colordepth; 1834 temp *= colordepth;
1994 if(xres % 16) { 1835 if(xres % 16) temp += (colordepth >> 1);
1995 colordepth >>= 1; 1836
1996 temp += colordepth; 1837 return temp;
1997 }
1998
1999 return(temp);
2000} 1838}
2001 1839
2002/*********************************************/ 1840/*********************************************/
@@ -2004,55 +1842,29 @@ SiS_GetOffset(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
2004/*********************************************/ 1842/*********************************************/
2005 1843
2006static void 1844static void
2007SiS_SetSeqRegs(SiS_Private *SiS_Pr, USHORT StandTableIndex, PSIS_HW_INFO HwInfo) 1845SiS_SetSeqRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
2008{ 1846{
2009 UCHAR SRdata; 1847 unsigned char SRdata;
2010 USHORT i; 1848 int i;
2011 1849
2012 SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x03); /* Set SR0 */ 1850 SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x03);
2013 1851
2014 SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[0]; 1852 /* or "display off" */
1853 SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[0] | 0x20;
2015 1854
2016 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 1855 /* determine whether to force x8 dotclock */
2017 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { 1856 if((SiS_Pr->SiS_VBType & VB_SISVB) || (SiS_Pr->SiS_IF_DEF_LVDS)) {
2018 SRdata |= 0x01;
2019 }
2020 if(HwInfo->jChipType >= SIS_661) {
2021 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
2022 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
2023 SRdata |= 0x01; /* 8 dot clock */
2024 }
2025 }
2026 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
2027 if(SiS_Pr->SiS_VBType & VB_NoLCD) {
2028 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
2029 SRdata |= 0x01; /* 8 dot clock */
2030 }
2031 }
2032 }
2033 }
2034 1857
2035 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 1858 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
2036 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 1859 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) SRdata |= 0x01;
2037 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 1860 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) SRdata |= 0x01;
2038 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
2039 SRdata |= 0x01; /* 8 dot clock */
2040 }
2041 }
2042 }
2043 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
2044 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
2045 SRdata |= 0x01; /* 8 dot clock */
2046 }
2047 }
2048 }
2049 1861
2050 SRdata |= 0x20; /* screen off */ 1862 }
2051 1863
2052 SiS_SetReg(SiS_Pr->SiS_P3c4,0x01,SRdata); 1864 SiS_SetReg(SiS_Pr->SiS_P3c4,0x01,SRdata);
2053 1865
2054 for(i = 2; i <= 4; i++) { 1866 for(i = 2; i <= 4; i++) {
2055 SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[i-1]; 1867 SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[i - 1];
2056 SiS_SetReg(SiS_Pr->SiS_P3c4,i,SRdata); 1868 SiS_SetReg(SiS_Pr->SiS_P3c4,i,SRdata);
2057 } 1869 }
2058} 1870}
@@ -2062,17 +1874,17 @@ SiS_SetSeqRegs(SiS_Private *SiS_Pr, USHORT StandTableIndex, PSIS_HW_INFO HwInfo)
2062/*********************************************/ 1874/*********************************************/
2063 1875
2064static void 1876static void
2065SiS_SetMiscRegs(SiS_Private *SiS_Pr, USHORT StandTableIndex, PSIS_HW_INFO HwInfo) 1877SiS_SetMiscRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
2066{ 1878{
2067 UCHAR Miscdata; 1879 unsigned char Miscdata;
2068 1880
2069 Miscdata = SiS_Pr->SiS_StandTable[StandTableIndex].MISC; 1881 Miscdata = SiS_Pr->SiS_StandTable[StandTableIndex].MISC;
2070 1882
2071 if(HwInfo->jChipType < SIS_661) { 1883 if(SiS_Pr->ChipType < SIS_661) {
2072 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 1884 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
2073 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { 1885 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
2074 Miscdata |= 0x0C; 1886 Miscdata |= 0x0C;
2075 } 1887 }
2076 } 1888 }
2077 } 1889 }
2078 1890
@@ -2084,33 +1896,34 @@ SiS_SetMiscRegs(SiS_Private *SiS_Pr, USHORT StandTableIndex, PSIS_HW_INFO HwInfo
2084/*********************************************/ 1896/*********************************************/
2085 1897
2086static void 1898static void
2087SiS_SetCRTCRegs(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 1899SiS_SetCRTCRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
2088 USHORT StandTableIndex)
2089{ 1900{
2090 UCHAR CRTCdata; 1901 unsigned char CRTCdata;
2091 USHORT i; 1902 unsigned short i;
2092 1903
2093 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f); /* Unlock CRTC */ 1904 /* Unlock CRTC */
2094 1905 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
2095 for(i = 0; i <= 0x18; i++) { 1906
2096 CRTCdata = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[i]; 1907 for(i = 0; i <= 0x18; i++) {
2097 SiS_SetReg(SiS_Pr->SiS_P3d4,i,CRTCdata); /* Set CRTC(3d4) */ 1908 CRTCdata = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[i];
2098 } 1909 SiS_SetReg(SiS_Pr->SiS_P3d4,i,CRTCdata);
2099 if(HwInfo->jChipType >= SIS_661) { 1910 }
2100 SiS_SetupCR5x(SiS_Pr, HwInfo); 1911
2101 for(i = 0x13; i <= 0x14; i++) { 1912 if(SiS_Pr->ChipType >= SIS_661) {
2102 CRTCdata = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[i]; 1913 SiS_OpenCRTC(SiS_Pr);
2103 SiS_SetReg(SiS_Pr->SiS_P3d4,i,CRTCdata); 1914 for(i = 0x13; i <= 0x14; i++) {
2104 } 1915 CRTCdata = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[i];
2105 } else if( ( (HwInfo->jChipType == SIS_630) || 1916 SiS_SetReg(SiS_Pr->SiS_P3d4,i,CRTCdata);
2106 (HwInfo->jChipType == SIS_730) ) && 1917 }
2107 (HwInfo->jChipRevision >= 0x30) ) { /* for 630S0 */ 1918 } else if( ( (SiS_Pr->ChipType == SIS_630) ||
2108 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { 1919 (SiS_Pr->ChipType == SIS_730) ) &&
2109 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) { 1920 (SiS_Pr->ChipRevision >= 0x30) ) {
2110 SiS_SetReg(SiS_Pr->SiS_P3d4,0x18,0xFE); 1921 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
2111 } 1922 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
2112 } 1923 SiS_SetReg(SiS_Pr->SiS_P3d4,0x18,0xFE);
2113 } 1924 }
1925 }
1926 }
2114} 1927}
2115 1928
2116/*********************************************/ 1929/*********************************************/
@@ -2118,64 +1931,58 @@ SiS_SetCRTCRegs(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
2118/*********************************************/ 1931/*********************************************/
2119 1932
2120static void 1933static void
2121SiS_SetATTRegs(SiS_Private *SiS_Pr, USHORT StandTableIndex, 1934SiS_SetATTRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
2122 PSIS_HW_INFO HwInfo)
2123{ 1935{
2124 UCHAR ARdata; 1936 unsigned char ARdata;
2125 USHORT i; 1937 unsigned short i;
2126 1938
2127 for(i = 0; i <= 0x13; i++) { 1939 for(i = 0; i <= 0x13; i++) {
2128 ARdata = SiS_Pr->SiS_StandTable[StandTableIndex].ATTR[i]; 1940 ARdata = SiS_Pr->SiS_StandTable[StandTableIndex].ATTR[i];
2129#if 0 1941
2130 if((i <= 0x0f) || (i == 0x11)) {
2131 if(ds:489 & 0x08) {
2132 continue;
2133 }
2134 }
2135#endif
2136 if(i == 0x13) { 1942 if(i == 0x13) {
2137 /* Pixel shift. If screen on LCD or TV is shifted left or right, 1943 /* Pixel shift. If screen on LCD or TV is shifted left or right,
2138 * this might be the cause. 1944 * this might be the cause.
2139 */ 1945 */
2140 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 1946 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
2141 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) ARdata=0; 1947 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) ARdata = 0;
2142 } 1948 }
2143 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 1949 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
2144 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 1950 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
2145 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 1951 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
2146 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata=0; 1952 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
2147 } 1953 }
2148 } 1954 }
2149 } 1955 }
2150 if(HwInfo->jChipType >= SIS_661) { 1956 if(SiS_Pr->ChipType >= SIS_661) {
2151 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) { 1957 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
2152 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata=0; 1958 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
2153 } 1959 }
2154 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 1960 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
2155 if(HwInfo->jChipType >= SIS_315H) { 1961 if(SiS_Pr->ChipType >= SIS_315H) {
2156 if(IS_SIS550650740660) { 1962 if(IS_SIS550650740660) {
2157 /* 315, 330 don't do this */ 1963 /* 315, 330 don't do this */
2158 if(SiS_Pr->SiS_VBType & VB_SIS301B302B) { 1964 if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
2159 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata=0; 1965 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
2160 } else { 1966 } else {
2161 ARdata = 0; 1967 ARdata = 0;
2162 } 1968 }
2163 } 1969 }
2164 } else { 1970 } else {
2165 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata=0; 1971 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
2166 } 1972 }
2167 } 1973 }
2168 } 1974 }
2169 SiS_GetRegByte(SiS_Pr->SiS_P3da); /* reset 3da */ 1975 SiS_GetRegByte(SiS_Pr->SiS_P3da); /* reset 3da */
2170 SiS_SetRegByte(SiS_Pr->SiS_P3c0,i); /* set index */ 1976 SiS_SetRegByte(SiS_Pr->SiS_P3c0,i); /* set index */
2171 SiS_SetRegByte(SiS_Pr->SiS_P3c0,ARdata); /* set data */ 1977 SiS_SetRegByte(SiS_Pr->SiS_P3c0,ARdata); /* set data */
2172 } 1978 }
2173 SiS_GetRegByte(SiS_Pr->SiS_P3da); /* reset 3da */ 1979
2174 SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x14); /* set index */ 1980 SiS_GetRegByte(SiS_Pr->SiS_P3da); /* reset 3da */
2175 SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x00); /* set data */ 1981 SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x14); /* set index */
1982 SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x00); /* set data */
2176 1983
2177 SiS_GetRegByte(SiS_Pr->SiS_P3da); 1984 SiS_GetRegByte(SiS_Pr->SiS_P3da);
2178 SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x20); /* Enable Attribute */ 1985 SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x20); /* Enable Attribute */
2179 SiS_GetRegByte(SiS_Pr->SiS_P3da); 1986 SiS_GetRegByte(SiS_Pr->SiS_P3da);
2180} 1987}
2181 1988
@@ -2184,10 +1991,10 @@ SiS_SetATTRegs(SiS_Private *SiS_Pr, USHORT StandTableIndex,
2184/*********************************************/ 1991/*********************************************/
2185 1992
2186static void 1993static void
2187SiS_SetGRCRegs(SiS_Private *SiS_Pr, USHORT StandTableIndex) 1994SiS_SetGRCRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
2188{ 1995{
2189 UCHAR GRdata; 1996 unsigned char GRdata;
2190 USHORT i; 1997 unsigned short i;
2191 1998
2192 for(i = 0; i <= 0x08; i++) { 1999 for(i = 0; i <= 0x08; i++) {
2193 GRdata = SiS_Pr->SiS_StandTable[StandTableIndex].GRC[i]; 2000 GRdata = SiS_Pr->SiS_StandTable[StandTableIndex].GRC[i];
@@ -2205,22 +2012,22 @@ SiS_SetGRCRegs(SiS_Private *SiS_Pr, USHORT StandTableIndex)
2205/*********************************************/ 2012/*********************************************/
2206 2013
2207static void 2014static void
2208SiS_ClearExt1Regs(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo) 2015SiS_ClearExt1Regs(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
2209{ 2016{
2210 USHORT i; 2017 unsigned short i;
2211 2018
2212 for(i = 0x0A; i <= 0x0E; i++) { 2019 for(i = 0x0A; i <= 0x0E; i++) {
2213 SiS_SetReg(SiS_Pr->SiS_P3c4,i,0x00); 2020 SiS_SetReg(SiS_Pr->SiS_P3c4,i,0x00);
2214 } 2021 }
2215 2022
2216 if(HwInfo->jChipType >= SIS_315H) { 2023 if(SiS_Pr->ChipType >= SIS_315H) {
2217 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x37,0xFE); 2024 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x37,0xFE);
2218 if(ModeNo <= 0x13) { 2025 if(ModeNo <= 0x13) {
2219 if(ModeNo == 0x06 || ModeNo >= 0x0e) { 2026 if(ModeNo == 0x06 || ModeNo >= 0x0e) {
2220 SiS_SetReg(SiS_Pr->SiS_P3c4,0x0e,0x20); 2027 SiS_SetReg(SiS_Pr->SiS_P3c4,0x0e,0x20);
2221 } 2028 }
2222 } 2029 }
2223 } 2030 }
2224} 2031}
2225 2032
2226/*********************************************/ 2033/*********************************************/
@@ -2228,32 +2035,24 @@ SiS_ClearExt1Regs(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
2228/*********************************************/ 2035/*********************************************/
2229 2036
2230static void 2037static void
2231SiS_ResetCRT1VCLK(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 2038SiS_ResetCRT1VCLK(struct SiS_Private *SiS_Pr)
2232{ 2039{
2233 if(HwInfo->jChipType >= SIS_315H) { 2040 if(SiS_Pr->ChipType >= SIS_315H) {
2234 if(HwInfo->jChipType < SIS_661) { 2041 if(SiS_Pr->ChipType < SIS_661) {
2235 if(SiS_Pr->SiS_IF_DEF_LVDS == 0) return; 2042 if(SiS_Pr->SiS_IF_DEF_LVDS == 0) return;
2236 } 2043 }
2237 } else { 2044 } else {
2238 if((SiS_Pr->SiS_IF_DEF_LVDS == 0) && 2045 if((SiS_Pr->SiS_IF_DEF_LVDS == 0) &&
2239 (!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) ) { 2046 (!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) ) {
2240 return; 2047 return;
2241 } 2048 }
2242 } 2049 }
2243 2050
2244 if(HwInfo->jChipType >= SIS_315H) { 2051 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x31,0xcf,0x20);
2245 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x31,0xCF,0x20);
2246 } else {
2247 SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x20);
2248 }
2249 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2B,SiS_Pr->SiS_VCLKData[1].SR2B); 2052 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2B,SiS_Pr->SiS_VCLKData[1].SR2B);
2250 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2C,SiS_Pr->SiS_VCLKData[1].SR2C); 2053 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2C,SiS_Pr->SiS_VCLKData[1].SR2C);
2251 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80); 2054 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80);
2252 if(HwInfo->jChipType >= SIS_315H) { 2055 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x31,0xcf,0x10);
2253 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x31,0xcf,0x10);
2254 } else {
2255 SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x10);
2256 }
2257 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2B,SiS_Pr->SiS_VCLKData[0].SR2B); 2056 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2B,SiS_Pr->SiS_VCLKData[0].SR2B);
2258 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2C,SiS_Pr->SiS_VCLKData[0].SR2C); 2057 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2C,SiS_Pr->SiS_VCLKData[0].SR2C);
2259 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80); 2058 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80);
@@ -2264,19 +2063,19 @@ SiS_ResetCRT1VCLK(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
2264/*********************************************/ 2063/*********************************************/
2265 2064
2266static void 2065static void
2267SiS_SetCRT1Sync(SiS_Private *SiS_Pr, USHORT RefreshRateTableIndex) 2066SiS_SetCRT1Sync(struct SiS_Private *SiS_Pr, unsigned short RRTI)
2268{ 2067{
2269 USHORT sync; 2068 unsigned short sync;
2270 2069
2271 if(SiS_Pr->UseCustomMode) { 2070 if(SiS_Pr->UseCustomMode) {
2272 sync = SiS_Pr->CInfoFlag >> 8; 2071 sync = SiS_Pr->CInfoFlag >> 8;
2273 } else { 2072 } else {
2274 sync = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8; 2073 sync = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag >> 8;
2275 } 2074 }
2276 2075
2277 sync &= 0xC0; 2076 sync &= 0xC0;
2278 sync |= 0x2f; 2077 sync |= 0x2f;
2279 SiS_SetRegByte(SiS_Pr->SiS_P3c2,sync); 2078 SiS_SetRegByte(SiS_Pr->SiS_P3c2,sync);
2280} 2079}
2281 2080
2282/*********************************************/ 2081/*********************************************/
@@ -2284,72 +2083,67 @@ SiS_SetCRT1Sync(SiS_Private *SiS_Pr, USHORT RefreshRateTableIndex)
2284/*********************************************/ 2083/*********************************************/
2285 2084
2286static void 2085static void
2287SiS_SetCRT1CRTC(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 2086SiS_SetCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2288 USHORT RefreshRateTableIndex, 2087 unsigned short ModeIdIndex, unsigned short RRTI)
2289 PSIS_HW_INFO HwInfo)
2290{ 2088{
2291 UCHAR index; 2089 unsigned short temp, i, j, modeflag;
2292 USHORT temp,i,j,modeflag; 2090 unsigned char *crt1data = NULL;
2293 2091
2294 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f); /* unlock cr0-7 */ 2092 modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
2295 2093
2296 if(SiS_Pr->UseCustomMode) { 2094 if(SiS_Pr->UseCustomMode) {
2297 2095
2298 modeflag = SiS_Pr->CModeFlag; 2096 crt1data = &SiS_Pr->CCRT1CRTC[0];
2299 2097
2300 for(i=0,j=0;i<=7;i++,j++) { 2098 } else {
2301 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]); 2099
2302 } 2100 temp = SiS_GetRefCRT1CRTC(SiS_Pr, RRTI, SiS_Pr->SiS_UseWide);
2303 for(j=0x10;i<=10;i++,j++) { 2101
2304 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]); 2102 /* Alternate for 1600x1200 LCDA */
2305 } 2103 if((temp == 0x20) && (SiS_Pr->Alternate1600x1200)) temp = 0x57;
2306 for(j=0x15;i<=12;i++,j++) { 2104
2307 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]); 2105 crt1data = (unsigned char *)&SiS_Pr->SiS_CRT1Table[temp].CR[0];
2308 } 2106
2309 for(j=0x0A;i<=15;i++,j++) { 2107 }
2310 SiS_SetReg(SiS_Pr->SiS_P3c4,j,SiS_Pr->CCRT1CRTC[i]); 2108
2311 } 2109 /* unlock cr0-7 */
2312 2110 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
2313 temp = SiS_Pr->CCRT1CRTC[16] & 0xE0; 2111
2314 SiS_SetReg(SiS_Pr->SiS_P3c4,0x0E,temp); 2112 for(i = 0, j = 0; i <= 7; i++, j++) {
2315 2113 SiS_SetReg(SiS_Pr->SiS_P3d4,j,crt1data[i]);
2316 temp = (SiS_Pr->CCRT1CRTC[16] & 0x01) << 5; 2114 }
2317 if(modeflag & DoubleScanMode) temp |= 0x80; 2115 for(j = 0x10; i <= 10; i++, j++) {
2318 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,0x5F,temp); 2116 SiS_SetReg(SiS_Pr->SiS_P3d4,j,crt1data[i]);
2319 2117 }
2320 } else { 2118 for(j = 0x15; i <= 12; i++, j++) {
2321 2119 SiS_SetReg(SiS_Pr->SiS_P3d4,j,crt1data[i]);
2322 if(ModeNo <= 0x13) { 2120 }
2323 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; 2121 for(j = 0x0A; i <= 15; i++, j++) {
2324 } else { 2122 SiS_SetReg(SiS_Pr->SiS_P3c4,j,crt1data[i]);
2325 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 2123 }
2326 } 2124
2327 2125 SiS_SetReg(SiS_Pr->SiS_P3c4,0x0E,crt1data[16] & 0xE0);
2328 index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; 2126
2329 2127 temp = (crt1data[16] & 0x01) << 5;
2330 for(i=0,j=0;i<=7;i++,j++) { 2128 if(modeflag & DoubleScanMode) temp |= 0x80;
2331 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->SiS_CRT1Table[index].CR[i]); 2129 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,0x5F,temp);
2332 } 2130
2333 for(j=0x10;i<=10;i++,j++) { 2131 if(SiS_Pr->SiS_ModeType > ModeVGA) {
2334 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->SiS_CRT1Table[index].CR[i]); 2132 SiS_SetReg(SiS_Pr->SiS_P3d4,0x14,0x4F);
2335 } 2133 }
2336 for(j=0x15;i<=12;i++,j++) { 2134
2337 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->SiS_CRT1Table[index].CR[i]); 2135#ifdef SIS315H
2338 } 2136 if(SiS_Pr->ChipType == XGI_20) {
2339 for(j=0x0A;i<=15;i++,j++) { 2137 SiS_SetReg(SiS_Pr->SiS_P3d4,0x04,crt1data[4] - 1);
2340 SiS_SetReg(SiS_Pr->SiS_P3c4,j,SiS_Pr->SiS_CRT1Table[index].CR[i]); 2138 if(!(temp = crt1data[5] & 0x1f)) {
2341 } 2139 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x0c,0xfb);
2342 2140 }
2343 temp = SiS_Pr->SiS_CRT1Table[index].CR[16] & 0xE0; 2141 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x05,0xe0,((temp - 1) & 0x1f));
2344 SiS_SetReg(SiS_Pr->SiS_P3c4,0x0E,temp); 2142 temp = (crt1data[16] >> 5) + 3;
2345 2143 if(temp > 7) temp -= 7;
2346 temp = ((SiS_Pr->SiS_CRT1Table[index].CR[16]) & 0x01) << 5; 2144 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0e,0x1f,(temp << 5));
2347 if(modeflag & DoubleScanMode) temp |= 0x80; 2145 }
2348 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,0x5F,temp); 2146#endif
2349
2350 }
2351
2352 if(SiS_Pr->SiS_ModeType > ModeVGA) SiS_SetReg(SiS_Pr->SiS_P3d4,0x14,0x4F);
2353} 2147}
2354 2148
2355/*********************************************/ 2149/*********************************************/
@@ -2359,33 +2153,32 @@ SiS_SetCRT1CRTC(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2359/*********************************************/ 2153/*********************************************/
2360 2154
2361static void 2155static void
2362SiS_SetCRT1Offset(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 2156SiS_SetCRT1Offset(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2363 USHORT RefreshRateTableIndex, 2157 unsigned short ModeIdIndex, unsigned short RRTI)
2364 PSIS_HW_INFO HwInfo)
2365{ 2158{
2366 USHORT temp, DisplayUnit, infoflag; 2159 unsigned short temp, DisplayUnit, infoflag;
2367 2160
2368 if(SiS_Pr->UseCustomMode) { 2161 if(SiS_Pr->UseCustomMode) {
2369 infoflag = SiS_Pr->CInfoFlag; 2162 infoflag = SiS_Pr->CInfoFlag;
2370 } else { 2163 } else {
2371 infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag; 2164 infoflag = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag;
2372 } 2165 }
2373 2166
2374 DisplayUnit = SiS_GetOffset(SiS_Pr,ModeNo,ModeIdIndex, 2167 DisplayUnit = SiS_GetOffset(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
2375 RefreshRateTableIndex,HwInfo);
2376 2168
2377 temp = (DisplayUnit >> 8) & 0x0f; 2169 temp = (DisplayUnit >> 8) & 0x0f;
2378 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0xF0,temp); 2170 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0xF0,temp);
2379 2171
2380 temp = DisplayUnit & 0xFF; 2172 SiS_SetReg(SiS_Pr->SiS_P3d4,0x13,DisplayUnit & 0xFF);
2381 SiS_SetReg(SiS_Pr->SiS_P3d4,0x13,temp);
2382 2173
2383 if(infoflag & InterlaceMode) DisplayUnit >>= 1; 2174 if(infoflag & InterlaceMode) DisplayUnit >>= 1;
2384 2175
2385 DisplayUnit <<= 5; 2176 DisplayUnit <<= 5;
2386 temp = (DisplayUnit & 0xff00) >> 8; 2177 temp = (DisplayUnit >> 8) + 1;
2387 if(DisplayUnit & 0xff) temp++; 2178 if(DisplayUnit & 0xff) temp++;
2388 temp++; 2179 if(SiS_Pr->ChipType == XGI_20) {
2180 if(ModeNo == 0x4a || ModeNo == 0x49) temp--;
2181 }
2389 SiS_SetReg(SiS_Pr->SiS_P3c4,0x10,temp); 2182 SiS_SetReg(SiS_Pr->SiS_P3c4,0x10,temp);
2390} 2183}
2391 2184
@@ -2394,39 +2187,49 @@ SiS_SetCRT1Offset(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2394/*********************************************/ 2187/*********************************************/
2395 2188
2396static void 2189static void
2397SiS_SetCRT1VCLK(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 2190SiS_SetCRT1VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2398 PSIS_HW_INFO HwInfo, USHORT RefreshRateTableIndex) 2191 unsigned short ModeIdIndex, unsigned short RRTI)
2399{ 2192{
2400 USHORT index=0, clka, clkb; 2193 unsigned short index = 0, clka, clkb;
2401 2194
2402 if(SiS_Pr->UseCustomMode) { 2195 if(SiS_Pr->UseCustomMode) {
2403 clka = SiS_Pr->CSR2B; 2196 clka = SiS_Pr->CSR2B;
2404 clkb = SiS_Pr->CSR2C; 2197 clkb = SiS_Pr->CSR2C;
2405 } else { 2198 } else {
2406 index = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo); 2199 index = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
2407 if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { 2200 if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) &&
2408 clka = SiS_Pr->SiS_VBVCLKData[index].Part4_A; 2201 (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
2409 clkb = SiS_Pr->SiS_VBVCLKData[index].Part4_B; 2202 /* Alternate for 1600x1200 LCDA */
2410 } else { 2203 if((index == 0x21) && (SiS_Pr->Alternate1600x1200)) index = 0x72;
2411 clka = SiS_Pr->SiS_VCLKData[index].SR2B; 2204 clka = SiS_Pr->SiS_VBVCLKData[index].Part4_A;
2412 clkb = SiS_Pr->SiS_VCLKData[index].SR2C; 2205 clkb = SiS_Pr->SiS_VBVCLKData[index].Part4_B;
2413 } 2206 } else {
2414 } 2207 clka = SiS_Pr->SiS_VCLKData[index].SR2B;
2415 2208 clkb = SiS_Pr->SiS_VCLKData[index].SR2C;
2416 if(HwInfo->jChipType >= SIS_315H) { 2209 }
2417 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x31,0xCF); 2210 }
2418 } else { 2211
2419 SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x00); 2212 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x31,0xCF);
2420 } 2213
2421 2214 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2b,clka);
2422 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2B,clka); 2215 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,clkb);
2423 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2C,clkb); 2216
2424 2217 if(SiS_Pr->ChipType >= SIS_315H) {
2425 if(HwInfo->jChipType >= SIS_315H) { 2218#ifdef SIS315H
2426 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x01); 2219 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x01);
2427 } else { 2220 if(SiS_Pr->ChipType == XGI_20) {
2428 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80); 2221 unsigned short mf = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
2429 } 2222 if(mf & HalfDCLK) {
2223 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2b,SiS_GetReg(SiS_Pr->SiS_P3c4,0x2b));
2224 clkb = SiS_GetReg(SiS_Pr->SiS_P3c4,0x2c);
2225 clkb = (((clkb & 0x1f) << 1) + 1) | (clkb & 0xe0);
2226 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,clkb);
2227 }
2228 }
2229#endif
2230 } else {
2231 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80);
2232 }
2430} 2233}
2431 2234
2432/*********************************************/ 2235/*********************************************/
@@ -2434,415 +2237,358 @@ SiS_SetCRT1VCLK(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2434/*********************************************/ 2237/*********************************************/
2435 2238
2436#ifdef SIS300 2239#ifdef SIS300
2437static USHORT 2240void
2438SiS_DoCalcDelay(SiS_Private *SiS_Pr, USHORT MCLK, USHORT VCLK, USHORT colordepth, USHORT key) 2241SiS_GetFIFOThresholdIndex300(struct SiS_Private *SiS_Pr, unsigned short *idx1,
2242 unsigned short *idx2)
2243{
2244 unsigned short temp1, temp2;
2245 static const unsigned char ThTiming[8] = {
2246 1, 2, 2, 3, 0, 1, 1, 2
2247 };
2248
2249 temp1 = temp2 = (SiS_GetReg(SiS_Pr->SiS_P3c4,0x18) & 0x62) >> 1;
2250 (*idx2) = (unsigned short)(ThTiming[((temp2 >> 3) | temp1) & 0x07]);
2251 (*idx1) = (unsigned short)(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) >> 6) & 0x03;
2252 (*idx1) |= (unsigned short)(((SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) >> 4) & 0x0c));
2253 (*idx1) <<= 1;
2254}
2255
2256static unsigned short
2257SiS_GetFIFOThresholdA300(unsigned short idx1, unsigned short idx2)
2258{
2259 static const unsigned char ThLowA[8 * 3] = {
2260 61, 3,52, 5,68, 7,100,11,
2261 43, 3,42, 5,54, 7, 78,11,
2262 34, 3,37, 5,47, 7, 67,11
2263 };
2264
2265 return (unsigned short)((ThLowA[idx1 + 1] * idx2) + ThLowA[idx1]);
2266}
2267
2268unsigned short
2269SiS_GetFIFOThresholdB300(unsigned short idx1, unsigned short idx2)
2270{
2271 static const unsigned char ThLowB[8 * 3] = {
2272 81, 4,72, 6,88, 8,120,12,
2273 55, 4,54, 6,66, 8, 90,12,
2274 42, 4,45, 6,55, 8, 75,12
2275 };
2276
2277 return (unsigned short)((ThLowB[idx1 + 1] * idx2) + ThLowB[idx1]);
2278}
2279
2280static unsigned short
2281SiS_DoCalcDelay(struct SiS_Private *SiS_Pr, unsigned short MCLK, unsigned short VCLK,
2282 unsigned short colordepth, unsigned short key)
2439{ 2283{
2440 const UCHAR ThLowA[] = { 61, 3,52, 5,68, 7,100,11, 2284 unsigned short idx1, idx2;
2441 43, 3,42, 5,54, 7, 78,11, 2285 unsigned int longtemp = VCLK * colordepth;
2442 34, 3,37, 5,47, 7, 67,11 }; 2286
2443 2287 SiS_GetFIFOThresholdIndex300(SiS_Pr, &idx1, &idx2);
2444 const UCHAR ThLowB[] = { 81, 4,72, 6,88, 8,120,12, 2288
2445 55, 4,54, 6,66, 8, 90,12, 2289 if(key == 0) {
2446 42, 4,45, 6,55, 8, 75,12 }; 2290 longtemp *= SiS_GetFIFOThresholdA300(idx1, idx2);
2447 2291 } else {
2448 const UCHAR ThTiming[] = { 1, 2, 2, 3, 0, 1, 1, 2 }; 2292 longtemp *= SiS_GetFIFOThresholdB300(idx1, idx2);
2449 2293 }
2450 USHORT tempah, tempal, tempcl, tempbx, temp; 2294 idx1 = longtemp % (MCLK * 16);
2451 ULONG longtemp; 2295 longtemp /= (MCLK * 16);
2452 2296 if(idx1) longtemp++;
2453 tempah = SiS_GetReg(SiS_Pr->SiS_P3c4,0x18); 2297 return (unsigned short)longtemp;
2454 tempah &= 0x62;
2455 tempah >>= 1;
2456 tempal = tempah;
2457 tempah >>= 3;
2458 tempal |= tempah;
2459 tempal &= 0x07;
2460 tempcl = ThTiming[tempal];
2461 tempbx = SiS_GetReg(SiS_Pr->SiS_P3c4,0x16);
2462 tempbx >>= 6;
2463 tempah = SiS_GetReg(SiS_Pr->SiS_P3c4,0x14);
2464 tempah >>= 4;
2465 tempah &= 0x0c;
2466 tempbx |= tempah;
2467 tempbx <<= 1;
2468 if(key == 0) {
2469 tempal = ThLowA[tempbx + 1];
2470 tempal *= tempcl;
2471 tempal += ThLowA[tempbx];
2472 } else {
2473 tempal = ThLowB[tempbx + 1];
2474 tempal *= tempcl;
2475 tempal += ThLowB[tempbx];
2476 }
2477 longtemp = tempal * VCLK * colordepth;
2478 temp = longtemp % (MCLK * 16);
2479 longtemp /= (MCLK * 16);
2480 if(temp) longtemp++;
2481 return((USHORT)longtemp);
2482} 2298}
2483 2299
2484static USHORT 2300static unsigned short
2485SiS_CalcDelay(SiS_Private *SiS_Pr, USHORT VCLK, USHORT colordepth, USHORT MCLK) 2301SiS_CalcDelay(struct SiS_Private *SiS_Pr, unsigned short VCLK,
2302 unsigned short colordepth, unsigned short MCLK)
2486{ 2303{
2487 USHORT tempax, tempbx; 2304 unsigned short temp1, temp2;
2488 2305
2489 tempbx = SiS_DoCalcDelay(SiS_Pr, MCLK, VCLK, colordepth, 0); 2306 temp2 = SiS_DoCalcDelay(SiS_Pr, MCLK, VCLK, colordepth, 0);
2490 tempax = SiS_DoCalcDelay(SiS_Pr, MCLK, VCLK, colordepth, 1); 2307 temp1 = SiS_DoCalcDelay(SiS_Pr, MCLK, VCLK, colordepth, 1);
2491 if(tempax < 4) tempax = 4; 2308 if(temp1 < 4) temp1 = 4;
2492 tempax -= 4; 2309 temp1 -= 4;
2493 if(tempbx < tempax) tempbx = tempax; 2310 if(temp2 < temp1) temp2 = temp1;
2494 return(tempbx); 2311 return temp2;
2495} 2312}
2496 2313
2497static void 2314static void
2498SiS_SetCRT1FIFO_300(SiS_Private *SiS_Pr, USHORT ModeNo, PSIS_HW_INFO HwInfo, 2315SiS_SetCRT1FIFO_300(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2499 USHORT RefreshRateTableIndex) 2316 unsigned short RefreshRateTableIndex)
2317{
2318 unsigned short ThresholdLow = 0;
2319 unsigned short temp, index, VCLK, MCLK, colorth;
2320 static const unsigned short colortharray[6] = { 1, 1, 2, 2, 3, 4 };
2321
2322 if(ModeNo > 0x13) {
2323
2324 /* Get VCLK */
2325 if(SiS_Pr->UseCustomMode) {
2326 VCLK = SiS_Pr->CSRClock;
2327 } else {
2328 index = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWide);
2329 VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
2330 }
2331
2332 /* Get half colordepth */
2333 colorth = colortharray[(SiS_Pr->SiS_ModeType - ModeEGA)];
2334
2335 /* Get MCLK */
2336 index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3A) & 0x07;
2337 MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK;
2338
2339 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xc3;
2340 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x16,0x3c,temp);
2341
2342 do {
2343 ThresholdLow = SiS_CalcDelay(SiS_Pr, VCLK, colorth, MCLK) + 1;
2344 if(ThresholdLow < 0x13) break;
2345 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x16,0xfc);
2346 ThresholdLow = 0x13;
2347 temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) >> 6;
2348 if(!temp) break;
2349 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x16,0x3f,((temp - 1) << 6));
2350 } while(0);
2351
2352 } else ThresholdLow = 2;
2353
2354 /* Write CRT/CPU threshold low, CRT/Engine threshold high */
2355 temp = (ThresholdLow << 4) | 0x0f;
2356 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,temp);
2357
2358 temp = (ThresholdLow & 0x10) << 1;
2359 if(ModeNo > 0x13) temp |= 0x40;
2360 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0f,0x9f,temp);
2361
2362 /* What is this? */
2363 SiS_SetReg(SiS_Pr->SiS_P3c4,0x3B,0x09);
2364
2365 /* Write CRT/CPU threshold high */
2366 temp = ThresholdLow + 3;
2367 if(temp > 0x0f) temp = 0x0f;
2368 SiS_SetReg(SiS_Pr->SiS_P3c4,0x09,temp);
2369}
2370
2371unsigned short
2372SiS_GetLatencyFactor630(struct SiS_Private *SiS_Pr, unsigned short index)
2500{ 2373{
2501 USHORT ThresholdLow = 0; 2374 static const unsigned char LatencyFactor[] = {
2502 USHORT index, VCLK, MCLK, colorth=0; 2375 97, 88, 86, 79, 77, 0, /* 64 bit BQ=2 */
2503 USHORT tempah, temp; 2376 0, 87, 85, 78, 76, 54, /* 64 bit BQ=1 */
2504 2377 97, 88, 86, 79, 77, 0, /* 128 bit BQ=2 */
2505 if(ModeNo > 0x13) { 2378 0, 79, 77, 70, 68, 48, /* 128 bit BQ=1 */
2506 2379 80, 72, 69, 63, 61, 0, /* 64 bit BQ=2 */
2507 if(SiS_Pr->UseCustomMode) { 2380 0, 70, 68, 61, 59, 37, /* 64 bit BQ=1 */
2508 VCLK = SiS_Pr->CSRClock; 2381 86, 77, 75, 68, 66, 0, /* 128 bit BQ=2 */
2509 } else { 2382 0, 68, 66, 59, 57, 37 /* 128 bit BQ=1 */
2510 index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK; 2383 };
2511 index &= 0x3F; 2384 static const unsigned char LatencyFactor730[] = {
2512 VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK; /* Get VCLK */ 2385 69, 63, 61,
2513 } 2386 86, 79, 77,
2514 2387 103, 96, 94,
2515 switch (SiS_Pr->SiS_ModeType - ModeEGA) { /* Get half colordepth */ 2388 120,113,111,
2516 case 0 : colorth = 1; break; 2389 137,130,128
2517 case 1 : colorth = 1; break; 2390 };
2518 case 2 : colorth = 2; break; 2391
2519 case 3 : colorth = 2; break; 2392 if(SiS_Pr->ChipType == SIS_730) {
2520 case 4 : colorth = 3; break; 2393 return (unsigned short)LatencyFactor730[index];
2521 case 5 : colorth = 4; break; 2394 } else {
2522 } 2395 return (unsigned short)LatencyFactor[index];
2523 2396 }
2524 index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3A);
2525 index &= 0x07;
2526 MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK; /* Get MCLK */
2527
2528 tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
2529 tempah &= 0xc3;
2530 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x16,0x3c,tempah);
2531
2532 do {
2533 ThresholdLow = SiS_CalcDelay(SiS_Pr, VCLK, colorth, MCLK);
2534 ThresholdLow++;
2535 if(ThresholdLow < 0x13) break;
2536 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x16,0xfc);
2537 ThresholdLow = 0x13;
2538 tempah = SiS_GetReg(SiS_Pr->SiS_P3c4,0x16);
2539 tempah >>= 6;
2540 if(!(tempah)) break;
2541 tempah--;
2542 tempah <<= 6;
2543 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x16,0x3f,tempah);
2544 } while(0);
2545
2546 } else ThresholdLow = 2;
2547
2548 /* Write CRT/CPU threshold low, CRT/Engine threshold high */
2549 temp = (ThresholdLow << 4) | 0x0f;
2550 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,temp);
2551
2552 temp = (ThresholdLow & 0x10) << 1;
2553 if(ModeNo > 0x13) temp |= 0x40;
2554 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0f,0x9f,temp);
2555
2556 /* What is this? */
2557 SiS_SetReg(SiS_Pr->SiS_P3c4,0x3B,0x09);
2558
2559 /* Write CRT/CPU threshold high */
2560 temp = ThresholdLow + 3;
2561 if(temp > 0x0f) temp = 0x0f;
2562 SiS_SetReg(SiS_Pr->SiS_P3c4,0x09,temp);
2563} 2397}
2564 2398
2565static USHORT 2399static unsigned short
2566SiS_CalcDelay2(SiS_Private *SiS_Pr, UCHAR key, PSIS_HW_INFO HwInfo) 2400SiS_CalcDelay2(struct SiS_Private *SiS_Pr, unsigned char key)
2567{ 2401{
2568 USHORT data,index; 2402 unsigned short index;
2569 const UCHAR LatencyFactor[] = { 2403
2570 97, 88, 86, 79, 77, 00, /*; 64 bit BQ=2 */ 2404 if(SiS_Pr->ChipType == SIS_730) {
2571 00, 87, 85, 78, 76, 54, /*; 64 bit BQ=1 */ 2405 index = ((key & 0x0f) * 3) + ((key & 0xc0) >> 6);
2572 97, 88, 86, 79, 77, 00, /*; 128 bit BQ=2 */ 2406 } else {
2573 00, 79, 77, 70, 68, 48, /*; 128 bit BQ=1 */ 2407 index = (key & 0xe0) >> 5;
2574 80, 72, 69, 63, 61, 00, /*; 64 bit BQ=2 */ 2408 if(key & 0x10) index += 6;
2575 00, 70, 68, 61, 59, 37, /*; 64 bit BQ=1 */ 2409 if(!(key & 0x01)) index += 24;
2576 86, 77, 75, 68, 66, 00, /*; 128 bit BQ=2 */ 2410 if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80) index += 12;
2577 00, 68, 66, 59, 57, 37 /*; 128 bit BQ=1 */ 2411 }
2578 }; 2412 return SiS_GetLatencyFactor630(SiS_Pr, index);
2579 const UCHAR LatencyFactor730[] = {
2580 69, 63, 61,
2581 86, 79, 77,
2582 103, 96, 94,
2583 120,113,111,
2584 137,130,128, /* --- Table ends with this entry, data below */
2585 137,130,128, /* to avoid using illegal values */
2586 137,130,128,
2587 137,130,128,
2588 137,130,128,
2589 137,130,128,
2590 137,130,128,
2591 137,130,128,
2592 137,130,128,
2593 137,130,128,
2594 137,130,128,
2595 137,130,128,
2596 };
2597
2598 if(HwInfo->jChipType == SIS_730) {
2599 index = ((key & 0x0f) * 3) + ((key & 0xC0) >> 6);
2600 data = LatencyFactor730[index];
2601 } else {
2602 index = (key & 0xE0) >> 5;
2603 if(key & 0x10) index +=6;
2604 if(!(key & 0x01)) index += 24;
2605 data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x14);
2606 if(data & 0x0080) index += 12;
2607 data = LatencyFactor[index];
2608 }
2609 return(data);
2610} 2413}
2611 2414
2612static void 2415static void
2613SiS_SetCRT1FIFO_630(SiS_Private *SiS_Pr, USHORT ModeNo, 2416SiS_SetCRT1FIFO_630(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2614 PSIS_HW_INFO HwInfo, 2417 unsigned short RefreshRateTableIndex)
2615 USHORT RefreshRateTableIndex)
2616{ 2418{
2617 USHORT i,index,data,VCLK,MCLK,colorth=0; 2419 unsigned short ThresholdLow = 0;
2618 ULONG B,eax,bl,data2; 2420 unsigned short i, data, VCLK, MCLK16, colorth = 0;
2619 USHORT ThresholdLow=0; 2421 unsigned int templ, datal;
2620 UCHAR FQBQData[]= { 2422 const unsigned char *queuedata = NULL;
2621 0x01,0x21,0x41,0x61,0x81, 2423 static const unsigned char FQBQData[21] = {
2622 0x31,0x51,0x71,0x91,0xb1, 2424 0x01,0x21,0x41,0x61,0x81,
2623 0x00,0x20,0x40,0x60,0x80, 2425 0x31,0x51,0x71,0x91,0xb1,
2624 0x30,0x50,0x70,0x90,0xb0, 2426 0x00,0x20,0x40,0x60,0x80,
2625 0xFF 2427 0x30,0x50,0x70,0x90,0xb0,
2626 }; 2428 0xff
2627 UCHAR FQBQData730[]= { 2429 };
2628 0x34,0x74,0xb4, 2430 static const unsigned char FQBQData730[16] = {
2629 0x23,0x63,0xa3, 2431 0x34,0x74,0xb4,
2630 0x12,0x52,0x92, 2432 0x23,0x63,0xa3,
2631 0x01,0x41,0x81, 2433 0x12,0x52,0x92,
2632 0x00,0x40,0x80, 2434 0x01,0x41,0x81,
2633 0xff 2435 0x00,0x40,0x80,
2634 }; 2436 0xff
2635 2437 };
2636 i=0; 2438 static const unsigned short colortharray[6] = {
2637 if(ModeNo > 0x13) { 2439 1, 1, 2, 2, 3, 4
2638 if(SiS_Pr->UseCustomMode) { 2440 };
2639 VCLK = SiS_Pr->CSRClock;
2640 } else {
2641 index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
2642 index &= 0x3F;
2643 VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK; /* Get VCLK */
2644 }
2645
2646 index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1A);
2647 index &= 0x07;
2648 MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK; /* Get MCLK */
2649
2650 data2 = SiS_Pr->SiS_ModeType - ModeEGA; /* Get half colordepth */
2651 switch (data2) {
2652 case 0 : colorth = 1; break;
2653 case 1 : colorth = 1; break;
2654 case 2 : colorth = 2; break;
2655 case 3 : colorth = 2; break;
2656 case 4 : colorth = 3; break;
2657 case 5 : colorth = 4; break;
2658 }
2659
2660 if(HwInfo->jChipType == SIS_730) {
2661
2662 do {
2663 B = SiS_CalcDelay2(SiS_Pr, FQBQData730[i], HwInfo) * VCLK * colorth;
2664 bl = B / (MCLK * 16);
2665
2666 if(B == bl * 16 * MCLK) {
2667 bl = bl + 1;
2668 } else {
2669 bl = bl + 2;
2670 }
2671
2672 if(bl > 0x13) {
2673 if(FQBQData730[i+1] == 0xFF) {
2674 ThresholdLow = 0x13;
2675 break;
2676 }
2677 i++;
2678 } else {
2679 ThresholdLow = bl;
2680 break;
2681 }
2682 } while(FQBQData730[i] != 0xFF);
2683 2441
2684 } else { 2442 i = 0;
2685 2443
2686 do { 2444 if(ModeNo > 0x13) {
2687 B = SiS_CalcDelay2(SiS_Pr, FQBQData[i], HwInfo) * VCLK * colorth;
2688 bl = B / (MCLK * 16);
2689 2445
2690 if(B == bl * 16 * MCLK) { 2446 /* Get VCLK */
2691 bl = bl + 1; 2447 if(SiS_Pr->UseCustomMode) {
2692 } else { 2448 VCLK = SiS_Pr->CSRClock;
2693 bl = bl + 2; 2449 } else {
2694 } 2450 data = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWide);
2451 VCLK = SiS_Pr->SiS_VCLKData[data].CLOCK;
2452 }
2695 2453
2696 if(bl > 0x13) { 2454 /* Get MCLK * 16 */
2697 if(FQBQData[i+1] == 0xFF) { 2455 data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1A) & 0x07;
2698 ThresholdLow = 0x13; 2456 MCLK16 = SiS_Pr->SiS_MCLKData_0[data].CLOCK * 16;
2699 break; 2457
2700 } 2458 /* Get half colordepth */
2701 i++; 2459 colorth = colortharray[(SiS_Pr->SiS_ModeType - ModeEGA)];
2702 } else { 2460
2703 ThresholdLow = bl; 2461 if(SiS_Pr->ChipType == SIS_730) {
2704 break; 2462 queuedata = &FQBQData730[0];
2705 } 2463 } else {
2706 } while(FQBQData[i] != 0xFF); 2464 queuedata = &FQBQData[0];
2707 } 2465 }
2708 } 2466
2709 else { 2467 do {
2710 if(HwInfo->jChipType == SIS_730) { 2468 templ = SiS_CalcDelay2(SiS_Pr, queuedata[i]) * VCLK * colorth;
2711 } else { 2469
2712 i = 9; 2470 datal = templ % MCLK16;
2713 } 2471 templ = (templ / MCLK16) + 1;
2714 ThresholdLow = 0x02; 2472 if(datal) templ++;
2715 } 2473
2474 if(templ > 0x13) {
2475 if(queuedata[i + 1] == 0xFF) {
2476 ThresholdLow = 0x13;
2477 break;
2478 }
2479 i++;
2480 } else {
2481 ThresholdLow = templ;
2482 break;
2483 }
2484 } while(queuedata[i] != 0xFF);
2485
2486 } else {
2487
2488 if(SiS_Pr->ChipType != SIS_730) i = 9;
2489 ThresholdLow = 0x02;
2490
2491 }
2492
2493 /* Write CRT/CPU threshold low, CRT/Engine threshold high */
2494 data = ((ThresholdLow & 0x0f) << 4) | 0x0f;
2495 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,data);
2496
2497 data = (ThresholdLow & 0x10) << 1;
2498 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xDF,data);
2499
2500 /* What is this? */
2501 SiS_SetReg(SiS_Pr->SiS_P3c4,0x3B,0x09);
2502
2503 /* Write CRT/CPU threshold high (gap = 3) */
2504 data = ThresholdLow + 3;
2505 if(data > 0x0f) data = 0x0f;
2506 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x09,0x80,data);
2716 2507
2717 /* Write foreground and background queue */ 2508 /* Write foreground and background queue */
2718 if(HwInfo->jChipType == SIS_730) { 2509#ifdef SIS_LINUX_KERNEL
2719 2510 templ = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50);
2720 data2 = FQBQData730[i];
2721 data2 = (data2 & 0xC0) >> 5;
2722 data2 <<= 8;
2723
2724#ifdef LINUX_KERNEL
2725 SiS_SetRegLong(0xcf8,0x80000050);
2726 eax = SiS_GetRegLong(0xcfc);
2727 eax &= 0xfffff9ff;
2728 eax |= data2;
2729 SiS_SetRegLong(0xcfc,eax);
2730#else 2511#else
2731 /* We use pci functions X offers. We use pcitag 0, because 2512 templ = pciReadLong(0x00000000, 0x50);
2732 * we want to read/write to the host bridge (which is always
2733 * 00:00.0 on 630, 730 and 540), not the VGA device.
2734 */
2735 eax = pciReadLong(0x00000000, 0x50);
2736 eax &= 0xfffff9ff;
2737 eax |= data2;
2738 pciWriteLong(0x00000000, 0x50, eax);
2739#endif 2513#endif
2740 2514
2741 /* Write GUI grant timer (PCI config 0xA3) */ 2515 if(SiS_Pr->ChipType == SIS_730) {
2742 data2 = FQBQData730[i] << 8;
2743 data2 = (data2 & 0x0f00) | ((data2 & 0x3000) >> 8);
2744 data2 <<= 20;
2745
2746#ifdef LINUX_KERNEL
2747 SiS_SetRegLong(0xcf8,0x800000A0);
2748 eax = SiS_GetRegLong(0xcfc);
2749 eax &= 0x00ffffff;
2750 eax |= data2;
2751 SiS_SetRegLong(0xcfc,eax);
2752#else
2753 eax = pciReadLong(0x00000000, 0xA0);
2754 eax &= 0x00ffffff;
2755 eax |= data2;
2756 pciWriteLong(0x00000000, 0xA0, eax);
2757#endif
2758 2516
2759 } else { 2517 templ &= 0xfffff9ff;
2518 templ |= ((queuedata[i] & 0xc0) << 3);
2760 2519
2761 data2 = FQBQData[i]; 2520 } else {
2762 data2 = (data2 & 0xf0) >> 4;
2763 data2 <<= 24;
2764 2521
2765#ifdef LINUX_KERNEL 2522 templ &= 0xf0ffffff;
2766 SiS_SetRegLong(0xcf8,0x80000050); 2523 if( (ModeNo <= 0x13) &&
2767 eax = SiS_GetRegLong(0xcfc); 2524 (SiS_Pr->ChipType == SIS_630) &&
2768 eax &= 0xf0ffffff; 2525 (SiS_Pr->ChipRevision >= 0x30) ) {
2769 eax |= data2; 2526 templ |= 0x0b000000;
2770 SiS_SetRegLong(0xcfc,eax); 2527 } else {
2771#else 2528 templ |= ((queuedata[i] & 0xf0) << 20);
2772 eax = pciReadLong(0x00000000, 0x50); 2529 }
2773 eax &= 0xf0ffffff; 2530
2774 eax |= data2; 2531 }
2775 pciWriteLong(0x00000000, 0x50, eax);
2776#endif
2777 2532
2778 /* Write GUI grant timer (PCI config 0xA3) */ 2533#ifdef SIS_LINUX_KERNEL
2779 data2 = FQBQData[i]; 2534 sisfb_write_nbridge_pci_dword(SiS_Pr, 0x50, templ);
2780 data2 &= 0x0f; 2535 templ = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xA0);
2781 data2 <<= 24;
2782
2783#ifdef LINUX_KERNEL
2784 SiS_SetRegLong(0xcf8,0x800000A0);
2785 eax = SiS_GetRegLong(0xcfc);
2786 eax &= 0xf0ffffff;
2787 eax |= data2;
2788 SiS_SetRegLong(0xcfc,eax);
2789#else 2536#else
2790 eax = pciReadLong(0x00000000, 0xA0); 2537 pciWriteLong(0x00000000, 0x50, templ);
2791 eax &= 0xf0ffffff; 2538 templ = pciReadLong(0x00000000, 0xA0);
2792 eax |= data2;
2793 pciWriteLong(0x00000000, 0xA0, eax);
2794#endif 2539#endif
2795 2540
2796 } 2541 /* GUI grant timer (PCI config 0xA3) */
2542 if(SiS_Pr->ChipType == SIS_730) {
2543
2544 templ &= 0x00ffffff;
2545 datal = queuedata[i] << 8;
2546 templ |= (((datal & 0x0f00) | ((datal & 0x3000) >> 8)) << 20);
2797 2547
2798 /* Write CRT/CPU threshold low, CRT/Engine threshold high */ 2548 } else {
2799 data = ((ThresholdLow & 0x0f) << 4) | 0x0f;
2800 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,data);
2801 2549
2802 data = (ThresholdLow & 0x10) << 1; 2550 templ &= 0xf0ffffff;
2803 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xDF,data); 2551 templ |= ((queuedata[i] & 0x0f) << 24);
2804 2552
2805 /* What is this? */ 2553 }
2806 SiS_SetReg(SiS_Pr->SiS_P3c4,0x3B,0x09);
2807 2554
2808 /* Write CRT/CPU threshold high (gap = 3) */ 2555#ifdef SIS_LINUX_KERNEL
2809 data = ThresholdLow + 3; 2556 sisfb_write_nbridge_pci_dword(SiS_Pr, 0xA0, templ);
2810 if(data > 0x0f) data = 0x0f; 2557#else
2811 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x09,0x80,data); 2558 pciWriteLong(0x00000000, 0xA0, templ);
2812}
2813#endif 2559#endif
2560}
2561#endif /* SIS300 */
2814 2562
2815#ifdef SIS315H 2563#ifdef SIS315H
2816static void 2564static void
2817SiS_SetCRT1FIFO_310(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 2565SiS_SetCRT1FIFO_310(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
2818 PSIS_HW_INFO HwInfo)
2819{ 2566{
2820 USHORT modeflag; 2567 unsigned short modeflag;
2821 2568
2822 /* disable auto-threshold */ 2569 /* disable auto-threshold */
2823 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x3D,0xFE); 2570 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x3D,0xFE);
2824 2571
2825 if(SiS_Pr->UseCustomMode) { 2572 modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
2826 modeflag = SiS_Pr->CModeFlag; 2573
2827 } else { 2574 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0xAE);
2828 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 2575 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x09,0xF0);
2829 } 2576 if(ModeNo > 0x13) {
2830 2577 if(SiS_Pr->ChipType >= XGI_20) {
2831 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0xAE); 2578 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
2832 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x09,0xF0); 2579 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
2833 if(ModeNo > 0x13) { 2580 } else if(SiS_Pr->ChipType >= SIS_661) {
2834 if(HwInfo->jChipType >= SIS_661) { 2581 if(!(modeflag & HalfDCLK)) {
2835 if(!(modeflag & HalfDCLK)) { 2582 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
2836 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34); 2583 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
2837 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01); 2584 }
2838 } 2585 } else {
2839 } else { 2586 if((!(modeflag & DoubleScanMode)) || (!(modeflag & HalfDCLK))) {
2840 if((!(modeflag & DoubleScanMode)) || (!(modeflag & HalfDCLK))) { 2587 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
2841 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34); 2588 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
2842 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01); 2589 }
2843 } 2590 }
2844 } 2591 }
2845 }
2846} 2592}
2847#endif 2593#endif
2848 2594
@@ -2851,385 +2597,370 @@ SiS_SetCRT1FIFO_310(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2851/*********************************************/ 2597/*********************************************/
2852 2598
2853static void 2599static void
2854SiS_SetVCLKState(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 2600SiS_SetVCLKState(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2855 USHORT ModeNo, USHORT RefreshRateTableIndex, 2601 unsigned short RefreshRateTableIndex, unsigned short ModeIdIndex)
2856 USHORT ModeIdIndex)
2857{ 2602{
2858 USHORT data=0, VCLK=0, index=0; 2603 unsigned short data = 0, VCLK = 0, index = 0;
2859 2604
2860 if(ModeNo > 0x13) { 2605 if(ModeNo > 0x13) {
2861 if(SiS_Pr->UseCustomMode) { 2606 if(SiS_Pr->UseCustomMode) {
2862 VCLK = SiS_Pr->CSRClock; 2607 VCLK = SiS_Pr->CSRClock;
2863 } else { 2608 } else {
2864 index = SiS_GetVCLK2Ptr(SiS_Pr,ModeNo,ModeIdIndex, 2609 index = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
2865 RefreshRateTableIndex,HwInfo); 2610 VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
2866 VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK; 2611 }
2867 } 2612 }
2868 }
2869
2870 if(HwInfo->jChipType < SIS_315H) {
2871
2872 if(VCLK > 150) data |= 0x80;
2873 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0x7B,data);
2874
2875 data = 0x00;
2876 if(VCLK >= 150) data |= 0x08;
2877 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xF7,data);
2878 2613
2879 } else { 2614 if(SiS_Pr->ChipType < SIS_315H) {
2615#ifdef SIS300
2616 if(VCLK > 150) data |= 0x80;
2617 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0x7B,data);
2880 2618
2881 if(VCLK >= 166) data |= 0x0c; 2619 data = 0x00;
2882 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xf3,data); 2620 if(VCLK >= 150) data |= 0x08;
2621 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xF7,data);
2622#endif
2623 } else if(SiS_Pr->ChipType < XGI_20) {
2624#ifdef SIS315H
2625 if(VCLK >= 166) data |= 0x0c;
2626 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xf3,data);
2883 2627
2884 if(VCLK >= 166) { 2628 if(VCLK >= 166) {
2885 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1f,0xe7); 2629 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1f,0xe7);
2886 } 2630 }
2887 } 2631#endif
2632 } else {
2633#ifdef SIS315H
2634 if(VCLK >= 200) data |= 0x0c;
2635 if(SiS_Pr->ChipType == XGI_20) data &= ~0x04;
2636 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xf3,data);
2637 if(SiS_Pr->ChipType != XGI_20) {
2638 data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xe7;
2639 if(VCLK < 200) data |= 0x10;
2640 SiS_SetReg(SiS_Pr->SiS_P3c4,0x1f,data);
2641 }
2642#endif
2643 }
2888 2644
2889 /* DAC speed */ 2645 /* DAC speed */
2890 if(HwInfo->jChipType >= SIS_661) { 2646 if(SiS_Pr->ChipType >= SIS_661) {
2891 2647
2892 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xE8,0x10); 2648 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xE8,0x10);
2893 2649
2894 } else { 2650 } else {
2895 2651
2896 data = 0x03; 2652 data = 0x03;
2897 if((VCLK >= 135) && (VCLK < 160)) data = 0x02; 2653 if(VCLK >= 260) data = 0x00;
2898 else if((VCLK >= 160) && (VCLK < 260)) data = 0x01; 2654 else if(VCLK >= 160) data = 0x01;
2899 else if(VCLK >= 260) data = 0x00; 2655 else if(VCLK >= 135) data = 0x02;
2900 2656
2901 if(HwInfo->jChipType == SIS_540) { 2657 if(SiS_Pr->ChipType == SIS_540) {
2902 if((VCLK == 203) || (VCLK < 234)) data = 0x02; 2658 if((VCLK == 203) || (VCLK < 234)) data = 0x02;
2903 } 2659 }
2904 2660
2905 if(HwInfo->jChipType < SIS_315H) { 2661 if(SiS_Pr->ChipType < SIS_315H) {
2906 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xFC,data); 2662 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xFC,data);
2907 } else { 2663 } else {
2908 if(HwInfo->jChipType > SIS_315PRO) { 2664 if(SiS_Pr->ChipType > SIS_315PRO) {
2909 if(ModeNo > 0x13) data &= 0xfc; 2665 if(ModeNo > 0x13) data &= 0xfc;
2910 } 2666 }
2911 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xF8,data); 2667 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xF8,data);
2912 } 2668 }
2913 2669
2914 } 2670 }
2915} 2671}
2916 2672
2917static void 2673static void
2918SiS_SetCRT1ModeRegs(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 2674SiS_SetCRT1ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2919 USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex) 2675 unsigned short ModeIdIndex, unsigned short RRTI)
2920{ 2676{
2921 USHORT data,infoflag=0,modeflag; 2677 unsigned short data, infoflag = 0, modeflag, resindex;
2922 USHORT resindex,xres;
2923#ifdef SIS315H 2678#ifdef SIS315H
2924 USHORT data2,data3; 2679 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
2925 ULONG longdata; 2680 unsigned short data2, data3;
2926 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
2927#endif 2681#endif
2928 2682
2929 if(SiS_Pr->UseCustomMode) { 2683 modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
2930 modeflag = SiS_Pr->CModeFlag; 2684
2931 infoflag = SiS_Pr->CInfoFlag; 2685 if(SiS_Pr->UseCustomMode) {
2932 xres = SiS_Pr->CHDisplay; 2686 infoflag = SiS_Pr->CInfoFlag;
2933 } else { 2687 } else {
2934 resindex = SiS_GetResInfo(SiS_Pr,ModeNo,ModeIdIndex); 2688 resindex = SiS_GetResInfo(SiS_Pr, ModeNo, ModeIdIndex);
2935 if(ModeNo > 0x13) { 2689 if(ModeNo > 0x13) {
2936 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 2690 infoflag = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag;
2937 infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag; 2691 }
2938 xres = SiS_Pr->SiS_ModeResInfo[resindex].HTotal; 2692 }
2939 } else { 2693
2940 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; 2694 /* Disable DPMS */
2941 xres = SiS_Pr->SiS_StResInfo[resindex].HTotal; 2695 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1F,0x3F);
2942 } 2696
2943 } 2697 data = 0;
2944 2698 if(ModeNo > 0x13) {
2945 /* Disable DPMS */ 2699 if(SiS_Pr->SiS_ModeType > ModeEGA) {
2946 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1F,0x3F); 2700 data |= 0x02;
2947 2701 data |= ((SiS_Pr->SiS_ModeType - ModeVGA) << 2);
2948 data = 0; 2702 }
2949 if(ModeNo > 0x13) { 2703 if(infoflag & InterlaceMode) data |= 0x20;
2950 if(SiS_Pr->SiS_ModeType > ModeEGA) { 2704 }
2951 data |= 0x02; 2705 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x06,0xC0,data);
2952 data |= ((SiS_Pr->SiS_ModeType - ModeVGA) << 2); 2706
2953 } 2707 if(SiS_Pr->ChipType != SIS_300) {
2954 if(infoflag & InterlaceMode) data |= 0x20; 2708 data = 0;
2955 } 2709 if(infoflag & InterlaceMode) {
2956 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x06,0xC0,data); 2710 /* data = (Hsync / 8) - ((Htotal / 8) / 2) + 3 */
2957 2711 int hrs = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x04) |
2958 if(HwInfo->jChipType != SIS_300) { 2712 ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0xc0) << 2)) - 3;
2959 data = 0; 2713 int hto = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x00) |
2960 if(infoflag & InterlaceMode) { 2714 ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0x03) << 8)) + 5;
2961 if(xres <= 800) data = 0x0020; 2715 data = hrs - (hto >> 1) + 3;
2962 else if(xres <= 1024) data = 0x0035; 2716 }
2963 else data = 0x0048; 2717 SiS_SetReg(SiS_Pr->SiS_P3d4,0x19,data);
2964 } 2718 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x1a,0xFC,((data >> 8) & 0x03));
2965 SiS_SetReg(SiS_Pr->SiS_P3d4,0x19,(data & 0xFF)); 2719 }
2966 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x1a,0xFC,(data >> 8)); 2720
2967 } 2721 if(modeflag & HalfDCLK) {
2968 2722 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x01,0x08);
2969 if(modeflag & HalfDCLK) { 2723 }
2970 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x01,0x08); 2724
2971 } 2725 data = 0;
2972 2726 if(modeflag & LineCompareOff) data = 0x08;
2973 data = 0; 2727 if(SiS_Pr->ChipType == SIS_300) {
2974 if(modeflag & LineCompareOff) data = 0x08; 2728 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xF7,data);
2975 if(HwInfo->jChipType == SIS_300) { 2729 } else {
2976 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xF7,data); 2730 if(SiS_Pr->ChipType >= XGI_20) data |= 0x20;
2977 } else { 2731 if(SiS_Pr->SiS_ModeType == ModeEGA) {
2978 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xB7,data); 2732 if(ModeNo > 0x13) {
2979 if(SiS_Pr->SiS_ModeType == ModeEGA) { 2733 data |= 0x40;
2980 if(ModeNo > 0x13) { 2734 }
2981 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x0F,0x40); 2735 }
2982 } 2736 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xB7,data);
2983 } 2737 }
2984 }
2985
2986 if(HwInfo->jChipType >= SIS_661) {
2987 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x31,0xfb);
2988 }
2989 2738
2990#ifdef SIS315H 2739#ifdef SIS315H
2991 if(HwInfo->jChipType == SIS_315PRO) { 2740 if(SiS_Pr->ChipType >= SIS_315H) {
2992 2741 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x31,0xfb);
2993 data = SiS_Get310DRAMType(SiS_Pr, HwInfo); 2742 }
2994 data = SiS_Pr->SiS_SR15[2][data];
2995 if(SiS_Pr->SiS_ModeType == ModeText) {
2996 data &= 0xc7;
2997 } else {
2998 data2 = SiS_GetOffset(SiS_Pr,ModeNo,ModeIdIndex,
2999 RefreshRateTableIndex,HwInfo);
3000 data2 >>= 1;
3001 if(infoflag & InterlaceMode) data2 >>= 1;
3002 data3 = SiS_GetColorDepth(SiS_Pr,ModeNo,ModeIdIndex) >> 1;
3003 if(!data3) data3++;
3004 data2 /= data3;
3005 if(data2 >= 0x50) {
3006 data &= 0x0f;
3007 data |= 0x50;
3008 }
3009 }
3010 SiS_SetReg(SiS_Pr->SiS_P3c4,0x17,data);
3011
3012 } else if( (HwInfo->jChipType == SIS_330) ||
3013 ((HwInfo->jChipType == SIS_760) && (SiS_Pr->SiS_SysFlags & SF_760LFB))) {
3014
3015 data = SiS_Get310DRAMType(SiS_Pr, HwInfo);
3016 if(HwInfo->jChipType == SIS_330) {
3017 data = SiS_Pr->SiS_SR15[2][data];
3018 } else {
3019 if(SiS_Pr->SiS_ROMNew) data = ROMAddr[0xf6];
3020 else if(SiS_Pr->SiS_UseROM) data = ROMAddr[0x100 + data];
3021 else data = 0xba;
3022 }
3023 if(SiS_Pr->SiS_ModeType <= ModeEGA) {
3024 data &= 0xc7;
3025 } else {
3026 if(SiS_Pr->UseCustomMode) {
3027 data2 = SiS_Pr->CSRClock;
3028 } else {
3029 data2 = SiS_GetVCLK2Ptr(SiS_Pr,ModeNo,ModeIdIndex,
3030 RefreshRateTableIndex,HwInfo);
3031 data2 = SiS_Pr->SiS_VCLKData[data2].CLOCK;
3032 }
3033 2743
3034 data3 = SiS_GetColorDepth(SiS_Pr,ModeNo,ModeIdIndex) >> 1; 2744 if(SiS_Pr->ChipType == SIS_315PRO) {
3035 if(data3) data2 *= data3; 2745
3036 2746 data = SiS_Pr->SiS_SR15[(2 * 4) + SiS_Get310DRAMType(SiS_Pr)];
3037 longdata = SiS_GetMCLK(SiS_Pr, HwInfo) * 1024; 2747 if(SiS_Pr->SiS_ModeType == ModeText) {
3038 2748 data &= 0xc7;
3039 data2 = longdata / data2; 2749 } else {
3040 2750 data2 = SiS_GetOffset(SiS_Pr, ModeNo, ModeIdIndex, RRTI) >> 1;
3041 if(HwInfo->jChipType == SIS_330) { 2751 if(infoflag & InterlaceMode) data2 >>= 1;
3042 if(SiS_Pr->SiS_ModeType != Mode16Bpp) { 2752 data3 = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex) >> 1;
3043 if (data2 >= 0x19c) data = 0xba; 2753 if(data3) data2 /= data3;
3044 else if(data2 >= 0x140) data = 0x7a; 2754 if(data2 >= 0x50) {
3045 else if(data2 >= 0x101) data = 0x3a; 2755 data &= 0x0f;
3046 else if(data2 >= 0xf5) data = 0x32; 2756 data |= 0x50;
3047 else if(data2 >= 0xe2) data = 0x2a; 2757 }
3048 else if(data2 >= 0xc4) data = 0x22; 2758 }
3049 else if(data2 >= 0xac) data = 0x1a; 2759 SiS_SetReg(SiS_Pr->SiS_P3c4,0x17,data);
3050 else if(data2 >= 0x9e) data = 0x12; 2760
3051 else if(data2 >= 0x8e) data = 0x0a; 2761 } else if((SiS_Pr->ChipType == SIS_330) || (SiS_Pr->SiS_SysFlags & SF_760LFB)) {
3052 else data = 0x02; 2762
3053 } else { 2763 data = SiS_Get310DRAMType(SiS_Pr);
3054 if(data2 >= 0x127) data = 0xba; 2764 if(SiS_Pr->ChipType == SIS_330) {
3055 else data = 0x7a; 2765 data = SiS_Pr->SiS_SR15[(2 * 4) + data];
3056 } 2766 } else {
3057 } else { /* 760+LFB */ 2767 if(SiS_Pr->SiS_ROMNew) data = ROMAddr[0xf6];
3058 if (data2 >= 0x190) data = 0xba; 2768 else if(SiS_Pr->SiS_UseROM) data = ROMAddr[0x100 + data];
3059 else if(data2 >= 0xff) data = 0x7a; 2769 else data = 0xba;
3060 else if(data2 >= 0xd3) data = 0x3a; 2770 }
3061 else if(data2 >= 0xa9) data = 0x1a; 2771 if(SiS_Pr->SiS_ModeType <= ModeEGA) {
3062 else if(data2 >= 0x93) data = 0x0a; 2772 data &= 0xc7;
3063 else data = 0x02; 2773 } else {
3064 } 2774 if(SiS_Pr->UseCustomMode) {
3065 } 2775 data2 = SiS_Pr->CSRClock;
3066 SiS_SetReg(SiS_Pr->SiS_P3c4,0x17,data); 2776 } else {
3067 } else if(HwInfo->jChipType == SIS_340) { 2777 data2 = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
3068 /* TODO */ 2778 data2 = SiS_Pr->SiS_VCLKData[data2].CLOCK;
3069 } 2779 }
2780
2781 data3 = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex) >> 1;
2782 if(data3) data2 *= data3;
2783
2784 data2 = ((unsigned int)(SiS_GetMCLK(SiS_Pr) * 1024)) / data2;
2785
2786 if(SiS_Pr->ChipType == SIS_330) {
2787 if(SiS_Pr->SiS_ModeType != Mode16Bpp) {
2788 if (data2 >= 0x19c) data = 0xba;
2789 else if(data2 >= 0x140) data = 0x7a;
2790 else if(data2 >= 0x101) data = 0x3a;
2791 else if(data2 >= 0xf5) data = 0x32;
2792 else if(data2 >= 0xe2) data = 0x2a;
2793 else if(data2 >= 0xc4) data = 0x22;
2794 else if(data2 >= 0xac) data = 0x1a;
2795 else if(data2 >= 0x9e) data = 0x12;
2796 else if(data2 >= 0x8e) data = 0x0a;
2797 else data = 0x02;
2798 } else {
2799 if(data2 >= 0x127) data = 0xba;
2800 else data = 0x7a;
2801 }
2802 } else { /* 76x+LFB */
2803 if (data2 >= 0x190) data = 0xba;
2804 else if(data2 >= 0xff) data = 0x7a;
2805 else if(data2 >= 0xd3) data = 0x3a;
2806 else if(data2 >= 0xa9) data = 0x1a;
2807 else if(data2 >= 0x93) data = 0x0a;
2808 else data = 0x02;
2809 }
2810 }
2811 SiS_SetReg(SiS_Pr->SiS_P3c4,0x17,data);
2812
2813 }
2814 /* XGI: Nothing. */
2815 /* TODO: Check SiS340 */
3070#endif 2816#endif
3071 2817
3072 data = 0x60; 2818 data = 0x60;
3073 if(SiS_Pr->SiS_ModeType != ModeText) { 2819 if(SiS_Pr->SiS_ModeType != ModeText) {
3074 data ^= 0x60; 2820 data ^= 0x60;
3075 if(SiS_Pr->SiS_ModeType != ModeEGA) { 2821 if(SiS_Pr->SiS_ModeType != ModeEGA) {
3076 data ^= 0xA0; 2822 data ^= 0xA0;
3077 } 2823 }
3078 } 2824 }
3079 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x21,0x1F,data); 2825 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x21,0x1F,data);
3080 2826
3081 SiS_SetVCLKState(SiS_Pr, HwInfo, ModeNo, RefreshRateTableIndex, ModeIdIndex); 2827 SiS_SetVCLKState(SiS_Pr, ModeNo, RRTI, ModeIdIndex);
3082 2828
3083#ifdef SIS315H 2829#ifdef SIS315H
3084 if(HwInfo->jChipType >= SIS_315H) { 2830 if(((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) ||
3085 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) { 2831 (SiS_Pr->ChipType == XGI_40)) {
3086 SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x2c); 2832 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
3087 } else { 2833 SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x2c);
3088 SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x6c); 2834 } else {
3089 } 2835 SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x6c);
3090 } 2836 }
2837 } else if(SiS_Pr->ChipType == XGI_20) {
2838 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
2839 SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x33);
2840 } else {
2841 SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x73);
2842 }
2843 SiS_SetReg(SiS_Pr->SiS_P3d4,0x51,0x02);
2844 }
3091#endif 2845#endif
3092} 2846}
3093 2847
3094/*********************************************/ 2848#ifdef SIS315H
3095/* LOAD DAC */
3096/*********************************************/
3097
3098#if 0
3099static void 2849static void
3100SiS_ClearDAC(SiS_Private *SiS_Pr, ULONG port) 2850SiS_SetupDualChip(struct SiS_Private *SiS_Pr)
3101{ 2851{
2852#if 0
2853 /* TODO: Find out about IOAddress2 */
2854 SISIOADDRESS P2_3c2 = SiS_Pr->IOAddress2 + 0x12;
2855 SISIOADDRESS P2_3c4 = SiS_Pr->IOAddress2 + 0x14;
2856 SISIOADDRESS P2_3ce = SiS_Pr->IOAddress2 + 0x1e;
3102 int i; 2857 int i;
3103 2858
3104 OutPortByte(port, 0); 2859 if((SiS_Pr->ChipRevision != 0) ||
3105 port++; 2860 (!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x3a) & 0x04)))
3106 for (i=0; i < (256 * 3); i++) { 2861 return;
3107 OutPortByte(port, 0); 2862
2863 for(i = 0; i <= 4; i++) { /* SR00 - SR04 */
2864 SiS_SetReg(P2_3c4,i,SiS_GetReg(SiS_Pr->SiS_P3c4,i));
3108 } 2865 }
2866 for(i = 0; i <= 8; i++) { /* GR00 - GR08 */
2867 SiS_SetReg(P2_3ce,i,SiS_GetReg(SiS_Pr->SiS_P3ce,i));
2868 }
2869 SiS_SetReg(P2_3c4,0x05,0x86);
2870 SiS_SetReg(P2_3c4,0x06,SiS_GetReg(SiS_Pr->SiS_P3c4,0x06)); /* SR06 */
2871 SiS_SetReg(P2_3c4,0x21,SiS_GetReg(SiS_Pr->SiS_P3c4,0x21)); /* SR21 */
2872 SiS_SetRegByte(P2_3c2,SiS_GetRegByte(SiS_Pr->SiS_P3cc)); /* MISC */
2873 SiS_SetReg(P2_3c4,0x05,0x00);
2874#endif
3109} 2875}
3110#endif 2876#endif
3111 2877
2878/*********************************************/
2879/* LOAD DAC */
2880/*********************************************/
2881
3112static void 2882static void
3113SiS_WriteDAC(SiS_Private *SiS_Pr, SISIOADDRESS DACData, USHORT shiftflag, 2883SiS_WriteDAC(struct SiS_Private *SiS_Pr, SISIOADDRESS DACData, unsigned short shiftflag,
3114 USHORT dl, USHORT ah, USHORT al, USHORT dh) 2884 unsigned short dl, unsigned short ah, unsigned short al, unsigned short dh)
3115{ 2885{
3116 USHORT temp,bh,bl; 2886 unsigned short d1, d2, d3;
3117 2887
3118 bh = ah; 2888 switch(dl) {
3119 bl = al; 2889 case 0: d1 = dh; d2 = ah; d3 = al; break;
3120 if(dl != 0) { 2890 case 1: d1 = ah; d2 = al; d3 = dh; break;
3121 temp = bh; 2891 default: d1 = al; d2 = dh; d3 = ah;
3122 bh = dh; 2892 }
3123 dh = temp; 2893 SiS_SetRegByte(DACData, (d1 << shiftflag));
3124 if(dl == 1) { 2894 SiS_SetRegByte(DACData, (d2 << shiftflag));
3125 temp = bl; 2895 SiS_SetRegByte(DACData, (d3 << shiftflag));
3126 bl = dh;
3127 dh = temp;
3128 } else {
3129 temp = bl;
3130 bl = bh;
3131 bh = temp;
3132 }
3133 }
3134 if(shiftflag) {
3135 dh <<= 2;
3136 bh <<= 2;
3137 bl <<= 2;
3138 }
3139 SiS_SetRegByte(DACData,(USHORT)dh);
3140 SiS_SetRegByte(DACData,(USHORT)bh);
3141 SiS_SetRegByte(DACData,(USHORT)bl);
3142} 2896}
3143 2897
3144void 2898void
3145SiS_LoadDAC(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 2899SiS_LoadDAC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
3146 USHORT ModeNo, USHORT ModeIdIndex)
3147{ 2900{
3148 USHORT data,data2; 2901 unsigned short data, data2, time, i, j, k, m, n, o;
3149 USHORT time,i,j,k,m,n,o; 2902 unsigned short si, di, bx, sf;
3150 USHORT si,di,bx,dl,al,ah,dh;
3151 USHORT shiftflag;
3152 SISIOADDRESS DACAddr, DACData; 2903 SISIOADDRESS DACAddr, DACData;
3153 const USHORT *table = NULL; 2904 const unsigned char *table = NULL;
3154 2905
3155 if(ModeNo <= 0x13) { 2906 data = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex) & DACInfoFlag;
3156 data = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
3157 } else {
3158 if(SiS_Pr->UseCustomMode) {
3159 data = SiS_Pr->CModeFlag;
3160 } else {
3161 data = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3162 }
3163 }
3164 2907
3165 data &= DACInfoFlag; 2908 j = time = 64;
3166 time = 64; 2909 if(data == 0x00) table = SiS_MDA_DAC;
3167 if(data == 0x00) table = SiS_MDA_DAC; 2910 else if(data == 0x08) table = SiS_CGA_DAC;
3168 if(data == 0x08) table = SiS_CGA_DAC; 2911 else if(data == 0x10) table = SiS_EGA_DAC;
3169 if(data == 0x10) table = SiS_EGA_DAC; 2912 else if(data == 0x18) {
3170 if(data == 0x18) { 2913 j = 16;
3171 time = 256; 2914 time = 256;
3172 table = SiS_VGA_DAC; 2915 table = SiS_VGA_DAC;
3173 } 2916 }
3174 if(time == 256) j = 16;
3175 else j = time;
3176 2917
3177 if( ( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && /* 301B-DH LCD */ 2918 if( ( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && /* 301B-DH LCD */
3178 (SiS_Pr->SiS_VBType & VB_NoLCD) ) || 2919 (SiS_Pr->SiS_VBType & VB_NoLCD) ) ||
3179 (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) || /* LCDA */ 2920 (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) || /* LCDA */
3180 (!(SiS_Pr->SiS_SetFlag & ProgrammingCRT2)) ) { /* Programming CRT1 */ 2921 (!(SiS_Pr->SiS_SetFlag & ProgrammingCRT2)) ) { /* Programming CRT1 */
2922 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
3181 DACAddr = SiS_Pr->SiS_P3c8; 2923 DACAddr = SiS_Pr->SiS_P3c8;
3182 DACData = SiS_Pr->SiS_P3c9; 2924 DACData = SiS_Pr->SiS_P3c9;
3183 shiftflag = 0; 2925 sf = 0;
3184 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
3185 } else { 2926 } else {
3186 shiftflag = 1;
3187 DACAddr = SiS_Pr->SiS_Part5Port; 2927 DACAddr = SiS_Pr->SiS_Part5Port;
3188 DACData = SiS_Pr->SiS_Part5Port + 1; 2928 DACData = SiS_Pr->SiS_Part5Port + 1;
2929 sf = 2;
3189 } 2930 }
3190 2931
3191 SiS_SetRegByte(DACAddr,0x00); 2932 SiS_SetRegByte(DACAddr,0x00);
3192 2933
3193 for(i=0; i<j; i++) { 2934 for(i = 0; i < j; i++) {
3194 data = table[i]; 2935 data = table[i];
3195 for(k=0; k<3; k++) { 2936 for(k = 0; k < 3; k++) {
3196 data2 = 0; 2937 data2 = 0;
3197 if(data & 0x01) data2 = 0x2A; 2938 if(data & 0x01) data2 += 0x2A;
3198 if(data & 0x02) data2 += 0x15; 2939 if(data & 0x02) data2 += 0x15;
3199 if(shiftflag) data2 <<= 2; 2940 SiS_SetRegByte(DACData, (data2 << sf));
3200 SiS_SetRegByte(DACData, data2);
3201 data >>= 2; 2941 data >>= 2;
3202 } 2942 }
3203 } 2943 }
3204 2944
3205 if(time == 256) { 2945 if(time == 256) {
3206 for(i = 16; i < 32; i++) { 2946 for(i = 16; i < 32; i++) {
3207 data = table[i]; 2947 data = table[i] << sf;
3208 if(shiftflag) data <<= 2;
3209 for(k = 0; k < 3; k++) SiS_SetRegByte(DACData, data); 2948 for(k = 0; k < 3; k++) SiS_SetRegByte(DACData, data);
3210 } 2949 }
3211 si = 32; 2950 si = 32;
3212 for(m = 0; m < 9; m++) { 2951 for(m = 0; m < 9; m++) {
3213 di = si; 2952 di = si;
3214 bx = si + 4; 2953 bx = si + 4;
3215 dl = 0; 2954 for(n = 0; n < 3; n++) {
3216 for(n = 0; n < 3; n++) { 2955 for(o = 0; o < 5; o++) {
3217 for(o = 0; o < 5; o++) { 2956 SiS_WriteDAC(SiS_Pr, DACData, sf, n, table[di], table[bx], table[si]);
3218 dh = table[si];
3219 ah = table[di];
3220 al = table[bx];
3221 si++; 2957 si++;
3222 SiS_WriteDAC(SiS_Pr, DACData, shiftflag, dl, ah, al, dh);
3223 } 2958 }
3224 si -= 2; 2959 si -= 2;
3225 for(o = 0; o < 3; o++) { 2960 for(o = 0; o < 3; o++) {
3226 dh = table[bx]; 2961 SiS_WriteDAC(SiS_Pr, DACData, sf, n, table[di], table[si], table[bx]);
3227 ah = table[di];
3228 al = table[si];
3229 si--; 2962 si--;
3230 SiS_WriteDAC(SiS_Pr, DACData, shiftflag, dl, ah, al, dh);
3231 } 2963 }
3232 dl++;
3233 } /* for n < 3 */ 2964 } /* for n < 3 */
3234 si += 5; 2965 si += 5;
3235 } /* for m < 9 */ 2966 } /* for m < 9 */
@@ -3241,89 +2972,114 @@ SiS_LoadDAC(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
3241/*********************************************/ 2972/*********************************************/
3242 2973
3243static void 2974static void
3244SiS_SetCRT1Group(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 2975SiS_SetCRT1Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
3245 USHORT ModeNo, USHORT ModeIdIndex)
3246{ 2976{
3247 USHORT StandTableIndex,RefreshRateTableIndex; 2977 unsigned short StandTableIndex, RefreshRateTableIndex;
3248 2978
3249 SiS_Pr->SiS_CRT1Mode = ModeNo; 2979 SiS_Pr->SiS_CRT1Mode = ModeNo;
3250 StandTableIndex = SiS_GetModePtr(SiS_Pr, ModeNo, ModeIdIndex); 2980
3251 if(SiS_Pr->SiS_SetFlag & LowModeTests) { 2981 StandTableIndex = SiS_GetModePtr(SiS_Pr, ModeNo, ModeIdIndex);
3252 if(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2)) { 2982
3253 SiS_DisableBridge(SiS_Pr, HwInfo); 2983 if(SiS_Pr->SiS_SetFlag & LowModeTests) {
3254 } 2984 if(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2)) {
3255 } 2985 SiS_DisableBridge(SiS_Pr);
3256 2986 }
3257 SiS_ResetSegmentRegisters(SiS_Pr, HwInfo); 2987 }
3258 2988
3259 SiS_SetSeqRegs(SiS_Pr, StandTableIndex, HwInfo); 2989 SiS_ResetSegmentRegisters(SiS_Pr);
3260 SiS_SetMiscRegs(SiS_Pr, StandTableIndex, HwInfo); 2990
3261 SiS_SetCRTCRegs(SiS_Pr, HwInfo, StandTableIndex); 2991 SiS_SetSeqRegs(SiS_Pr, StandTableIndex);
3262 SiS_SetATTRegs(SiS_Pr, StandTableIndex, HwInfo); 2992 SiS_SetMiscRegs(SiS_Pr, StandTableIndex);
3263 SiS_SetGRCRegs(SiS_Pr, StandTableIndex); 2993 SiS_SetCRTCRegs(SiS_Pr, StandTableIndex);
3264 SiS_ClearExt1Regs(SiS_Pr, HwInfo, ModeNo); 2994 SiS_SetATTRegs(SiS_Pr, StandTableIndex);
3265 SiS_ResetCRT1VCLK(SiS_Pr, HwInfo); 2995 SiS_SetGRCRegs(SiS_Pr, StandTableIndex);
3266 2996 SiS_ClearExt1Regs(SiS_Pr, ModeNo);
3267 SiS_Pr->SiS_SelectCRT2Rate = 0; 2997 SiS_ResetCRT1VCLK(SiS_Pr);
3268 SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2); 2998
3269 2999 SiS_Pr->SiS_SelectCRT2Rate = 0;
3270#ifdef LINUX_XF86 3000 SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
3271 xf86DrvMsgVerb(0, X_PROBED, 4, "(init: VBType=0x%04x, VBInfo=0x%04x)\n", 3001
3002#ifdef SIS_XORG_XF86
3003 xf86DrvMsgVerb(0, X_PROBED, 4, "(init: VBType=0x%04x, VBInfo=0x%04x)\n",
3272 SiS_Pr->SiS_VBType, SiS_Pr->SiS_VBInfo); 3004 SiS_Pr->SiS_VBType, SiS_Pr->SiS_VBInfo);
3273#endif 3005#endif
3274 3006
3275 if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) { 3007 if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) {
3276 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { 3008 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
3277 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2; 3009 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
3278 } 3010 }
3279 } 3011 }
3280 3012
3281 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { 3013 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
3282 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2; 3014 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
3283 } 3015 }
3284 3016
3285 RefreshRateTableIndex = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex, HwInfo); 3017 RefreshRateTableIndex = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex);
3286 3018
3287 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { 3019 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
3288 SiS_Pr->SiS_SetFlag &= ~ProgrammingCRT2; 3020 SiS_Pr->SiS_SetFlag &= ~ProgrammingCRT2;
3289 } 3021 }
3290 3022
3291 if(RefreshRateTableIndex != 0xFFFF) { 3023 if(RefreshRateTableIndex != 0xFFFF) {
3292 SiS_SetCRT1Sync(SiS_Pr, RefreshRateTableIndex); 3024 SiS_SetCRT1Sync(SiS_Pr, RefreshRateTableIndex);
3293 SiS_SetCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo); 3025 SiS_SetCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3294 SiS_SetCRT1Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo); 3026 SiS_SetCRT1Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3295 SiS_SetCRT1VCLK(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, RefreshRateTableIndex); 3027 SiS_SetCRT1VCLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3296 } 3028 }
3297 3029
3030 switch(SiS_Pr->ChipType) {
3298#ifdef SIS300 3031#ifdef SIS300
3299 if(HwInfo->jChipType == SIS_300) { 3032 case SIS_300:
3300 SiS_SetCRT1FIFO_300(SiS_Pr, ModeNo,HwInfo,RefreshRateTableIndex); 3033 SiS_SetCRT1FIFO_300(SiS_Pr, ModeNo, RefreshRateTableIndex);
3301 } else if((HwInfo->jChipType == SIS_630) || 3034 break;
3302 (HwInfo->jChipType == SIS_730) || 3035 case SIS_540:
3303 (HwInfo->jChipType == SIS_540)) { 3036 case SIS_630:
3304 SiS_SetCRT1FIFO_630(SiS_Pr, ModeNo, HwInfo, RefreshRateTableIndex); 3037 case SIS_730:
3305 } 3038 SiS_SetCRT1FIFO_630(SiS_Pr, ModeNo, RefreshRateTableIndex);
3039 break;
3306#endif 3040#endif
3041 default:
3307#ifdef SIS315H 3042#ifdef SIS315H
3308 if(HwInfo->jChipType >= SIS_315H) { 3043 if(SiS_Pr->ChipType == XGI_20) {
3309 SiS_SetCRT1FIFO_310(SiS_Pr, ModeNo, ModeIdIndex, HwInfo); 3044 unsigned char sr2b = 0, sr2c = 0;
3310 } 3045 switch(ModeNo) {
3046 case 0x00:
3047 case 0x01: sr2b = 0x4e; sr2c = 0xe9; break;
3048 case 0x04:
3049 case 0x05:
3050 case 0x0d: sr2b = 0x1b; sr2c = 0xe3; break;
3051 }
3052 if(sr2b) {
3053 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2b,sr2b);
3054 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,sr2c);
3055 SiS_SetRegByte(SiS_Pr->SiS_P3c2,(SiS_GetRegByte(SiS_Pr->SiS_P3cc) | 0x0c));
3056 }
3057 }
3058 SiS_SetCRT1FIFO_310(SiS_Pr, ModeNo, ModeIdIndex);
3311#endif 3059#endif
3060 break;
3061 }
3062
3063 SiS_SetCRT1ModeRegs(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3312 3064
3313 SiS_SetCRT1ModeRegs(SiS_Pr, HwInfo, ModeNo, ModeIdIndex, RefreshRateTableIndex); 3065#ifdef SIS315H
3066 if(SiS_Pr->ChipType == XGI_40) {
3067 SiS_SetupDualChip(SiS_Pr);
3068 }
3069#endif
3314 3070
3315 SiS_LoadDAC(SiS_Pr, HwInfo, ModeNo, ModeIdIndex); 3071 SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex);
3316 3072
3317#ifdef LINUX_KERNEL 3073#ifdef SIS_LINUX_KERNEL
3318 if(SiS_Pr->SiS_flag_clearbuffer) { 3074 if(SiS_Pr->SiS_flag_clearbuffer) {
3319 SiS_ClearBuffer(SiS_Pr,HwInfo,ModeNo); 3075 SiS_ClearBuffer(SiS_Pr, ModeNo);
3320 } 3076 }
3321#endif 3077#endif
3322 3078
3323 if(!(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2 | SetCRT2ToLCDA))) { 3079 if(!(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2 | SetCRT2ToLCDA))) {
3324 SiS_WaitRetrace1(SiS_Pr); 3080 SiS_WaitRetrace1(SiS_Pr);
3325 SiS_DisplayOn(SiS_Pr); 3081 SiS_DisplayOn(SiS_Pr);
3326 } 3082 }
3327} 3083}
3328 3084
3329/*********************************************/ 3085/*********************************************/
@@ -3331,33 +3087,62 @@ SiS_SetCRT1Group(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
3331/*********************************************/ 3087/*********************************************/
3332 3088
3333static void 3089static void
3334SiS_ResetVB(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 3090SiS_InitVB(struct SiS_Private *SiS_Pr)
3091{
3092 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
3093
3094 SiS_Pr->Init_P4_0E = 0;
3095 if(SiS_Pr->SiS_ROMNew) {
3096 SiS_Pr->Init_P4_0E = ROMAddr[0x82];
3097 } else if(SiS_Pr->ChipType >= XGI_40) {
3098 if(SiS_Pr->SiS_XGIROM) {
3099 SiS_Pr->Init_P4_0E = ROMAddr[0x80];
3100 }
3101 }
3102}
3103
3104static void
3105SiS_ResetVB(struct SiS_Private *SiS_Pr)
3335{ 3106{
3336 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 3107#ifdef SIS315H
3337 USHORT temp; 3108 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
3109 unsigned short temp;
3338 3110
3339 /* VB programming clock */ 3111 /* VB programming clock */
3340 if(SiS_Pr->SiS_UseROM) { 3112 if(SiS_Pr->SiS_UseROM) {
3341 if(HwInfo->jChipType < SIS_330) { 3113 if(SiS_Pr->ChipType < SIS_330) {
3342 temp = ROMAddr[VB310Data_1_2_Offset] | 0x40; 3114 temp = ROMAddr[VB310Data_1_2_Offset] | 0x40;
3343 if(SiS_Pr->SiS_ROMNew) temp = ROMAddr[0x80] | 0x40; 3115 if(SiS_Pr->SiS_ROMNew) temp = ROMAddr[0x80] | 0x40;
3344 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp); 3116 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
3345 } else if(HwInfo->jChipType >= SIS_661) { 3117 } else if(SiS_Pr->ChipType >= SIS_661 && SiS_Pr->ChipType < XGI_20) {
3346 temp = ROMAddr[0x7e] | 0x40; 3118 temp = ROMAddr[0x7e] | 0x40;
3347 if(SiS_Pr->SiS_ROMNew) temp = ROMAddr[0x80] | 0x40; 3119 if(SiS_Pr->SiS_ROMNew) temp = ROMAddr[0x80] | 0x40;
3348 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp); 3120 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
3349 } 3121 }
3122 } else if(SiS_Pr->ChipType >= XGI_40) {
3123 temp = 0x40;
3124 if(SiS_Pr->SiS_XGIROM) temp |= ROMAddr[0x7e];
3125 /* Can we do this on any chipset? */
3126 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
3350 } 3127 }
3128#endif
3351} 3129}
3352 3130
3353/*********************************************/ 3131/*********************************************/
3354/* HELPER: SET VIDEO REGISTERS */ 3132/* HELPER: SET VIDEO/CAPTURE REGISTERS */
3355/*********************************************/ 3133/*********************************************/
3356 3134
3357static void 3135static void
3358SiS_StrangeStuff(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 3136SiS_StrangeStuff(struct SiS_Private *SiS_Pr)
3359{ 3137{
3360 if((IS_SIS651) || (IS_SISM650)) { 3138 /* SiS65x and XGI set up some sort of "lock mode" for text
3139 * which locks CRT2 in some way to CRT1 timing. Disable
3140 * this here.
3141 */
3142#ifdef SIS315H
3143 if((IS_SIS651) || (IS_SISM650) ||
3144 SiS_Pr->ChipType == SIS_340 ||
3145 SiS_Pr->ChipType == XGI_40) {
3361 SiS_SetReg(SiS_Pr->SiS_VidCapt, 0x3f, 0x00); /* Fiddle with capture regs */ 3146 SiS_SetReg(SiS_Pr->SiS_VidCapt, 0x3f, 0x00); /* Fiddle with capture regs */
3362 SiS_SetReg(SiS_Pr->SiS_VidCapt, 0x00, 0x00); 3147 SiS_SetReg(SiS_Pr->SiS_VidCapt, 0x00, 0x00);
3363 SiS_SetReg(SiS_Pr->SiS_VidPlay, 0x00, 0x86); /* (BIOS does NOT unlock) */ 3148 SiS_SetReg(SiS_Pr->SiS_VidPlay, 0x00, 0x86); /* (BIOS does NOT unlock) */
@@ -3365,49 +3150,99 @@ SiS_StrangeStuff(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
3365 SiS_SetRegAND(SiS_Pr->SiS_VidPlay, 0x3f, 0xef); 3150 SiS_SetRegAND(SiS_Pr->SiS_VidPlay, 0x3f, 0xef);
3366 } 3151 }
3367 /* !!! This does not support modes < 0x13 !!! */ 3152 /* !!! This does not support modes < 0x13 !!! */
3153#endif
3368} 3154}
3369 3155
3370/*********************************************/ 3156/*********************************************/
3371/* XFree86: SET SCREEN PITCH */ 3157/* HELPER: SET AGP TIMING FOR SiS760 */
3372/*********************************************/ 3158/*********************************************/
3373 3159
3374#ifdef LINUX_XF86
3375static void 3160static void
3376SiS_SetPitchCRT1(SiS_Private *SiS_Pr, ScrnInfoPtr pScrn) 3161SiS_Handle760(struct SiS_Private *SiS_Pr)
3162{
3163#ifdef SIS315H
3164 unsigned int somebase;
3165 unsigned char temp1, temp2, temp3;
3166
3167 if( (SiS_Pr->ChipType != SIS_760) ||
3168 ((SiS_GetReg(SiS_Pr->SiS_P3d4, 0x5c) & 0xf8) != 0x80) ||
3169 (!(SiS_Pr->SiS_SysFlags & SF_760LFB)) ||
3170 (!(SiS_Pr->SiS_SysFlags & SF_760UMA)) )
3171 return;
3172
3173#ifdef SIS_LINUX_KERNEL
3174 somebase = sisfb_read_mio_pci_word(SiS_Pr, 0x74);
3175#else
3176 somebase = pciReadWord(0x00001000, 0x74);
3177#endif
3178 somebase &= 0xffff;
3179
3180 if(somebase == 0) return;
3181
3182 temp3 = SiS_GetRegByte((somebase + 0x85)) & 0xb7;
3183
3184 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
3185 temp1 = 0x21;
3186 temp2 = 0x03;
3187 temp3 |= 0x08;
3188 } else {
3189 temp1 = 0x25;
3190 temp2 = 0x0b;
3191 }
3192
3193#ifdef SIS_LINUX_KERNEL
3194 sisfb_write_nbridge_pci_byte(SiS_Pr, 0x7e, temp1);
3195 sisfb_write_nbridge_pci_byte(SiS_Pr, 0x8d, temp2);
3196#else
3197 pciWriteByte(0x00000000, 0x7e, temp1);
3198 pciWriteByte(0x00000000, 0x8d, temp2);
3199#endif
3200
3201 SiS_SetRegByte((somebase + 0x85), temp3);
3202#endif
3203}
3204
3205/*********************************************/
3206/* X.org/XFree86: SET SCREEN PITCH */
3207/*********************************************/
3208
3209#ifdef SIS_XORG_XF86
3210static void
3211SiS_SetPitchCRT1(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn)
3377{ 3212{
3378 SISPtr pSiS = SISPTR(pScrn); 3213 SISPtr pSiS = SISPTR(pScrn);
3379 UShort HDisplay = pSiS->scrnPitch >> 3; 3214 unsigned short HDisplay = pSiS->scrnPitch >> 3;
3380 3215
3381 SiS_SetReg(SiS_Pr->SiS_P3d4,0x13,(HDisplay & 0xFF)); 3216 SiS_SetReg(SiS_Pr->SiS_P3d4,0x13,(HDisplay & 0xFF));
3382 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0xF0,(HDisplay>>8)); 3217 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0xF0,(HDisplay >> 8));
3383} 3218}
3384 3219
3385static void 3220static void
3386SiS_SetPitchCRT2(SiS_Private *SiS_Pr, ScrnInfoPtr pScrn) 3221SiS_SetPitchCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn)
3387{ 3222{
3388 SISPtr pSiS = SISPTR(pScrn); 3223 SISPtr pSiS = SISPTR(pScrn);
3389 UShort HDisplay = pSiS->scrnPitch2 >> 3; 3224 unsigned short HDisplay = pSiS->scrnPitch2 >> 3;
3390 3225
3391 /* Unlock CRT2 */ 3226 /* Unlock CRT2 */
3392 if(pSiS->VGAEngine == SIS_315_VGA) 3227 if(pSiS->VGAEngine == SIS_315_VGA)
3393 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2F, 0x01); 3228 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2F, 0x01);
3394 else 3229 else
3395 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24, 0x01); 3230 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24, 0x01);
3396 3231
3397 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,(HDisplay & 0xFF)); 3232 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,(HDisplay & 0xFF));
3398 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0xF0,(HDisplay >> 8)); 3233 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0xF0,(HDisplay >> 8));
3399} 3234}
3400 3235
3401static void 3236static void
3402SiS_SetPitch(SiS_Private *SiS_Pr, ScrnInfoPtr pScrn) 3237SiS_SetPitch(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn)
3403{ 3238{
3404 SISPtr pSiS = SISPTR(pScrn); 3239 SISPtr pSiS = SISPTR(pScrn);
3405 BOOLEAN isslavemode = FALSE; 3240 BOOLEAN isslavemode = FALSE;
3406 3241
3407 if( (pSiS->VBFlags & VB_VIDEOBRIDGE) && 3242 if( (pSiS->VBFlags2 & VB2_VIDEOBRIDGE) &&
3408 ( ((pSiS->VGAEngine == SIS_300_VGA) && 3243 ( ((pSiS->VGAEngine == SIS_300_VGA) &&
3409 (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0xa0) == 0x20) || 3244 (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0xa0) == 0x20) ||
3410 ((pSiS->VGAEngine == SIS_315_VGA) && 3245 ((pSiS->VGAEngine == SIS_315_VGA) &&
3411 (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x50) == 0x10) ) ) { 3246 (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x50) == 0x10) ) ) {
3412 isslavemode = TRUE; 3247 isslavemode = TRUE;
3413 } 3248 }
@@ -3427,59 +3262,59 @@ SiS_SetPitch(SiS_Private *SiS_Pr, ScrnInfoPtr pScrn)
3427/* SiSSetMode() */ 3262/* SiSSetMode() */
3428/*********************************************/ 3263/*********************************************/
3429 3264
3430#ifdef LINUX_XF86 3265#ifdef SIS_XORG_XF86
3431/* We need pScrn for setting the pitch correctly */ 3266/* We need pScrn for setting the pitch correctly */
3432BOOLEAN 3267BOOLEAN
3433SiSSetMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,ScrnInfoPtr pScrn,USHORT ModeNo, BOOLEAN dosetpitch) 3268SiSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn, unsigned short ModeNo, BOOLEAN dosetpitch)
3434#else 3269#else
3435BOOLEAN 3270BOOLEAN
3436SiSSetMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,USHORT ModeNo) 3271SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
3437#endif 3272#endif
3438{ 3273{
3439 USHORT ModeIdIndex; 3274 SISIOADDRESS BaseAddr = SiS_Pr->IOAddress;
3440 SISIOADDRESS BaseAddr = HwInfo->ulIOAddress; 3275 unsigned short RealModeNo, ModeIdIndex;
3441 unsigned char backupreg=0; 3276 unsigned char backupreg = 0;
3442#ifdef LINUX_KERNEL 3277#ifdef SIS_LINUX_KERNEL
3443 USHORT KeepLockReg; 3278 unsigned short KeepLockReg;
3444 ULONG temp;
3445 3279
3446 SiS_Pr->UseCustomMode = FALSE; 3280 SiS_Pr->UseCustomMode = FALSE;
3447 SiS_Pr->CRT1UsesCustomMode = FALSE; 3281 SiS_Pr->CRT1UsesCustomMode = FALSE;
3448#endif 3282#endif
3449 3283
3284 SiS_Pr->SiS_flag_clearbuffer = 0;
3285
3450 if(SiS_Pr->UseCustomMode) { 3286 if(SiS_Pr->UseCustomMode) {
3451 ModeNo = 0xfe; 3287 ModeNo = 0xfe;
3288 } else {
3289#ifdef SIS_LINUX_KERNEL
3290 if(!(ModeNo & 0x80)) SiS_Pr->SiS_flag_clearbuffer = 1;
3291#endif
3292 ModeNo &= 0x7f;
3452 } 3293 }
3453 3294
3454 SiSInitPtr(SiS_Pr, HwInfo); 3295 /* Don't use FSTN mode for CRT1 */
3296 RealModeNo = ModeNo;
3297 if(ModeNo == 0x5b) ModeNo = 0x56;
3298
3299 SiSInitPtr(SiS_Pr);
3455 SiSRegInit(SiS_Pr, BaseAddr); 3300 SiSRegInit(SiS_Pr, BaseAddr);
3456 SiS_GetSysFlags(SiS_Pr, HwInfo); 3301 SiS_GetSysFlags(SiS_Pr);
3457 3302
3458#if defined(LINUX_XF86) && (defined(i386) || defined(__i386) || defined(__i386__) || defined(__AMD64__)) 3303 SiS_Pr->SiS_VGAINFO = 0x11;
3304#if defined(SIS_XORG_XF86) && (defined(i386) || defined(__i386) || defined(__i386__) || defined(__AMD64__) || defined(__amd64__) || defined(__x86_64__))
3459 if(pScrn) SiS_Pr->SiS_VGAINFO = SiS_GetSetBIOSScratch(pScrn, 0x489, 0xff); 3305 if(pScrn) SiS_Pr->SiS_VGAINFO = SiS_GetSetBIOSScratch(pScrn, 0x489, 0xff);
3460 else
3461#endif
3462 SiS_Pr->SiS_VGAINFO = 0x11;
3463
3464 SiSInitPCIetc(SiS_Pr, HwInfo);
3465 SiSSetLVDSetc(SiS_Pr, HwInfo);
3466 SiSDetermineROMUsage(SiS_Pr, HwInfo);
3467
3468 SiS_Pr->SiS_flag_clearbuffer = 0;
3469
3470 if(!SiS_Pr->UseCustomMode) {
3471#ifdef LINUX_KERNEL
3472 if(!(ModeNo & 0x80)) SiS_Pr->SiS_flag_clearbuffer = 1;
3473#endif 3306#endif
3474 ModeNo &= 0x7f;
3475 }
3476 3307
3477#ifdef LINUX_KERNEL 3308#ifdef SIS_LINUX_KERNEL
3478 KeepLockReg = SiS_GetReg(SiS_Pr->SiS_P3c4,0x05); 3309 KeepLockReg = SiS_GetReg(SiS_Pr->SiS_P3c4,0x05);
3479#endif 3310#endif
3480 SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86); 3311 SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86);
3481 3312
3482 SiS_UnLockCRT2(SiS_Pr, HwInfo); 3313 SiSInitPCIetc(SiS_Pr);
3314 SiSSetLVDSetc(SiS_Pr);
3315 SiSDetermineROMUsage(SiS_Pr);
3316
3317 SiS_UnLockCRT2(SiS_Pr);
3483 3318
3484 if(!SiS_Pr->UseCustomMode) { 3319 if(!SiS_Pr->UseCustomMode) {
3485 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return FALSE; 3320 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return FALSE;
@@ -3487,13 +3322,13 @@ SiSSetMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,USHORT ModeNo)
3487 ModeIdIndex = 0; 3322 ModeIdIndex = 0;
3488 } 3323 }
3489 3324
3490 SiS_GetVBType(SiS_Pr, HwInfo); 3325 SiS_GetVBType(SiS_Pr);
3491 3326
3492 /* Init/restore some VB registers */ 3327 /* Init/restore some VB registers */
3493 3328 SiS_InitVB(SiS_Pr);
3494 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 3329 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3495 if(HwInfo->jChipType >= SIS_315H) { 3330 if(SiS_Pr->ChipType >= SIS_315H) {
3496 SiS_ResetVB(SiS_Pr, HwInfo); 3331 SiS_ResetVB(SiS_Pr);
3497 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x32,0x10); 3332 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x32,0x10);
3498 SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x00,0x0c); 3333 SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x00,0x0c);
3499 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 3334 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
@@ -3503,21 +3338,20 @@ SiSSetMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,USHORT ModeNo)
3503 } 3338 }
3504 3339
3505 /* Get VB information (connectors, connected devices) */ 3340 /* Get VB information (connectors, connected devices) */
3506 SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, (SiS_Pr->UseCustomMode) ? 0 : 1); 3341 SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, (SiS_Pr->UseCustomMode) ? 0 : 1);
3507 SiS_SetYPbPr(SiS_Pr, HwInfo); 3342 SiS_SetYPbPr(SiS_Pr);
3508 SiS_SetTVMode(SiS_Pr, ModeNo, ModeIdIndex, HwInfo); 3343 SiS_SetTVMode(SiS_Pr, ModeNo, ModeIdIndex);
3509 SiS_GetLCDResInfo(SiS_Pr, ModeNo, ModeIdIndex, HwInfo); 3344 SiS_GetLCDResInfo(SiS_Pr, ModeNo, ModeIdIndex);
3510 SiS_SetLowModeTest(SiS_Pr, ModeNo, HwInfo); 3345 SiS_SetLowModeTest(SiS_Pr, ModeNo);
3511 3346
3512#ifdef LINUX_KERNEL 3347#ifdef SIS_LINUX_KERNEL
3513 /* 3. Check memory size (Kernel framebuffer driver only) */ 3348 /* Check memory size (kernel framebuffer driver only) */
3514 temp = SiS_CheckMemorySize(SiS_Pr, HwInfo, ModeNo, ModeIdIndex); 3349 if(!SiS_CheckMemorySize(SiS_Pr, ModeNo, ModeIdIndex)) {
3515 if(!temp) return(0); 3350 return FALSE;
3351 }
3516#endif 3352#endif
3517 3353
3518 if(HwInfo->jChipType >= SIS_315H) { 3354 SiS_OpenCRTC(SiS_Pr);
3519 SiS_SetupCR5x(SiS_Pr, HwInfo);
3520 }
3521 3355
3522 if(SiS_Pr->UseCustomMode) { 3356 if(SiS_Pr->UseCustomMode) {
3523 SiS_Pr->CRT1UsesCustomMode = TRUE; 3357 SiS_Pr->CRT1UsesCustomMode = TRUE;
@@ -3530,38 +3364,41 @@ SiSSetMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,USHORT ModeNo)
3530 /* Set mode on CRT1 */ 3364 /* Set mode on CRT1 */
3531 if( (SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) || 3365 if( (SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) ||
3532 (!(SiS_Pr->SiS_VBInfo & SwitchCRT2)) ) { 3366 (!(SiS_Pr->SiS_VBInfo & SwitchCRT2)) ) {
3533 SiS_SetCRT1Group(SiS_Pr, HwInfo, ModeNo, ModeIdIndex); 3367 SiS_SetCRT1Group(SiS_Pr, ModeNo, ModeIdIndex);
3534 } 3368 }
3535 3369
3536 /* Set mode on CRT2 */ 3370 /* Set mode on CRT2 */
3537 if(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2 | SetCRT2ToLCDA)) { 3371 if(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2 | SetCRT2ToLCDA)) {
3538 if( (SiS_Pr->SiS_VBType & VB_SISVB) || 3372 if( (SiS_Pr->SiS_VBType & VB_SISVB) ||
3539 (SiS_Pr->SiS_IF_DEF_LVDS == 1) || 3373 (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
3540 (SiS_Pr->SiS_IF_DEF_CH70xx != 0) || 3374 (SiS_Pr->SiS_IF_DEF_CH70xx != 0) ||
3541 (SiS_Pr->SiS_IF_DEF_TRUMPION != 0) ) { 3375 (SiS_Pr->SiS_IF_DEF_TRUMPION != 0) ) {
3542 SiS_SetCRT2Group(SiS_Pr, HwInfo, ModeNo); 3376 SiS_SetCRT2Group(SiS_Pr, RealModeNo);
3543 } 3377 }
3544 } 3378 }
3545 3379
3546 SiS_HandleCRT1(SiS_Pr); 3380 SiS_HandleCRT1(SiS_Pr);
3547 3381
3548 SiS_StrangeStuff(SiS_Pr, HwInfo); 3382 SiS_StrangeStuff(SiS_Pr);
3549 3383
3550 SiS_DisplayOn(SiS_Pr); 3384 SiS_DisplayOn(SiS_Pr);
3551 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF); 3385 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
3552 3386
3553 if(HwInfo->jChipType >= SIS_315H) { 3387#ifdef SIS315H
3388 if(SiS_Pr->ChipType >= SIS_315H) {
3554 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 3389 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
3555 if(!(SiS_IsDualEdge(SiS_Pr, HwInfo))) { 3390 if(!(SiS_IsDualEdge(SiS_Pr))) {
3556 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb); 3391 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
3557 } 3392 }
3558 } 3393 }
3559 } 3394 }
3395#endif
3560 3396
3561 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 3397 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3562 if(HwInfo->jChipType >= SIS_315H) { 3398 if(SiS_Pr->ChipType >= SIS_315H) {
3563 if(!SiS_Pr->SiS_ROMNew) { 3399#ifdef SIS315H
3564 if(SiS_IsVAMode(SiS_Pr,HwInfo)) { 3400 if(!SiS_Pr->SiS_ROMNew) {
3401 if(SiS_IsVAMode(SiS_Pr)) {
3565 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01); 3402 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01);
3566 } else { 3403 } else {
3567 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x35,0xFE); 3404 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x35,0xFE);
@@ -3574,23 +3411,24 @@ SiSSetMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,USHORT ModeNo)
3574 if((ModeNo == 0x03) || (ModeNo == 0x10)) { 3411 if((ModeNo == 0x03) || (ModeNo == 0x10)) {
3575 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x51,0x80); 3412 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x51,0x80);
3576 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x56,0x08); 3413 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x56,0x08);
3577 } 3414 }
3578 } 3415 }
3579 3416
3580 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & SetCRT2ToLCD) { 3417 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & SetCRT2ToLCD) {
3581 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc); 3418 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
3582 } 3419 }
3583 } else if((HwInfo->jChipType == SIS_630) || 3420#endif
3584 (HwInfo->jChipType == SIS_730)) { 3421 } else if((SiS_Pr->ChipType == SIS_630) ||
3585 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupreg); 3422 (SiS_Pr->ChipType == SIS_730)) {
3423 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupreg);
3586 } 3424 }
3587 } 3425 }
3588 3426
3589#ifdef LINUX_XF86 3427#ifdef SIS_XORG_XF86
3590 if(pScrn) { 3428 if(pScrn) {
3591 /* SetPitch: Adapt to virtual size & position */ 3429 /* SetPitch: Adapt to virtual size & position */
3592 if((ModeNo > 0x13) && (dosetpitch)) { 3430 if((ModeNo > 0x13) && (dosetpitch)) {
3593 SiS_SetPitch(SiS_Pr, pScrn); 3431 SiS_SetPitch(SiS_Pr, pScrn);
3594 } 3432 }
3595 3433
3596 /* Backup/Set ModeNo in BIOS scratch area */ 3434 /* Backup/Set ModeNo in BIOS scratch area */
@@ -3598,33 +3436,37 @@ SiSSetMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,USHORT ModeNo)
3598 } 3436 }
3599#endif 3437#endif
3600 3438
3601#ifdef LINUX_KERNEL /* We never lock registers in XF86 */ 3439 SiS_CloseCRTC(SiS_Pr);
3602 if(KeepLockReg == 0xA1) SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86); 3440
3603 else SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x00); 3441 SiS_Handle760(SiS_Pr);
3442
3443#ifdef SIS_LINUX_KERNEL
3444 /* We never lock registers in XF86 */
3445 if(KeepLockReg != 0xA1) SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x00);
3604#endif 3446#endif
3605 3447
3606 return TRUE; 3448 return TRUE;
3607} 3449}
3608 3450
3609/*********************************************/ 3451/*********************************************/
3610/* XFree86: SiSBIOSSetMode() */ 3452/* X.org/XFree86: SiSBIOSSetMode() */
3611/* for non-Dual-Head mode */ 3453/* for non-Dual-Head mode */
3612/*********************************************/ 3454/*********************************************/
3613 3455
3614#ifdef LINUX_XF86 3456#ifdef SIS_XORG_XF86
3615BOOLEAN 3457BOOLEAN
3616SiSBIOSSetMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn, 3458SiSBIOSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3617 DisplayModePtr mode, BOOLEAN IsCustom) 3459 DisplayModePtr mode, BOOLEAN IsCustom)
3618{ 3460{
3619 SISPtr pSiS = SISPTR(pScrn); 3461 SISPtr pSiS = SISPTR(pScrn);
3620 UShort ModeNo = 0; 3462 unsigned short ModeNo = 0;
3621 3463
3622 SiS_Pr->UseCustomMode = FALSE; 3464 SiS_Pr->UseCustomMode = FALSE;
3623 3465
3624 if((IsCustom) && (SiS_CheckBuildCustomMode(pScrn, mode, pSiS->VBFlags))) { 3466 if((IsCustom) && (SiS_CheckBuildCustomMode(pScrn, mode, pSiS->VBFlags))) {
3625 3467
3626 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3, "Setting custom mode %dx%d\n", 3468 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3, "Setting custom mode %dx%d\n",
3627 SiS_Pr->CHDisplay, 3469 SiS_Pr->CHDisplay,
3628 (mode->Flags & V_INTERLACE ? SiS_Pr->CVDisplay * 2 : 3470 (mode->Flags & V_INTERLACE ? SiS_Pr->CVDisplay * 2 :
3629 (mode->Flags & V_DBLSCAN ? SiS_Pr->CVDisplay / 2 : 3471 (mode->Flags & V_DBLSCAN ? SiS_Pr->CVDisplay / 2 :
3630 SiS_Pr->CVDisplay))); 3472 SiS_Pr->CVDisplay)));
@@ -3632,32 +3474,33 @@ SiSBIOSSetMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn,
3632 } else { 3474 } else {
3633 3475
3634 /* Don't need vbflags here; checks done earlier */ 3476 /* Don't need vbflags here; checks done earlier */
3635 ModeNo = SiS_GetModeNumber(pScrn, mode, 0); 3477 ModeNo = SiS_GetModeNumber(pScrn, mode, pSiS->VBFlags);
3636 if(!ModeNo) return FALSE; 3478 if(!ModeNo) return FALSE;
3637 3479
3638 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3, "Setting standard mode 0x%x\n", ModeNo); 3480 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3, "Setting standard mode 0x%x\n", ModeNo);
3639 3481
3640 } 3482 }
3641 3483
3642 return(SiSSetMode(SiS_Pr, HwInfo, pScrn, ModeNo, TRUE)); 3484 return(SiSSetMode(SiS_Pr, pScrn, ModeNo, TRUE));
3643} 3485}
3644 3486
3645/*********************************************/ 3487/*********************************************/
3646/* XFree86: SiSBIOSSetModeCRT2() */ 3488/* X.org/XFree86: SiSBIOSSetModeCRT2() */
3647/* for Dual-Head modes */ 3489/* for Dual-Head modes */
3648/*********************************************/ 3490/*********************************************/
3491
3649BOOLEAN 3492BOOLEAN
3650SiSBIOSSetModeCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn, 3493SiSBIOSSetModeCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3651 DisplayModePtr mode, BOOLEAN IsCustom) 3494 DisplayModePtr mode, BOOLEAN IsCustom)
3652{ 3495{
3653 USHORT ModeIdIndex; 3496 SISIOADDRESS BaseAddr = SiS_Pr->IOAddress;
3654 SISIOADDRESS BaseAddr = HwInfo->ulIOAddress; 3497 SISPtr pSiS = SISPTR(pScrn);
3655 UShort ModeNo = 0;
3656 unsigned char backupreg=0;
3657 SISPtr pSiS = SISPTR(pScrn);
3658#ifdef SISDUALHEAD 3498#ifdef SISDUALHEAD
3659 SISEntPtr pSiSEnt = pSiS->entityPrivate; 3499 SISEntPtr pSiSEnt = pSiS->entityPrivate;
3660#endif 3500#endif
3501 unsigned short ModeIdIndex;
3502 unsigned short ModeNo = 0;
3503 unsigned char backupreg = 0;
3661 3504
3662 SiS_Pr->UseCustomMode = FALSE; 3505 SiS_Pr->UseCustomMode = FALSE;
3663 3506
@@ -3672,22 +3515,25 @@ SiSBIOSSetModeCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn,
3672 3515
3673 } else { 3516 } else {
3674 3517
3675 ModeNo = SiS_GetModeNumber(pScrn, mode, 0); 3518 ModeNo = SiS_GetModeNumber(pScrn, mode, pSiS->VBFlags);
3676 if(!ModeNo) return FALSE; 3519 if(!ModeNo) return FALSE;
3677 3520
3678 } 3521 }
3679 3522
3680 SiSRegInit(SiS_Pr, BaseAddr); 3523 SiSRegInit(SiS_Pr, BaseAddr);
3681 SiSInitPtr(SiS_Pr, HwInfo); 3524 SiSInitPtr(SiS_Pr);
3682 SiS_GetSysFlags(SiS_Pr, HwInfo); 3525 SiS_GetSysFlags(SiS_Pr);
3683#if (defined(i386) || defined(__i386) || defined(__i386__) || defined(__AMD64__)) 3526#if defined(i386) || defined(__i386) || defined(__i386__) || defined(__AMD64__) || defined(__amd64__) || defined(__x86_64__)
3684 SiS_Pr->SiS_VGAINFO = SiS_GetSetBIOSScratch(pScrn, 0x489, 0xff); 3527 SiS_Pr->SiS_VGAINFO = SiS_GetSetBIOSScratch(pScrn, 0x489, 0xff);
3685#else 3528#else
3686 SiS_Pr->SiS_VGAINFO = 0x11; 3529 SiS_Pr->SiS_VGAINFO = 0x11;
3687#endif 3530#endif
3688 SiSInitPCIetc(SiS_Pr, HwInfo); 3531
3689 SiSSetLVDSetc(SiS_Pr, HwInfo); 3532 SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86);
3690 SiSDetermineROMUsage(SiS_Pr, HwInfo); 3533
3534 SiSInitPCIetc(SiS_Pr);
3535 SiSSetLVDSetc(SiS_Pr);
3536 SiSDetermineROMUsage(SiS_Pr);
3691 3537
3692 /* Save mode info so we can set it from within SetMode for CRT1 */ 3538 /* Save mode info so we can set it from within SetMode for CRT1 */
3693#ifdef SISDUALHEAD 3539#ifdef SISDUALHEAD
@@ -3700,23 +3546,20 @@ SiSBIOSSetModeCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn,
3700 pSiSEnt->CRT2CR35 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35); 3546 pSiSEnt->CRT2CR35 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
3701 pSiSEnt->CRT2CR38 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 3547 pSiSEnt->CRT2CR38 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
3702#if 0 3548#if 0
3703 /* We can't set CRT2 mode before CRT1 mode is set */ 3549 /* We can't set CRT2 mode before CRT1 mode is set - says who...? */
3704 if(pSiSEnt->CRT1ModeNo == -1) { 3550 if(pSiSEnt->CRT1ModeNo == -1) {
3705 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3, 3551 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
3706 "Setting CRT2 mode delayed until after setting CRT1 mode\n"); 3552 "Setting CRT2 mode delayed until after setting CRT1 mode\n");
3707 return TRUE; 3553 return TRUE;
3708 } 3554 }
3709#endif 3555#endif
3710 pSiSEnt->CRT2ModeSet = TRUE; 3556 pSiSEnt->CRT2ModeSet = TRUE;
3711 } 3557 }
3712#endif 3558#endif
3713 3559
3714 /* We don't clear the buffer in X */
3715 SiS_Pr->SiS_flag_clearbuffer=0;
3716
3717 if(SiS_Pr->UseCustomMode) { 3560 if(SiS_Pr->UseCustomMode) {
3718 3561
3719 USHORT temptemp = SiS_Pr->CVDisplay; 3562 unsigned short temptemp = SiS_Pr->CVDisplay;
3720 3563
3721 if(SiS_Pr->CModeFlag & DoubleScanMode) temptemp >>= 1; 3564 if(SiS_Pr->CModeFlag & DoubleScanMode) temptemp >>= 1;
3722 else if(SiS_Pr->CInfoFlag & InterlaceMode) temptemp <<= 1; 3565 else if(SiS_Pr->CInfoFlag & InterlaceMode) temptemp <<= 1;
@@ -3728,13 +3571,11 @@ SiSBIOSSetModeCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn,
3728 } else { 3571 } else {
3729 3572
3730 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3, 3573 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
3731 "Setting standard mode 0x%x on CRT2\n", ModeNo); 3574 "Setting standard mode 0x%x on CRT2\n", ModeNo);
3732 3575
3733 } 3576 }
3734 3577
3735 SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86); 3578 SiS_UnLockCRT2(SiS_Pr);
3736
3737 SiS_UnLockCRT2(SiS_Pr, HwInfo);
3738 3579
3739 if(!SiS_Pr->UseCustomMode) { 3580 if(!SiS_Pr->UseCustomMode) {
3740 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return FALSE; 3581 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return FALSE;
@@ -3742,56 +3583,59 @@ SiSBIOSSetModeCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn,
3742 ModeIdIndex = 0; 3583 ModeIdIndex = 0;
3743 } 3584 }
3744 3585
3745 SiS_GetVBType(SiS_Pr, HwInfo); 3586 SiS_GetVBType(SiS_Pr);
3746 3587
3747 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 3588 SiS_InitVB(SiS_Pr);
3748 if(HwInfo->jChipType >= SIS_315H) { 3589 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3749 SiS_ResetVB(SiS_Pr, HwInfo); 3590 if(SiS_Pr->ChipType >= SIS_315H) {
3591 SiS_ResetVB(SiS_Pr);
3750 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x32,0x10); 3592 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x32,0x10);
3751 SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x00,0x0c); 3593 SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x00,0x0c);
3752 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 3594 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
3753 } else { 3595 } else {
3754 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35); 3596 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
3755 } 3597 }
3756 } 3598 }
3757 3599
3758 /* Get VB information (connectors, connected devices) */ 3600 /* Get VB information (connectors, connected devices) */
3759 if(!SiS_Pr->UseCustomMode) { 3601 if(!SiS_Pr->UseCustomMode) {
3760 SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, 1); 3602 SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, 1);
3761 } else { 3603 } else {
3762 /* If this is a custom mode, we don't check the modeflag for CRT2Mode */ 3604 /* If this is a custom mode, we don't check the modeflag for CRT2Mode */
3763 SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, 0); 3605 SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, 0);
3764 } 3606 }
3765 SiS_SetYPbPr(SiS_Pr, HwInfo); 3607 SiS_SetYPbPr(SiS_Pr);
3766 SiS_SetTVMode(SiS_Pr, ModeNo, ModeIdIndex, HwInfo); 3608 SiS_SetTVMode(SiS_Pr, ModeNo, ModeIdIndex);
3767 SiS_GetLCDResInfo(SiS_Pr, ModeNo, ModeIdIndex, HwInfo); 3609 SiS_GetLCDResInfo(SiS_Pr, ModeNo, ModeIdIndex);
3768 SiS_SetLowModeTest(SiS_Pr, ModeNo, HwInfo); 3610 SiS_SetLowModeTest(SiS_Pr, ModeNo);
3611
3612 SiS_ResetSegmentRegisters(SiS_Pr);
3769 3613
3770 /* Set mode on CRT2 */ 3614 /* Set mode on CRT2 */
3771 if( (SiS_Pr->SiS_VBType & VB_SISVB) || 3615 if( (SiS_Pr->SiS_VBType & VB_SISVB) ||
3772 (SiS_Pr->SiS_IF_DEF_LVDS == 1) || 3616 (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
3773 (SiS_Pr->SiS_IF_DEF_CH70xx != 0) || 3617 (SiS_Pr->SiS_IF_DEF_CH70xx != 0) ||
3774 (SiS_Pr->SiS_IF_DEF_TRUMPION != 0) ) { 3618 (SiS_Pr->SiS_IF_DEF_TRUMPION != 0) ) {
3775 SiS_SetCRT2Group(SiS_Pr, HwInfo, ModeNo); 3619 SiS_SetCRT2Group(SiS_Pr, ModeNo);
3776 } 3620 }
3777 3621
3778 SiS_StrangeStuff(SiS_Pr, HwInfo); 3622 SiS_StrangeStuff(SiS_Pr);
3779 3623
3780 SiS_DisplayOn(SiS_Pr); 3624 SiS_DisplayOn(SiS_Pr);
3781 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF); 3625 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
3782 3626
3783 if(HwInfo->jChipType >= SIS_315H) { 3627 if(SiS_Pr->ChipType >= SIS_315H) {
3784 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 3628 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
3785 if(!(SiS_IsDualEdge(SiS_Pr, HwInfo))) { 3629 if(!(SiS_IsDualEdge(SiS_Pr))) {
3786 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb); 3630 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
3787 } 3631 }
3788 } 3632 }
3789 } 3633 }
3790 3634
3791 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 3635 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3792 if(HwInfo->jChipType >= SIS_315H) { 3636 if(SiS_Pr->ChipType >= SIS_315H) {
3793 if(!SiS_Pr->SiS_ROMNew) { 3637 if(!SiS_Pr->SiS_ROMNew) {
3794 if(SiS_IsVAMode(SiS_Pr,HwInfo)) { 3638 if(SiS_IsVAMode(SiS_Pr)) {
3795 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01); 3639 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01);
3796 } else { 3640 } else {
3797 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x35,0xFE); 3641 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x35,0xFE);
@@ -3803,8 +3647,8 @@ SiSBIOSSetModeCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn,
3803 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & SetCRT2ToLCD) { 3647 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & SetCRT2ToLCD) {
3804 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc); 3648 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
3805 } 3649 }
3806 } else if((HwInfo->jChipType == SIS_630) || 3650 } else if((SiS_Pr->ChipType == SIS_630) ||
3807 (HwInfo->jChipType == SIS_730)) { 3651 (SiS_Pr->ChipType == SIS_730)) {
3808 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupreg); 3652 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupreg);
3809 } 3653 }
3810 } 3654 }
@@ -3812,25 +3656,27 @@ SiSBIOSSetModeCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn,
3812 /* SetPitch: Adapt to virtual size & position */ 3656 /* SetPitch: Adapt to virtual size & position */
3813 SiS_SetPitchCRT2(SiS_Pr, pScrn); 3657 SiS_SetPitchCRT2(SiS_Pr, pScrn);
3814 3658
3659 SiS_Handle760(SiS_Pr);
3660
3815 return TRUE; 3661 return TRUE;
3816} 3662}
3817 3663
3818/*********************************************/ 3664/*********************************************/
3819/* XFree86: SiSBIOSSetModeCRT1() */ 3665/* X.org/XFree86: SiSBIOSSetModeCRT1() */
3820/* for Dual-Head modes */ 3666/* for Dual-Head modes */
3821/*********************************************/ 3667/*********************************************/
3822 3668
3823BOOLEAN 3669BOOLEAN
3824SiSBIOSSetModeCRT1(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn, 3670SiSBIOSSetModeCRT1(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3825 DisplayModePtr mode, BOOLEAN IsCustom) 3671 DisplayModePtr mode, BOOLEAN IsCustom)
3826{ 3672{
3673 SISIOADDRESS BaseAddr = SiS_Pr->IOAddress;
3827 SISPtr pSiS = SISPTR(pScrn); 3674 SISPtr pSiS = SISPTR(pScrn);
3828 SISIOADDRESS BaseAddr = HwInfo->ulIOAddress; 3675 unsigned short ModeIdIndex, ModeNo = 0;
3829 USHORT ModeIdIndex, ModeNo=0; 3676 unsigned char backupreg = 0;
3830 UCHAR backupreg=0;
3831#ifdef SISDUALHEAD 3677#ifdef SISDUALHEAD
3832 SISEntPtr pSiSEnt = pSiS->entityPrivate; 3678 SISEntPtr pSiSEnt = pSiS->entityPrivate;
3833 UCHAR backupcr30, backupcr31, backupcr38, backupcr35, backupp40d=0; 3679 unsigned char backupcr30, backupcr31, backupcr38, backupcr35, backupp40d=0;
3834 BOOLEAN backupcustom; 3680 BOOLEAN backupcustom;
3835#endif 3681#endif
3836 3682
@@ -3838,43 +3684,41 @@ SiSBIOSSetModeCRT1(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn,
3838 3684
3839 if((IsCustom) && (SiS_CheckBuildCustomMode(pScrn, mode, pSiS->VBFlags))) { 3685 if((IsCustom) && (SiS_CheckBuildCustomMode(pScrn, mode, pSiS->VBFlags))) {
3840 3686
3841 USHORT temptemp = SiS_Pr->CVDisplay; 3687 unsigned short temptemp = SiS_Pr->CVDisplay;
3842 3688
3843 if(SiS_Pr->CModeFlag & DoubleScanMode) temptemp >>= 1; 3689 if(SiS_Pr->CModeFlag & DoubleScanMode) temptemp >>= 1;
3844 else if(SiS_Pr->CInfoFlag & InterlaceMode) temptemp <<= 1; 3690 else if(SiS_Pr->CInfoFlag & InterlaceMode) temptemp <<= 1;
3845 3691
3846 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3, 3692 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
3847 "Setting custom mode %dx%d on CRT1\n", 3693 "Setting custom mode %dx%d on CRT1\n",
3848 SiS_Pr->CHDisplay, temptemp); 3694 SiS_Pr->CHDisplay, temptemp);
3849 ModeNo = 0xfe; 3695 ModeNo = 0xfe;
3850 3696
3851 } else { 3697 } else {
3852 3698
3853 ModeNo = SiS_GetModeNumber(pScrn, mode, 0); 3699 ModeNo = SiS_GetModeNumber(pScrn, mode, 0); /* don't give VBFlags */
3854 if(!ModeNo) return FALSE; 3700 if(!ModeNo) return FALSE;
3855 3701
3856 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3, 3702 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
3857 "Setting standard mode 0x%x on CRT1\n", ModeNo); 3703 "Setting standard mode 0x%x on CRT1\n", ModeNo);
3858 } 3704 }
3859 3705
3860 SiSInitPtr(SiS_Pr, HwInfo); 3706 SiSInitPtr(SiS_Pr);
3861 SiSRegInit(SiS_Pr, BaseAddr); 3707 SiSRegInit(SiS_Pr, BaseAddr);
3862 SiS_GetSysFlags(SiS_Pr, HwInfo); 3708 SiS_GetSysFlags(SiS_Pr);
3863#if (defined(i386) || defined(__i386) || defined(__i386__) || defined(__AMD64__)) 3709#if defined(i386) || defined(__i386) || defined(__i386__) || defined(__AMD64__) || defined(__amd64__) || defined(__x86_64__)
3864 SiS_Pr->SiS_VGAINFO = SiS_GetSetBIOSScratch(pScrn, 0x489, 0xff); 3710 SiS_Pr->SiS_VGAINFO = SiS_GetSetBIOSScratch(pScrn, 0x489, 0xff);
3865#else 3711#else
3866 SiS_Pr->SiS_VGAINFO = 0x11; 3712 SiS_Pr->SiS_VGAINFO = 0x11;
3867#endif 3713#endif
3868 SiSInitPCIetc(SiS_Pr, HwInfo);
3869 SiSSetLVDSetc(SiS_Pr, HwInfo);
3870 SiSDetermineROMUsage(SiS_Pr, HwInfo);
3871
3872 /* We don't clear the buffer in X */
3873 SiS_Pr->SiS_flag_clearbuffer = 0;
3874 3714
3875 SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86); 3715 SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86);
3876 3716
3877 SiS_UnLockCRT2(SiS_Pr, HwInfo); 3717 SiSInitPCIetc(SiS_Pr);
3718 SiSSetLVDSetc(SiS_Pr);
3719 SiSDetermineROMUsage(SiS_Pr);
3720
3721 SiS_UnLockCRT2(SiS_Pr);
3878 3722
3879 if(!SiS_Pr->UseCustomMode) { 3723 if(!SiS_Pr->UseCustomMode) {
3880 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return FALSE; 3724 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return FALSE;
@@ -3883,10 +3727,11 @@ SiSBIOSSetModeCRT1(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn,
3883 } 3727 }
3884 3728
3885 /* Determine VBType */ 3729 /* Determine VBType */
3886 SiS_GetVBType(SiS_Pr, HwInfo); 3730 SiS_GetVBType(SiS_Pr);
3887 3731
3888 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 3732 SiS_InitVB(SiS_Pr);
3889 if(HwInfo->jChipType >= SIS_315H) { 3733 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3734 if(SiS_Pr->ChipType >= SIS_315H) {
3890 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 3735 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
3891 } else { 3736 } else {
3892 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35); 3737 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
@@ -3895,25 +3740,29 @@ SiSBIOSSetModeCRT1(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn,
3895 3740
3896 /* Get VB information (connectors, connected devices) */ 3741 /* Get VB information (connectors, connected devices) */
3897 /* (We don't care if the current mode is a CRT2 mode) */ 3742 /* (We don't care if the current mode is a CRT2 mode) */
3898 SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, 0); 3743 SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, 0);
3899 SiS_SetYPbPr(SiS_Pr, HwInfo); 3744 SiS_SetYPbPr(SiS_Pr);
3900 SiS_SetTVMode(SiS_Pr, ModeNo, ModeIdIndex, HwInfo); 3745 SiS_SetTVMode(SiS_Pr, ModeNo, ModeIdIndex);
3901 SiS_GetLCDResInfo(SiS_Pr, ModeNo, ModeIdIndex, HwInfo); 3746 SiS_GetLCDResInfo(SiS_Pr, ModeNo, ModeIdIndex);
3902 SiS_SetLowModeTest(SiS_Pr, ModeNo, HwInfo); 3747 SiS_SetLowModeTest(SiS_Pr, ModeNo);
3903 3748
3904 if(HwInfo->jChipType >= SIS_315H) { 3749 SiS_OpenCRTC(SiS_Pr);
3905 SiS_SetupCR5x(SiS_Pr, HwInfo);
3906 }
3907 3750
3908 /* Set mode on CRT1 */ 3751 /* Set mode on CRT1 */
3909 SiS_SetCRT1Group(SiS_Pr, HwInfo, ModeNo, ModeIdIndex); 3752 SiS_SetCRT1Group(SiS_Pr, ModeNo, ModeIdIndex);
3910 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { 3753 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
3911 SiS_SetCRT2Group(SiS_Pr, HwInfo, ModeNo); 3754 SiS_SetCRT2Group(SiS_Pr, ModeNo);
3912 } 3755 }
3913 3756
3914 /* SetPitch: Adapt to virtual size & position */ 3757 /* SetPitch: Adapt to virtual size & position */
3915 SiS_SetPitchCRT1(SiS_Pr, pScrn); 3758 SiS_SetPitchCRT1(SiS_Pr, pScrn);
3916 3759
3760 SiS_HandleCRT1(SiS_Pr);
3761
3762 SiS_StrangeStuff(SiS_Pr);
3763
3764 SiS_CloseCRTC(SiS_Pr);
3765
3917#ifdef SISDUALHEAD 3766#ifdef SISDUALHEAD
3918 if(pSiS->DualHeadMode) { 3767 if(pSiS->DualHeadMode) {
3919 pSiSEnt->CRT1ModeNo = ModeNo; 3768 pSiSEnt->CRT1ModeNo = ModeNo;
@@ -3933,7 +3782,7 @@ SiSBIOSSetModeCRT1(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn,
3933#ifdef SISDUALHEAD 3782#ifdef SISDUALHEAD
3934 if(pSiS->DualHeadMode) { 3783 if(pSiS->DualHeadMode) {
3935 if(pSiSEnt->CRT2ModeNo != -1) { 3784 if(pSiSEnt->CRT2ModeNo != -1) {
3936 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3, 3785 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
3937 "(Re-)Setting mode for CRT2\n"); 3786 "(Re-)Setting mode for CRT2\n");
3938 backupcustom = SiS_Pr->UseCustomMode; 3787 backupcustom = SiS_Pr->UseCustomMode;
3939 backupcr30 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); 3788 backupcr30 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
@@ -3952,9 +3801,11 @@ SiSBIOSSetModeCRT1(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn,
3952 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,pSiSEnt->CRT2CR35); 3801 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,pSiSEnt->CRT2CR35);
3953 SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,pSiSEnt->CRT2CR38); 3802 SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,pSiSEnt->CRT2CR38);
3954 } 3803 }
3955 SiSBIOSSetModeCRT2(SiS_Pr, HwInfo, pSiSEnt->pScrn_1, 3804
3805 SiSBIOSSetModeCRT2(SiS_Pr, pSiSEnt->pScrn_1,
3956 pSiSEnt->CRT2DMode, pSiSEnt->CRT2IsCustom); 3806 pSiSEnt->CRT2DMode, pSiSEnt->CRT2IsCustom);
3957 SiS_SetReg(SiS_Pr->SiS_P3d4,0x30,backupcr30); 3807
3808 SiS_SetReg(SiS_Pr->SiS_P3d4,0x30,backupcr30);
3958 SiS_SetReg(SiS_Pr->SiS_P3d4,0x31,backupcr31); 3809 SiS_SetReg(SiS_Pr->SiS_P3d4,0x31,backupcr31);
3959 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupcr35); 3810 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupcr35);
3960 SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,backupcr38); 3811 SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,backupcr38);
@@ -3970,22 +3821,20 @@ SiSBIOSSetModeCRT1(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn,
3970 * possibly overwritten 3821 * possibly overwritten
3971 */ 3822 */
3972 3823
3973 SiS_HandleCRT1(SiS_Pr);
3974
3975 SiS_StrangeStuff(SiS_Pr, HwInfo);
3976
3977 SiS_DisplayOn(SiS_Pr); 3824 SiS_DisplayOn(SiS_Pr);
3978 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF); 3825 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
3979 3826
3980 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 3827 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3981 if(HwInfo->jChipType >= SIS_315H) { 3828 if(SiS_Pr->ChipType >= SIS_315H) {
3982 SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,backupreg); 3829 SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,backupreg);
3983 } else if((HwInfo->jChipType == SIS_630) || 3830 } else if((SiS_Pr->ChipType == SIS_630) ||
3984 (HwInfo->jChipType == SIS_730)) { 3831 (SiS_Pr->ChipType == SIS_730)) {
3985 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupreg); 3832 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupreg);
3986 } 3833 }
3987 } 3834 }
3988 3835
3836 SiS_Handle760(SiS_Pr);
3837
3989 /* Backup/Set ModeNo in BIOS scratch area */ 3838 /* Backup/Set ModeNo in BIOS scratch area */
3990 SiS_GetSetModeID(pScrn,ModeNo); 3839 SiS_GetSetModeID(pScrn,ModeNo);
3991 3840
@@ -3993,84 +3842,6 @@ SiSBIOSSetModeCRT1(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn,
3993} 3842}
3994#endif /* Linux_XF86 */ 3843#endif /* Linux_XF86 */
3995 3844
3996
3997#ifdef LINUX_XF86
3998BOOLEAN
3999SiS_GetPanelID(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4000{
4001 const USHORT PanelTypeTable300[16] = {
4002 0xc101, 0xc117, 0x0121, 0xc135, 0xc142, 0xc152, 0xc162, 0xc072,
4003 0xc181, 0xc192, 0xc1a1, 0xc1b6, 0xc1c2, 0xc0d2, 0xc1e2, 0xc1f2
4004 };
4005 const USHORT PanelTypeTable31030x[16] = {
4006 0xc102, 0xc112, 0x0122, 0xc132, 0xc142, 0xc152, 0xc169, 0xc179,
4007 0x0189, 0xc192, 0xc1a2, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
4008 };
4009 const USHORT PanelTypeTable310LVDS[16] = {
4010 0xc111, 0xc122, 0xc133, 0xc144, 0xc155, 0xc166, 0xc177, 0xc188,
4011 0xc199, 0xc0aa, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
4012 };
4013 USHORT tempax,tempbx,temp;
4014
4015 if(HwInfo->jChipType < SIS_315H) {
4016
4017 tempax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x18);
4018 tempbx = tempax & 0x0F;
4019 if(!(tempax & 0x10)){
4020 if(SiS_Pr->SiS_IF_DEF_LVDS == 1){
4021 tempbx = 0;
4022 temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x38);
4023 if(temp & 0x40) tempbx |= 0x08;
4024 if(temp & 0x20) tempbx |= 0x02;
4025 if(temp & 0x01) tempbx |= 0x01;
4026 temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x39);
4027 if(temp & 0x80) tempbx |= 0x04;
4028 } else {
4029 return 0;
4030 }
4031 }
4032 tempbx = PanelTypeTable300[tempbx];
4033 tempbx |= LCDSync;
4034 temp = tempbx & 0x00FF;
4035 SiS_SetReg(SiS_Pr->SiS_P3d4,0x36,temp);
4036 temp = (tempbx & 0xFF00) >> 8;
4037 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x37,~(LCDSyncBit|LCDRGB18Bit),temp);
4038
4039 } else {
4040
4041 if(HwInfo->jChipType >= SIS_661) return 0;
4042
4043 tempax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1a);
4044 tempax &= 0x1e;
4045 tempax >>= 1;
4046 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
4047 if(tempax == 0) {
4048 /* TODO: Include HUGE detection routine
4049 (Probably not worth bothering)
4050 */
4051 return 0;
4052 }
4053 temp = tempax & 0xff;
4054 tempax--;
4055 tempbx = PanelTypeTable310LVDS[tempax];
4056 } else {
4057 tempbx = PanelTypeTable31030x[tempax];
4058 temp = tempbx & 0xff;
4059 }
4060 SiS_SetReg(SiS_Pr->SiS_P3d4,0x36,temp);
4061 tempbx = (tempbx & 0xff00) >> 8;
4062 temp = tempbx & 0xc1;
4063 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x37,~(LCDSyncBit|LCDRGB18Bit),temp);
4064 if(SiS_Pr->SiS_VBType & VB_SISVB) {
4065 temp = tempbx & 0x04;
4066 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x39,0xfb,temp);
4067 }
4068
4069 }
4070 return 1;
4071}
4072#endif
4073
4074#ifndef GETBITSTR 3845#ifndef GETBITSTR
4075#define BITMASK(h,l) (((unsigned)(1U << ((h)-(l)+1))-1)<<(l)) 3846#define BITMASK(h,l) (((unsigned)(1U << ((h)-(l)+1))-1)<<(l))
4076#define GENMASK(mask) BITMASK(1?mask,0?mask) 3847#define GENMASK(mask) BITMASK(1?mask,0?mask)
@@ -4078,26 +3849,28 @@ SiS_GetPanelID(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4078#define GETBITSTR(val,from,to) ((GETBITS(val,from)) << (0?to)) 3849#define GETBITSTR(val,from,to) ((GETBITS(val,from)) << (0?to))
4079#endif 3850#endif
4080 3851
4081static void 3852void
4082SiS_CalcCRRegisters(SiS_Private *SiS_Pr, int depth) 3853SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth)
4083{ 3854{
3855 int x = 1; /* Fix sync */
3856
4084 SiS_Pr->CCRT1CRTC[0] = ((SiS_Pr->CHTotal >> 3) - 5) & 0xff; /* CR0 */ 3857 SiS_Pr->CCRT1CRTC[0] = ((SiS_Pr->CHTotal >> 3) - 5) & 0xff; /* CR0 */
4085 SiS_Pr->CCRT1CRTC[1] = (SiS_Pr->CHDisplay >> 3) - 1; /* CR1 */ 3858 SiS_Pr->CCRT1CRTC[1] = (SiS_Pr->CHDisplay >> 3) - 1; /* CR1 */
4086 SiS_Pr->CCRT1CRTC[2] = (SiS_Pr->CHBlankStart >> 3) - 1; /* CR2 */ 3859 SiS_Pr->CCRT1CRTC[2] = (SiS_Pr->CHBlankStart >> 3) - 1; /* CR2 */
4087 SiS_Pr->CCRT1CRTC[3] = (((SiS_Pr->CHBlankEnd >> 3) - 1) & 0x1F) | 0x80; /* CR3 */ 3860 SiS_Pr->CCRT1CRTC[3] = (((SiS_Pr->CHBlankEnd >> 3) - 1) & 0x1F) | 0x80; /* CR3 */
4088 SiS_Pr->CCRT1CRTC[4] = (SiS_Pr->CHSyncStart >> 3) + 3; /* CR4 */ 3861 SiS_Pr->CCRT1CRTC[4] = (SiS_Pr->CHSyncStart >> 3) + 3; /* CR4 */
4089 SiS_Pr->CCRT1CRTC[5] = ((((SiS_Pr->CHBlankEnd >> 3) - 1) & 0x20) << 2) | /* CR5 */ 3862 SiS_Pr->CCRT1CRTC[5] = ((((SiS_Pr->CHBlankEnd >> 3) - 1) & 0x20) << 2) | /* CR5 */
4090 (((SiS_Pr->CHSyncEnd >> 3) + 3) & 0x1F); 3863 (((SiS_Pr->CHSyncEnd >> 3) + 3) & 0x1F);
4091 3864
4092 SiS_Pr->CCRT1CRTC[6] = (SiS_Pr->CVTotal - 2) & 0xFF; /* CR6 */ 3865 SiS_Pr->CCRT1CRTC[6] = (SiS_Pr->CVTotal - 2) & 0xFF; /* CR6 */
4093 SiS_Pr->CCRT1CRTC[7] = (((SiS_Pr->CVTotal - 2) & 0x100) >> 8) /* CR7 */ 3866 SiS_Pr->CCRT1CRTC[7] = (((SiS_Pr->CVTotal - 2) & 0x100) >> 8) /* CR7 */
4094 | (((SiS_Pr->CVDisplay - 1) & 0x100) >> 7) 3867 | (((SiS_Pr->CVDisplay - 1) & 0x100) >> 7)
4095 | ((SiS_Pr->CVSyncStart & 0x100) >> 6) 3868 | (((SiS_Pr->CVSyncStart - x) & 0x100) >> 6)
4096 | (((SiS_Pr->CVBlankStart - 1) & 0x100) >> 5) 3869 | (((SiS_Pr->CVBlankStart- 1) & 0x100) >> 5)
4097 | 0x10 3870 | 0x10
4098 | (((SiS_Pr->CVTotal - 2) & 0x200) >> 4) 3871 | (((SiS_Pr->CVTotal - 2) & 0x200) >> 4)
4099 | (((SiS_Pr->CVDisplay - 1) & 0x200) >> 3) 3872 | (((SiS_Pr->CVDisplay - 1) & 0x200) >> 3)
4100 | ((SiS_Pr->CVSyncStart & 0x200) >> 2); 3873 | (((SiS_Pr->CVSyncStart - x) & 0x200) >> 2);
4101 3874
4102 SiS_Pr->CCRT1CRTC[16] = ((((SiS_Pr->CVBlankStart - 1) & 0x200) >> 4) >> 5); /* CR9 */ 3875 SiS_Pr->CCRT1CRTC[16] = ((((SiS_Pr->CVBlankStart - 1) & 0x200) >> 4) >> 5); /* CR9 */
4103 3876
@@ -4106,55 +3879,44 @@ SiS_CalcCRRegisters(SiS_Private *SiS_Pr, int depth)
4106 else if(SiS_Pr->CHDisplay >= 640) SiS_Pr->CCRT1CRTC[16] |= 0x40; 3879 else if(SiS_Pr->CHDisplay >= 640) SiS_Pr->CCRT1CRTC[16] |= 0x40;
4107 } 3880 }
4108 3881
4109#if 0 3882 SiS_Pr->CCRT1CRTC[8] = (SiS_Pr->CVSyncStart - x) & 0xFF; /* CR10 */
4110 if (mode->VScan >= 32) 3883 SiS_Pr->CCRT1CRTC[9] = ((SiS_Pr->CVSyncEnd - x) & 0x0F) | 0x80; /* CR11 */
4111 regp->CRTC[9] |= 0x1F;
4112 else if (mode->VScan > 1)
4113 regp->CRTC[9] |= mode->VScan - 1;
4114#endif
4115
4116 SiS_Pr->CCRT1CRTC[8] = (SiS_Pr->CVSyncStart ) & 0xFF; /* CR10 */
4117 SiS_Pr->CCRT1CRTC[9] = ((SiS_Pr->CVSyncEnd ) & 0x0F) | 0x80; /* CR11 */
4118 SiS_Pr->CCRT1CRTC[10] = (SiS_Pr->CVDisplay - 1) & 0xFF; /* CR12 */ 3884 SiS_Pr->CCRT1CRTC[10] = (SiS_Pr->CVDisplay - 1) & 0xFF; /* CR12 */
4119 SiS_Pr->CCRT1CRTC[11] = (SiS_Pr->CVBlankStart - 1) & 0xFF; /* CR15 */ 3885 SiS_Pr->CCRT1CRTC[11] = (SiS_Pr->CVBlankStart - 1) & 0xFF; /* CR15 */
4120 SiS_Pr->CCRT1CRTC[12] = (SiS_Pr->CVBlankEnd - 1) & 0xFF; /* CR16 */ 3886 SiS_Pr->CCRT1CRTC[12] = (SiS_Pr->CVBlankEnd - 1) & 0xFF; /* CR16 */
4121 3887
4122 SiS_Pr->CCRT1CRTC[13] = /* SRA */ 3888 SiS_Pr->CCRT1CRTC[13] = /* SRA */
4123 GETBITSTR((SiS_Pr->CVTotal -2), 10:10, 0:0) | 3889 GETBITSTR((SiS_Pr->CVTotal -2), 10:10, 0:0) |
4124 GETBITSTR((SiS_Pr->CVDisplay -1), 10:10, 1:1) | 3890 GETBITSTR((SiS_Pr->CVDisplay -1), 10:10, 1:1) |
4125 GETBITSTR((SiS_Pr->CVBlankStart-1), 10:10, 2:2) | 3891 GETBITSTR((SiS_Pr->CVBlankStart-1), 10:10, 2:2) |
4126 GETBITSTR((SiS_Pr->CVSyncStart ), 10:10, 3:3) | 3892 GETBITSTR((SiS_Pr->CVSyncStart -x), 10:10, 3:3) |
4127 GETBITSTR((SiS_Pr->CVBlankEnd -1), 8:8, 4:4) | 3893 GETBITSTR((SiS_Pr->CVBlankEnd -1), 8:8, 4:4) |
4128 GETBITSTR((SiS_Pr->CVSyncEnd ), 4:4, 5:5) ; 3894 GETBITSTR((SiS_Pr->CVSyncEnd ), 4:4, 5:5) ;
4129 3895
4130 SiS_Pr->CCRT1CRTC[14] = /* SRB */ 3896 SiS_Pr->CCRT1CRTC[14] = /* SRB */
4131 GETBITSTR((SiS_Pr->CHTotal >> 3) - 5, 9:8, 1:0) | 3897 GETBITSTR((SiS_Pr->CHTotal >> 3) - 5, 9:8, 1:0) |
4132 GETBITSTR((SiS_Pr->CHDisplay >> 3) - 1, 9:8, 3:2) | 3898 GETBITSTR((SiS_Pr->CHDisplay >> 3) - 1, 9:8, 3:2) |
4133 GETBITSTR((SiS_Pr->CHBlankStart >> 3) - 1, 9:8, 5:4) | 3899 GETBITSTR((SiS_Pr->CHBlankStart >> 3) - 1, 9:8, 5:4) |
4134 GETBITSTR((SiS_Pr->CHSyncStart >> 3) + 3, 9:8, 7:6) ; 3900 GETBITSTR((SiS_Pr->CHSyncStart >> 3) + 3, 9:8, 7:6) ;
4135 3901
4136 3902
4137 SiS_Pr->CCRT1CRTC[15] = /* SRC */ 3903 SiS_Pr->CCRT1CRTC[15] = /* SRC */
4138 GETBITSTR((SiS_Pr->CHBlankEnd >> 3) - 1, 7:6, 1:0) | 3904 GETBITSTR((SiS_Pr->CHBlankEnd >> 3) - 1, 7:6, 1:0) |
4139 GETBITSTR((SiS_Pr->CHSyncEnd >> 3) + 3, 5:5, 2:2) ; 3905 GETBITSTR((SiS_Pr->CHSyncEnd >> 3) + 3, 5:5, 2:2) ;
4140} 3906}
4141 3907
4142void 3908void
4143SiS_CalcLCDACRT1Timing(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex) 3909SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
3910 unsigned short ModeIdIndex)
4144{ 3911{
4145 USHORT modeflag, tempax, tempbx, VGAHDE = SiS_Pr->SiS_VGAHDE; 3912 unsigned short modeflag, tempax, tempbx = 0, remaining = 0;
4146 int i,j; 3913 unsigned short VGAHDE = SiS_Pr->SiS_VGAHDE;
3914 int i, j;
4147 3915
4148 /* 1:1 data: use data set by setcrt1crtc() */ 3916 /* 1:1 data: use data set by setcrt1crtc() */
4149 if(SiS_Pr->SiS_LCDInfo & LCDPass11) return; 3917 if(SiS_Pr->SiS_LCDInfo & LCDPass11) return;
4150 3918
4151 if(ModeNo <= 0x13) { 3919 modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
4152 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
4153 } else if(SiS_Pr->UseCustomMode) {
4154 modeflag = SiS_Pr->CModeFlag;
4155 } else {
4156 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4157 }
4158 3920
4159 if(modeflag & HalfDCLK) VGAHDE >>= 1; 3921 if(modeflag & HalfDCLK) VGAHDE >>= 1;
4160 3922
@@ -4164,32 +3926,91 @@ SiS_CalcLCDACRT1Timing(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex)
4164 SiS_Pr->CVDisplay = SiS_Pr->SiS_VGAVDE; 3926 SiS_Pr->CVDisplay = SiS_Pr->SiS_VGAVDE;
4165 SiS_Pr->CVBlankStart = SiS_Pr->SiS_VGAVDE; 3927 SiS_Pr->CVBlankStart = SiS_Pr->SiS_VGAVDE;
4166 3928
4167 tempbx = SiS_Pr->PanelHT - SiS_Pr->PanelXRes; 3929 if(SiS_Pr->ChipType < SIS_315H) {
4168 tempax = SiS_Pr->SiS_VGAHDE; /* not /2 ! */ 3930#ifdef SIS300
4169 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { 3931 tempbx = SiS_Pr->SiS_VGAHT;
4170 tempax = SiS_Pr->PanelXRes; 3932 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3933 tempbx = SiS_Pr->PanelHT;
3934 }
3935 if(modeflag & HalfDCLK) tempbx >>= 1;
3936 remaining = tempbx % 8;
3937#endif
3938 } else {
3939#ifdef SIS315H
3940 /* OK for LCDA, LVDS */
3941 tempbx = SiS_Pr->PanelHT - SiS_Pr->PanelXRes;
3942 tempax = SiS_Pr->SiS_VGAHDE; /* not /2 ! */
3943 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3944 tempax = SiS_Pr->PanelXRes;
3945 }
3946 tempbx += tempax;
3947 if(modeflag & HalfDCLK) tempbx -= VGAHDE;
3948#endif
4171 } 3949 }
4172 tempbx += tempax;
4173 if(modeflag & HalfDCLK) tempbx -= VGAHDE;
4174 SiS_Pr->CHTotal = SiS_Pr->CHBlankEnd = tempbx; 3950 SiS_Pr->CHTotal = SiS_Pr->CHBlankEnd = tempbx;
4175 3951
4176 tempax = VGAHDE; 3952 if(SiS_Pr->ChipType < SIS_315H) {
4177 tempbx = SiS_Pr->CHTotal; 3953#ifdef SIS300
4178 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { 3954 if(SiS_Pr->SiS_VGAHDE == SiS_Pr->PanelXRes) {
4179 tempbx = SiS_Pr->PanelXRes; 3955 SiS_Pr->CHSyncStart = SiS_Pr->SiS_VGAHDE + ((SiS_Pr->PanelHRS + 1) & ~1);
4180 if(modeflag & HalfDCLK) tempbx >>= 1; 3956 SiS_Pr->CHSyncEnd = SiS_Pr->CHSyncStart + SiS_Pr->PanelHRE;
4181 tempax += ((tempbx - tempax) >> 1); 3957 if(modeflag & HalfDCLK) {
3958 SiS_Pr->CHSyncStart >>= 1;
3959 SiS_Pr->CHSyncEnd >>= 1;
3960 }
3961 } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3962 tempax = (SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) >> 1;
3963 tempbx = (SiS_Pr->PanelHRS + 1) & ~1;
3964 if(modeflag & HalfDCLK) {
3965 tempax >>= 1;
3966 tempbx >>= 1;
3967 }
3968 SiS_Pr->CHSyncStart = (VGAHDE + tempax + tempbx + 7) & ~7;
3969 tempax = SiS_Pr->PanelHRE + 7;
3970 if(modeflag & HalfDCLK) tempax >>= 1;
3971 SiS_Pr->CHSyncEnd = (SiS_Pr->CHSyncStart + tempax) & ~7;
3972 } else {
3973 SiS_Pr->CHSyncStart = SiS_Pr->SiS_VGAHDE;
3974 if(modeflag & HalfDCLK) {
3975 SiS_Pr->CHSyncStart >>= 1;
3976 tempax = ((SiS_Pr->CHTotal - SiS_Pr->CHSyncStart) / 3) << 1;
3977 SiS_Pr->CHSyncEnd = SiS_Pr->CHSyncStart + tempax;
3978 } else {
3979 SiS_Pr->CHSyncEnd = (SiS_Pr->CHSyncStart + (SiS_Pr->CHTotal / 10) + 7) & ~7;
3980 SiS_Pr->CHSyncStart += 8;
3981 }
3982 }
3983#endif
3984 } else {
3985#ifdef SIS315H
3986 tempax = VGAHDE;
3987 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3988 tempbx = SiS_Pr->PanelXRes;
3989 if(modeflag & HalfDCLK) tempbx >>= 1;
3990 tempax += ((tempbx - tempax) >> 1);
3991 }
3992 tempax += SiS_Pr->PanelHRS;
3993 SiS_Pr->CHSyncStart = tempax;
3994 tempax += SiS_Pr->PanelHRE;
3995 SiS_Pr->CHSyncEnd = tempax;
3996#endif
4182 } 3997 }
4183 3998
4184 tempax += SiS_Pr->PanelHRS;
4185 SiS_Pr->CHSyncStart = tempax;
4186 tempax += SiS_Pr->PanelHRE;
4187 SiS_Pr->CHSyncEnd = tempax;
4188
4189 tempbx = SiS_Pr->PanelVT - SiS_Pr->PanelYRes; 3999 tempbx = SiS_Pr->PanelVT - SiS_Pr->PanelYRes;
4190 tempax = SiS_Pr->SiS_VGAVDE; 4000 tempax = SiS_Pr->SiS_VGAVDE;
4191 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { 4001 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
4192 tempax = SiS_Pr->PanelYRes; 4002 tempax = SiS_Pr->PanelYRes;
4003 } else if(SiS_Pr->ChipType < SIS_315H) {
4004#ifdef SIS300
4005 /* Stupid hack for 640x400/320x200 */
4006 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
4007 if((tempax + tempbx) == 438) tempbx += 16;
4008 } else if((SiS_Pr->SiS_LCDResInfo == Panel_800x600) ||
4009 (SiS_Pr->SiS_LCDResInfo == Panel_1024x600)) {
4010 tempax = 0;
4011 tempbx = SiS_Pr->SiS_VGAVT;
4012 }
4013#endif
4193 } 4014 }
4194 SiS_Pr->CVTotal = SiS_Pr->CVBlankEnd = tempbx + tempax; 4015 SiS_Pr->CVTotal = SiS_Pr->CVBlankEnd = tempbx + tempax;
4195 4016
@@ -4201,22 +4022,28 @@ SiS_CalcLCDACRT1Timing(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex)
4201 SiS_Pr->CVSyncStart = tempax; 4022 SiS_Pr->CVSyncStart = tempax;
4202 tempax += SiS_Pr->PanelVRE; 4023 tempax += SiS_Pr->PanelVRE;
4203 SiS_Pr->CVSyncEnd = tempax; 4024 SiS_Pr->CVSyncEnd = tempax;
4025 if(SiS_Pr->ChipType < SIS_315H) {
4026 SiS_Pr->CVSyncStart--;
4027 SiS_Pr->CVSyncEnd--;
4028 }
4204 4029
4205 SiS_CalcCRRegisters(SiS_Pr, 8); 4030 SiS_CalcCRRegisters(SiS_Pr, 8);
4031 SiS_Pr->CCRT1CRTC[15] &= ~0xF8;
4032 SiS_Pr->CCRT1CRTC[15] |= (remaining << 4);
4206 SiS_Pr->CCRT1CRTC[16] &= ~0xE0; 4033 SiS_Pr->CCRT1CRTC[16] &= ~0xE0;
4207 4034
4208 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f); 4035 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
4209 4036
4210 for(i=0,j=0;i<=7;i++,j++) { 4037 for(i = 0, j = 0; i <= 7; i++, j++) {
4211 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]); 4038 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
4212 } 4039 }
4213 for(j=0x10;i<=10;i++,j++) { 4040 for(j = 0x10; i <= 10; i++, j++) {
4214 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]); 4041 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
4215 } 4042 }
4216 for(j=0x15;i<=12;i++,j++) { 4043 for(j = 0x15; i <= 12; i++, j++) {
4217 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]); 4044 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
4218 } 4045 }
4219 for(j=0x0A;i<=15;i++,j++) { 4046 for(j = 0x0A; i <= 15; i++, j++) {
4220 SiS_SetReg(SiS_Pr->SiS_P3c4,j,SiS_Pr->CCRT1CRTC[i]); 4047 SiS_SetReg(SiS_Pr->SiS_P3c4,j,SiS_Pr->CCRT1CRTC[i]);
4221 } 4048 }
4222 4049
@@ -4227,1092 +4054,192 @@ SiS_CalcLCDACRT1Timing(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex)
4227 if(modeflag & DoubleScanMode) tempax |= 0x80; 4054 if(modeflag & DoubleScanMode) tempax |= 0x80;
4228 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,0x5F,tempax); 4055 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,0x5F,tempax);
4229 4056
4057#ifdef SIS_XORG_XF86
4230#ifdef TWDEBUG 4058#ifdef TWDEBUG
4231 xf86DrvMsg(0, X_INFO, "%d %d %d %d %d %d %d %d (%d %d %d %d)\n", 4059 xf86DrvMsg(0, X_INFO, "%d %d %d %d %d %d %d %d (%d %d %d %d)\n",
4232 SiS_Pr->CHDisplay, SiS_Pr->CHSyncStart, SiS_Pr->CHSyncEnd, SiS_Pr->CHTotal, 4060 SiS_Pr->CHDisplay, SiS_Pr->CHSyncStart, SiS_Pr->CHSyncEnd, SiS_Pr->CHTotal,
4233 SiS_Pr->CVDisplay, SiS_Pr->CVSyncStart, SiS_Pr->CVSyncEnd, SiS_Pr->CVTotal, 4061 SiS_Pr->CVDisplay, SiS_Pr->CVSyncStart, SiS_Pr->CVSyncEnd, SiS_Pr->CVTotal,
4234 SiS_Pr->CHBlankStart, SiS_Pr->CHBlankEnd, SiS_Pr->CVBlankStart, SiS_Pr->CVBlankEnd); 4062 SiS_Pr->CHBlankStart, SiS_Pr->CHBlankEnd, SiS_Pr->CVBlankStart, SiS_Pr->CVBlankEnd);
4235
4236 xf86DrvMsg(0, X_INFO, " {{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n", 4063 xf86DrvMsg(0, X_INFO, " {{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n",
4237 SiS_Pr->CCRT1CRTC[0], SiS_Pr->CCRT1CRTC[1], 4064 SiS_Pr->CCRT1CRTC[0], SiS_Pr->CCRT1CRTC[1],
4238 SiS_Pr->CCRT1CRTC[2], SiS_Pr->CCRT1CRTC[3], 4065 SiS_Pr->CCRT1CRTC[2], SiS_Pr->CCRT1CRTC[3],
4239 SiS_Pr->CCRT1CRTC[4], SiS_Pr->CCRT1CRTC[5], 4066 SiS_Pr->CCRT1CRTC[4], SiS_Pr->CCRT1CRTC[5],
4240 SiS_Pr->CCRT1CRTC[6], SiS_Pr->CCRT1CRTC[7]); 4067 SiS_Pr->CCRT1CRTC[6], SiS_Pr->CCRT1CRTC[7]);
4241 xf86DrvMsg(0, X_INFO, " 0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n", 4068 xf86DrvMsg(0, X_INFO, " 0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n",
4242 SiS_Pr->CCRT1CRTC[8], SiS_Pr->CCRT1CRTC[9], 4069 SiS_Pr->CCRT1CRTC[8], SiS_Pr->CCRT1CRTC[9],
4243 SiS_Pr->CCRT1CRTC[10], SiS_Pr->CCRT1CRTC[11], 4070 SiS_Pr->CCRT1CRTC[10], SiS_Pr->CCRT1CRTC[11],
4244 SiS_Pr->CCRT1CRTC[12], SiS_Pr->CCRT1CRTC[13], 4071 SiS_Pr->CCRT1CRTC[12], SiS_Pr->CCRT1CRTC[13],
4245 SiS_Pr->CCRT1CRTC[14], SiS_Pr->CCRT1CRTC[15]); 4072 SiS_Pr->CCRT1CRTC[14], SiS_Pr->CCRT1CRTC[15]);
4246 xf86DrvMsg(0, X_INFO, " 0x%02x}},\n", SiS_Pr->CCRT1CRTC[16]); 4073 xf86DrvMsg(0, X_INFO, " 0x%02x}},\n", SiS_Pr->CCRT1CRTC[16]);
4247#endif 4074#endif
4075#endif
4248} 4076}
4249 4077
4250#ifdef LINUX_XF86
4251
4252void 4078void
4253SiS_MakeClockRegs(ScrnInfoPtr pScrn, int clock, UCHAR *p2b, UCHAR *p2c) 4079SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata,
4254{ 4080 int xres, int yres,
4255 int out_n, out_dn, out_div, out_sbit, out_scale; 4081#ifdef SIS_XORG_XF86
4256 unsigned int vclk[5]; 4082 DisplayModePtr current
4257
4258#define Midx 0
4259#define Nidx 1
4260#define VLDidx 2
4261#define Pidx 3
4262#define PSNidx 4
4263
4264 if(SiS_compute_vclk(clock, &out_n, &out_dn, &out_div, &out_sbit, &out_scale)) {
4265 (*p2b) = (out_div == 2) ? 0x80 : 0x00;
4266 (*p2b) |= ((out_n - 1) & 0x7f);
4267 (*p2c) = (out_dn - 1) & 0x1f;
4268 (*p2c) |= (((out_scale - 1) & 3) << 5);
4269 (*p2c) |= ((out_sbit & 0x01) << 7);
4270#ifdef TWDEBUG
4271 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Clock %d: n %d dn %d div %d sb %d sc %d\n",
4272 clock, out_n, out_dn, out_div, out_sbit, out_scale);
4273#endif 4083#endif
4274 } else { 4084#ifdef SIS_LINUX_KERNEL
4275 SiSCalcClock(pScrn, clock, 2, vclk); 4085 struct fb_var_screeninfo *var, BOOLEAN writeres
4276 (*p2b) = (vclk[VLDidx] == 2) ? 0x80 : 0x00;
4277 (*p2b) |= (vclk[Midx] - 1) & 0x7f;
4278 (*p2c) = (vclk[Nidx] - 1) & 0x1f;
4279 if(vclk[Pidx] <= 4) {
4280 /* postscale 1,2,3,4 */
4281 (*p2c) |= ((vclk[Pidx] - 1) & 3) << 5;
4282 } else {
4283 /* postscale 6,8 */
4284 (*p2c) |= (((vclk[Pidx] / 2) - 1) & 3) << 5;
4285 (*p2c) |= 0x80;
4286 }
4287#ifdef TWDEBUG
4288 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Clock %d: n %d dn %d div %d sc %d\n",
4289 clock, vclk[Midx], vclk[Nidx], vclk[VLDidx], vclk[Pidx]);
4290#endif 4086#endif
4291 } 4087)
4292}
4293
4294#endif
4295
4296/* ================ XFREE86/X.ORG ================= */
4297
4298/* Helper functions */
4299
4300#ifdef LINUX_XF86
4301
4302USHORT
4303SiS_CheckBuildCustomMode(ScrnInfoPtr pScrn, DisplayModePtr mode, int VBFlags)
4304{ 4088{
4305 SISPtr pSiS = SISPTR(pScrn); 4089 unsigned short HRE, HBE, HRS, HBS, HDE, HT;
4306 int depth = pSiS->CurrentLayout.bitsPerPixel; 4090 unsigned short VRE, VBE, VRS, VBS, VDE, VT;
4307 4091 unsigned char sr_data, cr_data, cr_data2;
4308 pSiS->SiS_Pr->CModeFlag = 0; 4092 int A, B, C, D, E, F, temp;
4309
4310 pSiS->SiS_Pr->CDClock = mode->Clock;
4311
4312 pSiS->SiS_Pr->CHDisplay = mode->HDisplay;
4313 pSiS->SiS_Pr->CHSyncStart = mode->HSyncStart;
4314 pSiS->SiS_Pr->CHSyncEnd = mode->HSyncEnd;
4315 pSiS->SiS_Pr->CHTotal = mode->HTotal;
4316
4317 pSiS->SiS_Pr->CVDisplay = mode->VDisplay;
4318 pSiS->SiS_Pr->CVSyncStart = mode->VSyncStart;
4319 pSiS->SiS_Pr->CVSyncEnd = mode->VSyncEnd;
4320 pSiS->SiS_Pr->CVTotal = mode->VTotal;
4321
4322 pSiS->SiS_Pr->CFlags = mode->Flags;
4323
4324 if(pSiS->SiS_Pr->CFlags & V_INTERLACE) {
4325 pSiS->SiS_Pr->CVDisplay >>= 1;
4326 pSiS->SiS_Pr->CVSyncStart >>= 1;
4327 pSiS->SiS_Pr->CVSyncEnd >>= 1;
4328 pSiS->SiS_Pr->CVTotal >>= 1;
4329 }
4330 if(pSiS->SiS_Pr->CFlags & V_DBLSCAN) {
4331 /* pSiS->SiS_Pr->CDClock <<= 1; */
4332 pSiS->SiS_Pr->CVDisplay <<= 1;
4333 pSiS->SiS_Pr->CVSyncStart <<= 1;
4334 pSiS->SiS_Pr->CVSyncEnd <<= 1;
4335 pSiS->SiS_Pr->CVTotal <<= 1;
4336 }
4337
4338 pSiS->SiS_Pr->CHBlankStart = pSiS->SiS_Pr->CHDisplay;
4339 pSiS->SiS_Pr->CHBlankEnd = pSiS->SiS_Pr->CHTotal;
4340 pSiS->SiS_Pr->CVBlankStart = pSiS->SiS_Pr->CVSyncStart - 1;
4341 pSiS->SiS_Pr->CVBlankEnd = pSiS->SiS_Pr->CVTotal;
4342 4093
4343 SiS_MakeClockRegs(pScrn, pSiS->SiS_Pr->CDClock, &pSiS->SiS_Pr->CSR2B, &pSiS->SiS_Pr->CSR2C); 4094 sr_data = crdata[14];
4344 4095
4345 pSiS->SiS_Pr->CSRClock = (pSiS->SiS_Pr->CDClock / 1000) + 1; 4096 /* Horizontal total */
4097 HT = crdata[0] | ((unsigned short)(sr_data & 0x03) << 8);
4098 A = HT + 5;
4346 4099
4347 SiS_CalcCRRegisters(pSiS->SiS_Pr, depth); 4100 /* Horizontal display enable end */
4101 HDE = crdata[1] | ((unsigned short)(sr_data & 0x0C) << 6);
4102 E = HDE + 1;
4348 4103
4349 switch(depth) { 4104 /* Horizontal retrace (=sync) start */
4350 case 8: pSiS->SiS_Pr->CModeFlag |= 0x223b; break; 4105 HRS = crdata[4] | ((unsigned short)(sr_data & 0xC0) << 2);
4351 case 16: pSiS->SiS_Pr->CModeFlag |= 0x227d; break; 4106 F = HRS - E - 3;
4352 case 32: pSiS->SiS_Pr->CModeFlag |= 0x22ff; break;
4353 default: return 0;
4354 }
4355 4107
4356 if(pSiS->SiS_Pr->CFlags & V_DBLSCAN) 4108 /* Horizontal blank start */
4357 pSiS->SiS_Pr->CModeFlag |= DoubleScanMode; 4109 HBS = crdata[2] | ((unsigned short)(sr_data & 0x30) << 4);
4358 4110
4359 if((pSiS->SiS_Pr->CVDisplay >= 1024) || 4111 sr_data = crdata[15];
4360 (pSiS->SiS_Pr->CVTotal >= 1024) || 4112 cr_data = crdata[5];
4361 (pSiS->SiS_Pr->CHDisplay >= 1024))
4362 pSiS->SiS_Pr->CModeFlag |= LineCompareOff;
4363 4113
4364 if(pSiS->SiS_Pr->CFlags & V_CLKDIV2) 4114 /* Horizontal blank end */
4365 pSiS->SiS_Pr->CModeFlag |= HalfDCLK; 4115 HBE = (crdata[3] & 0x1f) |
4116 ((unsigned short)(cr_data & 0x80) >> 2) |
4117 ((unsigned short)(sr_data & 0x03) << 6);
4366 4118
4367 pSiS->SiS_Pr->CInfoFlag = 0x0007; 4119 /* Horizontal retrace (=sync) end */
4120 HRE = (cr_data & 0x1f) | ((sr_data & 0x04) << 3);
4368 4121
4369 if(pSiS->SiS_Pr->CFlags & V_NHSYNC) 4122 temp = HBE - ((E - 1) & 255);
4370 pSiS->SiS_Pr->CInfoFlag |= 0x4000; 4123 B = (temp > 0) ? temp : (temp + 256);
4371 4124
4372 if(pSiS->SiS_Pr->CFlags & V_NVSYNC) 4125 temp = HRE - ((E + F + 3) & 63);
4373 pSiS->SiS_Pr->CInfoFlag |= 0x8000; 4126 C = (temp > 0) ? temp : (temp + 64);
4374 4127
4375 if(pSiS->SiS_Pr->CFlags & V_INTERLACE) 4128 D = B - F - C;
4376 pSiS->SiS_Pr->CInfoFlag |= InterlaceMode;
4377 4129
4378 pSiS->SiS_Pr->UseCustomMode = TRUE; 4130#ifdef SIS_XORG_XF86
4131 current->HDisplay = (E * 8);
4132 current->HSyncStart = (E * 8) + (F * 8);
4133 current->HSyncEnd = (E * 8) + (F * 8) + (C * 8);
4134 current->HTotal = (E * 8) + (F * 8) + (C * 8) + (D * 8);
4379#ifdef TWDEBUG 4135#ifdef TWDEBUG
4380 xf86DrvMsg(0, X_INFO, "Custom mode %dx%d:\n", 4136 xf86DrvMsg(0, X_INFO,
4381 pSiS->SiS_Pr->CHDisplay,pSiS->SiS_Pr->CVDisplay); 4137 "H: A %d B %d C %d D %d E %d F %d HT %d HDE %d HRS %d HBS %d HBE %d HRE %d\n",
4382 xf86DrvMsg(0, X_INFO, "Modeflag %04x, Infoflag %04x\n", 4138 A, B, C, D, E, F, HT, HDE, HRS, HBS, HBE, HRE);
4383 pSiS->SiS_Pr->CModeFlag, pSiS->SiS_Pr->CInfoFlag);
4384 xf86DrvMsg(0, X_INFO, " {{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n",
4385 pSiS->SiS_Pr->CCRT1CRTC[0], pSiS->SiS_Pr->CCRT1CRTC[1],
4386 pSiS->SiS_Pr->CCRT1CRTC[2], pSiS->SiS_Pr->CCRT1CRTC[3],
4387 pSiS->SiS_Pr->CCRT1CRTC[4], pSiS->SiS_Pr->CCRT1CRTC[5],
4388 pSiS->SiS_Pr->CCRT1CRTC[6], pSiS->SiS_Pr->CCRT1CRTC[7]);
4389 xf86DrvMsg(0, X_INFO, " 0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n",
4390 pSiS->SiS_Pr->CCRT1CRTC[8], pSiS->SiS_Pr->CCRT1CRTC[9],
4391 pSiS->SiS_Pr->CCRT1CRTC[10], pSiS->SiS_Pr->CCRT1CRTC[11],
4392 pSiS->SiS_Pr->CCRT1CRTC[12], pSiS->SiS_Pr->CCRT1CRTC[13],
4393 pSiS->SiS_Pr->CCRT1CRTC[14], pSiS->SiS_Pr->CCRT1CRTC[15]);
4394 xf86DrvMsg(0, X_INFO, " 0x%02x}},\n", pSiS->SiS_Pr->CCRT1CRTC[16]);
4395 xf86DrvMsg(0, X_INFO, "Clock: 0x%02x, 0x%02x, %d\n",
4396 pSiS->SiS_Pr->CSR2B, pSiS->SiS_Pr->CSR2C, pSiS->SiS_Pr->CSRClock);
4397#endif
4398 return 1;
4399}
4400
4401int
4402SiS_FindPanelFromDB(SISPtr pSiS, USHORT panelvendor, USHORT panelproduct, int *maxx, int *maxy, int *prefx, int *prefy)
4403{
4404 int i, j;
4405 BOOLEAN done = FALSE;
4406
4407 i = 0;
4408 while((!done) && (SiS_PlasmaTable[i].vendor) && panelvendor) {
4409 if(SiS_PlasmaTable[i].vendor == panelvendor) {
4410 for(j=0; j<SiS_PlasmaTable[i].productnum; j++) {
4411 if(SiS_PlasmaTable[i].product[j] == panelproduct) {
4412 if(SiS_PlasmaTable[i].maxx && SiS_PlasmaTable[i].maxy) {
4413 (*maxx) = (int)SiS_PlasmaTable[i].maxx;
4414 (*maxy) = (int)SiS_PlasmaTable[i].maxy;
4415 (*prefx) = (int)SiS_PlasmaTable[i].prefx;
4416 (*prefy) = (int)SiS_PlasmaTable[i].prefy;
4417 done = TRUE;
4418 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
4419 "Identified %s, correcting max X res %d, max Y res %d\n",
4420 SiS_PlasmaTable[i].plasmaname,
4421 SiS_PlasmaTable[i].maxx, SiS_PlasmaTable[i].maxy);
4422 break;
4423 }
4424 }
4425 }
4426 }
4427 i++;
4428 }
4429 return (done) ? 1 : 0;
4430}
4431
4432/* Build a list of supported modes:
4433 * Built-in modes for which we have all data are M_T_DEFAULT,
4434 * modes derived from DDC or database data are M_T_BUILTIN
4435 */
4436DisplayModePtr
4437SiSBuildBuiltInModeList(ScrnInfoPtr pScrn, BOOLEAN includelcdmodes, BOOLEAN isfordvi)
4438{
4439 SISPtr pSiS = SISPTR(pScrn);
4440 unsigned short VRE, VBE, VRS, VBS, VDE, VT;
4441 unsigned short HRE, HBE, HRS, HBS, HDE, HT;
4442 unsigned char sr_data, cr_data, cr_data2, cr_data3;
4443 unsigned char sr2b, sr2c;
4444 float num, denum, postscalar, divider;
4445 int A, B, C, D, E, F, temp, i, j, k, l, index, vclkindex;
4446 DisplayModePtr new = NULL, current = NULL, first = NULL;
4447 BOOLEAN done = FALSE;
4448#if 0
4449 DisplayModePtr backup = NULL;
4450#endif
4451
4452 pSiS->backupmodelist = NULL;
4453 pSiS->AddedPlasmaModes = FALSE;
4454
4455 /* Initialize our pointers */
4456 if(pSiS->VGAEngine == SIS_300_VGA) {
4457#ifdef SIS300
4458 InitTo300Pointer(pSiS->SiS_Pr, &pSiS->sishw_ext);
4459#else 4139#else
4460 return NULL; 4140 (void)VBS; (void)HBS; (void)A;
4461#endif 4141#endif
4462 } else if(pSiS->VGAEngine == SIS_315_VGA) {
4463#ifdef SIS315H
4464 InitTo310Pointer(pSiS->SiS_Pr, &pSiS->sishw_ext);
4465#else
4466 return NULL;
4467#endif
4468 } else return NULL;
4469
4470 i = 0;
4471 while(pSiS->SiS_Pr->SiS_RefIndex[i].Ext_InfoFlag != 0xFFFF) {
4472
4473 index = pSiS->SiS_Pr->SiS_RefIndex[i].Ext_CRT1CRTC;
4474
4475 /* 0x5a (320x240) is a pure FTSN mode, not DSTN! */
4476 if((!pSiS->FSTN) &&
4477 (pSiS->SiS_Pr->SiS_RefIndex[i].ModeID == 0x5a)) {
4478 i++;
4479 continue;
4480 }
4481 if((pSiS->FSTN) &&
4482 (pSiS->SiS_Pr->SiS_RefIndex[i].XRes == 320) &&
4483 (pSiS->SiS_Pr->SiS_RefIndex[i].YRes == 240) &&
4484 (pSiS->SiS_Pr->SiS_RefIndex[i].ModeID != 0x5a)) {
4485 i++;
4486 continue;
4487 }
4488
4489 if(!(new = xalloc(sizeof(DisplayModeRec)))) return first;
4490 memset(new, 0, sizeof(DisplayModeRec));
4491 if(!(new->name = xalloc(10))) {
4492 xfree(new);
4493 return first;
4494 }
4495 if(!first) first = new;
4496 if(current) {
4497 current->next = new;
4498 new->prev = current;
4499 }
4500
4501 current = new;
4502
4503 sprintf(current->name, "%dx%d", pSiS->SiS_Pr->SiS_RefIndex[i].XRes,
4504 pSiS->SiS_Pr->SiS_RefIndex[i].YRes);
4505
4506 current->status = MODE_OK;
4507
4508 current->type = M_T_DEFAULT;
4509
4510 vclkindex = pSiS->SiS_Pr->SiS_RefIndex[i].Ext_CRTVCLK;
4511 if(pSiS->VGAEngine == SIS_300_VGA) vclkindex &= 0x3F;
4512
4513 sr2b = pSiS->SiS_Pr->SiS_VCLKData[vclkindex].SR2B;
4514 sr2c = pSiS->SiS_Pr->SiS_VCLKData[vclkindex].SR2C;
4515
4516 divider = (sr2b & 0x80) ? 2.0 : 1.0;
4517 postscalar = (sr2c & 0x80) ?
4518 ( (((sr2c >> 5) & 0x03) == 0x02) ? 6.0 : 8.0) : (((sr2c >> 5) & 0x03) + 1.0);
4519 num = (sr2b & 0x7f) + 1.0;
4520 denum = (sr2c & 0x1f) + 1.0;
4521
4522#ifdef TWDEBUG
4523 xf86DrvMsg(0, X_INFO, "------------\n");
4524 xf86DrvMsg(0, X_INFO, "sr2b: %x sr2c %x div %f ps %f num %f denum %f\n",
4525 sr2b, sr2c, divider, postscalar, num, denum);
4526#endif 4142#endif
4527 4143#ifdef SIS_LINUX_KERNEL
4528 current->Clock = (int)(14318 * (divider / postscalar) * (num / denum)); 4144 if(writeres) var->xres = xres = E * 8;
4529 4145 var->left_margin = D * 8;
4530 sr_data = pSiS->SiS_Pr->SiS_CRT1Table[index].CR[14]; 4146 var->right_margin = F * 8;
4531 /* inSISIDXREG(SISSR, 0x0b, sr_data); */ 4147 var->hsync_len = C * 8;
4532
4533 cr_data = pSiS->SiS_Pr->SiS_CRT1Table[index].CR[0];
4534 /* inSISIDXREG(SISCR, 0x00, cr_data); */
4535
4536 /* Horizontal total */
4537 HT = (cr_data & 0xff) |
4538 ((unsigned short) (sr_data & 0x03) << 8);
4539 A = HT + 5;
4540
4541 cr_data = pSiS->SiS_Pr->SiS_CRT1Table[index].CR[1];
4542 /* inSISIDXREG(SISCR, 0x01, cr_data); */
4543
4544 /* Horizontal display enable end */
4545 HDE = (cr_data & 0xff) |
4546 ((unsigned short) (sr_data & 0x0C) << 6);
4547 E = HDE + 1; /* 0x80 0x64 */
4548
4549 cr_data = pSiS->SiS_Pr->SiS_CRT1Table[index].CR[4];
4550 /* inSISIDXREG(SISCR, 0x04, cr_data); */
4551
4552 /* Horizontal retrace (=sync) start */
4553 HRS = (cr_data & 0xff) |
4554 ((unsigned short) (sr_data & 0xC0) << 2);
4555 F = HRS - E - 3; /* 0x06 0x06 */
4556
4557 cr_data = pSiS->SiS_Pr->SiS_CRT1Table[index].CR[2];
4558 /* inSISIDXREG(SISCR, 0x02, cr_data); */
4559
4560 /* Horizontal blank start */
4561 HBS = (cr_data & 0xff) |
4562 ((unsigned short) (sr_data & 0x30) << 4);
4563
4564 sr_data = pSiS->SiS_Pr->SiS_CRT1Table[index].CR[15];
4565 /* inSISIDXREG(SISSR, 0x0c, sr_data); */
4566
4567 cr_data = pSiS->SiS_Pr->SiS_CRT1Table[index].CR[3];
4568 /* inSISIDXREG(SISCR, 0x03, cr_data); */
4569
4570 cr_data2 = pSiS->SiS_Pr->SiS_CRT1Table[index].CR[5];
4571 /* inSISIDXREG(SISCR, 0x05, cr_data2); */
4572
4573 /* Horizontal blank end */
4574 HBE = (cr_data & 0x1f) |
4575 ((unsigned short) (cr_data2 & 0x80) >> 2) |
4576 ((unsigned short) (sr_data & 0x03) << 6);
4577
4578 /* Horizontal retrace (=sync) end */
4579 HRE = (cr_data2 & 0x1f) | ((sr_data & 0x04) << 3);
4580
4581 temp = HBE - ((E - 1) & 255);
4582 B = (temp > 0) ? temp : (temp + 256);
4583
4584 temp = HRE - ((E + F + 3) & 63);
4585 C = (temp > 0) ? temp : (temp + 64); /* 0x0b 0x0b */
4586
4587 D = B - F - C;
4588
4589 if((pSiS->SiS_Pr->SiS_RefIndex[i].XRes == 320) &&
4590 ((pSiS->SiS_Pr->SiS_RefIndex[i].YRes == 200) ||
4591 (pSiS->SiS_Pr->SiS_RefIndex[i].YRes == 240))) {
4592
4593 /* Terrible hack, but correct CRTC data for
4594 * these modes only produces a black screen...
4595 * (HRE is 0, leading into a too large C and
4596 * a negative D. The CRT controller does not
4597 * seem to like correcting HRE to 50
4598 */
4599 current->HDisplay = 320;
4600 current->HSyncStart = 328;
4601 current->HSyncEnd = 376;
4602 current->HTotal = 400;
4603
4604 } else {
4605
4606 current->HDisplay = (E * 8);
4607 current->HSyncStart = (E * 8) + (F * 8);
4608 current->HSyncEnd = (E * 8) + (F * 8) + (C * 8);
4609 current->HTotal = (E * 8) + (F * 8) + (C * 8) + (D * 8);
4610
4611 }
4612
4613#ifdef TWDEBUG
4614 xf86DrvMsg(0, X_INFO,
4615 "H: A %d B %d C %d D %d E %d F %d HT %d HDE %d HRS %d HBS %d HBE %d HRE %d\n",
4616 A, B, C, D, E, F, HT, HDE, HRS, HBS, HBE, HRE);
4617#endif 4148#endif
4618 4149
4619 sr_data = pSiS->SiS_Pr->SiS_CRT1Table[index].CR[13]; 4150 /* Vertical */
4620 /* inSISIDXREG(SISSR, 0x0A, sr_data); */ 4151 sr_data = crdata[13];
4621 4152 cr_data = crdata[7];
4622 cr_data = pSiS->SiS_Pr->SiS_CRT1Table[index].CR[6]; 4153
4623 /* inSISIDXREG(SISCR, 0x06, cr_data); */ 4154 /* Vertical total */
4624 4155 VT = crdata[6] |
4625 cr_data2 = pSiS->SiS_Pr->SiS_CRT1Table[index].CR[7]; 4156 ((unsigned short)(cr_data & 0x01) << 8) |
4626 /* inSISIDXREG(SISCR, 0x07, cr_data2); */ 4157 ((unsigned short)(cr_data & 0x20) << 4) |
4627 4158 ((unsigned short)(sr_data & 0x01) << 10);
4628 /* Vertical total */ 4159 A = VT + 2;
4629 VT = (cr_data & 0xFF) | 4160
4630 ((unsigned short) (cr_data2 & 0x01) << 8) | 4161 /* Vertical display enable end */
4631 ((unsigned short)(cr_data2 & 0x20) << 4) | 4162 VDE = crdata[10] |
4632 ((unsigned short) (sr_data & 0x01) << 10); 4163 ((unsigned short)(cr_data & 0x02) << 7) |
4633 A = VT + 2; 4164 ((unsigned short)(cr_data & 0x40) << 3) |
4634 4165 ((unsigned short)(sr_data & 0x02) << 9);
4635 cr_data = pSiS->SiS_Pr->SiS_CRT1Table[index].CR[10]; 4166 E = VDE + 1;
4636 /* inSISIDXREG(SISCR, 0x12, cr_data); */ 4167
4637 4168 /* Vertical retrace (=sync) start */
4638 /* Vertical display enable end */ 4169 VRS = crdata[8] |
4639 VDE = (cr_data & 0xff) | 4170 ((unsigned short)(cr_data & 0x04) << 6) |
4640 ((unsigned short) (cr_data2 & 0x02) << 7) | 4171 ((unsigned short)(cr_data & 0x80) << 2) |
4641 ((unsigned short) (cr_data2 & 0x40) << 3) | 4172 ((unsigned short)(sr_data & 0x08) << 7);
4642 ((unsigned short) (sr_data & 0x02) << 9); 4173 F = VRS + 1 - E;
4643 E = VDE + 1; 4174
4644 4175 cr_data2 = (crdata[16] & 0x01) << 5;
4645 cr_data = pSiS->SiS_Pr->SiS_CRT1Table[index].CR[8]; 4176
4646 /* inSISIDXREG(SISCR, 0x10, cr_data); */ 4177 /* Vertical blank start */
4647 4178 VBS = crdata[11] |
4648 /* Vertical retrace (=sync) start */ 4179 ((unsigned short)(cr_data & 0x08) << 5) |
4649 VRS = (cr_data & 0xff) | 4180 ((unsigned short)(cr_data2 & 0x20) << 4) |
4650 ((unsigned short) (cr_data2 & 0x04) << 6) | 4181 ((unsigned short)(sr_data & 0x04) << 8);
4651 ((unsigned short) (cr_data2 & 0x80) << 2) | 4182
4652 ((unsigned short) (sr_data & 0x08) << 7); 4183 /* Vertical blank end */
4653 F = VRS + 1 - E; 4184 VBE = crdata[12] | ((unsigned short)(sr_data & 0x10) << 4);
4654 4185 temp = VBE - ((E - 1) & 511);
4655 cr_data = pSiS->SiS_Pr->SiS_CRT1Table[index].CR[11]; 4186 B = (temp > 0) ? temp : (temp + 512);
4656 /* inSISIDXREG(SISCR, 0x15, cr_data); */ 4187
4657 4188 /* Vertical retrace (=sync) end */
4658 cr_data3 = (pSiS->SiS_Pr->SiS_CRT1Table[index].CR[16] & 0x01) << 5; 4189 VRE = (crdata[9] & 0x0f) | ((sr_data & 0x20) >> 1);
4659 /* inSISIDXREG(SISCR, 0x09, cr_data3); */ 4190 temp = VRE - ((E + F - 1) & 31);
4660 4191 C = (temp > 0) ? temp : (temp + 32);
4661 /* Vertical blank start */ 4192
4662 VBS = (cr_data & 0xff) | 4193 D = B - F - C;
4663 ((unsigned short) (cr_data2 & 0x08) << 5) | 4194
4664 ((unsigned short) (cr_data3 & 0x20) << 4) | 4195#ifdef SIS_XORG_XF86
4665 ((unsigned short) (sr_data & 0x04) << 8); 4196 current->VDisplay = VDE + 1;
4666 4197 current->VSyncStart = VRS + 1;
4667 cr_data = pSiS->SiS_Pr->SiS_CRT1Table[index].CR[12]; 4198 current->VSyncEnd = ((VRS & ~0x1f) | VRE) + 1;
4668 /* inSISIDXREG(SISCR, 0x16, cr_data); */ 4199 if(VRE <= (VRS & 0x1f)) current->VSyncEnd += 32;
4669 4200 current->VTotal = E + D + C + F;
4670 /* Vertical blank end */
4671 VBE = (cr_data & 0xff) |
4672 ((unsigned short) (sr_data & 0x10) << 4);
4673 temp = VBE - ((E - 1) & 511);
4674 B = (temp > 0) ? temp : (temp + 512);
4675
4676 cr_data = pSiS->SiS_Pr->SiS_CRT1Table[index].CR[9];
4677 /* inSISIDXREG(SISCR, 0x11, cr_data); */
4678
4679 /* Vertical retrace (=sync) end */
4680 VRE = (cr_data & 0x0f) | ((sr_data & 0x20) >> 1);
4681 temp = VRE - ((E + F - 1) & 31);
4682 C = (temp > 0) ? temp : (temp + 32);
4683
4684 D = B - F - C;
4685
4686 current->VDisplay = VDE + 1;
4687 current->VSyncStart = VRS + 1;
4688 current->VSyncEnd = ((VRS & ~0x1f) | VRE) + 1;
4689 if(VRE <= (VRS & 0x1f)) current->VSyncEnd += 32;
4690 current->VTotal = E + D + C + F;
4691
4692#if 0 4201#if 0
4693 current->VDisplay = E; 4202 current->VDisplay = E;
4694 current->VSyncStart = E + D; 4203 current->VSyncStart = E + D;
4695 current->VSyncEnd = E + D + C; 4204 current->VSyncEnd = E + D + C;
4696 current->VTotal = E + D + C + F; 4205 current->VTotal = E + D + C + F;
4697#endif 4206#endif
4698
4699#ifdef TWDEBUG 4207#ifdef TWDEBUG
4700 xf86DrvMsg(0, X_INFO, 4208 xf86DrvMsg(0, X_INFO,
4701 "V: A %d B %d C %d D %d E %d F %d VT %d VDE %d VRS %d VBS %d VBE %d VRE %d\n", 4209 "V: A %d B %d C %d D %d E %d F %d VT %d VDE %d VRS %d VBS %d VBE %d VRE %d\n",
4702 A, B, C, D, E, F, VT, VDE, VRS, VBS, VBE, VRE); 4210 A, B, C, D, E, F, VT, VDE, VRS, VBS, VBE, VRE);
4703#endif 4211#endif
4704
4705 if(pSiS->SiS_Pr->SiS_RefIndex[i].Ext_InfoFlag & 0x4000)
4706 current->Flags |= V_NHSYNC;
4707 else
4708 current->Flags |= V_PHSYNC;
4709
4710 if(pSiS->SiS_Pr->SiS_RefIndex[i].Ext_InfoFlag & 0x8000)
4711 current->Flags |= V_NVSYNC;
4712 else
4713 current->Flags |= V_PVSYNC;
4714
4715 if(pSiS->SiS_Pr->SiS_RefIndex[i].Ext_InfoFlag & 0x0080)
4716 current->Flags |= V_INTERLACE;
4717
4718 j = 0;
4719 while(pSiS->SiS_Pr->SiS_EModeIDTable[j].Ext_ModeID != 0xff) {
4720 if(pSiS->SiS_Pr->SiS_EModeIDTable[j].Ext_ModeID ==
4721 pSiS->SiS_Pr->SiS_RefIndex[i].ModeID) {
4722 if(pSiS->SiS_Pr->SiS_EModeIDTable[j].Ext_ModeFlag & DoubleScanMode) {
4723 current->Flags |= V_DBLSCAN;
4724 }
4725 break;
4726 }
4727 j++;
4728 }
4729
4730 if(current->Flags & V_INTERLACE) {
4731 current->VDisplay <<= 1;
4732 current->VSyncStart <<= 1;
4733 current->VSyncEnd <<= 1;
4734 current->VTotal <<= 1;
4735 current->VTotal |= 1;
4736 }
4737 if(current->Flags & V_DBLSCAN) {
4738 current->Clock >>= 1;
4739 current->VDisplay >>= 1;
4740 current->VSyncStart >>= 1;
4741 current->VSyncEnd >>= 1;
4742 current->VTotal >>= 1;
4743 }
4744
4745#ifdef TWDEBUG
4746 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
4747 "Built-in: %s %.2f %d %d %d %d %d %d %d %d\n",
4748 current->name, (float)current->Clock / 1000,
4749 current->HDisplay, current->HSyncStart, current->HSyncEnd, current->HTotal,
4750 current->VDisplay, current->VSyncStart, current->VSyncEnd, current->VTotal);
4751#else
4752 (void)VBS; (void)HBS; (void)A;
4753#endif 4212#endif
4754 4213#ifdef SIS_LINUX_KERNEL
4755 i++; 4214 if(writeres) var->yres = yres = E;
4756 } 4215 var->upper_margin = D;
4757 4216 var->lower_margin = F;
4758 /* Add non-standard LCD modes for panel's detailed timings */ 4217 var->vsync_len = C;
4759
4760 if(!includelcdmodes) return first;
4761
4762 if(pSiS->SiS_Pr->CP_Vendor) {
4763 xf86DrvMsg(0, X_INFO, "Checking database for vendor %x, product %x\n",
4764 pSiS->SiS_Pr->CP_Vendor, pSiS->SiS_Pr->CP_Product);
4765 }
4766
4767 i = 0;
4768 while((!done) && (SiS_PlasmaTable[i].vendor) && (pSiS->SiS_Pr->CP_Vendor)) {
4769
4770 if(SiS_PlasmaTable[i].vendor == pSiS->SiS_Pr->CP_Vendor) {
4771
4772 for(j=0; j<SiS_PlasmaTable[i].productnum; j++) {
4773
4774 if(SiS_PlasmaTable[i].product[j] == pSiS->SiS_Pr->CP_Product) {
4775
4776 xf86DrvMsg(pScrn->scrnIndex, X_PROBED,
4777 "Identified %s panel, adding specific modes\n",
4778 SiS_PlasmaTable[i].plasmaname);
4779
4780 for(k=0; k<SiS_PlasmaTable[i].modenum; k++) {
4781
4782 if(isfordvi) {
4783 if(!(SiS_PlasmaTable[i].plasmamodes[k] & 0x80)) continue;
4784 } else {
4785 if(!(SiS_PlasmaTable[i].plasmamodes[k] & 0x40)) continue;
4786 }
4787
4788 l = SiS_PlasmaTable[i].plasmamodes[k] & 0x3f;
4789
4790 if(pSiS->VBFlags & (VB_301|VB_301B|VB_302B|VB_301LV)) {
4791 if(isfordvi) {
4792 if(SiS_PlasmaMode[l].VDisplay > 1024) continue;
4793 }
4794 }
4795
4796 if(!(new = xalloc(sizeof(DisplayModeRec)))) return first;
4797
4798 memset(new, 0, sizeof(DisplayModeRec));
4799 if(!(new->name = xalloc(12))) {
4800 xfree(new);
4801 return first;
4802 }
4803 if(!first) first = new;
4804 if(current) {
4805 current->next = new;
4806 new->prev = current;
4807 }
4808
4809 current = new;
4810
4811 pSiS->AddedPlasmaModes = TRUE;
4812
4813 strcpy(current->name, SiS_PlasmaMode[l].name);
4814 /* sprintf(current->name, "%dx%d", SiS_PlasmaMode[l].HDisplay,
4815 SiS_PlasmaMode[l].VDisplay); */
4816
4817 current->status = MODE_OK;
4818
4819 current->type = M_T_BUILTIN;
4820
4821 current->Clock = SiS_PlasmaMode[l].clock;
4822 current->SynthClock = current->Clock;
4823
4824 current->HDisplay = SiS_PlasmaMode[l].HDisplay;
4825 current->HSyncStart = current->HDisplay + SiS_PlasmaMode[l].HFrontPorch;
4826 current->HSyncEnd = current->HSyncStart + SiS_PlasmaMode[l].HSyncWidth;
4827 current->HTotal = SiS_PlasmaMode[l].HTotal;
4828
4829 current->VDisplay = SiS_PlasmaMode[l].VDisplay;
4830 current->VSyncStart = current->VDisplay + SiS_PlasmaMode[l].VFrontPorch;
4831 current->VSyncEnd = current->VSyncStart + SiS_PlasmaMode[l].VSyncWidth;
4832 current->VTotal = SiS_PlasmaMode[l].VTotal;
4833
4834 current->CrtcHDisplay = current->HDisplay;
4835 current->CrtcHBlankStart = current->HSyncStart;
4836 current->CrtcHSyncStart = current->HSyncStart;
4837 current->CrtcHSyncEnd = current->HSyncEnd;
4838 current->CrtcHBlankEnd = current->HSyncEnd;
4839 current->CrtcHTotal = current->HTotal;
4840
4841 current->CrtcVDisplay = current->VDisplay;
4842 current->CrtcVBlankStart = current->VSyncStart;
4843 current->CrtcVSyncStart = current->VSyncStart;
4844 current->CrtcVSyncEnd = current->VSyncEnd;
4845 current->CrtcVBlankEnd = current->VSyncEnd;
4846 current->CrtcVTotal = current->VTotal;
4847
4848 if(SiS_PlasmaMode[l].SyncFlags & SIS_PL_HSYNCP)
4849 current->Flags |= V_PHSYNC;
4850 else
4851 current->Flags |= V_NHSYNC;
4852
4853 if(SiS_PlasmaMode[l].SyncFlags & SIS_PL_VSYNCP)
4854 current->Flags |= V_PVSYNC;
4855 else
4856 current->Flags |= V_NVSYNC;
4857
4858 if(current->HDisplay > pSiS->LCDwidth)
4859 pSiS->LCDwidth = pSiS->SiS_Pr->CP_MaxX = current->HDisplay;
4860 if(current->VDisplay > pSiS->LCDheight)
4861 pSiS->LCDheight = pSiS->SiS_Pr->CP_MaxY = current->VDisplay;
4862
4863 xf86DrvMsg(pScrn->scrnIndex, X_PROBED,
4864 "\tAdding \"%s\" to list of built-in modes\n", current->name);
4865
4866 }
4867 done = TRUE;
4868 break;
4869 }
4870 }
4871 }
4872
4873 i++;
4874
4875 }
4876
4877 if(pSiS->SiS_Pr->CP_HaveCustomData) {
4878
4879 for(i=0; i<7; i++) {
4880
4881 if(pSiS->SiS_Pr->CP_DataValid[i]) {
4882
4883 if(!(new = xalloc(sizeof(DisplayModeRec)))) return first;
4884
4885 memset(new, 0, sizeof(DisplayModeRec));
4886 if(!(new->name = xalloc(10))) {
4887 xfree(new);
4888 return first;
4889 }
4890 if(!first) first = new;
4891 if(current) {
4892 current->next = new;
4893 new->prev = current;
4894 }
4895
4896 current = new;
4897
4898 sprintf(current->name, "%dx%d", pSiS->SiS_Pr->CP_HDisplay[i],
4899 pSiS->SiS_Pr->CP_VDisplay[i]);
4900
4901 current->status = MODE_OK;
4902
4903 current->type = M_T_BUILTIN;
4904
4905 current->Clock = pSiS->SiS_Pr->CP_Clock[i];
4906 current->SynthClock = current->Clock;
4907
4908 current->HDisplay = pSiS->SiS_Pr->CP_HDisplay[i];
4909 current->HSyncStart = pSiS->SiS_Pr->CP_HSyncStart[i];
4910 current->HSyncEnd = pSiS->SiS_Pr->CP_HSyncEnd[i];
4911 current->HTotal = pSiS->SiS_Pr->CP_HTotal[i];
4912
4913 current->VDisplay = pSiS->SiS_Pr->CP_VDisplay[i];
4914 current->VSyncStart = pSiS->SiS_Pr->CP_VSyncStart[i];
4915 current->VSyncEnd = pSiS->SiS_Pr->CP_VSyncEnd[i];
4916 current->VTotal = pSiS->SiS_Pr->CP_VTotal[i];
4917
4918 current->CrtcHDisplay = current->HDisplay;
4919 current->CrtcHBlankStart = pSiS->SiS_Pr->CP_HBlankStart[i];
4920 current->CrtcHSyncStart = current->HSyncStart;
4921 current->CrtcHSyncEnd = current->HSyncEnd;
4922 current->CrtcHBlankEnd = pSiS->SiS_Pr->CP_HBlankEnd[i];
4923 current->CrtcHTotal = current->HTotal;
4924
4925 current->CrtcVDisplay = current->VDisplay;
4926 current->CrtcVBlankStart = pSiS->SiS_Pr->CP_VBlankStart[i];
4927 current->CrtcVSyncStart = current->VSyncStart;
4928 current->CrtcVSyncEnd = current->VSyncEnd;
4929 current->CrtcVBlankEnd = pSiS->SiS_Pr->CP_VBlankEnd[i];
4930 current->CrtcVTotal = current->VTotal;
4931
4932 if(pSiS->SiS_Pr->CP_SyncValid[i]) {
4933 if(pSiS->SiS_Pr->CP_HSync_P[i])
4934 current->Flags |= V_PHSYNC;
4935 else
4936 current->Flags |= V_NHSYNC;
4937
4938 if(pSiS->SiS_Pr->CP_VSync_P[i])
4939 current->Flags |= V_PVSYNC;
4940 else
4941 current->Flags |= V_NVSYNC;
4942 } else {
4943 /* No sync data? Use positive sync... */
4944 current->Flags |= V_PHSYNC;
4945 current->Flags |= V_PVSYNC;
4946 }
4947 }
4948 }
4949 }
4950
4951 return first;
4952
4953}
4954
4955/* Translate a mode number into the VESA pendant */
4956int
4957SiSTranslateToVESA(ScrnInfoPtr pScrn, int modenumber)
4958{
4959 SISPtr pSiS = SISPTR(pScrn);
4960 int i = 0;
4961
4962 /* Initialize our pointers */
4963 if(pSiS->VGAEngine == SIS_300_VGA) {
4964#ifdef SIS300
4965 InitTo300Pointer(pSiS->SiS_Pr, &pSiS->sishw_ext);
4966#else
4967 return -1;
4968#endif
4969 } else if(pSiS->VGAEngine == SIS_315_VGA) {
4970#ifdef SIS315H
4971 InitTo310Pointer(pSiS->SiS_Pr, &pSiS->sishw_ext);
4972#else
4973 return -1;
4974#endif 4218#endif
4975 } else return -1;
4976
4977 if(modenumber <= 0x13) return modenumber;
4978 4219
4979#ifdef SIS315H 4220 if((xres == 320) && ((yres == 200) || (yres == 240))) {
4980 if(pSiS->ROM661New) { 4221 /* Terrible hack, but correct CRTC data for
4981 while(SiS_EModeIDTable661[i].Ext_ModeID != 0xff) { 4222 * these modes only produces a black screen...
4982 if(SiS_EModeIDTable661[i].Ext_ModeID == modenumber) { 4223 * (HRE is 0, leading into a too large C and
4983 return (int)SiS_EModeIDTable661[i].Ext_VESAID; 4224 * a negative D. The CRT controller does not
4984 } 4225 * seem to like correcting HRE to 50)
4985 i++; 4226 */
4986 } 4227#ifdef SIS_XORG_XF86
4987 } else { 4228 current->HDisplay = 320;
4229 current->HSyncStart = 328;
4230 current->HSyncEnd = 376;
4231 current->HTotal = 400;
4988#endif 4232#endif
4989 while(pSiS->SiS_Pr->SiS_EModeIDTable[i].Ext_ModeID != 0xff) { 4233#ifdef SIS_LINUX_KERNEL
4990 if(pSiS->SiS_Pr->SiS_EModeIDTable[i].Ext_ModeID == modenumber) { 4234 var->left_margin = (400 - 376);
4991 return (int)pSiS->SiS_Pr->SiS_EModeIDTable[i].Ext_VESAID; 4235 var->right_margin = (328 - 320);
4992 } 4236 var->hsync_len = (376 - 328);
4993 i++;
4994 }
4995#ifdef SIS315H
4996 }
4997#endif 4237#endif
4998 return -1;
4999}
5000 4238
5001/* Translate a new BIOS mode number into the driver's pendant */
5002int
5003SiSTranslateToOldMode(int modenumber)
5004{
5005#ifdef SIS315H
5006 int i = 0;
5007
5008 while(SiS_EModeIDTable661[i].Ext_ModeID != 0xff) {
5009 if(SiS_EModeIDTable661[i].Ext_ModeID == modenumber) {
5010 if(SiS_EModeIDTable661[i].Ext_MyModeID)
5011 return (int)SiS_EModeIDTable661[i].Ext_MyModeID;
5012 else
5013 return modenumber;
5014 }
5015 i++;
5016 } 4239 }
5017#endif
5018 return modenumber;
5019}
5020
5021#endif /* Xfree86 */
5022
5023#ifdef LINUX_KERNEL
5024int
5025sisfb_mode_rate_to_dclock(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
5026 unsigned char modeno, unsigned char rateindex)
5027{
5028 USHORT ModeNo = modeno;
5029 USHORT ModeIdIndex = 0, ClockIndex = 0;
5030 USHORT RefreshRateTableIndex = 0;
5031 int Clock;
5032
5033 if(HwInfo->jChipType < SIS_315H) {
5034#ifdef SIS300
5035 InitTo300Pointer(SiS_Pr, HwInfo);
5036#else
5037 return 65 * 1000;
5038#endif
5039 } else {
5040#ifdef SIS315H
5041 InitTo310Pointer(SiS_Pr, HwInfo);
5042#else
5043 return 65 * 1000;
5044#endif
5045 }
5046
5047 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) {;
5048 printk(KERN_ERR "Could not find mode %x\n", ModeNo);
5049 return 65 * 1000;
5050 }
5051
5052 RefreshRateTableIndex = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
5053 RefreshRateTableIndex += (rateindex - 1);
5054 ClockIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
5055 if(HwInfo->jChipType < SIS_315H) {
5056 ClockIndex &= 0x3F;
5057 }
5058 Clock = SiS_Pr->SiS_VCLKData[ClockIndex].CLOCK * 1000;
5059
5060 return(Clock);
5061}
5062
5063BOOLEAN
5064sisfb_gettotalfrommode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
5065 unsigned char modeno, int *htotal, int *vtotal, unsigned char rateindex)
5066{
5067 USHORT ModeNo = modeno;
5068 USHORT ModeIdIndex = 0, CRT1Index = 0;
5069 USHORT RefreshRateTableIndex = 0;
5070 unsigned char sr_data, cr_data, cr_data2;
5071
5072 if(HwInfo->jChipType < SIS_315H) {
5073#ifdef SIS300
5074 InitTo300Pointer(SiS_Pr, HwInfo);
5075#else
5076 return FALSE;
5077#endif
5078 } else {
5079#ifdef SIS315H
5080 InitTo310Pointer(SiS_Pr, HwInfo);
5081#else
5082 return FALSE;
5083#endif
5084 }
5085
5086 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return FALSE;
5087
5088 RefreshRateTableIndex = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
5089 RefreshRateTableIndex += (rateindex - 1);
5090 CRT1Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
5091
5092 sr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14];
5093 cr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[0];
5094 *htotal = (((cr_data & 0xff) | ((unsigned short) (sr_data & 0x03) << 8)) + 5) * 8;
5095 4240
5096 sr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13];
5097 cr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[6];
5098 cr_data2 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[7];
5099 *vtotal = ((cr_data & 0xFF) |
5100 ((unsigned short)(cr_data2 & 0x01) << 8) |
5101 ((unsigned short)(cr_data2 & 0x20) << 4) |
5102 ((unsigned short)(sr_data & 0x01) << 10)) + 2;
5103
5104 if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag & InterlaceMode)
5105 *vtotal *= 2;
5106
5107 return TRUE;
5108} 4241}
5109 4242
5110int
5111sisfb_mode_rate_to_ddata(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
5112 unsigned char modeno, unsigned char rateindex,
5113 struct fb_var_screeninfo *var)
5114{
5115 USHORT ModeNo = modeno;
5116 USHORT ModeIdIndex = 0, index = 0;
5117 USHORT RefreshRateTableIndex = 0;
5118 unsigned short VRE, VBE, VRS, VBS, VDE, VT;
5119 unsigned short HRE, HBE, HRS, HBS, HDE, HT;
5120 unsigned char sr_data, cr_data, cr_data2, cr_data3;
5121 int A, B, C, D, E, F, temp, j;
5122
5123 if(HwInfo->jChipType < SIS_315H) {
5124#ifdef SIS300
5125 InitTo300Pointer(SiS_Pr, HwInfo);
5126#else
5127 return 0;
5128#endif
5129 } else {
5130#ifdef SIS315H
5131 InitTo310Pointer(SiS_Pr, HwInfo);
5132#else
5133 return 0;
5134#endif
5135 }
5136
5137 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return 0;
5138
5139 RefreshRateTableIndex = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
5140 RefreshRateTableIndex += (rateindex - 1);
5141 index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
5142
5143 sr_data = SiS_Pr->SiS_CRT1Table[index].CR[14];
5144
5145 cr_data = SiS_Pr->SiS_CRT1Table[index].CR[0];
5146
5147 /* Horizontal total */
5148 HT = (cr_data & 0xff) |
5149 ((unsigned short) (sr_data & 0x03) << 8);
5150 A = HT + 5;
5151
5152 cr_data = SiS_Pr->SiS_CRT1Table[index].CR[1];
5153
5154 /* Horizontal display enable end */
5155 HDE = (cr_data & 0xff) |
5156 ((unsigned short) (sr_data & 0x0C) << 6);
5157 E = HDE + 1;
5158
5159 cr_data = SiS_Pr->SiS_CRT1Table[index].CR[4];
5160
5161 /* Horizontal retrace (=sync) start */
5162 HRS = (cr_data & 0xff) |
5163 ((unsigned short) (sr_data & 0xC0) << 2);
5164 F = HRS - E - 3;
5165
5166 cr_data = SiS_Pr->SiS_CRT1Table[index].CR[2];
5167
5168 /* Horizontal blank start */
5169 HBS = (cr_data & 0xff) |
5170 ((unsigned short) (sr_data & 0x30) << 4);
5171
5172 sr_data = SiS_Pr->SiS_CRT1Table[index].CR[15];
5173
5174 cr_data = SiS_Pr->SiS_CRT1Table[index].CR[3];
5175
5176 cr_data2 = SiS_Pr->SiS_CRT1Table[index].CR[5];
5177
5178 /* Horizontal blank end */
5179 HBE = (cr_data & 0x1f) |
5180 ((unsigned short) (cr_data2 & 0x80) >> 2) |
5181 ((unsigned short) (sr_data & 0x03) << 6);
5182
5183 /* Horizontal retrace (=sync) end */
5184 HRE = (cr_data2 & 0x1f) | ((sr_data & 0x04) << 3);
5185 4243
5186 temp = HBE - ((E - 1) & 255);
5187 B = (temp > 0) ? temp : (temp + 256);
5188 4244
5189 temp = HRE - ((E + F + 3) & 63);
5190 C = (temp > 0) ? temp : (temp + 64);
5191
5192 D = B - F - C;
5193
5194 if((SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].XRes == 320) &&
5195 ((SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].YRes == 200) ||
5196 (SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].YRes == 240))) {
5197
5198 /* Terrible hack, but the correct CRTC data for
5199 * these modes only produces a black screen...
5200 */
5201 var->left_margin = (400 - 376);
5202 var->right_margin = (328 - 320);
5203 var->hsync_len = (376 - 328);
5204
5205 } else {
5206
5207 var->left_margin = D * 8;
5208 var->right_margin = F * 8;
5209 var->hsync_len = C * 8;
5210
5211 }
5212
5213 sr_data = SiS_Pr->SiS_CRT1Table[index].CR[13];
5214
5215 cr_data = SiS_Pr->SiS_CRT1Table[index].CR[6];
5216
5217 cr_data2 = SiS_Pr->SiS_CRT1Table[index].CR[7];
5218
5219 /* Vertical total */
5220 VT = (cr_data & 0xFF) |
5221 ((unsigned short) (cr_data2 & 0x01) << 8) |
5222 ((unsigned short)(cr_data2 & 0x20) << 4) |
5223 ((unsigned short) (sr_data & 0x01) << 10);
5224 A = VT + 2;
5225
5226 cr_data = SiS_Pr->SiS_CRT1Table[index].CR[10];
5227
5228 /* Vertical display enable end */
5229 VDE = (cr_data & 0xff) |
5230 ((unsigned short) (cr_data2 & 0x02) << 7) |
5231 ((unsigned short) (cr_data2 & 0x40) << 3) |
5232 ((unsigned short) (sr_data & 0x02) << 9);
5233 E = VDE + 1;
5234
5235 cr_data = SiS_Pr->SiS_CRT1Table[index].CR[8];
5236
5237 /* Vertical retrace (=sync) start */
5238 VRS = (cr_data & 0xff) |
5239 ((unsigned short) (cr_data2 & 0x04) << 6) |
5240 ((unsigned short) (cr_data2 & 0x80) << 2) |
5241 ((unsigned short) (sr_data & 0x08) << 7);
5242 F = VRS + 1 - E;
5243
5244 cr_data = SiS_Pr->SiS_CRT1Table[index].CR[11];
5245
5246 cr_data3 = (SiS_Pr->SiS_CRT1Table[index].CR[16] & 0x01) << 5;
5247
5248 /* Vertical blank start */
5249 VBS = (cr_data & 0xff) |
5250 ((unsigned short) (cr_data2 & 0x08) << 5) |
5251 ((unsigned short) (cr_data3 & 0x20) << 4) |
5252 ((unsigned short) (sr_data & 0x04) << 8);
5253
5254 cr_data = SiS_Pr->SiS_CRT1Table[index].CR[12];
5255
5256 /* Vertical blank end */
5257 VBE = (cr_data & 0xff) |
5258 ((unsigned short) (sr_data & 0x10) << 4);
5259 temp = VBE - ((E - 1) & 511);
5260 B = (temp > 0) ? temp : (temp + 512);
5261
5262 cr_data = SiS_Pr->SiS_CRT1Table[index].CR[9];
5263
5264 /* Vertical retrace (=sync) end */
5265 VRE = (cr_data & 0x0f) | ((sr_data & 0x20) >> 1);
5266 temp = VRE - ((E + F - 1) & 31);
5267 C = (temp > 0) ? temp : (temp + 32);
5268
5269 D = B - F - C;
5270
5271 var->upper_margin = D;
5272 var->lower_margin = F;
5273 var->vsync_len = C;
5274
5275 if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag & 0x8000)
5276 var->sync &= ~FB_SYNC_VERT_HIGH_ACT;
5277 else
5278 var->sync |= FB_SYNC_VERT_HIGH_ACT;
5279
5280 if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag & 0x4000)
5281 var->sync &= ~FB_SYNC_HOR_HIGH_ACT;
5282 else
5283 var->sync |= FB_SYNC_HOR_HIGH_ACT;
5284
5285 var->vmode = FB_VMODE_NONINTERLACED;
5286 if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag & 0x0080)
5287 var->vmode = FB_VMODE_INTERLACED;
5288 else {
5289 j = 0;
5290 while(SiS_Pr->SiS_EModeIDTable[j].Ext_ModeID != 0xff) {
5291 if(SiS_Pr->SiS_EModeIDTable[j].Ext_ModeID ==
5292 SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].ModeID) {
5293 if(SiS_Pr->SiS_EModeIDTable[j].Ext_ModeFlag & DoubleScanMode) {
5294 var->vmode = FB_VMODE_DOUBLE;
5295 }
5296 break;
5297 }
5298 j++;
5299 }
5300 }
5301
5302 if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
5303#if 0 /* Do this? */
5304 var->upper_margin <<= 1;
5305 var->lower_margin <<= 1;
5306 var->vsync_len <<= 1;
5307#endif
5308 } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {
5309 var->upper_margin >>= 1;
5310 var->lower_margin >>= 1;
5311 var->vsync_len >>= 1;
5312 }
5313
5314 return 1;
5315}
5316
5317#endif
5318 4245
diff --git a/drivers/video/sis/init.h b/drivers/video/sis/init.h
index 7e36b7ac14..634c0a9d21 100644
--- a/drivers/video/sis/init.h
+++ b/drivers/video/sis/init.h
@@ -3,7 +3,7 @@
3/* 3/*
4 * Data and prototypes for init.c 4 * Data and prototypes for init.c
5 * 5 *
6 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria 6 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
7 * 7 *
8 * If distributed as part of the Linux kernel, the following license terms 8 * If distributed as part of the Linux kernel, the following license terms
9 * apply: 9 * apply:
@@ -50,18 +50,24 @@
50 * 50 *
51 */ 51 */
52 52
53#ifndef _INIT_ 53#ifndef _INIT_H_
54#define _INIT_ 54#define _INIT_H_
55 55
56#include "osdef.h" 56#include "osdef.h"
57#include "initdef.h" 57#include "initdef.h"
58 58
59#ifdef LINUX_XF86 59#ifdef SIS_XORG_XF86
60#include "sis.h" 60#include "sis.h"
61#define SIS_NEED_inSISREG
62#define SIS_NEED_inSISREGW
63#define SIS_NEED_inSISREGL
64#define SIS_NEED_outSISREG
65#define SIS_NEED_outSISREGW
66#define SIS_NEED_outSISREGL
61#include "sis_regs.h" 67#include "sis_regs.h"
62#endif 68#endif
63 69
64#ifdef LINUX_KERNEL 70#ifdef SIS_LINUX_KERNEL
65#include "vgatypes.h" 71#include "vgatypes.h"
66#include "vstruct.h" 72#include "vstruct.h"
67#ifdef SIS_CP 73#ifdef SIS_CP
@@ -73,6 +79,10 @@
73#include <asm/io.h> 79#include <asm/io.h>
74#include <linux/fb.h> 80#include <linux/fb.h>
75#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 81#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
82#include <video/fbcon.h>
83#endif
84#include "sis.h"
85#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
76#include <linux/sisfb.h> 86#include <linux/sisfb.h>
77#else 87#else
78#include <video/sisfb.h> 88#include <video/sisfb.h>
@@ -80,44 +90,45 @@
80#endif 90#endif
81 91
82/* Mode numbers */ 92/* Mode numbers */
83static const USHORT ModeIndex_320x200[] = {0x59, 0x41, 0x00, 0x4f}; 93static const unsigned short ModeIndex_320x200[] = {0x59, 0x41, 0x00, 0x4f};
84static const USHORT ModeIndex_320x240[] = {0x50, 0x56, 0x00, 0x53}; 94static const unsigned short ModeIndex_320x240[] = {0x50, 0x56, 0x00, 0x53};
85static const USHORT ModeIndex_320x240_FSTN[] = {0x5a, 0x5b, 0x00, 0x00}; /* FSTN */ 95static const unsigned short ModeIndex_320x240_FSTN[] = {0x5a, 0x5b, 0x00, 0x00}; /* FSTN */
86static const USHORT ModeIndex_400x300[] = {0x51, 0x57, 0x00, 0x54}; 96static const unsigned short ModeIndex_400x300[] = {0x51, 0x57, 0x00, 0x54};
87static const USHORT ModeIndex_512x384[] = {0x52, 0x58, 0x00, 0x5c}; 97static const unsigned short ModeIndex_512x384[] = {0x52, 0x58, 0x00, 0x5c};
88static const USHORT ModeIndex_640x400[] = {0x2f, 0x5d, 0x00, 0x5e}; 98static const unsigned short ModeIndex_640x400[] = {0x2f, 0x5d, 0x00, 0x5e};
89static const USHORT ModeIndex_640x480[] = {0x2e, 0x44, 0x00, 0x62}; 99static const unsigned short ModeIndex_640x480[] = {0x2e, 0x44, 0x00, 0x62};
90static const USHORT ModeIndex_720x480[] = {0x31, 0x33, 0x00, 0x35}; 100static const unsigned short ModeIndex_720x480[] = {0x31, 0x33, 0x00, 0x35};
91static const USHORT ModeIndex_720x576[] = {0x32, 0x34, 0x00, 0x36}; 101static const unsigned short ModeIndex_720x576[] = {0x32, 0x34, 0x00, 0x36};
92static const USHORT ModeIndex_768x576[] = {0x5f, 0x60, 0x00, 0x61}; 102static const unsigned short ModeIndex_768x576[] = {0x5f, 0x60, 0x00, 0x61};
93static const USHORT ModeIndex_800x480[] = {0x70, 0x7a, 0x00, 0x76}; 103static const unsigned short ModeIndex_800x480[] = {0x70, 0x7a, 0x00, 0x76};
94static const USHORT ModeIndex_800x600[] = {0x30, 0x47, 0x00, 0x63}; 104static const unsigned short ModeIndex_800x600[] = {0x30, 0x47, 0x00, 0x63};
95static const USHORT ModeIndex_848x480[] = {0x39, 0x3b, 0x00, 0x3e}; 105static const unsigned short ModeIndex_848x480[] = {0x39, 0x3b, 0x00, 0x3e};
96static const USHORT ModeIndex_856x480[] = {0x3f, 0x42, 0x00, 0x45}; 106static const unsigned short ModeIndex_856x480[] = {0x3f, 0x42, 0x00, 0x45};
97static const USHORT ModeIndex_960x540[] = {0x1d, 0x1e, 0x00, 0x1f}; /* 315 series only */ 107static const unsigned short ModeIndex_960x540[] = {0x1d, 0x1e, 0x00, 0x1f}; /* 315 series only */
98static const USHORT ModeIndex_960x600[] = {0x20, 0x21, 0x00, 0x22}; /* 315 series only */ 108static const unsigned short ModeIndex_960x600[] = {0x20, 0x21, 0x00, 0x22}; /* 315 series only */
99static const USHORT ModeIndex_1024x768[] = {0x38, 0x4a, 0x00, 0x64}; 109static const unsigned short ModeIndex_1024x768[] = {0x38, 0x4a, 0x00, 0x64};
100static const USHORT ModeIndex_1024x576[] = {0x71, 0x74, 0x00, 0x77}; 110static const unsigned short ModeIndex_1024x576[] = {0x71, 0x74, 0x00, 0x77};
101static const USHORT ModeIndex_1024x600[] = {0x20, 0x21, 0x00, 0x22}; /* 300 series only */ 111static const unsigned short ModeIndex_1024x600[] = {0x20, 0x21, 0x00, 0x22}; /* 300 series only */
102static const USHORT ModeIndex_1280x1024[] = {0x3a, 0x4d, 0x00, 0x65}; 112static const unsigned short ModeIndex_1280x1024[] = {0x3a, 0x4d, 0x00, 0x65};
103static const USHORT ModeIndex_1280x960[] = {0x7c, 0x7d, 0x00, 0x7e}; 113static const unsigned short ModeIndex_1280x960[] = {0x7c, 0x7d, 0x00, 0x7e};
104static const USHORT ModeIndex_1152x768[] = {0x23, 0x24, 0x00, 0x25}; /* 300 series only */ 114static const unsigned short ModeIndex_1152x768[] = {0x23, 0x24, 0x00, 0x25}; /* 300 series only */
105static const USHORT ModeIndex_1152x864[] = {0x29, 0x2a, 0x00, 0x2b}; 115static const unsigned short ModeIndex_1152x864[] = {0x29, 0x2a, 0x00, 0x2b};
106static const USHORT ModeIndex_300_1280x768[] = {0x55, 0x5a, 0x00, 0x5b}; 116static const unsigned short ModeIndex_300_1280x768[] = {0x55, 0x5a, 0x00, 0x5b};
107static const USHORT ModeIndex_310_1280x768[] = {0x23, 0x24, 0x00, 0x25}; 117static const unsigned short ModeIndex_310_1280x768[] = {0x23, 0x24, 0x00, 0x25};
108static const USHORT ModeIndex_1280x720[] = {0x79, 0x75, 0x00, 0x78}; 118static const unsigned short ModeIndex_1280x720[] = {0x79, 0x75, 0x00, 0x78};
109static const USHORT ModeIndex_1280x800[] = {0x14, 0x15, 0x00, 0x16}; 119static const unsigned short ModeIndex_1280x800[] = {0x14, 0x15, 0x00, 0x16};
110static const USHORT ModeIndex_1360x768[] = {0x48, 0x4b, 0x00, 0x4e}; 120static const unsigned short ModeIndex_1280x854[] = {0x1a, 0x1b, 0x00, 0x1c};
111static const USHORT ModeIndex_300_1360x1024[]= {0x67, 0x6f, 0x00, 0x72}; /* 300 series, BARCO only */ 121static const unsigned short ModeIndex_1360x768[] = {0x48, 0x4b, 0x00, 0x4e};
112static const USHORT ModeIndex_1400x1050[] = {0x26, 0x27, 0x00, 0x28}; /* 315 series only */ 122static const unsigned short ModeIndex_300_1360x1024[]= {0x67, 0x6f, 0x00, 0x72}; /* 300 series, BARCO only */
113static const USHORT ModeIndex_1680x1050[] = {0x17, 0x18, 0x00, 0x19}; /* 315 series only */ 123static const unsigned short ModeIndex_1400x1050[] = {0x26, 0x27, 0x00, 0x28}; /* 315 series only */
114static const USHORT ModeIndex_1600x1200[] = {0x3c, 0x3d, 0x00, 0x66}; 124static const unsigned short ModeIndex_1680x1050[] = {0x17, 0x18, 0x00, 0x19}; /* 315 series only */
115static const USHORT ModeIndex_1920x1080[] = {0x2c, 0x2d, 0x00, 0x73}; /* 315 series only */ 125static const unsigned short ModeIndex_1600x1200[] = {0x3c, 0x3d, 0x00, 0x66};
116static const USHORT ModeIndex_1920x1440[] = {0x68, 0x69, 0x00, 0x6b}; 126static const unsigned short ModeIndex_1920x1080[] = {0x2c, 0x2d, 0x00, 0x73}; /* 315 series only */
117static const USHORT ModeIndex_300_2048x1536[]= {0x6c, 0x6d, 0x00, 0x00}; 127static const unsigned short ModeIndex_1920x1440[] = {0x68, 0x69, 0x00, 0x6b};
118static const USHORT ModeIndex_310_2048x1536[]= {0x6c, 0x6d, 0x00, 0x6e}; 128static const unsigned short ModeIndex_300_2048x1536[]= {0x6c, 0x6d, 0x00, 0x00};
119 129static const unsigned short ModeIndex_310_2048x1536[]= {0x6c, 0x6d, 0x00, 0x6e};
120static const USHORT SiS_DRAMType[17][5]={ 130
131static const unsigned short SiS_DRAMType[17][5]={
121 {0x0C,0x0A,0x02,0x40,0x39}, 132 {0x0C,0x0A,0x02,0x40,0x39},
122 {0x0D,0x0A,0x01,0x40,0x48}, 133 {0x0D,0x0A,0x01,0x40,0x48},
123 {0x0C,0x09,0x02,0x20,0x35}, 134 {0x0C,0x09,0x02,0x20,0x35},
@@ -137,7 +148,7 @@ static const USHORT SiS_DRAMType[17][5]={
137 {0x09,0x08,0x01,0x01,0x00} 148 {0x09,0x08,0x01,0x01,0x00}
138}; 149};
139 150
140static const USHORT SiS_SDRDRAM_TYPE[13][5] = 151static const unsigned short SiS_SDRDRAM_TYPE[13][5] =
141{ 152{
142 { 2,12, 9,64,0x35}, 153 { 2,12, 9,64,0x35},
143 { 1,13, 9,64,0x44}, 154 { 1,13, 9,64,0x44},
@@ -154,7 +165,7 @@ static const USHORT SiS_SDRDRAM_TYPE[13][5] =
154 { 1, 9, 8, 2,0x00} 165 { 1, 9, 8, 2,0x00}
155}; 166};
156 167
157static const USHORT SiS_DDRDRAM_TYPE[4][5] = 168static const unsigned short SiS_DDRDRAM_TYPE[4][5] =
158{ 169{
159 { 2,12, 9,64,0x35}, 170 { 2,12, 9,64,0x35},
160 { 2,12, 8,32,0x31}, 171 { 2,12, 8,32,0x31},
@@ -162,7 +173,7 @@ static const USHORT SiS_DDRDRAM_TYPE[4][5] =
162 { 2, 9, 8, 4,0x01} 173 { 2, 9, 8, 4,0x01}
163}; 174};
164 175
165static const USHORT SiS_MDA_DAC[] = 176static const unsigned char SiS_MDA_DAC[] =
166{ 177{
167 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 178 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
168 0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15, 179 0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,
@@ -174,7 +185,7 @@ static const USHORT SiS_MDA_DAC[] =
174 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F 185 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F
175}; 186};
176 187
177static const USHORT SiS_CGA_DAC[] = 188static const unsigned char SiS_CGA_DAC[] =
178{ 189{
179 0x00,0x10,0x04,0x14,0x01,0x11,0x09,0x15, 190 0x00,0x10,0x04,0x14,0x01,0x11,0x09,0x15,
180 0x00,0x10,0x04,0x14,0x01,0x11,0x09,0x15, 191 0x00,0x10,0x04,0x14,0x01,0x11,0x09,0x15,
@@ -186,7 +197,7 @@ static const USHORT SiS_CGA_DAC[] =
186 0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F 197 0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F
187}; 198};
188 199
189static const USHORT SiS_EGA_DAC[] = 200static const unsigned char SiS_EGA_DAC[] =
190{ 201{
191 0x00,0x10,0x04,0x14,0x01,0x11,0x05,0x15, 202 0x00,0x10,0x04,0x14,0x01,0x11,0x05,0x15,
192 0x20,0x30,0x24,0x34,0x21,0x31,0x25,0x35, 203 0x20,0x30,0x24,0x34,0x21,0x31,0x25,0x35,
@@ -198,7 +209,7 @@ static const USHORT SiS_EGA_DAC[] =
198 0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F 209 0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F
199}; 210};
200 211
201static const USHORT SiS_VGA_DAC[] = 212static const unsigned char SiS_VGA_DAC[] =
202{ 213{
203 0x00,0x10,0x04,0x14,0x01,0x11,0x09,0x15, 214 0x00,0x10,0x04,0x14,0x01,0x11,0x09,0x15,
204 0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F, 215 0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F,
@@ -212,7 +223,31 @@ static const USHORT SiS_VGA_DAC[] =
212 0x0B,0x0C,0x0D,0x0F,0x10 223 0x0B,0x0C,0x0D,0x0F,0x10
213}; 224};
214 225
215static const SiS_StResInfoStruct SiS_StResInfo[]= 226static const struct SiS_St SiS_SModeIDTable[] =
227{
228 {0x01,0x9208,0x01,0x00,0x00,0x00,0x01,0x00,0x40},
229 {0x01,0x1210,0x14,0x01,0x01,0x00,0x01,0x00,0x40},
230 {0x01,0x1010,0x17,0x02,0x02,0x00,0x01,0x01,0x40},
231 {0x03,0x8208,0x03,0x00,0x00,0x00,0x01,0x02,0x40},
232 {0x03,0x0210,0x16,0x01,0x01,0x00,0x01,0x02,0x40},
233 {0x03,0x0010,0x18,0x02,0x02,0x00,0x01,0x03,0x40},
234 {0x05,0x9209,0x05,0x00,0x00,0x00,0x00,0x04,0x40},
235 {0x06,0x8209,0x06,0x00,0x00,0x00,0x00,0x05,0x40},
236 {0x07,0x0000,0x07,0x03,0x03,0x00,0x01,0x03,0x40},
237 {0x07,0x0000,0x19,0x02,0x02,0x00,0x01,0x03,0x40},
238 {0x0d,0x920a,0x0d,0x00,0x00,0x00,0x00,0x04,0x40},
239 {0x0e,0x820a,0x0e,0x00,0x00,0x00,0x00,0x05,0x40},
240 {0x0f,0x0202,0x11,0x01,0x01,0x00,0x00,0x05,0x40},
241 {0x10,0x0212,0x12,0x01,0x01,0x00,0x00,0x05,0x40},
242 {0x11,0x0212,0x1a,0x04,0x04,0x00,0x00,0x05,0x40},
243 {0x12,0x0212,0x1b,0x04,0x04,0x00,0x00,0x05,0x40},
244 {0x13,0x021b,0x1c,0x00,0x00,0x00,0x00,0x04,0x40},
245 {0x12,0x0010,0x18,0x02,0x02,0x00,0x00,0x05,0x40},
246 {0x12,0x0210,0x18,0x01,0x01,0x00,0x00,0x05,0x40},
247 {0xff,0x0000,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
248};
249
250static const struct SiS_StResInfo_S SiS_StResInfo[]=
216{ 251{
217 { 640,400}, 252 { 640,400},
218 { 640,350}, 253 { 640,350},
@@ -221,7 +256,7 @@ static const SiS_StResInfoStruct SiS_StResInfo[]=
221 { 640,480} 256 { 640,480}
222}; 257};
223 258
224static const SiS_ModeResInfoStruct SiS_ModeResInfo[] = 259static const struct SiS_ModeResInfo_S SiS_ModeResInfo[] =
225{ 260{
226 { 320, 200, 8, 8}, /* 0x00 */ 261 { 320, 200, 8, 8}, /* 0x00 */
227 { 320, 240, 8, 8}, /* 0x01 */ 262 { 320, 240, 8, 8}, /* 0x01 */
@@ -256,11 +291,12 @@ static const SiS_ModeResInfoStruct SiS_ModeResInfo[] =
256 { 1280, 800, 8,16}, /* 0x1e */ 291 { 1280, 800, 8,16}, /* 0x1e */
257 { 1920,1080, 8,16}, /* 0x1f */ 292 { 1920,1080, 8,16}, /* 0x1f */
258 { 960, 540, 8,16}, /* 0x20 */ 293 { 960, 540, 8,16}, /* 0x20 */
259 { 960, 600, 8,16} /* 0x21 */ 294 { 960, 600, 8,16}, /* 0x21 */
295 { 1280, 854, 8,16} /* 0x22 */
260}; 296};
261 297
262#if defined(SIS300) || defined(SIS315H) 298#if defined(SIS300) || defined(SIS315H)
263static const SiS_StandTableStruct SiS_StandTable[]= 299static const struct SiS_StandTable_S SiS_StandTable[]=
264{ 300{
265/* 0x00: MD_0_200 */ 301/* 0x00: MD_0_200 */
266 { 302 {
@@ -704,11 +740,11 @@ static const SiS_StandTableStruct SiS_StandTable[]=
704/* SIS VIDEO BRIDGE ----------------------------------------- */ 740/* SIS VIDEO BRIDGE ----------------------------------------- */
705/**************************************************************/ 741/**************************************************************/
706 742
707static const UCHAR SiS_SoftSetting = 0x30; /* RAM setting */ 743static const unsigned char SiS_SoftSetting = 0x30; /* RAM setting */
708 744
709static const UCHAR SiS_OutputSelect = 0x40; 745static const unsigned char SiS_OutputSelect = 0x40;
710 746
711static const UCHAR SiS_NTSCTiming[] = { 747static const unsigned char SiS_NTSCTiming[] = {
712 0x17,0x1d,0x03,0x09,0x05,0x06,0x0c,0x0c, 748 0x17,0x1d,0x03,0x09,0x05,0x06,0x0c,0x0c,
713 0x94,0x49,0x01,0x0a,0x06,0x0d,0x04,0x0a, 749 0x94,0x49,0x01,0x0a,0x06,0x0d,0x04,0x0a,
714 0x06,0x14,0x0d,0x04,0x0a,0x00,0x85,0x1b, 750 0x06,0x14,0x0d,0x04,0x0a,0x00,0x85,0x1b,
@@ -719,7 +755,7 @@ static const UCHAR SiS_NTSCTiming[] = {
719 0x00,0x40,0x44,0x00,0xdb,0x02,0x3b,0x00 755 0x00,0x40,0x44,0x00,0xdb,0x02,0x3b,0x00
720}; 756};
721 757
722static const UCHAR SiS_PALTiming[] = { 758static const unsigned char SiS_PALTiming[] = {
723 0x19,0x52,0x35,0x6e,0x04,0x38,0x3d,0x70, 759 0x19,0x52,0x35,0x6e,0x04,0x38,0x3d,0x70,
724 0x94,0x49,0x01,0x12,0x06,0x3e,0x35,0x6d, 760 0x94,0x49,0x01,0x12,0x06,0x3e,0x35,0x6d,
725 0x06,0x14,0x3e,0x35,0x6d,0x00,0x45,0x2b, 761 0x06,0x14,0x3e,0x35,0x6d,0x00,0x45,0x2b,
@@ -730,8 +766,8 @@ static const UCHAR SiS_PALTiming[] = {
730 0x00,0x40,0x3e,0x00,0xe1,0x02,0x28,0x00 766 0x00,0x40,0x3e,0x00,0xe1,0x02,0x28,0x00
731}; 767};
732 768
733static const UCHAR SiS_HiTVExtTiming[] = { 769static const unsigned char SiS_HiTVExtTiming[] = {
734 0x32,0x65,0x2c,0x5f,0x08,0x31,0x3a,0x64, 770 0x32,0x65,0x2c,0x5f,0x08,0x31,0x3a,0x64,
735 0x28,0x02,0x01,0x3d,0x06,0x3e,0x35,0x6d, 771 0x28,0x02,0x01,0x3d,0x06,0x3e,0x35,0x6d,
736 0x06,0x14,0x3e,0x35,0x6d,0x00,0xc5,0x3f, 772 0x06,0x14,0x3e,0x35,0x6d,0x00,0xc5,0x3f,
737 0x64,0x90,0x33,0x8c,0x18,0x36,0x3e,0x13, 773 0x64,0x90,0x33,0x8c,0x18,0x36,0x3e,0x13,
@@ -741,8 +777,8 @@ static const UCHAR SiS_HiTVExtTiming[] = {
741 0x63,0x4f,0x27,0x00,0xfc,0xff,0x6a,0x00 777 0x63,0x4f,0x27,0x00,0xfc,0xff,0x6a,0x00
742}; 778};
743 779
744static const UCHAR SiS_HiTVSt1Timing[] = { 780static const unsigned char SiS_HiTVSt1Timing[] = {
745 0x32,0x65,0x2c,0x5f,0x08,0x31,0x3a,0x65, 781 0x32,0x65,0x2c,0x5f,0x08,0x31,0x3a,0x65,
746 0x28,0x02,0x01,0x3d,0x06,0x3e,0x35,0x6d, 782 0x28,0x02,0x01,0x3d,0x06,0x3e,0x35,0x6d,
747 0x06,0x14,0x3e,0x35,0x6d,0x00,0xc5,0x3f, 783 0x06,0x14,0x3e,0x35,0x6d,0x00,0xc5,0x3f,
748 0x65,0x90,0x7b,0xa8,0x03,0xf0,0x87,0x03, 784 0x65,0x90,0x7b,0xa8,0x03,0xf0,0x87,0x03,
@@ -752,8 +788,8 @@ static const UCHAR SiS_HiTVSt1Timing[] = {
752 0xaf,0x5d,0x0e,0x00,0xfc,0xff,0x2d,0x00 788 0xaf,0x5d,0x0e,0x00,0xfc,0xff,0x2d,0x00
753}; 789};
754 790
755static const UCHAR SiS_HiTVSt2Timing[] = { 791static const unsigned char SiS_HiTVSt2Timing[] = {
756 0x32,0x65,0x2c,0x5f,0x08,0x31,0x3a,0x64, 792 0x32,0x65,0x2c,0x5f,0x08,0x31,0x3a,0x64,
757 0x28,0x02,0x01,0x3d,0x06,0x3e,0x35,0x6d, 793 0x28,0x02,0x01,0x3d,0x06,0x3e,0x35,0x6d,
758 0x06,0x14,0x3e,0x35,0x6d,0x00,0xc5,0x3f, 794 0x06,0x14,0x3e,0x35,0x6d,0x00,0xc5,0x3f,
759 0x64,0x90,0x33,0x8c,0x18,0x36,0x3e,0x13, 795 0x64,0x90,0x33,0x8c,0x18,0x36,0x3e,0x13,
@@ -764,8 +800,8 @@ static const UCHAR SiS_HiTVSt2Timing[] = {
764}; 800};
765 801
766#if 0 802#if 0
767static const UCHAR SiS_HiTVTextTiming[] = { 803static const unsigned char SiS_HiTVTextTiming[] = {
768 0x32,0x65,0x2c,0x5f,0x08,0x31,0x3a,0x65, 804 0x32,0x65,0x2c,0x5f,0x08,0x31,0x3a,0x65,
769 0x28,0x02,0x01,0x3d,0x06,0x3e,0x35,0x6d, 805 0x28,0x02,0x01,0x3d,0x06,0x3e,0x35,0x6d,
770 0x06,0x14,0x3e,0x35,0x6d,0x00,0xc5,0x3f, 806 0x06,0x14,0x3e,0x35,0x6d,0x00,0xc5,0x3f,
771 0x65,0x90,0xe7,0xbc,0x03,0x0c,0x97,0x03, 807 0x65,0x90,0xe7,0xbc,0x03,0x0c,0x97,0x03,
@@ -776,8 +812,8 @@ static const UCHAR SiS_HiTVTextTiming[] = {
776}; 812};
777#endif 813#endif
778 814
779static const UCHAR SiS_HiTVGroup3Data[] = { 815static const unsigned char SiS_HiTVGroup3Data[] = {
780 0x00,0x1a,0x22,0x63,0x62,0x22,0x08,0x5f, 816 0x00,0x1a,0x22,0x63,0x62,0x22,0x08,0x5f,
781 0x05,0x21,0xb2,0xb2,0x55,0x77,0x2a,0xa6, 817 0x05,0x21,0xb2,0xb2,0x55,0x77,0x2a,0xa6,
782 0x25,0x2f,0x47,0xfa,0xc8,0xff,0x8e,0x20, 818 0x25,0x2f,0x47,0xfa,0xc8,0xff,0x8e,0x20,
783 0x8c,0x6e,0x60,0x2e,0x58,0x48,0x72,0x44, 819 0x8c,0x6e,0x60,0x2e,0x58,0x48,0x72,0x44,
@@ -787,8 +823,8 @@ static const UCHAR SiS_HiTVGroup3Data[] = {
787 0x18,0x05,0x18,0x05,0x4c,0xa8,0x01 823 0x18,0x05,0x18,0x05,0x4c,0xa8,0x01
788}; 824};
789 825
790static const UCHAR SiS_HiTVGroup3Simu[] = { 826static const unsigned char SiS_HiTVGroup3Simu[] = {
791 0x00,0x1a,0x22,0x63,0x62,0x22,0x08,0x95, 827 0x00,0x1a,0x22,0x63,0x62,0x22,0x08,0x95,
792 0xdb,0x20,0xb8,0xb8,0x55,0x47,0x2a,0xa6, 828 0xdb,0x20,0xb8,0xb8,0x55,0x47,0x2a,0xa6,
793 0x25,0x2f,0x47,0xfa,0xc8,0xff,0x8e,0x20, 829 0x25,0x2f,0x47,0xfa,0xc8,0xff,0x8e,0x20,
794 0x8c,0x6e,0x60,0x15,0x26,0xd3,0xe4,0x11, 830 0x8c,0x6e,0x60,0x15,0x26,0xd3,0xe4,0x11,
@@ -799,8 +835,8 @@ static const UCHAR SiS_HiTVGroup3Simu[] = {
799}; 835};
800 836
801#if 0 837#if 0
802static const UCHAR SiS_HiTVGroup3Text[] = { 838static const unsigned char SiS_HiTVGroup3Text[] = {
803 0x00,0x1a,0x22,0x63,0x62,0x22,0x08,0xa7, 839 0x00,0x1a,0x22,0x63,0x62,0x22,0x08,0xa7,
804 0xf5,0x20,0xce,0xce,0x55,0x47,0x2a,0xa6, 840 0xf5,0x20,0xce,0xce,0x55,0x47,0x2a,0xa6,
805 0x25,0x2f,0x47,0xfa,0xc8,0xff,0x8e,0x20, 841 0x25,0x2f,0x47,0xfa,0xc8,0xff,0x8e,0x20,
806 0x8c,0x6e,0x60,0x18,0x2c,0x0c,0x20,0x22, 842 0x8c,0x6e,0x60,0x18,0x2c,0x0c,0x20,0x22,
@@ -811,136 +847,141 @@ static const UCHAR SiS_HiTVGroup3Text[] = {
811}; 847};
812#endif 848#endif
813 849
814static const UCHAR SiS_NTSCPhase[] = {0x21,0xed,0xba,0x08}; 850static const struct SiS_TVData SiS_StPALData[] =
815static const UCHAR SiS_PALPhase[] = {0x2a,0x05,0xe3,0x00};
816static const UCHAR SiS_PALMPhase[] = {0x21,0xE4,0x2E,0x9B};
817static const UCHAR SiS_PALNPhase[] = {0x21,0xF4,0x3E,0xBA};
818static const UCHAR SiS_NTSCPhase2[] = {0x21,0xF0,0x7B,0xD6};
819static const UCHAR SiS_PALPhase2[] = {0x2a,0x09,0x86,0xe9};
820static const UCHAR SiS_PALMPhase2[] = {0x21,0xE6,0xEF,0xA4};
821static const UCHAR SiS_PALNPhase2[] = {0x21,0xF6,0x94,0x46};
822static const UCHAR SiS_SpecialPhase[] = {0x1e,0x8c,0x5c,0x7a};
823static const UCHAR SiS_SpecialPhaseM[]= {0x1e,0x83,0x0a,0xe0};
824static const UCHAR SiS_SpecialPhaseJ[]= {0x25,0xd4,0xfd,0x5e};
825
826static const SiS_TVDataStruct SiS_StPALData[] =
827{ 851{
828 { 1, 1, 864, 525,1270, 400, 100, 0, 760,0xf4,0xff,0x1c,0x22}, 852 { 1, 1, 864, 525,1270, 400, 100, 0, 760, 0,0xf4,0xff,0x1c,0x22},
829 { 1, 1, 864, 525,1270, 350, 100, 0, 760,0xf4,0xff,0x1c,0x22}, 853 { 1, 1, 864, 525,1270, 350, 100, 0, 760, 0,0xf4,0xff,0x1c,0x22},
830 { 1, 1, 864, 525,1270, 400, 0, 0, 720,0xf1,0x04,0x1f,0x18}, 854 { 1, 1, 864, 525,1270, 400, 0, 0, 720, 0,0xf1,0x04,0x1f,0x18},
831 { 1, 1, 864, 525,1270, 350, 0, 0, 720,0xf4,0x0b,0x1c,0x0a}, 855 { 1, 1, 864, 525,1270, 350, 0, 0, 720, 0,0xf4,0x0b,0x1c,0x0a},
832 { 1, 1, 864, 525,1270, 480, 50, 0, 760,0xf4,0xff,0x1c,0x22}, 856 { 1, 1, 864, 525,1270, 480, 50, 0, 760, 0,0xf4,0xff,0x1c,0x22},
833 { 1, 1, 864, 525,1270, 600, 50, 0, 0,0xf4,0xff,0x1c,0x22} 857 { 1, 1, 864, 525,1270, 600, 50, 0, 0,0x300,0xf4,0xff,0x1c,0x22}
834}; 858};
835 859
836static const SiS_TVDataStruct SiS_ExtPALData[] = 860static const struct SiS_TVData SiS_ExtPALData[] =
837{ 861{
838 { 27, 10, 848, 448,1270, 530, 50, 0, 50,0xf4,0xff,0x1c,0x22}, /* 640x400, 320x200 */ 862 { 27, 10, 848, 448,1270, 530, 50, 0, 50, 0,0xf4,0xff,0x1c,0x22}, /* 640x400, 320x200 */
839 { 108, 35, 848, 398,1270, 530, 50, 0, 50,0xf4,0xff,0x1c,0x22}, 863 { 108, 35, 848, 398,1270, 530, 50, 0, 50, 0,0xf4,0xff,0x1c,0x22},
840 { 12, 5, 954, 448,1270, 530, 50, 0, 50,0xf1,0x04,0x1f,0x18}, 864 { 12, 5, 954, 448,1270, 530, 50, 0, 50, 0,0xf1,0x04,0x1f,0x18},
841 { 9, 4, 960, 463,1644, 438, 50, 0, 50,0xf4,0x0b,0x1c,0x0a}, 865 { 9, 4, 960, 463,1644, 438, 50, 0, 50, 0,0xf4,0x0b,0x1c,0x0a},
842 { 9, 4, 848, 528,1270, 530, 0, 0, 50,0xf5,0xfb,0x1b,0x2a}, /* 640x480, 320x240 */ 866 { 9, 4, 848, 528,1270, 530, 0, 0, 50, 0,0xf5,0xfb,0x1b,0x2a}, /* 640x480, 320x240 */
843/*{ 36, 25,1060, 648,1316, 530, 438, 0, 438,0xeb,0x05,0x25,0x16},*//* 800x600, 400x300 */ 867 { 36, 25,1060, 648,1270, 530, 438, 0, 438, 0,0xeb,0x05,0x25,0x16}, /* 800x600, 400x300 */
844 { 36, 25,1060, 648,1270, 530, 438, 0, 438,0xeb,0x05,0x25,0x16}, /* 800x600, 400x300 - better */ 868 { 3, 2,1080, 619,1270, 540, 438, 0, 438, 0,0xf3,0x00,0x1d,0x20}, /* 720x576 */
845 { 3, 2,1080, 619,1270, 540, 438, 0, 438,0xf3,0x00,0x1d,0x20}, /* 720x576 */ 869 { 1, 1,1170, 821,1270, 520, 686, 0, 686, 0,0xF3,0x00,0x1D,0x20}, /* 1024x768 */
846 { 1, 1,1170, 821,1270, 520, 686, 0, 686,0xF3,0x00,0x1D,0x20}, /* 1024x768 */ 870 { 1, 1,1170, 821,1270, 520, 686, 0, 686, 0,0xF3,0x00,0x1D,0x20}, /* 1024x768 (for NTSC equ) */
847 { 1, 1,1170, 821,1270, 520, 686, 0, 686,0xF3,0x00,0x1D,0x20}, /* 1024x768 (for NTSC equ) */ 871 { 9, 4, 848, 528,1270, 530, 0, 0, 50, 0,0xf5,0xfb,0x1b,0x2a} /* 720x480 */
848 { 9, 4, 848, 528,1270, 530, 0, 0, 50,0xf5,0xfb,0x1b,0x2a} /* 720x480 test */
849}; 872};
850 873
851static const SiS_TVDataStruct SiS_StNTSCData[] = 874static const struct SiS_TVData SiS_StNTSCData[] =
852{ 875{
853 { 1, 1, 858, 525,1270, 400, 50, 0, 760,0xf1,0x04,0x1f,0x18}, 876 { 1, 1, 858, 525,1270, 400, 50, 0, 760, 0,0xf1,0x04,0x1f,0x18},
854 { 1, 1, 858, 525,1270, 350, 50, 0, 640,0xf1,0x04,0x1f,0x18}, 877 { 1, 1, 858, 525,1270, 350, 50, 0, 640, 0,0xf1,0x04,0x1f,0x18},
855 { 1, 1, 858, 525,1270, 400, 0, 0, 720,0xf1,0x04,0x1f,0x18}, 878 { 1, 1, 858, 525,1270, 400, 0, 0, 720, 0,0xf1,0x04,0x1f,0x18},
856 { 1, 1, 858, 525,1270, 350, 0, 0, 720,0xf4,0x0b,0x1c,0x0a}, 879 { 1, 1, 858, 525,1270, 350, 0, 0, 720, 0,0xf4,0x0b,0x1c,0x0a},
857 { 1, 1, 858, 525,1270, 480, 0, 0, 760,0xf1,0x04,0x1f,0x18} 880 { 1, 1, 858, 525,1270, 480, 0, 0, 760, 0,0xf1,0x04,0x1f,0x18}
858}; 881};
859 882
860static const SiS_TVDataStruct SiS_ExtNTSCData[] = 883static const struct SiS_TVData SiS_ExtNTSCData[] =
861{ 884{
862 { 143, 65, 858, 443,1270, 440, 171, 0, 171,0xf1,0x04,0x1f,0x18}, /* 640x400, 320x200 */ 885 { 143, 65, 858, 443,1270, 440, 171, 0, 171, 0,0xf1,0x04,0x1f,0x18}, /* 640x400, 320x200 */
863 { 88, 35, 858, 393,1270, 440, 171, 0, 171,0xf1,0x04,0x1f,0x18}, 886 { 88, 35, 858, 393,1270, 440, 171, 0, 171, 0,0xf1,0x04,0x1f,0x18},
864 { 143, 70, 924, 443,1270, 440, 92, 0, 92,0xf1,0x04,0x1f,0x18}, 887 { 143, 70, 924, 443,1270, 440, 92, 0, 92, 0,0xf1,0x04,0x1f,0x18},
865 { 143, 70, 924, 393,1270, 440, 92, 0, 92,0xf4,0x0b,0x1c,0x0a}, 888 { 143, 70, 924, 393,1270, 440, 92, 0, 92, 0,0xf4,0x0b,0x1c,0x0a},
866 { 143, 76, 836, 523,1270, 440, 224, 0, 0,0xf1,0x05,0x1f,0x16}, /* 640x480, 320x240 */ 889 { 143, 76, 836, 523,1270, 440, 224, 0, 0, 0,0xf1,0x05,0x1f,0x16}, /* 640x480, 320x240 */
867 { 143, 120,1056, 643,1270, 440, 0, 128, 0,0xf4,0x10,0x1c,0x00}, /* 800x600, 400x300 */ 890 { 143, 120,1056, 643,1270, 440, 0, 1, 0, 0,0xf4,0x10,0x1c,0x00}, /* 800x600, 400x300 */
868/*{ 2, 1, 858, 503,1270, 480, 0, 128, 0,0xee,0x0c,0x22,0x08},*/ /* 720x480 (old, from 650) */ 891 { 143, 76, 836, 523,1270, 440, 0, 1, 0, 0,0xee,0x0c,0x22,0x08}, /* 720x480 - BETTER (from 300 series) */
869 { 143, 76, 836, 523,1270, 440, 0, 128, 0,0xee,0x0c,0x22,0x08}, /* 720x480 - BETTER (from 300 series) */ 892 { 1, 1,1100, 811,1412, 440, 0, 1, 0, 0,0xee,0x0c,0x22,0x08}, /* 1024x768 (525i) CORRECTED */
870/*{ 65, 64,1056, 791,1270, 480, 638, 0, 0,0xEE,0x0C,0x22,0x08} */ /* 1024x768 (525i) */ 893#if 0 /* flimmert und ist unten abgeschnitten (NTSCHT, NTSC clock) */
871 { 1, 1,1100, 811,1412, 440, 0, 128, 0,0xee,0x0c,0x22,0x08}, /* 1024x768 (525i) CORRECTED */ 894 { 65, 64,1056, 791,1270, 480, 455, 0, 0, 0,0x00,0x00,0x00,0x00} /* 1024x768 (525p) */
872 { 65, 64,1056, 791,1270, 480, 455, 0, 0,0x00,0x00,0x00,0x00} /* 1024x768 (525p) */ 895#endif
896#if 0
897 { 1, 1,1100, 811,1412, 440, 0, 1, 0, 0,0x00,0x00,0x00,0x00} /* 1024x768 (525p) */
898#endif
899#if 0
900 { 1, 1,1120, 821,1516, 420, 0, 1, 0, 0,0x00,0x00,0x00,0x00} /* 1024x768 (525p) */
901#endif
902#if 0
903 { 1, 1, 938, 821,1516, 420, 0, 1, 0, 0,0x00,0x00,0x00,0x00} /* 1024x768 (525p) */
904#endif
905#if 0 /* zoom hin, unten abgeschnitten (NTSC2HT, NTSC1024 clock) */
906 { 1, 1,1072, 791,1270, 480, 455, 0, 0, 0,0x00,0x00,0x00,0x00} /* 1024x768 (525p) */
907#endif
908#if 1 /* zu weit links (squeezed) (NTSC2HT, NTSC1024 clock) */
909 { 1, 1,1100, 846,1270, 440, 455, 0, 0, 0,0x00,0x00,0x00,0x00} /* 1024x768 (525p) */
910#endif
911#if 0 /* zu weit links, rechts abgeschnitten (NTSC2HT, NTSC1024 clock) */
912 { 1, 1,1100, 846,1412, 440, 455, 0, 0, 0,0x00,0x00,0x00,0x00} /* 1024x768 (525p) */
913#endif
873}; 914};
874 915
875static const SiS_TVDataStruct SiS_StHiTVData[] = /* Slave + TVSimu */ 916static const struct SiS_TVData SiS_StHiTVData[] = /* Slave + TVSimu */
876{ 917{
877 { 1, 1, 0x37c,0x233,0x2b2,0x320, 0, 0, 0, 0x00,0x00,0x00,0x00}, 918 { 1, 1, 0x37c,0x233,0x2b2,0x320, 0, 0, 0, 0, 0, 0, 0, 0},
878 { 1, 1, 0x37c,0x233,0x2b2,0x2bc, 0, 0, 0, 0x00,0x00,0x00,0x00}, 919 { 1, 1, 0x37c,0x233,0x2b2,0x2bc, 0, 0, 0, 0, 0, 0, 0, 0},
879 { 1, 1, 0x37c,0x233,0x2b2,0x320, 0, 0, 0, 0x00,0x00,0x00,0x00}, 920 { 1, 1, 0x37c,0x233,0x2b2,0x320, 0, 0, 0, 0, 0, 0, 0, 0},
880 { 1, 1, 0x37c,0x233,0x2b2,0x2bc, 0, 0, 0, 0x00,0x00,0x00,0x00}, 921 { 1, 1, 0x37c,0x233,0x2b2,0x2bc, 0, 0, 0, 0, 0, 0, 0, 0},
881 { 1, 1, 0x37c,0x233,0x2b2,0x3c0, 0, 0, 0, 0x00,0x00,0x00,0x00}, 922 { 1, 1, 0x37c,0x233,0x2b2,0x3c0, 0, 0, 0, 0, 0, 0, 0, 0},
882 { 8, 5, 0x41a,0x2ab,0x670,0x3c0,0x150,128, 0, 0x00,0x00,0x00,0x00} 923 { 8, 5, 0x41a,0x2ab,0x670,0x3c0,0x150, 1, 0, 0, 0, 0, 0, 0}
883}; 924};
884 925
885static const SiS_TVDataStruct SiS_St2HiTVData[] = /* Slave */ 926static const struct SiS_TVData SiS_St2HiTVData[] = /* Slave */
886{ 927{
887 { 3, 1, 0x348,0x1e3,0x670,0x3c0,0x032, 0, 0, 0x00,0x00,0x00,0x00}, 928 { 3, 1, 0x348,0x1e3,0x670,0x3c0,0x032, 0, 0, 0, 0, 0, 0, 0},
888 { 1, 1, 0x37c,0x233,0x2b2,0x2bc, 0, 0, 0, 0x00,0x00,0x00,0x00}, 929 { 1, 1, 0x37c,0x233,0x2b2,0x2bc, 0, 0, 0, 0, 0, 0, 0, 0},
889 { 3, 1, 0x348,0x1e3,0x670,0x3c0,0x032, 0, 0, 0x00,0x00,0x00,0x00}, 930 { 3, 1, 0x348,0x1e3,0x670,0x3c0,0x032, 0, 0, 0, 0, 0, 0, 0},
890 { 1, 1, 0x37c,0x233,0x2b2,0x2bc, 0, 0, 0, 0x00,0x00,0x00,0x00}, 931 { 1, 1, 0x37c,0x233,0x2b2,0x2bc, 0, 0, 0, 0, 0, 0, 0, 0},
891 { 5, 2, 0x348,0x233,0x670,0x3c0,0x08d,128, 0, 0x00,0x00,0x00,0x00}, 932 { 5, 2, 0x348,0x233,0x670,0x3c0,0x08d, 1, 0, 0, 0, 0, 0, 0},
892 { 8, 5, 0x41a,0x2ab,0x670,0x3c0,0x17c,128, 0, 0x00,0x00,0x00,0x00} 933 { 8, 5, 0x41a,0x2ab,0x670,0x3c0,0x17c, 1, 0, 0, 0, 0, 0, 0}
893}; 934};
894 935
895static const SiS_TVDataStruct SiS_ExtHiTVData[] = 936static const struct SiS_TVData SiS_ExtHiTVData[] =
896{ 937{ /* all ok */
897 { 6, 1, 0x348,0x233,0x660,0x3c0, 0, 0, 0, 0x00,0x00,0x00,0x00}, 938 { 6, 1, 0x348,0x233,0x660,0x3c0, 0, 0, 0, 0, 0, 0, 0, 0},
898 { 3, 1, 0x3c0,0x233,0x660,0x3c0, 0, 0, 0, 0x00,0x00,0x00,0x00}, 939 { 3, 1, 0x3c0,0x233,0x660,0x3c0, 0, 0, 0, 0, 0, 0, 0, 0},
899 { 6, 1, 0x348,0x233,0x660,0x3c0, 0, 0, 0, 0x00,0x00,0x00,0x00}, 940 { 6, 1, 0x348,0x233,0x660,0x3c0, 0, 0, 0, 0, 0, 0, 0, 0},
900 { 3, 1, 0x3c0,0x233,0x660,0x3c0, 0, 0, 0, 0x00,0x00,0x00,0x00}, 941 { 3, 1, 0x3c0,0x233,0x660,0x3c0, 0, 0, 0, 0, 0, 0, 0, 0},
901 { 5, 1, 0x348,0x233,0x670,0x3c0,0x166,128, 0, 0x00,0x00,0x00,0x00}, /* 640x480 */ 942 { 5, 1, 0x348,0x233,0x670,0x3c0,0x166, 1, 0, 0, 0, 0, 0, 0}, /* 640x480 */
902 { 16, 5, 0x41a,0x2ab,0x670,0x3c0,0x143,128, 0, 0x00,0x00,0x00,0x00}, /* 800x600 */ 943 { 16, 5, 0x41a,0x2ab,0x670,0x3c0,0x143, 1, 0, 0, 0, 0, 0, 0}, /* 800x600 */
903 { 25, 12, 0x4ec,0x353,0x670,0x3c0,0x032, 0, 0, 0x00,0x00,0x00,0x00}, /* 1024x768 */ 944 { 25, 12, 0x4ec,0x353,0x670,0x3c0,0x032, 0, 0, 0, 0, 0, 0, 0}, /* 1024x768 */
904 { 5, 4, 0x627,0x464,0x670,0x3c0,0x128, 0, 0, 0x00,0x00,0x00,0x00}, /* 1280x1024 */ 945 { 5, 4, 0x627,0x464,0x670,0x3c0,0x128, 0, 0, 0, 0, 0, 0, 0}, /* 1280x1024 */
905 { 4, 1, 0x41a,0x233,0x60c,0x3c0,0x143,128, 0, 0x00,0x00,0x00,0x00}, /* 800x480 */ 946 { 4, 1, 0x41a,0x233,0x60c,0x3c0,0x143, 1, 0, 0, 0, 0, 0, 0}, /* 800x480 */
906 { 5, 2, 0x578,0x293,0x670,0x3c0,0x032, 0, 0, 0x00,0x00,0x00,0x00}, /* 1024x576 */ 947 { 5, 2, 0x578,0x293,0x670,0x3c0,0x032, 0, 0, 0, 0, 0, 0, 0}, /* 1024x576 */
907 { 8, 5, 0x6d6,0x323,0x670,0x3c0,0x128, 0, 0, 0x00,0x00,0x00,0x00}, /* 1280x720 */ 948 { 8, 5, 0x6d6,0x323,0x670,0x3c0,0x128, 0, 0, 0, 0, 0, 0, 0}, /* 1280x720 */
908 { 137, 32, 0x3d4,0x233,0x663,0x3bf,0x143, 0, 0, 0x00,0x00,0x00,0x00} /* 960x600 */ 949 { 8, 3, 0x4ec,0x353,0x670,0x3c0,0x032, 0, 0, 0, 0, 0, 0, 0}, /* 960x600 */
909}; 950};
910 951
911static const SiS_TVDataStruct SiS_St525pData[] = 952static const struct SiS_TVData SiS_St525pData[] =
912{ 953{
913 { 1, 1, 0x6b4,0x20d,0x4f6,0x190, 50, 0, 0x2f8, 0x00,0x00,0x00,0x00}, 954 { 1, 1, 0x6b4,0x20d,0x4f6,0x190, 50, 0, 0x2f8, 0, 0, 0, 0, 0},
914 { 1, 1, 0x6b4,0x20d,0x4f6,0x15e, 50, 0, 0x280, 0x00,0x00,0x00,0x00}, 955 { 1, 1, 0x6b4,0x20d,0x4f6,0x15e, 50, 0, 0x280, 0, 0, 0, 0, 0},
915 { 1, 1, 0x6b4,0x20d,0x4f6,0x190, 50, 0, 0x2f8, 0x00,0x00,0x00,0x00}, 956 { 1, 1, 0x6b4,0x20d,0x4f6,0x190, 50, 0, 0x2f8, 0, 0, 0, 0, 0},
916 { 1, 1, 0x6b4,0x20d,0x4f6,0x15e, 50, 0, 0x280, 0x00,0x00,0x00,0x00}, 957 { 1, 1, 0x6b4,0x20d,0x4f6,0x15e, 50, 0, 0x280, 0, 0, 0, 0, 0},
917 { 1, 1, 0x6b4,0x20d,0x4f6,0x1e0, 0, 0, 0x2f8, 0x00,0x00,0x00,0x00} 958 { 1, 1, 0x6b4,0x20d,0x4f6,0x1e0, 0, 0, 0x2f8, 0, 0, 0, 0, 0}
918}; 959};
919 960
920static const SiS_TVDataStruct SiS_St750pData[] = 961static const struct SiS_TVData SiS_St750pData[] =
921{ 962{
922 { 1, 1, 0x672,0x2ee,0x500,0x190, 50, 0, 0x2f8, 0x00,0x00,0x00,0x00}, 963 { 1, 1, 0x672,0x2ee,0x500,0x190, 50, 0, 0x2f8, 0, 0, 0, 0, 0},
923 { 1, 1, 0x672,0x2ee,0x500,0x15e, 50, 0, 0x280, 0x00,0x00,0x00,0x00}, 964 { 1, 1, 0x672,0x2ee,0x500,0x15e, 50, 0, 0x280, 0, 0, 0, 0, 0},
924 { 1, 1, 0x672,0x2ee,0x500,0x190, 0, 0, 0x2d0, 0x00,0x00,0x00,0x00}, 965 { 1, 1, 0x672,0x2ee,0x500,0x190, 0, 0, 0x2d0, 0, 0, 0, 0, 0},
925 { 1, 1, 0x672,0x2ee,0x500,0x15e, 0, 0, 0x2d0, 0x00,0x00,0x00,0x00}, 966 { 1, 1, 0x672,0x2ee,0x500,0x15e, 0, 0, 0x2d0, 0, 0, 0, 0, 0},
926 { 1, 1, 0x672,0x2ee,0x500,0x1e0, 0, 0, 0x2f8, 0x00,0x00,0x00,0x00} 967 { 1, 1, 0x672,0x2ee,0x500,0x1e0, 0, 0, 0x2f8, 0, 0, 0, 0, 0}
927}; 968};
928 969
929static const SiS_TVDataStruct SiS_Ext750pData[] = 970static const struct SiS_TVData SiS_Ext750pData[] =
930{ 971{ /* all ok */
931 { 143, 65, 0x35a,0x1bb,0x4f6,0x1b8,0x0ab, 0, 0x0ab, 0x00,0x00,0x00,0x00}, 972 { 3, 1, 935, 470, 1130, 680, 50, 0, 0, 0, 0, 0, 0, 0}, /* 320x200/640x400 */
932 { 88, 35, 0x35a,0x189,0x4f6,0x1b8,0x0ab, 0, 0x0ab, 0x00,0x00,0x00,0x00}, 973 { 24, 7, 935, 420, 1130, 680, 50, 0, 0, 0, 0, 0, 0, 0},
933 { 18, 5, 0x339,0x1ae,0x500,0x2d0,0x05c, 0, 0x05c, 0x00,0x00,0x00,0x00}, 974 { 3, 1, 935, 470, 1130, 680, 50, 0, 0, 0, 0, 0, 0, 0},
934 { 143, 70, 0x39c,0x189,0x4f6,0x1b8,0x05c, 0, 0x05c, 0x00,0x00,0x00,0x00}, 975 { 24, 7, 935, 420, 1130, 680, 50, 0, 0, 0, 0, 0, 0, 0},
935 { 99, 32, 0x320,0x1fe,0x500,0x2d0, 50, 0, 0, 0x00,0x00,0x00,0x00}, /* 640x480 */ 976 { 2, 1, 1100, 590, 1130, 640, 50, 0, 0, 0, 0, 0, 0, 0}, /* 640x480 */
936 { 5, 4, 0x5d8,0x29e,0x500,0x2a8, 50, 0, 0, 0x00,0x00,0x00,0x00}, /* 800x600 */ 977 { 3, 2, 1210, 690, 1130, 660, 50, 0, 0, 0, 0, 0, 0, 0}, /* 800x600 OK */
937 { 99, 32, 0x320,0x1fe,0x500,0x2d0, 50, 0, 0, 0x00,0x00,0x00,0x00}, /* 720x480 test WORKS */ 978 { 2, 1, 1100, 562, 1130, 640, 0, 1, 0, 0, 0, 0, 0, 0}, /* 720x480 OK */
938 { 68, 64, 0x55f,0x346,0x500,0x2a8,0x27e, 0, 0, 0x00,0x00,0x00,0x00}, /* 1024x768 */ 979 { 1, 1, 1375, 878, 1130, 640, 638, 0, 0, 0, 0, 0, 0, 0}, /* 1024x768 OK */
939 { 5, 2, 0x3a7,0x226,0x500,0x2a8, 0,128, 0, 0x00,0x00,0x00,0x00}, /* 720x576 */ 980 { 5, 3, 1100, 675, 1130, 640, 0, 1, 0, 0, 0, 0, 0, 0}, /* 720/768x576 OK */
940 { 25, 24, 0x5d8,0x2f3,0x460,0x2a8, 50, 0, 0, 0x00,0x00,0x00,0x00} /* 1280x720 WORKS */ 981 { 25, 24, 1496, 755, 1120, 680, 50, 0, 0, 0, 0, 0, 0, 0} /* 1280x720 OK */
941}; 982};
942 983
943static const SiS_LCDDataStruct SiS_LCD1280x720Data[] = /* 2.03.00 */ 984static const struct SiS_LCDData SiS_LCD1280x720Data[] = /* 2.03.00 */
944{ 985{
945 { 44, 15, 864, 430, 1408, 806 }, /* 640x400 */ 986 { 44, 15, 864, 430, 1408, 806 }, /* 640x400 */
946 { 128, 35, 792, 385, 1408, 806 }, 987 { 128, 35, 792, 385, 1408, 806 },
@@ -962,7 +1003,7 @@ static const SiS_LCDDataStruct SiS_LCD1280x720Data[] = /* 2.03.00 */
962 * (Note: 1280x768_3 is now special for SiS301/NetVista 1003 * (Note: 1280x768_3 is now special for SiS301/NetVista
963 */ 1004 */
964 1005
965static const SiS_LCDDataStruct SiS_StLCD1280x768_2Data[] = /* 2.03.00 */ 1006static const struct SiS_LCDData SiS_StLCD1280x768_2Data[] = /* 2.03.00 */
966{ 1007{
967 { 64, 21, 858, 434, 1408, 806 }, /* 640x400 */ 1008 { 64, 21, 858, 434, 1408, 806 }, /* 640x400 */
968 { 32, 9, 858, 372, 1408, 806 }, 1009 { 32, 9, 858, 372, 1408, 806 },
@@ -977,7 +1018,7 @@ static const SiS_LCDDataStruct SiS_StLCD1280x768_2Data[] = /* 2.03.00 */
977 { 16, 15, 1600, 750, 1600, 806 } /* 1280x720 - from Ext */ 1018 { 16, 15, 1600, 750, 1600, 806 } /* 1280x720 - from Ext */
978}; 1019};
979 1020
980static const SiS_LCDDataStruct SiS_ExtLCD1280x768_2Data[] = /* 2.03.00 */ 1021static const struct SiS_LCDData SiS_ExtLCD1280x768_2Data[] = /* 2.03.00 */
981{ 1022{
982 { 16, 5, 960, 410, 1600, 806 }, /* 640x400 */ 1023 { 16, 5, 960, 410, 1600, 806 }, /* 640x400 */
983 { 64, 21, 1152, 364, 1600, 806 }, 1024 { 64, 21, 1152, 364, 1600, 806 },
@@ -993,7 +1034,7 @@ static const SiS_LCDDataStruct SiS_ExtLCD1280x768_2Data[] = /* 2.03.00 */
993}; 1034};
994 1035
995#if 0 /* Not used; _3 now reserved for NetVista (SiS301) */ 1036#if 0 /* Not used; _3 now reserved for NetVista (SiS301) */
996static const SiS_LCDDataStruct SiS_LCD1280x768_3Data[] = 1037static const struct SiS_LCDData SiS_LCD1280x768_3Data[] =
997{ 1038{
998 { 64, 25, 1056, 422, 1664, 798 }, /* 640x400 */ 1039 { 64, 25, 1056, 422, 1664, 798 }, /* 640x400 */
999 { 128, 39, 884, 396, 1408, 806 }, /* ,640 */ 1040 { 128, 39, 884, 396, 1408, 806 }, /* ,640 */
@@ -1009,7 +1050,7 @@ static const SiS_LCDDataStruct SiS_LCD1280x768_3Data[] =
1009}; 1050};
1010#endif 1051#endif
1011 1052
1012static const SiS_LCDDataStruct SiS_LCD1280x800Data[] = /* 0.93.12a (TMDS) */ 1053static const struct SiS_LCDData SiS_LCD1280x800Data[] = /* 0.93.12a (TMDS) */
1013{ 1054{
1014 { 128, 51, 1122, 412, 1408, 816 }, /* 640x400 */ 1055 { 128, 51, 1122, 412, 1408, 816 }, /* 640x400 */
1015 { 128, 49, 1232, 361, 1408, 816 }, 1056 { 128, 49, 1232, 361, 1408, 816 },
@@ -1024,7 +1065,7 @@ static const SiS_LCDDataStruct SiS_LCD1280x800Data[] = /* 0.93.12a (TMDS) */
1024 { 0, 0, 0, 0, 0, 0 } /* 1280x720 */ 1065 { 0, 0, 0, 0, 0, 0 } /* 1280x720 */
1025}; 1066};
1026 1067
1027static const SiS_LCDDataStruct SiS_LCD1280x800_2Data[] = /* 2.03.00 (LVDS) */ 1068static const struct SiS_LCDData SiS_LCD1280x800_2Data[] = /* 2.03.00 (LVDS) */
1028{ 1069{
1029 { 97, 42, 1344, 409, 1552, 812 }, /* 640x400 */ 1070 { 97, 42, 1344, 409, 1552, 812 }, /* 640x400 */
1030 { 97, 35, 1280, 358, 1552, 812 }, 1071 { 97, 35, 1280, 358, 1552, 812 },
@@ -1039,7 +1080,42 @@ static const SiS_LCDDataStruct SiS_LCD1280x800_2Data[] = /* 2.03.00 (LVDS) */
1039 { 97, 90, 1600, 730, 1552, 812 } /* 1280x720 */ 1080 { 97, 90, 1600, 730, 1552, 812 } /* 1280x720 */
1040}; 1081};
1041 1082
1042static const SiS_LCDDataStruct SiS_LCD1280x960Data[] = 1083#if 0
1084static const struct SiS_LCDData SiS_LCD1280x800_3Data[] = /* 2.02.05a (LVDS); m250 */
1085{
1086 { 128, 51, 1122, 412, 1408, 816 }, /* 640x400 */
1087 { 128, 49, 1232, 361, 1408, 816 },
1088 { 128, 51, 1122, 412, 1408, 816 },
1089 { 128, 49, 1232, 361, 1408, 816 },
1090 { 8, 3, 880, 491, 1408, 816 }, /* 640x480 */
1091 { 11, 6, 1024, 612, 1408, 816 }, /* 800x600 */
1092 { 22, 21, 1400, 784, 1408, 816 }, /* 1024x768 */
1093 { 0, 0, 0, 0, 0, 0 }, /* 1280x1024 */
1094 { 1, 1, 1408, 816, 1408, 816 }, /* 1280x800 */
1095 { 0, 0, 0, 0, 0, 0 }, /* 1280x768 - patch index */
1096 { 0, 0, 0, 0, 0, 0 } /* 1280x720 */
1097};
1098#endif
1099
1100static const struct SiS_LCDData SiS_LCD1280x854Data[] = /* 2.21.00CS (LVDS) */
1101{
1102 { 56, 15, 936, 410, 1664, 861 }, /* 640x400 */
1103 { 64, 25, 1586, 355, 1664, 861 },
1104 { 56, 15, 936, 410, 1664, 861 },
1105 { 64, 25, 1586, 355, 1664, 861 },
1106 { 91, 45, 1464, 485, 1664, 861 }, /* 640x480 */
1107 { 182, 75, 976, 605, 1664, 861 }, /* 800x600 */
1108 { 91, 66, 1342, 774, 1664, 861 }, /* 1024x768 */
1109 { 0, 0, 0, 0, 0, 0 }, /* 1280x1024 */
1110 { 26, 25, 1708, 807, 1664, 861 }, /* 1280x800 */
1111 { 13, 12, 1708, 774, 1664, 861 }, /* 1280x768 - patch index */
1112 { 52, 45, 1708, 725, 1664, 861 }, /* 1280x720 */
1113 { 0, 0, 0, 0, 0, 0 },
1114 { 0, 0, 0, 0, 0, 0 },
1115 { 1, 1, 1664, 861, 1664, 861 } /* 1280x854 */
1116};
1117
1118static const struct SiS_LCDData SiS_LCD1280x960Data[] =
1043{ 1119{
1044 { 9, 2, 800, 500, 1800, 1000 }, 1120 { 9, 2, 800, 500, 1800, 1000 },
1045 { 9, 2, 800, 500, 1800, 1000 }, 1121 { 9, 2, 800, 500, 1800, 1000 },
@@ -1049,10 +1125,15 @@ static const SiS_LCDDataStruct SiS_LCD1280x960Data[] =
1049 { 30, 11, 1056, 625, 1800, 1000 }, 1125 { 30, 11, 1056, 625, 1800, 1000 },
1050 { 5, 3, 1350, 800, 1800, 1000 }, 1126 { 5, 3, 1350, 800, 1800, 1000 },
1051 { 1, 1, 1576, 1050, 1576, 1050 }, 1127 { 1, 1, 1576, 1050, 1576, 1050 },
1052 { 1, 1, 1800, 1000, 1800, 1000 } 1128 { 1, 1, 1800, 1000, 1800, 1000 },
1129 { 0, 0, 0, 0, 0, 0 },
1130 { 0, 0, 0, 0, 0, 0 },
1131 { 0, 0, 0, 0, 0, 0 },
1132 { 0, 0, 0, 0, 0, 0 },
1133 { 0, 0, 0, 0, 0, 0 }
1053}; 1134};
1054 1135
1055static const SiS_LCDDataStruct SiS_StLCD1400x1050Data[] = 1136static const struct SiS_LCDData SiS_StLCD1400x1050Data[] =
1056{ 1137{
1057 { 211, 100, 2100, 408, 1688, 1066 }, 1138 { 211, 100, 2100, 408, 1688, 1066 },
1058 { 211, 64, 1536, 358, 1688, 1066 }, 1139 { 211, 64, 1536, 358, 1688, 1066 },
@@ -1062,10 +1143,15 @@ static const SiS_LCDDataStruct SiS_StLCD1400x1050Data[] =
1062 { 211, 72, 1008, 609, 1688, 1066 }, 1143 { 211, 72, 1008, 609, 1688, 1066 },
1063 { 211, 128, 1400, 776, 1688, 1066 }, 1144 { 211, 128, 1400, 776, 1688, 1066 },
1064 { 211, 205, 1680, 1041, 1688, 1066 }, 1145 { 211, 205, 1680, 1041, 1688, 1066 },
1065 { 1, 1, 1688, 1066, 1688, 1066 } 1146 { 1, 1, 1688, 1066, 1688, 1066 },
1147 { 0, 0, 0, 0, 0, 0 },
1148 { 0, 0, 0, 0, 0, 0 },
1149 { 0, 0, 0, 0, 0, 0 },
1150 { 0, 0, 0, 0, 0, 0 },
1151 { 0, 0, 0, 0, 0, 0 }
1066}; 1152};
1067 1153
1068static const SiS_LCDDataStruct SiS_ExtLCD1400x1050Data[] = 1154static const struct SiS_LCDData SiS_ExtLCD1400x1050Data[] =
1069{ 1155{
1070/* { 211, 60, 1260, 410, 1688, 1066 }, 640x400 (6330) */ 1156/* { 211, 60, 1260, 410, 1688, 1066 }, 640x400 (6330) */
1071 { 211, 100, 2100, 408, 1688, 1066 }, /* 640x400 (6325) WORKS */ 1157 { 211, 100, 2100, 408, 1688, 1066 }, /* 640x400 (6325) WORKS */
@@ -1080,10 +1166,13 @@ static const SiS_LCDDataStruct SiS_ExtLCD1400x1050Data[] =
1080 { 211, 205, 1680, 1041, 1688, 1066 }, /* 1280x1024 - not used (always unscaled) */ 1166 { 211, 205, 1680, 1041, 1688, 1066 }, /* 1280x1024 - not used (always unscaled) */
1081 { 1, 1, 1688, 1066, 1688, 1066 }, /* 1400x1050 */ 1167 { 1, 1, 1688, 1066, 1688, 1066 }, /* 1400x1050 */
1082 { 0, 0, 0, 0, 0, 0 }, /* kludge */ 1168 { 0, 0, 0, 0, 0, 0 }, /* kludge */
1083 { 211, 120, 1400, 730, 1688, 1066 } /* 1280x720 */ 1169 { 211, 120, 1400, 730, 1688, 1066 }, /* 1280x720 */
1170 { 0, 0, 0, 0, 0, 0 },
1171 { 0, 0, 0, 0, 0, 0 },
1172 { 0, 0, 0, 0, 0, 0 }
1084}; 1173};
1085 1174
1086static const SiS_LCDDataStruct SiS_LCD1680x1050Data[] = 1175static const struct SiS_LCDData SiS_LCD1680x1050Data[] =
1087{ 1176{
1088 { 95, 24, 1260, 410, 1900, 1066 }, /* 0 640x400 */ 1177 { 95, 24, 1260, 410, 1900, 1066 }, /* 0 640x400 */
1089 { 10, 3, 1710, 362, 1900, 1066 }, 1178 { 10, 3, 1710, 362, 1900, 1066 },
@@ -1097,10 +1186,11 @@ static const SiS_LCDDataStruct SiS_LCD1680x1050Data[] =
1097 { 95, 69, 1800, 817, 1900, 1066 }, /* 9 1280x800 patch index */ 1186 { 95, 69, 1800, 817, 1900, 1066 }, /* 9 1280x800 patch index */
1098 { 13, 9, 1900, 739, 1900, 1066 }, /* 10 1280x720 */ 1187 { 13, 9, 1900, 739, 1900, 1066 }, /* 10 1280x720 */
1099 { 95, 94, 1880, 1066, 1900, 1066 }, /* 11 1400x1050 patch index */ 1188 { 95, 94, 1880, 1066, 1900, 1066 }, /* 11 1400x1050 patch index */
1100 { 1, 1, 1900, 1066, 1900, 1066 } /* 12 1680x1050 */ 1189 { 1, 1, 1900, 1066, 1900, 1066 }, /* 12 1680x1050 */
1190 { 0, 0, 0, 0, 0, 0 }
1101}; 1191};
1102 1192
1103static const SiS_LCDDataStruct SiS_StLCD1600x1200Data[] = 1193static const struct SiS_LCDData SiS_StLCD1600x1200Data[] =
1104{ 1194{
1105 {27, 4, 800, 500, 2160, 1250 }, 1195 {27, 4, 800, 500, 2160, 1250 },
1106 {27, 4, 800, 500, 2160, 1250 }, 1196 {27, 4, 800, 500, 2160, 1250 },
@@ -1111,10 +1201,14 @@ static const SiS_LCDDataStruct SiS_StLCD1600x1200Data[] =
1111 { 5, 2,1350, 800, 2160, 1250 }, 1201 { 5, 2,1350, 800, 2160, 1250 },
1112 {135,88,1600,1100, 2160, 1250 }, 1202 {135,88,1600,1100, 2160, 1250 },
1113 {72, 49,1680,1092, 2160, 1250 }, 1203 {72, 49,1680,1092, 2160, 1250 },
1114 { 1, 1,2160,1250, 2160, 1250 } 1204 { 1, 1,2160,1250, 2160, 1250 },
1205 { 0, 0, 0, 0, 0, 0 },
1206 { 0, 0, 0, 0, 0, 0 },
1207 { 0, 0, 0, 0, 0, 0 },
1208 { 0, 0, 0, 0, 0, 0 }
1115}; 1209};
1116 1210
1117static const SiS_LCDDataStruct SiS_ExtLCD1600x1200Data[] = 1211static const struct SiS_LCDData SiS_ExtLCD1600x1200Data[] =
1118{ 1212{
1119 {72,11, 990, 422, 2160, 1250 }, /* 640x400 (6330) WORKS */ 1213 {72,11, 990, 422, 2160, 1250 }, /* 640x400 (6330) WORKS */
1120/* {27, 4, 800, 500, 2160, 1250 }, 640x400 (6235) */ 1214/* {27, 4, 800, 500, 2160, 1250 }, 640x400 (6235) */
@@ -1127,10 +1221,14 @@ static const SiS_LCDDataStruct SiS_ExtLCD1600x1200Data[] =
1127 { 5, 2,1350, 800, 2160, 1250 }, 1221 { 5, 2,1350, 800, 2160, 1250 },
1128 {27,16,1500,1064, 2160, 1250 }, /* 1280x1024 */ 1222 {27,16,1500,1064, 2160, 1250 }, /* 1280x1024 */
1129 {72,49,1680,1092, 2160, 1250 }, /* 1400x1050 (6330, was not supported on 6325) */ 1223 {72,49,1680,1092, 2160, 1250 }, /* 1400x1050 (6330, was not supported on 6325) */
1130 { 1, 1,2160,1250, 2160, 1250 } 1224 { 1, 1,2160,1250, 2160, 1250 },
1225 { 0, 0, 0, 0, 0, 0 },
1226 { 0, 0, 0, 0, 0, 0 },
1227 { 0, 0, 0, 0, 0, 0 },
1228 { 0, 0, 0, 0, 0, 0 }
1131}; 1229};
1132 1230
1133static const SiS_LCDDataStruct SiS_NoScaleData[] = 1231static const struct SiS_LCDData SiS_NoScaleData[] =
1134{ 1232{
1135 { 1, 1, 800, 449, 800, 449 }, /* 0x00: 320x200, 640x400 */ 1233 { 1, 1, 800, 449, 800, 449 }, /* 0x00: 320x200, 640x400 */
1136 { 1, 1, 800, 449, 800, 449 }, 1234 { 1, 1, 800, 449, 800, 449 },
@@ -1162,14 +1260,18 @@ static const SiS_LCDDataStruct SiS_NoScaleData[] =
1162 { 1, 1,1808, 808,1808, 808 }, /* 0x1b: 1360x768 */ 1260 { 1, 1,1808, 808,1808, 808 }, /* 0x1b: 1360x768 */
1163 { 1, 1,1104, 563,1104, 563 }, /* 0x1c: 960x540 */ 1261 { 1, 1,1104, 563,1104, 563 }, /* 0x1c: 960x540 */
1164 { 1, 1,1120, 618,1120, 618 }, /* 0x1d: 960x600 */ 1262 { 1, 1,1120, 618,1120, 618 }, /* 0x1d: 960x600 */
1165 { 1, 1,1408, 816,1408, 816 } /* 0x1f: 1280x800 (TMDS special) */ 1263 { 1, 1,1408, 816,1408, 816 }, /* 0x1f: 1280x800 (TMDS special) */
1264 { 1, 1,1760,1235,1760,1235 }, /* 0x20: 1600x1200 for LCDA */
1265 { 1, 1,2048,1320,2048,1320 }, /* 0x21: 1600x1200 for non-SiS LVDS */
1266 { 1, 1,1664, 861,1664, 861 } /* 0x22: 1280x854 */
1166}; 1267};
1167 1268
1168/**************************************************************/ 1269/**************************************************************/
1169/* LVDS ----------------------------------------------------- */ 1270/* LVDS ----------------------------------------------------- */
1170/**************************************************************/ 1271/**************************************************************/
1171 1272
1172static const SiS_LVDSDataStruct SiS_LVDS320x480Data_1[]= 1273/* FSTN/DSTN 320x240, 2 variants */
1274static const struct SiS_LVDSData SiS_LVDS320x240Data_1[]=
1173{ 1275{
1174 { 848, 433, 400, 525}, 1276 { 848, 433, 400, 525},
1175 { 848, 389, 400, 525}, 1277 { 848, 389, 400, 525},
@@ -1177,157 +1279,40 @@ static const SiS_LVDSDataStruct SiS_LVDS320x480Data_1[]=
1177 { 848, 389, 400, 525}, 1279 { 848, 389, 400, 525},
1178 { 848, 518, 400, 525}, 1280 { 848, 518, 400, 525},
1179 {1056, 628, 400, 525}, 1281 {1056, 628, 400, 525},
1180 { 400, 525, 400, 525}, 1282 { 400, 525, 400, 525} /* xSTN */
1181 { 800, 449,1000, 644},
1182 { 800, 525,1000, 635}
1183}; 1283};
1184 1284
1185static const SiS_LVDSDataStruct SiS_LVDS640x480Data_1[]= 1285static const struct SiS_LVDSData SiS_LVDS320x240Data_2[]=
1186{ 1286{
1187 { 800, 445, 800, 525}, /* 800, 449, 800, 449 */ 1287 { 800, 445, 800, 525},
1188 { 800, 395, 800, 525}, 1288 { 800, 395, 800, 525},
1189 { 800, 445, 800, 525}, 1289 { 800, 445, 800, 525},
1190 { 800, 395, 800, 525}, 1290 { 800, 395, 800, 525},
1191 { 800, 525, 800, 525}, 1291 { 800, 525, 800, 525},
1192 { 800, 525, 800, 525}, /* pseudo */ 1292 {1056, 628,1056, 628},
1193 { 800, 525, 800, 525} /* pseudo */ 1293 { 480, 525, 480, 525} /* xSTN */
1194}; 1294};
1195 1295
1196/* FSTN 320x240 */ 1296static const struct SiS_LVDSData SiS_LVDS640x480Data_1[]=
1197static const SiS_LVDSDataStruct SiS_LVDS640x480Data_2[]=
1198{ 1297{
1199 { 800, 445, 800, 525}, 1298 { 800, 445, 800, 525}, /* 800, 449, 800, 449 */
1200 { 800, 395, 800, 525}, 1299 { 800, 395, 800, 525},
1201 { 800, 445, 800, 525}, 1300 { 800, 445, 800, 525},
1202 { 800, 395, 800, 525}, 1301 { 800, 395, 800, 525},
1203 { 800, 525, 800, 525}, 1302 { 800, 525, 800, 525}
1204 { 800, 525, 800, 525}, /* pseudo */
1205 { 800, 525, 800, 525} /* pseudo */
1206}; 1303};
1207 1304
1208static const SiS_LVDSDataStruct SiS_LVDS800x600Data_1[]= 1305static const struct SiS_LVDSData SiS_LVDS800x600Data_1[]=
1209{ 1306{
1210 { 848, 433,1060, 629}, 1307 { 848, 433,1060, 629},
1211 { 848, 389,1060, 629}, 1308 { 848, 389,1060, 629},
1212 { 848, 433,1060, 629}, 1309 { 848, 433,1060, 629},
1213 { 848, 389,1060, 629}, 1310 { 848, 389,1060, 629},
1214 { 848, 518,1060, 629}, 1311 { 848, 518,1060, 629},
1215 {1056, 628,1056, 628},
1216 {1056, 628,1056, 628} 1312 {1056, 628,1056, 628}
1217}; 1313};
1218 1314
1219static const SiS_LVDSDataStruct SiS_LVDS800x600Data_2[]= 1315static const struct SiS_LVDSData SiS_LVDS1024x600Data_1[] =
1220{
1221 {1056, 628,1056, 628}
1222};
1223
1224static const SiS_LVDSDataStruct SiS_LVDS1024x768Data_1[]=
1225{
1226 { 840, 438,1344, 806},
1227 { 840, 409,1344, 806},
1228 { 840, 438,1344, 806},
1229 { 840, 409,1344, 806},
1230 { 840, 518,1344, 806}, /* 640x480 */
1231 {1050, 638,1344, 806}, /* 800x600 */
1232 {1344, 806,1344, 806}, /* 1024x768 */
1233};
1234
1235static const SiS_LVDSDataStruct SiS_LVDS1024x768Data_2[]=
1236{
1237 {1344, 806,1344, 806}
1238};
1239
1240static const SiS_LVDSDataStruct SiS_LVDS1280x1024Data_1[]=
1241{
1242 {1048, 442,1688,1066},
1243 {1048, 392,1688,1066},
1244 {1048, 442,1688,1066},
1245 {1048, 392,1688,1066},
1246 {1048, 522,1688,1066},
1247 {1208, 642,1688,1066},
1248 {1432, 810,1688,1066},
1249 {1688,1066,1688,1066}
1250};
1251
1252static const SiS_LVDSDataStruct SiS_LVDS1280x1024Data_2[]=
1253{
1254 {1688,1066,1688,1066}
1255};
1256
1257static const SiS_LVDSDataStruct SiS_LVDS1400x1050Data_1[]=
1258{
1259 { 928, 416, 1688,1066},
1260 { 928, 366, 1688,1066},
1261 { 928, 416, 1688,1066},
1262 { 928, 366, 1688,1066},
1263 { 928, 496, 1688,1066},
1264 {1088, 616, 1688,1066},
1265 {1312, 784, 1688,1066},
1266 {1568,1040, 1688,1066},
1267 {1688,1066, 1688,1066}
1268};
1269
1270static const SiS_LVDSDataStruct SiS_LVDS1400x1050Data_2[]=
1271{
1272 {1688,1066, 1688,1066}
1273};
1274
1275static const SiS_LVDSDataStruct SiS_LVDS1600x1200Data_1[]=
1276{
1277 {1088, 520, 2048,1320},
1278 {1088, 470, 2048,1320},
1279 {1088, 520, 2048,1320},
1280 {1088, 470, 2048,1320},
1281 {1088, 600, 2048,1320},
1282 {1248, 720, 2048,1320},
1283 {1472, 888, 2048,1320},
1284 {1728,1144, 2048,1320},
1285 {1848,1170, 2048,1320},
1286 {2048,1320, 2048,1320}
1287};
1288
1289static const SiS_LVDSDataStruct SiS_LVDS1600x1200Data_2[]=
1290{
1291 {2048,1320, 2048,1320}
1292};
1293
1294static const SiS_LVDSDataStruct SiS_LVDS1280x960Data_1[]=
1295{
1296 { 840, 438,1344, 806},
1297 { 840, 409,1344, 806},
1298 { 840, 438,1344, 806},
1299 { 840, 409,1344, 806},
1300 { 840, 518,1344, 806},
1301 {1050, 638,1344, 806},
1302 {1344, 806,1344, 806},
1303 { 800, 449,1280, 801},
1304 { 800, 525,1280, 813}
1305};
1306
1307static const SiS_LVDSDataStruct SiS_LVDS1280x960Data_2[]=
1308{
1309 {1344, 806,1344, 806}
1310};
1311
1312static const SiS_LVDSDataStruct SiS_LVDS1280x768Data_1[]=
1313{
1314 { 768, 438, 1408, 806},
1315 { 768, 388, 1408, 806},
1316 { 768, 438, 1408, 806},
1317 { 768, 388, 1408, 806},
1318 { 768, 518, 1408, 806},
1319 { 928, 638, 1408, 806},
1320 {1152, 806, 1408, 806},
1321 {1408, 806, 1408, 806},
1322 {1408, 806, 1408, 806}
1323};
1324
1325static const SiS_LVDSDataStruct SiS_LVDS1280x768Data_2[]=
1326{
1327 {1408, 806, 1408, 806}
1328};
1329
1330static const SiS_LVDSDataStruct SiS_LVDS1024x600Data_1[] =
1331{ 1316{
1332 { 840, 604,1344, 800}, 1317 { 840, 604,1344, 800},
1333 { 840, 560,1344, 800}, 1318 { 840, 560,1344, 800},
@@ -1338,124 +1323,18 @@ static const SiS_LVDSDataStruct SiS_LVDS1024x600Data_1[] =
1338 {1344, 800,1344, 800} 1323 {1344, 800,1344, 800}
1339}; 1324};
1340 1325
1341static const SiS_LVDSDataStruct SiS_LVDS1024x600Data_2[] = 1326static const struct SiS_LVDSData SiS_LVDS1024x768Data_1[]=
1342{
1343 {1344, 800,1344, 800}
1344};
1345
1346static const SiS_LVDSDataStruct SiS_LVDS1152x768Data_1[] =
1347{ 1327{
1348 { 840, 438,1344, 806}, 1328 { 840, 438,1344, 806},
1349 { 840, 409,1344, 806}, 1329 { 840, 409,1344, 806},
1350 { 840, 438,1344, 806}, 1330 { 840, 438,1344, 806},
1351 { 840, 409,1344, 806}, 1331 { 840, 409,1344, 806},
1352 { 840, 518,1344, 806}, 1332 { 840, 518,1344, 806}, /* 640x480 */
1353 {1050, 638,1344, 806},
1354 {1344, 806,1344, 806}
1355};
1356
1357static const SiS_LVDSDataStruct SiS_LVDS1152x768Data_2[] =
1358{
1359 {1344, 806,1344, 806}
1360};
1361
1362/* Pass 1:1 data */
1363static const SiS_LVDSDataStruct SiS_LVDSXXXxXXXData_1[]=
1364{
1365 { 800, 449, 800, 449},
1366 { 800, 449, 800, 449},
1367 { 900, 449, 900, 449},
1368 { 900, 449, 900, 449},
1369 { 800, 525, 800, 525}, /* 640x480 */
1370 {1056, 628, 1056, 628}, /* 800x600 */
1371 {1344, 806, 1344, 806}, /* 1024x768 */
1372 {1688,1066, 1688,1066}, /* 1280x1024 */ /* INSERTED */
1373 {1688, 806, 1688, 806}, /* 1280x768 */
1374};
1375
1376/* Custom data for Barco iQ R series */
1377static const SiS_LVDSDataStruct SiS_LVDSBARCO1366Data_1[]=
1378{
1379 { 832, 438,1331, 806},
1380 { 832, 388,1331, 806},
1381 { 832, 438,1331, 806},
1382 { 832, 388,1331, 806},
1383 { 832, 518,1331, 806},
1384 {1050, 638,1344, 806},
1385 {1344, 806,1344, 806},
1386 {1688,1066,1688,1066},
1387 {1688,1066,1688,1066} /* 1360x1024 */
1388};
1389
1390/* Custom data for Barco iQ R series */
1391static const SiS_LVDSDataStruct SiS_LVDSBARCO1366Data_2[]=
1392{
1393 {1344, 806,1344, 806},
1394 {1344, 806,1344, 806},
1395 {1344, 806,1344, 806},
1396 {1344, 806,1344, 806},
1397 {1344, 806,1344, 806},
1398 {1344, 806,1344, 806},
1399 {1344, 806,1344, 806},
1400 {1688,1066,1688,1066},
1401 {1688,1066,1688,1066} /* 1360x1024 */
1402};
1403
1404/* Custom data for Barco iQ G series */
1405static const SiS_LVDSDataStruct SiS_LVDSBARCO1024Data_1[]=
1406{
1407 { 832, 438,1331, 806},
1408 { 832, 409,1331, 806},
1409 { 832, 438,1331, 806},
1410 { 832, 409,1331, 806},
1411 { 832, 518,1331, 806}, /* 640x480 */
1412 {1050, 638,1344, 806}, /* 800x600 */ 1333 {1050, 638,1344, 806}, /* 800x600 */
1413 {1344, 806,1344, 806}, /* 1024x768 */ 1334 {1344, 806,1344, 806}, /* 1024x768 */
1414}; 1335};
1415 1336
1416/* Custom data for Barco iQ G series */ 1337static const struct SiS_LVDSData SiS_CHTVUNTSCData[]=
1417static const SiS_LVDSDataStruct SiS_LVDSBARCO1024Data_2[]=
1418{
1419 {1344, 806,1344, 806}
1420};
1421
1422/* Custom data for 848x480 parallel panel */
1423static const SiS_LVDSDataStruct SiS_LVDS848x480Data_1[]=
1424{
1425 { 0, 0, 0, 0},
1426 { 0, 0, 0, 0},
1427 { 0, 0, 0, 0},
1428 { 0, 0, 0, 0},
1429 {1088, 525,1088, 525}, /* 640x480 TODO */
1430 {1088, 525,1088, 525}, /* 800x600 TODO */
1431 {1088, 525,1088, 525}, /* 1024x768 TODO */
1432 { 0, 0, 0, 0},
1433 { 0, 0, 0, 0},
1434 { 0, 0, 0, 0},
1435 { 0, 0, 0, 0},
1436 {1088, 525,1088, 525}, /* 848x480 */
1437 {1088, 525,1088, 525} /* 1360x768 TODO */
1438};
1439
1440/* Custom data for 848x480 parallel panel */
1441static const SiS_LVDSDataStruct SiS_LVDS848x480Data_2[]=
1442{
1443 { 0, 0, 0, 0},
1444 { 0, 0, 0, 0},
1445 { 0, 0, 0, 0},
1446 { 0, 0, 0, 0},
1447 {1088, 525,1088, 525}, /* 640x480 */
1448 {1088, 525,1088, 525}, /* 800x600 */
1449 {1088, 525,1088, 525}, /* 1024x768 */
1450 { 0, 0, 0, 0},
1451 { 0, 0, 0, 0},
1452 { 0, 0, 0, 0},
1453 { 0, 0, 0, 0},
1454 {1088, 525,1088, 525}, /* 848x480 */
1455 {1088, 525,1088, 525} /* 1360x768 TODO */
1456};
1457
1458static const SiS_LVDSDataStruct SiS_CHTVUNTSCData[]=
1459{ 1338{
1460 { 840, 600, 840, 600}, 1339 { 840, 600, 840, 600},
1461 { 840, 600, 840, 600}, 1340 { 840, 600, 840, 600},
@@ -1466,7 +1345,7 @@ static const SiS_LVDSDataStruct SiS_CHTVUNTSCData[]=
1466 {1160, 945,1160, 945} 1345 {1160, 945,1160, 945}
1467}; 1346};
1468 1347
1469static const SiS_LVDSDataStruct SiS_CHTVONTSCData[]= 1348static const struct SiS_LVDSData SiS_CHTVONTSCData[]=
1470{ 1349{
1471 { 840, 525, 840, 525}, 1350 { 840, 525, 840, 525},
1472 { 840, 525, 840, 525}, 1351 { 840, 525, 840, 525},
@@ -1477,55 +1356,9 @@ static const SiS_LVDSDataStruct SiS_CHTVONTSCData[]=
1477 {1160, 840,1160, 840} 1356 {1160, 840,1160, 840}
1478}; 1357};
1479 1358
1480/* Chrontel TV Skew */
1481
1482static const SiS_LVDSDesStruct SiS_CHTVUNTSCDesData[]=
1483{
1484 { 0, 0},
1485 { 0, 0},
1486 { 0, 0},
1487 { 0, 0},
1488 { 0, 0},
1489 { 0, 0},
1490 { 0, 0}
1491};
1492
1493static const SiS_LVDSDesStruct SiS_CHTVONTSCDesData[]=
1494{
1495 { 0, 0},
1496 { 0, 0},
1497 { 0, 0},
1498 { 0, 0},
1499 { 0, 0},
1500 { 0, 0},
1501 { 0, 0}
1502};
1503
1504static const SiS_LVDSDesStruct SiS_CHTVUPALDesData[]=
1505{
1506 {256, 0},
1507 {256, 0},
1508 {256, 0},
1509 {256, 0},
1510 { 0, 0},
1511 { 0, 0},
1512 { 0, 0}
1513};
1514
1515static const SiS_LVDSDesStruct SiS_CHTVOPALDesData[]=
1516{
1517 {256, 0},
1518 {256, 0},
1519 {256, 0},
1520 {256, 0},
1521 { 0, 0},
1522 { 0, 0},
1523 { 0, 0}
1524};
1525
1526/* CRT1 CRTC data for slave modes */ 1359/* CRT1 CRTC data for slave modes */
1527 1360
1528static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT1320x480_1[] = 1361static const struct SiS_LVDSCRT1Data SiS_LVDSCRT1320x240_1[] =
1529{ 1362{
1530 {{0x65,0x4f,0x89,0x56,0x83,0xaa,0x1f, 1363 {{0x65,0x4f,0x89,0x56,0x83,0xaa,0x1f,
1531 0x90,0x85,0x8f,0xab,0x30,0x00,0x05, 1364 0x90,0x85,0x8f,0xab,0x30,0x00,0x05,
@@ -1550,48 +1383,7 @@ static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT1320x480_1[] =
1550 0x00 }} 1383 0x00 }}
1551}; 1384};
1552 1385
1553static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT1640x480_1[] = 1386static const struct SiS_LVDSCRT1Data SiS_LVDSCRT1320x240_2[] =
1554{
1555 {{0x5f,0x4f,0x82,0x55,0x81,0x0b,0x3e,
1556 0xe9,0x8b,0xdf,0x04,0x30,0x00,0x05,
1557 0x00}},
1558 {{0x5f,0x4f,0x82,0x55,0x81,0x0b,0x3e,
1559 0xe9,0x8b,0xdf,0x04,0x30,0x00,0x05,
1560 0x00}},
1561 {{0x5f,0x4f,0x82,0x55,0x81,0x0b,0x3e,
1562 0xe9,0x8b,0xdf,0x04,0x30,0x00,0x05,
1563 0x00}},
1564 {{0x5f,0x4f,0x82,0x55,0x81,0x0b,0x3e,
1565 0xe9,0x8b,0xdf,0x04,0x30,0x00,0x05,
1566 0x00}},
1567 {{0x5f,0x4f,0x82,0x55,0x81,0x0b,0x3e,
1568 0xe9,0x8b,0xdf,0x04,0x30,0x00,0x05,
1569 0x00}},
1570 {{0x7f,0x63,0x83,0x6c,0x1c,0x72,0xf0,
1571 0x58,0x8c,0x57,0x73,0x20,0x00,0x06,
1572 0x01}}
1573};
1574
1575static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT1640x480_1_H[] =
1576{
1577 {{0x2d,0x28,0x90,0x2b,0xa0,0xbf,0x1f,
1578 0x9c,0x8e,0x96,0xb9,0x00,0x00,0x00,
1579 0x00}},
1580 {{0x2d,0x28,0x90,0x2b,0xa0,0xbf,0x1f,
1581 0x83,0x85,0x63,0xba,0x00,0x00,0x00,
1582 0x00}},
1583 {{0x2d,0x28,0x90,0x2b,0xa0,0xbf,0x1f,
1584 0x9c,0x8e,0x96,0xb9,0x00,0x00,0x00,
1585 0x00}},
1586 {{0x2d,0x28,0x90,0x2b,0xa0,0xbf,0x1f,
1587 0x83,0x85,0x63,0xba,0x00,0x00,0x00,
1588 0x00}},
1589 {{0x2d,0x28,0x90,0x2c,0x80,0x0b,0x3e,
1590 0xe9,0x8b,0xe7,0x04,0x00,0x00,0x00,
1591 0x00}}
1592};
1593
1594static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT1640x480_2[] =
1595{ 1387{
1596 {{0x5f,0x4f,0x82,0x55,0x81,0x0b,0x3e, 1388 {{0x5f,0x4f,0x82,0x55,0x81,0x0b,0x3e,
1597 0xe9,0x8b,0xdf,0x04,0x30,0x00,0x05, 1389 0xe9,0x8b,0xdf,0x04,0x30,0x00,0x05,
@@ -1611,12 +1403,17 @@ static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT1640x480_2[] =
1611 {{0x7f,0x63,0x83,0x6c,0x1c,0x72,0xf0, 1403 {{0x7f,0x63,0x83,0x6c,0x1c,0x72,0xf0,
1612 0x58,0x8c,0x57,0x73,0x20,0x00,0x06, 1404 0x58,0x8c,0x57,0x73,0x20,0x00,0x06,
1613 0x01}}, 1405 0x01}},
1406#if 0
1614 {{0x2d,0x27,0x90,0x2c,0x80,0x0b,0x3e, 1407 {{0x2d,0x27,0x90,0x2c,0x80,0x0b,0x3e,
1615 0xe9,0x8b,0xe7,0x04,0x00,0x00,0x00, 1408 0xe9,0x8b,0xe7,0x04,0x00,0x00,0x00,
1616 0x00}} 1409 0x00}}
1410#endif
1411 {{0x5f,0x4f,0x83,0x55,0x81,0x0b,0x3e,
1412 0xe9,0x8b,0xe8,0x0c,0x00,0x00,0x05,
1413 0x00}},
1617}; 1414};
1618 1415
1619static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT1640x480_2_H[] = 1416static const struct SiS_LVDSCRT1Data SiS_LVDSCRT1320x240_2_H[] =
1620{ 1417{
1621 {{0x65,0x4f,0x89,0x56,0x83,0xaa,0x1f, 1418 {{0x65,0x4f,0x89,0x56,0x83,0xaa,0x1f,
1622 0x90,0x85,0x8f,0xab,0x30,0x00,0x05, 1419 0x90,0x85,0x8f,0xab,0x30,0x00,0x05,
@@ -1641,7 +1438,7 @@ static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT1640x480_2_H[] =
1641 0x00}} 1438 0x00}}
1642}; 1439};
1643 1440
1644static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT1640x480_3[] = 1441static const struct SiS_LVDSCRT1Data SiS_LVDSCRT1320x240_3[] =
1645{ 1442{
1646 {{0x5f,0x4f,0x82,0x55,0x81,0x0b,0x3e, 1443 {{0x5f,0x4f,0x82,0x55,0x81,0x0b,0x3e,
1647 0xe9,0x8b,0xdf,0x04,0x00,0x00,0x05, 1444 0xe9,0x8b,0xdf,0x04,0x00,0x00,0x05,
@@ -1666,7 +1463,7 @@ static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT1640x480_3[] =
1666 0x00}} 1463 0x00}}
1667}; 1464};
1668 1465
1669static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT1640x480_3_H[] = 1466static const struct SiS_LVDSCRT1Data SiS_LVDSCRT1320x240_3_H[] =
1670{ 1467{
1671 {{0x65,0x4f,0x89,0x56,0x83,0xaa,0x1f, 1468 {{0x65,0x4f,0x89,0x56,0x83,0xaa,0x1f,
1672 0x90,0x85,0x8f,0xab,0x30,0x00,0x05, 1469 0x90,0x85,0x8f,0xab,0x30,0x00,0x05,
@@ -1691,778 +1488,175 @@ static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT1640x480_3_H[] =
1691 0x00}} 1488 0x00}}
1692}; 1489};
1693 1490
1694static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT11024x600_1[] = 1491static const struct SiS_LVDSCRT1Data SiS_LVDSCRT1640x480_1[] =
1695{
1696 {{0x64,0x4f,0x88,0x54,0x9f,0x5a,0x3e,
1697 0xe8,0x8f,0x8f,0x5b,0x00,0x00,0x01,
1698 0x00}},
1699 {{0x64,0x4f,0x88,0x54,0x9f,0x2e,0x3e,
1700 0xb9,0x80,0x5d,0x2f,0x00,0x00,0x01,
1701 0x00}},
1702 {{0x64,0x4f,0x88,0x54,0x9f,0x5a,0x3e,
1703 0xe8,0x8f,0x8f,0x5b,0x00,0x00,0x01,
1704 0x00}},
1705 {{0x64,0x4f,0x88,0x54,0x9f,0x2e,0x3e,
1706 0xb9,0x80,0x5d,0x2f,0x00,0x00,0x01,
1707 0x00}},
1708 {{0x64,0x4f,0x88,0x54,0x9f,0xaf,0xba,
1709 0x3b,0x82,0xdf,0xb0,0x00,0x00,0x01,
1710 0x00}},
1711 {{0x7e,0x63,0x82,0x68,0x15,0x1e,0xf1,
1712 0xae,0x85,0x57,0x1f,0x30,0x00,0x26,
1713 0x01}},
1714 {{0xa3,0x7f,0x87,0x86,0x97,0x1e,0xf1,
1715 0xae,0x85,0x57,0x1f,0x30,0x00,0x02,
1716 0x01}}
1717};
1718
1719static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT11024x600_1_H[] =
1720{
1721 {{0x2f,0x27,0x93,0x2b,0x90,0xc4,0x1f,
1722 0x92,0x89,0x8f,0xb5,0x30,0x00,0x44,
1723 0x00}},
1724 {{0x2f,0x27,0x93,0x2b,0x90,0x97,0x1f,
1725 0x60,0x87,0x5d,0x83,0x10,0x00,0x44,
1726 0x00}},
1727 {{0x2f,0x27,0x93,0x2b,0x90,0xc4,0x1f,
1728 0x92,0x89,0x8f,0xb5,0x30,0x00,0x44,
1729 0x00}},
1730 {{0x2f,0x27,0x93,0x2b,0x90,0x97,0x1f,
1731 0x60,0x87,0x5d,0x83,0x10,0x00,0x44,
1732 0x00}},
1733 {{0x2f,0x27,0x93,0x2b,0x90,0x04,0x3e,
1734 0xe2,0x89,0xdf,0x05,0x00,0x00,0x44,
1735 0x00}},
1736 {{0x3c,0x31,0x80,0x35,0x1c,0x7c,0xf0,
1737 0x5a,0x8f,0x57,0x7d,0x20,0x00,0x55,
1738 0x01}},
1739 {{0x4f,0x3f,0x93,0x45,0x0d,0x24,0xf5,
1740 0x02,0x88,0xff,0x25,0x10,0x00,0x01,
1741 0x01}}
1742};
1743
1744static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT11024x600_2[] =
1745{
1746 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1747 0x4a,0x80,0x8f,0x25,0x30,0x00,0x06,
1748 0x00}},
1749 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1750 0x31,0x87,0x5d,0x25,0x30,0x00,0x06,
1751 0x00}},
1752 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1753 0x4a,0x80,0x8f,0x25,0x30,0x00,0x06,
1754 0x00}},
1755 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1756 0x31,0x87,0x5d,0x25,0x30,0x00,0x06,
1757 0x00}},
1758 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1759 0x72,0x88,0xdf,0x25,0x30,0x00,0x06,
1760 0x00}},
1761 {{0xa3,0x63,0x87,0x78,0x89,0x24,0xf1,
1762 0xae,0x84,0x57,0x25,0x30,0x00,0x02,
1763 0x01}},
1764 {{0xa3,0x7f,0x87,0x86,0x97,0x24,0xf5,
1765 0x02,0x88,0xff,0x25,0x10,0x00,0x02,
1766 0x01}}
1767};
1768
1769static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT11024x600_2_H[] =
1770{
1771 {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
1772 0x4a,0x80,0x8f,0x25,0x30,0x00,0x01,
1773 0x00}},
1774 {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
1775 0x31,0x87,0x5d,0x25,0x30,0x00,0x01,
1776 0x00}},
1777 {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
1778 0x4a,0x80,0x8f,0x25,0x30,0x00,0x01,
1779 0x00}},
1780 {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
1781 0x31,0x87,0x5d,0x25,0x30,0x00,0x01,
1782 0x00}},
1783 {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
1784 0x72,0x88,0xdf,0x25,0x30,0x00,0x01,
1785 0x00}},
1786 {{0x4f,0x31,0x93,0x3e,0x06,0x24,0xf1,
1787 0xae,0x84,0x57,0x25,0x30,0x00,0x01,
1788 0x01}},
1789 {{0x4f,0x3f,0x93,0x45,0x0d,0x24,0xf5,
1790 0x02,0x88,0xff,0x25,0x10,0x00,0x01,
1791 0x01}}
1792};
1793
1794static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT11152x768_1[] =
1795{
1796 {{0x64,0x4f,0x88,0x54,0x9f,0xc4,0x1f,
1797 0x92,0x89,0x8f,0xb5,0x30,0x00,0x01,
1798 0x00}},
1799 {{0x64,0x4f,0x88,0x54,0x9f,0x97,0x1f,
1800 0x60,0x87,0x5d,0x83,0x10,0x00,0x01,
1801 0x00}},
1802 {{0x64,0x4f,0x88,0x54,0x9f,0xc4,0x1f,
1803 0x92,0x89,0x8f,0xb5,0x30,0x00,0x01,
1804 0x00}},
1805 {{0x64,0x4f,0x88,0x54,0x9f,0x97,0x1f,
1806 0x60,0x87,0x5d,0x83,0x10,0x00,0x01,
1807 0x00}},
1808 {{0x64,0x4f,0x88,0x54,0x9f,0x04,0x3e,
1809 0xe2,0x89,0xdf,0x05,0x00,0x00,0x01,
1810 0x00}},
1811 {{0x7e,0x63,0x82,0x68,0x15,0x7c,0xf0,
1812 0x5a,0x8f,0x57,0x7d,0x20,0x00,0x26,
1813 0x01}},
1814 {{0xa3,0x7f,0x87,0x86,0x97,0x24,0xf5,
1815 0x02,0x88,0xff,0x25,0x10,0x00,0x02,
1816 0x01}}
1817};
1818
1819static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT11152x768_1_H[] =
1820{
1821 {{0x2f,0x27,0x93,0x2b,0x90,0xc4,0x1f,
1822 0x92,0x89,0x8f,0xb5,0x30,0x00,0x44,
1823 0x00}},
1824 {{0x2f,0x27,0x93,0x2b,0x90,0x97,0x1f,
1825 0x60,0x87,0x5d,0x83,0x10,0x00,0x44,
1826 0x00}},
1827 {{0x2f,0x27,0x93,0x2b,0x90,0xc4,0x1f,
1828 0x92,0x89,0x8f,0xb5,0x30,0x00,0x44,
1829 0x00}},
1830 {{0x2f,0x27,0x93,0x2b,0x90,0x97,0x1f,
1831 0x60,0x87,0x5d,0x83,0x10,0x00,0x44,
1832 0x00}},
1833 {{0x2f,0x27,0x93,0x2b,0x90,0x04,0x3e,
1834 0xe2,0x89,0xdf,0x05,0x00,0x00,0x44,
1835 0x00}},
1836 {{0x3c,0x31,0x80,0x35,0x1c,0x7c,0xf0,
1837 0x5a,0x8f,0x57,0x7d,0x20,0x00,0x55,
1838 0x01}},
1839 {{0x4f,0x3f,0x93,0x45,0x0d,0x24,0xf5,
1840 0x02,0x88,0xff,0x25,0x10,0x00,0x01,
1841 0x01}}
1842};
1843
1844static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT11152x768_2[] =
1845{
1846 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1847 0x4a,0x80,0x8f,0x25,0x30,0x00,0x06,
1848 0x00}},
1849 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1850 0x31,0x87,0x5d,0x25,0x30,0x00,0x06,
1851 0x00}},
1852 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1853 0x4a,0x80,0x8f,0x25,0x30,0x00,0x06,
1854 0x00}},
1855 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1856 0x31,0x87,0x5d,0x25,0x30,0x00,0x06,
1857 0x00}},
1858 {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
1859 0x72,0x88,0xdf,0x25,0x30,0x00,0x06,
1860 0x00}},
1861 {{0xa3,0x63,0x87,0x78,0x89,0x24,0xf1,
1862 0xae,0x84,0x57,0x25,0x30,0x00,0x02,
1863 0x01}},
1864 {{0xa3,0x7f,0x87,0x86,0x97,0x24,0xf5,
1865 0x02,0x88,0xff,0x25,0x10,0x00,0x02,
1866 0x01}}
1867};
1868
1869static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT11152x768_2_H[] =
1870{
1871 {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
1872 0x4a,0x80,0x8f,0x25,0x30,0x00,0x01,
1873 0x00}},
1874 {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
1875 0x31,0x87,0x5d,0x25,0x30,0x00,0x01,
1876 0x00}},
1877 {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
1878 0x4a,0x80,0x8f,0x25,0x30,0x00,0x01,
1879 0x00}},
1880 {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
1881 0x31,0x87,0x5d,0x25,0x30,0x00,0x01,
1882 0x00}},
1883 {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
1884 0x72,0x88,0xdf,0x25,0x30,0x00,0x01,
1885 0x00}},
1886 {{0x4f,0x31,0x93,0x3e,0x06,0x24,0xf1,
1887 0xae,0x84,0x57,0x25,0x30,0x00,0x01,
1888 0x01}},
1889 {{0x4f,0x3f,0x93,0x45,0x0d,0x24,0xf5,
1890 0x02,0x88,0xff,0x25,0x10,0x00,0x01,
1891 0x01}}
1892};
1893
1894static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT11280x768_1[] =
1895{
1896 {{0x5b,0x4f,0x9f,0x55,0x19,0xb4,0x1f,
1897 0x9c,0x8e,0x8f,0xb5,0x10,0x00,0x01,
1898 0x00}},
1899 {{0x5b,0x4f,0x9f,0x55,0x19,0x82,0x1f,
1900 0x6a,0x8c,0x5d,0x83,0x30,0x00,0x01,
1901 0x00}},
1902 {{0x5b,0x4f,0x9f,0x55,0x19,0xb4,0x1f,
1903 0x9c,0x8e,0x8f,0xb5,0x10,0x00,0x01,
1904 0x00}},
1905 {{0x5b,0x4f,0x9f,0x55,0x19,0x82,0x1f,
1906 0x6a,0x8c,0x5d,0x83,0x30,0x00,0x01,
1907 0x00}},
1908 {{0x5b,0x4f,0x9f,0x55,0x19,0x04,0x3e,
1909 0xec,0x8e,0xdf,0x05,0x20,0x00,0x01,
1910 0x00}},
1911 {{0x6f,0x63,0x93,0x69,0x8d,0x7c,0xf0,
1912 0x64,0x86,0x57,0x7d,0x20,0x00,0x05,
1913 0x01}},
1914 {{0x8b,0x7f,0x8f,0x85,0x09,0x24,0xf5,
1915 0x0c,0x8e,0xff,0x25,0x30,0x00,0x02,
1916 0x01}},
1917 {{0xab,0x9f,0x8f,0xa5,0x89,0x24,0xf5,
1918 0x0c,0x8e,0xff,0x25,0x30,0x00,0x06,
1919 0x01}},
1920 {{0xab,0x9f,0x8f,0xa5,0x89,0x24,0xf5,
1921 0x0c,0x8e,0xff,0x25,0x30,0x00,0x06,
1922 0x01}}
1923};
1924
1925static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT11280x768_1_H[] =
1926{ 1492{
1927 {{0x47,0x27,0x8b,0x2c,0x1a,0x9e,0x1f, 1493 {{0x5f,0x4f,0x82,0x55,0x81,0x0b,0x3e,
1928 0x93,0x86,0x8f,0x9f,0x30,0x00,0x05, 1494 0xe9,0x8b,0xdf,0x04,0x30,0x00,0x05,
1929 0x00}},
1930 {{0x47,0x27,0x8b,0x2c,0x1a,0x6c,0x1f,
1931 0x60,0x84,0x5d,0x6d,0x10,0x00,0x05,
1932 0x00}},
1933 {{0x47,0x27,0x8b,0x30,0x1e,0x9e,0x1f,
1934 0x92,0x86,0x8f,0x9f,0x30,0x00,0x05,
1935 0x00}},
1936 {{0x47,0x27,0x8b,0x2c,0x1a,0x6c,0x1f,
1937 0x60,0x84,0x5d,0x6d,0x10,0x00,0x05,
1938 0x00}},
1939 {{0x47,0x27,0x8b,0x2c,0x1a,0xee,0x1f,
1940 0xe2,0x86,0xdf,0xef,0x10,0x00,0x05,
1941 0x00}}, 1495 0x00}},
1942 {{0x51,0x31,0x95,0x36,0x04,0x66,0xf0, 1496 {{0x5f,0x4f,0x82,0x55,0x81,0x0b,0x3e,
1943 0x5a,0x8e,0x57,0x67,0x20,0x00,0x01, 1497 0xe9,0x8b,0xdf,0x04,0x30,0x00,0x05,
1944 0x01}},
1945 {{0x5f,0x3f,0x83,0x44,0x92,0x0e,0xf5,
1946 0x02,0x86,0xff,0x0f,0x10,0x00,0x01,
1947 0x01}},
1948 {{0x6f,0x4f,0x93,0x54,0x82,0x0e,0x5a,
1949 0x02,0x86,0xff,0x0f,0x09,0x00,0x05,
1950 0x01}},
1951 {{0x6f,0x4f,0x93,0x54,0x82,0x0e,0x5a,
1952 0x02,0x86,0xff,0x0f,0x09,0x00,0x05,
1953 0x01}}
1954};
1955
1956static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT11280x768_2[] =
1957{
1958 {{0xab,0x60,0x9f,0x80,0x04,0x24,0xbb,
1959 0x54,0x86,0xdb,0xda,0x00,0x00,0x02,
1960 0x00}}, 1498 0x00}},
1961 {{0xab,0x60,0x9f,0x80,0x04,0x24,0xbb, 1499 {{0x5f,0x4f,0x82,0x55,0x81,0x0b,0x3e,
1962 0x3b,0x8d,0xc2,0xc1,0x00,0x00,0x02, 1500 0xe9,0x8b,0xdf,0x04,0x30,0x00,0x05,
1963 0x00}}, 1501 0x00}},
1964 {{0xab,0x60,0x9f,0x80,0x04,0x24,0xbb, 1502 {{0x5f,0x4f,0x82,0x55,0x81,0x0b,0x3e,
1965 0x54,0x86,0xdb,0xda,0x00,0x00,0x02, 1503 0xe9,0x8b,0xdf,0x04,0x30,0x00,0x05,
1966 0x00}}, 1504 0x00}},
1967 {{0xab,0x60,0x9f,0x80,0x04,0x24,0xbb, 1505 {{0x5f,0x4f,0x82,0x55,0x81,0x0b,0x3e,
1968 0x3b,0x8d,0xc2,0xc1,0x00,0x00,0x02, 1506 0xe9,0x8b,0xdf,0x04,0x30,0x00,0x05,
1969 0x00}}, 1507 0x00}},
1970 {{0xab,0x60,0x9f,0x80,0x04,0x24,0xb3, 1508 {{0x7f,0x63,0x83,0x6c,0x1c,0x72,0xf0,
1971 0x7c,0x8e,0x03,0x02,0x10,0x00,0x02, 1509 0x58,0x8c,0x57,0x73,0x20,0x00,0x06,
1972 0x01}},
1973 {{0xab,0x63,0x8f,0x8a,0x8e,0x24,0xf1,
1974 0xb6,0x88,0x57,0x25,0x10,0x00,0x02,
1975 0x01}},
1976 {{0xab,0x7f,0x8f,0x98,0x9c,0x24,0xf5,
1977 0x0a,0x8c,0xff,0x25,0x30,0x00,0x02,
1978 0x01}},
1979 {{0xab,0x9f,0x8f,0xa8,0x8c,0x24,0xf5,
1980 0x0a,0x8c,0xff,0x25,0x30,0x00,0x06,
1981 0x01}},
1982 {{0xab,0x9f,0x8f,0xa8,0x8c,0x24,0xf5,
1983 0x0a,0x8c,0xff,0x25,0x30,0x00,0x06,
1984 0x01}} 1510 0x01}}
1985}; 1511};
1986 1512
1987static const SiS_LVDSCRT1DataStruct SiS_LVDSCRT11280x768_2_H[] = 1513static const struct SiS_LVDSCRT1Data SiS_LVDSCRT1640x480_1_H[] =
1988{ 1514{
1989 {{0x83,0x38,0x97,0x58,0x9c,0x24,0xbb, 1515 {{0x2d,0x28,0x90,0x2b,0xa0,0xbf,0x1f,
1990 0x54,0x86,0xdb,0xda,0x00,0x00,0x01, 1516 0x9c,0x8e,0x96,0xb9,0x00,0x00,0x00,
1991 0x00}}, 1517 0x00}},
1992 {{0x83,0x38,0x97,0x58,0x9c,0x24,0xbb, 1518 {{0x2d,0x28,0x90,0x2b,0xa0,0xbf,0x1f,
1993 0x3b,0x8d,0xc2,0xc1,0x00,0x00,0x01, 1519 0x83,0x85,0x63,0xba,0x00,0x00,0x00,
1994 0x00}}, 1520 0x00}},
1995 {{0x83,0x38,0x97,0x58,0x9c,0x24,0xbb, 1521 {{0x2d,0x28,0x90,0x2b,0xa0,0xbf,0x1f,
1996 0x54,0x86,0xdb,0xda,0x00,0x00,0x01, 1522 0x9c,0x8e,0x96,0xb9,0x00,0x00,0x00,
1997 0x00}}, 1523 0x00}},
1998 {{0x83,0x38,0x97,0x58,0x9c,0x24,0xbb, 1524 {{0x2d,0x28,0x90,0x2b,0xa0,0xbf,0x1f,
1999 0x3b,0x8d,0xc2,0xc1,0x00,0x00,0x01, 1525 0x83,0x85,0x63,0xba,0x00,0x00,0x00,
2000 0x00}}, 1526 0x00}},
2001 {{0x83,0x38,0x97,0x58,0x9c,0x24,0xb3, 1527 {{0x2d,0x28,0x90,0x2c,0x80,0x0b,0x3e,
2002 0x7c,0x8e,0x03,0x02,0x10,0x00,0x01, 1528 0xe9,0x8b,0xe7,0x04,0x00,0x00,0x00,
2003 0x01}}, 1529 0x00}}
2004 {{0x79,0x31,0x9d,0x58,0x9c,0x24,0xf1,
2005 0xb6,0x88,0x57,0x25,0x10,0x00,0x01,
2006 0x01}},
2007 {{0x6b,0x3f,0x8f,0x58,0x9c,0x24,0xf5,
2008 0x0a,0x8c,0xff,0x25,0x30,0x00,0x01,
2009 0x01}},
2010 {{0xab,0x9f,0x8f,0xa8,0x8c,0x24,0xf5,
2011 0x0a,0x8c,0xff,0x25,0x30,0x00,0x06,
2012 0x01}},
2013 {{0xab,0x9f,0x8f,0xa8,0x8c,0x24,0xf5,
2014 0x0a,0x8c,0xff,0x25,0x30,0x00,0x06,
2015 0x01}}
2016};
2017
2018/**************************************************************/
2019/* COMMON --------------------------------------------------- */
2020/**************************************************************/
2021
2022#ifdef LINUX_XF86
2023
2024#define SIS_PL_HSYNCP 0x01
2025#define SIS_PL_HSYNCN 0x02
2026#define SIS_PL_VSYNCP 0x04
2027#define SIS_PL_VSYNCN 0x08
2028#define SIS_PL_DVI 0x80
2029
2030typedef struct _SiS_PlasmaModes
2031{
2032 const char *name;
2033 ULONG clock;
2034 USHORT HDisplay, HTotal, HFrontPorch, HSyncWidth;
2035 USHORT VDisplay, VTotal, VFrontPorch, VSyncWidth;
2036 UCHAR SyncFlags;
2037} SiS_PlasmaModes;
2038
2039typedef struct _SiS_PlasmaTables
2040{
2041 USHORT vendor;
2042 UCHAR productnum;
2043 USHORT product[5];
2044 const char *DDCnames[5];
2045 const char *plasmaname;
2046 USHORT maxx,maxy;
2047 USHORT prefx, prefy;
2048 UCHAR modenum;
2049 UCHAR plasmamodes[20]; /* | 0x80 = DVI-capable, | 0x40 = analog */
2050} SiS_PlasmaTables;
2051
2052static const SiS_PlasmaModes SiS_PlasmaMode[] = {
2053 { "640x400", /* 00: IBM 400@70 */
2054 25175,
2055 640, 800, 17, 64,
2056 400, 449, 13, 2,
2057 SIS_PL_HSYNCN | SIS_PL_VSYNCN },
2058 { "640x480", /* 01: VESA 480@72 */
2059 31500,
2060 640, 832, 24, 40,
2061 480, 520, 9, 3,
2062 SIS_PL_HSYNCN | SIS_PL_VSYNCN },
2063 { "800x600", /* 02: VESA 600@72 */
2064 50000,
2065 800, 1040, 56, 120,
2066 600, 666, 37, 6,
2067 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2068 { "864x480", /* 03: Cereb wide 1 */
2069 42526,
2070 864, 1134, 22, 86,
2071 480, 500, 1, 3,
2072 SIS_PL_HSYNCP | SIS_PL_VSYNCN },
2073 { "848x480", /* 04: VESA wide (NEC1) */
2074 33750,
2075 848, 1088, 16, 112,
2076 480, 517, 6, 8,
2077 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2078 { "1024x576", /* 05: VESA wide (NEC2) */
2079 47250,
2080 1024, 1320, 16, 144,
2081 576, 596, 2, 4,
2082 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2083 { "1280x720", /* 06: VESA wide (NEC3) */
2084 76500,
2085 1280, 1696, 48, 176,
2086 720, 750, 4, 8,
2087 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2088 { "1360x765", /* 07: VESA wide (NEC4) */
2089 85500,
2090 1360, 1792, 64, 176,
2091 765, 795, 4, 8,
2092 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2093 { "1024x600", /* 08: CEREB wide 2 */
2094 51200,
2095 1024, 1352, 51, 164,
2096 600, 628, 1, 4,
2097 SIS_PL_HSYNCN | SIS_PL_VSYNCP },
2098 { "1024x768", /* 09: VESA 768@75 */
2099 78750,
2100 1024, 1312, 16, 96,
2101 768, 800, 1, 3,
2102 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2103 { "1152x864", /* 10: VESA 1152x864@75 */
2104 108000,
2105 1152, 1600, 64, 128,
2106 864, 900, 1, 3,
2107 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2108 { "1280x1024", /* 11: VESA 1024@60 */
2109 108000,
2110 1280, 1688, 48, 112,
2111 1024, 1066, 1, 3,
2112 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2113 { "1280x768", /* 12: W_XGA */
2114 81000,
2115 1280, 1688, 48, 112,
2116 768, 802, 3, 6,
2117 SIS_PL_HSYNCP | SIS_PL_VSYNCN },
2118 { "1280x768", /* 13: I/O Data W_XGA@56Hz */
2119 76064,
2120 1280, 1688, 48, 112,
2121 768, 802, 2, 3,
2122 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2123 { "1376x768", /* 14: I/O Wide XGA */
2124 87340,
2125 1376, 1808, 32, 128,
2126 768, 806, 3, 6,
2127 SIS_PL_HSYNCN | SIS_PL_VSYNCP },
2128 { "1280x960", /* 15: VESA 960@60 */
2129 108000,
2130 1280, 1800, 96, 112,
2131 960, 1000, 1, 3,
2132 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2133 { "1400x1050", /* 16: VESA 1050@60Hz */
2134 108000,
2135 1400, 1688, 48, 112,
2136 1050, 1066, 1, 3,
2137 SIS_PL_HSYNCN | SIS_PL_VSYNCN },
2138 { "1360x768", /* 17: VESA wide (NEC4/2) */
2139 85500,
2140 1360, 1792, 64, 112,
2141 765, 795, 3, 6,
2142 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2143 { "800x600", /* 18: VESA 600@56 */
2144 36000,
2145 800, 1024, 24, 2,
2146 600, 625, 1, 2,
2147 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2148 { "1072x600", /* 19: Panasonic 1072x600 (sync?) */
2149 54100,
2150 1072, 1424, 48, 176,
2151 600, 628, 16, 1,
2152 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2153 { "848x480", /* 20: Panasonic 848x480 (sync?) */
2154 33070, /* is 852x480, but we can't use 852 */
2155 848, 1068, 20, 40, /* differs from DDC data, better centered */
2156 480, 516, 3, 5, /* won't work assumingly, because data is % 8 */
2157 SIS_PL_HSYNCN | SIS_PL_VSYNCN },
2158 { "1280x720", /* 21: WIDE720(60) (aka "750p") (Panasonic) */
2159 74300,
2160 1280, 1650,110, 40,
2161 720, 750, 5, 5,
2162 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2163 { "1280x768", /* 22: 1280x768@56.5 (Panasonic) */
2164 76200, /* (According to manual not supported for HDMI; but works) */
2165 1280, 1680, 16, 24,
2166 768, 802, 2, 5,
2167 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2168 { "1280x720@50", /* 23: WIDE720(50) (aka "750p") (Panasonic) */
2169 74300, /* Panasonic states 45.0kHz. Not possible. This one works (with some overscan) */
2170 1280, 1980,400, 80,
2171 720, 750, 1, 2,
2172 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2173 { "720x480", /* 24: 720x480 (aka "525p" and "480p") (Panasonic) */
2174 27000,
2175 720, 856, 40, 32,
2176 480, 525, 1, 3,
2177 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2178 { "720x576", /* 25: 720x576 (aka "625p"and "576p") (Panasonic) */
2179 27500,
2180 720, 864, 16, 64,
2181 576, 625, 5, 6,
2182 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2183 { "1280x720@50", /* 26: WIDE720(50) (aka "750p") (Generic) */
2184 74300,
2185 1280, 1980,400, 80,
2186 720, 750, 5, 5,
2187 SIS_PL_HSYNCP | SIS_PL_VSYNCP },
2188}; 1530};
2189 1531
2190/* 1532BOOLEAN SiSInitPtr(struct SiS_Private *SiS_Pr);
219127.00 720 755 791 858 480 480 484 525 1533#ifdef SIS_XORG_XF86
219227.50 720 732 795 864 576 581 587 625 1534unsigned short SiS_GetModeID(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay,
2193*/ 1535 int Depth, BOOLEAN FSTN, int LCDwith, int LCDheight);
2194
2195static const SiS_PlasmaTables SiS_PlasmaTable[] = {
2196#if 0 /* Product IDs missing */
2197 { 0x38a3, 4,
2198 { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 },
2199 { "", "", "", "", "" },
2200 "NEC PlasmaSync 42VP4/42VP4D/42VP4G/42VP4DG",
2201 0, 0,
2202 0, 0,
2203 11, /* All DVI, except 0, 7, 13 */
2204 { 0|0x40, 1|0xc0, 2|0xc0, 4|0xc0, 7|0x40, 9|0xc0,10|0xc0,11|0xc0,13|0x40,14|0xc0,
2205 17|0xc0, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
2206 },
2207#endif 1536#endif
2208#if 0 /* Product IDs missing */ 1537unsigned short SiS_GetModeID_LCD(int VGAEngine, unsigned int VBFlags, int HDisplay,
2209 { 0x38a3, 3, 1538 int VDisplay, int Depth, BOOLEAN FSTN,
2210 { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 }, 1539 unsigned short CustomT, int LCDwith, int LCDheight,
2211 { "", "", "", "", "" }, 1540 unsigned int VBFlags2);
2212 "NEC PlasmaSync 42PD1/50PD1/50PD2", 1541unsigned short SiS_GetModeID_TV(int VGAEngine, unsigned int VBFlags, int HDisplay,
2213 0, 0, 1542 int VDisplay, int Depth, unsigned int VBFlags2);
2214 0, 0, 1543unsigned short SiS_GetModeID_VGA2(int VGAEngine, unsigned int VBFlags, int HDisplay,
2215 5, /* DVI entirely unknown */ 1544 int VDisplay, int Depth, unsigned int VBFlags2);
2216 { 0|0x40, 1|0xc0, 2|0xc0, 4|0xc0, 9|0xc0, 0 , 0 , 0 , 0 , 0 , 1545
2217 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } 1546void SiS_SetReg(SISIOADDRESS port, unsigned short index, unsigned short data);
2218 }, 1547void SiS_SetRegByte(SISIOADDRESS port, unsigned short data);
2219 { 0x38a3, 1, 1548void SiS_SetRegShort(SISIOADDRESS port, unsigned short data);
2220 { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 }, 1549void SiS_SetRegLong(SISIOADDRESS port, unsigned int data);
2221 { "", "", "", "", "" }, 1550unsigned char SiS_GetReg(SISIOADDRESS port, unsigned short index);
2222 "NEC PlasmaSync 42PD3", 1551unsigned char SiS_GetRegByte(SISIOADDRESS port);
2223 0, 0, 1552unsigned short SiS_GetRegShort(SISIOADDRESS port);
2224 0, 0, 1553unsigned int SiS_GetRegLong(SISIOADDRESS port);
2225 10, /* DVI entirely unknown */ 1554void SiS_SetRegANDOR(SISIOADDRESS Port, unsigned short Index, unsigned short DataAND,
2226 { 0|0x40, 1|0xc0, 2|0xc0, 3|0xc0, 4|0xc0, 5|0xc0, 6|0xc0, 7|0x40, 8|0xc0, 9|0xc0, 1555 unsigned short DataOR);
2227 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } 1556void SiS_SetRegAND(SISIOADDRESS Port,unsigned short Index, unsigned short DataAND);
2228 }, 1557void SiS_SetRegOR(SISIOADDRESS Port,unsigned short Index, unsigned short DataOR);
2229 { 0x38a3, 2, 1558
2230 { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 }, 1559void SiS_DisplayOn(struct SiS_Private *SiS_Pr);
2231 { "", "", "", "", "" }, 1560void SiS_DisplayOff(struct SiS_Private *SiS_Pr);
2232 "NEC PlasmaSync 42VM3/61XM1", 1561void SiSRegInit(struct SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr);
2233 0, 0, 1562#ifndef SIS_LINUX_KERNEL
2234 0, 0, 1563void SiSSetLVDSetc(struct SiS_Private *SiS_Pr);
2235 11, /* DVI entirely unknown */
2236 { 0|0x40, 1|0xc0, 2|0xc0, 3|0xc0, 4|0xc0, 5|0xc0, 6|0xc0, 8|0xc0, 9|0xc0,11|0xc0,
2237 17|0xc0, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
2238 },
2239 { 0x38a3, 2,
2240 { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 },
2241 { "", "", "", "", "" },
2242 "NEC PlasmaSync 42MP1/42MP2",
2243 0, 0,
2244 0, 0,
2245 6, /* DVI entirely unknown */
2246 { 0|0x40, 1|0xc0, 2|0xc0, 4|0xc0, 9|0xc0,11|0xc0, 0 , 0 , 0 , 0 ,
2247 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
2248 },
2249 { 0x38a3, 1,
2250 { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 },
2251 { "", "", "", "", "" },
2252 "NEC PlasmaSync 50MP1",
2253 0, 0,
2254 0, 0,
2255 10, /* DVI entirely unknown */
2256 { 0|0x40, 1|0xc0, 2|0xc0, 4|0xc0, 7|0x40, 9|0xc0,10|0xc0,11|0xc0,13|0x40,14|0xc0,
2257 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
2258 },
2259#endif 1564#endif
2260 { 0x38a3, 4, 1565void SiS_SetEnableDstn(struct SiS_Private *SiS_Pr, int enable);
2261 { 0xa482, 0xa483, 0x0000, 0x0000, 0x0000 }, 1566void SiS_SetEnableFstn(struct SiS_Private *SiS_Pr, int enable);
2262 { "PX-42VM", "", "", "", "" }, 1567unsigned short SiS_GetModeFlag(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2263 "NEC PlasmaSync 42MP3/42MP4/50MP2/61MP1", 1568 unsigned short ModeIdIndex);
2264 0, 0, 1569BOOLEAN SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr);
2265 0, 0, 1570#ifndef SIS_LINUX_KERNEL
2266 11, /* All DVI except 0, 7, 13, 17 */ 1571void SiS_GetVBType(struct SiS_Private *SiS_Pr);
2267 { 0|0x40, 1|0xc0, 2|0xc0, 4|0xc0, 7|0x40, 9|0xc0,10|0xc0,11|0xc0,13|0x40,14|0xc0,
2268 17|0x40, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
2269 },
2270#if 0 /* Product IDs missing */
2271 { 0x38a3, 1,
2272 { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 },
2273 { "", "", "", "", "" },
2274 "NEC PlasmaSync 3300W",
2275 0, 0,
2276 0, 0,
2277 3,
2278 { 0|0x40, 1|0xc0,18|0xc0, 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
2279 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
2280 },
2281 { 0x38a3, 1,
2282 { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 },
2283 { "", "", "", "", "" },
2284 "NEC PlasmaSync 4200W",
2285 4, /* DVI entirely unknown */
2286 { 0|0x40, 1|0xc0, 2|0xc0, 4|0xc0, 0 , 0 , 0 , 0 , 0 , 0 ,
2287 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
2288 },
2289 { 0x38a3, 1,
2290 { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 },
2291 { "", "", "", "", "" },
2292 "NEC PlasmaSync 4210W",
2293 0, 0,
2294 0, 0,
2295 6, /* DVI entirely unknown */
2296 { 0|0x40, 1|0xc0, 2|0xc0, 4|0xc0, 9|0xc0,11|0xc0, 0 , 0 , 0 , 0 ,
2297 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
2298 },
2299 { 0x38a3, 1,
2300 { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 },
2301 { "", "", "", "", "" },
2302 "NEC PlasmaSync 5000W",
2303 0, 0,
2304 0, 0,
2305 7, /* DVI entirely unknown */
2306 { 0|0x40, 1|0xc0, 2|0xc0, 4|0xc0, 7|0x40, 9|0xc0,11|0xc0, 0 , 0 , 0 ,
2307 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
2308 },
2309#endif
2310 { 0x412f, 2,
2311 { 0x000c, 0x000b, 0x0000, 0x0000, 0x0000 },
2312 { "", "", "", "", "" },
2313 "Pioneer 503CMX/PDA-5002",
2314 0, 0,
2315 0, 0,
2316 6, /* DVI unknown */
2317 { 1|0xc0, 2|0xc0, 9|0xc0,11|0xc0,12|0xc0,15|0xc0, 0 , 0 , 0 , 0 ,
2318 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
2319 },
2320 { 0x34a9, 1,
2321 { 0xa00e, 0x0000, 0x0000, 0x0000, 0x0000 },
2322 { "", "", "", "", "" },
2323 "Panasonic TH-42",
2324 0, 0,
2325 0, 0,
2326 5, /* No DVI output */
2327 { 1|0x40, 2|0x40, 4|0x40, 9|0x40,15|0x40, 0 , 0 , 0 , 0 , 0 ,
2328 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
2329 },
2330 { 0x34a9, 1,
2331 { 0xa005, 0x0000, 0x0000, 0x0000, 0x0000 },
2332 { "TH-42PW*4", "", "", "", "" },
2333 "Panasonic TH-42PW5",
2334 0, 0,
2335 0, 0,
2336 1, /* No special modes otherwise; no DVI. */
2337 {20|0x40,19|0x40, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
2338 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
2339 },
2340 { 0x4c2e, 1,
2341 { 0x9b05, 0x0000, 0x0000, 0x0000, 0x0000 },
2342 { "PLV-Z2", "", "", "", "" },
2343 "Sanyo PLV-Z2 (non HDCP-mode)", /* HDCP mode would be id 9b06, but not needed */
2344 1280, 768, /* as it then advertises correct size */
2345 1280, 720,
2346 1, /* 1280x720, no special modes otherwise */
2347 {21|0xc0, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
2348 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
2349 },
2350 { 0x34a9, 1,
2351 { 0xd034, 0x0000, 0x0000, 0x0000, 0x0000 },
2352 { "AE500U (DVI-D)", "", "", "", "" },
2353 "Panasonic AE500U",
2354 1280, 768,
2355 1280, 720,
2356 1, /* 1280x720, no special modes otherwise */
2357 {21|0xc0, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
2358 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
2359 },
2360 { 0x34a9, 1,
2361 { 0xd043, 0x0000, 0x0000, 0x0000, 0x0000 },
2362 { "AE700U (HDMI)", "", "", "", "" },
2363 "Panasonic AE700U",
2364 1360, 768,
2365 1280, 720,
2366 6, /* 1280x720/60, 1280x720/50, 1280x768@56(digital/analog), 720x480, 720x576 */
2367 {21|0xc0,23|0xc0,22|0x80,13|0x40,24|0x80,25|0x80, 0 , 0 , 0 , 0 ,
2368 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
2369 },
2370 { 0x0000 }
2371};
2372#endif 1572#endif
2373 1573
2374#ifdef LINUX_XF86 1574BOOLEAN SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo,
2375USHORT SiS_GetModeID(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, 1575 unsigned short *ModeIdIndex);
2376 int Depth, BOOLEAN FSTN, int LCDwith, int LCDheight); 1576unsigned short SiS_GetModePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1577 unsigned short ModeIdIndex);
1578unsigned short SiS_GetRefCRTVCLK(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide);
1579unsigned short SiS_GetRefCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide);
1580unsigned short SiS_GetColorDepth(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1581 unsigned short ModeIdIndex);
1582unsigned short SiS_GetOffset(struct SiS_Private *SiS_Pr,unsigned short ModeNo,
1583 unsigned short ModeIdIndex, unsigned short RRTI);
1584#ifdef SIS300
1585void SiS_GetFIFOThresholdIndex300(struct SiS_Private *SiS_Pr, unsigned short *idx1,
1586 unsigned short *idx2);
1587unsigned short SiS_GetFIFOThresholdB300(unsigned short idx1, unsigned short idx2);
1588unsigned short SiS_GetLatencyFactor630(struct SiS_Private *SiS_Pr, unsigned short index);
2377#endif 1589#endif
2378USHORT SiS_GetModeID_LCD(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int Depth, BOOLEAN FSTN, 1590void SiS_LoadDAC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex);
2379 USHORT CustomT, int LCDwith, int LCDheight); 1591#ifdef SIS_XORG_XF86
2380USHORT SiS_GetModeID_TV(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int Depth); 1592BOOLEAN SiSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn, unsigned short ModeNo,
2381USHORT SiS_GetModeID_VGA2(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int Depth); 1593 BOOLEAN dosetpitch);
2382 1594BOOLEAN SiSBIOSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
2383void SiS_SetReg(SISIOADDRESS port, USHORT index, USHORT data); 1595 DisplayModePtr mode, BOOLEAN IsCustom);
2384void SiS_SetRegByte(SISIOADDRESS port, USHORT data); 1596BOOLEAN SiSBIOSSetModeCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
2385void SiS_SetRegShort(SISIOADDRESS port, USHORT data); 1597 DisplayModePtr mode, BOOLEAN IsCustom);
2386void SiS_SetRegLong(SISIOADDRESS port, ULONG data); 1598BOOLEAN SiSBIOSSetModeCRT1(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
2387UCHAR SiS_GetReg(SISIOADDRESS port, USHORT index); 1599 DisplayModePtr mode, BOOLEAN IsCustom);
2388UCHAR SiS_GetRegByte(SISIOADDRESS port); 1600#endif
2389USHORT SiS_GetRegShort(SISIOADDRESS port); 1601#ifdef SIS_LINUX_KERNEL
2390ULONG SiS_GetRegLong(SISIOADDRESS port); 1602BOOLEAN SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo);
2391void SiS_SetRegANDOR(SISIOADDRESS Port, USHORT Index, USHORT DataAND, USHORT DataOR); 1603#endif
2392void SiS_SetRegAND(SISIOADDRESS Port,USHORT Index, USHORT DataAND); 1604void SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth);
2393void SiS_SetRegOR(SISIOADDRESS Port,USHORT Index, USHORT DataOR); 1605void SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2394void SiS_DisplayOn(SiS_Private *SiS_Pr); 1606 unsigned short ModeIdIndex);
2395void SiS_DisplayOff(SiS_Private *SiS_Pr); 1607#ifdef SIS_XORG_XF86
2396void SiSRegInit(SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr); 1608void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata, int xres,
2397BOOLEAN SiSDetermineROMLayout661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo); 1609 int yres, DisplayModePtr current);
2398void SiS_SetEnableDstn(SiS_Private *SiS_Pr, int enable); 1610#endif
2399void SiS_SetEnableFstn(SiS_Private *SiS_Pr, int enable); 1611#ifdef SIS_LINUX_KERNEL
2400BOOLEAN SiS_SearchModeID(SiS_Private *SiS_Pr, USHORT *ModeNo, USHORT *ModeIdIndex); 1612void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata, int xres,
2401UCHAR SiS_GetModePtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex); 1613 int yres, struct fb_var_screeninfo *var, BOOLEAN writeres);
2402USHORT SiS_GetColorDepth(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex);
2403USHORT SiS_GetOffset(SiS_Private *SiS_Pr,USHORT ModeNo, USHORT ModeIdIndex,
2404 USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo);
2405void SiS_LoadDAC(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo, USHORT ModeIdIndex);
2406void SiS_CalcLCDACRT1Timing(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex);
2407
2408#ifdef LINUX_XF86
2409BOOLEAN SiSSetMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,ScrnInfoPtr pScrn,USHORT ModeNo, BOOLEAN dosetpitch);
2410BOOLEAN SiSBIOSSetMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn,
2411 DisplayModePtr mode, BOOLEAN IsCustom);
2412BOOLEAN SiSBIOSSetModeCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn,
2413 DisplayModePtr mode, BOOLEAN IsCustom);
2414BOOLEAN SiSBIOSSetModeCRT1(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, ScrnInfoPtr pScrn,
2415 DisplayModePtr mode, BOOLEAN IsCustom);
2416int SiSTranslateToVESA(ScrnInfoPtr pScrn, int modenumber);
2417int SiSTranslateToOldMode(int modenumber);
2418BOOLEAN SiS_GetPanelID(SiS_Private *SiS_Pr, PSIS_HW_INFO);
2419USHORT SiS_CheckBuildCustomMode(ScrnInfoPtr pScrn, DisplayModePtr mode, int VBFlags);
2420DisplayModePtr SiSBuildBuiltInModeList(ScrnInfoPtr pScrn, BOOLEAN includelcdmodes, BOOLEAN isfordvi);
2421int SiS_FindPanelFromDB(SISPtr pSiS, USHORT panelvendor, USHORT panelproduct, int *maxx, int *maxy, int *prefx, int *prefy);
2422void SiS_MakeClockRegs(ScrnInfoPtr pScrn, int clock, UCHAR *p2b, UCHAR *p2c);
2423#else
2424BOOLEAN SiSSetMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,USHORT ModeNo);
2425#endif 1614#endif
2426 1615
2427#ifdef LINUX_KERNEL 1616/* From init301.c: */
2428int sisfb_mode_rate_to_dclock(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 1617extern void SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2429 UCHAR modeno, UCHAR rateindex); 1618 unsigned short ModeIdIndex, int chkcrt2mode);
2430int sisfb_mode_rate_to_ddata(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 1619extern void SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2431 UCHAR modeno, UCHAR rateindex, 1620 unsigned short ModeIdIndex);
2432 struct fb_var_screeninfo *var); 1621extern void SiS_SetYPbPr(struct SiS_Private *SiS_Pr);
2433BOOLEAN sisfb_gettotalfrommode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 1622extern void SiS_SetTVMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2434 UCHAR modeno, int *htotal, int *vtotal, UCHAR rateindex); 1623 unsigned short ModeIdIndex);
1624extern void SiS_UnLockCRT2(struct SiS_Private *SiS_Pr);
1625extern void SiS_DisableBridge(struct SiS_Private *);
1626extern BOOLEAN SiS_SetCRT2Group(struct SiS_Private *, unsigned short);
1627extern unsigned short SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1628 unsigned short ModeIdIndex);
1629extern void SiS_WaitRetrace1(struct SiS_Private *SiS_Pr);
1630extern unsigned short SiS_GetResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1631 unsigned short ModeIdIndex);
1632extern unsigned short SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short tempax);
1633extern unsigned short SiS_GetVCLK2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1634 unsigned short ModeIdIndex, unsigned short RRTI);
1635extern BOOLEAN SiS_IsVAMode(struct SiS_Private *);
1636extern BOOLEAN SiS_IsDualEdge(struct SiS_Private *);
1637
1638#ifdef SIS_XORG_XF86
1639/* From other modules: */
1640extern unsigned short SiS_CheckBuildCustomMode(ScrnInfoPtr pScrn, DisplayModePtr mode,
1641 unsigned int VBFlags);
1642extern unsigned char SiS_GetSetBIOSScratch(ScrnInfoPtr pScrn, unsigned short offset,
1643 unsigned char value);
1644extern unsigned char SiS_GetSetModeID(ScrnInfoPtr pScrn, unsigned char id);
1645extern unsigned short SiS_GetModeNumber(ScrnInfoPtr pScrn, DisplayModePtr mode,
1646 unsigned int VBFlags);
2435#endif 1647#endif
2436 1648
2437/* init301.c: */ 1649#ifdef SIS_LINUX_KERNEL
2438extern void SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 1650#ifdef SIS300
2439 PSIS_HW_INFO HwInfo, int chkcrt2mode); 1651extern unsigned int sisfb_read_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg);
2440extern void SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 1652extern void sisfb_write_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg,
2441 PSIS_HW_INFO HwInfo); 1653 unsigned int val);
2442extern void SiS_SetYPbPr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo); 1654#endif
2443extern void SiS_SetTVMode(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, PSIS_HW_INFO HwInfo); 1655#ifdef SIS315H
2444extern void SiS_UnLockCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo); 1656extern void sisfb_write_nbridge_pci_byte(struct SiS_Private *SiS_Pr, int reg,
2445extern void SiS_DisableBridge(SiS_Private *, PSIS_HW_INFO); 1657 unsigned char val);
2446extern BOOLEAN SiS_SetCRT2Group(SiS_Private *, PSIS_HW_INFO, USHORT); 1658extern unsigned int sisfb_read_mio_pci_word(struct SiS_Private *SiS_Pr, int reg);
2447extern USHORT SiS_GetRatePtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 1659#endif
2448 PSIS_HW_INFO HwInfo);
2449extern void SiS_WaitRetrace1(SiS_Private *SiS_Pr);
2450extern USHORT SiS_GetResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex);
2451extern USHORT SiS_GetCH700x(SiS_Private *SiS_Pr, USHORT tempax);
2452extern USHORT SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2453 USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo);
2454extern BOOLEAN SiS_IsVAMode(SiS_Private *, PSIS_HW_INFO);
2455extern BOOLEAN SiS_IsDualEdge(SiS_Private *, PSIS_HW_INFO);
2456
2457#ifdef LINUX_XF86
2458/* From other sis driver modules: */
2459extern int SiS_compute_vclk(int Clock, int *out_n, int *out_dn, int *out_div,
2460 int *out_sbit, int *out_scale);
2461extern void SiSCalcClock(ScrnInfoPtr pScrn, int clock, int max_VLD, unsigned int *vclk);
2462
2463extern UCHAR SiS_GetSetBIOSScratch(ScrnInfoPtr pScrn, USHORT offset, UCHAR value);
2464extern UCHAR SiS_GetSetModeID(ScrnInfoPtr pScrn, UCHAR id);
2465extern USHORT SiS_GetModeNumber(ScrnInfoPtr pScrn, DisplayModePtr mode, ULONG VBFlags);
2466#endif 1660#endif
2467 1661
2468#endif 1662#endif
diff --git a/drivers/video/sis/init301.c b/drivers/video/sis/init301.c
index 274dacd54b..2d88f90817 100644
--- a/drivers/video/sis/init301.c
+++ b/drivers/video/sis/init301.c
@@ -2,11 +2,12 @@
2/* $XdotOrg$ */ 2/* $XdotOrg$ */
3/* 3/*
4 * Mode initializing code (CRT2 section) 4 * Mode initializing code (CRT2 section)
5 * for SiS 300/305/540/630/730 and 5 * for SiS 300/305/540/630/730,
6 * SiS 315/550/650/M650/651/661FX/M661xX/740/741(GX)/M741/330/660/M660/760/M760 6 * SiS 315/550/[M]650/651/[M]661[FGM]X/[M]74x[GX]/330/[M]76x[GX],
7 * (Universal module for Linux kernel framebuffer and XFree86/X.org 4.x) 7 * XGI V3XT/V5/V8, Z7
8 * (Universal module for Linux kernel framebuffer and X.org/XFree86 4.x)
8 * 9 *
9 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria 10 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
10 * 11 *
11 * If distributed as part of the Linux kernel, the following license terms 12 * If distributed as part of the Linux kernel, the following license terms
12 * apply: 13 * apply:
@@ -38,7 +39,7 @@
38 * * 3) The name of the author may not be used to endorse or promote products 39 * * 3) The name of the author may not be used to endorse or promote products
39 * * derived from this software without specific prior written permission. 40 * * derived from this software without specific prior written permission.
40 * * 41 * *
41 * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR 42 * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
42 * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 43 * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43 * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 44 * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
44 * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 45 * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
@@ -54,20 +55,20 @@
54 * Formerly based on non-functional code-fragements for 300 series by SiS, Inc. 55 * Formerly based on non-functional code-fragements for 300 series by SiS, Inc.
55 * Used by permission. 56 * Used by permission.
56 * 57 *
57 * TW says: This code looks awful, I know. But please don't do anything about
58 * this otherwise debugging will be hell.
59 * The code is extremely fragile as regards the different chipsets, different
60 * video bridges and combinations thereof. If anything is changed, extreme
61 * care has to be taken that that change doesn't break it for other chipsets,
62 * bridges or combinations thereof.
63 * All comments in this file are by me, regardless if marked TW or not.
64 *
65 */ 58 */
66 59
60#ifdef HAVE_CONFIG_H
61#include "config.h"
62#endif
63
67#if 1 64#if 1
68#define SET_EMI /* 302LV/ELV: Set EMI values */ 65#define SET_EMI /* 302LV/ELV: Set EMI values */
69#endif 66#endif
70 67
68#if 1
69#define SET_PWD /* 301/302LV: Set PWD */
70#endif
71
71#define COMPAL_HACK /* Needed for Compal 1400x1050 (EMI) */ 72#define COMPAL_HACK /* Needed for Compal 1400x1050 (EMI) */
72#define COMPAQ_HACK /* Needed for Inventec/Compaq 1280x1024 (EMI) */ 73#define COMPAQ_HACK /* Needed for Inventec/Compaq 1280x1024 (EMI) */
73#define ASUS_HACK /* Needed for Asus A2H 1024x768 (EMI) */ 74#define ASUS_HACK /* Needed for Asus A2H 1024x768 (EMI) */
@@ -85,26 +86,35 @@
85#define SiS_I2CDELAY 1000 86#define SiS_I2CDELAY 1000
86#define SiS_I2CDELAYSHORT 150 87#define SiS_I2CDELAYSHORT 150
87 88
88static USHORT SiS_GetBIOSLCDResInfo(SiS_Private *SiS_Pr); 89static unsigned short SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr);
89static void SiS_SetCH70xx(SiS_Private *SiS_Pr, USHORT tempbx); 90#ifdef SIS_LINUX_KERNEL
91static void SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val);
92#endif
90 93
91/*********************************************/ 94/*********************************************/
92/* HELPER: Lock/Unlock CRT2 */ 95/* HELPER: Lock/Unlock CRT2 */
93/*********************************************/ 96/*********************************************/
94 97
95void 98void
96SiS_UnLockCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 99SiS_UnLockCRT2(struct SiS_Private *SiS_Pr)
97{ 100{
98 if(HwInfo->jChipType >= SIS_315H) 101 if(SiS_Pr->ChipType == XGI_20)
102 return;
103 else if(SiS_Pr->ChipType >= SIS_315H)
99 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2f,0x01); 104 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2f,0x01);
100 else 105 else
101 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24,0x01); 106 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24,0x01);
102} 107}
103 108
104static void 109#ifdef SIS_LINUX_KERNEL
105SiS_LockCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 110static
111#endif
112void
113SiS_LockCRT2(struct SiS_Private *SiS_Pr)
106{ 114{
107 if(HwInfo->jChipType >= SIS_315H) 115 if(SiS_Pr->ChipType == XGI_20)
116 return;
117 else if(SiS_Pr->ChipType >= SIS_315H)
108 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2F,0xFE); 118 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2F,0xFE);
109 else 119 else
110 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x24,0xFE); 120 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x24,0xFE);
@@ -115,9 +125,9 @@ SiS_LockCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
115/*********************************************/ 125/*********************************************/
116 126
117static void 127static void
118SiS_SetRegSR11ANDOR(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DataAND, USHORT DataOR) 128SiS_SetRegSR11ANDOR(struct SiS_Private *SiS_Pr, unsigned short DataAND, unsigned short DataOR)
119{ 129{
120 if(HwInfo->jChipType >= SIS_661) { 130 if(SiS_Pr->ChipType >= SIS_661) {
121 DataAND &= 0x0f; 131 DataAND &= 0x0f;
122 DataOR &= 0x0f; 132 DataOR &= 0x0f;
123 } 133 }
@@ -129,12 +139,12 @@ SiS_SetRegSR11ANDOR(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DataAND, US
129/*********************************************/ 139/*********************************************/
130 140
131#ifdef SIS315H 141#ifdef SIS315H
132static UCHAR * 142static unsigned char *
133GetLCDStructPtr661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 143GetLCDStructPtr661(struct SiS_Private *SiS_Pr)
134{ 144{
135 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 145 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
136 UCHAR *myptr = NULL; 146 unsigned char *myptr = NULL;
137 USHORT romindex = 0, reg = 0, idx = 0; 147 unsigned short romindex = 0, reg = 0, idx = 0;
138 148
139 /* Use the BIOS tables only for LVDS panels; TMDS is unreliable 149 /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
140 * due to the variaty of panels the BIOS doesn't know about. 150 * due to the variaty of panels the BIOS doesn't know about.
@@ -144,15 +154,15 @@ GetLCDStructPtr661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
144 */ 154 */
145 155
146 if((SiS_Pr->SiS_ROMNew) && 156 if((SiS_Pr->SiS_ROMNew) &&
147 ((SiS_Pr->SiS_VBType & VB_SIS301LV302LV) || (!SiS_Pr->PanelSelfDetected))) { 157 ((SiS_Pr->SiS_VBType & VB_SISLVDS) || (!SiS_Pr->PanelSelfDetected))) {
148 158
149 if(HwInfo->jChipType < SIS_661) reg = 0x3c; 159 if(SiS_Pr->ChipType < SIS_661) reg = 0x3c;
150 else reg = 0x7d; 160 else reg = 0x7d;
151 161
152 idx = (SiS_GetReg(SiS_Pr->SiS_P3d4,reg) & 0x1f) * 26; 162 idx = (SiS_GetReg(SiS_Pr->SiS_P3d4,reg) & 0x1f) * 26;
153 163
154 if(idx < (8*26)) { 164 if(idx < (8*26)) {
155 myptr = (UCHAR *)&SiS_LCDStruct661[idx]; 165 myptr = (unsigned char *)&SiS_LCDStruct661[idx];
156 } 166 }
157 romindex = SISGETROMW(0x100); 167 romindex = SISGETROMW(0x100);
158 if(romindex) { 168 if(romindex) {
@@ -163,11 +173,11 @@ GetLCDStructPtr661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
163 return myptr; 173 return myptr;
164} 174}
165 175
166static USHORT 176static unsigned short
167GetLCDStructPtr661_2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 177GetLCDStructPtr661_2(struct SiS_Private *SiS_Pr)
168{ 178{
169 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 179 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
170 USHORT romptr = 0; 180 unsigned short romptr = 0;
171 181
172 /* Use the BIOS tables only for LVDS panels; TMDS is unreliable 182 /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
173 * due to the variaty of panels the BIOS doesn't know about. 183 * due to the variaty of panels the BIOS doesn't know about.
@@ -177,12 +187,12 @@ GetLCDStructPtr661_2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
177 */ 187 */
178 188
179 if((SiS_Pr->SiS_ROMNew) && 189 if((SiS_Pr->SiS_ROMNew) &&
180 ((SiS_Pr->SiS_VBType & VB_SIS301LV302LV) || (!SiS_Pr->PanelSelfDetected))) { 190 ((SiS_Pr->SiS_VBType & VB_SISLVDS) || (!SiS_Pr->PanelSelfDetected))) {
181 romptr = SISGETROMW(0x102); 191 romptr = SISGETROMW(0x102);
182 romptr += ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) * SiS_Pr->SiS661LCD2TableSize); 192 romptr += ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) * SiS_Pr->SiS661LCD2TableSize);
183 } 193 }
184 194
185 return(romptr); 195 return romptr;
186} 196}
187#endif 197#endif
188 198
@@ -191,186 +201,187 @@ GetLCDStructPtr661_2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
191/*********************************************/ 201/*********************************************/
192 202
193static BOOLEAN 203static BOOLEAN
194SiS_AdjustCRT2Rate(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 204SiS_AdjustCRT2Rate(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
195 USHORT RRTI, USHORT *i, PSIS_HW_INFO HwInfo) 205 unsigned short RRTI, unsigned short *i)
196{ 206{
197 USHORT checkmask=0,modeid,infoflag; 207 unsigned short checkmask=0, modeid, infoflag;
198 208
199 modeid = SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID; 209 modeid = SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID;
200 210
201 if(SiS_Pr->SiS_VBType & VB_SISVB) { 211 if(SiS_Pr->SiS_VBType & VB_SISVB) {
202 212
203 if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { 213 if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
204 214
205 checkmask |= SupportRAMDAC2; 215 checkmask |= SupportRAMDAC2;
206 if(HwInfo->jChipType >= SIS_315H) { 216 if(SiS_Pr->ChipType >= SIS_315H) {
207 checkmask |= SupportRAMDAC2_135; 217 checkmask |= SupportRAMDAC2_135;
208 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 218 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
209 checkmask |= SupportRAMDAC2_162; 219 checkmask |= SupportRAMDAC2_162;
210 if(SiS_Pr->SiS_VBType & VB_SIS301C) { 220 if(SiS_Pr->SiS_VBType & VB_SISRAMDAC202) {
211 checkmask |= SupportRAMDAC2_202; 221 checkmask |= SupportRAMDAC2_202;
212 } 222 }
213 } 223 }
214 } 224 }
215 225
216 } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { 226 } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
217 227
218 checkmask |= SupportLCD; 228 checkmask |= SupportLCD;
219 if(HwInfo->jChipType >= SIS_315H) { 229 if(SiS_Pr->ChipType >= SIS_315H) {
220 if(SiS_Pr->SiS_VBType & VB_SISVB) { 230 if(SiS_Pr->SiS_VBType & VB_SISVB) {
221 if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) { 231 if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
222 if(modeid == 0x2e) checkmask |= Support64048060Hz; 232 if(modeid == 0x2e) checkmask |= Support64048060Hz;
223 } 233 }
224 } 234 }
225 } 235 }
226 236
227 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { 237 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
228 238
229 checkmask |= SupportHiVision; 239 checkmask |= SupportHiVision;
230 240
231 } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750|SetCRT2ToAVIDEO|SetCRT2ToSVIDEO|SetCRT2ToSCART)) { 241 } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750|SetCRT2ToAVIDEO|SetCRT2ToSVIDEO|SetCRT2ToSCART)) {
232 242
233 checkmask |= SupportTV; 243 checkmask |= SupportTV;
234 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 244 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
235 checkmask |= SupportTV1024; 245 checkmask |= SupportTV1024;
236 if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { 246 if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
237 if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) { 247 if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
238 checkmask |= SupportYPbPr750p; 248 checkmask |= SupportYPbPr750p;
239 } 249 }
240 } 250 }
241 } 251 }
242 252
243 } 253 }
244 254
245 } else { /* LVDS */ 255 } else { /* LVDS */
246 256
247 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 257 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
248 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 258 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
249 checkmask |= SupportCHTV; 259 checkmask |= SupportCHTV;
250 } 260 }
251 } 261 }
252 262
253 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 263 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
254 checkmask |= SupportLCD; 264 checkmask |= SupportLCD;
255 } 265 }
256 266
257 } 267 }
258 268
259 /* Look backwards in table for matching CRT2 mode */ 269 /* Look backwards in table for matching CRT2 mode */
260 for(; SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID == modeid; (*i)--) { 270 for(; SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID == modeid; (*i)--) {
261 infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag; 271 infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
262 if(infoflag & checkmask) return TRUE; 272 if(infoflag & checkmask) return TRUE;
263 if((*i) == 0) break; 273 if((*i) == 0) break;
264 } 274 }
265 275
266 /* Look through the whole mode-section of the table from the beginning 276 /* Look through the whole mode-section of the table from the beginning
267 * for a matching CRT2 mode if no mode was found yet. 277 * for a matching CRT2 mode if no mode was found yet.
268 */ 278 */
269 for((*i) = 0; ; (*i)++) { 279 for((*i) = 0; ; (*i)++) {
270 if(SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID != modeid) break; 280 if(SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID != modeid) break;
271 infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag; 281 infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
272 if(infoflag & checkmask) return TRUE; 282 if(infoflag & checkmask) return TRUE;
273 } 283 }
274 return FALSE; 284 return FALSE;
275} 285}
276 286
277/*********************************************/ 287/*********************************************/
278/* Get rate index */ 288/* Get rate index */
279/*********************************************/ 289/*********************************************/
280 290
281USHORT 291unsigned short
282SiS_GetRatePtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 292SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
283 PSIS_HW_INFO HwInfo) 293{
284{ 294 unsigned short RRTI,i,backup_i;
285 SHORT LCDRefreshIndex[] = { 0x00, 0x00, 0x01, 0x01, 295 unsigned short modeflag,index,temp,backupindex;
286 0x01, 0x01, 0x01, 0x01, 296 static const unsigned short LCDRefreshIndex[] = {
287 0x01, 0x01, 0x01, 0x01, 297 0x00, 0x00, 0x01, 0x01,
288 0x01, 0x01, 0x01, 0x01, 298 0x01, 0x01, 0x01, 0x01,
289 0x00, 0x00, 0x00, 0x00 }; 299 0x01, 0x01, 0x01, 0x01,
290 USHORT RRTI,i,backup_i; 300 0x01, 0x01, 0x01, 0x01,
291 USHORT modeflag,index,temp,backupindex; 301 0x00, 0x00, 0x00, 0x00
302 };
292 303
293 /* Do NOT check for UseCustomMode here, will skrew up FIFO */ 304 /* Do NOT check for UseCustomMode here, will skrew up FIFO */
294 if(ModeNo == 0xfe) return 0; 305 if(ModeNo == 0xfe) return 0;
295 306
296 if(ModeNo <= 0x13) { 307 if(ModeNo <= 0x13) {
297 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; 308 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
298 } else { 309 } else {
299 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 310 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
300 } 311 }
301 312
302 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 313 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
303 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 314 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
304 if(modeflag & HalfDCLK) return 0; 315 if(modeflag & HalfDCLK) return 0;
305 } 316 }
306 } 317 }
307 318
308 if(ModeNo < 0x14) return 0xFFFF; 319 if(ModeNo < 0x14) return 0xFFFF;
309 320
310 index = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x33) >> SiS_Pr->SiS_SelectCRT2Rate) & 0x0F; 321 index = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x33) >> SiS_Pr->SiS_SelectCRT2Rate) & 0x0F;
311 backupindex = index; 322 backupindex = index;
312 323
313 if(index > 0) index--; 324 if(index > 0) index--;
314 325
315 if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) { 326 if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
316 if(SiS_Pr->SiS_VBType & VB_SISVB) { 327 if(SiS_Pr->SiS_VBType & VB_SISVB) {
317 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 328 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
318 if(SiS_Pr->SiS_VBType & VB_NoLCD) index = 0; 329 if(SiS_Pr->SiS_VBType & VB_NoLCD) index = 0;
319 else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index = backupindex = 0; 330 else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index = backupindex = 0;
320 } 331 }
321 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { 332 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
322 if(!(SiS_Pr->SiS_VBType & VB_NoLCD)) { 333 if(!(SiS_Pr->SiS_VBType & VB_NoLCD)) {
323 temp = LCDRefreshIndex[SiS_GetBIOSLCDResInfo(SiS_Pr)]; 334 temp = LCDRefreshIndex[SiS_GetBIOSLCDResInfo(SiS_Pr)];
324 if(index > temp) index = temp; 335 if(index > temp) index = temp;
325 } 336 }
326 } 337 }
327 } else { 338 } else {
328 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) index = 0; 339 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) index = 0;
329 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 340 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
330 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) index = 0; 341 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) index = 0;
331 } 342 }
332 } 343 }
333 } 344 }
334 345
335 RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex; 346 RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
336 ModeNo = SiS_Pr->SiS_RefIndex[RRTI].ModeID; 347 ModeNo = SiS_Pr->SiS_RefIndex[RRTI].ModeID;
337 348
338 if(HwInfo->jChipType >= SIS_315H) { 349 if(SiS_Pr->ChipType >= SIS_315H) {
339 if(!(SiS_Pr->SiS_VBInfo & DriverMode)) { 350 if(!(SiS_Pr->SiS_VBInfo & DriverMode)) {
340 if( (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x105) || 351 if( (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x105) ||
341 (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x107) ) { 352 (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x107) ) {
342 if(backupindex <= 1) RRTI++; 353 if(backupindex <= 1) RRTI++;
343 } 354 }
344 } 355 }
345 } 356 }
346 357
347 i = 0; 358 i = 0;
348 do { 359 do {
349 if(SiS_Pr->SiS_RefIndex[RRTI + i].ModeID != ModeNo) break; 360 if(SiS_Pr->SiS_RefIndex[RRTI + i].ModeID != ModeNo) break;
350 temp = SiS_Pr->SiS_RefIndex[RRTI + i].Ext_InfoFlag; 361 temp = SiS_Pr->SiS_RefIndex[RRTI + i].Ext_InfoFlag;
351 temp &= ModeTypeMask; 362 temp &= ModeTypeMask;
352 if(temp < SiS_Pr->SiS_ModeType) break; 363 if(temp < SiS_Pr->SiS_ModeType) break;
353 i++; 364 i++;
354 index--; 365 index--;
355 } while(index != 0xFFFF); 366 } while(index != 0xFFFF);
356 367
357 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) { 368 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
358 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { 369 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
359 temp = SiS_Pr->SiS_RefIndex[RRTI + i - 1].Ext_InfoFlag; 370 temp = SiS_Pr->SiS_RefIndex[RRTI + i - 1].Ext_InfoFlag;
360 if(temp & InterlaceMode) i++; 371 if(temp & InterlaceMode) i++;
361 } 372 }
362 } 373 }
363 374
364 i--; 375 i--;
365 376
366 if((SiS_Pr->SiS_SetFlag & ProgrammingCRT2) && (!(SiS_Pr->SiS_VBInfo & DisableCRT2Display))) { 377 if((SiS_Pr->SiS_SetFlag & ProgrammingCRT2) && (!(SiS_Pr->SiS_VBInfo & DisableCRT2Display))) {
367 backup_i = i; 378 backup_i = i;
368 if(!(SiS_AdjustCRT2Rate(SiS_Pr, ModeNo, ModeIdIndex, RRTI, &i, HwInfo))) { 379 if(!(SiS_AdjustCRT2Rate(SiS_Pr, ModeNo, ModeIdIndex, RRTI, &i))) {
369 i = backup_i; 380 i = backup_i;
370 } 381 }
371 } 382 }
372 383
373 return(RRTI + i); 384 return (RRTI + i);
374} 385}
375 386
376/*********************************************/ 387/*********************************************/
@@ -378,15 +389,15 @@ SiS_GetRatePtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
378/*********************************************/ 389/*********************************************/
379 390
380static void 391static void
381SiS_SaveCRT2Info(SiS_Private *SiS_Pr, USHORT ModeNo) 392SiS_SaveCRT2Info(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
382{ 393{
383 USHORT temp1,temp2; 394 unsigned short temp1, temp2;
384 395
385 /* Store CRT1 ModeNo in CR34 */ 396 /* Store CRT1 ModeNo in CR34 */
386 SiS_SetReg(SiS_Pr->SiS_P3d4,0x34,ModeNo); 397 SiS_SetReg(SiS_Pr->SiS_P3d4,0x34,ModeNo);
387 temp1 = (SiS_Pr->SiS_VBInfo & SetInSlaveMode) >> 8; 398 temp1 = (SiS_Pr->SiS_VBInfo & SetInSlaveMode) >> 8;
388 temp2 = ~(SetInSlaveMode >> 8); 399 temp2 = ~(SetInSlaveMode >> 8);
389 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x31,temp2,temp1); 400 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x31,temp2,temp1);
390} 401}
391 402
392/*********************************************/ 403/*********************************************/
@@ -395,35 +406,35 @@ SiS_SaveCRT2Info(SiS_Private *SiS_Pr, USHORT ModeNo)
395 406
396#ifdef SIS300 407#ifdef SIS300
397static BOOLEAN 408static BOOLEAN
398SiS_CR36BIOSWord23b(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 409SiS_CR36BIOSWord23b(struct SiS_Private *SiS_Pr)
399{ 410{
400 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 411 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
401 USHORT temp,temp1; 412 unsigned short temp,temp1;
402 413
403 if(SiS_Pr->SiS_UseROM) { 414 if(SiS_Pr->SiS_UseROM) {
404 if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) { 415 if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
405 temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f); 416 temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
406 temp1 = SISGETROMW(0x23b); 417 temp1 = SISGETROMW(0x23b);
407 if(temp1 & temp) return TRUE; 418 if(temp1 & temp) return TRUE;
408 } 419 }
409 } 420 }
410 return FALSE; 421 return FALSE;
411} 422}
412 423
413static BOOLEAN 424static BOOLEAN
414SiS_CR36BIOSWord23d(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 425SiS_CR36BIOSWord23d(struct SiS_Private *SiS_Pr)
415{ 426{
416 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 427 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
417 USHORT temp,temp1; 428 unsigned short temp,temp1;
418 429
419 if(SiS_Pr->SiS_UseROM) { 430 if(SiS_Pr->SiS_UseROM) {
420 if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) { 431 if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
421 temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f); 432 temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
422 temp1 = SISGETROMW(0x23d); 433 temp1 = SISGETROMW(0x23d);
423 if(temp1 & temp) return TRUE; 434 if(temp1 & temp) return TRUE;
424 } 435 }
425 } 436 }
426 return FALSE; 437 return FALSE;
427} 438}
428#endif 439#endif
429 440
@@ -432,85 +443,76 @@ SiS_CR36BIOSWord23d(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
432/*********************************************/ 443/*********************************************/
433 444
434void 445void
435SiS_DDC2Delay(SiS_Private *SiS_Pr, USHORT delaytime) 446SiS_DDC2Delay(struct SiS_Private *SiS_Pr, unsigned int delaytime)
436{ 447{
437 USHORT i, j; 448 unsigned int i, j;
438 449
439 for(i=0; i<delaytime; i++) { 450 for(i = 0; i < delaytime; i++) {
440 j += SiS_GetReg(SiS_Pr->SiS_P3c4,0x05); 451 j += SiS_GetReg(SiS_Pr->SiS_P3c4,0x05);
441 } 452 }
442} 453}
443 454
444#if defined(SIS300) || defined(SIS315H) 455#if defined(SIS300) || defined(SIS315H)
445static void 456static void
446SiS_GenericDelay(SiS_Private *SiS_Pr, USHORT delay) 457SiS_GenericDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
447{ 458{
448 USHORT temp,flag; 459 SiS_DDC2Delay(SiS_Pr, delay * 36);
449
450 flag = SiS_GetRegByte(0x61) & 0x10;
451
452 while(delay) {
453 temp = SiS_GetRegByte(0x61) & 0x10;
454 if(temp == flag) continue;
455 flag = temp;
456 delay--;
457 }
458} 460}
459#endif 461#endif
460 462
461#ifdef SIS315H 463#ifdef SIS315H
462static void 464static void
463SiS_LongDelay(SiS_Private *SiS_Pr, USHORT delay) 465SiS_LongDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
464{ 466{
465 while(delay--) { 467 while(delay--) {
466 SiS_GenericDelay(SiS_Pr,0x19df); 468 SiS_GenericDelay(SiS_Pr, 6623);
467 } 469 }
468} 470}
469#endif 471#endif
470 472
471#if defined(SIS300) || defined(SIS315H) 473#if defined(SIS300) || defined(SIS315H)
472static void 474static void
473SiS_ShortDelay(SiS_Private *SiS_Pr, USHORT delay) 475SiS_ShortDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
474{ 476{
475 while(delay--) { 477 while(delay--) {
476 SiS_GenericDelay(SiS_Pr,0x42); 478 SiS_GenericDelay(SiS_Pr, 66);
477 } 479 }
478} 480}
479#endif 481#endif
480 482
481static void 483static void
482SiS_PanelDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DelayTime) 484SiS_PanelDelay(struct SiS_Private *SiS_Pr, unsigned short DelayTime)
483{ 485{
484#if defined(SIS300) || defined(SIS315H) 486#if defined(SIS300) || defined(SIS315H)
485 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 487 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
486 USHORT PanelID, DelayIndex, Delay=0; 488 unsigned short PanelID, DelayIndex, Delay=0;
487#endif 489#endif
488 490
489 if(HwInfo->jChipType < SIS_315H) { 491 if(SiS_Pr->ChipType < SIS_315H) {
490 492
491#ifdef SIS300 493#ifdef SIS300
492 494
493 PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36); 495 PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
494 if(SiS_Pr->SiS_VBType & VB_SISVB) { 496 if(SiS_Pr->SiS_VBType & VB_SISVB) {
495 if(SiS_Pr->SiS_VBType & VB_SIS301) PanelID &= 0xf7; 497 if(SiS_Pr->SiS_VBType & VB_SIS301) PanelID &= 0xf7;
496 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x18) & 0x10)) PanelID = 0x12; 498 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x18) & 0x10)) PanelID = 0x12;
497 } 499 }
498 DelayIndex = PanelID >> 4; 500 DelayIndex = PanelID >> 4;
499 if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) { 501 if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) {
500 Delay = 3; 502 Delay = 3;
501 } else { 503 } else {
502 if(DelayTime >= 2) DelayTime -= 2; 504 if(DelayTime >= 2) DelayTime -= 2;
503 if(!(DelayTime & 0x01)) { 505 if(!(DelayTime & 0x01)) {
504 Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0]; 506 Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
505 } else { 507 } else {
506 Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1]; 508 Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
507 } 509 }
508 if(SiS_Pr->SiS_UseROM) { 510 if(SiS_Pr->SiS_UseROM) {
509 if(ROMAddr[0x220] & 0x40) { 511 if(ROMAddr[0x220] & 0x40) {
510 if(!(DelayTime & 0x01)) Delay = (USHORT)ROMAddr[0x225]; 512 if(!(DelayTime & 0x01)) Delay = (unsigned short)ROMAddr[0x225];
511 else Delay = (USHORT)ROMAddr[0x226]; 513 else Delay = (unsigned short)ROMAddr[0x226];
512 } 514 }
513 } 515 }
514 } 516 }
515 SiS_ShortDelay(SiS_Pr, Delay); 517 SiS_ShortDelay(SiS_Pr, Delay);
516 518
@@ -520,23 +522,23 @@ SiS_PanelDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DelayTime)
520 522
521#ifdef SIS315H 523#ifdef SIS315H
522 524
523 if((HwInfo->jChipType >= SIS_661) || 525 if((SiS_Pr->ChipType >= SIS_661) ||
524 (HwInfo->jChipType <= SIS_315PRO) || 526 (SiS_Pr->ChipType <= SIS_315PRO) ||
525 (HwInfo->jChipType == SIS_330) || 527 (SiS_Pr->ChipType == SIS_330) ||
526 (SiS_Pr->SiS_ROMNew)) { 528 (SiS_Pr->SiS_ROMNew)) {
527 529
528 if(!(DelayTime & 0x01)) { 530 if(!(DelayTime & 0x01)) {
529 SiS_DDC2Delay(SiS_Pr, 0x1000); 531 SiS_DDC2Delay(SiS_Pr, 0x1000);
530 } else { 532 } else {
531 SiS_DDC2Delay(SiS_Pr, 0x4000); 533 SiS_DDC2Delay(SiS_Pr, 0x4000);
532 } 534 }
533 535
534 } else if((SiS_Pr->SiS_IF_DEF_LVDS == 1) /* || 536 } else if((SiS_Pr->SiS_IF_DEF_LVDS == 1) /* ||
535 (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) || 537 (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
536 (SiS_Pr->SiS_CustomT == CUT_CLEVO1400) */ ) { /* 315 series, LVDS; Special */ 538 (SiS_Pr->SiS_CustomT == CUT_CLEVO1400) */ ) { /* 315 series, LVDS; Special */
537 539
538 if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { 540 if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
539 PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36); 541 PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
540 if(SiS_Pr->SiS_CustomT == CUT_CLEVO1400) { 542 if(SiS_Pr->SiS_CustomT == CUT_CLEVO1400) {
541 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1b) & 0x10)) PanelID = 0x12; 543 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1b) & 0x10)) PanelID = 0x12;
542 } 544 }
@@ -546,35 +548,35 @@ SiS_PanelDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DelayTime)
546 DelayIndex = PanelID >> 4; 548 DelayIndex = PanelID >> 4;
547 } 549 }
548 if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) { 550 if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) {
549 Delay = 3; 551 Delay = 3;
550 } else { 552 } else {
551 if(DelayTime >= 2) DelayTime -= 2; 553 if(DelayTime >= 2) DelayTime -= 2;
552 if(!(DelayTime & 0x01)) { 554 if(!(DelayTime & 0x01)) {
553 Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[0]; 555 Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[0];
554 } else { 556 } else {
555 Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[1]; 557 Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[1];
556 } 558 }
557 if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) { 559 if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
558 if(ROMAddr[0x13c] & 0x40) { 560 if(ROMAddr[0x13c] & 0x40) {
559 if(!(DelayTime & 0x01)) { 561 if(!(DelayTime & 0x01)) {
560 Delay = (USHORT)ROMAddr[0x17e]; 562 Delay = (unsigned short)ROMAddr[0x17e];
561 } else { 563 } else {
562 Delay = (USHORT)ROMAddr[0x17f]; 564 Delay = (unsigned short)ROMAddr[0x17f];
563 } 565 }
564 } 566 }
565 } 567 }
566 } 568 }
567 SiS_ShortDelay(SiS_Pr, Delay); 569 SiS_ShortDelay(SiS_Pr, Delay);
568 } 570 }
569 571
570 } else if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 315 series, all bridges */ 572 } else if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 315 series, all bridges */
571 573
572 DelayIndex = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4; 574 DelayIndex = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
573 if(!(DelayTime & 0x01)) { 575 if(!(DelayTime & 0x01)) {
574 Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0]; 576 Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
575 } else { 577 } else {
576 Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1]; 578 Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
577 } 579 }
578 Delay <<= 8; 580 Delay <<= 8;
579 SiS_DDC2Delay(SiS_Pr, Delay); 581 SiS_DDC2Delay(SiS_Pr, Delay);
580 582
@@ -587,12 +589,11 @@ SiS_PanelDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DelayTime)
587 589
588#ifdef SIS315H 590#ifdef SIS315H
589static void 591static void
590SiS_PanelDelayLoop(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 592SiS_PanelDelayLoop(struct SiS_Private *SiS_Pr, unsigned short DelayTime, unsigned short DelayLoop)
591 USHORT DelayTime, USHORT DelayLoop)
592{ 593{
593 int i; 594 int i;
594 for(i=0; i<DelayLoop; i++) { 595 for(i = 0; i < DelayLoop; i++) {
595 SiS_PanelDelay(SiS_Pr, HwInfo, DelayTime); 596 SiS_PanelDelay(SiS_Pr, DelayTime);
596 } 597 }
597} 598}
598#endif 599#endif
@@ -602,86 +603,86 @@ SiS_PanelDelayLoop(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
602/*********************************************/ 603/*********************************************/
603 604
604void 605void
605SiS_WaitRetrace1(SiS_Private *SiS_Pr) 606SiS_WaitRetrace1(struct SiS_Private *SiS_Pr)
606{ 607{
607 USHORT watchdog; 608 unsigned short watchdog;
608 609
609 if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xc0) return; 610 if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xc0) return;
610 if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80)) return; 611 if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80)) return;
611 612
612 watchdog = 65535; 613 watchdog = 65535;
613 while((SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08) && --watchdog); 614 while((SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08) && --watchdog);
614 watchdog = 65535; 615 watchdog = 65535;
615 while((!(SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08)) && --watchdog); 616 while((!(SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08)) && --watchdog);
616} 617}
617 618
618#if defined(SIS300) || defined(SIS315H) 619#if defined(SIS300) || defined(SIS315H)
619static void 620static void
620SiS_WaitRetrace2(SiS_Private *SiS_Pr, USHORT reg) 621SiS_WaitRetrace2(struct SiS_Private *SiS_Pr, unsigned short reg)
621{ 622{
622 USHORT watchdog; 623 unsigned short watchdog;
623 624
624 watchdog = 65535; 625 watchdog = 65535;
625 while((SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02) && --watchdog); 626 while((SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02) && --watchdog);
626 watchdog = 65535; 627 watchdog = 65535;
627 while((!(SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02)) && --watchdog); 628 while((!(SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02)) && --watchdog);
628} 629}
629#endif 630#endif
630 631
631static void 632static void
632SiS_WaitVBRetrace(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 633SiS_WaitVBRetrace(struct SiS_Private *SiS_Pr)
633{ 634{
634 if(HwInfo->jChipType < SIS_315H) { 635 if(SiS_Pr->ChipType < SIS_315H) {
635#ifdef SIS300 636#ifdef SIS300
636 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 637 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
637 if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x20)) return; 638 if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x20)) return;
638 } 639 }
639 if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x80)) { 640 if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x80)) {
640 SiS_WaitRetrace1(SiS_Pr); 641 SiS_WaitRetrace1(SiS_Pr);
641 } else { 642 } else {
642 SiS_WaitRetrace2(SiS_Pr, 0x25); 643 SiS_WaitRetrace2(SiS_Pr, 0x25);
643 } 644 }
644#endif 645#endif
645 } else { 646 } else {
646#ifdef SIS315H 647#ifdef SIS315H
647 if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x40)) { 648 if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x40)) {
648 SiS_WaitRetrace1(SiS_Pr); 649 SiS_WaitRetrace1(SiS_Pr);
649 } else { 650 } else {
650 SiS_WaitRetrace2(SiS_Pr, 0x30); 651 SiS_WaitRetrace2(SiS_Pr, 0x30);
651 } 652 }
652#endif 653#endif
653 } 654 }
654} 655}
655 656
656static void 657static void
657SiS_VBWait(SiS_Private *SiS_Pr) 658SiS_VBWait(struct SiS_Private *SiS_Pr)
658{ 659{
659 USHORT tempal,temp,i,j; 660 unsigned short tempal,temp,i,j;
660 661
661 temp = 0; 662 temp = 0;
662 for(i=0; i<3; i++) { 663 for(i = 0; i < 3; i++) {
663 for(j=0; j<100; j++) { 664 for(j = 0; j < 100; j++) {
664 tempal = SiS_GetRegByte(SiS_Pr->SiS_P3da); 665 tempal = SiS_GetRegByte(SiS_Pr->SiS_P3da);
665 if(temp & 0x01) { 666 if(temp & 0x01) {
666 if((tempal & 0x08)) continue; 667 if((tempal & 0x08)) continue;
667 else break; 668 else break;
668 } else { 669 } else {
669 if(!(tempal & 0x08)) continue; 670 if(!(tempal & 0x08)) continue;
670 else break; 671 else break;
671 } 672 }
672 } 673 }
673 temp ^= 0x01; 674 temp ^= 0x01;
674 } 675 }
675} 676}
676 677
677static void 678static void
678SiS_VBLongWait(SiS_Private *SiS_Pr) 679SiS_VBLongWait(struct SiS_Private *SiS_Pr)
679{ 680{
680 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 681 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
681 SiS_VBWait(SiS_Pr); 682 SiS_VBWait(SiS_Pr);
682 } else { 683 } else {
683 SiS_WaitRetrace1(SiS_Pr); 684 SiS_WaitRetrace1(SiS_Pr);
684 } 685 }
685} 686}
686 687
687/*********************************************/ 688/*********************************************/
@@ -690,237 +691,225 @@ SiS_VBLongWait(SiS_Private *SiS_Pr)
690 691
691#ifdef SIS300 692#ifdef SIS300
692static BOOLEAN 693static BOOLEAN
693SiS_Is301B(SiS_Private *SiS_Pr) 694SiS_Is301B(struct SiS_Private *SiS_Pr)
694{ 695{
695 if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01) >= 0xb0) return TRUE; 696 if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01) >= 0xb0) return TRUE;
696 return FALSE; 697 return FALSE;
697} 698}
698#endif 699#endif
699 700
700static BOOLEAN 701static BOOLEAN
701SiS_CRT2IsLCD(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 702SiS_CRT2IsLCD(struct SiS_Private *SiS_Pr)
702{ 703{
703 USHORT flag; 704 if(SiS_Pr->ChipType == SIS_730) {
704 705 if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x20) return TRUE;
705 if(HwInfo->jChipType == SIS_730) { 706 }
706 flag = SiS_GetReg(SiS_Pr->SiS_P3c4,0x13); 707 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & 0x20) return TRUE;
707 if(flag & 0x20) return TRUE; 708 return FALSE;
708 }
709 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
710 if(flag & 0x20) return TRUE;
711 return FALSE;
712} 709}
713 710
714BOOLEAN 711BOOLEAN
715SiS_IsDualEdge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 712SiS_IsDualEdge(struct SiS_Private *SiS_Pr)
716{ 713{
717#ifdef SIS315H 714#ifdef SIS315H
718 USHORT flag; 715 if(SiS_Pr->ChipType >= SIS_315H) {
719 716 if((SiS_Pr->ChipType != SIS_650) || (SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0)) {
720 if(HwInfo->jChipType >= SIS_315H) { 717 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableDualEdge) return TRUE;
721 if((HwInfo->jChipType != SIS_650) || (SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0)) { 718 }
722 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 719 }
723 if(flag & EnableDualEdge) return TRUE;
724 }
725 }
726#endif 720#endif
727 return FALSE; 721 return FALSE;
728} 722}
729 723
730BOOLEAN 724BOOLEAN
731SiS_IsVAMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 725SiS_IsVAMode(struct SiS_Private *SiS_Pr)
732{ 726{
733#ifdef SIS315H 727#ifdef SIS315H
734 USHORT flag; 728 unsigned short flag;
735 729
736 if(HwInfo->jChipType >= SIS_315H) { 730 if(SiS_Pr->ChipType >= SIS_315H) {
737 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 731 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
738 if((flag & EnableDualEdge) && (flag & SetToLCDA)) return TRUE; 732 if((flag & EnableDualEdge) && (flag & SetToLCDA)) return TRUE;
739 } 733 }
740#endif 734#endif
741 return FALSE; 735 return FALSE;
742} 736}
743 737
744#ifdef SIS315H 738#ifdef SIS315H
745static BOOLEAN 739static BOOLEAN
746SiS_IsVAorLCD(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 740SiS_IsVAorLCD(struct SiS_Private *SiS_Pr)
747{ 741{
748 if(SiS_IsVAMode(SiS_Pr,HwInfo)) return TRUE; 742 if(SiS_IsVAMode(SiS_Pr)) return TRUE;
749 if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) return TRUE; 743 if(SiS_CRT2IsLCD(SiS_Pr)) return TRUE;
750 return FALSE; 744 return FALSE;
751} 745}
752#endif 746#endif
753 747
754static BOOLEAN 748static BOOLEAN
755SiS_IsDualLink(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 749SiS_IsDualLink(struct SiS_Private *SiS_Pr)
756{ 750{
757#ifdef SIS315H 751#ifdef SIS315H
758 if(HwInfo->jChipType >= SIS_315H) { 752 if(SiS_Pr->ChipType >= SIS_315H) {
759 if((SiS_CRT2IsLCD(SiS_Pr, HwInfo)) || 753 if((SiS_CRT2IsLCD(SiS_Pr)) ||
760 (SiS_IsVAMode(SiS_Pr, HwInfo))) { 754 (SiS_IsVAMode(SiS_Pr))) {
761 if(SiS_Pr->SiS_LCDInfo & LCDDualLink) return TRUE; 755 if(SiS_Pr->SiS_LCDInfo & LCDDualLink) return TRUE;
762 } 756 }
763 } 757 }
764#endif 758#endif
765 return FALSE; 759 return FALSE;
766} 760}
767 761
768#ifdef SIS315H 762#ifdef SIS315H
769static BOOLEAN 763static BOOLEAN
770SiS_TVEnabled(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 764SiS_TVEnabled(struct SiS_Private *SiS_Pr)
771{ 765{
772 if((SiS_GetReg(SiS_Pr->SiS_Part2Port,0x00) & 0x0f) != 0x0c) return TRUE; 766 if((SiS_GetReg(SiS_Pr->SiS_Part2Port,0x00) & 0x0f) != 0x0c) return TRUE;
773 if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS301LV302LV)) { 767 if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
774 if(SiS_GetReg(SiS_Pr->SiS_Part2Port,0x4d) & 0x10) return TRUE; 768 if(SiS_GetReg(SiS_Pr->SiS_Part2Port,0x4d) & 0x10) return TRUE;
775 } 769 }
776 return FALSE; 770 return FALSE;
777} 771}
778#endif 772#endif
779 773
780#ifdef SIS315H 774#ifdef SIS315H
781static BOOLEAN 775static BOOLEAN
782SiS_LCDAEnabled(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 776SiS_LCDAEnabled(struct SiS_Private *SiS_Pr)
783{ 777{
784 if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x13) & 0x04) return TRUE; 778 if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x13) & 0x04) return TRUE;
785 return FALSE; 779 return FALSE;
786} 780}
787#endif 781#endif
788 782
789#ifdef SIS315H 783#ifdef SIS315H
790static BOOLEAN 784static BOOLEAN
791SiS_WeHaveBacklightCtrl(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 785SiS_WeHaveBacklightCtrl(struct SiS_Private *SiS_Pr)
792{ 786{
793 if((HwInfo->jChipType >= SIS_315H) && (HwInfo->jChipType < SIS_661)) { 787 if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) {
794 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0x10) return TRUE; 788 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0x10) return TRUE;
795 } 789 }
796 return FALSE; 790 return FALSE;
797} 791}
798#endif 792#endif
799 793
800#ifdef SIS315H 794#ifdef SIS315H
801static BOOLEAN 795static BOOLEAN
802SiS_IsNotM650orLater(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 796SiS_IsNotM650orLater(struct SiS_Private *SiS_Pr)
803{ 797{
804 USHORT flag; 798 unsigned short flag;
805 799
806 if(HwInfo->jChipType == SIS_650) { 800 if(SiS_Pr->ChipType == SIS_650) {
807 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f); 801 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0;
808 flag &= 0xF0; 802 /* Check for revision != A0 only */
809 /* Check for revision != A0 only */ 803 if((flag == 0xe0) || (flag == 0xc0) ||
810 if((flag == 0xe0) || (flag == 0xc0) || 804 (flag == 0xb0) || (flag == 0x90)) return FALSE;
811 (flag == 0xb0) || (flag == 0x90)) return FALSE; 805 } else if(SiS_Pr->ChipType >= SIS_661) return FALSE;
812 } else if(HwInfo->jChipType >= SIS_661) return FALSE; 806 return TRUE;
813 return TRUE;
814} 807}
815#endif 808#endif
816 809
817#ifdef SIS315H 810#ifdef SIS315H
818static BOOLEAN 811static BOOLEAN
819SiS_IsYPbPr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 812SiS_IsYPbPr(struct SiS_Private *SiS_Pr)
820{ 813{
821 USHORT flag; 814 if(SiS_Pr->ChipType >= SIS_315H) {
822 815 /* YPrPb = 0x08 */
823 if(HwInfo->jChipType >= SIS_315H) { 816 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHYPbPr) return TRUE;
824 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 817 }
825 if(flag & EnableCHYPbPr) return TRUE; /* = YPrPb = 0x08 */ 818 return FALSE;
826 }
827 return FALSE;
828} 819}
829#endif 820#endif
830 821
831#ifdef SIS315H 822#ifdef SIS315H
832static BOOLEAN 823static BOOLEAN
833SiS_IsChScart(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 824SiS_IsChScart(struct SiS_Private *SiS_Pr)
834{ 825{
835 USHORT flag; 826 if(SiS_Pr->ChipType >= SIS_315H) {
836 827 /* Scart = 0x04 */
837 if(HwInfo->jChipType >= SIS_315H) { 828 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHScart) return TRUE;
838 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 829 }
839 if(flag & EnableCHScart) return TRUE; /* = Scart = 0x04 */ 830 return FALSE;
840 }
841 return FALSE;
842} 831}
843#endif 832#endif
844 833
845#ifdef SIS315H 834#ifdef SIS315H
846static BOOLEAN 835static BOOLEAN
847SiS_IsTVOrYPbPrOrScart(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 836SiS_IsTVOrYPbPrOrScart(struct SiS_Private *SiS_Pr)
848{ 837{
849 USHORT flag; 838 unsigned short flag;
850 839
851 if(HwInfo->jChipType >= SIS_315H) { 840 if(SiS_Pr->ChipType >= SIS_315H) {
852 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); 841 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
853 if(flag & SetCRT2ToTV) return TRUE; 842 if(flag & SetCRT2ToTV) return TRUE;
854 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 843 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
855 if(flag & EnableCHYPbPr) return TRUE; /* = YPrPb = 0x08 */ 844 if(flag & EnableCHYPbPr) return TRUE; /* = YPrPb = 0x08 */
856 if(flag & EnableCHScart) return TRUE; /* = Scart = 0x04 - TW */ 845 if(flag & EnableCHScart) return TRUE; /* = Scart = 0x04 - TW */
857 } else { 846 } else {
858 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); 847 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
859 if(flag & SetCRT2ToTV) return TRUE; 848 if(flag & SetCRT2ToTV) return TRUE;
860 } 849 }
861 return FALSE; 850 return FALSE;
862} 851}
863#endif 852#endif
864 853
865#ifdef SIS315H 854#ifdef SIS315H
866static BOOLEAN 855static BOOLEAN
867SiS_IsLCDOrLCDA(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 856SiS_IsLCDOrLCDA(struct SiS_Private *SiS_Pr)
868{ 857{
869 USHORT flag; 858 unsigned short flag;
870 859
871 if(HwInfo->jChipType >= SIS_315H) { 860 if(SiS_Pr->ChipType >= SIS_315H) {
872 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); 861 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
873 if(flag & SetCRT2ToLCD) return TRUE; 862 if(flag & SetCRT2ToLCD) return TRUE;
874 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 863 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
875 if(flag & SetToLCDA) return TRUE; 864 if(flag & SetToLCDA) return TRUE;
876 } else { 865 } else {
877 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); 866 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
878 if(flag & SetCRT2ToLCD) return TRUE; 867 if(flag & SetCRT2ToLCD) return TRUE;
879 } 868 }
880 return FALSE; 869 return FALSE;
881} 870}
882#endif 871#endif
883 872
884static BOOLEAN 873static BOOLEAN
885SiS_BridgeIsOn(SiS_Private *SiS_Pr) 874SiS_HaveBridge(struct SiS_Private *SiS_Pr)
886{ 875{
887 USHORT flag; 876 unsigned short flag;
888 877
889 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 878 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
890 return TRUE; 879 return TRUE;
891 } else if(SiS_Pr->SiS_VBType & VB_SISVB) { 880 } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
892 flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00); 881 flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
893 if((flag == 1) || (flag == 2)) return TRUE; 882 if((flag == 1) || (flag == 2)) return TRUE;
894 } 883 }
895 return FALSE; 884 return FALSE;
896} 885}
897 886
898static BOOLEAN 887static BOOLEAN
899SiS_BridgeIsEnabled(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 888SiS_BridgeIsEnabled(struct SiS_Private *SiS_Pr)
900{ 889{
901 USHORT flag; 890 unsigned short flag;
902 891
903 if(SiS_BridgeIsOn(SiS_Pr)) { 892 if(SiS_HaveBridge(SiS_Pr)) {
904 flag = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00); 893 flag = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
905 if(HwInfo->jChipType < SIS_315H) { 894 if(SiS_Pr->ChipType < SIS_315H) {
906 flag &= 0xa0; 895 flag &= 0xa0;
907 if((flag == 0x80) || (flag == 0x20)) return TRUE; 896 if((flag == 0x80) || (flag == 0x20)) return TRUE;
908 } else { 897 } else {
909 flag &= 0x50; 898 flag &= 0x50;
910 if((flag == 0x40) || (flag == 0x10)) return TRUE; 899 if((flag == 0x40) || (flag == 0x10)) return TRUE;
911 } 900 }
912 } 901 }
913 return FALSE; 902 return FALSE;
914} 903}
915 904
916static BOOLEAN 905static BOOLEAN
917SiS_BridgeInSlavemode(SiS_Private *SiS_Pr) 906SiS_BridgeInSlavemode(struct SiS_Private *SiS_Pr)
918{ 907{
919 USHORT flag1; 908 unsigned short flag1;
920 909
921 flag1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31); 910 flag1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31);
922 if(flag1 & (SetInSlaveMode >> 8)) return TRUE; 911 if(flag1 & (SetInSlaveMode >> 8)) return TRUE;
923 return FALSE; 912 return FALSE;
924} 913}
925 914
926/*********************************************/ 915/*********************************************/
@@ -928,119 +917,97 @@ SiS_BridgeInSlavemode(SiS_Private *SiS_Pr)
928/*********************************************/ 917/*********************************************/
929 918
930/* Setup general purpose IO for Chrontel communication */ 919/* Setup general purpose IO for Chrontel communication */
920#ifdef SIS300
931void 921void
932SiS_SetChrontelGPIO(SiS_Private *SiS_Pr, USHORT myvbinfo) 922SiS_SetChrontelGPIO(struct SiS_Private *SiS_Pr, unsigned short myvbinfo)
933{ 923{
934 unsigned long acpibase; 924 unsigned int acpibase;
935 unsigned short temp; 925 unsigned short temp;
936 926
937 if(!(SiS_Pr->SiS_ChSW)) return; 927 if(!(SiS_Pr->SiS_ChSW)) return;
938 928
939#ifdef LINUX_KERNEL 929#ifdef SIS_LINUX_KERNEL
940 SiS_SetRegLong(0xcf8,0x80000874); /* get ACPI base */ 930 acpibase = sisfb_read_lpc_pci_dword(SiS_Pr, 0x74);
941 acpibase = SiS_GetRegLong(0xcfc);
942#else 931#else
943 acpibase = pciReadLong(0x00000800, 0x74); 932 acpibase = pciReadLong(0x00000800, 0x74);
944#endif 933#endif
945 acpibase &= 0xFFFF; 934 acpibase &= 0xFFFF;
946 temp = SiS_GetRegShort((USHORT)(acpibase + 0x3c)); /* ACPI register 0x3c: GP Event 1 I/O mode select */ 935 if(!acpibase) return;
936 temp = SiS_GetRegShort((acpibase + 0x3c)); /* ACPI register 0x3c: GP Event 1 I/O mode select */
947 temp &= 0xFEFF; 937 temp &= 0xFEFF;
948 SiS_SetRegShort((USHORT)(acpibase + 0x3c), temp); 938 SiS_SetRegShort((acpibase + 0x3c), temp);
949 temp = SiS_GetRegShort((USHORT)(acpibase + 0x3c)); 939 temp = SiS_GetRegShort((acpibase + 0x3c));
950 temp = SiS_GetRegShort((USHORT)(acpibase + 0x3a)); /* ACPI register 0x3a: GP Pin Level (low/high) */ 940 temp = SiS_GetRegShort((acpibase + 0x3a)); /* ACPI register 0x3a: GP Pin Level (low/high) */
951 temp &= 0xFEFF; 941 temp &= 0xFEFF;
952 if(!(myvbinfo & SetCRT2ToTV)) temp |= 0x0100; 942 if(!(myvbinfo & SetCRT2ToTV)) temp |= 0x0100;
953 SiS_SetRegShort((USHORT)(acpibase + 0x3a), temp); 943 SiS_SetRegShort((acpibase + 0x3a), temp);
954 temp = SiS_GetRegShort((USHORT)(acpibase + 0x3a)); 944 temp = SiS_GetRegShort((acpibase + 0x3a));
955} 945}
946#endif
956 947
957void 948void
958SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 949SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
959 PSIS_HW_INFO HwInfo, int checkcrt2mode) 950 unsigned short ModeIdIndex, int checkcrt2mode)
960{ 951{
961 USHORT tempax,tempbx,temp; 952 unsigned short tempax, tempbx, temp;
962 USHORT modeflag, resinfo=0; 953 unsigned short modeflag, resinfo = 0;
963 954
964 if(ModeNo <= 0x13) { 955 SiS_Pr->SiS_SetFlag = 0;
965 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
966 } else if(SiS_Pr->UseCustomMode) {
967 modeflag = SiS_Pr->CModeFlag;
968 } else {
969 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
970 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
971 }
972 956
973 SiS_Pr->SiS_SetFlag = 0; 957 modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
974 958
975 SiS_Pr->SiS_ModeType = modeflag & ModeTypeMask; 959 SiS_Pr->SiS_ModeType = modeflag & ModeTypeMask;
976 960
977 tempbx = 0; 961 if((ModeNo > 0x13) && (!SiS_Pr->UseCustomMode)) {
978 if(SiS_BridgeIsOn(SiS_Pr)) { 962 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
979 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); 963 }
980#if 0 964
981 if(HwInfo->jChipType < SIS_661) { 965 tempbx = 0;
982 /* NO - YPbPr not set yet ! */ 966
983 if(SiS_Pr->SiS_YPbPr & <all ypbpr except 525i>) { 967 if(SiS_HaveBridge(SiS_Pr)) {
984 temp &= (SetCRT2ToHiVision | SwitchCRT2 | SetSimuScanMode); /* 0x83 */ 968
985 temp |= SetCRT2ToHiVision; /* 0x80 */ 969 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
986 } 970 tempbx |= temp;
987 if(SiS_Pr->SiS_YPbPr & <ypbpr525i>) { 971 tempax = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) << 8;
988 temp &= (SetCRT2ToHiVision | SwitchCRT2 | SetSimuScanMode); /* 0x83 */ 972 tempax &= (DriverMode | LoadDACFlag | SetNotSimuMode | SetPALTV);
989 temp |= SetCRT2ToSVIDEO; /* 0x08 */ 973 tempbx |= tempax;
990 }
991 }
992#endif
993 tempbx |= temp;
994 tempax = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) << 8;
995 tempax &= (DriverMode | LoadDACFlag | SetNotSimuMode | SetPALTV);
996 tempbx |= tempax;
997 974
998#ifdef SIS315H 975#ifdef SIS315H
999 if(HwInfo->jChipType >= SIS_315H) { 976 if(SiS_Pr->ChipType >= SIS_315H) {
1000 if(SiS_Pr->SiS_VBType & VB_SISLCDA) { 977 if(SiS_Pr->SiS_VBType & VB_SISLCDA) {
1001 if(ModeNo == 0x03) { 978 if(ModeNo == 0x03) {
1002 /* Mode 0x03 is never in driver mode */ 979 /* Mode 0x03 is never in driver mode */
1003 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x31,0xbf); 980 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x31,0xbf);
1004 } 981 }
1005 if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8))) { 982 if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8))) {
1006 /* Reset LCDA setting if not driver mode */ 983 /* Reset LCDA setting if not driver mode */
1007 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc); 984 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
1008 } 985 }
1009 if(IS_SIS650) { 986 if(IS_SIS650) {
1010 if(SiS_Pr->SiS_UseLCDA) { 987 if(SiS_Pr->SiS_UseLCDA) {
1011 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xF0) { 988 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xF0) {
1012 if((ModeNo <= 0x13) || (!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8)))) { 989 if((ModeNo <= 0x13) || (!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8)))) {
1013 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x38,(EnableDualEdge | SetToLCDA)); 990 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x38,(EnableDualEdge | SetToLCDA));
1014 } 991 }
1015 } 992 }
1016 } 993 }
1017 } 994 }
1018 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 995 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
1019 if((temp & (EnableDualEdge | SetToLCDA)) == (EnableDualEdge | SetToLCDA)) { 996 if((temp & (EnableDualEdge | SetToLCDA)) == (EnableDualEdge | SetToLCDA)) {
1020 tempbx |= SetCRT2ToLCDA; 997 tempbx |= SetCRT2ToLCDA;
1021 } 998 }
1022 } 999 }
1023 1000
1024 if(SiS_Pr->SiS_VBType & (VB_SIS301LV|VB_SIS302LV|VB_SIS302ELV)) { 1001 if(SiS_Pr->ChipType >= SIS_661) { /* New CR layout */
1025 tempbx &= ~(SetCRT2ToRAMDAC);
1026 }
1027
1028 if(HwInfo->jChipType >= SIS_661) {
1029 tempbx &= ~(SetCRT2ToYPbPr525750 | SetCRT2ToHiVision); 1002 tempbx &= ~(SetCRT2ToYPbPr525750 | SetCRT2ToHiVision);
1030 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 1003 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & 0x04) {
1031 if(SiS_Pr->SiS_VBType & VB_SISYPBPR) { 1004 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xe0;
1032 if(temp & 0x04) { 1005 if(temp == 0x60) tempbx |= SetCRT2ToHiVision;
1033 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xe0; 1006 else if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
1034 if(temp == 0x60) tempbx |= SetCRT2ToHiVision; 1007 tempbx |= SetCRT2ToYPbPr525750;
1035 else tempbx |= SetCRT2ToYPbPr525750;
1036 }
1037 } else if(SiS_Pr->SiS_VBType & VB_SISHIVISION) {
1038 if(temp & 0x04) {
1039 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xe0;
1040 if(temp == 0x60) tempbx |= SetCRT2ToHiVision;
1041 } 1008 }
1042 } 1009 }
1043 } 1010 }
1044 1011
1045 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 1012 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
1046 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 1013 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
@@ -1048,7 +1015,7 @@ SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1048 tempbx |= SetCRT2ToLCDA; 1015 tempbx |= SetCRT2ToLCDA;
1049 } 1016 }
1050 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 1017 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
1051 if(temp & EnableCHYPbPr) { 1018 if(temp & EnableCHYPbPr) {
1052 tempbx |= SetCRT2ToCHYPbPr; 1019 tempbx |= SetCRT2ToCHYPbPr;
1053 } 1020 }
1054 } 1021 }
@@ -1057,44 +1024,49 @@ SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1057 1024
1058#endif /* SIS315H */ 1025#endif /* SIS315H */
1059 1026
1060 if(SiS_Pr->SiS_VBType & VB_SISVB) { 1027 if(!(SiS_Pr->SiS_VBType & VB_SISVGA2)) {
1028 tempbx &= ~(SetCRT2ToRAMDAC);
1029 }
1030
1031 if(SiS_Pr->SiS_VBType & VB_SISVB) {
1061 temp = SetCRT2ToSVIDEO | 1032 temp = SetCRT2ToSVIDEO |
1062 SetCRT2ToAVIDEO | 1033 SetCRT2ToAVIDEO |
1063 SetCRT2ToSCART | 1034 SetCRT2ToSCART |
1064 SetCRT2ToLCDA | 1035 SetCRT2ToLCDA |
1065 SetCRT2ToLCD | 1036 SetCRT2ToLCD |
1066 SetCRT2ToRAMDAC | 1037 SetCRT2ToRAMDAC |
1067 SetCRT2ToHiVision | 1038 SetCRT2ToHiVision |
1068 SetCRT2ToYPbPr525750; 1039 SetCRT2ToYPbPr525750;
1069 } else { 1040 } else {
1070 if(HwInfo->jChipType >= SIS_315H) { 1041 if(SiS_Pr->ChipType >= SIS_315H) {
1071 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 1042 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
1072 temp = SetCRT2ToAVIDEO | 1043 temp = SetCRT2ToAVIDEO |
1073 SetCRT2ToSVIDEO | 1044 SetCRT2ToSVIDEO |
1074 SetCRT2ToSCART | 1045 SetCRT2ToSCART |
1075 SetCRT2ToLCDA | 1046 SetCRT2ToLCDA |
1076 SetCRT2ToLCD | 1047 SetCRT2ToLCD |
1077 SetCRT2ToCHYPbPr; 1048 SetCRT2ToCHYPbPr;
1078 } else { 1049 } else {
1079 temp = SetCRT2ToLCDA | 1050 temp = SetCRT2ToLCDA |
1080 SetCRT2ToLCD; 1051 SetCRT2ToLCD;
1081 } 1052 }
1082 } else { 1053 } else {
1083 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 1054 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
1084 temp = SetCRT2ToTV | SetCRT2ToLCD; 1055 temp = SetCRT2ToTV | SetCRT2ToLCD;
1085 } else { 1056 } else {
1086 temp = SetCRT2ToLCD; 1057 temp = SetCRT2ToLCD;
1087 } 1058 }
1088 } 1059 }
1089 } 1060 }
1061
1062 if(!(tempbx & temp)) {
1063 tempax = DisableCRT2Display;
1064 tempbx = 0;
1065 }
1090 1066
1091 if(!(tempbx & temp)) { 1067 if(SiS_Pr->SiS_VBType & VB_SISVB) {
1092 tempax = DisableCRT2Display;
1093 tempbx = 0;
1094 }
1095 1068
1096 if(SiS_Pr->SiS_VBType & VB_SISVB) { 1069 unsigned short clearmask = ( DriverMode |
1097 USHORT clearmask = ( DriverMode |
1098 DisableCRT2Display | 1070 DisableCRT2Display |
1099 LoadDACFlag | 1071 LoadDACFlag |
1100 SetNotSimuMode | 1072 SetNotSimuMode |
@@ -1102,106 +1074,104 @@ SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1102 SetPALTV | 1074 SetPALTV |
1103 SwitchCRT2 | 1075 SwitchCRT2 |
1104 SetSimuScanMode ); 1076 SetSimuScanMode );
1105 if(tempbx & SetCRT2ToLCDA) tempbx &= (clearmask | SetCRT2ToLCDA); 1077
1078 if(tempbx & SetCRT2ToLCDA) tempbx &= (clearmask | SetCRT2ToLCDA);
1106 if(tempbx & SetCRT2ToRAMDAC) tempbx &= (clearmask | SetCRT2ToRAMDAC); 1079 if(tempbx & SetCRT2ToRAMDAC) tempbx &= (clearmask | SetCRT2ToRAMDAC);
1107 if(tempbx & SetCRT2ToLCD) tempbx &= (clearmask | SetCRT2ToLCD); 1080 if(tempbx & SetCRT2ToLCD) tempbx &= (clearmask | SetCRT2ToLCD);
1108 if(tempbx & SetCRT2ToSCART) tempbx &= (clearmask | SetCRT2ToSCART); 1081 if(tempbx & SetCRT2ToSCART) tempbx &= (clearmask | SetCRT2ToSCART);
1109 if(tempbx & SetCRT2ToHiVision) tempbx &= (clearmask | SetCRT2ToHiVision); 1082 if(tempbx & SetCRT2ToHiVision) tempbx &= (clearmask | SetCRT2ToHiVision);
1110 if(tempbx & SetCRT2ToYPbPr525750) tempbx &= (clearmask | SetCRT2ToYPbPr525750); 1083 if(tempbx & SetCRT2ToYPbPr525750) tempbx &= (clearmask | SetCRT2ToYPbPr525750);
1111 } else { 1084
1112 if(HwInfo->jChipType >= SIS_315H) { 1085 } else {
1086
1087 if(SiS_Pr->ChipType >= SIS_315H) {
1113 if(tempbx & SetCRT2ToLCDA) { 1088 if(tempbx & SetCRT2ToLCDA) {
1114 tempbx &= (0xFF00|SwitchCRT2|SetSimuScanMode); 1089 tempbx &= (0xFF00|SwitchCRT2|SetSimuScanMode);
1115 } 1090 }
1116 } 1091 }
1117 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 1092 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
1118 if(tempbx & SetCRT2ToTV) { 1093 if(tempbx & SetCRT2ToTV) {
1119 tempbx &= (0xFF00|SetCRT2ToTV|SwitchCRT2|SetSimuScanMode); 1094 tempbx &= (0xFF00|SetCRT2ToTV|SwitchCRT2|SetSimuScanMode);
1120 } 1095 }
1121 }
1122 if(tempbx & SetCRT2ToLCD) {
1123 tempbx &= (0xFF00|SetCRT2ToLCD|SwitchCRT2|SetSimuScanMode);
1124 } 1096 }
1125 if(HwInfo->jChipType >= SIS_315H) { 1097 if(tempbx & SetCRT2ToLCD) {
1098 tempbx &= (0xFF00|SetCRT2ToLCD|SwitchCRT2|SetSimuScanMode);
1099 }
1100 if(SiS_Pr->ChipType >= SIS_315H) {
1126 if(tempbx & SetCRT2ToLCDA) { 1101 if(tempbx & SetCRT2ToLCDA) {
1127 tempbx |= SetCRT2ToLCD; 1102 tempbx |= SetCRT2ToLCD;
1128 } 1103 }
1129 } 1104 }
1105
1130 } 1106 }
1131 1107
1132 if(tempax & DisableCRT2Display) { 1108 if(tempax & DisableCRT2Display) {
1133 if(!(tempbx & (SwitchCRT2 | SetSimuScanMode))) { 1109 if(!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
1134 tempbx = SetSimuScanMode | DisableCRT2Display; 1110 tempbx = SetSimuScanMode | DisableCRT2Display;
1135 } 1111 }
1136 } 1112 }
1137 1113
1138 if(!(tempbx & DriverMode)) tempbx |= SetSimuScanMode; 1114 if(!(tempbx & DriverMode)) tempbx |= SetSimuScanMode;
1139 1115
1140 /* LVDS/CHRONTEL (LCD/TV) and 301BDH (LCD) can only be slave in 8bpp modes */ 1116 /* LVDS/CHRONTEL (LCD/TV) and 301BDH (LCD) can only be slave in 8bpp modes */
1141 if(SiS_Pr->SiS_ModeType <= ModeVGA) { 1117 if(SiS_Pr->SiS_ModeType <= ModeVGA) {
1142 if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) || 1118 if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
1143 ((SiS_Pr->SiS_VBType & VB_NoLCD) && (tempbx & SetCRT2ToLCD)) ) { 1119 ((SiS_Pr->SiS_VBType & VB_NoLCD) && (tempbx & SetCRT2ToLCD)) ) {
1144 modeflag &= (~CRT2Mode); 1120 modeflag &= (~CRT2Mode);
1145 } 1121 }
1146 } 1122 }
1147 1123
1148 if(!(tempbx & SetSimuScanMode)) { 1124 if(!(tempbx & SetSimuScanMode)) {
1149 if(tempbx & SwitchCRT2) { 1125 if(tempbx & SwitchCRT2) {
1150 if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) { 1126 if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) {
1151 if( (HwInfo->jChipType >= SIS_315H) && 1127 if(resinfo != SIS_RI_1600x1200) {
1152 (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) ) { 1128 tempbx |= SetSimuScanMode;
1153 if(resinfo != SIS_RI_1600x1200) { 1129 }
1154 tempbx |= SetSimuScanMode;
1155 }
1156 } else {
1157 tempbx |= SetSimuScanMode;
1158 }
1159 } 1130 }
1160 } else { 1131 } else {
1161 if(SiS_BridgeIsEnabled(SiS_Pr,HwInfo)) { 1132 if(SiS_BridgeIsEnabled(SiS_Pr)) {
1162 if(!(tempbx & DriverMode)) { 1133 if(!(tempbx & DriverMode)) {
1163 if(SiS_BridgeInSlavemode(SiS_Pr)) { 1134 if(SiS_BridgeInSlavemode(SiS_Pr)) {
1164 tempbx |= SetSimuScanMode; 1135 tempbx |= SetSimuScanMode;
1165 } 1136 }
1166 } 1137 }
1167 } 1138 }
1168 } 1139 }
1169 } 1140 }
1170
1171 if(!(tempbx & DisableCRT2Display)) {
1172 if(tempbx & DriverMode) {
1173 if(tempbx & SetSimuScanMode) {
1174 if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) {
1175 if( (HwInfo->jChipType >= SIS_315H) &&
1176 (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) ) {
1177 if(resinfo != SIS_RI_1600x1200) {
1178 tempbx |= SetInSlaveMode;
1179 }
1180 } else {
1181 tempbx |= SetInSlaveMode;
1182 }
1183 }
1184 }
1185 } else {
1186 tempbx |= SetInSlaveMode;
1187 }
1188 }
1189 1141
1190 } 1142 if(!(tempbx & DisableCRT2Display)) {
1143 if(tempbx & DriverMode) {
1144 if(tempbx & SetSimuScanMode) {
1145 if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) {
1146 if(resinfo != SIS_RI_1600x1200) {
1147 tempbx |= SetInSlaveMode;
1148 }
1149 }
1150 }
1151 } else {
1152 tempbx |= SetInSlaveMode;
1153 }
1154 }
1191 1155
1192 SiS_Pr->SiS_VBInfo = tempbx; 1156 }
1193 1157
1194 if(HwInfo->jChipType == SIS_630) { 1158 SiS_Pr->SiS_VBInfo = tempbx;
1195 SiS_SetChrontelGPIO(SiS_Pr, SiS_Pr->SiS_VBInfo);
1196 }
1197 1159
1198#ifdef TWDEBUG 1160#ifdef SIS300
1199#ifdef LINUX_KERNEL 1161 if(SiS_Pr->ChipType == SIS_630) {
1200 printk(KERN_DEBUG "sisfb: (VBInfo= 0x%04x, SetFlag=0x%04x)\n", 1162 SiS_SetChrontelGPIO(SiS_Pr, SiS_Pr->SiS_VBInfo);
1163 }
1164#endif
1165
1166#ifdef SIS_LINUX_KERNEL
1167#if 0
1168 printk(KERN_DEBUG "sisfb: (init301: VBInfo= 0x%04x, SetFlag=0x%04x)\n",
1201 SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag); 1169 SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag);
1202#endif 1170#endif
1203#ifdef LINUX_XF86 1171#endif
1204 xf86DrvMsgVerb(0, X_PROBED, 3, "(init301: VBInfo=0x%04x, SetFlag=0x%04x)\n", 1172#ifdef SIS_XORG_XF86
1173#ifdef TWDEBUG
1174 xf86DrvMsg(0, X_PROBED, "(init301: VBInfo=0x%04x, SetFlag=0x%04x)\n",
1205 SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag); 1175 SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag);
1206#endif 1176#endif
1207#endif 1177#endif
@@ -1212,41 +1182,41 @@ SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1212/*********************************************/ 1182/*********************************************/
1213 1183
1214void 1184void
1215SiS_SetYPbPr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 1185SiS_SetYPbPr(struct SiS_Private *SiS_Pr)
1216{ 1186{
1217 1187
1218 UCHAR temp; 1188 unsigned char temp;
1219 1189
1220 /* Note: This variable is only used on 30xLV systems. 1190 /* Note: This variable is only used on 30xLV systems.
1221 * CR38 has a different meaning on LVDS/CH7019 systems. 1191 * CR38 has a different meaning on LVDS/CH7019 systems.
1222 * On 661 and later, these bits moved to CR35. 1192 * On 661 and later, these bits moved to CR35.
1223 * 1193 *
1224 * On 301, 301B, only HiVision 1080i is supported. 1194 * On 301, 301B, only HiVision 1080i is supported.
1225 * On 30xLV, 301C, only YPbPr 1080i is supported. 1195 * On 30xLV, 301C, only YPbPr 1080i is supported.
1226 */ 1196 */
1227 1197
1228 SiS_Pr->SiS_YPbPr = 0; 1198 SiS_Pr->SiS_YPbPr = 0;
1229 if(HwInfo->jChipType >= SIS_661) return; 1199 if(SiS_Pr->ChipType >= SIS_661) return;
1230 1200
1231 if(SiS_Pr->SiS_VBType) { 1201 if(SiS_Pr->SiS_VBType) {
1232 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { 1202 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
1233 SiS_Pr->SiS_YPbPr = YPbPrHiVision; 1203 SiS_Pr->SiS_YPbPr = YPbPrHiVision;
1234 } 1204 }
1235 } 1205 }
1236 1206
1237 if(HwInfo->jChipType >= SIS_315H) { 1207 if(SiS_Pr->ChipType >= SIS_315H) {
1238 if(SiS_Pr->SiS_VBType & (VB_SIS301LV302LV | VB_SIS301C)) { 1208 if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
1239 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 1209 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
1240 if(temp & 0x08) { 1210 if(temp & 0x08) {
1241 switch((temp >> 4)) { 1211 switch((temp >> 4)) {
1242 case 0x00: SiS_Pr->SiS_YPbPr = YPbPr525i; break; 1212 case 0x00: SiS_Pr->SiS_YPbPr = YPbPr525i; break;
1243 case 0x01: SiS_Pr->SiS_YPbPr = YPbPr525p; break; 1213 case 0x01: SiS_Pr->SiS_YPbPr = YPbPr525p; break;
1244 case 0x02: SiS_Pr->SiS_YPbPr = YPbPr750p; break; 1214 case 0x02: SiS_Pr->SiS_YPbPr = YPbPr750p; break;
1245 case 0x03: SiS_Pr->SiS_YPbPr = YPbPrHiVision; break; 1215 case 0x03: SiS_Pr->SiS_YPbPr = YPbPrHiVision; break;
1246 } 1216 }
1247 } 1217 }
1248 } 1218 }
1249 } 1219 }
1250 1220
1251} 1221}
1252 1222
@@ -1255,199 +1225,204 @@ SiS_SetYPbPr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
1255/*********************************************/ 1225/*********************************************/
1256 1226
1257void 1227void
1258SiS_SetTVMode(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, PSIS_HW_INFO HwInfo) 1228SiS_SetTVMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
1259{ 1229{
1260 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 1230 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
1261 USHORT temp, temp1, resinfo = 0, romindex = 0; 1231 unsigned short temp, temp1, resinfo = 0, romindex = 0;
1262 UCHAR OutputSelect = *SiS_Pr->pSiS_OutputSelect; 1232 unsigned char OutputSelect = *SiS_Pr->pSiS_OutputSelect;
1263 1233
1264 SiS_Pr->SiS_TVMode = 0; 1234 SiS_Pr->SiS_TVMode = 0;
1265 1235
1266 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return; 1236 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return;
1267 if(SiS_Pr->UseCustomMode) return; 1237 if(SiS_Pr->UseCustomMode) return;
1268 1238
1269 if(ModeNo > 0x13) { 1239 if(ModeNo > 0x13) {
1270 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; 1240 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
1271 } 1241 }
1272 1242
1273 if(HwInfo->jChipType < SIS_661) { 1243 if(SiS_Pr->ChipType < SIS_661) {
1274 1244
1275 if(SiS_Pr->SiS_VBInfo & SetPALTV) SiS_Pr->SiS_TVMode |= TVSetPAL; 1245 if(SiS_Pr->SiS_VBInfo & SetPALTV) SiS_Pr->SiS_TVMode |= TVSetPAL;
1276 1246
1277 if(SiS_Pr->SiS_VBType & VB_SISVB) { 1247 if(SiS_Pr->SiS_VBType & VB_SISVB) {
1278 temp = 0; 1248 temp = 0;
1279 if((HwInfo->jChipType == SIS_630) || 1249 if((SiS_Pr->ChipType == SIS_630) ||
1280 (HwInfo->jChipType == SIS_730)) { 1250 (SiS_Pr->ChipType == SIS_730)) {
1281 temp = 0x35; 1251 temp = 0x35;
1282 romindex = 0xfe; 1252 romindex = 0xfe;
1283 } else if(HwInfo->jChipType >= SIS_315H) { 1253 } else if(SiS_Pr->ChipType >= SIS_315H) {
1284 temp = 0x38; 1254 temp = 0x38;
1285 romindex = 0xf3; 1255 if(SiS_Pr->ChipType < XGI_20) {
1286 if(HwInfo->jChipType >= SIS_330) romindex = 0x11b; 1256 romindex = 0xf3;
1287 } 1257 if(SiS_Pr->ChipType >= SIS_330) romindex = 0x11b;
1288 if(temp) { 1258 }
1289 if(romindex && SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) { 1259 }
1290 OutputSelect = ROMAddr[romindex]; 1260 if(temp) {
1291 if(!(OutputSelect & EnablePALMN)) { 1261 if(romindex && SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
1292 SiS_SetRegAND(SiS_Pr->SiS_P3d4,temp,0x3F); 1262 OutputSelect = ROMAddr[romindex];
1293 } 1263 if(!(OutputSelect & EnablePALMN)) {
1294 } 1264 SiS_SetRegAND(SiS_Pr->SiS_P3d4,temp,0x3F);
1295 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,temp); 1265 }
1296 if(SiS_Pr->SiS_TVMode & TVSetPAL) { 1266 }
1297 if(temp1 & EnablePALM) { /* 0x40 */ 1267 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,temp);
1298 SiS_Pr->SiS_TVMode |= TVSetPALM; 1268 if(SiS_Pr->SiS_TVMode & TVSetPAL) {
1299 SiS_Pr->SiS_TVMode &= ~TVSetPAL; 1269 if(temp1 & EnablePALM) { /* 0x40 */
1300 } else if(temp1 & EnablePALN) { /* 0x80 */ 1270 SiS_Pr->SiS_TVMode |= TVSetPALM;
1301 SiS_Pr->SiS_TVMode |= TVSetPALN; 1271 SiS_Pr->SiS_TVMode &= ~TVSetPAL;
1302 } 1272 } else if(temp1 & EnablePALN) { /* 0x80 */
1303 } else { 1273 SiS_Pr->SiS_TVMode |= TVSetPALN;
1304 if(temp1 & EnableNTSCJ) { /* 0x40 */ 1274 }
1305 SiS_Pr->SiS_TVMode |= TVSetNTSCJ; 1275 } else {
1306 } 1276 if(temp1 & EnableNTSCJ) { /* 0x40 */
1307 } 1277 SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
1308 } 1278 }
1309 /* Translate HiVision/YPbPr to our new flags */ 1279 }
1310 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { 1280 }
1311 if(SiS_Pr->SiS_YPbPr == YPbPr750p) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p; 1281 /* Translate HiVision/YPbPr to our new flags */
1312 else if(SiS_Pr->SiS_YPbPr == YPbPr525p) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p; 1282 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
1313 else if(SiS_Pr->SiS_YPbPr == YPbPrHiVision) SiS_Pr->SiS_TVMode |= TVSetHiVision; 1283 if(SiS_Pr->SiS_YPbPr == YPbPr750p) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p;
1314 else SiS_Pr->SiS_TVMode |= TVSetYPbPr525i; 1284 else if(SiS_Pr->SiS_YPbPr == YPbPr525p) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p;
1315 if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p | TVSetYPbPr525i)) { 1285 else if(SiS_Pr->SiS_YPbPr == YPbPrHiVision) SiS_Pr->SiS_TVMode |= TVSetHiVision;
1316 SiS_Pr->SiS_VBInfo &= ~SetCRT2ToHiVision; 1286 else SiS_Pr->SiS_TVMode |= TVSetYPbPr525i;
1317 SiS_Pr->SiS_VBInfo |= SetCRT2ToYPbPr525750; 1287 if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p | TVSetYPbPr525i)) {
1318 } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) { 1288 SiS_Pr->SiS_VBInfo &= ~SetCRT2ToHiVision;
1319 SiS_Pr->SiS_TVMode |= TVSetPAL; 1289 SiS_Pr->SiS_VBInfo |= SetCRT2ToYPbPr525750;
1320 } 1290 } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) {
1321 } 1291 SiS_Pr->SiS_TVMode |= TVSetPAL;
1322 } else if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 1292 }
1323 if(SiS_Pr->SiS_CHOverScan) { 1293 }
1324 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { 1294 } else if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
1325 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35); 1295 if(SiS_Pr->SiS_CHOverScan) {
1326 if((temp & TVOverScan) || (SiS_Pr->SiS_CHOverScan == 1)) { 1296 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
1327 SiS_Pr->SiS_TVMode |= TVSetCHOverScan; 1297 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
1328 } 1298 if((temp & TVOverScan) || (SiS_Pr->SiS_CHOverScan == 1)) {
1329 } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { 1299 SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
1330 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x79); 1300 }
1331 if((temp & 0x80) || (SiS_Pr->SiS_CHOverScan == 1)) { 1301 } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
1332 SiS_Pr->SiS_TVMode |= TVSetCHOverScan; 1302 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x79);
1333 } 1303 if((temp & 0x80) || (SiS_Pr->SiS_CHOverScan == 1)) {
1334 } 1304 SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
1335 if(SiS_Pr->SiS_CHSOverScan) { 1305 }
1336 SiS_Pr->SiS_TVMode |= TVSetCHOverScan; 1306 }
1337 } 1307 if(SiS_Pr->SiS_CHSOverScan) {
1338 } 1308 SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
1339 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { 1309 }
1340 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 1310 }
1341 if(SiS_Pr->SiS_TVMode & TVSetPAL) { 1311 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
1342 if(temp & EnablePALM) SiS_Pr->SiS_TVMode |= TVSetPALM; 1312 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
1343 else if(temp & EnablePALN) SiS_Pr->SiS_TVMode |= TVSetPALN; 1313 if(SiS_Pr->SiS_TVMode & TVSetPAL) {
1344 } else { 1314 if(temp & EnablePALM) SiS_Pr->SiS_TVMode |= TVSetPALM;
1345 if(temp & EnableNTSCJ) { 1315 else if(temp & EnablePALN) SiS_Pr->SiS_TVMode |= TVSetPALN;
1346 SiS_Pr->SiS_TVMode |= TVSetNTSCJ; 1316 } else {
1347 } 1317 if(temp & EnableNTSCJ) {
1348 } 1318 SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
1349 } 1319 }
1350 } 1320 }
1321 }
1322 }
1351 1323
1352 } else { /* 661 and later */ 1324 } else { /* 661 and later */
1353 1325
1354 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35); 1326 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
1355 if(temp1 & 0x01) { 1327 if(temp1 & 0x01) {
1356 SiS_Pr->SiS_TVMode |= TVSetPAL; 1328 SiS_Pr->SiS_TVMode |= TVSetPAL;
1357 if(temp1 & 0x08) { 1329 if(temp1 & 0x08) {
1358 SiS_Pr->SiS_TVMode |= TVSetPALN; 1330 SiS_Pr->SiS_TVMode |= TVSetPALN;
1359 } else if(temp1 & 0x04) { 1331 } else if(temp1 & 0x04) {
1360 if(SiS_Pr->SiS_VBType & VB_SISVB) { 1332 if(SiS_Pr->SiS_VBType & VB_SISVB) {
1361 SiS_Pr->SiS_TVMode &= ~TVSetPAL; 1333 SiS_Pr->SiS_TVMode &= ~TVSetPAL;
1362 } 1334 }
1363 SiS_Pr->SiS_TVMode |= TVSetPALM; 1335 SiS_Pr->SiS_TVMode |= TVSetPALM;
1364 } 1336 }
1365 } else { 1337 } else {
1366 if(temp1 & 0x02) { 1338 if(temp1 & 0x02) {
1367 SiS_Pr->SiS_TVMode |= TVSetNTSCJ; 1339 SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
1368 } 1340 }
1369 } 1341 }
1370 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { 1342 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
1371 if(SiS_Pr->SiS_CHOverScan) { 1343 if(SiS_Pr->SiS_CHOverScan) {
1372 if((temp1 & 0x10) || (SiS_Pr->SiS_CHOverScan == 1)) { 1344 if((temp1 & 0x10) || (SiS_Pr->SiS_CHOverScan == 1)) {
1373 SiS_Pr->SiS_TVMode |= TVSetCHOverScan; 1345 SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
1374 } 1346 }
1375 } 1347 }
1376 } 1348 }
1377 if(SiS_Pr->SiS_VBType & VB_SISVB) { 1349 if(SiS_Pr->SiS_VBType & VB_SISVB) {
1378 if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { 1350 if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
1379 temp1 &= 0xe0; 1351 temp1 &= 0xe0;
1380 if(temp1 == 0x00) SiS_Pr->SiS_TVMode |= TVSetYPbPr525i; 1352 if(temp1 == 0x00) SiS_Pr->SiS_TVMode |= TVSetYPbPr525i;
1381 else if(temp1 == 0x20) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p; 1353 else if(temp1 == 0x20) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p;
1382 else if(temp1 == 0x40) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p; 1354 else if(temp1 == 0x40) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p;
1383 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { 1355 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
1384 SiS_Pr->SiS_TVMode |= (TVSetHiVision | TVSetPAL); 1356 SiS_Pr->SiS_TVMode |= (TVSetHiVision | TVSetPAL);
1385 } 1357 }
1386 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750 | SetCRT2ToHiVision)) { 1358 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750 | SetCRT2ToHiVision)) {
1387 if(resinfo == SIS_RI_800x480 || resinfo == SIS_RI_1024x576 || resinfo == SIS_RI_1280x720) { 1359 if(resinfo == SIS_RI_800x480 || resinfo == SIS_RI_1024x576 || resinfo == SIS_RI_1280x720) {
1388 SiS_Pr->SiS_TVMode |= TVAspect169; 1360 SiS_Pr->SiS_TVMode |= TVAspect169;
1389 } else { 1361 } else {
1390 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x39); 1362 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x39);
1391 if(temp1 & 0x02) { 1363 if(temp1 & 0x02) {
1392 if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetHiVision)) { 1364 if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetHiVision)) {
1393 SiS_Pr->SiS_TVMode |= TVAspect169; 1365 SiS_Pr->SiS_TVMode |= TVAspect169;
1394 } else { 1366 } else {
1395 SiS_Pr->SiS_TVMode |= TVAspect43LB; 1367 SiS_Pr->SiS_TVMode |= TVAspect43LB;
1396 } 1368 }
1397 } else { 1369 } else {
1398 SiS_Pr->SiS_TVMode |= TVAspect43; 1370 SiS_Pr->SiS_TVMode |= TVAspect43;
1399 } 1371 }
1400 } 1372 }
1401 } 1373 }
1402 } 1374 }
1403 } 1375 }
1404 1376
1405 if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) SiS_Pr->SiS_TVMode |= TVSetPAL; 1377 if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) SiS_Pr->SiS_TVMode |= TVSetPAL;
1406 1378
1407 if(SiS_Pr->SiS_VBType & VB_SISVB) { 1379 if(SiS_Pr->SiS_VBType & VB_SISVB) {
1408 1380
1409 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { 1381 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
1410 SiS_Pr->SiS_TVMode |= TVSetPAL; 1382 SiS_Pr->SiS_TVMode |= TVSetPAL;
1411 SiS_Pr->SiS_TVMode &= ~(TVSetPALM | TVSetPALN | TVSetNTSCJ); 1383 SiS_Pr->SiS_TVMode &= ~(TVSetPALM | TVSetPALN | TVSetNTSCJ);
1412 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { 1384 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
1413 if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525i | TVSetYPbPr525p | TVSetYPbPr750p)) { 1385 if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525i | TVSetYPbPr525p | TVSetYPbPr750p)) {
1414 SiS_Pr->SiS_TVMode &= ~(TVSetPAL | TVSetNTSCJ | TVSetPALM | TVSetPALN); 1386 SiS_Pr->SiS_TVMode &= ~(TVSetPAL | TVSetNTSCJ | TVSetPALM | TVSetPALN);
1415 } 1387 }
1416 } 1388 }
1417 1389
1418 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { 1390 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
1419 if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) { 1391 if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
1420 SiS_Pr->SiS_TVMode |= TVSetTVSimuMode; 1392 SiS_Pr->SiS_TVMode |= TVSetTVSimuMode;
1421 } 1393 }
1422 } 1394 }
1423 1395
1424 if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { 1396 if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
1425 /* BIOS sets TVNTSC1024 without checking 525p here. Wrong? */ 1397 if(resinfo == SIS_RI_1024x768) {
1426 if(!(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr525p | TVSetYPbPr750p))) { 1398 if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
1427 if(resinfo == SIS_RI_1024x768) { 1399 SiS_Pr->SiS_TVMode |= TVSet525p1024;
1428 SiS_Pr->SiS_TVMode |= TVSetNTSC1024; 1400 } else if(!(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p))) {
1429 } 1401 SiS_Pr->SiS_TVMode |= TVSetNTSC1024;
1430 } 1402 }
1431 } 1403 }
1404 }
1432 1405
1433 SiS_Pr->SiS_TVMode |= TVRPLLDIV2XO; 1406 SiS_Pr->SiS_TVMode |= TVRPLLDIV2XO;
1434 if((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) && 1407 if((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) &&
1435 (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { 1408 (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
1436 SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO; 1409 SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
1437 } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) { 1410 } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
1438 SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO; 1411 SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
1439 } else if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) { 1412 } else if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) {
1440 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) { 1413 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
1441 SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO; 1414 SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
1442 } 1415 }
1443 } 1416 }
1444 1417
1445 } 1418 }
1446 1419
1447 SiS_Pr->SiS_VBInfo &= ~SetPALTV; 1420 SiS_Pr->SiS_VBInfo &= ~SetPALTV;
1448 1421
1422#ifdef SIS_XORG_XF86
1449#ifdef TWDEBUG 1423#ifdef TWDEBUG
1450 xf86DrvMsg(0, X_INFO, "(init301: TVMode %x, VBInfo %x)\n", SiS_Pr->SiS_TVMode, SiS_Pr->SiS_VBInfo); 1424 xf86DrvMsg(0, X_INFO, "(init301: TVMode %x, VBInfo %x)\n", SiS_Pr->SiS_TVMode, SiS_Pr->SiS_VBInfo);
1425#endif
1451#endif 1426#endif
1452} 1427}
1453 1428
@@ -1455,41 +1430,46 @@ SiS_SetTVMode(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, PSIS_HW_IN
1455/* GET LCD INFO */ 1430/* GET LCD INFO */
1456/*********************************************/ 1431/*********************************************/
1457 1432
1458static USHORT 1433static unsigned short
1459SiS_GetBIOSLCDResInfo(SiS_Private *SiS_Pr) 1434SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr)
1460{ 1435{
1461 USHORT temp = SiS_Pr->SiS_LCDResInfo; 1436 unsigned short temp = SiS_Pr->SiS_LCDResInfo;
1462 /* Translate my LCDResInfo to BIOS value */ 1437 /* Translate my LCDResInfo to BIOS value */
1463 if(temp == Panel_1280x768_2) temp = Panel_1280x768; 1438 switch(temp) {
1464 if(temp == Panel_1280x800_2) temp = Panel_1280x800; 1439 case Panel_1280x768_2: temp = Panel_1280x768; break;
1440 case Panel_1280x800_2: temp = Panel_1280x800; break;
1441 case Panel_1280x854: temp = Panel661_1280x854; break;
1442 }
1465 return temp; 1443 return temp;
1466} 1444}
1467 1445
1468static void 1446static void
1469SiS_GetLCDInfoBIOS(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 1447SiS_GetLCDInfoBIOS(struct SiS_Private *SiS_Pr)
1470{ 1448{
1471#ifdef SIS315H 1449#ifdef SIS315H
1472 UCHAR *ROMAddr; 1450 unsigned char *ROMAddr;
1473 USHORT temp; 1451 unsigned short temp;
1474 1452
1453#ifdef SIS_XORG_XF86
1475#ifdef TWDEBUG 1454#ifdef TWDEBUG
1476 xf86DrvMsg(0, X_INFO, "Paneldata driver: [%d %d] [H %d %d] [V %d %d] [C %d 0x%02x 0x%02x]\n", 1455 xf86DrvMsg(0, X_INFO, "Paneldata driver: [%d %d] [H %d %d] [V %d %d] [C %d 0x%02x 0x%02x]\n",
1477 SiS_Pr->PanelHT, SiS_Pr->PanelVT, 1456 SiS_Pr->PanelHT, SiS_Pr->PanelVT,
1478 SiS_Pr->PanelHRS, SiS_Pr->PanelHRE, 1457 SiS_Pr->PanelHRS, SiS_Pr->PanelHRE,
1479 SiS_Pr->PanelVRS, SiS_Pr->PanelVRE, 1458 SiS_Pr->PanelVRS, SiS_Pr->PanelVRE,
1480 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].CLOCK, 1459 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].CLOCK,
1481 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_A, 1460 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_A,
1482 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_B); 1461 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_B);
1483#endif 1462#endif
1463#endif
1484 1464
1485 if((ROMAddr = GetLCDStructPtr661(SiS_Pr, HwInfo))) { 1465 if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) {
1486 if((temp = SISGETROMW(6)) != SiS_Pr->PanelHT) { 1466 if((temp = SISGETROMW(6)) != SiS_Pr->PanelHT) {
1487 SiS_Pr->SiS_NeedRomModeData = TRUE; 1467 SiS_Pr->SiS_NeedRomModeData = TRUE;
1488 SiS_Pr->PanelHT = temp; 1468 SiS_Pr->PanelHT = temp;
1489 } 1469 }
1490 if((temp = SISGETROMW(8)) != SiS_Pr->PanelVT) { 1470 if((temp = SISGETROMW(8)) != SiS_Pr->PanelVT) {
1491 SiS_Pr->SiS_NeedRomModeData = TRUE; 1471 SiS_Pr->SiS_NeedRomModeData = TRUE;
1492 SiS_Pr->PanelVT = temp; 1472 SiS_Pr->PanelVT = temp;
1493 } 1473 }
1494 SiS_Pr->PanelHRS = SISGETROMW(10); 1474 SiS_Pr->PanelHRS = SISGETROMW(10);
1495 SiS_Pr->PanelHRE = SISGETROMW(12); 1475 SiS_Pr->PanelHRE = SISGETROMW(12);
@@ -1497,56 +1477,58 @@ SiS_GetLCDInfoBIOS(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
1497 SiS_Pr->PanelVRE = SISGETROMW(16); 1477 SiS_Pr->PanelVRE = SISGETROMW(16);
1498 SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315; 1478 SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
1499 SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].CLOCK = 1479 SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].CLOCK =
1500 SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].CLOCK = (USHORT)((UCHAR)ROMAddr[18]); 1480 SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].CLOCK = (unsigned short)((unsigned char)ROMAddr[18]);
1501 SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2B = 1481 SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2B =
1502 SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_A = ROMAddr[19]; 1482 SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_A = ROMAddr[19];
1503 SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2C = 1483 SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2C =
1504 SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_B = ROMAddr[20]; 1484 SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_B = ROMAddr[20];
1505 1485
1486#ifdef SIS_XORG_XF86
1506#ifdef TWDEBUG 1487#ifdef TWDEBUG
1507 xf86DrvMsg(0, X_INFO, "Paneldata BIOS: [%d %d] [H %d %d] [V %d %d] [C %d 0x%02x 0x%02x]\n", 1488 xf86DrvMsg(0, X_INFO, "Paneldata BIOS: [%d %d] [H %d %d] [V %d %d] [C %d 0x%02x 0x%02x]\n",
1508 SiS_Pr->PanelHT, SiS_Pr->PanelVT, 1489 SiS_Pr->PanelHT, SiS_Pr->PanelVT,
1509 SiS_Pr->PanelHRS, SiS_Pr->PanelHRE, 1490 SiS_Pr->PanelHRS, SiS_Pr->PanelHRE,
1510 SiS_Pr->PanelVRS, SiS_Pr->PanelVRE, 1491 SiS_Pr->PanelVRS, SiS_Pr->PanelVRE,
1511 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].CLOCK, 1492 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].CLOCK,
1512 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_A, 1493 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_A,
1513 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_B); 1494 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_B);
1514#endif 1495#endif
1496#endif
1515 1497
1516 } 1498 }
1517#endif 1499#endif
1518} 1500}
1519 1501
1520static void 1502static void
1521SiS_CheckScaling(SiS_Private *SiS_Pr, USHORT resinfo, const UCHAR *nonscalingmodes) 1503SiS_CheckScaling(struct SiS_Private *SiS_Pr, unsigned short resinfo,
1522{ 1504 const unsigned char *nonscalingmodes)
1523 int i = 0; 1505{
1524 while(nonscalingmodes[i] != 0xff) { 1506 int i = 0;
1525 if(nonscalingmodes[i++] == resinfo) { 1507 while(nonscalingmodes[i] != 0xff) {
1526 if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) || 1508 if(nonscalingmodes[i++] == resinfo) {
1527 (SiS_Pr->UsePanelScaler == -1)) { 1509 if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) ||
1528 SiS_Pr->SiS_LCDInfo |= DontExpandLCD; 1510 (SiS_Pr->UsePanelScaler == -1)) {
1529 } 1511 SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
1530 break; 1512 }
1531 } 1513 break;
1532 } 1514 }
1515 }
1533} 1516}
1534 1517
1535void 1518void
1536SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 1519SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
1537 PSIS_HW_INFO HwInfo)
1538{ 1520{
1521 unsigned short temp,modeflag,resinfo=0,modexres=0,modeyres=0;
1522 BOOLEAN panelcanscale = FALSE;
1539#ifdef SIS300 1523#ifdef SIS300
1540 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 1524 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
1541 const unsigned char SiS300SeriesLCDRes[] = 1525 static const unsigned char SiS300SeriesLCDRes[] =
1542 { 0, 1, 2, 3, 7, 4, 5, 8, 1526 { 0, 1, 2, 3, 7, 4, 5, 8,
1543 0, 0, 10, 0, 0, 0, 0, 15 }; 1527 0, 0, 10, 0, 0, 0, 0, 15 };
1544#endif 1528#endif
1545#ifdef SIS315H 1529#ifdef SIS315H
1546 UCHAR *myptr = NULL; 1530 unsigned char *myptr = NULL;
1547#endif 1531#endif
1548 USHORT temp,modeflag,resinfo=0,modexres=0,modeyres=0;
1549 BOOLEAN panelcanscale = FALSE;
1550 1532
1551 SiS_Pr->SiS_LCDResInfo = 0; 1533 SiS_Pr->SiS_LCDResInfo = 0;
1552 SiS_Pr->SiS_LCDTypeInfo = 0; 1534 SiS_Pr->SiS_LCDTypeInfo = 0;
@@ -1557,14 +1539,14 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1557 SiS_Pr->PanelVRE = 999; /* VSync end */ 1539 SiS_Pr->PanelVRE = 999; /* VSync end */
1558 SiS_Pr->SiS_NeedRomModeData = FALSE; 1540 SiS_Pr->SiS_NeedRomModeData = FALSE;
1559 1541
1542 /* Alternative 1600x1200@60 timing for 1600x1200 LCDA */
1543 SiS_Pr->Alternate1600x1200 = FALSE;
1544
1560 if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))) return; 1545 if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))) return;
1561 1546
1562 if(ModeNo <= 0x13) { 1547 modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
1563 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; 1548
1564 } else if(SiS_Pr->UseCustomMode) { 1549 if((ModeNo > 0x13) && (!SiS_Pr->UseCustomMode)) {
1565 modeflag = SiS_Pr->CModeFlag;
1566 } else {
1567 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1568 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; 1550 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
1569 modexres = SiS_Pr->SiS_ModeResInfo[resinfo].HTotal; 1551 modexres = SiS_Pr->SiS_ModeResInfo[resinfo].HTotal;
1570 modeyres = SiS_Pr->SiS_ModeResInfo[resinfo].VTotal; 1552 modeyres = SiS_Pr->SiS_ModeResInfo[resinfo].VTotal;
@@ -1575,16 +1557,16 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1575 /* For broken BIOSes: Assume 1024x768 */ 1557 /* For broken BIOSes: Assume 1024x768 */
1576 if(temp == 0) temp = 0x02; 1558 if(temp == 0) temp = 0x02;
1577 1559
1578 if((HwInfo->jChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) { 1560 if((SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
1579 SiS_Pr->SiS_LCDTypeInfo = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x7c) >> 2; 1561 SiS_Pr->SiS_LCDTypeInfo = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x7c) >> 2;
1580 } else if((HwInfo->jChipType < SIS_315H) || (HwInfo->jChipType >= SIS_661)) { 1562 } else if((SiS_Pr->ChipType < SIS_315H) || (SiS_Pr->ChipType >= SIS_661)) {
1581 SiS_Pr->SiS_LCDTypeInfo = temp >> 4; 1563 SiS_Pr->SiS_LCDTypeInfo = temp >> 4;
1582 } else { 1564 } else {
1583 SiS_Pr->SiS_LCDTypeInfo = (temp & 0x0F) - 1; 1565 SiS_Pr->SiS_LCDTypeInfo = (temp & 0x0F) - 1;
1584 } 1566 }
1585 temp &= 0x0f; 1567 temp &= 0x0f;
1586#ifdef SIS300 1568#ifdef SIS300
1587 if(HwInfo->jChipType < SIS_315H) { 1569 if(SiS_Pr->ChipType < SIS_315H) {
1588 /* Very old BIOSes only know 7 sizes (NetVista 2179, 1.01g) */ 1570 /* Very old BIOSes only know 7 sizes (NetVista 2179, 1.01g) */
1589 if(SiS_Pr->SiS_VBType & VB_SIS301) { 1571 if(SiS_Pr->SiS_VBType & VB_SIS301) {
1590 if(temp < 0x0f) temp &= 0x07; 1572 if(temp < 0x0f) temp &= 0x07;
@@ -1595,17 +1577,22 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1595#endif 1577#endif
1596 1578
1597 /* Translate to our internal types */ 1579 /* Translate to our internal types */
1598 if(HwInfo->jChipType == SIS_550) { 1580#ifdef SIS315H
1599 if(temp == Panel310_640x480_2) temp = Panel_640x480_2; 1581 if(SiS_Pr->ChipType == SIS_550) {
1600 if(temp == Panel310_640x480_3) temp = Panel_640x480_3; 1582 if (temp == Panel310_1152x768) temp = Panel_320x240_2; /* Verified working */
1583 else if(temp == Panel310_320x240_2) temp = Panel_320x240_2;
1584 else if(temp == Panel310_320x240_3) temp = Panel_320x240_3;
1585 } else if(SiS_Pr->ChipType >= SIS_661) {
1586 if(temp == Panel661_1280x854) temp = Panel_1280x854;
1601 } 1587 }
1588#endif
1602 1589
1603 if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* SiS LVDS */ 1590 if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* SiS LVDS */
1604 if(temp == Panel310_1280x768) { 1591 if(temp == Panel310_1280x768) {
1605 temp = Panel_1280x768_2; 1592 temp = Panel_1280x768_2;
1606 } 1593 }
1607 if(SiS_Pr->SiS_ROMNew) { 1594 if(SiS_Pr->SiS_ROMNew) {
1608 if(temp == Panel661_1280x800) { 1595 if(temp == Panel661_1280x800) {
1609 temp = Panel_1280x800_2; 1596 temp = Panel_1280x800_2;
1610 } 1597 }
1611 } 1598 }
@@ -1613,13 +1600,17 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1613 1600
1614 SiS_Pr->SiS_LCDResInfo = temp; 1601 SiS_Pr->SiS_LCDResInfo = temp;
1615 1602
1603#ifdef SIS300
1616 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 1604 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
1617 if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) { 1605 if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
1618 SiS_Pr->SiS_LCDResInfo = Panel_Barco1366; 1606 SiS_Pr->SiS_LCDResInfo = Panel_Barco1366;
1619 } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848) { 1607 } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848) {
1620 SiS_Pr->SiS_LCDResInfo = Panel_848x480; 1608 SiS_Pr->SiS_LCDResInfo = Panel_848x480;
1609 } else if(SiS_Pr->SiS_CustomT == CUT_PANEL856) {
1610 SiS_Pr->SiS_LCDResInfo = Panel_856x480;
1621 } 1611 }
1622 } 1612 }
1613#endif
1623 1614
1624 if(SiS_Pr->SiS_VBType & VB_SISVB) { 1615 if(SiS_Pr->SiS_VBType & VB_SISVB) {
1625 if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMin301) 1616 if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMin301)
@@ -1633,10 +1624,16 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1633 SiS_Pr->SiS_LCDInfo = temp & ~0x000e; 1624 SiS_Pr->SiS_LCDInfo = temp & ~0x000e;
1634 /* Need temp below! */ 1625 /* Need temp below! */
1635 1626
1636 /* These can't scale no matter what */ 1627 /* These must/can't scale no matter what */
1637 switch(SiS_Pr->SiS_LCDResInfo) { 1628 switch(SiS_Pr->SiS_LCDResInfo) {
1629 case Panel_320x240_1:
1630 case Panel_320x240_2:
1631 case Panel_320x240_3:
1638 case Panel_1280x960: 1632 case Panel_1280x960:
1639 SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD; 1633 SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
1634 break;
1635 case Panel_640x480:
1636 SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
1640 } 1637 }
1641 1638
1642 panelcanscale = (SiS_Pr->SiS_LCDInfo & DontExpandLCD) ? TRUE : FALSE; 1639 panelcanscale = (SiS_Pr->SiS_LCDInfo & DontExpandLCD) ? TRUE : FALSE;
@@ -1646,41 +1643,41 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1646 1643
1647 /* Dual link, Pass 1:1 BIOS default, etc. */ 1644 /* Dual link, Pass 1:1 BIOS default, etc. */
1648#ifdef SIS315H 1645#ifdef SIS315H
1649 if(HwInfo->jChipType >= SIS_661) { 1646 if(SiS_Pr->ChipType >= SIS_661) {
1650 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { 1647 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
1651 if(temp & 0x08) SiS_Pr->SiS_LCDInfo |= LCDPass11; 1648 if(temp & 0x08) SiS_Pr->SiS_LCDInfo |= LCDPass11;
1652 } 1649 }
1653 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) { 1650 if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
1654 if(SiS_Pr->SiS_ROMNew) { 1651 if(SiS_Pr->SiS_ROMNew) {
1655 if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink; 1652 if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
1656 } else if((myptr = GetLCDStructPtr661(SiS_Pr, HwInfo))) { 1653 } else if((myptr = GetLCDStructPtr661(SiS_Pr))) {
1657 if(myptr[2] & 0x01) SiS_Pr->SiS_LCDInfo |= LCDDualLink; 1654 if(myptr[2] & 0x01) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
1658 } 1655 }
1659 } 1656 }
1660 } else if(HwInfo->jChipType >= SIS_315H) { 1657 } else if(SiS_Pr->ChipType >= SIS_315H) {
1661 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { 1658 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
1662 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x01) SiS_Pr->SiS_LCDInfo |= LCDPass11; 1659 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x01) SiS_Pr->SiS_LCDInfo |= LCDPass11;
1663 } 1660 }
1664 if((SiS_Pr->SiS_ROMNew) && (!(SiS_Pr->PanelSelfDetected))) { 1661 if((SiS_Pr->SiS_ROMNew) && (!(SiS_Pr->PanelSelfDetected))) {
1665 SiS_Pr->SiS_LCDInfo &= ~(LCDRGB18Bit); 1662 SiS_Pr->SiS_LCDInfo &= ~(LCDRGB18Bit);
1666 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35); 1663 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
1667 if(temp & 0x01) SiS_Pr->SiS_LCDInfo |= LCDRGB18Bit; 1664 if(temp & 0x01) SiS_Pr->SiS_LCDInfo |= LCDRGB18Bit;
1668 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) { 1665 if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
1669 if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink; 1666 if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
1670 } 1667 }
1671 } else if(!(SiS_Pr->SiS_ROMNew)) { 1668 } else if(!(SiS_Pr->SiS_ROMNew)) {
1672 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) { 1669 if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
1673 if((SiS_Pr->SiS_CustomT == CUT_CLEVO1024) && 1670 if((SiS_Pr->SiS_CustomT == CUT_CLEVO1024) &&
1674 (SiS_Pr->SiS_LCDResInfo == Panel_1024x768)) { 1671 (SiS_Pr->SiS_LCDResInfo == Panel_1024x768)) {
1675 SiS_Pr->SiS_LCDInfo |= LCDDualLink; 1672 SiS_Pr->SiS_LCDInfo |= LCDDualLink;
1676 } 1673 }
1677 if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) || 1674 if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
1678 (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) || 1675 (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
1679 (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) || 1676 (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
1680 (SiS_Pr->SiS_LCDResInfo == Panel_1680x1050)) { 1677 (SiS_Pr->SiS_LCDResInfo == Panel_1680x1050)) {
1681 SiS_Pr->SiS_LCDInfo |= LCDDualLink; 1678 SiS_Pr->SiS_LCDInfo |= LCDDualLink;
1682 } 1679 }
1683 } 1680 }
1684 } 1681 }
1685 } 1682 }
1686#endif 1683#endif
@@ -1691,12 +1688,12 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1691 SiS_Pr->SiS_LCDInfo &= ~LCDPass11; 1688 SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
1692 } else if(SiS_Pr->SiS_VBType & VB_SISVB) { 1689 } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
1693 if(SiS_Pr->SiS_VBType & VB_SISLVDS) { 1690 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
1694 /* Always center screen on SiS LVDS (if scaling is disabled) */ 1691 /* Always center screen on SiS LVDS (if scaling is disabled) */
1695 SiS_Pr->SiS_LCDInfo &= ~LCDPass11; 1692 SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
1696 } else { 1693 } else {
1697 /* By default, pass 1:1 on SiS TMDS (if scaling is supported) */ 1694 /* By default, pass 1:1 on SiS TMDS (if scaling is supported) */
1698 if(panelcanscale) SiS_Pr->SiS_LCDInfo |= LCDPass11; 1695 if(panelcanscale) SiS_Pr->SiS_LCDInfo |= LCDPass11;
1699 if(SiS_Pr->CenterScreen == 1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11; 1696 if(SiS_Pr->CenterScreen == 1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
1700 } 1697 }
1701 } 1698 }
1702 1699
@@ -1704,19 +1701,15 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1704 SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315; 1701 SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
1705 1702
1706 switch(SiS_Pr->SiS_LCDResInfo) { 1703 switch(SiS_Pr->SiS_LCDResInfo) {
1707 case Panel_320x480: SiS_Pr->PanelXRes = 320; SiS_Pr->PanelYRes = 480; 1704 case Panel_320x240_1:
1708 SiS_Pr->PanelHT = 400; SiS_Pr->PanelVT = 525; 1705 case Panel_320x240_2:
1709 SiS_Pr->PanelVCLKIdx300 = VCLK28; 1706 case Panel_320x240_3: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480;
1710 SiS_Pr->PanelVCLKIdx315 = VCLK28; 1707 SiS_Pr->PanelVRS = 24; SiS_Pr->PanelVRE = 3;
1711 break;
1712 case Panel_640x480_2:
1713 case Panel_640x480_3: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480;
1714 SiS_Pr->PanelVRS = 24; SiS_Pr->PanelVRE = 3;
1715 SiS_Pr->PanelVCLKIdx300 = VCLK28; 1708 SiS_Pr->PanelVCLKIdx300 = VCLK28;
1716 SiS_Pr->PanelVCLKIdx315 = VCLK28; 1709 SiS_Pr->PanelVCLKIdx315 = VCLK28;
1717 break; 1710 break;
1718 case Panel_640x480: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480; 1711 case Panel_640x480: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480;
1719 SiS_Pr->PanelVRE = 3; 1712 SiS_Pr->PanelVRE = 3;
1720 SiS_Pr->PanelVCLKIdx300 = VCLK28; 1713 SiS_Pr->PanelVCLKIdx300 = VCLK28;
1721 SiS_Pr->PanelVCLKIdx315 = VCLK28; 1714 SiS_Pr->PanelVCLKIdx315 = VCLK28;
1722 break; 1715 break;
@@ -1728,52 +1721,52 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1728 SiS_Pr->PanelVCLKIdx315 = VCLK40; 1721 SiS_Pr->PanelVCLKIdx315 = VCLK40;
1729 break; 1722 break;
1730 case Panel_1024x600: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 600; 1723 case Panel_1024x600: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 600;
1731 SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 800; 1724 SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 800;
1732 SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136; 1725 SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
1733 SiS_Pr->PanelVRS = 2 /* 88 */ ; SiS_Pr->PanelVRE = 6; 1726 SiS_Pr->PanelVRS = 2 /* 88 */ ; SiS_Pr->PanelVRE = 6;
1734 SiS_Pr->PanelVCLKIdx300 = VCLK65_300; 1727 SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
1735 SiS_Pr->PanelVCLKIdx315 = VCLK65_315; 1728 SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
1736 break; 1729 break;
1737 case Panel_1024x768: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768; 1730 case Panel_1024x768: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768;
1738 SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806; 1731 SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
1739 SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136; 1732 SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
1740 SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6; 1733 SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
1741 if(HwInfo->jChipType < SIS_315H) { 1734 if(SiS_Pr->ChipType < SIS_315H) {
1742 SiS_Pr->PanelHRS = 23; 1735 SiS_Pr->PanelHRS = 23;
1743 SiS_Pr->PanelVRE = 5; 1736 SiS_Pr->PanelVRE = 5;
1744 } 1737 }
1745 SiS_Pr->PanelVCLKIdx300 = VCLK65_300; 1738 SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
1746 SiS_Pr->PanelVCLKIdx315 = VCLK65_315; 1739 SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
1747 SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo); 1740 SiS_GetLCDInfoBIOS(SiS_Pr);
1748 break; 1741 break;
1749 case Panel_1152x768: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 768; 1742 case Panel_1152x768: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 768;
1750 SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806; 1743 SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
1751 SiS_Pr->PanelHRS = 24; 1744 SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
1752 SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6; 1745 SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
1753 if(HwInfo->jChipType < SIS_315H) { 1746 if(SiS_Pr->ChipType < SIS_315H) {
1754 SiS_Pr->PanelHRS = 23; 1747 SiS_Pr->PanelHRS = 23;
1755 SiS_Pr->PanelVRE = 5; 1748 SiS_Pr->PanelVRE = 5;
1756 } 1749 }
1757 SiS_Pr->PanelVCLKIdx300 = VCLK65_300; 1750 SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
1758 SiS_Pr->PanelVCLKIdx315 = VCLK65_315; 1751 SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
1759 break; 1752 break;
1760 case Panel_1152x864: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 864; 1753 case Panel_1152x864: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 864;
1761 break; 1754 break;
1762 case Panel_1280x720: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 720; 1755 case Panel_1280x720: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 720;
1763 SiS_Pr->PanelHT = 1650; SiS_Pr->PanelVT = 750; 1756 SiS_Pr->PanelHT = 1650; SiS_Pr->PanelVT = 750;
1764 SiS_Pr->PanelHRS = 110; SiS_Pr->PanelHRE = 40; 1757 SiS_Pr->PanelHRS = 110; SiS_Pr->PanelHRE = 40;
1765 SiS_Pr->PanelVRS = 5; SiS_Pr->PanelVRE = 5; 1758 SiS_Pr->PanelVRS = 5; SiS_Pr->PanelVRE = 5;
1766 SiS_Pr->PanelVCLKIdx315 = VCLK_1280x720; 1759 SiS_Pr->PanelVCLKIdx315 = VCLK_1280x720;
1767 /* Data above for TMDS (projector); get from BIOS for LVDS */ 1760 /* Data above for TMDS (projector); get from BIOS for LVDS */
1768 SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo); 1761 SiS_GetLCDInfoBIOS(SiS_Pr);
1769 break; 1762 break;
1770 case Panel_1280x768: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768; 1763 case Panel_1280x768: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768;
1771 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 1764 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
1772 SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 806; 1765 SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 806;
1773 SiS_Pr->PanelVCLKIdx300 = VCLK81_300; /* ? */ 1766 SiS_Pr->PanelVCLKIdx300 = VCLK81_300; /* ? */
1774 SiS_Pr->PanelVCLKIdx315 = VCLK81_315; /* ? */ 1767 SiS_Pr->PanelVCLKIdx315 = VCLK81_315; /* ? */
1775 } else { 1768 } else {
1776 SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 802; 1769 SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 802;
1777 SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRS = 112; 1770 SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRS = 112;
1778 SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6; 1771 SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
1779 SiS_Pr->PanelVCLKIdx300 = VCLK81_300; 1772 SiS_Pr->PanelVCLKIdx300 = VCLK81_300;
@@ -1781,77 +1774,100 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1781 } 1774 }
1782 break; 1775 break;
1783 case Panel_1280x768_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768; 1776 case Panel_1280x768_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768;
1784 SiS_Pr->PanelHT = 1660; SiS_Pr->PanelVT = 806; 1777 SiS_Pr->PanelHT = 1660; SiS_Pr->PanelVT = 806;
1785 SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112; 1778 SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
1786 SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6; 1779 SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
1787 SiS_Pr->PanelVCLKIdx315 = VCLK_1280x768_2; 1780 SiS_Pr->PanelVCLKIdx315 = VCLK_1280x768_2;
1788 SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo); 1781 SiS_GetLCDInfoBIOS(SiS_Pr);
1789 break; 1782 break;
1790 case Panel_1280x800: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800; 1783 case Panel_1280x800: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800;
1791 SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 816; 1784 SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 816;
1792 SiS_Pr->PanelHRS = 21; SiS_Pr->PanelHRE = 24; 1785 SiS_Pr->PanelHRS = 21; SiS_Pr->PanelHRE = 24;
1793 SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3; 1786 SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3;
1794 SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315; 1787 SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315;
1795 SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo); 1788 SiS_GetLCDInfoBIOS(SiS_Pr);
1796 break; 1789 break;
1797 case Panel_1280x800_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800; 1790 case Panel_1280x800_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800;
1798 SiS_Pr->PanelHT = 1552; SiS_Pr->PanelVT = 812; 1791 SiS_Pr->PanelHT = 1552; SiS_Pr->PanelVT = 812;
1799 SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112; 1792 SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
1800 SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3; 1793 SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3;
1801 SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315_2; 1794 SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315_2;
1802 SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo); 1795 SiS_GetLCDInfoBIOS(SiS_Pr);
1796 break;
1797 case Panel_1280x854: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 854;
1798 SiS_Pr->PanelHT = 1664; SiS_Pr->PanelVT = 861;
1799 SiS_Pr->PanelHRS = 16; SiS_Pr->PanelHRE = 112;
1800 SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
1801 SiS_Pr->PanelVCLKIdx315 = VCLK_1280x854;
1802 SiS_GetLCDInfoBIOS(SiS_Pr);
1803 break; 1803 break;
1804 case Panel_1280x960: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 960; 1804 case Panel_1280x960: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 960;
1805 SiS_Pr->PanelHT = 1800; SiS_Pr->PanelVT = 1000; 1805 SiS_Pr->PanelHT = 1800; SiS_Pr->PanelVT = 1000;
1806 SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300; 1806 SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
1807 SiS_Pr->PanelVCLKIdx315 = VCLK108_3_315; 1807 SiS_Pr->PanelVCLKIdx315 = VCLK108_3_315;
1808 if(resinfo == SIS_RI_1280x1024) { 1808 if(resinfo == SIS_RI_1280x1024) {
1809 SiS_Pr->PanelVCLKIdx300 = VCLK100_300; 1809 SiS_Pr->PanelVCLKIdx300 = VCLK100_300;
1810 SiS_Pr->PanelVCLKIdx315 = VCLK100_315; 1810 SiS_Pr->PanelVCLKIdx315 = VCLK100_315;
1811 } 1811 }
1812 break; 1812 break;
1813 case Panel_1280x1024: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 1024; 1813 case Panel_1280x1024: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 1024;
1814 SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066; 1814 SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
1815 SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112; 1815 SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
1816 SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3; 1816 SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
1817 SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300; 1817 SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
1818 SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315; 1818 SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
1819 SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo); 1819 SiS_GetLCDInfoBIOS(SiS_Pr);
1820 break; 1820 break;
1821 case Panel_1400x1050: SiS_Pr->PanelXRes = 1400; SiS_Pr->PanelYRes = 1050; 1821 case Panel_1400x1050: SiS_Pr->PanelXRes = 1400; SiS_Pr->PanelYRes = 1050;
1822 SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066; 1822 SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
1823 SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112; /* HRE OK for LVDS, not for LCDA */ 1823 SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
1824 SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3; 1824 SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
1825 SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315; 1825 SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
1826 SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo); 1826 SiS_GetLCDInfoBIOS(SiS_Pr);
1827 break; 1827 break;
1828 case Panel_1600x1200: SiS_Pr->PanelXRes = 1600; SiS_Pr->PanelYRes = 1200; 1828 case Panel_1600x1200: SiS_Pr->PanelXRes = 1600; SiS_Pr->PanelYRes = 1200;
1829 SiS_Pr->PanelHT = 2160; SiS_Pr->PanelVT = 1250; 1829 SiS_Pr->PanelHT = 2160; SiS_Pr->PanelVT = 1250;
1830 SiS_Pr->PanelHRS = 64; SiS_Pr->PanelHRE = 192; 1830 SiS_Pr->PanelHRS = 64; SiS_Pr->PanelHRE = 192;
1831 SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3; 1831 SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
1832 SiS_Pr->PanelVCLKIdx315 = VCLK162_315; 1832 SiS_Pr->PanelVCLKIdx315 = VCLK162_315;
1833 SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo); 1833 if(SiS_Pr->SiS_VBType & VB_SISTMDSLCDA) {
1834 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
1835 SiS_Pr->PanelHT = 1760; SiS_Pr->PanelVT = 1235;
1836 SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 32;
1837 SiS_Pr->PanelVRS = 2; SiS_Pr->PanelVRE = 4;
1838 SiS_Pr->PanelVCLKIdx315 = VCLK130_315;
1839 SiS_Pr->Alternate1600x1200 = TRUE;
1840 }
1841 } else if(SiS_Pr->SiS_IF_DEF_LVDS) {
1842 SiS_Pr->PanelHT = 2048; SiS_Pr->PanelVT = 1320;
1843 SiS_Pr->PanelHRS = SiS_Pr->PanelHRE = 999;
1844 SiS_Pr->PanelVRS = SiS_Pr->PanelVRE = 999;
1845 }
1846 SiS_GetLCDInfoBIOS(SiS_Pr);
1834 break; 1847 break;
1835 case Panel_1680x1050: SiS_Pr->PanelXRes = 1680; SiS_Pr->PanelYRes = 1050; 1848 case Panel_1680x1050: SiS_Pr->PanelXRes = 1680; SiS_Pr->PanelYRes = 1050;
1836 SiS_Pr->PanelHT = 1900; SiS_Pr->PanelVT = 1066; 1849 SiS_Pr->PanelHT = 1900; SiS_Pr->PanelVT = 1066;
1837 SiS_Pr->PanelHRS = 26; SiS_Pr->PanelHRE = 76; 1850 SiS_Pr->PanelHRS = 26; SiS_Pr->PanelHRE = 76;
1838 SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6; 1851 SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
1839 SiS_Pr->PanelVCLKIdx315 = VCLK121_315; 1852 SiS_Pr->PanelVCLKIdx315 = VCLK121_315;
1840 SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo); 1853 SiS_GetLCDInfoBIOS(SiS_Pr);
1841 break; 1854 break;
1842 case Panel_Barco1366: SiS_Pr->PanelXRes = 1360; SiS_Pr->PanelYRes = 1024; 1855 case Panel_Barco1366: SiS_Pr->PanelXRes = 1360; SiS_Pr->PanelYRes = 1024;
1843 SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066; 1856 SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
1844 break; 1857 break;
1845 case Panel_848x480: SiS_Pr->PanelXRes = 848; SiS_Pr->PanelYRes = 480; 1858 case Panel_848x480: SiS_Pr->PanelXRes = 848; SiS_Pr->PanelYRes = 480;
1846 SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525; 1859 SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525;
1847 break; 1860 break;
1861 case Panel_856x480: SiS_Pr->PanelXRes = 856; SiS_Pr->PanelYRes = 480;
1862 SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525;
1863 break;
1848 case Panel_Custom: SiS_Pr->PanelXRes = SiS_Pr->CP_MaxX; 1864 case Panel_Custom: SiS_Pr->PanelXRes = SiS_Pr->CP_MaxX;
1849 SiS_Pr->PanelYRes = SiS_Pr->CP_MaxY; 1865 SiS_Pr->PanelYRes = SiS_Pr->CP_MaxY;
1850 SiS_Pr->PanelHT = SiS_Pr->CHTotal; 1866 SiS_Pr->PanelHT = SiS_Pr->CHTotal;
1851 SiS_Pr->PanelVT = SiS_Pr->CVTotal; 1867 SiS_Pr->PanelVT = SiS_Pr->CVTotal;
1852 if(SiS_Pr->CP_PreferredIndex != -1) { 1868 if(SiS_Pr->CP_PreferredIndex != -1) {
1853 SiS_Pr->PanelXRes = SiS_Pr->CP_HDisplay[SiS_Pr->CP_PreferredIndex]; 1869 SiS_Pr->PanelXRes = SiS_Pr->CP_HDisplay[SiS_Pr->CP_PreferredIndex];
1854 SiS_Pr->PanelYRes = SiS_Pr->CP_VDisplay[SiS_Pr->CP_PreferredIndex]; 1870 SiS_Pr->PanelYRes = SiS_Pr->CP_VDisplay[SiS_Pr->CP_PreferredIndex];
1855 SiS_Pr->PanelHT = SiS_Pr->CP_HTotal[SiS_Pr->CP_PreferredIndex]; 1871 SiS_Pr->PanelHT = SiS_Pr->CP_HTotal[SiS_Pr->CP_PreferredIndex];
1856 SiS_Pr->PanelVT = SiS_Pr->CP_VTotal[SiS_Pr->CP_PreferredIndex]; 1872 SiS_Pr->PanelVT = SiS_Pr->CP_VTotal[SiS_Pr->CP_PreferredIndex];
1857 SiS_Pr->PanelHRS = SiS_Pr->CP_HSyncStart[SiS_Pr->CP_PreferredIndex]; 1873 SiS_Pr->PanelHRS = SiS_Pr->CP_HSyncStart[SiS_Pr->CP_PreferredIndex];
@@ -1863,22 +1879,22 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1863 SiS_Pr->PanelVRS -= SiS_Pr->PanelYRes; 1879 SiS_Pr->PanelVRS -= SiS_Pr->PanelYRes;
1864 SiS_Pr->PanelVRE -= SiS_Pr->PanelVRS; 1880 SiS_Pr->PanelVRE -= SiS_Pr->PanelVRS;
1865 if(SiS_Pr->CP_PrefClock) { 1881 if(SiS_Pr->CP_PrefClock) {
1866 int idx; 1882 int idx;
1867 SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315; 1883 SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
1868 SiS_Pr->PanelVCLKIdx300 = VCLK_CUSTOM_300; 1884 SiS_Pr->PanelVCLKIdx300 = VCLK_CUSTOM_300;
1869 if(HwInfo->jChipType < SIS_315H) idx = VCLK_CUSTOM_300; 1885 if(SiS_Pr->ChipType < SIS_315H) idx = VCLK_CUSTOM_300;
1870 else idx = VCLK_CUSTOM_315; 1886 else idx = VCLK_CUSTOM_315;
1871 SiS_Pr->SiS_VCLKData[idx].CLOCK = 1887 SiS_Pr->SiS_VCLKData[idx].CLOCK =
1872 SiS_Pr->SiS_VBVCLKData[idx].CLOCK = SiS_Pr->CP_PrefClock; 1888 SiS_Pr->SiS_VBVCLKData[idx].CLOCK = SiS_Pr->CP_PrefClock;
1873 SiS_Pr->SiS_VCLKData[idx].SR2B = 1889 SiS_Pr->SiS_VCLKData[idx].SR2B =
1874 SiS_Pr->SiS_VBVCLKData[idx].Part4_A = SiS_Pr->CP_PrefSR2B; 1890 SiS_Pr->SiS_VBVCLKData[idx].Part4_A = SiS_Pr->CP_PrefSR2B;
1875 SiS_Pr->SiS_VCLKData[idx].SR2C = 1891 SiS_Pr->SiS_VCLKData[idx].SR2C =
1876 SiS_Pr->SiS_VBVCLKData[idx].Part4_B = SiS_Pr->CP_PrefSR2C; 1892 SiS_Pr->SiS_VBVCLKData[idx].Part4_B = SiS_Pr->CP_PrefSR2C;
1877 } 1893 }
1878 } 1894 }
1879 break; 1895 break;
1880 default: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768; 1896 default: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768;
1881 SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806; 1897 SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
1882 break; 1898 break;
1883 } 1899 }
1884 1900
@@ -1887,14 +1903,16 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1887 (SiS_Pr->SiS_IF_DEF_DSTN) || 1903 (SiS_Pr->SiS_IF_DEF_DSTN) ||
1888 (SiS_Pr->SiS_CustomT == CUT_BARCO1366) || 1904 (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
1889 (SiS_Pr->SiS_CustomT == CUT_BARCO1024) || 1905 (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
1890 (SiS_Pr->SiS_CustomT == CUT_PANEL848) ) { 1906 (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
1907 (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
1891 SiS_Pr->PanelHRS = 999; 1908 SiS_Pr->PanelHRS = 999;
1892 SiS_Pr->PanelHRE = 999; 1909 SiS_Pr->PanelHRE = 999;
1893 } 1910 }
1894 1911
1895 if( (SiS_Pr->SiS_CustomT == CUT_BARCO1366) || 1912 if( (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
1896 (SiS_Pr->SiS_CustomT == CUT_BARCO1024) || 1913 (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
1897 (SiS_Pr->SiS_CustomT == CUT_PANEL848) ) { 1914 (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
1915 (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
1898 SiS_Pr->PanelVRS = 999; 1916 SiS_Pr->PanelVRS = 999;
1899 SiS_Pr->PanelVRE = 999; 1917 SiS_Pr->PanelVRE = 999;
1900 } 1918 }
@@ -1912,18 +1930,18 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1912 case Panel_Custom: 1930 case Panel_Custom:
1913 case Panel_1152x864: 1931 case Panel_1152x864:
1914 case Panel_1280x768: /* TMDS only */ 1932 case Panel_1280x768: /* TMDS only */
1915 SiS_Pr->SiS_LCDInfo |= DontExpandLCD; 1933 SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
1916 break; 1934 break;
1917 1935
1918 case Panel_800x600: { 1936 case Panel_800x600: {
1919 static const UCHAR nonscalingmodes[] = { 1937 static const unsigned char nonscalingmodes[] = {
1920 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, 0xff 1938 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, 0xff
1921 }; 1939 };
1922 SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); 1940 SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
1923 break; 1941 break;
1924 } 1942 }
1925 case Panel_1024x768: { 1943 case Panel_1024x768: {
1926 static const UCHAR nonscalingmodes[] = { 1944 static const unsigned char nonscalingmodes[] = {
1927 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, 1945 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
1928 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, 1946 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
1929 0xff 1947 0xff
@@ -1932,7 +1950,7 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1932 break; 1950 break;
1933 } 1951 }
1934 case Panel_1280x720: { 1952 case Panel_1280x720: {
1935 static const UCHAR nonscalingmodes[] = { 1953 static const unsigned char nonscalingmodes[] = {
1936 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, 1954 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
1937 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, 1955 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
1938 0xff 1956 0xff
@@ -1944,7 +1962,7 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1944 break; 1962 break;
1945 } 1963 }
1946 case Panel_1280x768_2: { /* LVDS only */ 1964 case Panel_1280x768_2: { /* LVDS only */
1947 static const UCHAR nonscalingmodes[] = { 1965 static const unsigned char nonscalingmodes[] = {
1948 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, 1966 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
1949 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, 1967 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
1950 SIS_RI_1152x768,0xff 1968 SIS_RI_1152x768,0xff
@@ -1952,23 +1970,23 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1952 SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); 1970 SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
1953 switch(resinfo) { 1971 switch(resinfo) {
1954 case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) { 1972 case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) {
1955 SiS_Pr->SiS_LCDInfo |= DontExpandLCD; 1973 SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
1956 } 1974 }
1957 break; 1975 break;
1958 } 1976 }
1959 break; 1977 break;
1960 } 1978 }
1961 case Panel_1280x800: { /* SiS TMDS special (Averatec 6200 series) */ 1979 case Panel_1280x800: { /* SiS TMDS special (Averatec 6200 series) */
1962 static const UCHAR nonscalingmodes[] = { 1980 static const unsigned char nonscalingmodes[] = {
1963 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, 1981 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
1964 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, 1982 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
1965 SIS_RI_1152x768,SIS_RI_1280x720,SIS_RI_1280x768,0xff 1983 SIS_RI_1152x768,SIS_RI_1280x720,SIS_RI_1280x768,0xff
1966 }; 1984 };
1967 SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); 1985 SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
1968 break; 1986 break;
1969 } 1987 }
1970 case Panel_1280x800_2: { /* SiS LVDS */ 1988 case Panel_1280x800_2: { /* SiS LVDS */
1971 static const UCHAR nonscalingmodes[] = { 1989 static const unsigned char nonscalingmodes[] = {
1972 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, 1990 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
1973 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, 1991 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
1974 SIS_RI_1152x768,0xff 1992 SIS_RI_1152x768,0xff
@@ -1977,66 +1995,83 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
1977 switch(resinfo) { 1995 switch(resinfo) {
1978 case SIS_RI_1280x720: 1996 case SIS_RI_1280x720:
1979 case SIS_RI_1280x768: if(SiS_Pr->UsePanelScaler == -1) { 1997 case SIS_RI_1280x768: if(SiS_Pr->UsePanelScaler == -1) {
1980 SiS_Pr->SiS_LCDInfo |= DontExpandLCD; 1998 SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
1981 } 1999 }
1982 break; 2000 break;
1983 } 2001 }
1984 break; 2002 break;
2003 }
2004 case Panel_1280x854: { /* SiS LVDS */
2005 static const unsigned char nonscalingmodes[] = {
2006 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
2007 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
2008 SIS_RI_1152x768,0xff
2009 };
2010 SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
2011 switch(resinfo) {
2012 case SIS_RI_1280x720:
2013 case SIS_RI_1280x768:
2014 case SIS_RI_1280x800: if(SiS_Pr->UsePanelScaler == -1) {
2015 SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
2016 }
2017 break;
2018 }
2019 break;
1985 } 2020 }
1986 case Panel_1280x960: { 2021 case Panel_1280x960: {
1987 static const UCHAR nonscalingmodes[] = { 2022 static const unsigned char nonscalingmodes[] = {
1988 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, 2023 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
1989 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, 2024 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
1990 SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800, 2025 SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
1991 0xff 2026 SIS_RI_1280x854,0xff
1992 }; 2027 };
1993 SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); 2028 SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
1994 break; 2029 break;
1995 } 2030 }
1996 case Panel_1280x1024: { 2031 case Panel_1280x1024: {
1997 static const UCHAR nonscalingmodes[] = { 2032 static const unsigned char nonscalingmodes[] = {
1998 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, 2033 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
1999 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, 2034 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
2000 SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800, 2035 SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
2001 SIS_RI_1280x960,0xff 2036 SIS_RI_1280x854,SIS_RI_1280x960,0xff
2002 }; 2037 };
2003 SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); 2038 SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
2004 break; 2039 break;
2005 } 2040 }
2006 case Panel_1400x1050: { 2041 case Panel_1400x1050: {
2007 static const UCHAR nonscalingmodes[] = { 2042 static const unsigned char nonscalingmodes[] = {
2008 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, 2043 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
2009 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, 2044 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
2010 SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x768,SIS_RI_1280x800,SIS_RI_1280x960, 2045 SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x768,SIS_RI_1280x800,SIS_RI_1280x854,
2011 0xff 2046 SIS_RI_1280x960,0xff
2012 }; 2047 };
2013 SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); 2048 SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
2014 switch(resinfo) { 2049 switch(resinfo) {
2015 case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) { 2050 case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) {
2016 SiS_Pr->SiS_LCDInfo |= DontExpandLCD; 2051 SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
2017 } 2052 }
2018 break; 2053 break;
2019 case SIS_RI_1280x1024: SiS_Pr->SiS_LCDInfo |= DontExpandLCD; 2054 case SIS_RI_1280x1024: SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
2020 break; 2055 break;
2021 } 2056 }
2022 break; 2057 break;
2023 } 2058 }
2024 case Panel_1600x1200: { 2059 case Panel_1600x1200: {
2025 static const UCHAR nonscalingmodes[] = { 2060 static const unsigned char nonscalingmodes[] = {
2026 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, 2061 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
2027 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, 2062 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
2028 SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800, 2063 SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
2029 SIS_RI_1280x960,SIS_RI_1360x768,SIS_RI_1360x1024,0xff 2064 SIS_RI_1280x854,SIS_RI_1280x960,SIS_RI_1360x768,SIS_RI_1360x1024,0xff
2030 }; 2065 };
2031 SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); 2066 SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
2032 break; 2067 break;
2033 } 2068 }
2034 case Panel_1680x1050: { 2069 case Panel_1680x1050: {
2035 static const UCHAR nonscalingmodes[] = { 2070 static const unsigned char nonscalingmodes[] = {
2036 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, 2071 SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
2037 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, 2072 SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
2038 SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x960,SIS_RI_1360x768,SIS_RI_1360x1024, 2073 SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x854,SIS_RI_1280x960,SIS_RI_1360x768,
2039 0xff 2074 SIS_RI_1360x1024,0xff
2040 }; 2075 };
2041 SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); 2076 SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
2042 break; 2077 break;
@@ -2044,25 +2079,25 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2044 } 2079 }
2045 } 2080 }
2046 2081
2082#ifdef SIS300
2047 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 2083 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
2048 if(SiS_Pr->SiS_CustomT == CUT_PANEL848) { 2084 if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
2049 SiS_Pr->SiS_LCDInfo = 0x80 | 0x40 | 0x20; /* neg h/v sync, RGB24(D0 = 0) */ 2085 SiS_Pr->SiS_LCDInfo = 0x80 | 0x40 | 0x20; /* neg h/v sync, RGB24(D0 = 0) */
2050 } 2086 }
2051 } 2087 }
2052 2088
2053#ifdef SIS300 2089 if(SiS_Pr->ChipType < SIS_315H) {
2054 if(HwInfo->jChipType < SIS_315H) {
2055 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 2090 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
2056 if(SiS_Pr->SiS_UseROM) { 2091 if(SiS_Pr->SiS_UseROM) {
2057 if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) { 2092 if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
2058 if(!(ROMAddr[0x235] & 0x02)) { 2093 if(!(ROMAddr[0x235] & 0x02)) {
2059 SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD); 2094 SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
2060 } 2095 }
2061 } 2096 }
2062 } 2097 }
2063 } else if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 2098 } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
2064 if((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10))) { 2099 if((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10))) {
2065 SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD); 2100 SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
2066 } 2101 }
2067 } 2102 }
2068 } 2103 }
@@ -2080,7 +2115,7 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2080 2115
2081 switch(SiS_Pr->SiS_LCDResInfo) { 2116 switch(SiS_Pr->SiS_LCDResInfo) {
2082 case Panel_640x480: 2117 case Panel_640x480:
2083 SiS_Pr->SiS_LCDInfo |= LCDPass11; 2118 SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
2084 break; 2119 break;
2085 case Panel_1280x800: 2120 case Panel_1280x800:
2086 /* Don't pass 1:1 by default (TMDS special) */ 2121 /* Don't pass 1:1 by default (TMDS special) */
@@ -2097,7 +2132,7 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2097 break; 2132 break;
2098 } 2133 }
2099 2134
2100 if(SiS_Pr->UseCustomMode) { 2135 if((SiS_Pr->UseCustomMode) || (SiS_Pr->SiS_CustomT == CUT_UNKNOWNLCD)) {
2101 SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11); 2136 SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
2102 } 2137 }
2103 2138
@@ -2107,19 +2142,19 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2107 } 2142 }
2108 2143
2109 /* LVDS DDA */ 2144 /* LVDS DDA */
2110 if(!((HwInfo->jChipType < SIS_315H) && (SiS_Pr->SiS_SetFlag & SetDOSMode))) { 2145 if(!((SiS_Pr->ChipType < SIS_315H) && (SiS_Pr->SiS_SetFlag & SetDOSMode))) {
2111 2146
2112 if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) { 2147 if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
2113 if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) { 2148 if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) {
2114 if(ModeNo == 0x12) { 2149 if(ModeNo == 0x12) {
2115 if(SiS_Pr->SiS_LCDInfo & LCDPass11) { 2150 if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
2116 SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; 2151 SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
2117 } 2152 }
2118 } else if(ModeNo > 0x13) { 2153 } else if(ModeNo > 0x13) {
2119 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) { 2154 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) {
2120 if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { 2155 if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
2121 if((resinfo == SIS_RI_800x600) || (resinfo == SIS_RI_400x300)) { 2156 if((resinfo == SIS_RI_800x600) || (resinfo == SIS_RI_400x300)) {
2122 SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; 2157 SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
2123 } 2158 }
2124 } 2159 }
2125 } 2160 }
@@ -2128,18 +2163,18 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2128 } 2163 }
2129 2164
2130 if(modeflag & HalfDCLK) { 2165 if(modeflag & HalfDCLK) {
2131 if(SiS_Pr->SiS_IF_DEF_TRUMPION == 1) { 2166 if(SiS_Pr->SiS_IF_DEF_TRUMPION == 1) {
2132 SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; 2167 SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
2133 } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { 2168 } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
2134 SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; 2169 SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
2135 } else if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) { 2170 } else if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) {
2136 SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; 2171 SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
2137 } else if(ModeNo > 0x13) { 2172 } else if(ModeNo > 0x13) {
2138 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { 2173 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
2139 if(resinfo == SIS_RI_512x384) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; 2174 if(resinfo == SIS_RI_512x384) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
2140 } else if(SiS_Pr->SiS_LCDResInfo == Panel_800x600) { 2175 } else if(SiS_Pr->SiS_LCDResInfo == Panel_800x600) {
2141 if(resinfo == SIS_RI_400x300) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; 2176 if(resinfo == SIS_RI_400x300) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
2142 } 2177 }
2143 } 2178 }
2144 } 2179 }
2145 2180
@@ -2148,21 +2183,21 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2148 /* VESA timing */ 2183 /* VESA timing */
2149 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { 2184 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
2150 if(SiS_Pr->SiS_VBInfo & SetNotSimuMode) { 2185 if(SiS_Pr->SiS_VBInfo & SetNotSimuMode) {
2151 SiS_Pr->SiS_SetFlag |= LCDVESATiming; 2186 SiS_Pr->SiS_SetFlag |= LCDVESATiming;
2152 } 2187 }
2153 } else { 2188 } else {
2154 SiS_Pr->SiS_SetFlag |= LCDVESATiming; 2189 SiS_Pr->SiS_SetFlag |= LCDVESATiming;
2155 } 2190 }
2156 2191
2157#ifdef LINUX_KERNEL 2192#ifdef SIS_LINUX_KERNEL
2158#ifdef TWDEBUG 2193#if 0
2159 printk(KERN_DEBUG "sisfb: (LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x)\n", 2194 printk(KERN_DEBUG "sisfb: (LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x)\n",
2160 SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo); 2195 SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo);
2161#endif 2196#endif
2162#endif 2197#endif
2163#ifdef LINUX_XF86 2198#ifdef SIS_XORG_XF86
2164 xf86DrvMsgVerb(0, X_PROBED, 4, 2199 xf86DrvMsgVerb(0, X_PROBED, 4,
2165 "(init301: LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x SetFlag=0x%04x)\n", 2200 "(init301: LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x SetFlag=0x%04x)\n",
2166 SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo, SiS_Pr->SiS_SetFlag); 2201 SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo, SiS_Pr->SiS_SetFlag);
2167#endif 2202#endif
2168} 2203}
@@ -2171,45 +2206,46 @@ SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2171/* GET VCLK */ 2206/* GET VCLK */
2172/*********************************************/ 2207/*********************************************/
2173 2208
2174USHORT 2209unsigned short
2175SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 2210SiS_GetVCLK2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
2176 USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo) 2211 unsigned short RefreshRateTableIndex)
2177{ 2212{
2178 USHORT CRT2Index,VCLKIndex=0,VCLKIndexGEN=0; 2213 unsigned short CRT2Index, VCLKIndex = 0, VCLKIndexGEN = 0, VCLKIndexGENCRT = 0;
2179 USHORT modeflag,resinfo,tempbx; 2214 unsigned short modeflag, resinfo, tempbx;
2180 const UCHAR *CHTVVCLKPtr = NULL; 2215 const unsigned char *CHTVVCLKPtr = NULL;
2181 2216
2182 if(ModeNo <= 0x13) { 2217 if(ModeNo <= 0x13) {
2183 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; 2218 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
2184 resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; 2219 resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
2185 CRT2Index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; 2220 CRT2Index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2186 VCLKIndexGEN = (SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02)) >> 2) & 0x03; 2221 VCLKIndexGEN = (SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02)) >> 2) & 0x03;
2222 VCLKIndexGENCRT = VCLKIndexGEN;
2187 } else { 2223 } else {
2188 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 2224 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2189 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; 2225 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
2190 CRT2Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; 2226 CRT2Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2191 VCLKIndexGEN = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK; 2227 VCLKIndexGEN = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
2192 if(HwInfo->jChipType < SIS_315H) VCLKIndexGEN &= 0x3f; 2228 VCLKIndexGENCRT = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex,
2229 (SiS_Pr->SiS_SetFlag & ProgrammingCRT2) ? SiS_Pr->SiS_UseWideCRT2 : SiS_Pr->SiS_UseWide);
2193 } 2230 }
2194 2231
2195 if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 30x/B/LV */ 2232 if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 30x/B/LV */
2196 2233
2197 if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) { 2234 if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
2198 2235
2199 CRT2Index >>= 6; 2236 CRT2Index >>= 6;
2200 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /* LCD */ 2237 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /* LCD */
2201 2238
2202 if(HwInfo->jChipType < SIS_315H) { 2239 if(SiS_Pr->ChipType < SIS_315H) {
2203 VCLKIndex = SiS_Pr->PanelVCLKIdx300; 2240 VCLKIndex = SiS_Pr->PanelVCLKIdx300;
2204 if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) { 2241 if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
2205 VCLKIndex = VCLKIndexGEN; 2242 VCLKIndex = VCLKIndexGEN;
2206 } 2243 }
2207 } else { 2244 } else {
2208 VCLKIndex = SiS_Pr->PanelVCLKIdx315; 2245 VCLKIndex = SiS_Pr->PanelVCLKIdx315;
2209 if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) { 2246 if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
2210 switch(resinfo) { 2247 switch(resinfo) {
2211 /* Only those whose IndexGEN doesn't match VBVCLK array */ 2248 /* Correct those whose IndexGEN doesn't match VBVCLK array */
2212 case SIS_RI_1280x720: VCLKIndex = VCLK_1280x720; break;
2213 case SIS_RI_720x480: VCLKIndex = VCLK_720x480; break; 2249 case SIS_RI_720x480: VCLKIndex = VCLK_720x480; break;
2214 case SIS_RI_720x576: VCLKIndex = VCLK_720x576; break; 2250 case SIS_RI_720x576: VCLKIndex = VCLK_720x576; break;
2215 case SIS_RI_768x576: VCLKIndex = VCLK_768x576; break; 2251 case SIS_RI_768x576: VCLKIndex = VCLK_768x576; break;
@@ -2218,18 +2254,19 @@ SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2218 case SIS_RI_800x480: VCLKIndex = VCLK_800x480; break; 2254 case SIS_RI_800x480: VCLKIndex = VCLK_800x480; break;
2219 case SIS_RI_1024x576: VCLKIndex = VCLK_1024x576; break; 2255 case SIS_RI_1024x576: VCLKIndex = VCLK_1024x576; break;
2220 case SIS_RI_1152x864: VCLKIndex = VCLK_1152x864; break; 2256 case SIS_RI_1152x864: VCLKIndex = VCLK_1152x864; break;
2257 case SIS_RI_1280x720: VCLKIndex = VCLK_1280x720; break;
2221 case SIS_RI_1360x768: VCLKIndex = VCLK_1360x768; break; 2258 case SIS_RI_1360x768: VCLKIndex = VCLK_1360x768; break;
2222 default: VCLKIndex = VCLKIndexGEN; 2259 default: VCLKIndex = VCLKIndexGEN;
2223 } 2260 }
2224 2261
2225 if(ModeNo <= 0x13) { 2262 if(ModeNo <= 0x13) {
2226 if(HwInfo->jChipType <= SIS_315PRO) { 2263 if(SiS_Pr->ChipType <= SIS_315PRO) {
2227 if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x42; 2264 if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x42;
2228 } else { 2265 } else {
2229 if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x00; 2266 if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x00;
2230 } 2267 }
2231 } 2268 }
2232 if(HwInfo->jChipType <= SIS_315PRO) { 2269 if(SiS_Pr->ChipType <= SIS_315PRO) {
2233 if(VCLKIndex == 0) VCLKIndex = 0x41; 2270 if(VCLKIndex == 0) VCLKIndex = 0x41;
2234 if(VCLKIndex == 1) VCLKIndex = 0x43; 2271 if(VCLKIndex == 1) VCLKIndex = 0x43;
2235 if(VCLKIndex == 4) VCLKIndex = 0x44; 2272 if(VCLKIndex == 4) VCLKIndex = 0x44;
@@ -2237,49 +2274,46 @@ SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2237 } 2274 }
2238 } 2275 }
2239 2276
2240 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* TV */ 2277 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* TV */
2241 2278
2242 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { 2279 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
2243 if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = HiTVVCLKDIV2; 2280 if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = HiTVVCLKDIV2;
2244 else VCLKIndex = HiTVVCLK; 2281 else VCLKIndex = HiTVVCLK;
2245 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) { 2282 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) VCLKIndex = HiTVSimuVCLK;
2246 if(modeflag & Charx8Dot) VCLKIndex = HiTVSimuVCLK; 2283 } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) VCLKIndex = YPbPr750pVCLK;
2247 else VCLKIndex = HiTVTextVCLK; 2284 else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) VCLKIndex = TVVCLKDIV2;
2248 } 2285 else if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = TVVCLKDIV2;
2249 } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) VCLKIndex = YPbPr750pVCLK; 2286 else VCLKIndex = TVVCLK;
2250 else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) VCLKIndex = TVVCLKDIV2; 2287
2251 else if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = TVVCLKDIV2; 2288 if(SiS_Pr->ChipType < SIS_315H) VCLKIndex += TVCLKBASE_300;
2252 else VCLKIndex = TVVCLK; 2289 else VCLKIndex += TVCLKBASE_315;
2253 2290
2254 if(HwInfo->jChipType < SIS_315H) VCLKIndex += TVCLKBASE_300; 2291 } else { /* VGA2 */
2255 else VCLKIndex += TVCLKBASE_315; 2292
2256 2293 VCLKIndex = VCLKIndexGENCRT;
2257 } else { /* VGA2 */ 2294 if(SiS_Pr->ChipType < SIS_315H) {
2258 2295 if(ModeNo > 0x13) {
2259 VCLKIndex = VCLKIndexGEN; 2296 if( (SiS_Pr->ChipType == SIS_630) &&
2260 if(HwInfo->jChipType < SIS_315H) { 2297 (SiS_Pr->ChipRevision >= 0x30)) {
2261 if(ModeNo > 0x13) {
2262 if( (HwInfo->jChipType == SIS_630) &&
2263 (HwInfo->jChipRevision >= 0x30)) {
2264 if(VCLKIndex == 0x14) VCLKIndex = 0x34; 2298 if(VCLKIndex == 0x14) VCLKIndex = 0x34;
2265 } 2299 }
2266 /* Better VGA2 clock for 1280x1024@75 */ 2300 /* Better VGA2 clock for 1280x1024@75 */
2267 if(VCLKIndex == 0x17) VCLKIndex = 0x45; 2301 if(VCLKIndex == 0x17) VCLKIndex = 0x45;
2268 } 2302 }
2269 } 2303 }
2270 } 2304 }
2271 2305
2272 } else { /* If not programming CRT2 */ 2306 } else { /* If not programming CRT2 */
2273 2307
2274 VCLKIndex = VCLKIndexGEN; 2308 VCLKIndex = VCLKIndexGENCRT;
2275 if(HwInfo->jChipType < SIS_315H) { 2309 if(SiS_Pr->ChipType < SIS_315H) {
2276 if(ModeNo > 0x13) { 2310 if(ModeNo > 0x13) {
2277 if( (HwInfo->jChipType != SIS_630) && 2311 if( (SiS_Pr->ChipType != SIS_630) &&
2278 (HwInfo->jChipType != SIS_300) ) { 2312 (SiS_Pr->ChipType != SIS_300) ) {
2279 if(VCLKIndex == 0x1b) VCLKIndex = 0x48; 2313 if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
2280 } 2314 }
2281 } 2315 }
2282 } 2316 }
2283 } 2317 }
2284 2318
2285 } else { /* LVDS */ 2319 } else { /* LVDS */
@@ -2288,12 +2322,12 @@ SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2288 2322
2289 if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) { 2323 if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
2290 2324
2291 if( (SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) ) { 2325 if( (SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) ) {
2292 2326
2293 VCLKIndex &= 0x1f; 2327 VCLKIndex &= 0x1f;
2294 tempbx = 0; 2328 tempbx = 0;
2295 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1; 2329 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
2296 if(SiS_Pr->SiS_TVMode & TVSetPAL) { 2330 if(SiS_Pr->SiS_TVMode & TVSetPAL) {
2297 tempbx += 2; 2331 tempbx += 2;
2298 if(SiS_Pr->SiS_ModeType > ModeVGA) { 2332 if(SiS_Pr->SiS_ModeType > ModeVGA) {
2299 if(SiS_Pr->SiS_CHSOverScan) tempbx = 8; 2333 if(SiS_Pr->SiS_CHSOverScan) tempbx = 8;
@@ -2306,66 +2340,68 @@ SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2306 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1; 2340 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
2307 } 2341 }
2308 } 2342 }
2309 switch(tempbx) { 2343 switch(tempbx) {
2310 case 0: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUNTSC; break; 2344 case 0: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUNTSC; break;
2311 case 1: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKONTSC; break; 2345 case 1: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKONTSC; break;
2312 case 2: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPAL; break; 2346 case 2: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPAL; break;
2313 case 3: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break; 2347 case 3: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break;
2314 case 4: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALM; break; 2348 case 4: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALM; break;
2315 case 5: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALM; break; 2349 case 5: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALM; break;
2316 case 6: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALN; break; 2350 case 6: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALN; break;
2317 case 7: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALN; break; 2351 case 7: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALN; break;
2318 case 8: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKSOPAL; break; 2352 case 8: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKSOPAL; break;
2319 default: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break; 2353 default: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break;
2320 } 2354 }
2321 VCLKIndex = CHTVVCLKPtr[VCLKIndex]; 2355 VCLKIndex = CHTVVCLKPtr[VCLKIndex];
2322 2356
2323 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 2357 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
2324 2358
2325 if(HwInfo->jChipType < SIS_315H) { 2359 if(SiS_Pr->ChipType < SIS_315H) {
2326 VCLKIndex = SiS_Pr->PanelVCLKIdx300; 2360 VCLKIndex = SiS_Pr->PanelVCLKIdx300;
2327 } else { 2361 } else {
2328 VCLKIndex = SiS_Pr->PanelVCLKIdx315; 2362 VCLKIndex = SiS_Pr->PanelVCLKIdx315;
2329 } 2363 }
2330 2364
2365#ifdef SIS300
2331 /* Special Timing: Barco iQ Pro R series */ 2366 /* Special Timing: Barco iQ Pro R series */
2332 if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) VCLKIndex = 0x44; 2367 if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) VCLKIndex = 0x44;
2333 2368
2334 /* Special Timing: 848x480 parallel lvds */ 2369 /* Special Timing: 848x480 and 856x480 parallel lvds panels */
2335 if(SiS_Pr->SiS_CustomT == CUT_PANEL848) { 2370 if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
2336 if(HwInfo->jChipType < SIS_315H) { 2371 if(SiS_Pr->ChipType < SIS_315H) {
2337 VCLKIndex = VCLK34_300; 2372 VCLKIndex = VCLK34_300;
2338 /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */ 2373 /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */
2339 } else { 2374 } else {
2340 VCLKIndex = VCLK34_315; 2375 VCLKIndex = VCLK34_315;
2341 /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */ 2376 /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */
2342 } 2377 }
2343 } 2378 }
2379#endif
2344 2380
2345 } else { 2381 } else {
2346 2382
2347 VCLKIndex = VCLKIndexGEN; 2383 VCLKIndex = VCLKIndexGENCRT;
2348 if(HwInfo->jChipType < SIS_315H) { 2384 if(SiS_Pr->ChipType < SIS_315H) {
2349 if(ModeNo > 0x13) { 2385 if(ModeNo > 0x13) {
2350 if( (HwInfo->jChipType == SIS_630) && 2386 if( (SiS_Pr->ChipType == SIS_630) &&
2351 (HwInfo->jChipRevision >= 0x30) ) { 2387 (SiS_Pr->ChipRevision >= 0x30) ) {
2352 if(VCLKIndex == 0x14) VCLKIndex = 0x2e; 2388 if(VCLKIndex == 0x14) VCLKIndex = 0x2e;
2353 } 2389 }
2354 } 2390 }
2355 } 2391 }
2356 } 2392 }
2357 2393
2358 } else { /* if not programming CRT2 */ 2394 } else { /* if not programming CRT2 */
2359 2395
2360 VCLKIndex = VCLKIndexGEN; 2396 VCLKIndex = VCLKIndexGENCRT;
2361 if(HwInfo->jChipType < SIS_315H) { 2397 if(SiS_Pr->ChipType < SIS_315H) {
2362 if(ModeNo > 0x13) { 2398 if(ModeNo > 0x13) {
2363 if( (HwInfo->jChipType != SIS_630) && 2399 if( (SiS_Pr->ChipType != SIS_630) &&
2364 (HwInfo->jChipType != SIS_300) ) { 2400 (SiS_Pr->ChipType != SIS_300) ) {
2365 if(VCLKIndex == 0x1b) VCLKIndex = 0x48; 2401 if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
2366 } 2402 }
2367#if 0 2403#if 0
2368 if(HwInfo->jChipType == SIS_730) { 2404 if(SiS_Pr->ChipType == SIS_730) {
2369 if(VCLKIndex == 0x0b) VCLKIndex = 0x40; /* 1024x768-70 */ 2405 if(VCLKIndex == 0x0b) VCLKIndex = 0x40; /* 1024x768-70 */
2370 if(VCLKIndex == 0x0d) VCLKIndex = 0x41; /* 1024x768-75 */ 2406 if(VCLKIndex == 0x0d) VCLKIndex = 0x41; /* 1024x768-75 */
2371 } 2407 }
@@ -2377,11 +2413,13 @@ SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2377 2413
2378 } 2414 }
2379 2415
2416#ifdef SIS_XORG_XF86
2380#ifdef TWDEBUG 2417#ifdef TWDEBUG
2381 xf86DrvMsg(0, X_INFO, "VCLKIndex %d (0x%x)\n", VCLKIndex, VCLKIndex); 2418 xf86DrvMsg(0, X_INFO, "VCLKIndex %d (0x%x)\n", VCLKIndex, VCLKIndex);
2382#endif 2419#endif
2420#endif
2383 2421
2384 return(VCLKIndex); 2422 return VCLKIndex;
2385} 2423}
2386 2424
2387/*********************************************/ 2425/*********************************************/
@@ -2389,26 +2427,19 @@ SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2389/*********************************************/ 2427/*********************************************/
2390 2428
2391static void 2429static void
2392SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 2430SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
2393 PSIS_HW_INFO HwInfo)
2394{ 2431{
2395 USHORT i,j,modeflag; 2432 unsigned short i, j, modeflag, tempah=0;
2396 USHORT tempcl,tempah=0; 2433 short tempcl;
2397#if defined(SIS300) || defined(SIS315H) 2434#if defined(SIS300) || defined(SIS315H)
2398 USHORT tempbl; 2435 unsigned short tempbl;
2399#endif 2436#endif
2400#ifdef SIS315H 2437#ifdef SIS315H
2401 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 2438 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
2402 USHORT tempah2, tempbl2; 2439 unsigned short tempah2, tempbl2;
2403#endif 2440#endif
2404 2441
2405 if(ModeNo <= 0x13) { 2442 modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
2406 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
2407 } else if(SiS_Pr->UseCustomMode) {
2408 modeflag = SiS_Pr->CModeFlag;
2409 } else {
2410 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2411 }
2412 2443
2413 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { 2444 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
2414 2445
@@ -2418,18 +2449,18 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2418 } else { 2449 } else {
2419 2450
2420 for(i=0,j=4; i<3; i++,j++) SiS_SetReg(SiS_Pr->SiS_Part1Port,j,0); 2451 for(i=0,j=4; i<3; i++,j++) SiS_SetReg(SiS_Pr->SiS_Part1Port,j,0);
2421 if(HwInfo->jChipType >= SIS_315H) { 2452 if(SiS_Pr->ChipType >= SIS_315H) {
2422 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0x7F); 2453 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0x7F);
2423 } 2454 }
2424 2455
2425 tempcl = SiS_Pr->SiS_ModeType; 2456 tempcl = SiS_Pr->SiS_ModeType;
2426 2457
2427 if(HwInfo->jChipType < SIS_315H) { 2458 if(SiS_Pr->ChipType < SIS_315H) {
2428 2459
2429#ifdef SIS300 /* ---- 300 series ---- */ 2460#ifdef SIS300 /* ---- 300 series ---- */
2430 2461
2431 /* For 301BDH: (with LCD via LVDS) */ 2462 /* For 301BDH: (with LCD via LVDS) */
2432 if(SiS_Pr->SiS_VBType & VB_NoLCD) { 2463 if(SiS_Pr->SiS_VBType & VB_NoLCD) {
2433 tempbl = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32); 2464 tempbl = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32);
2434 tempbl &= 0xef; 2465 tempbl &= 0xef;
2435 tempbl |= 0x02; 2466 tempbl |= 0x02;
@@ -2438,16 +2469,16 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2438 tempbl &= 0xfd; 2469 tempbl &= 0xfd;
2439 } 2470 }
2440 SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,tempbl); 2471 SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,tempbl);
2441 } 2472 }
2442 2473
2443 if(ModeNo > 0x13) { 2474 if(ModeNo > 0x13) {
2444 tempcl -= ModeVGA; 2475 tempcl -= ModeVGA;
2445 if((tempcl > 0) || (tempcl == 0)) { /* tempcl is USHORT -> always true! */ 2476 if(tempcl >= 0) {
2446 tempah = ((0x10 >> tempcl) | 0x80); 2477 tempah = ((0x10 >> tempcl) | 0x80);
2447 } 2478 }
2448 } else tempah = 0x80; 2479 } else tempah = 0x80;
2449 2480
2450 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0xA0; 2481 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0xA0;
2451 2482
2452#endif /* SIS300 */ 2483#endif /* SIS300 */
2453 2484
@@ -2455,22 +2486,16 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2455 2486
2456#ifdef SIS315H /* ------- 315/330 series ------ */ 2487#ifdef SIS315H /* ------- 315/330 series ------ */
2457 2488
2458 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 2489 if(ModeNo > 0x13) {
2459 if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) { 2490 tempcl -= ModeVGA;
2460 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x08); 2491 if(tempcl >= 0) {
2461 } 2492 tempah = (0x08 >> tempcl);
2462 } 2493 if (tempah == 0) tempah = 1;
2463 2494 tempah |= 0x40;
2464 if(ModeNo > 0x13) { 2495 }
2465 tempcl -= ModeVGA; 2496 } else tempah = 0x40;
2466 if((tempcl > 0) || (tempcl == 0)) { /* tempcl is USHORT -> always true! */
2467 tempah = (0x08 >> tempcl);
2468 if (tempah == 0) tempah = 1;
2469 tempah |= 0x40;
2470 }
2471 } else tempah = 0x40;
2472 2497
2473 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0x50; 2498 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0x50;
2474 2499
2475#endif /* SIS315H */ 2500#endif /* SIS315H */
2476 2501
@@ -2478,84 +2503,89 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2478 2503
2479 if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0; 2504 if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
2480 2505
2481 if(HwInfo->jChipType < SIS_315H) { 2506 if(SiS_Pr->ChipType < SIS_315H) {
2482 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah); 2507 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah);
2483 } else { 2508 } else {
2484 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 2509#ifdef SIS315H
2485 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah); 2510 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
2486 } else if(SiS_Pr->SiS_VBType & VB_SISVB) { 2511 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah);
2487 if(IS_SIS740) { 2512 } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
2513 if(IS_SIS740) {
2488 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah); 2514 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah);
2489 } else { 2515 } else {
2490 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah); 2516 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah);
2491 } 2517 }
2492 } 2518 }
2519#endif
2493 } 2520 }
2494 2521
2495 if(SiS_Pr->SiS_VBType & VB_SISVB) { 2522 if(SiS_Pr->SiS_VBType & VB_SISVB) {
2496 2523
2497 tempah = 0x01; 2524 tempah = 0x01;
2498 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { 2525 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
2499 tempah |= 0x02; 2526 tempah |= 0x02;
2500 } 2527 }
2501 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) { 2528 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
2502 tempah ^= 0x05; 2529 tempah ^= 0x05;
2503 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { 2530 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
2504 tempah ^= 0x01; 2531 tempah ^= 0x01;
2505 } 2532 }
2506 } 2533 }
2507 2534
2508 if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0; 2535 if(SiS_Pr->ChipType < SIS_315H) {
2509 2536
2510 if(HwInfo->jChipType < SIS_315H) { 2537 if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
2511 2538
2512 tempah = (tempah << 5) & 0xFF; 2539 tempah = (tempah << 5) & 0xFF;
2513 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah); 2540 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah);
2514 tempah = (tempah >> 5) & 0xFF; 2541 tempah = (tempah >> 5) & 0xFF;
2515 2542
2516 } else { 2543 } else {
2517 2544
2518 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2E,0xF8,tempah); 2545 if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0x08;
2546 else if(!(SiS_IsDualEdge(SiS_Pr))) tempah |= 0x08;
2547 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2E,0xF0,tempah);
2548 tempah &= ~0x08;
2519 2549
2520 } 2550 }
2521 2551
2522 if((SiS_Pr->SiS_ModeType == ModeVGA) && (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) { 2552 if((SiS_Pr->SiS_ModeType == ModeVGA) && (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) {
2523 tempah |= 0x10; 2553 tempah |= 0x10;
2524 } 2554 }
2525 2555
2526 tempah |= 0x80; 2556 tempah |= 0x80;
2527 if(SiS_Pr->SiS_VBType & VB_SIS301) { 2557 if(SiS_Pr->SiS_VBType & VB_SIS301) {
2528 if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah &= ~0x80; 2558 if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah &= ~0x80;
2529 } 2559 }
2530 2560
2531 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 2561 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
2532 if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p))) { 2562 if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p))) {
2533 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { 2563 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
2534 tempah |= 0x20; 2564 tempah |= 0x20;
2535 } 2565 }
2536 } 2566 }
2537 } 2567 }
2538 2568
2539 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0D,0x40,tempah); 2569 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0D,0x40,tempah);
2540 2570
2541 tempah = 0x80; 2571 tempah = 0x80;
2542 if(SiS_Pr->SiS_VBType & VB_SIS301) { 2572 if(SiS_Pr->SiS_VBType & VB_SIS301) {
2543 if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah = 0; 2573 if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah = 0;
2544 } 2574 }
2545 2575
2546 if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempah |= 0x40; 2576 if(SiS_IsDualLink(SiS_Pr)) tempah |= 0x40;
2547 2577
2548 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 2578 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
2549 if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) { 2579 if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) {
2550 tempah |= 0x40; 2580 tempah |= 0x40;
2551 } 2581 }
2552 } 2582 }
2553 2583
2554 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0C,tempah); 2584 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0C,tempah);
2555 2585
2556 } else { /* LVDS */ 2586 } else { /* LVDS */
2557 2587
2558 if(HwInfo->jChipType >= SIS_315H) { 2588 if(SiS_Pr->ChipType >= SIS_315H) {
2559 2589
2560#ifdef SIS315H 2590#ifdef SIS315H
2561 /* LVDS can only be slave in 8bpp modes */ 2591 /* LVDS can only be slave in 8bpp modes */
@@ -2566,36 +2596,30 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2566 } 2596 }
2567 } 2597 }
2568 2598
2569 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { 2599 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) tempah |= 0x02;
2570 tempah |= 0x02;
2571 }
2572 2600
2573 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 2601 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah ^= 0x01;
2574 tempah ^= 0x01;
2575 }
2576 2602
2577 if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) { 2603 if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 1;
2578 tempah = 1;
2579 }
2580 2604
2581 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2e,0xF0,tempah); 2605 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2e,0xF0,tempah);
2582#endif 2606#endif
2583 2607
2584 } else { 2608 } else {
2585 2609
2586#ifdef SIS300 2610#ifdef SIS300
2587 tempah = 0; 2611 tempah = 0;
2588 if( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) && (SiS_Pr->SiS_ModeType > ModeVGA) ) { 2612 if( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) && (SiS_Pr->SiS_ModeType > ModeVGA) ) {
2589 tempah |= 0x02; 2613 tempah |= 0x02;
2590 } 2614 }
2591 tempah <<= 5; 2615 tempah <<= 5;
2592 2616
2593 if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0; 2617 if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
2594 2618
2595 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah); 2619 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah);
2596#endif 2620#endif
2597 2621
2598 } 2622 }
2599 2623
2600 } 2624 }
2601 2625
@@ -2603,10 +2627,10 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2603 2627
2604 if(SiS_Pr->SiS_VBType & VB_SISVB) { 2628 if(SiS_Pr->SiS_VBType & VB_SISVB) {
2605 2629
2606 if(HwInfo->jChipType >= SIS_315H) { 2630 if(SiS_Pr->ChipType >= SIS_315H) {
2607 2631
2608#ifdef SIS315H 2632#ifdef SIS315H
2609 unsigned char bridgerev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01); 2633 /* unsigned char bridgerev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01); */
2610 2634
2611 /* The following is nearly unpreditable and varies from machine 2635 /* The following is nearly unpreditable and varies from machine
2612 * to machine. Especially the 301DH seems to be a real trouble 2636 * to machine. Especially the 301DH seems to be a real trouble
@@ -2619,25 +2643,28 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2619 2643
2620 /* 740 variants match for 30xB, 301B-DH, 30xLV */ 2644 /* 740 variants match for 30xB, 301B-DH, 30xLV */
2621 2645
2622 if(!(IS_SIS740)) { 2646 if(!(IS_SIS740)) {
2623 tempah = 0x04; /* For all bridges */ 2647 tempah = 0x04; /* For all bridges */
2624 tempbl = 0xfb; 2648 tempbl = 0xfb;
2625 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { 2649 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
2626 tempah = 0x00; 2650 tempah = 0x00;
2627 if(SiS_IsDualEdge(SiS_Pr, HwInfo)) { 2651 if(SiS_IsDualEdge(SiS_Pr)) {
2628 tempbl = 0xff; 2652 tempbl = 0xff;
2629 } 2653 }
2630 } 2654 }
2631 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah); 2655 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah);
2632 } 2656 }
2633 2657
2634 /* The following two are responsible for eventually wrong colors 2658 /* The following two are responsible for eventually wrong colors
2635 * in TV output. The DH (VB_NoLCD) conditions are unknown; the 2659 * in TV output. The DH (VB_NoLCD) conditions are unknown; the
2636 * b0 was found in some 651 machine (Pim; P4_23=0xe5); the b1 version 2660 * b0 was found in some 651 machine (Pim; P4_23=0xe5); the b1 version
2637 * in a 650 box (Jake). What is the criteria? 2661 * in a 650 box (Jake). What is the criteria?
2662 * Addendum: Another combination 651+301B-DH(b1) (Rapo) needs same
2663 * treatment like the 651+301B-DH(b0) case. Seems more to be the
2664 * chipset than the bridge revision.
2638 */ 2665 */
2639 2666
2640 if((IS_SIS740) || (HwInfo->jChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) { 2667 if((IS_SIS740) || (SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
2641 tempah = 0x30; 2668 tempah = 0x30;
2642 tempbl = 0xc0; 2669 tempbl = 0xc0;
2643 if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) || 2670 if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
@@ -2649,20 +2676,30 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2649 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0x3f,tempbl); 2676 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0x3f,tempbl);
2650 } else if(SiS_Pr->SiS_VBType & VB_SIS301) { 2677 } else if(SiS_Pr->SiS_VBType & VB_SIS301) {
2651 /* Fixes "TV-blue-bug" on 315+301 */ 2678 /* Fixes "TV-blue-bug" on 315+301 */
2652 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2c,0xcf); /* For 301 */ 2679 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2c,0xcf); /* For 301 */
2653 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f); 2680 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
2654 } else if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 2681 } else if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
2655 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30); /* For 30xLV */ 2682 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30); /* For 30xLV */
2656 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x21,0xc0);
2657 } else if((SiS_Pr->SiS_VBType & VB_NoLCD) && (bridgerev == 0xb0)) {
2658 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30); /* For 30xB-DH rev b0 (or "DH on 651"?) */
2659 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x21,0xc0); 2683 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x21,0xc0);
2684 } else if(SiS_Pr->SiS_VBType & VB_NoLCD) { /* For 301B-DH */
2685 tempah = 0x30; tempah2 = 0xc0;
2686 tempbl = 0xcf; tempbl2 = 0x3f;
2687 if(SiS_Pr->SiS_TVBlue == 0) {
2688 tempah = tempah2 = 0x00;
2689 } else if(SiS_Pr->SiS_TVBlue == -1) {
2690 /* Set on 651/M650, clear on 315/650 */
2691 if(!(IS_SIS65x)) /* (bridgerev != 0xb0) */ {
2692 tempah = tempah2 = 0x00;
2693 }
2694 }
2695 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,tempbl,tempah);
2696 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,tempbl2,tempah2);
2660 } else { 2697 } else {
2661 tempah = 0x30; tempah2 = 0xc0; /* For 30xB (and 301BDH rev b1) */ 2698 tempah = 0x30; tempah2 = 0xc0; /* For 30xB, 301C */
2662 tempbl = 0xcf; tempbl2 = 0x3f; 2699 tempbl = 0xcf; tempbl2 = 0x3f;
2663 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { 2700 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
2664 tempah = tempah2 = 0x00; 2701 tempah = tempah2 = 0x00;
2665 if(SiS_IsDualEdge(SiS_Pr, HwInfo)) { 2702 if(SiS_IsDualEdge(SiS_Pr)) {
2666 tempbl = tempbl2 = 0xff; 2703 tempbl = tempbl2 = 0xff;
2667 } 2704 }
2668 } 2705 }
@@ -2676,23 +2713,23 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2676 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,0x7f,tempah); 2713 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,0x7f,tempah);
2677 } else { 2714 } else {
2678 tempah = 0x00; 2715 tempah = 0x00;
2679 tempbl = 0x7f; 2716 tempbl = 0x7f;
2680 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { 2717 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
2681 tempbl = 0xff; 2718 tempbl = 0xff;
2682 if(!(SiS_IsDualEdge(SiS_Pr, HwInfo))) tempah = 0x80; 2719 if(!(SiS_IsDualEdge(SiS_Pr))) tempah = 0x80;
2683 } 2720 }
2684 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,tempbl,tempah); 2721 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,tempbl,tempah);
2685 } 2722 }
2686 2723
2687#endif /* SIS315H */ 2724#endif /* SIS315H */
2688 2725
2689 } else if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 2726 } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
2690 2727
2691#ifdef SIS300 2728#ifdef SIS300
2692 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f); 2729 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
2693 2730
2694 if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) || 2731 if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
2695 ((SiS_Pr->SiS_VBType & VB_NoLCD) && 2732 ((SiS_Pr->SiS_VBType & VB_NoLCD) &&
2696 (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD))) { 2733 (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD))) {
2697 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x23,0x7F); 2734 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x23,0x7F);
2698 } else { 2735 } else {
@@ -2702,9 +2739,9 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2702 2739
2703 } 2740 }
2704 2741
2705 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 2742 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
2706 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x0D,0x80); 2743 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x0D,0x80);
2707 if(SiS_Pr->SiS_VBType & VB_SIS301C) { 2744 if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
2708 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3A,0xC0); 2745 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3A,0xC0);
2709 } 2746 }
2710 } 2747 }
@@ -2712,16 +2749,16 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2712 } else { /* LVDS */ 2749 } else { /* LVDS */
2713 2750
2714#ifdef SIS315H 2751#ifdef SIS315H
2715 if(HwInfo->jChipType >= SIS_315H) { 2752 if(SiS_Pr->ChipType >= SIS_315H) {
2716 2753
2717 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 2754 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
2718 2755
2719 tempah = 0x04; 2756 tempah = 0x04;
2720 tempbl = 0xfb; 2757 tempbl = 0xfb;
2721 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { 2758 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
2722 tempah = 0x00; 2759 tempah = 0x00;
2723 if(SiS_IsDualEdge(SiS_Pr, HwInfo)) tempbl = 0xff; 2760 if(SiS_IsDualEdge(SiS_Pr)) tempbl = 0xff;
2724 } 2761 }
2725 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah); 2762 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah);
2726 2763
2727 if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) { 2764 if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
@@ -2730,7 +2767,7 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2730 2767
2731 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30); 2768 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30);
2732 2769
2733 } else if(HwInfo->jChipType == SIS_550) { 2770 } else if(SiS_Pr->ChipType == SIS_550) {
2734 2771
2735 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb); 2772 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
2736 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30); 2773 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30);
@@ -2748,212 +2785,120 @@ SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2748/* GET RESOLUTION DATA */ 2785/* GET RESOLUTION DATA */
2749/*********************************************/ 2786/*********************************************/
2750 2787
2751USHORT 2788unsigned short
2752SiS_GetResInfo(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex) 2789SiS_GetResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
2753{ 2790{
2754 if(ModeNo <= 0x13) return((USHORT)SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo); 2791 if(ModeNo <= 0x13)
2755 else return((USHORT)SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO); 2792 return ((unsigned short)SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo);
2793 else
2794 return ((unsigned short)SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO);
2756} 2795}
2757 2796
2758static void 2797static void
2759SiS_GetCRT2ResInfo(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex, 2798SiS_GetCRT2ResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
2760 PSIS_HW_INFO HwInfo)
2761{ 2799{
2762 USHORT xres,yres,modeflag=0,resindex; 2800 unsigned short xres, yres, modeflag=0, resindex;
2763 2801
2764 if(SiS_Pr->UseCustomMode) { 2802 if(SiS_Pr->UseCustomMode) {
2765 xres = SiS_Pr->CHDisplay; 2803 xres = SiS_Pr->CHDisplay;
2766 if(SiS_Pr->CModeFlag & HalfDCLK) xres *= 2; 2804 if(SiS_Pr->CModeFlag & HalfDCLK) xres <<= 1;
2767 SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres; 2805 SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
2768 yres = SiS_Pr->CVDisplay; 2806 /* DoubleScanMode-check done in CheckCalcCustomMode()! */
2769 if(SiS_Pr->CModeFlag & DoubleScanMode) yres *= 2; 2807 SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = SiS_Pr->CVDisplay;
2770 SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = yres; 2808 return;
2771 return; 2809 }
2772 }
2773
2774 resindex = SiS_GetResInfo(SiS_Pr,ModeNo,ModeIdIndex);
2775 2810
2776 if(ModeNo <= 0x13) { 2811 resindex = SiS_GetResInfo(SiS_Pr,ModeNo,ModeIdIndex);
2777 xres = SiS_Pr->SiS_StResInfo[resindex].HTotal;
2778 yres = SiS_Pr->SiS_StResInfo[resindex].VTotal;
2779 } else {
2780 xres = SiS_Pr->SiS_ModeResInfo[resindex].HTotal;
2781 yres = SiS_Pr->SiS_ModeResInfo[resindex].VTotal;
2782 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2783 }
2784 2812
2785 if(!SiS_Pr->SiS_IF_DEF_DSTN && !SiS_Pr->SiS_IF_DEF_FSTN) { 2813 if(ModeNo <= 0x13) {
2814 xres = SiS_Pr->SiS_StResInfo[resindex].HTotal;
2815 yres = SiS_Pr->SiS_StResInfo[resindex].VTotal;
2816 } else {
2817 xres = SiS_Pr->SiS_ModeResInfo[resindex].HTotal;
2818 yres = SiS_Pr->SiS_ModeResInfo[resindex].VTotal;
2819 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2820 }
2786 2821
2787 if((HwInfo->jChipType >= SIS_315H) && (SiS_Pr->SiS_IF_DEF_LVDS == 1)) { 2822 if(!SiS_Pr->SiS_IF_DEF_DSTN && !SiS_Pr->SiS_IF_DEF_FSTN) {
2788 if((ModeNo != 0x03) && (SiS_Pr->SiS_SetFlag & SetDOSMode)) {
2789 if(yres == 350) yres = 400;
2790 }
2791 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x3a) & 0x01) {
2792 if(ModeNo == 0x12) yres = 400;
2793 }
2794 }
2795 2823
2796 if(modeflag & HalfDCLK) xres *= 2; 2824 if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_IF_DEF_LVDS == 1)) {
2797 if(modeflag & DoubleScanMode) yres *= 2; 2825 if((ModeNo != 0x03) && (SiS_Pr->SiS_SetFlag & SetDOSMode)) {
2826 if(yres == 350) yres = 400;
2827 }
2828 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x3a) & 0x01) {
2829 if(ModeNo == 0x12) yres = 400;
2830 }
2831 }
2798 2832
2799 } 2833 if(modeflag & HalfDCLK) xres <<= 1;
2834 if(modeflag & DoubleScanMode) yres <<= 1;
2800 2835
2801 if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) { 2836 }
2802 2837
2803#if 0 2838 if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
2804 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCDA | SetCRT2ToLCD | SetCRT2ToHiVision)) {
2805 if(xres == 720) xres = 640;
2806 }
2807#endif
2808 2839
2809 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 2840 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
2810 switch(SiS_Pr->SiS_LCDResInfo) { 2841 switch(SiS_Pr->SiS_LCDResInfo) {
2811 case Panel_1024x768: 2842 case Panel_1024x768:
2812 if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) { 2843 if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
2813 if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { 2844 if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
2814 if(yres == 350) yres = 357; 2845 if(yres == 350) yres = 357;
2815 if(yres == 400) yres = 420; 2846 if(yres == 400) yres = 420;
2816 if(yres == 480) yres = 525; 2847 if(yres == 480) yres = 525;
2817 } 2848 }
2818 } 2849 }
2819 break; 2850 break;
2820 case Panel_1280x1024: 2851 case Panel_1280x1024:
2821 if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { 2852 if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
2822 /* BIOS bug - does this regardless of scaling */ 2853 /* BIOS bug - does this regardless of scaling */
2823 if(yres == 400) yres = 405; 2854 if(yres == 400) yres = 405;
2855 }
2856 if(yres == 350) yres = 360;
2857 if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
2858 if(yres == 360) yres = 375;
2824 } 2859 }
2825 if(yres == 350) yres = 360;
2826 if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
2827 if(yres == 360) yres = 375;
2828 }
2829 break; 2860 break;
2830 case Panel_1600x1200: 2861 case Panel_1600x1200:
2831 if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) { 2862 if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
2832 if(yres == 1024) yres = 1056; 2863 if(yres == 1024) yres = 1056;
2833 } 2864 }
2834 break; 2865 break;
2835 } 2866 }
2836 } 2867 }
2837 2868
2838 } else { 2869 } else {
2839 2870
2840 if(SiS_Pr->SiS_VBType & VB_SISVB) { 2871 if(SiS_Pr->SiS_VBType & VB_SISVB) {
2841 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToHiVision)) { 2872 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToHiVision)) {
2842 if(xres == 720) xres = 640; 2873 if(xres == 720) xres = 640;
2843 } 2874 }
2844 } else if(xres == 720) xres = 640; 2875 } else if(xres == 720) xres = 640;
2845 2876
2846 if(SiS_Pr->SiS_SetFlag & SetDOSMode) { 2877 if(SiS_Pr->SiS_SetFlag & SetDOSMode) {
2847 yres = 400; 2878 yres = 400;
2848 if(HwInfo->jChipType >= SIS_315H) { 2879 if(SiS_Pr->ChipType >= SIS_315H) {
2849 if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x17) & 0x80) yres = 480; 2880 if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x17) & 0x80) yres = 480;
2850 } else { 2881 } else {
2851 if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) yres = 480; 2882 if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) yres = 480;
2852 } 2883 }
2853 if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) yres = 480; 2884 if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) yres = 480;
2854 } 2885 }
2855 2886
2856 } 2887 }
2857 SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres; 2888 SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
2858 SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = yres; 2889 SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = yres;
2859} 2890}
2860 2891
2861/*********************************************/ 2892/*********************************************/
2862/* GET CRT2 TIMING DATA */ 2893/* GET CRT2 TIMING DATA */
2863/*********************************************/ 2894/*********************************************/
2864 2895
2865static BOOLEAN
2866SiS_GetLVDSCRT1Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
2867 USHORT RefreshRateTableIndex, USHORT *ResIndex,
2868 USHORT *DisplayType)
2869 {
2870 USHORT modeflag=0;
2871
2872 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
2873 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
2874 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return FALSE;
2875 }
2876 } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
2877 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return FALSE;
2878 } else
2879 return FALSE;
2880
2881 if(ModeNo <= 0x13) {
2882 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
2883 (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2884 } else {
2885 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2886 (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2887 }
2888
2889 (*ResIndex) &= 0x3F;
2890
2891 if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
2892 (*DisplayType) = 18;
2893 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*DisplayType)++;
2894 if(SiS_Pr->SiS_TVMode & TVSetPAL) {
2895 (*DisplayType) += 2;
2896 if(SiS_Pr->SiS_ModeType > ModeVGA) {
2897 if(SiS_Pr->SiS_CHSOverScan) (*DisplayType) = 99;
2898 }
2899 if(SiS_Pr->SiS_TVMode & TVSetPALM) {
2900 (*DisplayType) = 18; /* PALM uses NTSC data */
2901 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*DisplayType)++;
2902 } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
2903 (*DisplayType) = 20; /* PALN uses PAL data */
2904 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*DisplayType)++;
2905 }
2906 }
2907 } else {
2908 switch(SiS_Pr->SiS_LCDResInfo) {
2909 case Panel_640x480: (*DisplayType) = 50; break;
2910 case Panel_640x480_2: (*DisplayType) = 52; break;
2911 case Panel_640x480_3: (*DisplayType) = 54; break;
2912 case Panel_800x600: (*DisplayType) = 0; break;
2913 case Panel_1024x600: (*DisplayType) = 23; break;
2914 case Panel_1024x768: (*DisplayType) = 4; break;
2915 case Panel_1152x768: (*DisplayType) = 27; break;
2916 case Panel_1280x768: (*DisplayType) = 40; break;
2917 case Panel_1280x1024: (*DisplayType) = 8; break;
2918 case Panel_1400x1050: (*DisplayType) = 14; break;
2919 case Panel_1600x1200: (*DisplayType) = 36; break;
2920 default: return FALSE;
2921 }
2922
2923 if(modeflag & HalfDCLK) (*DisplayType)++;
2924
2925 switch(SiS_Pr->SiS_LCDResInfo) {
2926 case Panel_640x480:
2927 case Panel_640x480_2:
2928 case Panel_640x480_3:
2929 break;
2930 default:
2931 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) (*DisplayType) += 2;
2932 }
2933
2934 if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
2935 (*DisplayType) = 12;
2936 if(modeflag & HalfDCLK) (*DisplayType)++;
2937 }
2938 }
2939
2940#if 0
2941 if(SiS_Pr->SiS_IF_DEF_FSTN) {
2942 if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel320x480){
2943 (*DisplayType) = 22;
2944 }
2945 }
2946#endif
2947
2948 return TRUE;
2949}
2950
2951static void 2896static void
2952SiS_GetCRT2Ptr(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex, 2897SiS_GetCRT2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
2953 USHORT RefreshRateTableIndex,USHORT *CRT2Index,USHORT *ResIndex, 2898 unsigned short RefreshRateTableIndex, unsigned short *CRT2Index,
2954 PSIS_HW_INFO HwInfo) 2899 unsigned short *ResIndex)
2955{ 2900{
2956 USHORT tempbx=0,tempal=0,resinfo=0; 2901 unsigned short tempbx=0, tempal=0, resinfo=0;
2957 2902
2958 if(ModeNo <= 0x13) { 2903 if(ModeNo <= 0x13) {
2959 tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; 2904 tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
@@ -2966,18 +2911,20 @@ SiS_GetCRT2Ptr(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
2966 2911
2967 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { /* LCD */ 2912 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { /* LCD */
2968 2913
2969 tempbx = SiS_Pr->SiS_LCDResInfo; 2914 tempbx = SiS_Pr->SiS_LCDResInfo;
2970 if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 32; 2915 if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 32;
2971 2916
2917 /* patch index */
2972 if(SiS_Pr->SiS_LCDResInfo == Panel_1680x1050) { 2918 if(SiS_Pr->SiS_LCDResInfo == Panel_1680x1050) {
2973 if (resinfo == SIS_RI_1280x800) tempal = 9; 2919 if (resinfo == SIS_RI_1280x800) tempal = 9;
2974 else if(resinfo == SIS_RI_1400x1050) tempal = 11; 2920 else if(resinfo == SIS_RI_1400x1050) tempal = 11;
2975 } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x800) || 2921 } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x800) ||
2976 (SiS_Pr->SiS_LCDResInfo == Panel_1280x800_2)) { 2922 (SiS_Pr->SiS_LCDResInfo == Panel_1280x800_2) ||
2923 (SiS_Pr->SiS_LCDResInfo == Panel_1280x854)) {
2977 if (resinfo == SIS_RI_1280x768) tempal = 9; 2924 if (resinfo == SIS_RI_1280x768) tempal = 9;
2978 } 2925 }
2979 2926
2980 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { 2927 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
2981 /* Pass 1:1 only (center-screen handled outside) */ 2928 /* Pass 1:1 only (center-screen handled outside) */
2982 /* This is never called for the panel's native resolution */ 2929 /* This is never called for the panel's native resolution */
2983 /* since Pass1:1 will not be set in this case */ 2930 /* since Pass1:1 will not be set in this case */
@@ -2991,8 +2938,8 @@ SiS_GetCRT2Ptr(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
2991 if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) { 2938 if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
2992 if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) { 2939 if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
2993 if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { 2940 if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
2994 tempbx = 200; 2941 tempbx = 200;
2995 if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++; 2942 if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++;
2996 } 2943 }
2997 } 2944 }
2998 } 2945 }
@@ -3000,23 +2947,23 @@ SiS_GetCRT2Ptr(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
3000 2947
3001 } else { /* TV */ 2948 } else { /* TV */
3002 2949
3003 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { 2950 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
3004 /* if(SiS_Pr->SiS_VGAVDE > 480) SiS_Pr->SiS_TVMode &= (~TVSetTVSimuMode); */ 2951 /* if(SiS_Pr->SiS_VGAVDE > 480) SiS_Pr->SiS_TVMode &= (~TVSetTVSimuMode); */
3005 tempbx = 2; 2952 tempbx = 2;
3006 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { 2953 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
3007 tempbx = 13; 2954 tempbx = 13;
3008 if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) tempbx = 14; 2955 if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) tempbx = 14;
3009 } 2956 }
3010 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { 2957 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
3011 if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempbx = 7; 2958 if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempbx = 7;
3012 else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempbx = 6; 2959 else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempbx = 6;
3013 else tempbx = 5; 2960 else tempbx = 5;
3014 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5; 2961 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5;
3015 } else { 2962 } else {
3016 if(SiS_Pr->SiS_TVMode & TVSetPAL) tempbx = 3; 2963 if(SiS_Pr->SiS_TVMode & TVSetPAL) tempbx = 3;
3017 else tempbx = 4; 2964 else tempbx = 4;
3018 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5; 2965 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5;
3019 } 2966 }
3020 2967
3021 } 2968 }
3022 2969
@@ -3024,26 +2971,34 @@ SiS_GetCRT2Ptr(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
3024 2971
3025 if(ModeNo > 0x13) { 2972 if(ModeNo > 0x13) {
3026 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) { 2973 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) {
3027 if(tempal == 6) tempal = 7; 2974 switch(resinfo) {
3028 if((resinfo == SIS_RI_720x480) || 2975 case SIS_RI_720x480:
3029 (resinfo == SIS_RI_720x576) ||
3030 (resinfo == SIS_RI_768x576)) {
3031 tempal = 6; 2976 tempal = 6;
3032 if(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetPALN)) { 2977 if(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetPALN)) tempal = 9;
3033 if(resinfo == SIS_RI_720x480) tempal = 9; 2978 break;
2979 case SIS_RI_720x576:
2980 case SIS_RI_768x576:
2981 case SIS_RI_1024x576: /* Not in NTSC or YPBPR mode (except 1080i)! */
2982 tempal = 6;
2983 if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
2984 if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempal = 8;
3034 } 2985 }
3035 } 2986 break;
3036 if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { 2987 case SIS_RI_800x480:
3037 if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) { 2988 tempal = 4;
3038 if(resinfo == SIS_RI_1024x768) tempal = 8; 2989 break;
2990 case SIS_RI_512x384:
2991 case SIS_RI_1024x768:
2992 tempal = 7;
2993 if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
2994 if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempal = 8;
3039 } 2995 }
3040 if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) { 2996 break;
3041 if((resinfo == SIS_RI_720x576) || 2997 case SIS_RI_1280x720:
3042 (resinfo == SIS_RI_768x576)) { 2998 if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
3043 tempal = 8; 2999 if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempal = 9;
3044 }
3045 if(resinfo == SIS_RI_1280x720) tempal = 9;
3046 } 3000 }
3001 break;
3047 } 3002 }
3048 } 3003 }
3049 } 3004 }
@@ -3056,65 +3011,60 @@ SiS_GetCRT2Ptr(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
3056 tempbx = 0; 3011 tempbx = 0;
3057 if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) { 3012 if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
3058 3013
3059 tempbx = 10; 3014 tempbx = 90;
3060 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1; 3015 if(SiS_Pr->SiS_TVMode & TVSetPAL) {
3061 if(SiS_Pr->SiS_TVMode & TVSetPAL) { 3016 tempbx = 92;
3062 tempbx += 2;
3063 if(SiS_Pr->SiS_ModeType > ModeVGA) { 3017 if(SiS_Pr->SiS_ModeType > ModeVGA) {
3064 if(SiS_Pr->SiS_CHSOverScan) tempbx = 99; 3018 if(SiS_Pr->SiS_CHSOverScan) tempbx = 99;
3065 } 3019 }
3066 if(SiS_Pr->SiS_TVMode & TVSetPALM) { 3020 if(SiS_Pr->SiS_TVMode & TVSetPALM) tempbx = 94;
3067 tempbx = 90; 3021 else if(SiS_Pr->SiS_TVMode & TVSetPALN) tempbx = 96;
3068 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1; 3022 }
3069 } else if(SiS_Pr->SiS_TVMode & TVSetPALN) { 3023 if(tempbx != 99) {
3070 tempbx = 92; 3024 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx++;
3071 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1; 3025 }
3072 }
3073 }
3074 3026
3075 } else { 3027 } else {
3076 3028
3077 switch(SiS_Pr->SiS_LCDResInfo) { 3029 switch(SiS_Pr->SiS_LCDResInfo) {
3078 case Panel_640x480: tempbx = 6; break; 3030 case Panel_640x480: tempbx = 12; break;
3079 case Panel_640x480_2: 3031 case Panel_320x240_1: tempbx = 10; break;
3080 case Panel_640x480_3: tempbx = 30; break; 3032 case Panel_320x240_2:
3081 case Panel_800x600: tempbx = 0; break; 3033 case Panel_320x240_3: tempbx = 14; break;
3082 case Panel_1024x600: tempbx = 15; break; 3034 case Panel_800x600: tempbx = 16; break;
3083 case Panel_1024x768: tempbx = 2; break; 3035 case Panel_1024x600: tempbx = 18; break;
3084 case Panel_1152x768: tempbx = 17; break; 3036 case Panel_1152x768:
3085 case Panel_1280x768: tempbx = 18; break; 3037 case Panel_1024x768: tempbx = 20; break;
3086 case Panel_1280x1024: tempbx = 4; break; 3038 case Panel_1280x768: tempbx = 22; break;
3087 case Panel_1400x1050: tempbx = 8; break; 3039 case Panel_1280x1024: tempbx = 24; break;
3088 case Panel_1600x1200: tempbx = 21; break; 3040 case Panel_1400x1050: tempbx = 26; break;
3041 case Panel_1600x1200: tempbx = 28; break;
3042#ifdef SIS300
3089 case Panel_Barco1366: tempbx = 80; break; 3043 case Panel_Barco1366: tempbx = 80; break;
3044#endif
3090 } 3045 }
3091 3046
3092 switch(SiS_Pr->SiS_LCDResInfo) { 3047 switch(SiS_Pr->SiS_LCDResInfo) {
3048 case Panel_320x240_1:
3049 case Panel_320x240_2:
3050 case Panel_320x240_3:
3093 case Panel_640x480: 3051 case Panel_640x480:
3094 case Panel_640x480_2:
3095 case Panel_640x480_3:
3096 break; 3052 break;
3097 default: 3053 default:
3098 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++; 3054 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
3099 } 3055 }
3100 3056
3101 if(SiS_Pr->SiS_LCDInfo & LCDPass11) tempbx = 7; 3057 if(SiS_Pr->SiS_LCDInfo & LCDPass11) tempbx = 30;
3102 3058
3059#ifdef SIS300
3103 if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) { 3060 if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
3104 tempbx = 82; 3061 tempbx = 82;
3105 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++; 3062 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
3106 } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848) { 3063 } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
3107 tempbx = 84; 3064 tempbx = 84;
3108 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++; 3065 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
3109 } 3066 }
3110 3067#endif
3111 if((SiS_Pr->SiS_CustomT != CUT_BARCO1366) &&
3112 (SiS_Pr->SiS_CustomT != CUT_PANEL848)) {
3113 if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) &&
3114 (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
3115 tempal = 0;
3116 }
3117 }
3118 3068
3119 } 3069 }
3120 3070
@@ -3124,12 +3074,11 @@ SiS_GetCRT2Ptr(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
3124} 3074}
3125 3075
3126static void 3076static void
3127SiS_GetRAMDAC2DATA(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex, 3077SiS_GetRAMDAC2DATA(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
3128 USHORT RefreshRateTableIndex,PSIS_HW_INFO HwInfo) 3078 unsigned short RefreshRateTableIndex)
3129{ 3079{
3130 USHORT tempax=0,tempbx=0; 3080 unsigned short tempax=0, tempbx=0, index, dotclock;
3131 USHORT temp1=0,modeflag=0,tempcx=0; 3081 unsigned short temp1=0, modeflag=0, tempcx=0;
3132 USHORT index;
3133 3082
3134 SiS_Pr->SiS_RVBHCMAX = 1; 3083 SiS_Pr->SiS_RVBHCMAX = 1;
3135 SiS_Pr->SiS_RVBHCFACT = 1; 3084 SiS_Pr->SiS_RVBHCFACT = 1;
@@ -3143,10 +3092,12 @@ SiS_GetRAMDAC2DATA(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
3143 tempbx = SiS_Pr->SiS_StandTable[index].CRTC[6]; 3092 tempbx = SiS_Pr->SiS_StandTable[index].CRTC[6];
3144 temp1 = SiS_Pr->SiS_StandTable[index].CRTC[7]; 3093 temp1 = SiS_Pr->SiS_StandTable[index].CRTC[7];
3145 3094
3095 dotclock = (modeflag & Charx8Dot) ? 8 : 9;
3096
3146 } else { 3097 } else {
3147 3098
3148 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 3099 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3149 index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; 3100 index = SiS_GetRefCRT1CRTC(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWideCRT2);
3150 3101
3151 tempax = SiS_Pr->SiS_CRT1Table[index].CR[0]; 3102 tempax = SiS_Pr->SiS_CRT1Table[index].CR[0];
3152 tempax |= (SiS_Pr->SiS_CRT1Table[index].CR[14] << 8); 3103 tempax |= (SiS_Pr->SiS_CRT1Table[index].CR[14] << 8);
@@ -3158,22 +3109,16 @@ SiS_GetRAMDAC2DATA(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
3158 tempbx |= tempcx; 3109 tempbx |= tempcx;
3159 temp1 = SiS_Pr->SiS_CRT1Table[index].CR[7]; 3110 temp1 = SiS_Pr->SiS_CRT1Table[index].CR[7];
3160 3111
3112 dotclock = 8;
3113
3161 } 3114 }
3162 3115
3163 if(temp1 & 0x01) tempbx |= 0x0100; 3116 if(temp1 & 0x01) tempbx |= 0x0100;
3164 if(temp1 & 0x20) tempbx |= 0x0200; 3117 if(temp1 & 0x20) tempbx |= 0x0200;
3165 3118
3166 tempax += 5; 3119 tempax += 5;
3167 3120 tempax *= dotclock;
3168 /* Charx8Dot is no more used (and assumed), so we set it */ 3121 if(modeflag & HalfDCLK) tempax <<= 1;
3169 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
3170 modeflag |= Charx8Dot;
3171 }
3172
3173 if(modeflag & Charx8Dot) tempax *= 8;
3174 else tempax *= 9;
3175
3176 if(modeflag & HalfDCLK) tempax <<= 1;
3177 3122
3178 tempbx++; 3123 tempbx++;
3179 3124
@@ -3182,13 +3127,56 @@ SiS_GetRAMDAC2DATA(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
3182} 3127}
3183 3128
3184static void 3129static void
3185SiS_GetCRT2DataLVDS(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex, 3130SiS_CalcPanelLinkTiming(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
3186 USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo) 3131 unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex)
3132{
3133 unsigned short ResIndex;
3134
3135 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3136 if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
3137 if(SiS_Pr->UseCustomMode) {
3138 ResIndex = SiS_Pr->CHTotal;
3139 if(SiS_Pr->CModeFlag & HalfDCLK) ResIndex <<= 1;
3140 SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = ResIndex;
3141 SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
3142 } else {
3143 if(ModeNo < 0x13) {
3144 ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
3145 } else {
3146 ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
3147 }
3148 if(ResIndex == 0x09) {
3149 if(SiS_Pr->Alternate1600x1200) ResIndex = 0x20; /* 1600x1200 LCDA */
3150 else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) ResIndex = 0x21; /* 1600x1200 LVDS */
3151 }
3152 SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAHT;
3153 SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAVT;
3154 SiS_Pr->SiS_HT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDHT;
3155 SiS_Pr->SiS_VT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDVT;
3156 }
3157 } else {
3158 SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
3159 SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
3160 }
3161 } else {
3162 /* This handles custom modes and custom panels */
3163 SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
3164 SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
3165 SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
3166 SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
3167 SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT - (SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE);
3168 SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT - (SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE);
3169 }
3170}
3171
3172static void
3173SiS_GetCRT2DataLVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
3174 unsigned short RefreshRateTableIndex)
3187{ 3175{
3188 USHORT CRT2Index, ResIndex; 3176 unsigned short CRT2Index, ResIndex, backup;
3189 const SiS_LVDSDataStruct *LVDSData = NULL; 3177 const struct SiS_LVDSData *LVDSData = NULL;
3190 3178
3191 SiS_GetCRT2ResInfo(SiS_Pr, ModeNo, ModeIdIndex, HwInfo); 3179 SiS_GetCRT2ResInfo(SiS_Pr, ModeNo, ModeIdIndex);
3192 3180
3193 if(SiS_Pr->SiS_VBType & VB_SISVB) { 3181 if(SiS_Pr->SiS_VBType & VB_SISVB) {
3194 SiS_Pr->SiS_RVBHCMAX = 1; 3182 SiS_Pr->SiS_RVBHCMAX = 1;
@@ -3199,133 +3187,94 @@ SiS_GetCRT2DataLVDS(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
3199 SiS_Pr->SiS_RY2COE = 0; 3187 SiS_Pr->SiS_RY2COE = 0;
3200 SiS_Pr->SiS_RY3COE = 0; 3188 SiS_Pr->SiS_RY3COE = 0;
3201 SiS_Pr->SiS_RY4COE = 0; 3189 SiS_Pr->SiS_RY4COE = 0;
3190 SiS_Pr->SiS_RVBHRS2 = 0;
3202 } 3191 }
3203 3192
3204 if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { 3193 if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
3205 3194
3206#ifdef SIS315H 3195#ifdef SIS315H
3207 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { 3196 SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3208 if(SiS_Pr->SiS_LCDInfo & LCDPass11) { 3197 SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex);
3209 if(SiS_Pr->UseCustomMode) {
3210 SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = SiS_Pr->CHTotal;
3211 SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
3212 } else {
3213 if(ModeNo < 0x13) {
3214 ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
3215 } else {
3216 ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
3217 }
3218 SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAHT;
3219 SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAVT;
3220 SiS_Pr->SiS_HT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDHT;
3221 SiS_Pr->SiS_VT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDVT;
3222 }
3223 } else {
3224 SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
3225 SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
3226 }
3227 } else {
3228 /* This handles custom modes and custom panels */
3229 SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
3230 SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
3231 SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
3232 SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
3233 SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT - (SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE);
3234 SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT - (SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE);
3235 }
3236
3237 SiS_CalcLCDACRT1Timing(SiS_Pr,ModeNo,ModeIdIndex);
3238
3239#endif 3198#endif
3240 3199
3241 } else { 3200 } else {
3242 3201
3243 /* 301BDH needs LVDS Data */ 3202 /* 301BDH needs LVDS Data */
3203 backup = SiS_Pr->SiS_IF_DEF_LVDS;
3244 if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { 3204 if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
3245 SiS_Pr->SiS_IF_DEF_LVDS = 1; 3205 SiS_Pr->SiS_IF_DEF_LVDS = 1;
3246 } 3206 }
3247 3207
3248 SiS_GetCRT2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, 3208 SiS_GetCRT2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
3249 &CRT2Index, &ResIndex, HwInfo); 3209 &CRT2Index, &ResIndex);
3250 3210
3251 /* 301BDH needs LVDS Data */ 3211 SiS_Pr->SiS_IF_DEF_LVDS = backup;
3252 if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
3253 SiS_Pr->SiS_IF_DEF_LVDS = 0;
3254 }
3255 3212
3256 switch (CRT2Index) { 3213 switch(CRT2Index) {
3257 case 0: LVDSData = SiS_Pr->SiS_LVDS800x600Data_1; break; 3214 case 10: LVDSData = SiS_Pr->SiS_LVDS320x240Data_1; break;
3258 case 1: LVDSData = SiS_Pr->SiS_LVDS800x600Data_2; break; 3215 case 14: LVDSData = SiS_Pr->SiS_LVDS320x240Data_2; break;
3259 case 2: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break; 3216 case 12: LVDSData = SiS_Pr->SiS_LVDS640x480Data_1; break;
3260 case 3: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_2; break; 3217 case 16: LVDSData = SiS_Pr->SiS_LVDS800x600Data_1; break;
3261 case 4: LVDSData = SiS_Pr->SiS_LVDS1280x1024Data_1; break; 3218 case 18: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_1; break;
3262 case 5: LVDSData = SiS_Pr->SiS_LVDS1280x1024Data_2; break; 3219 case 20: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break;
3263 case 6: LVDSData = SiS_Pr->SiS_LVDS640x480Data_1; break; 3220#ifdef SIS300
3264 case 7: LVDSData = SiS_Pr->SiS_LVDSXXXxXXXData_1; break;
3265 case 8: LVDSData = SiS_Pr->SiS_LVDS1400x1050Data_1; break;
3266 case 9: LVDSData = SiS_Pr->SiS_LVDS1400x1050Data_2; break;
3267 case 10: LVDSData = SiS_Pr->SiS_CHTVUNTSCData; break;
3268 case 11: LVDSData = SiS_Pr->SiS_CHTVONTSCData; break;
3269 case 12: LVDSData = SiS_Pr->SiS_CHTVUPALData; break;
3270 case 13: LVDSData = SiS_Pr->SiS_CHTVOPALData; break;
3271 case 14: LVDSData = SiS_Pr->SiS_LVDS320x480Data_1; break;
3272 case 15: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_1; break;
3273 case 16: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_2; break;
3274 case 17: LVDSData = SiS_Pr->SiS_LVDS1152x768Data_1; break;
3275 case 18: LVDSData = SiS_Pr->SiS_LVDS1152x768Data_2; break;
3276 case 19: LVDSData = SiS_Pr->SiS_LVDS1280x768Data_1; break;
3277 case 20: LVDSData = SiS_Pr->SiS_LVDS1280x768Data_2; break;
3278 case 21: LVDSData = SiS_Pr->SiS_LVDS1600x1200Data_1; break;
3279 case 22: LVDSData = SiS_Pr->SiS_LVDS1600x1200Data_2; break;
3280 case 30: LVDSData = SiS_Pr->SiS_LVDS640x480Data_2; break;
3281 case 80: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_1; break; 3221 case 80: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_1; break;
3282 case 81: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_2; break; 3222 case 81: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_2; break;
3283 case 82: LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_1; break; 3223 case 82: LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_1; break;
3284 case 83: LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_2; break;
3285 case 84: LVDSData = SiS_Pr->SiS_LVDS848x480Data_1; break; 3224 case 84: LVDSData = SiS_Pr->SiS_LVDS848x480Data_1; break;
3286 case 85: LVDSData = SiS_Pr->SiS_LVDS848x480Data_2; break; 3225 case 85: LVDSData = SiS_Pr->SiS_LVDS848x480Data_2; break;
3287 case 90: LVDSData = SiS_Pr->SiS_CHTVUPALMData; break; 3226#endif
3288 case 91: LVDSData = SiS_Pr->SiS_CHTVOPALMData; break; 3227 case 90: LVDSData = SiS_Pr->SiS_CHTVUNTSCData; break;
3289 case 92: LVDSData = SiS_Pr->SiS_CHTVUPALNData; break; 3228 case 91: LVDSData = SiS_Pr->SiS_CHTVONTSCData; break;
3290 case 93: LVDSData = SiS_Pr->SiS_CHTVOPALNData; break; 3229 case 92: LVDSData = SiS_Pr->SiS_CHTVUPALData; break;
3291 case 99: LVDSData = SiS_Pr->SiS_CHTVSOPALData; break; /* Super Overscan */ 3230 case 93: LVDSData = SiS_Pr->SiS_CHTVOPALData; break;
3292 default: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break; 3231 case 94: LVDSData = SiS_Pr->SiS_CHTVUPALMData; break;
3232 case 95: LVDSData = SiS_Pr->SiS_CHTVOPALMData; break;
3233 case 96: LVDSData = SiS_Pr->SiS_CHTVUPALNData; break;
3234 case 97: LVDSData = SiS_Pr->SiS_CHTVOPALNData; break;
3235 case 99: LVDSData = SiS_Pr->SiS_CHTVSOPALData; break;
3293 } 3236 }
3294 3237
3295 SiS_Pr->SiS_VGAHT = (LVDSData+ResIndex)->VGAHT; 3238 if(LVDSData) {
3296 SiS_Pr->SiS_VGAVT = (LVDSData+ResIndex)->VGAVT; 3239 SiS_Pr->SiS_VGAHT = (LVDSData+ResIndex)->VGAHT;
3297 SiS_Pr->SiS_HT = (LVDSData+ResIndex)->LCDHT; 3240 SiS_Pr->SiS_VGAVT = (LVDSData+ResIndex)->VGAVT;
3298 SiS_Pr->SiS_VT = (LVDSData+ResIndex)->LCDVT; 3241 SiS_Pr->SiS_HT = (LVDSData+ResIndex)->LCDHT;
3299 3242 SiS_Pr->SiS_VT = (LVDSData+ResIndex)->LCDVT;
3300 if(!(SiS_Pr->SiS_VBType & VB_SISVB)) { 3243 } else {
3301 if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) { 3244 SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3302 if((!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) || (SiS_Pr->SiS_SetFlag & SetDOSMode)) { 3245 }
3303 SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes; 3246
3304 SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes; 3247 if( (!(SiS_Pr->SiS_VBType & VB_SISVB)) &&
3305 if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) { 3248 (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) &&
3306 if(ResIndex < 0x08) { 3249 (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) ) {
3307 SiS_Pr->SiS_HDE = 1280; 3250 if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ||
3308 SiS_Pr->SiS_VDE = 1024; 3251 (SiS_Pr->SiS_SetFlag & SetDOSMode) ) {
3309 } 3252 SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
3310 } 3253 SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
3311 } 3254#ifdef SIS300
3255 if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
3256 if(ResIndex < 0x08) {
3257 SiS_Pr->SiS_HDE = 1280;
3258 SiS_Pr->SiS_VDE = 1024;
3259 }
3260 }
3261#endif
3312 } 3262 }
3313 } 3263 }
3314 } 3264 }
3315} 3265}
3316 3266
3317static void 3267static void
3318SiS_GetCRT2Data301(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex, 3268SiS_GetCRT2Data301(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
3319 USHORT RefreshRateTableIndex, 3269 unsigned short RefreshRateTableIndex)
3320 PSIS_HW_INFO HwInfo) 3270{
3321{ 3271 unsigned char *ROMAddr = NULL;
3322 UCHAR *ROMAddr = NULL; 3272 unsigned short tempax, tempbx, modeflag, romptr=0;
3323 USHORT tempax,tempbx,modeflag,romptr=0; 3273 unsigned short resinfo, CRT2Index, ResIndex;
3324 USHORT resinfo,CRT2Index,ResIndex; 3274 const struct SiS_LCDData *LCDPtr = NULL;
3325 const SiS_LCDDataStruct *LCDPtr = NULL; 3275 const struct SiS_TVData *TVPtr = NULL;
3326 const SiS_TVDataStruct *TVPtr = NULL;
3327#ifdef SIS315H 3276#ifdef SIS315H
3328 SHORT resinfo661; 3277 short resinfo661;
3329#endif 3278#endif
3330 3279
3331 if(ModeNo <= 0x13) { 3280 if(ModeNo <= 0x13) {
@@ -3340,67 +3289,69 @@ SiS_GetCRT2Data301(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
3340#ifdef SIS315H 3289#ifdef SIS315H
3341 resinfo661 = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].ROMMODEIDX661; 3290 resinfo661 = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].ROMMODEIDX661;
3342 if( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && 3291 if( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) &&
3343 (SiS_Pr->SiS_SetFlag & LCDVESATiming) && 3292 (SiS_Pr->SiS_SetFlag & LCDVESATiming) &&
3344 (resinfo661 >= 0) && 3293 (resinfo661 >= 0) &&
3345 (SiS_Pr->SiS_NeedRomModeData) ) { 3294 (SiS_Pr->SiS_NeedRomModeData) ) {
3346 if((ROMAddr = GetLCDStructPtr661(SiS_Pr, HwInfo))) { 3295 if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) {
3347 if((romptr = (SISGETROMW(21)))) { 3296 if((romptr = (SISGETROMW(21)))) {
3348 romptr += (resinfo661 * 10); 3297 romptr += (resinfo661 * 10);
3349 ROMAddr = HwInfo->pjVirtualRomBase; 3298 ROMAddr = SiS_Pr->VirtualRomBase;
3350 } 3299 }
3351 } 3300 }
3352 } 3301 }
3353#endif 3302#endif
3354 } 3303 }
3355 3304
3356 SiS_Pr->SiS_NewFlickerMode = 0; 3305 SiS_Pr->SiS_NewFlickerMode = 0;
3357 SiS_Pr->SiS_RVBHRS = 50; 3306 SiS_Pr->SiS_RVBHRS = 50;
3358 SiS_Pr->SiS_RY1COE = 0; 3307 SiS_Pr->SiS_RY1COE = 0;
3359 SiS_Pr->SiS_RY2COE = 0; 3308 SiS_Pr->SiS_RY2COE = 0;
3360 SiS_Pr->SiS_RY3COE = 0; 3309 SiS_Pr->SiS_RY3COE = 0;
3361 SiS_Pr->SiS_RY4COE = 0; 3310 SiS_Pr->SiS_RY4COE = 0;
3311 SiS_Pr->SiS_RVBHRS2 = 0;
3362 3312
3363 SiS_GetCRT2ResInfo(SiS_Pr,ModeNo,ModeIdIndex,HwInfo); 3313 SiS_GetCRT2ResInfo(SiS_Pr,ModeNo,ModeIdIndex);
3364 3314
3365 if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC){ 3315 if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
3366 3316
3367 if(SiS_Pr->UseCustomMode) { 3317 if(SiS_Pr->UseCustomMode) {
3368 3318
3369 SiS_Pr->SiS_RVBHCMAX = 1; 3319 SiS_Pr->SiS_RVBHCMAX = 1;
3370 SiS_Pr->SiS_RVBHCFACT = 1; 3320 SiS_Pr->SiS_RVBHCFACT = 1;
3371 SiS_Pr->SiS_VGAHT = SiS_Pr->CHTotal;
3372 SiS_Pr->SiS_VGAVT = SiS_Pr->CVTotal;
3373 SiS_Pr->SiS_HT = SiS_Pr->CHTotal;
3374 SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
3375 SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE; 3321 SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE;
3376 SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE; 3322 SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE;
3323
3324 tempax = SiS_Pr->CHTotal;
3325 if(modeflag & HalfDCLK) tempax <<= 1;
3326 SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
3327 SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
3377 3328
3378 } else { 3329 } else {
3379 3330
3380 SiS_GetRAMDAC2DATA(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo); 3331 SiS_GetRAMDAC2DATA(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3381 3332
3382 } 3333 }
3383 3334
3384 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 3335 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
3385 3336
3386 SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex, 3337 SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
3387 &CRT2Index,&ResIndex,HwInfo); 3338 &CRT2Index,&ResIndex);
3388 3339
3389 switch(CRT2Index) { 3340 switch(CRT2Index) {
3390 case 2: TVPtr = SiS_Pr->SiS_ExtHiTVData; break; 3341 case 2: TVPtr = SiS_Pr->SiS_ExtHiTVData; break;
3391 case 3: TVPtr = SiS_Pr->SiS_ExtPALData; break; 3342 case 3: TVPtr = SiS_Pr->SiS_ExtPALData; break;
3392 case 4: TVPtr = SiS_Pr->SiS_ExtNTSCData; break; 3343 case 4: TVPtr = SiS_Pr->SiS_ExtNTSCData; break;
3393 case 5: TVPtr = SiS_Pr->SiS_Ext525iData; break; 3344 case 5: TVPtr = SiS_Pr->SiS_Ext525iData; break;
3394 case 6: TVPtr = SiS_Pr->SiS_Ext525pData; break; 3345 case 6: TVPtr = SiS_Pr->SiS_Ext525pData; break;
3395 case 7: TVPtr = SiS_Pr->SiS_Ext750pData; break; 3346 case 7: TVPtr = SiS_Pr->SiS_Ext750pData; break;
3396 case 8: TVPtr = SiS_Pr->SiS_StPALData; break; 3347 case 8: TVPtr = SiS_Pr->SiS_StPALData; break;
3397 case 9: TVPtr = SiS_Pr->SiS_StNTSCData; break; 3348 case 9: TVPtr = SiS_Pr->SiS_StNTSCData; break;
3398 case 10: TVPtr = SiS_Pr->SiS_St525iData; break; 3349 case 10: TVPtr = SiS_Pr->SiS_St525iData; break;
3399 case 11: TVPtr = SiS_Pr->SiS_St525pData; break; 3350 case 11: TVPtr = SiS_Pr->SiS_St525pData; break;
3400 case 12: TVPtr = SiS_Pr->SiS_St750pData; break; 3351 case 12: TVPtr = SiS_Pr->SiS_St750pData; break;
3401 case 13: TVPtr = SiS_Pr->SiS_St1HiTVData; break; 3352 case 13: TVPtr = SiS_Pr->SiS_St1HiTVData; break;
3402 case 14: TVPtr = SiS_Pr->SiS_St2HiTVData; break; 3353 case 14: TVPtr = SiS_Pr->SiS_St2HiTVData; break;
3403 default: TVPtr = SiS_Pr->SiS_StPALData; break; 3354 default: TVPtr = SiS_Pr->SiS_StPALData; break;
3404 } 3355 }
3405 3356
3406 SiS_Pr->SiS_RVBHCMAX = (TVPtr+ResIndex)->RVBHCMAX; 3357 SiS_Pr->SiS_RVBHCMAX = (TVPtr+ResIndex)->RVBHCMAX;
@@ -3409,73 +3360,77 @@ SiS_GetCRT2Data301(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
3409 SiS_Pr->SiS_VGAVT = (TVPtr+ResIndex)->VGAVT; 3360 SiS_Pr->SiS_VGAVT = (TVPtr+ResIndex)->VGAVT;
3410 SiS_Pr->SiS_HDE = (TVPtr+ResIndex)->TVHDE; 3361 SiS_Pr->SiS_HDE = (TVPtr+ResIndex)->TVHDE;
3411 SiS_Pr->SiS_VDE = (TVPtr+ResIndex)->TVVDE; 3362 SiS_Pr->SiS_VDE = (TVPtr+ResIndex)->TVVDE;
3412 SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->RVBHRS; 3363 SiS_Pr->SiS_RVBHRS2 = (TVPtr+ResIndex)->RVBHRS2 & 0x0fff;
3413 SiS_Pr->SiS_NewFlickerMode = (TVPtr+ResIndex)->FlickerMode;
3414 if(modeflag & HalfDCLK) { 3364 if(modeflag & HalfDCLK) {
3415 SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->HALFRVBHRS; 3365 SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->HALFRVBHRS;
3366 if(SiS_Pr->SiS_RVBHRS2) {
3367 SiS_Pr->SiS_RVBHRS2 = ((SiS_Pr->SiS_RVBHRS2 + 3) >> 1) - 3;
3368 tempax = ((TVPtr+ResIndex)->RVBHRS2 >> 12) & 0x07;
3369 if((TVPtr+ResIndex)->RVBHRS2 & 0x8000) SiS_Pr->SiS_RVBHRS2 -= tempax;
3370 else SiS_Pr->SiS_RVBHRS2 += tempax;
3371 }
3372 } else {
3373 SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->RVBHRS;
3416 } 3374 }
3375 SiS_Pr->SiS_NewFlickerMode = ((TVPtr+ResIndex)->FlickerMode) << 7;
3417 3376
3418 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { 3377 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
3419 3378
3420 if((resinfo == SIS_RI_1024x768) || 3379 if((resinfo == SIS_RI_960x600) ||
3421 (resinfo == SIS_RI_1280x1024) || 3380 (resinfo == SIS_RI_1024x768) ||
3422 (resinfo == SIS_RI_1280x720)) { 3381 (resinfo == SIS_RI_1280x1024) ||
3382 (resinfo == SIS_RI_1280x720)) {
3423 SiS_Pr->SiS_NewFlickerMode = 0x40; 3383 SiS_Pr->SiS_NewFlickerMode = 0x40;
3424 } 3384 }
3425 3385
3426 if(SiS_Pr->SiS_VGAVDE == 350) SiS_Pr->SiS_TVMode |= TVSetTVSimuMode; 3386 if(SiS_Pr->SiS_VGAVDE == 350) SiS_Pr->SiS_TVMode |= TVSetTVSimuMode;
3427 3387
3428 SiS_Pr->SiS_HT = ExtHiTVHT; 3388 SiS_Pr->SiS_HT = ExtHiTVHT;
3429 SiS_Pr->SiS_VT = ExtHiTVVT; 3389 SiS_Pr->SiS_VT = ExtHiTVVT;
3430 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { 3390 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
3431 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) { 3391 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
3432 SiS_Pr->SiS_HT = StHiTVHT; 3392 SiS_Pr->SiS_HT = StHiTVHT;
3433 SiS_Pr->SiS_VT = StHiTVVT; 3393 SiS_Pr->SiS_VT = StHiTVVT;
3434#if 0 3394 }
3435 if(!(modeflag & Charx8Dot)) { 3395 }
3436 SiS_Pr->SiS_HT = StHiTextTVHT;
3437 SiS_Pr->SiS_VT = StHiTextTVVT;
3438 }
3439#endif
3440 }
3441 }
3442 3396
3443 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { 3397 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
3444 3398
3445 if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) { 3399 if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
3446 SiS_Pr->SiS_HT = 1650; 3400 SiS_Pr->SiS_HT = 1650;
3447 SiS_Pr->SiS_VT = 750; 3401 SiS_Pr->SiS_VT = 750;
3448 } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) { 3402 } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
3449 SiS_Pr->SiS_HT = NTSCHT; 3403 SiS_Pr->SiS_HT = NTSCHT;
3404 if(SiS_Pr->SiS_TVMode & TVSet525p1024) SiS_Pr->SiS_HT = NTSC2HT;
3450 SiS_Pr->SiS_VT = NTSCVT; 3405 SiS_Pr->SiS_VT = NTSCVT;
3451 } else { 3406 } else {
3452 SiS_Pr->SiS_HT = NTSCHT; 3407 SiS_Pr->SiS_HT = NTSCHT;
3453 if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT; 3408 if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT;
3454 SiS_Pr->SiS_VT = NTSCVT; 3409 SiS_Pr->SiS_VT = NTSCVT;
3455 } 3410 }
3456 3411
3457 } else { 3412 } else {
3458 3413
3459 SiS_Pr->SiS_RY1COE = (TVPtr+ResIndex)->RY1COE; 3414 SiS_Pr->SiS_RY1COE = (TVPtr+ResIndex)->RY1COE;
3460 SiS_Pr->SiS_RY2COE = (TVPtr+ResIndex)->RY2COE; 3415 SiS_Pr->SiS_RY2COE = (TVPtr+ResIndex)->RY2COE;
3461 SiS_Pr->SiS_RY3COE = (TVPtr+ResIndex)->RY3COE; 3416 SiS_Pr->SiS_RY3COE = (TVPtr+ResIndex)->RY3COE;
3462 SiS_Pr->SiS_RY4COE = (TVPtr+ResIndex)->RY4COE; 3417 SiS_Pr->SiS_RY4COE = (TVPtr+ResIndex)->RY4COE;
3463 3418
3464 if(modeflag & HalfDCLK) { 3419 if(modeflag & HalfDCLK) {
3465 SiS_Pr->SiS_RY1COE = 0x00; 3420 SiS_Pr->SiS_RY1COE = 0x00;
3466 SiS_Pr->SiS_RY2COE = 0xf4; 3421 SiS_Pr->SiS_RY2COE = 0xf4;
3467 SiS_Pr->SiS_RY3COE = 0x10; 3422 SiS_Pr->SiS_RY3COE = 0x10;
3468 SiS_Pr->SiS_RY4COE = 0x38; 3423 SiS_Pr->SiS_RY4COE = 0x38;
3469 } 3424 }
3470 3425
3471 if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { 3426 if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
3472 SiS_Pr->SiS_HT = NTSCHT; 3427 SiS_Pr->SiS_HT = NTSCHT;
3473 if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT; 3428 if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT;
3474 SiS_Pr->SiS_VT = NTSCVT; 3429 SiS_Pr->SiS_VT = NTSCVT;
3475 } else { 3430 } else {
3476 SiS_Pr->SiS_HT = PALHT; 3431 SiS_Pr->SiS_HT = PALHT;
3477 SiS_Pr->SiS_VT = PALVT; 3432 SiS_Pr->SiS_VT = PALVT;
3478 } 3433 }
3479 3434
3480 } 3435 }
3481 3436
@@ -3486,42 +3441,53 @@ SiS_GetCRT2Data301(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
3486 3441
3487 if(SiS_Pr->UseCustomMode) { 3442 if(SiS_Pr->UseCustomMode) {
3488 3443
3489 SiS_Pr->SiS_VGAHT = SiS_Pr->CHTotal;
3490 SiS_Pr->SiS_VGAVT = SiS_Pr->CVTotal;
3491 SiS_Pr->SiS_HT = SiS_Pr->CHTotal;
3492 SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
3493 SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE; 3444 SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE;
3494 SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE; 3445 SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE;
3446
3447 tempax = SiS_Pr->CHTotal;
3448 if(modeflag & HalfDCLK) tempax <<= 1;
3449 SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
3450 SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
3495 3451
3496 } else { 3452 } else {
3497 3453
3498 BOOLEAN gotit = FALSE; 3454 BOOLEAN gotit = FALSE;
3499 3455
3500 if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) { 3456 if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
3501 3457
3502 SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT; 3458 SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT;
3503 SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT; 3459 SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
3504 SiS_Pr->SiS_HT = SiS_Pr->PanelHT; 3460 SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
3505 SiS_Pr->SiS_VT = SiS_Pr->PanelVT; 3461 SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
3506 gotit = TRUE; 3462 gotit = TRUE;
3507 3463
3508 } else if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) && (romptr) && (ROMAddr) ) { 3464 } else if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) && (romptr) && (ROMAddr) ) {
3509 3465
3510#ifdef SIS315H 3466#ifdef SIS315H
3511 SiS_Pr->SiS_RVBHCMAX = ROMAddr[romptr]; 3467 SiS_Pr->SiS_RVBHCMAX = ROMAddr[romptr];
3512 SiS_Pr->SiS_RVBHCFACT = ROMAddr[romptr+1]; 3468 SiS_Pr->SiS_RVBHCFACT = ROMAddr[romptr+1];
3513 SiS_Pr->SiS_VGAHT = ROMAddr[romptr+2] | ((ROMAddr[romptr+3] & 0x0f) << 8); 3469 SiS_Pr->SiS_VGAHT = ROMAddr[romptr+2] | ((ROMAddr[romptr+3] & 0x0f) << 8);
3514 SiS_Pr->SiS_VGAVT = ROMAddr[romptr+4] | ((ROMAddr[romptr+3] & 0xf0) << 4); 3470 SiS_Pr->SiS_VGAVT = (ROMAddr[romptr+4] << 4) | ((ROMAddr[romptr+3] & 0xf0) >> 4);
3515 SiS_Pr->SiS_HT = ROMAddr[romptr+5] | ((ROMAddr[romptr+6] & 0x0f) << 8); 3471 SiS_Pr->SiS_HT = ROMAddr[romptr+5] | ((ROMAddr[romptr+6] & 0x0f) << 8);
3516 SiS_Pr->SiS_VT = ROMAddr[romptr+7] | ((ROMAddr[romptr+6] & 0xf0) << 4); 3472 SiS_Pr->SiS_VT = (ROMAddr[romptr+7] << 4) | ((ROMAddr[romptr+6] & 0xf0) >> 4);
3473 SiS_Pr->SiS_RVBHRS2 = ROMAddr[romptr+8] | ((ROMAddr[romptr+9] & 0x0f) << 8);
3474 if((SiS_Pr->SiS_RVBHRS2) && (modeflag & HalfDCLK)) {
3475 SiS_Pr->SiS_RVBHRS2 = ((SiS_Pr->SiS_RVBHRS2 + 3) >> 1) - 3;
3476 tempax = (ROMAddr[romptr+9] >> 4) & 0x07;
3477 if(ROMAddr[romptr+9] & 0x80) SiS_Pr->SiS_RVBHRS2 -= tempax;
3478 else SiS_Pr->SiS_RVBHRS2 += tempax;
3479 }
3517 if(SiS_Pr->SiS_VGAHT) gotit = TRUE; 3480 if(SiS_Pr->SiS_VGAHT) gotit = TRUE;
3518 else { 3481 else {
3519 SiS_Pr->SiS_LCDInfo |= DontExpandLCD; 3482 SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
3520 SiS_Pr->SiS_LCDInfo &= ~LCDPass11; 3483 SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
3484 SiS_Pr->SiS_RVBHCMAX = 1;
3485 SiS_Pr->SiS_RVBHCFACT = 1;
3521 SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT; 3486 SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT;
3522 SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT; 3487 SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
3523 SiS_Pr->SiS_HT = SiS_Pr->PanelHT; 3488 SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
3524 SiS_Pr->SiS_VT = SiS_Pr->PanelVT; 3489 SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
3490 SiS_Pr->SiS_RVBHRS2 = 0;
3525 gotit = TRUE; 3491 gotit = TRUE;
3526 } 3492 }
3527#endif 3493#endif
@@ -3530,28 +3496,30 @@ SiS_GetCRT2Data301(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
3530 3496
3531 if(!gotit) { 3497 if(!gotit) {
3532 3498
3533 SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex, 3499 SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
3534 &CRT2Index,&ResIndex,HwInfo); 3500 &CRT2Index,&ResIndex);
3535 3501
3536 switch(CRT2Index) { 3502 switch(CRT2Index) {
3537 case Panel_1024x768 : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break; 3503 case Panel_1024x768 : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break;
3538 case Panel_1024x768 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1024x768Data; break; 3504 case Panel_1024x768 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1024x768Data; break;
3539 case Panel_1280x720 : 3505 case Panel_1280x720 :
3540 case Panel_1280x720 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x720Data; break; 3506 case Panel_1280x720 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x720Data; break;
3541 case Panel_1280x768_2 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x768_2Data; break; 3507 case Panel_1280x768_2 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x768_2Data; break;
3542 case Panel_1280x768_2+ 32: LCDPtr = SiS_Pr->SiS_StLCD1280x768_2Data; break; 3508 case Panel_1280x768_2+ 32: LCDPtr = SiS_Pr->SiS_StLCD1280x768_2Data; break;
3543 case Panel_1280x800 : 3509 case Panel_1280x800 :
3544 case Panel_1280x800 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x800Data; break; 3510 case Panel_1280x800 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x800Data; break;
3545 case Panel_1280x800_2 : 3511 case Panel_1280x800_2 :
3546 case Panel_1280x800_2+ 32: LCDPtr = SiS_Pr->SiS_LCD1280x800_2Data; break; 3512 case Panel_1280x800_2+ 32: LCDPtr = SiS_Pr->SiS_LCD1280x800_2Data; break;
3513 case Panel_1280x854 :
3514 case Panel_1280x854 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x854Data; break;
3547 case Panel_1280x960 : 3515 case Panel_1280x960 :
3548 case Panel_1280x960 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x960Data; break; 3516 case Panel_1280x960 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x960Data; break;
3549 case Panel_1280x1024 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x1024Data; break; 3517 case Panel_1280x1024 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x1024Data; break;
3550 case Panel_1280x1024 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break; 3518 case Panel_1280x1024 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break;
3551 case Panel_1400x1050 : LCDPtr = SiS_Pr->SiS_ExtLCD1400x1050Data; break; 3519 case Panel_1400x1050 : LCDPtr = SiS_Pr->SiS_ExtLCD1400x1050Data; break;
3552 case Panel_1400x1050 + 32: LCDPtr = SiS_Pr->SiS_StLCD1400x1050Data; break; 3520 case Panel_1400x1050 + 32: LCDPtr = SiS_Pr->SiS_StLCD1400x1050Data; break;
3553 case Panel_1600x1200 : LCDPtr = SiS_Pr->SiS_ExtLCD1600x1200Data; break; 3521 case Panel_1600x1200 : LCDPtr = SiS_Pr->SiS_ExtLCD1600x1200Data; break;
3554 case Panel_1600x1200 + 32: LCDPtr = SiS_Pr->SiS_StLCD1600x1200Data; break; 3522 case Panel_1600x1200 + 32: LCDPtr = SiS_Pr->SiS_StLCD1600x1200Data; break;
3555 case Panel_1680x1050 : 3523 case Panel_1680x1050 :
3556 case Panel_1680x1050 + 32: LCDPtr = SiS_Pr->SiS_LCD1680x1050Data; break; 3524 case Panel_1680x1050 + 32: LCDPtr = SiS_Pr->SiS_LCD1680x1050Data; break;
3557 case 100 : LCDPtr = SiS_Pr->SiS_NoScaleData; break; 3525 case 100 : LCDPtr = SiS_Pr->SiS_NoScaleData; break;
@@ -3559,271 +3527,340 @@ SiS_GetCRT2Data301(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
3559 case 200 : LCDPtr = SiS310_ExtCompaq1280x1024Data; break; 3527 case 200 : LCDPtr = SiS310_ExtCompaq1280x1024Data; break;
3560 case 201 : LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break; 3528 case 201 : LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break;
3561#endif 3529#endif
3562 default : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break; 3530 default : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break;
3563 } 3531 }
3564 3532
3533#ifdef SIS_XORG_XF86
3565#ifdef TWDEBUG 3534#ifdef TWDEBUG
3566 xf86DrvMsg(0, X_INFO, "GetCRT2Data: Index %d ResIndex %d\n", CRT2Index, ResIndex); 3535 xf86DrvMsg(0, X_INFO, "GetCRT2Data: Index %d ResIndex %d\n", CRT2Index, ResIndex);
3536#endif
3567#endif 3537#endif
3568 3538
3569 SiS_Pr->SiS_RVBHCMAX = (LCDPtr+ResIndex)->RVBHCMAX; 3539 SiS_Pr->SiS_RVBHCMAX = (LCDPtr+ResIndex)->RVBHCMAX;
3570 SiS_Pr->SiS_RVBHCFACT = (LCDPtr+ResIndex)->RVBHCFACT; 3540 SiS_Pr->SiS_RVBHCFACT = (LCDPtr+ResIndex)->RVBHCFACT;
3571 SiS_Pr->SiS_VGAHT = (LCDPtr+ResIndex)->VGAHT; 3541 SiS_Pr->SiS_VGAHT = (LCDPtr+ResIndex)->VGAHT;
3572 SiS_Pr->SiS_VGAVT = (LCDPtr+ResIndex)->VGAVT; 3542 SiS_Pr->SiS_VGAVT = (LCDPtr+ResIndex)->VGAVT;
3573 SiS_Pr->SiS_HT = (LCDPtr+ResIndex)->LCDHT; 3543 SiS_Pr->SiS_HT = (LCDPtr+ResIndex)->LCDHT;
3574 SiS_Pr->SiS_VT = (LCDPtr+ResIndex)->LCDVT; 3544 SiS_Pr->SiS_VT = (LCDPtr+ResIndex)->LCDVT;
3575 3545
3576 } 3546 }
3577 3547
3578 tempax = SiS_Pr->PanelXRes; 3548 tempax = SiS_Pr->PanelXRes;
3579 tempbx = SiS_Pr->PanelYRes; 3549 tempbx = SiS_Pr->PanelYRes;
3580 3550
3581 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { 3551 switch(SiS_Pr->SiS_LCDResInfo) {
3582 if(SiS_Pr->SiS_SetFlag & LCDVESATiming) { 3552 case Panel_1024x768:
3583 if(HwInfo->jChipType < SIS_315H) { 3553 if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
3584 if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 560; 3554 if(SiS_Pr->ChipType < SIS_315H) {
3585 else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640; 3555 if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
3586 } 3556 else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
3587 } else { 3557 }
3588 if (SiS_Pr->SiS_VGAVDE == 357) tempbx = 527; 3558 } else {
3589 else if(SiS_Pr->SiS_VGAVDE == 420) tempbx = 620; 3559 if (SiS_Pr->SiS_VGAVDE == 357) tempbx = 527;
3590 else if(SiS_Pr->SiS_VGAVDE == 525) tempbx = 775; 3560 else if(SiS_Pr->SiS_VGAVDE == 420) tempbx = 620;
3591 else if(SiS_Pr->SiS_VGAVDE == 600) tempbx = 775; 3561 else if(SiS_Pr->SiS_VGAVDE == 525) tempbx = 775;
3592 else if(SiS_Pr->SiS_VGAVDE == 350) tempbx = 560; 3562 else if(SiS_Pr->SiS_VGAVDE == 600) tempbx = 775;
3593 else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640; 3563 else if(SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
3594 } 3564 else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
3595 } else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x960) { 3565 }
3596 if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 700; 3566 break;
3597 else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 800; 3567 case Panel_1280x960:
3598 else if(SiS_Pr->SiS_VGAVDE == 1024) tempbx = 960; 3568 if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 700;
3599 } else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) { 3569 else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 800;
3600 if (SiS_Pr->SiS_VGAVDE == 360) tempbx = 768; 3570 else if(SiS_Pr->SiS_VGAVDE == 1024) tempbx = 960;
3601 else if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 800; 3571 break;
3602 else if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 864; 3572 case Panel_1280x1024:
3603 } else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) { 3573 if (SiS_Pr->SiS_VGAVDE == 360) tempbx = 768;
3574 else if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 800;
3575 else if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 864;
3576 break;
3577 case Panel_1600x1200:
3604 if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) { 3578 if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
3605 if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 875; 3579 if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 875;
3606 else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 1000; 3580 else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 1000;
3607 } 3581 }
3608 } 3582 break;
3583 }
3609 3584
3610 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { 3585 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3611 tempax = SiS_Pr->SiS_VGAHDE; 3586 tempax = SiS_Pr->SiS_VGAHDE;
3612 tempbx = SiS_Pr->SiS_VGAVDE; 3587 tempbx = SiS_Pr->SiS_VGAVDE;
3613 } 3588 }
3614 3589
3615 SiS_Pr->SiS_HDE = tempax; 3590 SiS_Pr->SiS_HDE = tempax;
3616 SiS_Pr->SiS_VDE = tempbx; 3591 SiS_Pr->SiS_VDE = tempbx;
3617 } 3592 }
3618 } 3593 }
3619} 3594}
3620 3595
3621static void 3596static void
3622SiS_GetCRT2Data(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 3597SiS_GetCRT2Data(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
3623 USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo) 3598 unsigned short RefreshRateTableIndex)
3624{ 3599{
3625 3600
3626 if(SiS_Pr->SiS_VBType & VB_SISVB) { 3601 if(SiS_Pr->SiS_VBType & VB_SISVB) {
3627 3602
3628 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { 3603 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
3629 SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo); 3604 SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3630 } else { 3605 } else {
3631 if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { 3606 if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
3632 /* Need LVDS Data for LCD on 301B-DH */ 3607 /* Need LVDS Data for LCD on 301B-DH */
3633 SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo); 3608 SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3634 } else { 3609 } else {
3635 SiS_GetCRT2Data301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo); 3610 SiS_GetCRT2Data301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3636 } 3611 }
3637 } 3612 }
3638 3613
3639 } else { 3614 } else {
3640 3615
3641 SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo); 3616 SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3642 3617
3643 } 3618 }
3644} 3619}
3645 3620
3646/*********************************************/ 3621/*********************************************/
3647/* GET LVDS DES (SKEW) DATA */ 3622/* GET LVDS DES (SKEW) DATA */
3648/*********************************************/ 3623/*********************************************/
3649 3624
3650static void 3625static const struct SiS_LVDSDes *
3651SiS_GetLVDSDesPtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 3626SiS_GetLVDSDesPtr(struct SiS_Private *SiS_Pr)
3652 USHORT RefreshRateTableIndex, USHORT *PanelIndex,
3653 USHORT *ResIndex, PSIS_HW_INFO HwInfo)
3654{ 3627{
3655 USHORT modeflag; 3628 const struct SiS_LVDSDes *PanelDesPtr = NULL;
3656 3629
3657 if(ModeNo <= 0x13) { 3630#ifdef SIS300
3658 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; 3631 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
3659 (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; 3632
3660 } else { 3633 if(SiS_Pr->ChipType < SIS_315H) {
3661 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 3634 if(SiS_Pr->SiS_LCDTypeInfo == 4) {
3662 (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; 3635 if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
3663 } 3636 PanelDesPtr = SiS_Pr->SiS_PanelType04_1a;
3637 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3638 PanelDesPtr = SiS_Pr->SiS_PanelType04_2a;
3639 }
3640 } else if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
3641 PanelDesPtr = SiS_Pr->SiS_PanelType04_1b;
3642 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3643 PanelDesPtr = SiS_Pr->SiS_PanelType04_2b;
3644 }
3645 }
3646 }
3647 }
3648 }
3649#endif
3650 return PanelDesPtr;
3651}
3664 3652
3665 (*ResIndex) &= 0x1F; 3653static void
3666 (*PanelIndex) = 0; 3654SiS_GetLVDSDesData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
3655 unsigned short RefreshRateTableIndex)
3656{
3657 unsigned short modeflag, ResIndex;
3658 const struct SiS_LVDSDes *PanelDesPtr = NULL;
3667 3659
3668 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 3660 SiS_Pr->SiS_LCDHDES = 0;
3669 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 3661 SiS_Pr->SiS_LCDVDES = 0;
3670 (*PanelIndex) = 50;
3671 if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) (*PanelIndex) += 2;
3672 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*PanelIndex) += 1;
3673 /* Nothing special needed for SOverscan */
3674 /* PALM uses NTSC data, PALN uses PAL data */
3675 }
3676 }
3677 3662
3663 /* Some special cases */
3678 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 3664 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
3679 *PanelIndex = SiS_Pr->SiS_LCDTypeInfo; 3665
3680 if(HwInfo->jChipType >= SIS_661) { 3666 /* Trumpion */
3681 /* As long as we don's use the BIOS tables, we 3667 if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
3682 * need to convert the TypeInfo as for 315 series 3668 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
3683 */ 3669 if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
3684 (*PanelIndex) = SiS_Pr->SiS_LCDResInfo - 1; 3670 SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
3685 } 3671 }
3686 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3687 (*PanelIndex) += 16;
3688 if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
3689 (*PanelIndex) = 32;
3690 if(modeflag & HalfDCLK) (*PanelIndex)++;
3691 } 3672 }
3673 return;
3692 } 3674 }
3693 }
3694 3675
3695 if(SiS_Pr->SiS_SetFlag & SetDOSMode) { 3676 /* 640x480 on LVDS */
3696 if(SiS_Pr->SiS_LCDResInfo != Panel_640x480) { 3677 if(SiS_Pr->ChipType < SIS_315H) {
3697 (*ResIndex) = 7; 3678 if(SiS_Pr->SiS_LCDResInfo == Panel_640x480 && SiS_Pr->SiS_LCDTypeInfo == 3) {
3698 if(HwInfo->jChipType < SIS_315H) { 3679 SiS_Pr->SiS_LCDHDES = 8;
3699 if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) (*ResIndex)++; 3680 if (SiS_Pr->SiS_VGAVDE >= 480) SiS_Pr->SiS_LCDVDES = 512;
3700 } 3681 else if(SiS_Pr->SiS_VGAVDE >= 400) SiS_Pr->SiS_LCDVDES = 436;
3682 else if(SiS_Pr->SiS_VGAVDE >= 350) SiS_Pr->SiS_LCDVDES = 440;
3683 return;
3684 }
3701 } 3685 }
3702 }
3703}
3704
3705static void
3706SiS_GetLVDSDesData(SiS_Private *SiS_Pr, USHORT ModeNo,USHORT ModeIdIndex,
3707 USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo)
3708{
3709 USHORT modeflag;
3710 USHORT PanelIndex,ResIndex;
3711 const SiS_LVDSDesStruct *PanelDesPtr = NULL;
3712 3686
3713 SiS_Pr->SiS_LCDHDES = 0; 3687 } /* LCD */
3714 SiS_Pr->SiS_LCDVDES = 0;
3715 3688
3716 if( (SiS_Pr->UseCustomMode) || 3689 if( (SiS_Pr->UseCustomMode) ||
3717 (SiS_Pr->SiS_LCDResInfo == Panel_Custom) || 3690 (SiS_Pr->SiS_LCDResInfo == Panel_Custom) ||
3718 (SiS_Pr->SiS_CustomT == CUT_PANEL848) || 3691 (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
3719 ((SiS_Pr->SiS_VBType & VB_SISVB) && 3692 (SiS_Pr->SiS_CustomT == CUT_PANEL856) ||
3720 (SiS_Pr->SiS_LCDInfo & DontExpandLCD) && 3693 (SiS_Pr->SiS_LCDInfo & LCDPass11) ) {
3721 (SiS_Pr->SiS_LCDInfo & LCDPass11)) ) {
3722 return; 3694 return;
3723 } 3695 }
3724 3696
3725 if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { 3697 if(ModeNo <= 0x13) ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
3698 else ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
3699
3700 if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
3726 3701
3727#ifdef SIS315H 3702#ifdef SIS315H
3728 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { 3703 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3729 /* non-pass 1:1 only, see above */ 3704 /* non-pass 1:1 only, see above */
3730 if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) { 3705 if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) {
3731 SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2); 3706 SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2);
3732 } 3707 }
3733 if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) { 3708 if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) {
3734 SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2); 3709 SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2);
3735 } 3710 }
3736 } 3711 }
3737 if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) { 3712 if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
3738 switch(SiS_Pr->SiS_CustomT) { 3713 switch(SiS_Pr->SiS_CustomT) {
3739 case CUT_UNIWILL1024: 3714 case CUT_UNIWILL1024:
3740 case CUT_UNIWILL10242: 3715 case CUT_UNIWILL10242:
3741 case CUT_CLEVO1400: 3716 case CUT_CLEVO1400:
3742 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { 3717 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
3743 SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1; 3718 SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
3744 } 3719 }
3745 break; 3720 break;
3746 } 3721 }
3747 if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) { 3722 switch(SiS_Pr->SiS_LCDResInfo) {
3723 case Panel_1280x1024:
3748 if(SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) { 3724 if(SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) {
3749 SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1; 3725 SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
3750 } 3726 }
3727 break;
3728 case Panel_1280x800: /* Verified for Averatec 6240 */
3729 case Panel_1280x800_2: /* Verified for Asus A4L */
3730 case Panel_1280x854: /* Not verified yet FIXME */
3731 SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
3732 break;
3751 } 3733 }
3752 } 3734 }
3753#endif 3735#endif
3754 3736
3755 } else { 3737 } else {
3756 3738
3757 SiS_GetLVDSDesPtr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, 3739 if((SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
3758 &PanelIndex, &ResIndex, HwInfo); 3740
3759 3741 if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) {
3760 switch(PanelIndex) { 3742 if(ResIndex <= 3) SiS_Pr->SiS_LCDHDES = 256;
3761 case 0: PanelDesPtr = SiS_Pr->SiS_PanelType00_1; break; /* --- */ 3743 }
3762 case 1: PanelDesPtr = SiS_Pr->SiS_PanelType01_1; break; 3744
3763 case 2: PanelDesPtr = SiS_Pr->SiS_PanelType02_1; break; 3745 } else if((PanelDesPtr = SiS_GetLVDSDesPtr(SiS_Pr))) {
3764 case 3: PanelDesPtr = SiS_Pr->SiS_PanelType03_1; break; 3746
3765 case 4: PanelDesPtr = SiS_Pr->SiS_PanelType04_1; break; 3747 SiS_Pr->SiS_LCDHDES = (PanelDesPtr+ResIndex)->LCDHDES;
3766 case 5: PanelDesPtr = SiS_Pr->SiS_PanelType05_1; break; 3748 SiS_Pr->SiS_LCDVDES = (PanelDesPtr+ResIndex)->LCDVDES;
3767 case 6: PanelDesPtr = SiS_Pr->SiS_PanelType06_1; break; 3749
3768 case 7: PanelDesPtr = SiS_Pr->SiS_PanelType07_1; break; 3750 } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3769 case 8: PanelDesPtr = SiS_Pr->SiS_PanelType08_1; break; 3751
3770 case 9: PanelDesPtr = SiS_Pr->SiS_PanelType09_1; break; 3752 if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) {
3771 case 10: PanelDesPtr = SiS_Pr->SiS_PanelType0a_1; break; 3753 SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2);
3772 case 11: PanelDesPtr = SiS_Pr->SiS_PanelType0b_1; break; 3754 }
3773 case 12: PanelDesPtr = SiS_Pr->SiS_PanelType0c_1; break; 3755 if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) {
3774 case 13: PanelDesPtr = SiS_Pr->SiS_PanelType0d_1; break; 3756 SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2);
3775 case 14: PanelDesPtr = SiS_Pr->SiS_PanelType0e_1; break; 3757 } else {
3776 case 15: PanelDesPtr = SiS_Pr->SiS_PanelType0f_1; break; 3758 if(SiS_Pr->ChipType < SIS_315H) {
3777 case 16: PanelDesPtr = SiS_Pr->SiS_PanelType00_2; break; /* --- */ 3759 SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
3778 case 17: PanelDesPtr = SiS_Pr->SiS_PanelType01_2; break; 3760 } else {
3779 case 18: PanelDesPtr = SiS_Pr->SiS_PanelType02_2; break; 3761 switch(SiS_Pr->SiS_LCDResInfo) {
3780 case 19: PanelDesPtr = SiS_Pr->SiS_PanelType03_2; break; 3762 case Panel_800x600:
3781 case 20: PanelDesPtr = SiS_Pr->SiS_PanelType04_2; break; 3763 case Panel_1024x768:
3782 case 21: PanelDesPtr = SiS_Pr->SiS_PanelType05_2; break; 3764 case Panel_1280x1024:
3783 case 22: PanelDesPtr = SiS_Pr->SiS_PanelType06_2; break; 3765 SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT;
3784 case 23: PanelDesPtr = SiS_Pr->SiS_PanelType07_2; break; 3766 break;
3785 case 24: PanelDesPtr = SiS_Pr->SiS_PanelType08_2; break; 3767 case Panel_1400x1050:
3786 case 25: PanelDesPtr = SiS_Pr->SiS_PanelType09_2; break; 3768 SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
3787 case 26: PanelDesPtr = SiS_Pr->SiS_PanelType0a_2; break; 3769 break;
3788 case 27: PanelDesPtr = SiS_Pr->SiS_PanelType0b_2; break; 3770 }
3789 case 28: PanelDesPtr = SiS_Pr->SiS_PanelType0c_2; break; 3771 }
3790 case 29: PanelDesPtr = SiS_Pr->SiS_PanelType0d_2; break; 3772 }
3791 case 30: PanelDesPtr = SiS_Pr->SiS_PanelType0e_2; break; 3773
3792 case 31: PanelDesPtr = SiS_Pr->SiS_PanelType0f_2; break; 3774 } else {
3793 case 32: PanelDesPtr = SiS_Pr->SiS_PanelTypeNS_1; break; /* pass 1:1 */ 3775
3794 case 33: PanelDesPtr = SiS_Pr->SiS_PanelTypeNS_2; break; 3776 if(SiS_Pr->ChipType < SIS_315H) {
3795 case 50: PanelDesPtr = SiS_Pr->SiS_CHTVUNTSCDesData; break; /* TV */ 3777#ifdef SIS300
3796 case 51: PanelDesPtr = SiS_Pr->SiS_CHTVONTSCDesData; break; 3778 switch(SiS_Pr->SiS_LCDResInfo) {
3797 case 52: PanelDesPtr = SiS_Pr->SiS_CHTVUPALDesData; break; 3779 case Panel_800x600:
3798 case 53: PanelDesPtr = SiS_Pr->SiS_CHTVOPALDesData; break; 3780 if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
3799 default: return; 3781 SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
3800 } 3782 } else {
3801 3783 SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT + 3;
3802 SiS_Pr->SiS_LCDHDES = (PanelDesPtr+ResIndex)->LCDHDES; 3784 SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT;
3803 SiS_Pr->SiS_LCDVDES = (PanelDesPtr+ResIndex)->LCDVDES; 3785 if(SiS_Pr->SiS_VGAVDE == 400) SiS_Pr->SiS_LCDVDES -= 2;
3786 else SiS_Pr->SiS_LCDVDES -= 4;
3787 }
3788 break;
3789 case Panel_1024x768:
3790 if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
3791 SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
3792 } else {
3793 SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT - 1;
3794 if(SiS_Pr->SiS_VGAVDE <= 400) SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 8;
3795 if(SiS_Pr->SiS_VGAVDE <= 350) SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 12;
3796 }
3797 break;
3798 case Panel_1024x600:
3799 default:
3800 if( (SiS_Pr->SiS_VGAHDE == SiS_Pr->PanelXRes) &&
3801 (SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) ) {
3802 SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
3803 } else {
3804 SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT - 1;
3805 }
3806 break;
3807 }
3808
3809 switch(SiS_Pr->SiS_LCDTypeInfo) {
3810 case 1:
3811 SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0;
3812 break;
3813 case 3: /* 640x480 only? */
3814 SiS_Pr->SiS_LCDHDES = 8;
3815 if (SiS_Pr->SiS_VGAVDE >= 480) SiS_Pr->SiS_LCDVDES = 512;
3816 else if(SiS_Pr->SiS_VGAVDE >= 400) SiS_Pr->SiS_LCDVDES = 436;
3817 else if(SiS_Pr->SiS_VGAVDE >= 350) SiS_Pr->SiS_LCDVDES = 440;
3818 break;
3819 }
3820#endif
3821 } else {
3822#ifdef SIS315H
3823 switch(SiS_Pr->SiS_LCDResInfo) {
3824 case Panel_1024x768:
3825 case Panel_1280x1024:
3826 if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
3827 SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
3828 }
3829 break;
3830 case Panel_320x240_1:
3831 case Panel_320x240_2:
3832 case Panel_320x240_3:
3833 SiS_Pr->SiS_LCDVDES = 524;
3834 break;
3835 }
3836#endif
3837 }
3838 }
3804 3839
3805 if((ModeNo <= 0x13) && (SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { 3840 if((ModeNo <= 0x13) && (SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
3806 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; 3841 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
3807 if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { 3842 if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
3808 if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 632; 3843 if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 632;
3809 } else if(!(SiS_Pr->SiS_SetFlag & SetDOSMode)) { 3844 } else if(!(SiS_Pr->SiS_SetFlag & SetDOSMode)) {
3810 if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) { 3845 if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) {
3811 if(SiS_Pr->SiS_LCDResInfo >= Panel_1024x768) { 3846 if(SiS_Pr->SiS_LCDResInfo >= Panel_1024x768) {
3812 if(HwInfo->jChipType < SIS_315H) { 3847 if(SiS_Pr->ChipType < SIS_315H) {
3813 if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 320; 3848 if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 320;
3814 } else { 3849 } else {
3815 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) SiS_Pr->SiS_LCDHDES = 480; 3850#ifdef SIS315H
3816 if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 804; 3851 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) SiS_Pr->SiS_LCDHDES = 480;
3852 if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 804;
3817 if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 704; 3853 if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 704;
3818 if(!(modeflag & HalfDCLK)) { 3854 if(!(modeflag & HalfDCLK)) {
3819 SiS_Pr->SiS_LCDHDES = 320; 3855 SiS_Pr->SiS_LCDHDES = 320;
3820 if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 632; 3856 if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 632;
3821 if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 542; 3857 if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 542;
3822 } 3858 }
3823 } 3859#endif
3824 } 3860 }
3825 } 3861 }
3826 } 3862 }
3863 }
3827 } 3864 }
3828 } 3865 }
3829} 3866}
@@ -3832,54 +3869,90 @@ SiS_GetLVDSDesData(SiS_Private *SiS_Pr, USHORT ModeNo,USHORT ModeIdIndex,
3832/* DISABLE VIDEO BRIDGE */ 3869/* DISABLE VIDEO BRIDGE */
3833/*********************************************/ 3870/*********************************************/
3834 3871
3872#ifdef SIS315H
3873static int
3874SiS_HandlePWD(struct SiS_Private *SiS_Pr)
3875{
3876 int ret = 0;
3877#ifdef SET_PWD
3878 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
3879 unsigned short romptr = GetLCDStructPtr661_2(SiS_Pr);
3880 unsigned char drivermode = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40;
3881 unsigned short temp;
3882
3883 if( (SiS_Pr->SiS_VBType & VB_SISPWD) &&
3884 (romptr) &&
3885 (SiS_Pr->SiS_PWDOffset) ) {
3886 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2b,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 0]);
3887 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2c,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 1]);
3888 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2d,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 2]);
3889 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2e,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 3]);
3890 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2f,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 4]);
3891 temp = 0x00;
3892 if((ROMAddr[romptr + 2] & (0x06 << 1)) && !drivermode) {
3893 temp = 0x80;
3894 ret = 1;
3895 }
3896 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x27,0x7f,temp);
3897#ifdef SIS_XORG_XF86
3898#ifdef TWDEBUG
3899 xf86DrvMsg(0, 0, "Setting PWD %x\n", temp);
3900#endif
3901#endif
3902 }
3903#endif
3904 return ret;
3905}
3906#endif
3907
3835/* NEVER use any variables (VBInfo), this will be called 3908/* NEVER use any variables (VBInfo), this will be called
3836 * from outside the context of modeswitch! 3909 * from outside the context of modeswitch!
3837 * MUST call getVBType before calling this 3910 * MUST call getVBType before calling this
3838 */ 3911 */
3839void 3912void
3840SiS_DisableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 3913SiS_DisableBridge(struct SiS_Private *SiS_Pr)
3841{ 3914{
3842#ifdef SIS315H 3915#ifdef SIS315H
3843 USHORT tempah,pushax=0,modenum; 3916 unsigned short tempah, pushax=0, modenum;
3844#endif 3917#endif
3845 USHORT temp=0; 3918 unsigned short temp=0;
3846 3919
3847 if(SiS_Pr->SiS_VBType & VB_SISVB) { 3920 if(SiS_Pr->SiS_VBType & VB_SISVB) {
3848 3921
3849 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { /* ===== For 30xB/LV ===== */ 3922 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* ===== For 30xB/C/LV ===== */
3850 3923
3851 if(HwInfo->jChipType < SIS_315H) { 3924 if(SiS_Pr->ChipType < SIS_315H) {
3852 3925
3853#ifdef SIS300 /* 300 series */ 3926#ifdef SIS300 /* 300 series */
3854 3927
3855 if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) { 3928 if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
3856 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 3929 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
3857 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE); 3930 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
3858 } else { 3931 } else {
3859 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x08); 3932 SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
3860 } 3933 }
3861 SiS_PanelDelay(SiS_Pr, HwInfo, 3); 3934 SiS_PanelDelay(SiS_Pr, 3);
3862 } 3935 }
3863 if(SiS_Is301B(SiS_Pr)) { 3936 if(SiS_Is301B(SiS_Pr)) {
3864 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0x3f); 3937 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0x3f);
3865 SiS_ShortDelay(SiS_Pr,1); 3938 SiS_ShortDelay(SiS_Pr,1);
3866 } 3939 }
3867 SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF); 3940 SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF);
3868 SiS_DisplayOff(SiS_Pr); 3941 SiS_DisplayOff(SiS_Pr);
3869 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); 3942 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
3870 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); 3943 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
3871 SiS_UnLockCRT2(SiS_Pr,HwInfo); 3944 SiS_UnLockCRT2(SiS_Pr);
3872 if(!(SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) { 3945 if(!(SiS_Pr->SiS_VBType & VB_SISLVDS)) {
3873 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80); 3946 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80);
3874 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40); 3947 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
3875 } 3948 }
3876 if( (!(SiS_CRT2IsLCD(SiS_Pr, HwInfo))) || 3949 if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
3877 (!(SiS_CR36BIOSWord23d(SiS_Pr, HwInfo))) ) { 3950 (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
3878 SiS_PanelDelay(SiS_Pr, HwInfo, 2); 3951 SiS_PanelDelay(SiS_Pr, 2);
3879 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 3952 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
3880 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD); 3953 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
3881 } else { 3954 } else {
3882 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x04); 3955 SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
3883 } 3956 }
3884 } 3957 }
3885 3958
@@ -3889,130 +3962,127 @@ SiS_DisableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
3889 3962
3890#ifdef SIS315H /* 315 series */ 3963#ifdef SIS315H /* 315 series */
3891 3964
3965 int didpwd = 0;
3892 BOOLEAN custom1 = ((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) || 3966 BOOLEAN custom1 = ((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
3893 (SiS_Pr->SiS_CustomT == CUT_CLEVO1400)) ? TRUE : FALSE; 3967 (SiS_Pr->SiS_CustomT == CUT_CLEVO1400)) ? TRUE : FALSE;
3894 3968
3895 modenum = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34) & 0x7f; 3969 modenum = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34) & 0x7f;
3896 3970
3897 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 3971 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
3898 3972
3899#ifdef SET_EMI 3973#ifdef SET_EMI
3900 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) { 3974 if(SiS_Pr->SiS_VBType & VB_SISEMI) {
3901 if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) { 3975 if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
3902 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c); 3976 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
3903 } 3977 }
3904 } 3978 }
3905#endif 3979#endif
3906 if( (modenum <= 0x13) || 3980
3907 (SiS_IsVAMode(SiS_Pr,HwInfo)) || 3981 didpwd = SiS_HandlePWD(SiS_Pr);
3908 (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) ) { 3982
3909 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE); 3983 if( (modenum <= 0x13) ||
3910 if(custom1) SiS_PanelDelay(SiS_Pr, HwInfo, 3); 3984 (SiS_IsVAMode(SiS_Pr)) ||
3985 (!(SiS_IsDualEdge(SiS_Pr))) ) {
3986 if(!didpwd) {
3987 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xfe);
3988 if(custom1) SiS_PanelDelay(SiS_Pr, 3);
3989 } else {
3990 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xfc);
3991 }
3911 } 3992 }
3912 3993
3913 if(!custom1) { 3994 if(!custom1) {
3914 SiS_DDC2Delay(SiS_Pr,0xff00); 3995 SiS_DDC2Delay(SiS_Pr,0xff00);
3915 SiS_DDC2Delay(SiS_Pr,0xe000); 3996 SiS_DDC2Delay(SiS_Pr,0xe000);
3916 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00); 3997 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
3917 pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06); 3998 pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
3918 if(IS_SIS740) { 3999 if(IS_SIS740) {
3919 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3); 4000 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
3920 } 4001 }
3921 SiS_PanelDelay(SiS_Pr, HwInfo, 3); 4002 SiS_PanelDelay(SiS_Pr, 3);
3922 } 4003 }
3923 4004
3924 } 4005 }
3925 4006
3926 if(!(SiS_IsNotM650orLater(SiS_Pr, HwInfo))) { 4007 if(!(SiS_IsNotM650orLater(SiS_Pr))) {
3927 if(HwInfo->jChipType < SIS_340) { 4008 /* if(SiS_Pr->ChipType < SIS_340) {*/
3928 tempah = 0xef; 4009 tempah = 0xef;
3929 if(SiS_IsVAMode(SiS_Pr,HwInfo)) tempah = 0xf7; 4010 if(SiS_IsVAMode(SiS_Pr)) tempah = 0xf7;
3930 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,tempah); 4011 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,tempah);
3931 } 4012 /*}*/
3932 } 4013 }
3933 4014
3934 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 4015 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
3935 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,~0x10); 4016 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,~0x10);
3936 } 4017 }
3937 4018
3938 tempah = 0x3f; 4019 tempah = 0x3f;
3939 if(SiS_IsDualEdge(SiS_Pr,HwInfo)) { 4020 if(SiS_IsDualEdge(SiS_Pr)) {
3940 tempah = 0x7f; 4021 tempah = 0x7f;
3941 if(!(SiS_IsVAMode(SiS_Pr,HwInfo))) tempah = 0xbf; 4022 if(!(SiS_IsVAMode(SiS_Pr))) tempah = 0xbf;
3942 } 4023 }
3943 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,tempah); 4024 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,tempah);
3944 4025
3945 if((SiS_IsVAMode(SiS_Pr,HwInfo)) || 4026 if((SiS_IsVAMode(SiS_Pr)) ||
3946 ((SiS_Pr->SiS_VBType & VB_SIS301LV302LV) && (modenum <= 0x13))) { 4027 ((SiS_Pr->SiS_VBType & VB_SISLVDS) && (modenum <= 0x13))) {
3947 4028
3948 SiS_DisplayOff(SiS_Pr); 4029 SiS_DisplayOff(SiS_Pr);
3949 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 4030 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
3950 SiS_PanelDelay(SiS_Pr, HwInfo, 2); 4031 SiS_PanelDelay(SiS_Pr, 2);
3951 } 4032 }
3952 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); 4033 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
3953 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1E,0xDF); 4034 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1E,0xDF);
3954 4035
3955 } 4036 }
3956 4037
3957 if((!(SiS_IsVAMode(SiS_Pr,HwInfo))) || 4038 if((!(SiS_IsVAMode(SiS_Pr))) ||
3958 ((SiS_Pr->SiS_VBType & VB_SIS301LV302LV) && (modenum <= 0x13))) { 4039 ((SiS_Pr->SiS_VBType & VB_SISLVDS) && (modenum <= 0x13))) {
3959 4040
3960 if(!(SiS_IsDualEdge(SiS_Pr,HwInfo))) { 4041 if(!(SiS_IsDualEdge(SiS_Pr))) {
3961 SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xdf); 4042 SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xdf);
3962 SiS_DisplayOff(SiS_Pr); 4043 SiS_DisplayOff(SiS_Pr);
3963 } 4044 }
3964 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80); 4045 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
3965 4046
3966 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 4047 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
3967 SiS_PanelDelay(SiS_Pr, HwInfo, 2); 4048 SiS_PanelDelay(SiS_Pr, 2);
3968 } 4049 }
3969 4050
3970 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); 4051 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
3971 temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00); 4052 temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
3972 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10); 4053 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
3973 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); 4054 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
3974 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp); 4055 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
3975 4056
3976 } 4057 }
3977 4058
3978 if(SiS_IsNotM650orLater(SiS_Pr,HwInfo)) { 4059 if(SiS_IsNotM650orLater(SiS_Pr)) {
3979 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f); 4060 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
3980 } 4061 }
3981 4062
3982 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 4063 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
3983
3984 if(!custom1) {
3985
3986 if(!(SiS_IsVAMode(SiS_Pr,HwInfo))) {
3987 if(!(SiS_CRT2IsLCD(SiS_Pr,HwInfo))) {
3988 if(!(SiS_IsDualEdge(SiS_Pr,HwInfo))) {
3989 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
3990 }
3991 }
3992 }
3993 4064
3994 SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax); 4065 if( (!(SiS_IsVAMode(SiS_Pr))) &&
4066 (!(SiS_CRT2IsLCD(SiS_Pr))) &&
4067 (!(SiS_IsDualEdge(SiS_Pr))) ) {
3995 4068
3996 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) { 4069 if(custom1) SiS_PanelDelay(SiS_Pr, 2);
3997 if(SiS_IsVAorLCD(SiS_Pr, HwInfo)) { 4070 if(!didpwd) {
3998 SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 20); 4071 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
3999 } 4072 }
4000 } 4073 if(custom1) SiS_PanelDelay(SiS_Pr, 4);
4001 4074 }
4002 } else {
4003 4075
4004 if((SiS_IsVAMode(SiS_Pr,HwInfo)) || 4076 if(!custom1) {
4005 (!(SiS_IsDualEdge(SiS_Pr,HwInfo)))) { 4077 SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
4006 if((!(SiS_WeHaveBacklightCtrl(SiS_Pr, HwInfo))) || 4078 if(SiS_Pr->SiS_VBType & VB_SISEMI) {
4007 (!(SiS_CRT2IsLCD(SiS_Pr, HwInfo)))) { 4079 if(SiS_IsVAorLCD(SiS_Pr)) {
4008 SiS_PanelDelay(SiS_Pr, HwInfo, 2); 4080 SiS_PanelDelayLoop(SiS_Pr, 3, 20);
4009 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
4010 SiS_PanelDelay(SiS_Pr, HwInfo, 4);
4011 } 4081 }
4012 } 4082 }
4013
4014 } 4083 }
4015 } 4084
4085 }
4016 4086
4017#endif /* SIS315H */ 4087#endif /* SIS315H */
4018 4088
@@ -4020,36 +4090,36 @@ SiS_DisableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4020 4090
4021 } else { /* ============ For 301 ================ */ 4091 } else { /* ============ For 301 ================ */
4022 4092
4023 if(HwInfo->jChipType < SIS_315H) { 4093 if(SiS_Pr->ChipType < SIS_315H) {
4024#ifdef SIS300 4094#ifdef SIS300
4025 if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) { 4095 if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
4026 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x08); 4096 SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
4027 SiS_PanelDelay(SiS_Pr, HwInfo, 3); 4097 SiS_PanelDelay(SiS_Pr, 3);
4028 } 4098 }
4029#endif 4099#endif
4030 } 4100 }
4031 4101
4032 SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF); /* disable VB */ 4102 SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF); /* disable VB */
4033 SiS_DisplayOff(SiS_Pr); 4103 SiS_DisplayOff(SiS_Pr);
4034 4104
4035 if(HwInfo->jChipType >= SIS_315H) { 4105 if(SiS_Pr->ChipType >= SIS_315H) {
4036 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80); 4106 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
4037 } 4107 }
4038 4108
4039 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); /* disable lock mode */ 4109 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); /* disable lock mode */
4040 4110
4041 if(HwInfo->jChipType >= SIS_315H) { 4111 if(SiS_Pr->ChipType >= SIS_315H) {
4042 temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00); 4112 temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
4043 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10); 4113 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
4044 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); 4114 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
4045 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp); 4115 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
4046 } else { 4116 } else {
4047#ifdef SIS300 4117#ifdef SIS300
4048 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); /* disable CRT2 */ 4118 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); /* disable CRT2 */
4049 if( (!(SiS_CRT2IsLCD(SiS_Pr, HwInfo))) || 4119 if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
4050 (!(SiS_CR36BIOSWord23d(SiS_Pr,HwInfo))) ) { 4120 (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
4051 SiS_PanelDelay(SiS_Pr, HwInfo, 2); 4121 SiS_PanelDelay(SiS_Pr, 2);
4052 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x04); 4122 SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
4053 } 4123 }
4054#endif 4124#endif
4055 } 4125 }
@@ -4058,34 +4128,34 @@ SiS_DisableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4058 4128
4059 } else { /* ============ For LVDS =============*/ 4129 } else { /* ============ For LVDS =============*/
4060 4130
4061 if(HwInfo->jChipType < SIS_315H) { 4131 if(SiS_Pr->ChipType < SIS_315H) {
4062 4132
4063#ifdef SIS300 /* 300 series */ 4133#ifdef SIS300 /* 300 series */
4064 4134
4065 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { 4135 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
4066 SiS_SetCH700x(SiS_Pr,0x090E); 4136 SiS_SetCH700x(SiS_Pr,0x0E,0x09);
4067 } 4137 }
4068 4138
4069 if(HwInfo->jChipType == SIS_730) { 4139 if(SiS_Pr->ChipType == SIS_730) {
4070 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) { 4140 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) {
4071 SiS_WaitVBRetrace(SiS_Pr,HwInfo); 4141 SiS_WaitVBRetrace(SiS_Pr);
4072 } 4142 }
4073 if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) { 4143 if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
4074 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x08); 4144 SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
4075 SiS_PanelDelay(SiS_Pr, HwInfo, 3); 4145 SiS_PanelDelay(SiS_Pr, 3);
4076 } 4146 }
4077 } else { 4147 } else {
4078 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) { 4148 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) {
4079 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) { 4149 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
4080 if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) { 4150 if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
4081 SiS_WaitVBRetrace(SiS_Pr,HwInfo); 4151 SiS_WaitVBRetrace(SiS_Pr);
4082 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x1c)) { 4152 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x1c)) {
4083 SiS_DisplayOff(SiS_Pr); 4153 SiS_DisplayOff(SiS_Pr);
4084 } 4154 }
4085 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x08); 4155 SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
4086 SiS_PanelDelay(SiS_Pr, HwInfo, 3); 4156 SiS_PanelDelay(SiS_Pr, 3);
4087 } 4157 }
4088 } 4158 }
4089 } 4159 }
4090 } 4160 }
4091 4161
@@ -4094,14 +4164,14 @@ SiS_DisableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4094 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); 4164 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
4095 4165
4096 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); 4166 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
4097 SiS_UnLockCRT2(SiS_Pr,HwInfo); 4167 SiS_UnLockCRT2(SiS_Pr);
4098 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80); 4168 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80);
4099 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40); 4169 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
4100 4170
4101 if( (!(SiS_CRT2IsLCD(SiS_Pr, HwInfo))) || 4171 if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
4102 (!(SiS_CR36BIOSWord23d(SiS_Pr,HwInfo))) ) { 4172 (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
4103 SiS_PanelDelay(SiS_Pr, HwInfo, 2); 4173 SiS_PanelDelay(SiS_Pr, 2);
4104 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x04); 4174 SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
4105 } 4175 }
4106 4176
4107#endif /* SIS300 */ 4177#endif /* SIS300 */
@@ -4110,113 +4180,113 @@ SiS_DisableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4110 4180
4111#ifdef SIS315H /* 315 series */ 4181#ifdef SIS315H /* 315 series */
4112 4182
4113 if(!(SiS_IsNotM650orLater(SiS_Pr,HwInfo))) { 4183 if(!(SiS_IsNotM650orLater(SiS_Pr))) {
4114 if(HwInfo->jChipType < SIS_340) { 4184 /*if(SiS_Pr->ChipType < SIS_340) { */ /* XGI needs this */
4115 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,~0x18); 4185 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,~0x18);
4116 } 4186 /* } */
4117 } 4187 }
4118 4188
4119 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 4189 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
4120 4190
4121 if(HwInfo->jChipType == SIS_740) { 4191 if(SiS_Pr->ChipType == SIS_740) {
4122 temp = SiS_GetCH701x(SiS_Pr,0x61); 4192 temp = SiS_GetCH701x(SiS_Pr,0x61);
4123 if(temp < 1) { 4193 if(temp < 1) {
4124 SiS_SetCH701x(SiS_Pr,0xac76); 4194 SiS_SetCH701x(SiS_Pr,0x76,0xac);
4125 SiS_SetCH701x(SiS_Pr,0x0066); 4195 SiS_SetCH701x(SiS_Pr,0x66,0x00);
4126 } 4196 }
4127 4197
4128 if( (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) || 4198 if( (!(SiS_IsDualEdge(SiS_Pr))) ||
4129 (SiS_IsTVOrYPbPrOrScart(SiS_Pr,HwInfo)) ) { 4199 (SiS_IsTVOrYPbPrOrScart(SiS_Pr)) ) {
4130 SiS_SetCH701x(SiS_Pr,0x3e49); 4200 SiS_SetCH701x(SiS_Pr,0x49,0x3e);
4131 } 4201 }
4132 } 4202 }
4133 4203
4134 if( (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) || 4204 if( (!(SiS_IsDualEdge(SiS_Pr))) ||
4135 (SiS_IsVAMode(SiS_Pr,HwInfo)) ) { 4205 (SiS_IsVAMode(SiS_Pr)) ) {
4136 SiS_Chrontel701xBLOff(SiS_Pr); 4206 SiS_Chrontel701xBLOff(SiS_Pr);
4137 SiS_Chrontel701xOff(SiS_Pr,HwInfo); 4207 SiS_Chrontel701xOff(SiS_Pr);
4138 } 4208 }
4139 4209
4140 if(HwInfo->jChipType != SIS_740) { 4210 if(SiS_Pr->ChipType != SIS_740) {
4141 if( (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) || 4211 if( (!(SiS_IsDualEdge(SiS_Pr))) ||
4142 (SiS_IsTVOrYPbPrOrScart(SiS_Pr,HwInfo)) ) { 4212 (SiS_IsTVOrYPbPrOrScart(SiS_Pr)) ) {
4143 SiS_SetCH701x(SiS_Pr,0x0149); 4213 SiS_SetCH701x(SiS_Pr,0x49,0x01);
4144 } 4214 }
4145 } 4215 }
4146 4216
4147 } 4217 }
4148 4218
4149 if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { 4219 if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
4150 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x08); 4220 SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
4151 SiS_PanelDelay(SiS_Pr, HwInfo, 3); 4221 SiS_PanelDelay(SiS_Pr, 3);
4152 } 4222 }
4153 4223
4154 if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) || 4224 if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
4155 (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) || 4225 (!(SiS_IsDualEdge(SiS_Pr))) ||
4156 (!(SiS_IsTVOrYPbPrOrScart(SiS_Pr,HwInfo))) ) { 4226 (!(SiS_IsTVOrYPbPrOrScart(SiS_Pr))) ) {
4157 SiS_DisplayOff(SiS_Pr); 4227 SiS_DisplayOff(SiS_Pr);
4158 } 4228 }
4159 4229
4160 if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) || 4230 if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
4161 (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) || 4231 (!(SiS_IsDualEdge(SiS_Pr))) ||
4162 (!(SiS_IsVAMode(SiS_Pr,HwInfo))) ) { 4232 (!(SiS_IsVAMode(SiS_Pr))) ) {
4163 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80); 4233 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
4164 } 4234 }
4165 4235
4166 if(HwInfo->jChipType == SIS_740) { 4236 if(SiS_Pr->ChipType == SIS_740) {
4167 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f); 4237 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
4168 } 4238 }
4169 4239
4170 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); 4240 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
4171 4241
4172 if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) || 4242 if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
4173 (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) || 4243 (!(SiS_IsDualEdge(SiS_Pr))) ||
4174 (!(SiS_IsVAMode(SiS_Pr,HwInfo))) ) { 4244 (!(SiS_IsVAMode(SiS_Pr))) ) {
4175 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); 4245 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
4176 } 4246 }
4177 4247
4178 if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { 4248 if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
4179 if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) { 4249 if(SiS_CRT2IsLCD(SiS_Pr)) {
4180 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf); 4250 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
4181 if(HwInfo->jChipType == SIS_550) { 4251 if(SiS_Pr->ChipType == SIS_550) {
4182 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xbf); 4252 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xbf);
4183 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xef); 4253 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xef);
4184 } 4254 }
4185 } 4255 }
4186 } else { 4256 } else {
4187 if(HwInfo->jChipType == SIS_740) { 4257 if(SiS_Pr->ChipType == SIS_740) {
4188 if(SiS_IsLCDOrLCDA(SiS_Pr,HwInfo)) { 4258 if(SiS_IsLCDOrLCDA(SiS_Pr)) {
4189 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf); 4259 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
4190 } 4260 }
4191 } else if(SiS_IsVAMode(SiS_Pr,HwInfo)) { 4261 } else if(SiS_IsVAMode(SiS_Pr)) {
4192 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf); 4262 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
4193 } 4263 }
4194 } 4264 }
4195 4265
4196 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 4266 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
4197 if(SiS_IsDualEdge(SiS_Pr,HwInfo)) { 4267 if(SiS_IsDualEdge(SiS_Pr)) {
4198 /* SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xff); */ 4268 /* SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xff); */
4199 } else { 4269 } else {
4200 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb); 4270 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
4201 } 4271 }
4202 } 4272 }
4203 4273
4204 SiS_UnLockCRT2(SiS_Pr,HwInfo); 4274 SiS_UnLockCRT2(SiS_Pr);
4205 4275
4206 if(HwInfo->jChipType == SIS_550) { 4276 if(SiS_Pr->ChipType == SIS_550) {
4207 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80); /* DirectDVD PAL?*/ 4277 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80); /* DirectDVD PAL?*/
4208 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40); /* VB clock / 4 ? */ 4278 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40); /* VB clock / 4 ? */
4209 } else if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) || 4279 } else if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
4210 (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) || 4280 (!(SiS_IsDualEdge(SiS_Pr))) ||
4211 (!(SiS_IsVAMode(SiS_Pr,HwInfo))) ) { 4281 (!(SiS_IsVAMode(SiS_Pr))) ) {
4212 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7); 4282 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7);
4213 } 4283 }
4214 4284
4215 if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { 4285 if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
4216 if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) { 4286 if(SiS_CRT2IsLCD(SiS_Pr)) {
4217 if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) { 4287 if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
4218 SiS_PanelDelay(SiS_Pr, HwInfo, 2); 4288 SiS_PanelDelay(SiS_Pr, 2);
4219 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x04); 4289 SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
4220 } 4290 }
4221 } 4291 }
4222 } 4292 }
@@ -4237,78 +4307,81 @@ SiS_DisableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4237 * from outside the context of a mode switch! 4307 * from outside the context of a mode switch!
4238 * MUST call getVBType before calling this 4308 * MUST call getVBType before calling this
4239 */ 4309 */
4240static void 4310#ifdef SIS_LINUX_KERNEL
4241SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 4311static
4312#endif
4313void
4314SiS_EnableBridge(struct SiS_Private *SiS_Pr)
4242{ 4315{
4243 USHORT temp=0,tempah; 4316 unsigned short temp=0, tempah;
4244#ifdef SIS315H 4317#ifdef SIS315H
4245 USHORT temp1,pushax=0; 4318 unsigned short temp1, pushax=0;
4246 BOOLEAN delaylong = FALSE; 4319 BOOLEAN delaylong = FALSE;
4247#endif 4320#endif
4248 4321
4249 if(SiS_Pr->SiS_VBType & VB_SISVB) { 4322 if(SiS_Pr->SiS_VBType & VB_SISVB) {
4250 4323
4251 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { /* ====== For 301B et al ====== */ 4324 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* ====== For 301B et al ====== */
4252 4325
4253 if(HwInfo->jChipType < SIS_315H) { 4326 if(SiS_Pr->ChipType < SIS_315H) {
4254 4327
4255#ifdef SIS300 /* 300 series */ 4328#ifdef SIS300 /* 300 series */
4256 4329
4257 if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) { 4330 if(SiS_CRT2IsLCD(SiS_Pr)) {
4258 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 4331 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
4259 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02); 4332 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
4260 } else if(SiS_Pr->SiS_VBType & VB_NoLCD) { 4333 } else if(SiS_Pr->SiS_VBType & VB_NoLCD) {
4261 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x00); 4334 SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
4262 } 4335 }
4263 if(SiS_Pr->SiS_VBType & (VB_SIS301LV302LV | VB_NoLCD)) { 4336 if(SiS_Pr->SiS_VBType & (VB_SISLVDS | VB_NoLCD)) {
4264 if(!(SiS_CR36BIOSWord23d(SiS_Pr, HwInfo))) { 4337 if(!(SiS_CR36BIOSWord23d(SiS_Pr))) {
4265 SiS_PanelDelay(SiS_Pr, HwInfo, 0); 4338 SiS_PanelDelay(SiS_Pr, 0);
4266 } 4339 }
4267 } 4340 }
4268 } 4341 }
4269 4342
4270 if((SiS_Pr->SiS_VBType & VB_NoLCD) && 4343 if((SiS_Pr->SiS_VBType & VB_NoLCD) &&
4271 (SiS_CRT2IsLCD(SiS_Pr, HwInfo))) { 4344 (SiS_CRT2IsLCD(SiS_Pr))) {
4272 4345
4273 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* Enable CRT2 */ 4346 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* Enable CRT2 */
4274 SiS_DisplayOn(SiS_Pr); 4347 SiS_DisplayOn(SiS_Pr);
4275 SiS_UnLockCRT2(SiS_Pr,HwInfo); 4348 SiS_UnLockCRT2(SiS_Pr);
4276 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF); 4349 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
4277 if(SiS_BridgeInSlavemode(SiS_Pr)) { 4350 if(SiS_BridgeInSlavemode(SiS_Pr)) {
4278 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F); 4351 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
4279 } else { 4352 } else {
4280 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40); 4353 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
4281 } 4354 }
4282 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) { 4355 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
4283 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) { 4356 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
4284 if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) { 4357 if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
4285 SiS_PanelDelay(SiS_Pr, HwInfo, 1); 4358 SiS_PanelDelay(SiS_Pr, 1);
4286 } 4359 }
4287 SiS_WaitVBRetrace(SiS_Pr,HwInfo); 4360 SiS_WaitVBRetrace(SiS_Pr);
4288 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x00); 4361 SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
4289 } 4362 }
4290 } 4363 }
4291 4364
4292 } else { 4365 } else {
4293 4366
4294 temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */ 4367 temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */
4295 if(SiS_BridgeInSlavemode(SiS_Pr)) { 4368 if(SiS_BridgeInSlavemode(SiS_Pr)) {
4296 tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); 4369 tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
4297 if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20; 4370 if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
4298 } 4371 }
4299 SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp); 4372 SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
4300 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); 4373 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
4301 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */ 4374 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */
4302 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,0xC0); 4375 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,0xC0);
4303 SiS_DisplayOn(SiS_Pr); 4376 SiS_DisplayOn(SiS_Pr);
4304 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 4377 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
4305 if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) { 4378 if(SiS_CRT2IsLCD(SiS_Pr)) {
4306 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) { 4379 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
4307 if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) { 4380 if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
4308 SiS_PanelDelay(SiS_Pr, HwInfo, 1); 4381 SiS_PanelDelay(SiS_Pr, 1);
4309 } 4382 }
4310 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01); 4383 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
4311 } 4384 }
4312 } 4385 }
4313 } 4386 }
4314 4387
@@ -4322,31 +4395,32 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4322#ifdef SIS315H /* 315 series */ 4395#ifdef SIS315H /* 315 series */
4323 4396
4324#ifdef SET_EMI 4397#ifdef SET_EMI
4325 UCHAR r30=0, r31=0, r32=0, r33=0, cr36=0; 4398 unsigned char r30=0, r31=0, r32=0, r33=0, cr36=0;
4326 /* USHORT emidelay=0; */ 4399 int didpwd = 0;
4400 /* unsigned short emidelay=0; */
4327#endif 4401#endif
4328 4402
4329 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 4403 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
4330 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0xef); 4404 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0xef);
4331#ifdef SET_EMI 4405#ifdef SET_EMI
4332 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) { 4406 if(SiS_Pr->SiS_VBType & VB_SISEMI) {
4333 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c); 4407 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
4334 } 4408 }
4335#endif 4409#endif
4336 } 4410 }
4337 4411
4338 if(!(SiS_IsNotM650orLater(SiS_Pr, HwInfo))) { 4412 if(!(SiS_IsNotM650orLater(SiS_Pr))) {
4339 if(HwInfo->jChipType < SIS_340) { 4413 /*if(SiS_Pr->ChipType < SIS_340) { */
4340 tempah = 0x10; 4414 tempah = 0x10;
4341 if(SiS_LCDAEnabled(SiS_Pr, HwInfo)) { 4415 if(SiS_LCDAEnabled(SiS_Pr)) {
4342 if(SiS_TVEnabled(SiS_Pr, HwInfo)) tempah = 0x18; 4416 if(SiS_TVEnabled(SiS_Pr)) tempah = 0x18;
4343 else tempah = 0x08; 4417 else tempah = 0x08;
4344 } 4418 }
4345 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4c,tempah); 4419 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4c,tempah);
4346 } 4420 /*}*/
4347 } 4421 }
4348 4422
4349 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 4423 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
4350 4424
4351 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00); 4425 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
4352 SiS_DisplayOff(SiS_Pr); 4426 SiS_DisplayOff(SiS_Pr);
@@ -4355,42 +4429,51 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4355 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3); 4429 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
4356 } 4430 }
4357 4431
4358 if(SiS_IsVAorLCD(SiS_Pr, HwInfo)) { 4432 didpwd = SiS_HandlePWD(SiS_Pr);
4359 if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) { 4433
4360 SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 2); 4434 if(SiS_IsVAorLCD(SiS_Pr)) {
4361 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02); 4435 if(!didpwd) {
4362 SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 2); 4436 if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
4363 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) { 4437 SiS_PanelDelayLoop(SiS_Pr, 3, 2);
4364 SiS_GenericDelay(SiS_Pr, 0x4500); 4438 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
4439 SiS_PanelDelayLoop(SiS_Pr, 3, 2);
4440 if(SiS_Pr->SiS_VBType & VB_SISEMI) {
4441 SiS_GenericDelay(SiS_Pr, 17664);
4442 }
4443 }
4444 } else {
4445 SiS_PanelDelayLoop(SiS_Pr, 3, 2);
4446 if(SiS_Pr->SiS_VBType & VB_SISEMI) {
4447 SiS_GenericDelay(SiS_Pr, 17664);
4365 } 4448 }
4366 } 4449 }
4367 } 4450 }
4368 4451
4369 if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40)) { 4452 if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40)) {
4370 SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 10); 4453 SiS_PanelDelayLoop(SiS_Pr, 3, 10);
4371 delaylong = TRUE; 4454 delaylong = TRUE;
4372 } 4455 }
4373 4456
4374 } 4457 }
4375 4458
4376 if(!(SiS_IsVAMode(SiS_Pr,HwInfo))) { 4459 if(!(SiS_IsVAMode(SiS_Pr))) {
4377 4460
4378 temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; 4461 temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF;
4379 if(SiS_BridgeInSlavemode(SiS_Pr)) { 4462 if(SiS_BridgeInSlavemode(SiS_Pr)) {
4380 tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); 4463 tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
4381 if(!(tempah & SetCRT2ToRAMDAC)) { 4464 if(!(tempah & SetCRT2ToRAMDAC)) {
4382 if(!(SiS_LCDAEnabled(SiS_Pr, HwInfo))) temp |= 0x20; 4465 if(!(SiS_LCDAEnabled(SiS_Pr))) temp |= 0x20;
4383 } 4466 }
4384 } 4467 }
4385 SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp); 4468 SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
4386 4469
4387 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */ 4470 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */
4388 4471
4389 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f); 4472 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
4390 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80); 4473 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
4391 4474
4392 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 4475 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
4393 SiS_PanelDelay(SiS_Pr, HwInfo, 2); 4476 SiS_PanelDelay(SiS_Pr, 2);
4394 } 4477 }
4395 4478
4396 } else { 4479 } else {
@@ -4402,38 +4485,48 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4402 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1f,0x20); 4485 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1f,0x20);
4403 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80); 4486 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
4404 4487
4488 if(SiS_Pr->SiS_VBType & VB_SISPOWER) {
4489 if( (SiS_LCDAEnabled(SiS_Pr)) ||
4490 (SiS_CRT2IsLCD(SiS_Pr)) ) {
4491 /* Enable "LVDS PLL power on" (even on 301C) */
4492 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x2a,0x7f);
4493 /* Enable "LVDS Driver Power on" (even on 301C) */
4494 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x7f);
4495 }
4496 }
4497
4405 tempah = 0xc0; 4498 tempah = 0xc0;
4406 if(SiS_IsDualEdge(SiS_Pr, HwInfo)) { 4499 if(SiS_IsDualEdge(SiS_Pr)) {
4407 tempah = 0x80; 4500 tempah = 0x80;
4408 if(!(SiS_IsVAMode(SiS_Pr, HwInfo))) tempah = 0x40; 4501 if(!(SiS_IsVAMode(SiS_Pr))) tempah = 0x40;
4409 } 4502 }
4410 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,tempah); 4503 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,tempah);
4411 4504
4412 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 4505 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
4413 4506
4414 SiS_PanelDelay(SiS_Pr, HwInfo, 2); 4507 SiS_PanelDelay(SiS_Pr, 2);
4415 4508
4416 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1f,0x10); 4509 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1f,0x10);
4417 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80); 4510 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
4418 4511
4419 if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) { 4512 if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
4420#ifdef SET_EMI 4513#ifdef SET_EMI
4421 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) { 4514 if(SiS_Pr->SiS_VBType & VB_SISEMI) {
4422 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c); 4515 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
4423 SiS_GenericDelay(SiS_Pr, 0x500); 4516 SiS_GenericDelay(SiS_Pr, 2048);
4424 } 4517 }
4425#endif 4518#endif
4426 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x0c); 4519 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x0c);
4427 4520
4428 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) { 4521 if(SiS_Pr->SiS_VBType & VB_SISEMI) {
4429#ifdef SET_EMI 4522#ifdef SET_EMI
4430 cr36 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36); 4523 cr36 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
4431 4524
4432 if(SiS_Pr->SiS_ROMNew) { 4525 if(SiS_Pr->SiS_ROMNew) {
4433 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 4526 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
4434 USHORT romptr = GetLCDStructPtr661_2(SiS_Pr, HwInfo); 4527 unsigned short romptr = GetLCDStructPtr661_2(SiS_Pr);
4435 if(romptr) { 4528 if(romptr) {
4436 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */ 4529 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
4437 SiS_Pr->EMI_30 = 0; 4530 SiS_Pr->EMI_30 = 0;
4438 SiS_Pr->EMI_31 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 0]; 4531 SiS_Pr->EMI_31 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 0];
4439 SiS_Pr->EMI_32 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 1]; 4532 SiS_Pr->EMI_32 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 1];
@@ -4511,21 +4604,21 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4511 if(!SiS_Pr->OverruleEMI) { 4604 if(!SiS_Pr->OverruleEMI) {
4512#ifdef COMPAL_HACK 4605#ifdef COMPAL_HACK
4513 if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) { 4606 if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
4514 if((cr36 & 0x0f) == 0x09) { 4607 if((cr36 & 0x0f) == 0x09) {
4515 r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x00; 4608 r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x00;
4516 } 4609 }
4517 } 4610 }
4518#endif 4611#endif
4519#ifdef COMPAQ_HACK 4612#ifdef COMPAQ_HACK
4520 if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) { 4613 if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
4521 if((cr36 & 0x0f) == 0x03) { 4614 if((cr36 & 0x0f) == 0x03) {
4522 r30 = 0x20; r31 = 0x12; r32 = 0xd0; r33 = 0x6b; 4615 r30 = 0x20; r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
4523 } 4616 }
4524 } 4617 }
4525#endif 4618#endif
4526#ifdef ASUS_HACK 4619#ifdef ASUS_HACK
4527 if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) { 4620 if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
4528 if((cr36 & 0x0f) == 0x02) { 4621 if((cr36 & 0x0f) == 0x02) {
4529 /* r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 2 */ 4622 /* r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 2 */
4530 /* r30 = 0x20; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 3 */ 4623 /* r30 = 0x20; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 3 */
4531 /* r30 = 0x60; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 4 */ 4624 /* r30 = 0x60; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 4 */
@@ -4533,11 +4626,11 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4533 } 4626 }
4534 } 4627 }
4535#endif 4628#endif
4536 } 4629 }
4537 4630
4538 if(!(SiS_Pr->OverruleEMI && (!r30) && (!r31) && (!r32) && (!r33))) { 4631 if(!(SiS_Pr->OverruleEMI && (!r30) && (!r31) && (!r32) && (!r33))) {
4539 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */ 4632 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
4540 SiS_GenericDelay(SiS_Pr, 0x500); 4633 SiS_GenericDelay(SiS_Pr, 2048);
4541 } 4634 }
4542 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x31,r31); 4635 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x31,r31);
4543 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x32,r32); 4636 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x32,r32);
@@ -4547,36 +4640,44 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4547 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10); 4640 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
4548 4641
4549#ifdef SET_EMI 4642#ifdef SET_EMI
4550 if( (SiS_LCDAEnabled(SiS_Pr, HwInfo)) || 4643 if( (SiS_LCDAEnabled(SiS_Pr)) ||
4551 (SiS_CRT2IsLCD(SiS_Pr, HwInfo)) ) { 4644 (SiS_CRT2IsLCD(SiS_Pr)) ) {
4552 if(r30 & 0x40) { 4645 if(r30 & 0x40) {
4553 SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 5); 4646 /*SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x2a,0x80);*/
4647 SiS_PanelDelayLoop(SiS_Pr, 3, 5);
4554 if(delaylong) { 4648 if(delaylong) {
4555 SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 5); 4649 SiS_PanelDelayLoop(SiS_Pr, 3, 5);
4556 delaylong = FALSE; 4650 delaylong = FALSE;
4557 } 4651 }
4558 SiS_WaitVBRetrace(SiS_Pr,HwInfo); 4652 SiS_WaitVBRetrace(SiS_Pr);
4653 SiS_WaitVBRetrace(SiS_Pr);
4559 if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) { 4654 if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
4560 SiS_GenericDelay(SiS_Pr, 0x500); 4655 SiS_GenericDelay(SiS_Pr, 1280);
4561 } 4656 }
4562 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x40); /* Enable */ 4657 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x40); /* Enable */
4563 } 4658 /*SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x2a,0x7f);*/
4659 }
4564 } 4660 }
4565#endif 4661#endif
4566 } 4662 }
4567 } 4663 }
4568 4664
4569 if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) { 4665 if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
4570 if(SiS_IsVAorLCD(SiS_Pr, HwInfo)) { 4666 if(SiS_IsVAorLCD(SiS_Pr)) {
4571 SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 10); 4667 SiS_PanelDelayLoop(SiS_Pr, 3, 10);
4572 if(delaylong) { 4668 if(delaylong) {
4573 SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 10); 4669 SiS_PanelDelayLoop(SiS_Pr, 3, 10);
4574 } 4670 }
4575 SiS_WaitVBRetrace(SiS_Pr,HwInfo); 4671 SiS_WaitVBRetrace(SiS_Pr);
4576 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) { 4672 if(SiS_Pr->SiS_VBType & VB_SISEMI) {
4577 SiS_GenericDelay(SiS_Pr, 0x500); 4673 SiS_GenericDelay(SiS_Pr, 2048);
4674 SiS_WaitVBRetrace(SiS_Pr);
4675 }
4676 if(!didpwd) {
4677 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
4678 } else {
4679 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x03);
4578 } 4680 }
4579 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
4580 } 4681 }
4581 } 4682 }
4582 4683
@@ -4586,7 +4687,7 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4586 4687
4587 } 4688 }
4588 4689
4589 if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) { 4690 if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
4590 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f); 4691 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
4591 } 4692 }
4592 4693
@@ -4596,26 +4697,26 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4596 4697
4597 } else { /* ============ For 301 ================ */ 4698 } else { /* ============ For 301 ================ */
4598 4699
4599 if(HwInfo->jChipType < SIS_315H) { 4700 if(SiS_Pr->ChipType < SIS_315H) {
4600 if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) { 4701 if(SiS_CRT2IsLCD(SiS_Pr)) {
4601 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x00); 4702 SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
4602 SiS_PanelDelay(SiS_Pr, HwInfo, 0); 4703 SiS_PanelDelay(SiS_Pr, 0);
4603 } 4704 }
4604 } 4705 }
4605 4706
4606 temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */ 4707 temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */
4607 if(SiS_BridgeInSlavemode(SiS_Pr)) { 4708 if(SiS_BridgeInSlavemode(SiS_Pr)) {
4608 tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); 4709 tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
4609 if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20; 4710 if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
4610 } 4711 }
4611 SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp); 4712 SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
4612 4713
4613 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */ 4714 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */
4614 4715
4615 if(HwInfo->jChipType >= SIS_315H) { 4716 if(SiS_Pr->ChipType >= SIS_315H) {
4616 temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E); 4717 temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
4617 if(!(temp & 0x80)) { 4718 if(!(temp & 0x80)) {
4618 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80); /* BVBDOENABLE=1 */ 4719 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80); /* BVBDOENABLE=1 */
4619 } 4720 }
4620 } 4721 }
4621 4722
@@ -4623,15 +4724,15 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4623 4724
4624 SiS_VBLongWait(SiS_Pr); 4725 SiS_VBLongWait(SiS_Pr);
4625 SiS_DisplayOn(SiS_Pr); 4726 SiS_DisplayOn(SiS_Pr);
4626 if(HwInfo->jChipType >= SIS_315H) { 4727 if(SiS_Pr->ChipType >= SIS_315H) {
4627 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f); 4728 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
4628 } 4729 }
4629 SiS_VBLongWait(SiS_Pr); 4730 SiS_VBLongWait(SiS_Pr);
4630 4731
4631 if(HwInfo->jChipType < SIS_315H) { 4732 if(SiS_Pr->ChipType < SIS_315H) {
4632 if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) { 4733 if(SiS_CRT2IsLCD(SiS_Pr)) {
4633 SiS_PanelDelay(SiS_Pr, HwInfo, 1); 4734 SiS_PanelDelay(SiS_Pr, 1);
4634 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x00); 4735 SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
4635 } 4736 }
4636 } 4737 }
4637 4738
@@ -4639,49 +4740,49 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4639 4740
4640 } else { /* =================== For LVDS ================== */ 4741 } else { /* =================== For LVDS ================== */
4641 4742
4642 if(HwInfo->jChipType < SIS_315H) { 4743 if(SiS_Pr->ChipType < SIS_315H) {
4643 4744
4644#ifdef SIS300 /* 300 series */ 4745#ifdef SIS300 /* 300 series */
4645 4746
4646 if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) { 4747 if(SiS_CRT2IsLCD(SiS_Pr)) {
4647 if(HwInfo->jChipType == SIS_730) { 4748 if(SiS_Pr->ChipType == SIS_730) {
4648 SiS_PanelDelay(SiS_Pr, HwInfo, 1); 4749 SiS_PanelDelay(SiS_Pr, 1);
4649 SiS_PanelDelay(SiS_Pr, HwInfo, 1); 4750 SiS_PanelDelay(SiS_Pr, 1);
4650 SiS_PanelDelay(SiS_Pr, HwInfo, 1); 4751 SiS_PanelDelay(SiS_Pr, 1);
4651 } 4752 }
4652 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x00); 4753 SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
4653 if(!(SiS_CR36BIOSWord23d(SiS_Pr,HwInfo))) { 4754 if(!(SiS_CR36BIOSWord23d(SiS_Pr))) {
4654 SiS_PanelDelay(SiS_Pr, HwInfo, 0); 4755 SiS_PanelDelay(SiS_Pr, 0);
4655 } 4756 }
4656 } 4757 }
4657 4758
4658 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); 4759 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
4659 SiS_DisplayOn(SiS_Pr); 4760 SiS_DisplayOn(SiS_Pr);
4660 SiS_UnLockCRT2(SiS_Pr,HwInfo); 4761 SiS_UnLockCRT2(SiS_Pr);
4661 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF); 4762 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
4662 if(SiS_BridgeInSlavemode(SiS_Pr)) { 4763 if(SiS_BridgeInSlavemode(SiS_Pr)) {
4663 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F); 4764 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
4664 } else { 4765 } else {
4665 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40); 4766 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
4666 } 4767 }
4667 4768
4668 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { 4769 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
4669 if(!(SiS_CRT2IsLCD(SiS_Pr, HwInfo))) { 4770 if(!(SiS_CRT2IsLCD(SiS_Pr))) {
4670 SiS_WaitVBRetrace(SiS_Pr, HwInfo); 4771 SiS_WaitVBRetrace(SiS_Pr);
4671 SiS_SetCH700x(SiS_Pr,0x0B0E); 4772 SiS_SetCH700x(SiS_Pr,0x0E,0x0B);
4672 } 4773 }
4673 } 4774 }
4674 4775
4675 if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) { 4776 if(SiS_CRT2IsLCD(SiS_Pr)) {
4676 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) { 4777 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
4677 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) { 4778 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
4678 if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) { 4779 if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
4679 SiS_PanelDelay(SiS_Pr, HwInfo, 1); 4780 SiS_PanelDelay(SiS_Pr, 1);
4680 SiS_PanelDelay(SiS_Pr, HwInfo, 1); 4781 SiS_PanelDelay(SiS_Pr, 1);
4681 } 4782 }
4682 SiS_WaitVBRetrace(SiS_Pr, HwInfo); 4783 SiS_WaitVBRetrace(SiS_Pr);
4683 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x00); 4784 SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
4684 } 4785 }
4685 } 4786 }
4686 } 4787 }
4687 4788
@@ -4691,94 +4792,94 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4691 4792
4692#ifdef SIS315H /* 315 series */ 4793#ifdef SIS315H /* 315 series */
4693 4794
4694 if(!(SiS_IsNotM650orLater(SiS_Pr,HwInfo))) { 4795 if(!(SiS_IsNotM650orLater(SiS_Pr))) {
4695 if(HwInfo->jChipType < SIS_340) { 4796 /*if(SiS_Pr->ChipType < SIS_340) {*/ /* XGI needs this */
4696 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x4c,0x18); 4797 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x4c,0x18);
4697 } 4798 /*}*/
4698 } 4799 }
4699 4800
4700 if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { 4801 if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
4701 if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) { 4802 if(SiS_CRT2IsLCD(SiS_Pr)) {
4702 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x00); 4803 SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
4703 SiS_PanelDelay(SiS_Pr, HwInfo, 0); 4804 SiS_PanelDelay(SiS_Pr, 0);
4704 } 4805 }
4705 } 4806 }
4706 4807
4707 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); 4808 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
4708 SiS_UnLockCRT2(SiS_Pr,HwInfo); 4809 SiS_UnLockCRT2(SiS_Pr);
4709 4810
4710 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7); 4811 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7);
4711 4812
4712 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { 4813 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
4713 temp = SiS_GetCH701x(SiS_Pr,0x66); 4814 temp = SiS_GetCH701x(SiS_Pr,0x66);
4714 temp &= 0x20; 4815 temp &= 0x20;
4715 SiS_Chrontel701xBLOff(SiS_Pr); 4816 SiS_Chrontel701xBLOff(SiS_Pr);
4716 } 4817 }
4717 4818
4718 if(HwInfo->jChipType != SIS_550) { 4819 if(SiS_Pr->ChipType != SIS_550) {
4719 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f); 4820 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
4720 } 4821 }
4721 4822
4722 if(HwInfo->jChipType == SIS_740) { 4823 if(SiS_Pr->ChipType == SIS_740) {
4723 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { 4824 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
4724 if(SiS_IsLCDOrLCDA(SiS_Pr, HwInfo)) { 4825 if(SiS_IsLCDOrLCDA(SiS_Pr)) {
4725 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20); 4826 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
4726 } 4827 }
4727 } 4828 }
4728 } 4829 }
4729 4830
4730 temp1 = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E); 4831 temp1 = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
4731 if(!(temp1 & 0x80)) { 4832 if(!(temp1 & 0x80)) {
4732 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80); 4833 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80);
4733 } 4834 }
4734 4835
4735 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { 4836 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
4736 if(temp) { 4837 if(temp) {
4737 SiS_Chrontel701xBLOn(SiS_Pr, HwInfo); 4838 SiS_Chrontel701xBLOn(SiS_Pr);
4738 } 4839 }
4739 } 4840 }
4740 4841
4741 if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { 4842 if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
4742 if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) { 4843 if(SiS_CRT2IsLCD(SiS_Pr)) {
4743 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20); 4844 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
4744 if(HwInfo->jChipType == SIS_550) { 4845 if(SiS_Pr->ChipType == SIS_550) {
4745 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x40); 4846 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x40);
4746 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x10); 4847 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x10);
4747 } 4848 }
4748 } 4849 }
4749 } else if(SiS_IsVAMode(SiS_Pr,HwInfo)) { 4850 } else if(SiS_IsVAMode(SiS_Pr)) {
4750 if(HwInfo->jChipType != SIS_740) { 4851 if(SiS_Pr->ChipType != SIS_740) {
4751 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20); 4852 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
4752 } 4853 }
4753 } 4854 }
4754 4855
4755 if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) { 4856 if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
4756 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f); 4857 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
4757 } 4858 }
4758 4859
4759 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { 4860 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
4760 if(SiS_IsTVOrYPbPrOrScart(SiS_Pr,HwInfo)) { 4861 if(SiS_IsTVOrYPbPrOrScart(SiS_Pr)) {
4761 SiS_Chrontel701xOn(SiS_Pr,HwInfo); 4862 SiS_Chrontel701xOn(SiS_Pr);
4762 } 4863 }
4763 if( (SiS_IsVAMode(SiS_Pr,HwInfo)) || 4864 if( (SiS_IsVAMode(SiS_Pr)) ||
4764 (SiS_IsLCDOrLCDA(SiS_Pr,HwInfo)) ) { 4865 (SiS_IsLCDOrLCDA(SiS_Pr)) ) {
4765 SiS_ChrontelDoSomething1(SiS_Pr,HwInfo); 4866 SiS_ChrontelDoSomething1(SiS_Pr);
4766 } 4867 }
4767 } 4868 }
4768 4869
4769 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { 4870 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
4770 if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) { 4871 if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
4771 if( (SiS_IsVAMode(SiS_Pr,HwInfo)) || 4872 if( (SiS_IsVAMode(SiS_Pr)) ||
4772 (SiS_IsLCDOrLCDA(SiS_Pr,HwInfo)) ) { 4873 (SiS_IsLCDOrLCDA(SiS_Pr)) ) {
4773 SiS_Chrontel701xBLOn(SiS_Pr, HwInfo); 4874 SiS_Chrontel701xBLOn(SiS_Pr);
4774 SiS_ChrontelInitTVVSync(SiS_Pr,HwInfo); 4875 SiS_ChrontelInitTVVSync(SiS_Pr);
4775 } 4876 }
4776 } 4877 }
4777 } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { 4878 } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
4778 if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) { 4879 if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
4779 if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) { 4880 if(SiS_CRT2IsLCD(SiS_Pr)) {
4780 SiS_PanelDelay(SiS_Pr, HwInfo, 1); 4881 SiS_PanelDelay(SiS_Pr, 1);
4781 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x00); 4882 SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
4782 } 4883 }
4783 } 4884 }
4784 } 4885 }
@@ -4797,243 +4898,204 @@ SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
4797 4898
4798/* Set CRT2 OFFSET / PITCH */ 4899/* Set CRT2 OFFSET / PITCH */
4799static void 4900static void
4800SiS_SetCRT2Offset(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 4901SiS_SetCRT2Offset(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
4801 USHORT RRTI, PSIS_HW_INFO HwInfo) 4902 unsigned short RRTI)
4802{ 4903{
4803 USHORT offset; 4904 unsigned short offset;
4804 UCHAR temp; 4905 unsigned char temp;
4805 4906
4806 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) return; 4907 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) return;
4807 4908
4808 offset = SiS_GetOffset(SiS_Pr,ModeNo,ModeIdIndex,RRTI,HwInfo); 4909 offset = SiS_GetOffset(SiS_Pr,ModeNo,ModeIdIndex,RRTI);
4809 4910
4810 if((SiS_Pr->SiS_LCDResInfo == Panel_640x480_2) || 4911 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,(offset & 0xFF));
4811 (SiS_Pr->SiS_LCDResInfo == Panel_640x480_3)) { 4912 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x09,(offset >> 8));
4812 offset >>= 1;
4813 }
4814 4913
4815 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,(offset & 0xFF)); 4914 temp = (unsigned char)(((offset >> 3) & 0xFF) + 1);
4816 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x09,(offset >> 8)); 4915 if(offset & 0x07) temp++;
4817 temp = (UCHAR)(((offset >> 3) & 0xFF) + 1); 4916 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,temp);
4818 if(offset % 8) temp++;
4819 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,temp);
4820} 4917}
4821 4918
4822/* Set CRT2 sync and PanelLink mode */ 4919/* Set CRT2 sync and PanelLink mode */
4823static void 4920static void
4824SiS_SetCRT2Sync(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT RefreshRateTableIndex, 4921SiS_SetCRT2Sync(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short RefreshRateTableIndex)
4825 PSIS_HW_INFO HwInfo)
4826{ 4922{
4827 USHORT tempah=0,tempbl,infoflag; 4923 unsigned short tempah=0, tempbl, infoflag;
4828 4924
4829 tempbl = 0xC0; 4925 tempbl = 0xC0;
4830 4926
4831 if(SiS_Pr->UseCustomMode) { 4927 if(SiS_Pr->UseCustomMode) {
4832 infoflag = SiS_Pr->CInfoFlag; 4928 infoflag = SiS_Pr->CInfoFlag;
4833 } else { 4929 } else {
4834 infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag; 4930 infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
4835 } 4931 }
4836 4932
4837 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { /* LVDS */ 4933 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { /* LVDS */
4838 4934
4839 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 4935 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
4840 tempah = 0; 4936 tempah = 0;
4841 } else if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->SiS_LCDInfo & LCDSync)) { 4937 } else if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->SiS_LCDInfo & LCDSync)) {
4842 tempah = SiS_Pr->SiS_LCDInfo; 4938 tempah = SiS_Pr->SiS_LCDInfo;
4843 } else tempah = infoflag >> 8; 4939 } else tempah = infoflag >> 8;
4844 tempah &= 0xC0; 4940 tempah &= 0xC0;
4845 tempah |= 0x20; 4941 tempah |= 0x20;
4846 if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10; 4942 if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
4847 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 4943 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
4848 if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || 4944 if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
4849 (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) { 4945 (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
4850 tempah |= 0xf0; 4946 tempah |= 0xf0;
4851 } 4947 }
4852 if( (SiS_Pr->SiS_IF_DEF_FSTN) || 4948 if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
4853 (SiS_Pr->SiS_IF_DEF_DSTN) || 4949 (SiS_Pr->SiS_IF_DEF_DSTN) ||
4854 (SiS_Pr->SiS_IF_DEF_TRUMPION) || 4950 (SiS_Pr->SiS_IF_DEF_TRUMPION) ||
4855 (SiS_Pr->SiS_CustomT == CUT_PANEL848) ) { 4951 (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
4856 tempah |= 0x30; 4952 (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
4857 } 4953 tempah |= 0x30;
4858 } 4954 }
4859 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 4955 if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
4860 if(HwInfo->jChipType >= SIS_315H) { 4956 (SiS_Pr->SiS_IF_DEF_DSTN) ) {
4861 tempah >>= 3; 4957 tempah &= ~0xc0;
4862 tempah &= 0x18; 4958 }
4863 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xE7,tempah); 4959 }
4864 /* Don't care about 12/18/24 bit mode - TV is via VGA, not PL */ 4960 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
4865 } else { 4961 if(SiS_Pr->ChipType >= SIS_315H) {
4866 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,0xe0); 4962 tempah >>= 3;
4867 } 4963 tempah &= 0x18;
4868 } else { 4964 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xE7,tempah);
4869 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah); 4965 /* Don't care about 12/18/24 bit mode - TV is via VGA, not PL */
4870 } 4966 } else {
4967 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,0xe0);
4968 }
4969 } else {
4970 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
4971 }
4871 4972
4872 } else if(SiS_Pr->SiS_VBType & VB_SISVB) { 4973 } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
4873 4974
4874 if(HwInfo->jChipType < SIS_315H) { 4975 if(SiS_Pr->ChipType < SIS_315H) {
4875 4976
4876#ifdef SIS300 /* ---- 300 series --- */ 4977#ifdef SIS300 /* ---- 300 series --- */
4877 4978
4878 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { /* 630 - 301B(-DH) */ 4979 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* 630 - 301B(-DH) */
4879 4980
4880 tempah = infoflag >> 8; 4981 tempah = infoflag >> 8;
4881 tempbl = 0; 4982 tempbl = 0;
4882 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 4983 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
4883 if(SiS_Pr->SiS_LCDInfo & LCDSync) { 4984 if(SiS_Pr->SiS_LCDInfo & LCDSync) {
4884 tempah = SiS_Pr->SiS_LCDInfo; 4985 tempah = SiS_Pr->SiS_LCDInfo;
4885 tempbl = (tempah >> 6) & 0x03; 4986 tempbl = (tempah >> 6) & 0x03;
4886 } 4987 }
4887 } 4988 }
4888 tempah &= 0xC0; 4989 tempah &= 0xC0;
4889 tempah |= 0x20; 4990 tempah |= 0x20;
4890 if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10; 4991 if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
4891 tempah |= 0xc0; 4992 tempah |= 0xc0;
4892 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah); 4993 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
4893 if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) { 4994 if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
4894 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl); 4995 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
4895 } 4996 }
4896 4997
4897 } else { /* 630 - 301 */ 4998 } else { /* 630 - 301 */
4898 4999
4899 tempah = infoflag >> 8; 5000 tempah = ((infoflag >> 8) & 0xc0) | 0x20;
4900 tempah &= 0xC0; 5001 if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
4901 tempah |= 0x20; 5002 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
4902 if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
4903 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
4904 5003
4905 } 5004 }
4906 5005
4907#endif /* SIS300 */ 5006#endif /* SIS300 */
4908 5007
4909 } else { 5008 } else {
4910 5009
4911#ifdef SIS315H /* ------- 315 series ------ */ 5010#ifdef SIS315H /* ------- 315 series ------ */
4912 5011
4913 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { /* 315 - LVDS */ 5012 if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* 315 - LVDS */
4914 5013
4915 tempbl = 0; 5014 tempbl = 0;
4916 if((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) && 5015 if((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) &&
4917 (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) { 5016 (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
4918 tempah = infoflag >> 8; 5017 tempah = infoflag >> 8;
4919 if(SiS_Pr->SiS_LCDInfo & LCDSync) { 5018 if(SiS_Pr->SiS_LCDInfo & LCDSync) {
4920 tempbl = ((SiS_Pr->SiS_LCDInfo & 0xc0) >> 6); 5019 tempbl = ((SiS_Pr->SiS_LCDInfo & 0xc0) >> 6);
4921 } 5020 }
4922 } else if((SiS_Pr->SiS_CustomT == CUT_CLEVO1400) && 5021 } else if((SiS_Pr->SiS_CustomT == CUT_CLEVO1400) &&
4923 (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050)) { 5022 (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050)) {
4924 tempah = infoflag >> 8; 5023 tempah = infoflag >> 8;
4925 tempbl = 0x03; 5024 tempbl = 0x03;
4926 } else { 5025 } else {
4927 tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37); 5026 tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
4928 tempbl = (tempah >> 6) & 0x03; 5027 tempbl = (tempah >> 6) & 0x03;
4929 tempbl |= 0x08; 5028 tempbl |= 0x08;
4930 if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempbl |= 0x04; 5029 if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempbl |= 0x04;
4931 } 5030 }
4932 tempah &= 0xC0; 5031 tempah &= 0xC0;
4933 tempah |= 0x20; 5032 tempah |= 0x20;
4934 if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10; 5033 if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
4935 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) tempah |= 0xc0; 5034 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) tempah |= 0xc0;
4936 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah); 5035 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
4937 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 5036 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
4938 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 5037 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
4939 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl); 5038 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
4940 } 5039 }
4941 } 5040 }
4942 5041
4943 } else { /* 315 - TMDS */ 5042 } else { /* 315 - TMDS */
4944 5043
4945 tempah = tempbl = infoflag >> 8; 5044 tempah = tempbl = infoflag >> 8;
4946 if(!SiS_Pr->UseCustomMode) { 5045 if(!SiS_Pr->UseCustomMode) {
4947 tempbl = 0; 5046 tempbl = 0;
4948 if((SiS_Pr->SiS_VBType & VB_SIS301C) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) { 5047 if((SiS_Pr->SiS_VBType & VB_SIS30xC) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
4949 if(ModeNo <= 0x13) { 5048 if(ModeNo <= 0x13) {
4950 tempah = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02)); 5049 tempah = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
4951 } 5050 }
4952 } 5051 }
4953 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { 5052 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
4954 if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { 5053 if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
4955 if(SiS_Pr->SiS_LCDInfo & LCDSync) { 5054 if(SiS_Pr->SiS_LCDInfo & LCDSync) {
4956 tempah = SiS_Pr->SiS_LCDInfo; 5055 tempah = SiS_Pr->SiS_LCDInfo;
4957 tempbl = (tempah >> 6) & 0x03; 5056 tempbl = (tempah >> 6) & 0x03;
4958 } 5057 }
4959 } 5058 }
4960 } 5059 }
4961 } 5060 }
4962 tempah &= 0xC0; 5061 tempah &= 0xC0;
4963 tempah |= 0x20; 5062 tempah |= 0x20;
4964 if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10; 5063 if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
4965 if(SiS_Pr->SiS_VBType & VB_NoLCD) { 5064 if(SiS_Pr->SiS_VBType & VB_NoLCD) {
4966 /* Imitate BIOS bug */ 5065 /* Imitate BIOS bug */
4967 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah |= 0xc0; 5066 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah |= 0xc0;
4968 } 5067 }
4969 if((SiS_Pr->SiS_VBType & VB_SIS301C) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) { 5068 if((SiS_Pr->SiS_VBType & VB_SIS30xC) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
4970 tempah >>= 3; 5069 tempah >>= 3;
4971 tempah &= 0x18; 5070 tempah &= 0x18;
4972 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xe7,tempah); 5071 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xe7,tempah);
4973 } else { 5072 } else {
4974 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah); 5073 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
4975 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 5074 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
4976 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 5075 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
4977 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl); 5076 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
4978 } 5077 }
4979 } 5078 }
4980 } 5079 }
4981 5080
4982 } 5081 }
4983#endif /* SIS315H */ 5082#endif /* SIS315H */
4984 } 5083 }
4985 } 5084 }
4986} 5085}
4987 5086
4988/* Set CRT2 FIFO on 300/630/730 */ 5087/* Set CRT2 FIFO on 300/540/630/730 */
4989#ifdef SIS300 5088#ifdef SIS300
4990static void 5089static void
4991SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr,USHORT ModeNo, 5090SiS_SetCRT2FIFO_300(struct SiS_Private *SiS_Pr,unsigned short ModeNo)
4992 PSIS_HW_INFO HwInfo) 5091{
4993{ 5092 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
4994 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 5093 unsigned short temp, index, modeidindex, refreshratetableindex;
4995 USHORT temp,index; 5094 unsigned short VCLK = 0, MCLK, colorth = 0, data2 = 0;
4996 USHORT modeidindex,refreshratetableindex; 5095 unsigned short tempbx, tempcl, CRT1ModeNo, CRT2ModeNo, SelectRate_backup;
4997 USHORT VCLK=0,MCLK,colorth=0,data2=0; 5096 unsigned int data, pci50, pciA0;
4998 USHORT tempal, tempah, tempbx, tempcl, tempax; 5097 static const unsigned char colortharray[] = {
4999 USHORT CRT1ModeNo,CRT2ModeNo; 5098 1, 1, 2, 2, 3, 4
5000 USHORT SelectRate_backup;
5001 ULONG data,eax;
5002 const UCHAR LatencyFactor[] = {
5003 97, 88, 86, 79, 77, 00, /*; 64 bit BQ=2 */
5004 00, 87, 85, 78, 76, 54, /*; 64 bit BQ=1 */
5005 97, 88, 86, 79, 77, 00, /*; 128 bit BQ=2 */
5006 00, 79, 77, 70, 68, 48, /*; 128 bit BQ=1 */
5007 80, 72, 69, 63, 61, 00, /*; 64 bit BQ=2 */
5008 00, 70, 68, 61, 59, 37, /*; 64 bit BQ=1 */
5009 86, 77, 75, 68, 66, 00, /*; 128 bit BQ=2 */
5010 00, 68, 66, 59, 57, 37 /*; 128 bit BQ=1 */
5011 };
5012 const UCHAR LatencyFactor730[] = {
5013 69, 63, 61,
5014 86, 79, 77,
5015 103, 96, 94,
5016 120,113,111,
5017 137,130,128, /* <-- last entry, data below */
5018 137,130,128, /* to avoid using illegal values */
5019 137,130,128,
5020 137,130,128,
5021 137,130,128,
5022 137,130,128,
5023 137,130,128,
5024 137,130,128,
5025 137,130,128,
5026 137,130,128,
5027 137,130,128,
5028 137,130,128,
5029 };
5030 const UCHAR ThLowB[] = {
5031 81, 4, 72, 6, 88, 8,120,12,
5032 55, 4, 54, 6, 66, 8, 90,12,
5033 42, 4, 45, 6, 55, 8, 75,12
5034 };
5035 const UCHAR ThTiming[] = {
5036 1, 2, 2, 3, 0, 1, 1, 2
5037 }; 5099 };
5038 5100
5039 SelectRate_backup = SiS_Pr->SiS_SelectCRT2Rate; 5101 SelectRate_backup = SiS_Pr->SiS_SelectCRT2Rate;
@@ -5044,232 +5106,159 @@ SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr,USHORT ModeNo,
5044 SiS_SearchModeID(SiS_Pr, &CRT1ModeNo, &modeidindex); 5106 SiS_SearchModeID(SiS_Pr, &CRT1ModeNo, &modeidindex);
5045 SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2); 5107 SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
5046 SiS_Pr->SiS_SelectCRT2Rate = 0; 5108 SiS_Pr->SiS_SelectCRT2Rate = 0;
5047 refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT1ModeNo, modeidindex, HwInfo); 5109 refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT1ModeNo, modeidindex);
5048 5110
5049 if(CRT1ModeNo >= 0x13) { 5111 if(CRT1ModeNo >= 0x13) {
5050 index = SiS_Pr->SiS_RefIndex[refreshratetableindex].Ext_CRTVCLK; 5112 /* Get VCLK */
5051 index &= 0x3F; 5113 index = SiS_GetRefCRTVCLK(SiS_Pr, refreshratetableindex, SiS_Pr->SiS_UseWide);
5052 VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK; /* Get VCLK */ 5114 VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
5053 5115
5054 colorth = SiS_GetColorDepth(SiS_Pr,CRT1ModeNo,modeidindex); /* Get colordepth */ 5116 /* Get colordepth */
5055 colorth >>= 1; 5117 colorth = SiS_GetColorDepth(SiS_Pr,CRT1ModeNo,modeidindex) >> 1;
5056 if(!colorth) colorth++; 5118 if(!colorth) colorth++;
5057 } 5119 }
5058 5120
5059 } else { 5121 } else {
5060 5122
5061 CRT1ModeNo = 0xfe; 5123 CRT1ModeNo = 0xfe;
5062 VCLK = SiS_Pr->CSRClock_CRT1; /* Get VCLK */ 5124
5063 data2 = (SiS_Pr->CModeFlag_CRT1 & ModeTypeMask) - 2; 5125 /* Get VCLK */
5064 switch(data2) { /* Get color depth */ 5126 VCLK = SiS_Pr->CSRClock_CRT1;
5065 case 0 : colorth = 1; break; 5127
5066 case 1 : colorth = 1; break; 5128 /* Get color depth */
5067 case 2 : colorth = 2; break; 5129 colorth = colortharray[((SiS_Pr->CModeFlag_CRT1 & ModeTypeMask) - 2)];
5068 case 3 : colorth = 2; break;
5069 case 4 : colorth = 3; break;
5070 case 5 : colorth = 4; break;
5071 default: colorth = 2;
5072 }
5073 5130
5074 } 5131 }
5075 5132
5076 if(CRT1ModeNo >= 0x13) { 5133 if(CRT1ModeNo >= 0x13) {
5077 if(HwInfo->jChipType == SIS_300) { 5134 /* Get MCLK */
5078 index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3A); 5135 if(SiS_Pr->ChipType == SIS_300) {
5079 } else { 5136 index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3A);
5080 index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1A); 5137 } else {
5081 } 5138 index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1A);
5082 index &= 0x07; 5139 }
5083 MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK; /* Get MCLK */ 5140 index &= 0x07;
5141 MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK;
5084 5142
5085 data2 = (colorth * VCLK) / MCLK; 5143 temp = ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) >> 6) & 0x03) << 1;
5144 if(!temp) temp++;
5145 temp <<= 2;
5086 5146
5087 temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x14); 5147 data2 = temp - ((colorth * VCLK) / MCLK);
5088 temp = ((temp & 0x00FF) >> 6) << 1;
5089 if(temp == 0) temp = 1;
5090 temp <<= 2;
5091 temp &= 0xff;
5092 5148
5093 data2 = temp - data2; 5149 temp = (28 * 16) % data2;
5150 data2 = (28 * 16) / data2;
5151 if(temp) data2++;
5094 5152
5095 if((28 * 16) % data2) { 5153 if(SiS_Pr->ChipType == SIS_300) {
5096 data2 = (28 * 16) / data2;
5097 data2++;
5098 } else {
5099 data2 = (28 * 16) / data2;
5100 }
5101 5154
5102 if(HwInfo->jChipType == SIS_300) { 5155 SiS_GetFIFOThresholdIndex300(SiS_Pr, &tempbx, &tempcl);
5103 5156 data = SiS_GetFIFOThresholdB300(tempbx, tempcl);
5104 tempah = SiS_GetReg(SiS_Pr->SiS_P3c4,0x18); 5157
5105 tempah &= 0x62; 5158 } else {
5106 tempah >>= 1; 5159
5107 tempal = tempah; 5160#ifdef SIS_LINUX_KERNEL
5108 tempah >>= 3; 5161 pci50 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50);
5109 tempal |= tempah; 5162 pciA0 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xa0);
5110 tempal &= 0x07;
5111 tempcl = ThTiming[tempal];
5112 tempbx = SiS_GetReg(SiS_Pr->SiS_P3c4,0x16);
5113 tempbx >>= 6;
5114 tempah = SiS_GetReg(SiS_Pr->SiS_P3c4,0x14);
5115 tempah >>= 4;
5116 tempah &= 0x0c;
5117 tempbx |= tempah;
5118 tempbx <<= 1;
5119 tempal = ThLowB[tempbx + 1];
5120 tempal *= tempcl;
5121 tempal += ThLowB[tempbx];
5122 data = tempal;
5123
5124 } else if(HwInfo->jChipType == SIS_730) {
5125
5126#ifdef LINUX_KERNEL
5127 SiS_SetRegLong(0xcf8,0x80000050);
5128 eax = SiS_GetRegLong(0xcfc);
5129#else 5163#else
5130 eax = pciReadLong(0x00000000, 0x50); 5164 pci50 = pciReadLong(0x00000000, 0x50);
5165 pciA0 = pciReadLong(0x00000000, 0xA0);
5131#endif 5166#endif
5132 tempal = (USHORT)(eax >> 8);
5133 tempal &= 0x06;
5134 tempal <<= 5;
5135 5167
5136#ifdef LINUX_KERNEL 5168 if(SiS_Pr->ChipType == SIS_730) {
5137 SiS_SetRegLong(0xcf8,0x800000A0);
5138 eax = SiS_GetRegLong(0xcfc);
5139#else
5140 eax = pciReadLong(0x00000000, 0xA0);
5141#endif
5142 temp = (USHORT)(eax >> 28);
5143 temp &= 0x0F;
5144 tempal |= temp;
5145
5146 tempbx = tempal; /* BIOS BUG (2.04.5d, 2.04.6a use ah here, which is unset!) */
5147 tempbx = 0; /* -- do it like the BIOS anyway... */
5148 tempax = tempbx;
5149 tempbx &= 0xc0;
5150 tempbx >>= 6;
5151 tempax &= 0x0f;
5152 tempax *= 3;
5153 tempbx += tempax;
5154
5155 data = LatencyFactor730[tempbx];
5156 data += 15;
5157 temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x14);
5158 if(!(temp & 0x80)) data += 5;
5159 5169
5160 } else { 5170 index = (unsigned short)(((pciA0 >> 28) & 0x0f) * 3);
5171 index += (unsigned short)(((pci50 >> 9)) & 0x03);
5161 5172
5162 index = 0; 5173 /* BIOS BUG (2.04.5d, 2.04.6a use ah here, which is unset!) */
5163 temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x14); 5174 index = 0; /* -- do it like the BIOS anyway... */
5164 if(temp & 0x0080) index += 12;
5165 5175
5166#ifdef LINUX_KERNEL 5176 } else {
5167 SiS_SetRegLong(0xcf8,0x800000A0);
5168 eax = SiS_GetRegLong(0xcfc);
5169#else
5170 /* We use pci functions X offers. We use tag 0, because
5171 * we want to read/write to the host bridge (which is always
5172 * 00:00.0 on 630, 730 and 540), not the VGA device.
5173 */
5174 eax = pciReadLong(0x00000000, 0xA0);
5175#endif
5176 temp = (USHORT)(eax >> 24);
5177 if(!(temp&0x01)) index += 24;
5178
5179#ifdef LINUX_KERNEL
5180 SiS_SetRegLong(0xcf8,0x80000050);
5181 eax = SiS_GetRegLong(0xcfc);
5182#else
5183 eax = pciReadLong(0x00000000, 0x50);
5184#endif
5185 temp=(USHORT)(eax >> 24);
5186 if(temp & 0x01) index += 6;
5187 5177
5188 temp = (temp & 0x0F) >> 1; 5178 pci50 >>= 24;
5189 index += temp; 5179 pciA0 >>= 24;
5190 5180
5191 data = LatencyFactor[index]; 5181 index = (pci50 >> 1) & 0x07;
5192 data += 15;
5193 temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x14);
5194 if(!(temp & 0x80)) data += 5;
5195 }
5196 5182
5197 data += data2; /* CRT1 Request Period */ 5183 if(pci50 & 0x01) index += 6;
5184 if(!(pciA0 & 0x01)) index += 24;
5198 5185
5199 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2; 5186 if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80) index += 12;
5200 SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup;
5201 5187
5202 if(!SiS_Pr->UseCustomMode) { 5188 }
5203 5189
5204 CRT2ModeNo = ModeNo; 5190 data = SiS_GetLatencyFactor630(SiS_Pr, index) + 15;
5205 SiS_SearchModeID(SiS_Pr, &CRT2ModeNo, &modeidindex); 5191 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80)) data += 5;
5206 5192
5207 refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT2ModeNo, modeidindex, HwInfo); 5193 }
5208 5194
5209 index = SiS_GetVCLK2Ptr(SiS_Pr,CRT2ModeNo,modeidindex, 5195 data += data2; /* CRT1 Request Period */
5210 refreshratetableindex,HwInfo);
5211 VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK; /* Get VCLK */
5212 5196
5213 if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) { 5197 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
5214 if(SiS_Pr->SiS_UseROM) { 5198 SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup;
5215 if(ROMAddr[0x220] & 0x01) {
5216 VCLK = ROMAddr[0x229] | (ROMAddr[0x22a] << 8);
5217 }
5218 }
5219 }
5220 5199
5221 } else { 5200 if(!SiS_Pr->UseCustomMode) {
5222 5201
5223 CRT2ModeNo = 0xfe; 5202 CRT2ModeNo = ModeNo;
5224 VCLK = SiS_Pr->CSRClock; /* Get VCLK */ 5203 SiS_SearchModeID(SiS_Pr, &CRT2ModeNo, &modeidindex);
5225 5204
5226 } 5205 refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT2ModeNo, modeidindex);
5227 5206
5228 colorth = SiS_GetColorDepth(SiS_Pr,CRT2ModeNo,modeidindex); /* Get colordepth */ 5207 /* Get VCLK */
5229 colorth >>= 1; 5208 index = SiS_GetVCLK2Ptr(SiS_Pr, CRT2ModeNo, modeidindex, refreshratetableindex);
5230 if(!colorth) colorth++; 5209 VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
5231 5210
5232 data = data * VCLK * colorth; 5211 if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
5233 if(data % (MCLK << 4)) { 5212 if(SiS_Pr->SiS_UseROM) {
5234 data = data / (MCLK << 4); 5213 if(ROMAddr[0x220] & 0x01) {
5235 data++; 5214 VCLK = ROMAddr[0x229] | (ROMAddr[0x22a] << 8);
5236 } else { 5215 }
5237 data = data / (MCLK << 4); 5216 }
5238 } 5217 }
5239 5218
5240 if(data <= 6) data = 6; 5219 } else {
5241 if(data > 0x14) data = 0x14;
5242 5220
5243 temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x01); 5221 /* Get VCLK */
5244 if(HwInfo->jChipType == SIS_300) { 5222 CRT2ModeNo = 0xfe;
5245 if(data <= 0x0f) temp = (temp & (~0x1F)) | 0x13; 5223 VCLK = SiS_Pr->CSRClock;
5246 else temp = (temp & (~0x1F)) | 0x16;
5247 if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
5248 temp = (temp & (~0x1F)) | 0x13;
5249 }
5250 } else {
5251 if( ( (HwInfo->jChipType == SIS_630) ||
5252 (HwInfo->jChipType == SIS_730) ) &&
5253 (HwInfo->jChipRevision >= 0x30) ) /* 630s or 730(s?) */
5254 {
5255 temp = (temp & (~0x1F)) | 0x1b;
5256 } else {
5257 temp = (temp & (~0x1F)) | 0x16;
5258 }
5259 }
5260 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0xe0,temp);
5261 5224
5262 if( (HwInfo->jChipType == SIS_630) && 5225 }
5263 (HwInfo->jChipRevision >= 0x30) ) /* 630s, NOT 730 */ 5226
5264 { 5227 /* Get colordepth */
5265 if(data > 0x13) data = 0x13; 5228 colorth = SiS_GetColorDepth(SiS_Pr,CRT2ModeNo,modeidindex) >> 1;
5266 } 5229 if(!colorth) colorth++;
5267 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,0xe0,data); 5230
5231 data = data * VCLK * colorth;
5232 temp = data % (MCLK << 4);
5233 data = data / (MCLK << 4);
5234 if(temp) data++;
5235
5236 if(data < 6) data = 6;
5237 else if(data > 0x14) data = 0x14;
5238
5239 if(SiS_Pr->ChipType == SIS_300) {
5240 temp = 0x16;
5241 if((data <= 0x0f) || (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024))
5242 temp = 0x13;
5243 } else {
5244 temp = 0x16;
5245 if(( (SiS_Pr->ChipType == SIS_630) ||
5246 (SiS_Pr->ChipType == SIS_730) ) &&
5247 (SiS_Pr->ChipRevision >= 0x30))
5248 temp = 0x1b;
5249 }
5250 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0xe0,temp);
5251
5252 if((SiS_Pr->ChipType == SIS_630) &&
5253 (SiS_Pr->ChipRevision >= 0x30)) {
5254 if(data > 0x13) data = 0x13;
5255 }
5256 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,0xe0,data);
5268 5257
5269 } else { /* If mode <= 0x13, we just restore everything */ 5258 } else { /* If mode <= 0x13, we just restore everything */
5270 5259
5271 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2; 5260 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
5272 SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup; 5261 SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup;
5273 5262
5274 } 5263 }
5275} 5264}
@@ -5278,10 +5267,10 @@ SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr,USHORT ModeNo,
5278/* Set CRT2 FIFO on 315/330 series */ 5267/* Set CRT2 FIFO on 315/330 series */
5279#ifdef SIS315H 5268#ifdef SIS315H
5280static void 5269static void
5281SiS_SetCRT2FIFO_310(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 5270SiS_SetCRT2FIFO_310(struct SiS_Private *SiS_Pr)
5282{ 5271{
5283 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3B); 5272 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3B);
5284 if( (HwInfo->jChipType == SIS_760) && 5273 if( (SiS_Pr->ChipType == SIS_760) &&
5285 (SiS_Pr->SiS_SysFlags & SF_760LFB) && 5274 (SiS_Pr->SiS_SysFlags & SF_760LFB) &&
5286 (SiS_Pr->SiS_ModeType == Mode32Bpp) && 5275 (SiS_Pr->SiS_ModeType == Mode32Bpp) &&
5287 (SiS_Pr->SiS_VGAHDE >= 1280) && 5276 (SiS_Pr->SiS_VGAHDE >= 1280) &&
@@ -5299,337 +5288,162 @@ SiS_SetCRT2FIFO_310(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
5299} 5288}
5300#endif 5289#endif
5301 5290
5302static USHORT 5291static unsigned short
5303SiS_GetVGAHT2(SiS_Private *SiS_Pr) 5292SiS_GetVGAHT2(struct SiS_Private *SiS_Pr)
5304{ 5293{
5305 ULONG tempax,tempbx; 5294 unsigned int tempax,tempbx;
5306 5295
5307 tempbx = (SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) * SiS_Pr->SiS_RVBHCMAX; 5296 tempbx = (SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) * SiS_Pr->SiS_RVBHCMAX;
5308 tempax = (SiS_Pr->SiS_VT - SiS_Pr->SiS_VDE) * SiS_Pr->SiS_RVBHCFACT; 5297 tempax = (SiS_Pr->SiS_VT - SiS_Pr->SiS_VDE) * SiS_Pr->SiS_RVBHCFACT;
5309 tempax = (tempax * SiS_Pr->SiS_HT) / tempbx; 5298 tempax = (tempax * SiS_Pr->SiS_HT) / tempbx;
5310 return((USHORT)tempax); 5299 return (unsigned short)tempax;
5311} 5300}
5312 5301
5313/* Set Part 1 / SiS bridge slave mode */ 5302/* Set Part 1 / SiS bridge slave mode */
5314static void 5303static void
5315SiS_SetGroup1_301(SiS_Private *SiS_Pr, USHORT ModeNo,USHORT ModeIdIndex, 5304SiS_SetGroup1_301(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex,
5316 PSIS_HW_INFO HwInfo,USHORT RefreshRateTableIndex) 5305 unsigned short RefreshRateTableIndex)
5317{ 5306{
5318 USHORT push1,push2; 5307 unsigned short temp, modeflag, i, j, xres=0, VGAVDE;
5319 USHORT tempax,tempbx,tempcx,temp; 5308 static const unsigned short CRTranslation[] = {
5320 USHORT resinfo,modeflag,xres=0; 5309 /* CR0 CR1 CR2 CR3 CR4 CR5 CR6 CR7 */
5321 unsigned char p1_7, p1_8; 5310 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
5311 /* CR8 CR9 SR0A SR0B SR0C SR0D SR0E CR0F */
5312 0x00, 0x0b, 0x17, 0x18, 0x19, 0x00, 0x1a, 0x00,
5313 /* CR10 CR11 CR12 CR13 CR14 CR15 CR16 CR17 */
5314 0x0c, 0x0d, 0x0e, 0x00, 0x0f, 0x10, 0x11, 0x00
5315 };
5322 5316
5323 if(ModeNo <= 0x13) { 5317 if(ModeNo <= 0x13) {
5324 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; 5318 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
5325 resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
5326 } else if(SiS_Pr->UseCustomMode) { 5319 } else if(SiS_Pr->UseCustomMode) {
5327 modeflag = SiS_Pr->CModeFlag; 5320 modeflag = SiS_Pr->CModeFlag;
5328 resinfo = 0;
5329 xres = SiS_Pr->CHDisplay; 5321 xres = SiS_Pr->CHDisplay;
5330 } else { 5322 } else {
5331 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 5323 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5332 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
5333 xres = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].XRes; 5324 xres = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].XRes;
5334 } 5325 }
5335 5326
5336 /* The following is only done if bridge is in slave mode: */ 5327 /* The following is only done if bridge is in slave mode: */
5337 5328
5338 if((HwInfo->jChipType >= SIS_661) && (ModeNo > 0x13)) { 5329 if(SiS_Pr->ChipType >= SIS_315H) {
5339 if(xres >= 1600) { 5330 if(xres >= 1600) { /* BIOS: == 1600 */
5340 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x31,0x04); 5331 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x31,0x04);
5341 } 5332 }
5342 } 5333 }
5343 5334
5344 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,0xff); /* set MAX HT */ 5335 SiS_Pr->CHTotal = 8224; /* Max HT, 0x2020, results in 0x3ff in registers */
5345
5346 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) modeflag |= Charx8Dot;
5347 5336
5348 if(modeflag & Charx8Dot) tempcx = 0x08; 5337 SiS_Pr->CHDisplay = SiS_Pr->SiS_VGAHDE;
5349 else tempcx = 0x09; 5338 if(modeflag & HalfDCLK) SiS_Pr->CHDisplay >>= 1;
5350
5351 tempax = SiS_Pr->SiS_VGAHDE; /* 0x04 Horizontal Display End */
5352 if(modeflag & HalfDCLK) tempax >>= 1;
5353 tempax = ((tempax / tempcx) - 1) & 0xff;
5354 tempbx = tempax;
5355
5356 temp = tempax;
5357 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x04,temp);
5358 5339
5340 SiS_Pr->CHBlankStart = SiS_Pr->CHDisplay;
5359 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 5341 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
5360 if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) { 5342 SiS_Pr->CHBlankStart += 16;
5361 temp += 2;
5362 }
5363 }
5364 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
5365 if(resinfo == SIS_RI_800x600) temp -= 2;
5366 }
5367 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x05,temp); /* 0x05 Horizontal Display Start */
5368
5369 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x06,0x03); /* 0x06 Horizontal Blank end */
5370
5371 tempax = 0xFFFF;
5372 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempax = SiS_GetVGAHT2(SiS_Pr);
5373 if(tempax >= SiS_Pr->SiS_VGAHT) tempax = SiS_Pr->SiS_VGAHT;
5374 if(modeflag & HalfDCLK) tempax >>= 1;
5375 tempax = (tempax / tempcx) - 5;
5376 tempcx = tempax;
5377
5378 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
5379 temp = tempcx - 1;
5380 if(!(modeflag & HalfDCLK)) {
5381 temp -= 6;
5382 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
5383 temp -= 2;
5384 if(ModeNo > 0x13) temp -= 10;
5385 }
5386 }
5387 } else {
5388 tempcx = (tempcx + tempbx) >> 1;
5389 temp = (tempcx & 0x00FF) + 2;
5390 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
5391 temp--;
5392 if(!(modeflag & HalfDCLK)) {
5393 if((modeflag & Charx8Dot)) {
5394 temp += 4;
5395 if(SiS_Pr->SiS_VGAHDE >= 800) temp -= 6;
5396 if(HwInfo->jChipType >= SIS_315H) {
5397 if(SiS_Pr->SiS_VGAHDE == 800) temp += 2;
5398 }
5399 }
5400 }
5401 } else {
5402 if(!(modeflag & HalfDCLK)) {
5403 temp -= 4;
5404 if((SiS_Pr->SiS_LCDResInfo != Panel_1280x960) &&
5405 (SiS_Pr->SiS_LCDResInfo != Panel_1600x1200)) {
5406 if(SiS_Pr->SiS_VGAHDE >= 800) {
5407 temp -= 7;
5408 if(HwInfo->jChipType < SIS_315H) {
5409 if(SiS_Pr->SiS_ModeType == ModeEGA) {
5410 if(SiS_Pr->SiS_VGAVDE == 1024) {
5411 temp += 15;
5412 if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024)
5413 temp += 7;
5414 }
5415 }
5416 }
5417 if(SiS_Pr->SiS_LCDResInfo != Panel_1400x1050) {
5418 if(SiS_Pr->SiS_VGAHDE >= 1280) {
5419 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) temp += 28;
5420 }
5421 }
5422 }
5423 }
5424 }
5425 }
5426 } 5343 }
5427 5344
5428 p1_7 = temp; 5345 SiS_Pr->CHBlankEnd = 32;
5429 p1_8 = 0x00; 5346 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
5430 5347 if(xres == 1600) SiS_Pr->CHBlankEnd += 80;
5431 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
5432 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
5433 if(ModeNo <= 0x01) {
5434 p1_7 = 0x2a;
5435 if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) p1_8 = 0x61;
5436 else p1_8 = 0x41;
5437 } else if(SiS_Pr->SiS_ModeType == ModeText) {
5438 if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) p1_7 = 0x54;
5439 else p1_7 = 0x55;
5440 p1_8 = 0x00;
5441 } else if(ModeNo <= 0x13) {
5442 if(modeflag & HalfDCLK) {
5443 if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
5444 p1_7 = 0x30;
5445 p1_8 = 0x03;
5446 } else {
5447 p1_7 = 0x2f;
5448 p1_8 = 0x02;
5449 }
5450 } else {
5451 p1_7 = 0x5b;
5452 p1_8 = 0x03;
5453 }
5454 } else if( ((HwInfo->jChipType >= SIS_315H) &&
5455 ((ModeNo == 0x50) || (ModeNo == 0x56) || (ModeNo == 0x53))) ||
5456 ((HwInfo->jChipType < SIS_315H) &&
5457 (resinfo == SIS_RI_320x200 || resinfo == SIS_RI_320x240)) ) {
5458 if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
5459 p1_7 = 0x30,
5460 p1_8 = 0x03;
5461 } else {
5462 p1_7 = 0x2f;
5463 p1_8 = 0x03;
5464 }
5465 }
5466 }
5467 } 5348 }
5468 5349
5469 if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { 5350 temp = SiS_Pr->SiS_VGAHT - 96;
5470 if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p|TVSetYPbPr750p)) { 5351 if(!(modeflag & HalfDCLK)) temp -= 32;
5471 p1_7 = 0x63; 5352 if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
5472 if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) p1_7 = 0x55; 5353 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x04);
5473 } 5354 temp |= ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0xc0) << 2);
5474 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) { 5355 temp -= 3;
5475 if(!(modeflag & HalfDCLK)) { 5356 temp <<= 3;
5476 p1_7 = 0xb2; 5357 } else {
5477 if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) { 5358 if(SiS_Pr->SiS_RVBHRS2) temp = SiS_Pr->SiS_RVBHRS2;
5478 p1_7 = 0xab;
5479 }
5480 }
5481 } else {
5482 if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
5483 if(modeflag & HalfDCLK) p1_7 = 0x30;
5484 }
5485 }
5486 } 5359 }
5360 SiS_Pr->CHSyncStart = temp;
5487 5361
5488 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,p1_7); /* 0x07 Horizontal Retrace Start */ 5362 SiS_Pr->CHSyncEnd = 0xffe8; /* results in 0x2000 in registers */
5489 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,p1_8); /* 0x08 Horizontal Retrace End */
5490 5363
5491 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x03); /* 0x18 SR08 (FIFO Threshold?) */ 5364 SiS_Pr->CVTotal = 2049; /* Max VT, 0x0801, results in 0x7ff in registers */
5492 5365
5493 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x19,0xF0); 5366 VGAVDE = SiS_Pr->SiS_VGAVDE;
5367 if (VGAVDE == 357) VGAVDE = 350;
5368 else if(VGAVDE == 360) VGAVDE = 350;
5369 else if(VGAVDE == 375) VGAVDE = 350;
5370 else if(VGAVDE == 405) VGAVDE = 400;
5371 else if(VGAVDE == 420) VGAVDE = 400;
5372 else if(VGAVDE == 525) VGAVDE = 480;
5373 else if(VGAVDE == 1056) VGAVDE = 1024;
5374 SiS_Pr->CVDisplay = VGAVDE;
5494 5375
5495 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x09,0xFF); /* 0x09 Set Max VT */ 5376 SiS_Pr->CVBlankStart = SiS_Pr->CVDisplay;
5496 5377
5497 tempcx = 0x121; 5378 SiS_Pr->CVBlankEnd = 1;
5498 tempbx = SiS_Pr->SiS_VGAVDE; /* 0x0E Vertical Display End */ 5379 if(ModeNo == 0x3c) SiS_Pr->CVBlankEnd = 226;
5499 if (tempbx == 357) tempbx = 350;
5500 else if(tempbx == 360) tempbx = 350;
5501 else if(tempbx == 375) tempbx = 350;
5502 else if(tempbx == 405) tempbx = 400;
5503 else if(tempbx == 420) tempbx = 400;
5504 else if(tempbx == 525) tempbx = 480;
5505 push2 = tempbx;
5506 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
5507 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
5508 if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
5509 if (tempbx == 350) tempbx += 5;
5510 else if(tempbx == 480) tempbx += 5;
5511 }
5512 }
5513 }
5514 tempbx -= 2;
5515 temp = tempbx & 0x00FF;
5516 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x10,temp); /* 0x10 vertical Blank Start */
5517
5518 tempbx = push2;
5519 tempbx--;
5520 temp = tempbx & 0x00FF;
5521#if 0
5522 /* Missing code from 630/301B 2.04.5a and 650/302LV 1.10.6s (calles int 2f) */
5523 if(xxx()) {
5524 if(temp == 0xdf) temp = 0xda;
5525 }
5526#endif
5527 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0E,temp);
5528
5529 temp = 0;
5530 if(modeflag & DoubleScanMode) temp |= 0x80;
5531 if(HwInfo->jChipType >= SIS_661) {
5532 if(tempbx & 0x0200) temp |= 0x20;
5533 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x0B,0x5F,temp);
5534 if(tempbx & 0x0100) tempcx |= 0x000a;
5535 if(tempbx & 0x0400) tempcx |= 0x1200;
5536 } else {
5537 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0B,temp);
5538 if(tempbx & 0x0100) tempcx |= 0x0002;
5539 if(tempbx & 0x0400) tempcx |= 0x0600;
5540 }
5541 5380
5542 if(tempbx & 0x0200) tempcx |= 0x0040; 5381 temp = (SiS_Pr->SiS_VGAVT - VGAVDE) >> 1;
5382 SiS_Pr->CVSyncStart = VGAVDE + temp;
5543 5383
5544 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x11,0x00); /* 0x11 Vertical Blank End */ 5384 temp >>= 3;
5385 SiS_Pr->CVSyncEnd = SiS_Pr->CVSyncStart + temp;
5545 5386
5546 tempax = (SiS_Pr->SiS_VGAVT - tempbx) >> 2; 5387 SiS_CalcCRRegisters(SiS_Pr, 0);
5388 SiS_Pr->CCRT1CRTC[16] &= ~0xE0;
5547 5389
5548 if((ModeNo > 0x13) || (HwInfo->jChipType < SIS_315H)) { 5390 for(i = 0; i <= 7; i++) {
5549 if(resinfo != SIS_RI_1280x1024) { 5391 SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[i]);
5550 tempbx += (tempax << 1);
5551 }
5552 } else if(HwInfo->jChipType >= SIS_315H) {
5553 if(SiS_Pr->SiS_LCDResInfo != Panel_1400x1050) {
5554 tempbx += (tempax << 1);
5555 }
5556 } 5392 }
5557 5393 for(i = 0x10, j = 8; i <= 0x12; i++, j++) {
5558 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { 5394 SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
5559 tempbx -= 10;
5560 } else {
5561 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
5562 if(SiS_Pr->SiS_TVMode & TVSetPAL) {
5563 tempbx += 40;
5564 if(HwInfo->jChipType >= SIS_315H) {
5565 if(SiS_Pr->SiS_VGAHDE == 800) tempbx += 10;
5566 }
5567 }
5568 }
5569 }
5570 tempax >>= 2;
5571 tempax++;
5572 tempax += tempbx;
5573 push1 = tempax;
5574 if(SiS_Pr->SiS_TVMode & TVSetPAL) {
5575 if(tempbx <= 513) {
5576 if(tempax >= 513) tempbx = 513;
5577 }
5578 } 5395 }
5579 temp = tempbx & 0x00FF; 5396 for(i = 0x15, j = 11; i <= 0x16; i++, j++) {
5580 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0C,temp); /* 0x0C Vertical Retrace Start */ 5397 SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
5581
5582 tempbx--;
5583 temp = tempbx & 0x00FF;
5584 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x10,temp);
5585
5586 if(tempbx & 0x0100) tempcx |= 0x0008;
5587
5588 if(tempbx & 0x0200) {
5589 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x0B,0x20);
5590 } 5398 }
5591 tempbx++; 5399 for(i = 0x0a, j = 13; i <= 0x0c; i++, j++) {
5592 5400 SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
5593 if(tempbx & 0x0100) tempcx |= 0x0004;
5594 if(tempbx & 0x0200) tempcx |= 0x0080;
5595 if(tempbx & 0x0400) {
5596 if(HwInfo->jChipType >= SIS_661) tempcx |= 0x0800;
5597 else if(SiS_Pr->SiS_VBType & VB_SIS301) tempcx |= 0x0800;
5598 else tempcx |= 0x0C00;
5599 } 5401 }
5600 5402
5601 tempbx = push1; 5403 temp = SiS_Pr->CCRT1CRTC[16] & 0xE0;
5602 temp = tempbx & 0x000F; 5404 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,CRTranslation[0x0E],0x1F,temp);
5603 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0D,temp); /* 0x0D vertical Retrace End */
5604
5605 if(tempbx & 0x0010) tempcx |= 0x2000;
5606
5607 temp = tempcx & 0x00FF;
5608 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,temp); /* 0x0A CR07 */
5609
5610 temp = (tempcx & 0xFF00) >> 8;
5611 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,temp); /* 0x17 SR0A */
5612 5405
5613 tempax = modeflag; 5406 temp = (SiS_Pr->CCRT1CRTC[16] & 0x01) << 5;
5614 temp = (tempax & 0xFF00) >> 8; 5407 if(modeflag & DoubleScanMode) temp |= 0x80;
5615 temp = (temp >> 1) & 0x09; 5408 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,CRTranslation[0x09],0x5F,temp);
5616 if(!(SiS_Pr->SiS_VBType & VB_SIS301)) temp |= 0x01; /* Always 8 dotclock */
5617 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* 0x16 SR01 */
5618 5409
5619 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,0x00); /* 0x0F CR14 */ 5410 temp = 0;
5411 temp |= (SiS_GetReg(SiS_Pr->SiS_P3c4,0x01) & 0x01);
5412 if(modeflag & HalfDCLK) temp |= 0x08;
5413 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* SR01: HalfDCLK[3], 8/9 div dotclock[0] */
5620 5414
5621 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,0x00); /* 0x12 CR17 */ 5415 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,0x00); /* CR14: (text mode: underline location) */
5416 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,0x00); /* CR17: n/a */
5622 5417
5623 temp = 0x00; 5418 temp = 0;
5624 if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) { 5419 if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
5625 if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) { 5420 temp = (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) << 7;
5626 temp = 0x80;
5627 }
5628 } 5421 }
5629 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* 0x1A SR0E */ 5422 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* SR0E, dither[7] */
5630 5423
5631 temp = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02)); 5424 temp = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
5632 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp); 5425 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp); /* ? */
5426
5427#ifdef SIS_XORG_XF86
5428#ifdef TWDEBUG
5429 xf86DrvMsg(0, X_INFO, "%d %d %d %d %d %d %d %d (%d %d %d %d)\n",
5430 SiS_Pr->CHDisplay, SiS_Pr->CHSyncStart, SiS_Pr->CHSyncEnd, SiS_Pr->CHTotal,
5431 SiS_Pr->CVDisplay, SiS_Pr->CVSyncStart, SiS_Pr->CVSyncEnd, SiS_Pr->CVTotal,
5432 SiS_Pr->CHBlankStart, SiS_Pr->CHBlankEnd, SiS_Pr->CVBlankStart, SiS_Pr->CVBlankEnd);
5433
5434 xf86DrvMsg(0, X_INFO, " {{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n",
5435 SiS_Pr->CCRT1CRTC[0], SiS_Pr->CCRT1CRTC[1],
5436 SiS_Pr->CCRT1CRTC[2], SiS_Pr->CCRT1CRTC[3],
5437 SiS_Pr->CCRT1CRTC[4], SiS_Pr->CCRT1CRTC[5],
5438 SiS_Pr->CCRT1CRTC[6], SiS_Pr->CCRT1CRTC[7]);
5439 xf86DrvMsg(0, X_INFO, " 0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n",
5440 SiS_Pr->CCRT1CRTC[8], SiS_Pr->CCRT1CRTC[9],
5441 SiS_Pr->CCRT1CRTC[10], SiS_Pr->CCRT1CRTC[11],
5442 SiS_Pr->CCRT1CRTC[12], SiS_Pr->CCRT1CRTC[13],
5443 SiS_Pr->CCRT1CRTC[14], SiS_Pr->CCRT1CRTC[15]);
5444 xf86DrvMsg(0, X_INFO, " 0x%02x}},\n", SiS_Pr->CCRT1CRTC[16]);
5445#endif
5446#endif
5633} 5447}
5634 5448
5635/* Setup panel link 5449/* Setup panel link
@@ -5637,18 +5451,18 @@ SiS_SetGroup1_301(SiS_Private *SiS_Pr, USHORT ModeNo,USHORT ModeIdIndex,
5637 * 300/LVDS+TV, 300/301B-DH, 315/LVDS+TV, 315/LCDA 5451 * 300/LVDS+TV, 300/301B-DH, 315/LVDS+TV, 315/LCDA
5638 */ 5452 */
5639static void 5453static void
5640SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 5454SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
5641 PSIS_HW_INFO HwInfo, USHORT RefreshRateTableIndex) 5455 unsigned short RefreshRateTableIndex)
5642{ 5456{
5643 USHORT modeflag,resinfo; 5457 unsigned short modeflag, resinfo = 0;
5644 USHORT push2,tempax,tempbx,tempcx,temp; 5458 unsigned short push2, tempax, tempbx, tempcx, temp;
5645 ULONG tempeax=0,tempebx,tempecx,tempvcfact=0; 5459 unsigned int tempeax = 0, tempebx, tempecx, tempvcfact = 0;
5646 BOOLEAN islvds = FALSE, issis = FALSE, chkdclkfirst = FALSE; 5460 BOOLEAN islvds = FALSE, issis = FALSE, chkdclkfirst = FALSE;
5647#ifdef SIS300 5461#ifdef SIS300
5648 USHORT crt2crtc; 5462 unsigned short crt2crtc = 0;
5649#endif 5463#endif
5650#ifdef SIS315H 5464#ifdef SIS315H
5651 USHORT pushcx; 5465 unsigned short pushcx;
5652#endif 5466#endif
5653 5467
5654 if(ModeNo <= 0x13) { 5468 if(ModeNo <= 0x13) {
@@ -5659,15 +5473,11 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
5659#endif 5473#endif
5660 } else if(SiS_Pr->UseCustomMode) { 5474 } else if(SiS_Pr->UseCustomMode) {
5661 modeflag = SiS_Pr->CModeFlag; 5475 modeflag = SiS_Pr->CModeFlag;
5662 resinfo = 0;
5663#ifdef SIS300
5664 crt2crtc = 0;
5665#endif
5666 } else { 5476 } else {
5667 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 5477 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5668 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; 5478 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
5669#ifdef SIS300 5479#ifdef SIS300
5670 crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; 5480 crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
5671#endif 5481#endif
5672 } 5482 }
5673 5483
@@ -5681,14 +5491,14 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
5681 issis = TRUE; 5491 issis = TRUE;
5682 } 5492 }
5683 5493
5684 if((HwInfo->jChipType >= SIS_315H) && (islvds) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA))) { 5494 if((SiS_Pr->ChipType >= SIS_315H) && (islvds) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA))) {
5685 if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) { 5495 if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) {
5686 chkdclkfirst = TRUE; 5496 chkdclkfirst = TRUE;
5687 } 5497 }
5688 } 5498 }
5689 5499
5690#ifdef SIS315H 5500#ifdef SIS315H
5691 if((HwInfo->jChipType >= SIS_315H) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { 5501 if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
5692 if(IS_SIS330) { 5502 if(IS_SIS330) {
5693 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10); 5503 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
5694 } else if(IS_SIS740) { 5504 } else if(IS_SIS740) {
@@ -5704,7 +5514,7 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
5704 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x00); 5514 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x00);
5705 } else if(SiS_Pr->SiS_VBType & VB_SISVB) { 5515 } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
5706 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2D,0x0f); 5516 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2D,0x0f);
5707 if(SiS_Pr->SiS_VBType & VB_SIS301C) { 5517 if(SiS_Pr->SiS_VBType & VB_SIS30xC) {
5708 if((SiS_Pr->SiS_LCDResInfo == Panel_1024x768) || 5518 if((SiS_Pr->SiS_LCDResInfo == Panel_1024x768) ||
5709 (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) { 5519 (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
5710 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x20); 5520 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x20);
@@ -5720,10 +5530,10 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
5720 tempax = SiS_Pr->SiS_LCDHDES; 5530 tempax = SiS_Pr->SiS_LCDHDES;
5721 if(islvds) { 5531 if(islvds) {
5722 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { 5532 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
5723 if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) { 5533 if(!SiS_Pr->SiS_IF_DEF_FSTN && !SiS_Pr->SiS_IF_DEF_DSTN) {
5724 if((SiS_Pr->SiS_LCDResInfo == Panel_640x480) && 5534 if((SiS_Pr->SiS_LCDResInfo == Panel_640x480) &&
5725 (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) { 5535 (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) {
5726 tempax -= 8; 5536 tempax -= 8;
5727 } 5537 }
5728 } 5538 }
5729 } 5539 }
@@ -5736,13 +5546,14 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
5736 5546
5737 tempbx = SiS_Pr->SiS_HDE; 5547 tempbx = SiS_Pr->SiS_HDE;
5738 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { 5548 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
5739 if((SiS_Pr->SiS_LCDResInfo == Panel_640x480_2) ||
5740 (SiS_Pr->SiS_LCDResInfo == Panel_640x480_3)) {
5741 tempbx >>= 1;
5742 }
5743 if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { 5549 if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
5744 tempbx = SiS_Pr->PanelXRes; 5550 tempbx = SiS_Pr->PanelXRes;
5745 } 5551 }
5552 if((SiS_Pr->SiS_LCDResInfo == Panel_320x240_1) ||
5553 (SiS_Pr->SiS_LCDResInfo == Panel_320x240_2) ||
5554 (SiS_Pr->SiS_LCDResInfo == Panel_320x240_3)) {
5555 tempbx >>= 1;
5556 }
5746 } 5557 }
5747 5558
5748 tempax += tempbx; 5559 tempax += tempbx;
@@ -5767,25 +5578,25 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
5767 temp = (tempcx >> 3) & 0x00FF; 5578 temp = (tempcx >> 3) & 0x00FF;
5768 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { 5579 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
5769 if(SiS_Pr->SiS_IF_DEF_TRUMPION) { 5580 if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
5770 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { 5581 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
5771 switch(ModeNo) { 5582 switch(ModeNo) {
5772 case 0x04: 5583 case 0x04:
5773 case 0x05: 5584 case 0x05:
5774 case 0x0d: temp = 0x56; break; 5585 case 0x0d: temp = 0x56; break;
5775 case 0x10: temp = 0x60; break; 5586 case 0x10: temp = 0x60; break;
5776 case 0x13: temp = 0x5f; break; 5587 case 0x13: temp = 0x5f; break;
5777 case 0x40: 5588 case 0x40:
5778 case 0x41: 5589 case 0x41:
5779 case 0x4f: 5590 case 0x4f:
5780 case 0x43: 5591 case 0x43:
5781 case 0x44: 5592 case 0x44:
5782 case 0x62: 5593 case 0x62:
5783 case 0x56: 5594 case 0x56:
5784 case 0x53: 5595 case 0x53:
5785 case 0x5d: 5596 case 0x5d:
5786 case 0x5e: temp = 0x54; break; 5597 case 0x5e: temp = 0x54; break;
5787 } 5598 }
5788 } 5599 }
5789 } 5600 }
5790 } 5601 }
5791 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,temp); /* BPLHRS */ 5602 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,temp); /* BPLHRS */
@@ -5793,12 +5604,12 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
5793 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { 5604 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
5794 temp += 2; 5605 temp += 2;
5795 if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { 5606 if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
5796 temp += 8; 5607 temp += 8;
5797 if(SiS_Pr->PanelHRE != 999) { 5608 if(SiS_Pr->PanelHRE != 999) {
5798 temp = tempcx + SiS_Pr->PanelHRE; 5609 temp = tempcx + SiS_Pr->PanelHRE;
5799 if(temp >= SiS_Pr->SiS_HT) temp -= SiS_Pr->SiS_HT; 5610 if(temp >= SiS_Pr->SiS_HT) temp -= SiS_Pr->SiS_HT;
5800 temp >>= 3; 5611 temp >>= 3;
5801 } 5612 }
5802 } 5613 }
5803 } else { 5614 } else {
5804 temp += 10; 5615 temp += 10;
@@ -5806,9 +5617,6 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
5806 5617
5807 temp &= 0x1F; 5618 temp &= 0x1F;
5808 temp |= ((tempcx & 0x07) << 5); 5619 temp |= ((tempcx & 0x07) << 5);
5809#if 0
5810 if(SiS_Pr->SiS_IF_DEF_FSTN) temp = 0x20; /* WRONG? BIOS loads cl, not ah */
5811#endif
5812 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,temp); /* BPLHRE */ 5620 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,temp); /* BPLHRE */
5813 5621
5814 /* Vertical */ 5622 /* Vertical */
@@ -5826,9 +5634,9 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
5826 push2 = tempbx; 5634 push2 = tempbx;
5827 5635
5828 tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE; 5636 tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE;
5829 if(HwInfo->jChipType < SIS_315H) { 5637 if(SiS_Pr->ChipType < SIS_315H) {
5830 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { 5638 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
5831 if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { 5639 if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
5832 tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->PanelYRes; 5640 tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->PanelYRes;
5833 } 5641 }
5834 } 5642 }
@@ -5844,19 +5652,19 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
5844 if(issis) tempbx++; 5652 if(issis) tempbx++;
5845 } else { 5653 } else {
5846 tempbx += tempcx; 5654 tempbx += tempcx;
5847 if(HwInfo->jChipType < SIS_315H) tempbx++; 5655 if(SiS_Pr->ChipType < SIS_315H) tempbx++;
5848 else if(issis) tempbx++; 5656 else if(issis) tempbx++;
5849 } 5657 }
5850 5658
5851 if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT; /* BPLVRS */ 5659 if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
5852 5660
5853 temp = tempbx & 0x00FF; 5661 temp = tempbx & 0x00FF;
5854 if(SiS_Pr->SiS_IF_DEF_TRUMPION) { 5662 if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
5855 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { 5663 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
5856 if(ModeNo == 0x10) temp = 0xa9; 5664 if(ModeNo == 0x10) temp = 0xa9;
5857 } 5665 }
5858 } 5666 }
5859 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp); 5667 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp); /* BPLVRS */
5860 5668
5861 tempcx >>= 3; 5669 tempcx >>= 3;
5862 tempcx++; 5670 tempcx++;
@@ -5879,13 +5687,13 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
5879 } else if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40; 5687 } else if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40;
5880 if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) temp |= 0x40; 5688 if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) temp |= 0x40;
5881 tempbx = 0x87; 5689 tempbx = 0x87;
5882 if((HwInfo->jChipType >= SIS_315H) || 5690 if((SiS_Pr->ChipType >= SIS_315H) ||
5883 (HwInfo->jChipRevision >= 0x30)) { 5691 (SiS_Pr->ChipRevision >= 0x30)) {
5884 tempbx = 0x07; 5692 tempbx = 0x07;
5885 if((SiS_Pr->SiS_IF_DEF_CH70xx == 1) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) { 5693 if((SiS_Pr->SiS_IF_DEF_CH70xx == 1) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
5886 if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x03) temp |= 0x80; 5694 if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x03) temp |= 0x80;
5887 } 5695 }
5888 /* Chrontel 701x operates in 24bit mode (8-8-8, 2x12bit mutliplexed) via VGA2 */ 5696 /* Chrontel 701x operates in 24bit mode (8-8-8, 2x12bit multiplexed) via VGA2 */
5889 if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) { 5697 if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
5890 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { 5698 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
5891 if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x10) temp |= 0x80; 5699 if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x10) temp |= 0x80;
@@ -5896,59 +5704,58 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
5896 } 5704 }
5897 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1A,tempbx,temp); 5705 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1A,tempbx,temp);
5898 5706
5899 tempbx = push2; /* BPLVDEE */ 5707 tempbx = push2; /* BPLVDEE */
5900 5708
5901 tempcx = SiS_Pr->SiS_LCDVDES; /* BPLVDES */ 5709 tempcx = SiS_Pr->SiS_LCDVDES; /* BPLVDES */
5902 5710
5903 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { 5711 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
5904 switch(SiS_Pr->SiS_LCDResInfo) { 5712 switch(SiS_Pr->SiS_LCDResInfo) {
5905 case Panel_640x480: 5713 case Panel_640x480:
5906 tempbx = SiS_Pr->SiS_VGAVDE - 1; 5714 tempbx = SiS_Pr->SiS_VGAVDE - 1;
5907 tempcx = SiS_Pr->SiS_VGAVDE; 5715 tempcx = SiS_Pr->SiS_VGAVDE;
5908 break; 5716 break;
5909 case Panel_800x600: 5717 case Panel_800x600:
5910 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { 5718 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
5911 if(resinfo == SIS_RI_800x600) tempcx++; 5719 if(resinfo == SIS_RI_800x600) tempcx++;
5912 } 5720 }
5913 break; 5721 break;
5914 case Panel_1024x600: 5722 case Panel_1024x600:
5915 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { 5723 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
5916 if(resinfo == SIS_RI_1024x600) tempcx++; 5724 if(resinfo == SIS_RI_1024x600) tempcx++;
5917 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { 5725 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
5918 if(resinfo == SIS_RI_800x600) tempcx++; 5726 if(resinfo == SIS_RI_800x600) tempcx++;
5919 } 5727 }
5920 } 5728 }
5921 break; 5729 break;
5922 case Panel_1024x768: 5730 case Panel_1024x768:
5923 if(HwInfo->jChipType < SIS_315H) { 5731 if(SiS_Pr->ChipType < SIS_315H) {
5924 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { 5732 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
5925 if(resinfo == SIS_RI_1024x768) tempcx++; 5733 if(resinfo == SIS_RI_1024x768) tempcx++;
5926 } 5734 }
5927 } 5735 }
5928 break; 5736 break;
5929 } 5737 }
5930 } 5738 }
5931 5739
5932 temp = ((tempbx >> 8) & 0x07) << 3; 5740 temp = ((tempbx >> 8) & 0x07) << 3;
5933 temp = temp | ((tempcx >> 8) & 0x07); 5741 temp |= ((tempcx >> 8) & 0x07);
5934 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1D,temp); 5742 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1D,temp);
5935 /* if(SiS_Pr->SiS_IF_DEF_FSTN) tempbx++; */
5936 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1C,tempbx); 5743 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1C,tempbx);
5937 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1B,tempcx); 5744 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1B,tempcx);
5938 5745
5939 /* Vertical scaling */ 5746 /* Vertical scaling */
5940 5747
5941 if(HwInfo->jChipType < SIS_315H) { 5748 if(SiS_Pr->ChipType < SIS_315H) {
5942 5749
5943#ifdef SIS300 /* 300 series */ 5750#ifdef SIS300 /* 300 series */
5944 tempeax = SiS_Pr->SiS_VGAVDE << 6; 5751 tempeax = SiS_Pr->SiS_VGAVDE << 6;
5945 temp = (tempeax % (ULONG)SiS_Pr->SiS_VDE); 5752 temp = (tempeax % (unsigned int)SiS_Pr->SiS_VDE);
5946 tempeax = tempeax / (ULONG)SiS_Pr->SiS_VDE; 5753 tempeax = tempeax / (unsigned int)SiS_Pr->SiS_VDE;
5947 if(temp) tempeax++; 5754 if(temp) tempeax++;
5948 5755
5949 if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) tempeax = 0x3F; 5756 if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) tempeax = 0x3F;
5950 5757
5951 temp = (USHORT)(tempeax & 0x00FF); 5758 temp = (unsigned short)(tempeax & 0x00FF);
5952 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1E,temp); /* BPLVCFACT */ 5759 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1E,temp); /* BPLVCFACT */
5953 tempvcfact = temp; 5760 tempvcfact = temp;
5954#endif /* SIS300 */ 5761#endif /* SIS300 */
@@ -5963,20 +5770,20 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
5963 if(temp) tempeax++; 5770 if(temp) tempeax++;
5964 tempvcfact = tempeax; 5771 tempvcfact = tempeax;
5965 5772
5966 temp = (USHORT)(tempeax & 0x00FF); 5773 temp = (unsigned short)(tempeax & 0x00FF);
5967 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,temp); 5774 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,temp);
5968 temp = (USHORT)((tempeax & 0x00FF00) >> 8); 5775 temp = (unsigned short)((tempeax & 0x00FF00) >> 8);
5969 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,temp); 5776 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,temp);
5970 temp = (USHORT)((tempeax & 0x00030000) >> 16); 5777 temp = (unsigned short)((tempeax & 0x00030000) >> 16);
5971 if(SiS_Pr->SiS_VDE == SiS_Pr->SiS_VGAVDE) temp |= 0x04; 5778 if(SiS_Pr->SiS_VDE == SiS_Pr->SiS_VGAVDE) temp |= 0x04;
5972 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,temp); 5779 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,temp);
5973 5780
5974 if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302ELV)) { 5781 if(SiS_Pr->SiS_VBType & VB_SISPART4SCALER) {
5975 temp = (USHORT)(tempeax & 0x00FF); 5782 temp = (unsigned short)(tempeax & 0x00FF);
5976 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3c,temp); 5783 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3c,temp);
5977 temp = (USHORT)((tempeax & 0x00FF00) >> 8); 5784 temp = (unsigned short)((tempeax & 0x00FF00) >> 8);
5978 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3b,temp); 5785 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3b,temp);
5979 temp = (USHORT)(((tempeax & 0x00030000) >> 16) << 6); 5786 temp = (unsigned short)(((tempeax & 0x00030000) >> 16) << 6);
5980 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0x3f,temp); 5787 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0x3f,temp);
5981 temp = 0; 5788 temp = 0;
5982 if(SiS_Pr->SiS_VDE != SiS_Pr->SiS_VGAVDE) temp |= 0x08; 5789 if(SiS_Pr->SiS_VDE != SiS_Pr->SiS_VGAVDE) temp |= 0x08;
@@ -5997,29 +5804,29 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
5997 tempecx = 0xFFFF; 5804 tempecx = 0xFFFF;
5998 } else { 5805 } else {
5999 tempecx = tempebx / SiS_Pr->SiS_HDE; 5806 tempecx = tempebx / SiS_Pr->SiS_HDE;
6000 if(HwInfo->jChipType >= SIS_315H) { 5807 if(SiS_Pr->ChipType >= SIS_315H) {
6001 if(tempebx % SiS_Pr->SiS_HDE) tempecx++; 5808 if(tempebx % SiS_Pr->SiS_HDE) tempecx++;
6002 } 5809 }
6003 } 5810 }
6004 5811
6005 if(HwInfo->jChipType >= SIS_315H) { 5812 if(SiS_Pr->ChipType >= SIS_315H) {
6006 tempeax = (tempebx / tempecx) - 1; 5813 tempeax = (tempebx / tempecx) - 1;
6007 } else { 5814 } else {
6008 tempeax = ((SiS_Pr->SiS_VGAHT << 16) / tempecx) - 1; 5815 tempeax = ((SiS_Pr->SiS_VGAHT << 16) / tempecx) - 1;
6009 } 5816 }
6010 tempecx = (tempecx << 16) | (tempeax & 0xFFFF); 5817 tempecx = (tempecx << 16) | (tempeax & 0xFFFF);
6011 temp = (USHORT)(tempecx & 0x00FF); 5818 temp = (unsigned short)(tempecx & 0x00FF);
6012 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1F,temp); 5819 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1F,temp);
6013 5820
6014 if(HwInfo->jChipType >= SIS_315H) { 5821 if(SiS_Pr->ChipType >= SIS_315H) {
6015 tempeax = (SiS_Pr->SiS_VGAVDE << 18) / tempvcfact; 5822 tempeax = (SiS_Pr->SiS_VGAVDE << 18) / tempvcfact;
6016 tempbx = (USHORT)(tempeax & 0xFFFF); 5823 tempbx = (unsigned short)(tempeax & 0xFFFF);
6017 } else { 5824 } else {
6018 tempeax = SiS_Pr->SiS_VGAVDE << 6; 5825 tempeax = SiS_Pr->SiS_VGAVDE << 6;
6019 tempbx = tempvcfact & 0x3f; 5826 tempbx = tempvcfact & 0x3f;
6020 if(tempbx == 0) tempbx = 64; 5827 if(tempbx == 0) tempbx = 64;
6021 tempeax /= tempbx; 5828 tempeax /= tempbx;
6022 tempbx = (USHORT)(tempeax & 0xFFFF); 5829 tempbx = (unsigned short)(tempeax & 0xFFFF);
6023 } 5830 }
6024 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tempbx--; 5831 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tempbx--;
6025 if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) { 5832 if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) {
@@ -6032,24 +5839,24 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6032 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x20,temp); 5839 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x20,temp);
6033 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x21,tempbx); 5840 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x21,tempbx);
6034 5841
6035 tempecx >>= 16; /* BPLHCFACT */ 5842 tempecx >>= 16; /* BPLHCFACT */
6036 if(!chkdclkfirst) { 5843 if(!chkdclkfirst) {
6037 if(modeflag & HalfDCLK) tempecx >>= 1; 5844 if(modeflag & HalfDCLK) tempecx >>= 1;
6038 } 5845 }
6039 temp = (USHORT)((tempecx & 0xFF00) >> 8); 5846 temp = (unsigned short)((tempecx & 0xFF00) >> 8);
6040 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x22,temp); 5847 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x22,temp);
6041 temp = (USHORT)(tempecx & 0x00FF); 5848 temp = (unsigned short)(tempecx & 0x00FF);
6042 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x23,temp); 5849 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x23,temp);
6043 5850
6044#ifdef SIS315H 5851#ifdef SIS315H
6045 if(HwInfo->jChipType >= SIS_315H) { 5852 if(SiS_Pr->ChipType >= SIS_315H) {
6046 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { 5853 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
6047 if((islvds) || (SiS_Pr->SiS_VBInfo & VB_SIS301LV302LV)) { 5854 if((islvds) || (SiS_Pr->SiS_VBInfo & VB_SISLVDS)) {
6048 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x20); 5855 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x20);
6049 } 5856 }
6050 } else { 5857 } else {
6051 if(islvds) { 5858 if(islvds) {
6052 if(HwInfo->jChipType == SIS_740) { 5859 if(SiS_Pr->ChipType == SIS_740) {
6053 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03); 5860 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03);
6054 } else { 5861 } else {
6055 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x23); 5862 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x23);
@@ -6061,17 +5868,26 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6061 5868
6062#ifdef SIS300 5869#ifdef SIS300
6063 if(SiS_Pr->SiS_IF_DEF_TRUMPION) { 5870 if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
6064 int i; 5871 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
6065 UCHAR TrumpMode13[4] = { 0x01, 0x10, 0x2c, 0x00 }; 5872 unsigned char *trumpdata;
6066 UCHAR TrumpMode10_1[4] = { 0x01, 0x10, 0x27, 0x00 }; 5873 int i, j = crt2crtc;
6067 UCHAR TrumpMode10_2[4] = { 0x01, 0x16, 0x10, 0x00 }; 5874 unsigned char TrumpMode13[4] = { 0x01, 0x10, 0x2c, 0x00 };
5875 unsigned char TrumpMode10_1[4] = { 0x01, 0x10, 0x27, 0x00 };
5876 unsigned char TrumpMode10_2[4] = { 0x01, 0x16, 0x10, 0x00 };
5877
5878 if(SiS_Pr->SiS_UseROM) {
5879 trumpdata = &ROMAddr[0x8001 + (j * 80)];
5880 } else {
5881 if(SiS_Pr->SiS_LCDTypeInfo == 0x0e) j += 7;
5882 trumpdata = &SiS300_TrumpionData[j][0];
5883 }
6068 5884
6069 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xbf); 5885 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xbf);
6070 for(i=0; i<5; i++) { 5886 for(i=0; i<5; i++) {
6071 SiS_SetTrumpionBlock(SiS_Pr, &SiS300_TrumpionData[crt2crtc][0]); 5887 SiS_SetTrumpionBlock(SiS_Pr, trumpdata);
6072 } 5888 }
6073 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { 5889 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
6074 if(ModeNo == 0x13) { 5890 if(ModeNo == 0x13) {
6075 for(i=0; i<4; i++) { 5891 for(i=0; i<4; i++) {
6076 SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode13[0]); 5892 SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode13[0]);
6077 } 5893 }
@@ -6095,67 +5911,66 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6095 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x29,0x5A); 5911 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x29,0x5A);
6096 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2A,0x4B); 5912 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2A,0x4B);
6097 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x07,0x03); 5913 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x07,0x03);
6098 tempax = SiS_Pr->SiS_HDE; /* Blps = lcdhdee(lcdhdes+HDE) + 64 */ 5914 tempax = SiS_Pr->SiS_HDE; /* Blps = lcdhdee(lcdhdes+HDE) + 64 */
6099 if(SiS_Pr->SiS_LCDResInfo == Panel_640x480_2 || 5915 if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
6100 SiS_Pr->SiS_LCDResInfo == Panel_640x480_3) tempax >>= 1; 5916 SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
5917 SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
6101 tempax += 64; 5918 tempax += 64;
6102 temp = tempax & 0x00FF; 5919 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,tempax & 0xff);
6103 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,temp); 5920 temp = (tempax >> 8) << 3;
6104 temp = ((tempax & 0xFF00) >> 8) << 3;
6105 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,~0x078,temp); 5921 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,~0x078,temp);
6106 tempax += 32; /* Blpe=lBlps+32 */ 5922 tempax += 32; /* Blpe = lBlps+32 */
6107 temp = tempax & 0x00FF; 5923 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,tempax & 0xff);
6108 if(SiS_Pr->SiS_IF_DEF_FSTN) temp = 0; 5924 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3A,0x00); /* Bflml = 0 */
6109 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,temp); 5925 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x3C,~0x007);
6110 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3A,0x00); /* Bflml=0 */
6111 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x007,0x00);
6112 5926
6113 tempax = SiS_Pr->SiS_VDE; 5927 tempax = SiS_Pr->SiS_VDE;
6114 if(SiS_Pr->SiS_LCDResInfo == Panel_640x480_2 || 5928 if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
6115 SiS_Pr->SiS_LCDResInfo == Panel_640x480_3) tempax >>= 1; 5929 SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
5930 SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
6116 tempax >>= 1; 5931 tempax >>= 1;
6117 temp = tempax & 0x00FF; 5932 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3B,tempax & 0xff);
6118 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3B,temp); 5933 temp = (tempax >> 8) << 3;
6119 temp = ((tempax & 0xFF00) >> 8) << 3;
6120 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x038,temp); 5934 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x038,temp);
6121 5935
6122 tempeax = SiS_Pr->SiS_HDE; 5936 tempeax = SiS_Pr->SiS_HDE;
6123 if(SiS_Pr->SiS_LCDResInfo == Panel_640x480_2 || 5937 if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
6124 SiS_Pr->SiS_LCDResInfo == Panel_640x480_3) tempeax >>= 1; 5938 SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
6125 tempeax <<= 2; /* BDxFIFOSTOP = (HDE*4)/128 */ 5939 SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempeax >>= 1;
6126 tempebx = 128; 5940 tempeax <<= 2; /* BDxFIFOSTOP = (HDE*4)/128 */
6127 temp = (USHORT)(tempeax % tempebx); 5941 temp = tempeax & 0x7f;
6128 tempeax = tempeax / tempebx; 5942 tempeax >>= 7;
6129 if(temp) tempeax++; 5943 if(temp) tempeax++;
6130 temp = (USHORT)(tempeax & 0x003F); 5944 temp = tempeax & 0x3f;
6131 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x45,~0x0FF,temp); 5945 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,temp);
6132 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3F,0x00); /* BDxWadrst0 */ 5946 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3F,0x00); /* BDxWadrst0 */
6133 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3E,0x00); 5947 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3E,0x00);
6134 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3D,0x10); 5948 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3D,0x10);
6135 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x040,0x00); 5949 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x3C,~0x040);
6136 5950
6137 tempax = SiS_Pr->SiS_HDE; 5951 tempax = SiS_Pr->SiS_HDE;
6138 if(SiS_Pr->SiS_LCDResInfo == Panel_640x480_2 || 5952 if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
6139 SiS_Pr->SiS_LCDResInfo == Panel_640x480_3) tempax >>= 1; 5953 SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
6140 tempax >>= 4; /* BDxWadroff = HDE*4/8/8 */ 5954 SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
5955 tempax >>= 4; /* BDxWadroff = HDE*4/8/8 */
6141 pushcx = tempax; 5956 pushcx = tempax;
6142 temp = tempax & 0x00FF; 5957 temp = tempax & 0x00FF;
6143 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,temp); 5958 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,temp);
6144 temp = ((tempax & 0xFF00) >> 8) << 3; 5959 temp = ((tempax & 0xFF00) >> 8) << 3;
6145 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x0F8,temp); 5960 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x0F8,temp);
6146 5961
6147 tempax = SiS_Pr->SiS_VDE; /* BDxWadrst1 = BDxWadrst0 + BDxWadroff * VDE */ 5962 tempax = SiS_Pr->SiS_VDE; /* BDxWadrst1 = BDxWadrst0 + BDxWadroff * VDE */
6148 if(SiS_Pr->SiS_LCDResInfo == Panel_640x480_2 || 5963 if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
6149 SiS_Pr->SiS_LCDResInfo == Panel_640x480_3) tempax >>= 1; 5964 SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
6150 tempeax = (tempax * pushcx); 5965 SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
6151 tempebx = 0x00100000 + tempeax; 5966 tempeax = tempax * pushcx;
6152 temp = (USHORT)tempebx & 0x000000FF; 5967 temp = tempeax & 0xFF;
6153 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,temp); 5968 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,temp);
6154 temp = (USHORT)((tempebx & 0x0000FF00) >> 8); 5969 temp = (tempeax & 0xFF00) >> 8;
6155 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,temp); 5970 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,temp);
6156 temp = (USHORT)((tempebx & 0x00FF0000) >> 16); 5971 temp = ((tempeax & 0xFF0000) >> 16) | 0x10;
6157 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,temp); 5972 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,temp);
6158 temp = (USHORT)(((tempebx & 0x01000000) >> 24) << 7); 5973 temp = ((tempeax & 0x01000000) >> 24) << 7;
6159 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x080,temp); 5974 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x080,temp);
6160 5975
6161 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x03); 5976 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x03);
@@ -6192,20 +6007,20 @@ SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6192 6007
6193/* Set Part 1 */ 6008/* Set Part 1 */
6194static void 6009static void
6195SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 6010SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
6196 PSIS_HW_INFO HwInfo, USHORT RefreshRateTableIndex) 6011 unsigned short RefreshRateTableIndex)
6197{ 6012{
6198#if defined(SIS300) || defined(SIS315H) 6013#if defined(SIS300) || defined(SIS315H)
6199 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 6014 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
6200#endif 6015#endif
6201 USHORT temp=0, tempax=0, tempbx=0, tempcx=0, bridgeadd=0; 6016 unsigned short temp=0, tempax=0, tempbx=0, tempcx=0, bridgeadd=0;
6202 USHORT pushbx=0, CRT1Index=0, modeflag, resinfo=0; 6017 unsigned short pushbx=0, CRT1Index=0, modeflag, resinfo=0;
6203#ifdef SIS315H 6018#ifdef SIS315H
6204 USHORT tempbl=0; 6019 unsigned short tempbl=0;
6205#endif 6020#endif
6206 6021
6207 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { 6022 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
6208 SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, RefreshRateTableIndex); 6023 SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
6209 return; 6024 return;
6210 } 6025 }
6211 6026
@@ -6214,47 +6029,47 @@ SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6214 } else if(SiS_Pr->UseCustomMode) { 6029 } else if(SiS_Pr->UseCustomMode) {
6215 modeflag = SiS_Pr->CModeFlag; 6030 modeflag = SiS_Pr->CModeFlag;
6216 } else { 6031 } else {
6217 CRT1Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; 6032 CRT1Index = SiS_GetRefCRT1CRTC(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWideCRT2);
6218 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; 6033 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
6219 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 6034 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
6220 } 6035 }
6221 6036
6222 SiS_SetCRT2Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo); 6037 SiS_SetCRT2Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
6223 6038
6224 if( ! ((HwInfo->jChipType >= SIS_315H) && 6039 if( ! ((SiS_Pr->ChipType >= SIS_315H) &&
6225 (SiS_Pr->SiS_IF_DEF_LVDS == 1) && 6040 (SiS_Pr->SiS_IF_DEF_LVDS == 1) &&
6226 (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ) { 6041 (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ) {
6227 6042
6228 if(HwInfo->jChipType < SIS_315H ) { 6043 if(SiS_Pr->ChipType < SIS_315H ) {
6229#ifdef SIS300 6044#ifdef SIS300
6230 SiS_SetCRT2FIFO_300(SiS_Pr, ModeNo, HwInfo); 6045 SiS_SetCRT2FIFO_300(SiS_Pr, ModeNo);
6231#endif 6046#endif
6232 } else { 6047 } else {
6233#ifdef SIS315H 6048#ifdef SIS315H
6234 SiS_SetCRT2FIFO_310(SiS_Pr, HwInfo); 6049 SiS_SetCRT2FIFO_310(SiS_Pr);
6235#endif 6050#endif
6236 } 6051 }
6237 6052
6238 /* 1. Horizontal setup */ 6053 /* 1. Horizontal setup */
6239 6054
6240 if(HwInfo->jChipType < SIS_315H ) { 6055 if(SiS_Pr->ChipType < SIS_315H ) {
6241 6056
6242#ifdef SIS300 /* ------------- 300 series --------------*/ 6057#ifdef SIS300 /* ------------- 300 series --------------*/
6243 6058
6244 temp = (SiS_Pr->SiS_VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */ 6059 temp = (SiS_Pr->SiS_VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
6245 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,temp); /* CRT2 Horizontal Total */ 6060 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,temp); /* CRT2 Horizontal Total */
6246 6061
6247 temp = (((SiS_Pr->SiS_VGAHT - 1) & 0xFF00) >> 8) << 4; 6062 temp = (((SiS_Pr->SiS_VGAHT - 1) & 0xFF00) >> 8) << 4;
6248 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0f,temp); /* CRT2 Horizontal Total Overflow [7:4] */ 6063 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0f,temp); /* CRT2 Horizontal Total Overflow [7:4] */
6249 6064
6250 temp = (SiS_Pr->SiS_VGAHDE + 12) & 0x0FF; /* BTVGA2HDEE 0x0A,0x0C */ 6065 temp = (SiS_Pr->SiS_VGAHDE + 12) & 0x0FF; /* BTVGA2HDEE 0x0A,0x0C */
6251 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,temp); /* CRT2 Horizontal Display Enable End */ 6066 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,temp); /* CRT2 Horizontal Display Enable End */
6252 6067
6253 pushbx = SiS_Pr->SiS_VGAHDE + 12; /* bx BTVGA2HRS 0x0B,0x0C */ 6068 pushbx = SiS_Pr->SiS_VGAHDE + 12; /* bx BTVGA2HRS 0x0B,0x0C */
6254 tempcx = (SiS_Pr->SiS_VGAHT - SiS_Pr->SiS_VGAHDE) >> 2; 6069 tempcx = (SiS_Pr->SiS_VGAHT - SiS_Pr->SiS_VGAHDE) >> 2;
6255 tempbx = pushbx + tempcx; 6070 tempbx = pushbx + tempcx;
6256 tempcx <<= 1; 6071 tempcx <<= 1;
6257 tempcx += tempbx; 6072 tempcx += tempbx;
6258 6073
6259 bridgeadd = 12; 6074 bridgeadd = 12;
6260 6075
@@ -6301,7 +6116,7 @@ SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6301 bridgeadd = 16; 6116 bridgeadd = 16;
6302 6117
6303 if(SiS_Pr->SiS_VBType & VB_SISVB) { 6118 if(SiS_Pr->SiS_VBType & VB_SISVB) {
6304 if(HwInfo->jChipType >= SIS_661) { 6119 if(SiS_Pr->ChipType >= SIS_661) {
6305 if((SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) || 6120 if((SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
6306 (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) { 6121 (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
6307 if(resinfo == SIS_RI_1280x1024) { 6122 if(resinfo == SIS_RI_1280x1024) {
@@ -6319,7 +6134,7 @@ SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6319 6134
6320 if(SiS_Pr->SiS_VBType & VB_SISVB) { 6135 if(SiS_Pr->SiS_VBType & VB_SISVB) {
6321 6136
6322 if(SiS_Pr->UseCustomMode) { 6137 if(SiS_Pr->UseCustomMode) {
6323 tempbx = SiS_Pr->CHSyncStart + bridgeadd; 6138 tempbx = SiS_Pr->CHSyncStart + bridgeadd;
6324 tempcx = SiS_Pr->CHSyncEnd + bridgeadd; 6139 tempcx = SiS_Pr->CHSyncEnd + bridgeadd;
6325 tempax = SiS_Pr->SiS_VGAHT; 6140 tempax = SiS_Pr->SiS_VGAHT;
@@ -6341,22 +6156,22 @@ SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6341 cr5 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[5]; 6156 cr5 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[5];
6342 cr15 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[15]; 6157 cr15 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[15];
6343 } 6158 }
6344 tempbx = ((cr4 | ((cr14 & 0xC0) << 2)) - 3) << 3; /* (VGAHRS-3)*8 */ 6159 tempbx = ((cr4 | ((cr14 & 0xC0) << 2)) - 3) << 3; /* (VGAHRS-3)*8 */
6345 tempcx = (((cr5 & 0x1f) | ((cr15 & 0x04) << (5-2))) - 3) << 3; /* (VGAHRE-3)*8 */ 6160 tempcx = (((cr5 & 0x1f) | ((cr15 & 0x04) << (5-2))) - 3) << 3; /* (VGAHRE-3)*8 */
6346 tempcx &= 0x00FF; 6161 tempcx &= 0x00FF;
6347 tempcx |= (tempbx & 0xFF00); 6162 tempcx |= (tempbx & 0xFF00);
6348 tempbx += bridgeadd; 6163 tempbx += bridgeadd;
6349 tempcx += bridgeadd; 6164 tempcx += bridgeadd;
6350 tempax = SiS_Pr->SiS_VGAHT; 6165 tempax = SiS_Pr->SiS_VGAHT;
6351 if(modeflag & HalfDCLK) tempax >>= 1; 6166 if(modeflag & HalfDCLK) tempax >>= 1;
6352 tempax--; 6167 tempax--;
6353 if(tempcx > tempax) tempcx = tempax; 6168 if(tempcx > tempax) tempcx = tempax;
6354 } 6169 }
6355 6170
6356 if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) { 6171 if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSet525p1024)) {
6357 tempbx = 1040; 6172 tempbx = 1040;
6358 tempcx = 1044; /* HWCursor bug! */ 6173 tempcx = 1044; /* HWCursor bug! */
6359 } 6174 }
6360 6175
6361 } 6176 }
6362 6177
@@ -6372,18 +6187,18 @@ SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6372 tempcx = SiS_Pr->SiS_VGAVT - 1; 6187 tempcx = SiS_Pr->SiS_VGAVT - 1;
6373 temp = tempcx & 0x00FF; 6188 temp = tempcx & 0x00FF;
6374 6189
6375 if(HwInfo->jChipType < SIS_661) { 6190 if(SiS_Pr->ChipType < SIS_661) {
6376 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 6191 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
6377 if(HwInfo->jChipType < SIS_315H) { 6192 if(SiS_Pr->ChipType < SIS_315H) {
6378 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 6193 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
6379 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) { 6194 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
6380 temp--; 6195 temp--;
6381 } 6196 }
6382 } 6197 }
6383 } else { 6198 } else {
6384 temp--; 6199 temp--;
6385 } 6200 }
6386 } else if(HwInfo->jChipType >= SIS_315H) { 6201 } else if(SiS_Pr->ChipType >= SIS_315H) {
6387 temp--; 6202 temp--;
6388 } 6203 }
6389 } 6204 }
@@ -6395,9 +6210,9 @@ SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6395 temp = ((tempbx >> 5) & 0x38) | ((tempcx >> 8) & 0x07); 6210 temp = ((tempbx >> 5) & 0x38) | ((tempcx >> 8) & 0x07);
6396 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,temp); /* Overflow */ 6211 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,temp); /* Overflow */
6397 6212
6398 if((HwInfo->jChipType >= SIS_315H) && (HwInfo->jChipType < SIS_661)) { 6213 if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) {
6399 tempbx++; 6214 tempbx++;
6400 tempax = tempbx; 6215 tempax = tempbx;
6401 tempcx++; 6216 tempcx++;
6402 tempcx -= tempax; 6217 tempcx -= tempax;
6403 tempcx >>= 2; 6218 tempcx >>= 2;
@@ -6407,8 +6222,8 @@ SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6407 tempcx += tempbx; 6222 tempcx += tempbx;
6408 tempcx++; 6223 tempcx++;
6409 } else { 6224 } else {
6410 tempbx = (SiS_Pr->SiS_VGAVT + SiS_Pr->SiS_VGAVDE) >> 1; /* BTVGA2VRS 0x10,0x11 */ 6225 tempbx = (SiS_Pr->SiS_VGAVT + SiS_Pr->SiS_VGAVDE) >> 1; /* BTVGA2VRS 0x10,0x11 */
6411 tempcx = ((SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) >> 4) + tempbx + 1; /* BTVGA2VRE 0x11 */ 6226 tempcx = ((SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) >> 4) + tempbx + 1; /* BTVGA2VRE 0x11 */
6412 } 6227 }
6413 6228
6414 if(SiS_Pr->SiS_VBType & VB_SISVB) { 6229 if(SiS_Pr->SiS_VBType & VB_SISVB) {
@@ -6416,7 +6231,7 @@ SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6416 tempbx = SiS_Pr->CVSyncStart; 6231 tempbx = SiS_Pr->CVSyncStart;
6417 tempcx = SiS_Pr->CVSyncEnd; 6232 tempcx = SiS_Pr->CVSyncEnd;
6418 } 6233 }
6419 if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { 6234 if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
6420 unsigned char cr8, cr7, cr13; 6235 unsigned char cr8, cr7, cr13;
6421 if(SiS_Pr->UseCustomMode) { 6236 if(SiS_Pr->UseCustomMode) {
6422 cr8 = SiS_Pr->CCRT1CRTC[8]; 6237 cr8 = SiS_Pr->CCRT1CRTC[8];
@@ -6429,11 +6244,11 @@ SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6429 cr13 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13]; 6244 cr13 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13];
6430 tempcx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[9]; 6245 tempcx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[9];
6431 } 6246 }
6432 tempbx = cr8; 6247 tempbx = cr8;
6433 if(cr7 & 0x04) tempbx |= 0x0100; 6248 if(cr7 & 0x04) tempbx |= 0x0100;
6434 if(cr7 & 0x80) tempbx |= 0x0200; 6249 if(cr7 & 0x80) tempbx |= 0x0200;
6435 if(cr13 & 0x08) tempbx |= 0x0400; 6250 if(cr13 & 0x08) tempbx |= 0x0400;
6436 } 6251 }
6437 } 6252 }
6438 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x10,tempbx); /* CRT2 Vertical Retrace Start */ 6253 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x10,tempbx); /* CRT2 Vertical Retrace Start */
6439 6254
@@ -6442,13 +6257,13 @@ SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6442 6257
6443 /* 3. Panel delay compensation */ 6258 /* 3. Panel delay compensation */
6444 6259
6445 if(HwInfo->jChipType < SIS_315H) { 6260 if(SiS_Pr->ChipType < SIS_315H) {
6446 6261
6447#ifdef SIS300 /* ---------- 300 series -------------- */ 6262#ifdef SIS300 /* ---------- 300 series -------------- */
6448 6263
6449 if(SiS_Pr->SiS_VBType & VB_SISVB) { 6264 if(SiS_Pr->SiS_VBType & VB_SISVB) {
6450 temp = 0x20; 6265 temp = 0x20;
6451 if(HwInfo->jChipType == SIS_300) { 6266 if(SiS_Pr->ChipType == SIS_300) {
6452 temp = 0x10; 6267 temp = 0x10;
6453 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) temp = 0x2c; 6268 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) temp = 0x2c;
6454 if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20; 6269 if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20;
@@ -6460,24 +6275,23 @@ SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6460 if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) temp = 0x2c; 6275 if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) temp = 0x2c;
6461 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x08; 6276 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x08;
6462 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { 6277 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
6463 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) temp = 0x2c; 6278 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) temp = 0x2c;
6464 else temp = 0x20; 6279 else temp = 0x20;
6465 } 6280 }
6466 if(SiS_Pr->SiS_UseROM) { 6281 if(SiS_Pr->SiS_UseROM) {
6467 if(ROMAddr[0x220] & 0x80) { 6282 if(ROMAddr[0x220] & 0x80) {
6468 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision) 6283 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision)
6469 temp = ROMAddr[0x221]; 6284 temp = ROMAddr[0x221];
6470 else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) 6285 else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision)
6471 temp = ROMAddr[0x222]; 6286 temp = ROMAddr[0x222];
6472 else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) 6287 else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)
6473 temp = ROMAddr[0x223]; 6288 temp = ROMAddr[0x223];
6474 else 6289 else
6475 temp = ROMAddr[0x224]; 6290 temp = ROMAddr[0x224];
6476 temp &= 0x3c;
6477 } 6291 }
6478 } 6292 }
6479 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 6293 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
6480 if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC & 0x3c; 6294 if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC;
6481 } 6295 }
6482 6296
6483 } else { 6297 } else {
@@ -6487,15 +6301,17 @@ SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6487 } 6301 }
6488 if(SiS_Pr->SiS_UseROM) { 6302 if(SiS_Pr->SiS_UseROM) {
6489 if(ROMAddr[0x220] & 0x80) { 6303 if(ROMAddr[0x220] & 0x80) {
6490 temp = ROMAddr[0x220] & 0x3c; 6304 temp = ROMAddr[0x220];
6491 } 6305 }
6492 } 6306 }
6493 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 6307 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
6494 if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC & 0x3c; 6308 if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC;
6495 } 6309 }
6496 } 6310 }
6497 6311
6498 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* Panel Link Delay Compensation; (Software Command Reset; Power Saving) */ 6312 temp &= 0x3c;
6313
6314 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* Panel Link Delay Compensation; (Software Command Reset; Power Saving) */
6499 6315
6500#endif /* SIS300 */ 6316#endif /* SIS300 */
6501 6317
@@ -6503,16 +6319,16 @@ SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6503 6319
6504#ifdef SIS315H /* --------------- 315/330 series ---------------*/ 6320#ifdef SIS315H /* --------------- 315/330 series ---------------*/
6505 6321
6506 if(HwInfo->jChipType < SIS_661) { 6322 if(SiS_Pr->ChipType < SIS_661) {
6507 6323
6508 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 6324 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
6509 6325
6510 if(HwInfo->jChipType == SIS_740) temp = 0x03; 6326 if(SiS_Pr->ChipType == SIS_740) temp = 0x03;
6511 else temp = 0x00; 6327 else temp = 0x00;
6512 6328
6513 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x0a; 6329 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x0a;
6514 tempbl = 0xF0; 6330 tempbl = 0xF0;
6515 if(HwInfo->jChipType == SIS_650) { 6331 if(SiS_Pr->ChipType == SIS_650) {
6516 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 6332 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
6517 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempbl = 0x0F; 6333 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempbl = 0x0F;
6518 } 6334 }
@@ -6531,10 +6347,10 @@ SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6531 6347
6532 } /* < 661 */ 6348 } /* < 661 */
6533 6349
6534 tempax = 0; 6350 tempax = 0;
6535 if(modeflag & DoubleScanMode) tempax |= 0x80; 6351 if(modeflag & DoubleScanMode) tempax |= 0x80;
6536 if(modeflag & HalfDCLK) tempax |= 0x40; 6352 if(modeflag & HalfDCLK) tempax |= 0x40;
6537 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2C,0x3f,tempax); 6353 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2C,0x3f,tempax);
6538 6354
6539#endif /* SIS315H */ 6355#endif /* SIS315H */
6540 6356
@@ -6544,21 +6360,21 @@ SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6544 6360
6545 if(SiS_Pr->SiS_VBType & VB_SISVB) { 6361 if(SiS_Pr->SiS_VBType & VB_SISVB) {
6546 if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { 6362 if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
6547 /* For 301BDH with LCD, we set up the Panel Link */ 6363 /* For 301BDH with LCD, we set up the Panel Link */
6548 SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, RefreshRateTableIndex); 6364 SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
6549 } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { 6365 } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
6550 SiS_SetGroup1_301(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, RefreshRateTableIndex); 6366 SiS_SetGroup1_301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
6551 } 6367 }
6552 } else { 6368 } else {
6553 if(HwInfo->jChipType < SIS_315H) { 6369 if(SiS_Pr->ChipType < SIS_315H) {
6554 SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, RefreshRateTableIndex); 6370 SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
6555 } else { 6371 } else {
6556 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 6372 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
6557 if((!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) || (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { 6373 if((!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) || (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
6558 SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex, HwInfo,RefreshRateTableIndex); 6374 SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,RefreshRateTableIndex);
6559 } 6375 }
6560 } else { 6376 } else {
6561 SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex, HwInfo,RefreshRateTableIndex); 6377 SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,RefreshRateTableIndex);
6562 } 6378 }
6563 } 6379 }
6564 } 6380 }
@@ -6569,11 +6385,11 @@ SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6569/*********************************************/ 6385/*********************************************/
6570 6386
6571#ifdef SIS315H 6387#ifdef SIS315H
6572static UCHAR * 6388static unsigned char *
6573SiS_GetGroup2CLVXPtr(SiS_Private *SiS_Pr, int tabletype, PSIS_HW_INFO HwInfo) 6389SiS_GetGroup2CLVXPtr(struct SiS_Private *SiS_Pr, int tabletype)
6574{ 6390{
6575 const UCHAR *tableptr = NULL; 6391 const unsigned char *tableptr = NULL;
6576 USHORT a, b, p = 0; 6392 unsigned short a, b, p = 0;
6577 6393
6578 a = SiS_Pr->SiS_VGAHDE; 6394 a = SiS_Pr->SiS_VGAHDE;
6579 b = SiS_Pr->SiS_HDE; 6395 b = SiS_Pr->SiS_HDE;
@@ -6606,25 +6422,25 @@ SiS_GetGroup2CLVXPtr(SiS_Private *SiS_Pr, int tabletype, PSIS_HW_INFO HwInfo)
6606 if((tableptr[p] | tableptr[p+1] << 8) == 0xffff) p -= 0x42; 6422 if((tableptr[p] | tableptr[p+1] << 8) == 0xffff) p -= 0x42;
6607 } 6423 }
6608 p += 2; 6424 p += 2;
6609 return((UCHAR *)&tableptr[p]); 6425 return ((unsigned char *)&tableptr[p]);
6610} 6426}
6611 6427
6612static void 6428static void
6613SiS_SetGroup2_C_ELV(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 6429SiS_SetGroup2_C_ELV(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
6614 USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo) 6430 unsigned short RefreshRateTableIndex)
6615{ 6431{
6616 UCHAR *tableptr; 6432 unsigned char *tableptr;
6433 unsigned char temp;
6617 int i, j; 6434 int i, j;
6618 UCHAR temp;
6619 6435
6620 if(!(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302ELV))) return; 6436 if(!(SiS_Pr->SiS_VBType & VB_SISTAP4SCALER)) return;
6621 6437
6622 tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 0, HwInfo); 6438 tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 0);
6623 for(i = 0x80, j = 0; i <= 0xbf; i++, j++) { 6439 for(i = 0x80, j = 0; i <= 0xbf; i++, j++) {
6624 SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]); 6440 SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]);
6625 } 6441 }
6626 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 6442 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
6627 tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 1, HwInfo); 6443 tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 1);
6628 for(i = 0xc0, j = 0; i <= 0xff; i++, j++) { 6444 for(i = 0xc0, j = 0; i <= 0xff; i++, j++) {
6629 SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]); 6445 SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]);
6630 } 6446 }
@@ -6635,12 +6451,12 @@ SiS_SetGroup2_C_ELV(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
6635} 6451}
6636 6452
6637static BOOLEAN 6453static BOOLEAN
6638SiS_GetCRT2Part2Ptr(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex, 6454SiS_GetCRT2Part2Ptr(struct SiS_Private *SiS_Pr,unsigned short ModeNo,unsigned short ModeIdIndex,
6639 USHORT RefreshRateTableIndex,USHORT *CRT2Index, 6455 unsigned short RefreshRateTableIndex,unsigned short *CRT2Index,
6640 USHORT *ResIndex,PSIS_HW_INFO HwInfo) 6456 unsigned short *ResIndex)
6641{ 6457{
6642 6458
6643 if(HwInfo->jChipType < SIS_315H) return FALSE; 6459 if(SiS_Pr->ChipType < SIS_315H) return FALSE;
6644 6460
6645 if(ModeNo <= 0x13) 6461 if(ModeNo <= 0x13)
6646 (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; 6462 (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
@@ -6661,82 +6477,79 @@ SiS_GetCRT2Part2Ptr(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
6661 if(SiS_Pr->SiS_SetFlag & LCDVESATiming) (*CRT2Index) = 206; 6477 if(SiS_Pr->SiS_SetFlag & LCDVESATiming) (*CRT2Index) = 206;
6662 } 6478 }
6663 } 6479 }
6664 return(((*CRT2Index) != 0)); 6480 return (((*CRT2Index) != 0));
6665} 6481}
6666#endif 6482#endif
6667 6483
6668#ifdef SIS300 6484#ifdef SIS300
6669static void 6485static void
6670SiS_Group2LCDSpecial(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo, USHORT crt2crtc) 6486SiS_Group2LCDSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short crt2crtc)
6671{ 6487{
6672 USHORT tempcx; 6488 unsigned short tempcx;
6673 const UCHAR atable[] = { 6489 static const unsigned char atable[] = {
6674 0xc3,0x9e,0xc3,0x9e,0x02,0x02,0x02, 6490 0xc3,0x9e,0xc3,0x9e,0x02,0x02,0x02,
6675 0xab,0x87,0xab,0x9e,0xe7,0x02,0x02 6491 0xab,0x87,0xab,0x9e,0xe7,0x02,0x02
6676 }; 6492 };
6677 6493
6678 if(!SiS_Pr->UseCustomMode) { 6494 if(!SiS_Pr->UseCustomMode) {
6679 if( ( ( (HwInfo->jChipType == SIS_630) || 6495 if( ( ( (SiS_Pr->ChipType == SIS_630) ||
6680 (HwInfo->jChipType == SIS_730) ) && 6496 (SiS_Pr->ChipType == SIS_730) ) &&
6681 (HwInfo->jChipRevision > 2) ) && 6497 (SiS_Pr->ChipRevision > 2) ) &&
6682 (SiS_Pr->SiS_LCDResInfo == Panel_1024x768) && 6498 (SiS_Pr->SiS_LCDResInfo == Panel_1024x768) &&
6683 (!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) && 6499 (!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) &&
6684 (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ) { 6500 (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ) {
6685 if(ModeNo == 0x13) { 6501 if(ModeNo == 0x13) {
6686 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xB9); 6502 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xB9);
6687 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0xCC); 6503 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0xCC);
6688 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xA6); 6504 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xA6);
6689 } else { 6505 } else if((crt2crtc & 0x3F) == 4) {
6690 if((crt2crtc & 0x3F) == 4) { 6506 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x2B);
6691 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x2B); 6507 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x13);
6692 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x13); 6508 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xE5);
6693 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xE5); 6509 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0x08);
6694 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0x08); 6510 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xE2);
6695 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xE2); 6511 }
6696 }
6697 }
6698 } 6512 }
6699 6513
6700 if(HwInfo->jChipType < SIS_315H) { 6514 if(SiS_Pr->ChipType < SIS_315H) {
6701 if(SiS_Pr->SiS_LCDTypeInfo == 0x0c) { 6515 if(SiS_Pr->SiS_LCDTypeInfo == 0x0c) {
6702 crt2crtc &= 0x1f; 6516 crt2crtc &= 0x1f;
6703 tempcx = 0; 6517 tempcx = 0;
6704 if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) { 6518 if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
6705 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { 6519 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
6706 tempcx += 7; 6520 tempcx += 7;
6707 } 6521 }
6708 } 6522 }
6709 tempcx += crt2crtc; 6523 tempcx += crt2crtc;
6710 if(crt2crtc >= 4) { 6524 if(crt2crtc >= 4) {
6711 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xff); 6525 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xff);
6712 } 6526 }
6713 6527
6714 if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) { 6528 if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
6715 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { 6529 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
6716 if(crt2crtc == 4) { 6530 if(crt2crtc == 4) {
6717 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x28); 6531 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x28);
6718 } 6532 }
6719 } 6533 }
6720 } 6534 }
6721 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x18); 6535 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x18);
6722 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,atable[tempcx]); 6536 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,atable[tempcx]);
6723 } 6537 }
6724 } 6538 }
6725 } 6539 }
6726} 6540}
6727 6541
6728/* For ECS A907. Highly preliminary. */ 6542/* For ECS A907. Highly preliminary. */
6729static void 6543static void
6730SiS_Set300Part2Regs(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 6544SiS_Set300Part2Regs(struct SiS_Private *SiS_Pr, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex,
6731 USHORT ModeIdIndex, USHORT RefreshRateTableIndex, 6545 unsigned short ModeNo)
6732 USHORT ModeNo)
6733{ 6546{
6734 USHORT crt2crtc, resindex; 6547 const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL;
6735 int i,j; 6548 unsigned short crt2crtc, resindex;
6736 const SiS_Part2PortTblStruct *CRT2Part2Ptr = NULL; 6549 int i, j;
6737 6550
6738 if(HwInfo->jChipType != SIS_300) return; 6551 if(SiS_Pr->ChipType != SIS_300) return;
6739 if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) return; 6552 if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) return;
6740 if(SiS_Pr->UseCustomMode) return; 6553 if(SiS_Pr->UseCustomMode) return;
6741 6554
6742 if(ModeNo <= 0x13) { 6555 if(ModeNo <= 0x13) {
@@ -6758,13 +6571,13 @@ SiS_Set300Part2Regs(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
6758 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]); 6571 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
6759 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]); 6572 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]);
6760 for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) { 6573 for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) {
6761 SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]); 6574 SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
6762 } 6575 }
6763 for(j = 0x1c; j <= 0x1d; i++, j++ ) { 6576 for(j = 0x1c; j <= 0x1d; i++, j++ ) {
6764 SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]); 6577 SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
6765 } 6578 }
6766 for(j = 0x1f; j <= 0x21; i++, j++ ) { 6579 for(j = 0x1f; j <= 0x21; i++, j++ ) {
6767 SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]); 6580 SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
6768 } 6581 }
6769 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]); 6582 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]);
6770 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]); 6583 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]);
@@ -6772,15 +6585,15 @@ SiS_Set300Part2Regs(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
6772#endif 6585#endif
6773 6586
6774static void 6587static void
6775SiS_SetTVSpecial(SiS_Private *SiS_Pr, USHORT ModeNo) 6588SiS_SetTVSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
6776{ 6589{
6777 if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) return; 6590 if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) return;
6778 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision)) return; 6591 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision)) return;
6779 if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) return; 6592 if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) return;
6780 6593
6781 if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { 6594 if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
6782 if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) { 6595 if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
6783 const UCHAR specialtv[] = { 6596 const unsigned char specialtv[] = {
6784 0xa7,0x07,0xf2,0x6e,0x17,0x8b,0x73,0x53, 6597 0xa7,0x07,0xf2,0x6e,0x17,0x8b,0x73,0x53,
6785 0x13,0x40,0x34,0xf4,0x63,0xbb,0xcc,0x7a, 6598 0x13,0x40,0x34,0xf4,0x63,0xbb,0xcc,0x7a,
6786 0x58,0xe4,0x73,0xda,0x13 6599 0x58,0xe4,0x73,0xda,0x13
@@ -6813,16 +6626,16 @@ SiS_SetTVSpecial(SiS_Private *SiS_Pr, USHORT ModeNo)
6813} 6626}
6814 6627
6815static void 6628static void
6816SiS_SetGroup2_Tail(SiS_Private *SiS_Pr, USHORT ModeNo) 6629SiS_SetGroup2_Tail(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
6817{ 6630{
6818 USHORT temp; 6631 unsigned short temp;
6819 6632
6820 if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) { 6633 if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
6821 if(SiS_Pr->SiS_VGAVDE == 525) { 6634 if(SiS_Pr->SiS_VGAVDE == 525) {
6822 temp = 0xc3; 6635 temp = 0xc3;
6823 if(SiS_Pr->SiS_ModeType <= ModeVGA) { 6636 if(SiS_Pr->SiS_ModeType <= ModeVGA) {
6824 temp++; 6637 temp++;
6825 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) temp += 2; 6638 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) temp += 2;
6826 } 6639 }
6827 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp); 6640 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
6828 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,0xb3); 6641 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,0xb3);
@@ -6830,7 +6643,7 @@ SiS_SetGroup2_Tail(SiS_Private *SiS_Pr, USHORT ModeNo)
6830 temp = 0x4d; 6643 temp = 0x4d;
6831 if(SiS_Pr->SiS_ModeType <= ModeVGA) { 6644 if(SiS_Pr->SiS_ModeType <= ModeVGA) {
6832 temp++; 6645 temp++;
6833 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) temp++; 6646 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) temp++;
6834 } 6647 }
6835 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp); 6648 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
6836 } 6649 }
@@ -6838,7 +6651,7 @@ SiS_SetGroup2_Tail(SiS_Private *SiS_Pr, USHORT ModeNo)
6838 6651
6839 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 6652 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
6840 if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) { 6653 if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) {
6841 if(SiS_Pr->SiS_VBType & VB_SIS301B302B) { 6654 if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
6842 SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x1a,0x03); 6655 SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x1a,0x03);
6843 /* Not always for LV, see SetGrp2 */ 6656 /* Not always for LV, see SetGrp2 */
6844 } 6657 }
@@ -6872,17 +6685,17 @@ SiS_SetGroup2_Tail(SiS_Private *SiS_Pr, USHORT ModeNo)
6872} 6685}
6873 6686
6874static void 6687static void
6875SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT RefreshRateTableIndex, 6688SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
6876 PSIS_HW_INFO HwInfo) 6689 unsigned short RefreshRateTableIndex)
6877{ 6690{
6878 USHORT i, j, tempax, tempbx, tempcx, tempch, tempcl, temp; 6691 unsigned short i, j, tempax, tempbx, tempcx, tempch, tempcl, temp;
6879 USHORT push2, modeflag, crt2crtc, bridgeoffset; 6692 unsigned short push2, modeflag, crt2crtc, bridgeoffset;
6880 ULONG longtemp; 6693 unsigned int longtemp, PhaseIndex;
6881 const UCHAR *PhasePoint; 6694 BOOLEAN newtvphase;
6882 const UCHAR *TimingPoint; 6695 const unsigned char *TimingPoint;
6883#ifdef SIS315H 6696#ifdef SIS315H
6884 USHORT resindex, CRT2Index; 6697 unsigned short resindex, CRT2Index;
6885 const SiS_Part2PortTblStruct *CRT2Part2Ptr = NULL; 6698 const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL;
6886 6699
6887 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return; 6700 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
6888#endif 6701#endif
@@ -6908,9 +6721,16 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
6908 6721
6909 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x00,temp); 6722 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x00,temp);
6910 6723
6911 PhasePoint = SiS_Pr->SiS_PALPhase; 6724 PhaseIndex = 0x01; /* SiS_PALPhase */
6912 TimingPoint = SiS_Pr->SiS_PALTiming; 6725 TimingPoint = SiS_Pr->SiS_PALTiming;
6913 6726
6727 newtvphase = FALSE;
6728 if( (SiS_Pr->SiS_VBType & VB_SIS30xBLV) &&
6729 ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
6730 (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) {
6731 newtvphase = TRUE;
6732 }
6733
6914 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { 6734 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
6915 6735
6916 TimingPoint = SiS_Pr->SiS_HiTVExtTiming; 6736 TimingPoint = SiS_Pr->SiS_HiTVExtTiming;
@@ -6918,82 +6738,54 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
6918 TimingPoint = SiS_Pr->SiS_HiTVSt2Timing; 6738 TimingPoint = SiS_Pr->SiS_HiTVSt2Timing;
6919 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) { 6739 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
6920 TimingPoint = SiS_Pr->SiS_HiTVSt1Timing; 6740 TimingPoint = SiS_Pr->SiS_HiTVSt1Timing;
6921#if 0
6922 if(!(modeflag & Charx8Dot)) TimingPoint = SiS_Pr->SiS_HiTVTextTiming;
6923#endif
6924 } 6741 }
6925 } 6742 }
6926 6743
6927 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { 6744 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
6928 6745
6929 if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) TimingPoint = &SiS_YPbPrTable[2][0]; 6746 i = 0;
6930 else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) TimingPoint = &SiS_YPbPrTable[1][0]; 6747 if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) i = 2;
6931 else TimingPoint = &SiS_YPbPrTable[0][0]; 6748 else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) i = 1;
6749
6750 TimingPoint = &SiS_YPbPrTable[i][0];
6932 6751
6933 PhasePoint = SiS_Pr->SiS_NTSCPhase; 6752 PhaseIndex = 0x00; /* SiS_NTSCPhase */
6934 6753
6935 } else if(SiS_Pr->SiS_TVMode & TVSetPAL) { 6754 } else if(SiS_Pr->SiS_TVMode & TVSetPAL) {
6936 6755
6937 if( (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && 6756 if(newtvphase) PhaseIndex = 0x09; /* SiS_PALPhase2 */
6938 ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
6939 (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) {
6940 PhasePoint = SiS_Pr->SiS_PALPhase2;
6941 }
6942 6757
6943 } else { 6758 } else {
6944 6759
6945 TimingPoint = SiS_Pr->SiS_NTSCTiming; 6760 TimingPoint = SiS_Pr->SiS_NTSCTiming;
6946 PhasePoint = SiS_Pr->SiS_NTSCPhase; 6761 PhaseIndex = (SiS_Pr->SiS_TVMode & TVSetNTSCJ) ? 0x01 : 0x00; /* SiS_PALPhase : SiS_NTSCPhase */
6947 if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) { 6762 if(newtvphase) PhaseIndex += 8; /* SiS_PALPhase2 : SiS_NTSCPhase2 */
6948 PhasePoint = SiS_Pr->SiS_PALPhase;
6949 }
6950
6951 if( (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) &&
6952 ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
6953 (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) {
6954 PhasePoint = SiS_Pr->SiS_NTSCPhase2;
6955 if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) {
6956 PhasePoint = SiS_Pr->SiS_PALPhase2;
6957 }
6958 }
6959
6960 }
6961 6763
6962 if(SiS_Pr->SiS_TVMode & TVSetPALM) {
6963 PhasePoint = SiS_Pr->SiS_PALMPhase;
6964 if( (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) &&
6965 ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
6966 (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) {
6967 PhasePoint = SiS_Pr->SiS_PALMPhase2;
6968 }
6969 } 6764 }
6970 6765
6971 if(SiS_Pr->SiS_TVMode & TVSetPALN) { 6766 if(SiS_Pr->SiS_TVMode & (TVSetPALM | TVSetPALN)) {
6972 PhasePoint = SiS_Pr->SiS_PALNPhase; 6767 PhaseIndex = (SiS_Pr->SiS_TVMode & TVSetPALM) ? 0x02 : 0x03; /* SiS_PALMPhase : SiS_PALNPhase */
6973 if( (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && 6768 if(newtvphase) PhaseIndex += 8; /* SiS_PALMPhase2 : SiS_PALNPhase2 */
6974 ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
6975 (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) {
6976 PhasePoint = SiS_Pr->SiS_PALNPhase2;
6977 }
6978 } 6769 }
6979 6770
6980 if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) { 6771 if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
6981 PhasePoint = SiS_Pr->SiS_SpecialPhase;
6982 if(SiS_Pr->SiS_TVMode & TVSetPALM) { 6772 if(SiS_Pr->SiS_TVMode & TVSetPALM) {
6983 PhasePoint = SiS_Pr->SiS_SpecialPhaseM; 6773 PhaseIndex = 0x05; /* SiS_SpecialPhaseM */
6984 } else if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) { 6774 } else if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) {
6985 PhasePoint = SiS_Pr->SiS_SpecialPhaseJ; 6775 PhaseIndex = 0x11; /* SiS_SpecialPhaseJ */
6776 } else {
6777 PhaseIndex = 0x10; /* SiS_SpecialPhase */
6986 } 6778 }
6987 } 6779 }
6988 6780
6989 for(i=0x31, j=0; i<=0x34; i++, j++) { 6781 for(i = 0x31, j = 0; i <= 0x34; i++, j++) {
6990 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,PhasePoint[j]); 6782 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS_TVPhase[(PhaseIndex * 4) + j]);
6991 } 6783 }
6992 6784
6993 for(i=0x01, j=0; i<=0x2D; i++, j++) { 6785 for(i = 0x01, j = 0; i <= 0x2D; i++, j++) {
6994 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]); 6786 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
6995 } 6787 }
6996 for(i=0x39; i<=0x45; i++, j++) { 6788 for(i = 0x39; i <= 0x45; i++, j++) {
6997 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]); 6789 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
6998 } 6790 }
6999 6791
@@ -7010,28 +6802,32 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7010 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x37,SiS_Pr->SiS_RY3COE); 6802 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x37,SiS_Pr->SiS_RY3COE);
7011 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x38,SiS_Pr->SiS_RY4COE); 6803 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x38,SiS_Pr->SiS_RY4COE);
7012 6804
7013 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempax = 950; 6805 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempax = 950;
7014 else if(SiS_Pr->SiS_TVMode & TVSetPAL) tempax = 520; 6806 else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempax = 680;
7015 else tempax = 440; /* NTSC, YPbPr 525, 750 */ 6807 else if(SiS_Pr->SiS_TVMode & TVSetPAL) tempax = 520;
6808 else tempax = 440; /* NTSC, YPbPr 525 */
7016 6809
7017 if( ( (!(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision)) && (SiS_Pr->SiS_VDE <= tempax) ) || 6810 if( ((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) && (SiS_Pr->SiS_VDE <= tempax)) ||
7018 ( (SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) && 6811 ( (SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) &&
7019 ((SiS_Pr->SiS_VGAHDE == 1024) || (SiS_Pr->SiS_VDE <= tempax)) ) ) { 6812 ((SiS_Pr->SiS_VGAHDE == 1024) || (SiS_Pr->SiS_VDE <= tempax)) ) ) {
7020 6813
7021 tempax -= SiS_Pr->SiS_VDE; 6814 tempax -= SiS_Pr->SiS_VDE;
7022 tempax >>= 2; 6815 tempax >>= 1;
6816 if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) {
6817 tempax >>= 1;
6818 }
7023 tempax &= 0x00ff; 6819 tempax &= 0x00ff;
7024 6820
7025 temp = tempax + (USHORT)TimingPoint[0]; 6821 temp = tempax + (unsigned short)TimingPoint[0];
7026 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp); 6822 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
7027 6823
7028 temp = tempax + (USHORT)TimingPoint[1]; 6824 temp = tempax + (unsigned short)TimingPoint[1];
7029 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp); 6825 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
7030 6826
7031 if((SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision) && (SiS_Pr->SiS_VGAHDE >= 1024)) { 6827 if((SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision) && (SiS_Pr->SiS_VGAHDE >= 1024)) {
7032 if(SiS_Pr->SiS_TVMode & TVSetPAL) { 6828 if(SiS_Pr->SiS_TVMode & TVSetPAL) {
7033 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b); /* 19 */ 6829 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b);
7034 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54); /* 52 */ 6830 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54);
7035 } else { 6831 } else {
7036 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x17); 6832 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x17);
7037 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1d); 6833 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1d);
@@ -7041,14 +6837,14 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7041 } 6837 }
7042 6838
7043 tempcx = SiS_Pr->SiS_HT; 6839 tempcx = SiS_Pr->SiS_HT;
7044 if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempcx >>= 1; 6840 if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
7045 tempcx--; 6841 tempcx--;
7046 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) tempcx--; 6842 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) tempcx--;
7047 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1B,tempcx); 6843 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1B,tempcx);
7048 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0xF0,((tempcx >> 8) & 0x0f)); 6844 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0xF0,((tempcx >> 8) & 0x0f));
7049 6845
7050 tempcx = SiS_Pr->SiS_HT >> 1; 6846 tempcx = SiS_Pr->SiS_HT >> 1;
7051 if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempcx >>= 1; 6847 if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
7052 tempcx += 7; 6848 tempcx += 7;
7053 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4; 6849 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4;
7054 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x22,0x0F,((tempcx << 4) & 0xf0)); 6850 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x22,0x0F,((tempcx << 4) & 0xf0));
@@ -7075,7 +6871,7 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7075 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2A,0x0F,((tempcx << 4) & 0xf0)); 6871 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2A,0x0F,((tempcx << 4) & 0xf0));
7076 6872
7077 tempcx = SiS_Pr->SiS_HT >> 1; 6873 tempcx = SiS_Pr->SiS_HT >> 1;
7078 if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempcx >>= 1; 6874 if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
7079 j += 2; 6875 j += 2;
7080 tempcx -= (TimingPoint[j] | ((TimingPoint[j+1]) << 8)); 6876 tempcx -= (TimingPoint[j] | ((TimingPoint[j+1]) << 8));
7081 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2D,0x0F,((tempcx << 4) & 0xf0)); 6877 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2D,0x0F,((tempcx << 4) & 0xf0));
@@ -7094,7 +6890,7 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7094 } else if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) && 6890 } else if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
7095 (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p|TVSetYPbPr750p))) ) { 6891 (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p|TVSetYPbPr750p))) ) {
7096 tempbx >>= 1; 6892 tempbx >>= 1;
7097 if(HwInfo->jChipType >= SIS_315H) { 6893 if(SiS_Pr->ChipType >= SIS_315H) {
7098 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) { 6894 if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
7099 if((ModeNo <= 0x13) && (crt2crtc == 1)) tempbx++; 6895 if((ModeNo <= 0x13) && (crt2crtc == 1)) tempbx++;
7100 } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { 6896 } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
@@ -7123,23 +6919,11 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7123 } 6919 }
7124 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,temp); 6920 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,temp);
7125 6921
7126 if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302LV | VB_SIS302ELV)) { 6922 if(SiS_Pr->SiS_VBType & VB_SISPART4OVERFLOW) {
7127 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xdf,((tempbx & 0x0400) >> 5)); 6923 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xdf,((tempbx & 0x0400) >> 5));
7128 } 6924 }
7129 6925
7130#if 0 6926 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
7131 /* TEST qqqq */
7132 if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
7133 for(i=0x01, j=0; i<=0x2D; i++, j++) {
7134 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
7135 }
7136 for(i=0x39; i<=0x45; i++, j++) {
7137 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
7138 }
7139 }
7140#endif
7141
7142 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
7143 tempbx = SiS_Pr->SiS_VDE; 6927 tempbx = SiS_Pr->SiS_VDE;
7144 if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) && 6928 if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
7145 (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) ) { 6929 (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) ) {
@@ -7150,7 +6934,7 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7150 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x46,temp); 6934 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x46,temp);
7151 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x47,tempbx); 6935 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x47,tempbx);
7152 6936
7153 if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302LV | VB_SIS302ELV)) { 6937 if(SiS_Pr->SiS_VBType & VB_SISPART4OVERFLOW) {
7154 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xbf,((tempbx & 0x0400) >> 4)); 6938 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xbf,((tempbx & 0x0400) >> 4));
7155 } 6939 }
7156 } 6940 }
@@ -7165,14 +6949,17 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7165 6949
7166 tempch = tempcl = 0x01; 6950 tempch = tempcl = 0x01;
7167 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 6951 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
7168 if(SiS_Pr->SiS_VGAHDE >= 1024) { 6952 if(SiS_Pr->SiS_VGAHDE >= 960) {
7169 if((!(modeflag & HalfDCLK)) || (HwInfo->jChipType < SIS_315H)) { 6953 if((!(modeflag & HalfDCLK)) || (SiS_Pr->ChipType < SIS_315H)) {
7170 tempch = 0x19;
7171 tempcl = 0x20; 6954 tempcl = 0x20;
7172 if(SiS_Pr->SiS_VGAHDE >= 1280) { 6955 if(SiS_Pr->SiS_VGAHDE >= 1280) {
7173 tempch = 0x14; 6956 tempch = 20;
7174 tempbx &= ~0x20; 6957 tempbx &= ~0x20;
7175 } 6958 } else if(SiS_Pr->SiS_VGAHDE >= 1024) {
6959 tempch = 25;
6960 } else {
6961 tempch = 25; /* OK */
6962 }
7176 } 6963 }
7177 } 6964 }
7178 } 6965 }
@@ -7180,7 +6967,7 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7180 if(!(tempbx & 0x20)) { 6967 if(!(tempbx & 0x20)) {
7181 if(modeflag & HalfDCLK) tempcl <<= 1; 6968 if(modeflag & HalfDCLK) tempcl <<= 1;
7182 longtemp = ((SiS_Pr->SiS_VGAHDE * tempch) / tempcl) << 13; 6969 longtemp = ((SiS_Pr->SiS_VGAHDE * tempch) / tempcl) << 13;
7183 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) longtemp <<= 3; 6970 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) longtemp <<= 3;
7184 tempax = longtemp / SiS_Pr->SiS_HDE; 6971 tempax = longtemp / SiS_Pr->SiS_HDE;
7185 if(longtemp % SiS_Pr->SiS_HDE) tempax++; 6972 if(longtemp % SiS_Pr->SiS_HDE) tempax++;
7186 tempbx |= ((tempax >> 8) & 0x1F); 6973 tempbx |= ((tempax >> 8) & 0x1F);
@@ -7190,7 +6977,7 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7190 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x44,tempax); 6977 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x44,tempax);
7191 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x45,0xC0,tempbx); 6978 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x45,0xC0,tempbx);
7192 6979
7193 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 6980 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
7194 6981
7195 tempcx &= 0x07; 6982 tempcx &= 0x07;
7196 if(tempbx & 0x20) tempcx = 0; 6983 if(tempbx & 0x20) tempcx = 0;
@@ -7219,7 +7006,7 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7219 7006
7220 SiS_SetTVSpecial(SiS_Pr, ModeNo); 7007 SiS_SetTVSpecial(SiS_Pr, ModeNo);
7221 7008
7222 if(SiS_Pr->SiS_VBType & VB_SIS301C) { 7009 if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
7223 temp = 0; 7010 temp = 0;
7224 if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8; 7011 if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8;
7225 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xf7,temp); 7012 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xf7,temp);
@@ -7246,7 +7033,7 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7246 /* From here: Part2 LCD setup */ 7033 /* From here: Part2 LCD setup */
7247 7034
7248 tempbx = SiS_Pr->SiS_HDE; 7035 tempbx = SiS_Pr->SiS_HDE;
7249 if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempbx >>= 1; 7036 if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
7250 tempbx--; /* RHACTE = HDE - 1 */ 7037 tempbx--; /* RHACTE = HDE - 1 */
7251 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2C,tempbx); 7038 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2C,tempbx);
7252 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2B,0x0F,((tempbx >> 4) & 0xf0)); 7039 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2B,0x0F,((tempbx >> 4) & 0xf0));
@@ -7256,10 +7043,8 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7256 if(SiS_Pr->SiS_ModeType == ModeEGA) { 7043 if(SiS_Pr->SiS_ModeType == ModeEGA) {
7257 if(SiS_Pr->SiS_VGAHDE >= 1024) { 7044 if(SiS_Pr->SiS_VGAHDE >= 1024) {
7258 temp = 0x02; 7045 temp = 0x02;
7259 if(HwInfo->jChipType >= SIS_315H) { 7046 if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
7260 if(SiS_Pr->SiS_SetFlag & LCDVESATiming) { 7047 temp = 0x01;
7261 temp = 0x01;
7262 }
7263 } 7048 }
7264 } 7049 }
7265 } 7050 }
@@ -7289,11 +7074,11 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7289 7074
7290#ifdef SIS315H 7075#ifdef SIS315H
7291 if(SiS_GetCRT2Part2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, 7076 if(SiS_GetCRT2Part2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
7292 &CRT2Index, &resindex, HwInfo)) { 7077 &CRT2Index, &resindex)) {
7293 switch(CRT2Index) { 7078 switch(CRT2Index) {
7079 case 206: CRT2Part2Ptr = SiS310_CRT2Part2_Asus1024x768_3; break;
7080 default:
7294 case 200: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1; break; 7081 case 200: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1; break;
7295 case 206: CRT2Part2Ptr = SiS310_CRT2Part2_Asus1024x768_3; break;
7296 default: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_3; break;
7297 } 7082 }
7298 7083
7299 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]); 7084 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
@@ -7312,7 +7097,6 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7312 7097
7313 SiS_SetGroup2_Tail(SiS_Pr, ModeNo); 7098 SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
7314 7099
7315
7316 } else { 7100 } else {
7317#endif 7101#endif
7318 7102
@@ -7349,9 +7133,11 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7349 7133
7350 /* Non-expanding: lcdvdes = tempcx = VT-1; lcdvdee = tempbx = VDE-1 */ 7134 /* Non-expanding: lcdvdes = tempcx = VT-1; lcdvdee = tempbx = VDE-1 */
7351 7135
7136#ifdef SIS_XORG_XF86
7352#ifdef TWDEBUG 7137#ifdef TWDEBUG
7353 xf86DrvMsg(0, X_INFO, "lcdvdes 0x%x lcdvdee 0x%x\n", tempcx, tempbx); 7138 xf86DrvMsg(0, X_INFO, "lcdvdes 0x%x lcdvdee 0x%x\n", tempcx, tempbx);
7354#endif 7139#endif
7140#endif
7355 7141
7356 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,tempcx); /* lcdvdes */ 7142 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,tempcx); /* lcdvdes */
7357 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,tempbx); /* lcdvdee */ 7143 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,tempbx); /* lcdvdee */
@@ -7401,9 +7187,11 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7401 tempbx = SiS_Pr->CVSyncStart; 7187 tempbx = SiS_Pr->CVSyncStart;
7402 } 7188 }
7403 7189
7190#ifdef SIS_XORG_XF86
7404#ifdef TWDEBUG 7191#ifdef TWDEBUG
7405 xf86DrvMsg(0, X_INFO, "lcdvrs 0x%x\n", tempbx); 7192 xf86DrvMsg(0, X_INFO, "lcdvrs 0x%x\n", tempbx);
7406#endif 7193#endif
7194#endif
7407 7195
7408 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,tempbx); /* lcdvrs */ 7196 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,tempbx); /* lcdvrs */
7409 7197
@@ -7416,26 +7204,30 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7416 temp |= (SiS_Pr->CVSyncEnd & 0x0f); 7204 temp |= (SiS_Pr->CVSyncEnd & 0x0f);
7417 } 7205 }
7418 7206
7207#ifdef SIS_XORG_XF86
7419#ifdef TWDEBUG 7208#ifdef TWDEBUG
7420 xf86DrvMsg(0, X_INFO, "lcdvre[3:0] 0x%x\n", (temp & 0x0f)); 7209 xf86DrvMsg(0, X_INFO, "lcdvre[3:0] 0x%x\n", (temp & 0x0f));
7421#endif 7210#endif
7211#endif
7422 7212
7423 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp); 7213 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
7424 7214
7425#ifdef SIS300 7215#ifdef SIS300
7426 SiS_Group2LCDSpecial(SiS_Pr, HwInfo, ModeNo, crt2crtc); 7216 SiS_Group2LCDSpecial(SiS_Pr, ModeNo, crt2crtc);
7427#endif 7217#endif
7428 7218
7429 bridgeoffset = 7; 7219 bridgeoffset = 7;
7430 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) bridgeoffset += 2; 7220 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) bridgeoffset += 2;
7431 if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302ELV)) bridgeoffset++; 7221 if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) bridgeoffset += 2; /* OK for Averatec 1280x800 (301C) */
7432 if(SiS_IsDualLink(SiS_Pr, HwInfo)) bridgeoffset++; 7222 if(SiS_IsDualLink(SiS_Pr)) bridgeoffset++;
7223 else if(SiS_Pr->SiS_VBType & VB_SIS302LV) bridgeoffset++; /* OK for Asus A4L 1280x800 */
7224 /* Higher bridgeoffset shifts to the LEFT */
7433 7225
7434 temp = 0; 7226 temp = 0;
7435 if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) { 7227 if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
7436 if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) { 7228 if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) {
7437 temp = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2); 7229 temp = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
7438 if(SiS_IsDualLink(SiS_Pr, HwInfo)) temp >>= 1; 7230 if(SiS_IsDualLink(SiS_Pr)) temp >>= 1;
7439 } 7231 }
7440 } 7232 }
7441 temp += bridgeoffset; 7233 temp += bridgeoffset;
@@ -7450,15 +7242,17 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7450 tempbx = SiS_Pr->PanelXRes - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2); 7242 tempbx = SiS_Pr->PanelXRes - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
7451 } 7243 }
7452 } 7244 }
7453 if(SiS_IsDualLink(SiS_Pr, HwInfo)) { 7245 if(SiS_IsDualLink(SiS_Pr)) {
7454 tempcx >>= 1; 7246 tempcx >>= 1;
7455 tempbx >>= 1; 7247 tempbx >>= 1;
7456 tempax >>= 1; 7248 tempax >>= 1;
7457 } 7249 }
7458 7250
7251#ifdef SIS_XORG_XF86
7459#ifdef TWDEBUG 7252#ifdef TWDEBUG
7460 xf86DrvMsg(0, X_INFO, "lcdhdee 0x%x\n", tempbx); 7253 xf86DrvMsg(0, X_INFO, "lcdhdee 0x%x\n", tempbx);
7461#endif 7254#endif
7255#endif
7462 7256
7463 tempbx += bridgeoffset; 7257 tempbx += bridgeoffset;
7464 7258
@@ -7480,13 +7274,16 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7480 7274
7481 if(SiS_Pr->UseCustomMode) { 7275 if(SiS_Pr->UseCustomMode) {
7482 tempbx = SiS_Pr->CHSyncStart; 7276 tempbx = SiS_Pr->CHSyncStart;
7483 if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempbx >>= 1; 7277 if(modeflag & HalfDCLK) tempbx <<= 1;
7278 if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
7484 tempbx += bridgeoffset; 7279 tempbx += bridgeoffset;
7485 } 7280 }
7486 7281
7282#ifdef SIS_XORG_XF86
7487#ifdef TWDEBUG 7283#ifdef TWDEBUG
7488 xf86DrvMsg(0, X_INFO, "lcdhrs 0x%x\n", tempbx); 7284 xf86DrvMsg(0, X_INFO, "lcdhrs 0x%x\n", tempbx);
7489#endif 7285#endif
7286#endif
7490 7287
7491 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1C,tempbx); /* lcdhrs */ 7288 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1C,tempbx); /* lcdhrs */
7492 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0x0F,((tempbx >> 4) & 0xf0)); 7289 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0x0F,((tempbx >> 4) & 0xf0));
@@ -7501,20 +7298,23 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7501 7298
7502 if(SiS_Pr->UseCustomMode) { 7299 if(SiS_Pr->UseCustomMode) {
7503 tempbx = SiS_Pr->CHSyncEnd; 7300 tempbx = SiS_Pr->CHSyncEnd;
7504 if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempbx >>= 1; 7301 if(modeflag & HalfDCLK) tempbx <<= 1;
7302 if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
7505 tempbx += bridgeoffset; 7303 tempbx += bridgeoffset;
7506 } 7304 }
7507 7305
7306#ifdef SIS_XORG_XF86
7508#ifdef TWDEBUG 7307#ifdef TWDEBUG
7509 xf86DrvMsg(0, X_INFO, "lcdhre 0x%x\n", tempbx); 7308 xf86DrvMsg(0, X_INFO, "lcdhre 0x%x\n", tempbx);
7510#endif 7309#endif
7310#endif
7511 7311
7512 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x21,tempbx); /* lcdhre */ 7312 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x21,tempbx); /* lcdhre */
7513 7313
7514 SiS_SetGroup2_Tail(SiS_Pr, ModeNo); 7314 SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
7515 7315
7516#ifdef SIS300 7316#ifdef SIS300
7517 SiS_Set300Part2Regs(SiS_Pr, HwInfo, ModeIdIndex, RefreshRateTableIndex, ModeNo); 7317 SiS_Set300Part2Regs(SiS_Pr, ModeIdIndex, RefreshRateTableIndex, ModeNo);
7518#endif 7318#endif
7519#ifdef SIS315H 7319#ifdef SIS315H
7520 } /* CRT2-LCD from table */ 7320 } /* CRT2-LCD from table */
@@ -7526,11 +7326,10 @@ SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT Refr
7526/*********************************************/ 7326/*********************************************/
7527 7327
7528static void 7328static void
7529SiS_SetGroup3(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 7329SiS_SetGroup3(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
7530 PSIS_HW_INFO HwInfo)
7531{ 7330{
7532 USHORT i; 7331 unsigned short i;
7533 const UCHAR *tempdi; 7332 const unsigned char *tempdi;
7534 7333
7535 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return; 7334 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
7536 7335
@@ -7570,7 +7369,7 @@ SiS_SetGroup3(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
7570 for(i=0; i<=0x3E; i++) { 7369 for(i=0; i<=0x3E; i++) {
7571 SiS_SetReg(SiS_Pr->SiS_Part3Port,i,tempdi[i]); 7370 SiS_SetReg(SiS_Pr->SiS_Part3Port,i,tempdi[i]);
7572 } 7371 }
7573 if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302ELV)) { 7372 if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
7574 if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) { 7373 if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
7575 SiS_SetReg(SiS_Pr->SiS_Part3Port,0x28,0x3f); 7374 SiS_SetReg(SiS_Pr->SiS_Part3Port,0x28,0x3f);
7576 } 7375 }
@@ -7587,35 +7386,43 @@ SiS_SetGroup3(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
7587/*********************************************/ 7386/*********************************************/
7588 7387
7589#ifdef SIS315H 7388#ifdef SIS315H
7389#if 0
7590static void 7390static void
7591SiS_ShiftXPos(SiS_Private *SiS_Pr, int shift) 7391SiS_ShiftXPos(struct SiS_Private *SiS_Pr, int shift)
7592{ 7392{
7593 USHORT temp, temp1, temp2; 7393 unsigned short temp, temp1, temp2;
7594 7394
7595 temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x1f); 7395 temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x1f);
7596 temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x20); 7396 temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x20);
7597 temp = (USHORT)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift); 7397 temp = (unsigned short)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
7598 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1f,temp); 7398 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1f,temp);
7599 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0f,((temp >> 4) & 0xf0)); 7399 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0f,((temp >> 4) & 0xf0));
7600 temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x2b) & 0x0f; 7400 temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x2b) & 0x0f;
7601 temp = (USHORT)((int)(temp) + shift); 7401 temp = (unsigned short)((int)(temp) + shift);
7602 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2b,0xf0,(temp & 0x0f)); 7402 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2b,0xf0,(temp & 0x0f));
7603 temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43); 7403 temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43);
7604 temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x42); 7404 temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x42);
7605 temp = (USHORT)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift); 7405 temp = (unsigned short)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
7606 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,temp); 7406 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,temp);
7607 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x42,0x0f,((temp >> 4) & 0xf0)); 7407 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x42,0x0f,((temp >> 4) & 0xf0));
7608} 7408}
7409#endif
7609 7410
7610static void 7411static void
7611SiS_SetGroup4_C_ELV(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 7412SiS_SetGroup4_C_ELV(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
7612 USHORT ModeNo, USHORT ModeIdIndex)
7613{ 7413{
7614 USHORT temp, temp1, resinfo = 0; 7414 unsigned short temp, temp1, resinfo = 0;
7415 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
7615 7416
7616 if(!(SiS_Pr->SiS_VBType & VB_SIS301C)) return; 7417 if(!(SiS_Pr->SiS_VBType & VB_SIS30xCLV)) return;
7617 if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToHiVision | SetCRT2ToYPbPr525750))) return; 7418 if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToHiVision | SetCRT2ToYPbPr525750))) return;
7618 7419
7420 if(SiS_Pr->ChipType >= XGI_20) return;
7421
7422 if((SiS_Pr->ChipType >= SIS_661) && (SiS_Pr->SiS_ROMNew)) {
7423 if(!(ROMAddr[0x61] & 0x04)) return;
7424 }
7425
7619 if(ModeNo > 0x13) { 7426 if(ModeNo > 0x13) {
7620 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; 7427 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
7621 } 7428 }
@@ -7625,7 +7432,7 @@ SiS_SetGroup4_C_ELV(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
7625 if(!(temp & 0x01)) { 7432 if(!(temp & 0x01)) {
7626 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3a,0xdf); 7433 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3a,0xdf);
7627 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xfc); 7434 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xfc);
7628 if((HwInfo->jChipType < SIS_661) && (!(SiS_Pr->SiS_ROMNew))) { 7435 if((SiS_Pr->ChipType < SIS_661) && (!(SiS_Pr->SiS_ROMNew))) {
7629 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xf8); 7436 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xf8);
7630 } 7437 }
7631 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x0f,0xfb); 7438 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x0f,0xfb);
@@ -7633,24 +7440,29 @@ SiS_SetGroup4_C_ELV(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
7633 else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp = 0x0002; 7440 else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp = 0x0002;
7634 else if(SiS_Pr->SiS_TVMode & TVSetHiVision) temp = 0x0400; 7441 else if(SiS_Pr->SiS_TVMode & TVSetHiVision) temp = 0x0400;
7635 else temp = 0x0402; 7442 else temp = 0x0402;
7636 if((HwInfo->jChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) { 7443 if((SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
7637 temp1 = 0; 7444 temp1 = 0;
7638 if(SiS_Pr->SiS_TVMode & TVAspect43) temp1 = 4; 7445 if(SiS_Pr->SiS_TVMode & TVAspect43) temp1 = 4;
7639 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0f,0xfb,temp1); 7446 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0f,0xfb,temp1);
7640 if(SiS_Pr->SiS_TVMode & TVAspect43LB) temp |= 0x01; 7447 if(SiS_Pr->SiS_TVMode & TVAspect43LB) temp |= 0x01;
7641 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0x7c,(temp & 0xff)); 7448 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0x7c,(temp & 0xff));
7449 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8));
7450 if(ModeNo > 0x13) {
7451 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x39,0xfd);
7452 }
7642 } else { 7453 } else {
7643 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x3b) & 0x03; 7454 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x3b) & 0x03;
7644 if(temp1 == 0x01) temp |= 0x01; 7455 if(temp1 == 0x01) temp |= 0x01;
7645 if(temp1 == 0x03) temp |= 0x04; /* ? why not 0x10? */ 7456 if(temp1 == 0x03) temp |= 0x04; /* ? why not 0x10? */
7646 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xf8,(temp & 0xff)); 7457 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xf8,(temp & 0xff));
7647 } 7458 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8));
7648 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8)); 7459 if(ModeNo > 0x13) {
7649 if(ModeNo > 0x13) { 7460 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3b,0xfd);
7650 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3b,0xfd); 7461 }
7651 } 7462 }
7652 7463
7653 if(HwInfo->jChipType >= SIS_661) { /* ? */ 7464#if 0
7465 if(SiS_Pr->ChipType >= SIS_661) { /* ? */
7654 if(SiS_Pr->SiS_TVMode & TVAspect43) { 7466 if(SiS_Pr->SiS_TVMode & TVAspect43) {
7655 if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) { 7467 if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
7656 if(resinfo == SIS_RI_1024x768) { 7468 if(resinfo == SIS_RI_1024x768) {
@@ -7663,29 +7475,30 @@ SiS_SetGroup4_C_ELV(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
7663 } 7475 }
7664 } 7476 }
7665 } 7477 }
7478#endif
7479
7666 } 7480 }
7481
7667} 7482}
7668#endif 7483#endif
7669 7484
7670static void 7485static void
7671SiS_SetCRT2VCLK(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 7486SiS_SetCRT2VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
7672 USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo) 7487 unsigned short RefreshRateTableIndex)
7673{ 7488{
7674 USHORT vclkindex; 7489 unsigned short vclkindex, temp, reg1, reg2;
7675 USHORT temp, reg1, reg2;
7676 7490
7677 if(SiS_Pr->UseCustomMode) { 7491 if(SiS_Pr->UseCustomMode) {
7678 reg1 = SiS_Pr->CSR2B; 7492 reg1 = SiS_Pr->CSR2B;
7679 reg2 = SiS_Pr->CSR2C; 7493 reg2 = SiS_Pr->CSR2C;
7680 } else { 7494 } else {
7681 vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, 7495 vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
7682 HwInfo);
7683 reg1 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_A; 7496 reg1 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_A;
7684 reg2 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_B; 7497 reg2 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_B;
7685 } 7498 }
7686 7499
7687 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 7500 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
7688 if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) { 7501 if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSet525p1024)) {
7689 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x57); 7502 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x57);
7690 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,0x46); 7503 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,0x46);
7691 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1f,0xf6); 7504 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1f,0xf6);
@@ -7705,11 +7518,35 @@ SiS_SetCRT2VCLK(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
7705} 7518}
7706 7519
7707static void 7520static void
7708SiS_SetGroup4(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 7521SiS_SetDualLinkEtc(struct SiS_Private *SiS_Pr)
7709 USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo) 7522{
7523 if(SiS_Pr->ChipType >= SIS_315H) {
7524 if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
7525 if((SiS_CRT2IsLCD(SiS_Pr)) ||
7526 (SiS_IsVAMode(SiS_Pr))) {
7527 if(SiS_Pr->SiS_LCDInfo & LCDDualLink) {
7528 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x2c);
7529 } else {
7530 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,~0x20);
7531 }
7532 }
7533 }
7534 }
7535 if(SiS_Pr->SiS_VBType & VB_SISEMI) {
7536 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
7537#ifdef SET_EMI
7538 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
7539#endif
7540 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
7541 }
7542}
7543
7544static void
7545SiS_SetGroup4(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
7546 unsigned short RefreshRateTableIndex)
7710{ 7547{
7711 USHORT tempax,tempcx,tempbx,modeflag,temp,resinfo; 7548 unsigned short tempax, tempcx, tempbx, modeflag, temp, resinfo;
7712 ULONG tempebx,tempeax,templong; 7549 unsigned int tempebx, tempeax, templong;
7713 7550
7714 if(ModeNo <= 0x13) { 7551 if(ModeNo <= 0x13) {
7715 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; 7552 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
@@ -7722,38 +7559,24 @@ SiS_SetGroup4(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
7722 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; 7559 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
7723 } 7560 }
7724 7561
7725 if(HwInfo->jChipType >= SIS_315H) { 7562 if(SiS_Pr->ChipType >= SIS_315H) {
7726 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 7563 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
7727 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { 7564 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
7728 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e); 7565 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e);
7729 } 7566 }
7730 } 7567 }
7731 } 7568 }
7732 7569
7733 if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302LV)) { 7570 if(SiS_Pr->SiS_VBType & (VB_SIS30xCLV | VB_SIS302LV)) {
7734 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 7571 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
7735 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x10,0x9f); 7572 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x10,0x9f);
7736 } 7573 }
7737 } 7574 }
7738 7575
7739 if(HwInfo->jChipType >= SIS_315H) { 7576 if(SiS_Pr->ChipType >= SIS_315H) {
7740 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { 7577 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
7741 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 7578 SiS_SetDualLinkEtc(SiS_Pr);
7742 if(SiS_IsDualLink(SiS_Pr, HwInfo)) { 7579 return;
7743 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x2c);
7744 } else {
7745 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,~0x20);
7746 }
7747
7748 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
7749 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
7750#ifdef SET_EMI
7751 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
7752#endif
7753 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
7754 }
7755 }
7756 return;
7757 } 7580 }
7758 } 7581 }
7759 7582
@@ -7777,16 +7600,16 @@ SiS_SetGroup4(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
7777 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x15,temp); 7600 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x15,temp);
7778 7601
7779 tempbx = SiS_Pr->SiS_VGAHDE; 7602 tempbx = SiS_Pr->SiS_VGAHDE;
7780 if(modeflag & HalfDCLK) tempbx >>= 1; 7603 if(modeflag & HalfDCLK) tempbx >>= 1;
7781 if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempbx >>= 1; 7604 if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
7782 7605
7783 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 7606 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
7784 temp = 0; 7607 temp = 0;
7785 if(tempbx > 800) temp = 0x60; 7608 if(tempbx > 800) temp = 0x60;
7786 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { 7609 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
7787 temp = 0; 7610 temp = 0;
7788 if(tempbx == 1024) temp = 0xA0; 7611 if(tempbx > 1024) temp = 0xC0;
7789 else if(tempbx > 1024) temp = 0xC0; 7612 else if(tempbx >= 960) temp = 0xA0;
7790 } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) { 7613 } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
7791 temp = 0; 7614 temp = 0;
7792 if(tempbx >= 1280) temp = 0x40; 7615 if(tempbx >= 1280) temp = 0x40;
@@ -7796,8 +7619,13 @@ SiS_SetGroup4(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
7796 if(tempbx >= 1024) temp = 0xA0; 7619 if(tempbx >= 1024) temp = 0xA0;
7797 } 7620 }
7798 7621
7622 temp |= SiS_Pr->Init_P4_0E;
7623
7799 if(SiS_Pr->SiS_VBType & VB_SIS301) { 7624 if(SiS_Pr->SiS_VBType & VB_SIS301) {
7800 if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) temp |= 0x0A; 7625 if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) {
7626 temp &= 0xf0;
7627 temp |= 0x0A;
7628 }
7801 } 7629 }
7802 7630
7803 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0E,0x10,temp); 7631 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0E,0x10,temp);
@@ -7824,15 +7652,15 @@ SiS_SetGroup4(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
7824 tempeax /= tempebx; 7652 tempeax /= tempebx;
7825 if(templong) tempeax++; 7653 if(templong) tempeax++;
7826 7654
7827 temp = (USHORT)(tempeax & 0x000000FF); 7655 temp = (unsigned short)(tempeax & 0x000000FF);
7828 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1B,temp); 7656 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1B,temp);
7829 temp = (USHORT)((tempeax & 0x0000FF00) >> 8); 7657 temp = (unsigned short)((tempeax & 0x0000FF00) >> 8);
7830 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1A,temp); 7658 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1A,temp);
7831 temp = (USHORT)((tempeax >> 12) & 0x70); /* sic! */ 7659 temp = (unsigned short)((tempeax >> 12) & 0x70); /* sic! */
7832 temp |= (tempcx & 0x4F); 7660 temp |= (tempcx & 0x4F);
7833 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x19,temp); 7661 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x19,temp);
7834 7662
7835 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 7663 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
7836 7664
7837 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1C,0x28); 7665 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1C,0x28);
7838 7666
@@ -7840,23 +7668,26 @@ SiS_SetGroup4(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
7840 tempbx = 0; 7668 tempbx = 0;
7841 if(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p)) tempbx = 0x08; 7669 if(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p)) tempbx = 0x08;
7842 tempax = SiS_Pr->SiS_VGAHDE; 7670 tempax = SiS_Pr->SiS_VGAHDE;
7843 if(modeflag & HalfDCLK) tempax >>= 1; 7671 if(modeflag & HalfDCLK) tempax >>= 1;
7844 if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempax >>= 1; 7672 if(SiS_IsDualLink(SiS_Pr)) tempax >>= 1;
7845 if(tempax > 800) { 7673 if(tempax > 800) {
7846 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 7674 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
7847 tempax -= 800; 7675 tempax -= 800;
7848 } else { /* 651+301C: Only if TVNoHiviNoYPbPr */ 7676 } else {
7849 tempbx = 0x08; 7677 tempbx = 0x08;
7850 if(tempax == 1024) tempax *= 25; 7678 if(tempax == 960) tempax *= 25; /* Correct */
7851 else tempax *= 20; 7679 else if(tempax == 1024) tempax *= 25;
7680 else tempax *= 20;
7852 temp = tempax % 32; 7681 temp = tempax % 32;
7853 tempax /= 32; 7682 tempax /= 32;
7854 if(temp) tempax++; 7683 if(temp) tempax++;
7855 tempax++; 7684 tempax++;
7856 if((SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision) || 7685 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
7857 (SiS_Pr->SiS_TVMode & TVSetYPbPr525i)) { 7686 if(resinfo == SIS_RI_1024x768 ||
7858 if(resinfo == SIS_RI_1024x768) { 7687 resinfo == SIS_RI_1024x576 ||
7859 /* Otherwise white line at right edge */ 7688 resinfo == SIS_RI_1280x1024 ||
7689 resinfo == SIS_RI_1280x720) {
7690 /* Otherwise white line or garbage at right edge */
7860 tempax = (tempax & 0xff00) | 0x20; 7691 tempax = (tempax & 0xff00) | 0x20;
7861 } 7692 }
7862 } 7693 }
@@ -7868,7 +7699,7 @@ SiS_SetGroup4(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
7868 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1E,temp); 7699 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1E,temp);
7869 7700
7870 temp = 0x0036; tempbx = 0xD0; 7701 temp = 0x0036; tempbx = 0xD0;
7871 if((HwInfo->jChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) { 7702 if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
7872 temp = 0x0026; tempbx = 0xC0; /* See En/DisableBridge() */ 7703 temp = 0x0026; tempbx = 0xC0; /* See En/DisableBridge() */
7873 } 7704 }
7874 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 7705 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
@@ -7884,36 +7715,24 @@ SiS_SetGroup4(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
7884 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x1F,tempbx,temp); 7715 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x1F,tempbx,temp);
7885 7716
7886 tempbx = SiS_Pr->SiS_HT >> 1; 7717 tempbx = SiS_Pr->SiS_HT >> 1;
7887 if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempbx >>= 1; 7718 if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
7888 tempbx -= 2; 7719 tempbx -= 2;
7889 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x22,tempbx); 7720 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x22,tempbx);
7890 temp = (tempbx >> 5) & 0x38; 7721 temp = (tempbx >> 5) & 0x38;
7891 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0xC0,temp); 7722 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0xC0,temp);
7892 7723
7893 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 7724 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
7894 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 7725 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
7895 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e); 7726 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e);
7896 /* LCD-too-dark-error-source, see FinalizeLCD() */ 7727 /* LCD-too-dark-error-source, see FinalizeLCD() */
7897 } 7728 }
7898 if(HwInfo->jChipType >= SIS_315H) {
7899 if(SiS_IsDualLink(SiS_Pr, HwInfo)) {
7900 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x2c);
7901 } else {
7902 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,~0x20);
7903 }
7904 }
7905 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
7906 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
7907#ifdef SET_EMI
7908 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
7909#endif
7910 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
7911 }
7912 } 7729 }
7913 7730
7731 SiS_SetDualLinkEtc(SiS_Pr);
7732
7914 } /* 301B */ 7733 } /* 301B */
7915 7734
7916 SiS_SetCRT2VCLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo); 7735 SiS_SetCRT2VCLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
7917} 7736}
7918 7737
7919/*********************************************/ 7738/*********************************************/
@@ -7921,8 +7740,7 @@ SiS_SetGroup4(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
7921/*********************************************/ 7740/*********************************************/
7922 7741
7923static void 7742static void
7924SiS_SetGroup5(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 7743SiS_SetGroup5(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
7925 PSIS_HW_INFO HwInfo)
7926{ 7744{
7927 7745
7928 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return; 7746 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
@@ -7930,7 +7748,7 @@ SiS_SetGroup5(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
7930 if(SiS_Pr->SiS_ModeType == ModeVGA) { 7748 if(SiS_Pr->SiS_ModeType == ModeVGA) {
7931 if(!(SiS_Pr->SiS_VBInfo & (SetInSlaveMode | LoadDACFlag))) { 7749 if(!(SiS_Pr->SiS_VBInfo & (SetInSlaveMode | LoadDACFlag))) {
7932 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); 7750 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
7933 SiS_LoadDAC(SiS_Pr, HwInfo, ModeNo, ModeIdIndex); 7751 SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex);
7934 } 7752 }
7935 } 7753 }
7936} 7754}
@@ -7939,116 +7757,156 @@ SiS_SetGroup5(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
7939/* MODIFY CRT1 GROUP FOR SLAVE MODE */ 7757/* MODIFY CRT1 GROUP FOR SLAVE MODE */
7940/*********************************************/ 7758/*********************************************/
7941 7759
7942static void 7760static BOOLEAN
7943SiS_ModCRT1CRTC(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 7761SiS_GetLVDSCRT1Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
7944 USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo) 7762 unsigned short RefreshRateTableIndex, unsigned short *ResIndex,
7945{ 7763 unsigned short *DisplayType)
7946 USHORT tempah,i,modeflag,j; 7764 {
7947 USHORT ResIndex,DisplayType; 7765 unsigned short modeflag = 0;
7948 const SiS_LVDSCRT1DataStruct *LVDSCRT1Ptr=NULL; 7766 BOOLEAN checkhd = TRUE;
7949 7767
7950 if(ModeNo <= 0x13) modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; 7768 /* Pass 1:1 not supported here */
7951 else modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 7769
7770 if(ModeNo <= 0x13) {
7771 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
7772 (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
7773 } else {
7774 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
7775 (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
7776 }
7777
7778 (*ResIndex) &= 0x3F;
7779
7780 if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
7781
7782 (*DisplayType) = 80;
7783 if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) {
7784 (*DisplayType) = 82;
7785 if(SiS_Pr->SiS_ModeType > ModeVGA) {
7786 if(SiS_Pr->SiS_CHSOverScan) (*DisplayType) = 84;
7787 }
7788 }
7789 if((*DisplayType) != 84) {
7790 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*DisplayType)++;
7791 }
7792
7793 } else {
7794
7795 (*DisplayType = 0);
7796 switch(SiS_Pr->SiS_LCDResInfo) {
7797 case Panel_320x240_1: (*DisplayType) = 50;
7798 checkhd = FALSE;
7799 break;
7800 case Panel_320x240_2: (*DisplayType) = 14;
7801 break;
7802 case Panel_320x240_3: (*DisplayType) = 18;
7803 break;
7804 case Panel_640x480: (*DisplayType) = 10;
7805 break;
7806 case Panel_1024x600: (*DisplayType) = 26;
7807 break;
7808 default: return TRUE;
7809 }
7810
7811 if(checkhd) {
7812 if(modeflag & HalfDCLK) (*DisplayType)++;
7813 }
7814
7815 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) {
7816 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) (*DisplayType) += 2;
7817 }
7818
7819 }
7820
7821 return TRUE;
7822}
7823
7824static void
7825SiS_ModCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
7826 unsigned short RefreshRateTableIndex)
7827{
7828 unsigned short tempah, i, modeflag, j, ResIndex, DisplayType;
7829 const struct SiS_LVDSCRT1Data *LVDSCRT1Ptr=NULL;
7830 static const unsigned short CRIdx[] = {
7831 0x00, 0x02, 0x03, 0x04, 0x05, 0x06,
7832 0x07, 0x10, 0x11, 0x15, 0x16
7833 };
7952 7834
7953 if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || 7835 if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
7954 (SiS_Pr->SiS_CustomT == CUT_BARCO1024) || 7836 (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
7955 (SiS_Pr->SiS_CustomT == CUT_PANEL848)) 7837 (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
7838 (SiS_Pr->SiS_CustomT == CUT_PANEL856) )
7956 return; 7839 return;
7957 7840
7841 if(SiS_Pr->SiS_IF_DEF_LVDS) {
7842 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
7843 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return;
7844 }
7845 } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
7846 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return;
7847 } else return;
7848
7849 if(SiS_Pr->SiS_LCDInfo & LCDPass11) return;
7850
7851 if(SiS_Pr->ChipType < SIS_315H) {
7852 if(SiS_Pr->SiS_SetFlag & SetDOSMode) return;
7853 }
7854
7958 if(!(SiS_GetLVDSCRT1Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, 7855 if(!(SiS_GetLVDSCRT1Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
7959 &ResIndex, &DisplayType))) { 7856 &ResIndex, &DisplayType))) {
7960 return; 7857 return;
7961 } 7858 }
7962 7859
7963 if(HwInfo->jChipType < SIS_315H) { 7860 switch(DisplayType) {
7964 if(SiS_Pr->SiS_SetFlag & SetDOSMode) return; 7861 case 50: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_1; break; /* xSTN */
7862 case 14: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_2; break; /* xSTN */
7863 case 15: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_2_H; break; /* xSTN */
7864 case 18: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_3; break; /* xSTN */
7865 case 19: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_3_H; break; /* xSTN */
7866 case 10: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1; break;
7867 case 11: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1_H; break;
7868#if 0 /* Works better with calculated numbers */
7869 case 26: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1; break;
7870 case 27: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1_H; break;
7871 case 28: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2; break;
7872 case 29: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2_H; break;
7873#endif
7874 case 80: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UNTSC; break;
7875 case 81: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1ONTSC; break;
7876 case 82: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UPAL; break;
7877 case 83: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1OPAL; break;
7878 case 84: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1SOPAL; break;
7965 } 7879 }
7966 7880
7967 switch(DisplayType) { 7881 if(LVDSCRT1Ptr) {
7968 case 0 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_1; break; 7882
7969 case 1 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_1_H; break; 7883 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
7970 case 2 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_2; break; 7884
7971 case 3 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_2_H; break; 7885 for(i = 0; i <= 10; i++) {
7972 case 4 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1; break; 7886 tempah = (LVDSCRT1Ptr + ResIndex)->CR[i];
7973 case 5 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1_H; break; 7887 SiS_SetReg(SiS_Pr->SiS_P3d4,CRIdx[i],tempah);
7974 case 6 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_2; break; 7888 }
7975 case 7 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_2_H; break; 7889
7976 case 8 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_1; break; 7890 for(i = 0x0A, j = 11; i <= 0x0C; i++, j++) {
7977 case 9 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_1_H; break; 7891 tempah = (LVDSCRT1Ptr + ResIndex)->CR[j];
7978 case 10: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_2; break; 7892 SiS_SetReg(SiS_Pr->SiS_P3c4,i,tempah);
7979 case 11: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_2_H; break; 7893 }
7980 case 12: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1XXXxXXX_1; break; 7894
7981 case 13: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1XXXxXXX_1_H; break; 7895 tempah = (LVDSCRT1Ptr + ResIndex)->CR[14] & 0xE0;
7982 case 14: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_1; break; 7896 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0x1f,tempah);
7983 case 15: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_1_H; break; 7897
7984 case 16: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_2; break; 7898 if(ModeNo <= 0x13) modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
7985 case 17: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_2_H; break; 7899 else modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
7986 case 18: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UNTSC; break; 7900
7987 case 19: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1ONTSC; break; 7901 tempah = ((LVDSCRT1Ptr + ResIndex)->CR[14] & 0x01) << 5;
7988 case 20: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UPAL; break; 7902 if(modeflag & DoubleScanMode) tempah |= 0x80;
7989 case 21: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1OPAL; break; 7903 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,~0x020,tempah);
7990 case 22: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x480_1; break; /* FSTN */ 7904
7991 case 23: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1; break; 7905 } else {
7992 case 24: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1_H; break; 7906
7993 case 25: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2; break; 7907 SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex);
7994 case 26: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2_H; break; 7908
7995 case 27: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11152x768_1; break; 7909 }
7996 case 28: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11152x768_1_H; break;
7997 case 29: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11152x768_2; break;
7998 case 30: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11152x768_2_H; break;
7999 case 36: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11600x1200_1; break;
8000 case 37: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11600x1200_1_H; break;
8001 case 38: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11600x1200_2; break;
8002 case 39: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11600x1200_2_H; break;
8003 case 40: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x768_1; break;
8004 case 41: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x768_1_H; break;
8005 case 42: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x768_2; break;
8006 case 43: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x768_2_H; break;
8007 case 50: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1; break;
8008 case 51: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1_H; break;
8009 case 52: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_2; break;
8010 case 53: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_2_H; break;
8011 case 54: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_3; break;
8012 case 55: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_3_H; break;
8013 case 99: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1SOPAL; break;
8014 default: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1; break;
8015 }
8016
8017 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
8018
8019 tempah = (LVDSCRT1Ptr + ResIndex)->CR[0];
8020 SiS_SetReg(SiS_Pr->SiS_P3d4,0x00,tempah);
8021
8022 for(i=0x02,j=1;i<=0x05;i++,j++){
8023 tempah = (LVDSCRT1Ptr + ResIndex)->CR[j];
8024 SiS_SetReg(SiS_Pr->SiS_P3d4,i,tempah);
8025 }
8026 for(i=0x06,j=5;i<=0x07;i++,j++){
8027 tempah = (LVDSCRT1Ptr + ResIndex)->CR[j];
8028 SiS_SetReg(SiS_Pr->SiS_P3d4,i,tempah);
8029 }
8030 for(i=0x10,j=7;i<=0x11;i++,j++){
8031 tempah = (LVDSCRT1Ptr + ResIndex)->CR[j];
8032 SiS_SetReg(SiS_Pr->SiS_P3d4,i,tempah);
8033 }
8034 for(i=0x15,j=9;i<=0x16;i++,j++){
8035 tempah = (LVDSCRT1Ptr + ResIndex)->CR[j];
8036 SiS_SetReg(SiS_Pr->SiS_P3d4,i,tempah);
8037 }
8038 for(i=0x0A,j=11;i<=0x0C;i++,j++){
8039 tempah = (LVDSCRT1Ptr + ResIndex)->CR[j];
8040 SiS_SetReg(SiS_Pr->SiS_P3c4,i,tempah);
8041 }
8042
8043 tempah = (LVDSCRT1Ptr + ResIndex)->CR[14];
8044 tempah &= 0xE0;
8045 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0x1f,tempah);
8046
8047 tempah = (LVDSCRT1Ptr + ResIndex)->CR[14];
8048 tempah &= 0x01;
8049 tempah <<= 5;
8050 if(modeflag & DoubleScanMode) tempah |= 0x080;
8051 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,~0x020,tempah);
8052} 7910}
8053 7911
8054/*********************************************/ 7912/*********************************************/
@@ -8056,24 +7914,24 @@ SiS_ModCRT1CRTC(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
8056/*********************************************/ 7914/*********************************************/
8057 7915
8058static void 7916static void
8059SiS_SetCRT2ECLK(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 7917SiS_SetCRT2ECLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
8060 USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo) 7918 unsigned short RefreshRateTableIndex)
8061{ 7919{
8062 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 7920 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
8063 USHORT clkbase, vclkindex=0; 7921 unsigned short clkbase, vclkindex = 0;
8064 UCHAR sr2b, sr2c; 7922 unsigned char sr2b, sr2c;
8065 7923
8066 if((SiS_Pr->SiS_LCDResInfo == Panel_640x480) || (SiS_Pr->SiS_LCDInfo & LCDPass11)) { 7924 if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
8067 SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2); 7925 SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
8068 if((SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK & 0x3f) == 2) { 7926 if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK == 2) {
8069 RefreshRateTableIndex--; 7927 RefreshRateTableIndex--;
8070 } 7928 }
8071 vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, 7929 vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex,
8072 RefreshRateTableIndex, HwInfo); 7930 RefreshRateTableIndex);
8073 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2; 7931 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
8074 } else { 7932 } else {
8075 vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, 7933 vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex,
8076 RefreshRateTableIndex, HwInfo); 7934 RefreshRateTableIndex);
8077 } 7935 }
8078 7936
8079 sr2b = SiS_Pr->SiS_VCLKData[vclkindex].SR2B; 7937 sr2b = SiS_Pr->SiS_VCLKData[vclkindex].SR2B;
@@ -8082,7 +7940,7 @@ SiS_SetCRT2ECLK(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
8082 if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) { 7940 if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
8083 if(SiS_Pr->SiS_UseROM) { 7941 if(SiS_Pr->SiS_UseROM) {
8084 if(ROMAddr[0x220] & 0x01) { 7942 if(ROMAddr[0x220] & 0x01) {
8085 sr2b = ROMAddr[0x227]; 7943 sr2b = ROMAddr[0x227];
8086 sr2c = ROMAddr[0x228]; 7944 sr2c = ROMAddr[0x228];
8087 } 7945 }
8088 } 7946 }
@@ -8091,7 +7949,7 @@ SiS_SetCRT2ECLK(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
8091 clkbase = 0x02B; 7949 clkbase = 0x02B;
8092 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { 7950 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
8093 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { 7951 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
8094 clkbase += 3; 7952 clkbase += 3;
8095 } 7953 }
8096 } 7954 }
8097 7955
@@ -8111,368 +7969,331 @@ SiS_SetCRT2ECLK(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
8111/*********************************************/ 7969/*********************************************/
8112 7970
8113static void 7971static void
8114SiS_SetCHTVReg(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 7972SiS_SetCHTVReg(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
8115 USHORT RefreshRateTableIndex) 7973 unsigned short RefreshRateTableIndex)
8116{ 7974{
8117#if defined(SIS300) || defined(SIS315H) 7975 unsigned short TVType, resindex;
8118 USHORT temp, tempbx; 7976 const struct SiS_CHTVRegData *CHTVRegData = NULL;
8119#endif
8120 USHORT tempcl;
8121 USHORT TVType, resindex;
8122 const SiS_CHTVRegDataStruct *CHTVRegData = NULL;
8123 7977
8124 if(ModeNo <= 0x13) 7978 if(ModeNo <= 0x13)
8125 tempcl = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; 7979 resindex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
8126 else 7980 else
8127 tempcl = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; 7981 resindex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
8128 7982
8129 TVType = 0; 7983 resindex &= 0x3F;
8130 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1; 7984
8131 if(SiS_Pr->SiS_TVMode & TVSetPAL) { 7985 TVType = 0;
8132 TVType += 2; 7986 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
8133 if(SiS_Pr->SiS_ModeType > ModeVGA) { 7987 if(SiS_Pr->SiS_TVMode & TVSetPAL) {
8134 if(SiS_Pr->SiS_CHSOverScan) TVType = 8; 7988 TVType += 2;
8135 } 7989 if(SiS_Pr->SiS_ModeType > ModeVGA) {
8136 if(SiS_Pr->SiS_TVMode & TVSetPALM) { 7990 if(SiS_Pr->SiS_CHSOverScan) TVType = 8;
8137 TVType = 4; 7991 }
8138 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1; 7992 if(SiS_Pr->SiS_TVMode & TVSetPALM) {
8139 } else if(SiS_Pr->SiS_TVMode & TVSetPALN) { 7993 TVType = 4;
8140 TVType = 6; 7994 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
8141 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1; 7995 } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
8142 } 7996 TVType = 6;
8143 } 7997 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
8144 switch(TVType) { 7998 }
8145 case 0: CHTVRegData = SiS_Pr->SiS_CHTVReg_UNTSC; break; 7999 }
8146 case 1: CHTVRegData = SiS_Pr->SiS_CHTVReg_ONTSC; break; 8000
8147 case 2: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPAL; break; 8001 switch(TVType) {
8148 case 3: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break; 8002 case 0: CHTVRegData = SiS_Pr->SiS_CHTVReg_UNTSC; break;
8149 case 4: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALM; break; 8003 case 1: CHTVRegData = SiS_Pr->SiS_CHTVReg_ONTSC; break;
8150 case 5: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALM; break; 8004 case 2: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPAL; break;
8151 case 6: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALN; break; 8005 case 3: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break;
8152 case 7: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALN; break; 8006 case 4: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALM; break;
8153 case 8: CHTVRegData = SiS_Pr->SiS_CHTVReg_SOPAL; break; 8007 case 5: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALM; break;
8154 default: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break; 8008 case 6: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALN; break;
8155 } 8009 case 7: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALN; break;
8156 resindex = tempcl & 0x3F; 8010 case 8: CHTVRegData = SiS_Pr->SiS_CHTVReg_SOPAL; break;
8011 default: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break;
8012 }
8157 8013
8158 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { 8014
8015 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
8159 8016
8160#ifdef SIS300 8017#ifdef SIS300
8161 8018
8162 /* Chrontel 7005 - I assume that it does not come with a 315 series chip */ 8019 /* Chrontel 7005 - I assume that it does not come with a 315 series chip */
8163 8020
8164 /* We don't support modes >800x600 */ 8021 /* We don't support modes >800x600 */
8165 if (resindex > 5) return; 8022 if (resindex > 5) return;
8166 8023
8167 if(SiS_Pr->SiS_TVMode & TVSetPAL) { 8024 if(SiS_Pr->SiS_TVMode & TVSetPAL) {
8168 SiS_SetCH700x(SiS_Pr,0x4304); /* 0x40=76uA (PAL); 0x03=15bit non-multi RGB*/ 8025 SiS_SetCH700x(SiS_Pr,0x04,0x43); /* 0x40=76uA (PAL); 0x03=15bit non-multi RGB*/
8169 SiS_SetCH700x(SiS_Pr,0x6909); /* Black level for PAL (105)*/ 8026 SiS_SetCH700x(SiS_Pr,0x09,0x69); /* Black level for PAL (105)*/
8170 } else { 8027 } else {
8171 SiS_SetCH700x(SiS_Pr,0x0304); /* upper nibble=71uA (NTSC), 0x03=15bit non-multi RGB*/ 8028 SiS_SetCH700x(SiS_Pr,0x04,0x03); /* upper nibble=71uA (NTSC), 0x03=15bit non-multi RGB*/
8172 SiS_SetCH700x(SiS_Pr,0x7109); /* Black level for NTSC (113)*/ 8029 SiS_SetCH700x(SiS_Pr,0x09,0x71); /* Black level for NTSC (113)*/
8173 } 8030 }
8174 8031
8175 temp = CHTVRegData[resindex].Reg[0]; 8032 SiS_SetCH700x(SiS_Pr,0x00,CHTVRegData[resindex].Reg[0]); /* Mode register */
8176 tempbx=((temp&0x00FF)<<8)|0x00; /* Mode register */ 8033 SiS_SetCH700x(SiS_Pr,0x07,CHTVRegData[resindex].Reg[1]); /* Start active video register */
8177 SiS_SetCH700x(SiS_Pr,tempbx); 8034 SiS_SetCH700x(SiS_Pr,0x08,CHTVRegData[resindex].Reg[2]); /* Position overflow register */
8178 temp = CHTVRegData[resindex].Reg[1]; 8035 SiS_SetCH700x(SiS_Pr,0x0a,CHTVRegData[resindex].Reg[3]); /* Horiz Position register */
8179 tempbx=((temp&0x00FF)<<8)|0x07; /* Start active video register */ 8036 SiS_SetCH700x(SiS_Pr,0x0b,CHTVRegData[resindex].Reg[4]); /* Vertical Position register */
8180 SiS_SetCH700x(SiS_Pr,tempbx); 8037
8181 temp = CHTVRegData[resindex].Reg[2]; 8038 /* Set minimum flicker filter for Luma channel (SR1-0=00),
8182 tempbx=((temp&0x00FF)<<8)|0x08; /* Position overflow register */
8183 SiS_SetCH700x(SiS_Pr,tempbx);
8184 temp = CHTVRegData[resindex].Reg[3];
8185 tempbx=((temp&0x00FF)<<8)|0x0A; /* Horiz Position register */
8186 SiS_SetCH700x(SiS_Pr,tempbx);
8187 temp = CHTVRegData[resindex].Reg[4];
8188 tempbx=((temp&0x00FF)<<8)|0x0B; /* Vertical Position register */
8189 SiS_SetCH700x(SiS_Pr,tempbx);
8190
8191 /* Set minimum flicker filter for Luma channel (SR1-0=00),
8192 minimum text enhancement (S3-2=10), 8039 minimum text enhancement (S3-2=10),
8193 maximum flicker filter for Chroma channel (S5-4=10) 8040 maximum flicker filter for Chroma channel (S5-4=10)
8194 =00101000=0x28 (When reading, S1-0->S3-2, and S3-2->S1-0!) 8041 =00101000=0x28 (When reading, S1-0->S3-2, and S3-2->S1-0!)
8195 */ 8042 */
8196 SiS_SetCH700x(SiS_Pr,0x2801); 8043 SiS_SetCH700x(SiS_Pr,0x01,0x28);
8197 8044
8198 /* Set video bandwidth 8045 /* Set video bandwidth
8199 High bandwith Luma composite video filter(S0=1) 8046 High bandwith Luma composite video filter(S0=1)
8200 low bandwith Luma S-video filter (S2-1=00) 8047 low bandwith Luma S-video filter (S2-1=00)
8201 disable peak filter in S-video channel (S3=0) 8048 disable peak filter in S-video channel (S3=0)
8202 high bandwidth Chroma Filter (S5-4=11) 8049 high bandwidth Chroma Filter (S5-4=11)
8203 =00110001=0x31 8050 =00110001=0x31
8204 */ 8051 */
8205 SiS_SetCH700x(SiS_Pr,0xb103); /* old: 3103 */ 8052 SiS_SetCH700x(SiS_Pr,0x03,0xb1); /* old: 3103 */
8206 8053
8207 /* Register 0x3D does not exist in non-macrovision register map 8054 /* Register 0x3D does not exist in non-macrovision register map
8208 (Maybe this is a macrovision register?) 8055 (Maybe this is a macrovision register?)
8209 */ 8056 */
8210#ifndef SIS_CP 8057#ifndef SIS_CP
8211 SiS_SetCH70xx(SiS_Pr,0x003D); 8058 SiS_SetCH70xx(SiS_Pr,0x3d,0x00);
8212#endif 8059#endif
8213 8060
8214 /* Register 0x10 only contains 1 writable bit (S0) for sensing, 8061 /* Register 0x10 only contains 1 writable bit (S0) for sensing,
8215 all other bits a read-only. Macrovision? 8062 all other bits a read-only. Macrovision?
8216 */ 8063 */
8217 SiS_SetCH70xxANDOR(SiS_Pr,0x0010,0x1F); 8064 SiS_SetCH70xxANDOR(SiS_Pr,0x10,0x00,0x1F);
8218 8065
8219 /* Register 0x11 only contains 3 writable bits (S0-S2) for 8066 /* Register 0x11 only contains 3 writable bits (S0-S2) for
8220 contrast enhancement (set to 010 -> gain 1 Yout = 17/16*(Yin-30) ) 8067 contrast enhancement (set to 010 -> gain 1 Yout = 17/16*(Yin-30) )
8221 */ 8068 */
8222 SiS_SetCH70xxANDOR(SiS_Pr,0x0211,0xF8); 8069 SiS_SetCH70xxANDOR(SiS_Pr,0x11,0x02,0xF8);
8223 8070
8224 /* Clear DSEN 8071 /* Clear DSEN
8225 */ 8072 */
8226 SiS_SetCH70xxANDOR(SiS_Pr,0x001C,0xEF); 8073 SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x00,0xEF);
8227 8074
8228 if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { /* ---- NTSC ---- */ 8075 if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { /* ---- NTSC ---- */
8229 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) { 8076 if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) {
8230 if(resindex == 0x04) { /* 640x480 overscan: Mode 16 */ 8077 if(resindex == 0x04) { /* 640x480 overscan: Mode 16 */
8231 SiS_SetCH70xxANDOR(SiS_Pr,0x0020,0xEF); /* loop filter off */ 8078 SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
8232 SiS_SetCH70xxANDOR(SiS_Pr,0x0121,0xFE); /* ACIV on, no need to set FSCI */ 8079 SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on, no need to set FSCI */
8233 } else if(resindex == 0x05) { /* 800x600 overscan: Mode 23 */ 8080 } else if(resindex == 0x05) { /* 800x600 overscan: Mode 23 */
8234 SiS_SetCH70xxANDOR(SiS_Pr,0x0118,0xF0); /* 0x18-0x1f: FSCI 469,762,048 */ 8081 SiS_SetCH70xxANDOR(SiS_Pr,0x18,0x01,0xF0); /* 0x18-0x1f: FSCI 469,762,048 */
8235 SiS_SetCH70xxANDOR(SiS_Pr,0x0C19,0xF0); 8082 SiS_SetCH70xxANDOR(SiS_Pr,0x19,0x0C,0xF0);
8236 SiS_SetCH70xxANDOR(SiS_Pr,0x001A,0xF0); 8083 SiS_SetCH70xxANDOR(SiS_Pr,0x1a,0x00,0xF0);
8237 SiS_SetCH70xxANDOR(SiS_Pr,0x001B,0xF0); 8084 SiS_SetCH70xxANDOR(SiS_Pr,0x1b,0x00,0xF0);
8238 SiS_SetCH70xxANDOR(SiS_Pr,0x001C,0xF0); 8085 SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x00,0xF0);
8239 SiS_SetCH70xxANDOR(SiS_Pr,0x001D,0xF0); 8086 SiS_SetCH70xxANDOR(SiS_Pr,0x1d,0x00,0xF0);
8240 SiS_SetCH70xxANDOR(SiS_Pr,0x001E,0xF0); 8087 SiS_SetCH70xxANDOR(SiS_Pr,0x1e,0x00,0xF0);
8241 SiS_SetCH70xxANDOR(SiS_Pr,0x001F,0xF0); 8088 SiS_SetCH70xxANDOR(SiS_Pr,0x1f,0x00,0xF0);
8242 SiS_SetCH70xxANDOR(SiS_Pr,0x0120,0xEF); /* Loop filter on for mode 23 */ 8089 SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x01,0xEF); /* Loop filter on for mode 23 */
8243 SiS_SetCH70xxANDOR(SiS_Pr,0x0021,0xFE); /* ACIV off, need to set FSCI */ 8090 SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x00,0xFE); /* ACIV off, need to set FSCI */
8244 } 8091 }
8245 } else { 8092 } else {
8246 if(resindex == 0x04) { /* ----- 640x480 underscan; Mode 17 */ 8093 if(resindex == 0x04) { /* ----- 640x480 underscan; Mode 17 */
8247 SiS_SetCH70xxANDOR(SiS_Pr,0x0020,0xEF); /* loop filter off */ 8094 SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
8248 SiS_SetCH70xxANDOR(SiS_Pr,0x0121,0xFE); 8095 SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE);
8249 } else if(resindex == 0x05) { /* ----- 800x600 underscan: Mode 24 */ 8096 } else if(resindex == 0x05) { /* ----- 800x600 underscan: Mode 24 */
8250#if 0 8097#if 0
8251 SiS_SetCH70xxANDOR(SiS_Pr,0x0118,0xF0); /* (FSCI was 0x1f1c71c7 - this is for mode 22) */ 8098 SiS_SetCH70xxANDOR(SiS_Pr,0x18,0x01,0xF0); /* (FSCI was 0x1f1c71c7 - this is for mode 22) */
8252 SiS_SetCH70xxANDOR(SiS_Pr,0x0919,0xF0); /* FSCI for mode 24 is 428,554,851 */ 8099 SiS_SetCH70xxANDOR(SiS_Pr,0x19,0x09,0xF0); /* FSCI for mode 24 is 428,554,851 */
8253 SiS_SetCH70xxANDOR(SiS_Pr,0x081A,0xF0); /* 198b3a63 */ 8100 SiS_SetCH70xxANDOR(SiS_Pr,0x1a,0x08,0xF0); /* 198b3a63 */
8254 SiS_SetCH70xxANDOR(SiS_Pr,0x0b1B,0xF0); 8101 SiS_SetCH70xxANDOR(SiS_Pr,0x1b,0x0b,0xF0);
8255 SiS_SetCH70xxANDOR(SiS_Pr,0x041C,0xF0); 8102 SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x04,0xF0);
8256 SiS_SetCH70xxANDOR(SiS_Pr,0x011D,0xF0); 8103 SiS_SetCH70xxANDOR(SiS_Pr,0x1d,0x01,0xF0);
8257 SiS_SetCH70xxANDOR(SiS_Pr,0x061E,0xF0); 8104 SiS_SetCH70xxANDOR(SiS_Pr,0x1e,0x06,0xF0);
8258 SiS_SetCH70xxANDOR(SiS_Pr,0x051F,0xF0); 8105 SiS_SetCH70xxANDOR(SiS_Pr,0x1f,0x05,0xF0);
8259 SiS_SetCH70xxANDOR(SiS_Pr,0x0020,0xEF); /* loop filter off for mode 24 */ 8106 SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off for mode 24 */
8260 SiS_SetCH70xxANDOR(SiS_Pr,0x0021,0xFE); /* ACIV off, need to set FSCI */ 8107 SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x00,0xFE); * ACIV off, need to set FSCI */
8261#endif /* All alternatives wrong (datasheet wrong?), don't use FSCI */ 8108#endif /* All alternatives wrong (datasheet wrong?), don't use FSCI */
8262 SiS_SetCH70xxANDOR(SiS_Pr,0x0020,0xEF); /* loop filter off */ 8109 SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
8263 SiS_SetCH70xxANDOR(SiS_Pr,0x0121,0xFE); 8110 SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE);
8111 }
8264 } 8112 }
8265 } 8113 } else { /* ---- PAL ---- */
8266 } else { /* ---- PAL ---- */ 8114 /* We don't play around with FSCI in PAL mode */
8267 /* We don't play around with FSCI in PAL mode */
8268 if(resindex == 0x04) { 8115 if(resindex == 0x04) {
8269 SiS_SetCH70xxANDOR(SiS_Pr,0x0020,0xEF); /* loop filter off */ 8116 SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
8270 SiS_SetCH70xxANDOR(SiS_Pr,0x0121,0xFE); /* ACIV on */ 8117 SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on */
8271 } else { 8118 } else {
8272 SiS_SetCH70xxANDOR(SiS_Pr,0x0020,0xEF); /* loop filter off */ 8119 SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
8273 SiS_SetCH70xxANDOR(SiS_Pr,0x0121,0xFE); /* ACIV on */ 8120 SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on */
8274 } 8121 }
8275 } 8122 }
8276 8123
8277#endif /* 300 */ 8124#endif /* 300 */
8278 8125
8279 } else { 8126 } else {
8280 8127
8281 /* Chrontel 7019 - assumed that it does not come with a 300 series chip */ 8128 /* Chrontel 7019 - assumed that it does not come with a 300 series chip */
8282 8129
8283#ifdef SIS315H 8130#ifdef SIS315H
8284 8131
8285 /* We don't support modes >1024x768 */ 8132 unsigned short temp;
8286 if (resindex > 6) return; 8133
8287 8134 /* We don't support modes >1024x768 */
8288 temp = CHTVRegData[resindex].Reg[0]; 8135 if (resindex > 6) return;
8289 if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) { 8136
8290 temp |= 0x10; 8137 temp = CHTVRegData[resindex].Reg[0];
8291 } 8138 if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp |= 0x10;
8292 tempbx=((temp & 0x00FF) << 8) | 0x00; 8139 SiS_SetCH701x(SiS_Pr,0x00,temp);
8293 SiS_SetCH701x(SiS_Pr,tempbx); 8140
8294 8141 SiS_SetCH701x(SiS_Pr,0x01,CHTVRegData[resindex].Reg[1]);
8295 temp = CHTVRegData[resindex].Reg[1]; 8142 SiS_SetCH701x(SiS_Pr,0x02,CHTVRegData[resindex].Reg[2]);
8296 tempbx=((temp & 0x00FF) << 8) | 0x01; 8143 SiS_SetCH701x(SiS_Pr,0x04,CHTVRegData[resindex].Reg[3]);
8297 SiS_SetCH701x(SiS_Pr,tempbx); 8144 SiS_SetCH701x(SiS_Pr,0x03,CHTVRegData[resindex].Reg[4]);
8298 8145 SiS_SetCH701x(SiS_Pr,0x05,CHTVRegData[resindex].Reg[5]);
8299 temp = CHTVRegData[resindex].Reg[2]; 8146 SiS_SetCH701x(SiS_Pr,0x06,CHTVRegData[resindex].Reg[6]);
8300 tempbx=((temp & 0x00FF) << 8) | 0x02; 8147
8301 SiS_SetCH701x(SiS_Pr,tempbx); 8148 temp = CHTVRegData[resindex].Reg[7];
8302 8149 if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp = 0x66;
8303 temp = CHTVRegData[resindex].Reg[3]; 8150 SiS_SetCH701x(SiS_Pr,0x07,temp);
8304 tempbx=((temp & 0x00FF) << 8) | 0x04; 8151
8305 SiS_SetCH701x(SiS_Pr,tempbx); 8152 SiS_SetCH701x(SiS_Pr,0x08,CHTVRegData[resindex].Reg[8]);
8306 8153 SiS_SetCH701x(SiS_Pr,0x15,CHTVRegData[resindex].Reg[9]);
8307 temp = CHTVRegData[resindex].Reg[4]; 8154 SiS_SetCH701x(SiS_Pr,0x1f,CHTVRegData[resindex].Reg[10]);
8308 tempbx=((temp & 0x00FF) << 8) | 0x03; 8155 SiS_SetCH701x(SiS_Pr,0x0c,CHTVRegData[resindex].Reg[11]);
8309 SiS_SetCH701x(SiS_Pr,tempbx); 8156 SiS_SetCH701x(SiS_Pr,0x0d,CHTVRegData[resindex].Reg[12]);
8310 8157 SiS_SetCH701x(SiS_Pr,0x0e,CHTVRegData[resindex].Reg[13]);
8311 temp = CHTVRegData[resindex].Reg[5]; 8158 SiS_SetCH701x(SiS_Pr,0x0f,CHTVRegData[resindex].Reg[14]);
8312 tempbx=((temp & 0x00FF) << 8) | 0x05; 8159 SiS_SetCH701x(SiS_Pr,0x10,CHTVRegData[resindex].Reg[15]);
8313 SiS_SetCH701x(SiS_Pr,tempbx); 8160
8314 8161 temp = SiS_GetCH701x(SiS_Pr,0x21) & ~0x02;
8315 temp = CHTVRegData[resindex].Reg[6]; 8162 /* D1 should be set for PAL, PAL-N and NTSC-J,
8316 tempbx=((temp & 0x00FF) << 8) | 0x06; 8163 but I won't do that for PAL unless somebody
8317 SiS_SetCH701x(SiS_Pr,tempbx); 8164 tells me to do so. Since the BIOS uses
8318 8165 non-default CIV values and blacklevels,
8319 temp = CHTVRegData[resindex].Reg[7]; 8166 this might be compensated anyway.
8320 if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) { 8167 */
8321 temp = 0x66; 8168 if(SiS_Pr->SiS_TVMode & (TVSetPALN | TVSetNTSCJ)) temp |= 0x02;
8322 } 8169 SiS_SetCH701x(SiS_Pr,0x21,temp);
8323 tempbx=((temp & 0x00FF) << 8) | 0x07;
8324 SiS_SetCH701x(SiS_Pr,tempbx);
8325
8326 temp = CHTVRegData[resindex].Reg[8];
8327 tempbx=((temp & 0x00FF) << 8) | 0x08;
8328 SiS_SetCH701x(SiS_Pr,tempbx);
8329
8330 temp = CHTVRegData[resindex].Reg[9];
8331 tempbx=((temp & 0x00FF) << 8) | 0x15;
8332 SiS_SetCH701x(SiS_Pr,tempbx);
8333
8334 temp = CHTVRegData[resindex].Reg[10];
8335 tempbx=((temp & 0x00FF) << 8) | 0x1f;
8336 SiS_SetCH701x(SiS_Pr,tempbx);
8337
8338 temp = CHTVRegData[resindex].Reg[11];
8339 tempbx=((temp & 0x00FF) << 8) | 0x0c;
8340 SiS_SetCH701x(SiS_Pr,tempbx);
8341
8342 temp = CHTVRegData[resindex].Reg[12];
8343 tempbx=((temp & 0x00FF) << 8) | 0x0d;
8344 SiS_SetCH701x(SiS_Pr,tempbx);
8345
8346 temp = CHTVRegData[resindex].Reg[13];
8347 tempbx=((temp & 0x00FF) << 8) | 0x0e;
8348 SiS_SetCH701x(SiS_Pr,tempbx);
8349
8350 temp = CHTVRegData[resindex].Reg[14];
8351 tempbx=((temp & 0x00FF) << 8) | 0x0f;
8352 SiS_SetCH701x(SiS_Pr,tempbx);
8353
8354 temp = CHTVRegData[resindex].Reg[15];
8355 tempbx=((temp & 0x00FF) << 8) | 0x10;
8356 SiS_SetCH701x(SiS_Pr,tempbx);
8357
8358 temp = SiS_GetCH701x(SiS_Pr,0x21) & ~0x02;
8359 /* D1 should be set for PAL, PAL-N and NTSC-J,
8360 but I won't do that for PAL unless somebody
8361 tells me to do so. Since the BIOS uses
8362 non-default CIV values and blacklevels,
8363 this might be compensated anyway.
8364 */
8365 if(SiS_Pr->SiS_TVMode & (TVSetPALN | TVSetNTSCJ)) temp |= 0x02;
8366 SiS_SetCH701x(SiS_Pr,((temp << 8) | 0x21));
8367 8170
8368#endif /* 315 */ 8171#endif /* 315 */
8369 8172
8370 } 8173 }
8371 8174
8372#ifdef SIS_CP 8175#ifdef SIS_CP
8373 SIS_CP_INIT301_CP3 8176 SIS_CP_INIT301_CP3
8374#endif 8177#endif
8375 8178
8376} 8179}
8377 8180
8181#ifdef SIS315H /* ----------- 315 series only ---------- */
8182
8378void 8183void
8379SiS_Chrontel701xBLOn(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 8184SiS_Chrontel701xBLOn(struct SiS_Private *SiS_Pr)
8380{ 8185{
8381 USHORT temp; 8186 unsigned short temp;
8382 8187
8383 /* Enable Chrontel 7019 LCD panel backlight */ 8188 /* Enable Chrontel 7019 LCD panel backlight */
8384 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { 8189 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
8385 if(HwInfo->jChipType == SIS_740) { 8190 if(SiS_Pr->ChipType == SIS_740) {
8386 SiS_SetCH701x(SiS_Pr,0x6566); 8191 SiS_SetCH701x(SiS_Pr,0x66,0x65);
8387 } else { 8192 } else {
8388 temp = SiS_GetCH701x(SiS_Pr,0x66); 8193 temp = SiS_GetCH701x(SiS_Pr,0x66);
8389 temp |= 0x20; 8194 temp |= 0x20;
8390 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x66); 8195 SiS_SetCH701x(SiS_Pr,0x66,temp);
8391 } 8196 }
8392 } 8197 }
8393} 8198}
8394 8199
8395void 8200void
8396SiS_Chrontel701xBLOff(SiS_Private *SiS_Pr) 8201SiS_Chrontel701xBLOff(struct SiS_Private *SiS_Pr)
8397{ 8202{
8398 USHORT temp; 8203 unsigned short temp;
8399 8204
8400 /* Disable Chrontel 7019 LCD panel backlight */ 8205 /* Disable Chrontel 7019 LCD panel backlight */
8401 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { 8206 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
8402 temp = SiS_GetCH701x(SiS_Pr,0x66); 8207 temp = SiS_GetCH701x(SiS_Pr,0x66);
8403 temp &= 0xDF; 8208 temp &= 0xDF;
8404 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x66); 8209 SiS_SetCH701x(SiS_Pr,0x66,temp);
8405 } 8210 }
8406} 8211}
8407 8212
8408#ifdef SIS315H /* ----------- 315 series only ---------- */
8409
8410static void 8213static void
8411SiS_ChrontelPowerSequencing(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 8214SiS_ChrontelPowerSequencing(struct SiS_Private *SiS_Pr)
8412{ 8215{
8413 UCHAR regtable[] = { 0x67, 0x68, 0x69, 0x6a, 0x6b }; 8216 static const unsigned char regtable[] = { 0x67, 0x68, 0x69, 0x6a, 0x6b };
8414 UCHAR table1024_740[] = { 0x01, 0x02, 0x01, 0x01, 0x01 }; 8217 static const unsigned char table1024_740[] = { 0x01, 0x02, 0x01, 0x01, 0x01 };
8415 UCHAR table1400_740[] = { 0x01, 0x6e, 0x01, 0x01, 0x01 }; 8218 static const unsigned char table1400_740[] = { 0x01, 0x6e, 0x01, 0x01, 0x01 };
8416 UCHAR asus1024_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 }; 8219 static const unsigned char asus1024_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 };
8417 UCHAR asus1400_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 }; 8220 static const unsigned char asus1400_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 };
8418 UCHAR table1024_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 }; 8221 static const unsigned char table1024_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 };
8419 UCHAR table1400_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 }; 8222 static const unsigned char table1400_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 };
8420 UCHAR *tableptr = NULL; 8223 const unsigned char *tableptr = NULL;
8421 int i; 8224 int i;
8422 8225
8423 /* Set up Power up/down timing */ 8226 /* Set up Power up/down timing */
8424 8227
8425 if(HwInfo->jChipType == SIS_740) { 8228 if(SiS_Pr->ChipType == SIS_740) {
8426 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { 8229 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
8427 if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1024_740; 8230 if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1024_740;
8428 else tableptr = table1024_740; 8231 else tableptr = table1024_740;
8429 } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) || 8232 } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
8430 (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) || 8233 (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
8431 (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) { 8234 (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
8432 if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1400_740; 8235 if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1400_740;
8433 else tableptr = table1400_740; 8236 else tableptr = table1400_740;
8434 } else return; 8237 } else return;
8435 } else { 8238 } else {
8436 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { 8239 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
8437 tableptr = table1024_650; 8240 tableptr = table1024_650;
8438 } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) || 8241 } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
8439 (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) || 8242 (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
8440 (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) { 8243 (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
8441 tableptr = table1400_650; 8244 tableptr = table1400_650;
8442 } else return; 8245 } else return;
8443 } 8246 }
8444 8247
8445 for(i=0; i<5; i++) { 8248 for(i=0; i<5; i++) {
8446 SiS_SetCH701x(SiS_Pr,(tableptr[i] << 8) | regtable[i]); 8249 SiS_SetCH701x(SiS_Pr, regtable[i], tableptr[i]);
8447 } 8250 }
8448} 8251}
8449 8252
8450static void 8253static void
8451SiS_SetCH701xForLCD(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 8254SiS_SetCH701xForLCD(struct SiS_Private *SiS_Pr)
8452{ 8255{
8453 UCHAR regtable[] = { 0x1c, 0x5f, 0x64, 0x6f, 0x70, 0x71, 8256 const unsigned char *tableptr = NULL;
8454 0x72, 0x73, 0x74, 0x76, 0x78, 0x7d, 0x66 }; 8257 unsigned short tempbh;
8455 UCHAR table1024_740[] = { 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
8456 0xa3, 0xc8, 0xc7, 0xac, 0xe0, 0x02, 0x44 };
8457 UCHAR table1280_740[] = { 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
8458 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44 };
8459 UCHAR table1400_740[] = { 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
8460 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44 };
8461 UCHAR table1600_740[] = { 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
8462 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a, 0x44 };
8463 UCHAR table1024_650[] = { 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
8464 0xa3, 0xc8, 0xc7, 0xac, 0x60, 0x02 };
8465 UCHAR table1280_650[] = { 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
8466 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02 };
8467 UCHAR table1400_650[] = { 0x60, 0x03, 0x11, 0x00, 0x40, 0xef,
8468 0xad, 0xdb, 0xf6, 0xac, 0x60, 0x02 };
8469 UCHAR table1600_650[] = { 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
8470 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a };
8471 UCHAR *tableptr = NULL;
8472 USHORT tempbh;
8473 int i; 8258 int i;
8259 static const unsigned char regtable[] = {
8260 0x1c, 0x5f, 0x64, 0x6f, 0x70, 0x71,
8261 0x72, 0x73, 0x74, 0x76, 0x78, 0x7d, 0x66
8262 };
8263 static const unsigned char table1024_740[] = {
8264 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
8265 0xa3, 0xc8, 0xc7, 0xac, 0xe0, 0x02, 0x44
8266 };
8267 static const unsigned char table1280_740[] = {
8268 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
8269 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44
8270 };
8271 static const unsigned char table1400_740[] = {
8272 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
8273 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44
8274 };
8275 static const unsigned char table1600_740[] = {
8276 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
8277 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a, 0x44
8278 };
8279 static const unsigned char table1024_650[] = {
8280 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
8281 0xa3, 0xc8, 0xc7, 0xac, 0x60, 0x02
8282 };
8283 static const unsigned char table1280_650[] = {
8284 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
8285 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02
8286 };
8287 static const unsigned char table1400_650[] = {
8288 0x60, 0x03, 0x11, 0x00, 0x40, 0xef,
8289 0xad, 0xdb, 0xf6, 0xac, 0x60, 0x02
8290 };
8291 static const unsigned char table1600_650[] = {
8292 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
8293 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a
8294 };
8474 8295
8475 if(HwInfo->jChipType == SIS_740) { 8296 if(SiS_Pr->ChipType == SIS_740) {
8476 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_740; 8297 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_740;
8477 else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_740; 8298 else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_740;
8478 else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_740; 8299 else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_740;
@@ -8499,138 +8320,139 @@ SiS_SetCH701xForLCD(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
8499 } 8320 }
8500 } 8321 }
8501 8322
8502 if(HwInfo->jChipType == SIS_740) tempbh = 0x0d; 8323 if(SiS_Pr->ChipType == SIS_740) tempbh = 0x0d;
8503 else tempbh = 0x0c; 8324 else tempbh = 0x0c;
8504 8325
8505 for(i = 0; i < tempbh; i++) { 8326 for(i = 0; i < tempbh; i++) {
8506 SiS_SetCH701x(SiS_Pr,(tableptr[i] << 8) | regtable[i]); 8327 SiS_SetCH701x(SiS_Pr, regtable[i], tableptr[i]);
8507 } 8328 }
8508 SiS_ChrontelPowerSequencing(SiS_Pr,HwInfo); 8329 SiS_ChrontelPowerSequencing(SiS_Pr);
8509 tempbh = SiS_GetCH701x(SiS_Pr,0x1e); 8330 tempbh = SiS_GetCH701x(SiS_Pr,0x1e);
8510 tempbh |= 0xc0; 8331 tempbh |= 0xc0;
8511 SiS_SetCH701x(SiS_Pr,(tempbh << 8) | 0x1e); 8332 SiS_SetCH701x(SiS_Pr,0x1e,tempbh);
8512 8333
8513 if(HwInfo->jChipType == SIS_740) { 8334 if(SiS_Pr->ChipType == SIS_740) {
8514 tempbh = SiS_GetCH701x(SiS_Pr,0x1c); 8335 tempbh = SiS_GetCH701x(SiS_Pr,0x1c);
8515 tempbh &= 0xfb; 8336 tempbh &= 0xfb;
8516 SiS_SetCH701x(SiS_Pr,(tempbh << 8) | 0x1c); 8337 SiS_SetCH701x(SiS_Pr,0x1c,tempbh);
8517 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03); 8338 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03);
8518 tempbh = SiS_GetCH701x(SiS_Pr,0x64); 8339 tempbh = SiS_GetCH701x(SiS_Pr,0x64);
8519 tempbh |= 0x40; 8340 tempbh |= 0x40;
8520 SiS_SetCH701x(SiS_Pr,(tempbh << 8) | 0x64); 8341 SiS_SetCH701x(SiS_Pr,0x64,tempbh);
8521 tempbh = SiS_GetCH701x(SiS_Pr,0x03); 8342 tempbh = SiS_GetCH701x(SiS_Pr,0x03);
8522 tempbh &= 0x3f; 8343 tempbh &= 0x3f;
8523 SiS_SetCH701x(SiS_Pr,(tempbh << 8) | 0x03); 8344 SiS_SetCH701x(SiS_Pr,0x03,tempbh);
8524 } 8345 }
8525} 8346}
8526 8347
8527static void 8348static void
8528SiS_ChrontelResetVSync(SiS_Private *SiS_Pr) 8349SiS_ChrontelResetVSync(struct SiS_Private *SiS_Pr)
8529{ 8350{
8530 unsigned char temp, temp1; 8351 unsigned char temp, temp1;
8531 8352
8532 temp1 = SiS_GetCH701x(SiS_Pr,0x49); 8353 temp1 = SiS_GetCH701x(SiS_Pr,0x49);
8533 SiS_SetCH701x(SiS_Pr,0x3e49); 8354 SiS_SetCH701x(SiS_Pr,0x49,0x3e);
8534 temp = SiS_GetCH701x(SiS_Pr,0x47); 8355 temp = SiS_GetCH701x(SiS_Pr,0x47);
8535 temp &= 0x7f; /* Use external VSYNC */ 8356 temp &= 0x7f; /* Use external VSYNC */
8536 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x47); 8357 SiS_SetCH701x(SiS_Pr,0x47,temp);
8537 SiS_LongDelay(SiS_Pr,3); 8358 SiS_LongDelay(SiS_Pr, 3);
8538 temp = SiS_GetCH701x(SiS_Pr,0x47); 8359 temp = SiS_GetCH701x(SiS_Pr,0x47);
8539 temp |= 0x80; /* Use internal VSYNC */ 8360 temp |= 0x80; /* Use internal VSYNC */
8540 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x47); 8361 SiS_SetCH701x(SiS_Pr,0x47,temp);
8541 SiS_SetCH701x(SiS_Pr,(temp1 << 8) | 0x49); 8362 SiS_SetCH701x(SiS_Pr,0x49,temp1);
8542} 8363}
8543 8364
8544static void 8365static void
8545SiS_Chrontel701xOn(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 8366SiS_Chrontel701xOn(struct SiS_Private *SiS_Pr)
8546{ 8367{
8547 USHORT temp; 8368 unsigned short temp;
8548 8369
8549 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { 8370 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
8550 if(HwInfo->jChipType == SIS_740) { 8371 if(SiS_Pr->ChipType == SIS_740) {
8551 temp = SiS_GetCH701x(SiS_Pr,0x1c); 8372 temp = SiS_GetCH701x(SiS_Pr,0x1c);
8552 temp |= 0x04; /* Invert XCLK phase */ 8373 temp |= 0x04; /* Invert XCLK phase */
8553 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x1c); 8374 SiS_SetCH701x(SiS_Pr,0x1c,temp);
8554 } 8375 }
8555 if(SiS_IsYPbPr(SiS_Pr, HwInfo)) { 8376 if(SiS_IsYPbPr(SiS_Pr)) {
8556 temp = SiS_GetCH701x(SiS_Pr,0x01); 8377 temp = SiS_GetCH701x(SiS_Pr,0x01);
8557 temp &= 0x3f; 8378 temp &= 0x3f;
8558 temp |= 0x80; /* Enable YPrPb (HDTV) */ 8379 temp |= 0x80; /* Enable YPrPb (HDTV) */
8559 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x01); 8380 SiS_SetCH701x(SiS_Pr,0x01,temp);
8560 } 8381 }
8561 if(SiS_IsChScart(SiS_Pr, HwInfo)) { 8382 if(SiS_IsChScart(SiS_Pr)) {
8562 temp = SiS_GetCH701x(SiS_Pr,0x01); 8383 temp = SiS_GetCH701x(SiS_Pr,0x01);
8563 temp &= 0x3f; 8384 temp &= 0x3f;
8564 temp |= 0xc0; /* Enable SCART + CVBS */ 8385 temp |= 0xc0; /* Enable SCART + CVBS */
8565 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x01); 8386 SiS_SetCH701x(SiS_Pr,0x01,temp);
8566 } 8387 }
8567 if(HwInfo->jChipType == SIS_740) { 8388 if(SiS_Pr->ChipType == SIS_740) {
8568 SiS_ChrontelResetVSync(SiS_Pr); 8389 SiS_ChrontelResetVSync(SiS_Pr);
8569 SiS_SetCH701x(SiS_Pr,0x2049); /* Enable TV path */ 8390 SiS_SetCH701x(SiS_Pr,0x49,0x20); /* Enable TV path */
8570 } else { 8391 } else {
8571 SiS_SetCH701x(SiS_Pr,0x2049); /* Enable TV path */ 8392 SiS_SetCH701x(SiS_Pr,0x49,0x20); /* Enable TV path */
8572 temp = SiS_GetCH701x(SiS_Pr,0x49); 8393 temp = SiS_GetCH701x(SiS_Pr,0x49);
8573 if(SiS_IsYPbPr(SiS_Pr,HwInfo)) { 8394 if(SiS_IsYPbPr(SiS_Pr)) {
8574 temp = SiS_GetCH701x(SiS_Pr,0x73); 8395 temp = SiS_GetCH701x(SiS_Pr,0x73);
8575 temp |= 0x60; 8396 temp |= 0x60;
8576 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x73); 8397 SiS_SetCH701x(SiS_Pr,0x73,temp);
8577 } 8398 }
8578 temp = SiS_GetCH701x(SiS_Pr,0x47); 8399 temp = SiS_GetCH701x(SiS_Pr,0x47);
8579 temp &= 0x7f; 8400 temp &= 0x7f;
8580 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x47); 8401 SiS_SetCH701x(SiS_Pr,0x47,temp);
8581 SiS_LongDelay(SiS_Pr,2); 8402 SiS_LongDelay(SiS_Pr, 2);
8582 temp = SiS_GetCH701x(SiS_Pr,0x47); 8403 temp = SiS_GetCH701x(SiS_Pr,0x47);
8583 temp |= 0x80; 8404 temp |= 0x80;
8584 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x47); 8405 SiS_SetCH701x(SiS_Pr,0x47,temp);
8585 } 8406 }
8586 } 8407 }
8587} 8408}
8588 8409
8589static void 8410static void
8590SiS_Chrontel701xOff(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 8411SiS_Chrontel701xOff(struct SiS_Private *SiS_Pr)
8591{ 8412{
8592 USHORT temp; 8413 unsigned short temp;
8593 8414
8594 /* Complete power down of LVDS */ 8415 /* Complete power down of LVDS */
8595 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { 8416 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
8596 if(HwInfo->jChipType == SIS_740) { 8417 if(SiS_Pr->ChipType == SIS_740) {
8597 SiS_LongDelay(SiS_Pr,1); 8418 SiS_LongDelay(SiS_Pr, 1);
8598 SiS_GenericDelay(SiS_Pr,0x16ff); 8419 SiS_GenericDelay(SiS_Pr, 5887);
8599 SiS_SetCH701x(SiS_Pr,0xac76); 8420 SiS_SetCH701x(SiS_Pr,0x76,0xac);
8600 SiS_SetCH701x(SiS_Pr,0x0066); 8421 SiS_SetCH701x(SiS_Pr,0x66,0x00);
8601 } else { 8422 } else {
8602 SiS_LongDelay(SiS_Pr,2); 8423 SiS_LongDelay(SiS_Pr, 2);
8603 temp = SiS_GetCH701x(SiS_Pr,0x76); 8424 temp = SiS_GetCH701x(SiS_Pr,0x76);
8604 temp &= 0xfc; 8425 temp &= 0xfc;
8605 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x76); 8426 SiS_SetCH701x(SiS_Pr,0x76,temp);
8606 SiS_SetCH701x(SiS_Pr,0x0066); 8427 SiS_SetCH701x(SiS_Pr,0x66,0x00);
8607 } 8428 }
8608 } 8429 }
8609} 8430}
8610 8431
8611static void 8432static void
8612SiS_ChrontelResetDB(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 8433SiS_ChrontelResetDB(struct SiS_Private *SiS_Pr)
8613{ 8434{
8614 USHORT temp; 8435 unsigned short temp;
8615 8436
8616 if(HwInfo->jChipType == SIS_740) { 8437 if(SiS_Pr->ChipType == SIS_740) {
8617 8438
8618 temp = SiS_GetCH701x(SiS_Pr,0x4a); /* Version ID */ 8439 temp = SiS_GetCH701x(SiS_Pr,0x4a); /* Version ID */
8619 temp &= 0x01; 8440 temp &= 0x01;
8620 if(!temp) { 8441 if(!temp) {
8621 8442
8622 if(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo)) { 8443 if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
8623 temp = SiS_GetCH701x(SiS_Pr,0x49); 8444 temp = SiS_GetCH701x(SiS_Pr,0x49);
8624 SiS_SetCH701x(SiS_Pr,0x3e49); 8445 SiS_SetCH701x(SiS_Pr,0x49,0x3e);
8625 } 8446 }
8447
8626 /* Reset Chrontel 7019 datapath */ 8448 /* Reset Chrontel 7019 datapath */
8627 SiS_SetCH701x(SiS_Pr,0x1048); 8449 SiS_SetCH701x(SiS_Pr,0x48,0x10);
8628 SiS_LongDelay(SiS_Pr,1); 8450 SiS_LongDelay(SiS_Pr, 1);
8629 SiS_SetCH701x(SiS_Pr,0x1848); 8451 SiS_SetCH701x(SiS_Pr,0x48,0x18);
8630 8452
8631 if(SiS_WeHaveBacklightCtrl(SiS_Pr, HwInfo)) { 8453 if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
8632 SiS_ChrontelResetVSync(SiS_Pr); 8454 SiS_ChrontelResetVSync(SiS_Pr);
8633 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x49); 8455 SiS_SetCH701x(SiS_Pr,0x49,temp);
8634 } 8456 }
8635 8457
8636 } else { 8458 } else {
@@ -8638,72 +8460,72 @@ SiS_ChrontelResetDB(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
8638 /* Clear/set/clear GPIO */ 8460 /* Clear/set/clear GPIO */
8639 temp = SiS_GetCH701x(SiS_Pr,0x5c); 8461 temp = SiS_GetCH701x(SiS_Pr,0x5c);
8640 temp &= 0xef; 8462 temp &= 0xef;
8641 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x5c); 8463 SiS_SetCH701x(SiS_Pr,0x5c,temp);
8642 temp = SiS_GetCH701x(SiS_Pr,0x5c); 8464 temp = SiS_GetCH701x(SiS_Pr,0x5c);
8643 temp |= 0x10; 8465 temp |= 0x10;
8644 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x5c); 8466 SiS_SetCH701x(SiS_Pr,0x5c,temp);
8645 temp = SiS_GetCH701x(SiS_Pr,0x5c); 8467 temp = SiS_GetCH701x(SiS_Pr,0x5c);
8646 temp &= 0xef; 8468 temp &= 0xef;
8647 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x5c); 8469 SiS_SetCH701x(SiS_Pr,0x5c,temp);
8648 temp = SiS_GetCH701x(SiS_Pr,0x61); 8470 temp = SiS_GetCH701x(SiS_Pr,0x61);
8649 if(!temp) { 8471 if(!temp) {
8650 SiS_SetCH701xForLCD(SiS_Pr, HwInfo); 8472 SiS_SetCH701xForLCD(SiS_Pr);
8651 } 8473 }
8652 } 8474 }
8653 8475
8654 } else { /* 650 */ 8476 } else { /* 650 */
8655 /* Reset Chrontel 7019 datapath */ 8477 /* Reset Chrontel 7019 datapath */
8656 SiS_SetCH701x(SiS_Pr,0x1048); 8478 SiS_SetCH701x(SiS_Pr,0x48,0x10);
8657 SiS_LongDelay(SiS_Pr,1); 8479 SiS_LongDelay(SiS_Pr, 1);
8658 SiS_SetCH701x(SiS_Pr,0x1848); 8480 SiS_SetCH701x(SiS_Pr,0x48,0x18);
8659 } 8481 }
8660} 8482}
8661 8483
8662static void 8484static void
8663SiS_ChrontelInitTVVSync(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 8485SiS_ChrontelInitTVVSync(struct SiS_Private *SiS_Pr)
8664{ 8486{
8665 USHORT temp; 8487 unsigned short temp;
8666 8488
8667 if(HwInfo->jChipType == SIS_740) { 8489 if(SiS_Pr->ChipType == SIS_740) {
8668 8490
8669 if(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo)) { 8491 if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
8670 SiS_ChrontelResetVSync(SiS_Pr); 8492 SiS_ChrontelResetVSync(SiS_Pr);
8671 } 8493 }
8672 8494
8673 } else { 8495 } else {
8674 8496
8675 SiS_SetCH701x(SiS_Pr,0xaf76); /* Power up LVDS block */ 8497 SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* Power up LVDS block */
8676 temp = SiS_GetCH701x(SiS_Pr,0x49); 8498 temp = SiS_GetCH701x(SiS_Pr,0x49);
8677 temp &= 1; 8499 temp &= 1;
8678 if(temp != 1) { /* TV block powered? (0 = yes, 1 = no) */ 8500 if(temp != 1) { /* TV block powered? (0 = yes, 1 = no) */
8679 temp = SiS_GetCH701x(SiS_Pr,0x47); 8501 temp = SiS_GetCH701x(SiS_Pr,0x47);
8680 temp &= 0x70; 8502 temp &= 0x70;
8681 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x47); /* enable VSYNC */ 8503 SiS_SetCH701x(SiS_Pr,0x47,temp); /* enable VSYNC */
8682 SiS_LongDelay(SiS_Pr,3); 8504 SiS_LongDelay(SiS_Pr, 3);
8683 temp = SiS_GetCH701x(SiS_Pr,0x47); 8505 temp = SiS_GetCH701x(SiS_Pr,0x47);
8684 temp |= 0x80; 8506 temp |= 0x80;
8685 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x47); /* disable VSYNC */ 8507 SiS_SetCH701x(SiS_Pr,0x47,temp); /* disable VSYNC */
8686 } 8508 }
8687 8509
8688 } 8510 }
8689} 8511}
8690 8512
8691static void 8513static void
8692SiS_ChrontelDoSomething3(SiS_Private *SiS_Pr, USHORT ModeNo, PSIS_HW_INFO HwInfo) 8514SiS_ChrontelDoSomething3(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
8693{ 8515{
8694 USHORT temp,temp1; 8516 unsigned short temp,temp1;
8695 8517
8696 if(HwInfo->jChipType == SIS_740) { 8518 if(SiS_Pr->ChipType == SIS_740) {
8697 8519
8698 temp = SiS_GetCH701x(SiS_Pr,0x61); 8520 temp = SiS_GetCH701x(SiS_Pr,0x61);
8699 if(temp < 1) { 8521 if(temp < 1) {
8700 temp++; 8522 temp++;
8701 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x61); 8523 SiS_SetCH701x(SiS_Pr,0x61,temp);
8702 } 8524 }
8703 SiS_SetCH701x(SiS_Pr,0x4566); /* Panel power on */ 8525 SiS_SetCH701x(SiS_Pr,0x66,0x45); /* Panel power on */
8704 SiS_SetCH701x(SiS_Pr,0xaf76); /* All power on */ 8526 SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* All power on */
8705 SiS_LongDelay(SiS_Pr,1); 8527 SiS_LongDelay(SiS_Pr, 1);
8706 SiS_GenericDelay(SiS_Pr,0x16ff); 8528 SiS_GenericDelay(SiS_Pr, 5887);
8707 8529
8708 } else { /* 650 */ 8530 } else { /* 650 */
8709 8531
@@ -8711,38 +8533,38 @@ SiS_ChrontelDoSomething3(SiS_Private *SiS_Pr, USHORT ModeNo, PSIS_HW_INFO HwInfo
8711 temp = SiS_GetCH701x(SiS_Pr,0x61); 8533 temp = SiS_GetCH701x(SiS_Pr,0x61);
8712 if(temp < 2) { 8534 if(temp < 2) {
8713 temp++; 8535 temp++;
8714 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x61); 8536 SiS_SetCH701x(SiS_Pr,0x61,temp);
8715 temp1 = 1; 8537 temp1 = 1;
8716 } 8538 }
8717 SiS_SetCH701x(SiS_Pr,0xac76); 8539 SiS_SetCH701x(SiS_Pr,0x76,0xac);
8718 temp = SiS_GetCH701x(SiS_Pr,0x66); 8540 temp = SiS_GetCH701x(SiS_Pr,0x66);
8719 temp |= 0x5f; 8541 temp |= 0x5f;
8720 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x66); 8542 SiS_SetCH701x(SiS_Pr,0x66,temp);
8721 if(ModeNo > 0x13) { 8543 if(ModeNo > 0x13) {
8722 if(SiS_WeHaveBacklightCtrl(SiS_Pr, HwInfo)) { 8544 if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
8723 SiS_GenericDelay(SiS_Pr,0x3ff); 8545 SiS_GenericDelay(SiS_Pr, 1023);
8724 } else { 8546 } else {
8725 SiS_GenericDelay(SiS_Pr,0x2ff); 8547 SiS_GenericDelay(SiS_Pr, 767);
8726 } 8548 }
8727 } else { 8549 } else {
8728 if(!temp1) 8550 if(!temp1)
8729 SiS_GenericDelay(SiS_Pr,0x2ff); 8551 SiS_GenericDelay(SiS_Pr, 767);
8730 } 8552 }
8731 temp = SiS_GetCH701x(SiS_Pr,0x76); 8553 temp = SiS_GetCH701x(SiS_Pr,0x76);
8732 temp |= 0x03; 8554 temp |= 0x03;
8733 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x76); 8555 SiS_SetCH701x(SiS_Pr,0x76,temp);
8734 temp = SiS_GetCH701x(SiS_Pr,0x66); 8556 temp = SiS_GetCH701x(SiS_Pr,0x66);
8735 temp &= 0x7f; 8557 temp &= 0x7f;
8736 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x66); 8558 SiS_SetCH701x(SiS_Pr,0x66,temp);
8737 SiS_LongDelay(SiS_Pr,1); 8559 SiS_LongDelay(SiS_Pr, 1);
8738 8560
8739 } 8561 }
8740} 8562}
8741 8563
8742static void 8564static void
8743SiS_ChrontelDoSomething2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 8565SiS_ChrontelDoSomething2(struct SiS_Private *SiS_Pr)
8744{ 8566{
8745 USHORT temp,tempcl,tempch; 8567 unsigned short temp,tempcl,tempch;
8746 8568
8747 SiS_LongDelay(SiS_Pr, 1); 8569 SiS_LongDelay(SiS_Pr, 1);
8748 tempcl = 3; 8570 tempcl = 3;
@@ -8753,87 +8575,87 @@ SiS_ChrontelDoSomething2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
8753 temp &= 0x04; /* PLL stable? -> bail out */ 8575 temp &= 0x04; /* PLL stable? -> bail out */
8754 if(temp == 0x04) break; 8576 if(temp == 0x04) break;
8755 8577
8756 if(HwInfo->jChipType == SIS_740) { 8578 if(SiS_Pr->ChipType == SIS_740) {
8757 /* Power down LVDS output, PLL normal operation */ 8579 /* Power down LVDS output, PLL normal operation */
8758 SiS_SetCH701x(SiS_Pr,0xac76); 8580 SiS_SetCH701x(SiS_Pr,0x76,0xac);
8759 } 8581 }
8760 8582
8761 SiS_SetCH701xForLCD(SiS_Pr,HwInfo); 8583 SiS_SetCH701xForLCD(SiS_Pr);
8762 8584
8763 if(tempcl == 0) { 8585 if(tempcl == 0) {
8764 if(tempch == 3) break; 8586 if(tempch == 3) break;
8765 SiS_ChrontelResetDB(SiS_Pr,HwInfo); 8587 SiS_ChrontelResetDB(SiS_Pr);
8766 tempcl = 3; 8588 tempcl = 3;
8767 tempch++; 8589 tempch++;
8768 } 8590 }
8769 tempcl--; 8591 tempcl--;
8770 temp = SiS_GetCH701x(SiS_Pr,0x76); 8592 temp = SiS_GetCH701x(SiS_Pr,0x76);
8771 temp &= 0xfb; /* Reset PLL */ 8593 temp &= 0xfb; /* Reset PLL */
8772 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x76); 8594 SiS_SetCH701x(SiS_Pr,0x76,temp);
8773 SiS_LongDelay(SiS_Pr,2); 8595 SiS_LongDelay(SiS_Pr, 2);
8774 temp = SiS_GetCH701x(SiS_Pr,0x76); 8596 temp = SiS_GetCH701x(SiS_Pr,0x76);
8775 temp |= 0x04; /* PLL normal operation */ 8597 temp |= 0x04; /* PLL normal operation */
8776 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x76); 8598 SiS_SetCH701x(SiS_Pr,0x76,temp);
8777 if(HwInfo->jChipType == SIS_740) { 8599 if(SiS_Pr->ChipType == SIS_740) {
8778 SiS_SetCH701x(SiS_Pr,0xe078); /* PLL loop filter */ 8600 SiS_SetCH701x(SiS_Pr,0x78,0xe0); /* PLL loop filter */
8779 } else { 8601 } else {
8780 SiS_SetCH701x(SiS_Pr,0x6078); 8602 SiS_SetCH701x(SiS_Pr,0x78,0x60);
8781 } 8603 }
8782 SiS_LongDelay(SiS_Pr,2); 8604 SiS_LongDelay(SiS_Pr, 2);
8783 } while(0); 8605 } while(0);
8784 8606
8785 SiS_SetCH701x(SiS_Pr,0x0077); /* MV? */ 8607 SiS_SetCH701x(SiS_Pr,0x77,0x00); /* MV? */
8786} 8608}
8787 8609
8788static void 8610static void
8789SiS_ChrontelDoSomething1(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 8611SiS_ChrontelDoSomething1(struct SiS_Private *SiS_Pr)
8790{ 8612{
8791 USHORT temp; 8613 unsigned short temp;
8792 8614
8793 temp = SiS_GetCH701x(SiS_Pr,0x03); 8615 temp = SiS_GetCH701x(SiS_Pr,0x03);
8794 temp |= 0x80; /* Set datapath 1 to TV */ 8616 temp |= 0x80; /* Set datapath 1 to TV */
8795 temp &= 0xbf; /* Set datapath 2 to LVDS */ 8617 temp &= 0xbf; /* Set datapath 2 to LVDS */
8796 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x03); 8618 SiS_SetCH701x(SiS_Pr,0x03,temp);
8797 8619
8798 if(HwInfo->jChipType == SIS_740) { 8620 if(SiS_Pr->ChipType == SIS_740) {
8799 8621
8800 temp = SiS_GetCH701x(SiS_Pr,0x1c); 8622 temp = SiS_GetCH701x(SiS_Pr,0x1c);
8801 temp &= 0xfb; /* Normal XCLK phase */ 8623 temp &= 0xfb; /* Normal XCLK phase */
8802 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x1c); 8624 SiS_SetCH701x(SiS_Pr,0x1c,temp);
8803 8625
8804 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03); 8626 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03);
8805 8627
8806 temp = SiS_GetCH701x(SiS_Pr,0x64); 8628 temp = SiS_GetCH701x(SiS_Pr,0x64);
8807 temp |= 0x40; /* ? Bit not defined */ 8629 temp |= 0x40; /* ? Bit not defined */
8808 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x64); 8630 SiS_SetCH701x(SiS_Pr,0x64,temp);
8809 8631
8810 temp = SiS_GetCH701x(SiS_Pr,0x03); 8632 temp = SiS_GetCH701x(SiS_Pr,0x03);
8811 temp &= 0x3f; /* D1 input to both LVDS and TV */ 8633 temp &= 0x3f; /* D1 input to both LVDS and TV */
8812 SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x03); 8634 SiS_SetCH701x(SiS_Pr,0x03,temp);
8813 8635
8814 if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) { 8636 if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) {
8815 SiS_SetCH701x(SiS_Pr,0x4063); /* LVDS off */ 8637 SiS_SetCH701x(SiS_Pr,0x63,0x40); /* LVDS off */
8816 SiS_LongDelay(SiS_Pr, 1); 8638 SiS_LongDelay(SiS_Pr, 1);
8817 SiS_SetCH701x(SiS_Pr,0x0063); /* LVDS on */ 8639 SiS_SetCH701x(SiS_Pr,0x63,0x00); /* LVDS on */
8818 SiS_ChrontelResetDB(SiS_Pr, HwInfo); 8640 SiS_ChrontelResetDB(SiS_Pr);
8819 SiS_ChrontelDoSomething2(SiS_Pr, HwInfo); 8641 SiS_ChrontelDoSomething2(SiS_Pr);
8820 SiS_ChrontelDoSomething3(SiS_Pr, 0, HwInfo); 8642 SiS_ChrontelDoSomething3(SiS_Pr, 0);
8821 } else { 8643 } else {
8822 temp = SiS_GetCH701x(SiS_Pr,0x66); 8644 temp = SiS_GetCH701x(SiS_Pr,0x66);
8823 if(temp != 0x45) { 8645 if(temp != 0x45) {
8824 SiS_ChrontelResetDB(SiS_Pr, HwInfo); 8646 SiS_ChrontelResetDB(SiS_Pr);
8825 SiS_ChrontelDoSomething2(SiS_Pr, HwInfo); 8647 SiS_ChrontelDoSomething2(SiS_Pr);
8826 SiS_ChrontelDoSomething3(SiS_Pr, 0, HwInfo); 8648 SiS_ChrontelDoSomething3(SiS_Pr, 0);
8827 } 8649 }
8828 } 8650 }
8829 8651
8830 } else { /* 650 */ 8652 } else { /* 650 */
8831 8653
8832 SiS_ChrontelResetDB(SiS_Pr,HwInfo); 8654 SiS_ChrontelResetDB(SiS_Pr);
8833 SiS_ChrontelDoSomething2(SiS_Pr,HwInfo); 8655 SiS_ChrontelDoSomething2(SiS_Pr);
8834 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34); 8656 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34);
8835 SiS_ChrontelDoSomething3(SiS_Pr,temp,HwInfo); 8657 SiS_ChrontelDoSomething3(SiS_Pr,temp);
8836 SiS_SetCH701x(SiS_Pr,0xaf76); /* All power on, LVDS normal operation */ 8658 SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* All power on, LVDS normal operation */
8837 8659
8838 } 8660 }
8839 8661
@@ -8845,15 +8667,12 @@ SiS_ChrontelDoSomething1(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
8845/*********************************************/ 8667/*********************************************/
8846 8668
8847BOOLEAN 8669BOOLEAN
8848SiS_SetCRT2Group(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo) 8670SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
8849{ 8671{
8850#ifdef SIS300 8672#ifdef SIS300
8851 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 8673 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
8852#endif
8853 USHORT ModeIdIndex, RefreshRateTableIndex;
8854#if 0
8855 USHORT temp;
8856#endif 8674#endif
8675 unsigned short ModeIdIndex, RefreshRateTableIndex;
8857 8676
8858 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2; 8677 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
8859 8678
@@ -8866,37 +8685,37 @@ SiS_SetCRT2Group(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
8866 /* Used for shifting CR33 */ 8685 /* Used for shifting CR33 */
8867 SiS_Pr->SiS_SelectCRT2Rate = 4; 8686 SiS_Pr->SiS_SelectCRT2Rate = 4;
8868 8687
8869 SiS_UnLockCRT2(SiS_Pr, HwInfo); 8688 SiS_UnLockCRT2(SiS_Pr);
8870 8689
8871 RefreshRateTableIndex = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex, HwInfo); 8690 RefreshRateTableIndex = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex);
8872 8691
8873 SiS_SaveCRT2Info(SiS_Pr,ModeNo); 8692 SiS_SaveCRT2Info(SiS_Pr,ModeNo);
8874 8693
8875 if(SiS_Pr->SiS_SetFlag & LowModeTests) { 8694 if(SiS_Pr->SiS_SetFlag & LowModeTests) {
8876 SiS_DisableBridge(SiS_Pr,HwInfo); 8695 SiS_DisableBridge(SiS_Pr);
8877 if((SiS_Pr->SiS_IF_DEF_LVDS == 1) && (HwInfo->jChipType == SIS_730)) { 8696 if((SiS_Pr->SiS_IF_DEF_LVDS == 1) && (SiS_Pr->ChipType == SIS_730)) {
8878 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,0x80); 8697 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,0x80);
8879 } 8698 }
8880 SiS_SetCRT2ModeRegs(SiS_Pr, ModeNo, ModeIdIndex, HwInfo); 8699 SiS_SetCRT2ModeRegs(SiS_Pr, ModeNo, ModeIdIndex);
8881 } 8700 }
8882 8701
8883 if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) { 8702 if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
8884 SiS_LockCRT2(SiS_Pr, HwInfo); 8703 SiS_LockCRT2(SiS_Pr);
8885 SiS_DisplayOn(SiS_Pr); 8704 SiS_DisplayOn(SiS_Pr);
8886 return TRUE; 8705 return TRUE;
8887 } 8706 }
8888 8707
8889 SiS_GetCRT2Data(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo); 8708 SiS_GetCRT2Data(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
8890 8709
8891 /* Set up Panel Link for LVDS and LCDA */ 8710 /* Set up Panel Link for LVDS and LCDA */
8892 SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0; 8711 SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0;
8893 if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) || 8712 if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
8894 ((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) || 8713 ((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) ||
8895 ((HwInfo->jChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) ) { 8714 ((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS30xBLV)) ) {
8896 SiS_GetLVDSDesData(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo); 8715 SiS_GetLVDSDesData(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
8897 } 8716 }
8898 8717
8899#ifdef LINUX_XF86 8718#ifdef SIS_XORG_XF86
8900#ifdef TWDEBUG 8719#ifdef TWDEBUG
8901 xf86DrvMsg(0, X_INFO, "(init301: LCDHDES 0x%03x LCDVDES 0x%03x)\n", SiS_Pr->SiS_LCDHDES, SiS_Pr->SiS_LCDVDES); 8720 xf86DrvMsg(0, X_INFO, "(init301: LCDHDES 0x%03x LCDVDES 0x%03x)\n", SiS_Pr->SiS_LCDHDES, SiS_Pr->SiS_LCDVDES);
8902 xf86DrvMsg(0, X_INFO, "(init301: HDE 0x%03x VDE 0x%03x)\n", SiS_Pr->SiS_HDE, SiS_Pr->SiS_VDE); 8721 xf86DrvMsg(0, X_INFO, "(init301: HDE 0x%03x VDE 0x%03x)\n", SiS_Pr->SiS_HDE, SiS_Pr->SiS_VDE);
@@ -8907,86 +8726,79 @@ SiS_SetCRT2Group(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
8907#endif 8726#endif
8908 8727
8909 if(SiS_Pr->SiS_SetFlag & LowModeTests) { 8728 if(SiS_Pr->SiS_SetFlag & LowModeTests) {
8910 SiS_SetGroup1(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, RefreshRateTableIndex); 8729 SiS_SetGroup1(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
8911 } 8730 }
8912 8731
8913 if(SiS_Pr->SiS_VBType & VB_SISVB) { 8732 if(SiS_Pr->SiS_VBType & VB_SISVB) {
8914 8733
8915 if(SiS_Pr->SiS_SetFlag & LowModeTests) { 8734 if(SiS_Pr->SiS_SetFlag & LowModeTests) {
8916 8735
8917 SiS_SetGroup2(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo); 8736 SiS_SetGroup2(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
8918#ifdef SIS315H 8737#ifdef SIS315H
8919 SiS_SetGroup2_C_ELV(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo); 8738 SiS_SetGroup2_C_ELV(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
8920#endif 8739#endif
8921 SiS_SetGroup3(SiS_Pr, ModeNo, ModeIdIndex, HwInfo); 8740 SiS_SetGroup3(SiS_Pr, ModeNo, ModeIdIndex);
8922 SiS_SetGroup4(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo); 8741 SiS_SetGroup4(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
8923#ifdef SIS315H 8742#ifdef SIS315H
8924 SiS_SetGroup4_C_ELV(SiS_Pr, HwInfo, ModeNo, ModeIdIndex); 8743 SiS_SetGroup4_C_ELV(SiS_Pr, ModeNo, ModeIdIndex);
8925#endif 8744#endif
8926 SiS_SetGroup5(SiS_Pr, ModeNo, ModeIdIndex, HwInfo); 8745 SiS_SetGroup5(SiS_Pr, ModeNo, ModeIdIndex);
8927 8746
8928 SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex, HwInfo); 8747 SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex);
8929 8748
8930 /* For 301BDH (Panel link initialization): */ 8749 /* For 301BDH (Panel link initialization): */
8931 if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { 8750 if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
8932 if(SiS_Pr->SiS_LCDResInfo != Panel_640x480) { 8751
8933 if(!((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10)))) { 8752 if(!((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10)))) {
8934 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { 8753 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
8935 SiS_ModCRT1CRTC(SiS_Pr,ModeNo,ModeIdIndex, 8754 SiS_ModCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
8936 RefreshRateTableIndex,HwInfo); 8755 }
8937 } 8756 }
8938 } 8757 SiS_SetCRT2ECLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
8939 } 8758 }
8940 SiS_SetCRT2ECLK(SiS_Pr,ModeNo,ModeIdIndex, 8759 }
8941 RefreshRateTableIndex,HwInfo);
8942 }
8943 }
8944 8760
8945 } else { 8761 } else {
8946 8762
8947 SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex, HwInfo); 8763 SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex);
8948 8764
8949 if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { 8765 SiS_ModCRT1CRTC(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
8950 SiS_ModCRT1CRTC(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,HwInfo);
8951 }
8952 8766
8953 SiS_SetCRT2ECLK(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,HwInfo); 8767 SiS_SetCRT2ECLK(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
8954 8768
8955 if(SiS_Pr->SiS_SetFlag & LowModeTests) { 8769 if(SiS_Pr->SiS_SetFlag & LowModeTests) {
8956 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 8770 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
8957 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { 8771 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
8958 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { 8772 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
8959#ifdef SIS315H 8773#ifdef SIS315H
8960 SiS_SetCH701xForLCD(SiS_Pr,HwInfo); 8774 SiS_SetCH701xForLCD(SiS_Pr);
8961#endif 8775#endif
8962 } 8776 }
8963 } 8777 }
8964 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 8778 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
8965 SiS_SetCHTVReg(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex); 8779 SiS_SetCHTVReg(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
8966 } 8780 }
8967 } 8781 }
8968 } 8782 }
8969 8783
8970 } 8784 }
8971 8785
8972#ifdef SIS300 8786#ifdef SIS300
8973 if(HwInfo->jChipType < SIS_315H) { 8787 if(SiS_Pr->ChipType < SIS_315H) {
8974 if(SiS_Pr->SiS_SetFlag & LowModeTests) { 8788 if(SiS_Pr->SiS_SetFlag & LowModeTests) {
8975 if(SiS_Pr->SiS_UseOEM) { 8789 if(SiS_Pr->SiS_UseOEM) {
8976 if((SiS_Pr->SiS_UseROM) && (SiS_Pr->SiS_UseOEM == -1)) { 8790 if((SiS_Pr->SiS_UseROM) && (SiS_Pr->SiS_UseOEM == -1)) {
8977 if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) { 8791 if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
8978 SiS_OEM300Setting(SiS_Pr,HwInfo,ModeNo,ModeIdIndex, 8792 SiS_OEM300Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
8979 RefreshRateTableIndex);
8980 } 8793 }
8981 } else { 8794 } else {
8982 SiS_OEM300Setting(SiS_Pr,HwInfo,ModeNo,ModeIdIndex, 8795 SiS_OEM300Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
8983 RefreshRateTableIndex);
8984 } 8796 }
8985 } 8797 }
8986 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 8798 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
8987 if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || 8799 if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
8988 (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) { 8800 (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
8989 SetOEMLCDData2(SiS_Pr, HwInfo, ModeNo, ModeIdIndex,RefreshRateTableIndex); 8801 SetOEMLCDData2(SiS_Pr, ModeNo, ModeIdIndex,RefreshRateTableIndex);
8990 } 8802 }
8991 SiS_DisplayOn(SiS_Pr); 8803 SiS_DisplayOn(SiS_Pr);
8992 } 8804 }
@@ -8995,21 +8807,21 @@ SiS_SetCRT2Group(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
8995#endif 8807#endif
8996 8808
8997#ifdef SIS315H 8809#ifdef SIS315H
8998 if(HwInfo->jChipType >= SIS_315H) { 8810 if(SiS_Pr->ChipType >= SIS_315H) {
8999 if(SiS_Pr->SiS_SetFlag & LowModeTests) { 8811 if(SiS_Pr->SiS_SetFlag & LowModeTests) {
9000 if(HwInfo->jChipType < SIS_661) { 8812 if(SiS_Pr->ChipType < SIS_661) {
9001 SiS_FinalizeLCD(SiS_Pr, ModeNo, ModeIdIndex, HwInfo); 8813 SiS_FinalizeLCD(SiS_Pr, ModeNo, ModeIdIndex);
9002 SiS_OEM310Setting(SiS_Pr, HwInfo, ModeNo, ModeIdIndex, RefreshRateTableIndex); 8814 SiS_OEM310Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
9003 } else { 8815 } else {
9004 SiS_OEM661Setting(SiS_Pr, HwInfo, ModeNo, ModeIdIndex, RefreshRateTableIndex); 8816 SiS_OEM661Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
9005 } 8817 }
9006 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x40); 8818 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x40);
9007 } 8819 }
9008 } 8820 }
9009#endif 8821#endif
9010 8822
9011 if(SiS_Pr->SiS_SetFlag & LowModeTests) { 8823 if(SiS_Pr->SiS_SetFlag & LowModeTests) {
9012 SiS_EnableBridge(SiS_Pr, HwInfo); 8824 SiS_EnableBridge(SiS_Pr);
9013 } 8825 }
9014 8826
9015 SiS_DisplayOn(SiS_Pr); 8827 SiS_DisplayOn(SiS_Pr);
@@ -9017,15 +8829,15 @@ SiS_SetCRT2Group(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
9017 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { 8829 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
9018 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 8830 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
9019 /* Disable LCD panel when using TV */ 8831 /* Disable LCD panel when using TV */
9020 SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFF,0x0C); 8832 SiS_SetRegSR11ANDOR(SiS_Pr,0xFF,0x0C);
9021 } else { 8833 } else {
9022 /* Disable TV when using LCD */ 8834 /* Disable TV when using LCD */
9023 SiS_SetCH70xxANDOR(SiS_Pr,0x010E,0xF8); 8835 SiS_SetCH70xxANDOR(SiS_Pr,0x0e,0x01,0xf8);
9024 } 8836 }
9025 } 8837 }
9026 8838
9027 if(SiS_Pr->SiS_SetFlag & LowModeTests) { 8839 if(SiS_Pr->SiS_SetFlag & LowModeTests) {
9028 SiS_LockCRT2(SiS_Pr,HwInfo); 8840 SiS_LockCRT2(SiS_Pr);
9029 } 8841 }
9030 8842
9031 return TRUE; 8843 return TRUE;
@@ -9037,13 +8849,13 @@ SiS_SetCRT2Group(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
9037/*********************************************/ 8849/*********************************************/
9038 8850
9039void 8851void
9040SiS_SiS30xBLOn(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 8852SiS_SiS30xBLOn(struct SiS_Private *SiS_Pr)
9041{ 8853{
9042 /* Switch on LCD backlight on SiS30xLV */ 8854 /* Switch on LCD backlight on SiS30xLV */
9043 SiS_DDC2Delay(SiS_Pr,0xff00); 8855 SiS_DDC2Delay(SiS_Pr,0xff00);
9044 if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) { 8856 if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
9045 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02); 8857 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
9046 SiS_WaitVBRetrace(SiS_Pr,HwInfo); 8858 SiS_WaitVBRetrace(SiS_Pr);
9047 } 8859 }
9048 if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x01)) { 8860 if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x01)) {
9049 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01); 8861 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
@@ -9051,12 +8863,11 @@ SiS_SiS30xBLOn(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
9051} 8863}
9052 8864
9053void 8865void
9054SiS_SiS30xBLOff(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 8866SiS_SiS30xBLOff(struct SiS_Private *SiS_Pr)
9055{ 8867{
9056 /* Switch off LCD backlight on SiS30xLV */ 8868 /* Switch off LCD backlight on SiS30xLV */
9057 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE); 8869 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
9058 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD); 8870 SiS_DDC2Delay(SiS_Pr,0xff00);
9059 SiS_DDC2Delay(SiS_Pr,0xe000);
9060} 8871}
9061 8872
9062/*********************************************/ 8873/*********************************************/
@@ -9064,7 +8875,7 @@ SiS_SiS30xBLOff(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
9064/*********************************************/ 8875/*********************************************/
9065 8876
9066static void 8877static void
9067SiS_SetupDDCN(SiS_Private *SiS_Pr) 8878SiS_SetupDDCN(struct SiS_Private *SiS_Pr)
9068{ 8879{
9069 SiS_Pr->SiS_DDC_NData = ~SiS_Pr->SiS_DDC_Data; 8880 SiS_Pr->SiS_DDC_NData = ~SiS_Pr->SiS_DDC_Data;
9070 SiS_Pr->SiS_DDC_NClk = ~SiS_Pr->SiS_DDC_Clk; 8881 SiS_Pr->SiS_DDC_NClk = ~SiS_Pr->SiS_DDC_Clk;
@@ -9075,12 +8886,12 @@ SiS_SetupDDCN(SiS_Private *SiS_Pr)
9075} 8886}
9076 8887
9077#ifdef SIS300 8888#ifdef SIS300
9078static UCHAR * 8889static unsigned char *
9079SiS_SetTrumpBlockLoop(SiS_Private *SiS_Pr, UCHAR *dataptr) 8890SiS_SetTrumpBlockLoop(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
9080{ 8891{
9081 int i, j, num; 8892 int i, j, num;
9082 USHORT tempah,temp; 8893 unsigned short tempah,temp;
9083 UCHAR *mydataptr; 8894 unsigned char *mydataptr;
9084 8895
9085 for(i=0; i<20; i++) { /* Do 20 attempts to write */ 8896 for(i=0; i<20; i++) { /* Do 20 attempts to write */
9086 mydataptr = dataptr; 8897 mydataptr = dataptr;
@@ -9088,7 +8899,7 @@ SiS_SetTrumpBlockLoop(SiS_Private *SiS_Pr, UCHAR *dataptr)
9088 if(!num) return mydataptr; 8899 if(!num) return mydataptr;
9089 if(i) { 8900 if(i) {
9090 SiS_SetStop(SiS_Pr); 8901 SiS_SetStop(SiS_Pr);
9091 SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT*2); 8902 SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 2);
9092 } 8903 }
9093 if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */ 8904 if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
9094 tempah = SiS_Pr->SiS_DDC_DeviceAddr; 8905 tempah = SiS_Pr->SiS_DDC_DeviceAddr;
@@ -9110,12 +8921,12 @@ SiS_SetTrumpBlockLoop(SiS_Private *SiS_Pr, UCHAR *dataptr)
9110} 8921}
9111 8922
9112static BOOLEAN 8923static BOOLEAN
9113SiS_SetTrumpionBlock(SiS_Private *SiS_Pr, UCHAR *dataptr) 8924SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
9114{ 8925{
9115 SiS_Pr->SiS_DDC_DeviceAddr = 0xF0; /* DAB (Device Address Byte) */ 8926 SiS_Pr->SiS_DDC_DeviceAddr = 0xF0; /* DAB (Device Address Byte) */
9116 SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */ 8927 SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
9117 SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */ 8928 SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
9118 SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */ 8929 SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
9119 SiS_SetupDDCN(SiS_Pr); 8930 SiS_SetupDDCN(SiS_Pr);
9120 8931
9121 SiS_SetSwitchDDC2(SiS_Pr); 8932 SiS_SetSwitchDDC2(SiS_Pr);
@@ -9124,9 +8935,11 @@ SiS_SetTrumpionBlock(SiS_Private *SiS_Pr, UCHAR *dataptr)
9124 dataptr = SiS_SetTrumpBlockLoop(SiS_Pr, dataptr); 8935 dataptr = SiS_SetTrumpBlockLoop(SiS_Pr, dataptr);
9125 if(!dataptr) return FALSE; 8936 if(!dataptr) return FALSE;
9126 } 8937 }
8938#ifdef SIS_XORG_XF86
9127#ifdef TWDEBUG 8939#ifdef TWDEBUG
9128 xf86DrvMsg(0, X_INFO, "Trumpion block success\n"); 8940 xf86DrvMsg(0, X_INFO, "Trumpion block success\n");
9129#endif 8941#endif
8942#endif
9130 return TRUE; 8943 return TRUE;
9131} 8944}
9132#endif 8945#endif
@@ -9139,155 +8952,121 @@ SiS_SetTrumpionBlock(SiS_Private *SiS_Pr, UCHAR *dataptr)
9139 */ 8952 */
9140 8953
9141static BOOLEAN 8954static BOOLEAN
9142SiS_SetChReg(SiS_Private *SiS_Pr, USHORT tempbx, USHORT myor) 8955SiS_SetChReg(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val, unsigned short myor)
9143{ 8956{
9144 USHORT tempah,temp,i; 8957 unsigned short temp, i;
9145 8958
9146 for(i=0; i<20; i++) { /* Do 20 attempts to write */ 8959 for(i=0; i<20; i++) { /* Do 20 attempts to write */
9147 if(i) { 8960 if(i) {
9148 SiS_SetStop(SiS_Pr); 8961 SiS_SetStop(SiS_Pr);
9149 SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT); 8962 SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 4);
9150 } 8963 }
9151 if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */ 8964 if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
9152 tempah = SiS_Pr->SiS_DDC_DeviceAddr; 8965 temp = SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr); /* Write DAB (S0=0=write) */
9153 temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write DAB (S0=0=write) */ 8966 if(temp) continue; /* (ERROR: no ack) */
9154 if(temp) continue; /* (ERROR: no ack) */ 8967 temp = SiS_WriteDDC2Data(SiS_Pr, (reg | myor)); /* Write RAB (700x: set bit 7, see datasheet) */
9155 tempah = tempbx & 0x00FF; /* Write RAB */ 8968 if(temp) continue; /* (ERROR: no ack) */
9156 tempah |= myor; /* (700x: set bit 7, see datasheet) */ 8969 temp = SiS_WriteDDC2Data(SiS_Pr, val); /* Write data */
9157 temp = SiS_WriteDDC2Data(SiS_Pr,tempah); 8970 if(temp) continue; /* (ERROR: no ack) */
9158 if(temp) continue; /* (ERROR: no ack) */ 8971 if(SiS_SetStop(SiS_Pr)) continue; /* Set stop condition */
9159 tempah = (tempbx & 0xFF00) >> 8;
9160 temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write data */
9161 if(temp) continue; /* (ERROR: no ack) */
9162 if(SiS_SetStop(SiS_Pr)) continue; /* Set stop condition */
9163 SiS_Pr->SiS_ChrontelInit = 1; 8972 SiS_Pr->SiS_ChrontelInit = 1;
9164 return TRUE; 8973 return TRUE;
9165 } 8974 }
9166 return FALSE; 8975 return FALSE;
9167} 8976}
9168 8977
9169#if 0
9170#ifdef SIS300
9171/* Write Trumpion register */
9172static void
9173SiS_SetTrumpReg(SiS_Private *SiS_Pr, USHORT tempbx)
9174{
9175 SiS_Pr->SiS_DDC_DeviceAddr = 0xF0; /* DAB (Device Address Byte) */
9176 SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
9177 SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
9178 SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
9179 SiS_SetupDDCN(SiS_Pr);
9180 SiS_SetChReg(SiS_Pr, tempbx, 0);
9181}
9182#endif
9183#endif
9184
9185/* Write to Chrontel 700x */ 8978/* Write to Chrontel 700x */
9186/* Parameter is [Data (S15-S8) | Register no (S7-S0)] */
9187void 8979void
9188SiS_SetCH700x(SiS_Private *SiS_Pr, USHORT tempbx) 8980SiS_SetCH700x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
9189{ 8981{
9190 SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */ 8982 SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */
9191 8983
8984 SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
8985
9192 if(!(SiS_Pr->SiS_ChrontelInit)) { 8986 if(!(SiS_Pr->SiS_ChrontelInit)) {
9193 SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */ 8987 SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
9194 SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */ 8988 SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
9195 SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */ 8989 SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
9196 SiS_SetupDDCN(SiS_Pr); 8990 SiS_SetupDDCN(SiS_Pr);
9197 } 8991 }
9198 8992
9199 if( (!(SiS_SetChReg(SiS_Pr, tempbx, 0x80))) && 8993 if( (!(SiS_SetChReg(SiS_Pr, reg, val, 0x80))) &&
9200 (!(SiS_Pr->SiS_ChrontelInit)) ) { 8994 (!(SiS_Pr->SiS_ChrontelInit)) ) {
9201 SiS_Pr->SiS_DDC_Index = 0x0a; /* Bit 7 = SC; Bit 6 = SD */ 8995 SiS_Pr->SiS_DDC_Index = 0x0a;
9202 SiS_Pr->SiS_DDC_Data = 0x80; /* Bitmask in IndexReg for Data */ 8996 SiS_Pr->SiS_DDC_Data = 0x80;
9203 SiS_Pr->SiS_DDC_Clk = 0x40; /* Bitmask in IndexReg for Clk */ 8997 SiS_Pr->SiS_DDC_Clk = 0x40;
9204 SiS_SetupDDCN(SiS_Pr); 8998 SiS_SetupDDCN(SiS_Pr);
9205 8999
9206 SiS_SetChReg(SiS_Pr, tempbx, 0x80); 9000 SiS_SetChReg(SiS_Pr, reg, val, 0x80);
9207 } 9001 }
9208} 9002}
9209 9003
9210/* Write to Chrontel 701x */ 9004/* Write to Chrontel 701x */
9211/* Parameter is [Data (S15-S8) | Register no (S7-S0)] */ 9005/* Parameter is [Data (S15-S8) | Register no (S7-S0)] */
9212void 9006void
9213SiS_SetCH701x(SiS_Private *SiS_Pr, USHORT tempbx) 9007SiS_SetCH701x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
9214{ 9008{
9215 SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */ 9009 SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
9216 SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */ 9010 SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */
9217 SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */ 9011 SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */
9218 SiS_SetupDDCN(SiS_Pr); 9012 SiS_SetupDDCN(SiS_Pr);
9219 SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */ 9013 SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */
9220 SiS_SetChReg(SiS_Pr, tempbx, 0); 9014 SiS_SetChReg(SiS_Pr, reg, val, 0);
9221} 9015}
9222 9016
9223static void 9017#ifdef SIS_LINUX_KERNEL
9224SiS_SetCH70xx(SiS_Private *SiS_Pr, USHORT tempbx) 9018static
9019#endif
9020void
9021SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
9225{ 9022{
9226 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) 9023 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
9227 SiS_SetCH700x(SiS_Pr,tempbx); 9024 SiS_SetCH700x(SiS_Pr, reg, val);
9228 else 9025 else
9229 SiS_SetCH701x(SiS_Pr,tempbx); 9026 SiS_SetCH701x(SiS_Pr, reg, val);
9230} 9027}
9231 9028
9232static USHORT 9029static unsigned short
9233SiS_GetChReg(SiS_Private *SiS_Pr, USHORT myor) 9030SiS_GetChReg(struct SiS_Private *SiS_Pr, unsigned short myor)
9234{ 9031{
9235 USHORT tempah,temp,i; 9032 unsigned short tempah, temp, i;
9236 9033
9237 for(i=0; i<20; i++) { /* Do 20 attempts to read */ 9034 for(i=0; i<20; i++) { /* Do 20 attempts to read */
9238 if(i) { 9035 if(i) {
9239 SiS_SetStop(SiS_Pr); 9036 SiS_SetStop(SiS_Pr);
9240 SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT); 9037 SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 4);
9241 } 9038 }
9242 if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */ 9039 if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
9243 tempah = SiS_Pr->SiS_DDC_DeviceAddr; 9040 temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_DeviceAddr); /* Write DAB (S0=0=write) */
9244 temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write DAB (S0=0=write) */ 9041 if(temp) continue; /* (ERROR: no ack) */
9245 if(temp) continue; /* (ERROR: no ack) */ 9042 temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_ReadAddr | myor); /* Write RAB (700x: | 0x80) */
9246 tempah = SiS_Pr->SiS_DDC_ReadAddr | myor; /* Write RAB (700x: | 0x80) */ 9043 if(temp) continue; /* (ERROR: no ack) */
9247 temp = SiS_WriteDDC2Data(SiS_Pr,tempah); 9044 if (SiS_SetStart(SiS_Pr)) continue; /* Re-start */
9248 if(temp) continue; /* (ERROR: no ack) */ 9045 temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_DeviceAddr | 0x01);/* DAB (S0=1=read) */
9249 if (SiS_SetStart(SiS_Pr)) continue; /* Re-start */ 9046 if(temp) continue; /* (ERROR: no ack) */
9250 tempah = SiS_Pr->SiS_DDC_DeviceAddr | 0x01;/* DAB | 0x01 = Read */ 9047 tempah = SiS_ReadDDC2Data(SiS_Pr); /* Read byte */
9251 temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* DAB (S0=1=read) */ 9048 if(SiS_SetStop(SiS_Pr)) continue; /* Stop condition */
9252 if(temp) continue; /* (ERROR: no ack) */
9253 tempah = SiS_ReadDDC2Data(SiS_Pr,tempah); /* Read byte */
9254 if(SiS_SetStop(SiS_Pr)) continue; /* Stop condition */
9255 SiS_Pr->SiS_ChrontelInit = 1; 9049 SiS_Pr->SiS_ChrontelInit = 1;
9256 return(tempah); 9050 return tempah;
9257 } 9051 }
9258 return 0xFFFF; 9052 return 0xFFFF;
9259} 9053}
9260 9054
9261#if 0
9262#ifdef SIS300
9263/* Read from Trumpion */
9264static USHORT
9265SiS_GetTrumpReg(SiS_Private *SiS_Pr, USHORT tempbx)
9266{
9267 SiS_Pr->SiS_DDC_DeviceAddr = 0xF0; /* DAB */
9268 SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
9269 SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
9270 SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
9271 SiS_SetupDDCN(SiS_Pr);
9272 SiS_Pr->SiS_DDC_ReadAddr = tempbx;
9273 return(SiS_GetChReg(SiS_Pr,0));
9274}
9275#endif
9276#endif
9277
9278/* Read from Chrontel 700x */ 9055/* Read from Chrontel 700x */
9279/* Parameter is [Register no (S7-S0)] */ 9056/* Parameter is [Register no (S7-S0)] */
9280USHORT 9057unsigned short
9281SiS_GetCH700x(SiS_Private *SiS_Pr, USHORT tempbx) 9058SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short tempbx)
9282{ 9059{
9283 USHORT result; 9060 unsigned short result;
9284 9061
9285 SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */ 9062 SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */
9286 9063
9064 SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
9065
9287 if(!(SiS_Pr->SiS_ChrontelInit)) { 9066 if(!(SiS_Pr->SiS_ChrontelInit)) {
9288 SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */ 9067 SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
9289 SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */ 9068 SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
9290 SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */ 9069 SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
9291 SiS_SetupDDCN(SiS_Pr); 9070 SiS_SetupDDCN(SiS_Pr);
9292 } 9071 }
9293 9072
@@ -9303,52 +9082,69 @@ SiS_GetCH700x(SiS_Private *SiS_Pr, USHORT tempbx)
9303 9082
9304 result = SiS_GetChReg(SiS_Pr,0x80); 9083 result = SiS_GetChReg(SiS_Pr,0x80);
9305 } 9084 }
9306 return(result); 9085 return result;
9307} 9086}
9308 9087
9309/* Read from Chrontel 701x */ 9088/* Read from Chrontel 701x */
9310/* Parameter is [Register no (S7-S0)] */ 9089/* Parameter is [Register no (S7-S0)] */
9311USHORT 9090unsigned short
9312SiS_GetCH701x(SiS_Private *SiS_Pr, USHORT tempbx) 9091SiS_GetCH701x(struct SiS_Private *SiS_Pr, unsigned short tempbx)
9313{ 9092{
9314 SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */ 9093 SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
9315 SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */ 9094 SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */
9316 SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */ 9095 SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */
9317 SiS_SetupDDCN(SiS_Pr); 9096 SiS_SetupDDCN(SiS_Pr);
9318 SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */ 9097 SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */
9319 9098
9320 SiS_Pr->SiS_DDC_ReadAddr = tempbx; 9099 SiS_Pr->SiS_DDC_ReadAddr = tempbx;
9321 9100
9322 return(SiS_GetChReg(SiS_Pr,0)); 9101 return SiS_GetChReg(SiS_Pr,0);
9323} 9102}
9324 9103
9325/* Read from Chrontel 70xx */ 9104/* Read from Chrontel 70xx */
9326/* Parameter is [Register no (S7-S0)] */ 9105/* Parameter is [Register no (S7-S0)] */
9327static USHORT 9106#ifdef SIS_LINUX_KERNEL
9328SiS_GetCH70xx(SiS_Private *SiS_Pr, USHORT tempbx) 9107static
9108#endif
9109unsigned short
9110SiS_GetCH70xx(struct SiS_Private *SiS_Pr, unsigned short tempbx)
9329{ 9111{
9330 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) 9112 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
9331 return(SiS_GetCH700x(SiS_Pr, tempbx)); 9113 return SiS_GetCH700x(SiS_Pr, tempbx);
9332 else 9114 else
9333 return(SiS_GetCH701x(SiS_Pr, tempbx)); 9115 return SiS_GetCH701x(SiS_Pr, tempbx);
9116}
9117
9118void
9119SiS_SetCH70xxANDOR(struct SiS_Private *SiS_Pr, unsigned short reg,
9120 unsigned char myor, unsigned short myand)
9121{
9122 unsigned short tempbl;
9123
9124 tempbl = (SiS_GetCH70xx(SiS_Pr, (reg & 0xFF)) & myand) | myor;
9125 SiS_SetCH70xx(SiS_Pr, reg, tempbl);
9334} 9126}
9335 9127
9336/* Our own DDC functions */ 9128/* Our own DDC functions */
9337static USHORT 9129#ifndef SIS_XORG_XF86
9338SiS_InitDDCRegs(SiS_Private *SiS_Pr, unsigned long VBFlags, int VGAEngine, 9130static
9339 USHORT adaptnum, USHORT DDCdatatype, BOOLEAN checkcr32) 9131#endif
9132unsigned short
9133SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
9134 unsigned short adaptnum, unsigned short DDCdatatype, BOOLEAN checkcr32,
9135 unsigned int VBFlags2)
9340{ 9136{
9341 unsigned char ddcdtype[] = { 0xa0, 0xa0, 0xa0, 0xa2, 0xa6 }; 9137 unsigned char ddcdtype[] = { 0xa0, 0xa0, 0xa0, 0xa2, 0xa6 };
9342 unsigned char flag, cr32; 9138 unsigned char flag, cr32;
9343 USHORT temp = 0, myadaptnum = adaptnum; 9139 unsigned short temp = 0, myadaptnum = adaptnum;
9344 9140
9345 if(adaptnum != 0) { 9141 if(adaptnum != 0) {
9346 if(!(VBFlags & (VB_301|VB_301B|VB_301C|VB_302B))) return 0xFFFF; 9142 if(!(VBFlags2 & VB2_SISTMDSBRIDGE)) return 0xFFFF;
9347 if((VBFlags & VB_30xBDH) && (adaptnum == 1)) return 0xFFFF; 9143 if((VBFlags2 & VB2_30xBDH) && (adaptnum == 1)) return 0xFFFF;
9348 } 9144 }
9349 9145
9350 /* adapternum for SiS bridges: 0 = CRT1, 1 = LCD, 2 = VGA2 */ 9146 /* adapternum for SiS bridges: 0 = CRT1, 1 = LCD, 2 = VGA2 */
9351 9147
9352 SiS_Pr->SiS_ChrontelInit = 0; /* force re-detection! */ 9148 SiS_Pr->SiS_ChrontelInit = 0; /* force re-detection! */
9353 9149
9354 SiS_Pr->SiS_DDC_SecAddr = 0; 9150 SiS_Pr->SiS_DDC_SecAddr = 0;
@@ -9360,7 +9156,7 @@ SiS_InitDDCRegs(SiS_Private *SiS_Pr, unsigned long VBFlags, int VGAEngine,
9360 cr32 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x32); 9156 cr32 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x32);
9361 9157
9362#if 0 9158#if 0
9363 if(VBFlags & VB_SISBRIDGE) { 9159 if(VBFlags2 & VB2_SISBRIDGE) {
9364 if(myadaptnum == 0) { 9160 if(myadaptnum == 0) {
9365 if(!(cr32 & 0x20)) { 9161 if(!(cr32 & 0x20)) {
9366 myadaptnum = 2; 9162 myadaptnum = 2;
@@ -9376,20 +9172,20 @@ SiS_InitDDCRegs(SiS_Private *SiS_Pr, unsigned long VBFlags, int VGAEngine,
9376#endif 9172#endif
9377 9173
9378 if(VGAEngine == SIS_300_VGA) { /* 300 series */ 9174 if(VGAEngine == SIS_300_VGA) { /* 300 series */
9379 9175
9380 if(myadaptnum != 0) { 9176 if(myadaptnum != 0) {
9381 flag = 0; 9177 flag = 0;
9382 if(VBFlags & VB_SISBRIDGE) { 9178 if(VBFlags2 & VB2_SISBRIDGE) {
9383 SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port; 9179 SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port;
9384 SiS_Pr->SiS_DDC_Index = 0x0f; 9180 SiS_Pr->SiS_DDC_Index = 0x0f;
9385 } 9181 }
9386 } 9182 }
9387 9183
9388 if(!(VBFlags & VB_301)) { 9184 if(!(VBFlags2 & VB2_301)) {
9389 if((cr32 & 0x80) && (checkcr32)) { 9185 if((cr32 & 0x80) && (checkcr32)) {
9390 if(myadaptnum >= 1) { 9186 if(myadaptnum >= 1) {
9391 if(!(cr32 & 0x08)) { 9187 if(!(cr32 & 0x08)) {
9392 myadaptnum = 1; 9188 myadaptnum = 1;
9393 if(!(cr32 & 0x10)) return 0xFFFF; 9189 if(!(cr32 & 0x10)) return 0xFFFF;
9394 } 9190 }
9395 } 9191 }
@@ -9401,17 +9197,17 @@ SiS_InitDDCRegs(SiS_Private *SiS_Pr, unsigned long VBFlags, int VGAEngine,
9401 9197
9402 } else { /* 315/330 series */ 9198 } else { /* 315/330 series */
9403 9199
9404 /* here we simplify: 0 = CRT1, 1 = CRT2 (VGA, LCD) */ 9200 /* here we simplify: 0 = CRT1, 1 = CRT2 (VGA, LCD) */
9405 9201
9406 if(VBFlags & VB_SISBRIDGE) { 9202 if(VBFlags2 & VB2_SISBRIDGE) {
9407 if(myadaptnum == 2) { 9203 if(myadaptnum == 2) {
9408 myadaptnum = 1; 9204 myadaptnum = 1;
9409 } 9205 }
9410 } 9206 }
9411 9207
9412 if(myadaptnum == 1) { 9208 if(myadaptnum == 1) {
9413 flag = 0; 9209 flag = 0;
9414 if(VBFlags & VB_SISBRIDGE) { 9210 if(VBFlags2 & VB2_SISBRIDGE) {
9415 SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port; 9211 SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port;
9416 SiS_Pr->SiS_DDC_Index = 0x0f; 9212 SiS_Pr->SiS_DDC_Index = 0x0f;
9417 } 9213 }
@@ -9429,93 +9225,96 @@ SiS_InitDDCRegs(SiS_Private *SiS_Pr, unsigned long VBFlags, int VGAEngine,
9429 temp = myadaptnum; 9225 temp = myadaptnum;
9430 if(myadaptnum == 1) { 9226 if(myadaptnum == 1) {
9431 temp = 0; 9227 temp = 0;
9432 if(VBFlags & VB_LVDS) flag = 0xff; 9228 if(VBFlags2 & VB2_LVDS) flag = 0xff;
9433 } 9229 }
9434 9230
9435 if(flag) temp = 0; 9231 if(flag) temp = 0;
9436 } 9232 }
9437 9233
9438 SiS_Pr->SiS_DDC_Data = 0x02 << temp; 9234 SiS_Pr->SiS_DDC_Data = 0x02 << temp;
9439 SiS_Pr->SiS_DDC_Clk = 0x01 << temp; 9235 SiS_Pr->SiS_DDC_Clk = 0x01 << temp;
9440 9236
9441 SiS_SetupDDCN(SiS_Pr); 9237 SiS_SetupDDCN(SiS_Pr);
9442 9238
9239#ifdef SIS_XORG_XF86
9443#ifdef TWDEBUG 9240#ifdef TWDEBUG
9444 xf86DrvMsg(0, X_INFO, "DDC Port %x Index %x Shift %d\n", 9241 xf86DrvMsg(0, X_INFO, "DDC Port %x Index %x Shift %d\n",
9445 SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, temp); 9242 SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, temp);
9446#endif 9243#endif
9447 9244#endif
9448 return 0; 9245 return 0;
9449} 9246}
9450 9247
9451static USHORT 9248static unsigned short
9452SiS_WriteDABDDC(SiS_Private *SiS_Pr) 9249SiS_WriteDABDDC(struct SiS_Private *SiS_Pr)
9453{ 9250{
9454 if(SiS_SetStart(SiS_Pr)) return 0xFFFF; 9251 if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
9455 if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr)) { 9252 if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr)) {
9456 return 0xFFFF; 9253 return 0xFFFF;
9457 } 9254 }
9458 if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_SecAddr)) { 9255 if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_SecAddr)) {
9459 return 0xFFFF; 9256 return 0xFFFF;
9460 } 9257 }
9461 return(0); 9258 return 0;
9462} 9259}
9463 9260
9464static USHORT 9261static unsigned short
9465SiS_PrepareReadDDC(SiS_Private *SiS_Pr) 9262SiS_PrepareReadDDC(struct SiS_Private *SiS_Pr)
9466{ 9263{
9467 if(SiS_SetStart(SiS_Pr)) return 0xFFFF; 9264 if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
9468 if(SiS_WriteDDC2Data(SiS_Pr, (SiS_Pr->SiS_DDC_DeviceAddr | 0x01))) { 9265 if(SiS_WriteDDC2Data(SiS_Pr, (SiS_Pr->SiS_DDC_DeviceAddr | 0x01))) {
9469 return 0xFFFF; 9266 return 0xFFFF;
9470 } 9267 }
9471 return(0); 9268 return 0;
9472} 9269}
9473 9270
9474static USHORT 9271static unsigned short
9475SiS_PrepareDDC(SiS_Private *SiS_Pr) 9272SiS_PrepareDDC(struct SiS_Private *SiS_Pr)
9476{ 9273{
9477 if(SiS_WriteDABDDC(SiS_Pr)) SiS_WriteDABDDC(SiS_Pr); 9274 if(SiS_WriteDABDDC(SiS_Pr)) SiS_WriteDABDDC(SiS_Pr);
9478 if(SiS_PrepareReadDDC(SiS_Pr)) return(SiS_PrepareReadDDC(SiS_Pr)); 9275 if(SiS_PrepareReadDDC(SiS_Pr)) return (SiS_PrepareReadDDC(SiS_Pr));
9479 return(0); 9276 return 0;
9480} 9277}
9481 9278
9482static void 9279static void
9483SiS_SendACK(SiS_Private *SiS_Pr, USHORT yesno) 9280SiS_SendACK(struct SiS_Private *SiS_Pr, unsigned short yesno)
9484{ 9281{
9485 SiS_SetSCLKLow(SiS_Pr); 9282 SiS_SetSCLKLow(SiS_Pr);
9486 if(yesno) { 9283 if(yesno) {
9487 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, 9284 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
9488 SiS_Pr->SiS_DDC_Index, 9285 SiS_Pr->SiS_DDC_Index,
9489 SiS_Pr->SiS_DDC_NData, 9286 SiS_Pr->SiS_DDC_NData,
9490 SiS_Pr->SiS_DDC_Data); 9287 SiS_Pr->SiS_DDC_Data);
9491 } else { 9288 } else {
9492 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, 9289 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
9493 SiS_Pr->SiS_DDC_Index, 9290 SiS_Pr->SiS_DDC_Index,
9494 SiS_Pr->SiS_DDC_NData, 9291 SiS_Pr->SiS_DDC_NData,
9495 0); 9292 0);
9496 } 9293 }
9497 SiS_SetSCLKHigh(SiS_Pr); 9294 SiS_SetSCLKHigh(SiS_Pr);
9498} 9295}
9499 9296
9500static USHORT 9297static unsigned short
9501SiS_DoProbeDDC(SiS_Private *SiS_Pr) 9298SiS_DoProbeDDC(struct SiS_Private *SiS_Pr)
9502{ 9299{
9503 unsigned char mask, value; 9300 unsigned char mask, value;
9504 USHORT temp, ret=0; 9301 unsigned short temp, ret=0;
9505 BOOLEAN failed = FALSE; 9302 BOOLEAN failed = FALSE;
9506 9303
9507 SiS_SetSwitchDDC2(SiS_Pr); 9304 SiS_SetSwitchDDC2(SiS_Pr);
9508 if(SiS_PrepareDDC(SiS_Pr)) { 9305 if(SiS_PrepareDDC(SiS_Pr)) {
9509 SiS_SetStop(SiS_Pr); 9306 SiS_SetStop(SiS_Pr);
9307#ifdef SIS_XORG_XF86
9510#ifdef TWDEBUG 9308#ifdef TWDEBUG
9511 xf86DrvMsg(0, X_INFO, "Probe: Prepare failed\n"); 9309 xf86DrvMsg(0, X_INFO, "Probe: Prepare failed\n");
9512#endif 9310#endif
9513 return(0xFFFF); 9311#endif
9312 return 0xFFFF;
9514 } 9313 }
9515 mask = 0xf0; 9314 mask = 0xf0;
9516 value = 0x20; 9315 value = 0x20;
9517 if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) { 9316 if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) {
9518 temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr, 0); 9317 temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
9519 SiS_SendACK(SiS_Pr, 0); 9318 SiS_SendACK(SiS_Pr, 0);
9520 if(temp == 0) { 9319 if(temp == 0) {
9521 mask = 0xff; 9320 mask = 0xff;
@@ -9523,34 +9322,41 @@ SiS_DoProbeDDC(SiS_Private *SiS_Pr)
9523 } else { 9322 } else {
9524 failed = TRUE; 9323 failed = TRUE;
9525 ret = 0xFFFF; 9324 ret = 0xFFFF;
9325#ifdef SIS_XORG_XF86
9526#ifdef TWDEBUG 9326#ifdef TWDEBUG
9527 xf86DrvMsg(0, X_INFO, "Probe: Read 1 failed\n"); 9327 xf86DrvMsg(0, X_INFO, "Probe: Read 1 failed\n");
9528#endif 9328#endif
9329#endif
9529 } 9330 }
9530 } 9331 }
9531 if(failed == FALSE) { 9332 if(failed == FALSE) {
9532 temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr, 0); 9333 temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
9533 SiS_SendACK(SiS_Pr, 1); 9334 SiS_SendACK(SiS_Pr, 1);
9534 temp &= mask; 9335 temp &= mask;
9535 if(temp == value) ret = 0; 9336 if(temp == value) ret = 0;
9536 else { 9337 else {
9537 ret = 0xFFFF; 9338 ret = 0xFFFF;
9339#ifdef SIS_XORG_XF86
9538#ifdef TWDEBUG 9340#ifdef TWDEBUG
9539 xf86DrvMsg(0, X_INFO, "Probe: Read 2 failed\n"); 9341 xf86DrvMsg(0, X_INFO, "Probe: Read 2 failed\n");
9540#endif 9342#endif
9343#endif
9541 if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) { 9344 if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) {
9542 if(temp == 0x30) ret = 0; 9345 if(temp == 0x30) ret = 0;
9543 } 9346 }
9544 } 9347 }
9545 } 9348 }
9546 SiS_SetStop(SiS_Pr); 9349 SiS_SetStop(SiS_Pr);
9547 return(ret); 9350 return ret;
9548} 9351}
9549 9352
9550static USHORT 9353#ifndef SIS_XORG_XF86
9551SiS_ProbeDDC(SiS_Private *SiS_Pr) 9354static
9355#endif
9356unsigned short
9357SiS_ProbeDDC(struct SiS_Private *SiS_Pr)
9552{ 9358{
9553 USHORT flag; 9359 unsigned short flag;
9554 9360
9555 flag = 0x180; 9361 flag = 0x180;
9556 SiS_Pr->SiS_DDC_DeviceAddr = 0xa0; 9362 SiS_Pr->SiS_DDC_DeviceAddr = 0xa0;
@@ -9560,16 +9366,19 @@ SiS_ProbeDDC(SiS_Private *SiS_Pr)
9560 SiS_Pr->SiS_DDC_DeviceAddr = 0xa6; 9366 SiS_Pr->SiS_DDC_DeviceAddr = 0xa6;
9561 if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x10; 9367 if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x10;
9562 if(!(flag & 0x1a)) flag = 0; 9368 if(!(flag & 0x1a)) flag = 0;
9563 return(flag); 9369 return flag;
9564} 9370}
9565 9371
9566static USHORT 9372#ifndef SIS_XORG_XF86
9567SiS_ReadDDC(SiS_Private *SiS_Pr, USHORT DDCdatatype, unsigned char *buffer) 9373static
9374#endif
9375unsigned short
9376SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype, unsigned char *buffer)
9568{ 9377{
9569 USHORT flag, length, i; 9378 unsigned short flag, length, i;
9570 unsigned char chksum,gotcha; 9379 unsigned char chksum,gotcha;
9571 9380
9572 if(DDCdatatype > 4) return 0xFFFF; 9381 if(DDCdatatype > 4) return 0xFFFF;
9573 9382
9574 flag = 0; 9383 flag = 0;
9575 SiS_SetSwitchDDC2(SiS_Pr); 9384 SiS_SetSwitchDDC2(SiS_Pr);
@@ -9579,21 +9388,21 @@ SiS_ReadDDC(SiS_Private *SiS_Pr, USHORT DDCdatatype, unsigned char *buffer)
9579 chksum = 0; 9388 chksum = 0;
9580 gotcha = 0; 9389 gotcha = 0;
9581 for(i=0; i<length; i++) { 9390 for(i=0; i<length; i++) {
9582 buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr, 0); 9391 buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
9583 chksum += buffer[i]; 9392 chksum += buffer[i];
9584 gotcha |= buffer[i]; 9393 gotcha |= buffer[i];
9585 SiS_SendACK(SiS_Pr, 0); 9394 SiS_SendACK(SiS_Pr, 0);
9586 } 9395 }
9587 buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr, 0); 9396 buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
9588 chksum += buffer[i]; 9397 chksum += buffer[i];
9589 SiS_SendACK(SiS_Pr, 1); 9398 SiS_SendACK(SiS_Pr, 1);
9590 if(gotcha) flag = (USHORT)chksum; 9399 if(gotcha) flag = (unsigned short)chksum;
9591 else flag = 0xFFFF; 9400 else flag = 0xFFFF;
9592 } else { 9401 } else {
9593 flag = 0xFFFF; 9402 flag = 0xFFFF;
9594 } 9403 }
9595 SiS_SetStop(SiS_Pr); 9404 SiS_SetStop(SiS_Pr);
9596 return(flag); 9405 return flag;
9597} 9406}
9598 9407
9599/* Our private DDC functions 9408/* Our private DDC functions
@@ -9617,17 +9426,25 @@ SiS_ReadDDC(SiS_Private *SiS_Pr, USHORT DDCdatatype, unsigned char *buffer)
9617 if DDCdatatype = 0: Returns supported DDC modes 9426 if DDCdatatype = 0: Returns supported DDC modes
9618 9427
9619 */ 9428 */
9620USHORT 9429unsigned short
9621SiS_HandleDDC(SiS_Private *SiS_Pr, unsigned long VBFlags, int VGAEngine, 9430SiS_HandleDDC(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
9622 USHORT adaptnum, USHORT DDCdatatype, unsigned char *buffer) 9431 unsigned short adaptnum, unsigned short DDCdatatype, unsigned char *buffer,
9432 unsigned int VBFlags2)
9623{ 9433{
9624 unsigned char sr1f,cr17=1; 9434 unsigned char sr1f, cr17=1;
9625 USHORT result; 9435 unsigned short result;
9626 9436
9627 if(adaptnum > 2) return 0xFFFF; 9437 if(adaptnum > 2)
9628 if(DDCdatatype > 4) return 0xFFFF; 9438 return 0xFFFF;
9629 if((!(VBFlags & VB_VIDEOBRIDGE)) && (adaptnum > 0)) return 0xFFFF; 9439
9630 if(SiS_InitDDCRegs(SiS_Pr, VBFlags, VGAEngine, adaptnum, DDCdatatype, FALSE) == 0xFFFF) return 0xFFFF; 9440 if(DDCdatatype > 4)
9441 return 0xFFFF;
9442
9443 if((!(VBFlags2 & VB2_VIDEOBRIDGE)) && (adaptnum > 0))
9444 return 0xFFFF;
9445
9446 if(SiS_InitDDCRegs(SiS_Pr, VBFlags, VGAEngine, adaptnum, DDCdatatype, FALSE, VBFlags2) == 0xFFFF)
9447 return 0xFFFF;
9631 9448
9632 sr1f = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f); 9449 sr1f = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f);
9633 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x1f,0x3f,0x04); 9450 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x1f,0x3f,0x04);
@@ -9656,10 +9473,12 @@ SiS_HandleDDC(SiS_Private *SiS_Pr, unsigned long VBFlags, int VGAEngine,
9656 (buffer[4] == 0xff) && (buffer[5] == 0xff) && 9473 (buffer[4] == 0xff) && (buffer[5] == 0xff) &&
9657 (buffer[6] == 0xff) && (buffer[7] == 0x00) && 9474 (buffer[6] == 0xff) && (buffer[7] == 0x00) &&
9658 (buffer[0x12] == 1)) { 9475 (buffer[0x12] == 1)) {
9659 if(adaptnum == 1) { 9476 if(!SiS_Pr->DDCPortMixup) {
9660 if(!(buffer[0x14] & 0x80)) result = 0xFFFE; 9477 if(adaptnum == 1) {
9661 } else { 9478 if(!(buffer[0x14] & 0x80)) result = 0xFFFE;
9662 if(buffer[0x14] & 0x80) result = 0xFFFE; 9479 } else {
9480 if(buffer[0x14] & 0x80) result = 0xFFFE;
9481 }
9663 } 9482 }
9664 } 9483 }
9665 } 9484 }
@@ -9671,832 +9490,10 @@ SiS_HandleDDC(SiS_Private *SiS_Pr, unsigned long VBFlags, int VGAEngine,
9671 return result; 9490 return result;
9672} 9491}
9673 9492
9674#ifdef LINUX_XF86
9675
9676static BOOLEAN
9677checkedid1(unsigned char *buffer)
9678{
9679 /* Check header */
9680 if((buffer[0] != 0x00) ||
9681 (buffer[1] != 0xff) ||
9682 (buffer[2] != 0xff) ||
9683 (buffer[3] != 0xff) ||
9684 (buffer[4] != 0xff) ||
9685 (buffer[5] != 0xff) ||
9686 (buffer[6] != 0xff) ||
9687 (buffer[7] != 0x00))
9688 return FALSE;
9689
9690 /* Check EDID version and revision */
9691 if((buffer[0x12] != 1) || (buffer[0x13] > 4)) return FALSE;
9692
9693 /* Check week of manufacture for sanity */
9694 if(buffer[0x10] > 53) return FALSE;
9695
9696 /* Check year of manufacture for sanity */
9697 if(buffer[0x11] > 40) return FALSE;
9698
9699 return TRUE;
9700}
9701
9702static BOOLEAN
9703checkedid2(unsigned char *buffer)
9704{
9705 USHORT year = buffer[6] | (buffer[7] << 8);
9706
9707 /* Check EDID version */
9708 if((buffer[0] & 0xf0) != 0x20) return FALSE;
9709
9710 /* Check week of manufacture for sanity */
9711 if(buffer[5] > 53) return FALSE;
9712
9713 /* Check year of manufacture for sanity */
9714 if((year != 0) && ((year < 1990) || (year > 2030))) return FALSE;
9715
9716 return TRUE;
9717}
9718
9719/* Sense the LCD parameters (CR36, CR37) via DDC */
9720/* SiS30x(B) only */
9721USHORT
9722SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
9723{
9724 USHORT DDCdatatype, paneltype, flag, xres=0, yres=0;
9725 USHORT index, myindex, lumsize, numcodes, panelvendor, panelproduct;
9726 int maxx=0, maxy=0, prefx=0, prefy=0;
9727 unsigned char cr37=0, seekcode;
9728 BOOLEAN checkexpand = FALSE;
9729 BOOLEAN havesync = FALSE;
9730 BOOLEAN indb = FALSE;
9731 int retry, i;
9732 unsigned char buffer[256];
9733
9734 for(i=0; i<7; i++) SiS_Pr->CP_DataValid[i] = FALSE;
9735 SiS_Pr->CP_HaveCustomData = FALSE;
9736 SiS_Pr->CP_MaxX = SiS_Pr->CP_MaxY = SiS_Pr->CP_MaxClock = 0;
9737 SiS_Pr->CP_PreferredX = SiS_Pr->CP_PreferredY = 0;
9738 SiS_Pr->CP_PreferredIndex = -1;
9739 SiS_Pr->CP_PrefClock = 0;
9740 SiS_Pr->PanelSelfDetected = FALSE;
9741
9742 if(!(pSiS->VBFlags & (VB_301|VB_301B|VB_301C|VB_302B))) return 0;
9743 if(pSiS->VBFlags & VB_30xBDH) return 0;
9744
9745 if(SiS_InitDDCRegs(SiS_Pr, pSiS->VBFlags, pSiS->VGAEngine, 1, 0, FALSE) == 0xFFFF) return 0;
9746
9747 SiS_Pr->SiS_DDC_SecAddr = 0x00;
9748
9749 /* Probe supported DA's */
9750 flag = SiS_ProbeDDC(SiS_Pr);
9751#ifdef TWDEBUG
9752 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_INFO,
9753 "CRT2 DDC capabilities 0x%x\n", flag);
9754#endif
9755 if(flag & 0x10) {
9756 SiS_Pr->SiS_DDC_DeviceAddr = 0xa6; /* EDID V2 (FP) */
9757 DDCdatatype = 4;
9758 } else if(flag & 0x08) {
9759 SiS_Pr->SiS_DDC_DeviceAddr = 0xa2; /* EDID V2 (P&D-D Monitor) */
9760 DDCdatatype = 3;
9761 } else if(flag & 0x02) {
9762 SiS_Pr->SiS_DDC_DeviceAddr = 0xa0; /* EDID V1 */
9763 DDCdatatype = 1;
9764 } else return 0; /* no DDC support (or no device attached) */
9765
9766 /* Read the entire EDID */
9767 retry = 2;
9768 do {
9769 if(SiS_ReadDDC(SiS_Pr, DDCdatatype, buffer)) {
9770 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
9771 "CRT2: DDC read failed (attempt %d), %s\n",
9772 (3-retry), (retry == 1) ? "giving up" : "retrying");
9773 retry--;
9774 if(retry == 0) return 0xFFFF;
9775 } else break;
9776 } while(1);
9777
9778#ifdef TWDEBUG
9779 for(i=0; i<256; i+=16) {
9780 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
9781 "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
9782 buffer[i], buffer[i+1], buffer[i+2], buffer[i+3],
9783 buffer[i+4], buffer[i+5], buffer[i+6], buffer[i+7],
9784 buffer[i+8], buffer[i+9], buffer[i+10], buffer[i+11],
9785 buffer[i+12], buffer[i+13], buffer[i+14], buffer[i+15]);
9786 }
9787#endif
9788
9789 /* Analyze EDID and retrieve LCD panel information */
9790 paneltype = 0;
9791 switch(DDCdatatype) {
9792 case 1: /* Analyze EDID V1 */
9793 /* Catch a few clear cases: */
9794 if(!(checkedid1(buffer))) {
9795 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
9796 "LCD sense: EDID corrupt\n");
9797 return 0;
9798 }
9799
9800 if(!(buffer[0x14] & 0x80)) {
9801 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
9802 "LCD sense: Attached display expects analog input (0x%02x)\n",
9803 buffer[0x14]);
9804 return 0;
9805 }
9806
9807 if((buffer[0x18] & 0x18) != 0x08) {
9808 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
9809 "LCD sense: Warning: Attached display is not of RGB but of %s type (0x%02x)\n",
9810 ((buffer[0x18] & 0x18) == 0x00) ? "monochrome/greyscale" :
9811 ( ((buffer[0x18] & 0x18) == 0x10) ? "non-RGB multicolor" :
9812 "undefined"),
9813 buffer[0x18]);
9814 }
9815
9816 /* Now analyze the first Detailed Timing Block and see
9817 * if the preferred timing mode is stored there. If so,
9818 * check if this is a standard panel for which we already
9819 * know the timing.
9820 */
9821
9822 paneltype = Panel_Custom;
9823 checkexpand = FALSE;
9824
9825 panelvendor = buffer[9] | (buffer[8] << 8);
9826 panelproduct = buffer[10] | (buffer[11] << 8);
9827
9828 /* Overrule bogus preferred modes from database */
9829 if((indb = SiS_FindPanelFromDB(pSiS, panelvendor, panelproduct, &maxx, &maxy, &prefx, &prefy))) {
9830 if(prefx) SiS_Pr->CP_PreferredX = xres = prefx;
9831 if(prefy) SiS_Pr->CP_PreferredY = yres = prefy;
9832 }
9833
9834 if(buffer[0x18] & 0x02) {
9835
9836 USHORT pclk = (buffer[0x36] | (buffer[0x37] << 8));
9837 USHORT phb = (buffer[0x39] | ((buffer[0x3a] & 0x0f) << 8));
9838 USHORT pvb = (buffer[0x3c] | ((buffer[0x3d] & 0x0f) << 8));
9839
9840 if(!xres) SiS_Pr->CP_PreferredX = xres = buffer[0x38] | ((buffer[0x3a] & 0xf0) << 4);
9841 if(!yres) SiS_Pr->CP_PreferredY = yres = buffer[0x3b] | ((buffer[0x3d] & 0xf0) << 4);
9842
9843 switch(xres) {
9844#if 0 /* Treat as custom */
9845 case 800:
9846 if(yres == 600) {
9847 paneltype = Panel_800x600;
9848 checkexpand = TRUE;
9849 }
9850 break;
9851#endif
9852 case 1024:
9853 if(yres == 768) {
9854 paneltype = Panel_1024x768;
9855 checkexpand = TRUE;
9856 }
9857 break;
9858 case 1280:
9859 if(yres == 1024) {
9860 paneltype = Panel_1280x1024;
9861 checkexpand = TRUE;
9862 } else if(yres == 960) {
9863 if(pSiS->VGAEngine == SIS_300_VGA) {
9864 paneltype = Panel300_1280x960;
9865 } else {
9866 paneltype = Panel310_1280x960;
9867 }
9868 } else if(yres == 768) {
9869 if( (pclk == 8100) &&
9870 (phb == (1688 - 1280)) &&
9871 (pvb == (802 - 768)) ) {
9872 paneltype = Panel_1280x768;
9873 checkexpand = FALSE;
9874 cr37 |= 0x10;
9875 }
9876 } else if(yres == 800) {
9877 if( (pclk == 6900) &&
9878 (phb == (1408 - 1280)) &&
9879 (pvb == (816 - 800)) ) {
9880 paneltype = Panel_1280x800;
9881 }
9882 }
9883 break;
9884 case 1400:
9885 if(pSiS->VGAEngine == SIS_315_VGA) {
9886 if(yres == 1050) {
9887 paneltype = Panel310_1400x1050;
9888 checkexpand = TRUE;
9889 }
9890 }
9891 break;
9892 case 1600:
9893 if(pSiS->VGAEngine == SIS_315_VGA) {
9894 if(pSiS->VBFlags & VB_301C) {
9895 if(yres == 1200) {
9896 paneltype = Panel310_1600x1200;
9897 checkexpand = TRUE;
9898 }
9899 }
9900 }
9901 break;
9902 }
9903
9904 /* Save sync: This is used if "Pass 1:1" is off; in this case
9905 * we always use the panel's native mode = this "preferred mode"
9906 * we just have been analysing. Hence, we also need its sync.
9907 */
9908 if((buffer[0x47] & 0x18) == 0x18) {
9909 cr37 |= ((((buffer[0x47] & 0x06) ^ 0x06) << 5) | 0x20);
9910 havesync = TRUE;
9911 } else {
9912 /* What now? There is no digital separate output timing... */
9913 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_WARNING,
9914 "LCD sense: Unable to retrieve Sync polarity information\n");
9915 cr37 |= 0xc0; /* Default */
9916 }
9917
9918 }
9919
9920 /* Check against our database; eg. Sanyo Z2 projector reports
9921 * 1024x768 as preferred mode, although it supports 1280x720
9922 * natively in non-HDCP mode. Treat such wrongly reporting
9923 * panels as custom and fixup actual maximum resolutions.
9924 */
9925 if(paneltype != Panel_Custom) {
9926 if(indb) {
9927 paneltype = Panel_Custom;
9928 SiS_Pr->CP_MaxX = maxx;
9929 SiS_Pr->CP_MaxY = maxy;
9930 /* Leave preferred unchanged (MUST contain a valid mode!) */
9931 }
9932 }
9933
9934 /* If we still don't know what panel this is, we take it
9935 * as a custom panel and derive the timing data from the
9936 * detailed timing blocks
9937 */
9938 if(paneltype == Panel_Custom) {
9939
9940 int i, temp, base = 0x36;
9941 unsigned long estpack;
9942 const unsigned short estx[] = {
9943 720, 720, 640, 640, 640, 640, 800, 800,
9944 800, 800, 832,1024,1024,1024,1024,1280,
9945 1152
9946 };
9947 const unsigned short esty[] = {
9948 400, 400, 480, 480, 480, 480, 600, 600,
9949 600, 600, 624, 768, 768, 768, 768,1024,
9950 870
9951 };
9952 const int estclk[] = {
9953 0, 0, 25100, 0, 31500, 31500, 36100, 40000,
9954 50100, 49500, 0, 0, 65100, 75200, 78700,135200,
9955 0
9956 };
9957
9958 paneltype = 0;
9959 SiS_Pr->CP_Supports64048075 = TRUE;
9960
9961 /* Find the maximum resolution */
9962
9963 /* 1. From Established timings */
9964 estpack = (buffer[0x23] << 9) | (buffer[0x24] << 1) | ((buffer[0x25] >> 7) & 0x01);
9965 for(i=16; i>=0; i--) {
9966 if(estpack & (1 << i)) {
9967 if(estx[16 - i] > SiS_Pr->CP_MaxX) SiS_Pr->CP_MaxX = estx[16 - i];
9968 if(esty[16 - i] > SiS_Pr->CP_MaxY) SiS_Pr->CP_MaxY = esty[16 - i];
9969 if(estclk[16 - i] > SiS_Pr->CP_MaxClock) SiS_Pr->CP_MaxClock = estclk[16 - i];
9970 }
9971 }
9972
9973 /* By default we drive the LCD at 75Hz in 640x480 mode; if
9974 * the panel does not provide this mode, use 60hz
9975 */
9976 if(!(buffer[0x23] & 0x04)) SiS_Pr->CP_Supports64048075 = FALSE;
9977
9978 /* 2. From Standard Timings */
9979 for(i=0x26; i < 0x36; i+=2) {
9980 if((buffer[i] != 0x01) && (buffer[i+1] != 0x01)) {
9981 temp = (buffer[i] + 31) * 8;
9982 if(temp > SiS_Pr->CP_MaxX) SiS_Pr->CP_MaxX = temp;
9983 switch((buffer[i+1] & 0xc0) >> 6) {
9984 case 0x03: temp = temp * 9 / 16; break;
9985 case 0x02: temp = temp * 4 / 5; break;
9986 case 0x01: temp = temp * 3 / 4; break;
9987 }
9988 if(temp > SiS_Pr->CP_MaxY) SiS_Pr->CP_MaxY = temp;
9989 }
9990 }
9991
9992 /* Now extract the Detailed Timings and convert them into modes */
9993
9994 for(i = 0; i < 4; i++, base += 18) {
9995
9996 /* Is this a detailed timing block or a monitor descriptor? */
9997 if(buffer[base] || buffer[base+1] || buffer[base+2]) {
9998
9999 xres = buffer[base+2] | ((buffer[base+4] & 0xf0) << 4);
10000 yres = buffer[base+5] | ((buffer[base+7] & 0xf0) << 4);
10001
10002 SiS_Pr->CP_HDisplay[i] = xres;
10003 SiS_Pr->CP_HSyncStart[i] = xres + (buffer[base+8] | ((buffer[base+11] & 0xc0) << 2));
10004 SiS_Pr->CP_HSyncEnd[i] = SiS_Pr->CP_HSyncStart[i] + (buffer[base+9] | ((buffer[base+11] & 0x30) << 4));
10005 SiS_Pr->CP_HTotal[i] = xres + (buffer[base+3] | ((buffer[base+4] & 0x0f) << 8));
10006 SiS_Pr->CP_HBlankStart[i] = xres + 1;
10007 SiS_Pr->CP_HBlankEnd[i] = SiS_Pr->CP_HTotal[i];
10008
10009 SiS_Pr->CP_VDisplay[i] = yres;
10010 SiS_Pr->CP_VSyncStart[i] = yres + (((buffer[base+10] & 0xf0) >> 4) | ((buffer[base+11] & 0x0c) << 2));
10011 SiS_Pr->CP_VSyncEnd[i] = SiS_Pr->CP_VSyncStart[i] + ((buffer[base+10] & 0x0f) | ((buffer[base+11] & 0x03) << 4));
10012 SiS_Pr->CP_VTotal[i] = yres + (buffer[base+6] | ((buffer[base+7] & 0x0f) << 8));
10013 SiS_Pr->CP_VBlankStart[i] = yres + 1;
10014 SiS_Pr->CP_VBlankEnd[i] = SiS_Pr->CP_VTotal[i];
10015
10016 SiS_Pr->CP_Clock[i] = (buffer[base] | (buffer[base+1] << 8)) * 10;
10017
10018 SiS_Pr->CP_DataValid[i] = TRUE;
10019
10020 /* Sort out invalid timings, interlace and too high clocks */
10021 if((SiS_Pr->CP_HDisplay[i] & 7) ||
10022 (SiS_Pr->CP_HDisplay[i] > SiS_Pr->CP_HSyncStart[i]) ||
10023 (SiS_Pr->CP_HDisplay[i] >= SiS_Pr->CP_HSyncEnd[i]) ||
10024 (SiS_Pr->CP_HDisplay[i] >= SiS_Pr->CP_HTotal[i]) ||
10025 (SiS_Pr->CP_HSyncStart[i] >= SiS_Pr->CP_HSyncEnd[i]) ||
10026 (SiS_Pr->CP_HSyncStart[i] > SiS_Pr->CP_HTotal[i]) ||
10027 (SiS_Pr->CP_HSyncEnd[i] > SiS_Pr->CP_HTotal[i]) ||
10028 (SiS_Pr->CP_VDisplay[i] > SiS_Pr->CP_VSyncStart[i]) ||
10029 (SiS_Pr->CP_VDisplay[i] >= SiS_Pr->CP_VSyncEnd[i]) ||
10030 (SiS_Pr->CP_VDisplay[i] >= SiS_Pr->CP_VTotal[i]) ||
10031 (SiS_Pr->CP_VSyncStart[i] > SiS_Pr->CP_VSyncEnd[i]) ||
10032 (SiS_Pr->CP_VSyncStart[i] > SiS_Pr->CP_VTotal[i]) ||
10033 (SiS_Pr->CP_VSyncEnd[i] > SiS_Pr->CP_VTotal[i]) ||
10034 (((pSiS->VBFlags & VB_301C) && (SiS_Pr->CP_Clock[i] > 162500)) ||
10035 ((!(pSiS->VBFlags & VB_301C)) &&
10036 ((SiS_Pr->CP_Clock[i] > 108200) || (SiS_Pr->CP_VDisplay[i] > 1024) ||
10037 (SiS_Pr->CP_HDisplay[i] > 1600)))) ||
10038 (buffer[base+17] & 0x80)) {
10039
10040 SiS_Pr->CP_DataValid[i] = FALSE;
10041
10042 } else {
10043
10044 SiS_Pr->CP_HaveCustomData = TRUE;
10045
10046 if(xres > SiS_Pr->CP_MaxX) SiS_Pr->CP_MaxX = xres;
10047 if(yres > SiS_Pr->CP_MaxY) SiS_Pr->CP_MaxY = yres;
10048 if(SiS_Pr->CP_Clock[i] > SiS_Pr->CP_MaxClock) SiS_Pr->CP_MaxClock = SiS_Pr->CP_Clock[i];
10049
10050 if((SiS_Pr->CP_PreferredX == xres) && (SiS_Pr->CP_PreferredY == yres)) {
10051 SiS_Pr->CP_PreferredIndex = i;
10052 SiS_MakeClockRegs(pSiS->pScrn, SiS_Pr->CP_Clock[i], &SiS_Pr->CP_PrefSR2B, &SiS_Pr->CP_PrefSR2C);
10053 SiS_Pr->CP_PrefClock = (SiS_Pr->CP_Clock[i] / 1000) + 1;
10054 }
10055
10056 /* Extract the sync polarisation information. This only works
10057 * if the Flags indicate a digital separate output.
10058 */
10059 if((buffer[base+17] & 0x18) == 0x18) {
10060 SiS_Pr->CP_HSync_P[i] = (buffer[base+17] & 0x02) ? TRUE : FALSE;
10061 SiS_Pr->CP_VSync_P[i] = (buffer[base+17] & 0x04) ? TRUE : FALSE;
10062 SiS_Pr->CP_SyncValid[i] = TRUE;
10063 if((i == SiS_Pr->CP_PreferredIndex) && (!havesync)) {
10064 cr37 |= ((((buffer[base+17] & 0x06) ^ 0x06) << 5) | 0x20);
10065 havesync = TRUE;
10066 }
10067 } else {
10068 SiS_Pr->CP_SyncValid[i] = FALSE;
10069 }
10070
10071 }
10072
10073 } else if((!buffer[base]) && (!buffer[base+1]) && (!buffer[base+2]) && (!buffer[base+4])) {
10074
10075 /* Maximum pixclock from Monitor Range Limits */
10076 if((buffer[base+3] == 0xfd) && (buffer[base+9] != 0xff)) {
10077 int maxclk = buffer[base+9] * 10;
10078 /* More than 170 is not supported anyway */
10079 if(maxclk <= 170) SiS_Pr->CP_MaxClock = maxclk * 1000;
10080 }
10081
10082 }
10083
10084 }
10085
10086 if(SiS_Pr->CP_MaxX && SiS_Pr->CP_MaxY) {
10087 paneltype = Panel_Custom;
10088 checkexpand = FALSE;
10089 cr37 |= 0x10;
10090 SiS_Pr->CP_Vendor = panelvendor;
10091 SiS_Pr->CP_Product = panelproduct;
10092 }
10093
10094 }
10095
10096 if(paneltype && checkexpand) {
10097 /* If any of the Established low-res modes is supported, the
10098 * panel can scale automatically. For 800x600 panels, we only
10099 * check the even lower ones.
10100 */
10101 if(paneltype == Panel_800x600) {
10102 if(buffer[0x23] & 0xfc) cr37 |= 0x10;
10103 } else {
10104 if(buffer[0x23]) cr37 |= 0x10;
10105 }
10106 }
10107
10108 break;
10109
10110 case 3: /* Analyze EDID V2 */
10111 case 4:
10112 index = 0;
10113
10114 if(!(checkedid2(buffer))) {
10115 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
10116 "LCD sense: EDID corrupt\n");
10117 return 0;
10118 }
10119
10120 if((buffer[0x41] & 0x0f) == 0x03) {
10121 index = 0x42 + 3;
10122 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
10123 "LCD sense: Display supports TMDS input on primary interface\n");
10124 } else if((buffer[0x41] & 0xf0) == 0x30) {
10125 index = 0x46 + 3;
10126 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
10127 "LCD sense: Display supports TMDS input on secondary interface\n");
10128 } else {
10129 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
10130 "LCD sense: Display does not support TMDS video interface (0x%02x)\n",
10131 buffer[0x41]);
10132 return 0;
10133 }
10134
10135 SiS_Pr->CP_Vendor = panelvendor = buffer[2] | (buffer[1] << 8);
10136 SiS_Pr->CP_Product = panelproduct = buffer[3] | (buffer[4] << 8);
10137
10138 paneltype = Panel_Custom;
10139 SiS_Pr->CP_MaxX = SiS_Pr->CP_PreferredX = xres = buffer[0x76] | (buffer[0x77] << 8);
10140 SiS_Pr->CP_MaxY = SiS_Pr->CP_PreferredY = yres = buffer[0x78] | (buffer[0x79] << 8);
10141
10142 switch(xres) {
10143#if 0
10144 case 800:
10145 if(yres == 600) {
10146 paneltype = Panel_800x600;
10147 checkexpand = TRUE;
10148 }
10149 break;
10150#endif
10151 case 1024:
10152 if(yres == 768) {
10153 paneltype = Panel_1024x768;
10154 checkexpand = TRUE;
10155 }
10156 break;
10157 case 1280:
10158 if(yres == 960) {
10159 if(pSiS->VGAEngine == SIS_315_VGA) {
10160 paneltype = Panel310_1280x960;
10161 } else {
10162 paneltype = Panel300_1280x960;
10163 }
10164 } else if(yres == 1024) {
10165 paneltype = Panel_1280x1024;
10166 checkexpand = TRUE;
10167 }
10168 /* 1280x768 treated as custom here */
10169 break;
10170 case 1400:
10171 if(pSiS->VGAEngine == SIS_315_VGA) {
10172 if(yres == 1050) {
10173 paneltype = Panel310_1400x1050;
10174 checkexpand = TRUE;
10175 }
10176 }
10177 break;
10178 case 1600:
10179 if(pSiS->VGAEngine == SIS_315_VGA) {
10180 if(pSiS->VBFlags & VB_301C) {
10181 if(yres == 1200) {
10182 paneltype = Panel310_1600x1200;
10183 checkexpand = TRUE;
10184 }
10185 }
10186 }
10187 break;
10188 }
10189
10190 /* Determine if RGB18 or RGB24 */
10191 if(index) {
10192 if((buffer[index] == 0x20) || (buffer[index] == 0x34)) {
10193 cr37 |= 0x01;
10194 }
10195 }
10196
10197 if(checkexpand) {
10198 /* TODO - for now, we let the panel scale */
10199 cr37 |= 0x10;
10200 }
10201
10202 /* Now seek 4-Byte Timing codes and extract sync pol info */
10203 index = 0x80;
10204 if(buffer[0x7e] & 0x20) { /* skip Luminance Table (if provided) */
10205 lumsize = buffer[0x80] & 0x1f;
10206 if(buffer[0x80] & 0x80) lumsize *= 3;
10207 lumsize++; /* luminance header byte */
10208 index += lumsize;
10209 }
10210#if 0 /* "pixel rate" = pixel clock? */
10211 if(buffer[0x7e] & 0x1c) {
10212 for(i=0; i<((buffer[0x7e] & 0x1c) >> 2); i++) {
10213 if(buffer[index + (i*8) + 6] && (buffer[index + (i*8) + 7] & 0x0f)) {
10214 int clk = (buffer[index + (i*8) + 6] | ((buffer[index + (i*8) + 7] & 0x0f) << 4)) * 1000;
10215 if(clk > SiS_Pr->CP_MaxClock) SiS_Pr->CP_MaxClock = clk;
10216 }
10217 }
10218 }
10219#endif
10220 index += (((buffer[0x7e] & 0x1c) >> 2) * 8); /* skip Frequency Ranges */
10221 if(buffer[0x7e] & 0x03) {
10222 for(i=0; i<(buffer[0x7e] & 0x03); i++) {
10223 if((buffer[index + (i*27) + 9]) || (buffer[index + (i*27) + 10])) {
10224 int clk = ((buffer[index + (i*27) + 9]) | ((buffer[index + (i*27) + 9]) << 8)) * 10;
10225 if(clk > SiS_Pr->CP_MaxClock) SiS_Pr->CP_MaxClock = clk;
10226 }
10227 }
10228 }
10229 index += ((buffer[0x7e] & 0x03) * 27); /* skip Detailed Range Limits */
10230 numcodes = (buffer[0x7f] & 0xf8) >> 3;
10231 if(numcodes) {
10232 myindex = index;
10233 seekcode = (xres - 256) / 16;
10234 for(i=0; i<numcodes; i++) {
10235 if(buffer[myindex] == seekcode) break;
10236 myindex += 4;
10237 }
10238 if(buffer[myindex] == seekcode) {
10239 cr37 |= ((((buffer[myindex + 1] & 0x0c) ^ 0x0c) << 4) | 0x20);
10240 havesync = TRUE;
10241 } else {
10242 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_WARNING,
10243 "LCD sense: Unable to retrieve Sync polarity information\n");
10244 }
10245 } else {
10246 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_WARNING,
10247 "LCD sense: Unable to retrieve Sync polarity information\n");
10248 }
10249
10250 /* Check against our database; Eg. Sanyo projector reports
10251 * 1024x768 in non-HDPC mode, although it supports 1280x720.
10252 * Treat such wrongly reporting panels as custom.
10253 */
10254 if(paneltype != Panel_Custom) {
10255 int maxx, maxy, prefx, prefy;
10256 if((SiS_FindPanelFromDB(pSiS, panelvendor, panelproduct, &maxx, &maxy, &prefx, &prefy))) {
10257 paneltype = Panel_Custom;
10258 SiS_Pr->CP_MaxX = maxx;
10259 SiS_Pr->CP_MaxY = maxy;
10260 cr37 |= 0x10;
10261 /* Leave preferred unchanged (MUST be a valid mode!) */
10262 }
10263 }
10264
10265 /* Now seek the detailed timing descriptions for custom panels */
10266 if(paneltype == Panel_Custom) {
10267
10268 SiS_Pr->CP_Supports64048075 = TRUE;
10269
10270 index += (numcodes * 4);
10271 numcodes = buffer[0x7f] & 0x07;
10272 for(i=0; i<numcodes; i++, index += 18) {
10273 xres = buffer[index+2] | ((buffer[index+4] & 0xf0) << 4);
10274 yres = buffer[index+5] | ((buffer[index+7] & 0xf0) << 4);
10275
10276 SiS_Pr->CP_HDisplay[i] = xres;
10277 SiS_Pr->CP_HSyncStart[i] = xres + (buffer[index+8] | ((buffer[index+11] & 0xc0) << 2));
10278 SiS_Pr->CP_HSyncEnd[i] = SiS_Pr->CP_HSyncStart[i] + (buffer[index+9] | ((buffer[index+11] & 0x30) << 4));
10279 SiS_Pr->CP_HTotal[i] = xres + (buffer[index+3] | ((buffer[index+4] & 0x0f) << 8));
10280 SiS_Pr->CP_HBlankStart[i] = xres + 1;
10281 SiS_Pr->CP_HBlankEnd[i] = SiS_Pr->CP_HTotal[i];
10282
10283 SiS_Pr->CP_VDisplay[i] = yres;
10284 SiS_Pr->CP_VSyncStart[i] = yres + (((buffer[index+10] & 0xf0) >> 4) | ((buffer[index+11] & 0x0c) << 2));
10285 SiS_Pr->CP_VSyncEnd[i] = SiS_Pr->CP_VSyncStart[i] + ((buffer[index+10] & 0x0f) | ((buffer[index+11] & 0x03) << 4));
10286 SiS_Pr->CP_VTotal[i] = yres + (buffer[index+6] | ((buffer[index+7] & 0x0f) << 8));
10287 SiS_Pr->CP_VBlankStart[i] = yres + 1;
10288 SiS_Pr->CP_VBlankEnd[i] = SiS_Pr->CP_VTotal[i];
10289
10290 SiS_Pr->CP_Clock[i] = (buffer[index] | (buffer[index+1] << 8)) * 10;
10291
10292 SiS_Pr->CP_DataValid[i] = TRUE;
10293
10294 if((SiS_Pr->CP_HDisplay[i] & 7) ||
10295 (SiS_Pr->CP_HDisplay[i] > SiS_Pr->CP_HSyncStart[i]) ||
10296 (SiS_Pr->CP_HDisplay[i] >= SiS_Pr->CP_HSyncEnd[i]) ||
10297 (SiS_Pr->CP_HDisplay[i] >= SiS_Pr->CP_HTotal[i]) ||
10298 (SiS_Pr->CP_HSyncStart[i] >= SiS_Pr->CP_HSyncEnd[i]) ||
10299 (SiS_Pr->CP_HSyncStart[i] > SiS_Pr->CP_HTotal[i]) ||
10300 (SiS_Pr->CP_HSyncEnd[i] > SiS_Pr->CP_HTotal[i]) ||
10301 (SiS_Pr->CP_VDisplay[i] > SiS_Pr->CP_VSyncStart[i]) ||
10302 (SiS_Pr->CP_VDisplay[i] >= SiS_Pr->CP_VSyncEnd[i]) ||
10303 (SiS_Pr->CP_VDisplay[i] >= SiS_Pr->CP_VTotal[i]) ||
10304 (SiS_Pr->CP_VSyncStart[i] > SiS_Pr->CP_VSyncEnd[i]) ||
10305 (SiS_Pr->CP_VSyncStart[i] > SiS_Pr->CP_VTotal[i]) ||
10306 (SiS_Pr->CP_VSyncEnd[i] > SiS_Pr->CP_VTotal[i]) ||
10307 (((pSiS->VBFlags & VB_301C) && (SiS_Pr->CP_Clock[i] > 162500)) ||
10308 ((!(pSiS->VBFlags & VB_301C)) &&
10309 ((SiS_Pr->CP_Clock[i] > 108200) || (SiS_Pr->CP_VDisplay[i] > 1024)))) ||
10310 (buffer[index + 17] & 0x80)) {
10311
10312 SiS_Pr->CP_DataValid[i] = FALSE;
10313
10314 } else {
10315
10316 SiS_Pr->CP_HaveCustomData = TRUE;
10317
10318 if(SiS_Pr->CP_Clock[i] > SiS_Pr->CP_MaxClock) SiS_Pr->CP_MaxClock = SiS_Pr->CP_Clock[i];
10319
10320 if((SiS_Pr->CP_PreferredX == xres) && (SiS_Pr->CP_PreferredY == yres)) {
10321 SiS_Pr->CP_PreferredIndex = i;
10322 SiS_MakeClockRegs(pSiS->pScrn, SiS_Pr->CP_Clock[i], &SiS_Pr->CP_PrefSR2B, &SiS_Pr->CP_PrefSR2C);
10323 SiS_Pr->CP_PrefClock = (SiS_Pr->CP_Clock[i] / 1000) + 1;
10324 if(!havesync) {
10325 cr37 |= ((((buffer[index + 17] & 0x06) ^ 0x06) << 5) | 0x20);
10326 havesync = TRUE;
10327 }
10328 }
10329
10330 SiS_Pr->CP_HSync_P[i] = (buffer[index + 17] & 0x02) ? TRUE : FALSE;
10331 SiS_Pr->CP_VSync_P[i] = (buffer[index + 17] & 0x04) ? TRUE : FALSE;
10332 SiS_Pr->CP_SyncValid[i] = TRUE;
10333
10334 }
10335 }
10336
10337 cr37 |= 0x10;
10338
10339 }
10340
10341 break;
10342
10343 }
10344
10345 /* 1280x960 panels are always RGB24, unable to scale and use
10346 * high active sync polarity
10347 */
10348 if(pSiS->VGAEngine == SIS_315_VGA) {
10349 if(paneltype == Panel310_1280x960) cr37 &= 0x0e;
10350 } else {
10351 if(paneltype == Panel300_1280x960) cr37 &= 0x0e;
10352 }
10353
10354 for(i = 0; i < 7; i++) {
10355 if(SiS_Pr->CP_DataValid[i]) {
10356 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
10357 "Non-standard LCD/DVI-D timing data no. %d:\n", i);
10358 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
10359 " HDisplay %d HSync %d HSyncEnd %d HTotal %d\n",
10360 SiS_Pr->CP_HDisplay[i], SiS_Pr->CP_HSyncStart[i],
10361 SiS_Pr->CP_HSyncEnd[i], SiS_Pr->CP_HTotal[i]);
10362 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
10363 " VDisplay %d VSync %d VSyncEnd %d VTotal %d\n",
10364 SiS_Pr->CP_VDisplay[i], SiS_Pr->CP_VSyncStart[i],
10365 SiS_Pr->CP_VSyncEnd[i], SiS_Pr->CP_VTotal[i]);
10366 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
10367 " Pixel clock: %3.3fMhz\n", (float)SiS_Pr->CP_Clock[i] / 1000);
10368 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_INFO,
10369 " To use this, add \"%dx%d\" to the list of Modes in the Screen section\n",
10370 SiS_Pr->CP_HDisplay[i],
10371 SiS_Pr->CP_VDisplay[i]);
10372 }
10373 }
10374
10375 if(paneltype) {
10376 if(!SiS_Pr->CP_PreferredX) SiS_Pr->CP_PreferredX = SiS_Pr->CP_MaxX;
10377 if(!SiS_Pr->CP_PreferredY) SiS_Pr->CP_PreferredY = SiS_Pr->CP_MaxY;
10378 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x32,0x08);
10379 SiS_SetReg(SiS_Pr->SiS_P3d4,0x36,paneltype);
10380 cr37 &= 0xf1;
10381 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x37,0x0c,cr37);
10382 SiS_Pr->PanelSelfDetected = TRUE;
10383#ifdef TWDEBUG
10384 xf86DrvMsgVerb(pSiS->pScrn->scrnIndex, X_PROBED, 3,
10385 "LCD sense: [DDC LCD results: 0x%02x, 0x%02x]\n", paneltype, cr37);
10386#endif
10387 } else {
10388 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x32,~0x08);
10389 SiS_SetReg(SiS_Pr->SiS_P3d4,0x36,0x00);
10390 }
10391 return 0;
10392}
10393
10394USHORT
10395SiS_SenseVGA2DDC(SiS_Private *SiS_Pr, SISPtr pSiS)
10396{
10397 USHORT DDCdatatype,flag;
10398 BOOLEAN foundcrt = FALSE;
10399 int retry;
10400 unsigned char buffer[256];
10401
10402 if(!(pSiS->VBFlags & (VB_301|VB_301B|VB_301C|VB_302B))) return 0;
10403
10404 if(SiS_InitDDCRegs(SiS_Pr, pSiS->VBFlags, pSiS->VGAEngine, 2, 0, FALSE) == 0xFFFF) return 0;
10405
10406 SiS_Pr->SiS_DDC_SecAddr = 0x00;
10407
10408 /* Probe supported DA's */
10409 flag = SiS_ProbeDDC(SiS_Pr);
10410 if(flag & 0x10) {
10411 SiS_Pr->SiS_DDC_DeviceAddr = 0xa6; /* EDID V2 (FP) */
10412 DDCdatatype = 4;
10413 } else if(flag & 0x08) {
10414 SiS_Pr->SiS_DDC_DeviceAddr = 0xa2; /* EDID V2 (P&D-D Monitor) */
10415 DDCdatatype = 3;
10416 } else if(flag & 0x02) {
10417 SiS_Pr->SiS_DDC_DeviceAddr = 0xa0; /* EDID V1 */
10418 DDCdatatype = 1;
10419 } else {
10420 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
10421 "VGA2 sense: Do DDC answer\n");
10422 return 0; /* no DDC support (or no device attached) */
10423 }
10424
10425 /* Read the entire EDID */
10426 retry = 2;
10427 do {
10428 if(SiS_ReadDDC(SiS_Pr, DDCdatatype, buffer)) {
10429 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
10430 "VGA2 sense: DDC read failed (attempt %d), %s\n",
10431 (3-retry), (retry == 1) ? "giving up" : "retrying");
10432 retry--;
10433 if(retry == 0) return 0xFFFF;
10434 } else break;
10435 } while(1);
10436
10437 /* Analyze EDID. We don't have many chances to
10438 * distinguish a flat panel from a CRT...
10439 */
10440 switch(DDCdatatype) {
10441 case 1:
10442 if(!(checkedid1(buffer))) {
10443 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_ERROR,
10444 "VGA2 sense: EDID corrupt\n");
10445 return 0;
10446 }
10447 if(buffer[0x14] & 0x80) { /* Display uses digital input */
10448 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_ERROR,
10449 "VGA2 sense: Attached display expects digital input\n");
10450 return 0;
10451 }
10452 SiS_Pr->CP_Vendor = buffer[9] | (buffer[8] << 8);
10453 SiS_Pr->CP_Product = buffer[10] | (buffer[11] << 8);
10454 foundcrt = TRUE;
10455 break;
10456 case 3:
10457 case 4:
10458 if(!(checkedid2(buffer))) {
10459 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_ERROR,
10460 "VGA2 sense: EDID corrupt\n");
10461 return 0;
10462 }
10463 if( ((buffer[0x41] & 0x0f) != 0x01) && /* Display does not support analog input */
10464 ((buffer[0x41] & 0x0f) != 0x02) &&
10465 ((buffer[0x41] & 0xf0) != 0x10) &&
10466 ((buffer[0x41] & 0xf0) != 0x20) ) {
10467 xf86DrvMsg(pSiS->pScrn->scrnIndex, X_ERROR,
10468 "VGA2 sense: Attached display does not support analog input (0x%02x)\n",
10469 buffer[0x41]);
10470 return 0;
10471 }
10472 SiS_Pr->CP_Vendor = buffer[2] | (buffer[1] << 8);
10473 SiS_Pr->CP_Product = buffer[3] | (buffer[4] << 8);
10474 foundcrt = TRUE;
10475 break;
10476 }
10477
10478 if(foundcrt) {
10479 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x32,0x10);
10480 }
10481 return(0);
10482}
10483
10484#endif
10485
10486void
10487SiS_SetCH70xxANDOR(SiS_Private *SiS_Pr, USHORT tempax,USHORT tempbh)
10488{
10489 USHORT tempbl;
10490
10491 tempbl = SiS_GetCH70xx(SiS_Pr,(tempax & 0x00FF));
10492 tempbl = (((tempbl & tempbh) << 8) | tempax);
10493 SiS_SetCH70xx(SiS_Pr,tempbl);
10494}
10495
10496/* Generic I2C functions for Chrontel & DDC --------- */ 9493/* Generic I2C functions for Chrontel & DDC --------- */
10497 9494
10498static void 9495static void
10499SiS_SetSwitchDDC2(SiS_Private *SiS_Pr) 9496SiS_SetSwitchDDC2(struct SiS_Private *SiS_Pr)
10500{ 9497{
10501 SiS_SetSCLKHigh(SiS_Pr); 9498 SiS_SetSCLKHigh(SiS_Pr);
10502 SiS_WaitRetrace1(SiS_Pr); 9499 SiS_WaitRetrace1(SiS_Pr);
@@ -10505,125 +9502,127 @@ SiS_SetSwitchDDC2(SiS_Private *SiS_Pr)
10505 SiS_WaitRetrace1(SiS_Pr); 9502 SiS_WaitRetrace1(SiS_Pr);
10506} 9503}
10507 9504
10508USHORT 9505unsigned short
10509SiS_ReadDDC1Bit(SiS_Private *SiS_Pr) 9506SiS_ReadDDC1Bit(struct SiS_Private *SiS_Pr)
10510{ 9507{
10511 SiS_WaitRetrace1(SiS_Pr); 9508 SiS_WaitRetrace1(SiS_Pr);
10512 return((SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x02) >> 1); 9509 return ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x02) >> 1);
10513} 9510}
10514 9511
10515/* Set I2C start condition */ 9512/* Set I2C start condition */
10516/* This is done by a SD high-to-low transition while SC is high */ 9513/* This is done by a SD high-to-low transition while SC is high */
10517static USHORT 9514static unsigned short
10518SiS_SetStart(SiS_Private *SiS_Pr) 9515SiS_SetStart(struct SiS_Private *SiS_Pr)
10519{ 9516{
10520 if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */ 9517 if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */
10521 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, 9518 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
10522 SiS_Pr->SiS_DDC_Index, 9519 SiS_Pr->SiS_DDC_Index,
10523 SiS_Pr->SiS_DDC_NData, 9520 SiS_Pr->SiS_DDC_NData,
10524 SiS_Pr->SiS_DDC_Data); /* SD->high */ 9521 SiS_Pr->SiS_DDC_Data); /* SD->high */
10525 if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */ 9522 if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */
10526 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, 9523 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
10527 SiS_Pr->SiS_DDC_Index, 9524 SiS_Pr->SiS_DDC_Index,
10528 SiS_Pr->SiS_DDC_NData, 9525 SiS_Pr->SiS_DDC_NData,
10529 0x00); /* SD->low = start condition */ 9526 0x00); /* SD->low = start condition */
10530 if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->low) */ 9527 if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->low) */
10531 return 0; 9528 return 0;
10532} 9529}
10533 9530
10534/* Set I2C stop condition */ 9531/* Set I2C stop condition */
10535/* This is done by a SD low-to-high transition while SC is high */ 9532/* This is done by a SD low-to-high transition while SC is high */
10536static USHORT 9533static unsigned short
10537SiS_SetStop(SiS_Private *SiS_Pr) 9534SiS_SetStop(struct SiS_Private *SiS_Pr)
10538{ 9535{
10539 if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */ 9536 if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */
10540 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, 9537 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
10541 SiS_Pr->SiS_DDC_Index, 9538 SiS_Pr->SiS_DDC_Index,
10542 SiS_Pr->SiS_DDC_NData, 9539 SiS_Pr->SiS_DDC_NData,
10543 0x00); /* SD->low */ 9540 0x00); /* SD->low */
10544 if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */ 9541 if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */
10545 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, 9542 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
10546 SiS_Pr->SiS_DDC_Index, 9543 SiS_Pr->SiS_DDC_Index,
10547 SiS_Pr->SiS_DDC_NData, 9544 SiS_Pr->SiS_DDC_NData,
10548 SiS_Pr->SiS_DDC_Data); /* SD->high = stop condition */ 9545 SiS_Pr->SiS_DDC_Data); /* SD->high = stop condition */
10549 if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->high) */ 9546 if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->high) */
10550 return 0; 9547 return 0;
10551} 9548}
10552 9549
10553/* Write 8 bits of data */ 9550/* Write 8 bits of data */
10554static USHORT 9551static unsigned short
10555SiS_WriteDDC2Data(SiS_Private *SiS_Pr, USHORT tempax) 9552SiS_WriteDDC2Data(struct SiS_Private *SiS_Pr, unsigned short tempax)
10556{ 9553{
10557 USHORT i,flag,temp; 9554 unsigned short i,flag,temp;
10558 9555
10559 flag = 0x80; 9556 flag = 0x80;
10560 for(i=0; i<8; i++) { 9557 for(i = 0; i < 8; i++) {
10561 SiS_SetSCLKLow(SiS_Pr); /* SC->low */ 9558 SiS_SetSCLKLow(SiS_Pr); /* SC->low */
10562 if(tempax & flag) { 9559 if(tempax & flag) {
10563 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, 9560 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
10564 SiS_Pr->SiS_DDC_Index, 9561 SiS_Pr->SiS_DDC_Index,
10565 SiS_Pr->SiS_DDC_NData, 9562 SiS_Pr->SiS_DDC_NData,
10566 SiS_Pr->SiS_DDC_Data); /* Write bit (1) to SD */ 9563 SiS_Pr->SiS_DDC_Data); /* Write bit (1) to SD */
10567 } else { 9564 } else {
10568 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, 9565 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
10569 SiS_Pr->SiS_DDC_Index, 9566 SiS_Pr->SiS_DDC_Index,
10570 SiS_Pr->SiS_DDC_NData, 9567 SiS_Pr->SiS_DDC_NData,
10571 0x00); /* Write bit (0) to SD */ 9568 0x00); /* Write bit (0) to SD */
10572 } 9569 }
10573 SiS_SetSCLKHigh(SiS_Pr); /* SC->high */ 9570 SiS_SetSCLKHigh(SiS_Pr); /* SC->high */
10574 flag >>= 1; 9571 flag >>= 1;
10575 } 9572 }
10576 temp = SiS_CheckACK(SiS_Pr); /* Check acknowledge */ 9573 temp = SiS_CheckACK(SiS_Pr); /* Check acknowledge */
10577 return(temp); 9574 return temp;
10578} 9575}
10579 9576
10580static USHORT 9577static unsigned short
10581SiS_ReadDDC2Data(SiS_Private *SiS_Pr, USHORT tempax) 9578SiS_ReadDDC2Data(struct SiS_Private *SiS_Pr)
10582{ 9579{
10583 USHORT i,temp,getdata; 9580 unsigned short i, temp, getdata;
10584 9581
10585 getdata=0; 9582 getdata = 0;
10586 for(i=0; i<8; i++) { 9583 for(i = 0; i < 8; i++) {
10587 getdata <<= 1; 9584 getdata <<= 1;
10588 SiS_SetSCLKLow(SiS_Pr); 9585 SiS_SetSCLKLow(SiS_Pr);
10589 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, 9586 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
10590 SiS_Pr->SiS_DDC_Index, 9587 SiS_Pr->SiS_DDC_Index,
10591 SiS_Pr->SiS_DDC_NData, 9588 SiS_Pr->SiS_DDC_NData,
10592 SiS_Pr->SiS_DDC_Data); 9589 SiS_Pr->SiS_DDC_Data);
10593 SiS_SetSCLKHigh(SiS_Pr); 9590 SiS_SetSCLKHigh(SiS_Pr);
10594 temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); 9591 temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);
10595 if(temp & SiS_Pr->SiS_DDC_Data) getdata |= 0x01; 9592 if(temp & SiS_Pr->SiS_DDC_Data) getdata |= 0x01;
10596 } 9593 }
10597 return(getdata); 9594 return getdata;
10598} 9595}
10599 9596
10600static USHORT 9597static unsigned short
10601SiS_SetSCLKLow(SiS_Private *SiS_Pr) 9598SiS_SetSCLKLow(struct SiS_Private *SiS_Pr)
10602{ 9599{
10603 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, 9600 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
10604 SiS_Pr->SiS_DDC_Index, 9601 SiS_Pr->SiS_DDC_Index,
10605 SiS_Pr->SiS_DDC_NClk, 9602 SiS_Pr->SiS_DDC_NClk,
10606 0x00); /* SetSCLKLow() */ 9603 0x00); /* SetSCLKLow() */
10607 SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT); 9604 SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
10608 return 0; 9605 return 0;
10609} 9606}
10610 9607
10611static USHORT 9608static unsigned short
10612SiS_SetSCLKHigh(SiS_Private *SiS_Pr) 9609SiS_SetSCLKHigh(struct SiS_Private *SiS_Pr)
10613{ 9610{
10614 USHORT temp, watchdog=1000; 9611 unsigned short temp, watchdog=1000;
10615 9612
10616 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, 9613 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
10617 SiS_Pr->SiS_DDC_Index, 9614 SiS_Pr->SiS_DDC_Index,
10618 SiS_Pr->SiS_DDC_NClk, 9615 SiS_Pr->SiS_DDC_NClk,
10619 SiS_Pr->SiS_DDC_Clk); /* SetSCLKHigh() */ 9616 SiS_Pr->SiS_DDC_Clk); /* SetSCLKHigh() */
10620 do { 9617 do {
10621 temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); 9618 temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);
10622 } while((!(temp & SiS_Pr->SiS_DDC_Clk)) && --watchdog); 9619 } while((!(temp & SiS_Pr->SiS_DDC_Clk)) && --watchdog);
10623 if (!watchdog) { 9620 if (!watchdog) {
9621#ifdef SIS_XORG_XF86
10624#ifdef TWDEBUG 9622#ifdef TWDEBUG
10625 xf86DrvMsg(0, X_INFO, "SetClkHigh failed\n"); 9623 xf86DrvMsg(0, X_INFO, "SetClkHigh failed\n");
10626#endif 9624#endif
9625#endif
10627 return 0xFFFF; 9626 return 0xFFFF;
10628 } 9627 }
10629 SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT); 9628 SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
@@ -10632,21 +9631,21 @@ SiS_SetSCLKHigh(SiS_Private *SiS_Pr)
10632 9631
10633/* Check I2C acknowledge */ 9632/* Check I2C acknowledge */
10634/* Returns 0 if ack ok, non-0 if ack not ok */ 9633/* Returns 0 if ack ok, non-0 if ack not ok */
10635static USHORT 9634static unsigned short
10636SiS_CheckACK(SiS_Private *SiS_Pr) 9635SiS_CheckACK(struct SiS_Private *SiS_Pr)
10637{ 9636{
10638 USHORT tempah; 9637 unsigned short tempah;
10639 9638
10640 SiS_SetSCLKLow(SiS_Pr); /* (SC->low) */ 9639 SiS_SetSCLKLow(SiS_Pr); /* (SC->low) */
10641 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, 9640 SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
10642 SiS_Pr->SiS_DDC_Index, 9641 SiS_Pr->SiS_DDC_Index,
10643 SiS_Pr->SiS_DDC_NData, 9642 SiS_Pr->SiS_DDC_NData,
10644 SiS_Pr->SiS_DDC_Data); /* (SD->high) */ 9643 SiS_Pr->SiS_DDC_Data); /* (SD->high) */
10645 SiS_SetSCLKHigh(SiS_Pr); /* SC->high = clock impulse for ack */ 9644 SiS_SetSCLKHigh(SiS_Pr); /* SC->high = clock impulse for ack */
10646 tempah = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); /* Read SD */ 9645 tempah = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); /* Read SD */
10647 SiS_SetSCLKLow(SiS_Pr); /* SC->low = end of clock impulse */ 9646 SiS_SetSCLKLow(SiS_Pr); /* SC->low = end of clock impulse */
10648 if(tempah & SiS_Pr->SiS_DDC_Data) return(1); /* Ack OK if bit = 0 */ 9647 if(tempah & SiS_Pr->SiS_DDC_Data) return 1; /* Ack OK if bit = 0 */
10649 else return(0); 9648 return 0;
10650} 9649}
10651 9650
10652/* End of I2C functions ----------------------- */ 9651/* End of I2C functions ----------------------- */
@@ -10656,67 +9655,67 @@ SiS_CheckACK(SiS_Private *SiS_Pr)
10656 9655
10657#ifdef SIS315H 9656#ifdef SIS315H
10658 9657
10659static USHORT 9658static unsigned short
10660GetRAMDACromptr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 9659GetRAMDACromptr(struct SiS_Private *SiS_Pr)
10661{ 9660{
10662 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 9661 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
10663 USHORT romptr; 9662 unsigned short romptr;
10664 9663
10665 if(HwInfo->jChipType < SIS_330) { 9664 if(SiS_Pr->ChipType < SIS_330) {
10666 romptr = SISGETROMW(0x128); 9665 romptr = SISGETROMW(0x128);
10667 if(SiS_Pr->SiS_VBType & VB_SIS301B302B) 9666 if(SiS_Pr->SiS_VBType & VB_SIS30xB)
10668 romptr = SISGETROMW(0x12a); 9667 romptr = SISGETROMW(0x12a);
10669 } else { 9668 } else {
10670 romptr = SISGETROMW(0x1a8); 9669 romptr = SISGETROMW(0x1a8);
10671 if(SiS_Pr->SiS_VBType & VB_SIS301B302B) 9670 if(SiS_Pr->SiS_VBType & VB_SIS30xB)
10672 romptr = SISGETROMW(0x1aa); 9671 romptr = SISGETROMW(0x1aa);
10673 } 9672 }
10674 return(romptr); 9673 return romptr;
10675} 9674}
10676 9675
10677static USHORT 9676static unsigned short
10678GetLCDromptr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 9677GetLCDromptr(struct SiS_Private *SiS_Pr)
10679{ 9678{
10680 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 9679 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
10681 USHORT romptr; 9680 unsigned short romptr;
10682 9681
10683 if(HwInfo->jChipType < SIS_330) { 9682 if(SiS_Pr->ChipType < SIS_330) {
10684 romptr = SISGETROMW(0x120); 9683 romptr = SISGETROMW(0x120);
10685 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) 9684 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
10686 romptr = SISGETROMW(0x122); 9685 romptr = SISGETROMW(0x122);
10687 } else { 9686 } else {
10688 romptr = SISGETROMW(0x1a0); 9687 romptr = SISGETROMW(0x1a0);
10689 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) 9688 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
10690 romptr = SISGETROMW(0x1a2); 9689 romptr = SISGETROMW(0x1a2);
10691 } 9690 }
10692 return(romptr); 9691 return romptr;
10693} 9692}
10694 9693
10695static USHORT 9694static unsigned short
10696GetTVromptr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 9695GetTVromptr(struct SiS_Private *SiS_Pr)
10697{ 9696{
10698 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 9697 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
10699 USHORT romptr; 9698 unsigned short romptr;
10700 9699
10701 if(HwInfo->jChipType < SIS_330) { 9700 if(SiS_Pr->ChipType < SIS_330) {
10702 romptr = SISGETROMW(0x114); 9701 romptr = SISGETROMW(0x114);
10703 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) 9702 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
10704 romptr = SISGETROMW(0x11a); 9703 romptr = SISGETROMW(0x11a);
10705 } else { 9704 } else {
10706 romptr = SISGETROMW(0x194); 9705 romptr = SISGETROMW(0x194);
10707 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) 9706 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
10708 romptr = SISGETROMW(0x19a); 9707 romptr = SISGETROMW(0x19a);
10709 } 9708 }
10710 return(romptr); 9709 return romptr;
10711} 9710}
10712 9711
10713static USHORT 9712static unsigned short
10714GetLCDPtrIndexBIOS(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 9713GetLCDPtrIndexBIOS(struct SiS_Private *SiS_Pr)
10715{ 9714{
10716 USHORT index; 9715 unsigned short index;
10717 9716
10718 if((IS_SIS650) && (SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) { 9717 if((IS_SIS650) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
10719 if(!(SiS_IsNotM650orLater(SiS_Pr, HwInfo))) { 9718 if(!(SiS_IsNotM650orLater(SiS_Pr))) {
10720 if((index = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0)) { 9719 if((index = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0)) {
10721 index >>= 4; 9720 index >>= 4;
10722 index *= 3; 9721 index *= 3;
@@ -10729,7 +9728,12 @@ GetLCDPtrIndexBIOS(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
10729 9728
10730 index = SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F; 9729 index = SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F;
10731 if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) index -= 5; 9730 if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) index -= 5;
10732 else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 6; 9731 if(SiS_Pr->SiS_VBType & VB_SIS301C) { /* 1.15.20 and later (not VB specific) */
9732 if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 5;
9733 if(SiS_Pr->SiS_LCDResInfo == Panel_1280x768) index -= 5;
9734 } else {
9735 if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 6;
9736 }
10733 index--; 9737 index--;
10734 index *= 3; 9738 index *= 3;
10735 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2; 9739 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
@@ -10737,10 +9741,10 @@ GetLCDPtrIndexBIOS(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
10737 return index; 9741 return index;
10738} 9742}
10739 9743
10740static USHORT 9744static unsigned short
10741GetLCDPtrIndex(SiS_Private *SiS_Pr) 9745GetLCDPtrIndex(struct SiS_Private *SiS_Pr)
10742{ 9746{
10743 USHORT index; 9747 unsigned short index;
10744 9748
10745 index = ((SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F) - 1) * 3; 9749 index = ((SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F) - 1) * 3;
10746 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2; 9750 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
@@ -10748,10 +9752,10 @@ GetLCDPtrIndex(SiS_Private *SiS_Pr)
10748 return index; 9752 return index;
10749} 9753}
10750 9754
10751static USHORT 9755static unsigned short
10752GetTVPtrIndex(SiS_Private *SiS_Pr) 9756GetTVPtrIndex(struct SiS_Private *SiS_Pr)
10753{ 9757{
10754 USHORT index; 9758 unsigned short index;
10755 9759
10756 index = 0; 9760 index = 0;
10757 if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1; 9761 if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1;
@@ -10769,10 +9773,10 @@ GetTVPtrIndex(SiS_Private *SiS_Pr)
10769 return index; 9773 return index;
10770} 9774}
10771 9775
10772static ULONG 9776static unsigned int
10773GetOEMTVPtr661_2_GEN(SiS_Private *SiS_Pr, int addme) 9777GetOEMTVPtr661_2_GEN(struct SiS_Private *SiS_Pr, int addme)
10774{ 9778{
10775 USHORT index = 0, temp = 0; 9779 unsigned short index = 0, temp = 0;
10776 9780
10777 if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1; 9781 if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1;
10778 if(SiS_Pr->SiS_TVMode & TVSetPALM) index = 2; 9782 if(SiS_Pr->SiS_TVMode & TVSetPALM) index = 2;
@@ -10784,7 +9788,7 @@ GetOEMTVPtr661_2_GEN(SiS_Private *SiS_Pr, int addme)
10784 if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 7; 9788 if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 7;
10785 } 9789 }
10786 9790
10787 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 9791 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
10788 if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || 9792 if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
10789 (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) { 9793 (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
10790 index += addme; 9794 index += addme;
@@ -10792,25 +9796,25 @@ GetOEMTVPtr661_2_GEN(SiS_Private *SiS_Pr, int addme)
10792 } 9796 }
10793 temp += 0x0100; 9797 temp += 0x0100;
10794 } 9798 }
10795 return(ULONG)(index | (temp << 16)); 9799 return (unsigned int)(index | (temp << 16));
10796} 9800}
10797 9801
10798static ULONG 9802static unsigned int
10799GetOEMTVPtr661_2_OLD(SiS_Private *SiS_Pr) 9803GetOEMTVPtr661_2_OLD(struct SiS_Private *SiS_Pr)
10800{ 9804{
10801 return(GetOEMTVPtr661_2_GEN(SiS_Pr, 8)); 9805 return (GetOEMTVPtr661_2_GEN(SiS_Pr, 8));
10802} 9806}
10803 9807
10804#if 0 9808#if 0
10805static ULONG 9809static unsigned int
10806GetOEMTVPtr661_2_NEW(SiS_Private *SiS_Pr) 9810GetOEMTVPtr661_2_NEW(struct SiS_Private *SiS_Pr)
10807{ 9811{
10808 return(GetOEMTVPtr661_2_GEN(SiS_Pr, 6)); 9812 return (GetOEMTVPtr661_2_GEN(SiS_Pr, 6));
10809} 9813}
10810#endif 9814#endif
10811 9815
10812static int 9816static int
10813GetOEMTVPtr661(SiS_Private *SiS_Pr) 9817GetOEMTVPtr661(struct SiS_Private *SiS_Pr)
10814{ 9818{
10815 int index = 0; 9819 int index = 0;
10816 9820
@@ -10833,10 +9837,10 @@ GetOEMTVPtr661(SiS_Private *SiS_Pr)
10833} 9837}
10834 9838
10835static void 9839static void
10836SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo) 9840SetDelayComp(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
10837{ 9841{
10838 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 9842 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
10839 USHORT delay=0,index,myindex,temp,romptr=0; 9843 unsigned short delay=0,index,myindex,temp,romptr=0;
10840 BOOLEAN dochiptest = TRUE; 9844 BOOLEAN dochiptest = TRUE;
10841 9845
10842 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { 9846 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
@@ -10848,19 +9852,19 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
10848 /* Find delay (from ROM, internal tables, PCI subsystem) */ 9852 /* Find delay (from ROM, internal tables, PCI subsystem) */
10849 9853
10850 if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { /* ------------ VGA */ 9854 if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { /* ------------ VGA */
10851 9855
10852 if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) { 9856 if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
10853 romptr = GetRAMDACromptr(SiS_Pr, HwInfo); 9857 romptr = GetRAMDACromptr(SiS_Pr);
10854 } 9858 }
10855 if(romptr) delay = ROMAddr[romptr]; 9859 if(romptr) delay = ROMAddr[romptr];
10856 else { 9860 else {
10857 delay = 0x04; 9861 delay = 0x04;
10858 if(SiS_Pr->SiS_VBType & VB_SIS301B302B) { 9862 if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
10859 if(IS_SIS650) { 9863 if(IS_SIS650) {
10860 delay = 0x0a; 9864 delay = 0x0a;
10861 } else if(IS_SIS740) { 9865 } else if(IS_SIS740) {
10862 delay = 0x00; 9866 delay = 0x00;
10863 } else if(HwInfo->jChipType < SIS_330) { 9867 } else if(SiS_Pr->ChipType < SIS_330) {
10864 delay = 0x0c; 9868 delay = 0x0c;
10865 } else { 9869 } else {
10866 delay = 0x0c; 9870 delay = 0x0c;
@@ -10901,8 +9905,12 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
10901 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,delay); 9905 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,delay);
10902 } else { 9906 } else {
10903 delay = 0x0c; 9907 delay = 0x0c;
10904 if(SiS_Pr->SiS_VBType & VB_SIS301C) delay = 0x03; 9908 if(SiS_Pr->SiS_VBType & VB_SIS301C) {
10905 else if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 9909 delay = 0x03;
9910 if((SiS_Pr->PanelXRes > 1280) && (SiS_Pr->PanelYRes > 1024)) {
9911 delay = 0x00;
9912 }
9913 } else if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
10906 if(IS_SIS740) delay = 0x01; 9914 if(IS_SIS740) delay = 0x01;
10907 else delay = 0x03; 9915 else delay = 0x03;
10908 } 9916 }
@@ -10947,12 +9955,12 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
10947 9955
10948 if(!gotitfrompci) { 9956 if(!gotitfrompci) {
10949 9957
10950 index = GetLCDPtrIndexBIOS(SiS_Pr, HwInfo); 9958 index = GetLCDPtrIndexBIOS(SiS_Pr);
10951 myindex = GetLCDPtrIndex(SiS_Pr); 9959 myindex = GetLCDPtrIndex(SiS_Pr);
10952 9960
10953 if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) { 9961 if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
10954 9962
10955 if(SiS_IsNotM650orLater(SiS_Pr, HwInfo)) { 9963 if(SiS_IsNotM650orLater(SiS_Pr)) {
10956 9964
10957 if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) { 9965 if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
10958 /* Always use the second pointer on 650; some BIOSes */ 9966 /* Always use the second pointer on 650; some BIOSes */
@@ -10978,11 +9986,12 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
10978 (!(SiS_Pr->SiS_ROMNew)) && 9986 (!(SiS_Pr->SiS_ROMNew)) &&
10979 (SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) && 9987 (SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) &&
10980 (SiS_Pr->SiS_LCDResInfo != Panel_1280x768) && 9988 (SiS_Pr->SiS_LCDResInfo != Panel_1280x768) &&
10981 (SiS_Pr->SiS_LCDResInfo != Panel_1280x960)) { 9989 (SiS_Pr->SiS_LCDResInfo != Panel_1280x960) &&
9990 (SiS_Pr->SiS_LCDResInfo != Panel_1600x1200) &&
9991 ((romptr = GetLCDromptr(SiS_Pr)))) {
10982 9992
10983 /* Data for 1280x1024 wrong in 301B BIOS */ 9993 /* Data for 1280x1024 wrong in 301B BIOS */
10984 romptr = GetLCDromptr(SiS_Pr, HwInfo); 9994 /* Data for 1600x1200 wrong in 301C BIOS */
10985 if(!romptr) return;
10986 delay = ROMAddr[(romptr + index)]; 9995 delay = ROMAddr[(romptr + index)];
10987 9996
10988 } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 9997 } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
@@ -10993,14 +10002,15 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
10993 } else { 10002 } else {
10994 10003
10995 delay = SiS310_LCDDelayCompensation_301[myindex]; 10004 delay = SiS310_LCDDelayCompensation_301[myindex];
10996 if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { 10005 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
10997 if(IS_SIS740) delay = 0x01; 10006 if(IS_SIS740) delay = 0x01;
10998 else if(HwInfo->jChipType <= SIS_315PRO) delay = SiS310_LCDDelayCompensation_3xx301LV[myindex]; 10007 else if(SiS_Pr->ChipType <= SIS_315PRO) delay = SiS310_LCDDelayCompensation_3xx301LV[myindex];
10999 else delay = SiS310_LCDDelayCompensation_650301LV[myindex]; 10008 else delay = SiS310_LCDDelayCompensation_650301LV[myindex];
11000 } else if(SiS_Pr->SiS_VBType & VB_SIS301C) { 10009 } else if(SiS_Pr->SiS_VBType & VB_SIS301C) {
11001 if(IS_SIS740) delay = 0x01; /* ? */ 10010 if(IS_SIS740) delay = 0x01; /* ? */
11002 else delay = 0x03; 10011 else delay = 0x03;
11003 } else if(SiS_Pr->SiS_VBType & VB_SIS301B302B) { 10012 if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) delay = 0x00; /* experience */
10013 } else if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
11004 if(IS_SIS740) delay = 0x01; 10014 if(IS_SIS740) delay = 0x01;
11005 else delay = SiS310_LCDDelayCompensation_3xx301B[myindex]; 10015 else delay = SiS310_LCDDelayCompensation_3xx301B[myindex];
11006 } 10016 }
@@ -11013,14 +10023,14 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
11013 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,((delay << 4) & 0xf0)); 10023 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,((delay << 4) & 0xf0));
11014 dochiptest = FALSE; 10024 dochiptest = FALSE;
11015 } 10025 }
11016 10026
11017 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* ------------ TV */ 10027 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* ------------ TV */
11018 10028
11019 index = GetTVPtrIndex(SiS_Pr); 10029 index = GetTVPtrIndex(SiS_Pr);
11020
11021 if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) {
11022 10030
11023 if(SiS_IsNotM650orLater(SiS_Pr,HwInfo)) { 10031 if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
10032
10033 if(SiS_IsNotM650orLater(SiS_Pr)) {
11024 10034
11025 if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) { 10035 if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
11026 /* Always use the second pointer on 650; some BIOSes */ 10036 /* Always use the second pointer on 650; some BIOSes */
@@ -11062,7 +10072,7 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
11062 10072
11063 } else if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) { 10073 } else if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
11064 10074
11065 romptr = GetTVromptr(SiS_Pr, HwInfo); 10075 romptr = GetTVromptr(SiS_Pr);
11066 if(!romptr) return; 10076 if(!romptr) return;
11067 delay = ROMAddr[romptr + index]; 10077 delay = ROMAddr[romptr + index];
11068 10078
@@ -11073,7 +10083,7 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
11073 } else { 10083 } else {
11074 10084
11075 delay = SiS310_TVDelayCompensation_301[index]; 10085 delay = SiS310_TVDelayCompensation_301[index];
11076 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 10086 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
11077 if(IS_SIS740) { 10087 if(IS_SIS740) {
11078 delay = SiS310_TVDelayCompensation_740301B[index]; 10088 delay = SiS310_TVDelayCompensation_740301B[index];
11079 /* LV: use 301 data? BIOS bug? */ 10089 /* LV: use 301 data? BIOS bug? */
@@ -11085,18 +10095,18 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
11085 10095
11086 } 10096 }
11087 10097
11088 if(SiS_LCDAEnabled(SiS_Pr, HwInfo)) { 10098 if(SiS_LCDAEnabled(SiS_Pr)) {
11089 delay &= 0x0f; 10099 delay &= 0x0f;
11090 dochiptest = FALSE; 10100 dochiptest = FALSE;
11091 } 10101 }
11092 10102
11093 } else return; 10103 } else return;
11094 10104
11095 /* Write delay */ 10105 /* Write delay */
11096 10106
11097 if(SiS_Pr->SiS_VBType & VB_SISVB) { 10107 if(SiS_Pr->SiS_VBType & VB_SISVB) {
11098 10108
11099 if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SIS301LV302LV) && dochiptest) { 10109 if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS) && dochiptest) {
11100 10110
11101 temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0) >> 4; 10111 temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0) >> 4;
11102 if(temp == 8) { /* 1400x1050 BIOS (COMPAL) */ 10112 if(temp == 8) { /* 1400x1050 BIOS (COMPAL) */
@@ -11134,11 +10144,10 @@ SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
11134} 10144}
11135 10145
11136static void 10146static void
11137SetAntiFlicker(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 10147SetAntiFlicker(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
11138 USHORT ModeNo,USHORT ModeIdIndex)
11139{ 10148{
11140 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 10149 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
11141 USHORT index,temp,temp1,romptr=0; 10150 unsigned short index,temp,temp1,romptr=0;
11142 10151
11143 if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p|TVSetYPbPr525p)) return; 10152 if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p|TVSetYPbPr525p)) return;
11144 10153
@@ -11152,14 +10161,14 @@ SetAntiFlicker(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
11152 temp1 = temp; 10161 temp1 = temp;
11153 10162
11154 if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) { 10163 if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
11155 if(HwInfo->jChipType >= SIS_661) { 10164 if(SiS_Pr->ChipType >= SIS_661) {
11156 temp1 = GetOEMTVPtr661(SiS_Pr); 10165 temp1 = GetOEMTVPtr661(SiS_Pr);
11157 temp1 >>= 1; 10166 temp1 >>= 1;
11158 romptr = SISGETROMW(0x260); 10167 romptr = SISGETROMW(0x260);
11159 if(HwInfo->jChipType >= SIS_760) { 10168 if(SiS_Pr->ChipType >= SIS_760) {
11160 romptr = SISGETROMW(0x360); 10169 romptr = SISGETROMW(0x360);
11161 } 10170 }
11162 } else if(HwInfo->jChipType >= SIS_330) { 10171 } else if(SiS_Pr->ChipType >= SIS_330) {
11163 romptr = SISGETROMW(0x192); 10172 romptr = SISGETROMW(0x192);
11164 } else { 10173 } else {
11165 romptr = SISGETROMW(0x112); 10174 romptr = SISGETROMW(0x112);
@@ -11178,11 +10187,10 @@ SetAntiFlicker(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
11178} 10187}
11179 10188
11180static void 10189static void
11181SetEdgeEnhance(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 10190SetEdgeEnhance(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
11182 USHORT ModeNo,USHORT ModeIdIndex)
11183{ 10191{
11184 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 10192 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
11185 USHORT index,temp,temp1,romptr=0; 10193 unsigned short index,temp,temp1,romptr=0;
11186 10194
11187 temp = temp1 = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */ 10195 temp = temp1 = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
11188 10196
@@ -11192,14 +10200,14 @@ SetEdgeEnhance(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
11192 index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex; 10200 index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
11193 10201
11194 if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) { 10202 if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
11195 if(HwInfo->jChipType >= SIS_661) { 10203 if(SiS_Pr->ChipType >= SIS_661) {
11196 romptr = SISGETROMW(0x26c); 10204 romptr = SISGETROMW(0x26c);
11197 if(HwInfo->jChipType >= SIS_760) { 10205 if(SiS_Pr->ChipType >= SIS_760) {
11198 romptr = SISGETROMW(0x36c); 10206 romptr = SISGETROMW(0x36c);
11199 } 10207 }
11200 temp1 = GetOEMTVPtr661(SiS_Pr); 10208 temp1 = GetOEMTVPtr661(SiS_Pr);
11201 temp1 >>= 1; 10209 temp1 >>= 1;
11202 } else if(HwInfo->jChipType >= SIS_330) { 10210 } else if(SiS_Pr->ChipType >= SIS_330) {
11203 romptr = SISGETROMW(0x1a4); 10211 romptr = SISGETROMW(0x1a4);
11204 } else { 10212 } else {
11205 romptr = SISGETROMW(0x124); 10213 romptr = SISGETROMW(0x124);
@@ -11217,10 +10225,9 @@ SetEdgeEnhance(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
11217} 10225}
11218 10226
11219static void 10227static void
11220SetYFilter(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 10228SetYFilter(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
11221 USHORT ModeNo,USHORT ModeIdIndex)
11222{ 10229{
11223 USHORT index, temp, i, j; 10230 unsigned short index, temp, i, j;
11224 10231
11225 if(ModeNo <= 0x13) { 10232 if(ModeNo <= 0x13) {
11226 index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVYFilterIndex; 10233 index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVYFilterIndex;
@@ -11235,7 +10242,7 @@ SetYFilter(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
11235 else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 4; /* PAL-N */ 10242 else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 4; /* PAL-N */
11236 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp = 1; /* HiVision uses PAL */ 10243 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp = 1; /* HiVision uses PAL */
11237 10244
11238 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 10245 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
11239 for(i=0x35, j=0; i<=0x38; i++, j++) { 10246 for(i=0x35, j=0; i<=0x38; i++, j++) {
11240 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]); 10247 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]);
11241 } 10248 }
@@ -11250,23 +10257,22 @@ SetYFilter(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
11250} 10257}
11251 10258
11252static void 10259static void
11253SetPhaseIncr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 10260SetPhaseIncr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
11254 USHORT ModeNo,USHORT ModeIdIndex)
11255{ 10261{
11256 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 10262 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
11257 USHORT index,temp,i,j,resinfo,romptr=0; 10263 unsigned short index,temp,i,j,resinfo,romptr=0;
11258 ULONG lindex; 10264 unsigned int lindex;
11259 10265
11260 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return; 10266 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return;
11261 10267
11262 /* NTSC-J data not in BIOS, and already set in SetGroup2 */ 10268 /* NTSC-J data not in BIOS, and already set in SetGroup2 */
11263 if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) return; 10269 if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) return;
11264 10270
11265 if((HwInfo->jChipType >= SIS_661) || SiS_Pr->SiS_ROMNew) { 10271 if((SiS_Pr->ChipType >= SIS_661) || SiS_Pr->SiS_ROMNew) {
11266 lindex = GetOEMTVPtr661_2_OLD(SiS_Pr) & 0xffff; 10272 lindex = GetOEMTVPtr661_2_OLD(SiS_Pr) & 0xffff;
11267 lindex <<= 2; 10273 lindex <<= 2;
11268 for(j=0, i=0x31; i<=0x34; i++, j++) { 10274 for(j=0, i=0x31; i<=0x34; i++, j++) {
11269 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS661_TVPhase[lindex + j]); 10275 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS_TVPhase[lindex + j]);
11270 } 10276 }
11271 return; 10277 return;
11272 } 10278 }
@@ -11286,17 +10292,17 @@ SetPhaseIncr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
11286 */ 10292 */
11287 if(SiS_Pr->SiS_UseROM) { 10293 if(SiS_Pr->SiS_UseROM) {
11288 romptr = SISGETROMW(0x116); 10294 romptr = SISGETROMW(0x116);
11289 if(HwInfo->jChipType >= SIS_330) { 10295 if(SiS_Pr->ChipType >= SIS_330) {
11290 romptr = SISGETROMW(0x196); 10296 romptr = SISGETROMW(0x196);
11291 } 10297 }
11292 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 10298 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
11293 romptr = SISGETROMW(0x11c); 10299 romptr = SISGETROMW(0x11c);
11294 if(HwInfo->jChipType >= SIS_330) { 10300 if(SiS_Pr->ChipType >= SIS_330) {
11295 romptr = SISGETROMW(0x19c); 10301 romptr = SISGETROMW(0x19c);
11296 } 10302 }
11297 if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) && (!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode))) { 10303 if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) && (!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode))) {
11298 romptr = SISGETROMW(0x116); 10304 romptr = SISGETROMW(0x116);
11299 if(HwInfo->jChipType >= SIS_330) { 10305 if(SiS_Pr->ChipType >= SIS_330) {
11300 romptr = SISGETROMW(0x196); 10306 romptr = SISGETROMW(0x196);
11301 } 10307 }
11302 } 10308 }
@@ -11311,7 +10317,7 @@ SetPhaseIncr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
11311 index = temp % 2; 10317 index = temp % 2;
11312 temp >>= 1; /* 0:NTSC, 1:PAL, 2:HiTV */ 10318 temp >>= 1; /* 0:NTSC, 1:PAL, 2:HiTV */
11313 for(j=0, i=0x31; i<=0x34; i++, j++) { 10319 for(j=0, i=0x31; i<=0x34; i++, j++) {
11314 if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) 10320 if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV))
11315 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]); 10321 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]);
11316 else if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) 10322 else if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || (SiS_Pr->SiS_TVMode & TVSetTVSimuMode))
11317 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr2[temp][index][j]); 10323 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr2[temp][index][j]);
@@ -11320,7 +10326,7 @@ SetPhaseIncr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
11320 } 10326 }
11321 } 10327 }
11322 10328
11323 if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision))) { 10329 if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision))) {
11324 if((!(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetYPbPr525p | TVSetYPbPr750p))) && (ModeNo > 0x13)) { 10330 if((!(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetYPbPr525p | TVSetYPbPr750p))) && (ModeNo > 0x13)) {
11325 if((resinfo == SIS_RI_640x480) || 10331 if((resinfo == SIS_RI_640x480) ||
11326 (resinfo == SIS_RI_800x600)) { 10332 (resinfo == SIS_RI_800x600)) {
@@ -11339,11 +10345,11 @@ SetPhaseIncr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
11339} 10345}
11340 10346
11341static void 10347static void
11342SetDelayComp661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo, 10348SetDelayComp661(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
11343 USHORT ModeIdIndex, USHORT RTI) 10349 unsigned short ModeIdIndex, unsigned short RTI)
11344{ 10350{
11345 USHORT delay = 0, romptr = 0, index, lcdpdcindex; 10351 unsigned short delay = 0, romptr = 0, index, lcdpdcindex;
11346 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 10352 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
11347 10353
11348 if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD | SetCRT2ToLCDA | SetCRT2ToRAMDAC))) 10354 if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD | SetCRT2ToLCDA | SetCRT2ToRAMDAC)))
11349 return; 10355 return;
@@ -11359,7 +10365,7 @@ SetDelayComp661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo,
11359 if(SiS_Pr->UseCustomMode) { 10365 if(SiS_Pr->UseCustomMode) {
11360 index = SiS_Pr->CSRClock; 10366 index = SiS_Pr->CSRClock;
11361 } else if(ModeNo > 0x13) { 10367 } else if(ModeNo > 0x13) {
11362 index = SiS_GetVCLK2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RTI,HwInfo); 10368 index = SiS_GetVCLK2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RTI);
11363 index = SiS_Pr->SiS_VCLKData[index].CLOCK; 10369 index = SiS_Pr->SiS_VCLKData[index].CLOCK;
11364 } 10370 }
11365 if(index < 25) index = 25; 10371 if(index < 25) index = 25;
@@ -11387,7 +10393,36 @@ SetDelayComp661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo,
11387 else delay = (SiS_Pr->SiS_RefIndex[RTI].Ext_PDC >> 4); 10393 else delay = (SiS_Pr->SiS_RefIndex[RTI].Ext_PDC >> 4);
11388 delay |= (delay << 8); 10394 delay |= (delay << 8);
11389 10395
11390 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 10396 if(SiS_Pr->ChipType >= XGI_20) {
10397
10398 delay = 0x0606;
10399 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
10400
10401 delay = 0x0404;
10402 if(SiS_Pr->SiS_XGIROM) {
10403 index = GetTVPtrIndex(SiS_Pr);
10404 if((romptr = SISGETROMW(0x35e))) {
10405 delay = (ROMAddr[romptr + index] & 0x0f) << 1;
10406 delay |= (delay << 8);
10407 }
10408 }
10409
10410 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
10411 if(SiS_Pr->ChipType == XGI_40 && SiS_Pr->ChipRevision == 0x02) {
10412 delay -= 0x0404;
10413 }
10414 }
10415 }
10416
10417 } else if(SiS_Pr->ChipType >= SIS_340) {
10418
10419 delay = 0x0606;
10420 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
10421 delay = 0x0404;
10422 }
10423 /* TODO (eventually) */
10424
10425 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
11391 10426
11392 /* 3. TV */ 10427 /* 3. TV */
11393 10428
@@ -11406,7 +10441,7 @@ SetDelayComp661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo,
11406 /* 4. LCD, LCDA (for new ROM only LV and non-Pass 1:1) */ 10441 /* 4. LCD, LCDA (for new ROM only LV and non-Pass 1:1) */
11407 10442
11408 if( (SiS_Pr->SiS_LCDResInfo != Panel_Custom) && 10443 if( (SiS_Pr->SiS_LCDResInfo != Panel_Custom) &&
11409 ((romptr = GetLCDStructPtr661_2(SiS_Pr, HwInfo))) ) { 10444 ((romptr = GetLCDStructPtr661_2(SiS_Pr))) ) {
11410 10445
11411 lcdpdcindex = (SiS_Pr->SiS_VBType & VB_UMC) ? 14 : 12; 10446 lcdpdcindex = (SiS_Pr->SiS_VBType & VB_UMC) ? 14 : 12;
11412 10447
@@ -11426,6 +10461,7 @@ SetDelayComp661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo,
11426 case Panel_1280x768_2:delay = 0x0004; break; 10461 case Panel_1280x768_2:delay = 0x0004; break;
11427 case Panel_1280x800: 10462 case Panel_1280x800:
11428 case Panel_1280x800_2:delay = 0x0004; break; /* Verified for 1280x800 */ 10463 case Panel_1280x800_2:delay = 0x0004; break; /* Verified for 1280x800 */
10464 case Panel_1280x854: delay = 0x0004; break; /* FIXME */
11429 case Panel_1280x1024: delay = 0x1e04; break; 10465 case Panel_1280x1024: delay = 0x1e04; break;
11430 case Panel_1400x1050: delay = 0x0004; break; 10466 case Panel_1400x1050: delay = 0x0004; break;
11431 case Panel_1600x1200: delay = 0x0400; break; 10467 case Panel_1600x1200: delay = 0x0400; break;
@@ -11469,10 +10505,10 @@ SetDelayComp661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo,
11469} 10505}
11470 10506
11471static void 10507static void
11472SetCRT2SyncDither661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo, USHORT RTI) 10508SetCRT2SyncDither661(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short RTI)
11473{ 10509{
11474 USHORT infoflag; 10510 unsigned short infoflag;
11475 UCHAR temp; 10511 unsigned char temp;
11476 10512
11477 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { 10513 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
11478 10514
@@ -11513,12 +10549,16 @@ SetCRT2SyncDither661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo, US
11513} 10549}
11514 10550
11515static void 10551static void
11516SetPanelParms661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo) 10552SetPanelParms661(struct SiS_Private *SiS_Pr)
11517{ 10553{
11518 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 10554 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
11519 USHORT romptr, temp1, temp2; 10555 unsigned short romptr, temp1, temp2;
10556
10557 if(SiS_Pr->SiS_VBType & (VB_SISLVDS | VB_SIS30xC)) {
10558 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x24,0x0f);
10559 }
11520 10560
11521 if(SiS_Pr->SiS_VBType & (VB_SIS301LV | VB_SIS302LV | VB_SIS302ELV)) { 10561 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
11522 if(SiS_Pr->LVDSHL != -1) { 10562 if(SiS_Pr->LVDSHL != -1) {
11523 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL); 10563 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL);
11524 } 10564 }
@@ -11526,8 +10566,8 @@ SetPanelParms661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
11526 10566
11527 if(SiS_Pr->SiS_ROMNew) { 10567 if(SiS_Pr->SiS_ROMNew) {
11528 10568
11529 if((romptr = GetLCDStructPtr661_2(SiS_Pr, HwInfo))) { 10569 if((romptr = GetLCDStructPtr661_2(SiS_Pr))) {
11530 if(SiS_Pr->SiS_VBType & (VB_SIS301LV | VB_SIS302LV | VB_SIS302ELV)) { 10570 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
11531 temp1 = (ROMAddr[romptr] & 0x03) | 0x0c; 10571 temp1 = (ROMAddr[romptr] & 0x03) | 0x0c;
11532 temp2 = 0xfc; 10572 temp2 = 0xfc;
11533 if(SiS_Pr->LVDSHL != -1) { 10573 if(SiS_Pr->LVDSHL != -1) {
@@ -11546,48 +10586,47 @@ SetPanelParms661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
11546} 10586}
11547 10587
11548static void 10588static void
11549SiS_OEM310Setting(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 10589SiS_OEM310Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RRTI)
11550 USHORT ModeNo,USHORT ModeIdIndex,USHORT RRTI)
11551{ 10590{
11552 if((SiS_Pr->SiS_ROMNew) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) { 10591 if((SiS_Pr->SiS_ROMNew) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
11553 SetDelayComp661(SiS_Pr,HwInfo,ModeNo,ModeIdIndex,RRTI); 10592 SetDelayComp661(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
11554 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { 10593 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
11555 SetCRT2SyncDither661(SiS_Pr,HwInfo,ModeNo,RRTI); 10594 SetCRT2SyncDither661(SiS_Pr, ModeNo, RRTI);
11556 SetPanelParms661(SiS_Pr,HwInfo); 10595 SetPanelParms661(SiS_Pr);
11557 } 10596 }
11558 } else { 10597 } else {
11559 SetDelayComp(SiS_Pr,HwInfo,ModeNo); 10598 SetDelayComp(SiS_Pr,ModeNo);
11560 } 10599 }
11561 10600
11562 if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) { 10601 if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
11563 SetAntiFlicker(SiS_Pr,HwInfo,ModeNo,ModeIdIndex); 10602 SetAntiFlicker(SiS_Pr,ModeNo,ModeIdIndex);
11564 SetPhaseIncr(SiS_Pr,HwInfo,ModeNo,ModeIdIndex); 10603 SetPhaseIncr(SiS_Pr,ModeNo,ModeIdIndex);
11565 SetYFilter(SiS_Pr,HwInfo,ModeNo,ModeIdIndex); 10604 SetYFilter(SiS_Pr,ModeNo,ModeIdIndex);
11566 if(SiS_Pr->SiS_VBType & VB_SIS301) { 10605 if(SiS_Pr->SiS_VBType & VB_SIS301) {
11567 SetEdgeEnhance(SiS_Pr,HwInfo,ModeNo,ModeIdIndex); 10606 SetEdgeEnhance(SiS_Pr,ModeNo,ModeIdIndex);
11568 } 10607 }
11569 } 10608 }
11570} 10609}
11571 10610
11572static void 10611static void
11573SiS_OEM661Setting(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 10612SiS_OEM661Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
11574 USHORT ModeNo,USHORT ModeIdIndex, USHORT RRTI) 10613 unsigned short ModeIdIndex, unsigned short RRTI)
11575{ 10614{
11576 if(SiS_Pr->SiS_VBType & VB_SISVB) { 10615 if(SiS_Pr->SiS_VBType & VB_SISVB) {
11577 10616
11578 SetDelayComp661(SiS_Pr,HwInfo,ModeNo,ModeIdIndex,RRTI); 10617 SetDelayComp661(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
11579 10618
11580 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { 10619 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
11581 SetCRT2SyncDither661(SiS_Pr,HwInfo,ModeNo,RRTI); 10620 SetCRT2SyncDither661(SiS_Pr, ModeNo, RRTI);
11582 SetPanelParms661(SiS_Pr,HwInfo); 10621 SetPanelParms661(SiS_Pr);
11583 } 10622 }
11584 10623
11585 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 10624 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
11586 SetPhaseIncr(SiS_Pr,HwInfo,ModeNo,ModeIdIndex); 10625 SetPhaseIncr(SiS_Pr, ModeNo, ModeIdIndex);
11587 SetYFilter(SiS_Pr,HwInfo,ModeNo,ModeIdIndex); 10626 SetYFilter(SiS_Pr, ModeNo, ModeIdIndex);
11588 SetAntiFlicker(SiS_Pr,HwInfo,ModeNo,ModeIdIndex); 10627 SetAntiFlicker(SiS_Pr, ModeNo, ModeIdIndex);
11589 if(SiS_Pr->SiS_VBType & VB_SIS301) { 10628 if(SiS_Pr->SiS_VBType & VB_SIS301) {
11590 SetEdgeEnhance(SiS_Pr,HwInfo,ModeNo,ModeIdIndex); 10629 SetEdgeEnhance(SiS_Pr, ModeNo, ModeIdIndex);
11591 } 10630 }
11592 } 10631 }
11593 } 10632 }
@@ -11601,13 +10640,12 @@ SiS_OEM661Setting(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
11601 * pray that we have a backup... 10640 * pray that we have a backup...
11602 */ 10641 */
11603static void 10642static void
11604SiS_FinalizeLCD(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 10643SiS_FinalizeLCD(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
11605 PSIS_HW_INFO HwInfo)
11606{ 10644{
11607 USHORT tempcl,tempch,tempbl,tempbh,tempbx,tempax,temp; 10645 unsigned short tempcl,tempch,tempbl,tempbh,tempbx,tempax,temp;
11608 USHORT resinfo,modeflag; 10646 unsigned short resinfo,modeflag;
11609 10647
11610 if(!(SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) return; 10648 if(!(SiS_Pr->SiS_VBType & VB_SISLVDS)) return;
11611 if(SiS_Pr->SiS_ROMNew) return; 10649 if(SiS_Pr->SiS_ROMNew) return;
11612 10650
11613 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { 10651 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
@@ -11678,7 +10716,7 @@ SiS_FinalizeLCD(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
11678 10716
11679 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { 10717 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
11680 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { 10718 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
11681 if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) { 10719 if(SiS_Pr->SiS_VBType & VB_SISEMI) {
11682 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00); 10720 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
11683#ifdef SET_EMI 10721#ifdef SET_EMI
11684 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c); 10722 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
@@ -11806,11 +10844,11 @@ SiS_FinalizeLCD(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
11806#ifdef SIS300 10844#ifdef SIS300
11807 10845
11808static void 10846static void
11809SetOEMLCDData2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 10847SetOEMLCDData2(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex,
11810 USHORT ModeNo,USHORT ModeIdIndex, USHORT RefTabIndex) 10848 unsigned short RefTabIndex)
11811{ 10849{
11812 USHORT crt2crtc=0, modeflag, myindex=0; 10850 unsigned short crt2crtc=0, modeflag, myindex=0;
11813 UCHAR temp; 10851 unsigned char temp;
11814 int i; 10852 int i;
11815 10853
11816 if(ModeNo <= 0x13) { 10854 if(ModeNo <= 0x13) {
@@ -11849,21 +10887,21 @@ SetOEMLCDData2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
11849 } 10887 }
11850} 10888}
11851 10889
11852static USHORT 10890static unsigned short
11853GetOEMLCDPtr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, int Flag) 10891GetOEMLCDPtr(struct SiS_Private *SiS_Pr, int Flag)
11854{ 10892{
11855 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 10893 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
11856 USHORT tempbx=0,romptr=0; 10894 unsigned short tempbx=0,romptr=0;
11857 UCHAR customtable300[] = { 10895 static const unsigned char customtable300[] = {
11858 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 10896 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
11859 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff 10897 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
11860 }; 10898 };
11861 UCHAR customtable630[] = { 10899 static const unsigned char customtable630[] = {
11862 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 10900 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
11863 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff 10901 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
11864 }; 10902 };
11865 10903
11866 if(HwInfo->jChipType == SIS_300) { 10904 if(SiS_Pr->ChipType == SIS_300) {
11867 10905
11868 tempbx = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0x0f; 10906 tempbx = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0x0f;
11869 if(SiS_Pr->SiS_VBType & VB_SIS301) tempbx &= 0x07; 10907 if(SiS_Pr->SiS_VBType & VB_SIS301) tempbx &= 0x07;
@@ -11912,11 +10950,10 @@ GetOEMLCDPtr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, int Flag)
11912} 10950}
11913 10951
11914static void 10952static void
11915SetOEMLCDDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 10953SetOEMLCDDelay(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
11916 USHORT ModeNo,USHORT ModeIdIndex)
11917{ 10954{
11918 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 10955 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
11919 USHORT index,temp,romptr=0; 10956 unsigned short index,temp,romptr=0;
11920 10957
11921 if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return; 10958 if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return;
11922 10959
@@ -11927,22 +10964,22 @@ SetOEMLCDDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
11927 } 10964 }
11928 10965
11929 /* The Panel Compensation Delay should be set according to tables 10966 /* The Panel Compensation Delay should be set according to tables
11930 * here. Unfortunately, various BIOS versions don't case about 10967 * here. Unfortunately, various BIOS versions don't care about
11931 * a uniform way using eg. ROM byte 0x220, but use different 10968 * a uniform way using eg. ROM byte 0x220, but use different
11932 * hard coded delays (0x04, 0x20, 0x18) in SetGroup1(). 10969 * hard coded delays (0x04, 0x20, 0x18) in SetGroup1().
11933 * Thus we don't set this if the user select a custom pdc or if 10970 * Thus we don't set this if the user selected a custom pdc or if
11934 * we otherwise detected a valid pdc. 10971 * we otherwise detected a valid pdc.
11935 */ 10972 */
11936 if(SiS_Pr->PDC != -1) return; 10973 if(SiS_Pr->PDC != -1) return;
11937 10974
11938 temp = GetOEMLCDPtr(SiS_Pr,HwInfo, 0); 10975 temp = GetOEMLCDPtr(SiS_Pr, 0);
11939 10976
11940 if(SiS_Pr->UseCustomMode) 10977 if(SiS_Pr->UseCustomMode)
11941 index = 0; 10978 index = 0;
11942 else 10979 else
11943 index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_LCDDelayIndex; 10980 index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_LCDDelayIndex;
11944 10981
11945 if(HwInfo->jChipType != SIS_300) { 10982 if(SiS_Pr->ChipType != SIS_300) {
11946 if(romptr) { 10983 if(romptr) {
11947 romptr += (temp * 2); 10984 romptr += (temp * 2);
11948 romptr = SISGETROMW(romptr); 10985 romptr = SISGETROMW(romptr);
@@ -11986,12 +11023,11 @@ SetOEMLCDDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
11986} 11023}
11987 11024
11988static void 11025static void
11989SetOEMLCDData(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 11026SetOEMLCDData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
11990 USHORT ModeNo,USHORT ModeIdIndex)
11991{ 11027{
11992#if 0 /* Unfinished; Data table missing */ 11028#if 0 /* Unfinished; Data table missing */
11993 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 11029 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
11994 USHORT index,temp; 11030 unsigned short index,temp;
11995 11031
11996 if((SiS_Pr->SiS_UseROM) { 11032 if((SiS_Pr->SiS_UseROM) {
11997 if(!(ROMAddr[0x237] & 0x01)) return; 11033 if(!(ROMAddr[0x237] & 0x01)) return;
@@ -11999,8 +11035,8 @@ SetOEMLCDData(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
11999 /* No rom pointer in BIOS header! */ 11035 /* No rom pointer in BIOS header! */
12000 } 11036 }
12001 11037
12002 temp = GetOEMLCDPtr(SiS_Pr,HwInfo, 1); 11038 temp = GetOEMLCDPtr(SiS_Pr, 1);
12003 if(temp = 0xFFFF) return; 11039 if(temp == 0xFFFF) return;
12004 11040
12005 index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDHIndex; 11041 index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDHIndex;
12006 for(i=0x14, j=0; i<=0x17; i++, j++) { 11042 for(i=0x14, j=0; i<=0x17; i++, j++) {
@@ -12018,10 +11054,10 @@ SetOEMLCDData(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
12018#endif 11054#endif
12019} 11055}
12020 11056
12021static USHORT 11057static unsigned short
12022GetOEMTVPtr(SiS_Private *SiS_Pr) 11058GetOEMTVPtr(struct SiS_Private *SiS_Pr)
12023{ 11059{
12024 USHORT index; 11060 unsigned short index;
12025 11061
12026 index = 0; 11062 index = 0;
12027 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) index += 4; 11063 if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) index += 4;
@@ -12037,11 +11073,10 @@ GetOEMTVPtr(SiS_Private *SiS_Pr)
12037} 11073}
12038 11074
12039static void 11075static void
12040SetOEMTVDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 11076SetOEMTVDelay(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
12041 USHORT ModeNo,USHORT ModeIdIndex)
12042{ 11077{
12043 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 11078 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
12044 USHORT index,temp,romptr=0; 11079 unsigned short index,temp,romptr=0;
12045 11080
12046 if(SiS_Pr->SiS_UseROM) { 11081 if(SiS_Pr->SiS_UseROM) {
12047 if(!(ROMAddr[0x238] & 0x01)) return; 11082 if(!(ROMAddr[0x238] & 0x01)) return;
@@ -12070,11 +11105,10 @@ SetOEMTVDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
12070} 11105}
12071 11106
12072static void 11107static void
12073SetOEMAntiFlicker(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 11108SetOEMAntiFlicker(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
12074 USHORT ModeNo, USHORT ModeIdIndex)
12075{ 11109{
12076 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 11110 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
12077 USHORT index,temp,romptr=0; 11111 unsigned short index,temp,romptr=0;
12078 11112
12079 if(SiS_Pr->SiS_UseROM) { 11113 if(SiS_Pr->SiS_UseROM) {
12080 if(!(ROMAddr[0x238] & 0x01)) return; 11114 if(!(ROMAddr[0x238] & 0x01)) return;
@@ -12099,11 +11133,10 @@ SetOEMAntiFlicker(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
12099} 11133}
12100 11134
12101static void 11135static void
12102SetOEMPhaseIncr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 11136SetOEMPhaseIncr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
12103 USHORT ModeNo,USHORT ModeIdIndex)
12104{ 11137{
12105 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 11138 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
12106 USHORT index,i,j,temp,romptr=0; 11139 unsigned short index,i,j,temp,romptr=0;
12107 11140
12108 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) return; 11141 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) return;
12109 11142
@@ -12119,7 +11152,7 @@ SetOEMPhaseIncr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
12119 11152
12120 index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVPhaseIndex; 11153 index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVPhaseIndex;
12121 11154
12122 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 11155 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
12123 for(i=0x31, j=0; i<=0x34; i++, j++) { 11156 for(i=0x31, j=0; i<=0x34; i++, j++) {
12124 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase2[temp][index][j]); 11157 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase2[temp][index][j]);
12125 } 11158 }
@@ -12140,11 +11173,10 @@ SetOEMPhaseIncr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
12140} 11173}
12141 11174
12142static void 11175static void
12143SetOEMYFilter(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 11176SetOEMYFilter(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
12144 USHORT ModeNo,USHORT ModeIdIndex)
12145{ 11177{
12146 UCHAR *ROMAddr = HwInfo->pjVirtualRomBase; 11178 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
12147 USHORT index,temp,i,j,romptr=0; 11179 unsigned short index,temp,i,j,romptr=0;
12148 11180
12149 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSCART | SetCRT2ToHiVision | SetCRT2ToYPbPr525750)) return; 11181 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSCART | SetCRT2ToHiVision | SetCRT2ToYPbPr525750)) return;
12150 11182
@@ -12162,7 +11194,7 @@ SetOEMYFilter(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
12162 11194
12163 index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVYFilterIndex; 11195 index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVYFilterIndex;
12164 11196
12165 if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { 11197 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
12166 for(i=0x35, j=0; i<=0x38; i++, j++) { 11198 for(i=0x35, j=0; i<=0x38; i++, j++) {
12167 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]); 11199 SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]);
12168 } 11200 }
@@ -12185,11 +11217,11 @@ SetOEMYFilter(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
12185 } 11217 }
12186} 11218}
12187 11219
12188static USHORT 11220static unsigned short
12189SiS_SearchVBModeID(SiS_Private *SiS_Pr, USHORT *ModeNo) 11221SiS_SearchVBModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo)
12190{ 11222{
12191 USHORT ModeIdIndex; 11223 unsigned short ModeIdIndex;
12192 UCHAR VGAINFO = SiS_Pr->SiS_VGAINFO; 11224 unsigned char VGAINFO = SiS_Pr->SiS_VGAINFO;
12193 11225
12194 if(*ModeNo <= 5) *ModeNo |= 1; 11226 if(*ModeNo <= 5) *ModeNo |= 1;
12195 11227
@@ -12210,10 +11242,10 @@ SiS_SearchVBModeID(SiS_Private *SiS_Pr, USHORT *ModeNo)
12210} 11242}
12211 11243
12212static void 11244static void
12213SiS_OEM300Setting(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 11245SiS_OEM300Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
12214 USHORT ModeNo, USHORT ModeIdIndex, USHORT RefTableIndex) 11246 unsigned short RefTableIndex)
12215{ 11247{
12216 USHORT OEMModeIdIndex=0; 11248 unsigned short OEMModeIdIndex = 0;
12217 11249
12218 if(!SiS_Pr->UseCustomMode) { 11250 if(!SiS_Pr->UseCustomMode) {
12219 OEMModeIdIndex = SiS_SearchVBModeID(SiS_Pr,&ModeNo); 11251 OEMModeIdIndex = SiS_SearchVBModeID(SiS_Pr,&ModeNo);
@@ -12221,18 +11253,18 @@ SiS_OEM300Setting(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
12221 } 11253 }
12222 11254
12223 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 11255 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
12224 SetOEMLCDDelay(SiS_Pr, HwInfo, ModeNo, OEMModeIdIndex); 11256 SetOEMLCDDelay(SiS_Pr, ModeNo, OEMModeIdIndex);
12225 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 11257 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
12226 SetOEMLCDData(SiS_Pr, HwInfo, ModeNo, OEMModeIdIndex); 11258 SetOEMLCDData(SiS_Pr, ModeNo, OEMModeIdIndex);
12227 } 11259 }
12228 } 11260 }
12229 if(SiS_Pr->UseCustomMode) return; 11261 if(SiS_Pr->UseCustomMode) return;
12230 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { 11262 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
12231 SetOEMTVDelay(SiS_Pr, HwInfo, ModeNo,OEMModeIdIndex); 11263 SetOEMTVDelay(SiS_Pr, ModeNo,OEMModeIdIndex);
12232 if(SiS_Pr->SiS_VBType & VB_SISVB) { 11264 if(SiS_Pr->SiS_VBType & VB_SISVB) {
12233 SetOEMAntiFlicker(SiS_Pr, HwInfo, ModeNo, OEMModeIdIndex); 11265 SetOEMAntiFlicker(SiS_Pr, ModeNo, OEMModeIdIndex);
12234 SetOEMPhaseIncr(SiS_Pr, HwInfo, ModeNo, OEMModeIdIndex); 11266 SetOEMPhaseIncr(SiS_Pr, ModeNo, OEMModeIdIndex);
12235 SetOEMYFilter(SiS_Pr, HwInfo, ModeNo, OEMModeIdIndex); 11267 SetOEMYFilter(SiS_Pr, ModeNo, OEMModeIdIndex);
12236 } 11268 }
12237 } 11269 }
12238} 11270}
diff --git a/drivers/video/sis/init301.h b/drivers/video/sis/init301.h
index f84eb54164..f475b21a85 100644
--- a/drivers/video/sis/init301.h
+++ b/drivers/video/sis/init301.h
@@ -3,7 +3,7 @@
3/* 3/*
4 * Data and prototypes for init301.c 4 * Data and prototypes for init301.c
5 * 5 *
6 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria 6 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
7 * 7 *
8 * If distributed as part of the Linux kernel, the following license terms 8 * If distributed as part of the Linux kernel, the following license terms
9 * apply: 9 * apply:
@@ -50,18 +50,18 @@
50 * 50 *
51 */ 51 */
52 52
53#ifndef _INIT301_ 53#ifndef _INIT301_H_
54#define _INIT301_ 54#define _INIT301_H_
55 55
56#include "osdef.h" 56#include "osdef.h"
57#include "initdef.h" 57#include "initdef.h"
58 58
59#ifdef LINUX_XF86 59#ifdef SIS_XORG_XF86
60#include "sis.h" 60#include "sis.h"
61#include "sis_regs.h" 61#include "sis_regs.h"
62#endif 62#endif
63 63
64#ifdef LINUX_KERNEL 64#ifdef SIS_LINUX_KERNEL
65#include "vgatypes.h" 65#include "vgatypes.h"
66#include "vstruct.h" 66#include "vstruct.h"
67#ifdef SIS_CP 67#ifdef SIS_CP
@@ -69,8 +69,13 @@
69#endif 69#endif
70#include <linux/config.h> 70#include <linux/config.h>
71#include <linux/version.h> 71#include <linux/version.h>
72#include <asm/io.h>
73#include <linux/types.h> 72#include <linux/types.h>
73#include <asm/io.h>
74#include <linux/fb.h>
75#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
76#include <video/fbcon.h>
77#endif
78#include "sis.h"
74#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 79#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
75#include <linux/sisfb.h> 80#include <linux/sisfb.h>
76#else 81#else
@@ -78,7 +83,7 @@
78#endif 83#endif
79#endif 84#endif
80 85
81static const UCHAR SiS_YPbPrTable[3][64] = { 86static const unsigned char SiS_YPbPrTable[3][64] = {
82 { 87 {
83 0x17,0x1d,0x03,0x09,0x05,0x06,0x0c,0x0c, 88 0x17,0x1d,0x03,0x09,0x05,0x06,0x0c,0x0c,
84 0x94,0x49,0x01,0x0a,0x06,0x0d,0x04,0x0a, 89 0x94,0x49,0x01,0x0a,0x06,0x0d,0x04,0x0a,
@@ -90,17 +95,17 @@ static const UCHAR SiS_YPbPrTable[3][64] = {
90 0x00,0x40,0x44,0x00,0xdb,0x02,0x3b,0x00 95 0x00,0x40,0x44,0x00,0xdb,0x02,0x3b,0x00
91 }, 96 },
92 { 97 {
93 0x1d,0x11,0x06,0x09,0x0b,0x0c,0x0c,0x0c, 98 0x33,0x06,0x06,0x09,0x0b,0x0c,0x0c,0x0c,
94 0x98,0x0a,0x01,0x0d,0x06,0x0d,0x04,0x0a, 99 0x98,0x0a,0x01,0x0d,0x06,0x0d,0x04,0x0a,
95 0x06,0x14,0x0d,0x04,0x0a,0x00,0x85,0x3f, 100 0x06,0x14,0x0d,0x04,0x0a,0x00,0x85,0x3f,
96 0x0c,0x50,0xb2,0x9f,0x16,0x59,0x4c /*0x4f*/,0x13, 101 0x0c,0x50,0xb2,0x9f,0x16,0x59,0x4f,0x13,
97 0xad,0x11,0xad,0x1d,0x40,0x8a,0x3d,0xb8, 102 0xad,0x11,0xad,0x1d,0x40,0x8a,0x3d,0xb8,
98 0x51,0x5e,0x60,0x57 /*0x49*/,0x7b /*0x7d*/,0x92,0x0f,0x40, 103 0x51,0x5e,0x60,0x49,0x7d,0x92,0x0f,0x40,
99 0x60,0x80,0x14,0x90,0x8c,0x60,0x14,0x4b, 104 0x60,0x80,0x14,0x90,0x8c,0x60,0x14,0x4e,
100 0x43,0x41,0x11,0x00,0xfc,0xff,0x32,0x00 105 0x43,0x41,0x11,0x00,0xfc,0xff,0x32,0x00
101 }, 106 },
102 { 107 {
103#if 1 108#if 0 /* OK, but sticks to left edge */
104 0x13,0x1d,0xe8,0x09,0x09,0xed,0x0c,0x0c, 109 0x13,0x1d,0xe8,0x09,0x09,0xed,0x0c,0x0c,
105 0x98,0x0a,0x01,0x0c,0x06,0x0d,0x04,0x0a, 110 0x98,0x0a,0x01,0x0c,0x06,0x0d,0x04,0x0a,
106 0x06,0x14,0x0d,0x04,0x0a,0x00,0x85,0x3f, 111 0x06,0x14,0x0d,0x04,0x0a,0x00,0x85,0x3f,
@@ -110,20 +115,42 @@ static const UCHAR SiS_YPbPrTable[3][64] = {
110 0x60,0x80,0x14,0x90,0x8c,0x60,0x14,0x27, 115 0x60,0x80,0x14,0x90,0x8c,0x60,0x14,0x27,
111 0x00,0x40,0x11,0x00,0xfc,0xff,0x32,0x00 116 0x00,0x40,0x11,0x00,0xfc,0xff,0x32,0x00
112#endif 117#endif
113#if 0 118#if 1 /* Perfect */
114 0x2a,0x14,0xe8,0x09,0x09,0xed,0x0c,0x0c, /* TEST (0.93) - BAD */ 119 0x23,0x2d,0xe8,0x09,0x09,0xed,0x0c,0x0c,
115 0x98,0x0a,0x01,0x0c,0x06,0x0d,0x04,0x0a, 120 0x98,0x0a,0x01,0x0c,0x06,0x0d,0x04,0x0a,
116 0x06,0x14,0x0d,0x04,0x0a,0x00,0x85,0x3f, 121 0x06,0x14,0x0d,0x04,0x0a,0x00,0x85,0x3f,
117 0xed,0x50,0x70,0x9e,0x16,0x57,0x6c,0x13, 122 0xed,0x50,0x70,0x9f,0x16,0x59,0x60,0x13,
118 0x27,0x0b,0x27,0xfb,0x30,0x27,0x15,0xb0, 123 0x27,0x0b,0x27,0xfc,0x30,0x27,0x1c,0xb0,
119 0x3b,0xdb,0x61,0x24,0x78,0x92,0x0f,0xff, 124 0x4b,0x4b,0x6f,0x2f,0x63,0x92,0x0f,0x40,
120 0xff,0xff,0xff,0xff,0xff,0xff,0x14,0x6f, 125 0x60,0x80,0x14,0x90,0x8c,0x60,0x14,0x73,
121 0x00,0x52,0xbb,0x00,0xd5,0xf7,0xa2,0x00 126 0x00,0x40,0x11,0x00,0xfc,0xff,0x32,0x00
122#endif 127#endif
123 } 128 }
124}; 129};
125 130
126static const UCHAR SiS_HiTVGroup3_1[] = { 131static const unsigned char SiS_TVPhase[] =
132{
133 0x21,0xED,0xBA,0x08, /* 0x00 SiS_NTSCPhase */
134 0x2A,0x05,0xE3,0x00, /* 0x01 SiS_PALPhase */
135 0x21,0xE4,0x2E,0x9B, /* 0x02 SiS_PALMPhase */
136 0x21,0xF4,0x3E,0xBA, /* 0x03 SiS_PALNPhase */
137 0x1E,0x8B,0xA2,0xA7,
138 0x1E,0x83,0x0A,0xE0, /* 0x05 SiS_SpecialPhaseM */
139 0x00,0x00,0x00,0x00,
140 0x00,0x00,0x00,0x00,
141 0x21,0xF0,0x7B,0xD6, /* 0x08 SiS_NTSCPhase2 */
142 0x2A,0x09,0x86,0xE9, /* 0x09 SiS_PALPhase2 */
143 0x21,0xE6,0xEF,0xA4, /* 0x0a SiS_PALMPhase2 */
144 0x21,0xF6,0x94,0x46, /* 0x0b SiS_PALNPhase2 */
145 0x1E,0x8B,0xA2,0xA7,
146 0x1E,0x83,0x0A,0xE0, /* 0x0d SiS_SpecialPhaseM */
147 0x00,0x00,0x00,0x00,
148 0x00,0x00,0x00,0x00,
149 0x1e,0x8c,0x5c,0x7a, /* 0x10 SiS_SpecialPhase */
150 0x25,0xd4,0xfd,0x5e /* 0x11 SiS_SpecialPhaseJ */
151};
152
153static const unsigned char SiS_HiTVGroup3_1[] = {
127 0x00, 0x14, 0x15, 0x25, 0x55, 0x15, 0x0b, 0x13, 154 0x00, 0x14, 0x15, 0x25, 0x55, 0x15, 0x0b, 0x13,
128 0xb1, 0x41, 0x62, 0x62, 0xff, 0xf4, 0x45, 0xa6, 155 0xb1, 0x41, 0x62, 0x62, 0xff, 0xf4, 0x45, 0xa6,
129 0x25, 0x2f, 0x67, 0xf6, 0xbf, 0xff, 0x8e, 0x20, 156 0x25, 0x2f, 0x67, 0xf6, 0xbf, 0xff, 0x8e, 0x20,
@@ -134,7 +161,7 @@ static const UCHAR SiS_HiTVGroup3_1[] = {
134 0x1a, 0x1f, 0x25, 0x2a, 0x4c, 0xaa, 0x01 161 0x1a, 0x1f, 0x25, 0x2a, 0x4c, 0xaa, 0x01
135}; 162};
136 163
137static const UCHAR SiS_HiTVGroup3_2[] = { 164static const unsigned char SiS_HiTVGroup3_2[] = {
138 0x00, 0x14, 0x15, 0x25, 0x55, 0x15, 0x0b, 0x7a, 165 0x00, 0x14, 0x15, 0x25, 0x55, 0x15, 0x0b, 0x7a,
139 0x54, 0x41, 0xe7, 0xe7, 0xff, 0xf4, 0x45, 0xa6, 166 0x54, 0x41, 0xe7, 0xe7, 0xff, 0xf4, 0x45, 0xa6,
140 0x25, 0x2f, 0x67, 0xf6, 0xbf, 0xff, 0x8e, 0x20, 167 0x25, 0x2f, 0x67, 0xf6, 0xbf, 0xff, 0x8e, 0x20,
@@ -147,7 +174,7 @@ static const UCHAR SiS_HiTVGroup3_2[] = {
147 174
148/* 301C / 302ELV extended Part2 TV registers (4 tap scaler) */ 175/* 301C / 302ELV extended Part2 TV registers (4 tap scaler) */
149 176
150static const UCHAR SiS_Part2CLVX_1[] = { 177static const unsigned char SiS_Part2CLVX_1[] = {
151 0x00,0x00, 178 0x00,0x00,
152 0x00,0x20,0x00,0x00,0x7F,0x20,0x02,0x7F,0x7D,0x20,0x04,0x7F,0x7D,0x1F,0x06,0x7E, 179 0x00,0x20,0x00,0x00,0x7F,0x20,0x02,0x7F,0x7D,0x20,0x04,0x7F,0x7D,0x1F,0x06,0x7E,
153 0x7C,0x1D,0x09,0x7E,0x7C,0x1B,0x0B,0x7E,0x7C,0x19,0x0E,0x7D,0x7C,0x17,0x11,0x7C, 180 0x7C,0x1D,0x09,0x7E,0x7C,0x1B,0x0B,0x7E,0x7C,0x19,0x0E,0x7D,0x7C,0x17,0x11,0x7C,
@@ -155,7 +182,7 @@ static const UCHAR SiS_Part2CLVX_1[] = {
155 0x7E,0x09,0x1D,0x7C,0x7F,0x06,0x1F,0x7C,0x7F,0x04,0x20,0x7D,0x00,0x02,0x20,0x7E 182 0x7E,0x09,0x1D,0x7C,0x7F,0x06,0x1F,0x7C,0x7F,0x04,0x20,0x7D,0x00,0x02,0x20,0x7E
156}; 183};
157 184
158static const UCHAR SiS_Part2CLVX_2[] = { 185static const unsigned char SiS_Part2CLVX_2[] = {
159 0x00,0x00, 186 0x00,0x00,
160 0x00,0x20,0x00,0x00,0x7F,0x20,0x02,0x7F,0x7D,0x20,0x04,0x7F,0x7D,0x1F,0x06,0x7E, 187 0x00,0x20,0x00,0x00,0x7F,0x20,0x02,0x7F,0x7D,0x20,0x04,0x7F,0x7D,0x1F,0x06,0x7E,
161 0x7C,0x1D,0x09,0x7E,0x7C,0x1B,0x0B,0x7E,0x7C,0x19,0x0E,0x7D,0x7C,0x17,0x11,0x7C, 188 0x7C,0x1D,0x09,0x7E,0x7C,0x1B,0x0B,0x7E,0x7C,0x19,0x0E,0x7D,0x7C,0x17,0x11,0x7C,
@@ -163,7 +190,7 @@ static const UCHAR SiS_Part2CLVX_2[] = {
163 0x7E,0x09,0x1D,0x7C,0x7F,0x06,0x1F,0x7C,0x7F,0x04,0x20,0x7D,0x00,0x02,0x20,0x7E 190 0x7E,0x09,0x1D,0x7C,0x7F,0x06,0x1F,0x7C,0x7F,0x04,0x20,0x7D,0x00,0x02,0x20,0x7E
164}; 191};
165 192
166static const UCHAR SiS_Part2CLVX_3[] = { /* NTSC, 525i, 525p */ 193static const unsigned char SiS_Part2CLVX_3[] = { /* NTSC, 525i, 525p */
167 0xE0,0x01, 194 0xE0,0x01,
168 0x04,0x1A,0x04,0x7E,0x03,0x1A,0x06,0x7D,0x01,0x1A,0x08,0x7D,0x00,0x19,0x0A,0x7D, 195 0x04,0x1A,0x04,0x7E,0x03,0x1A,0x06,0x7D,0x01,0x1A,0x08,0x7D,0x00,0x19,0x0A,0x7D,
169 0x7F,0x19,0x0C,0x7C,0x7E,0x18,0x0E,0x7C,0x7E,0x17,0x10,0x7B,0x7D,0x15,0x12,0x7C, 196 0x7F,0x19,0x0C,0x7C,0x7E,0x18,0x0E,0x7C,0x7E,0x17,0x10,0x7B,0x7D,0x15,0x12,0x7C,
@@ -182,7 +209,7 @@ static const UCHAR SiS_Part2CLVX_3[] = { /* NTSC, 525i, 525p */
182 0xFF,0xFF 209 0xFF,0xFF
183}; 210};
184 211
185static const UCHAR SiS_Part2CLVX_4[] = { /* PAL */ 212static const unsigned char SiS_Part2CLVX_4[] = { /* PAL */
186 0x58,0x02, 213 0x58,0x02,
187 0x05,0x19,0x05,0x7D,0x03,0x19,0x06,0x7E,0x02,0x19,0x08,0x7D,0x01,0x18,0x0A,0x7D, 214 0x05,0x19,0x05,0x7D,0x03,0x19,0x06,0x7E,0x02,0x19,0x08,0x7D,0x01,0x18,0x0A,0x7D,
188 0x00,0x18,0x0C,0x7C,0x7F,0x17,0x0E,0x7C,0x7E,0x16,0x0F,0x7D,0x7E,0x14,0x11,0x7D, 215 0x00,0x18,0x0C,0x7C,0x7F,0x17,0x0E,0x7C,0x7E,0x16,0x0F,0x7D,0x7E,0x14,0x11,0x7D,
@@ -201,7 +228,7 @@ static const UCHAR SiS_Part2CLVX_4[] = { /* PAL */
201 0xFF,0xFF 228 0xFF,0xFF
202}; 229};
203 230
204static const UCHAR SiS_Part2CLVX_5[] = { /* 750p */ 231static const unsigned char SiS_Part2CLVX_5[] = { /* 750p */
205 0x00,0x03, 232 0x00,0x03,
206 0x05,0x19,0x05,0x7D,0x03,0x19,0x06,0x7E,0x02,0x19,0x08,0x7D,0x01,0x18,0x0A,0x7D, 233 0x05,0x19,0x05,0x7D,0x03,0x19,0x06,0x7E,0x02,0x19,0x08,0x7D,0x01,0x18,0x0A,0x7D,
207 0x00,0x18,0x0C,0x7C,0x7F,0x17,0x0E,0x7C,0x7E,0x16,0x0F,0x7D,0x7E,0x14,0x11,0x7D, 234 0x00,0x18,0x0C,0x7C,0x7F,0x17,0x0E,0x7C,0x7E,0x16,0x0F,0x7D,0x7E,0x14,0x11,0x7D,
@@ -210,7 +237,7 @@ static const UCHAR SiS_Part2CLVX_5[] = { /* 750p */
210 0xFF,0xFF 237 0xFF,0xFF
211}; 238};
212 239
213static const UCHAR SiS_Part2CLVX_6[] = { /* 1080i */ 240static const unsigned char SiS_Part2CLVX_6[] = { /* 1080i */
214 0x00,0x04, 241 0x00,0x04,
215 0x04,0x1A,0x04,0x7E,0x02,0x1B,0x05,0x7E,0x01,0x1A,0x07,0x7E,0x00,0x1A,0x09,0x7D, 242 0x04,0x1A,0x04,0x7E,0x02,0x1B,0x05,0x7E,0x01,0x1A,0x07,0x7E,0x00,0x1A,0x09,0x7D,
216 0x7F,0x19,0x0B,0x7D,0x7E,0x18,0x0D,0x7D,0x7D,0x17,0x10,0x7C,0x7D,0x15,0x12,0x7C, 243 0x7F,0x19,0x0B,0x7D,0x7E,0x18,0x0D,0x7D,0x7D,0x17,0x10,0x7C,0x7D,0x15,0x12,0x7C,
@@ -221,7 +248,7 @@ static const UCHAR SiS_Part2CLVX_6[] = { /* 1080i */
221 248
222#ifdef SIS315H 249#ifdef SIS315H
223/* 661 et al LCD data structure (2.03.00) */ 250/* 661 et al LCD data structure (2.03.00) */
224static const UCHAR SiS_LCDStruct661[] = { 251static const unsigned char SiS_LCDStruct661[] = {
225 /* 1024x768 */ 252 /* 1024x768 */
226/* type|CR37| HDE | VDE | HT | VT | hss | hse */ 253/* type|CR37| HDE | VDE | HT | VT | hss | hse */
227 0x02,0xC0,0x00,0x04,0x00,0x03,0x40,0x05,0x26,0x03,0x10,0x00,0x88, 254 0x02,0xC0,0x00,0x04,0x00,0x03,0x40,0x05,0x26,0x03,0x10,0x00,0x88,
@@ -249,11 +276,20 @@ static const UCHAR SiS_LCDStruct661[] = {
249 /* 1680x1050 */ 276 /* 1680x1050 */
250 0x0D,0xE0,0x90,0x06,0x1A,0x04,0x6C,0x07,0x2A,0x04,0x1A,0x00,0x4C, 277 0x0D,0xE0,0x90,0x06,0x1A,0x04,0x6C,0x07,0x2A,0x04,0x1A,0x00,0x4C,
251 0x00,0x03,0x00,0x06,0x00,0x79,0xBE,0x44,0x00,0x00,0x00,0x00,0x06, 278 0x00,0x03,0x00,0x06,0x00,0x79,0xBE,0x44,0x00,0x00,0x00,0x00,0x06,
279 /* 1280x800_3 */
280 0x0C,0xE0,0x00,0x05,0x20,0x03,0xAA,0x05,0x2E,0x03,0x30,0x00,0x50,
281 0x00,0x04,0x00,0x03,0x00,0x47,0xA9,0x10,0x00,0x00,0x00,0x00,0x07,
282 /* 800x600 */
283 0x01,0xC0,0x20,0x03,0x58,0x02,0x20,0x04,0x74,0x02,0x2A,0x00,0x80,
284 0x00,0x06,0x00,0x04,0x00,0x28,0x63,0x4B,0x00,0x00,0x00,0x00,0x00,
285 /* 1280x854 */
286 0x08,0xE0,0x00,0x05,0x56,0x03,0x80,0x06,0x5d,0x03,0x10,0x00,0x70,
287 0x00,0x01,0x00,0x03,0x00,0x54,0x75,0x13,0x00,0x00,0x00,0x00,0x08
252}; 288};
253#endif 289#endif
254 290
255#ifdef SIS300 291#ifdef SIS300
256static UCHAR SiS300_TrumpionData[7][80] = { 292static unsigned char SiS300_TrumpionData[14][80] = {
257 { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x0D,0x00,0x0D,0x10,0x7F,0x00,0x80,0x02, 293 { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x0D,0x00,0x0D,0x10,0x7F,0x00,0x80,0x02,
258 0x20,0x03,0x0B,0x00,0x90,0x01,0xC1,0x01,0x60,0x0C,0x30,0x10,0x00,0x00,0x04,0x23, 294 0x20,0x03,0x0B,0x00,0x90,0x01,0xC1,0x01,0x60,0x0C,0x30,0x10,0x00,0x00,0x04,0x23,
259 0x00,0x00,0x03,0x28,0x03,0x10,0x05,0x08,0x40,0x10,0x00,0x10,0x04,0x23,0x00,0x23, 295 0x00,0x00,0x03,0x28,0x03,0x10,0x05,0x08,0x40,0x10,0x00,0x10,0x04,0x23,0x00,0x23,
@@ -288,119 +324,182 @@ static UCHAR SiS300_TrumpionData[7][80] = {
288 0x40,0x05,0x13,0x00,0x00,0x03,0x26,0x03,0x88,0x0C,0x30,0x90,0x00,0x00,0x04,0x23, 324 0x40,0x05,0x13,0x00,0x00,0x03,0x26,0x03,0x88,0x0C,0x30,0x90,0x00,0x00,0x04,0x23,
289 0x00,0x01,0x03,0x24,0x03,0x28,0x06,0x08,0x40,0x90,0x00,0x90,0x04,0x23,0x00,0x23, 325 0x00,0x01,0x03,0x24,0x03,0x28,0x06,0x08,0x40,0x90,0x00,0x90,0x04,0x23,0x00,0x23,
290 0x03,0x11,0x60,0x40,0x05,0xFF,0x0F,0xF4,0x18,0x01,0x00,0x08,0x01,0x00,0x08,0x01, 326 0x03,0x11,0x60,0x40,0x05,0xFF,0x0F,0xF4,0x18,0x01,0x00,0x08,0x01,0x00,0x08,0x01,
291 0x00,0x08,0x01,0x01,0x02,0xB0,0x00,0x00,0x02,0xBA,0xF0,0x5B,0x01,0xBE,0x01,0x00 } 327 0x00,0x08,0x01,0x01,0x02,0xB0,0x00,0x00,0x02,0xBA,0xF0,0x5B,0x01,0xBE,0x01,0x00 },
328 /* variant 2 */
329 { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x11,0x00,0x0D,0x10,0x7F,0x00,0x80,0x02,
330 0x20,0x03,0x15,0x00,0x90,0x01,0xC1,0x01,0x60,0x0C,0x30,0x18,0x00,0x00,0x04,0x23,
331 0x00,0x01,0x03,0x44,0x03,0x28,0x06,0x08,0x40,0x18,0x00,0x18,0x04,0x23,0x00,0x23,
332 0x03,0x11,0x60,0xA6,0x01,0xFF,0x03,0xFF,0x19,0x01,0x00,0x05,0x13,0x04,0x04,0x05,
333 0x04,0x0C,0x13,0x0A,0x02,0xB0,0x00,0x00,0x02,0xBA,0xF0,0x55,0x01,0xBE,0x01,0x00 },
334 { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x11,0x00,0x0D,0x10,0x7F,0x00,0x80,0x02,
335 0x20,0x03,0x15,0x00,0x90,0x01,0xC1,0x01,0x60,0x0C,0x30,0x18,0x00,0x00,0x04,0x23,
336 0x00,0x01,0x03,0x44,0x03,0x28,0x06,0x08,0x40,0x18,0x00,0x18,0x04,0x23,0x00,0x23,
337 0x03,0x11,0x60,0xA6,0x01,0xFF,0x03,0xFF,0x19,0x01,0x00,0x05,0x13,0x04,0x04,0x05,
338 0x04,0x0C,0x13,0x0A,0x02,0xB0,0x00,0x00,0x02,0xBA,0xF0,0x55,0x01,0xBE,0x01,0x00 },
339 { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x11,0x00,0x0D,0x10,0x8A,0x00,0xD8,0x02,
340 0x84,0x03,0x16,0x00,0x90,0x01,0xC1,0x01,0x60,0x0C,0x30,0x1C,0x00,0x20,0x04,0x23,
341 0x00,0x01,0x03,0x53,0x03,0x28,0x06,0x08,0x40,0x1C,0x00,0x16,0x04,0x23,0x00,0x23,
342 0x03,0x11,0x60,0xDA,0x01,0xFF,0x0F,0xF4,0x18,0x07,0x05,0x05,0x13,0x04,0x04,0x05,
343 0x01,0x0B,0x13,0x0A,0x02,0xB0,0x00,0x00,0x02,0xBA,0xF0,0x55,0x01,0xBE,0x01,0x00 },
344 { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x11,0x00,0x0D,0x10,0x72,0x00,0xD8,0x02,
345 0x84,0x03,0x16,0x00,0x90,0x01,0xC1,0x01,0x60,0x0C,0x30,0x1C,0x00,0x20,0x04,0x23,
346 0x00,0x01,0x03,0x53,0x03,0x28,0x06,0x08,0x40,0x1C,0x00,0x16,0x04,0x23,0x00,0x23,
347 0x03,0x11,0x60,0xDA,0x01,0xFF,0x0F,0xF4,0x18,0x07,0x05,0x05,0x13,0x04,0x04,0x05,
348 0x01,0x0B,0x13,0x0A,0x02,0xB0,0x00,0x00,0x02,0xBA,0xF0,0x55,0x01,0xBE,0x01,0x00 },
349 { 0x02,0x0A,0x02,0x00,0x04,0x01,0x00,0x03,0x11,0x00,0x0D,0x10,0x7F,0x00,0x80,0x02,
350 0x20,0x03,0x16,0x00,0xE0,0x01,0x0D,0x02,0x60,0x0C,0x30,0x98,0x00,0x00,0x04,0x23,
351 0x00,0x01,0x03,0x45,0x03,0x48,0x06,0x08,0x40,0x98,0x00,0x98,0x04,0x23,0x00,0x23,
352 0x03,0x11,0x60,0xF4,0x01,0xFF,0x0F,0xF4,0x18,0x01,0x00,0x05,0x01,0x00,0x05,0x05,
353 0x04,0x0C,0x08,0x05,0x02,0xB0,0x00,0x00,0x02,0xBA,0xEA,0x58,0x01,0xBE,0x01,0x00 },
354 { 0x02,0x0A,0x02,0x01,0x04,0x01,0x00,0x03,0x11,0x00,0x0D,0x10,0xBF,0x00,0x20,0x03,
355 0x20,0x04,0x0D,0x00,0x58,0x02,0x71,0x02,0x80,0x0C,0x30,0x9A,0x00,0xFA,0x03,0x1D,
356 0x00,0x01,0x03,0x22,0x03,0x28,0x06,0x08,0x40,0x98,0x00,0x98,0x04,0x1D,0x00,0x1D,
357 0x03,0x11,0x60,0x39,0x03,0x40,0x05,0xF4,0x18,0x07,0x02,0x06,0x04,0x01,0x06,0x0B,
358 0x02,0x0A,0x20,0x19,0x02,0xB0,0x00,0x00,0x02,0xBA,0xEA,0x58,0x01,0xBE,0x01,0x00 },
359 { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x11,0x00,0x0D,0x10,0xEF,0x00,0x00,0x04,
360 0x40,0x05,0x13,0x00,0x00,0x03,0x26,0x03,0x88,0x0C,0x30,0x90,0x00,0x00,0x04,0x23,
361 0x00,0x01,0x03,0x24,0x03,0x28,0x06,0x08,0x40,0x90,0x00,0x90,0x04,0x23,0x00,0x23,
362 0x03,0x11,0x60,0x40,0x05,0xFF,0x0F,0xF4,0x18,0x01,0x00,0x08,0x01,0x00,0x08,0x01,
363 0x00,0x08,0x01,0x01,0x02,0xB0,0x00,0x00,0x02,0xBA,0xEA,0x58,0x01,0xBE,0x01,0x00 }
292}; 364};
293#endif 365#endif
294 366
295void SiS_UnLockCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo); 367void SiS_UnLockCRT2(struct SiS_Private *SiS_Pr);
296void SiS_EnableCRT2(SiS_Private *SiS_Pr); 368#ifndef SIS_LINUX_KERNEL
297USHORT SiS_GetRatePtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, PSIS_HW_INFO HwInfo); 369void SiS_LockCRT2(struct SiS_Private *SiS_Pr);
298void SiS_WaitRetrace1(SiS_Private *SiS_Pr); 370#endif
299BOOLEAN SiS_IsDualEdge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo); 371void SiS_EnableCRT2(struct SiS_Private *SiS_Pr);
300BOOLEAN SiS_IsVAMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo); 372unsigned short SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex);
301void SiS_SetChrontelGPIO(SiS_Private *SiS_Pr, USHORT myvbinfo); 373void SiS_WaitRetrace1(struct SiS_Private *SiS_Pr);
302void SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT ModeNo, 374BOOLEAN SiS_IsDualEdge(struct SiS_Private *SiS_Pr);
303 USHORT ModeIdIndex, PSIS_HW_INFO HwInfo, 375BOOLEAN SiS_IsVAMode(struct SiS_Private *SiS_Pr);
304 int checkcrt2mode); 376void SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
305void SiS_SetYPbPr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo); 377 unsigned short ModeIdIndex, int checkcrt2mode);
306void SiS_SetTVMode(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, PSIS_HW_INFO HwInfo); 378void SiS_SetYPbPr(struct SiS_Private *SiS_Pr);
307void SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, PSIS_HW_INFO HwInfo); 379void SiS_SetTVMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
308USHORT SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, 380 unsigned short ModeIdIndex);
309 USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo); 381void SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
310USHORT SiS_GetResInfo(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex); 382 unsigned short ModeIdIndex);
311void SiS_DisableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo); 383unsigned short SiS_GetVCLK2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
312BOOLEAN SiS_SetCRT2Group(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo); 384 unsigned short RefreshRateTableIndex);
313void SiS_SiS30xBLOn(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo); 385unsigned short SiS_GetResInfo(struct SiS_Private *SiS_Pr,unsigned short ModeNo,unsigned short ModeIdIndex);
314void SiS_SiS30xBLOff(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo); 386void SiS_DisableBridge(struct SiS_Private *SiS_Pr);
387#ifndef SIS_LINUX_KERNEL
388void SiS_EnableBridge(struct SiS_Private *SiS_Pr);
389#endif
390BOOLEAN SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo);
391void SiS_SiS30xBLOn(struct SiS_Private *SiS_Pr);
392void SiS_SiS30xBLOff(struct SiS_Private *SiS_Pr);
315 393
316void SiS_SetCH700x(SiS_Private *SiS_Pr, USHORT tempax); 394void SiS_SetCH700x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val);
317USHORT SiS_GetCH700x(SiS_Private *SiS_Pr, USHORT tempax); 395unsigned short SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short tempax);
318void SiS_SetCH701x(SiS_Private *SiS_Pr, USHORT tempax); 396void SiS_SetCH701x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val);
319USHORT SiS_GetCH701x(SiS_Private *SiS_Pr, USHORT tempax); 397unsigned short SiS_GetCH701x(struct SiS_Private *SiS_Pr, unsigned short tempax);
320void SiS_SetCH70xxANDOR(SiS_Private *SiS_Pr, USHORT tempax,USHORT tempbh); 398#ifndef SIS_LINUX_KERNEL
399void SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val);
400unsigned short SiS_GetCH70xx(struct SiS_Private *SiS_Pr, unsigned short tempax);
401#endif
402void SiS_SetCH70xxANDOR(struct SiS_Private *SiS_Pr, unsigned short reg,
403 unsigned char orval,unsigned short andval);
321#ifdef SIS315H 404#ifdef SIS315H
322static void SiS_Chrontel701xOn(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo); 405static void SiS_Chrontel701xOn(struct SiS_Private *SiS_Pr);
323static void SiS_Chrontel701xOff(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo); 406static void SiS_Chrontel701xOff(struct SiS_Private *SiS_Pr);
324static void SiS_ChrontelInitTVVSync(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo); 407static void SiS_ChrontelInitTVVSync(struct SiS_Private *SiS_Pr);
325static void SiS_ChrontelDoSomething1(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo); 408static void SiS_ChrontelDoSomething1(struct SiS_Private *SiS_Pr);
326void SiS_Chrontel701xBLOn(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo); 409void SiS_Chrontel701xBLOn(struct SiS_Private *SiS_Pr);
327void SiS_Chrontel701xBLOff(SiS_Private *SiS_Pr); 410void SiS_Chrontel701xBLOff(struct SiS_Private *SiS_Pr);
328#endif /* 315 */ 411#endif /* 315 */
329 412
330#ifdef SIS300 413#ifdef SIS300
331#if 0 414static BOOLEAN SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr);
332static void SiS_SetTrumpReg(SiS_Private *SiS_Pr, USHORT tempbx); 415void SiS_SetChrontelGPIO(struct SiS_Private *SiS_Pr, unsigned short myvbinfo);
333static USHORT SiS_GetTrumpReg(SiS_Private *SiS_Pr, USHORT tempbx);
334#endif
335static BOOLEAN SiS_SetTrumpionBlock(SiS_Private *SiS_Pr, UCHAR *dataptr);
336#endif 416#endif
337 417
338void SiS_DDC2Delay(SiS_Private *SiS_Pr, USHORT delaytime); 418void SiS_DDC2Delay(struct SiS_Private *SiS_Pr, unsigned int delaytime);
339USHORT SiS_ReadDDC1Bit(SiS_Private *SiS_Pr); 419unsigned short SiS_ReadDDC1Bit(struct SiS_Private *SiS_Pr);
340USHORT SiS_HandleDDC(SiS_Private *SiS_Pr, ULONG VBFlags, int VGAEngine, 420unsigned short SiS_HandleDDC(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
341 USHORT adaptnum, USHORT DDCdatatype, UCHAR *buffer); 421 unsigned short adaptnum, unsigned short DDCdatatype,
342#ifdef LINUX_XF86 422 unsigned char *buffer, unsigned int VBFlags2);
343USHORT SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS);
344USHORT SiS_SenseVGA2DDC(SiS_Private *SiS_Pr, SISPtr pSiS);
345#endif
346 423
347static void SiS_SetSwitchDDC2(SiS_Private *SiS_Pr); 424#ifdef SIS_XORG_XF86
348static USHORT SiS_SetStart(SiS_Private *SiS_Pr); 425unsigned short SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags,
349static USHORT SiS_SetStop(SiS_Private *SiS_Pr); 426 int VGAEngine, unsigned short adaptnum, unsigned short DDCdatatype,
350static USHORT SiS_SetSCLKLow(SiS_Private *SiS_Pr); 427 BOOLEAN checkcr32, unsigned int VBFlags2);
351static USHORT SiS_SetSCLKHigh(SiS_Private *SiS_Pr); 428unsigned short SiS_ProbeDDC(struct SiS_Private *SiS_Pr);
352static USHORT SiS_ReadDDC2Data(SiS_Private *SiS_Pr, USHORT tempax); 429unsigned short SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype,
353static USHORT SiS_WriteDDC2Data(SiS_Private *SiS_Pr, USHORT tempax); 430 unsigned char *buffer);
354static USHORT SiS_CheckACK(SiS_Private *SiS_Pr); 431#else
355static USHORT SiS_InitDDCRegs(SiS_Private *SiS_Pr, ULONG VBFlags, int VGAEngine, 432static unsigned short SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags,
356 USHORT adaptnum, USHORT DDCdatatype, BOOLEAN checkcr32); 433 int VGAEngine, unsigned short adaptnum, unsigned short DDCdatatype,
357static USHORT SiS_WriteDABDDC(SiS_Private *SiS_Pr); 434 BOOLEAN checkcr32, unsigned int VBFlags2);
358static USHORT SiS_PrepareReadDDC(SiS_Private *SiS_Pr); 435static unsigned short SiS_ProbeDDC(struct SiS_Private *SiS_Pr);
359static USHORT SiS_PrepareDDC(SiS_Private *SiS_Pr); 436static unsigned short SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype,
360static void SiS_SendACK(SiS_Private *SiS_Pr, USHORT yesno); 437 unsigned char *buffer);
361static USHORT SiS_DoProbeDDC(SiS_Private *SiS_Pr); 438#endif
362static USHORT SiS_ProbeDDC(SiS_Private *SiS_Pr); 439static void SiS_SetSwitchDDC2(struct SiS_Private *SiS_Pr);
363static USHORT SiS_ReadDDC(SiS_Private *SiS_Pr, USHORT DDCdatatype, UCHAR *buffer); 440static unsigned short SiS_SetStart(struct SiS_Private *SiS_Pr);
441static unsigned short SiS_SetStop(struct SiS_Private *SiS_Pr);
442static unsigned short SiS_SetSCLKLow(struct SiS_Private *SiS_Pr);
443static unsigned short SiS_SetSCLKHigh(struct SiS_Private *SiS_Pr);
444static unsigned short SiS_ReadDDC2Data(struct SiS_Private *SiS_Pr);
445static unsigned short SiS_WriteDDC2Data(struct SiS_Private *SiS_Pr, unsigned short tempax);
446static unsigned short SiS_CheckACK(struct SiS_Private *SiS_Pr);
447static unsigned short SiS_WriteDABDDC(struct SiS_Private *SiS_Pr);
448static unsigned short SiS_PrepareReadDDC(struct SiS_Private *SiS_Pr);
449static unsigned short SiS_PrepareDDC(struct SiS_Private *SiS_Pr);
450static void SiS_SendACK(struct SiS_Private *SiS_Pr, unsigned short yesno);
451static unsigned short SiS_DoProbeDDC(struct SiS_Private *SiS_Pr);
364 452
453#ifdef SIS300
454static void SiS_OEM300Setting(struct SiS_Private *SiS_Pr,
455 unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefTabindex);
456static void SetOEMLCDData2(struct SiS_Private *SiS_Pr,
457 unsigned short ModeNo, unsigned short ModeIdIndex,unsigned short RefTableIndex);
458#endif
365#ifdef SIS315H 459#ifdef SIS315H
366static void SiS_OEM310Setting(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 460static void SiS_OEM310Setting(struct SiS_Private *SiS_Pr,
367 USHORT ModeNo,USHORT ModeIdIndex, USHORT RRTI); 461 unsigned short ModeNo,unsigned short ModeIdIndex, unsigned short RRTI);
368static void SiS_OEM661Setting(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 462static void SiS_OEM661Setting(struct SiS_Private *SiS_Pr,
369 USHORT ModeNo,USHORT ModeIdIndex, USHORT RRTI); 463 unsigned short ModeNo,unsigned short ModeIdIndex, unsigned short RRTI);
370static void SiS_FinalizeLCD(SiS_Private *, USHORT, USHORT, PSIS_HW_INFO); 464static void SiS_FinalizeLCD(struct SiS_Private *, unsigned short, unsigned short);
371#endif 465#endif
466
467extern void SiS_SetReg(SISIOADDRESS, unsigned short, unsigned short);
468extern void SiS_SetRegByte(SISIOADDRESS, unsigned short);
469extern void SiS_SetRegShort(SISIOADDRESS, unsigned short);
470extern void SiS_SetRegLong(SISIOADDRESS, unsigned int);
471extern unsigned char SiS_GetReg(SISIOADDRESS, unsigned short);
472extern unsigned char SiS_GetRegByte(SISIOADDRESS);
473extern unsigned short SiS_GetRegShort(SISIOADDRESS);
474extern unsigned int SiS_GetRegLong(SISIOADDRESS);
475extern void SiS_SetRegANDOR(SISIOADDRESS, unsigned short, unsigned short, unsigned short);
476extern void SiS_SetRegOR(SISIOADDRESS, unsigned short, unsigned short);
477extern void SiS_SetRegAND(SISIOADDRESS, unsigned short, unsigned short);
478extern void SiS_DisplayOff(struct SiS_Private *SiS_Pr);
479extern void SiS_DisplayOn(struct SiS_Private *SiS_Pr);
480extern BOOLEAN SiS_SearchModeID(struct SiS_Private *, unsigned short *, unsigned short *);
481extern unsigned short SiS_GetModeFlag(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
482 unsigned short ModeIdIndex);
483extern unsigned short SiS_GetModePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex);
484extern unsigned short SiS_GetColorDepth(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex);
485extern unsigned short SiS_GetOffset(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
486 unsigned short RefreshRateTableIndex);
487extern void SiS_LoadDAC(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
488 unsigned short ModeIdIndex);
489extern void SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
490 unsigned short ModeIdIndex);
491extern void SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth);
492extern unsigned short SiS_GetRefCRTVCLK(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide);
493extern unsigned short SiS_GetRefCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide);
372#ifdef SIS300 494#ifdef SIS300
373static void SiS_OEM300Setting(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 495extern void SiS_GetFIFOThresholdIndex300(struct SiS_Private *SiS_Pr, unsigned short *tempbx,
374 USHORT ModeNo, USHORT ModeIdIndex, USHORT RefTabindex); 496 unsigned short *tempcl);
375static void SetOEMLCDData2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, 497extern unsigned short SiS_GetFIFOThresholdB300(unsigned short tempbx, unsigned short tempcl);
376 USHORT ModeNo, USHORT ModeIdIndex,USHORT RefTableIndex); 498extern unsigned short SiS_GetLatencyFactor630(struct SiS_Private *SiS_Pr, unsigned short index);
499#ifdef SIS_LINUX_KERNEL
500extern unsigned int sisfb_read_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg);
501extern unsigned int sisfb_read_lpc_pci_dword(struct SiS_Private *SiS_Pr, int reg);
377#endif 502#endif
378
379extern void SiS_SetReg(SISIOADDRESS, USHORT, USHORT);
380extern void SiS_SetRegByte(SISIOADDRESS, USHORT);
381extern void SiS_SetRegShort(SISIOADDRESS, USHORT);
382extern void SiS_SetRegLong(SISIOADDRESS, ULONG);
383extern UCHAR SiS_GetReg(SISIOADDRESS, USHORT);
384extern UCHAR SiS_GetRegByte(SISIOADDRESS);
385extern USHORT SiS_GetRegShort(SISIOADDRESS);
386extern ULONG SiS_GetRegLong(SISIOADDRESS);
387extern void SiS_SetRegANDOR(SISIOADDRESS, USHORT, USHORT, USHORT);
388extern void SiS_SetRegOR(SISIOADDRESS, USHORT, USHORT);
389extern void SiS_SetRegAND(SISIOADDRESS, USHORT, USHORT);
390extern void SiS_DisplayOff(SiS_Private *SiS_Pr);
391extern void SiS_DisplayOn(SiS_Private *SiS_Pr);
392extern BOOLEAN SiS_SearchModeID(SiS_Private *, USHORT *, USHORT *);
393extern UCHAR SiS_GetModePtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex);
394extern USHORT SiS_GetColorDepth(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex);
395extern USHORT SiS_GetOffset(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
396 USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo);
397extern void SiS_LoadDAC(SiS_Private *SiS_Pr, PSIS_HW_INFO, USHORT ModeNo,
398 USHORT ModeIdIndex);
399extern void SiS_CalcLCDACRT1Timing(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex);
400#ifdef LINUX_XF86
401extern void SiS_MakeClockRegs(ScrnInfoPtr pScrn, int clock, UCHAR *p2b, UCHAR *p2c);
402extern int SiS_FindPanelFromDB(SISPtr pSiS, USHORT panelvendor, USHORT panelproduct,
403 int *maxx, int *maxy, int *prefx, int *prefy);
404#endif 503#endif
405 504
406#endif 505#endif
diff --git a/drivers/video/sis/initdef.h b/drivers/video/sis/initdef.h
index 55a82d6dc4..264b55a594 100644
--- a/drivers/video/sis/initdef.h
+++ b/drivers/video/sis/initdef.h
@@ -3,7 +3,7 @@
3/* 3/*
4 * Global definitions for init.c and init301.c 4 * Global definitions for init.c and init301.c
5 * 5 *
6 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria 6 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
7 * 7 *
8 * If distributed as part of the Linux kernel, the following license terms 8 * If distributed as part of the Linux kernel, the following license terms
9 * apply: 9 * apply:
@@ -53,19 +53,20 @@
53#ifndef _INITDEF_ 53#ifndef _INITDEF_
54#define _INITDEF_ 54#define _INITDEF_
55 55
56#define IS_SIS330 (HwInfo->jChipType == SIS_330) 56#define IS_SIS330 (SiS_Pr->ChipType == SIS_330)
57#define IS_SIS550 (HwInfo->jChipType == SIS_550) 57#define IS_SIS550 (SiS_Pr->ChipType == SIS_550)
58#define IS_SIS650 (HwInfo->jChipType == SIS_650) /* All versions, incl 651, M65x */ 58#define IS_SIS650 (SiS_Pr->ChipType == SIS_650) /* All versions, incl 651, M65x */
59#define IS_SIS740 (HwInfo->jChipType == SIS_740) 59#define IS_SIS740 (SiS_Pr->ChipType == SIS_740)
60#define IS_SIS651 (SiS_Pr->SiS_SysFlags & (SF_Is651 | SF_Is652)) 60#define IS_SIS651 (SiS_Pr->SiS_SysFlags & (SF_Is651 | SF_Is652))
61#define IS_SISM650 (SiS_Pr->SiS_SysFlags & (SF_IsM650 | SF_IsM652 | SF_IsM653)) 61#define IS_SISM650 (SiS_Pr->SiS_SysFlags & (SF_IsM650 | SF_IsM652 | SF_IsM653))
62#define IS_SIS65x (IS_SIS651 || IS_SISM650) /* Only special versions of 65x */ 62#define IS_SIS65x (IS_SIS651 || IS_SISM650) /* Only special versions of 65x */
63#define IS_SIS661 (HwInfo->jChipType == SIS_661) 63#define IS_SIS661 (SiS_Pr->ChipType == SIS_661)
64#define IS_SIS741 (HwInfo->jChipType == SIS_741) 64#define IS_SIS741 (SiS_Pr->ChipType == SIS_741)
65#define IS_SIS660 (HwInfo->jChipType == SIS_660) 65#define IS_SIS660 (SiS_Pr->ChipType == SIS_660)
66#define IS_SIS760 (HwInfo->jChipType == SIS_760) 66#define IS_SIS760 (SiS_Pr->ChipType == SIS_760)
67#define IS_SIS661741660760 (IS_SIS661 || IS_SIS741 || IS_SIS660 || IS_SIS760) 67#define IS_SIS761 (SiS_Pr->ChipType == SIS_761)
68#define IS_SIS650740 ((HwInfo->jChipType >= SIS_650) && (HwInfo->jChipType < SIS_330)) 68#define IS_SIS661741660760 (IS_SIS661 || IS_SIS741 || IS_SIS660 || IS_SIS760 || IS_SIS761)
69#define IS_SIS650740 ((SiS_Pr->ChipType >= SIS_650) && (SiS_Pr->ChipType < SIS_330))
69#define IS_SIS550650740 (IS_SIS550 || IS_SIS650740) 70#define IS_SIS550650740 (IS_SIS550 || IS_SIS650740)
70#define IS_SIS650740660 (IS_SIS650 || IS_SIS740 || IS_SIS661741660760) 71#define IS_SIS650740660 (IS_SIS650 || IS_SIS740 || IS_SIS661741660760)
71#define IS_SIS550650740660 (IS_SIS550 || IS_SIS650740660) 72#define IS_SIS550650740660 (IS_SIS550 || IS_SIS650740660)
@@ -73,24 +74,37 @@
73#define SISGETROMW(x) (ROMAddr[(x)] | (ROMAddr[(x)+1] << 8)) 74#define SISGETROMW(x) (ROMAddr[(x)] | (ROMAddr[(x)+1] << 8))
74 75
75/* SiS_VBType */ 76/* SiS_VBType */
76#define VB_SIS301 0x0001 77#define VB_SIS301 0x0001
77#define VB_SIS301B 0x0002 78#define VB_SIS301B 0x0002
78#define VB_SIS302B 0x0004 79#define VB_SIS302B 0x0004
79#define VB_SIS301LV 0x0008 80#define VB_SIS301LV 0x0008
80#define VB_SIS302LV 0x0010 81#define VB_SIS302LV 0x0010
81#define VB_SIS302ELV 0x0020 82#define VB_SIS302ELV 0x0020
82#define VB_SIS301C 0x0040 83#define VB_SIS301C 0x0040
84#define VB_SIS307T 0x0080
85#define VB_SIS307LV 0x0100
83#define VB_UMC 0x4000 86#define VB_UMC 0x4000
84#define VB_NoLCD 0x8000 87#define VB_NoLCD 0x8000
85#define VB_SIS301BLV302BLV (VB_SIS301B|VB_SIS301C|VB_SIS302B|VB_SIS301LV|VB_SIS302LV|VB_SIS302ELV) 88#define VB_SIS30xB (VB_SIS301B | VB_SIS301C | VB_SIS302B | VB_SIS307T)
86#define VB_SIS301B302B (VB_SIS301B|VB_SIS301C|VB_SIS302B) 89#define VB_SIS30xC (VB_SIS301C | VB_SIS307T)
87#define VB_SIS301LV302LV (VB_SIS301LV|VB_SIS302LV|VB_SIS302ELV) 90#define VB_SISTMDS (VB_SIS301 | VB_SIS301B | VB_SIS301C | VB_SIS302B | VB_SIS307T)
88#define VB_SISVB (VB_SIS301 | VB_SIS301BLV302BLV) 91#define VB_SISLVDS (VB_SIS301LV | VB_SIS302LV | VB_SIS302ELV | VB_SIS307LV)
89#define VB_SISTMDS (VB_SIS301 | VB_SIS301B302B) 92#define VB_SIS30xBLV (VB_SIS30xB | VB_SISLVDS)
90#define VB_SISLVDS VB_SIS301LV302LV 93#define VB_SIS30xCLV (VB_SIS30xC | VB_SIS302ELV | VB_SIS307LV)
91#define VB_SISLCDA (VB_SIS302B|VB_SIS301C|VB_SIS301LV|VB_SIS302LV|VB_SIS302ELV) 94#define VB_SISVB (VB_SIS301 | VB_SIS30xBLV)
92#define VB_SISYPBPR (VB_SIS301C|VB_SIS301LV|VB_SIS302LV|VB_SIS302ELV) 95#define VB_SISLCDA (VB_SIS302B | VB_SIS301C | VB_SIS307T | VB_SISLVDS)
93#define VB_SISHIVISION (VB_SIS301|VB_SIS301B|VB_SIS302B) 96#define VB_SISTMDSLCDA (VB_SIS301C | VB_SIS307T)
97#define VB_SISPART4SCALER (VB_SIS301C | VB_SIS307T | VB_SIS302ELV | VB_SIS307LV)
98#define VB_SISHIVISION (VB_SIS301 | VB_SIS301B | VB_SIS302B)
99#define VB_SISYPBPR (VB_SIS301C | VB_SIS307T | VB_SIS301LV | VB_SIS302LV | VB_SIS302ELV | VB_SIS307LV)
100#define VB_SISTAP4SCALER (VB_SIS301C | VB_SIS307T | VB_SIS302ELV | VB_SIS307LV)
101#define VB_SISPART4OVERFLOW (VB_SIS301C | VB_SIS307T | VB_SIS302LV | VB_SIS302ELV | VB_SIS307LV)
102#define VB_SISPWD (VB_SIS301C | VB_SIS307T | VB_SISLVDS)
103#define VB_SISEMI (VB_SIS302LV | VB_SIS302ELV | VB_SIS307LV)
104#define VB_SISPOWER (VB_SIS301C | VB_SIS307T | VB_SIS302LV | VB_SIS302ELV | VB_SIS307LV)
105#define VB_SISDUALLINK (VB_SIS302LV | VB_SIS302ELV | VB_SIS307T | VB_SIS307LV)
106#define VB_SISVGA2 VB_SISTMDS
107#define VB_SISRAMDAC202 (VB_SIS301C | VB_SIS307T)
94 108
95/* VBInfo */ 109/* VBInfo */
96#define SetSimuScanMode 0x0001 /* CR 30 */ 110#define SetSimuScanMode 0x0001 /* CR 30 */
@@ -160,6 +174,7 @@
160#define SupportRAMDAC2_202 0x0400 /* C (<= 202Mhz) */ 174#define SupportRAMDAC2_202 0x0400 /* C (<= 202Mhz) */
161#define InterlaceMode 0x0080 175#define InterlaceMode 0x0080
162#define SyncPP 0x0000 176#define SyncPP 0x0000
177#define HaveWideTiming 0x2000 /* Have specific wide- and non-wide timing */
163#define SyncPN 0x4000 178#define SyncPN 0x4000
164#define SyncNP 0x8000 179#define SyncNP 0x8000
165#define SyncNN 0xc000 180#define SyncNN 0xc000
@@ -188,6 +203,7 @@
188#define TVSetTVSimuMode 0x0200 /* new 0x200, prev. 0x800 */ 203#define TVSetTVSimuMode 0x0200 /* new 0x200, prev. 0x800 */
189#define TVRPLLDIV2XO 0x0400 /* prev 0x1000 */ 204#define TVRPLLDIV2XO 0x0400 /* prev 0x1000 */
190#define TVSetNTSC1024 0x0800 /* new 0x100, prev. 0x2000 */ 205#define TVSetNTSC1024 0x0800 /* new 0x100, prev. 0x2000 */
206#define TVSet525p1024 0x1000 /* TW */
191#define TVAspect43 0x2000 207#define TVAspect43 0x2000
192#define TVAspect169 0x4000 208#define TVAspect169 0x4000
193#define TVAspect43LB 0x8000 209#define TVAspect43LB 0x8000
@@ -208,7 +224,8 @@
208#define SF_IsM661 0x0020 224#define SF_IsM661 0x0020
209#define SF_IsM741 0x0040 225#define SF_IsM741 0x0040
210#define SF_IsM760 0x0080 226#define SF_IsM760 0x0080
211#define SF_760LFB 0x8000 /* 760: We have LFB */ 227#define SF_760UMA 0x4000 /* 76x: We have UMA */
228#define SF_760LFB 0x8000 /* 76x: We have LFB */
212 229
213/* CR32 (Newer 630, and 315 series) 230/* CR32 (Newer 630, and 315 series)
214 231
@@ -228,25 +245,19 @@
228#define TVOverScanShift 4 245#define TVOverScanShift 4
229 246
230/* CR35 (661 series only) 247/* CR35 (661 series only)
231
232 [0] 1 = PAL, 0 = NTSC 248 [0] 1 = PAL, 0 = NTSC
233 [1] 1 = NTSC-J (if D0 = 0) 249 [1] 1 = NTSC-J (if D0 = 0)
234 [2] 1 = PALM (if D0 = 1) 250 [2] 1 = PALM (if D0 = 1)
235 [3] 1 = PALN (if D0 = 1) 251 [3] 1 = PALN (if D0 = 1)
236 [4] 1 = Overscan (Chrontel only) 252 [4] 1 = Overscan (Chrontel only)
237 [7:5] (only if D2 in CR38 is set) 253 [7:5] (only if D2 in CR38 is set)
238 000 525i 254 000 525i
239 001 525p 255 001 525p
240 010 750p 256 010 750p
241 011 1080i (or HiVision on 301, 301B) 257 011 1080i (or HiVision on 301, 301B)
242
243 These bits are being translated to TVMode flag.
244
245*/ 258*/
246 259
247/* 260/* CR37
248 CR37
249
250 [0] Set 24/18 bit (0/1) RGB to LVDS/TMDS transmitter (set by BIOS) 261 [0] Set 24/18 bit (0/1) RGB to LVDS/TMDS transmitter (set by BIOS)
251 [3:1] External chip 262 [3:1] External chip
252 300 series: 263 300 series:
@@ -260,7 +271,7 @@
260 010 LVDS 271 010 LVDS
261 011 LVDS + Chrontel 7019 272 011 LVDS + Chrontel 7019
262 660 series [2:1] only: 273 660 series [2:1] only:
263 reserved (now in CR38) 274 reserved (chip type now in CR38)
264 All other combinations reserved 275 All other combinations reserved
265 [3] 661 only: Pass 1:1 data 276 [3] 661 only: Pass 1:1 data
266 [4] LVDS: 0: Panel Link expands / 1: Panel Link does not expand 277 [4] LVDS: 0: Panel Link expands / 1: Panel Link does not expand
@@ -320,6 +331,7 @@
320#define Enable302LV_DualLink 0x04 /* 302LV only; enable dual link */ 331#define Enable302LV_DualLink 0x04 /* 302LV only; enable dual link */
321 332
322/* CR39 (661 and later) 333/* CR39 (661 and later)
334 D[7] LVDS (SiS or third party)
323 D[1:0] YPbPr Aspect Ratio 335 D[1:0] YPbPr Aspect Ratio
324 00 4:3 letterbox 336 00 4:3 letterbox
325 01 4:3 337 01 4:3
@@ -341,7 +353,7 @@
341 0101 Set Contrast event 353 0101 Set Contrast event
342 0110 Set Mute event 354 0110 Set Mute event
343 0111 Set Volume Up/Down event 355 0111 Set Volume Up/Down event
344 [4] Enable Backlight Control by BIOS/driver 356 [4] Enable Backlight Control by BIOS/driver
345 (set by driver; set means that the BIOS should 357 (set by driver; set means that the BIOS should
346 not touch the backlight registers because eg. 358 not touch the backlight registers because eg.
347 the driver already switched off the backlight) 359 the driver already switched off the backlight)
@@ -350,6 +362,26 @@
350 [7] TV UnderScan/OverScan (set by BIOS) 362 [7] TV UnderScan/OverScan (set by BIOS)
351*/ 363*/
352 364
365/* CR7C - 661 and later
366 [7] DualEdge enabled (or: to be enabled)
367 [6] CRT2 = TV/LCD/VGA enabled (or: to be enabled)
368 [5] Init done (set at end of SiS_Init)
369 {4] LVDS LCD capabilities
370 [3] LVDS LCD capabilities
371 [2] LVDS LCD capabilities (PWD)
372 [1] LVDS LCD capabilities (PWD)
373 [0] LVDS=1, TMDS=0 (SiS or third party)
374*/
375
376/* CR7E - 661 and later
377 VBType:
378 [7] LVDS (third party)
379 [3] 301C
380 [2] 302LV
381 [1] 301LV
382 [0] 301B
383*/
384
353/* LCDResInfo */ 385/* LCDResInfo */
354#define Panel300_800x600 0x01 /* CR36 */ 386#define Panel300_800x600 0x01 /* CR36 */
355#define Panel300_1024x768 0x02 387#define Panel300_1024x768 0x02
@@ -359,7 +391,6 @@
359#define Panel300_1024x600 0x06 391#define Panel300_1024x600 0x06
360#define Panel300_1152x768 0x07 392#define Panel300_1152x768 0x07
361#define Panel300_1280x768 0x0a 393#define Panel300_1280x768 0x0a
362#define Panel300_320x480 0x0e /* fstn - This is fake, can be any */
363#define Panel300_Custom 0x0f 394#define Panel300_Custom 0x0f
364#define Panel300_Barco1366 0x10 395#define Panel300_Barco1366 0x10
365 396
@@ -374,9 +405,9 @@
374#define Panel310_1400x1050 0x09 405#define Panel310_1400x1050 0x09
375#define Panel310_1280x768 0x0a 406#define Panel310_1280x768 0x0a
376#define Panel310_1600x1200 0x0b 407#define Panel310_1600x1200 0x0b
377#define Panel310_640x480_2 0x0c 408#define Panel310_320x240_2 0x0c /* xSTN */
378#define Panel310_640x480_3 0x0d 409#define Panel310_320x240_3 0x0d /* xSTN */
379#define Panel310_320x480 0x0e /* fstn - TW: This is fake, can be any */ 410#define Panel310_320x240_1 0x0e /* xSTN - This is fake, can be any */
380#define Panel310_Custom 0x0f 411#define Panel310_Custom 0x0f
381 412
382#define Panel661_800x600 0x01 413#define Panel661_800x600 0x01
@@ -386,7 +417,7 @@
386#define Panel661_1024x600 0x05 417#define Panel661_1024x600 0x05
387#define Panel661_1152x864 0x06 418#define Panel661_1152x864 0x06
388#define Panel661_1280x960 0x07 419#define Panel661_1280x960 0x07
389#define Panel661_1152x768 0x08 420#define Panel661_1280x854 0x08
390#define Panel661_1400x1050 0x09 421#define Panel661_1400x1050 0x09
391#define Panel661_1280x768 0x0a 422#define Panel661_1280x768 0x0a
392#define Panel661_1600x1200 0x0b 423#define Panel661_1600x1200 0x0b
@@ -410,14 +441,16 @@
410#define Panel_1680x1050 0x0d /* 661etc */ 441#define Panel_1680x1050 0x0d /* 661etc */
411#define Panel_1280x720 0x0e /* 661etc */ 442#define Panel_1280x720 0x0e /* 661etc */
412#define Panel_Custom 0x0f /* MUST BE 0x0f (for DVI DDC detection) */ 443#define Panel_Custom 0x0f /* MUST BE 0x0f (for DVI DDC detection) */
413#define Panel_320x480 0x10 /* SiS 550 fstn - TW: This is fake, can be any */ 444#define Panel_320x240_1 0x10 /* SiS 550 xSTN */
414#define Panel_Barco1366 0x11 445#define Panel_Barco1366 0x11
415#define Panel_848x480 0x12 446#define Panel_848x480 0x12
416#define Panel_640x480_2 0x13 /* SiS 550 */ 447#define Panel_320x240_2 0x13 /* SiS 550 xSTN */
417#define Panel_640x480_3 0x14 /* SiS 550 */ 448#define Panel_320x240_3 0x14 /* SiS 550 xSTN */
418#define Panel_1280x768_2 0x15 /* 30xLV */ 449#define Panel_1280x768_2 0x15 /* 30xLV */
419#define Panel_1280x768_3 0x16 /* (unused) */ 450#define Panel_1280x768_3 0x16 /* (unused) */
420#define Panel_1280x800_2 0x17 /* 30xLV */ 451#define Panel_1280x800_2 0x17 /* 30xLV */
452#define Panel_856x480 0x18
453#define Panel_1280x854 0x19 /* 661etc */
421 454
422/* Index in ModeResInfo table */ 455/* Index in ModeResInfo table */
423#define SIS_RI_320x200 0 456#define SIS_RI_320x200 0
@@ -454,6 +487,7 @@
454#define SIS_RI_1920x1080 31 487#define SIS_RI_1920x1080 31
455#define SIS_RI_960x540 32 488#define SIS_RI_960x540 32
456#define SIS_RI_960x600 33 489#define SIS_RI_960x600 33
490#define SIS_RI_1280x854 34
457 491
458/* CR5F */ 492/* CR5F */
459#define IsM650 0x80 493#define IsM650 0x80
@@ -482,16 +516,18 @@
482#define VCLK100_300 0x43 /* Index in VCLKData table (300) */ 516#define VCLK100_300 0x43 /* Index in VCLKData table (300) */
483#define VCLK34_300 0x3d /* Index in VCLKData table (300) */ 517#define VCLK34_300 0x3d /* Index in VCLKData table (300) */
484#define VCLK_CUSTOM_300 0x47 518#define VCLK_CUSTOM_300 0x47
485#define VCLK65_315 0x0b /* Index in (VB)VCLKData table (315) */ 519
486#define VCLK108_2_315 0x19 /* Index in (VB)VCLKData table (315) */ 520#define VCLK65_315 0x0b /* Indices in (VB)VCLKData table (315) */
487#define VCLK81_315 0x5b /* Index in (VB)VCLKData table (315) */ 521#define VCLK108_2_315 0x19
488#define VCLK162_315 0x5e /* Index in (VB)VCLKData table (315) */ 522#define VCLK81_315 0x5b
489#define VCLK108_3_315 0x45 /* Index in VBVCLKData table (315) */ 523#define VCLK162_315 0x5e
490#define VCLK100_315 0x46 /* Index in VBVCLKData table (315) */ 524#define VCLK108_3_315 0x45
525#define VCLK100_315 0x46
491#define VCLK34_315 0x55 526#define VCLK34_315 0x55
492#define VCLK68_315 0x0d 527#define VCLK68_315 0x0d
493#define VCLK_1280x800_315_2 0x5c /* Index in VBVCLKData table (315) */ 528#define VCLK_1280x800_315_2 0x5c
494#define VCLK121_315 0x5d /* Index in VBVCLKData table (315) */ 529#define VCLK121_315 0x5d
530#define VCLK130_315 0x72
495#define VCLK_1280x720 0x5f 531#define VCLK_1280x720 0x5f
496#define VCLK_1280x768_2 0x60 532#define VCLK_1280x768_2 0x60
497#define VCLK_1280x768_3 0x61 /* (unused?) */ 533#define VCLK_1280x768_3 0x61 /* (unused?) */
@@ -507,6 +543,7 @@
507#define VCLK_1152x864 0x64 543#define VCLK_1152x864 0x64
508#define VCLK_1360x768 0x58 544#define VCLK_1360x768 0x58
509#define VCLK_1280x800_315 0x6c 545#define VCLK_1280x800_315 0x6c
546#define VCLK_1280x854 0x76
510 547
511#define TVCLKBASE_300 0x21 /* Indices on TV clocks in VCLKData table (300) */ 548#define TVCLKBASE_300 0x21 /* Indices on TV clocks in VCLKData table (300) */
512#define TVCLKBASE_315 0x3a /* Indices on TV clocks in (VB)VCLKData table (315) */ 549#define TVCLKBASE_315 0x3a /* Indices on TV clocks in (VB)VCLKData table (315) */
diff --git a/drivers/video/sis/initextlfb.c b/drivers/video/sis/initextlfb.c
new file mode 100644
index 0000000000..cc856d9090
--- /dev/null
+++ b/drivers/video/sis/initextlfb.c
@@ -0,0 +1,238 @@
1/*
2 * SiS 300/540/630[S]/730[S]
3 * SiS 315[E|PRO]/550/[M]65x/[M]66x[F|M|G]X/[M]74x[GX]/330/[M]76x[GX]
4 * XGI V3XT/V5/V8, Z7
5 * frame buffer driver for Linux kernels >= 2.4.14 and >=2.6.3
6 *
7 * Linux kernel specific extensions to init.c/init301.c
8 *
9 * Copyright (C) 2001-2005 Thomas Winischhofer, Vienna, Austria.
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 named License,
14 * or any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
24 *
25 * Author: Thomas Winischhofer <thomas@winischhofer.net>
26 */
27
28#include "osdef.h"
29#include "initdef.h"
30#include "vgatypes.h"
31#include "vstruct.h"
32
33#include <linux/config.h>
34#include <linux/version.h>
35#include <linux/types.h>
36#include <linux/fb.h>
37
38#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
39int sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr,
40 unsigned char modeno, unsigned char rateindex);
41int sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno,
42 unsigned char rateindex, struct fb_var_screeninfo *var);
43#endif
44BOOLEAN sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno,
45 int *htotal, int *vtotal, unsigned char rateindex);
46
47extern BOOLEAN SiSInitPtr(struct SiS_Private *SiS_Pr);
48extern BOOLEAN SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo,
49 unsigned short *ModeIdIndex);
50extern void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata,
51 int xres, int yres, struct fb_var_screeninfo *var, BOOLEAN writeres);
52
53#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
54int
55sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr, unsigned char modeno,
56 unsigned char rateindex)
57{
58 unsigned short ModeNo = modeno;
59 unsigned short ModeIdIndex = 0, ClockIndex = 0;
60 unsigned short RRTI = 0;
61 int Clock;
62
63 if(!SiSInitPtr(SiS_Pr)) return 65000;
64
65 if(rateindex > 0) rateindex--;
66
67#ifdef SIS315H
68 switch(ModeNo) {
69 case 0x5a: ModeNo = 0x50; break;
70 case 0x5b: ModeNo = 0x56;
71 }
72#endif
73
74 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) {;
75 printk(KERN_ERR "Could not find mode %x\n", ModeNo);
76 return 65000;
77 }
78
79 RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
80
81 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & HaveWideTiming) {
82 if(SiS_Pr->SiS_UseWide == 1) {
83 /* Wide screen: Ignore rateindex */
84 ClockIndex = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRTVCLK_WIDE;
85 } else {
86 RRTI += rateindex;
87 ClockIndex = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRTVCLK_NORM;
88 }
89 } else {
90 RRTI += rateindex;
91 ClockIndex = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRTVCLK;
92 }
93
94 Clock = SiS_Pr->SiS_VCLKData[ClockIndex].CLOCK * 1000;
95
96 return Clock;
97}
98
99int
100sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno,
101 unsigned char rateindex, struct fb_var_screeninfo *var)
102{
103 unsigned short ModeNo = modeno;
104 unsigned short ModeIdIndex = 0, index = 0, RRTI = 0;
105 int j;
106
107 if(!SiSInitPtr(SiS_Pr)) return 0;
108
109 if(rateindex > 0) rateindex--;
110
111#ifdef SIS315H
112 switch(ModeNo) {
113 case 0x5a: ModeNo = 0x50; break;
114 case 0x5b: ModeNo = 0x56;
115 }
116#endif
117
118 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return 0;
119
120 RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
121 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & HaveWideTiming) {
122 if(SiS_Pr->SiS_UseWide == 1) {
123 /* Wide screen: Ignore rateindex */
124 index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC_WIDE;
125 } else {
126 RRTI += rateindex;
127 index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC_NORM;
128 }
129 } else {
130 RRTI += rateindex;
131 index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC;
132 }
133
134 SiS_Generic_ConvertCRData(SiS_Pr,
135 (unsigned char *)&SiS_Pr->SiS_CRT1Table[index].CR[0],
136 SiS_Pr->SiS_RefIndex[RRTI].XRes,
137 SiS_Pr->SiS_RefIndex[RRTI].YRes,
138 var, FALSE);
139
140 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & 0x8000)
141 var->sync &= ~FB_SYNC_VERT_HIGH_ACT;
142 else
143 var->sync |= FB_SYNC_VERT_HIGH_ACT;
144
145 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & 0x4000)
146 var->sync &= ~FB_SYNC_HOR_HIGH_ACT;
147 else
148 var->sync |= FB_SYNC_HOR_HIGH_ACT;
149
150 var->vmode = FB_VMODE_NONINTERLACED;
151 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & 0x0080)
152 var->vmode = FB_VMODE_INTERLACED;
153 else {
154 j = 0;
155 while(SiS_Pr->SiS_EModeIDTable[j].Ext_ModeID != 0xff) {
156 if(SiS_Pr->SiS_EModeIDTable[j].Ext_ModeID ==
157 SiS_Pr->SiS_RefIndex[RRTI].ModeID) {
158 if(SiS_Pr->SiS_EModeIDTable[j].Ext_ModeFlag & DoubleScanMode) {
159 var->vmode = FB_VMODE_DOUBLE;
160 }
161 break;
162 }
163 j++;
164 }
165 }
166
167 if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
168#if 0 /* Do this? */
169 var->upper_margin <<= 1;
170 var->lower_margin <<= 1;
171 var->vsync_len <<= 1;
172#endif
173 } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {
174 var->upper_margin >>= 1;
175 var->lower_margin >>= 1;
176 var->vsync_len >>= 1;
177 }
178
179 return 1;
180}
181#endif /* Linux >= 2.5 */
182
183BOOLEAN
184sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, int *htotal,
185 int *vtotal, unsigned char rateindex)
186{
187 unsigned short ModeNo = modeno;
188 unsigned short ModeIdIndex = 0, CRT1Index = 0;
189 unsigned short RRTI = 0;
190 unsigned char sr_data, cr_data, cr_data2;
191
192 if(!SiSInitPtr(SiS_Pr)) return FALSE;
193
194 if(rateindex > 0) rateindex--;
195
196#ifdef SIS315H
197 switch(ModeNo) {
198 case 0x5a: ModeNo = 0x50; break;
199 case 0x5b: ModeNo = 0x56;
200 }
201#endif
202
203 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return FALSE;
204
205 RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
206 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & HaveWideTiming) {
207 if(SiS_Pr->SiS_UseWide == 1) {
208 /* Wide screen: Ignore rateindex */
209 CRT1Index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC_WIDE;
210 } else {
211 RRTI += rateindex;
212 CRT1Index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC_NORM;
213 }
214 } else {
215 RRTI += rateindex;
216 CRT1Index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC;
217 }
218
219 sr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14];
220 cr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[0];
221 *htotal = (((cr_data & 0xff) | ((unsigned short) (sr_data & 0x03) << 8)) + 5) * 8;
222
223 sr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13];
224 cr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[6];
225 cr_data2 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[7];
226 *vtotal = ((cr_data & 0xFF) |
227 ((unsigned short)(cr_data2 & 0x01) << 8) |
228 ((unsigned short)(cr_data2 & 0x20) << 4) |
229 ((unsigned short)(sr_data & 0x01) << 10)) + 2;
230
231 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & InterlaceMode)
232 *vtotal *= 2;
233
234 return TRUE;
235}
236
237
238
diff --git a/drivers/video/sis/oem300.h b/drivers/video/sis/oem300.h
index b1358b750f..b73f268401 100644
--- a/drivers/video/sis/oem300.h
+++ b/drivers/video/sis/oem300.h
@@ -3,7 +3,7 @@
3/* 3/*
4 * OEM Data for 300 series 4 * OEM Data for 300 series
5 * 5 *
6 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria 6 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
7 * 7 *
8 * If distributed as part of the Linux kernel, the following license terms 8 * If distributed as part of the Linux kernel, the following license terms
9 * apply: 9 * apply:
@@ -50,7 +50,7 @@
50 * 50 *
51 */ 51 */
52 52
53static const UCHAR SiS300_OEMTVDelay301[8][4] = 53static const unsigned char SiS300_OEMTVDelay301[8][4] =
54{ 54{
55 {0x08,0x08,0x08,0x08}, 55 {0x08,0x08,0x08,0x08},
56 {0x08,0x08,0x08,0x08}, 56 {0x08,0x08,0x08,0x08},
@@ -62,7 +62,7 @@ static const UCHAR SiS300_OEMTVDelay301[8][4] =
62 {0x20,0x20,0x20,0x20} 62 {0x20,0x20,0x20,0x20}
63}; 63};
64 64
65static const UCHAR SiS300_OEMTVDelayLVDS[8][4] = 65static const unsigned char SiS300_OEMTVDelayLVDS[8][4] =
66{ 66{
67 {0x20,0x20,0x20,0x20}, 67 {0x20,0x20,0x20,0x20},
68 {0x20,0x20,0x20,0x20}, 68 {0x20,0x20,0x20,0x20},
@@ -74,7 +74,7 @@ static const UCHAR SiS300_OEMTVDelayLVDS[8][4] =
74 {0x20,0x20,0x20,0x20} 74 {0x20,0x20,0x20,0x20}
75}; 75};
76 76
77static const UCHAR SiS300_OEMTVFlicker[8][4] = 77static const unsigned char SiS300_OEMTVFlicker[8][4] =
78{ 78{
79 {0x00,0x00,0x00,0x00}, 79 {0x00,0x00,0x00,0x00},
80 {0x00,0x00,0x00,0x00}, 80 {0x00,0x00,0x00,0x00},
@@ -86,25 +86,7 @@ static const UCHAR SiS300_OEMTVFlicker[8][4] =
86 {0x00,0x00,0x00,0x00} 86 {0x00,0x00,0x00,0x00}
87}; 87};
88 88
89#if 0 /* TW: Not used */ 89static const unsigned char SiS300_OEMLCDDelay2[64][4] = /* for 301/301b/302b/301LV/302LV */
90static const UCHAR SiS300_OEMLCDDelay1[12][4]={
91 {0x2c,0x2c,0x2c,0x2c},
92 {0x20,0x20,0x20,0x20},
93 {0x20,0x20,0x20,0x20},
94 {0x2c,0x2c,0x2c,0x2c},
95 {0x2c,0x2c,0x2c,0x2c},
96 {0x20,0x20,0x20,0x20},
97 {0x20,0x20,0x20,0x20},
98 {0x24,0x24,0x24,0x24},
99 {0x24,0x24,0x24,0x24},
100 {0x20,0x20,0x20,0x20},
101 {0x20,0x20,0x20,0x20},
102 {0x24,0x24,0x24,0x24}
103};
104#endif
105
106/* From 630/301B BIOS */
107static const UCHAR SiS300_OEMLCDDelay2[64][4] = /* for 301/301b/302b/301LV/302LV */
108{ 90{
109 {0x20,0x20,0x20,0x20}, 91 {0x20,0x20,0x20,0x20},
110 {0x20,0x20,0x20,0x20}, 92 {0x20,0x20,0x20,0x20},
@@ -172,8 +154,7 @@ static const UCHAR SiS300_OEMLCDDelay2[64][4] = /* for 301/301b/302b/301LV/302
172 {0x20,0x20,0x20,0x20} 154 {0x20,0x20,0x20,0x20}
173}; 155};
174 156
175/* From 300/301LV BIOS */ 157static const unsigned char SiS300_OEMLCDDelay4[12][4] =
176static const UCHAR SiS300_OEMLCDDelay4[12][4] =
177{ 158{
178 {0x2c,0x2c,0x2c,0x2c}, 159 {0x2c,0x2c,0x2c,0x2c},
179 {0x20,0x20,0x20,0x20}, 160 {0x20,0x20,0x20,0x20},
@@ -189,8 +170,7 @@ static const UCHAR SiS300_OEMLCDDelay4[12][4] =
189 {0x24,0x24,0x24,0x24} 170 {0x24,0x24,0x24,0x24}
190}; 171};
191 172
192/* From 300/301LV BIOS */ 173static const unsigned char SiS300_OEMLCDDelay5[32][4] =
193static const UCHAR SiS300_OEMLCDDelay5[32][4] =
194{ 174{
195 {0x20,0x20,0x20,0x20}, 175 {0x20,0x20,0x20,0x20},
196 {0x20,0x20,0x20,0x20}, 176 {0x20,0x20,0x20,0x20},
@@ -226,8 +206,8 @@ static const UCHAR SiS300_OEMLCDDelay5[32][4] =
226 {0x20,0x20,0x20,0x20}, 206 {0x20,0x20,0x20,0x20},
227}; 207};
228 208
229/* Added for LVDS */ 209static const unsigned char SiS300_OEMLCDDelay3[64][4] = /* For LVDS */
230static const UCHAR SiS300_OEMLCDDelay3[64][4] = { /* For LVDS */ 210{
231 {0x20,0x20,0x20,0x20}, 211 {0x20,0x20,0x20,0x20},
232 {0x20,0x20,0x20,0x20}, 212 {0x20,0x20,0x20,0x20},
233 {0x20,0x20,0x20,0x20}, 213 {0x20,0x20,0x20,0x20},
@@ -294,7 +274,7 @@ static const UCHAR SiS300_OEMLCDDelay3[64][4] = { /* For LVDS */
294 {0x20,0x20,0x20,0x20} 274 {0x20,0x20,0x20,0x20}
295}; 275};
296 276
297static const UCHAR SiS300_Phase1[8][5][4] = 277static const unsigned char SiS300_Phase1[8][5][4] =
298{ 278{
299 { 279 {
300 {0x21,0xed,0x00,0x08}, 280 {0x21,0xed,0x00,0x08},
@@ -354,11 +334,10 @@ static const UCHAR SiS300_Phase1[8][5][4] =
354 } 334 }
355}; 335};
356 336
357 337static const unsigned char SiS300_Phase2[8][5][4] =
358static const UCHAR SiS300_Phase2[8][5][4] =
359{ 338{
360 { 339 {
361 {0x21,0xed,0x00,0x08}, 340 {0x21,0xed,0x00,0x08},
362 {0x21,0xed,0x8a,0x08}, 341 {0x21,0xed,0x8a,0x08},
363 {0x21,0xed,0x8a,0x08}, 342 {0x21,0xed,0x8a,0x08},
364 {0x21,0xed,0x8a,0x08}, 343 {0x21,0xed,0x8a,0x08},
@@ -372,42 +351,42 @@ static const UCHAR SiS300_Phase2[8][5][4] =
372 {0x2a,0x05,0xd3,0x00} 351 {0x2a,0x05,0xd3,0x00}
373 }, 352 },
374 { 353 {
375 {0x2a,0x05,0xd3,0x00}, 354 {0x2a,0x05,0xd3,0x00},
376 {0x2a,0x05,0xd3,0x00}, 355 {0x2a,0x05,0xd3,0x00},
377 {0x2a,0x05,0xd3,0x00}, 356 {0x2a,0x05,0xd3,0x00},
378 {0x2a,0x05,0xd3,0x00}, 357 {0x2a,0x05,0xd3,0x00},
379 {0x2a,0x05,0xd3,0x00} 358 {0x2a,0x05,0xd3,0x00}
380 }, 359 },
381 { 360 {
382 {0x2a,0x05,0xd3,0x00}, 361 {0x2a,0x05,0xd3,0x00},
383 {0x2a,0x05,0xd3,0x00}, 362 {0x2a,0x05,0xd3,0x00},
384 {0x2a,0x05,0xd3,0x00}, 363 {0x2a,0x05,0xd3,0x00},
385 {0x2a,0x05,0xd3,0x00}, 364 {0x2a,0x05,0xd3,0x00},
386 {0x2a,0x05,0xd3,0x00} 365 {0x2a,0x05,0xd3,0x00}
387 }, 366 },
388 { 367 {
389 {0x21,0xed,0x00,0x08}, 368 {0x21,0xed,0x00,0x08},
390 {0x21,0xed,0x8a,0x08}, 369 {0x21,0xed,0x8a,0x08},
391 {0x21,0xed,0x8a,0x08}, 370 {0x21,0xed,0x8a,0x08},
392 {0x21,0xed,0x8a,0x08}, 371 {0x21,0xed,0x8a,0x08},
393 {0x21,0xed,0x8a,0x08} 372 {0x21,0xed,0x8a,0x08}
394 }, 373 },
395 { 374 {
396 {0x2a,0x05,0xd3,0x00}, 375 {0x2a,0x05,0xd3,0x00},
397 {0x2a,0x05,0xd3,0x00}, 376 {0x2a,0x05,0xd3,0x00},
398 {0x2a,0x05,0xd3,0x00}, 377 {0x2a,0x05,0xd3,0x00},
399 {0x2a,0x05,0xd3,0x00}, 378 {0x2a,0x05,0xd3,0x00},
400 {0x2a,0x05,0xd3,0x00} 379 {0x2a,0x05,0xd3,0x00}
401 }, 380 },
402 { 381 {
403 {0x2a,0x05,0xd3,0x00}, 382 {0x2a,0x05,0xd3,0x00},
404 {0x2a,0x05,0xd3,0x00}, 383 {0x2a,0x05,0xd3,0x00},
405 {0x2a,0x05,0xd3,0x00}, 384 {0x2a,0x05,0xd3,0x00},
406 {0x2a,0x05,0xd3,0x00}, 385 {0x2a,0x05,0xd3,0x00},
407 {0x2a,0x05,0xd3,0x00} 386 {0x2a,0x05,0xd3,0x00}
408 }, 387 },
409 { 388 {
410 {0x2a,0x05,0xd3,0x00}, 389 {0x2a,0x05,0xd3,0x00},
411 {0x2a,0x05,0xd3,0x00}, 390 {0x2a,0x05,0xd3,0x00},
412 {0x2a,0x05,0xd3,0x00}, 391 {0x2a,0x05,0xd3,0x00},
413 {0x2a,0x05,0xd3,0x00}, 392 {0x2a,0x05,0xd3,0x00},
@@ -415,7 +394,7 @@ static const UCHAR SiS300_Phase2[8][5][4] =
415 } 394 }
416}; 395};
417 396
418static const UCHAR SiS300_Filter1[10][16][4] = 397static const unsigned char SiS300_Filter1[10][16][4] =
419{ 398{
420 { 399 {
421 {0x00,0xf4,0x10,0x38}, 400 {0x00,0xf4,0x10,0x38},
@@ -599,7 +578,7 @@ static const UCHAR SiS300_Filter1[10][16][4] =
599 }, 578 },
600}; 579};
601 580
602static const UCHAR SiS300_Filter2[10][9][7] = 581static const unsigned char SiS300_Filter2[10][9][7] =
603{ 582{
604 { 583 {
605 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46}, 584 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
@@ -714,142 +693,144 @@ static const UCHAR SiS300_Filter2[10][9][7] =
714}; 693};
715 694
716/* Custom data for Barco iQ Pro R300 */ 695/* Custom data for Barco iQ Pro R300 */
717static const UCHAR barco_p1[2][9][7][3] = { 696static const unsigned char barco_p1[2][9][7][3] =
718 { 697{
719 { { 0x16, 0xcf, 0x00 }, 698 {
720 { 0x18, 0x00, 0x00 }, 699 {
721 { 0x1a, 0xe7, 0x00 }, 700 { 0x16, 0xcf, 0x00 },
722 { 0x1b, 0x26, 0x00 }, 701 { 0x18, 0x00, 0x00 },
723 { 0x1c, 0xff, 0x00 }, 702 { 0x1a, 0xe7, 0x00 },
724 { 0x1d, 0x1c, 0x00 }, 703 { 0x1b, 0x26, 0x00 },
725 { 0x1e, 0x19, 0x00 } 704 { 0x1c, 0xff, 0x00 },
726 }, 705 { 0x1d, 0x1c, 0x00 },
727 { 706 { 0x1e, 0x19, 0x00 }
728 { 0x16, 0xcf, 0x00 }, 707 },
729 { 0x18, 0x00, 0x00 }, 708 {
730 { 0x1a, 0xe7, 0x00 }, 709 { 0x16, 0xcf, 0x00 },
731 { 0x1b, 0x1e, 0x00 }, 710 { 0x18, 0x00, 0x00 },
732 { 0x1c, 0xff, 0x00 }, 711 { 0x1a, 0xe7, 0x00 },
733 { 0x1d, 0x1c, 0x00 }, 712 { 0x1b, 0x1e, 0x00 },
734 { 0x1e, 0x16, 0x00 } 713 { 0x1c, 0xff, 0x00 },
735 }, 714 { 0x1d, 0x1c, 0x00 },
736 { 715 { 0x1e, 0x16, 0x00 }
737 { 0x16, 0xcf, 0x00 }, 716 },
738 { 0x1a, 0xe7, 0x00 }, 717 {
739 { 0x1b, 0x26, 0x00 }, 718 { 0x16, 0xcf, 0x00 },
740 { 0x1c, 0xff, 0x00 }, 719 { 0x1a, 0xe7, 0x00 },
741 { 0x1d, 0x1c, 0x00 }, 720 { 0x1b, 0x26, 0x00 },
742 { 0x1e, 0x19, 0x00 }, 721 { 0x1c, 0xff, 0x00 },
743 { 0, 0, 0 } 722 { 0x1d, 0x1c, 0x00 },
744 }, 723 { 0x1e, 0x19, 0x00 },
745 { 724 { 0, 0, 0 }
746 { 0, 0, 0 } 725 },
747 }, 726 {
748 { 727 { 0, 0, 0 }
749 { 0x16, 0xcf, 0x00 }, 728 },
750 { 0x1a, 0xe7, 0x00 }, 729 {
751 { 0x1b, 0x26, 0x00 }, 730 { 0x16, 0xcf, 0x00 },
752 { 0x1c, 0xff, 0x00 }, 731 { 0x1a, 0xe7, 0x00 },
753 { 0x1d, 0x1c, 0x00 }, 732 { 0x1b, 0x26, 0x00 },
754 { 0x1e, 0x1e, 0x00 }, 733 { 0x1c, 0xff, 0x00 },
755 { 0, 0, 0 } 734 { 0x1d, 0x1c, 0x00 },
756 }, 735 { 0x1e, 0x1e, 0x00 },
757 { 736 { 0, 0, 0 }
758 { 0x16, 0xd1, 0x00 }, 737 },
759 { 0x18, 0x00, 0x00 }, 738 {
760 { 0x1a, 0xe7, 0x00 }, 739 { 0x16, 0xd1, 0x00 },
761 { 0x1b, 0x11, 0x00 }, 740 { 0x18, 0x00, 0x00 },
762 { 0x1c, 0xff, 0x00 }, 741 { 0x1a, 0xe7, 0x00 },
763 { 0x1d, 0x1c, 0x00 }, 742 { 0x1b, 0x11, 0x00 },
764 { 0x1e, 0x26, 0x00 } 743 { 0x1c, 0xff, 0x00 },
765 }, 744 { 0x1d, 0x1c, 0x00 },
766 { 745 { 0x1e, 0x26, 0x00 }
767 { 0x16, 0xd1, 0x00 }, 746 },
768 { 0x1a, 0xe7, 0x00 }, 747 {
769 { 0x1b, 0x26, 0x00 }, 748 { 0x16, 0xd1, 0x00 },
770 { 0x1c, 0xff, 0x00 }, 749 { 0x1a, 0xe7, 0x00 },
771 { 0x1d, 0x1c, 0x00 }, 750 { 0x1b, 0x26, 0x00 },
772 { 0x1e, 0x30, 0x00 }, 751 { 0x1c, 0xff, 0x00 },
773 { 0, 0, 0 } 752 { 0x1d, 0x1c, 0x00 },
774 }, 753 { 0x1e, 0x30, 0x00 },
775 { 754 { 0, 0, 0 }
776 { 0x16, 0x00, 0x00 }, 755 },
777 { 0x17, 0xa0, 0x00 }, 756 {
778 { 0x1a, 0xa0, 0x00 }, 757 { 0x16, 0x00, 0x00 },
779 { 0x1b, 0x2a, 0x00 }, 758 { 0x17, 0xa0, 0x00 },
780 { 0x1c, 0xff, 0x00 }, 759 { 0x1a, 0xa0, 0x00 },
781 { 0x1d, 0x1c, 0x00 }, 760 { 0x1b, 0x2a, 0x00 },
782 { 0, 0, 0 } 761 { 0x1c, 0xff, 0x00 },
783 }, 762 { 0x1d, 0x1c, 0x00 },
784 { 763 { 0, 0, 0 }
785 { 0x16, 0x00, 0x00 }, 764 },
786 { 0x17, 0xaa, 0x00 }, 765 {
787 { 0x1a, 0xa0, 0x00 }, 766 { 0x16, 0x00, 0x00 },
788 { 0x1b, 0x2a, 0x00 }, 767 { 0x17, 0xaa, 0x00 },
789 { 0x1c, 0xff, 0x00 }, 768 { 0x1a, 0xa0, 0x00 },
790 { 0x1d, 0x1c, 0x00 }, 769 { 0x1b, 0x2a, 0x00 },
791 { 0, 0, 0 } 770 { 0x1c, 0xff, 0x00 },
792 } 771 { 0x1d, 0x1c, 0x00 },
793 }, 772 { 0, 0, 0 }
794 { 773 }
795 { 774 },
796 { 0x16, 0xcf, 0x00 }, 775 {
797 { 0x18, 0x00, 0x00 }, 776 {
798 { 0x1a, 0xe7, 0x00 }, 777 { 0x16, 0xcf, 0x00 },
799 { 0x1b, 0x26, 0x00 }, 778 { 0x18, 0x00, 0x00 },
800 { 0x1c, 0xff, 0x00 }, 779 { 0x1a, 0xe7, 0x00 },
801 { 0x1d, 0x1c, 0x00 }, 780 { 0x1b, 0x26, 0x00 },
802 { 0x1e, 0x19, 0x00 } 781 { 0x1c, 0xff, 0x00 },
803 }, 782 { 0x1d, 0x1c, 0x00 },
804 { 783 { 0x1e, 0x19, 0x00 }
805 { 0, 0, 0 } 784 },
806 }, 785 {
807 { 786 { 0, 0, 0 }
808 { 0x16, 0xcf, 0x00 }, 787 },
809 { 0x18, 0x00, 0x00 }, 788 {
810 { 0x1a, 0xe7, 0x00 }, 789 { 0x16, 0xcf, 0x00 },
811 { 0x1b, 0x26, 0x00 }, 790 { 0x18, 0x00, 0x00 },
812 { 0x1c, 0xff, 0x00 }, 791 { 0x1a, 0xe7, 0x00 },
813 { 0x1d, 0x1c, 0x00 }, 792 { 0x1b, 0x26, 0x00 },
814 { 0x1e, 0x19, 0x00 }, 793 { 0x1c, 0xff, 0x00 },
815 }, 794 { 0x1d, 0x1c, 0x00 },
816 { 795 { 0x1e, 0x19, 0x00 },
817 { 0, 0, 0 } 796 },
818 }, 797 {
819 { 798 { 0, 0, 0 }
820 { 0x16, 0xcf, 0x00 }, 799 },
821 { 0x18, 0x00, 0x00 }, 800 {
822 { 0x1a, 0xe7, 0x00 }, 801 { 0x16, 0xcf, 0x00 },
823 { 0x1b, 0x26, 0x00 }, 802 { 0x18, 0x00, 0x00 },
824 { 0x1c, 0xff, 0x00 }, 803 { 0x1a, 0xe7, 0x00 },
825 { 0x1d, 0x1c, 0x00 }, 804 { 0x1b, 0x26, 0x00 },
826 { 0x1e, 0x1e, 0x00 } 805 { 0x1c, 0xff, 0x00 },
827 }, 806 { 0x1d, 0x1c, 0x00 },
828 { 807 { 0x1e, 0x1e, 0x00 }
829 { 0x16, 0xd1, 0x00 }, 808 },
830 { 0x18, 0x00, 0x00 }, 809 {
831 { 0x1a, 0xe6, 0x00 }, 810 { 0x16, 0xd1, 0x00 },
832 { 0x1b, 0x11, 0x00 }, 811 { 0x18, 0x00, 0x00 },
833 { 0x1c, 0xff, 0x00 }, 812 { 0x1a, 0xe6, 0x00 },
834 { 0x1d, 0x1c, 0x00 }, 813 { 0x1b, 0x11, 0x00 },
835 { 0x1e, 0x26, 0x00 } 814 { 0x1c, 0xff, 0x00 },
836 }, 815 { 0x1d, 0x1c, 0x00 },
837 { 816 { 0x1e, 0x26, 0x00 }
838 { 0x18, 0x00, 0x00 }, 817 },
839 { 0x1a, 0xe0, 0x00 }, 818 {
840 { 0x1b, 0x26, 0x00 }, 819 { 0x18, 0x00, 0x00 },
841 { 0x1c, 0xff, 0x00 }, 820 { 0x1a, 0xe0, 0x00 },
842 { 0x1d, 0x1c, 0x00 }, 821 { 0x1b, 0x26, 0x00 },
843 { 0x1e, 0x30, 0x00 }, 822 { 0x1c, 0xff, 0x00 },
844 { 0, 0, 0 } 823 { 0x1d, 0x1c, 0x00 },
845 }, 824 { 0x1e, 0x30, 0x00 },
846 { 825 { 0, 0, 0 }
847 { 0, 0, 0 } 826 },
848 }, 827 {
849 { 828 { 0, 0, 0 }
850 { 0, 0, 0 } 829 },
851 } 830 {
852 } 831 { 0, 0, 0 }
832 }
833 }
853}; 834};
854 835
855 836
diff --git a/drivers/video/sis/oem310.h b/drivers/video/sis/oem310.h
index 2b7db916b7..8fce56e448 100644
--- a/drivers/video/sis/oem310.h
+++ b/drivers/video/sis/oem310.h
@@ -1,9 +1,9 @@
1/* $XFree86$ */ 1/* $XFree86$ */
2/* $XdotOrg$ */ 2/* $XdotOrg$ */
3/* 3/*
4 * OEM Data for 315/330 series 4 * OEM Data for 315/330/340 series
5 * 5 *
6 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria 6 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
7 * 7 *
8 * If distributed as part of the Linux kernel, the following license terms 8 * If distributed as part of the Linux kernel, the following license terms
9 * apply: 9 * apply:
@@ -50,206 +50,206 @@
50 * 50 *
51 */ 51 */
52 52
53static const UCHAR SiS310_LCDDelayCompensation_301[] = /* 301 */ 53static const unsigned char SiS310_LCDDelayCompensation_301[] = /* 301 */
54{ 54{
55 0x00,0x00,0x00, /* 800x600 */ 55 0x00,0x00,0x00, /* 800x600 */
56 0x0b,0x0b,0x0b, /* 1024x768 */ 56 0x0b,0x0b,0x0b, /* 1024x768 */
57 0x08,0x08,0x08, /* 1280x1024 */ 57 0x08,0x08,0x08, /* 1280x1024 */
58 0x00,0x00,0x00, /* 640x480 (unknown) */ 58 0x00,0x00,0x00, /* 640x480 (unknown) */
59 0x00,0x00,0x00, /* 1024x600 (unknown) */ 59 0x00,0x00,0x00, /* 1024x600 (unknown) */
60 0x00,0x00,0x00, /* 1152x864 (unknown) */ 60 0x00,0x00,0x00, /* 1152x864 (unknown) */
61 0x08,0x08,0x08, /* 1280x960 (guessed) */ 61 0x08,0x08,0x08, /* 1280x960 (guessed) */
62 0x00,0x00,0x00, /* 1152x768 (unknown) */ 62 0x00,0x00,0x00, /* 1152x768 (unknown) */
63 0x08,0x08,0x08, /* 1400x1050 */ 63 0x08,0x08,0x08, /* 1400x1050 */
64 0x08,0x08,0x08, /* 1280x768 (guessed) */ 64 0x08,0x08,0x08, /* 1280x768 (guessed) */
65 0x00,0x00,0x00, /* 1600x1200 */ 65 0x00,0x00,0x00, /* 1600x1200 */
66 0x00,0x00,0x00, /* 320x480 (unknown) */ 66 0x00,0x00,0x00, /* 320x480 (unknown) */
67 0x00,0x00,0x00, 67 0x00,0x00,0x00,
68 0x00,0x00,0x00, 68 0x00,0x00,0x00,
69 0x00,0x00,0x00 69 0x00,0x00,0x00
70}; 70};
71 71
72/* This is contained in 650+301B BIOSes, but it is wrong - so we don't use it */ 72/* This is contained in 650+301B BIOSes, but it is wrong - so we don't use it */
73static const UCHAR SiS310_LCDDelayCompensation_650301LV[] = /* 650 + 30xLV */ 73static const unsigned char SiS310_LCDDelayCompensation_650301LV[] = /* 650 + 30xLV */
74{ 74{
75 0x01,0x01,0x01, /* 800x600 */ 75 0x01,0x01,0x01, /* 800x600 */
76 0x01,0x01,0x01, /* 1024x768 */ 76 0x01,0x01,0x01, /* 1024x768 */
77 0x01,0x01,0x01, /* 1280x1024 */ 77 0x01,0x01,0x01, /* 1280x1024 */
78 0x01,0x01,0x01, /* 640x480 (unknown) */ 78 0x01,0x01,0x01, /* 640x480 (unknown) */
79 0x01,0x01,0x01, /* 1024x600 (unknown) */ 79 0x01,0x01,0x01, /* 1024x600 (unknown) */
80 0x01,0x01,0x01, /* 1152x864 (unknown) */ 80 0x01,0x01,0x01, /* 1152x864 (unknown) */
81 0x01,0x01,0x01, /* 1280x960 (guessed) */ 81 0x01,0x01,0x01, /* 1280x960 (guessed) */
82 0x01,0x01,0x01, /* 1152x768 (unknown) */ 82 0x01,0x01,0x01, /* 1152x768 (unknown) */
83 0x01,0x01,0x01, /* 1400x1050 */ 83 0x01,0x01,0x01, /* 1400x1050 */
84 0x01,0x01,0x01, /* 1280x768 (guessed) */ 84 0x01,0x01,0x01, /* 1280x768 (guessed) */
85 0x01,0x01,0x01, /* 1600x1200 */ 85 0x01,0x01,0x01, /* 1600x1200 */
86 0x02,0x02,0x02, 86 0x02,0x02,0x02,
87 0x02,0x02,0x02, 87 0x02,0x02,0x02,
88 0x02,0x02,0x02, 88 0x02,0x02,0x02,
89 0x02,0x02,0x02 89 0x02,0x02,0x02
90}; 90};
91 91
92static const UCHAR SiS310_LCDDelayCompensation_651301LV[] = /* M650/651 301LV */ 92static const unsigned char SiS310_LCDDelayCompensation_651301LV[] = /* M650/651 301LV */
93{ 93{
94 0x33,0x33,0x33, /* 800x600 (guessed) - new: PanelType, not PanelRes ! */ 94 0x33,0x33,0x33, /* 800x600 (guessed) - new: PanelType, not PanelRes ! */
95 0x33,0x33,0x33, /* 1024x768 */ 95 0x33,0x33,0x33, /* 1024x768 */
96 0x33,0x33,0x33, /* 1280x1024 */ 96 0x33,0x33,0x33, /* 1280x1024 */
97 0x33,0x33,0x33, /* 640x480 (unknown) */ 97 0x33,0x33,0x33, /* 640x480 (unknown) */
98 0x33,0x33,0x33, /* 1024x600 (unknown) */ 98 0x33,0x33,0x33, /* 1024x600 (unknown) */
99 0x33,0x33,0x33, /* 1152x864 (unknown) */ 99 0x33,0x33,0x33, /* 1152x864 (unknown) */
100 0x33,0x33,0x33, /* 1280x960 (guessed) */ 100 0x33,0x33,0x33, /* 1280x960 (guessed) */
101 0x33,0x33,0x33, /* 1152x768 (unknown) */ 101 0x33,0x33,0x33, /* 1152x768 (unknown) */
102 0x33,0x33,0x33, /* 1400x1050 */ 102 0x33,0x33,0x33, /* 1400x1050 */
103 0x33,0x33,0x33, /* 1280x768 (guessed) */ 103 0x33,0x33,0x33, /* 1280x768 (guessed) */
104 0x33,0x33,0x33, /* 1600x1200 */ 104 0x33,0x33,0x33, /* 1600x1200 */
105 0x33,0x33,0x33, 105 0x33,0x33,0x33,
106 0x33,0x33,0x33, 106 0x33,0x33,0x33,
107 0x33,0x33,0x33, 107 0x33,0x33,0x33,
108 0x33,0x33,0x33 108 0x33,0x33,0x33
109}; 109};
110 110
111static const UCHAR SiS310_LCDDelayCompensation_651302LV[] = /* M650/651 302LV */ 111static const unsigned char SiS310_LCDDelayCompensation_651302LV[] = /* M650/651 302LV */
112{ 112{
113 0x33,0x33,0x33, /* 800x600 (guessed) */ 113 0x33,0x33,0x33, /* 800x600 (guessed) */
114 0x33,0x33,0x33, /* 1024x768 */ 114 0x33,0x33,0x33, /* 1024x768 */
115 0x33,0x33,0x33, /* 1280x1024 */ 115 0x33,0x33,0x33, /* 1280x1024 */
116 0x33,0x33,0x33, /* 640x480 (unknown) */ 116 0x33,0x33,0x33, /* 640x480 (unknown) */
117 0x33,0x33,0x33, /* 1024x600 (unknown) */ 117 0x33,0x33,0x33, /* 1024x600 (unknown) */
118 0x33,0x33,0x33, /* 1152x864 (unknown) */ 118 0x33,0x33,0x33, /* 1152x864 (unknown) */
119 0x33,0x33,0x33, /* 1280x960 (guessed) */ 119 0x33,0x33,0x33, /* 1280x960 (guessed) */
120 0x33,0x33,0x33, /* 1152x768 (unknown) */ 120 0x33,0x33,0x33, /* 1152x768 (unknown) */
121 0x33,0x33,0x33, /* 1400x1050 */ 121 0x33,0x33,0x33, /* 1400x1050 */
122 0x33,0x33,0x33, /* 1280x768 (guessed) */ 122 0x33,0x33,0x33, /* 1280x768 (guessed) */
123 0x33,0x33,0x33, /* 1600x1200 */ 123 0x33,0x33,0x33, /* 1600x1200 */
124 0x33,0x33,0x33, 124 0x33,0x33,0x33,
125 0x33,0x33,0x33, 125 0x33,0x33,0x33,
126 0x33,0x33,0x33, 126 0x33,0x33,0x33,
127 0x33,0x33,0x33 127 0x33,0x33,0x33
128}; 128};
129 129
130static const UCHAR SiS310_LCDDelayCompensation_3xx301B[] = /* 30xB */ 130static const unsigned char SiS310_LCDDelayCompensation_3xx301B[] = /* 30xB */
131{ 131{
132 0x01,0x01,0x01, /* 800x600 */ 132 0x01,0x01,0x01, /* 800x600 */
133 0x0C,0x0C,0x0C, /* 1024x768 */ 133 0x0C,0x0C,0x0C, /* 1024x768 */
134 0x0C,0x0C,0x0C, /* 1280x1024 */ 134 0x0C,0x0C,0x0C, /* 1280x1024 */
135 0x08,0x08,0x08, /* 640x480 */ 135 0x08,0x08,0x08, /* 640x480 */
136 0x0C,0x0C,0x0C, /* 1024x600 (guessed) */ 136 0x0C,0x0C,0x0C, /* 1024x600 (guessed) */
137 0x0C,0x0C,0x0C, /* 1152x864 (guessed) */ 137 0x0C,0x0C,0x0C, /* 1152x864 (guessed) */
138 0x0C,0x0C,0x0C, /* 1280x960 (guessed) */ 138 0x0C,0x0C,0x0C, /* 1280x960 (guessed) */
139 0x0C,0x0C,0x0C, /* 1152x768 (guessed) */ 139 0x0C,0x0C,0x0C, /* 1152x768 (guessed) */
140 0x0C,0x0C,0x0C, /* 1400x1050 (guessed) */ 140 0x0C,0x0C,0x0C, /* 1400x1050 (guessed) */
141 0x0C,0x0C,0x0C, /* 1280x768 (guessed) */ 141 0x0C,0x0C,0x0C, /* 1280x768 (guessed) */
142 0x0C,0x0C,0x0C, /* 1600x1200 (guessed) */ 142 0x0C,0x0C,0x0C, /* 1600x1200 (guessed) */
143 0x02,0x02,0x02, 143 0x02,0x02,0x02,
144 0x02,0x02,0x02, 144 0x02,0x02,0x02,
145 0x02,0x02,0x02, 145 0x02,0x02,0x02,
146 0x02,0x02,0x02 146 0x02,0x02,0x02
147}; 147};
148 148
149static const UCHAR SiS310_LCDDelayCompensation_3xx301LV[] = /* 315+30xLV */ 149static const unsigned char SiS310_LCDDelayCompensation_3xx301LV[] = /* 315+30xLV */
150{ 150{
151 0x01,0x01,0x01, /* 800x600 */ 151 0x01,0x01,0x01, /* 800x600 */
152 0x04,0x04,0x04, /* 1024x768 (A531/BIOS 1.14.05f: 4 - works with 6 */ 152 0x04,0x04,0x04, /* 1024x768 (A531/BIOS 1.14.05f: 4 - works with 6 */
153 0x0C,0x0C,0x0C, /* 1280x1024 */ 153 0x0C,0x0C,0x0C, /* 1280x1024 */
154 0x08,0x08,0x08, /* 640x480 */ 154 0x08,0x08,0x08, /* 640x480 */
155 0x0C,0x0C,0x0C, /* 1024x600 (guessed) */ 155 0x0C,0x0C,0x0C, /* 1024x600 (guessed) */
156 0x0C,0x0C,0x0C, /* 1152x864 (guessed) */ 156 0x0C,0x0C,0x0C, /* 1152x864 (guessed) */
157 0x0C,0x0C,0x0C, /* 1280x960 (guessed) */ 157 0x0C,0x0C,0x0C, /* 1280x960 (guessed) */
158 0x0C,0x0C,0x0C, /* 1152x768 (guessed) */ 158 0x0C,0x0C,0x0C, /* 1152x768 (guessed) */
159 0x0C,0x0C,0x0C, /* 1400x1050 (guessed) */ 159 0x0C,0x0C,0x0C, /* 1400x1050 (guessed) */
160 0x0C,0x0C,0x0C, /* 1280x768 (guessed) */ 160 0x0C,0x0C,0x0C, /* 1280x768 (guessed) */
161 0x0C,0x0C,0x0C, /* 1600x1200 (guessed) */ 161 0x0C,0x0C,0x0C, /* 1600x1200 (guessed) */
162 0x02,0x02,0x02, 162 0x02,0x02,0x02,
163 0x02,0x02,0x02, 163 0x02,0x02,0x02,
164 0x02,0x02,0x02, 164 0x02,0x02,0x02,
165 0x02,0x02,0x02 165 0x02,0x02,0x02
166}; 166};
167 167
168static const UCHAR SiS310_TVDelayCompensation_301[] = /* 301 */ 168static const unsigned char SiS310_TVDelayCompensation_301[] = /* 301 */
169{ 169{
170 0x02,0x02, /* NTSC Enhanced, Standard */ 170 0x02,0x02, /* NTSC Enhanced, Standard */
171 0x02,0x02, /* PAL */ 171 0x02,0x02, /* PAL */
172 0x08,0x0b /* HiVision */ 172 0x08,0x0b /* HiVision */
173}; 173};
174 174
175static const UCHAR SiS310_TVDelayCompensation_301B[] = /* 30xB, 30xLV */ 175static const unsigned char SiS310_TVDelayCompensation_301B[] = /* 30xB, 30xLV */
176{ 176{
177 0x03,0x03, 177 0x03,0x03,
178 0x03,0x03, 178 0x03,0x03,
179 0x03,0x03 179 0x03,0x03
180}; 180};
181 181
182static const UCHAR SiS310_TVDelayCompensation_740301B[] = /* 740 + 30xB (30xLV?) */ 182static const unsigned char SiS310_TVDelayCompensation_740301B[] = /* 740 + 30xB (30xLV?) */
183{ 183{
184 0x05,0x05, 184 0x05,0x05,
185 0x05,0x05, 185 0x05,0x05,
186 0x05,0x05 186 0x05,0x05
187}; 187};
188 188
189static const UCHAR SiS310_TVDelayCompensation_651301LV[] = /* M650, 651, 301LV */ 189static const unsigned char SiS310_TVDelayCompensation_651301LV[] = /* M650, 651, 301LV */
190{ 190{
191 0x33,0x33, 191 0x33,0x33,
192 0x33,0x33, 192 0x33,0x33,
193 0x33,0x33 193 0x33,0x33
194}; 194};
195 195
196static const UCHAR SiS310_TVDelayCompensation_651302LV[] = /* M650, 651, 302LV */ 196static const unsigned char SiS310_TVDelayCompensation_651302LV[] = /* M650, 651, 302LV */
197{ 197{
198 0x33,0x33, 198 0x33,0x33,
199 0x33,0x33, 199 0x33,0x33,
200 0x33,0x33 200 0x33,0x33
201}; 201};
202 202
203static const UCHAR SiS_TVDelay661_301[] = /* 661, 301 */ 203static const unsigned char SiS_TVDelay661_301[] = /* 661, 301 */
204{ 204{
205 0x44,0x44, 205 0x44,0x44,
206 0x44,0x44, 206 0x44,0x44,
207 0x00,0x00, 207 0x00,0x00,
208 0x44,0x44, 208 0x44,0x44,
209 0x44,0x44, 209 0x44,0x44,
210 0x44,0x44 210 0x44,0x44
211}; 211};
212 212
213static const UCHAR SiS_TVDelay661_301B[] = /* 661, 301B et al */ 213static const unsigned char SiS_TVDelay661_301B[] = /* 661, 301B et al */
214{ 214{
215 0x44,0x44, 215 0x44,0x44,
216 0x44,0x44, 216 0x44,0x44,
217 0x00,0x00, 217 0x00,0x00,
218 0x44,0x44, 218 0x44,0x44,
219 0x44,0x44, 219 0x44,0x44,
220 0x44,0x44 220 0x44,0x44
221}; 221};
222 222
223static const UCHAR SiS310_TVDelayCompensation_LVDS[] = /* LVDS */ 223static const unsigned char SiS310_TVDelayCompensation_LVDS[] = /* LVDS */
224{ 224{
225 0x0a,0x0a, 225 0x0a,0x0a,
226 0x0a,0x0a, 226 0x0a,0x0a,
227 0x0a,0x0a 227 0x0a,0x0a
228}; 228};
229 229
230static const UCHAR SiS310_TVAntiFlick1[6][2] = 230static const unsigned char SiS310_TVAntiFlick1[6][2] =
231{ 231{
232 {0x4,0x0}, 232 {0x4,0x0},
233 {0x4,0x8}, 233 {0x4,0x8},
234 {0x0,0x0}, 234 {0x0,0x0},
235 {0x0,0x0}, 235 {0x0,0x0},
236 {0x0,0x0}, 236 {0x0,0x0},
237 {0x0,0x0} 237 {0x0,0x0}
238}; 238};
239 239
240static const UCHAR SiS310_TVEdge1[6][2] = 240static const unsigned char SiS310_TVEdge1[6][2] =
241{ 241{
242 {0x0,0x4}, 242 {0x0,0x4},
243 {0x0,0x4}, 243 {0x0,0x4},
244 {0x0,0x0}, 244 {0x0,0x0},
245 {0x0,0x0}, 245 {0x0,0x0},
246 {0x0,0x0}, 246 {0x0,0x0},
247 {0x0,0x0} 247 {0x0,0x0}
248}; 248};
249 249
250static const UCHAR SiS310_TVYFilter1[5][8][4] = 250static const unsigned char SiS310_TVYFilter1[5][8][4] =
251{ 251{
252 { 252 {
253 {0x00,0xf4,0x10,0x38}, /* NTSC */ 253 {0x00,0xf4,0x10,0x38}, /* NTSC */
254 {0x00,0xf4,0x10,0x38}, 254 {0x00,0xf4,0x10,0x38},
255 {0xeb,0x04,0x25,0x18}, 255 {0xeb,0x04,0x25,0x18},
@@ -258,8 +258,8 @@ static const UCHAR SiS310_TVYFilter1[5][8][4] =
258 {0xeb,0x04,0x25,0x18}, 258 {0xeb,0x04,0x25,0x18},
259 {0xee,0x0c,0x22,0x08}, 259 {0xee,0x0c,0x22,0x08},
260 {0xeb,0x15,0x25,0xf6} 260 {0xeb,0x15,0x25,0xf6}
261 }, 261 },
262 { 262 {
263 {0x00,0xf4,0x10,0x38}, /* PAL */ 263 {0x00,0xf4,0x10,0x38}, /* PAL */
264 {0x00,0xf4,0x10,0x38}, 264 {0x00,0xf4,0x10,0x38},
265 {0xf1,0xf7,0x1f,0x32}, 265 {0xf1,0xf7,0x1f,0x32},
@@ -268,8 +268,8 @@ static const UCHAR SiS310_TVYFilter1[5][8][4] =
268 {0xf1,0xf7,0x1f,0x32}, 268 {0xf1,0xf7,0x1f,0x32},
269 {0xf3,0x00,0x1d,0x20}, 269 {0xf3,0x00,0x1d,0x20},
270 {0xfc,0xfb,0x14,0x2a} 270 {0xfc,0xfb,0x14,0x2a}
271 }, 271 },
272 { 272 {
273 {0x00,0x00,0x00,0x00}, /* HiVision */ 273 {0x00,0x00,0x00,0x00}, /* HiVision */
274 {0x00,0xf4,0x10,0x38}, 274 {0x00,0xf4,0x10,0x38},
275 {0x00,0xf4,0x10,0x38}, 275 {0x00,0xf4,0x10,0x38},
@@ -278,9 +278,9 @@ static const UCHAR SiS310_TVYFilter1[5][8][4] =
278 {0x00,0xf4,0x10,0x38}, 278 {0x00,0xf4,0x10,0x38},
279 {0xeb,0x04,0x25,0x18}, 279 {0xeb,0x04,0x25,0x18},
280 {0xee,0x0c,0x22,0x08} 280 {0xee,0x0c,0x22,0x08}
281 }, 281 },
282 { 282 {
283 {0x00,0xf4,0x10,0x38}, /* PAL-M */ 283 {0x00,0xf4,0x10,0x38}, /* PAL-M */
284 {0x00,0xf4,0x10,0x38}, 284 {0x00,0xf4,0x10,0x38},
285 {0xeb,0x04,0x10,0x18}, 285 {0xeb,0x04,0x10,0x18},
286 {0xf7,0x06,0x19,0x14}, 286 {0xf7,0x06,0x19,0x14},
@@ -288,9 +288,9 @@ static const UCHAR SiS310_TVYFilter1[5][8][4] =
288 {0xeb,0x04,0x25,0x18}, 288 {0xeb,0x04,0x25,0x18},
289 {0xeb,0x04,0x25,0x18}, 289 {0xeb,0x04,0x25,0x18},
290 {0xeb,0x15,0x25,0xf6} 290 {0xeb,0x15,0x25,0xf6}
291 }, 291 },
292 { 292 {
293 {0x00,0xf4,0x10,0x38}, /* PAL-N */ 293 {0x00,0xf4,0x10,0x38}, /* PAL-N */
294 {0x00,0xf4,0x10,0x38}, 294 {0x00,0xf4,0x10,0x38},
295 {0xeb,0x04,0x10,0x18}, 295 {0xeb,0x04,0x10,0x18},
296 {0xf7,0x06,0x19,0x14}, 296 {0xf7,0x06,0x19,0x14},
@@ -298,12 +298,12 @@ static const UCHAR SiS310_TVYFilter1[5][8][4] =
298 {0xeb,0x04,0x25,0x18}, 298 {0xeb,0x04,0x25,0x18},
299 {0xeb,0x04,0x25,0x18}, 299 {0xeb,0x04,0x25,0x18},
300 {0xeb,0x15,0x25,0xf6} 300 {0xeb,0x15,0x25,0xf6}
301 } 301 }
302}; 302};
303 303
304static const UCHAR SiS310_TVYFilter2[5][9][7] = 304static const unsigned char SiS310_TVYFilter2[5][9][7] =
305{ 305{
306 { 306 {
307 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46}, /* NTSC */ 307 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46}, /* NTSC */
308 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C}, 308 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
309 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46}, 309 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
@@ -313,8 +313,8 @@ static const UCHAR SiS310_TVYFilter2[5][9][7] =
313 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C}, 313 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
314 {0x01,0x01,0xFC,0xF8,0x08,0x26,0x38}, 314 {0x01,0x01,0xFC,0xF8,0x08,0x26,0x38},
315 {0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28} 315 {0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28}
316 }, 316 },
317 { 317 {
318 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46}, /* PAL */ 318 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46}, /* PAL */
319 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C}, 319 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
320 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46}, 320 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
@@ -324,8 +324,8 @@ static const UCHAR SiS310_TVYFilter2[5][9][7] =
324 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C}, 324 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
325 {0x01,0x01,0xFC,0xF8,0x08,0x26,0x38}, 325 {0x01,0x01,0xFC,0xF8,0x08,0x26,0x38},
326 {0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28} 326 {0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28}
327 }, 327 },
328 { 328 {
329 {0x00,0x00,0x00,0xF4,0xFF,0x1C,0x22}, /* HiVision */ 329 {0x00,0x00,0x00,0xF4,0xFF,0x1C,0x22}, /* HiVision */
330 {0x00,0x00,0x00,0xF4,0xFF,0x1C,0x22}, 330 {0x00,0x00,0x00,0xF4,0xFF,0x1C,0x22},
331 {0x00,0x00,0x00,0xF4,0xFF,0x1C,0x22}, 331 {0x00,0x00,0x00,0xF4,0xFF,0x1C,0x22},
@@ -335,9 +335,9 @@ static const UCHAR SiS310_TVYFilter2[5][9][7] =
335 {0x00,0x00,0x00,0xF4,0xFF,0x1C,0x22}, 335 {0x00,0x00,0x00,0xF4,0xFF,0x1C,0x22},
336 {0x00,0x00,0x00,0xF4,0xFF,0x1C,0x22}, 336 {0x00,0x00,0x00,0xF4,0xFF,0x1C,0x22},
337 {0x00,0x00,0x00,0xF4,0xFF,0x1C,0x22} 337 {0x00,0x00,0x00,0xF4,0xFF,0x1C,0x22}
338 }, 338 },
339 { 339 {
340 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46}, /* PAL-M */ 340 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46}, /* PAL-M */
341 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C}, 341 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
342 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46}, 342 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
343 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C}, 343 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
@@ -346,9 +346,9 @@ static const UCHAR SiS310_TVYFilter2[5][9][7] =
346 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C}, 346 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
347 {0x01,0x01,0xFC,0xF8,0x08,0x26,0x38}, 347 {0x01,0x01,0xFC,0xF8,0x08,0x26,0x38},
348 {0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28} 348 {0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28}
349 }, 349 },
350 { 350 {
351 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46}, /* PAL-N */ 351 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46}, /* PAL-N */
352 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C}, 352 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
353 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46}, 353 {0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
354 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C}, 354 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
@@ -357,58 +357,39 @@ static const UCHAR SiS310_TVYFilter2[5][9][7] =
357 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C}, 357 {0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
358 {0x01,0x01,0xFC,0xF8,0x08,0x26,0x38}, 358 {0x01,0x01,0xFC,0xF8,0x08,0x26,0x38},
359 {0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28} 359 {0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28}
360 } 360 }
361}; 361};
362 362
363static const UCHAR SiS310_TVPhaseIncr1[3][2][4] = 363static const unsigned char SiS310_TVPhaseIncr1[3][2][4] =
364{ 364{
365 { 365 {
366 {0x21,0xed,0xba,0x08}, 366 {0x21,0xed,0xba,0x08},
367 {0x21,0xed,0xba,0x08} 367 {0x21,0xed,0xba,0x08}
368 }, 368 },
369 { 369 {
370 {0x2a,0x05,0xe3,0x00}, 370 {0x2a,0x05,0xe3,0x00},
371 {0x2a,0x05,0xe3,0x00} 371 {0x2a,0x05,0xe3,0x00}
372 }, 372 },
373 { 373 {
374 {0x2a,0x05,0xd3,0x00}, 374 {0x2a,0x05,0xd3,0x00},
375 {0x2a,0x05,0xd3,0x00} 375 {0x2a,0x05,0xd3,0x00}
376 } 376 }
377}; 377};
378 378
379static const UCHAR SiS310_TVPhaseIncr2[3][2][4] = 379static const unsigned char SiS310_TVPhaseIncr2[3][2][4] =
380{ 380{
381 { 381 {
382 {0x21,0xf0,0x7b,0xd6}, 382 {0x21,0xf0,0x7b,0xd6},
383 {0x21,0xf0,0x7b,0xd6} 383 {0x21,0xf0,0x7b,0xd6}
384 }, 384 },
385 { 385 {
386 {0x2a,0x0a,0x41,0xe9}, 386 {0x2a,0x0a,0x41,0xe9},
387 {0x2a,0x0a,0x41,0xe9} 387 {0x2a,0x0a,0x41,0xe9}
388 }, 388 },
389 { 389 {
390 {0x2a,0x05,0xd3,0x00}, 390 {0x2a,0x05,0xd3,0x00},
391 {0x2a,0x05,0xd3,0x00} 391 {0x2a,0x05,0xd3,0x00}
392 } 392 }
393};
394
395static const UCHAR SiS661_TVPhase[] = {
396 0x21,0xED,0xBA,0x08,
397 0x2A,0x05,0xE3,0x00,
398 0x21,0xE4,0x2E,0x9B,
399 0x21,0xF4,0x3E,0xBA,
400 0x1E,0x8B,0xA2,0xA7,
401 0x1E,0x83,0x0A,0xE0,
402 0x00,0x00,0x00,0x00,
403 0x00,0x00,0x00,0x00,
404 0x21,0xF0,0x7B,0xD6,
405 0x2A,0x09,0x86,0xE9,
406 0x21,0xE6,0xEF,0xA4,
407 0x21,0xF6,0x94,0x46,
408 0x1E,0x8B,0xA2,0xA7,
409 0x1E,0x83,0x0A,0xE0,
410 0x00,0x00,0x00,0x00,
411 0x00,0x00,0x00,0x00
412}; 393};
413 394
414/**************************************************************/ 395/**************************************************************/
@@ -417,7 +398,7 @@ static const UCHAR SiS661_TVPhase[] = {
417 398
418/* Inventec / Compaq Presario 3045US, 3017 */ 399/* Inventec / Compaq Presario 3045US, 3017 */
419 400
420static const SiS_LCDDataStruct SiS310_ExtCompaq1280x1024Data[] = 401static const struct SiS_LCDData SiS310_ExtCompaq1280x1024Data[] =
421{ 402{
422 { 211, 60,1024, 501,1688,1066}, 403 { 211, 60,1024, 501,1688,1066},
423 { 211, 60,1024, 508,1688,1066}, 404 { 211, 60,1024, 508,1688,1066},
@@ -431,17 +412,17 @@ static const SiS_LCDDataStruct SiS310_ExtCompaq1280x1024Data[] =
431 412
432/* Asus A2xxxH _2 */ 413/* Asus A2xxxH _2 */
433 414
434static const SiS_Part2PortTblStruct SiS310_CRT2Part2_Asus1024x768_3[] = 415static const struct SiS_Part2PortTbl SiS310_CRT2Part2_Asus1024x768_3[] =
435{ 416{
436 {{0x25,0x13,0xc9,0x25,0xff,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}}, 417 {{0x25,0x13,0xc9,0x25,0xff,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}},
437 {{0x2c,0x13,0x9a,0x25,0xff,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}}, 418 {{0x2c,0x13,0x9a,0x25,0xff,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}},
438 {{0x25,0x13,0xc9,0x25,0xff,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}}, 419 {{0x25,0x13,0xc9,0x25,0xff,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}},
439 {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, 420 {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
440 {{0x38,0x13,0x13,0x25,0xff,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}}, 421 {{0x38,0x13,0x13,0x25,0xff,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}},
441 {{0x38,0x13,0x16,0x25,0xff,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}}, 422 {{0x38,0x13,0x16,0x25,0xff,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}},
442 {{0x36,0x13,0x13,0x25,0xff,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}}, 423 {{0x36,0x13,0x13,0x25,0xff,0x5a,0x45,0x0a,0x07,0xfa,0x0a,0x24}},
443 {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, 424 {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
444 {{0x25,0x13,0xc9,0x25,0xff,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}} 425 {{0x25,0x13,0xc9,0x25,0xff,0x59,0x45,0x09,0x07,0xf9,0x09,0x24}}
445}; 426};
446 427
447 428
diff --git a/drivers/video/sis/osdef.h b/drivers/video/sis/osdef.h
index 15939b0577..841ca3190c 100644
--- a/drivers/video/sis/osdef.h
+++ b/drivers/video/sis/osdef.h
@@ -3,7 +3,7 @@
3/* 3/*
4 * OS depending defines 4 * OS depending defines
5 * 5 *
6 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria 6 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
7 * 7 *
8 * If distributed as part of the Linux kernel, the following license terms 8 * If distributed as part of the Linux kernel, the following license terms
9 * apply: 9 * apply:
@@ -55,8 +55,11 @@
55#define _SIS_OSDEF_H_ 55#define _SIS_OSDEF_H_
56 56
57/* The choices are: */ 57/* The choices are: */
58#define LINUX_KERNEL /* Linux kernel framebuffer */ 58#define SIS_LINUX_KERNEL /* Linux kernel framebuffer */
59/* #define LINUX_XF86 */ /* XFree86/X.org */ 59#undef SIS_XORG_XF86 /* XFree86/X.org */
60
61#undef SIS_LINUX_KERNEL_24
62#undef SIS_LINUX_KERNEL_26
60 63
61#ifdef OutPortByte 64#ifdef OutPortByte
62#undef OutPortByte 65#undef OutPortByte
@@ -86,8 +89,9 @@
86/* LINUX KERNEL */ 89/* LINUX KERNEL */
87/**********************************************************************/ 90/**********************************************************************/
88 91
89#ifdef LINUX_KERNEL 92#ifdef SIS_LINUX_KERNEL
90#include <linux/config.h> 93#include <linux/config.h>
94#include <linux/version.h>
91 95
92#ifdef CONFIG_FB_SIS_300 96#ifdef CONFIG_FB_SIS_300
93#define SIS300 97#define SIS300
@@ -97,6 +101,12 @@
97#define SIS315H 101#define SIS315H
98#endif 102#endif
99 103
104#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
105#define SIS_LINUX_KERNEL_26
106#else
107#define SIS_LINUX_KERNEL_24
108#endif
109
100#if !defined(SIS300) && !defined(SIS315H) 110#if !defined(SIS300) && !defined(SIS315H)
101#warning Neither CONFIG_FB_SIS_300 nor CONFIG_FB_SIS_315 is set 111#warning Neither CONFIG_FB_SIS_300 nor CONFIG_FB_SIS_315 is set
102#warning sisfb will not work! 112#warning sisfb will not work!
@@ -109,13 +119,15 @@
109#define InPortWord(p) inw((SISIOADDRESS)(p)) 119#define InPortWord(p) inw((SISIOADDRESS)(p))
110#define InPortLong(p) inl((SISIOADDRESS)(p)) 120#define InPortLong(p) inl((SISIOADDRESS)(p))
111#define SiS_SetMemory(MemoryAddress,MemorySize,value) memset_io(MemoryAddress, value, MemorySize) 121#define SiS_SetMemory(MemoryAddress,MemorySize,value) memset_io(MemoryAddress, value, MemorySize)
112#endif 122
123#endif /* LINUX_KERNEL */
113 124
114/**********************************************************************/ 125/**********************************************************************/
115/* XFree86/X.org */ 126/* XFree86/X.org */
116/**********************************************************************/ 127/**********************************************************************/
117 128
118#ifdef LINUX_XF86 129#ifdef SIS_XORG_XF86
130
119#define SIS300 131#define SIS300
120#define SIS315H 132#define SIS315H
121 133
@@ -126,6 +138,7 @@
126#define InPortWord(p) inSISREGW((IOADDRESS)(p)) 138#define InPortWord(p) inSISREGW((IOADDRESS)(p))
127#define InPortLong(p) inSISREGL((IOADDRESS)(p)) 139#define InPortLong(p) inSISREGL((IOADDRESS)(p))
128#define SiS_SetMemory(MemoryAddress,MemorySize,value) memset(MemoryAddress, value, MemorySize) 140#define SiS_SetMemory(MemoryAddress,MemorySize,value) memset(MemoryAddress, value, MemorySize)
129#endif 141
142#endif /* XF86 */
130 143
131#endif /* _OSDEF_H_ */ 144#endif /* _OSDEF_H_ */
diff --git a/drivers/video/sis/sis.h b/drivers/video/sis/sis.h
index d0103c162e..0b6e625d73 100644
--- a/drivers/video/sis/sis.h
+++ b/drivers/video/sis/sis.h
@@ -1,8 +1,10 @@
1/* 1/*
2 * SiS 300/630/730/540/315/550/[M]650/651/[M]661[FM]X/740/[M]741[GX]/330/[M]760[GX] 2 * SiS 300/540/630[S]/730[S],
3 * SiS 315[E|PRO]/550/[M]65x/[M]661[F|M]X/740/[M]741[GX]/330/[M]76x[GX],
4 * XGI V3XT/V5/V8, Z7
3 * frame buffer driver for Linux kernels >=2.4.14 and >=2.6.3 5 * frame buffer driver for Linux kernels >=2.4.14 and >=2.6.3
4 * 6 *
5 * Copyright (C) 2001-2004 Thomas Winischhofer, Vienna, Austria. 7 * Copyright (C) 2001-2005 Thomas Winischhofer, Vienna, Austria.
6 * 8 *
7 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
@@ -19,8 +21,8 @@
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
20 */ 22 */
21 23
22#ifndef _SIS_H 24#ifndef _SIS_H_
23#define _SIS_H 25#define _SIS_H_
24 26
25#include <linux/config.h> 27#include <linux/config.h>
26#include <linux/version.h> 28#include <linux/version.h>
@@ -35,26 +37,37 @@
35#include "vgatypes.h" 37#include "vgatypes.h"
36#include "vstruct.h" 38#include "vstruct.h"
37 39
38#define VER_MAJOR 1 40#define VER_MAJOR 1
39#define VER_MINOR 7 41#define VER_MINOR 8
40#define VER_LEVEL 17 42#define VER_LEVEL 9
41
42#undef SIS_CONFIG_COMPAT
43 43
44#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 44#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
45#include <linux/spinlock.h> 45#include <linux/spinlock.h>
46#define SIS_PCI_GET_CLASS(a, b) pci_get_class(a, b)
47#define SIS_PCI_GET_DEVICE(a,b,c) pci_get_device(a,b,c)
48#define SIS_PCI_GET_SLOT(a,b) pci_get_slot(a,b)
49#define SIS_PCI_PUT_DEVICE(a) pci_dev_put(a)
46#ifdef CONFIG_COMPAT 50#ifdef CONFIG_COMPAT
51#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,10)
47#include <linux/ioctl32.h> 52#include <linux/ioctl32.h>
48#define SIS_CONFIG_COMPAT 53#define SIS_OLD_CONFIG_COMPAT
49#endif 54#else
50#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,19) 55#include <linux/smp_lock.h>
51#ifdef __x86_64__ 56#define SIS_NEW_CONFIG_COMPAT
52/* Shouldn't we check for CONFIG_IA32_EMULATION here? */ 57#endif
58#endif /* CONFIG_COMPAT */
59#else /* 2.4 */
60#define SIS_PCI_GET_CLASS(a, b) pci_find_class(a, b)
61#define SIS_PCI_GET_DEVICE(a,b,c) pci_find_device(a,b,c)
62#define SIS_PCI_GET_SLOT(a,b) pci_find_slot(a,b)
63#define SIS_PCI_PUT_DEVICE(a)
64#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,19)
65#ifdef __x86_64__ /* Shouldn't we check for CONFIG_IA32_EMULATION here? */
53#include <asm/ioctl32.h> 66#include <asm/ioctl32.h>
54#define SIS_CONFIG_COMPAT 67#define SIS_OLD_CONFIG_COMPAT
55#endif 68#endif
56#endif 69#endif
57 70#endif /* 2.4 */
58#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8) 71#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8)
59#define SIS_IOTYPE1 void __iomem 72#define SIS_IOTYPE1 void __iomem
60#define SIS_IOTYPE2 __iomem 73#define SIS_IOTYPE2 __iomem
@@ -79,228 +92,312 @@
79 92
80/* To be included in pci_ids.h */ 93/* To be included in pci_ids.h */
81#ifndef PCI_DEVICE_ID_SI_650_VGA 94#ifndef PCI_DEVICE_ID_SI_650_VGA
82#define PCI_DEVICE_ID_SI_650_VGA 0x6325 95#define PCI_DEVICE_ID_SI_650_VGA 0x6325
83#endif 96#endif
84#ifndef PCI_DEVICE_ID_SI_650 97#ifndef PCI_DEVICE_ID_SI_650
85#define PCI_DEVICE_ID_SI_650 0x0650 98#define PCI_DEVICE_ID_SI_650 0x0650
86#endif 99#endif
87#ifndef PCI_DEVICE_ID_SI_651 100#ifndef PCI_DEVICE_ID_SI_651
88#define PCI_DEVICE_ID_SI_651 0x0651 101#define PCI_DEVICE_ID_SI_651 0x0651
89#endif 102#endif
90#ifndef PCI_DEVICE_ID_SI_740 103#ifndef PCI_DEVICE_ID_SI_740
91#define PCI_DEVICE_ID_SI_740 0x0740 104#define PCI_DEVICE_ID_SI_740 0x0740
92#endif 105#endif
93#ifndef PCI_DEVICE_ID_SI_330 106#ifndef PCI_DEVICE_ID_SI_330
94#define PCI_DEVICE_ID_SI_330 0x0330 107#define PCI_DEVICE_ID_SI_330 0x0330
95#endif 108#endif
96#ifndef PCI_DEVICE_ID_SI_660_VGA 109#ifndef PCI_DEVICE_ID_SI_660_VGA
97#define PCI_DEVICE_ID_SI_660_VGA 0x6330 110#define PCI_DEVICE_ID_SI_660_VGA 0x6330
98#endif 111#endif
99#ifndef PCI_DEVICE_ID_SI_661 112#ifndef PCI_DEVICE_ID_SI_661
100#define PCI_DEVICE_ID_SI_661 0x0661 113#define PCI_DEVICE_ID_SI_661 0x0661
101#endif 114#endif
102#ifndef PCI_DEVICE_ID_SI_741 115#ifndef PCI_DEVICE_ID_SI_741
103#define PCI_DEVICE_ID_SI_741 0x0741 116#define PCI_DEVICE_ID_SI_741 0x0741
104#endif 117#endif
105#ifndef PCI_DEVICE_ID_SI_660 118#ifndef PCI_DEVICE_ID_SI_660
106#define PCI_DEVICE_ID_SI_660 0x0660 119#define PCI_DEVICE_ID_SI_660 0x0660
107#endif 120#endif
108#ifndef PCI_DEVICE_ID_SI_760 121#ifndef PCI_DEVICE_ID_SI_760
109#define PCI_DEVICE_ID_SI_760 0x0760 122#define PCI_DEVICE_ID_SI_760 0x0760
123#endif
124#ifndef PCI_DEVICE_ID_SI_761
125#define PCI_DEVICE_ID_SI_761 0x0761
126#endif
127
128#ifndef PCI_VENDOR_ID_XGI
129#define PCI_VENDOR_ID_XGI 0x18ca
130#endif
131
132#ifndef PCI_DEVICE_ID_XGI_20
133#define PCI_DEVICE_ID_XGI_20 0x0020
134#endif
135
136#ifndef PCI_DEVICE_ID_XGI_40
137#define PCI_DEVICE_ID_XGI_40 0x0040
110#endif 138#endif
111 139
112/* To be included in fb.h */ 140/* To be included in fb.h */
113#ifndef FB_ACCEL_SIS_GLAMOUR_2 141#ifndef FB_ACCEL_SIS_GLAMOUR_2
114#define FB_ACCEL_SIS_GLAMOUR_2 40 /* SiS 315, 65x, 740, 661, 741 */ 142#define FB_ACCEL_SIS_GLAMOUR_2 40 /* SiS 315, 65x, 740, 661, 741 */
115#endif 143#endif
116#ifndef FB_ACCEL_SIS_XABRE 144#ifndef FB_ACCEL_SIS_XABRE
117#define FB_ACCEL_SIS_XABRE 41 /* SiS 330 ("Xabre"), 760 */ 145#define FB_ACCEL_SIS_XABRE 41 /* SiS 330 ("Xabre"), 76x */
146#endif
147#ifndef FB_ACCEL_XGI_VOLARI_V
148#define FB_ACCEL_XGI_VOLARI_V 47 /* XGI Volari Vx (V3XT, V5, V8) */
149#endif
150#ifndef FB_ACCEL_XGI_VOLARI_Z
151#define FB_ACCEL_XGI_VOLARI_Z 48 /* XGI Volari Z7 */
118#endif 152#endif
119
120#define MAX_ROM_SCAN 0x10000
121 153
122/* ivideo->caps */ 154/* ivideo->caps */
123#define HW_CURSOR_CAP 0x80 155#define HW_CURSOR_CAP 0x80
124#define TURBO_QUEUE_CAP 0x40 156#define TURBO_QUEUE_CAP 0x40
125#define AGP_CMD_QUEUE_CAP 0x20 157#define AGP_CMD_QUEUE_CAP 0x20
126#define VM_CMD_QUEUE_CAP 0x10 158#define VM_CMD_QUEUE_CAP 0x10
127#define MMIO_CMD_QUEUE_CAP 0x08 159#define MMIO_CMD_QUEUE_CAP 0x08
128 160
129/* For 300 series */ 161/* For 300 series */
130#define TURBO_QUEUE_AREA_SIZE 0x80000 /* 512K */ 162#define TURBO_QUEUE_AREA_SIZE (512 * 1024) /* 512K */
131#define HW_CURSOR_AREA_SIZE_300 0x1000 /* 4K */ 163#define HW_CURSOR_AREA_SIZE_300 4096 /* 4K */
132 164
133/* For 315/Xabre series */ 165/* For 315/Xabre series */
134#define COMMAND_QUEUE_AREA_SIZE 0x80000 /* 512K */ 166#define COMMAND_QUEUE_AREA_SIZE (512 * 1024) /* 512K */
135#define COMMAND_QUEUE_THRESHOLD 0x1F 167#define COMMAND_QUEUE_AREA_SIZE_Z7 (128 * 1024) /* 128k for XGI Z7 */
136#define HW_CURSOR_AREA_SIZE_315 0x4000 /* 16K */ 168#define HW_CURSOR_AREA_SIZE_315 16384 /* 16K */
137 169#define COMMAND_QUEUE_THRESHOLD 0x1F
138#define SIS_OH_ALLOC_SIZE 4000 170
139#define SENTINEL 0x7fffffff 171#define SIS_OH_ALLOC_SIZE 4000
140 172#define SENTINEL 0x7fffffff
141#define SEQ_ADR 0x14 173
142#define SEQ_DATA 0x15 174#define SEQ_ADR 0x14
143#define DAC_ADR 0x18 175#define SEQ_DATA 0x15
144#define DAC_DATA 0x19 176#define DAC_ADR 0x18
145#define CRTC_ADR 0x24 177#define DAC_DATA 0x19
146#define CRTC_DATA 0x25 178#define CRTC_ADR 0x24
147#define DAC2_ADR (0x16-0x30) 179#define CRTC_DATA 0x25
148#define DAC2_DATA (0x17-0x30) 180#define DAC2_ADR (0x16-0x30)
149#define VB_PART1_ADR (0x04-0x30) 181#define DAC2_DATA (0x17-0x30)
150#define VB_PART1_DATA (0x05-0x30) 182#define VB_PART1_ADR (0x04-0x30)
151#define VB_PART2_ADR (0x10-0x30) 183#define VB_PART1_DATA (0x05-0x30)
152#define VB_PART2_DATA (0x11-0x30) 184#define VB_PART2_ADR (0x10-0x30)
153#define VB_PART3_ADR (0x12-0x30) 185#define VB_PART2_DATA (0x11-0x30)
154#define VB_PART3_DATA (0x13-0x30) 186#define VB_PART3_ADR (0x12-0x30)
155#define VB_PART4_ADR (0x14-0x30) 187#define VB_PART3_DATA (0x13-0x30)
156#define VB_PART4_DATA (0x15-0x30) 188#define VB_PART4_ADR (0x14-0x30)
157 189#define VB_PART4_DATA (0x15-0x30)
158#define SISSR ivideo->SiS_Pr.SiS_P3c4 190
159#define SISCR ivideo->SiS_Pr.SiS_P3d4 191#define SISSR ivideo->SiS_Pr.SiS_P3c4
160#define SISDACA ivideo->SiS_Pr.SiS_P3c8 192#define SISCR ivideo->SiS_Pr.SiS_P3d4
161#define SISDACD ivideo->SiS_Pr.SiS_P3c9 193#define SISDACA ivideo->SiS_Pr.SiS_P3c8
162#define SISPART1 ivideo->SiS_Pr.SiS_Part1Port 194#define SISDACD ivideo->SiS_Pr.SiS_P3c9
163#define SISPART2 ivideo->SiS_Pr.SiS_Part2Port 195#define SISPART1 ivideo->SiS_Pr.SiS_Part1Port
164#define SISPART3 ivideo->SiS_Pr.SiS_Part3Port 196#define SISPART2 ivideo->SiS_Pr.SiS_Part2Port
165#define SISPART4 ivideo->SiS_Pr.SiS_Part4Port 197#define SISPART3 ivideo->SiS_Pr.SiS_Part3Port
166#define SISPART5 ivideo->SiS_Pr.SiS_Part5Port 198#define SISPART4 ivideo->SiS_Pr.SiS_Part4Port
167#define SISDAC2A SISPART5 199#define SISPART5 ivideo->SiS_Pr.SiS_Part5Port
168#define SISDAC2D (SISPART5 + 1) 200#define SISDAC2A SISPART5
169#define SISMISCR (ivideo->SiS_Pr.RelIO + 0x1c) 201#define SISDAC2D (SISPART5 + 1)
170#define SISMISCW ivideo->SiS_Pr.SiS_P3c2 202#define SISMISCR (ivideo->SiS_Pr.RelIO + 0x1c)
171#define SISINPSTAT (ivideo->SiS_Pr.RelIO + 0x2a) 203#define SISMISCW ivideo->SiS_Pr.SiS_P3c2
172#define SISPEL ivideo->SiS_Pr.SiS_P3c6 204#define SISINPSTAT (ivideo->SiS_Pr.RelIO + 0x2a)
173 205#define SISPEL ivideo->SiS_Pr.SiS_P3c6
174#define IND_SIS_PASSWORD 0x05 /* SRs */ 206#define SISVGAENABLE (ivideo->SiS_Pr.RelIO + 0x13)
175#define IND_SIS_COLOR_MODE 0x06 207#define SISVID (ivideo->SiS_Pr.RelIO + 0x02 - 0x30)
176#define IND_SIS_RAMDAC_CONTROL 0x07 208#define SISCAP (ivideo->SiS_Pr.RelIO + 0x00 - 0x30)
177#define IND_SIS_DRAM_SIZE 0x14 209
178#define IND_SIS_MODULE_ENABLE 0x1E 210#define IND_SIS_PASSWORD 0x05 /* SRs */
179#define IND_SIS_PCI_ADDRESS_SET 0x20 211#define IND_SIS_COLOR_MODE 0x06
180#define IND_SIS_TURBOQUEUE_ADR 0x26 212#define IND_SIS_RAMDAC_CONTROL 0x07
181#define IND_SIS_TURBOQUEUE_SET 0x27 213#define IND_SIS_DRAM_SIZE 0x14
182#define IND_SIS_POWER_ON_TRAP 0x38 214#define IND_SIS_MODULE_ENABLE 0x1E
183#define IND_SIS_POWER_ON_TRAP2 0x39 215#define IND_SIS_PCI_ADDRESS_SET 0x20
184#define IND_SIS_CMDQUEUE_SET 0x26 216#define IND_SIS_TURBOQUEUE_ADR 0x26
185#define IND_SIS_CMDQUEUE_THRESHOLD 0x27 217#define IND_SIS_TURBOQUEUE_SET 0x27
186 218#define IND_SIS_POWER_ON_TRAP 0x38
187#define IND_SIS_AGP_IO_PAD 0x48 219#define IND_SIS_POWER_ON_TRAP2 0x39
188 220#define IND_SIS_CMDQUEUE_SET 0x26
189#define SIS_CRT2_WENABLE_300 0x24 /* Part1 */ 221#define IND_SIS_CMDQUEUE_THRESHOLD 0x27
190#define SIS_CRT2_WENABLE_315 0x2F 222
191 223#define IND_SIS_AGP_IO_PAD 0x48
192#define SIS_PASSWORD 0x86 /* SR05 */ 224
193 225#define SIS_CRT2_WENABLE_300 0x24 /* Part1 */
194#define SIS_INTERLACED_MODE 0x20 /* SR06 */ 226#define SIS_CRT2_WENABLE_315 0x2F
195#define SIS_8BPP_COLOR_MODE 0x0 227
196#define SIS_15BPP_COLOR_MODE 0x1 228#define SIS_PASSWORD 0x86 /* SR05 */
197#define SIS_16BPP_COLOR_MODE 0x2 229
198#define SIS_32BPP_COLOR_MODE 0x4 230#define SIS_INTERLACED_MODE 0x20 /* SR06 */
199 231#define SIS_8BPP_COLOR_MODE 0x0
200#define SIS_ENABLE_2D 0x40 /* SR1E */ 232#define SIS_15BPP_COLOR_MODE 0x1
201 233#define SIS_16BPP_COLOR_MODE 0x2
202#define SIS_MEM_MAP_IO_ENABLE 0x01 /* SR20 */ 234#define SIS_32BPP_COLOR_MODE 0x4
203#define SIS_PCI_ADDR_ENABLE 0x80 235
204 236#define SIS_ENABLE_2D 0x40 /* SR1E */
205#define SIS_AGP_CMDQUEUE_ENABLE 0x80 /* 315/330 series SR26 */ 237
206#define SIS_VRAM_CMDQUEUE_ENABLE 0x40 238#define SIS_MEM_MAP_IO_ENABLE 0x01 /* SR20 */
207#define SIS_MMIO_CMD_ENABLE 0x20 239#define SIS_PCI_ADDR_ENABLE 0x80
208#define SIS_CMD_QUEUE_SIZE_512k 0x00 240
209#define SIS_CMD_QUEUE_SIZE_1M 0x04 241#define SIS_AGP_CMDQUEUE_ENABLE 0x80 /* 315/330/340 series SR26 */
210#define SIS_CMD_QUEUE_SIZE_2M 0x08 242#define SIS_VRAM_CMDQUEUE_ENABLE 0x40
211#define SIS_CMD_QUEUE_SIZE_4M 0x0C 243#define SIS_MMIO_CMD_ENABLE 0x20
212#define SIS_CMD_QUEUE_RESET 0x01 244#define SIS_CMD_QUEUE_SIZE_512k 0x00
213#define SIS_CMD_AUTO_CORR 0x02 245#define SIS_CMD_QUEUE_SIZE_1M 0x04
214 246#define SIS_CMD_QUEUE_SIZE_2M 0x08
215#define SIS_SIMULTANEOUS_VIEW_ENABLE 0x01 /* CR30 */ 247#define SIS_CMD_QUEUE_SIZE_4M 0x0C
216#define SIS_MODE_SELECT_CRT2 0x02 248#define SIS_CMD_QUEUE_RESET 0x01
217#define SIS_VB_OUTPUT_COMPOSITE 0x04 249#define SIS_CMD_AUTO_CORR 0x02
218#define SIS_VB_OUTPUT_SVIDEO 0x08 250
219#define SIS_VB_OUTPUT_SCART 0x10 251#define SIS_CMD_QUEUE_SIZE_Z7_64k 0x00 /* XGI Z7 */
220#define SIS_VB_OUTPUT_LCD 0x20 252#define SIS_CMD_QUEUE_SIZE_Z7_128k 0x04
221#define SIS_VB_OUTPUT_CRT2 0x40 253
222#define SIS_VB_OUTPUT_HIVISION 0x80 254#define SIS_SIMULTANEOUS_VIEW_ENABLE 0x01 /* CR30 */
223 255#define SIS_MODE_SELECT_CRT2 0x02
224#define SIS_VB_OUTPUT_DISABLE 0x20 /* CR31 */ 256#define SIS_VB_OUTPUT_COMPOSITE 0x04
225#define SIS_DRIVER_MODE 0x40 257#define SIS_VB_OUTPUT_SVIDEO 0x08
226 258#define SIS_VB_OUTPUT_SCART 0x10
227#define SIS_VB_COMPOSITE 0x01 /* CR32 */ 259#define SIS_VB_OUTPUT_LCD 0x20
228#define SIS_VB_SVIDEO 0x02 260#define SIS_VB_OUTPUT_CRT2 0x40
229#define SIS_VB_SCART 0x04 261#define SIS_VB_OUTPUT_HIVISION 0x80
230#define SIS_VB_LCD 0x08 262
231#define SIS_VB_CRT2 0x10 263#define SIS_VB_OUTPUT_DISABLE 0x20 /* CR31 */
232#define SIS_CRT1 0x20 264#define SIS_DRIVER_MODE 0x40
233#define SIS_VB_HIVISION 0x40 265
234#define SIS_VB_YPBPR 0x80 266#define SIS_VB_COMPOSITE 0x01 /* CR32 */
235#define SIS_VB_TV (SIS_VB_COMPOSITE | SIS_VB_SVIDEO | \ 267#define SIS_VB_SVIDEO 0x02
236 SIS_VB_SCART | SIS_VB_HIVISION | SIS_VB_YPBPR) 268#define SIS_VB_SCART 0x04
237 269#define SIS_VB_LCD 0x08
238#define SIS_EXTERNAL_CHIP_MASK 0x0E /* CR37 (< SiS 660) */ 270#define SIS_VB_CRT2 0x10
239#define SIS_EXTERNAL_CHIP_SIS301 0x01 /* in CR37 << 1 ! */ 271#define SIS_CRT1 0x20
240#define SIS_EXTERNAL_CHIP_LVDS 0x02 272#define SIS_VB_HIVISION 0x40
241#define SIS_EXTERNAL_CHIP_TRUMPION 0x03 273#define SIS_VB_YPBPR 0x80
242#define SIS_EXTERNAL_CHIP_LVDS_CHRONTEL 0x04 274#define SIS_VB_TV (SIS_VB_COMPOSITE | SIS_VB_SVIDEO | \
243#define SIS_EXTERNAL_CHIP_CHRONTEL 0x05 275 SIS_VB_SCART | SIS_VB_HIVISION | SIS_VB_YPBPR)
244#define SIS310_EXTERNAL_CHIP_LVDS 0x02 276
245#define SIS310_EXTERNAL_CHIP_LVDS_CHRONTEL 0x03 277#define SIS_EXTERNAL_CHIP_MASK 0x0E /* CR37 (< SiS 660) */
246 278#define SIS_EXTERNAL_CHIP_SIS301 0x01 /* in CR37 << 1 ! */
247#define SIS_AGP_2X 0x20 /* CR48 */ 279#define SIS_EXTERNAL_CHIP_LVDS 0x02
248 280#define SIS_EXTERNAL_CHIP_TRUMPION 0x03
249#define HW_DEVICE_EXTENSION SIS_HW_INFO 281#define SIS_EXTERNAL_CHIP_LVDS_CHRONTEL 0x04
250#define PHW_DEVICE_EXTENSION PSIS_HW_INFO 282#define SIS_EXTERNAL_CHIP_CHRONTEL 0x05
283#define SIS310_EXTERNAL_CHIP_LVDS 0x02
284#define SIS310_EXTERNAL_CHIP_LVDS_CHRONTEL 0x03
285
286#define SIS_AGP_2X 0x20 /* CR48 */
287
288/* vbflags, private entries (others in sisfb.h) */
289#define VB_CONEXANT 0x00000800 /* 661 series only */
290#define VB_TRUMPION VB_CONEXANT /* 300 series only */
291#define VB_302ELV 0x00004000
292#define VB_301 0x00100000 /* Video bridge type */
293#define VB_301B 0x00200000
294#define VB_302B 0x00400000
295#define VB_30xBDH 0x00800000 /* 30xB DH version (w/o LCD support) */
296#define VB_LVDS 0x01000000
297#define VB_CHRONTEL 0x02000000
298#define VB_301LV 0x04000000
299#define VB_302LV 0x08000000
300#define VB_301C 0x10000000
301
302#define VB_SISBRIDGE (VB_301|VB_301B|VB_301C|VB_302B|VB_301LV|VB_302LV|VB_302ELV)
303#define VB_VIDEOBRIDGE (VB_SISBRIDGE | VB_LVDS | VB_CHRONTEL | VB_CONEXANT)
304
305/* vbflags2 (static stuff only!) */
306#define VB2_SISUMC 0x00000001
307#define VB2_301 0x00000002 /* Video bridge type */
308#define VB2_301B 0x00000004
309#define VB2_301C 0x00000008
310#define VB2_307T 0x00000010
311#define VB2_302B 0x00000800
312#define VB2_301LV 0x00001000
313#define VB2_302LV 0x00002000
314#define VB2_302ELV 0x00004000
315#define VB2_307LV 0x00008000
316#define VB2_30xBDH 0x08000000 /* 30xB DH version (w/o LCD support) */
317#define VB2_CONEXANT 0x10000000
318#define VB2_TRUMPION 0x20000000
319#define VB2_LVDS 0x40000000
320#define VB2_CHRONTEL 0x80000000
321
322#define VB2_SISLVDSBRIDGE (VB2_301LV | VB2_302LV | VB2_302ELV | VB2_307LV)
323#define VB2_SISTMDSBRIDGE (VB2_301 | VB2_301B | VB2_301C | VB2_302B | VB2_307T)
324#define VB2_SISBRIDGE (VB2_SISLVDSBRIDGE | VB2_SISTMDSBRIDGE)
325
326#define VB2_SISTMDSLCDABRIDGE (VB2_301C | VB2_307T)
327#define VB2_SISLCDABRIDGE (VB2_SISTMDSLCDABRIDGE | VB2_301LV | VB2_302LV | VB2_302ELV | VB2_307LV)
328
329#define VB2_SISHIVISIONBRIDGE (VB2_301 | VB2_301B | VB2_302B)
330#define VB2_SISYPBPRBRIDGE (VB2_301C | VB2_307T | VB2_SISLVDSBRIDGE)
331#define VB2_SISYPBPRARBRIDGE (VB2_301C | VB2_307T | VB2_307LV)
332#define VB2_SISTAP4SCALER (VB2_301C | VB2_307T | VB2_302ELV | VB2_307LV)
333#define VB2_SISTVBRIDGE (VB2_SISHIVISIONBRIDGE | VB2_SISYPBPRBRIDGE)
334
335#define VB2_SISVGA2BRIDGE (VB2_301 | VB2_301B | VB2_301C | VB2_302B | VB2_307T)
336
337#define VB2_VIDEOBRIDGE (VB2_SISBRIDGE | VB2_LVDS | VB2_CHRONTEL | VB2_CONEXANT)
338
339#define VB2_30xB (VB2_301B | VB2_301C | VB2_302B | VB2_307T)
340#define VB2_30xBLV (VB2_30xB | VB2_SISLVDSBRIDGE)
341#define VB2_30xC (VB2_301C | VB2_307T)
342#define VB2_30xCLV (VB2_301C | VB2_307T | VB2_302ELV| VB2_307LV)
343#define VB2_SISEMIBRIDGE (VB2_302LV | VB2_302ELV | VB2_307LV)
344#define VB2_LCD162MHZBRIDGE (VB2_301C | VB2_307T)
345#define VB2_LCDOVER1280BRIDGE (VB2_301C | VB2_307T | VB2_302LV | VB2_302ELV | VB2_307LV)
346#define VB2_LCDOVER1600BRIDGE (VB2_307T | VB2_307LV)
347#define VB2_RAMDAC202MHZBRIDGE (VB2_301C | VB2_307T)
251 348
252/* I/O port access macros */ 349/* I/O port access macros */
253#define inSISREG(base) inb(base) 350#define inSISREG(base) inb(base)
254 351
255#define outSISREG(base,val) outb(val,base) 352#define outSISREG(base,val) outb(val,base)
256 353
257#define orSISREG(base,val) \ 354#define orSISREG(base,val) \
258 do { \ 355 do { \
259 u8 __Temp = inSISREG(base); \ 356 u8 __Temp = inSISREG(base); \
260 outSISREG(base, __Temp | (val)); \ 357 outSISREG(base, __Temp | (val));\
261 } while (0) 358 } while (0)
262 359
263#define andSISREG(base,val) \ 360#define andSISREG(base,val) \
264 do { \ 361 do { \
265 u8 __Temp = inSISREG(base); \ 362 u8 __Temp = inSISREG(base); \
266 outSISREG(base, __Temp & (val)); \ 363 outSISREG(base, __Temp & (val));\
267 } while (0) 364 } while (0)
268 365
269#define inSISIDXREG(base,idx,var) \ 366#define inSISIDXREG(base,idx,var) \
270 do { \ 367 do { \
271 outSISREG(base, idx); \ 368 outSISREG(base, idx); \
272 var = inSISREG((base)+1); \ 369 var = inSISREG((base)+1); \
273 } while (0) 370 } while (0)
274 371
275#define outSISIDXREG(base,idx,val) \ 372#define outSISIDXREG(base,idx,val) \
276 do { \ 373 do { \
277 outSISREG(base, idx); \ 374 outSISREG(base, idx); \
278 outSISREG((base)+1, val); \ 375 outSISREG((base)+1, val); \
279 } while (0) 376 } while (0)
280 377
281#define orSISIDXREG(base,idx,val) \ 378#define orSISIDXREG(base,idx,val) \
282 do { \ 379 do { \
283 u8 __Temp; \ 380 u8 __Temp; \
284 outSISREG(base, idx); \ 381 outSISREG(base, idx); \
285 __Temp = inSISREG((base)+1) | (val); \ 382 __Temp = inSISREG((base)+1) | (val); \
286 outSISREG((base)+1, __Temp); \ 383 outSISREG((base)+1, __Temp); \
287 } while (0) 384 } while (0)
288 385
289#define andSISIDXREG(base,idx,and) \ 386#define andSISIDXREG(base,idx,and) \
290 do { \ 387 do { \
291 u8 __Temp; \ 388 u8 __Temp; \
292 outSISREG(base, idx); \ 389 outSISREG(base, idx); \
293 __Temp = inSISREG((base)+1) & (and); \ 390 __Temp = inSISREG((base)+1) & (and); \
294 outSISREG((base)+1, __Temp); \ 391 outSISREG((base)+1, __Temp); \
295 } while (0) 392 } while (0)
296 393
297#define setSISIDXREG(base,idx,and,or) \ 394#define setSISIDXREG(base,idx,and,or) \
298 do { \ 395 do { \
299 u8 __Temp; \ 396 u8 __Temp; \
300 outSISREG(base, idx); \ 397 outSISREG(base, idx); \
301 __Temp = (inSISREG((base)+1) & (and)) | (or); \ 398 __Temp = (inSISREG((base)+1) & (and)) | (or); \
302 outSISREG((base)+1, __Temp); \ 399 outSISREG((base)+1, __Temp); \
303 } while (0) 400 } while (0)
304 401
305/* MMIO access macros */ 402/* MMIO access macros */
306#define MMIO_IN8(base, offset) readb((base+offset)) 403#define MMIO_IN8(base, offset) readb((base+offset))
@@ -322,19 +419,19 @@
322#define MMIO_QUEUE_READPORT Q_READ_PTR 419#define MMIO_QUEUE_READPORT Q_READ_PTR
323 420
324#ifndef FB_BLANK_UNBLANK 421#ifndef FB_BLANK_UNBLANK
325#define FB_BLANK_UNBLANK 0 422#define FB_BLANK_UNBLANK 0
326#endif 423#endif
327#ifndef FB_BLANK_NORMAL 424#ifndef FB_BLANK_NORMAL
328#define FB_BLANK_NORMAL 1 425#define FB_BLANK_NORMAL 1
329#endif 426#endif
330#ifndef FB_BLANK_VSYNC_SUSPEND 427#ifndef FB_BLANK_VSYNC_SUSPEND
331#define FB_BLANK_VSYNC_SUSPEND 2 428#define FB_BLANK_VSYNC_SUSPEND 2
332#endif 429#endif
333#ifndef FB_BLANK_HSYNC_SUSPEND 430#ifndef FB_BLANK_HSYNC_SUSPEND
334#define FB_BLANK_HSYNC_SUSPEND 3 431#define FB_BLANK_HSYNC_SUSPEND 3
335#endif 432#endif
336#ifndef FB_BLANK_POWERDOWN 433#ifndef FB_BLANK_POWERDOWN
337#define FB_BLANK_POWERDOWN 4 434#define FB_BLANK_POWERDOWN 4
338#endif 435#endif
339 436
340enum _SIS_LCD_TYPE { 437enum _SIS_LCD_TYPE {
@@ -347,18 +444,19 @@ enum _SIS_LCD_TYPE {
347 LCD_1600x1200, 444 LCD_1600x1200,
348 LCD_1920x1440, 445 LCD_1920x1440,
349 LCD_2048x1536, 446 LCD_2048x1536,
350 LCD_320x480, /* FSTN */ 447 LCD_320x240, /* FSTN */
351 LCD_1400x1050, 448 LCD_1400x1050,
352 LCD_1152x864, 449 LCD_1152x864,
353 LCD_1152x768, 450 LCD_1152x768,
354 LCD_1280x768, 451 LCD_1280x768,
355 LCD_1024x600, 452 LCD_1024x600,
356 LCD_640x480_2, /* DSTN */ 453 LCD_320x240_2, /* DSTN */
357 LCD_640x480_3, /* DSTN */ 454 LCD_320x240_3, /* DSTN */
358 LCD_848x480, 455 LCD_848x480,
359 LCD_1280x800, 456 LCD_1280x800,
360 LCD_1680x1050, 457 LCD_1680x1050,
361 LCD_1280x720, 458 LCD_1280x720,
459 LCD_1280x854,
362 LCD_CUSTOM, 460 LCD_CUSTOM,
363 LCD_UNKNOWN 461 LCD_UNKNOWN
364}; 462};
@@ -368,31 +466,50 @@ enum _SIS_CMDTYPE {
368 AGP_CMD_QUEUE, 466 AGP_CMD_QUEUE,
369 VM_CMD_QUEUE, 467 VM_CMD_QUEUE,
370}; 468};
371typedef unsigned int SIS_CMDTYPE; 469
470struct SIS_OH {
471 struct SIS_OH *poh_next;
472 struct SIS_OH *poh_prev;
473 u32 offset;
474 u32 size;
475};
476
477struct SIS_OHALLOC {
478 struct SIS_OHALLOC *poha_next;
479 struct SIS_OH aoh[1];
480};
481
482struct SIS_HEAP {
483 struct SIS_OH oh_free;
484 struct SIS_OH oh_used;
485 struct SIS_OH *poh_freelist;
486 struct SIS_OHALLOC *poha_chain;
487 u32 max_freesize;
488 struct sis_video_info *vinfo;
489};
372 490
373/* Our "par" */ 491/* Our "par" */
374struct sis_video_info { 492struct sis_video_info {
375 int cardnumber; 493 int cardnumber;
376 struct fb_info *memyselfandi; 494 struct fb_info *memyselfandi;
377 495
378 SIS_HW_INFO sishw_ext; 496 struct SiS_Private SiS_Pr;
379 SiS_Private SiS_Pr;
380 497
381 sisfb_info sisfbinfo; /* For ioctl SISFB_GET_INFO */ 498 struct sisfb_info sisfbinfo; /* For ioctl SISFB_GET_INFO */
382 499
383 struct fb_var_screeninfo default_var; 500 struct fb_var_screeninfo default_var;
384 501
385#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 502#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
386 struct fb_fix_screeninfo sisfb_fix; 503 struct fb_fix_screeninfo sisfb_fix;
387 u32 pseudo_palette[17]; 504 u32 pseudo_palette[17];
388#endif 505#endif
389 506
390#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 507#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
391 struct display sis_disp; 508 struct display sis_disp;
392 struct display_switch sisfb_sw; 509 struct display_switch sisfb_sw;
393 struct { 510 struct {
394 u16 red, green, blue, pad; 511 u16 red, green, blue, pad;
395 } sis_palette[256]; 512 } sis_palette[256];
396 union { 513 union {
397#ifdef FBCON_HAS_CFB16 514#ifdef FBCON_HAS_CFB16
398 u16 cfb16[16]; 515 u16 cfb16[16];
@@ -400,10 +517,10 @@ struct sis_video_info {
400#ifdef FBCON_HAS_CFB32 517#ifdef FBCON_HAS_CFB32
401 u32 cfb32[16]; 518 u32 cfb32[16];
402#endif 519#endif
403 } sis_fbcon_cmap; 520 } sis_fbcon_cmap;
404#endif 521#endif
405 522
406 struct sisfb_monitor { 523 struct sisfb_monitor {
407 u16 hmin; 524 u16 hmin;
408 u16 hmax; 525 u16 hmax;
409 u16 vmin; 526 u16 vmin;
@@ -411,163 +528,166 @@ struct sis_video_info {
411 u32 dclockmax; 528 u32 dclockmax;
412 u8 feature; 529 u8 feature;
413 BOOLEAN datavalid; 530 BOOLEAN datavalid;
414 } sisfb_thismonitor; 531 } sisfb_thismonitor;
415 532
416 int chip_id; 533 unsigned short chip_id; /* PCI ID of chip */
534 unsigned short chip_vendor; /* PCI ID of vendor */
417 char myid[40]; 535 char myid[40];
418 536
419 struct pci_dev *nbridge; 537 struct pci_dev *nbridge;
538 struct pci_dev *lpcdev;
420 539
421 int mni; /* Mode number index */ 540 int mni; /* Mode number index */
422 541
423#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 542#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
424 int currcon; 543 int currcon;
425#endif 544#endif
426 545
427 unsigned long video_size; 546 unsigned long video_size;
428 unsigned long video_base; 547 unsigned long video_base;
429 unsigned long mmio_size; 548 unsigned long mmio_size;
430 unsigned long mmio_base; 549 unsigned long mmio_base;
431 unsigned long vga_base; 550 unsigned long vga_base;
551
552 unsigned long video_offset;
432 553
433 SIS_IOTYPE1 *video_vbase; 554 unsigned long UMAsize, LFBsize;
434 SIS_IOTYPE1 *mmio_vbase;
435 555
436 unsigned char *bios_abase; 556 SIS_IOTYPE1 *video_vbase;
557 SIS_IOTYPE1 *mmio_vbase;
437 558
438 int mtrr; 559 unsigned char *bios_abase;
560
561 int mtrr;
439 562
440 u32 sisfb_mem; 563 u32 sisfb_mem;
441 564
442 u32 sisfb_parm_mem; 565 u32 sisfb_parm_mem;
443 int sisfb_accel; 566 int sisfb_accel;
444 int sisfb_ypan; 567 int sisfb_ypan;
445 int sisfb_max; 568 int sisfb_max;
446 int sisfb_userom; 569 int sisfb_userom;
447 int sisfb_useoem; 570 int sisfb_useoem;
448 int sisfb_mode_idx; 571 int sisfb_mode_idx;
449 int sisfb_parm_rate; 572 int sisfb_parm_rate;
450 int sisfb_crt1off; 573 int sisfb_crt1off;
451 int sisfb_forcecrt1; 574 int sisfb_forcecrt1;
452 int sisfb_crt2type; 575 int sisfb_crt2type;
453 int sisfb_crt2flags; 576 int sisfb_crt2flags;
454 int sisfb_dstn; 577 int sisfb_dstn;
455 int sisfb_fstn; 578 int sisfb_fstn;
456 int sisfb_tvplug; 579 int sisfb_tvplug;
457 int sisfb_tvstd; 580 int sisfb_tvstd;
458 int sisfb_filter;
459 int sisfb_nocrt2rate; 581 int sisfb_nocrt2rate;
460#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 582#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
461 int sisfb_inverse; 583 int sisfb_inverse;
462#endif 584#endif
463 585
464 u32 heapstart; /* offset */ 586 u32 heapstart; /* offset */
465 SIS_IOTYPE1 *sisfb_heap_start; /* address */ 587 SIS_IOTYPE1 *sisfb_heap_start; /* address */
466 SIS_IOTYPE1 *sisfb_heap_end; /* address */ 588 SIS_IOTYPE1 *sisfb_heap_end; /* address */
467 u32 sisfb_heap_size; 589 u32 sisfb_heap_size;
468 int havenoheap; 590 int havenoheap;
469#if 0
470 SIS_HEAP sisfb_heap;
471#endif
472 591
592 struct SIS_HEAP sisfb_heap; /* This card's vram heap */
473 593
474 int video_bpp; 594 int video_bpp;
475 int video_cmap_len; 595 int video_cmap_len;
476 int video_width; 596 int video_width;
477 int video_height; 597 int video_height;
478 unsigned int refresh_rate; 598 unsigned int refresh_rate;
479 599
480 unsigned int chip; 600 unsigned int chip;
481 u8 revision_id; 601 u8 revision_id;
602 int sisvga_enabled; /* PCI device was enabled */
482 603
483 int video_linelength; /* real pitch */ 604 int video_linelength; /* real pitch */
484 int scrnpitchCRT1; /* pitch regarding interlace */ 605 int scrnpitchCRT1; /* pitch regarding interlace */
485 606
486 u16 DstColor; /* For 2d acceleration */ 607 u16 DstColor; /* For 2d acceleration */
487 u32 SiS310_AccelDepth; 608 u32 SiS310_AccelDepth;
488 u32 CommandReg; 609 u32 CommandReg;
489 int cmdqueuelength; 610 int cmdqueuelength; /* Current (for accel) */
611 u32 cmdQueueSize; /* Total size in KB */
490 612
491 spinlock_t lockaccel; /* Do not use outside of kernel! */ 613 spinlock_t lockaccel; /* Do not use outside of kernel! */
492 614
493 unsigned int pcibus; 615 unsigned int pcibus;
494 unsigned int pcislot; 616 unsigned int pcislot;
495 unsigned int pcifunc; 617 unsigned int pcifunc;
496 618
497 int accel; 619 int accel;
620 int engineok;
498 621
499 u16 subsysvendor; 622 u16 subsysvendor;
500 u16 subsysdevice; 623 u16 subsysdevice;
501 624
502 u32 vbflags; /* Replacing deprecated stuff from above */ 625 u32 vbflags; /* Replacing deprecated stuff from above */
503 u32 currentvbflags; 626 u32 currentvbflags;
627 u32 vbflags2;
504 628
505 int lcdxres, lcdyres; 629 int lcdxres, lcdyres;
506 int lcddefmodeidx, tvdefmodeidx, defmodeidx; 630 int lcddefmodeidx, tvdefmodeidx, defmodeidx;
507 u32 CRT2LCDType; /* defined in "SIS_LCD_TYPE" */ 631 u32 CRT2LCDType; /* defined in "SIS_LCD_TYPE" */
508 632 u32 curFSTN, curDSTN;
509 int current_bpp; 633
510 int current_width; 634 int current_bpp;
511 int current_height; 635 int current_width;
512 int current_htotal; 636 int current_height;
513 int current_vtotal; 637 int current_htotal;
638 int current_vtotal;
514 int current_linelength; 639 int current_linelength;
515 __u32 current_pixclock; 640 __u32 current_pixclock;
516 int current_refresh_rate; 641 int current_refresh_rate;
642
643 unsigned int current_base;
517 644
518 u8 mode_no; 645 u8 mode_no;
519 u8 rate_idx; 646 u8 rate_idx;
520 int modechanged; 647 int modechanged;
521 unsigned char modeprechange; 648 unsigned char modeprechange;
522 649
523#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 650#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
524 u8 sisfb_lastrates[128]; 651 u8 sisfb_lastrates[128];
525#endif 652#endif
526 653
527 int newrom; 654 int newrom;
528 int registered; 655 int haveXGIROM;
656 int registered;
529 int warncount; 657 int warncount;
658#ifdef SIS_OLD_CONFIG_COMPAT
659 int ioctl32registered;
660#endif
530 661
531 int sisvga_engine; 662 int sisvga_engine;
532 int hwcursor_size; 663 int hwcursor_size;
533 int CRT2_write_enable; 664 int CRT2_write_enable;
534 u8 caps; 665 u8 caps;
535 666
536 u8 detectedpdc; 667 u8 detectedpdc;
537 u8 detectedpdca; 668 u8 detectedpdca;
538 u8 detectedlcda; 669 u8 detectedlcda;
539 670
540 SIS_IOTYPE1 *hwcursor_vbase; 671 SIS_IOTYPE1 *hwcursor_vbase;
541 672
542 int chronteltype; 673 int chronteltype;
543 int tvxpos, tvypos; 674 int tvxpos, tvypos;
544 u8 p2_1f,p2_20,p2_2b,p2_42,p2_43,p2_01,p2_02; 675 u8 p2_1f,p2_20,p2_2b,p2_42,p2_43,p2_01,p2_02;
545 int tvx, tvy; 676 int tvx, tvy;
546 677
547 u8 sisfblocked; 678 u8 sisfblocked;
679
680 struct sisfb_info sisfb_infoblock;
681
682 struct sisfb_cmd sisfb_command;
683
684 u32 sisfb_id;
685
686 u8 sisfb_can_post;
687 u8 sisfb_card_posted;
688 u8 sisfb_was_boot_device;
548 689
549 struct sis_video_info *next; 690 struct sis_video_info *next;
550}; 691};
551 692
552typedef struct _SIS_OH {
553 struct _SIS_OH *poh_next;
554 struct _SIS_OH *poh_prev;
555 u32 offset;
556 u32 size;
557} SIS_OH;
558
559typedef struct _SIS_OHALLOC {
560 struct _SIS_OHALLOC *poha_next;
561 SIS_OH aoh[1];
562} SIS_OHALLOC;
563
564typedef struct _SIS_HEAP {
565 SIS_OH oh_free;
566 SIS_OH oh_used;
567 SIS_OH *poh_freelist;
568 SIS_OHALLOC *poha_chain;
569 u32 max_freesize;
570 struct sis_video_info *vinfo;
571} SIS_HEAP;
572
573#endif 693#endif
diff --git a/drivers/video/sis/sis_accel.c b/drivers/video/sis/sis_accel.c
index 30e90a553e..bab933e6c6 100644
--- a/drivers/video/sis/sis_accel.c
+++ b/drivers/video/sis/sis_accel.c
@@ -1,6 +1,8 @@
1/* 1/*
2 * SiS 300/630/730/540/315/550/65x/74x/330/760 frame buffer driver 2 * SiS 300/540/630[S]/730[S],
3 * for Linux kernels 2.4.x and 2.6.x 3 * SiS 315[E|PRO]/550/[M]650/651/[M]661[F|M]X/740/[M]741[GX]/330/[M]760[GX],
4 * XGI V3XT/V5/V8, Z7
5 * frame buffer driver for Linux kernels >= 2.4.14 and >=2.6.3
4 * 6 *
5 * 2D acceleration part 7 * 2D acceleration part
6 * 8 *
@@ -19,7 +21,7 @@
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
20 * 22 *
21 * Based on the XFree86/X.org driver which is 23 * Based on the XFree86/X.org driver which is
22 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria 24 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
23 * 25 *
24 * Author: Thomas Winischhofer <thomas@winischhofer.net> 26 * Author: Thomas Winischhofer <thomas@winischhofer.net>
25 * (see http://www.winischhofer.net/ 27 * (see http://www.winischhofer.net/
@@ -30,13 +32,11 @@
30#include <linux/version.h> 32#include <linux/version.h>
31#include <linux/module.h> 33#include <linux/module.h>
32#include <linux/kernel.h> 34#include <linux/kernel.h>
33#include <linux/errno.h>
34#include <linux/fb.h> 35#include <linux/fb.h>
36#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
35#include <linux/console.h> 37#include <linux/console.h>
36#include <linux/selection.h> 38#endif
37#include <linux/ioport.h> 39#include <linux/ioport.h>
38#include <linux/capability.h>
39#include <linux/fs.h>
40#include <linux/types.h> 40#include <linux/types.h>
41 41
42#include <asm/io.h> 42#include <asm/io.h>
@@ -188,7 +188,7 @@ SiS300SubsequentSolidFillRect(struct sis_video_info *ivideo, int x, int y, int w
188} 188}
189#endif 189#endif
190 190
191/* 315/330 series ------------------------------------------------- */ 191/* 315/330/340 series ---------------------------------------------- */
192 192
193#ifdef CONFIG_FB_SIS_315 193#ifdef CONFIG_FB_SIS_315
194static void 194static void
@@ -202,7 +202,7 @@ SiS310SetupForScreenToScreenCopy(struct sis_video_info *ivideo, int rop, int tra
202{ 202{
203 SiS310SetupDSTColorDepth(ivideo->DstColor); 203 SiS310SetupDSTColorDepth(ivideo->DstColor);
204 SiS310SetupSRCPitch(ivideo->video_linelength) 204 SiS310SetupSRCPitch(ivideo->video_linelength)
205 SiS310SetupDSTRect(ivideo->video_linelength, 0xffff) 205 SiS310SetupDSTRect(ivideo->video_linelength, 0x0fff)
206 if(trans_color != -1) { 206 if(trans_color != -1) {
207 SiS310SetupROP(0x0A) 207 SiS310SetupROP(0x0A)
208 SiS310SetupSRCTrans(trans_color) 208 SiS310SetupSRCTrans(trans_color)
@@ -213,7 +213,7 @@ SiS310SetupForScreenToScreenCopy(struct sis_video_info *ivideo, int rop, int tra
213 /* SiSSetupCMDFlag(BITBLT | SRCVIDEO) */ 213 /* SiSSetupCMDFlag(BITBLT | SRCVIDEO) */
214 } 214 }
215 SiS310SetupCMDFlag(ivideo->SiS310_AccelDepth) 215 SiS310SetupCMDFlag(ivideo->SiS310_AccelDepth)
216 /* The 315 series is smart enough to know the direction */ 216 /* The chip is smart enough to know the direction */
217} 217}
218 218
219static void 219static void
@@ -223,35 +223,38 @@ SiS310SubsequentScreenToScreenCopy(struct sis_video_info *ivideo, int src_x, int
223 u32 srcbase = 0, dstbase = 0; 223 u32 srcbase = 0, dstbase = 0;
224 int mymin = min(src_y, dst_y); 224 int mymin = min(src_y, dst_y);
225 int mymax = max(src_y, dst_y); 225 int mymax = max(src_y, dst_y);
226 226
227 /* Although the chip knows the direction to use 227 /* Although the chip knows the direction to use
228 * if the source and destination areas overlap, 228 * if the source and destination areas overlap,
229 * that logic fails if we fiddle with the bitmap 229 * that logic fails if we fiddle with the bitmap
230 * addresses. Therefore, we check if the source 230 * addresses. Therefore, we check if the source
231 * and destination blitting areas overlap and 231 * and destination blitting areas overlap and
232 * adapt the bitmap addresses synchronously 232 * adapt the bitmap addresses synchronously
233 * if the coordinates exceed the valid range. 233 * if the coordinates exceed the valid range.
234 * The the areas do not overlap, we do our 234 * The the areas do not overlap, we do our
235 * normal check. 235 * normal check.
236 */ 236 */
237 if((mymax - mymin) < height) { 237 if((mymax - mymin) < height) {
238 if((src_y >= 2048) || (dst_y >= 2048)) { 238 if((src_y >= 2048) || (dst_y >= 2048)) {
239 srcbase = ivideo->video_linelength * mymin; 239 srcbase = ivideo->video_linelength * mymin;
240 dstbase = ivideo->video_linelength * mymin; 240 dstbase = ivideo->video_linelength * mymin;
241 src_y -= mymin; 241 src_y -= mymin;
242 dst_y -= mymin; 242 dst_y -= mymin;
243 } 243 }
244 } else { 244 } else {
245 if(src_y >= 2048) { 245 if(src_y >= 2048) {
246 srcbase = ivideo->video_linelength * src_y; 246 srcbase = ivideo->video_linelength * src_y;
247 src_y = 0; 247 src_y = 0;
248 } 248 }
249 if(dst_y >= 2048) { 249 if(dst_y >= 2048) {
250 dstbase = ivideo->video_linelength * dst_y; 250 dstbase = ivideo->video_linelength * dst_y;
251 dst_y = 0; 251 dst_y = 0;
252 } 252 }
253 } 253 }
254 254
255 srcbase += ivideo->video_offset;
256 dstbase += ivideo->video_offset;
257
255 SiS310SetupSRCBase(srcbase); 258 SiS310SetupSRCBase(srcbase);
256 SiS310SetupDSTBase(dstbase); 259 SiS310SetupDSTBase(dstbase);
257 SiS310SetupRect(width, height) 260 SiS310SetupRect(width, height)
@@ -264,7 +267,7 @@ static void
264SiS310SetupForSolidFill(struct sis_video_info *ivideo, u32 color, int rop) 267SiS310SetupForSolidFill(struct sis_video_info *ivideo, u32 color, int rop)
265{ 268{
266 SiS310SetupPATFG(color) 269 SiS310SetupPATFG(color)
267 SiS310SetupDSTRect(ivideo->video_linelength, 0xffff) 270 SiS310SetupDSTRect(ivideo->video_linelength, 0x0fff)
268 SiS310SetupDSTColorDepth(ivideo->DstColor); 271 SiS310SetupDSTColorDepth(ivideo->DstColor);
269 SiS310SetupROP(sisPatALUConv[rop]) 272 SiS310SetupROP(sisPatALUConv[rop])
270 SiS310SetupCMDFlag(PATFG | ivideo->SiS310_AccelDepth) 273 SiS310SetupCMDFlag(PATFG | ivideo->SiS310_AccelDepth)
@@ -279,6 +282,7 @@ SiS310SubsequentSolidFillRect(struct sis_video_info *ivideo, int x, int y, int w
279 dstbase = ivideo->video_linelength * y; 282 dstbase = ivideo->video_linelength * y;
280 y = 0; 283 y = 0;
281 } 284 }
285 dstbase += ivideo->video_offset;
282 SiS310SetupDSTBase(dstbase) 286 SiS310SetupDSTBase(dstbase)
283 SiS310SetupDSTXY(x,y) 287 SiS310SetupDSTXY(x,y)
284 SiS310SetupRect(w,h) 288 SiS310SetupRect(w,h)
@@ -294,384 +298,153 @@ SiS310SubsequentSolidFillRect(struct sis_video_info *ivideo, int x, int y, int w
294int sisfb_initaccel(struct sis_video_info *ivideo) 298int sisfb_initaccel(struct sis_video_info *ivideo)
295{ 299{
296#ifdef SISFB_USE_SPINLOCKS 300#ifdef SISFB_USE_SPINLOCKS
297 spin_lock_init(&ivideo->lockaccel); 301 spin_lock_init(&ivideo->lockaccel);
298#endif 302#endif
299 return(0); 303 return 0;
300} 304}
301 305
302void sisfb_syncaccel(struct sis_video_info *ivideo) 306void sisfb_syncaccel(struct sis_video_info *ivideo)
303{ 307{
304 if(ivideo->sisvga_engine == SIS_300_VGA) { 308 if(ivideo->sisvga_engine == SIS_300_VGA) {
305#ifdef CONFIG_FB_SIS_300 309#ifdef CONFIG_FB_SIS_300
306 SiS300Sync(ivideo); 310 SiS300Sync(ivideo);
307#endif 311#endif
308 } else { 312 } else {
309#ifdef CONFIG_FB_SIS_315 313#ifdef CONFIG_FB_SIS_315
310 SiS310Sync(ivideo); 314 SiS310Sync(ivideo);
311#endif 315#endif
312 } 316 }
313} 317}
314 318
315#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) /* --------------- 2.5 --------------- */ 319#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) /* --------------- 2.5 --------------- */
316 320
317int fbcon_sis_sync(struct fb_info *info) 321int fbcon_sis_sync(struct fb_info *info)
318{ 322{
319 struct sis_video_info *ivideo = (struct sis_video_info *)info->par; 323 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
320 CRITFLAGS 324 CRITFLAGS
321 325
322 if(!ivideo->accel) 326 if((!ivideo->accel) || (!ivideo->engineok))
323 return 0; 327 return 0;
324 328
325 if(ivideo->sisvga_engine == SIS_300_VGA) { 329 CRITBEGIN
326#ifdef CONFIG_FB_SIS_300 330 sisfb_syncaccel(ivideo);
327 SiS300Sync(ivideo); 331 CRITEND
328#endif 332
329 } else { 333 return 0;
330#ifdef CONFIG_FB_SIS_315
331 SiS310Sync(ivideo);
332#endif
333 }
334 CRITEND
335 return 0;
336} 334}
337 335
338void fbcon_sis_fillrect(struct fb_info *info, const struct fb_fillrect *rect) 336void fbcon_sis_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
339{ 337{
340 struct sis_video_info *ivideo = (struct sis_video_info *)info->par; 338 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
341 u32 col = 0; 339 u32 col = 0;
342 u32 vxres = info->var.xres_virtual; 340 u32 vxres = info->var.xres_virtual;
343 u32 vyres = info->var.yres_virtual; 341 u32 vyres = info->var.yres_virtual;
344 int width, height; 342 int width, height;
345 CRITFLAGS 343 CRITFLAGS
346 344
347 if(info->state != FBINFO_STATE_RUNNING) { 345 if(info->state != FBINFO_STATE_RUNNING)
348 return; 346 return;
349 } 347
350 348 if((!ivideo->accel) || (!ivideo->engineok)) {
351 if(!ivideo->accel) { 349 cfb_fillrect(info, rect);
352 cfb_fillrect(info, rect); 350 return;
353 return; 351 }
354 } 352
355 353 if(!rect->width || !rect->height || rect->dx >= vxres || rect->dy >= vyres)
356 if(!rect->width || !rect->height || rect->dx >= vxres || rect->dy >= vyres) { 354 return;
357 return; 355
358 } 356 /* Clipping */
359 357 width = ((rect->dx + rect->width) > vxres) ? (vxres - rect->dx) : rect->width;
360 /* Clipping */ 358 height = ((rect->dy + rect->height) > vyres) ? (vyres - rect->dy) : rect->height;
361 width = ((rect->dx + rect->width) > vxres) ? (vxres - rect->dx) : rect->width; 359
362 height = ((rect->dy + rect->height) > vyres) ? (vyres - rect->dy) : rect->height; 360 switch(info->var.bits_per_pixel) {
363
364 switch(info->var.bits_per_pixel) {
365 case 8: col = rect->color; 361 case 8: col = rect->color;
366 break; 362 break;
367 case 16: 363 case 16:
368 case 32: col = ((u32 *)(info->pseudo_palette))[rect->color]; 364 case 32: col = ((u32 *)(info->pseudo_palette))[rect->color];
369 break; 365 break;
370 } 366 }
371 367
372 if(ivideo->sisvga_engine == SIS_300_VGA) { 368 if(ivideo->sisvga_engine == SIS_300_VGA) {
373#ifdef CONFIG_FB_SIS_300 369#ifdef CONFIG_FB_SIS_300
374 CRITBEGIN 370 CRITBEGIN
375 SiS300SetupForSolidFill(ivideo, col, myrops[rect->rop]); 371 SiS300SetupForSolidFill(ivideo, col, myrops[rect->rop]);
376 SiS300SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height); 372 SiS300SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height);
377 CRITEND 373 CRITEND
378 SiS300Sync(ivideo);
379#endif 374#endif
380 } else { 375 } else {
381#ifdef CONFIG_FB_SIS_315 376#ifdef CONFIG_FB_SIS_315
382 CRITBEGIN 377 CRITBEGIN
383 SiS310SetupForSolidFill(ivideo, col, myrops[rect->rop]); 378 SiS310SetupForSolidFill(ivideo, col, myrops[rect->rop]);
384 SiS310SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height); 379 SiS310SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height);
385 CRITEND 380 CRITEND
386 SiS310Sync(ivideo);
387#endif 381#endif
388 } 382 }
389 383
384 sisfb_syncaccel(ivideo);
390} 385}
391 386
392void fbcon_sis_copyarea(struct fb_info *info, const struct fb_copyarea *area) 387void fbcon_sis_copyarea(struct fb_info *info, const struct fb_copyarea *area)
393{ 388{
394 struct sis_video_info *ivideo = (struct sis_video_info *)info->par; 389 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
395 u32 vxres = info->var.xres_virtual; 390 u32 vxres = info->var.xres_virtual;
396 u32 vyres = info->var.yres_virtual; 391 u32 vyres = info->var.yres_virtual;
397 int width = area->width; 392 int width = area->width;
398 int height = area->height; 393 int height = area->height;
399 CRITFLAGS
400
401 if(info->state != FBINFO_STATE_RUNNING) {
402 return;
403 }
404
405 if(!ivideo->accel) {
406 cfb_copyarea(info, area);
407 return;
408 }
409
410 if(!width || !height ||
411 area->sx >= vxres || area->sy >= vyres ||
412 area->dx >= vxres || area->dy >= vyres) {
413 return;
414 }
415
416 /* Clipping */
417 if((area->sx + width) > vxres) width = vxres - area->sx;
418 if((area->dx + width) > vxres) width = vxres - area->dx;
419 if((area->sy + height) > vyres) height = vyres - area->sy;
420 if((area->dy + height) > vyres) height = vyres - area->dy;
421
422 if(ivideo->sisvga_engine == SIS_300_VGA) {
423#ifdef CONFIG_FB_SIS_300
424 int xdir, ydir;
425
426 if(area->sx < area->dx) xdir = 0;
427 else xdir = 1;
428 if(area->sy < area->dy) ydir = 0;
429 else ydir = 1;
430
431 CRITBEGIN
432 SiS300SetupForScreenToScreenCopy(ivideo, xdir, ydir, 3, -1);
433 SiS300SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy, area->dx, area->dy,
434 width, height);
435 CRITEND
436 SiS300Sync(ivideo);
437#endif
438 } else {
439#ifdef CONFIG_FB_SIS_315
440 CRITBEGIN
441 SiS310SetupForScreenToScreenCopy(ivideo, 3, -1);
442 SiS310SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy, area->dx, area->dy,
443 width, height);
444 CRITEND
445 SiS310Sync(ivideo);
446#endif
447 }
448}
449
450#endif
451
452#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* -------------- 2.4 --------------- */
453
454void fbcon_sis_bmove(struct display *p, int srcy, int srcx,
455 int dsty, int dstx, int height, int width)
456{
457 struct sis_video_info *ivideo = (struct sis_video_info *)p->fb_info->par;
458
459 CRITFLAGS 394 CRITFLAGS
460 395
461 if(!ivideo->accel) { 396 if(info->state != FBINFO_STATE_RUNNING)
462 switch(ivideo->video_bpp) { 397 return;
463 case 8:
464#ifdef FBCON_HAS_CFB8
465 fbcon_cfb8_bmove(p, srcy, srcx, dsty, dstx, height, width);
466#endif
467 break;
468 case 16:
469#ifdef FBCON_HAS_CFB16
470 fbcon_cfb16_bmove(p, srcy, srcx, dsty, dstx, height, width);
471#endif
472 break;
473 case 32:
474#ifdef FBCON_HAS_CFB32
475 fbcon_cfb32_bmove(p, srcy, srcx, dsty, dstx, height, width);
476#endif
477 break;
478 }
479 return;
480 }
481
482 srcx *= fontwidth(p);
483 srcy *= fontheight(p);
484 dstx *= fontwidth(p);
485 dsty *= fontheight(p);
486 width *= fontwidth(p);
487 height *= fontheight(p);
488 398
489 if(ivideo->sisvga_engine == SIS_300_VGA) { 399 if((!ivideo->accel) || (!ivideo->engineok)) {
490#ifdef CONFIG_FB_SIS_300 400 cfb_copyarea(info, area);
491 int xdir, ydir; 401 return;
492
493 if(srcx < dstx) xdir = 0;
494 else xdir = 1;
495 if(srcy < dsty) ydir = 0;
496 else ydir = 1;
497
498 CRITBEGIN
499 SiS300SetupForScreenToScreenCopy(ivideo, xdir, ydir, 3, -1);
500 SiS300SubsequentScreenToScreenCopy(ivideo, srcx, srcy, dstx, dsty, width, height);
501 CRITEND
502 SiS300Sync(ivideo);
503#endif
504 } else {
505#ifdef CONFIG_FB_SIS_315
506 CRITBEGIN
507 SiS310SetupForScreenToScreenCopy(ivideo, 3, -1);
508 SiS310SubsequentScreenToScreenCopy(ivideo, srcx, srcy, dstx, dsty, width, height);
509 CRITEND
510 SiS310Sync(ivideo);
511#endif
512 } 402 }
513}
514 403
515static void fbcon_sis_clear(struct vc_data *conp, struct display *p, 404 if(!width || !height ||
516 int srcy, int srcx, int height, int width, int color) 405 area->sx >= vxres || area->sy >= vyres ||
517{ 406 area->dx >= vxres || area->dy >= vyres)
518 struct sis_video_info *ivideo = (struct sis_video_info *)p->fb_info->par; 407 return;
519 CRITFLAGS
520 408
521 srcx *= fontwidth(p); 409 /* Clipping */
522 srcy *= fontheight(p); 410 if((area->sx + width) > vxres) width = vxres - area->sx;
523 width *= fontwidth(p); 411 if((area->dx + width) > vxres) width = vxres - area->dx;
524 height *= fontheight(p); 412 if((area->sy + height) > vyres) height = vyres - area->sy;
413 if((area->dy + height) > vyres) height = vyres - area->dy;
525 414
526 if(ivideo->sisvga_engine == SIS_300_VGA) { 415 if(ivideo->sisvga_engine == SIS_300_VGA) {
527#ifdef CONFIG_FB_SIS_300 416#ifdef CONFIG_FB_SIS_300
528 CRITBEGIN 417 int xdir, ydir;
529 SiS300SetupForSolidFill(ivideo, color, 3); 418
530 SiS300SubsequentSolidFillRect(ivideo, srcx, srcy, width, height); 419 if(area->sx < area->dx) xdir = 0;
531 CRITEND 420 else xdir = 1;
532 SiS300Sync(ivideo); 421 if(area->sy < area->dy) ydir = 0;
422 else ydir = 1;
423
424 CRITBEGIN
425 SiS300SetupForScreenToScreenCopy(ivideo, xdir, ydir, 3, -1);
426 SiS300SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy,
427 area->dx, area->dy, width, height);
428 CRITEND
533#endif 429#endif
534 } else { 430 } else {
535#ifdef CONFIG_FB_SIS_315 431#ifdef CONFIG_FB_SIS_315
536 CRITBEGIN 432 CRITBEGIN
537 SiS310SetupForSolidFill(ivideo, color, 3); 433 SiS310SetupForScreenToScreenCopy(ivideo, 3, -1);
538 SiS310SubsequentSolidFillRect(ivideo, srcx, srcy, width, height); 434 SiS310SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy,
539 CRITEND 435 area->dx, area->dy, width, height);
540 SiS310Sync(ivideo); 436 CRITEND
541#endif
542 }
543}
544
545void fbcon_sis_clear8(struct vc_data *conp, struct display *p,
546 int srcy, int srcx, int height, int width)
547{
548 struct sis_video_info *ivideo = (struct sis_video_info *)p->fb_info->par;
549 u32 bgx;
550
551 if(!ivideo->accel) {
552#ifdef FBCON_HAS_CFB8
553 fbcon_cfb8_clear(conp, p, srcy, srcx, height, width);
554#endif 437#endif
555 return;
556 } 438 }
557 439
558 bgx = attr_bgcol_ec(p, conp); 440 sisfb_syncaccel(ivideo);
559 fbcon_sis_clear(conp, p, srcy, srcx, height, width, bgx);
560} 441}
561 442
562void fbcon_sis_clear16(struct vc_data *conp, struct display *p,
563 int srcy, int srcx, int height, int width)
564{
565 struct sis_video_info *ivideo = (struct sis_video_info *)p->fb_info->par;
566 u32 bgx;
567
568 if(!ivideo->accel) {
569#ifdef FBCON_HAS_CFB16
570 fbcon_cfb16_clear(conp, p, srcy, srcx, height, width);
571#endif 443#endif
572 return;
573 }
574
575 bgx = ((u_int16_t*)p->dispsw_data)[attr_bgcol_ec(p, conp)];
576 fbcon_sis_clear(conp, p, srcy, srcx, height, width, bgx);
577}
578 444
579void fbcon_sis_clear32(struct vc_data *conp, struct display *p, 445#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* -------------- 2.4 --------------- */
580 int srcy, int srcx, int height, int width)
581{
582 struct sis_video_info *ivideo = (struct sis_video_info *)p->fb_info->par;
583 u32 bgx;
584
585 if(!ivideo->accel) {
586#ifdef FBCON_HAS_CFB32
587 fbcon_cfb32_clear(conp, p, srcy, srcx, height, width);
588#endif
589 return;
590 }
591
592 bgx = ((u_int32_t*)p->dispsw_data)[attr_bgcol_ec(p, conp)];
593 fbcon_sis_clear(conp, p, srcy, srcx, height, width, bgx);
594}
595
596void fbcon_sis_revc(struct display *p, int srcx, int srcy)
597{
598 struct sis_video_info *ivideo = (struct sis_video_info *)p->fb_info->par;
599 CRITFLAGS
600
601 if(!ivideo->accel) {
602 switch(ivideo->video_bpp) {
603 case 16:
604#ifdef FBCON_HAS_CFB16
605 fbcon_cfb16_revc(p, srcx, srcy);
606#endif
607 break;
608 case 32:
609#ifdef FBCON_HAS_CFB32
610 fbcon_cfb32_revc(p, srcx, srcy);
611#endif
612 break;
613 }
614 return;
615 }
616
617 srcx *= fontwidth(p);
618 srcy *= fontheight(p);
619
620 if(ivideo->sisvga_engine == SIS_300_VGA) {
621#ifdef CONFIG_FB_SIS_300
622 CRITBEGIN
623 SiS300SetupForSolidFill(ivideo, 0, 0x0a);
624 SiS300SubsequentSolidFillRect(ivideo, srcx, srcy, fontwidth(p), fontheight(p));
625 CRITEND
626 SiS300Sync(ivideo);
627#endif
628 } else {
629#ifdef CONFIG_FB_SIS_315
630 CRITBEGIN
631 SiS310SetupForSolidFill(ivideo, 0, 0x0a);
632 SiS310SubsequentSolidFillRect(ivideo, srcx, srcy, fontwidth(p), fontheight(p));
633 CRITEND
634 SiS310Sync(ivideo);
635#endif
636 }
637}
638 446
639#ifdef FBCON_HAS_CFB8 447#include "sisfb_accel_2_4.h"
640struct display_switch fbcon_sis8 = {
641 .setup = fbcon_cfb8_setup,
642 .bmove = fbcon_sis_bmove,
643 .clear = fbcon_sis_clear8,
644 .putc = fbcon_cfb8_putc,
645 .putcs = fbcon_cfb8_putcs,
646 .revc = fbcon_cfb8_revc,
647 .clear_margins = fbcon_cfb8_clear_margins,
648 .fontwidthmask = FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
649};
650#endif
651#ifdef FBCON_HAS_CFB16
652struct display_switch fbcon_sis16 = {
653 .setup = fbcon_cfb16_setup,
654 .bmove = fbcon_sis_bmove,
655 .clear = fbcon_sis_clear16,
656 .putc = fbcon_cfb16_putc,
657 .putcs = fbcon_cfb16_putcs,
658 .revc = fbcon_sis_revc,
659 .clear_margins = fbcon_cfb16_clear_margins,
660 .fontwidthmask = FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
661};
662#endif
663#ifdef FBCON_HAS_CFB32
664struct display_switch fbcon_sis32 = {
665 .setup = fbcon_cfb32_setup,
666 .bmove = fbcon_sis_bmove,
667 .clear = fbcon_sis_clear32,
668 .putc = fbcon_cfb32_putc,
669 .putcs = fbcon_cfb32_putcs,
670 .revc = fbcon_sis_revc,
671 .clear_margins = fbcon_cfb32_clear_margins,
672 .fontwidthmask = FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
673};
674#endif
675 448
676#endif /* KERNEL VERSION */ 449#endif /* KERNEL VERSION */
677 450
diff --git a/drivers/video/sis/sis_accel.h b/drivers/video/sis/sis_accel.h
index bb28f331d6..046e2c4a8e 100644
--- a/drivers/video/sis/sis_accel.h
+++ b/drivers/video/sis/sis_accel.h
@@ -1,6 +1,8 @@
1/* 1/*
2 * SiS 300/630/730/540/315/550/650/740 frame buffer driver 2 * SiS 300/540/630[S]/730[S],
3 * for Linux kernels 2.4.x and 2.5.x 3 * SiS 315[E|PRO]/550/[M]650/651/[M]661[F|M]X/740/[M]741[GX]/330/[M]760[GX],
4 * XGI V3XT/V5/V8, Z7
5 * frame buffer driver for Linux kernels >= 2.4.14 and >=2.6.3
4 * 6 *
5 * 2D acceleration part 7 * 2D acceleration part
6 * 8 *
@@ -283,6 +285,8 @@
283 { \ 285 { \
284 while( (MMIO_IN16(ivideo->mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){}; \ 286 while( (MMIO_IN16(ivideo->mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){}; \
285 while( (MMIO_IN16(ivideo->mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){}; \ 287 while( (MMIO_IN16(ivideo->mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){}; \
288 while( (MMIO_IN16(ivideo->mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){}; \
289 while( (MMIO_IN16(ivideo->mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){}; \
286 CmdQueLen = 0; \ 290 CmdQueLen = 0; \
287 } 291 }
288 292
@@ -402,6 +406,7 @@ void fbcon_sis_clear32(struct vc_data *conp, struct display *p, int srcy,
402 int srcx, int height, int width); 406 int srcx, int height, int width);
403#endif 407#endif
404#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,34) 408#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,34)
409int fbcon_sis_sync(struct fb_info *info);
405void fbcon_sis_fillrect(struct fb_info *info, const struct fb_fillrect *rect); 410void fbcon_sis_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
406void fbcon_sis_copyarea(struct fb_info *info, const struct fb_copyarea *area); 411void fbcon_sis_copyarea(struct fb_info *info, const struct fb_copyarea *area);
407#endif 412#endif
diff --git a/drivers/video/sis/sis_main.c b/drivers/video/sis/sis_main.c
index 6982660368..42c54b6972 100644
--- a/drivers/video/sis/sis_main.c
+++ b/drivers/video/sis/sis_main.c
@@ -1,9 +1,10 @@
1/* 1/*
2 * SiS 300/305/540/630(S)/730(S) 2 * SiS 300/540/630[S]/730[S],
3 * SiS 315(H/PRO)/55x/(M)65x/(M)661(F/M)X/740/741(GX)/330/(M)760 3 * SiS 315[E|PRO]/550/[M]65x/[M]66x[F|M|G]X/[M]74x[GX]/330/[M]76x[GX],
4 * XGI V3XT/V5/V8, Z7
4 * frame buffer driver for Linux kernels >= 2.4.14 and >=2.6.3 5 * frame buffer driver for Linux kernels >= 2.4.14 and >=2.6.3
5 * 6 *
6 * Copyright (C) 2001-2004 Thomas Winischhofer, Vienna, Austria. 7 * Copyright (C) 2001-2005 Thomas Winischhofer, Vienna, Austria.
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
@@ -19,11 +20,11 @@
19 * along with this program; if not, write to the Free Software 20 * 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 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
21 * 22 *
22 * Author: Thomas Winischhofer <thomas@winischhofer.net> 23 * Author: Thomas Winischhofer <thomas@winischhofer.net>
23 * 24 *
24 * Author of (practically wiped) code base: 25 * Author of (practically wiped) code base:
25 * SiS (www.sis.com) 26 * SiS (www.sis.com)
26 * Copyright (C) 1999 Silicon Integrated Systems, Inc. 27 * Copyright (C) 1999 Silicon Integrated Systems, Inc.
27 * 28 *
28 * See http://www.winischhofer.net/ for more information and updates 29 * See http://www.winischhofer.net/ for more information and updates
29 * 30 *
@@ -46,16 +47,15 @@
46#include <linux/mm.h> 47#include <linux/mm.h>
47#include <linux/tty.h> 48#include <linux/tty.h>
48#include <linux/slab.h> 49#include <linux/slab.h>
49#include <linux/delay.h>
50#include <linux/fb.h> 50#include <linux/fb.h>
51#include <linux/console.h>
52#include <linux/selection.h> 51#include <linux/selection.h>
53#include <linux/smp_lock.h>
54#include <linux/ioport.h> 52#include <linux/ioport.h>
55#include <linux/init.h> 53#include <linux/init.h>
56#include <linux/pci.h> 54#include <linux/pci.h>
57#include <linux/vmalloc.h> 55#include <linux/vmalloc.h>
56#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
58#include <linux/vt_kern.h> 57#include <linux/vt_kern.h>
58#endif
59#include <linux/capability.h> 59#include <linux/capability.h>
60#include <linux/fs.h> 60#include <linux/fs.h>
61#include <linux/types.h> 61#include <linux/types.h>
@@ -94,71 +94,75 @@ extern struct display_switch fbcon_sis32;
94#endif 94#endif
95#endif 95#endif
96 96
97static void sisfb_handle_command(struct sis_video_info *ivideo,
98 struct sisfb_cmd *sisfb_command);
99
97/* ------------------ Internal helper routines ----------------- */ 100/* ------------------ Internal helper routines ----------------- */
98 101
99static void __init 102static void __init
100sisfb_setdefaultparms(void) 103sisfb_setdefaultparms(void)
101{ 104{
102 sisfb_off = 0; 105 sisfb_off = 0;
103 sisfb_parm_mem = 0; 106 sisfb_parm_mem = 0;
104 sisfb_accel = -1; 107 sisfb_accel = -1;
105 sisfb_ypan = -1; 108 sisfb_ypan = -1;
106 sisfb_max = -1; 109 sisfb_max = -1;
107 sisfb_userom = -1; 110 sisfb_userom = -1;
108 sisfb_useoem = -1; 111 sisfb_useoem = -1;
109#ifdef MODULE 112#ifdef MODULE
110 /* Module: "None" for 2.4, default mode for 2.5+ */ 113 /* Module: "None" for 2.4, default mode for 2.5+ */
111#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 114#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
112 sisfb_mode_idx = -1; 115 sisfb_mode_idx = -1;
113#else 116#else
114 sisfb_mode_idx = MODE_INDEX_NONE; 117 sisfb_mode_idx = MODE_INDEX_NONE;
115#endif 118#endif
116#else 119#else
117 /* Static: Default mode */ 120 /* Static: Default mode */
118 sisfb_mode_idx = -1; 121 sisfb_mode_idx = -1;
119#endif 122#endif
120 sisfb_parm_rate = -1; 123 sisfb_parm_rate = -1;
121 sisfb_crt1off = 0; 124 sisfb_crt1off = 0;
122 sisfb_forcecrt1 = -1; 125 sisfb_forcecrt1 = -1;
123 sisfb_crt2type = -1; 126 sisfb_crt2type = -1;
124 sisfb_crt2flags = 0; 127 sisfb_crt2flags = 0;
125 sisfb_pdc = 0xff; 128 sisfb_pdc = 0xff;
126 sisfb_pdca = 0xff; 129 sisfb_pdca = 0xff;
127 sisfb_scalelcd = -1; 130 sisfb_scalelcd = -1;
128 sisfb_specialtiming = CUT_NONE; 131 sisfb_specialtiming = CUT_NONE;
129 sisfb_lvdshl = -1; 132 sisfb_lvdshl = -1;
130 sisfb_dstn = 0; 133 sisfb_dstn = 0;
131 sisfb_fstn = 0; 134 sisfb_fstn = 0;
132 sisfb_tvplug = -1; 135 sisfb_tvplug = -1;
133 sisfb_tvstd = -1; 136 sisfb_tvstd = -1;
134 sisfb_tvxposoffset = 0; 137 sisfb_tvxposoffset = 0;
135 sisfb_tvyposoffset = 0; 138 sisfb_tvyposoffset = 0;
136 sisfb_filter = -1; 139 sisfb_nocrt2rate = 0;
137 sisfb_nocrt2rate = 0;
138#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 140#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
139 sisfb_inverse = 0; 141 sisfb_inverse = 0;
140 sisfb_fontname[0] = 0; 142 sisfb_fontname[0] = 0;
141#endif 143#endif
142#if !defined(__i386__) && !defined(__x86_64__) 144#if !defined(__i386__) && !defined(__x86_64__)
143 sisfb_resetcard = 0; 145 sisfb_resetcard = 0;
144 sisfb_videoram = 0; 146 sisfb_videoram = 0;
145#endif 147#endif
146} 148}
147 149
150/* ------------- Parameter parsing -------------- */
151
148static void __devinit 152static void __devinit
149sisfb_search_vesamode(unsigned int vesamode, BOOLEAN quiet) 153sisfb_search_vesamode(unsigned int vesamode, BOOLEAN quiet)
150{ 154{
151 int i = 0, j = 0; 155 int i = 0, j = 0;
152 156
153 /* BEWARE: We don't know the hardware specs yet and there is no ivideo */ 157 /* We don't know the hardware specs yet and there is no ivideo */
154 158
155 if(vesamode == 0) { 159 if(vesamode == 0) {
156#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 160#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
157 sisfb_mode_idx = MODE_INDEX_NONE; 161 sisfb_mode_idx = MODE_INDEX_NONE;
158#else 162#else
159 if(!quiet) { 163 if(!quiet)
160 printk(KERN_ERR "sisfb: Invalid mode. Using default.\n"); 164 printk(KERN_ERR "sisfb: Invalid mode. Using default.\n");
161 } 165
162 sisfb_mode_idx = DEFAULT_MODE; 166 sisfb_mode_idx = DEFAULT_MODE;
163#endif 167#endif
164 return; 168 return;
@@ -169,95 +173,102 @@ sisfb_search_vesamode(unsigned int vesamode, BOOLEAN quiet)
169 while(sisbios_mode[i++].mode_no[0] != 0) { 173 while(sisbios_mode[i++].mode_no[0] != 0) {
170 if( (sisbios_mode[i-1].vesa_mode_no_1 == vesamode) || 174 if( (sisbios_mode[i-1].vesa_mode_no_1 == vesamode) ||
171 (sisbios_mode[i-1].vesa_mode_no_2 == vesamode) ) { 175 (sisbios_mode[i-1].vesa_mode_no_2 == vesamode) ) {
172 if(sisfb_fstn) { 176 if(sisfb_fstn) {
173 if(sisbios_mode[i-1].mode_no[1] == 0x50 || 177 if(sisbios_mode[i-1].mode_no[1] == 0x50 ||
174 sisbios_mode[i-1].mode_no[1] == 0x56 || 178 sisbios_mode[i-1].mode_no[1] == 0x56 ||
175 sisbios_mode[i-1].mode_no[1] == 0x53) continue; 179 sisbios_mode[i-1].mode_no[1] == 0x53)
176 } else { 180 continue;
177 if(sisbios_mode[i-1].mode_no[1] == 0x5a || 181 } else {
178 sisbios_mode[i-1].mode_no[1] == 0x5b) continue; 182 if(sisbios_mode[i-1].mode_no[1] == 0x5a ||
179 } 183 sisbios_mode[i-1].mode_no[1] == 0x5b)
180 sisfb_mode_idx = i - 1; 184 continue;
181 j = 1; 185 }
182 break; 186 sisfb_mode_idx = i - 1;
187 j = 1;
188 break;
183 } 189 }
184 } 190 }
185 if((!j) && !quiet) printk(KERN_ERR "sisfb: Invalid VESA mode 0x%x'\n", vesamode); 191 if((!j) && !quiet)
192 printk(KERN_ERR "sisfb: Invalid VESA mode 0x%x'\n", vesamode);
186} 193}
187 194
188static void 195static void __devinit
189sisfb_search_mode(char *name, BOOLEAN quiet) 196sisfb_search_mode(char *name, BOOLEAN quiet)
190{ 197{
191 int i = 0;
192 unsigned int j = 0, xres = 0, yres = 0, depth = 0, rate = 0; 198 unsigned int j = 0, xres = 0, yres = 0, depth = 0, rate = 0;
199 int i = 0;
193 char strbuf[16], strbuf1[20]; 200 char strbuf[16], strbuf1[20];
194 char *nameptr = name; 201 char *nameptr = name;
195 202
196 /* BEWARE: We don't know the hardware specs yet and there is no ivideo */ 203 /* We don't know the hardware specs yet and there is no ivideo */
197 204
198 if(name == NULL) { 205 if(name == NULL) {
199 if(!quiet) { 206 if(!quiet)
200 printk(KERN_ERR "sisfb: Internal error, using default mode.\n"); 207 printk(KERN_ERR "sisfb: Internal error, using default mode.\n");
201 } 208
202 sisfb_mode_idx = DEFAULT_MODE; 209 sisfb_mode_idx = DEFAULT_MODE;
203 return; 210 return;
204 } 211 }
205 212
206#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 213#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
207 if(!strnicmp(name, sisbios_mode[MODE_INDEX_NONE].name, strlen(name))) { 214 if(!strnicmp(name, sisbios_mode[MODE_INDEX_NONE].name, strlen(name))) {
208 if(!quiet) { 215 if(!quiet)
209 printk(KERN_ERR "sisfb: Mode 'none' not supported anymore. Using default.\n"); 216 printk(KERN_ERR "sisfb: Mode 'none' not supported anymore. Using default.\n");
210 } 217
211 sisfb_mode_idx = DEFAULT_MODE; 218 sisfb_mode_idx = DEFAULT_MODE;
212 return; 219 return;
213 } 220 }
214#endif 221#endif
215 if(strlen(name) <= 19) { 222 if(strlen(name) <= 19) {
216 strcpy(strbuf1, name); 223 strcpy(strbuf1, name);
217 for(i=0; i<strlen(strbuf1); i++) { 224 for(i = 0; i < strlen(strbuf1); i++) {
218 if(strbuf1[i] < '0' || strbuf1[i] > '9') strbuf1[i] = ' '; 225 if(strbuf1[i] < '0' || strbuf1[i] > '9') strbuf1[i] = ' ';
219 } 226 }
220 227
221 /* This does some fuzzy mode naming detection */ 228 /* This does some fuzzy mode naming detection */
222 if(sscanf(strbuf1, "%u %u %u %u", &xres, &yres, &depth, &rate) == 4) { 229 if(sscanf(strbuf1, "%u %u %u %u", &xres, &yres, &depth, &rate) == 4) {
223 if((rate <= 32) || (depth > 32)) { 230 if((rate <= 32) || (depth > 32)) {
224 j = rate; rate = depth; depth = j; 231 j = rate; rate = depth; depth = j;
225 } 232 }
226 sprintf(strbuf, "%ux%ux%u", xres, yres, depth); 233 sprintf(strbuf, "%ux%ux%u", xres, yres, depth);
227 nameptr = strbuf; 234 nameptr = strbuf;
228 sisfb_parm_rate = rate; 235 sisfb_parm_rate = rate;
229 } else if(sscanf(strbuf1, "%u %u %u", &xres, &yres, &depth) == 3) { 236 } else if(sscanf(strbuf1, "%u %u %u", &xres, &yres, &depth) == 3) {
230 sprintf(strbuf, "%ux%ux%u", xres, yres, depth); 237 sprintf(strbuf, "%ux%ux%u", xres, yres, depth);
231 nameptr = strbuf; 238 nameptr = strbuf;
232 } else { 239 } else {
233 xres = 0; 240 xres = 0;
234 if((sscanf(strbuf1, "%u %u", &xres, &yres) == 2) && (xres != 0)) { 241 if((sscanf(strbuf1, "%u %u", &xres, &yres) == 2) && (xres != 0)) {
235 sprintf(strbuf, "%ux%ux8", xres, yres); 242 sprintf(strbuf, "%ux%ux8", xres, yres);
236 nameptr = strbuf; 243 nameptr = strbuf;
237 } else { 244 } else {
238 sisfb_search_vesamode(simple_strtoul(name, NULL, 0), quiet); 245 sisfb_search_vesamode(simple_strtoul(name, NULL, 0), quiet);
239 return; 246 return;
240 } 247 }
241 } 248 }
242 } 249 }
243 250
244 i = 0; j = 0; 251 i = 0; j = 0;
245 while(sisbios_mode[i].mode_no[0] != 0) { 252 while(sisbios_mode[i].mode_no[0] != 0) {
246 if(!strnicmp(nameptr, sisbios_mode[i++].name, strlen(nameptr))) { 253 if(!strnicmp(nameptr, sisbios_mode[i++].name, strlen(nameptr))) {
247 if(sisfb_fstn) { 254 if(sisfb_fstn) {
248 if(sisbios_mode[i-1].mode_no[1] == 0x50 || 255 if(sisbios_mode[i-1].mode_no[1] == 0x50 ||
249 sisbios_mode[i-1].mode_no[1] == 0x56 || 256 sisbios_mode[i-1].mode_no[1] == 0x56 ||
250 sisbios_mode[i-1].mode_no[1] == 0x53) continue; 257 sisbios_mode[i-1].mode_no[1] == 0x53)
251 } else { 258 continue;
252 if(sisbios_mode[i-1].mode_no[1] == 0x5a || 259 } else {
253 sisbios_mode[i-1].mode_no[1] == 0x5b) continue; 260 if(sisbios_mode[i-1].mode_no[1] == 0x5a ||
254 } 261 sisbios_mode[i-1].mode_no[1] == 0x5b)
255 sisfb_mode_idx = i - 1; 262 continue;
256 j = 1; 263 }
257 break; 264 sisfb_mode_idx = i - 1;
258 } 265 j = 1;
259 } 266 break;
260 if((!j) && !quiet) printk(KERN_ERR "sisfb: Invalid mode '%s'\n", nameptr); 267 }
268 }
269
270 if((!j) && !quiet)
271 printk(KERN_ERR "sisfb: Invalid mode '%s'\n", nameptr);
261} 272}
262 273
263#ifndef MODULE 274#ifndef MODULE
@@ -265,7 +276,7 @@ static void __devinit
265sisfb_get_vga_mode_from_kernel(void) 276sisfb_get_vga_mode_from_kernel(void)
266{ 277{
267#if (defined(__i386__) || defined(__x86_64__)) && defined(CONFIG_VIDEO_SELECT) 278#if (defined(__i386__) || defined(__x86_64__)) && defined(CONFIG_VIDEO_SELECT)
268 char mymode[32]; 279 char mymode[32];
269 int mydepth = screen_info.lfb_depth; 280 int mydepth = screen_info.lfb_depth;
270 281
271 if(screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB) return; 282 if(screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB) return;
@@ -274,15 +285,17 @@ sisfb_get_vga_mode_from_kernel(void)
274 (screen_info.lfb_height >= 200) && (screen_info.lfb_height <= 1536) && 285 (screen_info.lfb_height >= 200) && (screen_info.lfb_height <= 1536) &&
275 (mydepth >= 8) && (mydepth <= 32) ) { 286 (mydepth >= 8) && (mydepth <= 32) ) {
276 287
277 if(mydepth == 24) mydepth = 32; 288 if(mydepth == 24) mydepth = 32;
278 289
279 sprintf(mymode, "%ux%ux%u", screen_info.lfb_width, 290 sprintf(mymode, "%ux%ux%u", screen_info.lfb_width,
280 screen_info.lfb_height, 291 screen_info.lfb_height,
281 mydepth); 292 mydepth);
282 293
283 printk(KERN_DEBUG "sisfb: Using vga mode %s pre-set by kernel as default\n", mymode); 294 printk(KERN_DEBUG
295 "sisfb: Using vga mode %s pre-set by kernel as default\n",
296 mymode);
284 297
285 sisfb_search_mode(mymode, TRUE); 298 sisfb_search_mode(mymode, TRUE);
286 } 299 }
287#endif 300#endif
288 return; 301 return;
@@ -294,26 +307,25 @@ sisfb_search_crt2type(const char *name)
294{ 307{
295 int i = 0; 308 int i = 0;
296 309
297 /* BEWARE: We don't know the hardware specs yet and there is no ivideo */ 310 /* We don't know the hardware specs yet and there is no ivideo */
298 311
299 if(name == NULL) return; 312 if(name == NULL) return;
300 313
301 while(sis_crt2type[i].type_no != -1) { 314 while(sis_crt2type[i].type_no != -1) {
302 if(!strnicmp(name, sis_crt2type[i].name, strlen(sis_crt2type[i].name))) { 315 if(!strnicmp(name, sis_crt2type[i].name, strlen(sis_crt2type[i].name))) {
303 sisfb_crt2type = sis_crt2type[i].type_no; 316 sisfb_crt2type = sis_crt2type[i].type_no;
304 sisfb_tvplug = sis_crt2type[i].tvplug_no; 317 sisfb_tvplug = sis_crt2type[i].tvplug_no;
305 sisfb_crt2flags = sis_crt2type[i].flags; 318 sisfb_crt2flags = sis_crt2type[i].flags;
306 break; 319 break;
307 } 320 }
308 i++; 321 i++;
309 } 322 }
310 323
311 sisfb_dstn = (sisfb_crt2flags & FL_550_DSTN) ? 1 : 0; 324 sisfb_dstn = (sisfb_crt2flags & FL_550_DSTN) ? 1 : 0;
312 sisfb_fstn = (sisfb_crt2flags & FL_550_FSTN) ? 1 : 0; 325 sisfb_fstn = (sisfb_crt2flags & FL_550_FSTN) ? 1 : 0;
313 326
314 if(sisfb_crt2type < 0) { 327 if(sisfb_crt2type < 0)
315 printk(KERN_ERR "sisfb: Invalid CRT2 type: %s\n", name); 328 printk(KERN_ERR "sisfb: Invalid CRT2 type: %s\n", name);
316 }
317} 329}
318 330
319static void __init 331static void __init
@@ -321,16 +333,17 @@ sisfb_search_tvstd(const char *name)
321{ 333{
322 int i = 0; 334 int i = 0;
323 335
324 /* BEWARE: We don't know the hardware specs yet and there is no ivideo */ 336 /* We don't know the hardware specs yet and there is no ivideo */
325 337
326 if(name == NULL) return; 338 if(name == NULL)
339 return;
327 340
328 while(sis_tvtype[i].type_no != -1) { 341 while(sis_tvtype[i].type_no != -1) {
329 if(!strnicmp(name, sis_tvtype[i].name, strlen(sis_tvtype[i].name))) { 342 if(!strnicmp(name, sis_tvtype[i].name, strlen(sis_tvtype[i].name))) {
330 sisfb_tvstd = sis_tvtype[i].type_no; 343 sisfb_tvstd = sis_tvtype[i].type_no;
331 break; 344 break;
332 } 345 }
333 i++; 346 i++;
334 } 347 }
335} 348}
336 349
@@ -340,38 +353,101 @@ sisfb_search_specialtiming(const char *name)
340 int i = 0; 353 int i = 0;
341 BOOLEAN found = FALSE; 354 BOOLEAN found = FALSE;
342 355
343 /* BEWARE: We don't know the hardware specs yet and there is no ivideo */ 356 /* We don't know the hardware specs yet and there is no ivideo */
344 357
345 if(name == NULL) return; 358 if(name == NULL)
359 return;
346 360
347 if(!strnicmp(name, "none", 4)) { 361 if(!strnicmp(name, "none", 4)) {
348 sisfb_specialtiming = CUT_FORCENONE; 362 sisfb_specialtiming = CUT_FORCENONE;
349 printk(KERN_DEBUG "sisfb: Special timing disabled\n"); 363 printk(KERN_DEBUG "sisfb: Special timing disabled\n");
350 } else { 364 } else {
351 while(mycustomttable[i].chipID != 0) { 365 while(mycustomttable[i].chipID != 0) {
352 if(!strnicmp(name,mycustomttable[i].optionName, strlen(mycustomttable[i].optionName))) { 366 if(!strnicmp(name,mycustomttable[i].optionName,
353 sisfb_specialtiming = mycustomttable[i].SpecialID; 367 strlen(mycustomttable[i].optionName))) {
354 found = TRUE; 368 sisfb_specialtiming = mycustomttable[i].SpecialID;
355 printk(KERN_INFO "sisfb: Special timing for %s %s forced (\"%s\")\n", 369 found = TRUE;
356 mycustomttable[i].vendorName, mycustomttable[i].cardName, 370 printk(KERN_INFO "sisfb: Special timing for %s %s forced (\"%s\")\n",
357 mycustomttable[i].optionName); 371 mycustomttable[i].vendorName,
358 break; 372 mycustomttable[i].cardName,
359 } 373 mycustomttable[i].optionName);
360 i++; 374 break;
361 } 375 }
362 if(!found) { 376 i++;
363 printk(KERN_WARNING "sisfb: Invalid SpecialTiming parameter, valid are:"); 377 }
364 printk(KERN_WARNING "\t\"none\" (to disable special timings)\n"); 378 if(!found) {
365 i = 0; 379 printk(KERN_WARNING "sisfb: Invalid SpecialTiming parameter, valid are:");
366 while(mycustomttable[i].chipID != 0) { 380 printk(KERN_WARNING "\t\"none\" (to disable special timings)\n");
367 printk(KERN_WARNING "\t\"%s\" (for %s %s)\n", 381 i = 0;
368 mycustomttable[i].optionName, 382 while(mycustomttable[i].chipID != 0) {
369 mycustomttable[i].vendorName, 383 printk(KERN_WARNING "\t\"%s\" (for %s %s)\n",
370 mycustomttable[i].cardName); 384 mycustomttable[i].optionName,
371 i++; 385 mycustomttable[i].vendorName,
372 } 386 mycustomttable[i].cardName);
373 } 387 i++;
374 } 388 }
389 }
390 }
391}
392
393/* ----------- Various detection routines ----------- */
394
395static void __devinit
396sisfb_detect_custom_timing(struct sis_video_info *ivideo)
397{
398 unsigned char *biosver = NULL;
399 unsigned char *biosdate = NULL;
400 BOOLEAN footprint;
401 u32 chksum = 0;
402 int i, j;
403
404 if(ivideo->SiS_Pr.UseROM) {
405 biosver = ivideo->SiS_Pr.VirtualRomBase + 0x06;
406 biosdate = ivideo->SiS_Pr.VirtualRomBase + 0x2c;
407 for(i = 0; i < 32768; i++)
408 chksum += ivideo->SiS_Pr.VirtualRomBase[i];
409 }
410
411 i = 0;
412 do {
413 if( (mycustomttable[i].chipID == ivideo->chip) &&
414 ((!strlen(mycustomttable[i].biosversion)) ||
415 (ivideo->SiS_Pr.UseROM &&
416 (!strncmp(mycustomttable[i].biosversion, biosver,
417 strlen(mycustomttable[i].biosversion))))) &&
418 ((!strlen(mycustomttable[i].biosdate)) ||
419 (ivideo->SiS_Pr.UseROM &&
420 (!strncmp(mycustomttable[i].biosdate, biosdate,
421 strlen(mycustomttable[i].biosdate))))) &&
422 ((!mycustomttable[i].bioschksum) ||
423 (ivideo->SiS_Pr.UseROM &&
424 (mycustomttable[i].bioschksum == chksum))) &&
425 (mycustomttable[i].pcisubsysvendor == ivideo->subsysvendor) &&
426 (mycustomttable[i].pcisubsyscard == ivideo->subsysdevice) ) {
427 footprint = TRUE;
428 for(j = 0; j < 5; j++) {
429 if(mycustomttable[i].biosFootprintAddr[j]) {
430 if(ivideo->SiS_Pr.UseROM) {
431 if(ivideo->SiS_Pr.VirtualRomBase[mycustomttable[i].biosFootprintAddr[j]] !=
432 mycustomttable[i].biosFootprintData[j]) {
433 footprint = FALSE;
434 }
435 } else
436 footprint = FALSE;
437 }
438 }
439 if(footprint) {
440 ivideo->SiS_Pr.SiS_CustomT = mycustomttable[i].SpecialID;
441 printk(KERN_DEBUG "sisfb: Identified [%s %s], special timing applies\n",
442 mycustomttable[i].vendorName,
443 mycustomttable[i].cardName);
444 printk(KERN_DEBUG "sisfb: [specialtiming parameter name: %s]\n",
445 mycustomttable[i].optionName);
446 break;
447 }
448 }
449 i++;
450 } while(mycustomttable[i].chipID);
375} 451}
376 452
377static BOOLEAN __devinit 453static BOOLEAN __devinit
@@ -384,22 +460,23 @@ sisfb_interpret_edid(struct sisfb_monitor *monitor, u8 *buffer)
384 buffer[2] != 0xff || buffer[3] != 0xff || 460 buffer[2] != 0xff || buffer[3] != 0xff ||
385 buffer[4] != 0xff || buffer[5] != 0xff || 461 buffer[4] != 0xff || buffer[5] != 0xff ||
386 buffer[6] != 0xff || buffer[7] != 0x00) { 462 buffer[6] != 0xff || buffer[7] != 0x00) {
387 printk(KERN_DEBUG "sisfb: Bad EDID header\n"); 463 printk(KERN_DEBUG "sisfb: Bad EDID header\n");
388 return FALSE; 464 return FALSE;
389 } 465 }
390 466
391 if(buffer[0x12] != 0x01) { 467 if(buffer[0x12] != 0x01) {
392 printk(KERN_INFO "sisfb: EDID version %d not supported\n", 468 printk(KERN_INFO "sisfb: EDID version %d not supported\n",
393 buffer[0x12]); 469 buffer[0x12]);
394 return FALSE; 470 return FALSE;
395 } 471 }
396 472
397 monitor->feature = buffer[0x18]; 473 monitor->feature = buffer[0x18];
398 474
399 if(!buffer[0x14] & 0x80) { 475 if(!buffer[0x14] & 0x80) {
400 if(!(buffer[0x14] & 0x08)) { 476 if(!(buffer[0x14] & 0x08)) {
401 printk(KERN_INFO "sisfb: WARNING: Monitor does not support separate syncs\n"); 477 printk(KERN_INFO
402 } 478 "sisfb: WARNING: Monitor does not support separate syncs\n");
479 }
403 } 480 }
404 481
405 if(buffer[0x13] >= 0x01) { 482 if(buffer[0x13] >= 0x01) {
@@ -409,7 +486,7 @@ sisfb_interpret_edid(struct sisfb_monitor *monitor, u8 *buffer)
409 j = 0x36; 486 j = 0x36;
410 for(i=0; i<4; i++) { 487 for(i=0; i<4; i++) {
411 if(buffer[j] == 0x00 && buffer[j + 1] == 0x00 && 488 if(buffer[j] == 0x00 && buffer[j + 1] == 0x00 &&
412 buffer[j + 2] == 0x00 && buffer[j + 3] == 0xfd && 489 buffer[j + 2] == 0x00 && buffer[j + 3] == 0xfd &&
413 buffer[j + 4] == 0x00) { 490 buffer[j + 4] == 0x00) {
414 monitor->hmin = buffer[j + 7]; 491 monitor->hmin = buffer[j + 7];
415 monitor->hmax = buffer[j + 8]; 492 monitor->hmax = buffer[j + 8];
@@ -435,7 +512,7 @@ sisfb_interpret_edid(struct sisfb_monitor *monitor, u8 *buffer)
435 emodes = buffer[0x23] | (buffer[0x24] << 8) | (buffer[0x25] << 16); 512 emodes = buffer[0x23] | (buffer[0x24] << 8) | (buffer[0x25] << 16);
436 for(i = 0; i < 13; i++) { 513 for(i = 0; i < 13; i++) {
437 if(emodes & sisfb_ddcsmodes[i].mask) { 514 if(emodes & sisfb_ddcsmodes[i].mask) {
438 if(monitor->hmin > sisfb_ddcsmodes[i].h) monitor->hmin = sisfb_ddcsmodes[i].h; 515 if(monitor->hmin > sisfb_ddcsmodes[i].h) monitor->hmin = sisfb_ddcsmodes[i].h;
439 if(monitor->hmax < sisfb_ddcsmodes[i].h) monitor->hmax = sisfb_ddcsmodes[i].h + 1; 516 if(monitor->hmax < sisfb_ddcsmodes[i].h) monitor->hmax = sisfb_ddcsmodes[i].h + 1;
440 if(monitor->vmin > sisfb_ddcsmodes[i].v) monitor->vmin = sisfb_ddcsmodes[i].v; 517 if(monitor->vmin > sisfb_ddcsmodes[i].v) monitor->vmin = sisfb_ddcsmodes[i].v;
441 if(monitor->vmax < sisfb_ddcsmodes[i].v) monitor->vmax = sisfb_ddcsmodes[i].v; 518 if(monitor->vmax < sisfb_ddcsmodes[i].v) monitor->vmax = sisfb_ddcsmodes[i].v;
@@ -446,80 +523,81 @@ sisfb_interpret_edid(struct sisfb_monitor *monitor, u8 *buffer)
446 for(i = 0; i < 8; i++) { 523 for(i = 0; i < 8; i++) {
447 xres = (buffer[index] + 31) * 8; 524 xres = (buffer[index] + 31) * 8;
448 switch(buffer[index + 1] & 0xc0) { 525 switch(buffer[index + 1] & 0xc0) {
449 case 0xc0: yres = (xres * 9) / 16; break; 526 case 0xc0: yres = (xres * 9) / 16; break;
450 case 0x80: yres = (xres * 4) / 5; break; 527 case 0x80: yres = (xres * 4) / 5; break;
451 case 0x40: yres = (xres * 3) / 4; break; 528 case 0x40: yres = (xres * 3) / 4; break;
452 default: yres = xres; break; 529 default: yres = xres; break;
453 } 530 }
454 refresh = (buffer[index + 1] & 0x3f) + 60; 531 refresh = (buffer[index + 1] & 0x3f) + 60;
455 if((xres >= 640) && (yres >= 480)) { 532 if((xres >= 640) && (yres >= 480)) {
456 for(j = 0; j < 8; j++) { 533 for(j = 0; j < 8; j++) {
457 if((xres == sisfb_ddcfmodes[j].x) && 534 if((xres == sisfb_ddcfmodes[j].x) &&
458 (yres == sisfb_ddcfmodes[j].y) && 535 (yres == sisfb_ddcfmodes[j].y) &&
459 (refresh == sisfb_ddcfmodes[j].v)) { 536 (refresh == sisfb_ddcfmodes[j].v)) {
460 if(monitor->hmin > sisfb_ddcfmodes[j].h) monitor->hmin = sisfb_ddcfmodes[j].h; 537 if(monitor->hmin > sisfb_ddcfmodes[j].h) monitor->hmin = sisfb_ddcfmodes[j].h;
461 if(monitor->hmax < sisfb_ddcfmodes[j].h) monitor->hmax = sisfb_ddcfmodes[j].h + 1; 538 if(monitor->hmax < sisfb_ddcfmodes[j].h) monitor->hmax = sisfb_ddcfmodes[j].h + 1;
462 if(monitor->vmin > sisfb_ddcsmodes[j].v) monitor->vmin = sisfb_ddcsmodes[j].v; 539 if(monitor->vmin > sisfb_ddcsmodes[j].v) monitor->vmin = sisfb_ddcsmodes[j].v;
463 if(monitor->vmax < sisfb_ddcsmodes[j].v) monitor->vmax = sisfb_ddcsmodes[j].v; 540 if(monitor->vmax < sisfb_ddcsmodes[j].v) monitor->vmax = sisfb_ddcsmodes[j].v;
464 if(monitor->dclockmax < sisfb_ddcsmodes[j].d) monitor->dclockmax = sisfb_ddcsmodes[i].d; 541 if(monitor->dclockmax < sisfb_ddcsmodes[j].d) monitor->dclockmax = sisfb_ddcsmodes[j].d;
465 } 542 }
466 } 543 }
467 } 544 }
468 index += 2; 545 index += 2;
469 } 546 }
470 if((monitor->hmin <= monitor->hmax) && (monitor->vmin <= monitor->vmax)) { 547 if((monitor->hmin <= monitor->hmax) && (monitor->vmin <= monitor->vmax)) {
471 monitor->datavalid = TRUE; 548 monitor->datavalid = TRUE;
472 } 549 }
473 } 550 }
474 551
475 return(monitor->datavalid); 552 return monitor->datavalid;
476} 553}
477 554
478static void __devinit 555static void __devinit
479sisfb_handle_ddc(struct sis_video_info *ivideo, struct sisfb_monitor *monitor, int crtno) 556sisfb_handle_ddc(struct sis_video_info *ivideo, struct sisfb_monitor *monitor, int crtno)
480{ 557{
481 USHORT temp, i, realcrtno = crtno; 558 unsigned short temp, i, realcrtno = crtno;
482 u8 buffer[256]; 559 unsigned char buffer[256];
483 560
484 monitor->datavalid = FALSE; 561 monitor->datavalid = FALSE;
485 562
486 if(crtno) { 563 if(crtno) {
487 if(ivideo->vbflags & CRT2_LCD) realcrtno = 1; 564 if(ivideo->vbflags & CRT2_LCD) realcrtno = 1;
488 else if(ivideo->vbflags & CRT2_VGA) realcrtno = 2; 565 else if(ivideo->vbflags & CRT2_VGA) realcrtno = 2;
489 else return; 566 else return;
490 } 567 }
491 568
492 if((ivideo->sisfb_crt1off) && (!crtno)) return; 569 if((ivideo->sisfb_crt1off) && (!crtno))
570 return;
493 571
494 temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags, ivideo->sisvga_engine, 572 temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags, ivideo->sisvga_engine,
495 realcrtno, 0, &buffer[0]); 573 realcrtno, 0, &buffer[0], ivideo->vbflags2);
496 if((!temp) || (temp == 0xffff)) { 574 if((!temp) || (temp == 0xffff)) {
497 printk(KERN_INFO "sisfb: CRT%d DDC probing failed\n", crtno + 1); 575 printk(KERN_INFO "sisfb: CRT%d DDC probing failed\n", crtno + 1);
498 return; 576 return;
499 } else { 577 } else {
500 printk(KERN_INFO "sisfb: CRT%d DDC supported\n", crtno + 1); 578 printk(KERN_INFO "sisfb: CRT%d DDC supported\n", crtno + 1);
501 printk(KERN_INFO "sisfb: CRT%d DDC level: %s%s%s%s\n", 579 printk(KERN_INFO "sisfb: CRT%d DDC level: %s%s%s%s\n",
502 crtno + 1, 580 crtno + 1,
503 (temp & 0x1a) ? "" : "[none of the supported]", 581 (temp & 0x1a) ? "" : "[none of the supported]",
504 (temp & 0x02) ? "2 " : "", 582 (temp & 0x02) ? "2 " : "",
505 (temp & 0x08) ? "D&P" : "", 583 (temp & 0x08) ? "D&P" : "",
506 (temp & 0x10) ? "FPDI-2" : ""); 584 (temp & 0x10) ? "FPDI-2" : "");
507 if(temp & 0x02) { 585 if(temp & 0x02) {
508 i = 3; /* Number of retrys */ 586 i = 3; /* Number of retrys */
509 do { 587 do {
510 temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags, ivideo->sisvga_engine, 588 temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags, ivideo->sisvga_engine,
511 realcrtno, 1, &buffer[0]); 589 realcrtno, 1, &buffer[0], ivideo->vbflags2);
512 } while((temp) && i--); 590 } while((temp) && i--);
513 if(!temp) { 591 if(!temp) {
514 if(sisfb_interpret_edid(monitor, &buffer[0])) { 592 if(sisfb_interpret_edid(monitor, &buffer[0])) {
515 printk(KERN_INFO "sisfb: Monitor range H %d-%dKHz, V %d-%dHz, Max. dotclock %dMHz\n", 593 printk(KERN_INFO "sisfb: Monitor range H %d-%dKHz, V %d-%dHz, Max. dotclock %dMHz\n",
516 monitor->hmin, monitor->hmax, monitor->vmin, monitor->vmax, 594 monitor->hmin, monitor->hmax, monitor->vmin, monitor->vmax,
517 monitor->dclockmax / 1000); 595 monitor->dclockmax / 1000);
518 } else { 596 } else {
519 printk(KERN_INFO "sisfb: CRT%d DDC EDID corrupt\n", crtno + 1); 597 printk(KERN_INFO "sisfb: CRT%d DDC EDID corrupt\n", crtno + 1);
520 } 598 }
521 } else { 599 } else {
522 printk(KERN_INFO "sisfb: CRT%d DDC reading failed\n", crtno + 1); 600 printk(KERN_INFO "sisfb: CRT%d DDC reading failed\n", crtno + 1);
523 } 601 }
524 } else { 602 } else {
525 printk(KERN_INFO "sisfb: VESA D&P and FPDI-2 not supported yet\n"); 603 printk(KERN_INFO "sisfb: VESA D&P and FPDI-2 not supported yet\n");
@@ -527,6 +605,8 @@ sisfb_handle_ddc(struct sis_video_info *ivideo, struct sisfb_monitor *monitor, i
527 } 605 }
528} 606}
529 607
608/* -------------- Mode validation --------------- */
609
530static BOOLEAN 610static BOOLEAN
531sisfb_verify_rate(struct sis_video_info *ivideo, struct sisfb_monitor *monitor, 611sisfb_verify_rate(struct sis_video_info *ivideo, struct sisfb_monitor *monitor,
532 int mode_idx, int rate_idx, int rate) 612 int mode_idx, int rate_idx, int rate)
@@ -534,42 +614,49 @@ sisfb_verify_rate(struct sis_video_info *ivideo, struct sisfb_monitor *monitor,
534 int htotal, vtotal; 614 int htotal, vtotal;
535 unsigned int dclock, hsync; 615 unsigned int dclock, hsync;
536 616
537 if(!monitor->datavalid) return TRUE; 617 if(!monitor->datavalid)
618 return TRUE;
538 619
539 if(mode_idx < 0) return FALSE; 620 if(mode_idx < 0)
621 return FALSE;
540 622
541 /* Skip for 320x200, 320x240, 640x400 */ 623 /* Skip for 320x200, 320x240, 640x400 */
542 switch(sisbios_mode[mode_idx].mode_no[ivideo->mni]) { 624 switch(sisbios_mode[mode_idx].mode_no[ivideo->mni]) {
543 case 0x59: 625 case 0x59:
544 case 0x41: 626 case 0x41:
545 case 0x4f: 627 case 0x4f:
546 case 0x50: 628 case 0x50:
547 case 0x56: 629 case 0x56:
548 case 0x53: 630 case 0x53:
549 case 0x2f: 631 case 0x2f:
550 case 0x5d: 632 case 0x5d:
551 case 0x5e: 633 case 0x5e:
552 return TRUE; 634 return TRUE;
553#ifdef CONFIG_FB_SIS_315 635#ifdef CONFIG_FB_SIS_315
554 case 0x5a: 636 case 0x5a:
555 case 0x5b: 637 case 0x5b:
556 if(ivideo->sisvga_engine == SIS_315_VGA) return TRUE; 638 if(ivideo->sisvga_engine == SIS_315_VGA) return TRUE;
557#endif 639#endif
558 } 640 }
559 641
560 if(rate < (monitor->vmin - 1)) return FALSE; 642 if(rate < (monitor->vmin - 1))
561 if(rate > (monitor->vmax + 1)) return FALSE; 643 return FALSE;
644 if(rate > (monitor->vmax + 1))
645 return FALSE;
562 646
563 if(sisfb_gettotalfrommode(&ivideo->SiS_Pr, &ivideo->sishw_ext, 647 if(sisfb_gettotalfrommode(&ivideo->SiS_Pr,
564 sisbios_mode[mode_idx].mode_no[ivideo->mni], 648 sisbios_mode[mode_idx].mode_no[ivideo->mni],
565 &htotal, &vtotal, rate_idx)) { 649 &htotal, &vtotal, rate_idx)) {
566 dclock = (htotal * vtotal * rate) / 1000; 650 dclock = (htotal * vtotal * rate) / 1000;
567 if(dclock > (monitor->dclockmax + 1000)) return FALSE; 651 if(dclock > (monitor->dclockmax + 1000))
652 return FALSE;
568 hsync = dclock / htotal; 653 hsync = dclock / htotal;
569 if(hsync < (monitor->hmin - 1)) return FALSE; 654 if(hsync < (monitor->hmin - 1))
570 if(hsync > (monitor->hmax + 1)) return FALSE; 655 return FALSE;
656 if(hsync > (monitor->hmax + 1))
657 return FALSE;
571 } else { 658 } else {
572 return FALSE; 659 return FALSE;
573 } 660 }
574 return TRUE; 661 return TRUE;
575} 662}
@@ -577,82 +664,79 @@ sisfb_verify_rate(struct sis_video_info *ivideo, struct sisfb_monitor *monitor,
577static int 664static int
578sisfb_validate_mode(struct sis_video_info *ivideo, int myindex, u32 vbflags) 665sisfb_validate_mode(struct sis_video_info *ivideo, int myindex, u32 vbflags)
579{ 666{
580 u16 xres=0, yres, myres; 667 u16 xres=0, yres, myres;
581 668
582#ifdef CONFIG_FB_SIS_300 669#ifdef CONFIG_FB_SIS_300
583 if(ivideo->sisvga_engine == SIS_300_VGA) { 670 if(ivideo->sisvga_engine == SIS_300_VGA) {
584 if(!(sisbios_mode[myindex].chipset & MD_SIS300)) return(-1); 671 if(!(sisbios_mode[myindex].chipset & MD_SIS300))
585 } 672 return -1 ;
673 }
586#endif 674#endif
587#ifdef CONFIG_FB_SIS_315 675#ifdef CONFIG_FB_SIS_315
588 if(ivideo->sisvga_engine == SIS_315_VGA) { 676 if(ivideo->sisvga_engine == SIS_315_VGA) {
589 if(!(sisbios_mode[myindex].chipset & MD_SIS315)) return(-1); 677 if(!(sisbios_mode[myindex].chipset & MD_SIS315))
590 } 678 return -1;
679 }
591#endif 680#endif
592 681
593 myres = sisbios_mode[myindex].yres; 682 myres = sisbios_mode[myindex].yres;
594
595 switch(vbflags & VB_DISPTYPE_DISP2) {
596 683
597 case CRT2_LCD: 684 switch(vbflags & VB_DISPTYPE_DISP2) {
598 685
599 xres = ivideo->lcdxres; yres = ivideo->lcdyres; 686 case CRT2_LCD:
687 xres = ivideo->lcdxres; yres = ivideo->lcdyres;
600 688
601 if(ivideo->SiS_Pr.SiS_CustomT != CUT_PANEL848) { 689 if((ivideo->SiS_Pr.SiS_CustomT != CUT_PANEL848) &&
602 if(sisbios_mode[myindex].xres > xres) return(-1); 690 (ivideo->SiS_Pr.SiS_CustomT != CUT_PANEL856)) {
603 if(myres > yres) return(-1); 691 if(sisbios_mode[myindex].xres > xres)
604 } 692 return -1;
693 if(myres > yres)
694 return -1;
695 }
605 696
606 if(vbflags & (VB_LVDS | VB_30xBDH)) { 697 if(ivideo->sisfb_fstn) {
607 if(sisbios_mode[myindex].xres == 320) { 698 if(sisbios_mode[myindex].xres == 320) {
608 if((myres == 240) || (myres == 480)) { 699 if(myres == 240) {
609 if(!ivideo->sisfb_fstn) { 700 switch(sisbios_mode[myindex].mode_no[1]) {
610 if(sisbios_mode[myindex].mode_no[1] == 0x5a || 701 case 0x50: myindex = MODE_FSTN_8; break;
611 sisbios_mode[myindex].mode_no[1] == 0x5b) 702 case 0x56: myindex = MODE_FSTN_16; break;
612 return(-1); 703 case 0x53: return -1;
613 } else { 704 }
614 if(sisbios_mode[myindex].mode_no[1] == 0x50 || 705 }
615 sisbios_mode[myindex].mode_no[1] == 0x56 || 706 }
616 sisbios_mode[myindex].mode_no[1] == 0x53) 707 }
617 return(-1);
618 }
619 }
620 }
621 }
622 708
623 if(SiS_GetModeID_LCD(ivideo->sisvga_engine, vbflags, sisbios_mode[myindex].xres, 709 if(SiS_GetModeID_LCD(ivideo->sisvga_engine, vbflags, sisbios_mode[myindex].xres,
624 sisbios_mode[myindex].yres, 0, ivideo->sisfb_fstn, 710 sisbios_mode[myindex].yres, 0, ivideo->sisfb_fstn,
625 ivideo->SiS_Pr.SiS_CustomT, xres, yres) < 0x14) { 711 ivideo->SiS_Pr.SiS_CustomT, xres, yres, ivideo->vbflags2) < 0x14) {
626 return(-1); 712 return -1;
627 } 713 }
628 break; 714 break;
629 715
630 case CRT2_TV: 716 case CRT2_TV:
631 if(SiS_GetModeID_TV(ivideo->sisvga_engine, vbflags, sisbios_mode[myindex].xres, 717 if(SiS_GetModeID_TV(ivideo->sisvga_engine, vbflags, sisbios_mode[myindex].xres,
632 sisbios_mode[myindex].yres, 0) < 0x14) { 718 sisbios_mode[myindex].yres, 0, ivideo->vbflags2) < 0x14) {
633 return(-1); 719 return -1;
634 } 720 }
635 break; 721 break;
636 722
637 case CRT2_VGA: 723 case CRT2_VGA:
638 if(SiS_GetModeID_VGA2(ivideo->sisvga_engine, vbflags, sisbios_mode[myindex].xres, 724 if(SiS_GetModeID_VGA2(ivideo->sisvga_engine, vbflags, sisbios_mode[myindex].xres,
639 sisbios_mode[myindex].yres, 0) < 0x14) { 725 sisbios_mode[myindex].yres, 0, ivideo->vbflags2) < 0x14) {
640 return(-1); 726 return -1;
727 }
728 break;
641 } 729 }
642 break;
643 }
644 730
645 return(myindex); 731 return myindex;
646} 732}
647 733
648static u8 734static u8
649sisfb_search_refresh_rate(struct sis_video_info *ivideo, unsigned int rate, int mode_idx) 735sisfb_search_refresh_rate(struct sis_video_info *ivideo, unsigned int rate, int mode_idx)
650{ 736{
651 u16 xres, yres;
652 int i = 0; 737 int i = 0;
653 738 u16 xres = sisbios_mode[mode_idx].xres;
654 xres = sisbios_mode[mode_idx].xres; 739 u16 yres = sisbios_mode[mode_idx].yres;
655 yres = sisbios_mode[mode_idx].yres;
656 740
657 ivideo->rate_idx = 0; 741 ivideo->rate_idx = 0;
658 while((sisfb_vrate[i].idx != 0) && (sisfb_vrate[i].xres <= xres)) { 742 while((sisfb_vrate[i].idx != 0) && (sisfb_vrate[i].xres <= xres)) {
@@ -672,14 +756,14 @@ sisfb_search_refresh_rate(struct sis_video_info *ivideo, unsigned int rate, int
672 rate, sisfb_vrate[i-1].refresh); 756 rate, sisfb_vrate[i-1].refresh);
673 ivideo->rate_idx = sisfb_vrate[i-1].idx; 757 ivideo->rate_idx = sisfb_vrate[i-1].idx;
674 ivideo->refresh_rate = sisfb_vrate[i-1].refresh; 758 ivideo->refresh_rate = sisfb_vrate[i-1].refresh;
675 } 759 }
676 break; 760 break;
677 } else if((rate - sisfb_vrate[i].refresh) <= 2) { 761 } else if((rate - sisfb_vrate[i].refresh) <= 2) {
678 DPRINTK("sisfb: Adjusting rate from %d down to %d\n", 762 DPRINTK("sisfb: Adjusting rate from %d down to %d\n",
679 rate, sisfb_vrate[i].refresh); 763 rate, sisfb_vrate[i].refresh);
680 ivideo->rate_idx = sisfb_vrate[i].idx; 764 ivideo->rate_idx = sisfb_vrate[i].idx;
681 break; 765 break;
682 } 766 }
683 } 767 }
684 i++; 768 i++;
685 } 769 }
@@ -695,252 +779,321 @@ sisfb_search_refresh_rate(struct sis_video_info *ivideo, unsigned int rate, int
695static BOOLEAN 779static BOOLEAN
696sisfb_bridgeisslave(struct sis_video_info *ivideo) 780sisfb_bridgeisslave(struct sis_video_info *ivideo)
697{ 781{
698 unsigned char P1_00; 782 unsigned char P1_00;
699 783
700 if(!(ivideo->vbflags & VB_VIDEOBRIDGE)) return FALSE; 784 if(!(ivideo->vbflags2 & VB2_VIDEOBRIDGE))
785 return FALSE;
701 786
702 inSISIDXREG(SISPART1,0x00,P1_00); 787 inSISIDXREG(SISPART1,0x00,P1_00);
703 if( ((ivideo->sisvga_engine == SIS_300_VGA) && (P1_00 & 0xa0) == 0x20) || 788 if( ((ivideo->sisvga_engine == SIS_300_VGA) && (P1_00 & 0xa0) == 0x20) ||
704 ((ivideo->sisvga_engine == SIS_315_VGA) && (P1_00 & 0x50) == 0x10) ) { 789 ((ivideo->sisvga_engine == SIS_315_VGA) && (P1_00 & 0x50) == 0x10) ) {
705 return TRUE; 790 return TRUE;
706 } else { 791 } else {
707 return FALSE; 792 return FALSE;
708 } 793 }
709} 794}
710 795
711static BOOLEAN 796static BOOLEAN
712sisfballowretracecrt1(struct sis_video_info *ivideo) 797sisfballowretracecrt1(struct sis_video_info *ivideo)
713{ 798{
714 u8 temp; 799 u8 temp;
715 800
716 inSISIDXREG(SISCR,0x17,temp); 801 inSISIDXREG(SISCR,0x17,temp);
717 if(!(temp & 0x80)) return FALSE; 802 if(!(temp & 0x80))
803 return FALSE;
718 804
719 inSISIDXREG(SISSR,0x1f,temp); 805 inSISIDXREG(SISSR,0x1f,temp);
720 if(temp & 0xc0) return FALSE; 806 if(temp & 0xc0)
807 return FALSE;
721 808
722 return TRUE; 809 return TRUE;
723} 810}
724 811
725static BOOLEAN 812static BOOLEAN
726sisfbcheckvretracecrt1(struct sis_video_info *ivideo) 813sisfbcheckvretracecrt1(struct sis_video_info *ivideo)
727{ 814{
728 if(!sisfballowretracecrt1(ivideo)) return FALSE; 815 if(!sisfballowretracecrt1(ivideo))
816 return FALSE;
729 817
730 if(inSISREG(SISINPSTAT) & 0x08) return TRUE; 818 if(inSISREG(SISINPSTAT) & 0x08)
731 else return FALSE; 819 return TRUE;
820 else
821 return FALSE;
732} 822}
733 823
734static void 824static void
735sisfbwaitretracecrt1(struct sis_video_info *ivideo) 825sisfbwaitretracecrt1(struct sis_video_info *ivideo)
736{ 826{
737 int watchdog; 827 int watchdog;
738 828
739 if(!sisfballowretracecrt1(ivideo)) return; 829 if(!sisfballowretracecrt1(ivideo))
830 return;
740 831
741 watchdog = 65536; 832 watchdog = 65536;
742 while((!(inSISREG(SISINPSTAT) & 0x08)) && --watchdog); 833 while((!(inSISREG(SISINPSTAT) & 0x08)) && --watchdog);
743 watchdog = 65536; 834 watchdog = 65536;
744 while((inSISREG(SISINPSTAT) & 0x08) && --watchdog); 835 while((inSISREG(SISINPSTAT) & 0x08) && --watchdog);
745} 836}
746 837
747static BOOLEAN 838static BOOLEAN
748sisfbcheckvretracecrt2(struct sis_video_info *ivideo) 839sisfbcheckvretracecrt2(struct sis_video_info *ivideo)
749{ 840{
750 unsigned char temp, reg; 841 unsigned char temp, reg;
751 842
752 switch(ivideo->sisvga_engine) { 843 switch(ivideo->sisvga_engine) {
753 case SIS_300_VGA: reg = 0x25; break; 844 case SIS_300_VGA: reg = 0x25; break;
754 case SIS_315_VGA: reg = 0x30; break; 845 case SIS_315_VGA: reg = 0x30; break;
755 default: return FALSE; 846 default: return FALSE;
756 } 847 }
757 848
758 inSISIDXREG(SISPART1, reg, temp); 849 inSISIDXREG(SISPART1, reg, temp);
759 if(temp & 0x02) return TRUE; 850 if(temp & 0x02)
760 else return FALSE; 851 return TRUE;
852 else
853 return FALSE;
761} 854}
762 855
763static BOOLEAN 856static BOOLEAN
764sisfb_CheckVBRetrace(struct sis_video_info *ivideo) 857sisfb_CheckVBRetrace(struct sis_video_info *ivideo)
765{ 858{
766 if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) { 859 if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
767 if(sisfb_bridgeisslave(ivideo)) { 860 if(!sisfb_bridgeisslave(ivideo)) {
768 return(sisfbcheckvretracecrt1(ivideo)); 861 return sisfbcheckvretracecrt2(ivideo);
769 } else { 862 }
770 return(sisfbcheckvretracecrt2(ivideo)); 863 }
771 } 864 return sisfbcheckvretracecrt1(ivideo);
772 }
773 return(sisfbcheckvretracecrt1(ivideo));
774} 865}
775 866
776static u32 867static u32
777sisfb_setupvbblankflags(struct sis_video_info *ivideo, u32 *vcount, u32 *hcount) 868sisfb_setupvbblankflags(struct sis_video_info *ivideo, u32 *vcount, u32 *hcount)
778{ 869{
779 u8 idx, reg1, reg2, reg3, reg4; 870 u8 idx, reg1, reg2, reg3, reg4;
780 u32 ret = 0; 871 u32 ret = 0;
781 872
782 (*vcount) = (*hcount) = 0; 873 (*vcount) = (*hcount) = 0;
783 874
784 if((ivideo->currentvbflags & VB_DISPTYPE_DISP2) && (!(sisfb_bridgeisslave(ivideo)))) { 875 if((ivideo->currentvbflags & VB_DISPTYPE_DISP2) && (!(sisfb_bridgeisslave(ivideo)))) {
785 ret |= (FB_VBLANK_HAVE_VSYNC | 876
786 FB_VBLANK_HAVE_HBLANK | 877 ret |= (FB_VBLANK_HAVE_VSYNC |
787 FB_VBLANK_HAVE_VBLANK | 878 FB_VBLANK_HAVE_HBLANK |
788 FB_VBLANK_HAVE_VCOUNT | 879 FB_VBLANK_HAVE_VBLANK |
789 FB_VBLANK_HAVE_HCOUNT); 880 FB_VBLANK_HAVE_VCOUNT |
790 switch(ivideo->sisvga_engine) { 881 FB_VBLANK_HAVE_HCOUNT);
791 case SIS_300_VGA: idx = 0x25; break; 882 switch(ivideo->sisvga_engine) {
792 default: 883 case SIS_300_VGA: idx = 0x25; break;
793 case SIS_315_VGA: idx = 0x30; break; 884 default:
794 } 885 case SIS_315_VGA: idx = 0x30; break;
795 inSISIDXREG(SISPART1,(idx+0),reg1); /* 30 */ 886 }
796 inSISIDXREG(SISPART1,(idx+1),reg2); /* 31 */ 887 inSISIDXREG(SISPART1,(idx+0),reg1); /* 30 */
797 inSISIDXREG(SISPART1,(idx+2),reg3); /* 32 */ 888 inSISIDXREG(SISPART1,(idx+1),reg2); /* 31 */
798 inSISIDXREG(SISPART1,(idx+3),reg4); /* 33 */ 889 inSISIDXREG(SISPART1,(idx+2),reg3); /* 32 */
799 if(reg1 & 0x01) ret |= FB_VBLANK_VBLANKING; 890 inSISIDXREG(SISPART1,(idx+3),reg4); /* 33 */
800 if(reg1 & 0x02) ret |= FB_VBLANK_VSYNCING; 891 if(reg1 & 0x01) ret |= FB_VBLANK_VBLANKING;
801 if(reg4 & 0x80) ret |= FB_VBLANK_HBLANKING; 892 if(reg1 & 0x02) ret |= FB_VBLANK_VSYNCING;
802 (*vcount) = reg3 | ((reg4 & 0x70) << 4); 893 if(reg4 & 0x80) ret |= FB_VBLANK_HBLANKING;
803 (*hcount) = reg2 | ((reg4 & 0x0f) << 8); 894 (*vcount) = reg3 | ((reg4 & 0x70) << 4);
804 } else if(sisfballowretracecrt1(ivideo)) { 895 (*hcount) = reg2 | ((reg4 & 0x0f) << 8);
805 ret |= (FB_VBLANK_HAVE_VSYNC | 896
806 FB_VBLANK_HAVE_VBLANK | 897 } else if(sisfballowretracecrt1(ivideo)) {
807 FB_VBLANK_HAVE_VCOUNT | 898
808 FB_VBLANK_HAVE_HCOUNT); 899 ret |= (FB_VBLANK_HAVE_VSYNC |
809 reg1 = inSISREG(SISINPSTAT); 900 FB_VBLANK_HAVE_VBLANK |
810 if(reg1 & 0x08) ret |= FB_VBLANK_VSYNCING; 901 FB_VBLANK_HAVE_VCOUNT |
811 if(reg1 & 0x01) ret |= FB_VBLANK_VBLANKING; 902 FB_VBLANK_HAVE_HCOUNT);
812 inSISIDXREG(SISCR,0x20,reg1); 903 reg1 = inSISREG(SISINPSTAT);
813 inSISIDXREG(SISCR,0x1b,reg1); 904 if(reg1 & 0x08) ret |= FB_VBLANK_VSYNCING;
814 inSISIDXREG(SISCR,0x1c,reg2); 905 if(reg1 & 0x01) ret |= FB_VBLANK_VBLANKING;
815 inSISIDXREG(SISCR,0x1d,reg3); 906 inSISIDXREG(SISCR,0x20,reg1);
816 (*vcount) = reg2 | ((reg3 & 0x07) << 8); 907 inSISIDXREG(SISCR,0x1b,reg1);
817 (*hcount) = (reg1 | ((reg3 & 0x10) << 4)) << 3; 908 inSISIDXREG(SISCR,0x1c,reg2);
818 } 909 inSISIDXREG(SISCR,0x1d,reg3);
819 return ret; 910 (*vcount) = reg2 | ((reg3 & 0x07) << 8);
911 (*hcount) = (reg1 | ((reg3 & 0x10) << 4)) << 3;
912 }
913
914 return ret;
820} 915}
821 916
822static int 917static int
823sisfb_myblank(struct sis_video_info *ivideo, int blank) 918sisfb_myblank(struct sis_video_info *ivideo, int blank)
824{ 919{
825 u8 sr01, sr11, sr1f, cr63=0, p2_0, p1_13; 920 u8 sr01, sr11, sr1f, cr63=0, p2_0, p1_13;
826 BOOLEAN backlight = TRUE; 921 BOOLEAN backlight = TRUE;
827 922
828 switch(blank) { 923 switch(blank) {
829 case FB_BLANK_UNBLANK: /* on */ 924 case FB_BLANK_UNBLANK: /* on */
830 sr01 = 0x00; 925 sr01 = 0x00;
831 sr11 = 0x00; 926 sr11 = 0x00;
832 sr1f = 0x00; 927 sr1f = 0x00;
833 cr63 = 0x00; 928 cr63 = 0x00;
834 p2_0 = 0x20; 929 p2_0 = 0x20;
835 p1_13 = 0x00; 930 p1_13 = 0x00;
836 backlight = TRUE; 931 backlight = TRUE;
837 break; 932 break;
838 case FB_BLANK_NORMAL: /* blank */ 933 case FB_BLANK_NORMAL: /* blank */
839 sr01 = 0x20; 934 sr01 = 0x20;
840 sr11 = 0x00; 935 sr11 = 0x00;
841 sr1f = 0x00; 936 sr1f = 0x00;
842 cr63 = 0x00; 937 cr63 = 0x00;
843 p2_0 = 0x20; 938 p2_0 = 0x20;
844 p1_13 = 0x00; 939 p1_13 = 0x00;
845 backlight = TRUE; 940 backlight = TRUE;
846 break; 941 break;
847 case FB_BLANK_VSYNC_SUSPEND: /* no vsync */ 942 case FB_BLANK_VSYNC_SUSPEND: /* no vsync */
848 sr01 = 0x20; 943 sr01 = 0x20;
849 sr11 = 0x08; 944 sr11 = 0x08;
850 sr1f = 0x80; 945 sr1f = 0x80;
851 cr63 = 0x40; 946 cr63 = 0x40;
852 p2_0 = 0x40; 947 p2_0 = 0x40;
853 p1_13 = 0x80; 948 p1_13 = 0x80;
854 backlight = FALSE; 949 backlight = FALSE;
855 break; 950 break;
856 case FB_BLANK_HSYNC_SUSPEND: /* no hsync */ 951 case FB_BLANK_HSYNC_SUSPEND: /* no hsync */
857 sr01 = 0x20; 952 sr01 = 0x20;
858 sr11 = 0x08; 953 sr11 = 0x08;
859 sr1f = 0x40; 954 sr1f = 0x40;
860 cr63 = 0x40; 955 cr63 = 0x40;
861 p2_0 = 0x80; 956 p2_0 = 0x80;
862 p1_13 = 0x40; 957 p1_13 = 0x40;
863 backlight = FALSE; 958 backlight = FALSE;
864 break; 959 break;
865 case FB_BLANK_POWERDOWN: /* off */ 960 case FB_BLANK_POWERDOWN: /* off */
866 sr01 = 0x20; 961 sr01 = 0x20;
867 sr11 = 0x08; 962 sr11 = 0x08;
868 sr1f = 0xc0; 963 sr1f = 0xc0;
869 cr63 = 0x40; 964 cr63 = 0x40;
870 p2_0 = 0xc0; 965 p2_0 = 0xc0;
871 p1_13 = 0xc0; 966 p1_13 = 0xc0;
872 backlight = FALSE; 967 backlight = FALSE;
873 break; 968 break;
874 default: 969 default:
875 return 1; 970 return 1;
876 } 971 }
877 972
878 if(ivideo->currentvbflags & VB_DISPTYPE_CRT1) { 973 if(ivideo->currentvbflags & VB_DISPTYPE_CRT1) {
879 974
880 if( (!ivideo->sisfb_thismonitor.datavalid) || 975 if( (!ivideo->sisfb_thismonitor.datavalid) ||
881 ((ivideo->sisfb_thismonitor.datavalid) && 976 ((ivideo->sisfb_thismonitor.datavalid) &&
882 (ivideo->sisfb_thismonitor.feature & 0xe0))) { 977 (ivideo->sisfb_thismonitor.feature & 0xe0))) {
883 978
884 if(ivideo->sisvga_engine == SIS_315_VGA) { 979 if(ivideo->sisvga_engine == SIS_315_VGA) {
885 setSISIDXREG(SISCR, ivideo->SiS_Pr.SiS_MyCR63, 0xbf, cr63); 980 setSISIDXREG(SISCR, ivideo->SiS_Pr.SiS_MyCR63, 0xbf, cr63);
886 } 981 }
887 982
888 if(!(sisfb_bridgeisslave(ivideo))) { 983 if(!(sisfb_bridgeisslave(ivideo))) {
889 setSISIDXREG(SISSR, 0x01, ~0x20, sr01); 984 setSISIDXREG(SISSR, 0x01, ~0x20, sr01);
890 setSISIDXREG(SISSR, 0x1f, 0x3f, sr1f); 985 setSISIDXREG(SISSR, 0x1f, 0x3f, sr1f);
891 } 986 }
892 } 987 }
893 988
894 } 989 }
895 990
896 if(ivideo->currentvbflags & CRT2_LCD) { 991 if(ivideo->currentvbflags & CRT2_LCD) {
897 992
898 if(ivideo->vbflags & (VB_301LV|VB_302LV|VB_302ELV)) { 993 if(ivideo->vbflags2 & VB2_SISLVDSBRIDGE) {
899 if(backlight) { 994 if(backlight) {
900 SiS_SiS30xBLOn(&ivideo->SiS_Pr, &ivideo->sishw_ext); 995 SiS_SiS30xBLOn(&ivideo->SiS_Pr);
901 } else { 996 } else {
902 SiS_SiS30xBLOff(&ivideo->SiS_Pr, &ivideo->sishw_ext); 997 SiS_SiS30xBLOff(&ivideo->SiS_Pr);
903 } 998 }
904 } else if(ivideo->sisvga_engine == SIS_315_VGA) { 999 } else if(ivideo->sisvga_engine == SIS_315_VGA) {
905 if(ivideo->vbflags & VB_CHRONTEL) { 1000#ifdef CONFIG_FB_SIS_315
906 if(backlight) { 1001 if(ivideo->vbflags2 & VB2_CHRONTEL) {
907 SiS_Chrontel701xBLOn(&ivideo->SiS_Pr,&ivideo->sishw_ext); 1002 if(backlight) {
908 } else { 1003 SiS_Chrontel701xBLOn(&ivideo->SiS_Pr);
909 SiS_Chrontel701xBLOff(&ivideo->SiS_Pr); 1004 } else {
910 } 1005 SiS_Chrontel701xBLOff(&ivideo->SiS_Pr);
911 } 1006 }
912 } 1007 }
913 1008#endif
914 if(((ivideo->sisvga_engine == SIS_300_VGA) && 1009 }
915 (ivideo->vbflags & (VB_301|VB_30xBDH|VB_LVDS))) || 1010
916 ((ivideo->sisvga_engine == SIS_315_VGA) && 1011 if(((ivideo->sisvga_engine == SIS_300_VGA) &&
917 ((ivideo->vbflags & (VB_LVDS | VB_CHRONTEL)) == VB_LVDS))) { 1012 (ivideo->vbflags2 & (VB2_301|VB2_30xBDH|VB2_LVDS))) ||
918 setSISIDXREG(SISSR, 0x11, ~0x0c, sr11); 1013 ((ivideo->sisvga_engine == SIS_315_VGA) &&
919 } 1014 ((ivideo->vbflags2 & (VB2_LVDS | VB2_CHRONTEL)) == VB2_LVDS))) {
920 1015 setSISIDXREG(SISSR, 0x11, ~0x0c, sr11);
921 if(ivideo->sisvga_engine == SIS_300_VGA) { 1016 }
922 if((ivideo->vbflags & (VB_301B|VB_301C|VB_302B)) && 1017
923 (!(ivideo->vbflags & VB_30xBDH))) { 1018 if(ivideo->sisvga_engine == SIS_300_VGA) {
924 setSISIDXREG(SISPART1, 0x13, 0x3f, p1_13); 1019 if((ivideo->vbflags2 & VB2_30xB) &&
925 } 1020 (!(ivideo->vbflags2 & VB2_30xBDH))) {
926 } else if(ivideo->sisvga_engine == SIS_315_VGA) { 1021 setSISIDXREG(SISPART1, 0x13, 0x3f, p1_13);
927 if((ivideo->vbflags & (VB_301B|VB_301C|VB_302B)) && 1022 }
928 (!(ivideo->vbflags & VB_30xBDH))) { 1023 } else if(ivideo->sisvga_engine == SIS_315_VGA) {
929 setSISIDXREG(SISPART2, 0x00, 0x1f, p2_0); 1024 if((ivideo->vbflags2 & VB2_30xB) &&
930 } 1025 (!(ivideo->vbflags2 & VB2_30xBDH))) {
931 } 1026 setSISIDXREG(SISPART2, 0x00, 0x1f, p2_0);
932 1027 }
933 } else if(ivideo->currentvbflags & CRT2_VGA) { 1028 }
934 1029
935 if(ivideo->vbflags & (VB_301B|VB_301C|VB_302B)) { 1030 } else if(ivideo->currentvbflags & CRT2_VGA) {
936 setSISIDXREG(SISPART2, 0x00, 0x1f, p2_0); 1031
937 } 1032 if(ivideo->vbflags2 & VB2_30xB) {
938 1033 setSISIDXREG(SISPART2, 0x00, 0x1f, p2_0);
939 } 1034 }
940 1035
941 return(0); 1036 }
1037
1038 return 0;
1039}
1040
1041/* ------------- Callbacks from init.c/init301.c -------------- */
1042
1043#ifdef CONFIG_FB_SIS_300
1044unsigned int
1045sisfb_read_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg)
1046{
1047 struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo;
1048 u32 val = 0;
1049
1050 pci_read_config_dword(ivideo->nbridge, reg, &val);
1051 return (unsigned int)val;
1052}
1053
1054void
1055sisfb_write_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg, unsigned int val)
1056{
1057 struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo;
1058
1059 pci_write_config_dword(ivideo->nbridge, reg, (u32)val);
942} 1060}
943 1061
1062unsigned int
1063sisfb_read_lpc_pci_dword(struct SiS_Private *SiS_Pr, int reg)
1064{
1065 struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo;
1066 u32 val = 0;
1067
1068 if(!ivideo->lpcdev) return 0;
1069
1070 pci_read_config_dword(ivideo->lpcdev, reg, &val);
1071 return (unsigned int)val;
1072}
1073#endif
1074
1075#ifdef CONFIG_FB_SIS_315
1076void
1077sisfb_write_nbridge_pci_byte(struct SiS_Private *SiS_Pr, int reg, unsigned char val)
1078{
1079 struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo;
1080
1081 pci_write_config_byte(ivideo->nbridge, reg, (u8)val);
1082}
1083
1084unsigned int
1085sisfb_read_mio_pci_word(struct SiS_Private *SiS_Pr, int reg)
1086{
1087 struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo;
1088 u16 val = 0;
1089
1090 if(!ivideo->lpcdev) return 0;
1091
1092 pci_read_config_word(ivideo->lpcdev, reg, &val);
1093 return (unsigned int)val;
1094}
1095#endif
1096
944/* ----------- FBDev related routines for all series ----------- */ 1097/* ----------- FBDev related routines for all series ----------- */
945 1098
946static int 1099static int
@@ -952,7 +1105,7 @@ sisfb_get_cmap_len(const struct fb_var_screeninfo *var)
952static void 1105static void
953sisfb_set_vparms(struct sis_video_info *ivideo) 1106sisfb_set_vparms(struct sis_video_info *ivideo)
954{ 1107{
955 switch(ivideo->video_bpp) { 1108 switch(ivideo->video_bpp) {
956 case 8: 1109 case 8:
957 ivideo->DstColor = 0x0000; 1110 ivideo->DstColor = 0x0000;
958 ivideo->SiS310_AccelDepth = 0x00000000; 1111 ivideo->SiS310_AccelDepth = 0x00000000;
@@ -972,14 +1125,13 @@ sisfb_set_vparms(struct sis_video_info *ivideo)
972 ivideo->video_cmap_len = 16; 1125 ivideo->video_cmap_len = 16;
973 printk(KERN_ERR "sisfb: Unsupported depth %d", ivideo->video_bpp); 1126 printk(KERN_ERR "sisfb: Unsupported depth %d", ivideo->video_bpp);
974 ivideo->accel = 0; 1127 ivideo->accel = 0;
975 break; 1128 }
976 }
977} 1129}
978 1130
979static int 1131static int
980sisfb_calc_maxyres(struct sis_video_info *ivideo, struct fb_var_screeninfo *var) 1132sisfb_calc_maxyres(struct sis_video_info *ivideo, struct fb_var_screeninfo *var)
981{ 1133{
982 int maxyres = ivideo->heapstart / (var->xres_virtual * (var->bits_per_pixel >> 3)); 1134 int maxyres = ivideo->sisfb_mem / (var->xres_virtual * (var->bits_per_pixel >> 3));
983 1135
984 if(maxyres > 32767) maxyres = 32767; 1136 if(maxyres > 32767) maxyres = 32767;
985 1137
@@ -996,30 +1148,29 @@ sisfb_calc_pitch(struct sis_video_info *ivideo, struct fb_var_screeninfo *var)
996 ivideo->scrnpitchCRT1 <<= 1; 1148 ivideo->scrnpitchCRT1 <<= 1;
997 } 1149 }
998 } 1150 }
999
1000} 1151}
1001 1152
1002static void 1153static void
1003sisfb_set_pitch(struct sis_video_info *ivideo) 1154sisfb_set_pitch(struct sis_video_info *ivideo)
1004{ 1155{
1005 BOOLEAN isslavemode = FALSE; 1156 BOOLEAN isslavemode = FALSE;
1006 unsigned short HDisplay1 = ivideo->scrnpitchCRT1 >> 3; 1157 unsigned short HDisplay1 = ivideo->scrnpitchCRT1 >> 3;
1007 unsigned short HDisplay2 = ivideo->video_linelength >> 3; 1158 unsigned short HDisplay2 = ivideo->video_linelength >> 3;
1008 1159
1009 if(sisfb_bridgeisslave(ivideo)) isslavemode = TRUE; 1160 if(sisfb_bridgeisslave(ivideo)) isslavemode = TRUE;
1010 1161
1011 /* We need to set pitch for CRT1 if bridge is in slave mode, too */ 1162 /* We need to set pitch for CRT1 if bridge is in slave mode, too */
1012 if((ivideo->currentvbflags & VB_DISPTYPE_DISP1) || (isslavemode)) { 1163 if((ivideo->currentvbflags & VB_DISPTYPE_DISP1) || (isslavemode)) {
1013 outSISIDXREG(SISCR,0x13,(HDisplay1 & 0xFF)); 1164 outSISIDXREG(SISCR,0x13,(HDisplay1 & 0xFF));
1014 setSISIDXREG(SISSR,0x0E,0xF0,(HDisplay1 >> 8)); 1165 setSISIDXREG(SISSR,0x0E,0xF0,(HDisplay1 >> 8));
1015 } 1166 }
1016 1167
1017 /* We must not set the pitch for CRT2 if bridge is in slave mode */ 1168 /* We must not set the pitch for CRT2 if bridge is in slave mode */
1018 if((ivideo->currentvbflags & VB_DISPTYPE_DISP2) && (!isslavemode)) { 1169 if((ivideo->currentvbflags & VB_DISPTYPE_DISP2) && (!isslavemode)) {
1019 orSISIDXREG(SISPART1,ivideo->CRT2_write_enable,0x01); 1170 orSISIDXREG(SISPART1,ivideo->CRT2_write_enable,0x01);
1020 outSISIDXREG(SISPART1,0x07,(HDisplay2 & 0xFF)); 1171 outSISIDXREG(SISPART1,0x07,(HDisplay2 & 0xFF));
1021 setSISIDXREG(SISPART1,0x09,0xF0,(HDisplay2 >> 8)); 1172 setSISIDXREG(SISPART1,0x09,0xF0,(HDisplay2 >> 8));
1022 } 1173 }
1023} 1174}
1024 1175
1025static void 1176static void
@@ -1056,12 +1207,41 @@ sisfb_bpp_to_var(struct sis_video_info *ivideo, struct fb_var_screeninfo *var)
1056} 1207}
1057 1208
1058static int 1209static int
1210sisfb_set_mode(struct sis_video_info *ivideo, int clrscrn)
1211{
1212 unsigned short modeno = ivideo->mode_no;
1213
1214 /* >=2.6.12's fbcon clears the screen anyway */
1215#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12)
1216 if(!clrscrn) modeno |= 0x80;
1217#else
1218 modeno |= 0x80;
1219#endif
1220
1221 outSISIDXREG(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD);
1222
1223 sisfb_pre_setmode(ivideo);
1224
1225 if(SiSSetMode(&ivideo->SiS_Pr, modeno) == 0) {
1226 printk(KERN_ERR "sisfb: Setting mode[0x%x] failed\n", ivideo->mode_no);
1227 return -EINVAL;
1228 }
1229
1230 outSISIDXREG(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD);
1231
1232 sisfb_post_setmode(ivideo);
1233
1234 return 0;
1235}
1236
1237
1238static int
1059sisfb_do_set_var(struct fb_var_screeninfo *var, int isactive, struct fb_info *info) 1239sisfb_do_set_var(struct fb_var_screeninfo *var, int isactive, struct fb_info *info)
1060{ 1240{
1061 struct sis_video_info *ivideo = (struct sis_video_info *)info->par; 1241 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1062 unsigned int htotal = 0, vtotal = 0; 1242 unsigned int htotal = 0, vtotal = 0;
1063 unsigned int drate = 0, hrate = 0; 1243 unsigned int drate = 0, hrate = 0;
1064 int found_mode = 0; 1244 int found_mode = 0, ret;
1065 int old_mode; 1245 int old_mode;
1066 u32 pixclock; 1246 u32 pixclock;
1067 1247
@@ -1088,11 +1268,11 @@ sisfb_do_set_var(struct fb_var_screeninfo *var, int isactive, struct fb_info *in
1088 } 1268 }
1089 1269
1090 if(pixclock && htotal && vtotal) { 1270 if(pixclock && htotal && vtotal) {
1091 drate = 1000000000 / pixclock; 1271 drate = 1000000000 / pixclock;
1092 hrate = (drate * 1000) / htotal; 1272 hrate = (drate * 1000) / htotal;
1093 ivideo->refresh_rate = (unsigned int) (hrate * 2 / vtotal); 1273 ivideo->refresh_rate = (unsigned int) (hrate * 2 / vtotal);
1094 } else { 1274 } else {
1095 ivideo->refresh_rate = 60; 1275 ivideo->refresh_rate = 60;
1096 } 1276 }
1097 1277
1098 old_mode = ivideo->sisfb_mode_idx; 1278 old_mode = ivideo->sisfb_mode_idx;
@@ -1113,6 +1293,7 @@ sisfb_do_set_var(struct fb_var_screeninfo *var, int isactive, struct fb_info *in
1113 if(found_mode) { 1293 if(found_mode) {
1114 ivideo->sisfb_mode_idx = sisfb_validate_mode(ivideo, 1294 ivideo->sisfb_mode_idx = sisfb_validate_mode(ivideo,
1115 ivideo->sisfb_mode_idx, ivideo->currentvbflags); 1295 ivideo->sisfb_mode_idx, ivideo->currentvbflags);
1296 ivideo->mode_no = sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni];
1116 } else { 1297 } else {
1117 ivideo->sisfb_mode_idx = -1; 1298 ivideo->sisfb_mode_idx = -1;
1118 } 1299 }
@@ -1131,10 +1312,10 @@ sisfb_do_set_var(struct fb_var_screeninfo *var, int isactive, struct fb_info *in
1131 1312
1132#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 1313#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1133 if(ivideo->sisfb_thismonitor.datavalid) { 1314 if(ivideo->sisfb_thismonitor.datavalid) {
1134 if(!sisfb_verify_rate(ivideo, &ivideo->sisfb_thismonitor, ivideo->sisfb_mode_idx, 1315 if(!sisfb_verify_rate(ivideo, &ivideo->sisfb_thismonitor, ivideo->sisfb_mode_idx,
1135 ivideo->rate_idx, ivideo->refresh_rate)) { 1316 ivideo->rate_idx, ivideo->refresh_rate)) {
1136 printk(KERN_INFO "sisfb: WARNING: Refresh rate exceeds monitor specs!\n"); 1317 printk(KERN_INFO "sisfb: WARNING: Refresh rate exceeds monitor specs!\n");
1137 } 1318 }
1138 } 1319 }
1139#endif 1320#endif
1140 1321
@@ -1143,24 +1324,9 @@ sisfb_do_set_var(struct fb_var_screeninfo *var, int isactive, struct fb_info *in
1143#else 1324#else
1144 if(isactive) { 1325 if(isactive) {
1145#endif 1326#endif
1146 sisfb_pre_setmode(ivideo); 1327 /* If acceleration to be used? Need to know
1147 1328 * before pre/post_set_mode()
1148 if(SiSSetMode(&ivideo->SiS_Pr, &ivideo->sishw_ext, ivideo->mode_no) == 0) { 1329 */
1149 printk(KERN_ERR "sisfb: Setting mode[0x%x] failed\n", ivideo->mode_no);
1150 return -EINVAL;
1151 }
1152
1153 outSISIDXREG(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD);
1154
1155 sisfb_post_setmode(ivideo);
1156
1157 ivideo->video_bpp = sisbios_mode[ivideo->sisfb_mode_idx].bpp;
1158 ivideo->video_width = sisbios_mode[ivideo->sisfb_mode_idx].xres;
1159 ivideo->video_height = sisbios_mode[ivideo->sisfb_mode_idx].yres;
1160
1161 sisfb_calc_pitch(ivideo, var);
1162 sisfb_set_pitch(ivideo);
1163
1164 ivideo->accel = 0; 1330 ivideo->accel = 0;
1165#if defined(FBINFO_HWACCEL_DISABLED) && defined(FBINFO_HWACCEL_XPAN) 1331#if defined(FBINFO_HWACCEL_DISABLED) && defined(FBINFO_HWACCEL_XPAN)
1166#ifdef STUPID_ACCELF_TEXT_SHIT 1332#ifdef STUPID_ACCELF_TEXT_SHIT
@@ -1175,6 +1341,17 @@ sisfb_do_set_var(struct fb_var_screeninfo *var, int isactive, struct fb_info *in
1175 if(var->accel_flags & FB_ACCELF_TEXT) ivideo->accel = -1; 1341 if(var->accel_flags & FB_ACCELF_TEXT) ivideo->accel = -1;
1176#endif 1342#endif
1177 1343
1344 if((ret = sisfb_set_mode(ivideo, 1))) {
1345 return ret;
1346 }
1347
1348 ivideo->video_bpp = sisbios_mode[ivideo->sisfb_mode_idx].bpp;
1349 ivideo->video_width = sisbios_mode[ivideo->sisfb_mode_idx].xres;
1350 ivideo->video_height = sisbios_mode[ivideo->sisfb_mode_idx].yres;
1351
1352 sisfb_calc_pitch(ivideo, var);
1353 sisfb_set_pitch(ivideo);
1354
1178 sisfb_set_vparms(ivideo); 1355 sisfb_set_vparms(ivideo);
1179 1356
1180 ivideo->current_width = ivideo->video_width; 1357 ivideo->current_width = ivideo->video_width;
@@ -1186,572 +1363,79 @@ sisfb_do_set_var(struct fb_var_screeninfo *var, int isactive, struct fb_info *in
1186 ivideo->current_pixclock = var->pixclock; 1363 ivideo->current_pixclock = var->pixclock;
1187 ivideo->current_refresh_rate = ivideo->refresh_rate; 1364 ivideo->current_refresh_rate = ivideo->refresh_rate;
1188#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 1365#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1189 ivideo->sisfb_lastrates[ivideo->mode_no] = ivideo->refresh_rate; 1366 ivideo->sisfb_lastrates[ivideo->mode_no] = ivideo->refresh_rate;
1190#endif 1367#endif
1191 } 1368 }
1192 1369
1193 return 0; 1370 return 0;
1194} 1371}
1195 1372
1196static int 1373static void
1197sisfb_pan_var(struct sis_video_info *ivideo, struct fb_var_screeninfo *var) 1374sisfb_set_base_CRT1(struct sis_video_info *ivideo, unsigned int base)
1198{ 1375{
1199 unsigned int base;
1200
1201 if(var->xoffset > (var->xres_virtual - var->xres)) {
1202 return -EINVAL;
1203 }
1204 if(var->yoffset > (var->yres_virtual - var->yres)) {
1205 return -EINVAL;
1206 }
1207
1208 base = (var->yoffset * var->xres_virtual) + var->xoffset;
1209
1210 /* calculate base bpp dep. */
1211 switch(var->bits_per_pixel) {
1212 case 32:
1213 break;
1214 case 16:
1215 base >>= 1;
1216 break;
1217 case 8:
1218 default:
1219 base >>= 2;
1220 break;
1221 }
1222
1223 outSISIDXREG(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD); 1376 outSISIDXREG(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD);
1224 1377
1225 outSISIDXREG(SISCR, 0x0D, base & 0xFF); 1378 outSISIDXREG(SISCR, 0x0D, base & 0xFF);
1226 outSISIDXREG(SISCR, 0x0C, (base >> 8) & 0xFF); 1379 outSISIDXREG(SISCR, 0x0C, (base >> 8) & 0xFF);
1227 outSISIDXREG(SISSR, 0x0D, (base >> 16) & 0xFF); 1380 outSISIDXREG(SISSR, 0x0D, (base >> 16) & 0xFF);
1228 if(ivideo->sisvga_engine == SIS_315_VGA) { 1381 if(ivideo->sisvga_engine == SIS_315_VGA) {
1229 setSISIDXREG(SISSR, 0x37, 0xFE, (base >> 24) & 0x01); 1382 setSISIDXREG(SISSR, 0x37, 0xFE, (base >> 24) & 0x01);
1230 } 1383 }
1231 if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
1232 orSISIDXREG(SISPART1, ivideo->CRT2_write_enable, 0x01);
1233 outSISIDXREG(SISPART1, 0x06, (base & 0xFF));
1234 outSISIDXREG(SISPART1, 0x05, ((base >> 8) & 0xFF));
1235 outSISIDXREG(SISPART1, 0x04, ((base >> 16) & 0xFF));
1236 if(ivideo->sisvga_engine == SIS_315_VGA) {
1237 setSISIDXREG(SISPART1, 0x02, 0x7F, ((base >> 24) & 0x01) << 7);
1238 }
1239 }
1240 return 0;
1241} 1384}
1242 1385
1243/* ------------ FBDev related routines for 2.4 series ----------- */
1244
1245#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1246
1247static void 1386static void
1248sisfb_crtc_to_var(struct sis_video_info *ivideo, struct fb_var_screeninfo *var) 1387sisfb_set_base_CRT2(struct sis_video_info *ivideo, unsigned int base)
1249{
1250 u16 VRE, VBE, VRS, VBS, VDE, VT;
1251 u16 HRE, HBE, HRS, HBS, HDE, HT;
1252 u8 sr_data, cr_data, cr_data2, cr_data3, mr_data;
1253 int A, B, C, D, E, F, temp;
1254 unsigned int hrate, drate, maxyres;
1255
1256 inSISIDXREG(SISSR, IND_SIS_COLOR_MODE, sr_data);
1257
1258 if(sr_data & SIS_INTERLACED_MODE)
1259 var->vmode = FB_VMODE_INTERLACED;
1260 else
1261 var->vmode = FB_VMODE_NONINTERLACED;
1262
1263 switch((sr_data & 0x1C) >> 2) {
1264 case SIS_8BPP_COLOR_MODE:
1265 var->bits_per_pixel = 8;
1266 break;
1267 case SIS_16BPP_COLOR_MODE:
1268 var->bits_per_pixel = 16;
1269 break;
1270 case SIS_32BPP_COLOR_MODE:
1271 var->bits_per_pixel = 32;
1272 break;
1273 }
1274
1275 sisfb_bpp_to_var(ivideo, var);
1276
1277 inSISIDXREG(SISSR, 0x0A, sr_data);
1278 inSISIDXREG(SISCR, 0x06, cr_data);
1279 inSISIDXREG(SISCR, 0x07, cr_data2);
1280
1281 VT = (cr_data & 0xFF) |
1282 ((u16) (cr_data2 & 0x01) << 8) |
1283 ((u16) (cr_data2 & 0x20) << 4) |
1284 ((u16) (sr_data & 0x01) << 10);
1285 A = VT + 2;
1286
1287 inSISIDXREG(SISCR, 0x12, cr_data);
1288
1289 VDE = (cr_data & 0xff) |
1290 ((u16) (cr_data2 & 0x02) << 7) |
1291 ((u16) (cr_data2 & 0x40) << 3) |
1292 ((u16) (sr_data & 0x02) << 9);
1293 E = VDE + 1;
1294
1295 inSISIDXREG(SISCR, 0x10, cr_data);
1296
1297 VRS = (cr_data & 0xff) |
1298 ((u16) (cr_data2 & 0x04) << 6) |
1299 ((u16) (cr_data2 & 0x80) << 2) |
1300 ((u16) (sr_data & 0x08) << 7);
1301 F = VRS + 1 - E;
1302
1303 inSISIDXREG(SISCR, 0x15, cr_data);
1304 inSISIDXREG(SISCR, 0x09, cr_data3);
1305
1306 if(cr_data3 & 0x80) var->vmode = FB_VMODE_DOUBLE;
1307
1308 VBS = (cr_data & 0xff) |
1309 ((u16) (cr_data2 & 0x08) << 5) |
1310 ((u16) (cr_data3 & 0x20) << 4) |
1311 ((u16) (sr_data & 0x04) << 8);
1312
1313 inSISIDXREG(SISCR, 0x16, cr_data);
1314
1315 VBE = (cr_data & 0xff) | ((u16) (sr_data & 0x10) << 4);
1316 temp = VBE - ((E - 1) & 511);
1317 B = (temp > 0) ? temp : (temp + 512);
1318
1319 inSISIDXREG(SISCR, 0x11, cr_data);
1320
1321 VRE = (cr_data & 0x0f) | ((sr_data & 0x20) >> 1);
1322 temp = VRE - ((E + F - 1) & 31);
1323 C = (temp > 0) ? temp : (temp + 32);
1324
1325 D = B - F - C;
1326
1327 var->yres = E;
1328 var->upper_margin = D;
1329 var->lower_margin = F;
1330 var->vsync_len = C;
1331
1332 if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
1333 var->yres <<= 1;
1334 var->upper_margin <<= 1;
1335 var->lower_margin <<= 1;
1336 var->vsync_len <<= 1;
1337 } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {
1338 var->yres >>= 1;
1339 var->upper_margin >>= 1;
1340 var->lower_margin >>= 1;
1341 var->vsync_len >>= 1;
1342 }
1343
1344 inSISIDXREG(SISSR, 0x0b, sr_data);
1345 inSISIDXREG(SISCR, 0x00, cr_data);
1346
1347 HT = (cr_data & 0xff) | ((u16) (sr_data & 0x03) << 8);
1348 A = HT + 5;
1349
1350 inSISIDXREG(SISCR, 0x01, cr_data);
1351
1352 HDE = (cr_data & 0xff) | ((u16) (sr_data & 0x0C) << 6);
1353 E = HDE + 1;
1354
1355 inSISIDXREG(SISCR, 0x04, cr_data);
1356
1357 HRS = (cr_data & 0xff) | ((u16) (sr_data & 0xC0) << 2);
1358 F = HRS - E - 3;
1359
1360 inSISIDXREG(SISCR, 0x02, cr_data);
1361
1362 HBS = (cr_data & 0xff) | ((u16) (sr_data & 0x30) << 4);
1363
1364 inSISIDXREG(SISSR, 0x0c, sr_data);
1365 inSISIDXREG(SISCR, 0x03, cr_data);
1366 inSISIDXREG(SISCR, 0x05, cr_data2);
1367
1368 HBE = (cr_data & 0x1f) |
1369 ((u16) (cr_data2 & 0x80) >> 2) |
1370 ((u16) (sr_data & 0x03) << 6);
1371 HRE = (cr_data2 & 0x1f) | ((sr_data & 0x04) << 3);
1372
1373 temp = HBE - ((E - 1) & 255);
1374 B = (temp > 0) ? temp : (temp + 256);
1375
1376 temp = HRE - ((E + F + 3) & 63);
1377 C = (temp > 0) ? temp : (temp + 64);
1378
1379 D = B - F - C;
1380
1381 var->xres = E * 8;
1382 if(var->xres_virtual < var->xres) {
1383 var->xres_virtual = var->xres;
1384 }
1385
1386 if((var->xres == 320) &&
1387 (var->yres == 200 || var->yres == 240)) {
1388 /* Terrible hack, but the correct CRTC data for
1389 * these modes only produces a black screen...
1390 */
1391 var->left_margin = (400 - 376);
1392 var->right_margin = (328 - 320);
1393 var->hsync_len = (376 - 328);
1394 } else {
1395 var->left_margin = D * 8;
1396 var->right_margin = F * 8;
1397 var->hsync_len = C * 8;
1398 }
1399 var->activate = FB_ACTIVATE_NOW;
1400
1401 var->sync = 0;
1402
1403 mr_data = inSISREG(SISMISCR);
1404 if(mr_data & 0x80)
1405 var->sync &= ~FB_SYNC_VERT_HIGH_ACT;
1406 else
1407 var->sync |= FB_SYNC_VERT_HIGH_ACT;
1408
1409 if(mr_data & 0x40)
1410 var->sync &= ~FB_SYNC_HOR_HIGH_ACT;
1411 else
1412 var->sync |= FB_SYNC_HOR_HIGH_ACT;
1413
1414 VT += 2;
1415 VT <<= 1;
1416 HT = (HT + 5) * 8;
1417
1418 if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
1419 VT <<= 1;
1420 }
1421 hrate = ivideo->refresh_rate * VT / 2;
1422 drate = (hrate * HT) / 1000;
1423 var->pixclock = (u32) (1000000000 / drate);
1424
1425 if(ivideo->sisfb_ypan) {
1426 maxyres = sisfb_calc_maxyres(ivideo, var);
1427 if(ivideo->sisfb_max) {
1428 var->yres_virtual = maxyres;
1429 } else {
1430 if(var->yres_virtual > maxyres) {
1431 var->yres_virtual = maxyres;
1432 }
1433 }
1434 if(var->yres_virtual <= var->yres) {
1435 var->yres_virtual = var->yres;
1436 }
1437 } else {
1438 var->yres_virtual = var->yres;
1439 }
1440
1441}
1442
1443static int
1444sis_getcolreg(unsigned regno, unsigned *red, unsigned *green, unsigned *blue,
1445 unsigned *transp, struct fb_info *info)
1446{ 1388{
1447 struct sis_video_info *ivideo = (struct sis_video_info *)info->par; 1389 if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
1448 1390 orSISIDXREG(SISPART1, ivideo->CRT2_write_enable, 0x01);
1449 if(regno >= ivideo->video_cmap_len) return 1; 1391 outSISIDXREG(SISPART1, 0x06, (base & 0xFF));
1450 1392 outSISIDXREG(SISPART1, 0x05, ((base >> 8) & 0xFF));
1451 *red = ivideo->sis_palette[regno].red; 1393 outSISIDXREG(SISPART1, 0x04, ((base >> 16) & 0xFF));
1452 *green = ivideo->sis_palette[regno].green; 1394 if(ivideo->sisvga_engine == SIS_315_VGA) {
1453 *blue = ivideo->sis_palette[regno].blue; 1395 setSISIDXREG(SISPART1, 0x02, 0x7F, ((base >> 24) & 0x01) << 7);
1454 *transp = 0;
1455
1456 return 0;
1457}
1458
1459static int
1460sisfb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue,
1461 unsigned transp, struct fb_info *info)
1462{
1463 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1464
1465 if(regno >= ivideo->video_cmap_len) return 1;
1466
1467 ivideo->sis_palette[regno].red = red;
1468 ivideo->sis_palette[regno].green = green;
1469 ivideo->sis_palette[regno].blue = blue;
1470
1471 switch(ivideo->video_bpp) {
1472#ifdef FBCON_HAS_CFB8
1473 case 8:
1474 outSISREG(SISDACA, regno);
1475 outSISREG(SISDACD, (red >> 10));
1476 outSISREG(SISDACD, (green >> 10));
1477 outSISREG(SISDACD, (blue >> 10));
1478 if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
1479 outSISREG(SISDAC2A, regno);
1480 outSISREG(SISDAC2D, (red >> 8));
1481 outSISREG(SISDAC2D, (green >> 8));
1482 outSISREG(SISDAC2D, (blue >> 8));
1483 } 1396 }
1484 break;
1485#endif
1486#ifdef FBCON_HAS_CFB16
1487 case 16:
1488 ivideo->sis_fbcon_cmap.cfb16[regno] =
1489 ((red & 0xf800)) | ((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11);
1490 break;
1491#endif
1492#ifdef FBCON_HAS_CFB32
1493 case 32:
1494 red >>= 8;
1495 green >>= 8;
1496 blue >>= 8;
1497 ivideo->sis_fbcon_cmap.cfb32[regno] = (red << 16) | (green << 8) | (blue);
1498 break;
1499#endif
1500 }
1501
1502 return 0;
1503}
1504
1505static void
1506sisfb_set_disp(int con, struct fb_var_screeninfo *var, struct fb_info *info)
1507{
1508 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1509 struct display *display;
1510 struct display_switch *sw;
1511 struct fb_fix_screeninfo fix;
1512 long flags;
1513
1514 display = (con >= 0) ? &fb_display[con] : &ivideo->sis_disp;
1515
1516 sisfb_get_fix(&fix, con, info);
1517
1518 display->var = *var;
1519 display->screen_base = (char *)ivideo->video_vbase;
1520 display->visual = fix.visual;
1521 display->type = fix.type;
1522 display->type_aux = fix.type_aux;
1523 display->ypanstep = fix.ypanstep;
1524 display->ywrapstep = fix.ywrapstep;
1525 display->line_length = fix.line_length;
1526 display->can_soft_blank = 1;
1527 display->inverse = ivideo->sisfb_inverse;
1528 display->next_line = fix.line_length;
1529
1530 save_flags(flags);
1531
1532 switch(ivideo->video_bpp) {
1533#ifdef FBCON_HAS_CFB8
1534 case 8: sw = ivideo->accel ? &fbcon_sis8 : &fbcon_cfb8;
1535 break;
1536#endif
1537#ifdef FBCON_HAS_CFB16
1538 case 16:sw = ivideo->accel ? &fbcon_sis16 : &fbcon_cfb16;
1539 display->dispsw_data = &ivideo->sis_fbcon_cmap.cfb16;
1540 break;
1541#endif
1542#ifdef FBCON_HAS_CFB32
1543 case 32:sw = ivideo->accel ? &fbcon_sis32 : &fbcon_cfb32;
1544 display->dispsw_data = &ivideo->sis_fbcon_cmap.cfb32;
1545 break;
1546#endif
1547 default:sw = &fbcon_dummy;
1548 break;
1549 }
1550 memcpy(&ivideo->sisfb_sw, sw, sizeof(*sw));
1551 display->dispsw = &ivideo->sisfb_sw;
1552
1553 restore_flags(flags);
1554
1555 if(ivideo->sisfb_ypan) {
1556 /* display->scrollmode = 0; */
1557 } else {
1558 display->scrollmode = SCROLL_YREDRAW;
1559 ivideo->sisfb_sw.bmove = fbcon_redraw_bmove;
1560 }
1561}
1562
1563static void
1564sisfb_do_install_cmap(int con, struct fb_info *info)
1565{
1566 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1567
1568 if(con != ivideo->currcon) return;
1569
1570 if(fb_display[con].cmap.len) {
1571 fb_set_cmap(&fb_display[con].cmap, 1, sisfb_setcolreg, info);
1572 } else {
1573 int size = sisfb_get_cmap_len(&fb_display[con].var);
1574 fb_set_cmap(fb_default_cmap(size), 1, sisfb_setcolreg, info);
1575 } 1397 }
1576} 1398}
1577 1399
1578static int 1400static int
1579sisfb_get_var(struct fb_var_screeninfo *var, int con, struct fb_info *info) 1401sisfb_pan_var(struct sis_video_info *ivideo, struct fb_var_screeninfo *var)
1580{
1581 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1582
1583 if(con == -1) {
1584 memcpy(var, &ivideo->default_var, sizeof(struct fb_var_screeninfo));
1585 } else {
1586 *var = fb_display[con].var;
1587 }
1588
1589 if(ivideo->sisfb_fstn) {
1590 if(var->xres == 320 && var->yres == 480) var->yres = 240;
1591 }
1592
1593 return 0;
1594}
1595
1596static int
1597sisfb_set_var(struct fb_var_screeninfo *var, int con, struct fb_info *info)
1598{ 1402{
1599 struct sis_video_info *ivideo = (struct sis_video_info *)info->par; 1403 if(var->xoffset > (var->xres_virtual - var->xres)) {
1600 int err;
1601
1602 fb_display[con].var.activate = FB_ACTIVATE_NOW;
1603
1604 if(sisfb_do_set_var(var, con == ivideo->currcon, info)) {
1605 sisfb_crtc_to_var(ivideo, var);
1606 return -EINVAL; 1404 return -EINVAL;
1607 } 1405 }
1608 1406 if(var->yoffset > (var->yres_virtual - var->yres)) {
1609 sisfb_crtc_to_var(ivideo, var); 1407 return -EINVAL;
1610
1611 sisfb_set_disp(con, var, info);
1612
1613 if(info->changevar) {
1614 (*info->changevar)(con);
1615 }
1616
1617 if((err = fb_alloc_cmap(&fb_display[con].cmap, 0, 0))) {
1618 return err;
1619 }
1620
1621 sisfb_do_install_cmap(con, info);
1622
1623#if 0 /* Why was this called here? */
1624 unsigned int cols, rows;
1625 cols = sisbios_mode[ivideo->sisfb_mode_idx].cols;
1626 rows = sisbios_mode[ivideo->sisfb_mode_idx].rows;
1627 vc_resize_con(rows, cols, fb_display[con].conp->vc_num);
1628#endif
1629 return 0;
1630}
1631
1632static int
1633sisfb_get_cmap(struct fb_cmap *cmap, int kspc, int con, struct fb_info *info)
1634{
1635 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1636 struct display *display;
1637
1638 display = (con >= 0) ? &fb_display[con] : &ivideo->sis_disp;
1639
1640 if(con == ivideo->currcon) {
1641
1642 return fb_get_cmap(cmap, kspc, sis_getcolreg, info);
1643
1644 } else if(display->cmap.len) {
1645
1646 fb_copy_cmap(&display->cmap, cmap, kspc ? 0 : 2);
1647
1648 } else {
1649
1650 int size = sisfb_get_cmap_len(&display->var);
1651 fb_copy_cmap(fb_default_cmap(size), cmap, kspc ? 0 : 2);
1652
1653 } 1408 }
1654 1409
1655 return 0; 1410 ivideo->current_base = (var->yoffset * var->xres_virtual) + var->xoffset;
1656}
1657 1411
1658static int 1412 /* calculate base bpp dep. */
1659sisfb_set_cmap(struct fb_cmap *cmap, int kspc, int con, struct fb_info *info) 1413 switch(var->bits_per_pixel) {
1660{ 1414 case 32:
1661 struct sis_video_info *ivideo = (struct sis_video_info *)info->par; 1415 break;
1662 struct display *display; 1416 case 16:
1663 int err, size; 1417 ivideo->current_base >>= 1;
1664 1418 break;
1665 display = (con >= 0) ? &fb_display[con] : &ivideo->sis_disp; 1419 case 8:
1666 1420 default:
1667 size = sisfb_get_cmap_len(&display->var); 1421 ivideo->current_base >>= 2;
1668 if(display->cmap.len != size) { 1422 break;
1669 err = fb_alloc_cmap(&display->cmap, size, 0);
1670 if(err) return err;
1671 }
1672
1673 if(con == ivideo->currcon) {
1674 return fb_set_cmap(cmap, kspc, sisfb_setcolreg, info);
1675 } else {
1676 fb_copy_cmap(cmap, &display->cmap, kspc ? 0 : 1);
1677 }
1678
1679 return 0;
1680}
1681
1682static int
1683sisfb_pan_display(struct fb_var_screeninfo *var, int con, struct fb_info* info)
1684{
1685 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1686 int err;
1687
1688 if(var->vmode & FB_VMODE_YWRAP) return -EINVAL;
1689
1690 if((var->xoffset+fb_display[con].var.xres > fb_display[con].var.xres_virtual) ||
1691 (var->yoffset+fb_display[con].var.yres > fb_display[con].var.yres_virtual)) {
1692 return -EINVAL;
1693 } 1423 }
1694 1424
1695 if(con == ivideo->currcon) { 1425 ivideo->current_base += (ivideo->video_offset >> 2);
1696 if((err = sisfb_pan_var(ivideo, var)) < 0) return err;
1697 }
1698 1426
1699 fb_display[con].var.xoffset = var->xoffset; 1427 sisfb_set_base_CRT1(ivideo, ivideo->current_base);
1700 fb_display[con].var.yoffset = var->yoffset; 1428 sisfb_set_base_CRT2(ivideo, ivideo->current_base);
1701 1429
1702 return 0; 1430 return 0;
1703} 1431}
1704 1432
1705static int 1433/* ------------ FBDev related routines for 2.4 series ----------- */
1706sisfb_update_var(int con, struct fb_info *info)
1707{
1708 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1709
1710 return(sisfb_pan_var(ivideo, &fb_display[con].var));
1711}
1712
1713static int
1714sisfb_switch(int con, struct fb_info *info)
1715{
1716 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1717 int cols, rows;
1718
1719 if(fb_display[ivideo->currcon].cmap.len) {
1720 fb_get_cmap(&fb_display[ivideo->currcon].cmap, 1, sis_getcolreg, info);
1721 }
1722
1723 fb_display[con].var.activate = FB_ACTIVATE_NOW;
1724
1725 if(!memcmp(&fb_display[con].var, &fb_display[ivideo->currcon].var,
1726 sizeof(struct fb_var_screeninfo))) {
1727 ivideo->currcon = con;
1728 return 1;
1729 }
1730
1731 ivideo->currcon = con;
1732
1733 sisfb_do_set_var(&fb_display[con].var, 1, info);
1734
1735 sisfb_set_disp(con, &fb_display[con].var, info);
1736
1737 sisfb_do_install_cmap(con, info);
1738
1739 cols = sisbios_mode[ivideo->sisfb_mode_idx].cols;
1740 rows = sisbios_mode[ivideo->sisfb_mode_idx].rows;
1741 vc_resize_con(rows, cols, fb_display[con].conp->vc_num);
1742
1743 sisfb_update_var(con, info);
1744 1434
1745 return 1; 1435#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1746}
1747 1436
1748static void 1437#include "sisfb_fbdev_2_4.h"
1749sisfb_blank(int blank, struct fb_info *info)
1750{
1751 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1752 1438
1753 sisfb_myblank(ivideo, blank);
1754}
1755#endif 1439#endif
1756 1440
1757/* ------------ FBDev related routines for 2.6 series ----------- */ 1441/* ------------ FBDev related routines for 2.6 series ----------- */
@@ -1761,13 +1445,13 @@ sisfb_blank(int blank, struct fb_info *info)
1761static int 1445static int
1762sisfb_open(struct fb_info *info, int user) 1446sisfb_open(struct fb_info *info, int user)
1763{ 1447{
1764 return 0; 1448 return 0;
1765} 1449}
1766 1450
1767static int 1451static int
1768sisfb_release(struct fb_info *info, int user) 1452sisfb_release(struct fb_info *info, int user)
1769{ 1453{
1770 return 0; 1454 return 0;
1771} 1455}
1772 1456
1773static int 1457static int
@@ -1776,16 +1460,17 @@ sisfb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue,
1776{ 1460{
1777 struct sis_video_info *ivideo = (struct sis_video_info *)info->par; 1461 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1778 1462
1779 if(regno >= sisfb_get_cmap_len(&info->var)) return 1; 1463 if(regno >= sisfb_get_cmap_len(&info->var))
1464 return 1;
1780 1465
1781 switch(info->var.bits_per_pixel) { 1466 switch(info->var.bits_per_pixel) {
1782 case 8: 1467 case 8:
1783 outSISREG(SISDACA, regno); 1468 outSISREG(SISDACA, regno);
1784 outSISREG(SISDACD, (red >> 10)); 1469 outSISREG(SISDACD, (red >> 10));
1785 outSISREG(SISDACD, (green >> 10)); 1470 outSISREG(SISDACD, (green >> 10));
1786 outSISREG(SISDACD, (blue >> 10)); 1471 outSISREG(SISDACD, (blue >> 10));
1787 if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) { 1472 if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
1788 outSISREG(SISDAC2A, regno); 1473 outSISREG(SISDAC2A, regno);
1789 outSISREG(SISDAC2D, (red >> 8)); 1474 outSISREG(SISDAC2D, (red >> 8));
1790 outSISREG(SISDAC2D, (green >> 8)); 1475 outSISREG(SISDAC2D, (green >> 8));
1791 outSISREG(SISDAC2D, (blue >> 8)); 1476 outSISREG(SISDAC2D, (blue >> 8));
@@ -1793,7 +1478,9 @@ sisfb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue,
1793 break; 1478 break;
1794 case 16: 1479 case 16:
1795 ((u32 *)(info->pseudo_palette))[regno] = 1480 ((u32 *)(info->pseudo_palette))[regno] =
1796 ((red & 0xf800)) | ((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11); 1481 (red & 0xf800) |
1482 ((green & 0xfc00) >> 5) |
1483 ((blue & 0xf800) >> 11);
1797 break; 1484 break;
1798 case 32: 1485 case 32:
1799 red >>= 8; 1486 red >>= 8;
@@ -1811,13 +1498,13 @@ sisfb_set_par(struct fb_info *info)
1811{ 1498{
1812 int err; 1499 int err;
1813 1500
1814 if((err = sisfb_do_set_var(&info->var, 1, info))) { 1501 if((err = sisfb_do_set_var(&info->var, 1, info)))
1815 return err; 1502 return err;
1816 } 1503
1817#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10) 1504#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
1818 sisfb_get_fix(&info->fix, info->currcon, info); 1505 sisfb_get_fix(&info->fix, info->currcon, info);
1819#else 1506#else
1820 sisfb_get_fix(&info->fix, -1, info); 1507 sisfb_get_fix(&info->fix, -1, info);
1821#endif 1508#endif
1822 return 0; 1509 return 0;
1823} 1510}
@@ -1829,7 +1516,7 @@ sisfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1829 unsigned int htotal = 0, vtotal = 0, myrateindex = 0; 1516 unsigned int htotal = 0, vtotal = 0, myrateindex = 0;
1830 unsigned int drate = 0, hrate = 0, maxyres; 1517 unsigned int drate = 0, hrate = 0, maxyres;
1831 int found_mode = 0; 1518 int found_mode = 0;
1832 int refresh_rate, search_idx; 1519 int refresh_rate, search_idx, tidx;
1833 BOOLEAN recalc_clock = FALSE; 1520 BOOLEAN recalc_clock = FALSE;
1834 u32 pixclock; 1521 u32 pixclock;
1835 1522
@@ -1848,7 +1535,8 @@ sisfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1848 } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) { 1535 } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
1849 vtotal += var->yres; 1536 vtotal += var->yres;
1850 vtotal <<= 1; 1537 vtotal <<= 1;
1851 } else vtotal += var->yres; 1538 } else
1539 vtotal += var->yres;
1852 1540
1853 if(!(htotal) || !(vtotal)) { 1541 if(!(htotal) || !(vtotal)) {
1854 SISFAIL("sisfb: no valid timing data"); 1542 SISFAIL("sisfb: no valid timing data");
@@ -1860,60 +1548,68 @@ sisfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1860 if( (sisbios_mode[search_idx].xres == var->xres) && 1548 if( (sisbios_mode[search_idx].xres == var->xres) &&
1861 (sisbios_mode[search_idx].yres == var->yres) && 1549 (sisbios_mode[search_idx].yres == var->yres) &&
1862 (sisbios_mode[search_idx].bpp == var->bits_per_pixel)) { 1550 (sisbios_mode[search_idx].bpp == var->bits_per_pixel)) {
1863 if(sisfb_validate_mode(ivideo, search_idx, ivideo->currentvbflags) > 0) { 1551 if((tidx = sisfb_validate_mode(ivideo, search_idx,
1864 found_mode = 1; 1552 ivideo->currentvbflags)) > 0) {
1865 break; 1553 found_mode = 1;
1554 search_idx = tidx;
1555 break;
1866 } 1556 }
1867 } 1557 }
1868 search_idx++; 1558 search_idx++;
1869 } 1559 }
1870 1560
1871 if(!found_mode) { 1561 if(!found_mode) {
1872 search_idx = 0; 1562 search_idx = 0;
1873 while(sisbios_mode[search_idx].mode_no[0] != 0) { 1563 while(sisbios_mode[search_idx].mode_no[0] != 0) {
1874 if( (var->xres <= sisbios_mode[search_idx].xres) && 1564 if( (var->xres <= sisbios_mode[search_idx].xres) &&
1875 (var->yres <= sisbios_mode[search_idx].yres) && 1565 (var->yres <= sisbios_mode[search_idx].yres) &&
1876 (var->bits_per_pixel == sisbios_mode[search_idx].bpp) ) { 1566 (var->bits_per_pixel == sisbios_mode[search_idx].bpp) ) {
1877 if(sisfb_validate_mode(ivideo,search_idx, ivideo->currentvbflags) > 0) { 1567 if((tidx = sisfb_validate_mode(ivideo,search_idx,
1878 found_mode = 1; 1568 ivideo->currentvbflags)) > 0) {
1879 break; 1569 found_mode = 1;
1880 } 1570 search_idx = tidx;
1571 break;
1572 }
1881 } 1573 }
1882 search_idx++; 1574 search_idx++;
1883 } 1575 }
1884 if(found_mode) { 1576 if(found_mode) {
1885 printk(KERN_DEBUG "sisfb: Adapted from %dx%dx%d to %dx%dx%d\n", 1577 printk(KERN_DEBUG
1886 var->xres, var->yres, var->bits_per_pixel, 1578 "sisfb: Adapted from %dx%dx%d to %dx%dx%d\n",
1579 var->xres, var->yres, var->bits_per_pixel,
1887 sisbios_mode[search_idx].xres, 1580 sisbios_mode[search_idx].xres,
1888 sisbios_mode[search_idx].yres, 1581 sisbios_mode[search_idx].yres,
1889 var->bits_per_pixel); 1582 var->bits_per_pixel);
1890 var->xres = sisbios_mode[search_idx].xres; 1583 var->xres = sisbios_mode[search_idx].xres;
1891 var->yres = sisbios_mode[search_idx].yres; 1584 var->yres = sisbios_mode[search_idx].yres;
1892
1893
1894 } else { 1585 } else {
1895 printk(KERN_ERR "sisfb: Failed to find supported mode near %dx%dx%d\n", 1586 printk(KERN_ERR
1587 "sisfb: Failed to find supported mode near %dx%dx%d\n",
1896 var->xres, var->yres, var->bits_per_pixel); 1588 var->xres, var->yres, var->bits_per_pixel);
1897 return -EINVAL; 1589 return -EINVAL;
1898 } 1590 }
1899 } 1591 }
1900 1592
1901 if( ((ivideo->vbflags & VB_LVDS) || /* Slave modes on LVDS and 301B-DH */ 1593 if( ((ivideo->vbflags2 & VB2_LVDS) ||
1902 ((ivideo->vbflags & VB_30xBDH) && (ivideo->currentvbflags & CRT2_LCD))) && 1594 ((ivideo->vbflags2 & VB2_30xBDH) && (ivideo->currentvbflags & CRT2_LCD))) &&
1903 (var->bits_per_pixel == 8) ) { 1595 (var->bits_per_pixel == 8) ) {
1904 refresh_rate = 60; 1596 /* Slave modes on LVDS and 301B-DH */
1597 refresh_rate = 60;
1905 recalc_clock = TRUE; 1598 recalc_clock = TRUE;
1906 } else if( (ivideo->current_htotal == htotal) && /* x=x & y=y & c=c -> assume depth change */ 1599 } else if( (ivideo->current_htotal == htotal) &&
1907 (ivideo->current_vtotal == vtotal) && 1600 (ivideo->current_vtotal == vtotal) &&
1908 (ivideo->current_pixclock == pixclock) ) { 1601 (ivideo->current_pixclock == pixclock) ) {
1602 /* x=x & y=y & c=c -> assume depth change */
1909 drate = 1000000000 / pixclock; 1603 drate = 1000000000 / pixclock;
1910 hrate = (drate * 1000) / htotal; 1604 hrate = (drate * 1000) / htotal;
1911 refresh_rate = (unsigned int) (hrate * 2 / vtotal); 1605 refresh_rate = (unsigned int) (hrate * 2 / vtotal);
1912 } else if( ( (ivideo->current_htotal != htotal) || /* x!=x | y!=y & c=c -> invalid pixclock */ 1606 } else if( ( (ivideo->current_htotal != htotal) ||
1913 (ivideo->current_vtotal != vtotal) ) && 1607 (ivideo->current_vtotal != vtotal) ) &&
1914 (ivideo->current_pixclock == var->pixclock) ) { 1608 (ivideo->current_pixclock == var->pixclock) ) {
1609 /* x!=x | y!=y & c=c -> invalid pixclock */
1915 if(ivideo->sisfb_lastrates[sisbios_mode[search_idx].mode_no[ivideo->mni]]) { 1610 if(ivideo->sisfb_lastrates[sisbios_mode[search_idx].mode_no[ivideo->mni]]) {
1916 refresh_rate = ivideo->sisfb_lastrates[sisbios_mode[search_idx].mode_no[ivideo->mni]]; 1611 refresh_rate =
1612 ivideo->sisfb_lastrates[sisbios_mode[search_idx].mode_no[ivideo->mni]];
1917 } else if(ivideo->sisfb_parm_rate != -1) { 1613 } else if(ivideo->sisfb_parm_rate != -1) {
1918 /* Sic, sisfb_parm_rate - want to know originally desired rate here */ 1614 /* Sic, sisfb_parm_rate - want to know originally desired rate here */
1919 refresh_rate = ivideo->sisfb_parm_rate; 1615 refresh_rate = ivideo->sisfb_parm_rate;
@@ -1923,8 +1619,8 @@ sisfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1923 recalc_clock = TRUE; 1619 recalc_clock = TRUE;
1924 } else if((pixclock) && (htotal) && (vtotal)) { 1620 } else if((pixclock) && (htotal) && (vtotal)) {
1925 drate = 1000000000 / pixclock; 1621 drate = 1000000000 / pixclock;
1926 hrate = (drate * 1000) / htotal; 1622 hrate = (drate * 1000) / htotal;
1927 refresh_rate = (unsigned int) (hrate * 2 / vtotal); 1623 refresh_rate = (unsigned int) (hrate * 2 / vtotal);
1928 } else if(ivideo->current_refresh_rate) { 1624 } else if(ivideo->current_refresh_rate) {
1929 refresh_rate = ivideo->current_refresh_rate; 1625 refresh_rate = ivideo->current_refresh_rate;
1930 recalc_clock = TRUE; 1626 recalc_clock = TRUE;
@@ -1937,72 +1633,72 @@ sisfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1937 1633
1938 /* Eventually recalculate timing and clock */ 1634 /* Eventually recalculate timing and clock */
1939 if(recalc_clock) { 1635 if(recalc_clock) {
1940 if(!myrateindex) myrateindex = sisbios_mode[search_idx].rate_idx; 1636 if(!myrateindex) myrateindex = sisbios_mode[search_idx].rate_idx;
1941 var->pixclock = (u32) (1000000000 / sisfb_mode_rate_to_dclock(&ivideo->SiS_Pr, 1637 var->pixclock = (u32) (1000000000 / sisfb_mode_rate_to_dclock(&ivideo->SiS_Pr,
1942 &ivideo->sishw_ext,
1943 sisbios_mode[search_idx].mode_no[ivideo->mni], 1638 sisbios_mode[search_idx].mode_no[ivideo->mni],
1944 myrateindex)); 1639 myrateindex));
1945 sisfb_mode_rate_to_ddata(&ivideo->SiS_Pr, &ivideo->sishw_ext, 1640 sisfb_mode_rate_to_ddata(&ivideo->SiS_Pr,
1946 sisbios_mode[search_idx].mode_no[ivideo->mni], myrateindex, var); 1641 sisbios_mode[search_idx].mode_no[ivideo->mni],
1947 if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) { 1642 myrateindex, var);
1948 var->pixclock <<= 1; 1643 if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {
1949 } 1644 var->pixclock <<= 1;
1645 }
1950 } 1646 }
1951 1647
1952 if(ivideo->sisfb_thismonitor.datavalid) { 1648 if(ivideo->sisfb_thismonitor.datavalid) {
1953 if(!sisfb_verify_rate(ivideo, &ivideo->sisfb_thismonitor, search_idx, 1649 if(!sisfb_verify_rate(ivideo, &ivideo->sisfb_thismonitor, search_idx,
1954 myrateindex, refresh_rate)) { 1650 myrateindex, refresh_rate)) {
1955 printk(KERN_INFO "sisfb: WARNING: Refresh rate exceeds monitor specs!\n"); 1651 printk(KERN_INFO
1956 } 1652 "sisfb: WARNING: Refresh rate exceeds monitor specs!\n");
1653 }
1957 } 1654 }
1958 1655
1959 /* Adapt RGB settings */ 1656 /* Adapt RGB settings */
1960 sisfb_bpp_to_var(ivideo, var); 1657 sisfb_bpp_to_var(ivideo, var);
1961 1658
1962 /* Sanity check for offsets */ 1659 /* Sanity check for offsets */
1963 if(var->xoffset < 0) var->xoffset = 0; 1660 if(var->xoffset < 0) var->xoffset = 0;
1964 if(var->yoffset < 0) var->yoffset = 0; 1661 if(var->yoffset < 0) var->yoffset = 0;
1965 1662
1966 if(var->xres > var->xres_virtual) { 1663 if(var->xres > var->xres_virtual)
1967 var->xres_virtual = var->xres; 1664 var->xres_virtual = var->xres;
1968 }
1969 1665
1970 if(ivideo->sisfb_ypan) { 1666 if(ivideo->sisfb_ypan) {
1971 maxyres = sisfb_calc_maxyres(ivideo, var); 1667 maxyres = sisfb_calc_maxyres(ivideo, var);
1972 if(ivideo->sisfb_max) { 1668 if(ivideo->sisfb_max) {
1973 var->yres_virtual = maxyres; 1669 var->yres_virtual = maxyres;
1974 } else { 1670 } else {
1975 if(var->yres_virtual > maxyres) { 1671 if(var->yres_virtual > maxyres) {
1976 var->yres_virtual = maxyres; 1672 var->yres_virtual = maxyres;
1977 } 1673 }
1978 } 1674 }
1979 if(var->yres_virtual <= var->yres) { 1675 if(var->yres_virtual <= var->yres) {
1980 var->yres_virtual = var->yres; 1676 var->yres_virtual = var->yres;
1981 } 1677 }
1982 } else { 1678 } else {
1983 if(var->yres != var->yres_virtual) { 1679 if(var->yres != var->yres_virtual) {
1984 var->yres_virtual = var->yres; 1680 var->yres_virtual = var->yres;
1985 } 1681 }
1986 var->xoffset = 0; 1682 var->xoffset = 0;
1987 var->yoffset = 0; 1683 var->yoffset = 0;
1988 } 1684 }
1989 1685
1990 /* Truncate offsets to maximum if too high */ 1686 /* Truncate offsets to maximum if too high */
1991 if(var->xoffset > var->xres_virtual - var->xres) { 1687 if(var->xoffset > var->xres_virtual - var->xres) {
1992 var->xoffset = var->xres_virtual - var->xres - 1; 1688 var->xoffset = var->xres_virtual - var->xres - 1;
1993 } 1689 }
1994 1690
1995 if(var->yoffset > var->yres_virtual - var->yres) { 1691 if(var->yoffset > var->yres_virtual - var->yres) {
1996 var->yoffset = var->yres_virtual - var->yres - 1; 1692 var->yoffset = var->yres_virtual - var->yres - 1;
1997 } 1693 }
1998 1694
1999 /* Set everything else to 0 */ 1695 /* Set everything else to 0 */
2000 var->red.msb_right = 1696 var->red.msb_right =
2001 var->green.msb_right = 1697 var->green.msb_right =
2002 var->blue.msb_right = 1698 var->blue.msb_right =
2003 var->transp.offset = 1699 var->transp.offset =
2004 var->transp.length = 1700 var->transp.length =
2005 var->transp.msb_right = 0; 1701 var->transp.msb_right = 0;
2006 1702
2007 return 0; 1703 return 0;
2008} 1704}
@@ -2013,21 +1709,21 @@ sisfb_pan_display(struct fb_var_screeninfo *var, struct fb_info* info)
2013 struct sis_video_info *ivideo = (struct sis_video_info *)info->par; 1709 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
2014 int err; 1710 int err;
2015 1711
2016 if(var->xoffset > (var->xres_virtual - var->xres)) { 1712 if(var->xoffset > (var->xres_virtual - var->xres))
2017 return -EINVAL; 1713 return -EINVAL;
2018 } 1714
2019 if(var->yoffset > (var->yres_virtual - var->yres)) { 1715 if(var->yoffset > (var->yres_virtual - var->yres))
2020 return -EINVAL; 1716 return -EINVAL;
2021 }
2022 1717
2023 if(var->vmode & FB_VMODE_YWRAP) return -EINVAL; 1718 if(var->vmode & FB_VMODE_YWRAP)
1719 return -EINVAL;
2024 1720
2025 if(var->xoffset + info->var.xres > info->var.xres_virtual || 1721 if(var->xoffset + info->var.xres > info->var.xres_virtual ||
2026 var->yoffset + info->var.yres > info->var.yres_virtual) { 1722 var->yoffset + info->var.yres > info->var.yres_virtual)
2027 return -EINVAL; 1723 return -EINVAL;
2028 }
2029 1724
2030 if((err = sisfb_pan_var(ivideo, var)) < 0) return err; 1725 if((err = sisfb_pan_var(ivideo, var)) < 0)
1726 return err;
2031 1727
2032 info->var.xoffset = var->xoffset; 1728 info->var.xoffset = var->xoffset;
2033 info->var.yoffset = var->yoffset; 1729 info->var.yoffset = var->yoffset;
@@ -2040,7 +1736,7 @@ sisfb_blank(int blank, struct fb_info *info)
2040{ 1736{
2041 struct sis_video_info *ivideo = (struct sis_video_info *)info->par; 1737 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
2042 1738
2043 return(sisfb_myblank(ivideo, blank)); 1739 return sisfb_myblank(ivideo, blank);
2044} 1740}
2045 1741
2046#endif 1742#endif
@@ -2056,153 +1752,184 @@ sisfb_ioctl(struct inode *inode, struct file *file,
2056 struct fb_info *info) 1752 struct fb_info *info)
2057{ 1753{
2058 struct sis_video_info *ivideo = (struct sis_video_info *)info->par; 1754 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
2059 struct sis_memreq sismemreq; 1755 struct sis_memreq sismemreq;
2060 struct fb_vblank sisvbblank; 1756 struct fb_vblank sisvbblank;
2061 sisfb_info x;
2062 u32 gpu32 = 0; 1757 u32 gpu32 = 0;
2063#ifndef __user 1758#ifndef __user
2064#define __user 1759#define __user
2065#endif 1760#endif
2066 u32 __user *argp = (u32 __user *)arg; 1761 u32 __user *argp = (u32 __user *)arg;
2067 1762
2068 switch (cmd) { 1763 switch(cmd) {
2069 case FBIO_ALLOC: 1764 case FBIO_ALLOC:
2070 if(!capable(CAP_SYS_RAWIO)) { 1765 if(!capable(CAP_SYS_RAWIO))
2071 return -EPERM; 1766 return -EPERM;
2072 } 1767
2073 if(copy_from_user(&sismemreq, (void __user *)arg, sizeof(sismemreq))) { 1768 if(copy_from_user(&sismemreq, (void __user *)arg, sizeof(sismemreq)))
2074 return -EFAULT; 1769 return -EFAULT;
2075 } 1770
2076 sis_malloc(&sismemreq); 1771 sis_malloc(&sismemreq);
1772
2077 if(copy_to_user((void __user *)arg, &sismemreq, sizeof(sismemreq))) { 1773 if(copy_to_user((void __user *)arg, &sismemreq, sizeof(sismemreq))) {
2078 sis_free((u32)sismemreq.offset); 1774 sis_free((u32)sismemreq.offset);
2079 return -EFAULT; 1775 return -EFAULT;
2080 } 1776 }
2081 break; 1777 break;
2082 1778
2083 case FBIO_FREE: 1779 case FBIO_FREE:
2084 if(!capable(CAP_SYS_RAWIO)) { 1780 if(!capable(CAP_SYS_RAWIO))
2085 return -EPERM; 1781 return -EPERM;
2086 } 1782
2087 if(get_user(gpu32, argp)) { 1783 if(get_user(gpu32, argp))
2088 return -EFAULT; 1784 return -EFAULT;
2089 } 1785
2090 sis_free(gpu32); 1786 sis_free(gpu32);
2091 break; 1787 break;
2092 1788
2093 case FBIOGET_VBLANK: 1789 case FBIOGET_VBLANK:
2094 sisvbblank.count = 0; 1790 sisvbblank.count = 0;
2095 sisvbblank.flags = sisfb_setupvbblankflags(ivideo, &sisvbblank.vcount, &sisvbblank.hcount); 1791 sisvbblank.flags = sisfb_setupvbblankflags(ivideo, &sisvbblank.vcount, &sisvbblank.hcount);
2096 if(copy_to_user((void __user *)arg, &sisvbblank, sizeof(sisvbblank))) { 1792
1793 if(copy_to_user((void __user *)arg, &sisvbblank, sizeof(sisvbblank)))
2097 return -EFAULT; 1794 return -EFAULT;
2098 } 1795
2099 break; 1796 break;
2100 1797
2101 case SISFB_GET_INFO_SIZE: 1798 case SISFB_GET_INFO_SIZE:
2102 return put_user(sizeof(sisfb_info), argp); 1799 return put_user(sizeof(struct sisfb_info), argp);
2103 1800
2104 case SISFB_GET_INFO_OLD: 1801 case SISFB_GET_INFO_OLD:
2105 if(ivideo->warncount++ < 50) { 1802 if(ivideo->warncount++ < 10)
2106 printk(KERN_INFO "sisfb: Deprecated ioctl call received - update your application!\n"); 1803 printk(KERN_INFO
2107 } 1804 "sisfb: Deprecated ioctl call received - update your application!\n");
2108 case SISFB_GET_INFO: /* For communication with X driver */ 1805 case SISFB_GET_INFO: /* For communication with X driver */
2109 x.sisfb_id = SISFB_ID; 1806 ivideo->sisfb_infoblock.sisfb_id = SISFB_ID;
2110 x.sisfb_version = VER_MAJOR; 1807 ivideo->sisfb_infoblock.sisfb_version = VER_MAJOR;
2111 x.sisfb_revision = VER_MINOR; 1808 ivideo->sisfb_infoblock.sisfb_revision = VER_MINOR;
2112 x.sisfb_patchlevel = VER_LEVEL; 1809 ivideo->sisfb_infoblock.sisfb_patchlevel = VER_LEVEL;
2113 x.chip_id = ivideo->chip_id; 1810 ivideo->sisfb_infoblock.chip_id = ivideo->chip_id;
2114 x.memory = ivideo->video_size / 1024; 1811 ivideo->sisfb_infoblock.sisfb_pci_vendor = ivideo->chip_vendor;
2115 x.heapstart = ivideo->heapstart / 1024; 1812 ivideo->sisfb_infoblock.memory = ivideo->video_size / 1024;
1813 ivideo->sisfb_infoblock.heapstart = ivideo->heapstart / 1024;
2116 if(ivideo->modechanged) { 1814 if(ivideo->modechanged) {
2117 x.fbvidmode = ivideo->mode_no; 1815 ivideo->sisfb_infoblock.fbvidmode = ivideo->mode_no;
2118 } else { 1816 } else {
2119 x.fbvidmode = ivideo->modeprechange; 1817 ivideo->sisfb_infoblock.fbvidmode = ivideo->modeprechange;
2120 }
2121 x.sisfb_caps = ivideo->caps;
2122 x.sisfb_tqlen = 512; /* yet fixed */
2123 x.sisfb_pcibus = ivideo->pcibus;
2124 x.sisfb_pcislot = ivideo->pcislot;
2125 x.sisfb_pcifunc = ivideo->pcifunc;
2126 x.sisfb_lcdpdc = ivideo->detectedpdc;
2127 x.sisfb_lcdpdca = ivideo->detectedpdca;
2128 x.sisfb_lcda = ivideo->detectedlcda;
2129 x.sisfb_vbflags = ivideo->vbflags;
2130 x.sisfb_currentvbflags = ivideo->currentvbflags;
2131 x.sisfb_scalelcd = ivideo->SiS_Pr.UsePanelScaler;
2132 x.sisfb_specialtiming = ivideo->SiS_Pr.SiS_CustomT;
2133 x.sisfb_haveemi = ivideo->SiS_Pr.HaveEMI ? 1 : 0;
2134 x.sisfb_haveemilcd = ivideo->SiS_Pr.HaveEMILCD ? 1 : 0;
2135 x.sisfb_emi30 = ivideo->SiS_Pr.EMI_30;
2136 x.sisfb_emi31 = ivideo->SiS_Pr.EMI_31;
2137 x.sisfb_emi32 = ivideo->SiS_Pr.EMI_32;
2138 x.sisfb_emi33 = ivideo->SiS_Pr.EMI_33;
2139 x.sisfb_tvxpos = (u16)(ivideo->tvxpos + 32);
2140 x.sisfb_tvypos = (u16)(ivideo->tvypos + 32);
2141
2142 if(copy_to_user((void __user *)arg, &x, sizeof(x))) {
2143 return -EFAULT;
2144 } 1818 }
1819 ivideo->sisfb_infoblock.sisfb_caps = ivideo->caps;
1820 ivideo->sisfb_infoblock.sisfb_tqlen = ivideo->cmdQueueSize / 1024;
1821 ivideo->sisfb_infoblock.sisfb_pcibus = ivideo->pcibus;
1822 ivideo->sisfb_infoblock.sisfb_pcislot = ivideo->pcislot;
1823 ivideo->sisfb_infoblock.sisfb_pcifunc = ivideo->pcifunc;
1824 ivideo->sisfb_infoblock.sisfb_lcdpdc = ivideo->detectedpdc;
1825 ivideo->sisfb_infoblock.sisfb_lcdpdca = ivideo->detectedpdca;
1826 ivideo->sisfb_infoblock.sisfb_lcda = ivideo->detectedlcda;
1827 ivideo->sisfb_infoblock.sisfb_vbflags = ivideo->vbflags;
1828 ivideo->sisfb_infoblock.sisfb_currentvbflags = ivideo->currentvbflags;
1829 ivideo->sisfb_infoblock.sisfb_scalelcd = ivideo->SiS_Pr.UsePanelScaler;
1830 ivideo->sisfb_infoblock.sisfb_specialtiming = ivideo->SiS_Pr.SiS_CustomT;
1831 ivideo->sisfb_infoblock.sisfb_haveemi = ivideo->SiS_Pr.HaveEMI ? 1 : 0;
1832 ivideo->sisfb_infoblock.sisfb_haveemilcd = ivideo->SiS_Pr.HaveEMILCD ? 1 : 0;
1833 ivideo->sisfb_infoblock.sisfb_emi30 = ivideo->SiS_Pr.EMI_30;
1834 ivideo->sisfb_infoblock.sisfb_emi31 = ivideo->SiS_Pr.EMI_31;
1835 ivideo->sisfb_infoblock.sisfb_emi32 = ivideo->SiS_Pr.EMI_32;
1836 ivideo->sisfb_infoblock.sisfb_emi33 = ivideo->SiS_Pr.EMI_33;
1837 ivideo->sisfb_infoblock.sisfb_tvxpos = (u16)(ivideo->tvxpos + 32);
1838 ivideo->sisfb_infoblock.sisfb_tvypos = (u16)(ivideo->tvypos + 32);
1839 ivideo->sisfb_infoblock.sisfb_heapsize = ivideo->sisfb_heap_size / 1024;
1840 ivideo->sisfb_infoblock.sisfb_videooffset = ivideo->video_offset;
1841 ivideo->sisfb_infoblock.sisfb_curfstn = ivideo->curFSTN;
1842 ivideo->sisfb_infoblock.sisfb_curdstn = ivideo->curDSTN;
1843 ivideo->sisfb_infoblock.sisfb_vbflags2 = ivideo->vbflags2;
1844 ivideo->sisfb_infoblock.sisfb_can_post = ivideo->sisfb_can_post ? 1 : 0;
1845 ivideo->sisfb_infoblock.sisfb_card_posted = ivideo->sisfb_card_posted ? 1 : 0;
1846 ivideo->sisfb_infoblock.sisfb_was_boot_device = ivideo->sisfb_was_boot_device ? 1 : 0;
1847
1848 if(copy_to_user((void __user *)arg, &ivideo->sisfb_infoblock,
1849 sizeof(ivideo->sisfb_infoblock)))
1850 return -EFAULT;
1851
2145 break; 1852 break;
2146 1853
2147 case SISFB_GET_VBRSTATUS_OLD: 1854 case SISFB_GET_VBRSTATUS_OLD:
2148 if(ivideo->warncount++ < 50) { 1855 if(ivideo->warncount++ < 10)
2149 printk(KERN_INFO "sisfb: Deprecated ioctl call received - update your application!\n"); 1856 printk(KERN_INFO
2150 } 1857 "sisfb: Deprecated ioctl call received - update your application!\n");
2151 case SISFB_GET_VBRSTATUS: 1858 case SISFB_GET_VBRSTATUS:
2152 if(sisfb_CheckVBRetrace(ivideo)) { 1859 if(sisfb_CheckVBRetrace(ivideo))
2153 return put_user((u32)1, argp); 1860 return put_user((u32)1, argp);
2154 } else { 1861 else
2155 return put_user((u32)0, argp); 1862 return put_user((u32)0, argp);
2156 }
2157 1863
2158 case SISFB_GET_AUTOMAXIMIZE_OLD: 1864 case SISFB_GET_AUTOMAXIMIZE_OLD:
2159 if(ivideo->warncount++ < 50) { 1865 if(ivideo->warncount++ < 10)
2160 printk(KERN_INFO "sisfb: Deprecated ioctl call received - update your application!\n"); 1866 printk(KERN_INFO
2161 } 1867 "sisfb: Deprecated ioctl call received - update your application!\n");
2162 case SISFB_GET_AUTOMAXIMIZE: 1868 case SISFB_GET_AUTOMAXIMIZE:
2163 if(ivideo->sisfb_max) return put_user((u32)1, argp); 1869 if(ivideo->sisfb_max)
2164 else return put_user((u32)0, argp); 1870 return put_user((u32)1, argp);
1871 else
1872 return put_user((u32)0, argp);
2165 1873
2166 case SISFB_SET_AUTOMAXIMIZE_OLD: 1874 case SISFB_SET_AUTOMAXIMIZE_OLD:
2167 if(ivideo->warncount++ < 50) { 1875 if(ivideo->warncount++ < 10)
2168 printk(KERN_INFO "sisfb: Deprecated ioctl call received - update your application!\n"); 1876 printk(KERN_INFO
2169 } 1877 "sisfb: Deprecated ioctl call received - update your application!\n");
2170 case SISFB_SET_AUTOMAXIMIZE: 1878 case SISFB_SET_AUTOMAXIMIZE:
2171 if(copy_from_user(&gpu32, argp, sizeof(gpu32))) { 1879 if(get_user(gpu32, argp))
2172 return -EFAULT; 1880 return -EFAULT;
2173 } 1881
2174 ivideo->sisfb_max = (gpu32) ? 1 : 0; 1882 ivideo->sisfb_max = (gpu32) ? 1 : 0;
2175 break; 1883 break;
2176 1884
2177 case SISFB_SET_TVPOSOFFSET: 1885 case SISFB_SET_TVPOSOFFSET:
2178 if(copy_from_user(&gpu32, argp, sizeof(gpu32))) { 1886 if(get_user(gpu32, argp))
2179 return -EFAULT; 1887 return -EFAULT;
2180 } 1888
2181 sisfb_set_TVxposoffset(ivideo, ((int)(gpu32 >> 16)) - 32); 1889 sisfb_set_TVxposoffset(ivideo, ((int)(gpu32 >> 16)) - 32);
2182 sisfb_set_TVyposoffset(ivideo, ((int)(gpu32 & 0xffff)) - 32); 1890 sisfb_set_TVyposoffset(ivideo, ((int)(gpu32 & 0xffff)) - 32);
2183 break; 1891 break;
2184 1892
2185 case SISFB_GET_TVPOSOFFSET: 1893 case SISFB_GET_TVPOSOFFSET:
2186 return put_user((u32)(((ivideo->tvxpos+32)<<16)|((ivideo->tvypos+32)&0xffff)), 1894 return put_user((u32)(((ivideo->tvxpos+32)<<16)|((ivideo->tvypos+32)&0xffff)),
2187 argp); 1895 argp);
1896
1897 case SISFB_COMMAND:
1898 if(copy_from_user(&ivideo->sisfb_command, (void __user *)arg,
1899 sizeof(struct sisfb_cmd)))
1900 return -EFAULT;
1901
1902 sisfb_handle_command(ivideo, &ivideo->sisfb_command);
1903
1904 if(copy_to_user((void __user *)arg, &ivideo->sisfb_command,
1905 sizeof(struct sisfb_cmd)))
1906 return -EFAULT;
1907
1908 break;
2188 1909
2189 case SISFB_SET_LOCK: 1910 case SISFB_SET_LOCK:
2190 if(copy_from_user(&gpu32, argp, sizeof(gpu32))) { 1911 if(get_user(gpu32, argp))
2191 return -EFAULT; 1912 return -EFAULT;
2192 } 1913
2193 ivideo->sisfblocked = (gpu32) ? 1 : 0; 1914 ivideo->sisfblocked = (gpu32) ? 1 : 0;
2194 break; 1915 break;
2195 1916
2196 default: 1917 default:
1918#ifdef SIS_NEW_CONFIG_COMPAT
2197 return -ENOIOCTLCMD; 1919 return -ENOIOCTLCMD;
1920#else
1921 return -EINVAL;
1922#endif
2198 } 1923 }
2199 return 0; 1924 return 0;
2200} 1925}
2201 1926
2202#ifdef CONFIG_COMPAT 1927#ifdef SIS_NEW_CONFIG_COMPAT
2203static long sisfb_compat_ioctl(struct file *f, unsigned cmd, unsigned long arg, struct fb_info *info) 1928static long
1929sisfb_compat_ioctl(struct file *f, unsigned int cmd, unsigned long arg, struct fb_info *info)
2204{ 1930{
2205 int ret; 1931 int ret;
1932
2206 lock_kernel(); 1933 lock_kernel();
2207 ret = sisfb_ioctl(NULL, f, cmd, arg, info); 1934 ret = sisfb_ioctl(NULL, f, cmd, arg, info);
2208 unlock_kernel(); 1935 unlock_kernel();
@@ -2219,7 +1946,7 @@ sisfb_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info)
2219 1946
2220 strcpy(fix->id, ivideo->myid); 1947 strcpy(fix->id, ivideo->myid);
2221 1948
2222 fix->smem_start = ivideo->video_base; 1949 fix->smem_start = ivideo->video_base + ivideo->video_offset;
2223 fix->smem_len = ivideo->sisfb_mem; 1950 fix->smem_len = ivideo->sisfb_mem;
2224 fix->type = FB_TYPE_PACKED_PIXELS; 1951 fix->type = FB_TYPE_PACKED_PIXELS;
2225 fix->type_aux = 0; 1952 fix->type_aux = 0;
@@ -2231,11 +1958,17 @@ sisfb_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info)
2231 fix->mmio_start = ivideo->mmio_base; 1958 fix->mmio_start = ivideo->mmio_base;
2232 fix->mmio_len = ivideo->mmio_size; 1959 fix->mmio_len = ivideo->mmio_size;
2233 if(ivideo->sisvga_engine == SIS_300_VGA) { 1960 if(ivideo->sisvga_engine == SIS_300_VGA) {
2234 fix->accel = FB_ACCEL_SIS_GLAMOUR; 1961 fix->accel = FB_ACCEL_SIS_GLAMOUR;
2235 } else if((ivideo->chip == SIS_330) || (ivideo->chip == SIS_760)) { 1962 } else if((ivideo->chip == SIS_330) ||
2236 fix->accel = FB_ACCEL_SIS_XABRE; 1963 (ivideo->chip == SIS_760) ||
1964 (ivideo->chip == SIS_761)) {
1965 fix->accel = FB_ACCEL_SIS_XABRE;
1966 } else if(ivideo->chip == XGI_20) {
1967 fix->accel = FB_ACCEL_XGI_VOLARI_Z;
1968 } else if(ivideo->chip >= XGI_40) {
1969 fix->accel = FB_ACCEL_XGI_VOLARI_V;
2237 } else { 1970 } else {
2238 fix->accel = FB_ACCEL_SIS_GLAMOUR_2; 1971 fix->accel = FB_ACCEL_SIS_GLAMOUR_2;
2239 } 1972 }
2240 1973
2241 return 0; 1974 return 0;
@@ -2251,40 +1984,41 @@ static struct fb_ops sisfb_ops = {
2251 .fb_set_var = sisfb_set_var, 1984 .fb_set_var = sisfb_set_var,
2252 .fb_get_cmap = sisfb_get_cmap, 1985 .fb_get_cmap = sisfb_get_cmap,
2253 .fb_set_cmap = sisfb_set_cmap, 1986 .fb_set_cmap = sisfb_set_cmap,
2254 .fb_pan_display = sisfb_pan_display, 1987 .fb_pan_display = sisfb_pan_display,
2255 .fb_ioctl = sisfb_ioctl 1988 .fb_ioctl = sisfb_ioctl
2256}; 1989};
2257#endif 1990#endif
2258 1991
2259#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 1992#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
2260static struct fb_ops sisfb_ops = { 1993static struct fb_ops sisfb_ops = {
2261 .owner = THIS_MODULE, 1994 .owner = THIS_MODULE,
2262 .fb_open = sisfb_open, 1995 .fb_open = sisfb_open,
2263 .fb_release = sisfb_release, 1996 .fb_release = sisfb_release,
2264 .fb_check_var = sisfb_check_var, 1997 .fb_check_var = sisfb_check_var,
2265 .fb_set_par = sisfb_set_par, 1998 .fb_set_par = sisfb_set_par,
2266 .fb_setcolreg = sisfb_setcolreg, 1999 .fb_setcolreg = sisfb_setcolreg,
2267 .fb_pan_display = sisfb_pan_display, 2000 .fb_pan_display = sisfb_pan_display,
2268 .fb_blank = sisfb_blank, 2001 .fb_blank = sisfb_blank,
2269 .fb_fillrect = fbcon_sis_fillrect, 2002 .fb_fillrect = fbcon_sis_fillrect,
2270 .fb_copyarea = fbcon_sis_copyarea, 2003 .fb_copyarea = fbcon_sis_copyarea,
2271 .fb_imageblit = cfb_imageblit, 2004 .fb_imageblit = cfb_imageblit,
2272 .fb_cursor = soft_cursor, 2005 .fb_cursor = soft_cursor,
2273 .fb_sync = fbcon_sis_sync, 2006 .fb_sync = fbcon_sis_sync,
2274 .fb_ioctl = sisfb_ioctl, 2007#ifdef SIS_NEW_CONFIG_COMPAT
2275#ifdef CONFIG_COMPAT 2008 .fb_compat_ioctl= sisfb_compat_ioctl,
2276 .fb_compat_ioctl = sisfb_compat_ioctl,
2277#endif 2009#endif
2010 .fb_ioctl = sisfb_ioctl
2278}; 2011};
2279#endif 2012#endif
2280 2013
2281/* ---------------- Chip generation dependent routines ---------------- */ 2014/* ---------------- Chip generation dependent routines ---------------- */
2282 2015
2283static struct pci_dev * sisfb_get_northbridge(int basechipid) 2016static struct pci_dev * __devinit
2017sisfb_get_northbridge(int basechipid)
2284{ 2018{
2285 struct pci_dev *pdev = NULL; 2019 struct pci_dev *pdev = NULL;
2286 int nbridgenum, nbridgeidx, i; 2020 int nbridgenum, nbridgeidx, i;
2287 const unsigned short nbridgeids[] = { 2021 static const unsigned short nbridgeids[] = {
2288 PCI_DEVICE_ID_SI_540, /* for SiS 540 VGA */ 2022 PCI_DEVICE_ID_SI_540, /* for SiS 540 VGA */
2289 PCI_DEVICE_ID_SI_630, /* for SiS 630/730 VGA */ 2023 PCI_DEVICE_ID_SI_630, /* for SiS 630/730 VGA */
2290 PCI_DEVICE_ID_SI_730, 2024 PCI_DEVICE_ID_SI_730,
@@ -2292,13 +2026,14 @@ static struct pci_dev * sisfb_get_northbridge(int basechipid)
2292 PCI_DEVICE_ID_SI_650, /* for SiS 650/651/740 VGA */ 2026 PCI_DEVICE_ID_SI_650, /* for SiS 650/651/740 VGA */
2293 PCI_DEVICE_ID_SI_651, 2027 PCI_DEVICE_ID_SI_651,
2294 PCI_DEVICE_ID_SI_740, 2028 PCI_DEVICE_ID_SI_740,
2295 PCI_DEVICE_ID_SI_661, /* for SiS 661/741/660/760 VGA */ 2029 PCI_DEVICE_ID_SI_661, /* for SiS 661/741/660/760/761 VGA */
2296 PCI_DEVICE_ID_SI_741, 2030 PCI_DEVICE_ID_SI_741,
2297 PCI_DEVICE_ID_SI_660, 2031 PCI_DEVICE_ID_SI_660,
2298 PCI_DEVICE_ID_SI_760 2032 PCI_DEVICE_ID_SI_760,
2033 PCI_DEVICE_ID_SI_761
2299 }; 2034 };
2300 2035
2301 switch(basechipid) { 2036 switch(basechipid) {
2302#ifdef CONFIG_FB_SIS_300 2037#ifdef CONFIG_FB_SIS_300
2303 case SIS_540: nbridgeidx = 0; nbridgenum = 1; break; 2038 case SIS_540: nbridgeidx = 0; nbridgenum = 1; break;
2304 case SIS_630: nbridgeidx = 1; nbridgenum = 2; break; 2039 case SIS_630: nbridgeidx = 1; nbridgenum = 2; break;
@@ -2306,35 +2041,40 @@ static struct pci_dev * sisfb_get_northbridge(int basechipid)
2306#ifdef CONFIG_FB_SIS_315 2041#ifdef CONFIG_FB_SIS_315
2307 case SIS_550: nbridgeidx = 3; nbridgenum = 1; break; 2042 case SIS_550: nbridgeidx = 3; nbridgenum = 1; break;
2308 case SIS_650: nbridgeidx = 4; nbridgenum = 3; break; 2043 case SIS_650: nbridgeidx = 4; nbridgenum = 3; break;
2309 case SIS_660: nbridgeidx = 7; nbridgenum = 4; break; 2044 case SIS_660: nbridgeidx = 7; nbridgenum = 5; break;
2310#endif 2045#endif
2311 default: return NULL; 2046 default: return NULL;
2312 } 2047 }
2313 for(i = 0; i < nbridgenum; i++) { 2048 for(i = 0; i < nbridgenum; i++) {
2314 if((pdev = pci_find_device(PCI_VENDOR_ID_SI, nbridgeids[nbridgeidx+i], NULL))) break; 2049 if((pdev = SIS_PCI_GET_DEVICE(PCI_VENDOR_ID_SI,
2050 nbridgeids[nbridgeidx+i], NULL)))
2051 break;
2315 } 2052 }
2316 return pdev; 2053 return pdev;
2317} 2054}
2318 2055
2319static int __devinit sisfb_get_dram_size(struct sis_video_info *ivideo) 2056static int __devinit
2057sisfb_get_dram_size(struct sis_video_info *ivideo)
2320{ 2058{
2321#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315) 2059#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
2322 u8 reg; 2060 u8 reg;
2323#endif 2061#endif
2324 2062
2325 ivideo->video_size = 0; 2063 ivideo->video_size = 0;
2064 ivideo->UMAsize = ivideo->LFBsize = 0;
2326 2065
2327 switch(ivideo->chip) { 2066 switch(ivideo->chip) {
2328#ifdef CONFIG_FB_SIS_300 2067#ifdef CONFIG_FB_SIS_300
2329 case SIS_300: 2068 case SIS_300:
2330 inSISIDXREG(SISSR, 0x14, reg); 2069 inSISIDXREG(SISSR, 0x14, reg);
2331 ivideo->video_size = ((reg & 0x3F) + 1) << 20; 2070 ivideo->video_size = ((reg & 0x3F) + 1) << 20;
2332 break; 2071 break;
2333 case SIS_540: 2072 case SIS_540:
2334 case SIS_630: 2073 case SIS_630:
2335 case SIS_730: 2074 case SIS_730:
2336 if(!ivideo->nbridge) return -1; 2075 if(!ivideo->nbridge)
2337 pci_read_config_byte(ivideo->nbridge, 0x63, &reg); 2076 return -1;
2077 pci_read_config_byte(ivideo->nbridge, 0x63, &reg);
2338 ivideo->video_size = 1 << (((reg & 0x70) >> 4) + 21); 2078 ivideo->video_size = 1 << (((reg & 0x70) >> 4) + 21);
2339 break; 2079 break;
2340#endif 2080#endif
@@ -2342,45 +2082,68 @@ static int __devinit sisfb_get_dram_size(struct sis_video_info *ivideo)
2342 case SIS_315H: 2082 case SIS_315H:
2343 case SIS_315PRO: 2083 case SIS_315PRO:
2344 case SIS_315: 2084 case SIS_315:
2345 inSISIDXREG(SISSR, 0x14, reg); 2085 inSISIDXREG(SISSR, 0x14, reg);
2346 ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20; 2086 ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20;
2347 switch((reg >> 2) & 0x03) { 2087 switch((reg >> 2) & 0x03) {
2348 case 0x01: 2088 case 0x01:
2349 case 0x03: 2089 case 0x03:
2350 ivideo->video_size <<= 1; 2090 ivideo->video_size <<= 1;
2351 break; 2091 break;
2352 case 0x02: 2092 case 0x02:
2353 ivideo->video_size += (ivideo->video_size/2); 2093 ivideo->video_size += (ivideo->video_size/2);
2354 } 2094 }
2355 break; 2095 break;
2356 case SIS_330: 2096 case SIS_330:
2357 inSISIDXREG(SISSR, 0x14, reg); 2097 inSISIDXREG(SISSR, 0x14, reg);
2358 ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20; 2098 ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20;
2359 if(reg & 0x0c) ivideo->video_size <<= 1; 2099 if(reg & 0x0c) ivideo->video_size <<= 1;
2360 break; 2100 break;
2361 case SIS_550: 2101 case SIS_550:
2362 case SIS_650: 2102 case SIS_650:
2363 case SIS_740: 2103 case SIS_740:
2364 inSISIDXREG(SISSR, 0x14, reg); 2104 inSISIDXREG(SISSR, 0x14, reg);
2365 ivideo->video_size = (((reg & 0x3f) + 1) << 2) << 20; 2105 ivideo->video_size = (((reg & 0x3f) + 1) << 2) << 20;
2366 break; 2106 break;
2367 case SIS_661: 2107 case SIS_661:
2368 case SIS_741: 2108 case SIS_741:
2369 inSISIDXREG(SISCR, 0x79, reg); 2109 inSISIDXREG(SISCR, 0x79, reg);
2370 ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20; 2110 ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20;
2371 break; 2111 break;
2372 case SIS_660: 2112 case SIS_660:
2373 case SIS_760: 2113 case SIS_760:
2114 case SIS_761:
2374 inSISIDXREG(SISCR, 0x79, reg); 2115 inSISIDXREG(SISCR, 0x79, reg);
2375 reg = (reg & 0xf0) >> 4; 2116 reg = (reg & 0xf0) >> 4;
2376 if(reg) ivideo->video_size = (1 << reg) << 20; 2117 if(reg) {
2118 ivideo->video_size = (1 << reg) << 20;
2119 ivideo->UMAsize = ivideo->video_size;
2120 }
2377 inSISIDXREG(SISCR, 0x78, reg); 2121 inSISIDXREG(SISCR, 0x78, reg);
2378 reg &= 0x30; 2122 reg &= 0x30;
2379 if(reg) { 2123 if(reg) {
2380 if(reg == 0x10) ivideo->video_size += (32 << 20); 2124 if(reg == 0x10) {
2381 else ivideo->video_size += (64 << 20); 2125 ivideo->LFBsize = (32 << 20);
2126 } else {
2127 ivideo->LFBsize = (64 << 20);
2128 }
2129 ivideo->video_size += ivideo->LFBsize;
2382 } 2130 }
2383 break; 2131 break;
2132 case SIS_340:
2133 case XGI_20:
2134 case XGI_40:
2135 inSISIDXREG(SISSR, 0x14, reg);
2136 ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20;
2137 if(ivideo->chip != XGI_20) {
2138 reg = (reg & 0x0c) >> 2;
2139 if(ivideo->revision_id == 2) {
2140 if(reg & 0x01) reg = 0x02;
2141 else reg = 0x00;
2142 }
2143 if(reg == 0x02) ivideo->video_size <<= 1;
2144 else if(reg == 0x03) ivideo->video_size <<= 2;
2145 }
2146 break;
2384#endif 2147#endif
2385 default: 2148 default:
2386 return -1; 2149 return -1;
@@ -2390,17 +2153,24 @@ static int __devinit sisfb_get_dram_size(struct sis_video_info *ivideo)
2390 2153
2391/* -------------- video bridge device detection --------------- */ 2154/* -------------- video bridge device detection --------------- */
2392 2155
2393static void __devinit sisfb_detect_VB_connect(struct sis_video_info *ivideo) 2156static void __devinit
2157sisfb_detect_VB_connect(struct sis_video_info *ivideo)
2394{ 2158{
2395 u8 cr32, temp; 2159 u8 cr32, temp;
2396 2160
2161 /* No CRT2 on XGI Z7 */
2162 if(ivideo->chip == XGI_20) {
2163 ivideo->sisfb_crt1off = 0;
2164 return;
2165 }
2166
2397#ifdef CONFIG_FB_SIS_300 2167#ifdef CONFIG_FB_SIS_300
2398 if(ivideo->sisvga_engine == SIS_300_VGA) { 2168 if(ivideo->sisvga_engine == SIS_300_VGA) {
2399 inSISIDXREG(SISSR, 0x17, temp); 2169 inSISIDXREG(SISSR, 0x17, temp);
2400 if((temp & 0x0F) && (ivideo->chip != SIS_300)) { 2170 if((temp & 0x0F) && (ivideo->chip != SIS_300)) {
2401 /* PAL/NTSC is stored on SR16 on such machines */ 2171 /* PAL/NTSC is stored on SR16 on such machines */
2402 if(!(ivideo->vbflags & (TV_PAL | TV_NTSC | TV_PALM | TV_PALN))) { 2172 if(!(ivideo->vbflags & (TV_PAL | TV_NTSC | TV_PALM | TV_PALN))) {
2403 inSISIDXREG(SISSR, 0x16, temp); 2173 inSISIDXREG(SISSR, 0x16, temp);
2404 if(temp & 0x20) 2174 if(temp & 0x20)
2405 ivideo->vbflags |= TV_PAL; 2175 ivideo->vbflags |= TV_PAL;
2406 else 2176 else
@@ -2435,28 +2205,29 @@ static void __devinit sisfb_detect_VB_connect(struct sis_video_info *ivideo)
2435 2205
2436 if(ivideo->sisfb_tvplug != -1) { 2206 if(ivideo->sisfb_tvplug != -1) {
2437 if( (ivideo->sisvga_engine != SIS_315_VGA) || 2207 if( (ivideo->sisvga_engine != SIS_315_VGA) ||
2438 (!(ivideo->vbflags & (VB_301C|VB_301LV|VB_302LV))) ) { 2208 (!(ivideo->vbflags2 & VB2_SISYPBPRBRIDGE)) ) {
2439 if(ivideo->sisfb_tvplug & TV_YPBPR) { 2209 if(ivideo->sisfb_tvplug & TV_YPBPR) {
2440 ivideo->sisfb_tvplug = -1; 2210 ivideo->sisfb_tvplug = -1;
2441 printk(KERN_ERR "sisfb: YPbPr not supported\n"); 2211 printk(KERN_ERR "sisfb: YPbPr not supported\n");
2442 } 2212 }
2443 } 2213 }
2444 } 2214 }
2445 if(ivideo->sisfb_tvplug != -1) { 2215 if(ivideo->sisfb_tvplug != -1) {
2446 if( (ivideo->sisvga_engine != SIS_315_VGA) || 2216 if( (ivideo->sisvga_engine != SIS_315_VGA) ||
2447 (!(ivideo->vbflags & (VB_301|VB_301B|VB_302B))) ) { 2217 (!(ivideo->vbflags2 & VB2_SISHIVISIONBRIDGE)) ) {
2448 if(ivideo->sisfb_tvplug & TV_HIVISION) { 2218 if(ivideo->sisfb_tvplug & TV_HIVISION) {
2449 ivideo->sisfb_tvplug = -1; 2219 ivideo->sisfb_tvplug = -1;
2450 printk(KERN_ERR "sisfb: HiVision not supported\n"); 2220 printk(KERN_ERR "sisfb: HiVision not supported\n");
2451 } 2221 }
2452 } 2222 }
2453 } 2223 }
2454 if(ivideo->sisfb_tvstd != -1) { 2224 if(ivideo->sisfb_tvstd != -1) {
2455 if( (!(ivideo->vbflags & VB_SISBRIDGE)) && 2225 if( (!(ivideo->vbflags2 & VB2_SISBRIDGE)) &&
2456 (!((ivideo->sisvga_engine == SIS_315_VGA) && (ivideo->vbflags & VB_CHRONTEL))) ) { 2226 (!((ivideo->sisvga_engine == SIS_315_VGA) &&
2227 (ivideo->vbflags2 & VB2_CHRONTEL))) ) {
2457 if(ivideo->sisfb_tvstd & (TV_PALN | TV_PALN | TV_NTSCJ)) { 2228 if(ivideo->sisfb_tvstd & (TV_PALN | TV_PALN | TV_NTSCJ)) {
2458 ivideo->sisfb_tvstd = -1; 2229 ivideo->sisfb_tvstd = -1;
2459 printk(KERN_ERR "sisfb: PALM/PALN/NTSCJ not supported\n"); 2230 printk(KERN_ERR "sisfb: PALM/PALN/NTSCJ not supported\n");
2460 } 2231 }
2461 } 2232 }
2462 } 2233 }
@@ -2468,7 +2239,7 @@ static void __devinit sisfb_detect_VB_connect(struct sis_video_info *ivideo)
2468 if(cr32 & SIS_VB_YPBPR) ivideo->vbflags |= (TV_YPBPR|TV_YPBPR525I); /* default: 480i */ 2239 if(cr32 & SIS_VB_YPBPR) ivideo->vbflags |= (TV_YPBPR|TV_YPBPR525I); /* default: 480i */
2469 else if(cr32 & SIS_VB_HIVISION) ivideo->vbflags |= TV_HIVISION; 2240 else if(cr32 & SIS_VB_HIVISION) ivideo->vbflags |= TV_HIVISION;
2470 else if(cr32 & SIS_VB_SCART) ivideo->vbflags |= TV_SCART; 2241 else if(cr32 & SIS_VB_SCART) ivideo->vbflags |= TV_SCART;
2471 else { 2242 else {
2472 if(cr32 & SIS_VB_SVIDEO) ivideo->vbflags |= TV_SVIDEO; 2243 if(cr32 & SIS_VB_SVIDEO) ivideo->vbflags |= TV_SVIDEO;
2473 if(cr32 & SIS_VB_COMPOSITE) ivideo->vbflags |= TV_AVIDEO; 2244 if(cr32 & SIS_VB_COMPOSITE) ivideo->vbflags |= TV_AVIDEO;
2474 } 2245 }
@@ -2485,165 +2256,44 @@ static void __devinit sisfb_detect_VB_connect(struct sis_video_info *ivideo)
2485 } 2256 }
2486 if(!(ivideo->vbflags & (TV_PAL | TV_NTSC | TV_PALM | TV_PALN | TV_NTSCJ))) { 2257 if(!(ivideo->vbflags & (TV_PAL | TV_NTSC | TV_PALM | TV_PALN | TV_NTSCJ))) {
2487 if(ivideo->sisvga_engine == SIS_300_VGA) { 2258 if(ivideo->sisvga_engine == SIS_300_VGA) {
2488 inSISIDXREG(SISSR, 0x38, temp); 2259 inSISIDXREG(SISSR, 0x38, temp);
2489 if(temp & 0x01) ivideo->vbflags |= TV_PAL; 2260 if(temp & 0x01) ivideo->vbflags |= TV_PAL;
2490 else ivideo->vbflags |= TV_NTSC; 2261 else ivideo->vbflags |= TV_NTSC;
2491 } else if((ivideo->chip <= SIS_315PRO) || (ivideo->chip >= SIS_330)) { 2262 } else if((ivideo->chip <= SIS_315PRO) || (ivideo->chip >= SIS_330)) {
2492 inSISIDXREG(SISSR, 0x38, temp); 2263 inSISIDXREG(SISSR, 0x38, temp);
2493 if(temp & 0x01) ivideo->vbflags |= TV_PAL; 2264 if(temp & 0x01) ivideo->vbflags |= TV_PAL;
2494 else ivideo->vbflags |= TV_NTSC; 2265 else ivideo->vbflags |= TV_NTSC;
2495 } else { 2266 } else {
2496 inSISIDXREG(SISCR, 0x79, temp); 2267 inSISIDXREG(SISCR, 0x79, temp);
2497 if(temp & 0x20) ivideo->vbflags |= TV_PAL; 2268 if(temp & 0x20) ivideo->vbflags |= TV_PAL;
2498 else ivideo->vbflags |= TV_NTSC; 2269 else ivideo->vbflags |= TV_NTSC;
2499 } 2270 }
2500 } 2271 }
2501 } 2272 }
2502 2273
2503 /* Copy forceCRT1 option to CRT1off if option is given */ 2274 /* Copy forceCRT1 option to CRT1off if option is given */
2504 if(ivideo->sisfb_forcecrt1 != -1) { 2275 if(ivideo->sisfb_forcecrt1 != -1) {
2505 ivideo->sisfb_crt1off = (ivideo->sisfb_forcecrt1) ? 0 : 1; 2276 ivideo->sisfb_crt1off = (ivideo->sisfb_forcecrt1) ? 0 : 1;
2506 }
2507}
2508
2509static void __devinit sisfb_get_VB_type(struct sis_video_info *ivideo)
2510{
2511 char stdstr[] = "sisfb: Detected";
2512 char bridgestr[] = "video bridge";
2513 u8 vb_chipid;
2514 u8 reg;
2515
2516 inSISIDXREG(SISPART4, 0x00, vb_chipid);
2517 switch(vb_chipid) {
2518 case 0x01:
2519 inSISIDXREG(SISPART4, 0x01, reg);
2520 if(reg < 0xb0) {
2521 ivideo->vbflags |= VB_301;
2522 printk(KERN_INFO "%s SiS301 %s\n", stdstr, bridgestr);
2523 } else if(reg < 0xc0) {
2524 ivideo->vbflags |= VB_301B;
2525 inSISIDXREG(SISPART4,0x23,reg);
2526 if(!(reg & 0x02)) {
2527 ivideo->vbflags |= VB_30xBDH;
2528 printk(KERN_INFO "%s SiS301B-DH %s\n", stdstr, bridgestr);
2529 } else {
2530 printk(KERN_INFO "%s SiS301B %s\n", stdstr, bridgestr);
2531 }
2532 } else if(reg < 0xd0) {
2533 ivideo->vbflags |= VB_301C;
2534 printk(KERN_INFO "%s SiS301C %s\n", stdstr, bridgestr);
2535 } else if(reg < 0xe0) {
2536 ivideo->vbflags |= VB_301LV;
2537 printk(KERN_INFO "%s SiS301LV %s\n", stdstr, bridgestr);
2538 } else if(reg <= 0xe1) {
2539 inSISIDXREG(SISPART4,0x39,reg);
2540 if(reg == 0xff) {
2541 ivideo->vbflags |= VB_302LV;
2542 printk(KERN_INFO "%s SiS302LV %s\n", stdstr, bridgestr);
2543 } else {
2544 ivideo->vbflags |= VB_301C;
2545 printk(KERN_INFO "%s SiS301C(P4) %s\n", stdstr, bridgestr);
2546#if 0
2547 ivideo->vbflags |= VB_302ELV;
2548 printk(KERN_INFO "%s SiS302ELV %s\n", stdstr, bridgestr);
2549#endif
2550 }
2551 }
2552 break;
2553 case 0x02:
2554 ivideo->vbflags |= VB_302B;
2555 printk(KERN_INFO "%s SiS302B %s\n", stdstr, bridgestr);
2556 break;
2557 }
2558
2559 if((!(ivideo->vbflags & VB_VIDEOBRIDGE)) && (ivideo->chip != SIS_300)) {
2560 inSISIDXREG(SISCR, 0x37, reg);
2561 reg &= SIS_EXTERNAL_CHIP_MASK;
2562 reg >>= 1;
2563 if(ivideo->sisvga_engine == SIS_300_VGA) {
2564#ifdef CONFIG_FB_SIS_300
2565 switch(reg) {
2566 case SIS_EXTERNAL_CHIP_LVDS:
2567 ivideo->vbflags |= VB_LVDS;
2568 break;
2569 case SIS_EXTERNAL_CHIP_TRUMPION:
2570 ivideo->vbflags |= VB_TRUMPION;
2571 break;
2572 case SIS_EXTERNAL_CHIP_CHRONTEL:
2573 ivideo->vbflags |= VB_CHRONTEL;
2574 break;
2575 case SIS_EXTERNAL_CHIP_LVDS_CHRONTEL:
2576 ivideo->vbflags |= (VB_LVDS | VB_CHRONTEL);
2577 break;
2578 }
2579 if(ivideo->vbflags & VB_CHRONTEL) ivideo->chronteltype = 1;
2580#endif
2581 } else if(ivideo->chip < SIS_661) {
2582#ifdef CONFIG_FB_SIS_315
2583 switch (reg) {
2584 case SIS310_EXTERNAL_CHIP_LVDS:
2585 ivideo->vbflags |= VB_LVDS;
2586 break;
2587 case SIS310_EXTERNAL_CHIP_LVDS_CHRONTEL:
2588 ivideo->vbflags |= (VB_LVDS | VB_CHRONTEL);
2589 break;
2590 }
2591 if(ivideo->vbflags & VB_CHRONTEL) ivideo->chronteltype = 2;
2592#endif
2593 } else if(ivideo->chip >= SIS_661) {
2594#ifdef CONFIG_FB_SIS_315
2595 inSISIDXREG(SISCR, 0x38, reg);
2596 reg >>= 5;
2597 switch(reg) {
2598 case 0x02:
2599 ivideo->vbflags |= VB_LVDS;
2600 break;
2601 case 0x03:
2602 ivideo->vbflags |= (VB_LVDS | VB_CHRONTEL);
2603 break;
2604 case 0x04:
2605 ivideo->vbflags |= (VB_LVDS | VB_CONEXANT);
2606 break;
2607 }
2608 if(ivideo->vbflags & VB_CHRONTEL) ivideo->chronteltype = 2;
2609#endif
2610 }
2611 if(ivideo->vbflags & VB_LVDS) {
2612 printk(KERN_INFO "%s LVDS transmitter\n", stdstr);
2613 }
2614 if(ivideo->vbflags & VB_TRUMPION) {
2615 printk(KERN_INFO "%s Trumpion Zurac LCD scaler\n", stdstr);
2616 }
2617 if(ivideo->vbflags & VB_CHRONTEL) {
2618 printk(KERN_INFO "%s Chrontel TV encoder\n", stdstr);
2619 }
2620 if(ivideo->vbflags & VB_CONEXANT) {
2621 printk(KERN_INFO "%s Conexant external device\n", stdstr);
2622 }
2623 }
2624
2625 if(ivideo->vbflags & VB_SISBRIDGE) {
2626 SiS_Sense30x(ivideo);
2627 } else if(ivideo->vbflags & VB_CHRONTEL) {
2628 SiS_SenseCh(ivideo);
2629 } 2277 }
2630} 2278}
2631 2279
2632/* ------------------ Sensing routines ------------------ */ 2280/* ------------------ Sensing routines ------------------ */
2633 2281
2634static BOOLEAN __devinit sisfb_test_DDC1(struct sis_video_info *ivideo) 2282static BOOLEAN __devinit
2283sisfb_test_DDC1(struct sis_video_info *ivideo)
2635{ 2284{
2636 unsigned short old; 2285 unsigned short old;
2637 int count = 48; 2286 int count = 48;
2638 2287
2639 old = SiS_ReadDDC1Bit(&ivideo->SiS_Pr); 2288 old = SiS_ReadDDC1Bit(&ivideo->SiS_Pr);
2640 do { 2289 do {
2641 if(old != SiS_ReadDDC1Bit(&ivideo->SiS_Pr)) break; 2290 if(old != SiS_ReadDDC1Bit(&ivideo->SiS_Pr)) break;
2642 } while(count--); 2291 } while(count--);
2643 return (count == -1) ? FALSE : TRUE; 2292 return (count == -1) ? FALSE : TRUE;
2644} 2293}
2645 2294
2646static void __devinit sisfb_sense_crt1(struct sis_video_info *ivideo) 2295static void __devinit
2296sisfb_sense_crt1(struct sis_video_info *ivideo)
2647{ 2297{
2648 BOOLEAN mustwait = FALSE; 2298 BOOLEAN mustwait = FALSE;
2649 u8 sr1F, cr17; 2299 u8 sr1F, cr17;
@@ -2699,7 +2349,8 @@ static void __devinit sisfb_sense_crt1(struct sis_video_info *ivideo)
2699 if(temp == 0xffff) { 2349 if(temp == 0xffff) {
2700 i = 3; 2350 i = 3;
2701 do { 2351 do {
2702 temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags, ivideo->sisvga_engine, 0, 0, NULL); 2352 temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags,
2353 ivideo->sisvga_engine, 0, 0, NULL, ivideo->vbflags2);
2703 } while(((temp == 0) || (temp == 0xffff)) && i--); 2354 } while(((temp == 0) || (temp == 0xffff)) && i--);
2704 2355
2705 if((temp == 0) || (temp == 0xffff)) { 2356 if((temp == 0) || (temp == 0xffff)) {
@@ -2723,7 +2374,96 @@ static void __devinit sisfb_sense_crt1(struct sis_video_info *ivideo)
2723} 2374}
2724 2375
2725/* Determine and detect attached devices on SiS30x */ 2376/* Determine and detect attached devices on SiS30x */
2726static int __devinit SISDoSense(struct sis_video_info *ivideo, u16 type, u16 test) 2377static void __devinit
2378SiS_SenseLCD(struct sis_video_info *ivideo)
2379{
2380 unsigned char buffer[256];
2381 unsigned short temp, realcrtno, i;
2382 u8 reg, cr37 = 0, paneltype = 0;
2383 u16 xres, yres;
2384
2385 ivideo->SiS_Pr.PanelSelfDetected = FALSE;
2386
2387 /* LCD detection only for TMDS bridges */
2388 if(!(ivideo->vbflags2 & VB2_SISTMDSBRIDGE))
2389 return;
2390 if(ivideo->vbflags2 & VB2_30xBDH)
2391 return;
2392
2393 /* If LCD already set up by BIOS, skip it */
2394 inSISIDXREG(SISCR, 0x32, reg);
2395 if(reg & 0x08)
2396 return;
2397
2398 realcrtno = 1;
2399 if(ivideo->SiS_Pr.DDCPortMixup)
2400 realcrtno = 0;
2401
2402 /* Check DDC capabilities */
2403 temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags, ivideo->sisvga_engine,
2404 realcrtno, 0, &buffer[0], ivideo->vbflags2);
2405
2406 if((!temp) || (temp == 0xffff) || (!(temp & 0x02)))
2407 return;
2408
2409 /* Read DDC data */
2410 i = 3; /* Number of retrys */
2411 do {
2412 temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags,
2413 ivideo->sisvga_engine, realcrtno, 1,
2414 &buffer[0], ivideo->vbflags2);
2415 } while((temp) && i--);
2416
2417 if(temp)
2418 return;
2419
2420 /* No digital device */
2421 if(!(buffer[0x14] & 0x80))
2422 return;
2423
2424 /* First detailed timing preferred timing? */
2425 if(!(buffer[0x18] & 0x02))
2426 return;
2427
2428 xres = buffer[0x38] | ((buffer[0x3a] & 0xf0) << 4);
2429 yres = buffer[0x3b] | ((buffer[0x3d] & 0xf0) << 4);
2430
2431 switch(xres) {
2432 case 1024:
2433 if(yres == 768)
2434 paneltype = 0x02;
2435 break;
2436 case 1280:
2437 if(yres == 1024)
2438 paneltype = 0x03;
2439 break;
2440 case 1600:
2441 if((yres == 1200) && (ivideo->vbflags2 & VB2_30xC))
2442 paneltype = 0x0b;
2443 break;
2444 }
2445
2446 if(!paneltype)
2447 return;
2448
2449 if(buffer[0x23])
2450 cr37 |= 0x10;
2451
2452 if((buffer[0x47] & 0x18) == 0x18)
2453 cr37 |= ((((buffer[0x47] & 0x06) ^ 0x06) << 5) | 0x20);
2454 else
2455 cr37 |= 0xc0;
2456
2457 outSISIDXREG(SISCR, 0x36, paneltype);
2458 cr37 &= 0xf1;
2459 setSISIDXREG(SISCR, 0x37, 0x0c, cr37);
2460 orSISIDXREG(SISCR, 0x32, 0x08);
2461
2462 ivideo->SiS_Pr.PanelSelfDetected = TRUE;
2463}
2464
2465static int __devinit
2466SISDoSense(struct sis_video_info *ivideo, u16 type, u16 test)
2727{ 2467{
2728 int temp, mytest, result, i, j; 2468 int temp, mytest, result, i, j;
2729 2469
@@ -2749,10 +2489,11 @@ static int __devinit SISDoSense(struct sis_video_info *ivideo, u16 type, u16 tes
2749 } 2489 }
2750 if((result == 0) || (result >= 2)) break; 2490 if((result == 0) || (result >= 2)) break;
2751 } 2491 }
2752 return(result); 2492 return result;
2753} 2493}
2754 2494
2755static void __devinit SiS_Sense30x(struct sis_video_info *ivideo) 2495static void __devinit
2496SiS_Sense30x(struct sis_video_info *ivideo)
2756{ 2497{
2757 u8 backupP4_0d,backupP2_00,backupP2_4d,backupSR_1e,biosflag=0; 2498 u8 backupP4_0d,backupP2_00,backupP2_4d,backupSR_1e,biosflag=0;
2758 u16 svhs=0, svhs_c=0; 2499 u16 svhs=0, svhs_c=0;
@@ -2762,36 +2503,51 @@ static void __devinit SiS_Sense30x(struct sis_video_info *ivideo)
2762 char stdstr[] = "sisfb: Detected"; 2503 char stdstr[] = "sisfb: Detected";
2763 char tvstr[] = "TV connected to"; 2504 char tvstr[] = "TV connected to";
2764 2505
2765 if(ivideo->vbflags & VB_301) { 2506 if(ivideo->vbflags2 & VB2_301) {
2766 svhs = 0x00b9; cvbs = 0x00b3; vga2 = 0x00d1; 2507 svhs = 0x00b9; cvbs = 0x00b3; vga2 = 0x00d1;
2767 inSISIDXREG(SISPART4,0x01,myflag); 2508 inSISIDXREG(SISPART4,0x01,myflag);
2768 if(myflag & 0x04) { 2509 if(myflag & 0x04) {
2769 svhs = 0x00dd; cvbs = 0x00ee; vga2 = 0x00fd; 2510 svhs = 0x00dd; cvbs = 0x00ee; vga2 = 0x00fd;
2770 } 2511 }
2771 } else if(ivideo->vbflags & (VB_301B | VB_302B)) { 2512 } else if(ivideo->vbflags2 & (VB2_301B | VB2_302B)) {
2772 svhs = 0x016b; cvbs = 0x0174; vga2 = 0x0190; 2513 svhs = 0x016b; cvbs = 0x0174; vga2 = 0x0190;
2773 } else if(ivideo->vbflags & (VB_301LV | VB_302LV)) { 2514 } else if(ivideo->vbflags2 & (VB2_301LV | VB2_302LV)) {
2774 svhs = 0x0200; cvbs = 0x0100; 2515 svhs = 0x0200; cvbs = 0x0100;
2775 } else if(ivideo->vbflags & (VB_301C | VB_302ELV)) { 2516 } else if(ivideo->vbflags2 & (VB2_301C | VB2_302ELV | VB2_307T | VB2_307LV)) {
2776 svhs = 0x016b; cvbs = 0x0110; vga2 = 0x0190; 2517 svhs = 0x016b; cvbs = 0x0110; vga2 = 0x0190;
2777 } else return; 2518 } else
2519 return;
2778 2520
2779 vga2_c = 0x0e08; svhs_c = 0x0404; cvbs_c = 0x0804; 2521 vga2_c = 0x0e08; svhs_c = 0x0404; cvbs_c = 0x0804;
2780 if(ivideo->vbflags & (VB_301LV|VB_302LV|VB_302ELV)) { 2522 if(ivideo->vbflags & (VB2_301LV|VB2_302LV|VB2_302ELV|VB2_307LV)) {
2781 svhs_c = 0x0408; cvbs_c = 0x0808; 2523 svhs_c = 0x0408; cvbs_c = 0x0808;
2782 } 2524 }
2525
2783 biosflag = 2; 2526 biosflag = 2;
2527 if(ivideo->haveXGIROM) {
2528 biosflag = ivideo->bios_abase[0x58] & 0x03;
2529 } else if(ivideo->newrom) {
2530 if(ivideo->bios_abase[0x5d] & 0x04) biosflag |= 0x01;
2531 } else if(ivideo->sisvga_engine == SIS_300_VGA) {
2532 if(ivideo->bios_abase) {
2533 biosflag = ivideo->bios_abase[0xfe] & 0x03;
2534 }
2535 }
2784 2536
2785 if(ivideo->chip == SIS_300) { 2537 if(ivideo->chip == SIS_300) {
2786 inSISIDXREG(SISSR,0x3b,myflag); 2538 inSISIDXREG(SISSR,0x3b,myflag);
2787 if(!(myflag & 0x01)) vga2 = vga2_c = 0; 2539 if(!(myflag & 0x01)) vga2 = vga2_c = 0;
2788 } 2540 }
2789 2541
2542 if(!(ivideo->vbflags2 & VB2_SISVGA2BRIDGE)) {
2543 vga2 = vga2_c = 0;
2544 }
2545
2790 inSISIDXREG(SISSR,0x1e,backupSR_1e); 2546 inSISIDXREG(SISSR,0x1e,backupSR_1e);
2791 orSISIDXREG(SISSR,0x1e,0x20); 2547 orSISIDXREG(SISSR,0x1e,0x20);
2792 2548
2793 inSISIDXREG(SISPART4,0x0d,backupP4_0d); 2549 inSISIDXREG(SISPART4,0x0d,backupP4_0d);
2794 if(ivideo->vbflags & VB_301C) { 2550 if(ivideo->vbflags2 & VB2_30xC) {
2795 setSISIDXREG(SISPART4,0x0d,~0x07,0x01); 2551 setSISIDXREG(SISPART4,0x0d,~0x07,0x01);
2796 } else { 2552 } else {
2797 orSISIDXREG(SISPART4,0x0d,0x04); 2553 orSISIDXREG(SISPART4,0x0d,0x04);
@@ -2802,11 +2558,11 @@ static void __devinit SiS_Sense30x(struct sis_video_info *ivideo)
2802 outSISIDXREG(SISPART2,0x00,((backupP2_00 | 0x1c) & 0xfc)); 2558 outSISIDXREG(SISPART2,0x00,((backupP2_00 | 0x1c) & 0xfc));
2803 2559
2804 inSISIDXREG(SISPART2,0x4d,backupP2_4d); 2560 inSISIDXREG(SISPART2,0x4d,backupP2_4d);
2805 if(ivideo->vbflags & (VB_301C|VB_301LV|VB_302LV|VB_302ELV)) { 2561 if(ivideo->vbflags2 & VB2_SISYPBPRBRIDGE) {
2806 outSISIDXREG(SISPART2,0x4d,(backupP2_4d & ~0x10)); 2562 outSISIDXREG(SISPART2,0x4d,(backupP2_4d & ~0x10));
2807 } 2563 }
2808 2564
2809 if(!(ivideo->vbflags & VB_301C)) { 2565 if(!(ivideo->vbflags2 & VB2_30xCLV)) {
2810 SISDoSense(ivideo, 0, 0); 2566 SISDoSense(ivideo, 0, 0);
2811 } 2567 }
2812 2568
@@ -2826,12 +2582,11 @@ static void __devinit SiS_Sense30x(struct sis_video_info *ivideo)
2826 2582
2827 andSISIDXREG(SISCR, 0x32, 0x3f); 2583 andSISIDXREG(SISCR, 0x32, 0x3f);
2828 2584
2829 if(ivideo->vbflags & VB_301C) { 2585 if(ivideo->vbflags2 & VB2_30xCLV) {
2830 orSISIDXREG(SISPART4,0x0d,0x04); 2586 orSISIDXREG(SISPART4,0x0d,0x04);
2831 } 2587 }
2832 2588
2833 if((ivideo->sisvga_engine == SIS_315_VGA) && 2589 if((ivideo->sisvga_engine == SIS_315_VGA) && (ivideo->vbflags2 & VB2_SISYPBPRBRIDGE)) {
2834 (ivideo->vbflags & (VB_301C|VB_301LV|VB_302LV|VB_302ELV))) {
2835 outSISIDXREG(SISPART2,0x4d,(backupP2_4d | 0x10)); 2590 outSISIDXREG(SISPART2,0x4d,(backupP2_4d | 0x10));
2836 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x2000); 2591 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x2000);
2837 if((result = SISDoSense(ivideo, svhs, 0x0604))) { 2592 if((result = SISDoSense(ivideo, svhs, 0x0604))) {
@@ -2864,7 +2619,7 @@ static void __devinit SiS_Sense30x(struct sis_video_info *ivideo)
2864 outSISIDXREG(SISPART4,0x0d,backupP4_0d); 2619 outSISIDXREG(SISPART4,0x0d,backupP4_0d);
2865 outSISIDXREG(SISSR,0x1e,backupSR_1e); 2620 outSISIDXREG(SISSR,0x1e,backupSR_1e);
2866 2621
2867 if(ivideo->vbflags & VB_301C) { 2622 if(ivideo->vbflags2 & VB2_30xCLV) {
2868 inSISIDXREG(SISPART2,0x00,biosflag); 2623 inSISIDXREG(SISPART2,0x00,biosflag);
2869 if(biosflag & 0x20) { 2624 if(biosflag & 0x20) {
2870 for(myflag = 2; myflag > 0; myflag--) { 2625 for(myflag = 2; myflag > 0; myflag--) {
@@ -2878,7 +2633,8 @@ static void __devinit SiS_Sense30x(struct sis_video_info *ivideo)
2878} 2633}
2879 2634
2880/* Determine and detect attached TV's on Chrontel */ 2635/* Determine and detect attached TV's on Chrontel */
2881static void __devinit SiS_SenseCh(struct sis_video_info *ivideo) 2636static void __devinit
2637SiS_SenseCh(struct sis_video_info *ivideo)
2882{ 2638{
2883#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315) 2639#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
2884 u8 temp1, temp2; 2640 u8 temp1, temp2;
@@ -2899,7 +2655,7 @@ static void __devinit SiS_SenseCh(struct sis_video_info *ivideo)
2899 /* See Chrontel TB31 for explanation */ 2655 /* See Chrontel TB31 for explanation */
2900 temp2 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0e); 2656 temp2 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0e);
2901 if(((temp2 & 0x07) == 0x01) || (temp2 & 0x04)) { 2657 if(((temp2 & 0x07) == 0x01) || (temp2 & 0x04)) {
2902 SiS_SetCH700x(&ivideo->SiS_Pr, 0x0b0e); 2658 SiS_SetCH700x(&ivideo->SiS_Pr, 0x0e, 0x0b);
2903 SiS_DDC2Delay(&ivideo->SiS_Pr, 300); 2659 SiS_DDC2Delay(&ivideo->SiS_Pr, 300);
2904 } 2660 }
2905 temp2 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x25); 2661 temp2 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x25);
@@ -2909,15 +2665,15 @@ static void __devinit SiS_SenseCh(struct sis_video_info *ivideo)
2909 /* Read power status */ 2665 /* Read power status */
2910 temp1 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0e); 2666 temp1 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0e);
2911 if((temp1 & 0x03) != 0x03) { 2667 if((temp1 & 0x03) != 0x03) {
2912 /* Power all outputs */ 2668 /* Power all outputs */
2913 SiS_SetCH700x(&ivideo->SiS_Pr, 0x0B0E); 2669 SiS_SetCH700x(&ivideo->SiS_Pr, 0x0e,0x0b);
2914 SiS_DDC2Delay(&ivideo->SiS_Pr, 300); 2670 SiS_DDC2Delay(&ivideo->SiS_Pr, 300);
2915 } 2671 }
2916 /* Sense connected TV devices */ 2672 /* Sense connected TV devices */
2917 for(i = 0; i < 3; i++) { 2673 for(i = 0; i < 3; i++) {
2918 SiS_SetCH700x(&ivideo->SiS_Pr, 0x0110); 2674 SiS_SetCH700x(&ivideo->SiS_Pr, 0x10, 0x01);
2919 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96); 2675 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96);
2920 SiS_SetCH700x(&ivideo->SiS_Pr, 0x0010); 2676 SiS_SetCH700x(&ivideo->SiS_Pr, 0x10, 0x00);
2921 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96); 2677 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96);
2922 temp1 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x10); 2678 temp1 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x10);
2923 if(!(temp1 & 0x08)) test[i] = 0x02; 2679 if(!(temp1 & 0x08)) test[i] = 0x02;
@@ -2930,7 +2686,7 @@ static void __devinit SiS_SenseCh(struct sis_video_info *ivideo)
2930 else if(test[0] == test[2]) temp1 = test[0]; 2686 else if(test[0] == test[2]) temp1 = test[0];
2931 else if(test[1] == test[2]) temp1 = test[1]; 2687 else if(test[1] == test[2]) temp1 = test[1];
2932 else { 2688 else {
2933 printk(KERN_INFO 2689 printk(KERN_INFO
2934 "sisfb: TV detection unreliable - test results varied\n"); 2690 "sisfb: TV detection unreliable - test results varied\n");
2935 temp1 = test[2]; 2691 temp1 = test[2];
2936 } 2692 }
@@ -2945,11 +2701,11 @@ static void __devinit SiS_SenseCh(struct sis_video_info *ivideo)
2945 orSISIDXREG(SISCR, 0x32, 0x01); 2701 orSISIDXREG(SISCR, 0x32, 0x01);
2946 andSISIDXREG(SISCR, 0x32, ~0x06); 2702 andSISIDXREG(SISCR, 0x32, ~0x06);
2947 } else { 2703 } else {
2948 SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x010E,0xF8); 2704 SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x0e, 0x01, 0xF8);
2949 andSISIDXREG(SISCR, 0x32, ~0x07); 2705 andSISIDXREG(SISCR, 0x32, ~0x07);
2950 } 2706 }
2951 } else if(temp1 == 0) { 2707 } else if(temp1 == 0) {
2952 SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x010E,0xF8); 2708 SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x0e, 0x01, 0xF8);
2953 andSISIDXREG(SISCR, 0x32, ~0x07); 2709 andSISIDXREG(SISCR, 0x32, ~0x07);
2954 } 2710 }
2955 /* Set general purpose IO for Chrontel communication */ 2711 /* Set general purpose IO for Chrontel communication */
@@ -2960,19 +2716,19 @@ static void __devinit SiS_SenseCh(struct sis_video_info *ivideo)
2960 2716
2961#ifdef CONFIG_FB_SIS_315 2717#ifdef CONFIG_FB_SIS_315
2962 ivideo->SiS_Pr.SiS_IF_DEF_CH70xx = 2; /* Chrontel 7019 */ 2718 ivideo->SiS_Pr.SiS_IF_DEF_CH70xx = 2; /* Chrontel 7019 */
2963 temp1 = SiS_GetCH701x(&ivideo->SiS_Pr, 0x49); 2719 temp1 = SiS_GetCH701x(&ivideo->SiS_Pr, 0x49);
2964 SiS_SetCH701x(&ivideo->SiS_Pr, 0x2049); 2720 SiS_SetCH701x(&ivideo->SiS_Pr, 0x49, 0x20);
2965 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96); 2721 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96);
2966 temp2 = SiS_GetCH701x(&ivideo->SiS_Pr, 0x20); 2722 temp2 = SiS_GetCH701x(&ivideo->SiS_Pr, 0x20);
2967 temp2 |= 0x01; 2723 temp2 |= 0x01;
2968 SiS_SetCH701x(&ivideo->SiS_Pr, (temp2 << 8) | 0x20); 2724 SiS_SetCH701x(&ivideo->SiS_Pr, 0x20, temp2);
2969 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96); 2725 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96);
2970 temp2 ^= 0x01; 2726 temp2 ^= 0x01;
2971 SiS_SetCH701x(&ivideo->SiS_Pr, (temp2 << 8) | 0x20); 2727 SiS_SetCH701x(&ivideo->SiS_Pr, 0x20, temp2);
2972 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96); 2728 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96);
2973 temp2 = SiS_GetCH701x(&ivideo->SiS_Pr, 0x20); 2729 temp2 = SiS_GetCH701x(&ivideo->SiS_Pr, 0x20);
2974 SiS_SetCH701x(&ivideo->SiS_Pr, (temp1 << 8) | 0x49); 2730 SiS_SetCH701x(&ivideo->SiS_Pr, 0x49, temp1);
2975 temp1 = 0; 2731 temp1 = 0;
2976 if(temp2 & 0x02) temp1 |= 0x01; 2732 if(temp2 & 0x02) temp1 |= 0x01;
2977 if(temp2 & 0x10) temp1 |= 0x01; 2733 if(temp2 & 0x10) temp1 |= 0x01;
2978 if(temp2 & 0x04) temp1 |= 0x02; 2734 if(temp2 & 0x04) temp1 |= 0x02;
@@ -2983,18 +2739,18 @@ static void __devinit SiS_SenseCh(struct sis_video_info *ivideo)
2983 ivideo->vbflags |= TV_AVIDEO; 2739 ivideo->vbflags |= TV_AVIDEO;
2984 orSISIDXREG(SISCR, 0x32, 0x01); 2740 orSISIDXREG(SISCR, 0x32, 0x01);
2985 andSISIDXREG(SISCR, 0x32, ~0x06); 2741 andSISIDXREG(SISCR, 0x32, ~0x06);
2986 break; 2742 break;
2987 case 0x02: 2743 case 0x02:
2988 printk(KERN_INFO "%s SVIDEO output\n", stdstr); 2744 printk(KERN_INFO "%s SVIDEO output\n", stdstr);
2989 ivideo->vbflags |= TV_SVIDEO; 2745 ivideo->vbflags |= TV_SVIDEO;
2990 orSISIDXREG(SISCR, 0x32, 0x02); 2746 orSISIDXREG(SISCR, 0x32, 0x02);
2991 andSISIDXREG(SISCR, 0x32, ~0x05); 2747 andSISIDXREG(SISCR, 0x32, ~0x05);
2992 break; 2748 break;
2993 case 0x04: 2749 case 0x04:
2994 printk(KERN_INFO "%s SCART output\n", stdstr); 2750 printk(KERN_INFO "%s SCART output\n", stdstr);
2995 orSISIDXREG(SISCR, 0x32, 0x04); 2751 orSISIDXREG(SISCR, 0x32, 0x04);
2996 andSISIDXREG(SISCR, 0x32, ~0x03); 2752 andSISIDXREG(SISCR, 0x32, ~0x03);
2997 break; 2753 break;
2998 default: 2754 default:
2999 andSISIDXREG(SISCR, 0x32, ~0x07); 2755 andSISIDXREG(SISCR, 0x32, ~0x07);
3000 } 2756 }
@@ -3002,165 +2758,589 @@ static void __devinit SiS_SenseCh(struct sis_video_info *ivideo)
3002 } 2758 }
3003} 2759}
3004 2760
3005/* ------------------------ Heap routines -------------------------- */ 2761static void __devinit
3006 2762sisfb_get_VB_type(struct sis_video_info *ivideo)
3007static u32 __devinit
3008sisfb_getheapstart(struct sis_video_info *ivideo)
3009{ 2763{
3010 u32 ret = ivideo->sisfb_parm_mem * 1024; 2764 char stdstr[] = "sisfb: Detected";
3011 u32 max = ivideo->video_size - ivideo->hwcursor_size; 2765 char bridgestr[] = "video bridge";
3012 u32 def; 2766 u8 vb_chipid;
2767 u8 reg;
3013 2768
3014 /* Calculate heap start = end of memory for console 2769 /* No CRT2 on XGI Z7 */
3015 * 2770 if(ivideo->chip == XGI_20)
3016 * CCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDHHHHQQQQQQQQQQ 2771 return;
3017 * C = console, D = heap, H = HWCursor, Q = cmd-queue
3018 *
3019 * Basically given by "mem" parameter
3020 *
3021 * maximum = videosize - cmd_queue - hwcursor
3022 * (results in a heap of size 0)
3023 * default = SiS 300: depends on videosize
3024 * SiS 315/330: 32k below max
3025 */
3026 2772
3027 if(ivideo->sisvga_engine == SIS_300_VGA) { 2773 inSISIDXREG(SISPART4, 0x00, vb_chipid);
3028 max -= TURBO_QUEUE_AREA_SIZE; 2774 switch(vb_chipid) {
3029 if(ivideo->video_size > 0x1000000) { 2775 case 0x01:
3030 def = 0xc00000; 2776 inSISIDXREG(SISPART4, 0x01, reg);
3031 } else if(ivideo->video_size > 0x800000) { 2777 if(reg < 0xb0) {
3032 def = 0x800000; 2778 ivideo->vbflags |= VB_301; /* Deprecated */
3033 } else { 2779 ivideo->vbflags2 |= VB2_301;
3034 def = 0x400000; 2780 printk(KERN_INFO "%s SiS301 %s\n", stdstr, bridgestr);
3035 } 2781 } else if(reg < 0xc0) {
3036 } else { 2782 ivideo->vbflags |= VB_301B; /* Deprecated */
3037 max -= COMMAND_QUEUE_AREA_SIZE; 2783 ivideo->vbflags2 |= VB2_301B;
3038 def = max - 0x8000; 2784 inSISIDXREG(SISPART4,0x23,reg);
2785 if(!(reg & 0x02)) {
2786 ivideo->vbflags |= VB_30xBDH; /* Deprecated */
2787 ivideo->vbflags2 |= VB2_30xBDH;
2788 printk(KERN_INFO "%s SiS301B-DH %s\n", stdstr, bridgestr);
2789 } else {
2790 printk(KERN_INFO "%s SiS301B %s\n", stdstr, bridgestr);
2791 }
2792 } else if(reg < 0xd0) {
2793 ivideo->vbflags |= VB_301C; /* Deprecated */
2794 ivideo->vbflags2 |= VB2_301C;
2795 printk(KERN_INFO "%s SiS301C %s\n", stdstr, bridgestr);
2796 } else if(reg < 0xe0) {
2797 ivideo->vbflags |= VB_301LV; /* Deprecated */
2798 ivideo->vbflags2 |= VB2_301LV;
2799 printk(KERN_INFO "%s SiS301LV %s\n", stdstr, bridgestr);
2800 } else if(reg <= 0xe1) {
2801 inSISIDXREG(SISPART4,0x39,reg);
2802 if(reg == 0xff) {
2803 ivideo->vbflags |= VB_302LV; /* Deprecated */
2804 ivideo->vbflags2 |= VB2_302LV;
2805 printk(KERN_INFO "%s SiS302LV %s\n", stdstr, bridgestr);
2806 } else {
2807 ivideo->vbflags |= VB_301C; /* Deprecated */
2808 ivideo->vbflags2 |= VB2_301C;
2809 printk(KERN_INFO "%s SiS301C(P4) %s\n", stdstr, bridgestr);
2810#if 0
2811 ivideo->vbflags |= VB_302ELV; /* Deprecated */
2812 ivideo->vbflags2 |= VB2_302ELV;
2813 printk(KERN_INFO "%s SiS302ELV %s\n", stdstr, bridgestr);
2814#endif
2815 }
2816 }
2817 break;
2818 case 0x02:
2819 ivideo->vbflags |= VB_302B; /* Deprecated */
2820 ivideo->vbflags2 |= VB2_302B;
2821 printk(KERN_INFO "%s SiS302B %s\n", stdstr, bridgestr);
2822 break;
3039 } 2823 }
3040 2824
3041 if((!ret) || (ret > max) || (ivideo->cardnumber != 0)) { 2825 if((!(ivideo->vbflags2 & VB2_VIDEOBRIDGE)) && (ivideo->chip != SIS_300)) {
3042 ret = def; 2826 inSISIDXREG(SISCR, 0x37, reg);
3043 } 2827 reg &= SIS_EXTERNAL_CHIP_MASK;
2828 reg >>= 1;
2829 if(ivideo->sisvga_engine == SIS_300_VGA) {
2830#ifdef CONFIG_FB_SIS_300
2831 switch(reg) {
2832 case SIS_EXTERNAL_CHIP_LVDS:
2833 ivideo->vbflags |= VB_LVDS; /* Deprecated */
2834 ivideo->vbflags2 |= VB2_LVDS;
2835 break;
2836 case SIS_EXTERNAL_CHIP_TRUMPION:
2837 ivideo->vbflags |= (VB_LVDS | VB_TRUMPION); /* Deprecated */
2838 ivideo->vbflags2 |= (VB2_LVDS | VB2_TRUMPION);
2839 break;
2840 case SIS_EXTERNAL_CHIP_CHRONTEL:
2841 ivideo->vbflags |= VB_CHRONTEL; /* Deprecated */
2842 ivideo->vbflags2 |= VB2_CHRONTEL;
2843 break;
2844 case SIS_EXTERNAL_CHIP_LVDS_CHRONTEL:
2845 ivideo->vbflags |= (VB_LVDS | VB_CHRONTEL); /* Deprecated */
2846 ivideo->vbflags2 |= (VB2_LVDS | VB2_CHRONTEL);
2847 break;
2848 }
2849 if(ivideo->vbflags2 & VB2_CHRONTEL) ivideo->chronteltype = 1;
2850#endif
2851 } else if(ivideo->chip < SIS_661) {
2852#ifdef CONFIG_FB_SIS_315
2853 switch (reg) {
2854 case SIS310_EXTERNAL_CHIP_LVDS:
2855 ivideo->vbflags |= VB_LVDS; /* Deprecated */
2856 ivideo->vbflags2 |= VB2_LVDS;
2857 break;
2858 case SIS310_EXTERNAL_CHIP_LVDS_CHRONTEL:
2859 ivideo->vbflags |= (VB_LVDS | VB_CHRONTEL); /* Deprecated */
2860 ivideo->vbflags2 |= (VB2_LVDS | VB2_CHRONTEL);
2861 break;
2862 }
2863 if(ivideo->vbflags2 & VB2_CHRONTEL) ivideo->chronteltype = 2;
2864#endif
2865 } else if(ivideo->chip >= SIS_661) {
2866#ifdef CONFIG_FB_SIS_315
2867 inSISIDXREG(SISCR, 0x38, reg);
2868 reg >>= 5;
2869 switch(reg) {
2870 case 0x02:
2871 ivideo->vbflags |= VB_LVDS; /* Deprecated */
2872 ivideo->vbflags2 |= VB2_LVDS;
2873 break;
2874 case 0x03:
2875 ivideo->vbflags |= (VB_LVDS | VB_CHRONTEL); /* Deprecated */
2876 ivideo->vbflags2 |= (VB2_LVDS | VB2_CHRONTEL);
2877 break;
2878 case 0x04:
2879 ivideo->vbflags |= (VB_LVDS | VB_CONEXANT); /* Deprecated */
2880 ivideo->vbflags2 |= (VB2_LVDS | VB2_CONEXANT);
2881 break;
2882 }
2883 if(ivideo->vbflags2 & VB2_CHRONTEL) ivideo->chronteltype = 2;
2884#endif
2885 }
2886 if(ivideo->vbflags2 & VB2_LVDS) {
2887 printk(KERN_INFO "%s LVDS transmitter\n", stdstr);
2888 }
2889 if((ivideo->sisvga_engine == SIS_300_VGA) && (ivideo->vbflags2 & VB2_TRUMPION)) {
2890 printk(KERN_INFO "%s Trumpion Zurac LCD scaler\n", stdstr);
2891 }
2892 if(ivideo->vbflags2 & VB2_CHRONTEL) {
2893 printk(KERN_INFO "%s Chrontel TV encoder\n", stdstr);
2894 }
2895 if((ivideo->chip >= SIS_661) && (ivideo->vbflags2 & VB2_CONEXANT)) {
2896 printk(KERN_INFO "%s Conexant external device\n", stdstr);
2897 }
2898 }
3044 2899
3045 return ret; 2900 if(ivideo->vbflags2 & VB2_SISBRIDGE) {
2901 SiS_SenseLCD(ivideo);
2902 SiS_Sense30x(ivideo);
2903 } else if(ivideo->vbflags2 & VB2_CHRONTEL) {
2904 SiS_SenseCh(ivideo);
2905 }
3046} 2906}
3047 2907
3048static int __devinit 2908/* ---------- Engine initialization routines ------------ */
3049sisfb_heap_init(struct sis_video_info *ivideo) 2909
2910static void
2911sisfb_engine_init(struct sis_video_info *ivideo)
3050{ 2912{
3051 SIS_OH *poh;
3052 2913
3053 ivideo->heapstart = ivideo->sisfb_mem = sisfb_getheapstart(ivideo); 2914 /* Initialize command queue (we use MMIO only) */
3054 2915
3055 ivideo->sisfb_heap_start = ivideo->video_vbase + ivideo->heapstart; 2916 /* BEFORE THIS IS CALLED, THE ENGINES *MUST* BE SYNC'ED */
3056 ivideo->sisfb_heap_end = ivideo->video_vbase + ivideo->video_size;
3057 2917
3058 /* Initialize command queue (We use MMIO only) */ 2918 ivideo->caps &= ~(TURBO_QUEUE_CAP |
2919 MMIO_CMD_QUEUE_CAP |
2920 VM_CMD_QUEUE_CAP |
2921 AGP_CMD_QUEUE_CAP);
2922
2923#ifdef CONFIG_FB_SIS_300
2924 if(ivideo->sisvga_engine == SIS_300_VGA) {
2925 u32 tqueue_pos;
2926 u8 tq_state;
2927
2928 tqueue_pos = (ivideo->video_size - ivideo->cmdQueueSize) / (64 * 1024);
2929
2930 inSISIDXREG(SISSR, IND_SIS_TURBOQUEUE_SET, tq_state);
2931 tq_state |= 0xf0;
2932 tq_state &= 0xfc;
2933 tq_state |= (u8)(tqueue_pos >> 8);
2934 outSISIDXREG(SISSR, IND_SIS_TURBOQUEUE_SET, tq_state);
2935
2936 outSISIDXREG(SISSR, IND_SIS_TURBOQUEUE_ADR, (u8)(tqueue_pos & 0xff));
2937
2938 ivideo->caps |= TURBO_QUEUE_CAP;
2939 }
2940#endif
3059 2941
3060#ifdef CONFIG_FB_SIS_315 2942#ifdef CONFIG_FB_SIS_315
3061 if(ivideo->sisvga_engine == SIS_315_VGA) { 2943 if(ivideo->sisvga_engine == SIS_315_VGA) {
3062 u32 tempq = 0; 2944 u32 tempq = 0, templ;
3063 u8 temp = 0; 2945 u8 temp;
2946
2947 if(ivideo->chip == XGI_20) {
2948 switch(ivideo->cmdQueueSize) {
2949 case (64 * 1024):
2950 temp = SIS_CMD_QUEUE_SIZE_Z7_64k;
2951 break;
2952 case (128 * 1024):
2953 default:
2954 temp = SIS_CMD_QUEUE_SIZE_Z7_128k;
2955 }
2956 } else {
2957 switch(ivideo->cmdQueueSize) {
2958 case (4 * 1024 * 1024):
2959 temp = SIS_CMD_QUEUE_SIZE_4M;
2960 break;
2961 case (2 * 1024 * 1024):
2962 temp = SIS_CMD_QUEUE_SIZE_2M;
2963 break;
2964 case (1 * 1024 * 1024):
2965 temp = SIS_CMD_QUEUE_SIZE_1M;
2966 break;
2967 default:
2968 case (512 * 1024):
2969 temp = SIS_CMD_QUEUE_SIZE_512k;
2970 }
2971 }
2972
2973 outSISIDXREG(SISSR, IND_SIS_CMDQUEUE_THRESHOLD, COMMAND_QUEUE_THRESHOLD);
2974 outSISIDXREG(SISSR, IND_SIS_CMDQUEUE_SET, SIS_CMD_QUEUE_RESET);
2975
2976 if((ivideo->chip >= XGI_40) && ivideo->modechanged) {
2977 /* Must disable dual pipe on XGI_40. Can't do
2978 * this in MMIO mode, because it requires
2979 * setting/clearing a bit in the MMIO fire trigger
2980 * register.
2981 */
2982 if(!((templ = MMIO_IN32(ivideo->mmio_vbase, 0x8240)) & (1 << 10))) {
2983
2984 MMIO_OUT32(ivideo->mmio_vbase, Q_WRITE_PTR, 0);
2985
2986 outSISIDXREG(SISSR, IND_SIS_CMDQUEUE_SET, (temp | SIS_VRAM_CMDQUEUE_ENABLE));
2987
2988 tempq = MMIO_IN32(ivideo->mmio_vbase, Q_READ_PTR);
2989 MMIO_OUT32(ivideo->mmio_vbase, Q_WRITE_PTR, tempq);
2990
2991 tempq = (u32)(ivideo->video_size - ivideo->cmdQueueSize);
2992 MMIO_OUT32(ivideo->mmio_vbase, Q_BASE_ADDR, tempq);
2993
2994 writel(0x16800000 + 0x8240, ivideo->video_vbase + tempq);
2995 writel(templ | (1 << 10), ivideo->video_vbase + tempq + 4);
2996 writel(0x168F0000, ivideo->video_vbase + tempq + 8);
2997 writel(0x168F0000, ivideo->video_vbase + tempq + 12);
2998
2999 MMIO_OUT32(ivideo->mmio_vbase, Q_WRITE_PTR, (tempq + 16));
3000
3001 sisfb_syncaccel(ivideo);
3002
3003 outSISIDXREG(SISSR, IND_SIS_CMDQUEUE_SET, SIS_CMD_QUEUE_RESET);
3004
3005 }
3006 }
3007
3008 tempq = MMIO_IN32(ivideo->mmio_vbase, MMIO_QUEUE_READPORT);
3009 MMIO_OUT32(ivideo->mmio_vbase, MMIO_QUEUE_WRITEPORT, tempq);
3010
3011 temp |= (SIS_MMIO_CMD_ENABLE | SIS_CMD_AUTO_CORR);
3012 outSISIDXREG(SISSR, IND_SIS_CMDQUEUE_SET, temp);
3013
3014 tempq = (u32)(ivideo->video_size - ivideo->cmdQueueSize);
3015 MMIO_OUT32(ivideo->mmio_vbase, MMIO_QUEUE_PHYBASE, tempq);
3064 3016
3065 ivideo->sisfb_heap_end -= COMMAND_QUEUE_AREA_SIZE; 3017 ivideo->caps |= MMIO_CMD_QUEUE_CAP;
3018 }
3019#endif
3066 3020
3067 outSISIDXREG(SISSR, IND_SIS_CMDQUEUE_THRESHOLD, COMMAND_QUEUE_THRESHOLD); 3021 ivideo->engineok = 1;
3068 outSISIDXREG(SISSR, IND_SIS_CMDQUEUE_SET, SIS_CMD_QUEUE_RESET); 3022}
3069 3023
3070 tempq = MMIO_IN32(ivideo->mmio_vbase, MMIO_QUEUE_READPORT); 3024static void __devinit
3071 MMIO_OUT32(ivideo->mmio_vbase, MMIO_QUEUE_WRITEPORT, tempq); 3025sisfb_detect_lcd_type(struct sis_video_info *ivideo)
3026{
3027 u8 reg;
3028 int i;
3072 3029
3073 temp = SIS_CMD_QUEUE_SIZE_512k; 3030 inSISIDXREG(SISCR, 0x36, reg);
3074 temp |= (SIS_MMIO_CMD_ENABLE | SIS_CMD_AUTO_CORR); 3031 reg &= 0x0f;
3075 outSISIDXREG(SISSR, IND_SIS_CMDQUEUE_SET, temp); 3032 if(ivideo->sisvga_engine == SIS_300_VGA) {
3033 ivideo->CRT2LCDType = sis300paneltype[reg];
3034 } else if(ivideo->chip >= SIS_661) {
3035 ivideo->CRT2LCDType = sis661paneltype[reg];
3036 } else {
3037 ivideo->CRT2LCDType = sis310paneltype[reg];
3038 if((ivideo->chip == SIS_550) && (sisfb_fstn)) {
3039 if((ivideo->CRT2LCDType != LCD_320x240_2) &&
3040 (ivideo->CRT2LCDType != LCD_320x240_3)) {
3041 ivideo->CRT2LCDType = LCD_320x240;
3042 }
3043 }
3044 }
3076 3045
3077 tempq = (u32)(ivideo->video_size - COMMAND_QUEUE_AREA_SIZE); 3046 if(ivideo->CRT2LCDType == LCD_UNKNOWN) {
3078 MMIO_OUT32(ivideo->mmio_vbase, MMIO_QUEUE_PHYBASE, tempq); 3047 /* For broken BIOSes: Assume 1024x768, RGB18 */
3048 ivideo->CRT2LCDType = LCD_1024x768;
3049 setSISIDXREG(SISCR,0x36,0xf0,0x02);
3050 setSISIDXREG(SISCR,0x37,0xee,0x01);
3051 printk(KERN_DEBUG "sisfb: Invalid panel ID (%02x), assuming 1024x768, RGB18\n", reg);
3052 }
3079 3053
3080 ivideo->caps |= MMIO_CMD_QUEUE_CAP; 3054 for(i = 0; i < SIS_LCD_NUMBER; i++) {
3081 } 3055 if(ivideo->CRT2LCDType == sis_lcd_data[i].lcdtype) {
3056 ivideo->lcdxres = sis_lcd_data[i].xres;
3057 ivideo->lcdyres = sis_lcd_data[i].yres;
3058 ivideo->lcddefmodeidx = sis_lcd_data[i].default_mode_idx;
3059 break;
3060 }
3061 }
3062
3063#ifdef CONFIG_FB_SIS_300
3064 if(ivideo->SiS_Pr.SiS_CustomT == CUT_BARCO1366) {
3065 ivideo->lcdxres = 1360; ivideo->lcdyres = 1024;
3066 ivideo->lcddefmodeidx = DEFAULT_MODE_1360;
3067 } else if(ivideo->SiS_Pr.SiS_CustomT == CUT_PANEL848) {
3068 ivideo->lcdxres = 848; ivideo->lcdyres = 480;
3069 ivideo->lcddefmodeidx = DEFAULT_MODE_848;
3070 } else if(ivideo->SiS_Pr.SiS_CustomT == CUT_PANEL856) {
3071 ivideo->lcdxres = 856; ivideo->lcdyres = 480;
3072 ivideo->lcddefmodeidx = DEFAULT_MODE_856;
3073 }
3082#endif 3074#endif
3083 3075
3076 printk(KERN_DEBUG "sisfb: Detected %dx%d flat panel\n",
3077 ivideo->lcdxres, ivideo->lcdyres);
3078}
3079
3080static void __devinit
3081sisfb_save_pdc_emi(struct sis_video_info *ivideo)
3082{
3084#ifdef CONFIG_FB_SIS_300 3083#ifdef CONFIG_FB_SIS_300
3085 if(ivideo->sisvga_engine == SIS_300_VGA) { 3084 /* Save the current PanelDelayCompensation if the LCD is currently used */
3086 unsigned long tqueue_pos; 3085 if(ivideo->sisvga_engine == SIS_300_VGA) {
3087 u8 tq_state; 3086 if(ivideo->vbflags2 & (VB2_LVDS | VB2_30xBDH)) {
3087 int tmp;
3088 inSISIDXREG(SISCR,0x30,tmp);
3089 if(tmp & 0x20) {
3090 /* Currently on LCD? If yes, read current pdc */
3091 inSISIDXREG(SISPART1,0x13,ivideo->detectedpdc);
3092 ivideo->detectedpdc &= 0x3c;
3093 if(ivideo->SiS_Pr.PDC == -1) {
3094 /* Let option override detection */
3095 ivideo->SiS_Pr.PDC = ivideo->detectedpdc;
3096 }
3097 printk(KERN_INFO "sisfb: Detected LCD PDC 0x%02x\n",
3098 ivideo->detectedpdc);
3099 }
3100 if((ivideo->SiS_Pr.PDC != -1) &&
3101 (ivideo->SiS_Pr.PDC != ivideo->detectedpdc)) {
3102 printk(KERN_INFO "sisfb: Using LCD PDC 0x%02x\n",
3103 ivideo->SiS_Pr.PDC);
3104 }
3105 }
3106 }
3107#endif
3088 3108
3089 ivideo->sisfb_heap_end -= TURBO_QUEUE_AREA_SIZE; 3109#ifdef CONFIG_FB_SIS_315
3110 if(ivideo->sisvga_engine == SIS_315_VGA) {
3090 3111
3091 tqueue_pos = (ivideo->video_size - TURBO_QUEUE_AREA_SIZE) / (64 * 1024); 3112 /* Try to find about LCDA */
3113 if(ivideo->vbflags2 & VB2_SISLCDABRIDGE) {
3114 int tmp;
3115 inSISIDXREG(SISPART1,0x13,tmp);
3116 if(tmp & 0x04) {
3117 ivideo->SiS_Pr.SiS_UseLCDA = TRUE;
3118 ivideo->detectedlcda = 0x03;
3119 }
3120 }
3092 3121
3093 inSISIDXREG(SISSR, IND_SIS_TURBOQUEUE_SET, tq_state); 3122 /* Save PDC */
3094 tq_state |= 0xf0; 3123 if(ivideo->vbflags2 & VB2_SISLVDSBRIDGE) {
3095 tq_state &= 0xfc; 3124 int tmp;
3096 tq_state |= (u8)(tqueue_pos >> 8); 3125 inSISIDXREG(SISCR,0x30,tmp);
3097 outSISIDXREG(SISSR, IND_SIS_TURBOQUEUE_SET, tq_state); 3126 if((tmp & 0x20) || (ivideo->detectedlcda != 0xff)) {
3127 /* Currently on LCD? If yes, read current pdc */
3128 u8 pdc;
3129 inSISIDXREG(SISPART1,0x2D,pdc);
3130 ivideo->detectedpdc = (pdc & 0x0f) << 1;
3131 ivideo->detectedpdca = (pdc & 0xf0) >> 3;
3132 inSISIDXREG(SISPART1,0x35,pdc);
3133 ivideo->detectedpdc |= ((pdc >> 7) & 0x01);
3134 inSISIDXREG(SISPART1,0x20,pdc);
3135 ivideo->detectedpdca |= ((pdc >> 6) & 0x01);
3136 if(ivideo->newrom) {
3137 /* New ROM invalidates other PDC resp. */
3138 if(ivideo->detectedlcda != 0xff) {
3139 ivideo->detectedpdc = 0xff;
3140 } else {
3141 ivideo->detectedpdca = 0xff;
3142 }
3143 }
3144 if(ivideo->SiS_Pr.PDC == -1) {
3145 if(ivideo->detectedpdc != 0xff) {
3146 ivideo->SiS_Pr.PDC = ivideo->detectedpdc;
3147 }
3148 }
3149 if(ivideo->SiS_Pr.PDCA == -1) {
3150 if(ivideo->detectedpdca != 0xff) {
3151 ivideo->SiS_Pr.PDCA = ivideo->detectedpdca;
3152 }
3153 }
3154 if(ivideo->detectedpdc != 0xff) {
3155 printk(KERN_INFO
3156 "sisfb: Detected LCD PDC 0x%02x (for LCD=CRT2)\n",
3157 ivideo->detectedpdc);
3158 }
3159 if(ivideo->detectedpdca != 0xff) {
3160 printk(KERN_INFO
3161 "sisfb: Detected LCD PDC1 0x%02x (for LCD=CRT1)\n",
3162 ivideo->detectedpdca);
3163 }
3164 }
3098 3165
3099 outSISIDXREG(SISSR, IND_SIS_TURBOQUEUE_ADR, (u8)(tqueue_pos & 0xff)); 3166 /* Save EMI */
3167 if(ivideo->vbflags2 & VB2_SISEMIBRIDGE) {
3168 inSISIDXREG(SISPART4,0x30,ivideo->SiS_Pr.EMI_30);
3169 inSISIDXREG(SISPART4,0x31,ivideo->SiS_Pr.EMI_31);
3170 inSISIDXREG(SISPART4,0x32,ivideo->SiS_Pr.EMI_32);
3171 inSISIDXREG(SISPART4,0x33,ivideo->SiS_Pr.EMI_33);
3172 ivideo->SiS_Pr.HaveEMI = TRUE;
3173 if((tmp & 0x20) || (ivideo->detectedlcda != 0xff)) {
3174 ivideo->SiS_Pr.HaveEMILCD = TRUE;
3175 }
3176 }
3177 }
3100 3178
3101 ivideo->caps |= TURBO_QUEUE_CAP; 3179 /* Let user override detected PDCs (all bridges) */
3102 } 3180 if(ivideo->vbflags2 & VB2_30xBLV) {
3181 if((ivideo->SiS_Pr.PDC != -1) &&
3182 (ivideo->SiS_Pr.PDC != ivideo->detectedpdc)) {
3183 printk(KERN_INFO "sisfb: Using LCD PDC 0x%02x (for LCD=CRT2)\n",
3184 ivideo->SiS_Pr.PDC);
3185 }
3186 if((ivideo->SiS_Pr.PDCA != -1) &&
3187 (ivideo->SiS_Pr.PDCA != ivideo->detectedpdca)) {
3188 printk(KERN_INFO "sisfb: Using LCD PDC1 0x%02x (for LCD=CRT1)\n",
3189 ivideo->SiS_Pr.PDCA);
3190 }
3191 }
3192
3193 }
3103#endif 3194#endif
3195}
3104 3196
3105 /* Reserve memory for the HWCursor */ 3197/* -------------------- Memory manager routines ---------------------- */
3106 ivideo->sisfb_heap_end -= ivideo->hwcursor_size;
3107 ivideo->hwcursor_vbase = ivideo->sisfb_heap_end;
3108 ivideo->caps |= HW_CURSOR_CAP;
3109 3198
3110 ivideo->sisfb_heap_size = ivideo->sisfb_heap_end - ivideo->sisfb_heap_start; 3199static u32 __devinit
3200sisfb_getheapstart(struct sis_video_info *ivideo)
3201{
3202 u32 ret = ivideo->sisfb_parm_mem * 1024;
3203 u32 maxoffs = ivideo->video_size - ivideo->hwcursor_size - ivideo->cmdQueueSize;
3204 u32 def;
3111 3205
3112 if(ivideo->cardnumber == 0) { 3206 /* Calculate heap start = end of memory for console
3207 *
3208 * CCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDHHHHQQQQQQQQQQ
3209 * C = console, D = heap, H = HWCursor, Q = cmd-queue
3210 *
3211 * On 76x in UMA+LFB mode, the layout is as follows:
3212 * DDDDDDDDDDDCCCCCCCCCCCCCCCCCCCCCCCCHHHHQQQQQQQQQQQ
3213 * where the heap is the entire UMA area, eventually
3214 * into the LFB area if the given mem parameter is
3215 * higher than the size of the UMA memory.
3216 *
3217 * Basically given by "mem" parameter
3218 *
3219 * maximum = videosize - cmd_queue - hwcursor
3220 * (results in a heap of size 0)
3221 * default = SiS 300: depends on videosize
3222 * SiS 315/330/340/XGI: 32k below max
3223 */
3113 3224
3114 printk(KERN_INFO "sisfb: Memory heap starting at %dK, size %dK\n", 3225 if(ivideo->sisvga_engine == SIS_300_VGA) {
3115 (int)(ivideo->heapstart / 1024), (int)(ivideo->sisfb_heap_size / 1024)); 3226 if(ivideo->video_size > 0x1000000) {
3227 def = 0xc00000;
3228 } else if(ivideo->video_size > 0x800000) {
3229 def = 0x800000;
3230 } else {
3231 def = 0x400000;
3232 }
3233 } else if(ivideo->UMAsize && ivideo->LFBsize) {
3234 ret = def = 0;
3235 } else {
3236 def = maxoffs - 0x8000;
3237 }
3116 3238
3117 sisfb_heap.vinfo = ivideo; 3239 /* Use default for secondary card for now (FIXME) */
3240 if((!ret) || (ret > maxoffs) || (ivideo->cardnumber != 0))
3241 ret = def;
3118 3242
3119 sisfb_heap.poha_chain = NULL; 3243 return ret;
3120 sisfb_heap.poh_freelist = NULL; 3244}
3121 3245
3122 poh = sisfb_poh_new_node(); 3246static u32 __devinit
3123 if(poh == NULL) return 1; 3247sisfb_getheapsize(struct sis_video_info *ivideo)
3248{
3249 u32 max = ivideo->video_size - ivideo->hwcursor_size - ivideo->cmdQueueSize;
3250 u32 ret = 0;
3251
3252 if(ivideo->UMAsize && ivideo->LFBsize) {
3253 if( (!ivideo->sisfb_parm_mem) ||
3254 ((ivideo->sisfb_parm_mem * 1024) > max) ||
3255 ((max - (ivideo->sisfb_parm_mem * 1024)) < ivideo->UMAsize) ) {
3256 ret = ivideo->UMAsize;
3257 max -= ivideo->UMAsize;
3258 } else {
3259 ret = max - (ivideo->sisfb_parm_mem * 1024);
3260 max = ivideo->sisfb_parm_mem * 1024;
3261 }
3262 ivideo->video_offset = ret;
3263 ivideo->sisfb_mem = max;
3264 } else {
3265 ret = max - ivideo->heapstart;
3266 ivideo->sisfb_mem = ivideo->heapstart;
3267 }
3124 3268
3125 poh->poh_next = &sisfb_heap.oh_free; 3269 return ret;
3126 poh->poh_prev = &sisfb_heap.oh_free; 3270}
3127 poh->size = ivideo->sisfb_heap_size;
3128 poh->offset = ivideo->heapstart;
3129 3271
3130 sisfb_heap.oh_free.poh_next = poh; 3272static int __devinit
3131 sisfb_heap.oh_free.poh_prev = poh; 3273sisfb_heap_init(struct sis_video_info *ivideo)
3132 sisfb_heap.oh_free.size = 0; 3274{
3133 sisfb_heap.max_freesize = poh->size; 3275 struct SIS_OH *poh;
3134 3276
3135 sisfb_heap.oh_used.poh_next = &sisfb_heap.oh_used; 3277 ivideo->video_offset = 0;
3136 sisfb_heap.oh_used.poh_prev = &sisfb_heap.oh_used; 3278 if(ivideo->sisfb_parm_mem) {
3137 sisfb_heap.oh_used.size = SENTINEL; 3279 if( (ivideo->sisfb_parm_mem < (2 * 1024 * 1024)) ||
3280 (ivideo->sisfb_parm_mem > ivideo->video_size) ) {
3281 ivideo->sisfb_parm_mem = 0;
3282 }
3283 }
3138 3284
3139 } else { 3285 ivideo->heapstart = sisfb_getheapstart(ivideo);
3286 ivideo->sisfb_heap_size = sisfb_getheapsize(ivideo);
3140 3287
3141 printk(KERN_INFO "Skipped heap initialization for secondary cards\n"); 3288 ivideo->sisfb_heap_start = ivideo->video_vbase + ivideo->heapstart;
3289 ivideo->sisfb_heap_end = ivideo->sisfb_heap_start + ivideo->sisfb_heap_size;
3142 3290
3143 } 3291 printk(KERN_INFO "sisfb: Memory heap starting at %dK, size %dK\n",
3292 (int)(ivideo->heapstart / 1024), (int)(ivideo->sisfb_heap_size / 1024));
3144 3293
3145 return 0; 3294 ivideo->sisfb_heap.vinfo = ivideo;
3295
3296 ivideo->sisfb_heap.poha_chain = NULL;
3297 ivideo->sisfb_heap.poh_freelist = NULL;
3298
3299 poh = sisfb_poh_new_node(&ivideo->sisfb_heap);
3300 if(poh == NULL)
3301 return 1;
3302
3303 poh->poh_next = &ivideo->sisfb_heap.oh_free;
3304 poh->poh_prev = &ivideo->sisfb_heap.oh_free;
3305 poh->size = ivideo->sisfb_heap_size;
3306 poh->offset = ivideo->heapstart;
3307
3308 ivideo->sisfb_heap.oh_free.poh_next = poh;
3309 ivideo->sisfb_heap.oh_free.poh_prev = poh;
3310 ivideo->sisfb_heap.oh_free.size = 0;
3311 ivideo->sisfb_heap.max_freesize = poh->size;
3312
3313 ivideo->sisfb_heap.oh_used.poh_next = &ivideo->sisfb_heap.oh_used;
3314 ivideo->sisfb_heap.oh_used.poh_prev = &ivideo->sisfb_heap.oh_used;
3315 ivideo->sisfb_heap.oh_used.size = SENTINEL;
3316
3317 if(ivideo->cardnumber == 0) {
3318 /* For the first card, make this heap the "global" one
3319 * for old DRM (which could handle only one card)
3320 */
3321 sisfb_heap = &ivideo->sisfb_heap;
3322 }
3323
3324 return 0;
3146} 3325}
3147 3326
3148static SIS_OH * 3327static struct SIS_OH *
3149sisfb_poh_new_node(void) 3328sisfb_poh_new_node(struct SIS_HEAP *memheap)
3150{ 3329{
3151 int i; 3330 struct SIS_OHALLOC *poha;
3152 unsigned long cOhs; 3331 struct SIS_OH *poh;
3153 SIS_OHALLOC *poha; 3332 unsigned long cOhs;
3154 SIS_OH *poh; 3333 int i;
3155 3334
3156 if(sisfb_heap.poh_freelist == NULL) { 3335 if(memheap->poh_freelist == NULL) {
3157 poha = kmalloc(SIS_OH_ALLOC_SIZE, GFP_KERNEL); 3336 poha = kmalloc(SIS_OH_ALLOC_SIZE, GFP_KERNEL);
3158 if(!poha) return NULL; 3337 if(!poha)
3338 return NULL;
3159 3339
3160 poha->poha_next = sisfb_heap.poha_chain; 3340 poha->poha_next = memheap->poha_chain;
3161 sisfb_heap.poha_chain = poha; 3341 memheap->poha_chain = poha;
3162 3342
3163 cOhs = (SIS_OH_ALLOC_SIZE - sizeof(SIS_OHALLOC)) / sizeof(SIS_OH) + 1; 3343 cOhs = (SIS_OH_ALLOC_SIZE - sizeof(struct SIS_OHALLOC)) / sizeof(struct SIS_OH) + 1;
3164 3344
3165 poh = &poha->aoh[0]; 3345 poh = &poha->aoh[0];
3166 for(i = cOhs - 1; i != 0; i--) { 3346 for(i = cOhs - 1; i != 0; i--) {
@@ -3169,32 +3349,32 @@ sisfb_poh_new_node(void)
3169 } 3349 }
3170 3350
3171 poh->poh_next = NULL; 3351 poh->poh_next = NULL;
3172 sisfb_heap.poh_freelist = &poha->aoh[0]; 3352 memheap->poh_freelist = &poha->aoh[0];
3173 } 3353 }
3174 3354
3175 poh = sisfb_heap.poh_freelist; 3355 poh = memheap->poh_freelist;
3176 sisfb_heap.poh_freelist = poh->poh_next; 3356 memheap->poh_freelist = poh->poh_next;
3177 3357
3178 return (poh); 3358 return poh;
3179} 3359}
3180 3360
3181static SIS_OH * 3361static struct SIS_OH *
3182sisfb_poh_allocate(u32 size) 3362sisfb_poh_allocate(struct SIS_HEAP *memheap, u32 size)
3183{ 3363{
3184 SIS_OH *pohThis; 3364 struct SIS_OH *pohThis;
3185 SIS_OH *pohRoot; 3365 struct SIS_OH *pohRoot;
3186 int bAllocated = 0; 3366 int bAllocated = 0;
3187 3367
3188 if(size > sisfb_heap.max_freesize) { 3368 if(size > memheap->max_freesize) {
3189 DPRINTK("sisfb: Can't allocate %dk video memory\n", 3369 DPRINTK("sisfb: Can't allocate %dk video memory\n",
3190 (unsigned int) size / 1024); 3370 (unsigned int) size / 1024);
3191 return (NULL); 3371 return NULL;
3192 } 3372 }
3193 3373
3194 pohThis = sisfb_heap.oh_free.poh_next; 3374 pohThis = memheap->oh_free.poh_next;
3195 3375
3196 while(pohThis != &sisfb_heap.oh_free) { 3376 while(pohThis != &memheap->oh_free) {
3197 if (size <= pohThis->size) { 3377 if(size <= pohThis->size) {
3198 bAllocated = 1; 3378 bAllocated = 1;
3199 break; 3379 break;
3200 } 3380 }
@@ -3204,18 +3384,16 @@ sisfb_poh_allocate(u32 size)
3204 if(!bAllocated) { 3384 if(!bAllocated) {
3205 DPRINTK("sisfb: Can't allocate %dk video memory\n", 3385 DPRINTK("sisfb: Can't allocate %dk video memory\n",
3206 (unsigned int) size / 1024); 3386 (unsigned int) size / 1024);
3207 return (NULL); 3387 return NULL;
3208 } 3388 }
3209 3389
3210 if(size == pohThis->size) { 3390 if(size == pohThis->size) {
3211 pohRoot = pohThis; 3391 pohRoot = pohThis;
3212 sisfb_delete_node(pohThis); 3392 sisfb_delete_node(pohThis);
3213 } else { 3393 } else {
3214 pohRoot = sisfb_poh_new_node(); 3394 pohRoot = sisfb_poh_new_node(memheap);
3215 3395 if(pohRoot == NULL)
3216 if(pohRoot == NULL) { 3396 return NULL;
3217 return (NULL);
3218 }
3219 3397
3220 pohRoot->offset = pohThis->offset; 3398 pohRoot->offset = pohThis->offset;
3221 pohRoot->size = size; 3399 pohRoot->size = size;
@@ -3224,33 +3402,25 @@ sisfb_poh_allocate(u32 size)
3224 pohThis->size -= size; 3402 pohThis->size -= size;
3225 } 3403 }
3226 3404
3227 sisfb_heap.max_freesize -= size; 3405 memheap->max_freesize -= size;
3228 3406
3229 pohThis = &sisfb_heap.oh_used; 3407 pohThis = &memheap->oh_used;
3230 sisfb_insert_node(pohThis, pohRoot); 3408 sisfb_insert_node(pohThis, pohRoot);
3231 3409
3232 return (pohRoot); 3410 return pohRoot;
3233} 3411}
3234 3412
3235static void 3413static void
3236sisfb_delete_node(SIS_OH *poh) 3414sisfb_delete_node(struct SIS_OH *poh)
3237{ 3415{
3238 SIS_OH *poh_prev; 3416 poh->poh_prev->poh_next = poh->poh_next;
3239 SIS_OH *poh_next; 3417 poh->poh_next->poh_prev = poh->poh_prev;
3240
3241 poh_prev = poh->poh_prev;
3242 poh_next = poh->poh_next;
3243
3244 poh_prev->poh_next = poh_next;
3245 poh_next->poh_prev = poh_prev;
3246} 3418}
3247 3419
3248static void 3420static void
3249sisfb_insert_node(SIS_OH *pohList, SIS_OH *poh) 3421sisfb_insert_node(struct SIS_OH *pohList, struct SIS_OH *poh)
3250{ 3422{
3251 SIS_OH *pohTemp; 3423 struct SIS_OH *pohTemp = pohList->poh_next;
3252
3253 pohTemp = pohList->poh_next;
3254 3424
3255 pohList->poh_next = poh; 3425 pohList->poh_next = poh;
3256 pohTemp->poh_prev = poh; 3426 pohTemp->poh_prev = poh;
@@ -3259,20 +3429,20 @@ sisfb_insert_node(SIS_OH *pohList, SIS_OH *poh)
3259 poh->poh_next = pohTemp; 3429 poh->poh_next = pohTemp;
3260} 3430}
3261 3431
3262static SIS_OH * 3432static struct SIS_OH *
3263sisfb_poh_free(u32 base) 3433sisfb_poh_free(struct SIS_HEAP *memheap, u32 base)
3264{ 3434{
3265 SIS_OH *pohThis; 3435 struct SIS_OH *pohThis;
3266 SIS_OH *poh_freed; 3436 struct SIS_OH *poh_freed;
3267 SIS_OH *poh_prev; 3437 struct SIS_OH *poh_prev;
3268 SIS_OH *poh_next; 3438 struct SIS_OH *poh_next;
3269 u32 ulUpper; 3439 u32 ulUpper;
3270 u32 ulLower; 3440 u32 ulLower;
3271 int foundNode = 0; 3441 int foundNode = 0;
3272 3442
3273 poh_freed = sisfb_heap.oh_used.poh_next; 3443 poh_freed = memheap->oh_used.poh_next;
3274 3444
3275 while(poh_freed != &sisfb_heap.oh_used) { 3445 while(poh_freed != &memheap->oh_used) {
3276 if(poh_freed->offset == base) { 3446 if(poh_freed->offset == base) {
3277 foundNode = 1; 3447 foundNode = 1;
3278 break; 3448 break;
@@ -3281,17 +3451,18 @@ sisfb_poh_free(u32 base)
3281 poh_freed = poh_freed->poh_next; 3451 poh_freed = poh_freed->poh_next;
3282 } 3452 }
3283 3453
3284 if(!foundNode) return(NULL); 3454 if(!foundNode)
3455 return NULL;
3285 3456
3286 sisfb_heap.max_freesize += poh_freed->size; 3457 memheap->max_freesize += poh_freed->size;
3287 3458
3288 poh_prev = poh_next = NULL; 3459 poh_prev = poh_next = NULL;
3289 ulUpper = poh_freed->offset + poh_freed->size; 3460 ulUpper = poh_freed->offset + poh_freed->size;
3290 ulLower = poh_freed->offset; 3461 ulLower = poh_freed->offset;
3291 3462
3292 pohThis = sisfb_heap.oh_free.poh_next; 3463 pohThis = memheap->oh_free.poh_next;
3293 3464
3294 while(pohThis != &sisfb_heap.oh_free) { 3465 while(pohThis != &memheap->oh_free) {
3295 if(pohThis->offset == ulUpper) { 3466 if(pohThis->offset == ulUpper) {
3296 poh_next = pohThis; 3467 poh_next = pohThis;
3297 } else if((pohThis->offset + pohThis->size) == ulLower) { 3468 } else if((pohThis->offset + pohThis->size) == ulLower) {
@@ -3305,70 +3476,88 @@ sisfb_poh_free(u32 base)
3305 if(poh_prev && poh_next) { 3476 if(poh_prev && poh_next) {
3306 poh_prev->size += (poh_freed->size + poh_next->size); 3477 poh_prev->size += (poh_freed->size + poh_next->size);
3307 sisfb_delete_node(poh_next); 3478 sisfb_delete_node(poh_next);
3308 sisfb_free_node(poh_freed); 3479 sisfb_free_node(memheap, poh_freed);
3309 sisfb_free_node(poh_next); 3480 sisfb_free_node(memheap, poh_next);
3310 return(poh_prev); 3481 return poh_prev;
3311 } 3482 }
3312 3483
3313 if(poh_prev) { 3484 if(poh_prev) {
3314 poh_prev->size += poh_freed->size; 3485 poh_prev->size += poh_freed->size;
3315 sisfb_free_node(poh_freed); 3486 sisfb_free_node(memheap, poh_freed);
3316 return(poh_prev); 3487 return poh_prev;
3317 } 3488 }
3318 3489
3319 if(poh_next) { 3490 if(poh_next) {
3320 poh_next->size += poh_freed->size; 3491 poh_next->size += poh_freed->size;
3321 poh_next->offset = poh_freed->offset; 3492 poh_next->offset = poh_freed->offset;
3322 sisfb_free_node(poh_freed); 3493 sisfb_free_node(memheap, poh_freed);
3323 return(poh_next); 3494 return poh_next;
3324 } 3495 }
3325 3496
3326 sisfb_insert_node(&sisfb_heap.oh_free, poh_freed); 3497 sisfb_insert_node(&memheap->oh_free, poh_freed);
3327 3498
3328 return(poh_freed); 3499 return poh_freed;
3329} 3500}
3330 3501
3331static void 3502static void
3332sisfb_free_node(SIS_OH *poh) 3503sisfb_free_node(struct SIS_HEAP *memheap, struct SIS_OH *poh)
3333{ 3504{
3334 if(poh == NULL) return; 3505 if(poh == NULL)
3506 return;
3335 3507
3336 poh->poh_next = sisfb_heap.poh_freelist; 3508 poh->poh_next = memheap->poh_freelist;
3337 sisfb_heap.poh_freelist = poh; 3509 memheap->poh_freelist = poh;
3338} 3510}
3339 3511
3340void 3512static void
3341sis_malloc(struct sis_memreq *req) 3513sis_int_malloc(struct sis_video_info *ivideo, struct sis_memreq *req)
3342{ 3514{
3343 struct sis_video_info *ivideo = sisfb_heap.vinfo; 3515 struct SIS_OH *poh = NULL;
3344 SIS_OH *poh = NULL;
3345 3516
3346 if((ivideo) && (!ivideo->havenoheap)) { 3517 if((ivideo) && (ivideo->sisfb_id == SISFB_ID) && (!ivideo->havenoheap))
3347 poh = sisfb_poh_allocate((u32)req->size); 3518 poh = sisfb_poh_allocate(&ivideo->sisfb_heap, (u32)req->size);
3348 }
3349 3519
3350 if(poh == NULL) { 3520 if(poh == NULL) {
3351 req->offset = req->size = 0; 3521 req->offset = req->size = 0;
3352 DPRINTK("sisfb: Video RAM allocation failed\n"); 3522 DPRINTK("sisfb: Video RAM allocation failed\n");
3353 } else { 3523 } else {
3354 req->offset = poh->offset; 3524 req->offset = poh->offset;
3355 req->size = poh->size; 3525 req->size = poh->size;
3356 DPRINTK("sisfb: Video RAM allocation succeeded: 0x%lx\n", 3526 DPRINTK("sisfb: Video RAM allocation succeeded: 0x%lx\n",
3357 (poh->offset + ivideo->video_vbase)); 3527 (poh->offset + ivideo->video_vbase));
3358 } 3528 }
3359} 3529}
3360 3530
3361/* sis_free: u32 because "base" is offset inside video ram, can never be >4GB */ 3531void
3532sis_malloc(struct sis_memreq *req)
3533{
3534 struct sis_video_info *ivideo = sisfb_heap->vinfo;
3535
3536 if(&ivideo->sisfb_heap == sisfb_heap)
3537 sis_int_malloc(ivideo, req);
3538 else
3539 req->offset = req->size = 0;
3540}
3362 3541
3363void 3542void
3364sis_free(u32 base) 3543sis_malloc_new(struct pci_dev *pdev, struct sis_memreq *req)
3365{ 3544{
3366 struct sis_video_info *ivideo = sisfb_heap.vinfo; 3545 struct sis_video_info *ivideo = pci_get_drvdata(pdev);
3367 SIS_OH *poh; 3546
3547 sis_int_malloc(ivideo, req);
3548}
3549
3550/* sis_free: u32 because "base" is offset inside video ram, can never be >4GB */
3368 3551
3369 if((!ivideo) || (ivideo->havenoheap)) return; 3552static void
3553sis_int_free(struct sis_video_info *ivideo, u32 base)
3554{
3555 struct SIS_OH *poh;
3370 3556
3371 poh = sisfb_poh_free((u32)base); 3557 if((!ivideo) || (ivideo->sisfb_id != SISFB_ID) || (ivideo->havenoheap))
3558 return;
3559
3560 poh = sisfb_poh_free(&ivideo->sisfb_heap, base);
3372 3561
3373 if(poh == NULL) { 3562 if(poh == NULL) {
3374 DPRINTK("sisfb: sisfb_poh_free() failed at base 0x%x\n", 3563 DPRINTK("sisfb: sisfb_poh_free() failed at base 0x%x\n",
@@ -3376,9 +3565,63 @@ sis_free(u32 base)
3376 } 3565 }
3377} 3566}
3378 3567
3568void
3569sis_free(u32 base)
3570{
3571 struct sis_video_info *ivideo = sisfb_heap->vinfo;
3572
3573 sis_int_free(ivideo, base);
3574}
3575
3576void
3577sis_free_new(struct pci_dev *pdev, u32 base)
3578{
3579 struct sis_video_info *ivideo = pci_get_drvdata(pdev);
3580
3581 sis_int_free(ivideo, base);
3582}
3583
3379/* --------------------- SetMode routines ------------------------- */ 3584/* --------------------- SetMode routines ------------------------- */
3380 3585
3381static void 3586static void
3587sisfb_check_engine_and_sync(struct sis_video_info *ivideo)
3588{
3589 u8 cr30, cr31;
3590
3591 /* Check if MMIO and engines are enabled,
3592 * and sync in case they are. Can't use
3593 * ivideo->accel here, as this might have
3594 * been changed before this is called.
3595 */
3596 inSISIDXREG(SISSR, IND_SIS_PCI_ADDRESS_SET, cr30);
3597 inSISIDXREG(SISSR, IND_SIS_MODULE_ENABLE, cr31);
3598 /* MMIO and 2D/3D engine enabled? */
3599 if((cr30 & SIS_MEM_MAP_IO_ENABLE) && (cr31 & 0x42)) {
3600#ifdef CONFIG_FB_SIS_300
3601 if(ivideo->sisvga_engine == SIS_300_VGA) {
3602 /* Don't care about TurboQueue. It's
3603 * enough to know that the engines
3604 * are enabled
3605 */
3606 sisfb_syncaccel(ivideo);
3607 }
3608#endif
3609#ifdef CONFIG_FB_SIS_315
3610 if(ivideo->sisvga_engine == SIS_315_VGA) {
3611 /* Check that any queue mode is
3612 * enabled, and that the queue
3613 * is not in the state of "reset"
3614 */
3615 inSISIDXREG(SISSR, 0x26, cr30);
3616 if((cr30 & 0xe0) && (!(cr30 & 0x01))) {
3617 sisfb_syncaccel(ivideo);
3618 }
3619 }
3620#endif
3621 }
3622}
3623
3624static void
3382sisfb_pre_setmode(struct sis_video_info *ivideo) 3625sisfb_pre_setmode(struct sis_video_info *ivideo)
3383{ 3626{
3384 u8 cr30 = 0, cr31 = 0, cr33 = 0, cr35 = 0, cr38 = 0; 3627 u8 cr30 = 0, cr31 = 0, cr33 = 0, cr35 = 0, cr38 = 0;
@@ -3386,6 +3629,8 @@ sisfb_pre_setmode(struct sis_video_info *ivideo)
3386 3629
3387 ivideo->currentvbflags &= (VB_VIDEOBRIDGE | VB_DISPTYPE_DISP2); 3630 ivideo->currentvbflags &= (VB_VIDEOBRIDGE | VB_DISPTYPE_DISP2);
3388 3631
3632 outSISIDXREG(SISSR, 0x05, 0x86);
3633
3389 inSISIDXREG(SISCR, 0x31, cr31); 3634 inSISIDXREG(SISCR, 0x31, cr31);
3390 cr31 &= ~0x60; 3635 cr31 &= ~0x60;
3391 cr31 |= 0x04; 3636 cr31 |= 0x04;
@@ -3413,41 +3658,43 @@ sisfb_pre_setmode(struct sis_video_info *ivideo)
3413 3658
3414 SiS_SetEnableDstn(&ivideo->SiS_Pr, FALSE); 3659 SiS_SetEnableDstn(&ivideo->SiS_Pr, FALSE);
3415 SiS_SetEnableFstn(&ivideo->SiS_Pr, FALSE); 3660 SiS_SetEnableFstn(&ivideo->SiS_Pr, FALSE);
3661 ivideo->curFSTN = ivideo->curDSTN = 0;
3416 3662
3417 switch(ivideo->currentvbflags & VB_DISPTYPE_DISP2) { 3663 switch(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
3418 3664
3419 case CRT2_TV: 3665 case CRT2_TV:
3420 cr38 &= ~0xc0; /* Clear PAL-M / PAL-N bits */ 3666 cr38 &= ~0xc0; /* Clear PAL-M / PAL-N bits */
3421 if((ivideo->vbflags & TV_YPBPR) && (ivideo->vbflags & (VB_301C|VB_301LV|VB_302LV))) { 3667 if((ivideo->vbflags & TV_YPBPR) && (ivideo->vbflags2 & VB2_SISYPBPRBRIDGE)) {
3422#ifdef CONFIG_FB_SIS_315 3668#ifdef CONFIG_FB_SIS_315
3423 if(ivideo->chip >= SIS_661) { 3669 if(ivideo->chip >= SIS_661) {
3424 cr38 |= 0x04; 3670 cr38 |= 0x04;
3425 if(ivideo->vbflags & TV_YPBPR525P) cr35 |= 0x20; 3671 if(ivideo->vbflags & TV_YPBPR525P) cr35 |= 0x20;
3426 else if(ivideo->vbflags & TV_YPBPR750P) cr35 |= 0x40; 3672 else if(ivideo->vbflags & TV_YPBPR750P) cr35 |= 0x40;
3427 else if(ivideo->vbflags & TV_YPBPR1080I) cr35 |= 0x60; 3673 else if(ivideo->vbflags & TV_YPBPR1080I) cr35 |= 0x60;
3428 cr30 |= SIS_SIMULTANEOUS_VIEW_ENABLE; 3674 cr30 |= SIS_SIMULTANEOUS_VIEW_ENABLE;
3429 cr35 &= ~0x01; 3675 cr35 &= ~0x01;
3430 ivideo->currentvbflags |= (TV_YPBPR | (ivideo->vbflags & TV_YPBPRALL)); 3676 ivideo->currentvbflags |= (TV_YPBPR | (ivideo->vbflags & TV_YPBPRALL));
3431 } else if(ivideo->sisvga_engine == SIS_315_VGA) { 3677 } else if(ivideo->sisvga_engine == SIS_315_VGA) {
3432 cr30 |= (0x80 | SIS_SIMULTANEOUS_VIEW_ENABLE); 3678 cr30 |= (0x80 | SIS_SIMULTANEOUS_VIEW_ENABLE);
3433 cr38 |= 0x08; 3679 cr38 |= 0x08;
3434 if(ivideo->vbflags & TV_YPBPR525P) cr38 |= 0x10; 3680 if(ivideo->vbflags & TV_YPBPR525P) cr38 |= 0x10;
3435 else if(ivideo->vbflags & TV_YPBPR750P) cr38 |= 0x20; 3681 else if(ivideo->vbflags & TV_YPBPR750P) cr38 |= 0x20;
3436 else if(ivideo->vbflags & TV_YPBPR1080I) cr38 |= 0x30; 3682 else if(ivideo->vbflags & TV_YPBPR1080I) cr38 |= 0x30;
3437 cr31 &= ~0x01; 3683 cr31 &= ~0x01;
3438 ivideo->currentvbflags |= (TV_YPBPR | (ivideo->vbflags & TV_YPBPRALL)); 3684 ivideo->currentvbflags |= (TV_YPBPR | (ivideo->vbflags & TV_YPBPRALL));
3439 } 3685 }
3440#endif 3686#endif
3441 } else if((ivideo->vbflags & TV_HIVISION) && (ivideo->vbflags & (VB_301|VB_301B|VB_302B))) { 3687 } else if((ivideo->vbflags & TV_HIVISION) &&
3442 if(ivideo->chip >= SIS_661) { 3688 (ivideo->vbflags2 & VB2_SISHIVISIONBRIDGE)) {
3443 cr38 |= 0x04; 3689 if(ivideo->chip >= SIS_661) {
3444 cr35 |= 0x60; 3690 cr38 |= 0x04;
3445 } else { 3691 cr35 |= 0x60;
3446 cr30 |= 0x80; 3692 } else {
3447 } 3693 cr30 |= 0x80;
3694 }
3448 cr30 |= SIS_SIMULTANEOUS_VIEW_ENABLE; 3695 cr30 |= SIS_SIMULTANEOUS_VIEW_ENABLE;
3449 cr31 |= 0x01; 3696 cr31 |= 0x01;
3450 cr35 |= 0x01; 3697 cr35 |= 0x01;
3451 ivideo->currentvbflags |= TV_HIVISION; 3698 ivideo->currentvbflags |= TV_HIVISION;
3452 } else if(ivideo->vbflags & TV_SCART) { 3699 } else if(ivideo->vbflags & TV_SCART) {
3453 cr30 = (SIS_VB_OUTPUT_SCART | SIS_SIMULTANEOUS_VIEW_ENABLE); 3700 cr30 = (SIS_VB_OUTPUT_SCART | SIS_SIMULTANEOUS_VIEW_ENABLE);
@@ -3466,8 +3713,8 @@ sisfb_pre_setmode(struct sis_video_info *ivideo)
3466 } 3713 }
3467 cr31 |= SIS_DRIVER_MODE; 3714 cr31 |= SIS_DRIVER_MODE;
3468 3715
3469 if(ivideo->vbflags & (TV_AVIDEO|TV_SVIDEO)) { 3716 if(ivideo->vbflags & (TV_AVIDEO | TV_SVIDEO)) {
3470 if(ivideo->vbflags & TV_PAL) { 3717 if(ivideo->vbflags & TV_PAL) {
3471 cr31 |= 0x01; cr35 |= 0x01; 3718 cr31 |= 0x01; cr35 |= 0x01;
3472 ivideo->currentvbflags |= TV_PAL; 3719 ivideo->currentvbflags |= TV_PAL;
3473 if(ivideo->vbflags & TV_PALM) { 3720 if(ivideo->vbflags & TV_PALM) {
@@ -3476,14 +3723,14 @@ sisfb_pre_setmode(struct sis_video_info *ivideo)
3476 } else if(ivideo->vbflags & TV_PALN) { 3723 } else if(ivideo->vbflags & TV_PALN) {
3477 cr38 |= 0x80; cr35 |= 0x08; 3724 cr38 |= 0x80; cr35 |= 0x08;
3478 ivideo->currentvbflags |= TV_PALN; 3725 ivideo->currentvbflags |= TV_PALN;
3479 } 3726 }
3480 } else { 3727 } else {
3481 cr31 &= ~0x01; cr35 &= ~0x01; 3728 cr31 &= ~0x01; cr35 &= ~0x01;
3482 ivideo->currentvbflags |= TV_NTSC; 3729 ivideo->currentvbflags |= TV_NTSC;
3483 if(ivideo->vbflags & TV_NTSCJ) { 3730 if(ivideo->vbflags & TV_NTSCJ) {
3484 cr38 |= 0x40; cr35 |= 0x02; 3731 cr38 |= 0x40; cr35 |= 0x02;
3485 ivideo->currentvbflags |= TV_NTSCJ; 3732 ivideo->currentvbflags |= TV_NTSCJ;
3486 } 3733 }
3487 } 3734 }
3488 } 3735 }
3489 break; 3736 break;
@@ -3493,6 +3740,8 @@ sisfb_pre_setmode(struct sis_video_info *ivideo)
3493 cr31 |= SIS_DRIVER_MODE; 3740 cr31 |= SIS_DRIVER_MODE;
3494 SiS_SetEnableDstn(&ivideo->SiS_Pr, ivideo->sisfb_dstn); 3741 SiS_SetEnableDstn(&ivideo->SiS_Pr, ivideo->sisfb_dstn);
3495 SiS_SetEnableFstn(&ivideo->SiS_Pr, ivideo->sisfb_fstn); 3742 SiS_SetEnableFstn(&ivideo->SiS_Pr, ivideo->sisfb_fstn);
3743 ivideo->curFSTN = ivideo->sisfb_fstn;
3744 ivideo->curDSTN = ivideo->sisfb_dstn;
3496 break; 3745 break;
3497 3746
3498 case CRT2_VGA: 3747 case CRT2_VGA:
@@ -3525,9 +3774,9 @@ sisfb_pre_setmode(struct sis_video_info *ivideo)
3525 } 3774 }
3526 outSISIDXREG(SISCR, 0x31, cr31); 3775 outSISIDXREG(SISCR, 0x31, cr31);
3527 3776
3528 if(ivideo->accel) sisfb_syncaccel(ivideo);
3529
3530 ivideo->SiS_Pr.SiS_UseOEM = ivideo->sisfb_useoem; 3777 ivideo->SiS_Pr.SiS_UseOEM = ivideo->sisfb_useoem;
3778
3779 sisfb_check_engine_and_sync(ivideo);
3531} 3780}
3532 3781
3533/* Fix SR11 for 661 and later */ 3782/* Fix SR11 for 661 and later */
@@ -3535,125 +3784,129 @@ sisfb_pre_setmode(struct sis_video_info *ivideo)
3535static void 3784static void
3536sisfb_fixup_SR11(struct sis_video_info *ivideo) 3785sisfb_fixup_SR11(struct sis_video_info *ivideo)
3537{ 3786{
3538 u8 tmpreg; 3787 u8 tmpreg;
3539 3788
3540 if(ivideo->chip >= SIS_661) { 3789 if(ivideo->chip >= SIS_661) {
3541 inSISIDXREG(SISSR,0x11,tmpreg); 3790 inSISIDXREG(SISSR,0x11,tmpreg);
3542 if(tmpreg & 0x20) { 3791 if(tmpreg & 0x20) {
3543 inSISIDXREG(SISSR,0x3e,tmpreg); 3792 inSISIDXREG(SISSR,0x3e,tmpreg);
3544 tmpreg = (tmpreg + 1) & 0xff; 3793 tmpreg = (tmpreg + 1) & 0xff;
3545 outSISIDXREG(SISSR,0x3e,tmpreg); 3794 outSISIDXREG(SISSR,0x3e,tmpreg);
3546 inSISIDXREG(SISSR,0x11,tmpreg); 3795 inSISIDXREG(SISSR,0x11,tmpreg);
3547 } 3796 }
3548 if(tmpreg & 0xf0) { 3797 if(tmpreg & 0xf0) {
3549 andSISIDXREG(SISSR,0x11,0x0f); 3798 andSISIDXREG(SISSR,0x11,0x0f);
3550 } 3799 }
3551 } 3800 }
3552} 3801}
3553#endif 3802#endif
3554 3803
3555static void sisfb_set_TVxposoffset(struct sis_video_info *ivideo, int val) 3804static void
3805sisfb_set_TVxposoffset(struct sis_video_info *ivideo, int val)
3556{ 3806{
3557 if(val > 32) val = 32; 3807 if(val > 32) val = 32;
3558 if(val < -32) val = -32; 3808 if(val < -32) val = -32;
3559 ivideo->tvxpos = val; 3809 ivideo->tvxpos = val;
3560 3810
3561 if(ivideo->sisfblocked) return; 3811 if(ivideo->sisfblocked) return;
3562 if(!ivideo->modechanged) return; 3812 if(!ivideo->modechanged) return;
3563 3813
3564 if(ivideo->currentvbflags & CRT2_TV) { 3814 if(ivideo->currentvbflags & CRT2_TV) {
3565 3815
3566 if(ivideo->vbflags & VB_CHRONTEL) { 3816 if(ivideo->vbflags2 & VB2_CHRONTEL) {
3567 3817
3568 int x = ivideo->tvx; 3818 int x = ivideo->tvx;
3569 3819
3570 switch(ivideo->chronteltype) { 3820 switch(ivideo->chronteltype) {
3571 case 1: 3821 case 1:
3572 x += val; 3822 x += val;
3573 if(x < 0) x = 0; 3823 if(x < 0) x = 0;
3574 outSISIDXREG(SISSR,0x05,0x86); 3824 outSISIDXREG(SISSR,0x05,0x86);
3575 SiS_SetCH700x(&ivideo->SiS_Pr, (((x & 0xff) << 8) | 0x0a)); 3825 SiS_SetCH700x(&ivideo->SiS_Pr, 0x0a, (x & 0xff));
3576 SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, (((x & 0x0100) << 1) | 0x08),0xFD); 3826 SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x08, ((x & 0x0100) >> 7), 0xFD);
3577 break; 3827 break;
3578 case 2: 3828 case 2:
3579 /* Not supported by hardware */ 3829 /* Not supported by hardware */
3580 break; 3830 break;
3581 } 3831 }
3582 3832
3583 } else if(ivideo->vbflags & VB_SISBRIDGE) { 3833 } else if(ivideo->vbflags2 & VB2_SISBRIDGE) {
3584 3834
3585 u8 p2_1f,p2_20,p2_2b,p2_42,p2_43; 3835 u8 p2_1f,p2_20,p2_2b,p2_42,p2_43;
3586 unsigned short temp; 3836 unsigned short temp;
3587 3837
3588 p2_1f = ivideo->p2_1f; 3838 p2_1f = ivideo->p2_1f;
3589 p2_20 = ivideo->p2_20; 3839 p2_20 = ivideo->p2_20;
3590 p2_2b = ivideo->p2_2b; 3840 p2_2b = ivideo->p2_2b;
3591 p2_42 = ivideo->p2_42; 3841 p2_42 = ivideo->p2_42;
3592 p2_43 = ivideo->p2_43; 3842 p2_43 = ivideo->p2_43;
3593 3843
3594 temp = p2_1f | ((p2_20 & 0xf0) << 4); 3844 temp = p2_1f | ((p2_20 & 0xf0) << 4);
3595 temp += (val * 2); 3845 temp += (val * 2);
3596 p2_1f = temp & 0xff; 3846 p2_1f = temp & 0xff;
3597 p2_20 = (temp & 0xf00) >> 4; 3847 p2_20 = (temp & 0xf00) >> 4;
3598 p2_2b = ((p2_2b & 0x0f) + (val * 2)) & 0x0f; 3848 p2_2b = ((p2_2b & 0x0f) + (val * 2)) & 0x0f;
3599 temp = p2_43 | ((p2_42 & 0xf0) << 4); 3849 temp = p2_43 | ((p2_42 & 0xf0) << 4);
3600 temp += (val * 2); 3850 temp += (val * 2);
3601 p2_43 = temp & 0xff; 3851 p2_43 = temp & 0xff;
3602 p2_42 = (temp & 0xf00) >> 4; 3852 p2_42 = (temp & 0xf00) >> 4;
3603 outSISIDXREG(SISPART2,0x1f,p2_1f); 3853 outSISIDXREG(SISPART2,0x1f,p2_1f);
3604 setSISIDXREG(SISPART2,0x20,0x0F,p2_20); 3854 setSISIDXREG(SISPART2,0x20,0x0F,p2_20);
3605 setSISIDXREG(SISPART2,0x2b,0xF0,p2_2b); 3855 setSISIDXREG(SISPART2,0x2b,0xF0,p2_2b);
3606 setSISIDXREG(SISPART2,0x42,0x0F,p2_42); 3856 setSISIDXREG(SISPART2,0x42,0x0F,p2_42);
3607 outSISIDXREG(SISPART2,0x43,p2_43); 3857 outSISIDXREG(SISPART2,0x43,p2_43);
3608 } 3858 }
3609 } 3859 }
3610} 3860}
3611 3861
3612static void sisfb_set_TVyposoffset(struct sis_video_info *ivideo, int val) 3862static void
3863sisfb_set_TVyposoffset(struct sis_video_info *ivideo, int val)
3613{ 3864{
3614 if(val > 32) val = 32; 3865 if(val > 32) val = 32;
3615 if(val < -32) val = -32; 3866 if(val < -32) val = -32;
3616 ivideo->tvypos = val; 3867 ivideo->tvypos = val;
3617 3868
3618 if(ivideo->sisfblocked) return; 3869 if(ivideo->sisfblocked) return;
3619 if(!ivideo->modechanged) return; 3870 if(!ivideo->modechanged) return;
3620 3871
3621 if(ivideo->currentvbflags & CRT2_TV) { 3872 if(ivideo->currentvbflags & CRT2_TV) {
3622 3873
3623 if(ivideo->vbflags & VB_CHRONTEL) { 3874 if(ivideo->vbflags2 & VB2_CHRONTEL) {
3624 3875
3625 int y = ivideo->tvy; 3876 int y = ivideo->tvy;
3626 3877
3627 switch(ivideo->chronteltype) { 3878 switch(ivideo->chronteltype) {
3628 case 1: 3879 case 1:
3629 y -= val; 3880 y -= val;
3630 if(y < 0) y = 0; 3881 if(y < 0) y = 0;
3631 outSISIDXREG(SISSR,0x05,0x86); 3882 outSISIDXREG(SISSR,0x05,0x86);
3632 SiS_SetCH700x(&ivideo->SiS_Pr, (((y & 0xff) << 8) | 0x0b)); 3883 SiS_SetCH700x(&ivideo->SiS_Pr, 0x0b, (y & 0xff));
3633 SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, ((y & 0x0100) | 0x08),0xFE); 3884 SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x08, ((y & 0x0100) >> 8), 0xFE);
3634 break; 3885 break;
3635 case 2: 3886 case 2:
3636 /* Not supported by hardware */ 3887 /* Not supported by hardware */
3637 break; 3888 break;
3638 } 3889 }
3639 3890
3640 } else if(ivideo->vbflags & VB_SISBRIDGE) { 3891 } else if(ivideo->vbflags2 & VB2_SISBRIDGE) {
3641 3892
3642 char p2_01, p2_02; 3893 char p2_01, p2_02;
3643 val /= 2; 3894 val /= 2;
3644 p2_01 = ivideo->p2_01; 3895 p2_01 = ivideo->p2_01;
3645 p2_02 = ivideo->p2_02; 3896 p2_02 = ivideo->p2_02;
3646 3897
3647 p2_01 += val; 3898 p2_01 += val;
3648 p2_02 += val; 3899 p2_02 += val;
3649 while((p2_01 <= 0) || (p2_02 <= 0)) { 3900 if(!(ivideo->currentvbflags & (TV_HIVISION | TV_YPBPR))) {
3650 p2_01 += 2; 3901 while((p2_01 <= 0) || (p2_02 <= 0)) {
3651 p2_02 += 2; 3902 p2_01 += 2;
3652 } 3903 p2_02 += 2;
3653 outSISIDXREG(SISPART2,0x01,p2_01); 3904 }
3654 outSISIDXREG(SISPART2,0x02,p2_02); 3905 }
3655 } 3906 outSISIDXREG(SISPART2,0x01,p2_01);
3656 } 3907 outSISIDXREG(SISPART2,0x02,p2_02);
3908 }
3909 }
3657} 3910}
3658 3911
3659static void 3912static void
@@ -3668,207 +3921,172 @@ sisfb_post_setmode(struct sis_video_info *ivideo)
3668 u8 reg1; 3921 u8 reg1;
3669#endif 3922#endif
3670 3923
3671 outSISIDXREG(SISSR,0x05,0x86); 3924 outSISIDXREG(SISSR, 0x05, 0x86);
3672 3925
3673#ifdef CONFIG_FB_SIS_315 3926#ifdef CONFIG_FB_SIS_315
3674 sisfb_fixup_SR11(ivideo); 3927 sisfb_fixup_SR11(ivideo);
3675#endif 3928#endif
3676 3929
3677 /* Now we actually HAVE changed the display mode */ 3930 /* Now we actually HAVE changed the display mode */
3678 ivideo->modechanged = 1; 3931 ivideo->modechanged = 1;
3679 3932
3680 /* We can't switch off CRT1 if bridge is in slave mode */ 3933 /* We can't switch off CRT1 if bridge is in slave mode */
3681 if(ivideo->vbflags & VB_VIDEOBRIDGE) { 3934 if(ivideo->vbflags2 & VB2_VIDEOBRIDGE) {
3682 if(sisfb_bridgeisslave(ivideo)) doit = FALSE; 3935 if(sisfb_bridgeisslave(ivideo)) doit = FALSE;
3683 } else ivideo->sisfb_crt1off = 0; 3936 } else
3937 ivideo->sisfb_crt1off = 0;
3684 3938
3685#ifdef CONFIG_FB_SIS_300 3939#ifdef CONFIG_FB_SIS_300
3686 if(ivideo->sisvga_engine == SIS_300_VGA) { 3940 if(ivideo->sisvga_engine == SIS_300_VGA) {
3687 if((ivideo->sisfb_crt1off) && (doit)) { 3941 if((ivideo->sisfb_crt1off) && (doit)) {
3688 crt1isoff = TRUE; 3942 crt1isoff = TRUE;
3689 reg = 0x00; 3943 reg = 0x00;
3690 } else { 3944 } else {
3691 crt1isoff = FALSE; 3945 crt1isoff = FALSE;
3692 reg = 0x80; 3946 reg = 0x80;
3693 } 3947 }
3694 setSISIDXREG(SISCR, 0x17, 0x7f, reg); 3948 setSISIDXREG(SISCR, 0x17, 0x7f, reg);
3695 } 3949 }
3696#endif 3950#endif
3697#ifdef CONFIG_FB_SIS_315 3951#ifdef CONFIG_FB_SIS_315
3698 if(ivideo->sisvga_engine == SIS_315_VGA) { 3952 if(ivideo->sisvga_engine == SIS_315_VGA) {
3699 if((ivideo->sisfb_crt1off) && (doit)) { 3953 if((ivideo->sisfb_crt1off) && (doit)) {
3700 crt1isoff = TRUE; 3954 crt1isoff = TRUE;
3701 reg = 0x40; 3955 reg = 0x40;
3702 reg1 = 0xc0; 3956 reg1 = 0xc0;
3703 } else { 3957 } else {
3704 crt1isoff = FALSE; 3958 crt1isoff = FALSE;
3705 reg = 0x00; 3959 reg = 0x00;
3706 reg1 = 0x00; 3960 reg1 = 0x00;
3707 3961 }
3708 } 3962 setSISIDXREG(SISCR, ivideo->SiS_Pr.SiS_MyCR63, ~0x40, reg);
3709 setSISIDXREG(SISCR, ivideo->SiS_Pr.SiS_MyCR63, ~0x40, reg); 3963 setSISIDXREG(SISSR, 0x1f, ~0xc0, reg1);
3710 setSISIDXREG(SISSR, 0x1f, ~0xc0, reg1);
3711 } 3964 }
3712#endif 3965#endif
3713 3966
3714 if(crt1isoff) { 3967 if(crt1isoff) {
3715 ivideo->currentvbflags &= ~VB_DISPTYPE_CRT1; 3968 ivideo->currentvbflags &= ~VB_DISPTYPE_CRT1;
3716 ivideo->currentvbflags |= VB_SINGLE_MODE; 3969 ivideo->currentvbflags |= VB_SINGLE_MODE;
3717 } else { 3970 } else {
3718 ivideo->currentvbflags |= VB_DISPTYPE_CRT1; 3971 ivideo->currentvbflags |= VB_DISPTYPE_CRT1;
3719 if(ivideo->currentvbflags & VB_DISPTYPE_CRT2) { 3972 if(ivideo->currentvbflags & VB_DISPTYPE_CRT2) {
3720 ivideo->currentvbflags |= VB_MIRROR_MODE; 3973 ivideo->currentvbflags |= VB_MIRROR_MODE;
3721 } else { 3974 } else {
3722 ivideo->currentvbflags |= VB_SINGLE_MODE; 3975 ivideo->currentvbflags |= VB_SINGLE_MODE;
3723 } 3976 }
3724 } 3977 }
3725 3978
3726 andSISIDXREG(SISSR, IND_SIS_RAMDAC_CONTROL, ~0x04); 3979 andSISIDXREG(SISSR, IND_SIS_RAMDAC_CONTROL, ~0x04);
3727 3980
3728 if(ivideo->currentvbflags & CRT2_TV) { 3981 if(ivideo->currentvbflags & CRT2_TV) {
3729 if(ivideo->vbflags & VB_SISBRIDGE) { 3982 if(ivideo->vbflags2 & VB2_SISBRIDGE) {
3730 inSISIDXREG(SISPART2,0x1f,ivideo->p2_1f); 3983 inSISIDXREG(SISPART2,0x1f,ivideo->p2_1f);
3731 inSISIDXREG(SISPART2,0x20,ivideo->p2_20); 3984 inSISIDXREG(SISPART2,0x20,ivideo->p2_20);
3732 inSISIDXREG(SISPART2,0x2b,ivideo->p2_2b); 3985 inSISIDXREG(SISPART2,0x2b,ivideo->p2_2b);
3733 inSISIDXREG(SISPART2,0x42,ivideo->p2_42); 3986 inSISIDXREG(SISPART2,0x42,ivideo->p2_42);
3734 inSISIDXREG(SISPART2,0x43,ivideo->p2_43); 3987 inSISIDXREG(SISPART2,0x43,ivideo->p2_43);
3735 inSISIDXREG(SISPART2,0x01,ivideo->p2_01); 3988 inSISIDXREG(SISPART2,0x01,ivideo->p2_01);
3736 inSISIDXREG(SISPART2,0x02,ivideo->p2_02); 3989 inSISIDXREG(SISPART2,0x02,ivideo->p2_02);
3737 } else if(ivideo->vbflags & VB_CHRONTEL) { 3990 } else if(ivideo->vbflags2 & VB2_CHRONTEL) {
3738 if(ivideo->chronteltype == 1) { 3991 if(ivideo->chronteltype == 1) {
3739 ivideo->tvx = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0a); 3992 ivideo->tvx = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0a);
3740 ivideo->tvx |= (((SiS_GetCH700x(&ivideo->SiS_Pr, 0x08) & 0x02) >> 1) << 8); 3993 ivideo->tvx |= (((SiS_GetCH700x(&ivideo->SiS_Pr, 0x08) & 0x02) >> 1) << 8);
3741 ivideo->tvy = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0b); 3994 ivideo->tvy = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0b);
3742 ivideo->tvy |= ((SiS_GetCH700x(&ivideo->SiS_Pr, 0x08) & 0x01) << 8); 3995 ivideo->tvy |= ((SiS_GetCH700x(&ivideo->SiS_Pr, 0x08) & 0x01) << 8);
3743 } 3996 }
3744 } 3997 }
3745 } 3998 }
3746 3999
3747 if(ivideo->tvxpos) { 4000 if(ivideo->tvxpos) {
3748 sisfb_set_TVxposoffset(ivideo, ivideo->tvxpos); 4001 sisfb_set_TVxposoffset(ivideo, ivideo->tvxpos);
3749 } 4002 }
3750 if(ivideo->tvypos) { 4003 if(ivideo->tvypos) {
3751 sisfb_set_TVyposoffset(ivideo, ivideo->tvypos); 4004 sisfb_set_TVyposoffset(ivideo, ivideo->tvypos);
3752 } 4005 }
3753 4006
3754 if((ivideo->currentvbflags & CRT2_TV) && (ivideo->vbflags & VB_301)) { /* Set filter for SiS301 */ 4007 /* Eventually sync engines */
4008 sisfb_check_engine_and_sync(ivideo);
3755 4009
3756 unsigned char filter_tb = 0; 4010 /* (Re-)Initialize chip engines */
4011 if(ivideo->accel) {
4012 sisfb_engine_init(ivideo);
4013 } else {
4014 ivideo->engineok = 0;
4015 }
4016}
3757 4017
3758 switch (ivideo->video_width) { 4018static int
3759 case 320: 4019sisfb_reset_mode(struct sis_video_info *ivideo)
3760 filter_tb = (ivideo->vbflags & TV_NTSC) ? 4 : 12; 4020{
3761 break; 4021 if(sisfb_set_mode(ivideo, 0))
3762 case 640: 4022 return 1;
3763 filter_tb = (ivideo->vbflags & TV_NTSC) ? 5 : 13;
3764 break;
3765 case 720:
3766 filter_tb = (ivideo->vbflags & TV_NTSC) ? 6 : 14;
3767 break;
3768 case 400:
3769 case 800:
3770 filter_tb = (ivideo->vbflags & TV_NTSC) ? 7 : 15;
3771 break;
3772 default:
3773 ivideo->sisfb_filter = -1;
3774 break;
3775 }
3776 4023
3777 orSISIDXREG(SISPART1, ivideo->CRT2_write_enable, 0x01); 4024 sisfb_set_pitch(ivideo);
4025 sisfb_set_base_CRT1(ivideo, ivideo->current_base);
4026 sisfb_set_base_CRT2(ivideo, ivideo->current_base);
3778 4027
3779 if(ivideo->vbflags & TV_NTSC) { 4028 return 0;
3780 4029}
3781 andSISIDXREG(SISPART2, 0x3a, 0x1f); 4030
3782 4031static void
3783 if (ivideo->vbflags & TV_SVIDEO) { 4032sisfb_handle_command(struct sis_video_info *ivideo, struct sisfb_cmd *sisfb_command)
3784 4033{
3785 andSISIDXREG(SISPART2, 0x30, 0xdf); 4034 int mycrt1off;
3786
3787 } else if (ivideo->vbflags & TV_AVIDEO) {
3788
3789 orSISIDXREG(SISPART2, 0x30, 0x20);
3790
3791 switch (ivideo->video_width) {
3792 case 640:
3793 outSISIDXREG(SISPART2, 0x35, 0xEB);
3794 outSISIDXREG(SISPART2, 0x36, 0x04);
3795 outSISIDXREG(SISPART2, 0x37, 0x25);
3796 outSISIDXREG(SISPART2, 0x38, 0x18);
3797 break;
3798 case 720:
3799 outSISIDXREG(SISPART2, 0x35, 0xEE);
3800 outSISIDXREG(SISPART2, 0x36, 0x0C);
3801 outSISIDXREG(SISPART2, 0x37, 0x22);
3802 outSISIDXREG(SISPART2, 0x38, 0x08);
3803 break;
3804 case 400:
3805 case 800:
3806 outSISIDXREG(SISPART2, 0x35, 0xEB);
3807 outSISIDXREG(SISPART2, 0x36, 0x15);
3808 outSISIDXREG(SISPART2, 0x37, 0x25);
3809 outSISIDXREG(SISPART2, 0x38, 0xF6);
3810 break;
3811 }
3812 }
3813 4035
3814 } else if(ivideo->vbflags & TV_PAL) { 4036 switch(sisfb_command->sisfb_cmd) {
3815 4037 case SISFB_CMD_GETVBFLAGS:
3816 andSISIDXREG(SISPART2, 0x3A, 0x1F); 4038 if(!ivideo->modechanged) {
3817 4039 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_EARLY;
3818 if (ivideo->vbflags & TV_SVIDEO) { 4040 } else {
3819 4041 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_OK;
3820 andSISIDXREG(SISPART2, 0x30, 0xDF); 4042 sisfb_command->sisfb_result[1] = ivideo->currentvbflags;
3821 4043 sisfb_command->sisfb_result[2] = ivideo->vbflags2;
3822 } else if (ivideo->vbflags & TV_AVIDEO) { 4044 }
3823 4045 break;
3824 orSISIDXREG(SISPART2, 0x30, 0x20); 4046 case SISFB_CMD_SWITCHCRT1:
3825 4047 /* arg[0]: 0 = off, 1 = on, 99 = query */
3826 switch (ivideo->video_width) { 4048 if(!ivideo->modechanged) {
3827 case 640: 4049 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_EARLY;
3828 outSISIDXREG(SISPART2, 0x35, 0xF1); 4050 } else if(sisfb_command->sisfb_arg[0] == 99) {
3829 outSISIDXREG(SISPART2, 0x36, 0xF7); 4051 /* Query */
3830 outSISIDXREG(SISPART2, 0x37, 0x1F); 4052 sisfb_command->sisfb_result[1] = ivideo->sisfb_crt1off ? 0 : 1;
3831 outSISIDXREG(SISPART2, 0x38, 0x32); 4053 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_OK;
3832 break; 4054 } else if(ivideo->sisfblocked) {
3833 case 720: 4055 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_LOCKED;
3834 outSISIDXREG(SISPART2, 0x35, 0xF3); 4056 } else if((!(ivideo->currentvbflags & CRT2_ENABLE)) &&
3835 outSISIDXREG(SISPART2, 0x36, 0x00); 4057 (sisfb_command->sisfb_arg[0] == 0)) {
3836 outSISIDXREG(SISPART2, 0x37, 0x1D); 4058 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_NOCRT2;
3837 outSISIDXREG(SISPART2, 0x38, 0x20); 4059 } else {
3838 break; 4060 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_OK;
3839 case 400: 4061 mycrt1off = sisfb_command->sisfb_arg[0] ? 0 : 1;
3840 case 800: 4062 if( ((ivideo->currentvbflags & VB_DISPTYPE_CRT1) && mycrt1off) ||
3841 outSISIDXREG(SISPART2, 0x35, 0xFC); 4063 ((!(ivideo->currentvbflags & VB_DISPTYPE_CRT1)) && !mycrt1off) ) {
3842 outSISIDXREG(SISPART2, 0x36, 0xFB); 4064 ivideo->sisfb_crt1off = mycrt1off;
3843 outSISIDXREG(SISPART2, 0x37, 0x14); 4065 if(sisfb_reset_mode(ivideo)) {
3844 outSISIDXREG(SISPART2, 0x38, 0x2A); 4066 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_OTHER;
3845 break;
3846 } 4067 }
3847 } 4068 }
4069 sisfb_command->sisfb_result[1] = ivideo->sisfb_crt1off ? 0 : 1;
3848 } 4070 }
3849 4071 break;
3850 if((ivideo->sisfb_filter >= 0) && (ivideo->sisfb_filter <= 7)) { 4072 /* more to come */
3851 outSISIDXREG(SISPART2,0x35,(sis_TV_filter[filter_tb].filter[ivideo->sisfb_filter][0])); 4073 default:
3852 outSISIDXREG(SISPART2,0x36,(sis_TV_filter[filter_tb].filter[ivideo->sisfb_filter][1])); 4074 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_UNKNOWN;
3853 outSISIDXREG(SISPART2,0x37,(sis_TV_filter[filter_tb].filter[ivideo->sisfb_filter][2])); 4075 printk(KERN_ERR "sisfb: Unknown command 0x%x\n",
3854 outSISIDXREG(SISPART2,0x38,(sis_TV_filter[filter_tb].filter[ivideo->sisfb_filter][3])); 4076 sisfb_command->sisfb_cmd);
3855 }
3856
3857 } 4077 }
3858} 4078}
3859 4079
3860#ifndef MODULE 4080#ifndef MODULE
3861SISINITSTATIC int __init sisfb_setup(char *options) 4081SISINITSTATIC int __init
4082sisfb_setup(char *options)
3862{ 4083{
3863 char *this_opt; 4084 char *this_opt;
3864
3865 sisfb_setdefaultparms();
3866 4085
3867 printk(KERN_DEBUG "sisfb: Options %s\n", options); 4086 sisfb_setdefaultparms();
3868 4087
3869 if(!options || !(*options)) { 4088 if(!options || !(*options))
3870 return 0; 4089 return 0;
3871 }
3872 4090
3873 while((this_opt = strsep(&options, ",")) != NULL) { 4091 while((this_opt = strsep(&options, ",")) != NULL) {
3874 4092
@@ -3880,9 +4098,9 @@ SISINITSTATIC int __init sisfb_setup(char *options)
3880 /* Need to check crt2 type first for fstn/dstn */ 4098 /* Need to check crt2 type first for fstn/dstn */
3881 sisfb_search_crt2type(this_opt + 14); 4099 sisfb_search_crt2type(this_opt + 14);
3882 } else if(!strnicmp(this_opt, "tvmode:",7)) { 4100 } else if(!strnicmp(this_opt, "tvmode:",7)) {
3883 sisfb_search_tvstd(this_opt + 7);
3884 } else if(!strnicmp(this_opt, "tvstandard:",11)) {
3885 sisfb_search_tvstd(this_opt + 7); 4101 sisfb_search_tvstd(this_opt + 7);
4102 } else if(!strnicmp(this_opt, "tvstandard:",11)) {
4103 sisfb_search_tvstd(this_opt + 11);
3886 } else if(!strnicmp(this_opt, "mode:", 5)) { 4104 } else if(!strnicmp(this_opt, "mode:", 5)) {
3887 sisfb_search_mode(this_opt + 5, FALSE); 4105 sisfb_search_mode(this_opt + 5, FALSE);
3888 } else if(!strnicmp(this_opt, "vesa:", 5)) { 4106 } else if(!strnicmp(this_opt, "vesa:", 5)) {
@@ -3892,74 +4110,72 @@ SISINITSTATIC int __init sisfb_setup(char *options)
3892 sisfb_inverse = 1; 4110 sisfb_inverse = 1;
3893 /* fb_invert_cmaps(); */ 4111 /* fb_invert_cmaps(); */
3894 } else if(!strnicmp(this_opt, "font:", 5)) { 4112 } else if(!strnicmp(this_opt, "font:", 5)) {
3895 if(strlen(this_opt + 5) < 40) { 4113 if(strlen(this_opt + 5) < 40) {
3896 strncpy(sisfb_fontname, this_opt + 5, sizeof(sisfb_fontname) - 1); 4114 strncpy(sisfb_fontname, this_opt + 5, sizeof(sisfb_fontname) - 1);
3897 sisfb_fontname[sizeof(sisfb_fontname) - 1] = '\0'; 4115 sisfb_fontname[sizeof(sisfb_fontname) - 1] = '\0';
3898 } 4116 }
3899#endif 4117#endif
3900 } else if(!strnicmp(this_opt, "rate:", 5)) { 4118 } else if(!strnicmp(this_opt, "rate:", 5)) {
3901 sisfb_parm_rate = simple_strtoul(this_opt + 5, NULL, 0); 4119 sisfb_parm_rate = simple_strtoul(this_opt + 5, NULL, 0);
3902 } else if(!strnicmp(this_opt, "filter:", 7)) {
3903 sisfb_filter = (int)simple_strtoul(this_opt + 7, NULL, 0);
3904 } else if(!strnicmp(this_opt, "forcecrt1:", 10)) { 4120 } else if(!strnicmp(this_opt, "forcecrt1:", 10)) {
3905 sisfb_forcecrt1 = (int)simple_strtoul(this_opt + 10, NULL, 0); 4121 sisfb_forcecrt1 = (int)simple_strtoul(this_opt + 10, NULL, 0);
3906 } else if(!strnicmp(this_opt, "mem:",4)) { 4122 } else if(!strnicmp(this_opt, "mem:",4)) {
3907 sisfb_parm_mem = simple_strtoul(this_opt + 4, NULL, 0); 4123 sisfb_parm_mem = simple_strtoul(this_opt + 4, NULL, 0);
3908 } else if(!strnicmp(this_opt, "pdc:", 4)) { 4124 } else if(!strnicmp(this_opt, "pdc:", 4)) {
3909 sisfb_pdc = simple_strtoul(this_opt + 4, NULL, 0); 4125 sisfb_pdc = simple_strtoul(this_opt + 4, NULL, 0);
3910 } else if(!strnicmp(this_opt, "pdc1:", 5)) { 4126 } else if(!strnicmp(this_opt, "pdc1:", 5)) {
3911 sisfb_pdca = simple_strtoul(this_opt + 5, NULL, 0); 4127 sisfb_pdca = simple_strtoul(this_opt + 5, NULL, 0);
3912 } else if(!strnicmp(this_opt, "noaccel", 7)) { 4128 } else if(!strnicmp(this_opt, "noaccel", 7)) {
3913 sisfb_accel = 0; 4129 sisfb_accel = 0;
3914 } else if(!strnicmp(this_opt, "accel", 5)) { 4130 } else if(!strnicmp(this_opt, "accel", 5)) {
3915 sisfb_accel = -1; 4131 sisfb_accel = -1;
3916 } else if(!strnicmp(this_opt, "noypan", 6)) { 4132 } else if(!strnicmp(this_opt, "noypan", 6)) {
3917 sisfb_ypan = 0; 4133 sisfb_ypan = 0;
3918 } else if(!strnicmp(this_opt, "ypan", 4)) { 4134 } else if(!strnicmp(this_opt, "ypan", 4)) {
3919 sisfb_ypan = -1; 4135 sisfb_ypan = -1;
3920 } else if(!strnicmp(this_opt, "nomax", 5)) { 4136 } else if(!strnicmp(this_opt, "nomax", 5)) {
3921 sisfb_max = 0; 4137 sisfb_max = 0;
3922 } else if(!strnicmp(this_opt, "max", 3)) { 4138 } else if(!strnicmp(this_opt, "max", 3)) {
3923 sisfb_max = -1; 4139 sisfb_max = -1;
3924 } else if(!strnicmp(this_opt, "userom:", 7)) { 4140 } else if(!strnicmp(this_opt, "userom:", 7)) {
3925 sisfb_userom = (int)simple_strtoul(this_opt + 7, NULL, 0); 4141 sisfb_userom = (int)simple_strtoul(this_opt + 7, NULL, 0);
3926 } else if(!strnicmp(this_opt, "useoem:", 7)) { 4142 } else if(!strnicmp(this_opt, "useoem:", 7)) {
3927 sisfb_useoem = (int)simple_strtoul(this_opt + 7, NULL, 0); 4143 sisfb_useoem = (int)simple_strtoul(this_opt + 7, NULL, 0);
3928 } else if(!strnicmp(this_opt, "nocrt2rate", 10)) { 4144 } else if(!strnicmp(this_opt, "nocrt2rate", 10)) {
3929 sisfb_nocrt2rate = 1; 4145 sisfb_nocrt2rate = 1;
3930 } else if(!strnicmp(this_opt, "scalelcd:", 9)) { 4146 } else if(!strnicmp(this_opt, "scalelcd:", 9)) {
3931 unsigned long temp = 2; 4147 unsigned long temp = 2;
3932 temp = simple_strtoul(this_opt + 9, NULL, 0); 4148 temp = simple_strtoul(this_opt + 9, NULL, 0);
3933 if((temp == 0) || (temp == 1)) { 4149 if((temp == 0) || (temp == 1)) {
3934 sisfb_scalelcd = temp ^ 1; 4150 sisfb_scalelcd = temp ^ 1;
3935 } 4151 }
3936 } else if(!strnicmp(this_opt, "tvxposoffset:", 13)) { 4152 } else if(!strnicmp(this_opt, "tvxposoffset:", 13)) {
3937 int temp = 0; 4153 int temp = 0;
3938 temp = (int)simple_strtol(this_opt + 13, NULL, 0); 4154 temp = (int)simple_strtol(this_opt + 13, NULL, 0);
3939 if((temp >= -32) && (temp <= 32)) { 4155 if((temp >= -32) && (temp <= 32)) {
3940 sisfb_tvxposoffset = temp; 4156 sisfb_tvxposoffset = temp;
3941 } 4157 }
3942 } else if(!strnicmp(this_opt, "tvyposoffset:", 13)) { 4158 } else if(!strnicmp(this_opt, "tvyposoffset:", 13)) {
3943 int temp = 0; 4159 int temp = 0;
3944 temp = (int)simple_strtol(this_opt + 13, NULL, 0); 4160 temp = (int)simple_strtol(this_opt + 13, NULL, 0);
3945 if((temp >= -32) && (temp <= 32)) { 4161 if((temp >= -32) && (temp <= 32)) {
3946 sisfb_tvyposoffset = temp; 4162 sisfb_tvyposoffset = temp;
3947 } 4163 }
3948 } else if(!strnicmp(this_opt, "specialtiming:", 14)) { 4164 } else if(!strnicmp(this_opt, "specialtiming:", 14)) {
3949 sisfb_search_specialtiming(this_opt + 14); 4165 sisfb_search_specialtiming(this_opt + 14);
3950 } else if(!strnicmp(this_opt, "lvdshl:", 7)) { 4166 } else if(!strnicmp(this_opt, "lvdshl:", 7)) {
3951 int temp = 4; 4167 int temp = 4;
3952 temp = simple_strtoul(this_opt + 7, NULL, 0); 4168 temp = simple_strtoul(this_opt + 7, NULL, 0);
3953 if((temp >= 0) && (temp <= 3)) { 4169 if((temp >= 0) && (temp <= 3)) {
3954 sisfb_lvdshl = temp; 4170 sisfb_lvdshl = temp;
3955 } 4171 }
3956 } else if(this_opt[0] >= '0' && this_opt[0] <= '9') { 4172 } else if(this_opt[0] >= '0' && this_opt[0] <= '9') {
3957 sisfb_search_mode(this_opt, TRUE); 4173 sisfb_search_mode(this_opt, TRUE);
3958#if !defined(__i386__) && !defined(__x86_64__) 4174#if !defined(__i386__) && !defined(__x86_64__)
3959 } else if(!strnicmp(this_opt, "resetcard", 9)) { 4175 } else if(!strnicmp(this_opt, "resetcard", 9)) {
3960 sisfb_resetcard = 1; 4176 sisfb_resetcard = 1;
3961 } else if(!strnicmp(this_opt, "videoram:", 9)) { 4177 } else if(!strnicmp(this_opt, "videoram:", 9)) {
3962 sisfb_videoram = simple_strtoul(this_opt + 9, NULL, 0); 4178 sisfb_videoram = simple_strtoul(this_opt + 9, NULL, 0);
3963#endif 4179#endif
3964 } else { 4180 } else {
3965 printk(KERN_INFO "sisfb: Invalid option %s\n", this_opt); 4181 printk(KERN_INFO "sisfb: Invalid option %s\n", this_opt);
@@ -3967,63 +4183,99 @@ SISINITSTATIC int __init sisfb_setup(char *options)
3967 4183
3968 } 4184 }
3969 4185
3970
3971
3972 return 0; 4186 return 0;
3973} 4187}
3974#endif 4188#endif
3975 4189
3976static UCHAR * __devinit sis_find_rom(struct pci_dev *pdev) 4190static int __devinit
4191sisfb_check_rom(SIS_IOTYPE1 *rom_base, struct sis_video_info *ivideo)
4192{
4193 SIS_IOTYPE1 *rom;
4194 int romptr;
4195
4196 if((readb(rom_base) != 0x55) || (readb(rom_base + 1) != 0xaa))
4197 return 0;
4198
4199 romptr = (readb(rom_base + 0x18) | (readb(rom_base + 0x19) << 8));
4200 if(romptr > (0x10000 - 8))
4201 return 0;
4202
4203 rom = rom_base + romptr;
4204
4205 if((readb(rom) != 'P') || (readb(rom + 1) != 'C') ||
4206 (readb(rom + 2) != 'I') || (readb(rom + 3) != 'R'))
4207 return 0;
4208
4209 if((readb(rom + 4) | (readb(rom + 5) << 8)) != ivideo->chip_vendor)
4210 return 0;
4211
4212 if((readb(rom + 6) | (readb(rom + 7) << 8)) != ivideo->chip_id)
4213 return 0;
4214
4215 return 1;
4216}
4217
4218static unsigned char * __devinit
4219sisfb_find_rom(struct pci_dev *pdev)
3977{ 4220{
3978 struct sis_video_info *ivideo = pci_get_drvdata(pdev); 4221 struct sis_video_info *ivideo = pci_get_drvdata(pdev);
3979 USHORT pciid; 4222 SIS_IOTYPE1 *rom_base;
3980 int romptr; 4223 unsigned char *myrombase = NULL;
3981 UCHAR *myrombase; 4224 u32 temp;
3982 u32 temp; 4225#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
3983 SIS_IOTYPE1 *rom_base, *rom; 4226 size_t romsize;
4227
4228 /* First, try the official pci ROM functions (except
4229 * on integrated chipsets which have no ROM).
4230 */
3984 4231
3985 if(!(myrombase = vmalloc(65536))) return NULL; 4232 if(!ivideo->nbridge) {
3986 4233
3987#if defined(__i386__) || defined(__x86_64__) 4234 if((rom_base = pci_map_rom(pdev, &romsize))) {
3988 4235
3989 for(temp = 0x000c0000; temp < 0x000f0000; temp += 0x00001000) { 4236 if(sisfb_check_rom(rom_base, ivideo)) {
3990 4237
3991 rom_base = ioremap(temp, 0x10000); 4238 if((myrombase = vmalloc(65536))) {
3992 if(!rom_base) continue;
3993 4239
3994 if((readb(rom_base) != 0x55) || (readb(rom_base + 1) != 0xaa)) { 4240 /* Work around bug in pci/rom.c: Folks forgot to check
3995 iounmap(rom_base); 4241 * whether the size retrieved from the BIOS image eventually
3996 continue; 4242 * is larger than the mapped size
3997 } 4243 */
4244 if(pci_resource_len(pdev, PCI_ROM_RESOURCE) < romsize)
4245 romsize = pci_resource_len(pdev, PCI_ROM_RESOURCE);
3998 4246
3999 romptr = (unsigned short)(readb(rom_base + 0x18) | (readb(rom_base + 0x19) << 8)); 4247 memcpy_fromio(myrombase, rom_base,
4000 if(romptr > (0x10000 - 8)) { 4248 (romsize > 65536) ? 65536 : romsize);
4001 iounmap(rom_base); 4249 }
4002 continue; 4250 }
4003 } 4251 pci_unmap_rom(pdev, rom_base);
4252 }
4253 }
4004 4254
4005 rom = rom_base + romptr; 4255 if(myrombase) return myrombase;
4256#endif
4006 4257
4007 if((readb(rom) != 'P') || (readb(rom + 1) != 'C') || 4258 /* Otherwise do it the conventional way. */
4008 (readb(rom + 2) != 'I') || (readb(rom + 3) != 'R')) {
4009 iounmap(rom_base);
4010 continue;
4011 }
4012 4259
4013 pciid = readb(rom + 4) | (readb(rom + 5) << 8); 4260#if defined(__i386__) || defined(__x86_64__)
4014 if(pciid != 0x1039) {
4015 iounmap(rom_base);
4016 continue;
4017 }
4018 4261
4019 pciid = readb(rom + 6) | (readb(rom + 7) << 8); 4262 for(temp = 0x000c0000; temp < 0x000f0000; temp += 0x00001000) {
4020 if(pciid == ivideo->chip_id) { 4263
4021 memcpy_fromio(myrombase, rom_base, 65536); 4264 rom_base = ioremap(temp, 65536);
4022 iounmap(rom_base); 4265 if(!rom_base)
4023 return myrombase; 4266 continue;
4024 } 4267
4268 if(!sisfb_check_rom(rom_base, ivideo)) {
4269 iounmap(rom_base);
4270 continue;
4271 }
4272
4273 if((myrombase = vmalloc(65536)))
4274 memcpy_fromio(myrombase, rom_base, 65536);
4275
4276 iounmap(rom_base);
4277 break;
4025 4278
4026 iounmap(rom_base);
4027 } 4279 }
4028 4280
4029#else 4281#else
@@ -4034,752 +4286,1603 @@ static UCHAR * __devinit sis_find_rom(struct pci_dev *pdev)
4034 4286
4035 rom_base = ioremap(ivideo->video_base, 65536); 4287 rom_base = ioremap(ivideo->video_base, 65536);
4036 if(rom_base) { 4288 if(rom_base) {
4037 if((readb(rom_base) == 0x55) && (readb(rom_base + 1) == 0xaa)) { 4289 if(sisfb_check_rom(rom_base, ivideo)) {
4038 romptr = (u16)(readb(rom_base + 0x18) | (readb(rom_base + 0x19) << 8)); 4290 if((myrombase = vmalloc(65536)))
4039 if(romptr <= (0x10000 - 8)) { 4291 memcpy_fromio(myrombase, rom_base, 65536);
4040 rom = rom_base + romptr; 4292 }
4041 if((readb(rom) == 'P') && (readb(rom + 1) == 'C') && 4293 iounmap(rom_base);
4042 (readb(rom + 2) == 'I') && (readb(rom + 3) == 'R')) {
4043 pciid = readb(rom + 4) | (readb(rom + 5) << 8);
4044 if(pciid == 0x1039) {
4045 pciid = readb(rom + 6) | (readb(rom + 7) << 8);
4046 if(pciid == ivideo->chip_id) {
4047 memcpy_fromio(myrombase, rom_base, 65536);
4048 iounmap(rom_base);
4049 pci_write_config_dword(pdev, PCI_ROM_ADDRESS, temp);
4050 return myrombase;
4051 }
4052 }
4053 }
4054 }
4055 }
4056 iounmap(rom_base);
4057 } 4294 }
4058 pci_write_config_dword(pdev, PCI_ROM_ADDRESS, temp); 4295
4296 pci_write_config_dword(pdev, PCI_ROM_ADDRESS, temp);
4059 4297
4060#endif 4298#endif
4061 4299
4062 vfree(myrombase); 4300 return myrombase;
4063 return NULL; 4301}
4302
4303static void __devinit
4304sisfb_post_map_vram(struct sis_video_info *ivideo, unsigned int *mapsize,
4305 unsigned int min)
4306{
4307 ivideo->video_vbase = ioremap(ivideo->video_base, (*mapsize));
4308
4309 if(!ivideo->video_vbase) {
4310 printk(KERN_ERR
4311 "sisfb: Unable to map maximum video RAM for size detection\n");
4312 (*mapsize) >>= 1;
4313 while((!(ivideo->video_vbase = ioremap(ivideo->video_base, (*mapsize))))) {
4314 (*mapsize) >>= 1;
4315 if((*mapsize) < (min << 20))
4316 break;
4317 }
4318 if(ivideo->video_vbase) {
4319 printk(KERN_ERR
4320 "sisfb: Video RAM size detection limited to %dMB\n",
4321 (int)((*mapsize) >> 20));
4322 }
4323 }
4064} 4324}
4065 4325
4066#ifdef CONFIG_FB_SIS_300 4326#ifdef CONFIG_FB_SIS_300
4067static int __devinit 4327static int __devinit
4068sisfb_chkbuswidth300(struct pci_dev *pdev, SIS_IOTYPE1 *FBAddress) 4328sisfb_post_300_buswidth(struct sis_video_info *ivideo)
4069{ 4329{
4070 struct sis_video_info *ivideo = pci_get_drvdata(pdev); 4330 SIS_IOTYPE1 *FBAddress = ivideo->video_vbase;
4331 unsigned short temp;
4332 unsigned char reg;
4071 int i, j; 4333 int i, j;
4072 USHORT temp; 4334
4073 UCHAR reg; 4335 andSISIDXREG(SISSR, 0x15, 0xFB);
4074 4336 orSISIDXREG(SISSR, 0x15, 0x04);
4075 andSISIDXREG(SISSR,0x15,0xFB); 4337 outSISIDXREG(SISSR, 0x13, 0x00);
4076 orSISIDXREG(SISSR,0x15,0x04); 4338 outSISIDXREG(SISSR, 0x14, 0xBF);
4077 outSISIDXREG(SISSR,0x13,0x00); 4339
4078 outSISIDXREG(SISSR,0x14,0xBF); 4340 for(i = 0; i < 2; i++) {
4079 4341 temp = 0x1234;
4080 for(i=0; i<2; i++) { 4342 for(j = 0; j < 4; j++) {
4081 temp = 0x1234; 4343 writew(temp, FBAddress);
4082 for(j=0; j<4; j++) { 4344 if(readw(FBAddress) == temp)
4083 writew(temp, FBAddress); 4345 break;
4084 if(readw(FBAddress) == temp) break; 4346 orSISIDXREG(SISSR, 0x3c, 0x01);
4085 orSISIDXREG(SISSR,0x3c,0x01); 4347 inSISIDXREG(SISSR, 0x05, reg);
4086 inSISIDXREG(SISSR,0x05,reg); 4348 inSISIDXREG(SISSR, 0x05, reg);
4087 inSISIDXREG(SISSR,0x05,reg); 4349 andSISIDXREG(SISSR, 0x3c, 0xfe);
4088 andSISIDXREG(SISSR,0x3c,0xfe); 4350 inSISIDXREG(SISSR, 0x05, reg);
4089 inSISIDXREG(SISSR,0x05,reg); 4351 inSISIDXREG(SISSR, 0x05, reg);
4090 inSISIDXREG(SISSR,0x05,reg); 4352 temp++;
4091 temp++; 4353 }
4092 }
4093 } 4354 }
4094 4355
4095 writel(0x01234567L, FBAddress); 4356 writel(0x01234567L, FBAddress);
4096 writel(0x456789ABL, (FBAddress+4)); 4357 writel(0x456789ABL, (FBAddress + 4));
4097 writel(0x89ABCDEFL, (FBAddress+8)); 4358 writel(0x89ABCDEFL, (FBAddress + 8));
4098 writel(0xCDEF0123L, (FBAddress+12)); 4359 writel(0xCDEF0123L, (FBAddress + 12));
4099 inSISIDXREG(SISSR,0x3b,reg); 4360
4361 inSISIDXREG(SISSR, 0x3b, reg);
4100 if(reg & 0x01) { 4362 if(reg & 0x01) {
4101 if(readl((FBAddress+12)) == 0xCDEF0123L) return(4); /* Channel A 128bit */ 4363 if(readl((FBAddress + 12)) == 0xCDEF0123L)
4364 return 4; /* Channel A 128bit */
4102 } 4365 }
4103 if(readl((FBAddress+4)) == 0x456789ABL) return(2); /* Channel B 64bit */ 4366
4104 return(1); /* 32bit */ 4367 if(readl((FBAddress + 4)) == 0x456789ABL)
4368 return 2; /* Channel B 64bit */
4369
4370 return 1; /* 32bit */
4371}
4372
4373static int __devinit
4374sisfb_post_300_rwtest(struct sis_video_info *ivideo, int iteration, int buswidth,
4375 int PseudoRankCapacity, int PseudoAdrPinCount,
4376 unsigned int mapsize)
4377{
4378 SIS_IOTYPE1 *FBAddr = ivideo->video_vbase;
4379 unsigned short sr14;
4380 unsigned int k, RankCapacity, PageCapacity, BankNumHigh, BankNumMid;
4381 unsigned int PhysicalAdrOtherPage, PhysicalAdrHigh, PhysicalAdrHalfPage;
4382 static const unsigned short SiS_DRAMType[17][5] = {
4383 {0x0C,0x0A,0x02,0x40,0x39},
4384 {0x0D,0x0A,0x01,0x40,0x48},
4385 {0x0C,0x09,0x02,0x20,0x35},
4386 {0x0D,0x09,0x01,0x20,0x44},
4387 {0x0C,0x08,0x02,0x10,0x31},
4388 {0x0D,0x08,0x01,0x10,0x40},
4389 {0x0C,0x0A,0x01,0x20,0x34},
4390 {0x0C,0x09,0x01,0x08,0x32},
4391 {0x0B,0x08,0x02,0x08,0x21},
4392 {0x0C,0x08,0x01,0x08,0x30},
4393 {0x0A,0x08,0x02,0x04,0x11},
4394 {0x0B,0x0A,0x01,0x10,0x28},
4395 {0x09,0x08,0x02,0x02,0x01},
4396 {0x0B,0x09,0x01,0x08,0x24},
4397 {0x0B,0x08,0x01,0x04,0x20},
4398 {0x0A,0x08,0x01,0x02,0x10},
4399 {0x09,0x08,0x01,0x01,0x00}
4400 };
4401
4402 for(k = 0; k <= 16; k++) {
4403
4404 RankCapacity = buswidth * SiS_DRAMType[k][3];
4405
4406 if(RankCapacity != PseudoRankCapacity)
4407 continue;
4408
4409 if((SiS_DRAMType[k][2] + SiS_DRAMType[k][0]) > PseudoAdrPinCount)
4410 continue;
4411
4412 BankNumHigh = RankCapacity * 16 * iteration - 1;
4413 if(iteration == 3) { /* Rank No */
4414 BankNumMid = RankCapacity * 16 - 1;
4415 } else {
4416 BankNumMid = RankCapacity * 16 * iteration / 2 - 1;
4417 }
4418
4419 PageCapacity = (1 << SiS_DRAMType[k][1]) * buswidth * 4;
4420 PhysicalAdrHigh = BankNumHigh;
4421 PhysicalAdrHalfPage = (PageCapacity / 2 + PhysicalAdrHigh) % PageCapacity;
4422 PhysicalAdrOtherPage = PageCapacity * SiS_DRAMType[k][2] + PhysicalAdrHigh;
4423
4424 andSISIDXREG(SISSR, 0x15, 0xFB); /* Test */
4425 orSISIDXREG(SISSR, 0x15, 0x04); /* Test */
4426 sr14 = (SiS_DRAMType[k][3] * buswidth) - 1;
4427 if(buswidth == 4) sr14 |= 0x80;
4428 else if(buswidth == 2) sr14 |= 0x40;
4429 outSISIDXREG(SISSR, 0x13, SiS_DRAMType[k][4]);
4430 outSISIDXREG(SISSR, 0x14, sr14);
4431
4432 BankNumHigh <<= 16;
4433 BankNumMid <<= 16;
4434
4435 if((BankNumHigh + PhysicalAdrHigh >= mapsize) ||
4436 (BankNumMid + PhysicalAdrHigh >= mapsize) ||
4437 (BankNumHigh + PhysicalAdrHalfPage >= mapsize) ||
4438 (BankNumHigh + PhysicalAdrOtherPage >= mapsize))
4439 continue;
4440
4441 /* Write data */
4442 writew(((unsigned short)PhysicalAdrHigh),
4443 (FBAddr + BankNumHigh + PhysicalAdrHigh));
4444 writew(((unsigned short)BankNumMid),
4445 (FBAddr + BankNumMid + PhysicalAdrHigh));
4446 writew(((unsigned short)PhysicalAdrHalfPage),
4447 (FBAddr + BankNumHigh + PhysicalAdrHalfPage));
4448 writew(((unsigned short)PhysicalAdrOtherPage),
4449 (FBAddr + BankNumHigh + PhysicalAdrOtherPage));
4450
4451 /* Read data */
4452 if(readw(FBAddr + BankNumHigh + PhysicalAdrHigh) == PhysicalAdrHigh)
4453 return 1;
4454 }
4455
4456 return 0;
4105} 4457}
4106 4458
4107static void __devinit 4459static void __devinit
4108sisfb_setramsize300(struct pci_dev *pdev) 4460sisfb_post_300_ramsize(struct pci_dev *pdev, unsigned int mapsize)
4109{ 4461{
4110 struct sis_video_info *ivideo = pci_get_drvdata(pdev); 4462 struct sis_video_info *ivideo = pci_get_drvdata(pdev);
4111 SIS_IOTYPE1 *FBAddr = ivideo->video_vbase; 4463 int i, j, buswidth;
4112 SIS_IOTYPE1 *Addr; 4464 int PseudoRankCapacity, PseudoAdrPinCount;
4113 USHORT sr13, sr14=0, buswidth, Done, data, TotalCapacity, PhysicalAdrOtherPage=0; 4465
4114 int PseudoRankCapacity, PseudoTotalCapacity, PseudoAdrPinCount; 4466 buswidth = sisfb_post_300_buswidth(ivideo);
4115 int RankCapacity, AdrPinCount, BankNumHigh, BankNumMid, MB2Bank; 4467
4116 int PageCapacity, PhysicalAdrHigh, PhysicalAdrHalfPage, i, j, k; 4468 for(i = 6; i >= 0; i--) {
4117 const USHORT SiS_DRAMType[17][5] = { 4469 PseudoRankCapacity = 1 << i;
4118 {0x0C,0x0A,0x02,0x40,0x39}, 4470 for(j = 4; j >= 1; j--) {
4119 {0x0D,0x0A,0x01,0x40,0x48}, 4471 PseudoAdrPinCount = 15 - j;
4120 {0x0C,0x09,0x02,0x20,0x35}, 4472 if((PseudoRankCapacity * j) <= 64) {
4121 {0x0D,0x09,0x01,0x20,0x44}, 4473 if(sisfb_post_300_rwtest(ivideo,
4122 {0x0C,0x08,0x02,0x10,0x31}, 4474 j,
4123 {0x0D,0x08,0x01,0x10,0x40}, 4475 buswidth,
4124 {0x0C,0x0A,0x01,0x20,0x34}, 4476 PseudoRankCapacity,
4125 {0x0C,0x09,0x01,0x08,0x32}, 4477 PseudoAdrPinCount,
4126 {0x0B,0x08,0x02,0x08,0x21}, 4478 mapsize))
4127 {0x0C,0x08,0x01,0x08,0x30}, 4479 return;
4128 {0x0A,0x08,0x02,0x04,0x11}, 4480 }
4129 {0x0B,0x0A,0x01,0x10,0x28}, 4481 }
4130 {0x09,0x08,0x02,0x02,0x01}, 4482 }
4131 {0x0B,0x09,0x01,0x08,0x24},
4132 {0x0B,0x08,0x01,0x04,0x20},
4133 {0x0A,0x08,0x01,0x02,0x10},
4134 {0x09,0x08,0x01,0x01,0x00}
4135 };
4136
4137 buswidth = sisfb_chkbuswidth300(pdev, FBAddr);
4138
4139 MB2Bank = 16;
4140 Done = 0;
4141 for(i = 6; i >= 0; i--) {
4142 if(Done) break;
4143 PseudoRankCapacity = 1 << i;
4144 for(j = 4; j >= 1; j--) {
4145 if(Done) break;
4146 PseudoTotalCapacity = PseudoRankCapacity * j;
4147 PseudoAdrPinCount = 15 - j;
4148 if(PseudoTotalCapacity <= 64) {
4149 for(k = 0; k <= 16; k++) {
4150 if(Done) break;
4151 RankCapacity = buswidth * SiS_DRAMType[k][3];
4152 AdrPinCount = SiS_DRAMType[k][2] + SiS_DRAMType[k][0];
4153 if(RankCapacity == PseudoRankCapacity)
4154 if(AdrPinCount <= PseudoAdrPinCount) {
4155 if(j == 3) { /* Rank No */
4156 BankNumHigh = RankCapacity * MB2Bank * 3 - 1;
4157 BankNumMid = RankCapacity * MB2Bank * 1 - 1;
4158 } else {
4159 BankNumHigh = RankCapacity * MB2Bank * j - 1;
4160 BankNumMid = RankCapacity * MB2Bank * j / 2 - 1;
4161 }
4162 PageCapacity = (1 << SiS_DRAMType[k][1]) * buswidth * 4;
4163 PhysicalAdrHigh = BankNumHigh;
4164 PhysicalAdrHalfPage = (PageCapacity / 2 + PhysicalAdrHigh) % PageCapacity;
4165 PhysicalAdrOtherPage = PageCapacity * SiS_DRAMType[k][2] + PhysicalAdrHigh;
4166 /* Write data */
4167 andSISIDXREG(SISSR,0x15,0xFB); /* Test */
4168 orSISIDXREG(SISSR,0x15,0x04); /* Test */
4169 TotalCapacity = SiS_DRAMType[k][3] * buswidth;
4170 sr13 = SiS_DRAMType[k][4];
4171 if(buswidth == 4) sr14 = (TotalCapacity - 1) | 0x80;
4172 if(buswidth == 2) sr14 = (TotalCapacity - 1) | 0x40;
4173 if(buswidth == 1) sr14 = (TotalCapacity - 1) | 0x00;
4174 outSISIDXREG(SISSR,0x13,sr13);
4175 outSISIDXREG(SISSR,0x14,sr14);
4176 Addr = FBAddr + BankNumHigh * 64 * 1024 + PhysicalAdrHigh;
4177 /* *((USHORT *)(Addr)) = (USHORT)PhysicalAdrHigh; */
4178 writew(((USHORT)PhysicalAdrHigh), Addr);
4179 Addr = FBAddr + BankNumMid * 64 * 1024 + PhysicalAdrHigh;
4180 /* *((USHORT *)(Addr)) = (USHORT)BankNumMid; */
4181 writew(((USHORT)BankNumMid), Addr);
4182 Addr = FBAddr + BankNumHigh * 64 * 1024 + PhysicalAdrHalfPage;
4183 /* *((USHORT *)(Addr)) = (USHORT)PhysicalAdrHalfPage; */
4184 writew(((USHORT)PhysicalAdrHalfPage), Addr);
4185 Addr = FBAddr + BankNumHigh * 64 * 1024 + PhysicalAdrOtherPage;
4186 /* *((USHORT *)(Addr)) = PhysicalAdrOtherPage; */
4187 writew(((USHORT)PhysicalAdrOtherPage), Addr);
4188 /* Read data */
4189 Addr = FBAddr + BankNumHigh * 64 * 1024 + PhysicalAdrHigh;
4190 data = readw(Addr); /* *((USHORT *)(Addr)); */
4191 if(data == PhysicalAdrHigh) Done = 1;
4192 } /* if */
4193 } /* for k */
4194 } /* if */
4195 } /* for j */
4196 } /* for i */
4197} 4483}
4198 4484
4199static void __devinit sisfb_post_sis300(struct pci_dev *pdev) 4485static void __devinit
4486sisfb_post_sis300(struct pci_dev *pdev)
4200{ 4487{
4201 struct sis_video_info *ivideo = pci_get_drvdata(pdev); 4488 struct sis_video_info *ivideo = pci_get_drvdata(pdev);
4489 unsigned char *bios = ivideo->SiS_Pr.VirtualRomBase;
4202 u8 reg, v1, v2, v3, v4, v5, v6, v7, v8; 4490 u8 reg, v1, v2, v3, v4, v5, v6, v7, v8;
4203 u16 index, rindex, memtype = 0; 4491 u16 index, rindex, memtype = 0;
4492 unsigned int mapsize;
4204 4493
4205 outSISIDXREG(SISSR,0x05,0x86); 4494 if(!ivideo->SiS_Pr.UseROM)
4495 bios = NULL;
4206 4496
4207 if(ivideo->sishw_ext.UseROM) { 4497 outSISIDXREG(SISSR, 0x05, 0x86);
4208 if(ivideo->sishw_ext.pjVirtualRomBase[0x52] & 0x80) { 4498
4209 memtype = ivideo->sishw_ext.pjVirtualRomBase[0x52]; 4499 if(bios) {
4210 } else { 4500 if(bios[0x52] & 0x80) {
4211 inSISIDXREG(SISSR,0x3a,memtype); 4501 memtype = bios[0x52];
4212 } 4502 } else {
4213 memtype &= 0x07; 4503 inSISIDXREG(SISSR, 0x3a, memtype);
4504 }
4505 memtype &= 0x07;
4214 } 4506 }
4215 4507
4508 v3 = 0x80; v6 = 0x80;
4216 if(ivideo->revision_id <= 0x13) { 4509 if(ivideo->revision_id <= 0x13) {
4217 v1 = 0x44; v2 = 0x42; v3 = 0x80; 4510 v1 = 0x44; v2 = 0x42;
4218 v4 = 0x44; v5 = 0x42; v6 = 0x80; 4511 v4 = 0x44; v5 = 0x42;
4219 } else { 4512 } else {
4220 v1 = 0x68; v2 = 0x43; v3 = 0x80; /* Assume 125Mhz MCLK */ 4513 v1 = 0x68; v2 = 0x43; /* Assume 125Mhz MCLK */
4221 v4 = 0x68; v5 = 0x43; v6 = 0x80; /* Assume 125Mhz ECLK */ 4514 v4 = 0x68; v5 = 0x43; /* Assume 125Mhz ECLK */
4222 if(ivideo->sishw_ext.UseROM) { 4515 if(bios) {
4223 index = memtype * 5; 4516 index = memtype * 5;
4224 rindex = index + 0x54; 4517 rindex = index + 0x54;
4225 v1 = ivideo->sishw_ext.pjVirtualRomBase[rindex++]; 4518 v1 = bios[rindex++];
4226 v2 = ivideo->sishw_ext.pjVirtualRomBase[rindex++]; 4519 v2 = bios[rindex++];
4227 v3 = ivideo->sishw_ext.pjVirtualRomBase[rindex++]; 4520 v3 = bios[rindex++];
4228 rindex = index + 0x7c; 4521 rindex = index + 0x7c;
4229 v4 = ivideo->sishw_ext.pjVirtualRomBase[rindex++]; 4522 v4 = bios[rindex++];
4230 v5 = ivideo->sishw_ext.pjVirtualRomBase[rindex++]; 4523 v5 = bios[rindex++];
4231 v6 = ivideo->sishw_ext.pjVirtualRomBase[rindex++]; 4524 v6 = bios[rindex++];
4232 } 4525 }
4233 } 4526 }
4234 outSISIDXREG(SISSR,0x28,v1); 4527 outSISIDXREG(SISSR, 0x28, v1);
4235 outSISIDXREG(SISSR,0x29,v2); 4528 outSISIDXREG(SISSR, 0x29, v2);
4236 outSISIDXREG(SISSR,0x2a,v3); 4529 outSISIDXREG(SISSR, 0x2a, v3);
4237 outSISIDXREG(SISSR,0x2e,v4); 4530 outSISIDXREG(SISSR, 0x2e, v4);
4238 outSISIDXREG(SISSR,0x2f,v5); 4531 outSISIDXREG(SISSR, 0x2f, v5);
4239 outSISIDXREG(SISSR,0x30,v6); 4532 outSISIDXREG(SISSR, 0x30, v6);
4533
4240 v1 = 0x10; 4534 v1 = 0x10;
4241 if(ivideo->sishw_ext.UseROM) v1 = ivideo->sishw_ext.pjVirtualRomBase[0xa4]; 4535 if(bios)
4242 outSISIDXREG(SISSR,0x07,v1); /* DAC speed */ 4536 v1 = bios[0xa4];
4243 outSISIDXREG(SISSR,0x11,0x0f); /* DDC, power save */ 4537 outSISIDXREG(SISSR, 0x07, v1); /* DAC speed */
4538
4539 outSISIDXREG(SISSR, 0x11, 0x0f); /* DDC, power save */
4540
4244 v1 = 0x01; v2 = 0x43; v3 = 0x1e; v4 = 0x2a; 4541 v1 = 0x01; v2 = 0x43; v3 = 0x1e; v4 = 0x2a;
4245 v5 = 0x06; v6 = 0x00; v7 = 0x00; v8 = 0x00; 4542 v5 = 0x06; v6 = 0x00; v7 = 0x00; v8 = 0x00;
4246 if(ivideo->sishw_ext.UseROM) { 4543 if(bios) {
4247 memtype += 0xa5; 4544 memtype += 0xa5;
4248 v1 = ivideo->sishw_ext.pjVirtualRomBase[memtype]; 4545 v1 = bios[memtype];
4249 v2 = ivideo->sishw_ext.pjVirtualRomBase[memtype + 8]; 4546 v2 = bios[memtype + 8];
4250 v3 = ivideo->sishw_ext.pjVirtualRomBase[memtype + 16]; 4547 v3 = bios[memtype + 16];
4251 v4 = ivideo->sishw_ext.pjVirtualRomBase[memtype + 24]; 4548 v4 = bios[memtype + 24];
4252 v5 = ivideo->sishw_ext.pjVirtualRomBase[memtype + 32]; 4549 v5 = bios[memtype + 32];
4253 v6 = ivideo->sishw_ext.pjVirtualRomBase[memtype + 40]; 4550 v6 = bios[memtype + 40];
4254 v7 = ivideo->sishw_ext.pjVirtualRomBase[memtype + 48]; 4551 v7 = bios[memtype + 48];
4255 v8 = ivideo->sishw_ext.pjVirtualRomBase[memtype + 56]; 4552 v8 = bios[memtype + 56];
4256 } 4553 }
4257 if(ivideo->revision_id >= 0x80) v3 &= 0xfd; 4554 if(ivideo->revision_id >= 0x80)
4258 outSISIDXREG(SISSR,0x15,v1); /* Ram type (assuming 0, BIOS 0xa5 step 8) */ 4555 v3 &= 0xfd;
4259 outSISIDXREG(SISSR,0x16,v2); 4556 outSISIDXREG(SISSR, 0x15, v1); /* Ram type (assuming 0, BIOS 0xa5 step 8) */
4260 outSISIDXREG(SISSR,0x17,v3); 4557 outSISIDXREG(SISSR, 0x16, v2);
4261 outSISIDXREG(SISSR,0x18,v4); 4558 outSISIDXREG(SISSR, 0x17, v3);
4262 outSISIDXREG(SISSR,0x19,v5); 4559 outSISIDXREG(SISSR, 0x18, v4);
4263 outSISIDXREG(SISSR,0x1a,v6); 4560 outSISIDXREG(SISSR, 0x19, v5);
4264 outSISIDXREG(SISSR,0x1b,v7); 4561 outSISIDXREG(SISSR, 0x1a, v6);
4265 outSISIDXREG(SISSR,0x1c,v8); /* ---- */ 4562 outSISIDXREG(SISSR, 0x1b, v7);
4266 andSISIDXREG(SISSR,0x15,0xfb); 4563 outSISIDXREG(SISSR, 0x1c, v8); /* ---- */
4267 orSISIDXREG(SISSR,0x15,0x04); 4564 andSISIDXREG(SISSR, 0x15 ,0xfb);
4268 if(ivideo->sishw_ext.UseROM) { 4565 orSISIDXREG(SISSR, 0x15, 0x04);
4269 if(ivideo->sishw_ext.pjVirtualRomBase[0x53] & 0x02) { 4566 if(bios) {
4270 orSISIDXREG(SISSR,0x19,0x20); 4567 if(bios[0x53] & 0x02) {
4271 } 4568 orSISIDXREG(SISSR, 0x19, 0x20);
4569 }
4272 } 4570 }
4273 v1 = 0x04; /* DAC pedestal (BIOS 0xe5) */ 4571 v1 = 0x04; /* DAC pedestal (BIOS 0xe5) */
4274 if(ivideo->revision_id >= 0x80) v1 |= 0x01; 4572 if(ivideo->revision_id >= 0x80)
4275 outSISIDXREG(SISSR,0x1f,v1); 4573 v1 |= 0x01;
4276 outSISIDXREG(SISSR,0x20,0xa0); /* linear & relocated io */ 4574 outSISIDXREG(SISSR, 0x1f, v1);
4575 outSISIDXREG(SISSR, 0x20, 0xa4); /* linear & relocated io & disable a0000 */
4277 v1 = 0xf6; v2 = 0x0d; v3 = 0x00; 4576 v1 = 0xf6; v2 = 0x0d; v3 = 0x00;
4278 if(ivideo->sishw_ext.UseROM) { 4577 if(bios) {
4279 v1 = ivideo->sishw_ext.pjVirtualRomBase[0xe8]; 4578 v1 = bios[0xe8];
4280 v2 = ivideo->sishw_ext.pjVirtualRomBase[0xe9]; 4579 v2 = bios[0xe9];
4281 v3 = ivideo->sishw_ext.pjVirtualRomBase[0xea]; 4580 v3 = bios[0xea];
4282 } 4581 }
4283 outSISIDXREG(SISSR,0x23,v1); 4582 outSISIDXREG(SISSR, 0x23, v1);
4284 outSISIDXREG(SISSR,0x24,v2); 4583 outSISIDXREG(SISSR, 0x24, v2);
4285 outSISIDXREG(SISSR,0x25,v3); 4584 outSISIDXREG(SISSR, 0x25, v3);
4286 outSISIDXREG(SISSR,0x21,0x84); 4585 outSISIDXREG(SISSR, 0x21, 0x84);
4287 outSISIDXREG(SISSR,0x22,0x00); 4586 outSISIDXREG(SISSR, 0x22, 0x00);
4288 outSISIDXREG(SISCR,0x37,0x00); 4587 outSISIDXREG(SISCR, 0x37, 0x00);
4289 orSISIDXREG(SISPART1,0x24,0x01); /* unlock crt2 */ 4588 orSISIDXREG(SISPART1, 0x24, 0x01); /* unlock crt2 */
4290 outSISIDXREG(SISPART1,0x00,0x00); 4589 outSISIDXREG(SISPART1, 0x00, 0x00);
4291 v1 = 0x40; v2 = 0x11; 4590 v1 = 0x40; v2 = 0x11;
4292 if(ivideo->sishw_ext.UseROM) { 4591 if(bios) {
4293 v1 = ivideo->sishw_ext.pjVirtualRomBase[0xec]; 4592 v1 = bios[0xec];
4294 v2 = ivideo->sishw_ext.pjVirtualRomBase[0xeb]; 4593 v2 = bios[0xeb];
4295 } 4594 }
4296 outSISIDXREG(SISPART1,0x02,v1); 4595 outSISIDXREG(SISPART1, 0x02, v1);
4297 if(ivideo->revision_id >= 0x80) v2 &= ~0x01; 4596
4298 inSISIDXREG(SISPART4,0x00,reg); 4597 if(ivideo->revision_id >= 0x80)
4598 v2 &= ~0x01;
4599
4600 inSISIDXREG(SISPART4, 0x00, reg);
4299 if((reg == 1) || (reg == 2)) { 4601 if((reg == 1) || (reg == 2)) {
4300 outSISIDXREG(SISCR,0x37,0x02); 4602 outSISIDXREG(SISCR, 0x37, 0x02);
4301 outSISIDXREG(SISPART2,0x00,0x1c); 4603 outSISIDXREG(SISPART2, 0x00, 0x1c);
4302 v4 = 0x00; v5 = 0x00; v6 = 0x10; 4604 v4 = 0x00; v5 = 0x00; v6 = 0x10;
4303 if(ivideo->sishw_ext.UseROM) { 4605 if(ivideo->SiS_Pr.UseROM) {
4304 v4 = ivideo->sishw_ext.pjVirtualRomBase[0xf5]; 4606 v4 = bios[0xf5];
4305 v5 = ivideo->sishw_ext.pjVirtualRomBase[0xf6]; 4607 v5 = bios[0xf6];
4306 v6 = ivideo->sishw_ext.pjVirtualRomBase[0xf7]; 4608 v6 = bios[0xf7];
4307 } 4609 }
4308 outSISIDXREG(SISPART4,0x0d,v4); 4610 outSISIDXREG(SISPART4, 0x0d, v4);
4309 outSISIDXREG(SISPART4,0x0e,v5); 4611 outSISIDXREG(SISPART4, 0x0e, v5);
4310 outSISIDXREG(SISPART4,0x10,v6); 4612 outSISIDXREG(SISPART4, 0x10, v6);
4311 outSISIDXREG(SISPART4,0x0f,0x3f); 4613 outSISIDXREG(SISPART4, 0x0f, 0x3f);
4312 inSISIDXREG(SISPART4,0x01,reg); 4614 inSISIDXREG(SISPART4, 0x01, reg);
4313 if(reg >= 0xb0) { 4615 if(reg >= 0xb0) {
4314 inSISIDXREG(SISPART4,0x23,reg); 4616 inSISIDXREG(SISPART4, 0x23, reg);
4315 reg &= 0x20; 4617 reg &= 0x20;
4316 reg <<= 1; 4618 reg <<= 1;
4317 outSISIDXREG(SISPART4,0x23,reg); 4619 outSISIDXREG(SISPART4, 0x23, reg);
4318 } 4620 }
4319 } else { 4621 } else {
4320 v2 &= ~0x10; 4622 v2 &= ~0x10;
4321 } 4623 }
4322 outSISIDXREG(SISSR,0x32,v2); 4624 outSISIDXREG(SISSR, 0x32, v2);
4323 andSISIDXREG(SISPART1,0x24,0xfe); /* Lock CRT2 */ 4625
4324 inSISIDXREG(SISSR,0x16,reg); 4626 andSISIDXREG(SISPART1, 0x24, 0xfe); /* Lock CRT2 */
4627
4628 inSISIDXREG(SISSR, 0x16, reg);
4325 reg &= 0xc3; 4629 reg &= 0xc3;
4326 outSISIDXREG(SISCR,0x35,reg); 4630 outSISIDXREG(SISCR, 0x35, reg);
4327 outSISIDXREG(SISCR,0x83,0x00); 4631 outSISIDXREG(SISCR, 0x83, 0x00);
4328#if !defined(__i386__) && !defined(__x86_64__) 4632#if !defined(__i386__) && !defined(__x86_64__)
4329 if(sisfb_videoram) { 4633 if(sisfb_videoram) {
4330 outSISIDXREG(SISSR,0x13,0x28); /* ? */ 4634 outSISIDXREG(SISSR, 0x13, 0x28); /* ? */
4331 reg = ((sisfb_videoram >> 10) - 1) | 0x40; 4635 reg = ((sisfb_videoram >> 10) - 1) | 0x40;
4332 outSISIDXREG(SISSR,0x14,reg); 4636 outSISIDXREG(SISSR, 0x14, reg);
4333 } else { 4637 } else {
4334#endif 4638#endif
4335 /* Need to map max FB size for finding out about RAM size */ 4639 /* Need to map max FB size for finding out about RAM size */
4336 ivideo->video_vbase = ioremap(ivideo->video_base, 0x4000000); 4640 mapsize = 64 << 20;
4337 if(ivideo->video_vbase) { 4641 sisfb_post_map_vram(ivideo, &mapsize, 4);
4338 sisfb_setramsize300(pdev); 4642
4339 iounmap(ivideo->video_vbase); 4643 if(ivideo->video_vbase) {
4340 } else { 4644 sisfb_post_300_ramsize(pdev, mapsize);
4341 printk(KERN_DEBUG "sisfb: Failed to map memory for size detection, assuming 8MB\n"); 4645 iounmap(ivideo->video_vbase);
4342 outSISIDXREG(SISSR,0x13,0x28); /* ? */ 4646 } else {
4343 outSISIDXREG(SISSR,0x14,0x47); /* 8MB, 64bit default */ 4647 printk(KERN_DEBUG
4344 } 4648 "sisfb: Failed to map memory for size detection, assuming 8MB\n");
4649 outSISIDXREG(SISSR, 0x13, 0x28); /* ? */
4650 outSISIDXREG(SISSR, 0x14, 0x47); /* 8MB, 64bit default */
4651 }
4345#if !defined(__i386__) && !defined(__x86_64__) 4652#if !defined(__i386__) && !defined(__x86_64__)
4346 } 4653 }
4347#endif 4654#endif
4348 if(ivideo->sishw_ext.UseROM) { 4655 if(bios) {
4349 v1 = ivideo->sishw_ext.pjVirtualRomBase[0xe6]; 4656 v1 = bios[0xe6];
4350 v2 = ivideo->sishw_ext.pjVirtualRomBase[0xe7]; 4657 v2 = bios[0xe7];
4351 } else { 4658 } else {
4352 inSISIDXREG(SISSR,0x3a,reg); 4659 inSISIDXREG(SISSR, 0x3a, reg);
4353 if((reg & 0x30) == 0x30) { 4660 if((reg & 0x30) == 0x30) {
4354 v1 = 0x04; /* PCI */ 4661 v1 = 0x04; /* PCI */
4355 v2 = 0x92; 4662 v2 = 0x92;
4356 } else { 4663 } else {
4357 v1 = 0x14; /* AGP */ 4664 v1 = 0x14; /* AGP */
4358 v2 = 0xb2; 4665 v2 = 0xb2;
4359 } 4666 }
4360 } 4667 }
4361 outSISIDXREG(SISSR,0x21,v1); 4668 outSISIDXREG(SISSR, 0x21, v1);
4362 outSISIDXREG(SISSR,0x22,v2); 4669 outSISIDXREG(SISSR, 0x22, v2);
4670
4671 /* Sense CRT1 */
4672 sisfb_sense_crt1(ivideo);
4673
4674 /* Set default mode, don't clear screen */
4675 ivideo->SiS_Pr.SiS_UseOEM = FALSE;
4676 SiS_SetEnableDstn(&ivideo->SiS_Pr, FALSE);
4677 SiS_SetEnableFstn(&ivideo->SiS_Pr, FALSE);
4678 ivideo->curFSTN = ivideo->curDSTN = 0;
4679 ivideo->SiS_Pr.VideoMemorySize = 8 << 20;
4680 SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80);
4681
4682 outSISIDXREG(SISSR, 0x05, 0x86);
4683
4684 /* Display off */
4685 orSISIDXREG(SISSR, 0x01, 0x20);
4686
4687 /* Save mode number in CR34 */
4688 outSISIDXREG(SISCR, 0x34, 0x2e);
4689
4690 /* Let everyone know what the current mode is */
4691 ivideo->modeprechange = 0x2e;
4363} 4692}
4364#endif 4693#endif
4365 4694
4366#ifdef CONFIG_FB_SIS_315 4695#ifdef CONFIG_FB_SIS_315
4367static void __devinit sisfb_post_sis315330(struct pci_dev *pdev) 4696#if 0
4697static void __devinit
4698sisfb_post_sis315330(struct pci_dev *pdev)
4368{ 4699{
4369#ifdef YET_TO_BE_DONE 4700 /* TODO */
4370 struct sis_video_info *ivideo = pci_get_drvdata(pdev); 4701}
4371 u8 reg, v1, v2, v3, v4, v5, v6, v7, v8; 4702#endif
4372 u16 index, rindex, memtype = 0; 4703
4373 u32 reg1_32, reg2_32, reg3_32; 4704static void __devinit
4705sisfb_post_xgi_delay(struct sis_video_info *ivideo, int delay)
4706{
4707 unsigned int i;
4708 u8 reg;
4709
4710 for(i = 0; i <= (delay * 10 * 36); i++) {
4711 inSISIDXREG(SISSR, 0x05, reg);
4712 reg++;
4713 }
4714}
4715
4716static int __devinit
4717sisfb_find_host_bridge(struct sis_video_info *ivideo, struct pci_dev *mypdev,
4718 unsigned short pcivendor)
4719{
4720 struct pci_dev *pdev = NULL;
4721 unsigned short temp;
4722 int ret = 0;
4723
4724 while((pdev = SIS_PCI_GET_CLASS(PCI_CLASS_BRIDGE_HOST, pdev))) {
4725 temp = pdev->vendor;
4726 SIS_PCI_PUT_DEVICE(pdev);
4727 if(temp == pcivendor) {
4728 ret = 1;
4729 break;
4730 }
4731 }
4732
4733 return ret;
4734}
4735
4736static int __devinit
4737sisfb_post_xgi_rwtest(struct sis_video_info *ivideo, int starta,
4738 unsigned int enda, unsigned int mapsize)
4739{
4740 unsigned int pos;
4374 int i; 4741 int i;
4375 4742
4376 /* Unlock */ 4743 writel(0, ivideo->video_vbase);
4377 /* outSISIDXREG(0x3c4,0x05,0x86); */
4378 outSISIDXREG(SISSR,0x05,0x86);
4379 4744
4380 /* Enable relocated i/o ports */ 4745 for(i = starta; i <= enda; i++) {
4381 /* setSISIDXREG(0x3c4,0x20,~0x10,0x20); */ 4746 pos = 1 << i;
4382 setSISIDXREG(SISSR,0x20,~0x10,0x20); 4747 if(pos < mapsize)
4748 writel(pos, ivideo->video_vbase + pos);
4749 }
4750
4751 sisfb_post_xgi_delay(ivideo, 150);
4752
4753 if(readl(ivideo->video_vbase) != 0)
4754 return 0;
4383 4755
4384 /* Clear regs */ 4756 for(i = starta; i <= enda; i++) {
4757 pos = 1 << i;
4758 if(pos < mapsize) {
4759 if(readl(ivideo->video_vbase + pos) != pos)
4760 return 0;
4761 } else
4762 return 0;
4763 }
4764
4765 return 1;
4766}
4767
4768static void __devinit
4769sisfb_post_xgi_ramsize(struct sis_video_info *ivideo)
4770{
4771 unsigned int buswidth, ranksize, channelab, mapsize;
4772 int i, j, k, l;
4773 u8 reg, sr14;
4774 static const u8 dramsr13[12 * 5] = {
4775 0x02, 0x0e, 0x0b, 0x80, 0x5d,
4776 0x02, 0x0e, 0x0a, 0x40, 0x59,
4777 0x02, 0x0d, 0x0b, 0x40, 0x4d,
4778 0x02, 0x0e, 0x09, 0x20, 0x55,
4779 0x02, 0x0d, 0x0a, 0x20, 0x49,
4780 0x02, 0x0c, 0x0b, 0x20, 0x3d,
4781 0x02, 0x0e, 0x08, 0x10, 0x51,
4782 0x02, 0x0d, 0x09, 0x10, 0x45,
4783 0x02, 0x0c, 0x0a, 0x10, 0x39,
4784 0x02, 0x0d, 0x08, 0x08, 0x41,
4785 0x02, 0x0c, 0x09, 0x08, 0x35,
4786 0x02, 0x0c, 0x08, 0x04, 0x31
4787 };
4788 static const u8 dramsr13_4[4 * 5] = {
4789 0x02, 0x0d, 0x09, 0x40, 0x45,
4790 0x02, 0x0c, 0x09, 0x20, 0x35,
4791 0x02, 0x0c, 0x08, 0x10, 0x31,
4792 0x02, 0x0b, 0x08, 0x08, 0x21
4793 };
4794
4795 /* Enable linear mode, disable 0xa0000 address decoding */
4796 /* We disable a0000 address decoding, because
4797 * - if running on x86, if the card is disabled, it means
4798 * that another card is in the system. We don't want
4799 * to interphere with that primary card's textmode.
4800 * - if running on non-x86, there usually is no VGA window
4801 * at a0000.
4802 */
4803 orSISIDXREG(SISSR, 0x20, (0x80 | 0x04));
4804
4805 /* Need to map max FB size for finding out about RAM size */
4806 mapsize = 256 << 20;
4807 sisfb_post_map_vram(ivideo, &mapsize, 32);
4808
4809 if(!ivideo->video_vbase) {
4810 printk(KERN_ERR "sisfb: Unable to detect RAM size. Setting default.\n");
4811 outSISIDXREG(SISSR, 0x13, 0x35);
4812 outSISIDXREG(SISSR, 0x14, 0x41);
4813 /* TODO */
4814 return;
4815 }
4816
4817 /* Non-interleaving */
4818 outSISIDXREG(SISSR, 0x15, 0x00);
4819 /* No tiling */
4820 outSISIDXREG(SISSR, 0x1c, 0x00);
4821
4822 if(ivideo->chip == XGI_20) {
4823
4824 channelab = 1;
4825 inSISIDXREG(SISCR, 0x97, reg);
4826 if(!(reg & 0x01)) { /* Single 32/16 */
4827 buswidth = 32;
4828 outSISIDXREG(SISSR, 0x13, 0xb1);
4829 outSISIDXREG(SISSR, 0x14, 0x52);
4830 sisfb_post_xgi_delay(ivideo, 1);
4831 sr14 = 0x02;
4832 if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize))
4833 goto bail_out;
4834
4835 outSISIDXREG(SISSR, 0x13, 0x31);
4836 outSISIDXREG(SISSR, 0x14, 0x42);
4837 sisfb_post_xgi_delay(ivideo, 1);
4838 if(sisfb_post_xgi_rwtest(ivideo, 23, 23, mapsize))
4839 goto bail_out;
4840
4841 buswidth = 16;
4842 outSISIDXREG(SISSR, 0x13, 0xb1);
4843 outSISIDXREG(SISSR, 0x14, 0x41);
4844 sisfb_post_xgi_delay(ivideo, 1);
4845 sr14 = 0x01;
4846 if(sisfb_post_xgi_rwtest(ivideo, 22, 23, mapsize))
4847 goto bail_out;
4848 else
4849 outSISIDXREG(SISSR, 0x13, 0x31);
4850 } else { /* Dual 16/8 */
4851 buswidth = 16;
4852 outSISIDXREG(SISSR, 0x13, 0xb1);
4853 outSISIDXREG(SISSR, 0x14, 0x41);
4854 sisfb_post_xgi_delay(ivideo, 1);
4855 sr14 = 0x01;
4856 if(sisfb_post_xgi_rwtest(ivideo, 22, 23, mapsize))
4857 goto bail_out;
4858
4859 outSISIDXREG(SISSR, 0x13, 0x31);
4860 outSISIDXREG(SISSR, 0x14, 0x31);
4861 sisfb_post_xgi_delay(ivideo, 1);
4862 if(sisfb_post_xgi_rwtest(ivideo, 22, 22, mapsize))
4863 goto bail_out;
4864
4865 buswidth = 8;
4866 outSISIDXREG(SISSR, 0x13, 0xb1);
4867 outSISIDXREG(SISSR, 0x14, 0x30);
4868 sisfb_post_xgi_delay(ivideo, 1);
4869 sr14 = 0x00;
4870 if(sisfb_post_xgi_rwtest(ivideo, 21, 22, mapsize))
4871 goto bail_out;
4872 else
4873 outSISIDXREG(SISSR, 0x13, 0x31);
4874 }
4875
4876 } else { /* XGI_40 */
4877
4878 inSISIDXREG(SISCR, 0x97, reg);
4879 if(!(reg & 0x10)) {
4880 inSISIDXREG(SISSR, 0x39, reg);
4881 reg >>= 1;
4882 }
4883
4884 if(reg & 0x01) { /* DDRII */
4885 buswidth = 32;
4886 if(ivideo->revision_id == 2) {
4887 channelab = 2;
4888 outSISIDXREG(SISSR, 0x13, 0xa1);
4889 outSISIDXREG(SISSR, 0x14, 0x44);
4890 sr14 = 0x04;
4891 sisfb_post_xgi_delay(ivideo, 1);
4892 if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize))
4893 goto bail_out;
4894
4895 outSISIDXREG(SISSR, 0x13, 0x21);
4896 outSISIDXREG(SISSR, 0x14, 0x34);
4897 if(sisfb_post_xgi_rwtest(ivideo, 22, 23, mapsize))
4898 goto bail_out;
4899
4900 channelab = 1;
4901 outSISIDXREG(SISSR, 0x13, 0xa1);
4902 outSISIDXREG(SISSR, 0x14, 0x40);
4903 sr14 = 0x00;
4904 if(sisfb_post_xgi_rwtest(ivideo, 22, 23, mapsize))
4905 goto bail_out;
4906
4907 outSISIDXREG(SISSR, 0x13, 0x21);
4908 outSISIDXREG(SISSR, 0x14, 0x30);
4909 } else {
4910 channelab = 3;
4911 outSISIDXREG(SISSR, 0x13, 0xa1);
4912 outSISIDXREG(SISSR, 0x14, 0x4c);
4913 sr14 = 0x0c;
4914 sisfb_post_xgi_delay(ivideo, 1);
4915 if(sisfb_post_xgi_rwtest(ivideo, 23, 25, mapsize))
4916 goto bail_out;
4917
4918 channelab = 2;
4919 outSISIDXREG(SISSR, 0x14, 0x48);
4920 sisfb_post_xgi_delay(ivideo, 1);
4921 sr14 = 0x08;
4922 if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize))
4923 goto bail_out;
4924
4925 outSISIDXREG(SISSR, 0x13, 0x21);
4926 outSISIDXREG(SISSR, 0x14, 0x3c);
4927 sr14 = 0x0c;
4928
4929 if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize)) {
4930 channelab = 3;
4931 } else {
4932 channelab = 2;
4933 outSISIDXREG(SISSR, 0x14, 0x38);
4934 sr14 = 0x08;
4935 }
4936 }
4937 sisfb_post_xgi_delay(ivideo, 1);
4938
4939 } else { /* DDR */
4940
4941 buswidth = 64;
4942 if(ivideo->revision_id == 2) {
4943 channelab = 1;
4944 outSISIDXREG(SISSR, 0x13, 0xa1);
4945 outSISIDXREG(SISSR, 0x14, 0x52);
4946 sisfb_post_xgi_delay(ivideo, 1);
4947 sr14 = 0x02;
4948 if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize))
4949 goto bail_out;
4950
4951 outSISIDXREG(SISSR, 0x13, 0x21);
4952 outSISIDXREG(SISSR, 0x14, 0x42);
4953 } else {
4954 channelab = 2;
4955 outSISIDXREG(SISSR, 0x13, 0xa1);
4956 outSISIDXREG(SISSR, 0x14, 0x5a);
4957 sisfb_post_xgi_delay(ivideo, 1);
4958 sr14 = 0x0a;
4959 if(sisfb_post_xgi_rwtest(ivideo, 24, 25, mapsize))
4960 goto bail_out;
4961
4962 outSISIDXREG(SISSR, 0x13, 0x21);
4963 outSISIDXREG(SISSR, 0x14, 0x4a);
4964 }
4965 sisfb_post_xgi_delay(ivideo, 1);
4966
4967 }
4968 }
4969
4970bail_out:
4971 setSISIDXREG(SISSR, 0x14, 0xf0, sr14);
4972 sisfb_post_xgi_delay(ivideo, 1);
4973
4974 j = (ivideo->chip == XGI_20) ? 5 : 9;
4975 k = (ivideo->chip == XGI_20) ? 12 : 4;
4976
4977 for(i = 0; i < k; i++) {
4978
4979 reg = (ivideo->chip == XGI_20) ?
4980 dramsr13[(i * 5) + 4] : dramsr13_4[(i * 5) + 4];
4981 setSISIDXREG(SISSR, 0x13, 0x80, reg);
4982 sisfb_post_xgi_delay(ivideo, 50);
4983
4984 ranksize = (ivideo->chip == XGI_20) ?
4985 dramsr13[(i * 5) + 3] : dramsr13_4[(i * 5) + 3];
4986
4987 inSISIDXREG(SISSR, 0x13, reg);
4988 if(reg & 0x80) ranksize <<= 1;
4989
4990 if(ivideo->chip == XGI_20) {
4991 if(buswidth == 16) ranksize <<= 1;
4992 else if(buswidth == 32) ranksize <<= 2;
4993 } else {
4994 if(buswidth == 64) ranksize <<= 1;
4995 }
4996
4997 reg = 0;
4998 l = channelab;
4999 if(l == 3) l = 4;
5000 if((ranksize * l) <= 256) {
5001 while((ranksize >>= 1)) reg += 0x10;
5002 }
5003
5004 if(!reg) continue;
5005
5006 setSISIDXREG(SISSR, 0x14, 0x0f, (reg & 0xf0));
5007 sisfb_post_xgi_delay(ivideo, 1);
5008
5009 if(sisfb_post_xgi_rwtest(ivideo, j, ((reg >> 4) + channelab - 2 + 20), mapsize))
5010 break;
5011 }
5012
5013 iounmap(ivideo->video_vbase);
5014}
5015
5016static void __devinit
5017sisfb_post_xgi_setclocks(struct sis_video_info *ivideo, u8 regb)
5018{
5019 u8 v1, v2, v3;
5020 int index;
5021 static const u8 cs90[8 * 3] = {
5022 0x16, 0x01, 0x01,
5023 0x3e, 0x03, 0x01,
5024 0x7c, 0x08, 0x01,
5025 0x79, 0x06, 0x01,
5026 0x29, 0x01, 0x81,
5027 0x5c, 0x23, 0x01,
5028 0x5c, 0x23, 0x01,
5029 0x5c, 0x23, 0x01
5030 };
5031 static const u8 csb8[8 * 3] = {
5032 0x5c, 0x23, 0x01,
5033 0x29, 0x01, 0x01,
5034 0x7c, 0x08, 0x01,
5035 0x79, 0x06, 0x01,
5036 0x29, 0x01, 0x81,
5037 0x5c, 0x23, 0x01,
5038 0x5c, 0x23, 0x01,
5039 0x5c, 0x23, 0x01
5040 };
5041
5042 regb = 0; /* ! */
5043
5044 index = regb * 3;
5045 v1 = cs90[index]; v2 = cs90[index + 1]; v3 = cs90[index + 2];
5046 if(ivideo->haveXGIROM) {
5047 v1 = ivideo->bios_abase[0x90 + index];
5048 v2 = ivideo->bios_abase[0x90 + index + 1];
5049 v3 = ivideo->bios_abase[0x90 + index + 2];
5050 }
5051 outSISIDXREG(SISSR, 0x28, v1);
5052 outSISIDXREG(SISSR, 0x29, v2);
5053 outSISIDXREG(SISSR, 0x2a, v3);
5054 sisfb_post_xgi_delay(ivideo, 0x43);
5055 sisfb_post_xgi_delay(ivideo, 0x43);
5056 sisfb_post_xgi_delay(ivideo, 0x43);
5057 index = regb * 3;
5058 v1 = csb8[index]; v2 = csb8[index + 1]; v3 = csb8[index + 2];
5059 if(ivideo->haveXGIROM) {
5060 v1 = ivideo->bios_abase[0xb8 + index];
5061 v2 = ivideo->bios_abase[0xb8 + index + 1];
5062 v3 = ivideo->bios_abase[0xb8 + index + 2];
5063 }
5064 outSISIDXREG(SISSR, 0x2e, v1);
5065 outSISIDXREG(SISSR, 0x2f, v2);
5066 outSISIDXREG(SISSR, 0x30, v3);
5067 sisfb_post_xgi_delay(ivideo, 0x43);
5068 sisfb_post_xgi_delay(ivideo, 0x43);
5069 sisfb_post_xgi_delay(ivideo, 0x43);
5070}
5071
5072static int __devinit
5073sisfb_post_xgi(struct pci_dev *pdev)
5074{
5075 struct sis_video_info *ivideo = pci_get_drvdata(pdev);
5076 unsigned char *bios = ivideo->bios_abase;
5077 struct pci_dev *mypdev = NULL;
5078 const u8 *ptr, *ptr2;
5079 u8 v1, v2, v3, v4, v5, reg, ramtype;
5080 u32 rega, regb, regd;
5081 int i, j, k, index;
5082 static const u8 cs78[3] = { 0xf6, 0x0d, 0x00 };
5083 static const u8 cs76[2] = { 0xa3, 0xfb };
5084 static const u8 cs7b[3] = { 0xc0, 0x11, 0x00 };
5085 static const u8 cs158[8] = {
5086 0x88, 0xaa, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00
5087 };
5088 static const u8 cs160[8] = {
5089 0x44, 0x77, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00
5090 };
5091 static const u8 cs168[8] = {
5092 0x48, 0x78, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00
5093 };
5094 static const u8 cs128[3 * 8] = {
5095 0x90, 0x28, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
5096 0x77, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
5097 0x77, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00
5098 };
5099 static const u8 cs148[2 * 8] = {
5100 0x55, 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00,
5101 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
5102 };
5103 static const u8 cs31a[8 * 4] = {
5104 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
5105 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
5106 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5107 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
5108 };
5109 static const u8 cs33a[8 * 4] = {
5110 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5111 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5112 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5113 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
5114 };
5115 static const u8 cs45a[8 * 2] = {
5116 0x00, 0x00, 0xa0, 0x00, 0xa0, 0x00, 0x00, 0x00,
5117 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
5118 };
5119 static const u8 cs170[7 * 8] = {
5120 0x54, 0x32, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
5121 0x54, 0x43, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
5122 0x0a, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
5123 0x44, 0x34, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
5124 0x10, 0x0a, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
5125 0x11, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
5126 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00
5127 };
5128 static const u8 cs1a8[3 * 8] = {
5129 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
5130 0x05, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
5131 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
5132 };
5133 static const u8 cs100[2 * 8] = {
5134 0xc4, 0x04, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00,
5135 0xc4, 0x04, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
5136 };
5137
5138 /* VGA enable */
5139 reg = inSISREG(SISVGAENABLE) | 0x01;
5140 outSISREG(SISVGAENABLE, reg);
5141
5142 /* Misc */
5143 reg = inSISREG(SISMISCR) | 0x01;
5144 outSISREG(SISMISCW, reg);
5145
5146 /* Unlock SR */
5147 outSISIDXREG(SISSR, 0x05, 0x86);
5148 inSISIDXREG(SISSR, 0x05, reg);
5149 if(reg != 0xa1)
5150 return 0;
5151
5152 /* Clear some regs */
4385 for(i = 0; i < 0x22; i++) { 5153 for(i = 0; i < 0x22; i++) {
4386 outSISIDXREG(SISSR,(0x06 + i),0x00); 5154 if(0x06 + i == 0x20) continue;
5155 outSISIDXREG(SISSR, 0x06 + i, 0x00);
4387 } 5156 }
4388 v1 = 0x0d; 5157 for(i = 0; i < 0x0b; i++) {
4389 if( is 330) v1 = 0x0b; 5158 outSISIDXREG(SISSR, 0x31 + i, 0x00);
4390 for(i = 0; i < v1; i++) {
4391 outSISIDXREG(SISSR,(0x31 + i),0x00);
4392 } 5159 }
4393 for(i = 0; i < 0x10; i++) { 5160 for(i = 0; i < 0x10; i++) {
4394 outSISIDXREG(SISCR,(0x30 + i),0x00); 5161 outSISIDXREG(SISCR, 0x30 + i, 0x00);
4395 }
4396
4397 /* Reset clocks */
4398 reg = inSISREG(SISMISCR);
4399 outSISIDXREG(SISSR,0x28,0x81);
4400 outSISIDXREG(SISSR,0x2A,0x00);
4401 outSISIDXREG(SISSR,0x29,0xE1);
4402 outSISREG(SISMISCW,(reg | 0x0c));
4403 outSISIDXREG(SISSR,0x2B,0x81);
4404 outSISIDXREG(SISSR,0x2D,0x00);
4405 outSISIDXREG(SISSR,0x2C,0xE1);
4406 outSISIDXREG(SISSR,0x2E,0x81);
4407 outSISIDXREG(SISSR,0x30,0x00);
4408 outSISIDXREG(SISSR,0x2F,0xE1);
4409 SiS_DDC2Delay(....);
4410 outSISREG(SISMISCW,reg);
4411
4412 /* Get memory type */
4413 if(ivideo->sishw_ext.UseROM) {
4414 if(ivideo->sishw_ext.pjVirtualRomBase[0x52] & 0x80)) {
4415 memtype = ivideo->sishw_ext.pjVirtualRomBase[0x52];
4416 } else {
4417 inSISIDXREG(SISSR,0x3a,memtype);
4418 }
4419 memtype &= 0x03;
4420 if( is 330 ) {
4421 if(memtype <= 1) memtype = 0;
4422 else {
4423 inSISIDXREG(SISCR,0x5F,reg);
4424 reg &= 0x30;
4425 switch(reg) {
4426 case 0x00: memtype = 1; break;
4427 case 0x10: memtype = 3; break;
4428 case 0x20: memtype = 3; break;
4429 default: memtype = 2;
4430 }
4431 }
4432 }
4433 } 5162 }
4434 5163
4435 /* Set clocks */ 5164 ptr = cs78;
4436 v1 = 0x3b; v2 = 0x22; v3 = 0x01; /* Assume 143Mhz MCLK */ 5165 if(ivideo->haveXGIROM) {
4437 v4 = 0x5c; v5 = 0x23; v6 = 0x01; /* Assume 166Mhz ECLK */ 5166 ptr = (const u8 *)&bios[0x78];
4438 if(ivideo->sishw_ext.UseROM) { 5167 }
4439 index = memtype * 5; 5168 for(i = 0; i < 3; i++) {
4440 rindex = index + 0x54; 5169 outSISIDXREG(SISSR, 0x23 + i, ptr[i]);
4441 v1 = ivideo->sishw_ext.pjVirtualRomBase[rindex++]; 5170 }
4442 v2 = ivideo->sishw_ext.pjVirtualRomBase[rindex++]; 5171
4443 v3 = ivideo->sishw_ext.pjVirtualRomBase[rindex++]; 5172 ptr = cs76;
4444 rindex = index + 0x68; 5173 if(ivideo->haveXGIROM) {
4445 v4 = ivideo->sishw_ext.pjVirtualRomBase[rindex++]; 5174 ptr = (const u8 *)&bios[0x76];
4446 v5 = ivideo->sishw_ext.pjVirtualRomBase[rindex++]; 5175 }
4447 v6 = ivideo->sishw_ext.pjVirtualRomBase[rindex++]; 5176 for(i = 0; i < 2; i++) {
4448 } 5177 outSISIDXREG(SISSR, 0x21 + i, ptr[i]);
4449 outSISIDXREG(SISSR,0x28,v1); 5178 }
4450 outSISIDXREG(SISSR,0x29,v2); 5179
4451 outSISIDXREG(SISSR,0x2a,v3); 5180 v1 = 0x18; v2 = 0x00;
4452 if( is 330 ) { 5181 if(ivideo->haveXGIROM) {
4453 inSISIDXREG(SISSR,0x3a,reg); 5182 v1 = bios[0x74];
4454 reg &= 0x03; 5183 v2 = bios[0x75];
4455 if(reg >= 2) { 5184 }
4456 ... 5185 outSISIDXREG(SISSR, 0x07, v1);
4457 } 5186 outSISIDXREG(SISSR, 0x11, 0x0f);
5187 outSISIDXREG(SISSR, 0x1f, v2);
5188 /* PCI linear mode, RelIO enabled, A0000 decoding disabled */
5189 outSISIDXREG(SISSR, 0x20, 0x80 | 0x20 | 0x04);
5190 outSISIDXREG(SISSR, 0x27, 0x74);
5191
5192 ptr = cs7b;
5193 if(ivideo->haveXGIROM) {
5194 ptr = (const u8 *)&bios[0x7b];
5195 }
5196 for(i = 0; i < 3; i++) {
5197 outSISIDXREG(SISSR, 0x31 + i, ptr[i]);
4458 } 5198 }
4459 outSISIDXREG(SISSR,0x2e,v4);
4460 outSISIDXREG(SISSR,0x2f,v5);
4461 outSISIDXREG(SISSR,0x30,v6);
4462
4463 /* End of comp with 330 */
4464
4465 v1 = 0x18;
4466 if(ivideo->sishw_ext.UseROM) v1 = ivideo->sishw_ext.pjVirtualRomBase[0x7c];
4467 outSISIDXREG(SISSR,0x07,v1);
4468 outSISIDXREG(SISSR,0x11,0x0f);
4469
4470 v1 = 0x00; v2 = 0x0f; v3 = 0xba; v4 = 0xa9;
4471 v5 = 0xa0; v6 = 0x00; v7 = 0x30;
4472 if(ivideo->sishw_ext.UseROM) {
4473 index = memtype + 0x7d;
4474 v1 = ivideo->sishw_ext.pjVirtualRomBase[index];
4475 v2 = ivideo->sishw_ext.pjVirtualRomBase[index + 4];
4476 v3 = ivideo->sishw_ext.pjVirtualRomBase[index + 8];
4477 v4 = ivideo->sishw_ext.pjVirtualRomBase[index + 12];
4478 v5 = ivideo->sishw_ext.pjVirtualRomBase[index + 16];
4479 v6 = ivideo->sishw_ext.pjVirtualRomBase[index + 20];
4480 v7 = ivideo->sishw_ext.pjVirtualRomBase[index + 24];
4481 }
4482 outSISIDXREG(SISSR,0x15,v1); /* Ram type (assuming 0, BIOS 0x7d step 4) */
4483 outSISIDXREG(SISSR,0x16,v2);
4484 outSISIDXREG(SISSR,0x17,v3);
4485 outSISIDXREG(SISSR,0x18,v4);
4486 outSISIDXREG(SISSR,0x19,v5);
4487 outSISIDXREG(SISSR,0x1a,v6);
4488 outSISIDXREG(SISSR,0x1b,v7);
4489 outSISIDXREG(SISSR,0x1c,v8); /* ---- */
4490
4491 v1 = 0x77; v2 = 0x77; v3 = 0x00; v4 = 0x5b; v5 = 0x00;
4492 if(ivideo->sishw_ext.UseROM) {
4493 index = memtype + 0xa2;
4494 v1 = ivideo->sishw_ext.pjVirtualRomBase[index];
4495 v2 = ivideo->sishw_ext.pjVirtualRomBase[index + 4];
4496 v3 = ivideo->sishw_ext.pjVirtualRomBase[index + 8];
4497 v4 = ivideo->sishw_ext.pjVirtualRomBase[index + 12];
4498 v5 = ivideo->sishw_ext.pjVirtualRomBase[index + 16];
4499 }
4500 outSISIDXREG(SISCR,0x40,v1);
4501 outSISIDXREG(SISCR,0x41,v2);
4502 outSISIDXREG(SISCR,0x42,v3);
4503 outSISIDXREG(SISCR,0x43,v4);
4504 outSISIDXREG(SISCR,0x44,v5);
4505
4506 if( is 330 ) {
4507
4508 v1 = 0x;
4509 if(ivideo->sishw_ext.UseROM) {
4510 v1 = ivideo->sishw_ext.pjVirtualRomBase[0xBA];
4511 }
4512 outSISIDXREG(SISCR,0x59,v1);
4513
4514 v1 = 0x; v2 = 0x; v3 = 0x; v4 = 0x;
4515 v5 = 0x; v6 = 0x; v7 = 0x; v8 = 0x;
4516 if(ivideo->sishw_ext.UseROM) {
4517 index = memtype + 0xbe;
4518 v1 = ivideo->sishw_ext.pjVirtualRomBase[index];
4519 v2 = ivideo->sishw_ext.pjVirtualRomBase[index + 4];
4520 v3 = ivideo->sishw_ext.pjVirtualRomBase[index + 8];
4521 v4 = ivideo->sishw_ext.pjVirtualRomBase[index + 12];
4522 v5 = ivideo->sishw_ext.pjVirtualRomBase[index + 16];
4523 v6 = ivideo->sishw_ext.pjVirtualRomBase[index + 20];
4524 v7 = ivideo->sishw_ext.pjVirtualRomBase[index + 24];
4525 v8 = ivideo->sishw_ext.pjVirtualRomBase[index + 28];
4526 }
4527 outSISIDXREG(SISCR,0x68,v1);
4528 outSISIDXREG(SISCR,0x69,v2);
4529 outSISIDXREG(SISCR,0x6a,v3);
4530 outSISIDXREG(SISCR,0x6b,v4);
4531 outSISIDXREG(SISCR,0x6c,v5);
4532 outSISIDXREG(SISCR,0x6d,v6);
4533 outSISIDXREG(SISCR,0x6e,v7);
4534 outSISIDXREG(SISCR,0x6f,v8);
4535
4536 v1 = 0x20;
4537 inSISIDXREG(SISSR,0x3b,reg);
4538
4539 if(!(reg & 0x04)) {
4540 inSISIDXREG(SISCR,0x5F,reg);
4541 reg &= 0x30;
4542 if(reg) v1 = 0x23;
4543 }
4544 outSISIDXREG(SISCR,0x48,v1);
4545 outSISIDXREG(SISCR,0x4c,0x20);
4546
4547 xx= xxx();
4548 if(xx >= 1) {
4549 v1 = 0x;
4550 if(ivideo->sishw_ext.UseROM) {
4551 v1 = ivideo->sishw_ext.pjVirtualRomBase[0xBA];
4552 }
4553 outSISIDXREG(SISCR,0x59,v1);
4554 }
4555 5199
5200 if(ivideo->chip == XGI_40) {
5201 if(ivideo->revision_id == 2) {
5202 setSISIDXREG(SISSR, 0x3b, 0x3f, 0xc0);
5203 }
5204 outSISIDXREG(SISCR, 0x7d, 0xfe);
5205 outSISIDXREG(SISCR, 0x7e, 0x0f);
5206 }
5207 if(ivideo->revision_id == 0) { /* 40 *and* 20? */
5208 andSISIDXREG(SISCR, 0x58, 0xd7);
5209 inSISIDXREG(SISCR, 0xcb, reg);
5210 if(reg & 0x20) {
5211 setSISIDXREG(SISCR, 0x58, 0xd7, (reg & 0x10) ? 0x08 : 0x20); /* =0x28 Z7 ? */
5212 }
5213 }
4556 5214
5215 reg = (ivideo->chip == XGI_40) ? 0x20 : 0x00;
5216 setSISIDXREG(SISCR, 0x38, 0x1f, reg);
4557 5217
5218 if(ivideo->chip == XGI_20) {
5219 outSISIDXREG(SISSR, 0x36, 0x70);
4558 } else { 5220 } else {
5221 outSISIDXREG(SISVID, 0x00, 0x86);
5222 outSISIDXREG(SISVID, 0x32, 0x00);
5223 outSISIDXREG(SISVID, 0x30, 0x00);
5224 outSISIDXREG(SISVID, 0x32, 0x01);
5225 outSISIDXREG(SISVID, 0x30, 0x00);
5226 andSISIDXREG(SISVID, 0x2f, 0xdf);
5227 andSISIDXREG(SISCAP, 0x00, 0x3f);
5228
5229 outSISIDXREG(SISPART1, 0x2f, 0x01);
5230 outSISIDXREG(SISPART1, 0x00, 0x00);
5231 outSISIDXREG(SISPART1, 0x02, bios[0x7e]);
5232 outSISIDXREG(SISPART1, 0x2e, 0x08);
5233 andSISIDXREG(SISPART1, 0x35, 0x7f);
5234 andSISIDXREG(SISPART1, 0x50, 0xfe);
5235
5236 inSISIDXREG(SISPART4, 0x00, reg);
5237 if(reg == 1 || reg == 2) {
5238 outSISIDXREG(SISPART2, 0x00, 0x1c);
5239 outSISIDXREG(SISPART4, 0x0d, bios[0x7f]);
5240 outSISIDXREG(SISPART4, 0x0e, bios[0x80]);
5241 outSISIDXREG(SISPART4, 0x10, bios[0x81]);
5242 andSISIDXREG(SISPART4, 0x0f, 0x3f);
5243
5244 inSISIDXREG(SISPART4, 0x01, reg);
5245 if((reg & 0xf0) >= 0xb0) {
5246 inSISIDXREG(SISPART4, 0x23, reg);
5247 if(reg & 0x20) reg |= 0x40;
5248 outSISIDXREG(SISPART4, 0x23, reg);
5249 reg = (reg & 0x20) ? 0x02 : 0x00;
5250 setSISIDXREG(SISPART1, 0x1e, 0xfd, reg);
5251 }
5252 }
4559 5253
4560 outSISIDXREG(SISCR,0x48,0x23); 5254 v1 = bios[0x77];
5255
5256 inSISIDXREG(SISSR, 0x3b, reg);
5257 if(reg & 0x02) {
5258 inSISIDXREG(SISSR, 0x3a, reg);
5259 v2 = (reg & 0x30) >> 3;
5260 if(!(v2 & 0x04)) v2 ^= 0x02;
5261 inSISIDXREG(SISSR, 0x39, reg);
5262 if(reg & 0x80) v2 |= 0x80;
5263 v2 |= 0x01;
5264
5265 if((mypdev = SIS_PCI_GET_DEVICE(PCI_VENDOR_ID_SI, 0x0730, NULL))) {
5266 SIS_PCI_PUT_DEVICE(mypdev);
5267 if(((v2 & 0x06) == 2) || ((v2 & 0x06) == 4))
5268 v2 &= 0xf9;
5269 v2 |= 0x08;
5270 v1 &= 0xfe;
5271 } else {
5272 mypdev = SIS_PCI_GET_DEVICE(PCI_VENDOR_ID_SI, 0x0735, NULL);
5273 if(!mypdev)
5274 mypdev = SIS_PCI_GET_DEVICE(PCI_VENDOR_ID_SI, 0x0645, NULL);
5275 if(!mypdev)
5276 mypdev = SIS_PCI_GET_DEVICE(PCI_VENDOR_ID_SI, 0x0650, NULL);
5277 if(mypdev) {
5278 pci_read_config_dword(mypdev, 0x94, &regd);
5279 regd &= 0xfffffeff;
5280 pci_write_config_dword(mypdev, 0x94, regd);
5281 v1 &= 0xfe;
5282 SIS_PCI_PUT_DEVICE(mypdev);
5283 } else if(sisfb_find_host_bridge(ivideo, pdev, PCI_VENDOR_ID_SI)) {
5284 v1 &= 0xfe;
5285 } else if(sisfb_find_host_bridge(ivideo, pdev, 0x1106) ||
5286 sisfb_find_host_bridge(ivideo, pdev, 0x1022) ||
5287 sisfb_find_host_bridge(ivideo, pdev, 0x700e) ||
5288 sisfb_find_host_bridge(ivideo, pdev, 0x10de)) {
5289 if((v2 & 0x06) == 4)
5290 v2 ^= 0x06;
5291 v2 |= 0x08;
5292 }
5293 }
5294 setSISIDXREG(SISCR, 0x5f, 0xf0, v2);
5295 }
5296 outSISIDXREG(SISSR, 0x22, v1);
5297
5298 if(ivideo->revision_id == 2) {
5299 inSISIDXREG(SISSR, 0x3b, v1);
5300 inSISIDXREG(SISSR, 0x3a, v2);
5301 regd = bios[0x90 + 3] | (bios[0x90 + 4] << 8);
5302 if( (!(v1 & 0x02)) && (v2 & 0x30) && (regd < 0xcf) )
5303 setSISIDXREG(SISCR, 0x5f, 0xf1, 0x01);
5304
5305 if((mypdev = SIS_PCI_GET_DEVICE(0x10de, 0x01e0, NULL))) {
5306 /* TODO: set CR5f &0xf1 | 0x01 for version 6570
5307 * of nforce 2 ROM
5308 */
5309 if(0)
5310 setSISIDXREG(SISCR, 0x5f, 0xf1, 0x01);
5311 SIS_PCI_PUT_DEVICE(mypdev);
5312 }
5313 }
4561 5314
4562 andSISIDXREG(SISSR,0x16,0x0f); 5315 v1 = 0x30;
4563 if(memtype <= 1) { 5316 inSISIDXREG(SISSR, 0x3b, reg);
4564 orSISIDXREG(SISSR,0x16,0x80); 5317 inSISIDXREG(SISCR, 0x5f, v2);
4565 } else { 5318 if((!(reg & 0x02)) && (v2 & 0x0e))
4566 v1 = 0x0f; 5319 v1 |= 0x08;
4567 if(ivideo->sishw_ext.UseROM) { 5320 outSISIDXREG(SISSR, 0x27, v1);
4568 v1 = ivideo->sishw_ext.pjVirtualRomBase[0x81 + memtype]; 5321
4569 } 5322 if(bios[0x64] & 0x01) {
4570 if(!(v1 & 0x10)) v2 = 0xc0; 5323 setSISIDXREG(SISCR, 0x5f, 0xf0, bios[0x64]);
4571 else v2 = 0xd0; 5324 }
4572 orSISIDXREG(SISSR,0x16,v2);
4573 andSISIDXREG(SISSR,0x16,0x0f);
4574 if(!(v1 & 0x10)) v2 = 0x80;
4575 else v2 = 0xA0;
4576 orSISIDXREG(SISSR,0x16,v2);
4577 }
4578
4579 if(memtype >= 2) {
4580 const u8 sr3cseq1[] = { 0xc0,0xe0,0xf0,0xe0,0xf0,0xa0,0xb0,0xa0,0xb0,0x90,0xd0 };
4581 const u8 sr3cseq2[] = { 0xc0,0xa0,0xb0,0xa0,0xb0,0xe0,0xf0,0xa0,0xb0,0x90,0xd0 };
4582 for(i = 0; i < 11; i++) {
4583 outSISIDXREG(SISSR,0x3c,sr3cseq1[i]);
4584 }
4585 outSISIDXREG(SISSR,0x3d,0x00);
4586 outSISIDXREG(SISSR,0x3d,0x04);
4587 SiS_DDC2Delay(0x200);
4588 v1 = inSISIDXREG(SISCR,0xEC);
4589 v2 = inSISIDXREG(SISCR,0xED);
4590 reg1_32 = (v2 << 8) | v1;
4591 outSISIDXREG(SISSR,0x3D,0x00);
4592 for(i = 0; i < 11; i++) {
4593 outSISIDXREG(SISSR,0x3c,sr3cseq2[i]);
4594 }
4595 outSISIDXREG(SISSR,0x3d,0x00);
4596 outSISIDXREG(SISSR,0x3d,0x04);
4597 SiS_DDC2Delay(0x200);
4598 v1 = inSISIDXREG(SISCR,0xEC);
4599 v2 = inSISIDXREG(SISCR,0xED);
4600 reg2_32 = (v2 << 8) | v1;
4601 outSISIDXREG(SISSR,0x3D,0x00);
4602 reg3_32 = reg2_32 << 1;
4603 reg2_32 >>= 1;
4604 reg3_32 += reg2_32;
4605 v1 = 0x40;
4606 if(reg3_32 > reg1_32) v1 = 0x10;
4607 outSISIDXREG(SISCR,0x59,v1);
4608 }
4609 5325
5326 v1 = bios[0x4f7];
5327 pci_read_config_dword(pdev, 0x50, &regd);
5328 regd = (regd >> 20) & 0x0f;
5329 if(regd == 1) {
5330 v1 &= 0xfc;
5331 orSISIDXREG(SISCR, 0x5f, 0x08);
5332 }
5333 outSISIDXREG(SISCR, 0x48, v1);
5334
5335 setSISIDXREG(SISCR, 0x47, 0x04, bios[0x4f6] & 0xfb);
5336 setSISIDXREG(SISCR, 0x49, 0xf0, bios[0x4f8] & 0x0f);
5337 setSISIDXREG(SISCR, 0x4a, 0x60, bios[0x4f9] & 0x9f);
5338 setSISIDXREG(SISCR, 0x4b, 0x08, bios[0x4fa] & 0xf7);
5339 setSISIDXREG(SISCR, 0x4c, 0x80, bios[0x4fb] & 0x7f);
5340 outSISIDXREG(SISCR, 0x70, bios[0x4fc]);
5341 setSISIDXREG(SISCR, 0x71, 0xf0, bios[0x4fd] & 0x0f);
5342 outSISIDXREG(SISCR, 0x74, 0xd0);
5343 setSISIDXREG(SISCR, 0x74, 0xcf, bios[0x4fe] & 0x30);
5344 setSISIDXREG(SISCR, 0x75, 0xe0, bios[0x4ff] & 0x1f);
5345 setSISIDXREG(SISCR, 0x76, 0xe0, bios[0x500] & 0x1f);
5346 v1 = bios[0x501];
5347 if((mypdev = SIS_PCI_GET_DEVICE(0x8086, 0x2530, NULL))) {
5348 v1 = 0xf0;
5349 SIS_PCI_PUT_DEVICE(mypdev);
5350 }
5351 outSISIDXREG(SISCR, 0x77, v1);
4610 } 5352 }
4611 5353
4612 v1 = 0x00; 5354 /* RAM type */
4613 if(ivideo->sishw_ext.UseROM) { 5355
4614 v1 = ivideo->sishw_ext.pjVirtualRomBase[0x99]; 5356 regb = 0; /* ! */
5357
5358 v1 = 0xff;
5359 if(ivideo->haveXGIROM) {
5360 v1 = bios[0x140 + regb];
4615 } 5361 }
4616 outSISIDXREG(SISSR,0x1f,v1); 5362 outSISIDXREG(SISCR, 0x6d, v1);
4617 5363
4618 outSISIDXREG(SISSR,0x20,0x20); 5364 ptr = cs128;
5365 if(ivideo->haveXGIROM) {
5366 ptr = (const u8 *)&bios[0x128];
5367 }
5368 for(i = 0, j = 0; i < 3; i++, j += 8) {
5369 outSISIDXREG(SISCR, 0x68 + i, ptr[j + regb]);
5370 }
4619 5371
4620 v1 = 0xf6; v2 = 0x0d; v3 = 0x33; 5372 ptr = cs31a;
4621 if(ivideo->sishw_ext.UseROM) { 5373 ptr2 = cs33a;
4622 v1 = ivideo->sishw_ext.pjVirtualRomBase[0x9c]; 5374 if(ivideo->haveXGIROM) {
4623 v2 = ivideo->sishw_ext.pjVirtualRomBase[0x9d]; 5375 index = (ivideo->chip == XGI_20) ? 0x31a : 0x3a6;
4624 v3 = ivideo->sishw_ext.pjVirtualRomBase[0x9e]; 5376 ptr = (const u8 *)&bios[index];
5377 ptr2 = (const u8 *)&bios[index + 0x20];
5378 }
5379 for(i = 0; i < 2; i++) {
5380 if(i == 0) {
5381 regd = le32_to_cpu(((u32 *)ptr)[regb]);
5382 rega = 0x6b;
5383 } else {
5384 regd = le32_to_cpu(((u32 *)ptr2)[regb]);
5385 rega = 0x6e;
5386 }
5387 reg = 0x00;
5388 for(j = 0; j < 16; j++) {
5389 reg &= 0xf3;
5390 if(regd & 0x01) reg |= 0x04;
5391 if(regd & 0x02) reg |= 0x08;
5392 regd >>= 2;
5393 outSISIDXREG(SISCR, rega, reg);
5394 inSISIDXREG(SISCR, rega, reg);
5395 inSISIDXREG(SISCR, rega, reg);
5396 reg += 0x10;
5397 }
4625 } 5398 }
4626 outSISIDXREG(SISSR,0x23,v1);
4627 outSISIDXREG(SISSR,0x24,v2);
4628 outSISIDXREG(SISSR,0x25,v3);
4629 5399
4630 outSISIDXREG(SISSR,0x21,0x84); 5400 andSISIDXREG(SISCR, 0x6e, 0xfc);
4631 outSISIDXREG(SISSR,0x22,0x00);
4632 outSISIDXREG(SISSR,0x27,0x1f);
4633 5401
4634 v1 = 0x00; v2 = 0x00; 5402 ptr = NULL;
4635 if(ivideo->sishw_ext.UseROM) { 5403 if(ivideo->haveXGIROM) {
4636 v1 = ivideo->sishw_ext.pjVirtualRomBase[0x9F]; 5404 index = (ivideo->chip == XGI_20) ? 0x35a : 0x3e6;
4637 v2 = ivideo->sishw_ext.pjVirtualRomBase[0xA1]; 5405 ptr = (const u8 *)&bios[index];
4638 } 5406 }
4639 outSISIDXREG(SISSR,0x31,v1); 5407 for(i = 0; i < 4; i++) {
4640 outSISIDXREG(SISSR,0x33,v2); 5408 setSISIDXREG(SISCR, 0x6e, 0xfc, i);
4641 5409 reg = 0x00;
4642 v1 = 0x11; 5410 for(j = 0; j < 2; j++) {
4643 if(ivideo->sishw_ext.UseROM) { 5411 regd = 0;
4644 v1 = ivideo->sishw_ext.pjVirtualRomBase[0xA0]; 5412 if(ptr) {
4645 } 5413 regd = le32_to_cpu(((u32 *)ptr)[regb * 8]);
4646 v2 = inSISIDXREG(SISPART4,0x00); 5414 ptr += 4;
4647 if((v2 != 1) && (v2 != 2)) v1 &= 0xef; 5415 }
4648 outSISIDXREG(SISSR,0x32,v1); 5416 /* reg = 0x00; */
4649 5417 for(k = 0; k < 16; k++) {
4650 /* AGP */ 5418 reg &= 0xfc;
4651 pci_read_config_long(pdev, 0x50, &reg1_32); 5419 if(regd & 0x01) reg |= 0x01;
4652 reg1_32 >>= 20; 5420 if(regd & 0x02) reg |= 0x02;
4653 reg1_32 &= 0x0f; 5421 regd >>= 2;
4654 if(reg1_32 == 1) { 5422 outSISIDXREG(SISCR, 0x6f, reg);
4655 v1 = 0xAA; v2 = 0x33; 5423 inSISIDXREG(SISCR, 0x6f, reg);
4656 if(ivideo->sishw_ext.UseROM) { 5424 inSISIDXREG(SISCR, 0x6f, reg);
4657 v1 = ivideo->sishw_ext.pjVirtualRomBase[0xF7]; 5425 reg += 0x08;
4658 v2 = ivideo->sishw_ext.pjVirtualRomBase[0x9E]; 5426 }
4659 } 5427 }
4660 } else {
4661 v1 = 0x88; v2 = 0x03;
4662 if(ivideo->sishw_ext.UseROM) {
4663 v1 = ivideo->sishw_ext.pjVirtualRomBase[0xF8];
4664 v2 = ivideo->sishw_ext.pjVirtualRomBase[0xF6];
4665 }
4666 } 5428 }
4667 outSISIDXREG(SISCR,0x49,v1);
4668 outSISIDXREG(SISSR,0x25,v2);
4669 5429
4670 v1 = inSISIDXREG(SISPART4,0x00); 5430 ptr = cs148;
4671 if((v1 == 1) || (v1 == 2)) { 5431 if(ivideo->haveXGIROM) {
4672 orSISIDXREG(SISPART1,0x2F,0x01); /* Unlock CRT2 */ 5432 ptr = (const u8 *)&bios[0x148];
4673 outSISIDXREG(SISPART1,0x00,0x00); 5433 }
4674 v1 = 0x00; 5434 for(i = 0, j = 0; i < 2; i++, j += 8) {
4675 if(ivideo->sishw_ext.UseROM) { 5435 outSISIDXREG(SISCR, 0x80 + i, ptr[j + regb]);
4676 v1 = ivideo->sishw_ext.pjVirtualRomBase[0xb6];
4677 }
4678 outSISIDXREG(SISPART1,0x02,v1);
4679 outSISIDXREG(SISPART1,0x2E,0x08);
4680 outSISIDXREG(SISPART2,0x00,0x1c);
4681 v1 = 0x40; v2 = 0x00; v3 = 0x80;
4682 if(ivideo->sishw_ext.UseROM) {
4683 v1 = ivideo->sishw_ext.pjVirtualRomBase[0xb7];
4684 v2 = ivideo->sishw_ext.pjVirtualRomBase[0xb8];
4685 v3 = ivideo->sishw_ext.pjVirtualRomBase[0xbb];
4686 }
4687 outSISIDXREG(SISPART4,0x0d,v1);
4688 outSISIDXREG(SISPART4,0x0e,v2);
4689 outSISIDXREG(SISPART4,0x10,v3);
4690 outSISIDXREG(SISPART4,0x0F,0x3F);
4691
4692 inSISIDXREG(SISPART4,0x01,reg);
4693 if(reg >= 0xb0) {
4694 inSISIDXREG(SISPART4,0x23,reg);
4695 reg &= 0x20;
4696 reg <<= 1;
4697 outSISIDXREG(SISPART4,0x23,reg);
4698 }
4699 } 5436 }
4700 outSISIDXREG(SISCR,0x37,0x02); /* Why? */
4701
4702 outSISIDXREG(SISCR,0x83,0x00);
4703 outSISIDXREG(SISCR,0x90,0x00);
4704 andSISIDXREG(SISSR,0x5B,0xDF);
4705 outSISIDXREG(SISVID,0x00,0x86);
4706 outSISIDXREG(SISVID,0x32,0x00);
4707 outSISIDXREG(SISVID,0x30,0x00);
4708 outSISIDXREG(SISVID,0x32,0x01);
4709 outSISIDXREG(SISVID,0x30,0x00);
4710 orSISIDXREG(SISCR,0x63,0x80);
4711 /* End of Init1 */
4712
4713 /* Set Mode 0x2e */
4714
4715 /* Ramsize */
4716 orSISIDXREG(SISSR,0x16,0x0f);
4717 orSISIDXREG(SISSR,0x18,0xA9);
4718 orSISIDXREG(SISSR,0x19,0xA0);
4719 orSISIDXREG(SISSR,0x1B,0x30);
4720 andSISIDXREG(SISSR,0x17,0xF8);
4721 orSISIDXREG(SISSR,0x19,0x03);
4722 andSIDIDXREG(SISSR,0x13,0x00);
4723 5437
4724 /* Need to map max FB size for finding out about RAM size */ 5438 andSISIDXREG(SISCR, 0x89, 0x8f);
4725 ivideo->video_vbase = ioremap(ivideo->video_base, 0x4000000);
4726 if(ivideo->video_vbase) {
4727 /* Find out about bus width */
4728 if(memtype <= 1) {
4729 outSISIDXREG(SISSR,0x14,0x02);
4730 andSISIDXREG(SISSR,0x16,0x0F);
4731 orSISIDXREG(SISSR,0x16,0x80);
4732 5439
4733 ... 5440 ptr = cs45a;
5441 if(ivideo->haveXGIROM) {
5442 index = (ivideo->chip == XGI_20) ? 0x45a : 0x4e6;
5443 ptr = (const u8 *)&bios[index];
5444 }
5445 regd = le16_to_cpu(((const u16 *)ptr)[regb]);
5446 reg = 0x80;
5447 for(i = 0; i < 5; i++) {
5448 reg &= 0xfc;
5449 if(regd & 0x01) reg |= 0x01;
5450 if(regd & 0x02) reg |= 0x02;
5451 regd >>= 2;
5452 outSISIDXREG(SISCR, 0x89, reg);
5453 inSISIDXREG(SISCR, 0x89, reg);
5454 inSISIDXREG(SISCR, 0x89, reg);
5455 reg += 0x10;
5456 }
4734 5457
4735 } else { 5458 v1 = 0xb5; v2 = 0x20; v3 = 0xf0; v4 = 0x13;
5459 if(ivideo->haveXGIROM) {
5460 v1 = bios[0x118 + regb];
5461 v2 = bios[0xf8 + regb];
5462 v3 = bios[0x120 + regb];
5463 v4 = bios[0x1ca];
5464 }
5465 outSISIDXREG(SISCR, 0x45, v1 & 0x0f);
5466 outSISIDXREG(SISCR, 0x99, (v1 >> 4) & 0x07);
5467 orSISIDXREG(SISCR, 0x40, v1 & 0x80);
5468 outSISIDXREG(SISCR, 0x41, v2);
4736 5469
4737 ... 5470 ptr = cs170;
5471 if(ivideo->haveXGIROM) {
5472 ptr = (const u8 *)&bios[0x170];
5473 }
5474 for(i = 0, j = 0; i < 7; i++, j += 8) {
5475 outSISIDXREG(SISCR, 0x90 + i, ptr[j + regb]);
5476 }
4738 5477
4739 } 5478 outSISIDXREG(SISCR, 0x59, v3);
4740 5479
4741 /* Find out about size */ 5480 ptr = cs1a8;
5481 if(ivideo->haveXGIROM) {
5482 ptr = (const u8 *)&bios[0x1a8];
5483 }
5484 for(i = 0, j = 0; i < 3; i++, j += 8) {
5485 outSISIDXREG(SISCR, 0xc3 + i, ptr[j + regb]);
5486 }
4742 5487
5488 ptr = cs100;
5489 if(ivideo->haveXGIROM) {
5490 ptr = (const u8 *)&bios[0x100];
5491 }
5492 for(i = 0, j = 0; i < 2; i++, j += 8) {
5493 outSISIDXREG(SISCR, 0x8a + i, ptr[j + regb]);
5494 }
4743 5495
4744 iounmap(ivideo->video_vbase); 5496 outSISIDXREG(SISCR, 0xcf, v4);
4745 } else { 5497
4746 printk(KERN_DEBUG "sisfb: Failed to map memory for size detection, assuming 8MB\n"); 5498 outSISIDXREG(SISCR, 0x83, 0x09);
4747 outSISIDXREG(SISSR,0x14,0x??); /* 8MB, 64bit default */ 5499 outSISIDXREG(SISCR, 0x87, 0x00);
5500
5501 if(ivideo->chip == XGI_40) {
5502 if( (ivideo->revision_id == 1) ||
5503 (ivideo->revision_id == 2) ) {
5504 outSISIDXREG(SISCR, 0x8c, 0x87);
5505 }
5506 }
5507
5508 outSISIDXREG(SISSR, 0x17, 0x00);
5509 outSISIDXREG(SISSR, 0x1a, 0x87);
5510
5511 if(ivideo->chip == XGI_20) {
5512 outSISIDXREG(SISSR, 0x15, 0x00);
5513 outSISIDXREG(SISSR, 0x1c, 0x00);
5514 }
5515
5516 ramtype = 0x00; v1 = 0x10;
5517 if(ivideo->haveXGIROM) {
5518 ramtype = bios[0x62];
5519 v1 = bios[0x1d2];
5520 }
5521 if(!(ramtype & 0x80)) {
5522 if(ivideo->chip == XGI_20) {
5523 outSISIDXREG(SISCR, 0x97, v1);
5524 inSISIDXREG(SISCR, 0x97, reg);
5525 if(reg & 0x10) {
5526 ramtype = (reg & 0x01) << 1;
5527 }
5528 } else {
5529 inSISIDXREG(SISSR, 0x39, reg);
5530 ramtype = reg & 0x02;
5531 if(!(ramtype)) {
5532 inSISIDXREG(SISSR, 0x3a, reg);
5533 ramtype = (reg >> 1) & 0x01;
5534 }
5535 }
5536 }
5537 ramtype &= 0x07;
5538
5539 regb = 0; /* ! */
5540
5541 switch(ramtype) {
5542 case 0:
5543 sisfb_post_xgi_setclocks(ivideo, regb);
5544 if((ivideo->chip == XGI_20) ||
5545 (ivideo->revision_id == 1) ||
5546 (ivideo->revision_id == 2)) {
5547 v1 = cs158[regb]; v2 = cs160[regb]; v3 = cs168[regb];
5548 if(ivideo->haveXGIROM) {
5549 v1 = bios[regb + 0x158];
5550 v2 = bios[regb + 0x160];
5551 v3 = bios[regb + 0x168];
5552 }
5553 outSISIDXREG(SISCR, 0x82, v1);
5554 outSISIDXREG(SISCR, 0x85, v2);
5555 outSISIDXREG(SISCR, 0x86, v3);
5556 } else {
5557 outSISIDXREG(SISCR, 0x82, 0x88);
5558 outSISIDXREG(SISCR, 0x86, 0x00);
5559 inSISIDXREG(SISCR, 0x86, reg);
5560 outSISIDXREG(SISCR, 0x86, 0x88);
5561 inSISIDXREG(SISCR, 0x86, reg);
5562 outSISIDXREG(SISCR, 0x86, bios[regb + 0x168]);
5563 outSISIDXREG(SISCR, 0x82, 0x77);
5564 outSISIDXREG(SISCR, 0x85, 0x00);
5565 inSISIDXREG(SISCR, 0x85, reg);
5566 outSISIDXREG(SISCR, 0x85, 0x88);
5567 inSISIDXREG(SISCR, 0x85, reg);
5568 outSISIDXREG(SISCR, 0x85, bios[regb + 0x160]);
5569 outSISIDXREG(SISCR, 0x82, bios[regb + 0x158]);
5570 }
5571 if(ivideo->chip == XGI_40) {
5572 outSISIDXREG(SISCR, 0x97, 0x00);
5573 }
5574 outSISIDXREG(SISCR, 0x98, 0x01);
5575 outSISIDXREG(SISCR, 0x9a, 0x02);
5576
5577 outSISIDXREG(SISSR, 0x18, 0x01);
5578 if((ivideo->chip == XGI_20) ||
5579 (ivideo->revision_id == 2)) {
5580 outSISIDXREG(SISSR, 0x19, 0x40);
5581 } else {
5582 outSISIDXREG(SISSR, 0x19, 0x20);
5583 }
5584 outSISIDXREG(SISSR, 0x16, 0x00);
5585 outSISIDXREG(SISSR, 0x16, 0x80);
5586 if((ivideo->chip == XGI_20) || (bios[0x1cb] != 0x0c)) {
5587 sisfb_post_xgi_delay(ivideo, 0x43);
5588 sisfb_post_xgi_delay(ivideo, 0x43);
5589 sisfb_post_xgi_delay(ivideo, 0x43);
5590 outSISIDXREG(SISSR, 0x18, 0x00);
5591 if((ivideo->chip == XGI_20) ||
5592 (ivideo->revision_id == 2)) {
5593 outSISIDXREG(SISSR, 0x19, 0x40);
5594 } else {
5595 outSISIDXREG(SISSR, 0x19, 0x20);
5596 }
5597 } else if((ivideo->chip == XGI_40) && (bios[0x1cb] == 0x0c)) {
5598 /* outSISIDXREG(SISSR, 0x16, 0x0c); */ /* ? */
5599 }
5600 outSISIDXREG(SISSR, 0x16, 0x00);
5601 outSISIDXREG(SISSR, 0x16, 0x80);
5602 sisfb_post_xgi_delay(ivideo, 4);
5603 v1 = 0x31; v2 = 0x03; v3 = 0x83; v4 = 0x03; v5 = 0x83;
5604 if(ivideo->haveXGIROM) {
5605 v1 = bios[0xf0];
5606 index = (ivideo->chip == XGI_20) ? 0x4b2 : 0x53e;
5607 v2 = bios[index];
5608 v3 = bios[index + 1];
5609 v4 = bios[index + 2];
5610 v5 = bios[index + 3];
5611 }
5612 outSISIDXREG(SISSR, 0x18, v1);
5613 outSISIDXREG(SISSR, 0x19, ((ivideo->chip == XGI_20) ? 0x02 : 0x01));
5614 outSISIDXREG(SISSR, 0x16, v2);
5615 outSISIDXREG(SISSR, 0x16, v3);
5616 sisfb_post_xgi_delay(ivideo, 0x43);
5617 outSISIDXREG(SISSR, 0x1b, 0x03);
5618 sisfb_post_xgi_delay(ivideo, 0x22);
5619 outSISIDXREG(SISSR, 0x18, v1);
5620 outSISIDXREG(SISSR, 0x19, 0x00);
5621 outSISIDXREG(SISSR, 0x16, v4);
5622 outSISIDXREG(SISSR, 0x16, v5);
5623 outSISIDXREG(SISSR, 0x1b, 0x00);
5624 break;
5625 case 1:
5626 outSISIDXREG(SISCR, 0x82, 0x77);
5627 outSISIDXREG(SISCR, 0x86, 0x00);
5628 inSISIDXREG(SISCR, 0x86, reg);
5629 outSISIDXREG(SISCR, 0x86, 0x88);
5630 inSISIDXREG(SISCR, 0x86, reg);
5631 v1 = cs168[regb]; v2 = cs160[regb]; v3 = cs158[regb];
5632 if(ivideo->haveXGIROM) {
5633 v1 = bios[regb + 0x168];
5634 v2 = bios[regb + 0x160];
5635 v3 = bios[regb + 0x158];
5636 }
5637 outSISIDXREG(SISCR, 0x86, v1);
5638 outSISIDXREG(SISCR, 0x82, 0x77);
5639 outSISIDXREG(SISCR, 0x85, 0x00);
5640 inSISIDXREG(SISCR, 0x85, reg);
5641 outSISIDXREG(SISCR, 0x85, 0x88);
5642 inSISIDXREG(SISCR, 0x85, reg);
5643 outSISIDXREG(SISCR, 0x85, v2);
5644 outSISIDXREG(SISCR, 0x82, v3);
5645 outSISIDXREG(SISCR, 0x98, 0x01);
5646 outSISIDXREG(SISCR, 0x9a, 0x02);
5647
5648 outSISIDXREG(SISSR, 0x28, 0x64);
5649 outSISIDXREG(SISSR, 0x29, 0x63);
5650 sisfb_post_xgi_delay(ivideo, 15);
5651 outSISIDXREG(SISSR, 0x18, 0x00);
5652 outSISIDXREG(SISSR, 0x19, 0x20);
5653 outSISIDXREG(SISSR, 0x16, 0x00);
5654 outSISIDXREG(SISSR, 0x16, 0x80);
5655 outSISIDXREG(SISSR, 0x18, 0xc5);
5656 outSISIDXREG(SISSR, 0x19, 0x23);
5657 outSISIDXREG(SISSR, 0x16, 0x00);
5658 outSISIDXREG(SISSR, 0x16, 0x80);
5659 sisfb_post_xgi_delay(ivideo, 1);
5660 outSISIDXREG(SISCR, 0x97,0x11);
5661 sisfb_post_xgi_setclocks(ivideo, regb);
5662 sisfb_post_xgi_delay(ivideo, 0x46);
5663 outSISIDXREG(SISSR, 0x18, 0xc5);
5664 outSISIDXREG(SISSR, 0x19, 0x23);
5665 outSISIDXREG(SISSR, 0x16, 0x00);
5666 outSISIDXREG(SISSR, 0x16, 0x80);
5667 sisfb_post_xgi_delay(ivideo, 1);
5668 outSISIDXREG(SISSR, 0x1b, 0x04);
5669 sisfb_post_xgi_delay(ivideo, 1);
5670 outSISIDXREG(SISSR, 0x1b, 0x00);
5671 sisfb_post_xgi_delay(ivideo, 1);
5672 v1 = 0x31;
5673 if(ivideo->haveXGIROM) {
5674 v1 = bios[0xf0];
5675 }
5676 outSISIDXREG(SISSR, 0x18, v1);
5677 outSISIDXREG(SISSR, 0x19, 0x06);
5678 outSISIDXREG(SISSR, 0x16, 0x04);
5679 outSISIDXREG(SISSR, 0x16, 0x84);
5680 sisfb_post_xgi_delay(ivideo, 1);
5681 break;
5682 default:
5683 sisfb_post_xgi_setclocks(ivideo, regb);
5684 if((ivideo->chip == XGI_40) &&
5685 ((ivideo->revision_id == 1) ||
5686 (ivideo->revision_id == 2))) {
5687 outSISIDXREG(SISCR, 0x82, bios[regb + 0x158]);
5688 outSISIDXREG(SISCR, 0x85, bios[regb + 0x160]);
5689 outSISIDXREG(SISCR, 0x86, bios[regb + 0x168]);
5690 } else {
5691 outSISIDXREG(SISCR, 0x82, 0x88);
5692 outSISIDXREG(SISCR, 0x86, 0x00);
5693 inSISIDXREG(SISCR, 0x86, reg);
5694 outSISIDXREG(SISCR, 0x86, 0x88);
5695 outSISIDXREG(SISCR, 0x82, 0x77);
5696 outSISIDXREG(SISCR, 0x85, 0x00);
5697 inSISIDXREG(SISCR, 0x85, reg);
5698 outSISIDXREG(SISCR, 0x85, 0x88);
5699 inSISIDXREG(SISCR, 0x85, reg);
5700 v1 = cs160[regb]; v2 = cs158[regb];
5701 if(ivideo->haveXGIROM) {
5702 v1 = bios[regb + 0x160];
5703 v2 = bios[regb + 0x158];
5704 }
5705 outSISIDXREG(SISCR, 0x85, v1);
5706 outSISIDXREG(SISCR, 0x82, v2);
5707 }
5708 if(ivideo->chip == XGI_40) {
5709 outSISIDXREG(SISCR, 0x97, 0x11);
5710 }
5711 if((ivideo->chip == XGI_40) && (ivideo->revision_id == 2)) {
5712 outSISIDXREG(SISCR, 0x98, 0x01);
5713 } else {
5714 outSISIDXREG(SISCR, 0x98, 0x03);
5715 }
5716 outSISIDXREG(SISCR, 0x9a, 0x02);
5717
5718 if(ivideo->chip == XGI_40) {
5719 outSISIDXREG(SISSR, 0x18, 0x01);
5720 } else {
5721 outSISIDXREG(SISSR, 0x18, 0x00);
5722 }
5723 outSISIDXREG(SISSR, 0x19, 0x40);
5724 outSISIDXREG(SISSR, 0x16, 0x00);
5725 outSISIDXREG(SISSR, 0x16, 0x80);
5726 if((ivideo->chip == XGI_40) && (bios[0x1cb] != 0x0c)) {
5727 sisfb_post_xgi_delay(ivideo, 0x43);
5728 sisfb_post_xgi_delay(ivideo, 0x43);
5729 sisfb_post_xgi_delay(ivideo, 0x43);
5730 outSISIDXREG(SISSR, 0x18, 0x00);
5731 outSISIDXREG(SISSR, 0x19, 0x40);
5732 outSISIDXREG(SISSR, 0x16, 0x00);
5733 outSISIDXREG(SISSR, 0x16, 0x80);
5734 }
5735 sisfb_post_xgi_delay(ivideo, 4);
5736 v1 = 0x31;
5737 if(ivideo->haveXGIROM) {
5738 v1 = bios[0xf0];
5739 }
5740 outSISIDXREG(SISSR, 0x18, v1);
5741 outSISIDXREG(SISSR, 0x19, 0x01);
5742 if(ivideo->chip == XGI_40) {
5743 outSISIDXREG(SISSR, 0x16, bios[0x53e]);
5744 outSISIDXREG(SISSR, 0x16, bios[0x53f]);
5745 } else {
5746 outSISIDXREG(SISSR, 0x16, 0x05);
5747 outSISIDXREG(SISSR, 0x16, 0x85);
5748 }
5749 sisfb_post_xgi_delay(ivideo, 0x43);
5750 if(ivideo->chip == XGI_40) {
5751 outSISIDXREG(SISSR, 0x1b, 0x01);
5752 } else {
5753 outSISIDXREG(SISSR, 0x1b, 0x03);
5754 }
5755 sisfb_post_xgi_delay(ivideo, 0x22);
5756 outSISIDXREG(SISSR, 0x18, v1);
5757 outSISIDXREG(SISSR, 0x19, 0x00);
5758 if(ivideo->chip == XGI_40) {
5759 outSISIDXREG(SISSR, 0x16, bios[0x540]);
5760 outSISIDXREG(SISSR, 0x16, bios[0x541]);
5761 } else {
5762 outSISIDXREG(SISSR, 0x16, 0x05);
5763 outSISIDXREG(SISSR, 0x16, 0x85);
5764 }
5765 outSISIDXREG(SISSR, 0x1b, 0x00);
5766 }
5767
5768 regb = 0; /* ! */
5769 v1 = 0x03;
5770 if(ivideo->haveXGIROM) {
5771 v1 = bios[0x110 + regb];
5772 }
5773 outSISIDXREG(SISSR, 0x1b, v1);
5774
5775 /* RAM size */
5776 v1 = 0x00; v2 = 0x00;
5777 if(ivideo->haveXGIROM) {
5778 v1 = bios[0x62];
5779 v2 = bios[0x63];
4748 } 5780 }
5781 regb = 0; /* ! */
5782 regd = 1 << regb;
5783 if((v1 & 0x40) && (v2 & regd) && ivideo->haveXGIROM) {
5784
5785 outSISIDXREG(SISSR, 0x13, bios[regb + 0xe0]);
5786 outSISIDXREG(SISSR, 0x14, bios[regb + 0xe0 + 8]);
5787
5788 } else {
5789
5790 /* Set default mode, don't clear screen */
5791 ivideo->SiS_Pr.SiS_UseOEM = FALSE;
5792 SiS_SetEnableDstn(&ivideo->SiS_Pr, FALSE);
5793 SiS_SetEnableFstn(&ivideo->SiS_Pr, FALSE);
5794 ivideo->curFSTN = ivideo->curDSTN = 0;
5795 ivideo->SiS_Pr.VideoMemorySize = 8 << 20;
5796 SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80);
5797
5798 outSISIDXREG(SISSR, 0x05, 0x86);
5799
5800 /* Disable read-cache */
5801 andSISIDXREG(SISSR, 0x21, 0xdf);
5802 sisfb_post_xgi_ramsize(ivideo);
5803 /* Enable read-cache */
5804 orSISIDXREG(SISSR, 0x21, 0x20);
4749 5805
4750 /* AGP (Missing: Checks for VIA and AMD hosts) */
4751 v1 = 0xA5; v2 = 0xFB;
4752 if(ivideo->sishw_ext.UseROM) {
4753 v1 = ivideo->sishw_ext.pjVirtualRomBase[0x9A];
4754 v2 = ivideo->sishw_ext.pjVirtualRomBase[0x9B];
4755 } 5806 }
4756 outSISIDXREG(SISSR,0x21,v1);
4757 outSISIDXREG(SISSR,0x22,v2);
4758 5807
5808#if 0
5809 printk(KERN_DEBUG "-----------------\n");
5810 for(i = 0; i < 0xff; i++) {
5811 inSISIDXREG(SISCR, i, reg);
5812 printk(KERN_DEBUG "CR%02x(%x) = 0x%02x\n", i, SISCR, reg);
5813 }
5814 for(i = 0; i < 0x40; i++) {
5815 inSISIDXREG(SISSR, i, reg);
5816 printk(KERN_DEBUG "SR%02x(%x) = 0x%02x\n", i, SISSR, reg);
5817 }
5818 printk(KERN_DEBUG "-----------------\n");
4759#endif 5819#endif
4760 return; 5820
5821 /* Sense CRT1 */
5822 if(ivideo->chip == XGI_20) {
5823 orSISIDXREG(SISCR, 0x32, 0x20);
5824 } else {
5825 inSISIDXREG(SISPART4, 0x00, reg);
5826 if((reg == 1) || (reg == 2)) {
5827 sisfb_sense_crt1(ivideo);
5828 } else {
5829 orSISIDXREG(SISCR, 0x32, 0x20);
5830 }
5831 }
5832
5833 /* Set default mode, don't clear screen */
5834 ivideo->SiS_Pr.SiS_UseOEM = FALSE;
5835 SiS_SetEnableDstn(&ivideo->SiS_Pr, FALSE);
5836 SiS_SetEnableFstn(&ivideo->SiS_Pr, FALSE);
5837 ivideo->curFSTN = ivideo->curDSTN = 0;
5838 SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80);
5839
5840 outSISIDXREG(SISSR, 0x05, 0x86);
5841
5842 /* Display off */
5843 orSISIDXREG(SISSR, 0x01, 0x20);
5844
5845 /* Save mode number in CR34 */
5846 outSISIDXREG(SISCR, 0x34, 0x2e);
5847
5848 /* Let everyone know what the current mode is */
5849 ivideo->modeprechange = 0x2e;
5850
5851 if(ivideo->chip == XGI_40) {
5852 inSISIDXREG(SISCR, 0xca, reg);
5853 inSISIDXREG(SISCR, 0xcc, v1);
5854 if((reg & 0x10) && (!(v1 & 0x04))) {
5855 printk(KERN_ERR
5856 "sisfb: Please connect power to the card.\n");
5857 return 0;
5858 }
5859 }
5860
5861 return 1;
4761} 5862}
4762#endif 5863#endif
4763 5864
4764 5865static int __devinit
4765static int __devinit sisfb_probe(struct pci_dev *pdev, 5866sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
4766 const struct pci_device_id *ent)
4767{ 5867{
4768 struct sisfb_chip_info *chipinfo = &sisfb_chip_info[ent->driver_data]; 5868 struct sisfb_chip_info *chipinfo = &sisfb_chip_info[ent->driver_data];
4769 struct sis_video_info *ivideo = NULL; 5869 struct sis_video_info *ivideo = NULL;
4770 struct fb_info *sis_fb_info = NULL; 5870 struct fb_info *sis_fb_info = NULL;
4771 u16 reg16; 5871 u16 reg16;
4772 u8 reg; 5872 u8 reg;
4773 int sisvga_enabled = 0, i; 5873 int i, ret;
4774 5874
4775 if(sisfb_off) return -ENXIO; 5875 if(sisfb_off)
5876 return -ENXIO;
4776 5877
4777#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,3)) 5878#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,3))
4778 sis_fb_info = framebuffer_alloc(sizeof(*ivideo), &pdev->dev); 5879 sis_fb_info = framebuffer_alloc(sizeof(*ivideo), &pdev->dev);
4779 if(!sis_fb_info) return -ENOMEM; 5880 if(!sis_fb_info)
5881 return -ENOMEM;
4780#else 5882#else
4781 sis_fb_info = kmalloc(sizeof(*sis_fb_info) + sizeof(*ivideo), GFP_KERNEL); 5883 sis_fb_info = kmalloc(sizeof(*sis_fb_info) + sizeof(*ivideo), GFP_KERNEL);
4782 if(!sis_fb_info) return -ENOMEM; 5884 if(!sis_fb_info)
5885 return -ENOMEM;
4783 memset(sis_fb_info, 0, sizeof(*sis_fb_info) + sizeof(*ivideo)); 5886 memset(sis_fb_info, 0, sizeof(*sis_fb_info) + sizeof(*ivideo));
4784 sis_fb_info->par = ((char *)sis_fb_info + sizeof(*sis_fb_info)); 5887 sis_fb_info->par = ((char *)sis_fb_info + sizeof(*sis_fb_info));
4785#endif 5888#endif
@@ -4787,27 +5890,34 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
4787 ivideo = (struct sis_video_info *)sis_fb_info->par; 5890 ivideo = (struct sis_video_info *)sis_fb_info->par;
4788 ivideo->memyselfandi = sis_fb_info; 5891 ivideo->memyselfandi = sis_fb_info;
4789 5892
5893 ivideo->sisfb_id = SISFB_ID;
5894
4790 if(card_list == NULL) { 5895 if(card_list == NULL) {
4791 ivideo->cardnumber = 0; 5896 ivideo->cardnumber = 0;
4792 } else { 5897 } else {
4793 struct sis_video_info *countvideo = card_list; 5898 struct sis_video_info *countvideo = card_list;
4794 ivideo->cardnumber = 1; 5899 ivideo->cardnumber = 1;
4795 while((countvideo = countvideo->next) != NULL) ivideo->cardnumber++; 5900 while((countvideo = countvideo->next) != 0)
5901 ivideo->cardnumber++;
4796 } 5902 }
4797 5903
4798 strncpy(ivideo->myid, chipinfo->chip_name, 30); 5904 strncpy(ivideo->myid, chipinfo->chip_name, 30);
4799 5905
4800 ivideo->warncount = 0; 5906 ivideo->warncount = 0;
4801 ivideo->chip_id = pdev->device; 5907 ivideo->chip_id = pdev->device;
5908 ivideo->chip_vendor = pdev->vendor;
4802 pci_read_config_byte(pdev, PCI_REVISION_ID, &ivideo->revision_id); 5909 pci_read_config_byte(pdev, PCI_REVISION_ID, &ivideo->revision_id);
4803 ivideo->sishw_ext.jChipRevision = ivideo->revision_id; 5910 ivideo->SiS_Pr.ChipRevision = ivideo->revision_id;
4804 pci_read_config_word(pdev, PCI_COMMAND, &reg16); 5911 pci_read_config_word(pdev, PCI_COMMAND, &reg16);
4805 sisvga_enabled = reg16 & 0x01; 5912 ivideo->sisvga_enabled = reg16 & 0x01;
4806 ivideo->pcibus = pdev->bus->number; 5913 ivideo->pcibus = pdev->bus->number;
4807 ivideo->pcislot = PCI_SLOT(pdev->devfn); 5914 ivideo->pcislot = PCI_SLOT(pdev->devfn);
4808 ivideo->pcifunc = PCI_FUNC(pdev->devfn); 5915 ivideo->pcifunc = PCI_FUNC(pdev->devfn);
4809 ivideo->subsysvendor = pdev->subsystem_vendor; 5916 ivideo->subsysvendor = pdev->subsystem_vendor;
4810 ivideo->subsysdevice = pdev->subsystem_device; 5917 ivideo->subsysdevice = pdev->subsystem_device;
5918#ifdef SIS_OLD_CONFIG_COMPAT
5919 ivideo->ioctl32registered = 0;
5920#endif
4811 5921
4812#ifndef MODULE 5922#ifndef MODULE
4813 if(sisfb_mode_idx == -1) { 5923 if(sisfb_mode_idx == -1) {
@@ -4827,6 +5937,24 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
4827 5937
4828 ivideo->sisfb_thismonitor.datavalid = FALSE; 5938 ivideo->sisfb_thismonitor.datavalid = FALSE;
4829 5939
5940 ivideo->current_base = 0;
5941
5942 ivideo->engineok = 0;
5943
5944 ivideo->sisfb_was_boot_device = 0;
5945#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
5946 if(pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW) {
5947 if(ivideo->sisvga_enabled)
5948 ivideo->sisfb_was_boot_device = 1;
5949 else {
5950 printk(KERN_DEBUG "sisfb: PCI device is disabled, "
5951 "but marked as boot video device ???\n");
5952 printk(KERN_DEBUG "sisfb: I will not accept this "
5953 "as the primary VGA device\n");
5954 }
5955 }
5956#endif
5957
4830 ivideo->sisfb_parm_mem = sisfb_parm_mem; 5958 ivideo->sisfb_parm_mem = sisfb_parm_mem;
4831 ivideo->sisfb_accel = sisfb_accel; 5959 ivideo->sisfb_accel = sisfb_accel;
4832 ivideo->sisfb_ypan = sisfb_ypan; 5960 ivideo->sisfb_ypan = sisfb_ypan;
@@ -4846,7 +5974,6 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
4846 ivideo->sisfb_tvstd = sisfb_tvstd; 5974 ivideo->sisfb_tvstd = sisfb_tvstd;
4847 ivideo->tvxpos = sisfb_tvxposoffset; 5975 ivideo->tvxpos = sisfb_tvxposoffset;
4848 ivideo->tvypos = sisfb_tvyposoffset; 5976 ivideo->tvypos = sisfb_tvyposoffset;
4849 ivideo->sisfb_filter = sisfb_filter;
4850 ivideo->sisfb_nocrt2rate = sisfb_nocrt2rate; 5977 ivideo->sisfb_nocrt2rate = sisfb_nocrt2rate;
4851#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,0) 5978#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,0)
4852 ivideo->sisfb_inverse = sisfb_inverse; 5979 ivideo->sisfb_inverse = sisfb_inverse;
@@ -4854,7 +5981,7 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
4854 5981
4855 ivideo->refresh_rate = 0; 5982 ivideo->refresh_rate = 0;
4856 if(ivideo->sisfb_parm_rate != -1) { 5983 if(ivideo->sisfb_parm_rate != -1) {
4857 ivideo->refresh_rate = ivideo->sisfb_parm_rate; 5984 ivideo->refresh_rate = ivideo->sisfb_parm_rate;
4858 } 5985 }
4859 5986
4860 ivideo->SiS_Pr.UsePanelScaler = sisfb_scalelcd; 5987 ivideo->SiS_Pr.UsePanelScaler = sisfb_scalelcd;
@@ -4863,8 +5990,8 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
4863 ivideo->SiS_Pr.LVDSHL = sisfb_lvdshl; 5990 ivideo->SiS_Pr.LVDSHL = sisfb_lvdshl;
4864 5991
4865 ivideo->SiS_Pr.SiS_Backup70xx = 0xff; 5992 ivideo->SiS_Pr.SiS_Backup70xx = 0xff;
4866 ivideo->SiS_Pr.SiS_CHOverScan = -1; 5993 ivideo->SiS_Pr.SiS_CHOverScan = -1;
4867 ivideo->SiS_Pr.SiS_ChSW = FALSE; 5994 ivideo->SiS_Pr.SiS_ChSW = FALSE;
4868 ivideo->SiS_Pr.SiS_UseLCDA = FALSE; 5995 ivideo->SiS_Pr.SiS_UseLCDA = FALSE;
4869 ivideo->SiS_Pr.HaveEMI = FALSE; 5996 ivideo->SiS_Pr.HaveEMI = FALSE;
4870 ivideo->SiS_Pr.HaveEMILCD = FALSE; 5997 ivideo->SiS_Pr.HaveEMILCD = FALSE;
@@ -4873,12 +6000,13 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
4873 ivideo->SiS_Pr.SiS_MyCR63 = 0x63; 6000 ivideo->SiS_Pr.SiS_MyCR63 = 0x63;
4874 ivideo->SiS_Pr.PDC = -1; 6001 ivideo->SiS_Pr.PDC = -1;
4875 ivideo->SiS_Pr.PDCA = -1; 6002 ivideo->SiS_Pr.PDCA = -1;
6003 ivideo->SiS_Pr.DDCPortMixup = FALSE;
4876#ifdef CONFIG_FB_SIS_315 6004#ifdef CONFIG_FB_SIS_315
4877 if(ivideo->chip >= SIS_330) { 6005 if(ivideo->chip >= SIS_330) {
4878 ivideo->SiS_Pr.SiS_MyCR63 = 0x53; 6006 ivideo->SiS_Pr.SiS_MyCR63 = 0x53;
4879 if(ivideo->chip >= SIS_661) { 6007 if(ivideo->chip >= SIS_661) {
4880 ivideo->SiS_Pr.SiS_SensibleSR11 = TRUE; 6008 ivideo->SiS_Pr.SiS_SensibleSR11 = TRUE;
4881 } 6009 }
4882 } 6010 }
4883#endif 6011#endif
4884 6012
@@ -4891,9 +6019,9 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
4891 switch(ivideo->nbridge->device) { 6019 switch(ivideo->nbridge->device) {
4892#ifdef CONFIG_FB_SIS_300 6020#ifdef CONFIG_FB_SIS_300
4893 case PCI_DEVICE_ID_SI_730: 6021 case PCI_DEVICE_ID_SI_730:
4894 ivideo->chip = SIS_730; 6022 ivideo->chip = SIS_730;
4895 strcpy(ivideo->myid, "SiS 730"); 6023 strcpy(ivideo->myid, "SiS 730");
4896 break; 6024 break;
4897#endif 6025#endif
4898#ifdef CONFIG_FB_SIS_315 6026#ifdef CONFIG_FB_SIS_315
4899 case PCI_DEVICE_ID_SI_651: 6027 case PCI_DEVICE_ID_SI_651:
@@ -4901,22 +6029,28 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
4901 strcpy(ivideo->myid, "SiS 651"); 6029 strcpy(ivideo->myid, "SiS 651");
4902 break; 6030 break;
4903 case PCI_DEVICE_ID_SI_740: 6031 case PCI_DEVICE_ID_SI_740:
4904 ivideo->chip = SIS_740; 6032 ivideo->chip = SIS_740;
4905 strcpy(ivideo->myid, "SiS 740"); 6033 strcpy(ivideo->myid, "SiS 740");
4906 break; 6034 break;
4907 case PCI_DEVICE_ID_SI_661: 6035 case PCI_DEVICE_ID_SI_661:
4908 ivideo->chip = SIS_661; 6036 ivideo->chip = SIS_661;
4909 strcpy(ivideo->myid, "SiS 661"); 6037 strcpy(ivideo->myid, "SiS 661");
4910 break; 6038 break;
4911 case PCI_DEVICE_ID_SI_741: 6039 case PCI_DEVICE_ID_SI_741:
4912 ivideo->chip = SIS_741; 6040 ivideo->chip = SIS_741;
4913 strcpy(ivideo->myid, "SiS 741"); 6041 strcpy(ivideo->myid, "SiS 741");
4914 break; 6042 break;
4915 case PCI_DEVICE_ID_SI_760: 6043 case PCI_DEVICE_ID_SI_760:
4916 ivideo->chip = SIS_760; 6044 ivideo->chip = SIS_760;
4917 strcpy(ivideo->myid, "SiS 760"); 6045 strcpy(ivideo->myid, "SiS 760");
4918 break; 6046 break;
6047 case PCI_DEVICE_ID_SI_761:
6048 ivideo->chip = SIS_761;
6049 strcpy(ivideo->myid, "SiS 761");
6050 break;
4919#endif 6051#endif
6052 default:
6053 break;
4920 } 6054 }
4921 } 6055 }
4922 6056
@@ -4924,71 +6058,83 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
4924 strcpy(sis_fb_info->modename, ivideo->myid); 6058 strcpy(sis_fb_info->modename, ivideo->myid);
4925#endif 6059#endif
4926 6060
4927 ivideo->sishw_ext.jChipType = ivideo->chip; 6061 ivideo->SiS_Pr.ChipType = ivideo->chip;
6062
6063 ivideo->SiS_Pr.ivideo = (void *)ivideo;
4928 6064
4929#ifdef CONFIG_FB_SIS_315 6065#ifdef CONFIG_FB_SIS_315
4930 if((ivideo->sishw_ext.jChipType == SIS_315PRO) || 6066 if((ivideo->SiS_Pr.ChipType == SIS_315PRO) ||
4931 (ivideo->sishw_ext.jChipType == SIS_315)) { 6067 (ivideo->SiS_Pr.ChipType == SIS_315)) {
4932 ivideo->sishw_ext.jChipType = SIS_315H; 6068 ivideo->SiS_Pr.ChipType = SIS_315H;
4933 } 6069 }
4934#endif 6070#endif
4935 6071
6072 if(!ivideo->sisvga_enabled) {
6073 if(pci_enable_device(pdev)) {
6074 if(ivideo->nbridge) SIS_PCI_PUT_DEVICE(ivideo->nbridge);
6075 pci_set_drvdata(pdev, NULL);
6076 kfree(sis_fb_info);
6077 return -EIO;
6078 }
6079 }
6080
4936 ivideo->video_base = pci_resource_start(pdev, 0); 6081 ivideo->video_base = pci_resource_start(pdev, 0);
4937 ivideo->mmio_base = pci_resource_start(pdev, 1); 6082 ivideo->mmio_base = pci_resource_start(pdev, 1);
4938 ivideo->mmio_size = pci_resource_len(pdev, 1); 6083 ivideo->mmio_size = pci_resource_len(pdev, 1);
4939 ivideo->SiS_Pr.RelIO = pci_resource_start(pdev, 2) + 0x30; 6084 ivideo->SiS_Pr.RelIO = pci_resource_start(pdev, 2) + 0x30;
4940 ivideo->sishw_ext.ulIOAddress = ivideo->vga_base = ivideo->SiS_Pr.RelIO; 6085 ivideo->SiS_Pr.IOAddress = ivideo->vga_base = ivideo->SiS_Pr.RelIO;
4941 6086
4942 if(!sisvga_enabled) { 6087 SiSRegInit(&ivideo->SiS_Pr, ivideo->SiS_Pr.IOAddress);
4943 if(pci_enable_device(pdev)) {
4944 pci_set_drvdata(pdev, NULL);
4945 kfree(sis_fb_info);
4946 return -EIO;
4947 }
4948 }
4949
4950 SiSRegInit(&ivideo->SiS_Pr, ivideo->sishw_ext.ulIOAddress);
4951 6088
4952#ifdef CONFIG_FB_SIS_300 6089#ifdef CONFIG_FB_SIS_300
4953 /* Find PCI systems for Chrontel/GPIO communication setup */ 6090 /* Find PCI systems for Chrontel/GPIO communication setup */
4954 if(ivideo->chip == SIS_630) { 6091 if(ivideo->chip == SIS_630) {
4955 i=0; 6092 i = 0;
4956 do { 6093 do {
4957 if(mychswtable[i].subsysVendor == ivideo->subsysvendor && 6094 if(mychswtable[i].subsysVendor == ivideo->subsysvendor &&
4958 mychswtable[i].subsysCard == ivideo->subsysdevice) { 6095 mychswtable[i].subsysCard == ivideo->subsysdevice) {
4959 ivideo->SiS_Pr.SiS_ChSW = TRUE; 6096 ivideo->SiS_Pr.SiS_ChSW = TRUE;
4960 printk(KERN_DEBUG "sisfb: Identified [%s %s] requiring Chrontel/GPIO setup\n", 6097 printk(KERN_DEBUG "sisfb: Identified [%s %s] "
4961 mychswtable[i].vendorName, mychswtable[i].cardName); 6098 "requiring Chrontel/GPIO setup\n",
4962 break; 6099 mychswtable[i].vendorName,
4963 } 6100 mychswtable[i].cardName);
4964 i++; 6101 ivideo->lpcdev = SIS_PCI_GET_DEVICE(PCI_VENDOR_ID_SI, 0x0008, NULL);
4965 } while(mychswtable[i].subsysVendor != 0); 6102 break;
6103 }
6104 i++;
6105 } while(mychswtable[i].subsysVendor != 0);
6106 }
6107#endif
6108
6109#ifdef CONFIG_FB_SIS_315
6110 if((ivideo->chip == SIS_760) && (ivideo->nbridge)) {
6111 ivideo->lpcdev = SIS_PCI_GET_SLOT(ivideo->nbridge->bus, (2 << 3));
4966 } 6112 }
4967#endif 6113#endif
4968 6114
4969 outSISIDXREG(SISSR, 0x05, 0x86); 6115 outSISIDXREG(SISSR, 0x05, 0x86);
4970 6116
4971 if( (!sisvga_enabled) 6117 if( (!ivideo->sisvga_enabled)
4972#if !defined(__i386__) && !defined(__x86_64__) 6118#if !defined(__i386__) && !defined(__x86_64__)
4973 || (sisfb_resetcard) 6119 || (sisfb_resetcard)
4974#endif 6120#endif
4975 ) { 6121 ) {
4976 for(i = 0x30; i <= 0x3f; i++) { 6122 for(i = 0x30; i <= 0x3f; i++) {
4977 outSISIDXREG(SISCR,i,0x00); 6123 outSISIDXREG(SISCR, i, 0x00);
4978 } 6124 }
4979 } 6125 }
4980 6126
4981 /* Find out about current video mode */ 6127 /* Find out about current video mode */
4982 ivideo->modeprechange = 0x03; 6128 ivideo->modeprechange = 0x03;
4983 inSISIDXREG(SISCR,0x34,reg); 6129 inSISIDXREG(SISCR, 0x34, reg);
4984 if(reg & 0x7f) { 6130 if(reg & 0x7f) {
4985 ivideo->modeprechange = reg & 0x7f; 6131 ivideo->modeprechange = reg & 0x7f;
4986 } else if(sisvga_enabled) { 6132 } else if(ivideo->sisvga_enabled) {
4987#if defined(__i386__) || defined(__x86_64__) 6133#if defined(__i386__) || defined(__x86_64__)
4988 unsigned char SIS_IOTYPE2 *tt = ioremap(0, 0x1000); 6134 unsigned char SIS_IOTYPE2 *tt = ioremap(0x400, 0x100);
4989 if(tt) { 6135 if(tt) {
4990 ivideo->modeprechange = readb(tt + 0x449); 6136 ivideo->modeprechange = readb(tt + 0x49);
4991 iounmap(tt); 6137 iounmap(tt);
4992 } 6138 }
4993#endif 6139#endif
4994 } 6140 }
@@ -4996,219 +6142,221 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
4996#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 6142#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
4997#ifdef MODULE 6143#ifdef MODULE
4998 if((reg & 0x80) && (reg != 0xff)) { 6144 if((reg & 0x80) && (reg != 0xff)) {
4999 if((sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni]) != 0xFF) { 6145 if((sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni])
5000 printk(KERN_INFO "sisfb: Cannot initialize display mode, X server is active\n"); 6146 != 0xFF) {
5001 pci_set_drvdata(pdev, NULL); 6147 printk(KERN_INFO "sisfb: Cannot initialize display mode, "
5002 kfree(sis_fb_info); 6148 "X server is active\n");
5003 return -EBUSY; 6149 ret = -EBUSY;
5004 } 6150 goto error_4;
6151 }
5005 } 6152 }
5006#endif
5007#endif 6153#endif
5008
5009 ivideo->sishw_ext.bIntegratedMMEnabled = TRUE;
5010#ifdef CONFIG_FB_SIS_300
5011 if(ivideo->sisvga_engine == SIS_300_VGA) {
5012 if(ivideo->chip != SIS_300) {
5013 inSISIDXREG(SISSR, 0x1a, reg);
5014 if(!(reg & 0x10)) {
5015 ivideo->sishw_ext.bIntegratedMMEnabled = FALSE;
5016 }
5017 }
5018 }
5019#endif 6154#endif
5020 6155
6156 /* Search and copy ROM image */
5021 ivideo->bios_abase = NULL; 6157 ivideo->bios_abase = NULL;
6158 ivideo->SiS_Pr.VirtualRomBase = NULL;
6159 ivideo->SiS_Pr.UseROM = FALSE;
6160 ivideo->haveXGIROM = ivideo->SiS_Pr.SiS_XGIROM = FALSE;
5022 if(ivideo->sisfb_userom) { 6161 if(ivideo->sisfb_userom) {
5023 ivideo->sishw_ext.pjVirtualRomBase = sis_find_rom(pdev); 6162 ivideo->SiS_Pr.VirtualRomBase = sisfb_find_rom(pdev);
5024 ivideo->bios_abase = ivideo->sishw_ext.pjVirtualRomBase; 6163 ivideo->bios_abase = ivideo->SiS_Pr.VirtualRomBase;
5025 if(ivideo->sishw_ext.pjVirtualRomBase) { 6164 ivideo->SiS_Pr.UseROM = (ivideo->SiS_Pr.VirtualRomBase) ? TRUE : FALSE;
5026 printk(KERN_INFO "sisfb: Video ROM found and copied\n"); 6165 printk(KERN_INFO "sisfb: Video ROM %sfound\n",
5027 ivideo->sishw_ext.UseROM = TRUE; 6166 ivideo->SiS_Pr.UseROM ? "" : "not ");
5028 } else { 6167 if((ivideo->SiS_Pr.UseROM) && (ivideo->chip >= XGI_20)) {
5029 ivideo->sishw_ext.UseROM = FALSE; 6168 ivideo->SiS_Pr.UseROM = FALSE;
5030 printk(KERN_INFO "sisfb: Video ROM not found\n"); 6169 ivideo->haveXGIROM = ivideo->SiS_Pr.SiS_XGIROM = TRUE;
5031 } 6170 if( (ivideo->revision_id == 2) &&
6171 (!(ivideo->bios_abase[0x1d1] & 0x01)) ) {
6172 ivideo->SiS_Pr.DDCPortMixup = TRUE;
6173 }
6174 }
5032 } else { 6175 } else {
5033 ivideo->sishw_ext.pjVirtualRomBase = NULL; 6176 printk(KERN_INFO "sisfb: Video ROM usage disabled\n");
5034 ivideo->sishw_ext.UseROM = FALSE;
5035 printk(KERN_INFO "sisfb: Video ROM usage disabled\n");
5036 } 6177 }
5037 6178
5038 /* Find systems for special custom timing */ 6179 /* Find systems for special custom timing */
5039 if(ivideo->SiS_Pr.SiS_CustomT == CUT_NONE) { 6180 if(ivideo->SiS_Pr.SiS_CustomT == CUT_NONE) {
5040 int j; 6181 sisfb_detect_custom_timing(ivideo);
5041 unsigned char *biosver = NULL;
5042 unsigned char *biosdate = NULL;
5043 BOOLEAN footprint;
5044 u32 chksum = 0;
5045
5046 if(ivideo->sishw_ext.UseROM) {
5047 biosver = ivideo->sishw_ext.pjVirtualRomBase + 0x06;
5048 biosdate = ivideo->sishw_ext.pjVirtualRomBase + 0x2c;
5049 for(i=0; i<32768; i++) chksum += ivideo->sishw_ext.pjVirtualRomBase[i];
5050 }
5051
5052 i=0;
5053 do {
5054 if( (mycustomttable[i].chipID == ivideo->chip) &&
5055 ((!strlen(mycustomttable[i].biosversion)) ||
5056 (ivideo->sishw_ext.UseROM &&
5057 (!strncmp(mycustomttable[i].biosversion, biosver, strlen(mycustomttable[i].biosversion))))) &&
5058 ((!strlen(mycustomttable[i].biosdate)) ||
5059 (ivideo->sishw_ext.UseROM &&
5060 (!strncmp(mycustomttable[i].biosdate, biosdate, strlen(mycustomttable[i].biosdate))))) &&
5061 ((!mycustomttable[i].bioschksum) ||
5062 (ivideo->sishw_ext.UseROM &&
5063 (mycustomttable[i].bioschksum == chksum))) &&
5064 (mycustomttable[i].pcisubsysvendor == ivideo->subsysvendor) &&
5065 (mycustomttable[i].pcisubsyscard == ivideo->subsysdevice) ) {
5066 footprint = TRUE;
5067 for(j = 0; j < 5; j++) {
5068 if(mycustomttable[i].biosFootprintAddr[j]) {
5069 if(ivideo->sishw_ext.UseROM) {
5070 if(ivideo->sishw_ext.pjVirtualRomBase[mycustomttable[i].biosFootprintAddr[j]] !=
5071 mycustomttable[i].biosFootprintData[j]) {
5072 footprint = FALSE;
5073 }
5074 } else footprint = FALSE;
5075 }
5076 }
5077 if(footprint) {
5078 ivideo->SiS_Pr.SiS_CustomT = mycustomttable[i].SpecialID;
5079 printk(KERN_DEBUG "sisfb: Identified [%s %s], special timing applies\n",
5080 mycustomttable[i].vendorName,
5081 mycustomttable[i].cardName);
5082 printk(KERN_DEBUG "sisfb: [specialtiming parameter name: %s]\n",
5083 mycustomttable[i].optionName);
5084 break;
5085 }
5086 }
5087 i++;
5088 } while(mycustomttable[i].chipID);
5089 } 6182 }
5090 6183
5091#ifdef CONFIG_FB_SIS_300 6184 /* POST card in case this has not been done by the BIOS */
5092 if(ivideo->sisvga_engine == SIS_300_VGA) { 6185 if( (!ivideo->sisvga_enabled)
5093 if( (!sisvga_enabled)
5094#if !defined(__i386__) && !defined(__x86_64__) 6186#if !defined(__i386__) && !defined(__x86_64__)
5095 || (sisfb_resetcard) 6187 || (sisfb_resetcard)
5096#endif 6188#endif
5097 ) { 6189 ) {
6190#ifdef CONFIG_FB_SIS_300
6191 if(ivideo->sisvga_engine == SIS_300_VGA) {
5098 if(ivideo->chip == SIS_300) { 6192 if(ivideo->chip == SIS_300) {
5099 sisfb_post_sis300(pdev); 6193 sisfb_post_sis300(pdev);
6194 ivideo->sisfb_can_post = 1;
5100 } 6195 }
5101 } 6196 }
5102 }
5103#endif 6197#endif
5104 6198
5105#ifdef CONFIG_FB_SIS_315 6199#ifdef CONFIG_FB_SIS_315
5106 if(ivideo->sisvga_engine == SIS_315_VGA) { 6200 if(ivideo->sisvga_engine == SIS_315_VGA) {
5107 if( (!sisvga_enabled) 6201 int result = 1;
5108#if !defined(__i386__) && !defined(__x86_64__) 6202 /* if((ivideo->chip == SIS_315H) ||
5109 || (sisfb_resetcard)
5110#endif
5111 ) {
5112 if((ivideo->chip == SIS_315H) ||
5113 (ivideo->chip == SIS_315) || 6203 (ivideo->chip == SIS_315) ||
5114 (ivideo->chip == SIS_315PRO) || 6204 (ivideo->chip == SIS_315PRO) ||
5115 (ivideo->chip == SIS_330)) { 6205 (ivideo->chip == SIS_330)) {
5116 sisfb_post_sis315330(pdev); 6206 sisfb_post_sis315330(pdev);
6207 } else */ if(ivideo->chip == XGI_20) {
6208 result = sisfb_post_xgi(pdev);
6209 ivideo->sisfb_can_post = 1;
6210 } else if((ivideo->chip == XGI_40) && ivideo->haveXGIROM) {
6211 result = sisfb_post_xgi(pdev);
6212 ivideo->sisfb_can_post = 1;
6213 } else {
6214 printk(KERN_INFO "sisfb: Card is not "
6215 "POSTed and sisfb can't do this either.\n");
6216 }
6217 if(!result) {
6218 printk(KERN_ERR "sisfb: Failed to POST card\n");
6219 ret = -ENODEV;
6220 goto error_3;
5117 } 6221 }
5118 } 6222 }
5119 }
5120#endif 6223#endif
6224 }
5121 6225
6226 ivideo->sisfb_card_posted = 1;
6227
6228 /* Find out about RAM size */
5122 if(sisfb_get_dram_size(ivideo)) { 6229 if(sisfb_get_dram_size(ivideo)) {
5123 printk(KERN_INFO "sisfb: Fatal error: Unable to determine RAM size.\n"); 6230 printk(KERN_INFO "sisfb: Fatal error: Unable to determine VRAM size.\n");
5124 if(ivideo->bios_abase) vfree(ivideo->bios_abase); 6231 ret = -ENODEV;
5125 pci_set_drvdata(pdev, NULL); 6232 goto error_3;
5126 kfree(sis_fb_info);
5127 return -ENODEV;
5128 } 6233 }
5129 6234
6235
6236 /* Enable PCI addressing and MMIO */
5130 if((ivideo->sisfb_mode_idx < 0) || 6237 if((ivideo->sisfb_mode_idx < 0) ||
5131 ((sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni]) != 0xFF)) { 6238 ((sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni]) != 0xFF)) {
5132 /* Enable PCI_LINEAR_ADDRESSING and MMIO_ENABLE */ 6239 /* Enable PCI_LINEAR_ADDRESSING and MMIO_ENABLE */
5133 orSISIDXREG(SISSR, IND_SIS_PCI_ADDRESS_SET, (SIS_PCI_ADDR_ENABLE | SIS_MEM_MAP_IO_ENABLE)); 6240 orSISIDXREG(SISSR, IND_SIS_PCI_ADDRESS_SET, (SIS_PCI_ADDR_ENABLE | SIS_MEM_MAP_IO_ENABLE));
5134 /* Enable 2D accelerator engine */ 6241 /* Enable 2D accelerator engine */
5135 orSISIDXREG(SISSR, IND_SIS_MODULE_ENABLE, SIS_ENABLE_2D); 6242 orSISIDXREG(SISSR, IND_SIS_MODULE_ENABLE, SIS_ENABLE_2D);
5136 } 6243 }
5137 6244
5138 if(sisfb_pdc != 0xff) { 6245 if(sisfb_pdc != 0xff) {
5139 if(ivideo->sisvga_engine == SIS_300_VGA) sisfb_pdc &= 0x3c; 6246 if(ivideo->sisvga_engine == SIS_300_VGA)
5140 else sisfb_pdc &= 0x1f; 6247 sisfb_pdc &= 0x3c;
5141 ivideo->SiS_Pr.PDC = sisfb_pdc; 6248 else
6249 sisfb_pdc &= 0x1f;
6250 ivideo->SiS_Pr.PDC = sisfb_pdc;
5142 } 6251 }
5143#ifdef CONFIG_FB_SIS_315 6252#ifdef CONFIG_FB_SIS_315
5144 if(ivideo->sisvga_engine == SIS_315_VGA) { 6253 if(ivideo->sisvga_engine == SIS_315_VGA) {
5145 if(sisfb_pdca != 0xff) ivideo->SiS_Pr.PDCA = sisfb_pdca & 0x1f; 6254 if(sisfb_pdca != 0xff)
6255 ivideo->SiS_Pr.PDCA = sisfb_pdca & 0x1f;
5146 } 6256 }
5147#endif 6257#endif
5148 6258
5149 if(!request_mem_region(ivideo->video_base, ivideo->video_size, "sisfb FB")) { 6259 if(!request_mem_region(ivideo->video_base, ivideo->video_size, "sisfb FB")) {
5150 printk(KERN_ERR "sisfb: Fatal error: Unable to reserve frame buffer memory\n"); 6260 printk(KERN_ERR "sisfb: Fatal error: Unable to reserve %dMB framebuffer memory\n",
6261 (int)(ivideo->video_size >> 20));
5151 printk(KERN_ERR "sisfb: Is there another framebuffer driver active?\n"); 6262 printk(KERN_ERR "sisfb: Is there another framebuffer driver active?\n");
5152 if(ivideo->bios_abase) vfree(ivideo->bios_abase); 6263 ret = -ENODEV;
5153 pci_set_drvdata(pdev, NULL); 6264 goto error_3;
5154 kfree(sis_fb_info);
5155 return -ENODEV;
5156 } 6265 }
5157 6266
5158 if(!request_mem_region(ivideo->mmio_base, ivideo->mmio_size, "sisfb MMIO")) { 6267 if(!request_mem_region(ivideo->mmio_base, ivideo->mmio_size, "sisfb MMIO")) {
5159 printk(KERN_ERR "sisfb: Fatal error: Unable to reserve MMIO region\n"); 6268 printk(KERN_ERR "sisfb: Fatal error: Unable to reserve MMIO region\n");
5160 release_mem_region(ivideo->video_base, ivideo->video_size); 6269 ret = -ENODEV;
5161 if(ivideo->bios_abase) vfree(ivideo->bios_abase); 6270 goto error_2;
5162 pci_set_drvdata(pdev, NULL);
5163 kfree(sis_fb_info);
5164 return -ENODEV;
5165 } 6271 }
5166 6272
5167 ivideo->video_vbase = ioremap(ivideo->video_base, ivideo->video_size); 6273 ivideo->video_vbase = ioremap(ivideo->video_base, ivideo->video_size);
5168 ivideo->sishw_ext.pjVideoMemoryAddress = ivideo->video_vbase; 6274 ivideo->SiS_Pr.VideoMemoryAddress = ivideo->video_vbase;
5169 if(!ivideo->video_vbase) { 6275 if(!ivideo->video_vbase) {
5170 printk(KERN_ERR "sisfb: Fatal error: Unable to map frame buffer memory\n"); 6276 printk(KERN_ERR "sisfb: Fatal error: Unable to map framebuffer memory\n");
5171 release_mem_region(ivideo->video_base, ivideo->video_size); 6277 ret = -ENODEV;
5172 release_mem_region(ivideo->mmio_base, ivideo->mmio_size); 6278 goto error_1;
5173 if(ivideo->bios_abase) vfree(ivideo->bios_abase);
5174 pci_set_drvdata(pdev, NULL);
5175 kfree(sis_fb_info);
5176 return -ENODEV;
5177 } 6279 }
5178 6280
5179 ivideo->mmio_vbase = ioremap(ivideo->mmio_base, ivideo->mmio_size); 6281 ivideo->mmio_vbase = ioremap(ivideo->mmio_base, ivideo->mmio_size);
5180 if(!ivideo->mmio_vbase) { 6282 if(!ivideo->mmio_vbase) {
5181 printk(KERN_ERR "sisfb: Fatal error: Unable to map MMIO region\n"); 6283 printk(KERN_ERR "sisfb: Fatal error: Unable to map MMIO region\n");
5182 iounmap(ivideo->video_vbase); 6284 ret = -ENODEV;
5183 release_mem_region(ivideo->video_base, ivideo->video_size); 6285error_0: iounmap(ivideo->video_vbase);
5184 release_mem_region(ivideo->mmio_base, ivideo->mmio_size); 6286error_1: release_mem_region(ivideo->video_base, ivideo->video_size);
5185 if(ivideo->bios_abase) vfree(ivideo->bios_abase); 6287error_2: release_mem_region(ivideo->mmio_base, ivideo->mmio_size);
6288error_3: vfree(ivideo->bios_abase);
6289#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
6290error_4:
6291#endif
6292 if(ivideo->lpcdev)
6293 SIS_PCI_PUT_DEVICE(ivideo->lpcdev);
6294 if(ivideo->nbridge)
6295 SIS_PCI_PUT_DEVICE(ivideo->nbridge);
5186 pci_set_drvdata(pdev, NULL); 6296 pci_set_drvdata(pdev, NULL);
5187 kfree(sis_fb_info); 6297 if(!ivideo->sisvga_enabled)
5188 return -ENODEV; 6298 pci_disable_device(pdev);
6299 kfree(sis_fb_info);
6300 return ret;
5189 } 6301 }
5190 6302
5191 printk(KERN_INFO "sisfb: Framebuffer at 0x%lx, mapped to 0x%lx, size %ldk\n", 6303 printk(KERN_INFO "sisfb: Video RAM at 0x%lx, mapped to 0x%lx, size %ldk\n",
5192 ivideo->video_base, (ULONG)ivideo->video_vbase, ivideo->video_size / 1024); 6304 ivideo->video_base, (unsigned long)ivideo->video_vbase, ivideo->video_size / 1024);
6305
6306 if(ivideo->video_offset) {
6307 printk(KERN_INFO "sisfb: Viewport offset %ldk\n",
6308 ivideo->video_offset / 1024);
6309 }
5193 6310
5194 printk(KERN_INFO "sisfb: MMIO at 0x%lx, mapped to 0x%lx, size %ldk\n", 6311 printk(KERN_INFO "sisfb: MMIO at 0x%lx, mapped to 0x%lx, size %ldk\n",
5195 ivideo->mmio_base, (ULONG)ivideo->mmio_vbase, ivideo->mmio_size / 1024); 6312 ivideo->mmio_base, (unsigned long)ivideo->mmio_vbase, ivideo->mmio_size / 1024);
6313
5196 6314
6315 /* Determine the size of the command queue */
6316 if(ivideo->sisvga_engine == SIS_300_VGA) {
6317 ivideo->cmdQueueSize = TURBO_QUEUE_AREA_SIZE;
6318 } else {
6319 if(ivideo->chip == XGI_20) {
6320 ivideo->cmdQueueSize = COMMAND_QUEUE_AREA_SIZE_Z7;
6321 } else {
6322 ivideo->cmdQueueSize = COMMAND_QUEUE_AREA_SIZE;
6323 }
6324 }
6325
6326 /* Engines are no longer initialized here; this is
6327 * now done after the first mode-switch (if the
6328 * submitted var has its acceleration flags set).
6329 */
6330
6331 /* Calculate the base of the (unused) hw cursor */
6332 ivideo->hwcursor_vbase = ivideo->video_vbase
6333 + ivideo->video_size
6334 - ivideo->cmdQueueSize
6335 - ivideo->hwcursor_size;
6336 ivideo->caps |= HW_CURSOR_CAP;
6337
6338 /* Initialize offscreen memory manager */
5197 if((ivideo->havenoheap = sisfb_heap_init(ivideo))) { 6339 if((ivideo->havenoheap = sisfb_heap_init(ivideo))) {
5198 printk(KERN_WARNING "sisfb: Failed to initialize offscreen memory heap\n"); 6340 printk(KERN_WARNING "sisfb: Failed to initialize offscreen memory heap\n");
5199 } 6341 }
5200 6342
5201 /* Used for clearing the screen only, therefore respect our mem limit */ 6343 /* Used for clearing the screen only, therefore respect our mem limit */
5202 ivideo->sishw_ext.ulVideoMemorySize = ivideo->sisfb_mem; 6344 ivideo->SiS_Pr.VideoMemoryAddress += ivideo->video_offset;
6345 ivideo->SiS_Pr.VideoMemorySize = ivideo->sisfb_mem;
5203 6346
5204 ivideo->mtrr = 0; 6347 ivideo->mtrr = -1;
5205 6348
5206 ivideo->vbflags = 0; 6349 ivideo->vbflags = 0;
5207 ivideo->lcddefmodeidx = DEFAULT_LCDMODE; 6350 ivideo->lcddefmodeidx = DEFAULT_LCDMODE;
5208 ivideo->tvdefmodeidx = DEFAULT_TVMODE; 6351 ivideo->tvdefmodeidx = DEFAULT_TVMODE;
5209 ivideo->defmodeidx = DEFAULT_MODE; 6352 ivideo->defmodeidx = DEFAULT_MODE;
5210 6353
5211 ivideo->newrom = SiSDetermineROMLayout661(&ivideo->SiS_Pr, &ivideo->sishw_ext); 6354 ivideo->newrom = 0;
6355 if(ivideo->chip < XGI_20) {
6356 if(ivideo->bios_abase) {
6357 ivideo->newrom = SiSDetermineROMLayout661(&ivideo->SiS_Pr);
6358 }
6359 }
5212 6360
5213 if((ivideo->sisfb_mode_idx < 0) || 6361 if((ivideo->sisfb_mode_idx < 0) ||
5214 ((sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni]) != 0xFF)) { 6362 ((sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni]) != 0xFF)) {
@@ -5217,192 +6365,57 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
5217 6365
5218 sisfb_get_VB_type(ivideo); 6366 sisfb_get_VB_type(ivideo);
5219 6367
5220 if(ivideo->vbflags & VB_VIDEOBRIDGE) { 6368 if(ivideo->vbflags2 & VB2_VIDEOBRIDGE) {
5221 sisfb_detect_VB_connect(ivideo); 6369 sisfb_detect_VB_connect(ivideo);
5222 } 6370 }
5223 6371
5224 ivideo->currentvbflags = ivideo->vbflags & (VB_VIDEOBRIDGE | TV_STANDARD); 6372 ivideo->currentvbflags = ivideo->vbflags & (VB_VIDEOBRIDGE | TV_STANDARD);
5225 6373
5226 if(ivideo->vbflags & VB_VIDEOBRIDGE) { 6374 /* Decide on which CRT2 device to use */
5227 if(ivideo->sisfb_crt2type != -1) { 6375 if(ivideo->vbflags2 & VB2_VIDEOBRIDGE) {
5228 if((ivideo->sisfb_crt2type == CRT2_LCD) && (ivideo->vbflags & CRT2_LCD)) { 6376 if(ivideo->sisfb_crt2type != -1) {
5229 ivideo->currentvbflags |= CRT2_LCD; 6377 if((ivideo->sisfb_crt2type == CRT2_LCD) &&
5230 } else if(ivideo->sisfb_crt2type != CRT2_LCD) { 6378 (ivideo->vbflags & CRT2_LCD)) {
5231 ivideo->currentvbflags |= ivideo->sisfb_crt2type; 6379 ivideo->currentvbflags |= CRT2_LCD;
5232 } 6380 } else if(ivideo->sisfb_crt2type != CRT2_LCD) {
5233 } else { 6381 ivideo->currentvbflags |= ivideo->sisfb_crt2type;
5234 /* Chrontel 700x TV detection often unreliable, therefore use a 6382 }
5235 * different default order on such machines 6383 } else {
5236 */ 6384 /* Chrontel 700x TV detection often unreliable, therefore
5237 if((ivideo->sisvga_engine == SIS_300_VGA) && (ivideo->vbflags & VB_CHRONTEL)) { 6385 * use a different default order on such machines
5238 if(ivideo->vbflags & CRT2_LCD) ivideo->currentvbflags |= CRT2_LCD; 6386 */
5239 else if(ivideo->vbflags & CRT2_TV) ivideo->currentvbflags |= CRT2_TV; 6387 if((ivideo->sisvga_engine == SIS_300_VGA) &&
5240 else if(ivideo->vbflags & CRT2_VGA) ivideo->currentvbflags |= CRT2_VGA; 6388 (ivideo->vbflags2 & VB2_CHRONTEL)) {
5241 } else { 6389 if(ivideo->vbflags & CRT2_LCD)
5242 if(ivideo->vbflags & CRT2_TV) ivideo->currentvbflags |= CRT2_TV; 6390 ivideo->currentvbflags |= CRT2_LCD;
5243 else if(ivideo->vbflags & CRT2_LCD) ivideo->currentvbflags |= CRT2_LCD; 6391 else if(ivideo->vbflags & CRT2_TV)
5244 else if(ivideo->vbflags & CRT2_VGA) ivideo->currentvbflags |= CRT2_VGA; 6392 ivideo->currentvbflags |= CRT2_TV;
5245 } 6393 else if(ivideo->vbflags & CRT2_VGA)
5246 } 6394 ivideo->currentvbflags |= CRT2_VGA;
6395 } else {
6396 if(ivideo->vbflags & CRT2_TV)
6397 ivideo->currentvbflags |= CRT2_TV;
6398 else if(ivideo->vbflags & CRT2_LCD)
6399 ivideo->currentvbflags |= CRT2_LCD;
6400 else if(ivideo->vbflags & CRT2_VGA)
6401 ivideo->currentvbflags |= CRT2_VGA;
6402 }
6403 }
5247 } 6404 }
5248 6405
5249 if(ivideo->vbflags & CRT2_LCD) { 6406 if(ivideo->vbflags & CRT2_LCD) {
5250 inSISIDXREG(SISCR, 0x36, reg); 6407 sisfb_detect_lcd_type(ivideo);
5251 reg &= 0x0f;
5252 if(ivideo->sisvga_engine == SIS_300_VGA) {
5253 ivideo->CRT2LCDType = sis300paneltype[reg];
5254 } else if(ivideo->chip >= SIS_661) {
5255 ivideo->CRT2LCDType = sis661paneltype[reg];
5256 } else {
5257 ivideo->CRT2LCDType = sis310paneltype[reg];
5258 if((ivideo->chip == SIS_550) && (sisfb_fstn)) {
5259 if((ivideo->CRT2LCDType != LCD_640x480_2) &&
5260 (ivideo->CRT2LCDType != LCD_640x480_3)) {
5261 ivideo->CRT2LCDType = LCD_320x480;
5262 }
5263 }
5264 }
5265 if(ivideo->CRT2LCDType == LCD_UNKNOWN) {
5266 /* For broken BIOSes: Assume 1024x768, RGB18 */
5267 ivideo->CRT2LCDType = LCD_1024x768;
5268 setSISIDXREG(SISCR,0x36,0xf0,0x02);
5269 setSISIDXREG(SISCR,0x37,0xee,0x01);
5270 printk(KERN_DEBUG "sisfb: Invalid panel ID (%02x), assuming 1024x768, RGB18\n", reg);
5271 }
5272 for(i = 0; i < SIS_LCD_NUMBER; i++) {
5273 if(ivideo->CRT2LCDType == sis_lcd_data[i].lcdtype) {
5274 ivideo->lcdxres = sis_lcd_data[i].xres;
5275 ivideo->lcdyres = sis_lcd_data[i].yres;
5276 ivideo->lcddefmodeidx = sis_lcd_data[i].default_mode_idx;
5277 break;
5278 }
5279 }
5280 if(ivideo->SiS_Pr.SiS_CustomT == CUT_BARCO1366) {
5281 ivideo->lcdxres = 1360; ivideo->lcdyres = 1024; ivideo->lcddefmodeidx = 99;
5282 } else if(ivideo->SiS_Pr.SiS_CustomT == CUT_PANEL848) {
5283 ivideo->lcdxres = 848; ivideo->lcdyres = 480; ivideo->lcddefmodeidx = 47;
5284 }
5285 printk(KERN_DEBUG "sisfb: Detected %dx%d flat panel\n",
5286 ivideo->lcdxres, ivideo->lcdyres);
5287 }
5288
5289#ifdef CONFIG_FB_SIS_300
5290 /* Save the current PanelDelayCompensation if the LCD is currently used */
5291 if(ivideo->sisvga_engine == SIS_300_VGA) {
5292 if(ivideo->vbflags & (VB_LVDS | VB_30xBDH)) {
5293 int tmp;
5294 inSISIDXREG(SISCR,0x30,tmp);
5295 if(tmp & 0x20) {
5296 /* Currently on LCD? If yes, read current pdc */
5297 inSISIDXREG(SISPART1,0x13,ivideo->detectedpdc);
5298 ivideo->detectedpdc &= 0x3c;
5299 if(ivideo->SiS_Pr.PDC == -1) {
5300 /* Let option override detection */
5301 ivideo->SiS_Pr.PDC = ivideo->detectedpdc;
5302 }
5303 printk(KERN_INFO "sisfb: Detected LCD PDC 0x%02x\n",
5304 ivideo->detectedpdc);
5305 }
5306 if((ivideo->SiS_Pr.PDC != -1) && (ivideo->SiS_Pr.PDC != ivideo->detectedpdc)) {
5307 printk(KERN_INFO "sisfb: Using LCD PDC 0x%02x\n",
5308 ivideo->SiS_Pr.PDC);
5309 }
5310 }
5311 } 6408 }
5312#endif
5313
5314#ifdef CONFIG_FB_SIS_315
5315 if(ivideo->sisvga_engine == SIS_315_VGA) {
5316
5317 /* Try to find about LCDA */
5318 if(ivideo->vbflags & (VB_301C | VB_302B | VB_301LV | VB_302LV | VB_302ELV)) {
5319 int tmp;
5320 inSISIDXREG(SISPART1,0x13,tmp);
5321 if(tmp & 0x04) {
5322 ivideo->SiS_Pr.SiS_UseLCDA = TRUE;
5323 ivideo->detectedlcda = 0x03;
5324 }
5325 }
5326
5327 /* Save PDC */
5328 if(ivideo->vbflags & (VB_301LV | VB_302LV | VB_302ELV)) {
5329 int tmp;
5330 inSISIDXREG(SISCR,0x30,tmp);
5331 if((tmp & 0x20) || (ivideo->detectedlcda != 0xff)) {
5332 /* Currently on LCD? If yes, read current pdc */
5333 u8 pdc;
5334 inSISIDXREG(SISPART1,0x2D,pdc);
5335 ivideo->detectedpdc = (pdc & 0x0f) << 1;
5336 ivideo->detectedpdca = (pdc & 0xf0) >> 3;
5337 inSISIDXREG(SISPART1,0x35,pdc);
5338 ivideo->detectedpdc |= ((pdc >> 7) & 0x01);
5339 inSISIDXREG(SISPART1,0x20,pdc);
5340 ivideo->detectedpdca |= ((pdc >> 6) & 0x01);
5341 if(ivideo->newrom) {
5342 /* New ROM invalidates other PDC resp. */
5343 if(ivideo->detectedlcda != 0xff) {
5344 ivideo->detectedpdc = 0xff;
5345 } else {
5346 ivideo->detectedpdca = 0xff;
5347 }
5348 }
5349 if(ivideo->SiS_Pr.PDC == -1) {
5350 if(ivideo->detectedpdc != 0xff) {
5351 ivideo->SiS_Pr.PDC = ivideo->detectedpdc;
5352 }
5353 }
5354 if(ivideo->SiS_Pr.PDCA == -1) {
5355 if(ivideo->detectedpdca != 0xff) {
5356 ivideo->SiS_Pr.PDCA = ivideo->detectedpdca;
5357 }
5358 }
5359 if(ivideo->detectedpdc != 0xff) {
5360 printk(KERN_INFO
5361 "sisfb: Detected LCD PDC 0x%02x (for LCD=CRT2)\n",
5362 ivideo->detectedpdc);
5363 }
5364 if(ivideo->detectedpdca != 0xff) {
5365 printk(KERN_INFO
5366 "sisfb: Detected LCD PDC1 0x%02x (for LCD=CRT1)\n",
5367 ivideo->detectedpdca);
5368 }
5369 }
5370
5371 /* Save EMI */
5372 if(ivideo->vbflags & (VB_302LV | VB_302ELV)) {
5373 inSISIDXREG(SISPART4,0x30,ivideo->SiS_Pr.EMI_30);
5374 inSISIDXREG(SISPART4,0x31,ivideo->SiS_Pr.EMI_31);
5375 inSISIDXREG(SISPART4,0x32,ivideo->SiS_Pr.EMI_32);
5376 inSISIDXREG(SISPART4,0x33,ivideo->SiS_Pr.EMI_33);
5377 ivideo->SiS_Pr.HaveEMI = TRUE;
5378 if((tmp & 0x20) || (ivideo->detectedlcda != 0xff)) {
5379 ivideo->SiS_Pr.HaveEMILCD = TRUE;
5380 }
5381 }
5382 }
5383
5384 /* Let user override detected PDCs (all bridges) */
5385 if(ivideo->vbflags & (VB_301B | VB_301C | VB_301LV | VB_302LV | VB_302ELV)) {
5386 if((ivideo->SiS_Pr.PDC != -1) && (ivideo->SiS_Pr.PDC != ivideo->detectedpdc)) {
5387 printk(KERN_INFO "sisfb: Using LCD PDC 0x%02x (for LCD=CRT2)\n",
5388 ivideo->SiS_Pr.PDC);
5389 }
5390 if((ivideo->SiS_Pr.PDCA != -1) && (ivideo->SiS_Pr.PDCA != ivideo->detectedpdca)) {
5391 printk(KERN_INFO "sisfb: Using LCD PDC1 0x%02x (for LCD=CRT1)\n",
5392 ivideo->SiS_Pr.PDCA);
5393 }
5394 }
5395 6409
5396 } 6410 sisfb_save_pdc_emi(ivideo);
5397#endif
5398 6411
5399 if(!ivideo->sisfb_crt1off) { 6412 if(!ivideo->sisfb_crt1off) {
5400 sisfb_handle_ddc(ivideo, &ivideo->sisfb_thismonitor, 0); 6413 sisfb_handle_ddc(ivideo, &ivideo->sisfb_thismonitor, 0);
5401 } else { 6414 } else {
5402 if((ivideo->vbflags & (VB_301|VB_301B|VB_301C|VB_302B)) && 6415 if((ivideo->vbflags2 & VB2_SISTMDSBRIDGE) &&
5403 (ivideo->vbflags & (CRT2_VGA | CRT2_LCD))) { 6416 (ivideo->vbflags & (CRT2_VGA | CRT2_LCD))) {
5404 sisfb_handle_ddc(ivideo, &ivideo->sisfb_thismonitor, 1); 6417 sisfb_handle_ddc(ivideo, &ivideo->sisfb_thismonitor, 1);
5405 } 6418 }
5406 } 6419 }
5407 6420
5408 if(ivideo->sisfb_mode_idx >= 0) { 6421 if(ivideo->sisfb_mode_idx >= 0) {
@@ -5434,7 +6447,8 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
5434 ivideo->mode_no = sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni]; 6447 ivideo->mode_no = sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni];
5435 6448
5436 if(ivideo->refresh_rate != 0) { 6449 if(ivideo->refresh_rate != 0) {
5437 sisfb_search_refresh_rate(ivideo, ivideo->refresh_rate, ivideo->sisfb_mode_idx); 6450 sisfb_search_refresh_rate(ivideo, ivideo->refresh_rate,
6451 ivideo->sisfb_mode_idx);
5438 } 6452 }
5439 6453
5440 if(ivideo->rate_idx == 0) { 6454 if(ivideo->rate_idx == 0) {
@@ -5443,9 +6457,12 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
5443 } 6457 }
5444 6458
5445 if(ivideo->sisfb_thismonitor.datavalid) { 6459 if(ivideo->sisfb_thismonitor.datavalid) {
5446 if(!sisfb_verify_rate(ivideo, &ivideo->sisfb_thismonitor, ivideo->sisfb_mode_idx, 6460 if(!sisfb_verify_rate(ivideo, &ivideo->sisfb_thismonitor,
5447 ivideo->rate_idx, ivideo->refresh_rate)) { 6461 ivideo->sisfb_mode_idx,
5448 printk(KERN_INFO "sisfb: WARNING: Refresh rate exceeds monitor specs!\n"); 6462 ivideo->rate_idx,
6463 ivideo->refresh_rate)) {
6464 printk(KERN_INFO "sisfb: WARNING: Refresh rate "
6465 "exceeds monitor specs!\n");
5449 } 6466 }
5450 } 6467 }
5451 6468
@@ -5454,28 +6471,34 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
5454 ivideo->video_height = sisbios_mode[ivideo->sisfb_mode_idx].yres; 6471 ivideo->video_height = sisbios_mode[ivideo->sisfb_mode_idx].yres;
5455 6472
5456 sisfb_set_vparms(ivideo); 6473 sisfb_set_vparms(ivideo);
5457
5458#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
5459 6474
5460 /* ---------------- For 2.4: Now switch the mode ------------------ */ 6475#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
5461 6476
5462 printk(KERN_INFO "sisfb: Mode is %dx%dx%d (%dHz)\n", 6477 /* ---------------- For 2.4: Now switch the mode ------------------ */
5463 ivideo->video_width, ivideo->video_height, ivideo->video_bpp, 6478
6479 printk(KERN_INFO "sisfb: Setting mode %dx%dx%d (%dHz)\n",
6480 ivideo->video_width, ivideo->video_height, ivideo->video_bpp,
5464 ivideo->refresh_rate); 6481 ivideo->refresh_rate);
5465 6482
6483 /* Determine whether or not acceleration is to be
6484 * used. Need to know before pre/post_set_mode()
6485 */
6486 ivideo->accel = 0;
6487 ivideo->default_var.accel_flags &= ~FB_ACCELF_TEXT;
6488 if(ivideo->sisfb_accel) {
6489 ivideo->accel = -1;
6490 ivideo->default_var.accel_flags |= FB_ACCELF_TEXT;
6491 }
6492
6493 /* Now switch the mode */
5466 sisfb_pre_setmode(ivideo); 6494 sisfb_pre_setmode(ivideo);
5467 6495
5468 if(SiSSetMode(&ivideo->SiS_Pr, &ivideo->sishw_ext, ivideo->mode_no) == 0) { 6496 if(SiSSetMode(&ivideo->SiS_Pr, ivideo->mode_no) == 0) {
5469 printk(KERN_ERR "sisfb: Fatal error: Setting mode[0x%x] failed\n", 6497 printk(KERN_ERR "sisfb: Fatal error: Setting mode[0x%x] failed\n",
5470 ivideo->mode_no); 6498 ivideo->mode_no);
5471 iounmap(ivideo->video_vbase); 6499 ret = -EINVAL;
5472 iounmap(ivideo->mmio_vbase); 6500 iounmap(ivideo->mmio_vbase);
5473 release_mem_region(ivideo->video_base, ivideo->video_size); 6501 goto error_0;
5474 release_mem_region(ivideo->mmio_base, ivideo->mmio_size);
5475 if(ivideo->bios_abase) vfree(ivideo->bios_abase);
5476 pci_set_drvdata(pdev, NULL);
5477 kfree(sis_fb_info);
5478 return -EINVAL;
5479 } 6502 }
5480 6503
5481 outSISIDXREG(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD); 6504 outSISIDXREG(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD);
@@ -5488,18 +6511,17 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
5488 /* Force reset of x virtual in crtc_to_var */ 6511 /* Force reset of x virtual in crtc_to_var */
5489 ivideo->default_var.xres_virtual = 0; 6512 ivideo->default_var.xres_virtual = 0;
5490 6513
6514 /* Copy mode timing to var */
5491 sisfb_crtc_to_var(ivideo, &ivideo->default_var); 6515 sisfb_crtc_to_var(ivideo, &ivideo->default_var);
5492 6516
6517 /* Find out about screen pitch */
5493 sisfb_calc_pitch(ivideo, &ivideo->default_var); 6518 sisfb_calc_pitch(ivideo, &ivideo->default_var);
5494 sisfb_set_pitch(ivideo); 6519 sisfb_set_pitch(ivideo);
5495 6520
5496 ivideo->accel = 0; 6521 /* Init the accelerator (does nothing currently) */
5497 if(ivideo->sisfb_accel) {
5498 ivideo->accel = -1;
5499 ivideo->default_var.accel_flags |= FB_ACCELF_TEXT;
5500 }
5501 sisfb_initaccel(ivideo); 6522 sisfb_initaccel(ivideo);
5502 6523
6524 /* Init some fbinfo entries */
5503 sis_fb_info->node = -1; 6525 sis_fb_info->node = -1;
5504 sis_fb_info->flags = FBINFO_FLAG_DEFAULT; 6526 sis_fb_info->flags = FBINFO_FLAG_DEFAULT;
5505 sis_fb_info->fbops = &sisfb_ops; 6527 sis_fb_info->fbops = &sisfb_ops;
@@ -5515,41 +6537,42 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
5515#else /* --------- For 2.6: Setup a somewhat sane default var ------------ */ 6537#else /* --------- For 2.6: Setup a somewhat sane default var ------------ */
5516 6538
5517 printk(KERN_INFO "sisfb: Default mode is %dx%dx%d (%dHz)\n", 6539 printk(KERN_INFO "sisfb: Default mode is %dx%dx%d (%dHz)\n",
5518 ivideo->video_width, ivideo->video_height, ivideo->video_bpp, 6540 ivideo->video_width, ivideo->video_height, ivideo->video_bpp,
5519 ivideo->refresh_rate); 6541 ivideo->refresh_rate);
5520 6542
6543 /* Set up the default var according to chosen default display mode */
5521 ivideo->default_var.xres = ivideo->default_var.xres_virtual = ivideo->video_width; 6544 ivideo->default_var.xres = ivideo->default_var.xres_virtual = ivideo->video_width;
5522 ivideo->default_var.yres = ivideo->default_var.yres_virtual = ivideo->video_height; 6545 ivideo->default_var.yres = ivideo->default_var.yres_virtual = ivideo->video_height;
5523 ivideo->default_var.bits_per_pixel = ivideo->video_bpp; 6546 ivideo->default_var.bits_per_pixel = ivideo->video_bpp;
5524 6547
5525 sisfb_bpp_to_var(ivideo, &ivideo->default_var); 6548 sisfb_bpp_to_var(ivideo, &ivideo->default_var);
5526 6549
5527 ivideo->default_var.pixclock = (u32) (1000000000 / 6550 ivideo->default_var.pixclock = (u32) (1000000000 /
5528 sisfb_mode_rate_to_dclock(&ivideo->SiS_Pr, &ivideo->sishw_ext, 6551 sisfb_mode_rate_to_dclock(&ivideo->SiS_Pr, ivideo->mode_no, ivideo->rate_idx));
5529 ivideo->mode_no, ivideo->rate_idx)); 6552
5530 6553 if(sisfb_mode_rate_to_ddata(&ivideo->SiS_Pr, ivideo->mode_no,
5531 if(sisfb_mode_rate_to_ddata(&ivideo->SiS_Pr, &ivideo->sishw_ext, 6554 ivideo->rate_idx, &ivideo->default_var)) {
5532 ivideo->mode_no, ivideo->rate_idx, &ivideo->default_var)) { 6555 if((ivideo->default_var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {
5533 if((ivideo->default_var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) { 6556 ivideo->default_var.pixclock <<= 1;
5534 ivideo->default_var.pixclock <<= 1; 6557 }
5535 } 6558 }
5536 }
5537 6559
5538 if(ivideo->sisfb_ypan) { 6560 if(ivideo->sisfb_ypan) {
5539 /* Maximize regardless of sisfb_max at startup */ 6561 /* Maximize regardless of sisfb_max at startup */
5540 ivideo->default_var.yres_virtual = sisfb_calc_maxyres(ivideo, &ivideo->default_var); 6562 ivideo->default_var.yres_virtual =
5541 if(ivideo->default_var.yres_virtual < ivideo->default_var.yres) { 6563 sisfb_calc_maxyres(ivideo, &ivideo->default_var);
5542 ivideo->default_var.yres_virtual = ivideo->default_var.yres; 6564 if(ivideo->default_var.yres_virtual < ivideo->default_var.yres) {
5543 } 6565 ivideo->default_var.yres_virtual = ivideo->default_var.yres;
6566 }
5544 } 6567 }
5545 6568
5546 sisfb_calc_pitch(ivideo, &ivideo->default_var); 6569 sisfb_calc_pitch(ivideo, &ivideo->default_var);
5547 6570
5548 ivideo->accel = 0; 6571 ivideo->accel = 0;
5549 if(ivideo->sisfb_accel) { 6572 if(ivideo->sisfb_accel) {
5550 ivideo->accel = -1; 6573 ivideo->accel = -1;
5551#ifdef STUPID_ACCELF_TEXT_SHIT 6574#ifdef STUPID_ACCELF_TEXT_SHIT
5552 ivideo->default_var.accel_flags |= FB_ACCELF_TEXT; 6575 ivideo->default_var.accel_flags |= FB_ACCELF_TEXT;
5553#endif 6576#endif
5554 } 6577 }
5555 sisfb_initaccel(ivideo); 6578 sisfb_initaccel(ivideo);
@@ -5566,21 +6589,21 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
5566#endif 6589#endif
5567 sis_fb_info->var = ivideo->default_var; 6590 sis_fb_info->var = ivideo->default_var;
5568 sis_fb_info->fix = ivideo->sisfb_fix; 6591 sis_fb_info->fix = ivideo->sisfb_fix;
5569 sis_fb_info->screen_base = ivideo->video_vbase; 6592 sis_fb_info->screen_base = ivideo->video_vbase + ivideo->video_offset;
5570 sis_fb_info->fbops = &sisfb_ops; 6593 sis_fb_info->fbops = &sisfb_ops;
5571 6594
5572 sisfb_get_fix(&sis_fb_info->fix, -1, sis_fb_info); 6595 sisfb_get_fix(&sis_fb_info->fix, -1, sis_fb_info);
5573 sis_fb_info->pseudo_palette = ivideo->pseudo_palette; 6596 sis_fb_info->pseudo_palette = ivideo->pseudo_palette;
5574 6597
5575 fb_alloc_cmap(&sis_fb_info->cmap, 256 , 0); 6598 fb_alloc_cmap(&sis_fb_info->cmap, 256 , 0);
5576#endif /* 2.6 */ 6599#endif /* 2.6 */
5577 6600
5578 printk(KERN_DEBUG "sisfb: Initial vbflags 0x%lx\n", (unsigned long)ivideo->vbflags); 6601 printk(KERN_DEBUG "sisfb: Initial vbflags 0x%x\n", (int)ivideo->vbflags);
5579 6602
5580#ifdef CONFIG_MTRR 6603#ifdef CONFIG_MTRR
5581 ivideo->mtrr = mtrr_add(ivideo->video_base, ivideo->video_size, 6604 ivideo->mtrr = mtrr_add(ivideo->video_base, ivideo->video_size,
5582 MTRR_TYPE_WRCOMB, 1); 6605 MTRR_TYPE_WRCOMB, 1);
5583 if(!ivideo->mtrr) { 6606 if(ivideo->mtrr < 0) {
5584 printk(KERN_DEBUG "sisfb: Failed to add MTRRs\n"); 6607 printk(KERN_DEBUG "sisfb: Failed to add MTRRs\n");
5585 } 6608 }
5586#endif 6609#endif
@@ -5591,14 +6614,9 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
5591 6614
5592 if(register_framebuffer(sis_fb_info) < 0) { 6615 if(register_framebuffer(sis_fb_info) < 0) {
5593 printk(KERN_ERR "sisfb: Fatal error: Failed to register framebuffer\n"); 6616 printk(KERN_ERR "sisfb: Fatal error: Failed to register framebuffer\n");
5594 iounmap(ivideo->video_vbase); 6617 ret = -EINVAL;
5595 iounmap(ivideo->mmio_vbase); 6618 iounmap(ivideo->mmio_vbase);
5596 release_mem_region(ivideo->video_base, ivideo->video_size); 6619 goto error_0;
5597 release_mem_region(ivideo->mmio_base, ivideo->mmio_size);
5598 if(ivideo->bios_abase) vfree(ivideo->bios_abase);
5599 pci_set_drvdata(pdev, NULL);
5600 kfree(sis_fb_info);
5601 return -EINVAL;
5602 } 6620 }
5603 6621
5604 ivideo->registered = 1; 6622 ivideo->registered = 1;
@@ -5607,21 +6625,47 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
5607 ivideo->next = card_list; 6625 ivideo->next = card_list;
5608 card_list = ivideo; 6626 card_list = ivideo;
5609 6627
6628#ifdef SIS_OLD_CONFIG_COMPAT
6629 {
6630 int ret;
6631 /* Our ioctls are all "32/64bit compatible" */
6632 ret = register_ioctl32_conversion(FBIO_ALLOC, NULL);
6633 ret |= register_ioctl32_conversion(FBIO_FREE, NULL);
6634 ret |= register_ioctl32_conversion(FBIOGET_VBLANK, NULL);
6635 ret |= register_ioctl32_conversion(SISFB_GET_INFO_SIZE, NULL);
6636 ret |= register_ioctl32_conversion(SISFB_GET_INFO, NULL);
6637 ret |= register_ioctl32_conversion(SISFB_GET_TVPOSOFFSET, NULL);
6638 ret |= register_ioctl32_conversion(SISFB_SET_TVPOSOFFSET, NULL);
6639 ret |= register_ioctl32_conversion(SISFB_SET_LOCK, NULL);
6640 ret |= register_ioctl32_conversion(SISFB_GET_VBRSTATUS, NULL);
6641 ret |= register_ioctl32_conversion(SISFB_GET_AUTOMAXIMIZE, NULL);
6642 ret |= register_ioctl32_conversion(SISFB_SET_AUTOMAXIMIZE, NULL);
6643 ret |= register_ioctl32_conversion(SISFB_COMMAND, NULL);
6644 if(ret)
6645 printk(KERN_ERR
6646 "sisfb: Error registering ioctl32 translations\n");
6647 else
6648 ivideo->ioctl32registered = 1;
6649 }
6650#endif
6651
5610 printk(KERN_INFO "sisfb: 2D acceleration is %s, y-panning %s\n", 6652 printk(KERN_INFO "sisfb: 2D acceleration is %s, y-panning %s\n",
5611 ivideo->sisfb_accel ? "enabled" : "disabled", 6653 ivideo->sisfb_accel ? "enabled" : "disabled",
5612 ivideo->sisfb_ypan ? 6654 ivideo->sisfb_ypan ?
5613 (ivideo->sisfb_max ? "enabled (auto-max)" : "enabled (no auto-max)") : "disabled"); 6655 (ivideo->sisfb_max ? "enabled (auto-max)" :
6656 "enabled (no auto-max)") :
6657 "disabled");
5614 6658
5615 6659
5616 printk(KERN_INFO "fb%d: %s frame buffer device, Version %d.%d.%d\n", 6660 printk(KERN_INFO "fb%d: %s frame buffer device version %d.%d.%d\n",
5617#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 6661#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
5618 GET_FB_IDX(sis_fb_info->node), 6662 GET_FB_IDX(sis_fb_info->node),
5619#else 6663#else
5620 sis_fb_info->node, 6664 sis_fb_info->node,
5621#endif 6665#endif
5622 ivideo->myid, VER_MAJOR, VER_MINOR, VER_LEVEL); 6666 ivideo->myid, VER_MAJOR, VER_MINOR, VER_LEVEL);
5623 6667
5624 printk(KERN_INFO "sisfb: (C) 2001-2004 Thomas Winischhofer.\n"); 6668 printk(KERN_INFO "sisfb: Copyright (C) 2001-2005 Thomas Winischhofer\n");
5625 6669
5626 } /* if mode = "none" */ 6670 } /* if mode = "none" */
5627 6671
@@ -5634,26 +6678,62 @@ static int __devinit sisfb_probe(struct pci_dev *pdev,
5634 6678
5635static void __devexit sisfb_remove(struct pci_dev *pdev) 6679static void __devexit sisfb_remove(struct pci_dev *pdev)
5636{ 6680{
5637 struct sis_video_info *ivideo = pci_get_drvdata(pdev); 6681 struct sis_video_info *ivideo = pci_get_drvdata(pdev);
5638 struct fb_info *sis_fb_info = ivideo->memyselfandi; 6682 struct fb_info *sis_fb_info = ivideo->memyselfandi;
5639 int registered = ivideo->registered; 6683 int registered = ivideo->registered;
6684 int modechanged = ivideo->modechanged;
6685
6686#ifdef SIS_OLD_CONFIG_COMPAT
6687 if(ivideo->ioctl32registered) {
6688 int ret;
6689 ret = unregister_ioctl32_conversion(FBIO_ALLOC);
6690 ret |= unregister_ioctl32_conversion(FBIO_FREE);
6691 ret |= unregister_ioctl32_conversion(FBIOGET_VBLANK);
6692 ret |= unregister_ioctl32_conversion(SISFB_GET_INFO_SIZE);
6693 ret |= unregister_ioctl32_conversion(SISFB_GET_INFO);
6694 ret |= unregister_ioctl32_conversion(SISFB_GET_TVPOSOFFSET);
6695 ret |= unregister_ioctl32_conversion(SISFB_SET_TVPOSOFFSET);
6696 ret |= unregister_ioctl32_conversion(SISFB_SET_LOCK);
6697 ret |= unregister_ioctl32_conversion(SISFB_GET_VBRSTATUS);
6698 ret |= unregister_ioctl32_conversion(SISFB_GET_AUTOMAXIMIZE);
6699 ret |= unregister_ioctl32_conversion(SISFB_SET_AUTOMAXIMIZE);
6700 ret |= unregister_ioctl32_conversion(SISFB_COMMAND);
6701 if(ret)
6702 printk(KERN_ERR
6703 "sisfb: Error unregistering ioctl32 translations\n");
6704 }
6705#endif
5640 6706
5641 /* Unmap */ 6707 /* Unmap */
5642 iounmap(ivideo->video_vbase);
5643 iounmap(ivideo->mmio_vbase); 6708 iounmap(ivideo->mmio_vbase);
5644 vfree(ivideo->bios_abase); 6709 iounmap(ivideo->video_vbase);
5645 6710
5646 /* Release mem regions */ 6711 /* Release mem regions */
5647 release_mem_region(ivideo->video_base, ivideo->video_size); 6712 release_mem_region(ivideo->video_base, ivideo->video_size);
5648 release_mem_region(ivideo->mmio_base, ivideo->mmio_size); 6713 release_mem_region(ivideo->mmio_base, ivideo->mmio_size);
5649 6714
6715 vfree(ivideo->bios_abase);
6716
6717 if(ivideo->lpcdev)
6718 SIS_PCI_PUT_DEVICE(ivideo->lpcdev);
6719
6720 if(ivideo->nbridge)
6721 SIS_PCI_PUT_DEVICE(ivideo->nbridge);
6722
5650#ifdef CONFIG_MTRR 6723#ifdef CONFIG_MTRR
5651 /* Release MTRR region */ 6724 /* Release MTRR region */
5652 if(ivideo->mtrr) { 6725 if(ivideo->mtrr >= 0)
5653 mtrr_del(ivideo->mtrr, ivideo->video_base, ivideo->video_size); 6726 mtrr_del(ivideo->mtrr, ivideo->video_base, ivideo->video_size);
5654 }
5655#endif 6727#endif
5656 6728
6729 pci_set_drvdata(pdev, NULL);
6730
6731 /* If device was disabled when starting, disable
6732 * it when quitting.
6733 */
6734 if(!ivideo->sisvga_enabled)
6735 pci_disable_device(pdev);
6736
5657 /* Unregister the framebuffer */ 6737 /* Unregister the framebuffer */
5658 if(ivideo->registered) { 6738 if(ivideo->registered) {
5659 unregister_framebuffer(sis_fb_info); 6739 unregister_framebuffer(sis_fb_info);
@@ -5664,7 +6744,7 @@ static void __devexit sisfb_remove(struct pci_dev *pdev)
5664#endif 6744#endif
5665 } 6745 }
5666 6746
5667 pci_set_drvdata(pdev, NULL); 6747 /* OK, our ivideo is gone for good from here. */
5668 6748
5669 /* TODO: Restore the initial mode 6749 /* TODO: Restore the initial mode
5670 * This sounds easy but is as good as impossible 6750 * This sounds easy but is as good as impossible
@@ -5673,15 +6753,15 @@ static void __devexit sisfb_remove(struct pci_dev *pdev)
5673 * from machine to machine. Depends on the type 6753 * from machine to machine. Depends on the type
5674 * of integration between chipset and bridge. 6754 * of integration between chipset and bridge.
5675 */ 6755 */
5676 if(registered) { 6756 if(registered && modechanged)
5677 printk(KERN_INFO "sisfb: Restoring of text mode not supported yet\n"); 6757 printk(KERN_INFO
5678 } 6758 "sisfb: Restoring of text mode not supported yet\n");
5679}; 6759};
5680 6760
5681static struct pci_driver sisfb_driver = { 6761static struct pci_driver sisfb_driver = {
5682 .name = "sisfb", 6762 .name = "sisfb",
5683 .id_table = sisfb_pci_table, 6763 .id_table = sisfb_pci_table,
5684 .probe = sisfb_probe, 6764 .probe = sisfb_probe,
5685 .remove = __devexit_p(sisfb_remove) 6765 .remove = __devexit_p(sisfb_remove)
5686}; 6766};
5687 6767
@@ -5693,10 +6773,11 @@ SISINITSTATIC int __init sisfb_init(void)
5693 6773
5694 if(fb_get_options("sisfb", &options)) 6774 if(fb_get_options("sisfb", &options))
5695 return -ENODEV; 6775 return -ENODEV;
6776
5696 sisfb_setup(options); 6777 sisfb_setup(options);
5697#endif 6778#endif
5698#endif 6779#endif
5699 return(pci_register_driver(&sisfb_driver)); 6780 return pci_register_driver(&sisfb_driver);
5700} 6781}
5701 6782
5702#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8) 6783#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8)
@@ -5711,36 +6792,129 @@ module_init(sisfb_init);
5711 6792
5712#ifdef MODULE 6793#ifdef MODULE
5713 6794
5714static char *mode = NULL; 6795static char *mode = NULL;
5715static int vesa = -1; 6796static int vesa = -1;
5716static unsigned int rate = 0; 6797static unsigned int rate = 0;
5717static unsigned int crt1off = 1; 6798static unsigned int crt1off = 1;
5718static unsigned int mem = 0; 6799static unsigned int mem = 0;
5719static char *forcecrt2type = NULL; 6800static char *forcecrt2type = NULL;
5720static int forcecrt1 = -1; 6801static int forcecrt1 = -1;
5721static int pdc = -1; 6802static int pdc = -1;
5722static int pdc1 = -1; 6803static int pdc1 = -1;
5723static int noaccel = -1; 6804static int noaccel = -1;
5724static int noypan = -1; 6805static int noypan = -1;
5725static int nomax = -1; 6806static int nomax = -1;
6807#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
6808static int inverse = 0;
6809#endif
6810static int userom = -1;
6811static int useoem = -1;
6812static char *tvstandard = NULL;
6813static int nocrt2rate = 0;
6814static int scalelcd = -1;
6815static char *specialtiming = NULL;
6816static int lvdshl = -1;
6817static int tvxposoffset = 0, tvyposoffset = 0;
6818#if !defined(__i386__) && !defined(__x86_64__)
6819static int resetcard = 0;
6820static int videoram = 0;
6821#endif
6822
6823static int __init sisfb_init_module(void)
6824{
6825 sisfb_setdefaultparms();
6826
6827 if(rate)
6828 sisfb_parm_rate = rate;
6829
6830 if((scalelcd == 0) || (scalelcd == 1))
6831 sisfb_scalelcd = scalelcd ^ 1;
6832
6833 /* Need to check crt2 type first for fstn/dstn */
6834
6835 if(forcecrt2type)
6836 sisfb_search_crt2type(forcecrt2type);
6837
6838 if(tvstandard)
6839 sisfb_search_tvstd(tvstandard);
6840
6841 if(mode)
6842 sisfb_search_mode(mode, FALSE);
6843 else if(vesa != -1)
6844 sisfb_search_vesamode(vesa, FALSE);
6845
6846 sisfb_crt1off = (crt1off == 0) ? 1 : 0;
6847
6848 sisfb_forcecrt1 = forcecrt1;
6849 if(forcecrt1 == 1)
6850 sisfb_crt1off = 0;
6851 else if(forcecrt1 == 0)
6852 sisfb_crt1off = 1;
6853
6854 if(noaccel == 1)
6855 sisfb_accel = 0;
6856 else if(noaccel == 0)
6857 sisfb_accel = 1;
6858
6859 if(noypan == 1)
6860 sisfb_ypan = 0;
6861 else if(noypan == 0)
6862 sisfb_ypan = 1;
6863
6864 if(nomax == 1)
6865 sisfb_max = 0;
6866 else if(nomax == 0)
6867 sisfb_max = 1;
6868
5726#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 6869#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
5727static int inverse = 0; 6870 if(inverse) sisfb_inverse = 1;
5728#endif 6871#endif
5729static int userom = -1; 6872
5730static int useoem = -1; 6873 if(mem)
5731static char *tvstandard = NULL; 6874 sisfb_parm_mem = mem;
5732static int nocrt2rate = 0; 6875
5733static int scalelcd = -1; 6876 if(userom != -1)
5734static char *specialtiming = NULL; 6877 sisfb_userom = userom;
5735static int lvdshl = -1; 6878
5736static int tvxposoffset = 0, tvyposoffset = 0; 6879 if(useoem != -1)
5737static int filter = -1; 6880 sisfb_useoem = useoem;
6881
6882 if(pdc != -1)
6883 sisfb_pdc = (pdc & 0x7f);
6884
6885 if(pdc1 != -1)
6886 sisfb_pdca = (pdc1 & 0x1f);
6887
6888 sisfb_nocrt2rate = nocrt2rate;
6889
6890 if(specialtiming)
6891 sisfb_search_specialtiming(specialtiming);
6892
6893 if((lvdshl >= 0) && (lvdshl <= 3))
6894 sisfb_lvdshl = lvdshl;
6895
6896 sisfb_tvxposoffset = tvxposoffset;
6897 sisfb_tvyposoffset = tvyposoffset;
6898
5738#if !defined(__i386__) && !defined(__x86_64__) 6899#if !defined(__i386__) && !defined(__x86_64__)
5739static int resetcard = 0; 6900 sisfb_resetcard = (resetcard) ? 1 : 0;
5740static int videoram = 0; 6901 if(videoram)
6902 sisfb_videoram = videoram;
5741#endif 6903#endif
5742 6904
5743MODULE_DESCRIPTION("SiS 300/540/630/730/315/550/65x/661/74x/330/760 framebuffer device driver"); 6905 return sisfb_init();
6906}
6907
6908static void __exit sisfb_remove_module(void)
6909{
6910 pci_unregister_driver(&sisfb_driver);
6911 printk(KERN_DEBUG "sisfb: Module unloaded\n");
6912}
6913
6914module_init(sisfb_init_module);
6915module_exit(sisfb_remove_module);
6916
6917MODULE_DESCRIPTION("SiS 300/540/630/730/315/55x/65x/661/74x/330/76x/34x, XGI V3XT/V5/V8/Z7 framebuffer device driver");
5744MODULE_LICENSE("GPL"); 6918MODULE_LICENSE("GPL");
5745MODULE_AUTHOR("Thomas Winischhofer <thomas@winischhofer.net>, Others"); 6919MODULE_AUTHOR("Thomas Winischhofer <thomas@winischhofer.net>, Others");
5746 6920
@@ -5764,7 +6938,6 @@ MODULE_PARM(lvdshl, "i");
5764MODULE_PARM(tvstandard, "s"); 6938MODULE_PARM(tvstandard, "s");
5765MODULE_PARM(tvxposoffset, "i"); 6939MODULE_PARM(tvxposoffset, "i");
5766MODULE_PARM(tvyposoffset, "i"); 6940MODULE_PARM(tvyposoffset, "i");
5767MODULE_PARM(filter, "i");
5768MODULE_PARM(nocrt2rate, "i"); 6941MODULE_PARM(nocrt2rate, "i");
5769MODULE_PARM(inverse, "i"); 6942MODULE_PARM(inverse, "i");
5770#if !defined(__i386__) && !defined(__x86_64__) 6943#if !defined(__i386__) && !defined(__x86_64__)
@@ -5793,7 +6966,6 @@ module_param(lvdshl, int, 0);
5793module_param(tvstandard, charp, 0); 6966module_param(tvstandard, charp, 0);
5794module_param(tvxposoffset, int, 0); 6967module_param(tvxposoffset, int, 0);
5795module_param(tvyposoffset, int, 0); 6968module_param(tvyposoffset, int, 0);
5796module_param(filter, int, 0);
5797module_param(nocrt2rate, int, 0); 6969module_param(nocrt2rate, int, 0);
5798#if !defined(__i386__) && !defined(__x86_64__) 6970#if !defined(__i386__) && !defined(__x86_64__)
5799module_param(resetcard, int, 0); 6971module_param(resetcard, int, 0);
@@ -5801,25 +6973,35 @@ module_param(videoram, int, 0);
5801#endif 6973#endif
5802#endif 6974#endif
5803 6975
6976#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
5804MODULE_PARM_DESC(mem, 6977MODULE_PARM_DESC(mem,
5805 "\nDetermines the beginning of the video memory heap in KB. This heap is used\n" 6978 "\nDetermines the beginning of the video memory heap in KB. This heap is used\n"
5806 "for video RAM management for eg. DRM/DRI. On 300 series, the default depends\n" 6979 "for video RAM management for eg. DRM/DRI. On 300 series, the default depends\n"
5807 "on the amount of video RAM available. If 8MB of video RAM or less is available,\n" 6980 "on the amount of video RAM available. If 8MB of video RAM or less is available,\n"
5808 "the heap starts at 4096KB, if between 8 and 16MB are available at 8192KB,\n" 6981 "the heap starts at 4096KB, if between 8 and 16MB are available at 8192KB,\n"
5809 "otherwise at 12288KB. On 315 and Xabre series, the heap size is 32KB by default.\n" 6982 "otherwise at 12288KB. On 315/330/340 series, the heap size is 32KB by default.\n"
5810 "The value is to be specified without 'KB' and must match the MaxXFBMem setting\n" 6983 "The value is to be specified without 'KB' and must match the MaxXFBMem setting\n"
5811 "for XFree86 4.x/X.org 6.7 and later.\n"); 6984 "for XFree86 4.x/X.org 6.7 and later.\n");
6985#else
6986MODULE_PARM_DESC(mem,
6987 "\nDetermines the beginning of the video memory heap in KB. This heap is used\n"
6988 "for video RAM management for eg. DRM/DRI. On 300 series, the default depends\n"
6989 "on the amount of video RAM available. If 8MB of video RAM or less is available,\n"
6990 "the heap starts at 4096KB, if between 8 and 16MB are available at 8192KB,\n"
6991 "otherwise at 12288KB. On 315/330/340 series, the heap size is 32KB by default.\n"
6992 "The value is to be specified without 'KB'.\n");
6993#endif
5812 6994
5813MODULE_PARM_DESC(noaccel, 6995MODULE_PARM_DESC(noaccel,
5814 "\nIf set to anything other than 0, 2D acceleration will be disabled.\n" 6996 "\nIf set to anything other than 0, 2D acceleration will be disabled.\n"
5815 "(default: 0)\n"); 6997 "(default: 0)\n");
5816 6998
5817MODULE_PARM_DESC(noypan, 6999MODULE_PARM_DESC(noypan,
5818 "\nIf set to anything other than 0, y-panning will be disabled and scrolling\n" 7000 "\nIf set to anything other than 0, y-panning will be disabled and scrolling\n"
5819 "will be performed by redrawing the screen. (default: 0)\n"); 7001 "will be performed by redrawing the screen. (default: 0)\n");
5820 7002
5821MODULE_PARM_DESC(nomax, 7003MODULE_PARM_DESC(nomax,
5822 "\nIf y-panning is enabled, sisfb will by default use the entire available video\n" 7004 "\nIf y-panning is enabled, sisfb will by default use the entire available video\n"
5823 "memory for the virtual screen in order to optimize scrolling performance. If\n" 7005 "memory for the virtual screen in order to optimize scrolling performance. If\n"
5824 "this is set to anything other than 0, sisfb will not do this and thereby \n" 7006 "this is set to anything other than 0, sisfb will not do this and thereby \n"
5825 "enable the user to positively specify a virtual Y size of the screen using\n" 7007 "enable the user to positively specify a virtual Y size of the screen using\n"
@@ -5827,30 +7009,30 @@ MODULE_PARM_DESC(nomax,
5827 7009
5828#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 7010#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
5829MODULE_PARM_DESC(mode, 7011MODULE_PARM_DESC(mode,
5830 "\nSelects the desired display mode in the format [X]x[Y]x[Depth], eg.\n" 7012 "\nSelects the desired display mode in the format [X]x[Y]x[Depth], eg.\n"
5831 "1024x768x16. Other formats supported include XxY-Depth and\n" 7013 "1024x768x16. Other formats supported include XxY-Depth and\n"
5832 "XxY-Depth@Rate. If the parameter is only one (decimal or hexadecimal)\n" 7014 "XxY-Depth@Rate. If the parameter is only one (decimal or hexadecimal)\n"
5833 "number, it will be interpreted as a VESA mode number. (default: none if\n" 7015 "number, it will be interpreted as a VESA mode number. (default: none if\n"
5834 "sisfb is a module; this leaves the console untouched and the driver will\n" 7016 "sisfb is a module; this leaves the console untouched and the driver will\n"
5835 "only do the video memory management for eg. DRM/DRI; 800x600x8 if sisfb\n" 7017 "only do the video memory management for eg. DRM/DRI; 800x600x8 if sisfb\n"
5836 "is in the kernel)\n"); 7018 "is in the kernel)\n");
5837MODULE_PARM_DESC(vesa, 7019MODULE_PARM_DESC(vesa,
5838 "\nSelects the desired display mode by VESA defined mode number, eg. 0x117\n" 7020 "\nSelects the desired display mode by VESA defined mode number, eg. 0x117\n"
5839 "(default: 0x0000 if sisfb is a module; this leaves the console untouched\n" 7021 "(default: 0x0000 if sisfb is a module; this leaves the console untouched\n"
5840 "and the driver will only do the video memory management for eg. DRM/DRI;\n" 7022 "and the driver will only do the video memory management for eg. DRM/DRI;\n"
5841 "0x0103 if sisfb is in the kernel)\n"); 7023 "0x0103 if sisfb is in the kernel)\n");
5842#endif 7024#endif
5843 7025
5844#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 7026#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
5845MODULE_PARM_DESC(mode, 7027MODULE_PARM_DESC(mode,
5846 "\nSelects the desired default display mode in the format XxYxDepth,\n" 7028 "\nSelects the desired default display mode in the format XxYxDepth,\n"
5847 "eg. 1024x768x16. Other formats supported include XxY-Depth and\n" 7029 "eg. 1024x768x16. Other formats supported include XxY-Depth and\n"
5848 "XxY-Depth@Rate. If the parameter is only one (decimal or hexadecimal)\n" 7030 "XxY-Depth@Rate. If the parameter is only one (decimal or hexadecimal)\n"
5849 "number, it will be interpreted as a VESA mode number. (default: 800x600x8)\n"); 7031 "number, it will be interpreted as a VESA mode number. (default: 800x600x8)\n");
5850 7032
5851MODULE_PARM_DESC(vesa, 7033MODULE_PARM_DESC(vesa,
5852 "\nSelects the desired default display mode by VESA defined mode number, eg.\n" 7034 "\nSelects the desired default display mode by VESA defined mode number, eg.\n"
5853 "0x117 (default: 0x0103)\n"); 7035 "0x117 (default: 0x0103)\n");
5854#endif 7036#endif
5855 7037
5856MODULE_PARM_DESC(rate, 7038MODULE_PARM_DESC(rate,
@@ -5880,16 +7062,16 @@ MODULE_PARM_DESC(scalelcd,
5880 "themselves. Default: 1 on LVDS panels, 0 on TMDS panels\n"); 7062 "themselves. Default: 1 on LVDS panels, 0 on TMDS panels\n");
5881 7063
5882MODULE_PARM_DESC(pdc, 7064MODULE_PARM_DESC(pdc,
5883 "\nThis is for manually selecting the LCD panel delay compensation. The driver\n" 7065 "\nThis is for manually selecting the LCD panel delay compensation. The driver\n"
5884 "should detect this correctly in most cases; however, sometimes this is not\n" 7066 "should detect this correctly in most cases; however, sometimes this is not\n"
5885 "possible. If you see 'small waves' on the LCD, try setting this to 4, 32 or 24\n" 7067 "possible. If you see 'small waves' on the LCD, try setting this to 4, 32 or 24\n"
5886 "on a 300 series chipset; 6 on a 315 series chipset. If the problem persists,\n" 7068 "on a 300 series chipset; 6 on other chipsets. If the problem persists, try\n"
5887 "try other values (on 300 series: between 4 and 60 in steps of 4; on 315 series:\n" 7069 "other values (on 300 series: between 4 and 60 in steps of 4; otherwise: any\n"
5888 "any value from 0 to 31). (default: autodetected, if LCD is active during start)\n"); 7070 "value from 0 to 31). (default: autodetected, if LCD is active during start)\n");
5889 7071
5890#ifdef CONFIG_FB_SIS_315 7072#ifdef CONFIG_FB_SIS_315
5891MODULE_PARM_DESC(pdc1, 7073MODULE_PARM_DESC(pdc1,
5892 "\nThis is same as pdc, but for LCD-via CRT1. Hence, this is for the 315/330\n" 7074 "\nThis is same as pdc, but for LCD-via CRT1. Hence, this is for the 315/330/340\n"
5893 "series only. (default: autodetected if LCD is in LCD-via-CRT1 mode during\n" 7075 "series only. (default: autodetected if LCD is in LCD-via-CRT1 mode during\n"
5894 "startup) - Note: currently, this has no effect because LCD-via-CRT1 is not\n" 7076 "startup) - Note: currently, this has no effect because LCD-via-CRT1 is not\n"
5895 "implemented yet.\n"); 7077 "implemented yet.\n");
@@ -5913,17 +7095,13 @@ MODULE_PARM_DESC(tvyposoffset,
5913 "\nRelocate TV output vertically. Possible parameters: -32 through 32.\n" 7095 "\nRelocate TV output vertically. Possible parameters: -32 through 32.\n"
5914 "Default: 0\n"); 7096 "Default: 0\n");
5915 7097
5916MODULE_PARM_DESC(filter,
5917 "\nSelects TV flicker filter type (only for systems with a SiS301 video bridge).\n"
5918 "(Possible values 0-7, default: [no filter])\n");
5919
5920MODULE_PARM_DESC(nocrt2rate, 7098MODULE_PARM_DESC(nocrt2rate,
5921 "\nSetting this to 1 will force the driver to use the default refresh rate for\n" 7099 "\nSetting this to 1 will force the driver to use the default refresh rate for\n"
5922 "CRT2 if CRT2 type is VGA. (default: 0, use same rate as CRT1)\n"); 7100 "CRT2 if CRT2 type is VGA. (default: 0, use same rate as CRT1)\n");
5923 7101
5924#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 7102#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
5925MODULE_PARM_DESC(inverse, 7103MODULE_PARM_DESC(inverse,
5926 "\nSetting this to anything but 0 should invert the display colors, but this\n" 7104 "\nSetting this to anything but 0 should invert the display colors, but this\n"
5927 "does not seem to work. (default: 0)\n"); 7105 "does not seem to work. (default: 0)\n");
5928#endif 7106#endif
5929 7107
@@ -5931,98 +7109,23 @@ MODULE_PARM_DESC(inverse,
5931#ifdef CONFIG_FB_SIS_300 7109#ifdef CONFIG_FB_SIS_300
5932MODULE_PARM_DESC(resetcard, 7110MODULE_PARM_DESC(resetcard,
5933 "\nSet this to 1 in order to reset (POST) the card on non-x86 machines where\n" 7111 "\nSet this to 1 in order to reset (POST) the card on non-x86 machines where\n"
5934 "the BIOS did not POST the card (only supported for SiS 300/305 currently).\n" 7112 "the BIOS did not POST the card (only supported for SiS 300/305 and XGI cards\n"
5935 "Default: 0\n"); 7113 "currently). Default: 0\n");
5936 7114
5937MODULE_PARM_DESC(videoram, 7115MODULE_PARM_DESC(videoram,
5938 "\nSet this to the amount of video RAM (in kilobyte) the card has. Required on\n" 7116 "\nSet this to the amount of video RAM (in kilobyte) the card has. Required on\n"
5939 "some non-x86 architectures where the memory auto detection fails. Only\n" 7117 "some non-x86 architectures where the memory auto detection fails. Only\n"
5940 "relevant if resetcard is set, too. Default: [auto-detect]\n"); 7118 "relevant if resetcard is set, too. SiS300/305 only. Default: [auto-detect]\n");
5941#endif
5942#endif 7119#endif
5943
5944static int __devinit sisfb_init_module(void)
5945{
5946 sisfb_setdefaultparms();
5947
5948 if(rate) sisfb_parm_rate = rate;
5949
5950 if((scalelcd == 0) || (scalelcd == 1)) {
5951 sisfb_scalelcd = scalelcd ^ 1;
5952 }
5953
5954 /* Need to check crt2 type first for fstn/dstn */
5955
5956 if(forcecrt2type)
5957 sisfb_search_crt2type(forcecrt2type);
5958
5959 if(tvstandard)
5960 sisfb_search_tvstd(tvstandard);
5961
5962 if(mode)
5963 sisfb_search_mode(mode, FALSE);
5964 else if(vesa != -1)
5965 sisfb_search_vesamode(vesa, FALSE);
5966
5967 sisfb_crt1off = (crt1off == 0) ? 1 : 0;
5968
5969 sisfb_forcecrt1 = forcecrt1;
5970 if(forcecrt1 == 1) sisfb_crt1off = 0;
5971 else if(forcecrt1 == 0) sisfb_crt1off = 1;
5972
5973 if(noaccel == 1) sisfb_accel = 0;
5974 else if(noaccel == 0) sisfb_accel = 1;
5975
5976 if(noypan == 1) sisfb_ypan = 0;
5977 else if(noypan == 0) sisfb_ypan = 1;
5978
5979 if(nomax == 1) sisfb_max = 0;
5980 else if(nomax == 0) sisfb_max = 1;
5981
5982#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
5983 if(inverse) sisfb_inverse = 1;
5984#endif 7120#endif
5985 7121
5986 if(mem) sisfb_parm_mem = mem;
5987
5988 if(userom != -1) sisfb_userom = userom;
5989 if(useoem != -1) sisfb_useoem = useoem;
5990
5991 if(pdc != -1) sisfb_pdc = (pdc & 0x7f);
5992 if(pdc1 != -1) sisfb_pdca = (pdc1 & 0x1f);
5993
5994 sisfb_nocrt2rate = nocrt2rate;
5995
5996 if(specialtiming)
5997 sisfb_search_specialtiming(specialtiming);
5998
5999 if((lvdshl >= 0) && (lvdshl <= 3)) sisfb_lvdshl = lvdshl;
6000
6001 if(filter != -1) sisfb_filter = filter;
6002
6003 sisfb_tvxposoffset = tvxposoffset;
6004 sisfb_tvyposoffset = tvyposoffset;
6005
6006#if !defined(__i386__) && !defined(__x86_64__)
6007 sisfb_resetcard = (resetcard) ? 1 : 0;
6008 if(videoram) sisfb_videoram = videoram;
6009#endif
6010
6011 return(sisfb_init());
6012}
6013
6014static void __exit sisfb_remove_module(void)
6015{
6016 pci_unregister_driver(&sisfb_driver);
6017 printk(KERN_DEBUG "sisfb: Module unloaded\n");
6018}
6019
6020module_init(sisfb_init_module);
6021module_exit(sisfb_remove_module);
6022
6023#endif /* /MODULE */ 7122#endif /* /MODULE */
6024 7123
7124/* _GPL only for new symbols. */
6025EXPORT_SYMBOL(sis_malloc); 7125EXPORT_SYMBOL(sis_malloc);
6026EXPORT_SYMBOL(sis_free); 7126EXPORT_SYMBOL(sis_free);
7127EXPORT_SYMBOL_GPL(sis_malloc_new);
7128EXPORT_SYMBOL_GPL(sis_free_new);
7129
6027 7130
6028 7131
diff --git a/drivers/video/sis/sis_main.h b/drivers/video/sis/sis_main.h
index a6678a7aff..445bcbba03 100644
--- a/drivers/video/sis/sis_main.h
+++ b/drivers/video/sis/sis_main.h
@@ -1,9 +1,10 @@
1/* 1/*
2 * SiS 300/305/540/630(S)/730(S) 2 * SiS 300/305/540/630(S)/730(S),
3 * SiS 315(H/PRO)/55x/(M)65x/(M)661(F/M)X/740/741(GX)/330/(M)760 3 * SiS 315[E|PRO]/550/[M]65x/[M]66x[F|M|G]X/[M]74x[GX]/330/[M]76x[GX],
4 * XGI V3XT/V5/V8, Z7
4 * frame buffer driver for Linux kernels >=2.4.14 and >=2.6.3 5 * frame buffer driver for Linux kernels >=2.4.14 and >=2.6.3
5 * 6 *
6 * Copyright (C) 2001-2004 Thomas Winischhofer, Vienna, Austria. 7 * Copyright (C) 2001-2005 Thomas Winischhofer, Vienna, Austria.
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
@@ -23,13 +24,9 @@
23#ifndef _SISFB_MAIN 24#ifndef _SISFB_MAIN
24#define _SISFB_MAIN 25#define _SISFB_MAIN
25 26
26#include <linux/spinlock.h>
27
28#include "vstruct.h" 27#include "vstruct.h"
29#include "sis.h" 28#include "sis.h"
30 29
31#define MODE_INDEX_NONE 0 /* index for mode=none */
32
33/* Fbcon stuff */ 30/* Fbcon stuff */
34static struct fb_var_screeninfo my_default_var = { 31static struct fb_var_screeninfo my_default_var = {
35 .xres = 0, 32 .xres = 0,
@@ -60,6 +57,8 @@ static struct fb_var_screeninfo my_default_var = {
60 .vmode = FB_VMODE_NONINTERLACED, 57 .vmode = FB_VMODE_NONINTERLACED,
61}; 58};
62 59
60#define MODE_INDEX_NONE 0 /* index for mode=none */
61
63/* Boot-time parameters */ 62/* Boot-time parameters */
64static int sisfb_off = 0; 63static int sisfb_off = 0;
65static int sisfb_parm_mem = 0; 64static int sisfb_parm_mem = 0;
@@ -93,7 +92,6 @@ static int sisfb_tvplug = -1; /* Tv plug type (for overriding autodetection) */
93static int sisfb_tvstd = -1; 92static int sisfb_tvstd = -1;
94static int sisfb_tvxposoffset = 0; 93static int sisfb_tvxposoffset = 0;
95static int sisfb_tvyposoffset = 0; 94static int sisfb_tvyposoffset = 0;
96static int sisfb_filter = -1;
97static int sisfb_nocrt2rate = 0; 95static int sisfb_nocrt2rate = 0;
98#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 96#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
99static int sisfb_inverse = 0; 97static int sisfb_inverse = 0;
@@ -106,12 +104,12 @@ static int sisfb_videoram = 0;
106 104
107/* List of supported chips */ 105/* List of supported chips */
108static struct sisfb_chip_info { 106static struct sisfb_chip_info {
109 int chip; 107 int chip;
110 int vgaengine; 108 int vgaengine;
111 int mni; 109 int mni;
112 int hwcursor_size; 110 int hwcursor_size;
113 int CRT2_write_enable; 111 int CRT2_write_enable;
114 const char *chip_name; 112 const char *chip_name;
115} sisfb_chip_info[] __devinitdata = { 113} sisfb_chip_info[] __devinitdata = {
116 { SIS_300, SIS_300_VGA, 0, HW_CURSOR_AREA_SIZE_300 * 2, SIS_CRT2_WENABLE_300, "SiS 300/305" }, 114 { SIS_300, SIS_300_VGA, 0, HW_CURSOR_AREA_SIZE_300 * 2, SIS_CRT2_WENABLE_300, "SiS 300/305" },
117 { SIS_540, SIS_300_VGA, 0, HW_CURSOR_AREA_SIZE_300 * 2, SIS_CRT2_WENABLE_300, "SiS 540" }, 115 { SIS_540, SIS_300_VGA, 0, HW_CURSOR_AREA_SIZE_300 * 2, SIS_CRT2_WENABLE_300, "SiS 540" },
@@ -123,6 +121,8 @@ static struct sisfb_chip_info {
123 { SIS_650, SIS_315_VGA, 1, HW_CURSOR_AREA_SIZE_315 * 4, SIS_CRT2_WENABLE_315, "SiS 650" }, 121 { SIS_650, SIS_315_VGA, 1, HW_CURSOR_AREA_SIZE_315 * 4, SIS_CRT2_WENABLE_315, "SiS 650" },
124 { SIS_330, SIS_315_VGA, 1, HW_CURSOR_AREA_SIZE_315 * 4, SIS_CRT2_WENABLE_315, "SiS 330" }, 122 { SIS_330, SIS_315_VGA, 1, HW_CURSOR_AREA_SIZE_315 * 4, SIS_CRT2_WENABLE_315, "SiS 330" },
125 { SIS_660, SIS_315_VGA, 1, HW_CURSOR_AREA_SIZE_315 * 4, SIS_CRT2_WENABLE_315, "SiS 660" }, 123 { SIS_660, SIS_315_VGA, 1, HW_CURSOR_AREA_SIZE_315 * 4, SIS_CRT2_WENABLE_315, "SiS 660" },
124 { XGI_20, SIS_315_VGA, 1, HW_CURSOR_AREA_SIZE_315 * 4, SIS_CRT2_WENABLE_315, "XGI Z7" },
125 { XGI_40, SIS_315_VGA, 1, HW_CURSOR_AREA_SIZE_315 * 4, SIS_CRT2_WENABLE_315, "XGI V3XT/V5/V8" },
126}; 126};
127 127
128static struct pci_device_id __devinitdata sisfb_pci_table[] = { 128static struct pci_device_id __devinitdata sisfb_pci_table[] = {
@@ -139,6 +139,8 @@ static struct pci_device_id __devinitdata sisfb_pci_table[] = {
139 { PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_650_VGA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7}, 139 { PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_650_VGA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7},
140 { PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_330, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8}, 140 { PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_330, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8},
141 { PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_660_VGA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9}, 141 { PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_660_VGA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9},
142 { PCI_VENDOR_ID_XGI,PCI_DEVICE_ID_XGI_20, PCI_ANY_ID, PCI_ANY_ID, 0, 0,10},
143 { PCI_VENDOR_ID_XGI,PCI_DEVICE_ID_XGI_40, PCI_ANY_ID, PCI_ANY_ID, 0, 0,11},
142#endif 144#endif
143 { 0 } 145 { 0 }
144}; 146};
@@ -147,13 +149,12 @@ MODULE_DEVICE_TABLE(pci, sisfb_pci_table);
147 149
148static struct sis_video_info *card_list = NULL; 150static struct sis_video_info *card_list = NULL;
149 151
150/* TODO: This is not handled card-wise because the DRM 152/* The memory heap is now handled card-wise, by using
151 does not refer to a unique fb when calling sis_alloc 153 sis_malloc_new/sis_free_new. However, the DRM does
152 or sis_free. Therefore, this is handled globally for 154 not do this yet. Until it does, we keep a "global"
153 now (hoping that nobody is crazy enough to run two 155 heap which is actually the first card's one.
154 SiS cards at the same time).
155 */ 156 */
156static SIS_HEAP sisfb_heap; 157static struct SIS_HEAP *sisfb_heap;
157 158
158#define MD_SIS300 1 159#define MD_SIS300 1
159#define MD_SIS315 2 160#define MD_SIS315 2
@@ -181,8 +182,10 @@ static const struct _sisbios_mode {
181 {"320x240x16", {0x56,0x56}, 0x0135, 0x0000, 320, 240, 16, 1, 40, 15, MD_SIS300|MD_SIS315}, 182 {"320x240x16", {0x56,0x56}, 0x0135, 0x0000, 320, 240, 16, 1, 40, 15, MD_SIS300|MD_SIS315},
182 {"320x240x24", {0x53,0x53}, 0x0000, 0x0000, 320, 240, 32, 1, 40, 15, MD_SIS300|MD_SIS315}, 183 {"320x240x24", {0x53,0x53}, 0x0000, 0x0000, 320, 240, 32, 1, 40, 15, MD_SIS300|MD_SIS315},
183 {"320x240x32", {0x53,0x53}, 0x0000, 0x0000, 320, 240, 32, 1, 40, 15, MD_SIS300|MD_SIS315}, 184 {"320x240x32", {0x53,0x53}, 0x0000, 0x0000, 320, 240, 32, 1, 40, 15, MD_SIS300|MD_SIS315},
184 {"320x240x8", {0x5a,0x5a}, 0x0132, 0x0000, 320, 480, 8, 1, 40, 30, MD_SIS315}, /* FSTN */ 185#define MODE_FSTN_8 9
185/*10*/ {"320x240x16", {0x5b,0x5b}, 0x0135, 0x0000, 320, 480, 16, 1, 40, 30, MD_SIS315}, /* FSTN */ 186#define MODE_FSTN_16 10
187 {"320x240x8", {0x5a,0x5a}, 0x0132, 0x0000, 320, 240, 8, 1, 40, 15, MD_SIS315}, /* FSTN */
188/*10*/ {"320x240x16", {0x5b,0x5b}, 0x0135, 0x0000, 320, 240, 16, 1, 40, 15, MD_SIS315}, /* FSTN */
186 {"400x300x8", {0x51,0x51}, 0x0133, 0x0000, 400, 300, 8, 1, 50, 18, MD_SIS300|MD_SIS315}, 189 {"400x300x8", {0x51,0x51}, 0x0133, 0x0000, 400, 300, 8, 1, 50, 18, MD_SIS300|MD_SIS315},
187 {"400x300x16", {0x57,0x57}, 0x0136, 0x0000, 400, 300, 16, 1, 50, 18, MD_SIS300|MD_SIS315}, 190 {"400x300x16", {0x57,0x57}, 0x0136, 0x0000, 400, 300, 16, 1, 50, 18, MD_SIS300|MD_SIS315},
188 {"400x300x24", {0x54,0x54}, 0x0000, 0x0000, 400, 300, 32, 1, 50, 18, MD_SIS300|MD_SIS315}, 191 {"400x300x24", {0x54,0x54}, 0x0000, 0x0000, 400, 300, 32, 1, 50, 18, MD_SIS300|MD_SIS315},
@@ -215,18 +218,20 @@ static const struct _sisbios_mode {
215/*40*/ {"800x480x16", {0x7a,0x7a}, 0x0000, 0x0000, 800, 480, 16, 1, 100, 30, MD_SIS300|MD_SIS315}, 218/*40*/ {"800x480x16", {0x7a,0x7a}, 0x0000, 0x0000, 800, 480, 16, 1, 100, 30, MD_SIS300|MD_SIS315},
216 {"800x480x24", {0x76,0x76}, 0x0000, 0x0000, 800, 480, 32, 1, 100, 30, MD_SIS300|MD_SIS315}, 219 {"800x480x24", {0x76,0x76}, 0x0000, 0x0000, 800, 480, 32, 1, 100, 30, MD_SIS300|MD_SIS315},
217 {"800x480x32", {0x76,0x76}, 0x0000, 0x0000, 800, 480, 32, 1, 100, 30, MD_SIS300|MD_SIS315}, 220 {"800x480x32", {0x76,0x76}, 0x0000, 0x0000, 800, 480, 32, 1, 100, 30, MD_SIS300|MD_SIS315},
218#define DEFAULT_MODE 43 /* index for 800x600x8 */ 221#define DEFAULT_MODE 43 /* index for 800x600x8 */
219#define DEFAULT_LCDMODE 43 /* index for 800x600x8 */ 222#define DEFAULT_LCDMODE 43 /* index for 800x600x8 */
220#define DEFAULT_TVMODE 43 /* index for 800x600x8 */ 223#define DEFAULT_TVMODE 43 /* index for 800x600x8 */
221 {"800x600x8", {0x30,0x30}, 0x0103, 0x0103, 800, 600, 8, 2, 100, 37, MD_SIS300|MD_SIS315}, 224 {"800x600x8", {0x30,0x30}, 0x0103, 0x0103, 800, 600, 8, 2, 100, 37, MD_SIS300|MD_SIS315},
222 {"800x600x16", {0x47,0x47}, 0x0114, 0x0114, 800, 600, 16, 2, 100, 37, MD_SIS300|MD_SIS315}, 225 {"800x600x16", {0x47,0x47}, 0x0114, 0x0114, 800, 600, 16, 2, 100, 37, MD_SIS300|MD_SIS315},
223 {"800x600x24", {0x63,0x63}, 0x013b, 0x0115, 800, 600, 32, 2, 100, 37, MD_SIS300|MD_SIS315}, 226 {"800x600x24", {0x63,0x63}, 0x013b, 0x0115, 800, 600, 32, 2, 100, 37, MD_SIS300|MD_SIS315},
224 {"800x600x32", {0x63,0x63}, 0x013b, 0x0115, 800, 600, 32, 2, 100, 37, MD_SIS300|MD_SIS315}, 227 {"800x600x32", {0x63,0x63}, 0x013b, 0x0115, 800, 600, 32, 2, 100, 37, MD_SIS300|MD_SIS315},
225 {"848x480x8", {0x39,0x39}, 0x0000, 0x0000, 848, 480, 8, 2, 106, 30, MD_SIS300|MD_SIS315}, 228 {"848x480x8", {0x39,0x39}, 0x0000, 0x0000, 848, 480, 8, 2, 106, 30, MD_SIS300|MD_SIS315},
229#define DEFAULT_MODE_848 48
226 {"848x480x16", {0x3b,0x3b}, 0x0000, 0x0000, 848, 480, 16, 2, 106, 30, MD_SIS300|MD_SIS315}, 230 {"848x480x16", {0x3b,0x3b}, 0x0000, 0x0000, 848, 480, 16, 2, 106, 30, MD_SIS300|MD_SIS315},
227 {"848x480x24", {0x3e,0x3e}, 0x0000, 0x0000, 848, 480, 32, 2, 106, 30, MD_SIS300|MD_SIS315}, 231 {"848x480x24", {0x3e,0x3e}, 0x0000, 0x0000, 848, 480, 32, 2, 106, 30, MD_SIS300|MD_SIS315},
228/*50*/ {"848x480x32", {0x3e,0x3e}, 0x0000, 0x0000, 848, 480, 32, 2, 106, 30, MD_SIS300|MD_SIS315}, 232/*50*/ {"848x480x32", {0x3e,0x3e}, 0x0000, 0x0000, 848, 480, 32, 2, 106, 30, MD_SIS300|MD_SIS315},
229 {"856x480x8", {0x3f,0x3f}, 0x0000, 0x0000, 856, 480, 8, 2, 107, 30, MD_SIS300|MD_SIS315}, 233 {"856x480x8", {0x3f,0x3f}, 0x0000, 0x0000, 856, 480, 8, 2, 107, 30, MD_SIS300|MD_SIS315},
234#define DEFAULT_MODE_856 52
230 {"856x480x16", {0x42,0x42}, 0x0000, 0x0000, 856, 480, 16, 2, 107, 30, MD_SIS300|MD_SIS315}, 235 {"856x480x16", {0x42,0x42}, 0x0000, 0x0000, 856, 480, 16, 2, 107, 30, MD_SIS300|MD_SIS315},
231 {"856x480x24", {0x45,0x45}, 0x0000, 0x0000, 856, 480, 32, 2, 107, 30, MD_SIS300|MD_SIS315}, 236 {"856x480x24", {0x45,0x45}, 0x0000, 0x0000, 856, 480, 32, 2, 107, 30, MD_SIS300|MD_SIS315},
232 {"856x480x32", {0x45,0x45}, 0x0000, 0x0000, 856, 480, 32, 2, 107, 30, MD_SIS300|MD_SIS315}, 237 {"856x480x32", {0x45,0x45}, 0x0000, 0x0000, 856, 480, 32, 2, 107, 30, MD_SIS300|MD_SIS315},
@@ -270,42 +275,47 @@ static const struct _sisbios_mode {
270 {"1280x800x16", {0x15,0x15}, 0x0000, 0x0000, 1280, 800, 16, 1, 160, 50, MD_SIS315}, 275 {"1280x800x16", {0x15,0x15}, 0x0000, 0x0000, 1280, 800, 16, 1, 160, 50, MD_SIS315},
271 {"1280x800x24", {0x16,0x16}, 0x0000, 0x0000, 1280, 800, 32, 1, 160, 50, MD_SIS315}, 276 {"1280x800x24", {0x16,0x16}, 0x0000, 0x0000, 1280, 800, 32, 1, 160, 50, MD_SIS315},
272 {"1280x800x32", {0x16,0x16}, 0x0000, 0x0000, 1280, 800, 32, 1, 160, 50, MD_SIS315}, 277 {"1280x800x32", {0x16,0x16}, 0x0000, 0x0000, 1280, 800, 32, 1, 160, 50, MD_SIS315},
278 {"1280x854x8", {0x14,0x14}, 0x0000, 0x0000, 1280, 854, 8, 1, 160, 53, MD_SIS315},
279 {"1280x854x16", {0x15,0x15}, 0x0000, 0x0000, 1280, 854, 16, 1, 160, 53, MD_SIS315},
280 {"1280x854x24", {0x16,0x16}, 0x0000, 0x0000, 1280, 854, 32, 1, 160, 53, MD_SIS315},
281 {"1280x854x32", {0x16,0x16}, 0x0000, 0x0000, 1280, 854, 32, 1, 160, 53, MD_SIS315},
273 {"1280x960x8", {0x7c,0x7c}, 0x0000, 0x0000, 1280, 960, 8, 1, 160, 60, MD_SIS300|MD_SIS315}, 282 {"1280x960x8", {0x7c,0x7c}, 0x0000, 0x0000, 1280, 960, 8, 1, 160, 60, MD_SIS300|MD_SIS315},
274 {"1280x960x16", {0x7d,0x7d}, 0x0000, 0x0000, 1280, 960, 16, 1, 160, 60, MD_SIS300|MD_SIS315}, 283/*100*/ {"1280x960x16", {0x7d,0x7d}, 0x0000, 0x0000, 1280, 960, 16, 1, 160, 60, MD_SIS300|MD_SIS315},
275 {"1280x960x24", {0x7e,0x7e}, 0x0000, 0x0000, 1280, 960, 32, 1, 160, 60, MD_SIS300|MD_SIS315}, 284 {"1280x960x24", {0x7e,0x7e}, 0x0000, 0x0000, 1280, 960, 32, 1, 160, 60, MD_SIS300|MD_SIS315},
276 {"1280x960x32", {0x7e,0x7e}, 0x0000, 0x0000, 1280, 960, 32, 1, 160, 60, MD_SIS300|MD_SIS315}, 285 {"1280x960x32", {0x7e,0x7e}, 0x0000, 0x0000, 1280, 960, 32, 1, 160, 60, MD_SIS300|MD_SIS315},
277 {"1280x1024x8", {0x3a,0x3a}, 0x0107, 0x0107, 1280, 1024, 8, 2, 160, 64, MD_SIS300|MD_SIS315}, 286 {"1280x1024x8", {0x3a,0x3a}, 0x0107, 0x0107, 1280, 1024, 8, 2, 160, 64, MD_SIS300|MD_SIS315},
278/*100*/ {"1280x1024x16", {0x4d,0x4d}, 0x011a, 0x011a, 1280, 1024, 16, 2, 160, 64, MD_SIS300|MD_SIS315}, 287 {"1280x1024x16", {0x4d,0x4d}, 0x011a, 0x011a, 1280, 1024, 16, 2, 160, 64, MD_SIS300|MD_SIS315},
279 {"1280x1024x24", {0x65,0x65}, 0x013d, 0x011b, 1280, 1024, 32, 2, 160, 64, MD_SIS300|MD_SIS315}, 288 {"1280x1024x24", {0x65,0x65}, 0x013d, 0x011b, 1280, 1024, 32, 2, 160, 64, MD_SIS300|MD_SIS315},
280 {"1280x1024x32", {0x65,0x65}, 0x013d, 0x011b, 1280, 1024, 32, 2, 160, 64, MD_SIS300|MD_SIS315}, 289 {"1280x1024x32", {0x65,0x65}, 0x013d, 0x011b, 1280, 1024, 32, 2, 160, 64, MD_SIS300|MD_SIS315},
281 {"1360x768x8", {0x48,0x48}, 0x0000, 0x0000, 1360, 768, 8, 1, 170, 48, MD_SIS300|MD_SIS315}, 290 {"1360x768x8", {0x48,0x48}, 0x0000, 0x0000, 1360, 768, 8, 1, 170, 48, MD_SIS300|MD_SIS315},
282 {"1360x768x16", {0x4b,0x4b}, 0x0000, 0x0000, 1360, 768, 16, 1, 170, 48, MD_SIS300|MD_SIS315}, 291 {"1360x768x16", {0x4b,0x4b}, 0x0000, 0x0000, 1360, 768, 16, 1, 170, 48, MD_SIS300|MD_SIS315},
283 {"1360x768x24", {0x4e,0x4e}, 0x0000, 0x0000, 1360, 768, 32, 1, 170, 48, MD_SIS300|MD_SIS315}, 292 {"1360x768x24", {0x4e,0x4e}, 0x0000, 0x0000, 1360, 768, 32, 1, 170, 48, MD_SIS300|MD_SIS315},
284 {"1360x768x32", {0x4e,0x4e}, 0x0000, 0x0000, 1360, 768, 32, 1, 170, 48, MD_SIS300|MD_SIS315}, 293/*110*/ {"1360x768x32", {0x4e,0x4e}, 0x0000, 0x0000, 1360, 768, 32, 1, 170, 48, MD_SIS300|MD_SIS315},
285 {"1360x1024x8", {0x67,0x67}, 0x0000, 0x0000, 1360, 1024, 8, 1, 170, 64, MD_SIS300 }, 294 {"1360x1024x8", {0x67,0x67}, 0x0000, 0x0000, 1360, 1024, 8, 1, 170, 64, MD_SIS300 },
295#define DEFAULT_MODE_1360 112
286 {"1360x1024x16", {0x6f,0x6f}, 0x0000, 0x0000, 1360, 1024, 16, 1, 170, 64, MD_SIS300 }, 296 {"1360x1024x16", {0x6f,0x6f}, 0x0000, 0x0000, 1360, 1024, 16, 1, 170, 64, MD_SIS300 },
287 {"1360x1024x24", {0x72,0x72}, 0x0000, 0x0000, 1360, 1024, 32, 1, 170, 64, MD_SIS300 }, 297 {"1360x1024x24", {0x72,0x72}, 0x0000, 0x0000, 1360, 1024, 32, 1, 170, 64, MD_SIS300 },
288/*110*/ {"1360x1024x32", {0x72,0x72}, 0x0000, 0x0000, 1360, 1024, 32, 1, 170, 64, MD_SIS300 }, 298 {"1360x1024x32", {0x72,0x72}, 0x0000, 0x0000, 1360, 1024, 32, 1, 170, 64, MD_SIS300 },
289 {"1400x1050x8", {0x26,0x26}, 0x0000, 0x0000, 1400, 1050, 8, 1, 175, 65, MD_SIS315}, 299 {"1400x1050x8", {0x26,0x26}, 0x0000, 0x0000, 1400, 1050, 8, 1, 175, 65, MD_SIS315},
290 {"1400x1050x16", {0x27,0x27}, 0x0000, 0x0000, 1400, 1050, 16, 1, 175, 65, MD_SIS315}, 300 {"1400x1050x16", {0x27,0x27}, 0x0000, 0x0000, 1400, 1050, 16, 1, 175, 65, MD_SIS315},
291 {"1400x1050x24", {0x28,0x28}, 0x0000, 0x0000, 1400, 1050, 32, 1, 175, 65, MD_SIS315}, 301 {"1400x1050x24", {0x28,0x28}, 0x0000, 0x0000, 1400, 1050, 32, 1, 175, 65, MD_SIS315},
292 {"1400x1050x32", {0x28,0x28}, 0x0000, 0x0000, 1400, 1050, 32, 1, 175, 65, MD_SIS315}, 302 {"1400x1050x32", {0x28,0x28}, 0x0000, 0x0000, 1400, 1050, 32, 1, 175, 65, MD_SIS315},
293 {"1600x1200x8", {0x3c,0x3c}, 0x0130, 0x011c, 1600, 1200, 8, 1, 200, 75, MD_SIS300|MD_SIS315}, 303 {"1600x1200x8", {0x3c,0x3c}, 0x0130, 0x011c, 1600, 1200, 8, 1, 200, 75, MD_SIS300|MD_SIS315},
294 {"1600x1200x16", {0x3d,0x3d}, 0x0131, 0x011e, 1600, 1200, 16, 1, 200, 75, MD_SIS300|MD_SIS315}, 304/*120*/ {"1600x1200x16", {0x3d,0x3d}, 0x0131, 0x011e, 1600, 1200, 16, 1, 200, 75, MD_SIS300|MD_SIS315},
295 {"1600x1200x24", {0x66,0x66}, 0x013e, 0x011f, 1600, 1200, 32, 1, 200, 75, MD_SIS300|MD_SIS315}, 305 {"1600x1200x24", {0x66,0x66}, 0x013e, 0x011f, 1600, 1200, 32, 1, 200, 75, MD_SIS300|MD_SIS315},
296 {"1600x1200x32", {0x66,0x66}, 0x013e, 0x011f, 1600, 1200, 32, 1, 200, 75, MD_SIS300|MD_SIS315}, 306 {"1600x1200x32", {0x66,0x66}, 0x013e, 0x011f, 1600, 1200, 32, 1, 200, 75, MD_SIS300|MD_SIS315},
297 {"1680x1050x8", {0x17,0x17}, 0x0000, 0x0000, 1680, 1050, 8, 1, 210, 65, MD_SIS315}, 307 {"1680x1050x8", {0x17,0x17}, 0x0000, 0x0000, 1680, 1050, 8, 1, 210, 65, MD_SIS315},
298/*120*/ {"1680x1050x16", {0x18,0x18}, 0x0000, 0x0000, 1680, 1050, 16, 1, 210, 65, MD_SIS315}, 308 {"1680x1050x16", {0x18,0x18}, 0x0000, 0x0000, 1680, 1050, 16, 1, 210, 65, MD_SIS315},
299 {"1680x1050x24", {0x19,0x19}, 0x0000, 0x0000, 1680, 1050, 32, 1, 210, 65, MD_SIS315}, 309 {"1680x1050x24", {0x19,0x19}, 0x0000, 0x0000, 1680, 1050, 32, 1, 210, 65, MD_SIS315},
300 {"1680x1050x32", {0x19,0x19}, 0x0000, 0x0000, 1680, 1050, 32, 1, 210, 65, MD_SIS315}, 310 {"1680x1050x32", {0x19,0x19}, 0x0000, 0x0000, 1680, 1050, 32, 1, 210, 65, MD_SIS315},
301 {"1920x1080x8", {0x2c,0x2c}, 0x0000, 0x0000, 1920, 1080, 8, 1, 240, 67, MD_SIS315}, 311 {"1920x1080x8", {0x2c,0x2c}, 0x0000, 0x0000, 1920, 1080, 8, 1, 240, 67, MD_SIS315},
302 {"1920x1080x16", {0x2d,0x2d}, 0x0000, 0x0000, 1920, 1080, 16, 1, 240, 67, MD_SIS315}, 312 {"1920x1080x16", {0x2d,0x2d}, 0x0000, 0x0000, 1920, 1080, 16, 1, 240, 67, MD_SIS315},
303 {"1920x1080x24", {0x73,0x73}, 0x0000, 0x0000, 1920, 1080, 32, 1, 240, 67, MD_SIS315}, 313 {"1920x1080x24", {0x73,0x73}, 0x0000, 0x0000, 1920, 1080, 32, 1, 240, 67, MD_SIS315},
304 {"1920x1080x32", {0x73,0x73}, 0x0000, 0x0000, 1920, 1080, 32, 1, 240, 67, MD_SIS315}, 314/*130*/ {"1920x1080x32", {0x73,0x73}, 0x0000, 0x0000, 1920, 1080, 32, 1, 240, 67, MD_SIS315},
305 {"1920x1440x8", {0x68,0x68}, 0x013f, 0x0000, 1920, 1440, 8, 1, 240, 75, MD_SIS300|MD_SIS315}, 315 {"1920x1440x8", {0x68,0x68}, 0x013f, 0x0000, 1920, 1440, 8, 1, 240, 75, MD_SIS300|MD_SIS315},
306 {"1920x1440x16", {0x69,0x69}, 0x0140, 0x0000, 1920, 1440, 16, 1, 240, 75, MD_SIS300|MD_SIS315}, 316 {"1920x1440x16", {0x69,0x69}, 0x0140, 0x0000, 1920, 1440, 16, 1, 240, 75, MD_SIS300|MD_SIS315},
307 {"1920x1440x24", {0x6b,0x6b}, 0x0141, 0x0000, 1920, 1440, 32, 1, 240, 75, MD_SIS300|MD_SIS315}, 317 {"1920x1440x24", {0x6b,0x6b}, 0x0141, 0x0000, 1920, 1440, 32, 1, 240, 75, MD_SIS300|MD_SIS315},
308/*130*/ {"1920x1440x32", {0x6b,0x6b}, 0x0141, 0x0000, 1920, 1440, 32, 1, 240, 75, MD_SIS300|MD_SIS315}, 318 {"1920x1440x32", {0x6b,0x6b}, 0x0141, 0x0000, 1920, 1440, 32, 1, 240, 75, MD_SIS300|MD_SIS315},
309 {"2048x1536x8", {0x6c,0x6c}, 0x0000, 0x0000, 2048, 1536, 8, 1, 256, 96, MD_SIS315}, 319 {"2048x1536x8", {0x6c,0x6c}, 0x0000, 0x0000, 2048, 1536, 8, 1, 256, 96, MD_SIS315},
310 {"2048x1536x16", {0x6d,0x6d}, 0x0000, 0x0000, 2048, 1536, 16, 1, 256, 96, MD_SIS315}, 320 {"2048x1536x16", {0x6d,0x6d}, 0x0000, 0x0000, 2048, 1536, 16, 1, 256, 96, MD_SIS315},
311 {"2048x1536x24", {0x6e,0x6e}, 0x0000, 0x0000, 2048, 1536, 32, 1, 256, 96, MD_SIS315}, 321 {"2048x1536x24", {0x6e,0x6e}, 0x0000, 0x0000, 2048, 1536, 32, 1, 256, 96, MD_SIS315},
@@ -313,13 +323,13 @@ static const struct _sisbios_mode {
313 {"\0", {0x00,0x00}, 0, 0, 0, 0, 0, 0, 0} 323 {"\0", {0x00,0x00}, 0, 0, 0, 0, 0, 0, 0}
314}; 324};
315 325
316#define SIS_LCD_NUMBER 17 326#define SIS_LCD_NUMBER 18
317static const struct _sis_lcd_data { 327static struct _sis_lcd_data {
318 u32 lcdtype; 328 u32 lcdtype;
319 u16 xres; 329 u16 xres;
320 u16 yres; 330 u16 yres;
321 u8 default_mode_idx; 331 u8 default_mode_idx;
322} sis_lcd_data[] = { 332} sis_lcd_data[] __devinitdata = {
323 { LCD_640x480, 640, 480, 23 }, 333 { LCD_640x480, 640, 480, 23 },
324 { LCD_800x600, 800, 600, 43 }, 334 { LCD_800x600, 800, 600, 43 },
325 { LCD_1024x600, 1024, 600, 67 }, 335 { LCD_1024x600, 1024, 600, 67 },
@@ -329,34 +339,38 @@ static const struct _sis_lcd_data {
329 { LCD_1280x720, 1280, 720, 83 }, 339 { LCD_1280x720, 1280, 720, 83 },
330 { LCD_1280x768, 1280, 768, 87 }, 340 { LCD_1280x768, 1280, 768, 87 },
331 { LCD_1280x800, 1280, 800, 91 }, 341 { LCD_1280x800, 1280, 800, 91 },
332 { LCD_1280x960, 1280, 960, 95 }, 342 { LCD_1280x854, 1280, 854, 95 },
333 { LCD_1280x1024, 1280, 1024, 99 }, 343 { LCD_1280x960, 1280, 960, 99 },
334 { LCD_1400x1050, 1400, 1050, 111 }, 344 { LCD_1280x1024, 1280, 1024, 103 },
335 { LCD_1680x1050, 1680, 1050, 119 }, 345 { LCD_1400x1050, 1400, 1050, 115 },
336 { LCD_1600x1200, 1600, 1200, 115 }, 346 { LCD_1680x1050, 1680, 1050, 123 },
337 { LCD_640x480_2, 640, 480, 23 }, 347 { LCD_1600x1200, 1600, 1200, 119 },
338 { LCD_640x480_3, 640, 480, 23 }, 348 { LCD_320x240_2, 320, 240, 9 },
339 { LCD_320x480, 320, 480, 9 }, 349 { LCD_320x240_3, 320, 240, 9 },
350 { LCD_320x240, 320, 240, 9 },
340}; 351};
341 352
342/* CR36 evaluation */ 353/* CR36 evaluation */
343static const USHORT sis300paneltype[] = 354static unsigned short sis300paneltype[] __devinitdata = {
344 { LCD_UNKNOWN, LCD_800x600, LCD_1024x768, LCD_1280x1024, 355 LCD_UNKNOWN, LCD_800x600, LCD_1024x768, LCD_1280x1024,
345 LCD_1280x960, LCD_640x480, LCD_1024x600, LCD_1152x768, 356 LCD_1280x960, LCD_640x480, LCD_1024x600, LCD_1152x768,
346 LCD_UNKNOWN, LCD_UNKNOWN, LCD_UNKNOWN, LCD_UNKNOWN, 357 LCD_UNKNOWN, LCD_UNKNOWN, LCD_UNKNOWN, LCD_UNKNOWN,
347 LCD_UNKNOWN, LCD_UNKNOWN, LCD_UNKNOWN, LCD_UNKNOWN }; 358 LCD_UNKNOWN, LCD_UNKNOWN, LCD_UNKNOWN, LCD_UNKNOWN
348 359};
349static const USHORT sis310paneltype[] = 360
350 { LCD_UNKNOWN, LCD_800x600, LCD_1024x768, LCD_1280x1024, 361static unsigned short sis310paneltype[] __devinitdata = {
351 LCD_640x480, LCD_1024x600, LCD_1152x864, LCD_1280x960, 362 LCD_UNKNOWN, LCD_800x600, LCD_1024x768, LCD_1280x1024,
352 LCD_1152x768, LCD_1400x1050, LCD_1280x768, LCD_1600x1200, 363 LCD_640x480, LCD_1024x600, LCD_1152x864, LCD_1280x960,
353 LCD_640x480_2, LCD_640x480_3, LCD_UNKNOWN, LCD_UNKNOWN }; 364 LCD_1152x768, LCD_1400x1050, LCD_1280x768, LCD_1600x1200,
354 365 LCD_320x240_2, LCD_320x240_3, LCD_UNKNOWN, LCD_UNKNOWN
355static const USHORT sis661paneltype[] = 366};
356 { LCD_UNKNOWN, LCD_800x600, LCD_1024x768, LCD_1280x1024, 367
357 LCD_640x480, LCD_1024x600, LCD_1152x864, LCD_1280x960, 368static unsigned short sis661paneltype[] __devinitdata = {
358 LCD_1152x768, LCD_1400x1050, LCD_1280x768, LCD_1600x1200, 369 LCD_UNKNOWN, LCD_800x600, LCD_1024x768, LCD_1280x1024,
359 LCD_1280x800, LCD_1680x1050, LCD_1280x720, LCD_UNKNOWN }; 370 LCD_640x480, LCD_1024x600, LCD_1152x864, LCD_1280x960,
371 LCD_1280x854, LCD_1400x1050, LCD_1280x768, LCD_1600x1200,
372 LCD_1280x800, LCD_1680x1050, LCD_1280x720, LCD_UNKNOWN
373};
360 374
361#define FL_550_DSTN 0x01 375#define FL_550_DSTN 0x01
362#define FL_550_FSTN 0x02 376#define FL_550_FSTN 0x02
@@ -413,7 +427,6 @@ static const struct _sis_vrate {
413} sisfb_vrate[] = { 427} sisfb_vrate[] = {
414 {1, 320, 200, 70, TRUE}, 428 {1, 320, 200, 70, TRUE},
415 {1, 320, 240, 60, TRUE}, 429 {1, 320, 240, 60, TRUE},
416 {1, 320, 480, 60, TRUE},
417 {1, 400, 300, 60, TRUE}, 430 {1, 400, 300, 60, TRUE},
418 {1, 512, 384, 60, TRUE}, 431 {1, 512, 384, 60, TRUE},
419 {1, 640, 400, 72, TRUE}, 432 {1, 640, 400, 72, TRUE},
@@ -437,10 +450,11 @@ static const struct _sis_vrate {
437 {4, 1024, 768, 75, FALSE}, {5, 1024, 768, 85, TRUE}, {6, 1024, 768, 100, TRUE}, 450 {4, 1024, 768, 75, FALSE}, {5, 1024, 768, 85, TRUE}, {6, 1024, 768, 100, TRUE},
438 {7, 1024, 768, 120, TRUE}, 451 {7, 1024, 768, 120, TRUE},
439 {1, 1152, 768, 60, TRUE}, 452 {1, 1152, 768, 60, TRUE},
440 {1, 1152, 864, 60, TRUE}, {1, 1152, 864, 75, TRUE}, {2, 1152, 864, 84, TRUE}, 453 {1, 1152, 864, 60, TRUE}, {2, 1152, 864, 75, TRUE}, {3, 1152, 864, 84, TRUE},
441 {1, 1280, 720, 60, TRUE}, {2, 1280, 720, 75, TRUE}, {3, 1280, 720, 85, TRUE}, 454 {1, 1280, 720, 60, TRUE}, {2, 1280, 720, 75, TRUE}, {3, 1280, 720, 85, TRUE},
442 {1, 1280, 768, 60, TRUE}, 455 {1, 1280, 768, 60, TRUE},
443 {1, 1280, 800, 60, TRUE}, 456 {1, 1280, 800, 60, TRUE},
457 {1, 1280, 854, 60, TRUE},
444 {1, 1280, 960, 60, TRUE}, {2, 1280, 960, 85, TRUE}, 458 {1, 1280, 960, 60, TRUE}, {2, 1280, 960, 85, TRUE},
445 {1, 1280, 1024, 43, TRUE}, {2, 1280, 1024, 60, TRUE}, {3, 1280, 1024, 75, TRUE}, 459 {1, 1280, 1024, 43, TRUE}, {2, 1280, 1024, 60, TRUE}, {3, 1280, 1024, 75, TRUE},
446 {4, 1280, 1024, 85, TRUE}, 460 {4, 1280, 1024, 85, TRUE},
@@ -459,12 +473,12 @@ static const struct _sis_vrate {
459 {0, 0, 0, 0, FALSE} 473 {0, 0, 0, 0, FALSE}
460}; 474};
461 475
462static const struct _sisfbddcsmodes { 476static struct _sisfbddcsmodes {
463 u32 mask; 477 u32 mask;
464 u16 h; 478 u16 h;
465 u16 v; 479 u16 v;
466 u32 d; 480 u32 d;
467} sisfb_ddcsmodes[] = { 481} sisfb_ddcsmodes[] __devinitdata = {
468 { 0x10000, 67, 75, 108000}, 482 { 0x10000, 67, 75, 108000},
469 { 0x08000, 48, 72, 50000}, 483 { 0x08000, 48, 72, 50000},
470 { 0x04000, 46, 75, 49500}, 484 { 0x04000, 46, 75, 49500},
@@ -480,49 +494,49 @@ static const struct _sisfbddcsmodes {
480 { 0x00001, 38, 60, 40000} 494 { 0x00001, 38, 60, 40000}
481}; 495};
482 496
483static const struct _sisfbddcfmodes { 497static struct _sisfbddcfmodes {
484 u16 x; 498 u16 x;
485 u16 y; 499 u16 y;
486 u16 v; 500 u16 v;
487 u16 h; 501 u16 h;
488 u32 d; 502 u32 d;
489} sisfb_ddcfmodes[] = { 503} sisfb_ddcfmodes[] __devinitdata = {
490 { 1280, 1024, 85, 92, 157500}, 504 { 1280, 1024, 85, 92, 157500},
491 { 1600, 1200, 60, 75, 162000}, 505 { 1600, 1200, 60, 75, 162000},
492 { 1600, 1200, 65, 82, 175500}, 506 { 1600, 1200, 65, 82, 175500},
493 { 1600, 1200, 70, 88, 189000}, 507 { 1600, 1200, 70, 88, 189000},
494 { 1600, 1200, 75, 94, 202500}, 508 { 1600, 1200, 75, 94, 202500},
495 { 1600, 1200, 85, 107,229500}, 509 { 1600, 1200, 85, 107,229500},
496 { 1920, 1440, 60, 90, 234000}, 510 { 1920, 1440, 60, 90, 234000},
497 { 1920, 1440, 75, 113,297000} 511 { 1920, 1440, 75, 113,297000}
498}; 512};
499 513
500#ifdef CONFIG_FB_SIS_300 514#ifdef CONFIG_FB_SIS_300
501static struct _chswtable { 515static struct _chswtable {
502 u16 subsysVendor; 516 u16 subsysVendor;
503 u16 subsysCard; 517 u16 subsysCard;
504 char *vendorName; 518 char *vendorName;
505 char *cardName; 519 char *cardName;
506} mychswtable[] __devinitdata = { 520} mychswtable[] __devinitdata = {
507 { 0x1631, 0x1002, "Mitachi", "0x1002" }, 521 { 0x1631, 0x1002, "Mitachi", "0x1002" },
508 { 0x1071, 0x7521, "Mitac" , "7521P" }, 522 { 0x1071, 0x7521, "Mitac" , "7521P" },
509 { 0, 0, "" , "" } 523 { 0, 0, "" , "" }
510}; 524};
511#endif 525#endif
512 526
513static struct _customttable { 527static struct _customttable {
514 u16 chipID; 528 u16 chipID;
515 char *biosversion; 529 char *biosversion;
516 char *biosdate; 530 char *biosdate;
517 u32 bioschksum; 531 u32 bioschksum;
518 u16 biosFootprintAddr[5]; 532 u16 biosFootprintAddr[5];
519 u8 biosFootprintData[5]; 533 u8 biosFootprintData[5];
520 u16 pcisubsysvendor; 534 u16 pcisubsysvendor;
521 u16 pcisubsyscard; 535 u16 pcisubsyscard;
522 char *vendorName; 536 char *vendorName;
523 char *cardName; 537 char *cardName;
524 u32 SpecialID; 538 u32 SpecialID;
525 char *optionName; 539 char *optionName;
526} mycustomttable[] __devinitdata = { 540} mycustomttable[] __devinitdata = {
527 { SIS_630, "2.00.07", "09/27/2002-13:38:25", 541 { SIS_630, "2.00.07", "09/27/2002-13:38:25",
528 0x3240A8, 542 0x3240A8,
@@ -643,6 +657,13 @@ static struct _customttable {
643 0, 0, 657 0, 0,
644 "Generic", "LVDS/Parallel 848x480", CUT_PANEL848, "PANEL848x480" 658 "Generic", "LVDS/Parallel 848x480", CUT_PANEL848, "PANEL848x480"
645 }, 659 },
660 { 4322, "", "", /* never autodetected */
661 0,
662 { 0, 0, 0, 0, 0 },
663 { 0, 0, 0, 0, 0 },
664 0, 0,
665 "Generic", "LVDS/Parallel 856x480", CUT_PANEL856, "PANEL856x480"
666 },
646 { 0, "", "", 667 { 0, "", "",
647 0, 668 0,
648 { 0, 0, 0, 0 }, 669 { 0, 0, 0, 0 },
@@ -652,155 +673,6 @@ static struct _customttable {
652 } 673 }
653}; 674};
654 675
655static const struct _sis_TV_filter {
656 u8 filter[9][4];
657} sis_TV_filter[] = {
658 { {{0x00,0x00,0x00,0x40}, /* NTSCFilter_0 */
659 {0x00,0xE0,0x10,0x60},
660 {0x00,0xEE,0x10,0x44},
661 {0x00,0xF4,0x10,0x38},
662 {0xF8,0xF4,0x18,0x38},
663 {0xFC,0xFB,0x14,0x2A},
664 {0x00,0x00,0x10,0x20},
665 {0x00,0x04,0x10,0x18},
666 {0xFF,0xFF,0xFF,0xFF} }},
667 { {{0x00,0x00,0x00,0x40}, /* NTSCFilter_1 */
668 {0x00,0xE0,0x10,0x60},
669 {0x00,0xEE,0x10,0x44},
670 {0x00,0xF4,0x10,0x38},
671 {0xF8,0xF4,0x18,0x38},
672 {0xFC,0xFB,0x14,0x2A},
673 {0x00,0x00,0x10,0x20},
674 {0x00,0x04,0x10,0x18},
675 {0xFF,0xFF,0xFF,0xFF} }},
676 { {{0x00,0x00,0x00,0x40}, /* NTSCFilter_2 */
677 {0xF5,0xEE,0x1B,0x44},
678 {0xF8,0xF4,0x18,0x38},
679 {0xEB,0x04,0x25,0x18},
680 {0xF1,0x05,0x1F,0x16},
681 {0xF6,0x06,0x1A,0x14},
682 {0xFA,0x06,0x16,0x14},
683 {0x00,0x04,0x10,0x18},
684 {0xFF,0xFF,0xFF,0xFF} }},
685 { {{0x00,0x00,0x00,0x40}, /* NTSCFilter_3 */
686 {0xF1,0x04,0x1F,0x18},
687 {0xEE,0x0D,0x22,0x06},
688 {0xF7,0x06,0x19,0x14},
689 {0xF4,0x0B,0x1C,0x0A},
690 {0xFA,0x07,0x16,0x12},
691 {0xF9,0x0A,0x17,0x0C},
692 {0x00,0x07,0x10,0x12},
693 {0xFF,0xFF,0xFF,0xFF} }},
694 { {{0x00,0x00,0x00,0x40}, /* NTSCFilter_4 - 320 */
695 {0x00,0xE0,0x10,0x60},
696 {0x00,0xEE,0x10,0x44},
697 {0x00,0xF4,0x10,0x38},
698 {0xF8,0xF4,0x18,0x38},
699 {0xFC,0xFB,0x14,0x2A},
700 {0x00,0x00,0x10,0x20},
701 {0x00,0x04,0x10,0x18},
702 {0xFF,0xFF,0xFF,0xFF} }},
703 { {{0x00,0x00,0x00,0x40}, /* NTSCFilter_5 - 640 */
704 {0xF5,0xEE,0x1B,0x44},
705 {0xF8,0xF4,0x18,0x38},
706 {0xEB,0x04,0x25,0x18},
707 {0xF1,0x05,0x1F,0x16},
708 {0xF6,0x06,0x1A,0x14},
709 {0xFA,0x06,0x16,0x14},
710 {0x00,0x04,0x10,0x18},
711 {0xFF,0xFF,0xFF,0xFF} }},
712 { {{0x00,0x00,0x00,0x40}, /* NTSCFilter_6 - 720 */
713 {0xEB,0x04,0x25,0x18},
714 {0xE7,0x0E,0x29,0x04},
715 {0xEE,0x0C,0x22,0x08},
716 {0xF6,0x0B,0x1A,0x0A},
717 {0xF9,0x0A,0x17,0x0C},
718 {0xFC,0x0A,0x14,0x0C},
719 {0x00,0x08,0x10,0x10},
720 {0xFF,0xFF,0xFF,0xFF} }},
721 { {{0x00,0x00,0x00,0x40}, /* NTSCFilter_7 - 800 */
722 {0xEC,0x02,0x24,0x1C},
723 {0xF2,0x04,0x1E,0x18},
724 {0xEB,0x15,0x25,0xF6},
725 {0xF4,0x10,0x1C,0x00},
726 {0xF8,0x0F,0x18,0x02},
727 {0x00,0x04,0x10,0x18},
728 {0x01,0x06,0x0F,0x14},
729 {0xFF,0xFF,0xFF,0xFF} }},
730 { {{0x00,0x00,0x00,0x40}, /* PALFilter_0 */
731 {0x00,0xE0,0x10,0x60},
732 {0x00,0xEE,0x10,0x44},
733 {0x00,0xF4,0x10,0x38},
734 {0xF8,0xF4,0x18,0x38},
735 {0xFC,0xFB,0x14,0x2A},
736 {0x00,0x00,0x10,0x20},
737 {0x00,0x04,0x10,0x18},
738 {0xFF,0xFF,0xFF,0xFF} }},
739 { {{0x00,0x00,0x00,0x40}, /* PALFilter_1 */
740 {0x00,0xE0,0x10,0x60},
741 {0x00,0xEE,0x10,0x44},
742 {0x00,0xF4,0x10,0x38},
743 {0xF8,0xF4,0x18,0x38},
744 {0xFC,0xFB,0x14,0x2A},
745 {0x00,0x00,0x10,0x20},
746 {0x00,0x04,0x10,0x18},
747 {0xFF,0xFF,0xFF,0xFF} }},
748 { {{0x00,0x00,0x00,0x40}, /* PALFilter_2 */
749 {0xF5,0xEE,0x1B,0x44},
750 {0xF8,0xF4,0x18,0x38},
751 {0xF1,0xF7,0x01,0x32},
752 {0xF5,0xFB,0x1B,0x2A},
753 {0xF9,0xFF,0x17,0x22},
754 {0xFB,0x01,0x15,0x1E},
755 {0x00,0x04,0x10,0x18},
756 {0xFF,0xFF,0xFF,0xFF} }},
757 { {{0x00,0x00,0x00,0x40}, /* PALFilter_3 */
758 {0xF5,0xFB,0x1B,0x2A},
759 {0xEE,0xFE,0x22,0x24},
760 {0xF3,0x00,0x1D,0x20},
761 {0xF9,0x03,0x17,0x1A},
762 {0xFB,0x02,0x14,0x1E},
763 {0xFB,0x04,0x15,0x18},
764 {0x00,0x06,0x10,0x14},
765 {0xFF,0xFF,0xFF,0xFF} }},
766 { {{0x00,0x00,0x00,0x40}, /* PALFilter_4 - 320 */
767 {0x00,0xE0,0x10,0x60},
768 {0x00,0xEE,0x10,0x44},
769 {0x00,0xF4,0x10,0x38},
770 {0xF8,0xF4,0x18,0x38},
771 {0xFC,0xFB,0x14,0x2A},
772 {0x00,0x00,0x10,0x20},
773 {0x00,0x04,0x10,0x18},
774 {0xFF,0xFF,0xFF,0xFF} }},
775 { {{0x00,0x00,0x00,0x40}, /* PALFilter_5 - 640 */
776 {0xF5,0xEE,0x1B,0x44},
777 {0xF8,0xF4,0x18,0x38},
778 {0xF1,0xF7,0x1F,0x32},
779 {0xF5,0xFB,0x1B,0x2A},
780 {0xF9,0xFF,0x17,0x22},
781 {0xFB,0x01,0x15,0x1E},
782 {0x00,0x04,0x10,0x18},
783 {0xFF,0xFF,0xFF,0xFF} }},
784 { {{0x00,0x00,0x00,0x40}, /* PALFilter_6 - 720 */
785 {0xF5,0xEE,0x1B,0x2A},
786 {0xEE,0xFE,0x22,0x24},
787 {0xF3,0x00,0x1D,0x20},
788 {0xF9,0x03,0x17,0x1A},
789 {0xFB,0x02,0x14,0x1E},
790 {0xFB,0x04,0x15,0x18},
791 {0x00,0x06,0x10,0x14},
792 {0xFF,0xFF,0xFF,0xFF} }},
793 { {{0x00,0x00,0x00,0x40}, /* PALFilter_7 - 800 */
794 {0xF5,0xEE,0x1B,0x44},
795 {0xF8,0xF4,0x18,0x38},
796 {0xFC,0xFB,0x14,0x2A},
797 {0xEB,0x05,0x25,0x16},
798 {0xF1,0x05,0x1F,0x16},
799 {0xFA,0x07,0x16,0x12},
800 {0x00,0x07,0x10,0x12},
801 {0xFF,0xFF,0xFF,0xFF} }}
802};
803
804/* ---------------------- Prototypes ------------------------- */ 676/* ---------------------- Prototypes ------------------------- */
805 677
806/* Interface used by the world */ 678/* Interface used by the world */
@@ -811,145 +683,159 @@ SISINITSTATIC int sisfb_setup(char *options);
811/* Interface to the low level console driver */ 683/* Interface to the low level console driver */
812SISINITSTATIC int sisfb_init(void); 684SISINITSTATIC int sisfb_init(void);
813 685
814
815/* fbdev routines */ 686/* fbdev routines */
816static int sisfb_get_fix(struct fb_fix_screeninfo *fix, int con, 687static int sisfb_get_fix(struct fb_fix_screeninfo *fix, int con,
817 struct fb_info *info); 688 struct fb_info *info);
818 689
819#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 690#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
820static int sisfb_get_fix(struct fb_fix_screeninfo *fix, 691static int sisfb_get_fix(struct fb_fix_screeninfo *fix,
821 int con, 692 int con,
822 struct fb_info *info); 693 struct fb_info *info);
823static int sisfb_get_var(struct fb_var_screeninfo *var, 694static int sisfb_get_var(struct fb_var_screeninfo *var,
824 int con, 695 int con,
825 struct fb_info *info); 696 struct fb_info *info);
826static int sisfb_set_var(struct fb_var_screeninfo *var, 697static int sisfb_set_var(struct fb_var_screeninfo *var,
827 int con, 698 int con,
828 struct fb_info *info); 699 struct fb_info *info);
829static void sisfb_crtc_to_var(struct sis_video_info *ivideo, 700static void sisfb_crtc_to_var(struct sis_video_info *ivideo,
830 struct fb_var_screeninfo *var); 701 struct fb_var_screeninfo *var);
831static int sisfb_get_cmap(struct fb_cmap *cmap, 702static int sisfb_get_cmap(struct fb_cmap *cmap,
832 int kspc, 703 int kspc,
833 int con, 704 int con,
834 struct fb_info *info); 705 struct fb_info *info);
835static int sisfb_set_cmap(struct fb_cmap *cmap, 706static int sisfb_set_cmap(struct fb_cmap *cmap,
836 int kspc, 707 int kspc,
837 int con, 708 int con,
838 struct fb_info *info); 709 struct fb_info *info);
839static int sisfb_update_var(int con, 710static int sisfb_update_var(int con,
840 struct fb_info *info); 711 struct fb_info *info);
841static int sisfb_switch(int con, 712static int sisfb_switch(int con,
842 struct fb_info *info); 713 struct fb_info *info);
843static void sisfb_blank(int blank, 714static void sisfb_blank(int blank,
844 struct fb_info *info); 715 struct fb_info *info);
845static void sisfb_set_disp(int con, 716static void sisfb_set_disp(int con,
846 struct fb_var_screeninfo *var, 717 struct fb_var_screeninfo *var,
847 struct fb_info *info); 718 struct fb_info *info);
848static int sis_getcolreg(unsigned regno, unsigned *red, unsigned *green, 719static int sis_getcolreg(unsigned regno, unsigned *red, unsigned *green,
849 unsigned *blue, unsigned *transp, 720 unsigned *blue, unsigned *transp,
850 struct fb_info *fb_info); 721 struct fb_info *fb_info);
851static void sisfb_do_install_cmap(int con, 722static void sisfb_do_install_cmap(int con,
852 struct fb_info *info); 723 struct fb_info *info);
853static int sisfb_ioctl(struct inode *inode, struct file *file, 724static int sisfb_ioctl(struct inode *inode, struct file *file,
854 unsigned int cmd, unsigned long arg, int con, 725 unsigned int cmd, unsigned long arg, int con,
855 struct fb_info *info); 726 struct fb_info *info);
856#endif 727#endif
857 728
858#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 729#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
859static int sisfb_ioctl(struct inode *inode, struct file *file, 730static int sisfb_ioctl(struct inode *inode, struct file *file,
860 unsigned int cmd, unsigned long arg, 731 unsigned int cmd, unsigned long arg,
861 struct fb_info *info); 732 struct fb_info *info);
862static int sisfb_set_par(struct fb_info *info); 733static int sisfb_set_par(struct fb_info *info);
863static int sisfb_blank(int blank, 734static int sisfb_blank(int blank,
864 struct fb_info *info); 735 struct fb_info *info);
865extern void fbcon_sis_fillrect(struct fb_info *info, 736extern void fbcon_sis_fillrect(struct fb_info *info,
866 const struct fb_fillrect *rect); 737 const struct fb_fillrect *rect);
867extern void fbcon_sis_copyarea(struct fb_info *info, 738extern void fbcon_sis_copyarea(struct fb_info *info,
868 const struct fb_copyarea *area); 739 const struct fb_copyarea *area);
869extern int fbcon_sis_sync(struct fb_info *info); 740extern int fbcon_sis_sync(struct fb_info *info);
870#endif 741#endif
871 742
872/* Internal 2D accelerator functions */ 743/* Internal 2D accelerator functions */
873extern int sisfb_initaccel(struct sis_video_info *ivideo); 744extern int sisfb_initaccel(struct sis_video_info *ivideo);
874extern void sisfb_syncaccel(struct sis_video_info *ivideo); 745extern void sisfb_syncaccel(struct sis_video_info *ivideo);
875 746
876/* Internal general routines */ 747/* Internal general routines */
877static void sisfb_search_mode(char *name, BOOLEAN quiet); 748static void sisfb_search_mode(char *name, BOOLEAN quiet);
878static int sisfb_validate_mode(struct sis_video_info *ivideo, int modeindex, u32 vbflags); 749static int sisfb_validate_mode(struct sis_video_info *ivideo, int modeindex, u32 vbflags);
879static u8 sisfb_search_refresh_rate(struct sis_video_info *ivideo, unsigned int rate, 750static u8 sisfb_search_refresh_rate(struct sis_video_info *ivideo, unsigned int rate,
880 int index); 751 int index);
881static int sisfb_setcolreg(unsigned regno, unsigned red, unsigned green, 752static int sisfb_setcolreg(unsigned regno, unsigned red, unsigned green,
882 unsigned blue, unsigned transp, 753 unsigned blue, unsigned transp,
883 struct fb_info *fb_info); 754 struct fb_info *fb_info);
884static int sisfb_do_set_var(struct fb_var_screeninfo *var, int isactive, 755static int sisfb_do_set_var(struct fb_var_screeninfo *var, int isactive,
885 struct fb_info *info); 756 struct fb_info *info);
886static void sisfb_pre_setmode(struct sis_video_info *ivideo); 757static void sisfb_pre_setmode(struct sis_video_info *ivideo);
887static void sisfb_post_setmode(struct sis_video_info *ivideo); 758static void sisfb_post_setmode(struct sis_video_info *ivideo);
888static BOOLEAN sisfb_CheckVBRetrace(struct sis_video_info *ivideo); 759static BOOLEAN sisfb_CheckVBRetrace(struct sis_video_info *ivideo);
889static BOOLEAN sisfbcheckvretracecrt2(struct sis_video_info *ivideo); 760static BOOLEAN sisfbcheckvretracecrt2(struct sis_video_info *ivideo);
890static BOOLEAN sisfbcheckvretracecrt1(struct sis_video_info *ivideo); 761static BOOLEAN sisfbcheckvretracecrt1(struct sis_video_info *ivideo);
891static BOOLEAN sisfb_bridgeisslave(struct sis_video_info *ivideo); 762static BOOLEAN sisfb_bridgeisslave(struct sis_video_info *ivideo);
892static void sisfb_detect_VB_connect(struct sis_video_info *ivideo); 763static void sisfb_detect_VB_connect(struct sis_video_info *ivideo);
893static void sisfb_get_VB_type(struct sis_video_info *ivideo); 764static void sisfb_get_VB_type(struct sis_video_info *ivideo);
894static void sisfb_set_TVxposoffset(struct sis_video_info *ivideo, int val); 765static void sisfb_set_TVxposoffset(struct sis_video_info *ivideo, int val);
895static void sisfb_set_TVyposoffset(struct sis_video_info *ivideo, int val); 766static void sisfb_set_TVyposoffset(struct sis_video_info *ivideo, int val);
767#ifdef CONFIG_FB_SIS_300
768unsigned int sisfb_read_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg);
769void sisfb_write_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg, unsigned int val);
770unsigned int sisfb_read_lpc_pci_dword(struct SiS_Private *SiS_Pr, int reg);
771#endif
772#ifdef CONFIG_FB_SIS_315
773void sisfb_write_nbridge_pci_byte(struct SiS_Private *SiS_Pr, int reg, unsigned char val);
774unsigned int sisfb_read_mio_pci_word(struct SiS_Private *SiS_Pr, int reg);
775#endif
896 776
897/* SiS-specific exported functions */ 777/* SiS-specific exported functions */
898void sis_malloc(struct sis_memreq *req); 778void sis_malloc(struct sis_memreq *req);
899void sis_free(u32 base); 779void sis_malloc_new(struct pci_dev *pdev, struct sis_memreq *req);
780void sis_free(u32 base);
781void sis_free_new(struct pci_dev *pdev, u32 base);
900 782
901/* Internal heap routines */ 783/* Internal heap routines */
902static int sisfb_heap_init(struct sis_video_info *ivideo); 784static int sisfb_heap_init(struct sis_video_info *ivideo);
903static SIS_OH *sisfb_poh_new_node(void); 785static struct SIS_OH * sisfb_poh_new_node(struct SIS_HEAP *memheap);
904static SIS_OH *sisfb_poh_allocate(u32 size); 786static struct SIS_OH * sisfb_poh_allocate(struct SIS_HEAP *memheap, u32 size);
905static void sisfb_delete_node(SIS_OH *poh); 787static void sisfb_delete_node(struct SIS_OH *poh);
906static void sisfb_insert_node(SIS_OH *pohList, SIS_OH *poh); 788static void sisfb_insert_node(struct SIS_OH *pohList, struct SIS_OH *poh);
907static SIS_OH *sisfb_poh_free(u32 base); 789static struct SIS_OH * sisfb_poh_free(struct SIS_HEAP *memheap, u32 base);
908static void sisfb_free_node(SIS_OH *poh); 790static void sisfb_free_node(struct SIS_HEAP *memheap, struct SIS_OH *poh);
909
910/* Sensing routines */
911static void SiS_Sense30x(struct sis_video_info *ivideo);
912static void SiS_SenseCh(struct sis_video_info *ivideo);
913 791
914/* Routines from init.c/init301.c */ 792/* Routines from init.c/init301.c */
915extern USHORT SiS_GetModeID_LCD(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int Depth, 793extern unsigned short SiS_GetModeID_LCD(int VGAEngine, unsigned int VBFlags, int HDisplay,
916 BOOLEAN FSTN, USHORT CustomT, int LCDwith, int LCDheight); 794 int VDisplay, int Depth, BOOLEAN FSTN, unsigned short CustomT,
917extern USHORT SiS_GetModeID_TV(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int Depth); 795 int LCDwith, int LCDheight, unsigned int VBFlags2);
918extern USHORT SiS_GetModeID_VGA2(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int Depth); 796extern unsigned short SiS_GetModeID_TV(int VGAEngine, unsigned int VBFlags, int HDisplay,
919 797 int VDisplay, int Depth, unsigned int VBFlags2);
920extern void SiSRegInit(SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr); 798extern unsigned short SiS_GetModeID_VGA2(int VGAEngine, unsigned int VBFlags, int HDisplay,
921extern BOOLEAN SiSSetMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwDeviceInfo, USHORT ModeNo); 799 int VDisplay, int Depth, unsigned int VBFlags2);
922extern void SiS_SetEnableDstn(SiS_Private *SiS_Pr, int enable); 800extern void SiSRegInit(struct SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr);
923extern void SiS_SetEnableFstn(SiS_Private *SiS_Pr, int enable); 801extern BOOLEAN SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo);
924 802extern void SiS_SetEnableDstn(struct SiS_Private *SiS_Pr, int enable);
925extern BOOLEAN SiSDetermineROMLayout661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo); 803extern void SiS_SetEnableFstn(struct SiS_Private *SiS_Pr, int enable);
926 804
927extern BOOLEAN sisfb_gettotalfrommode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwDeviceExtension, 805extern BOOLEAN SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr);
928 unsigned char modeno, int *htotal, int *vtotal, unsigned char rateindex); 806
807extern BOOLEAN sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno,
808 int *htotal, int *vtotal, unsigned char rateindex);
929#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 809#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
930extern int sisfb_mode_rate_to_dclock(SiS_Private *SiS_Pr, 810extern int sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr,
931 PSIS_HW_INFO HwDeviceExtension, 811 unsigned char modeno, unsigned char rateindex);
932 unsigned char modeno, unsigned char rateindex); 812extern int sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno,
933extern int sisfb_mode_rate_to_ddata(SiS_Private *SiS_Pr, PSIS_HW_INFO HwDeviceExtension, 813 unsigned char rateindex, struct fb_var_screeninfo *var);
934 unsigned char modeno, unsigned char rateindex, 814#endif
935 struct fb_var_screeninfo *var); 815#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
816extern void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata, int xres,
817 int yres, struct fb_var_screeninfo *var, BOOLEAN writeres);
936#endif 818#endif
937 819
938/* Chrontel TV, DDC and DPMS functions */ 820/* Chrontel TV, DDC and DPMS functions */
939extern USHORT SiS_GetCH700x(SiS_Private *SiS_Pr, USHORT tempbx); 821extern unsigned short SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short reg);
940extern void SiS_SetCH700x(SiS_Private *SiS_Pr, USHORT tempbx); 822extern void SiS_SetCH700x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val);
941extern USHORT SiS_GetCH701x(SiS_Private *SiS_Pr, USHORT tempbx); 823extern unsigned short SiS_GetCH701x(struct SiS_Private *SiS_Pr, unsigned short reg);
942extern void SiS_SetCH701x(SiS_Private *SiS_Pr, USHORT tempbx); 824extern void SiS_SetCH701x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val);
943extern void SiS_SetCH70xxANDOR(SiS_Private *SiS_Pr, USHORT tempax,USHORT tempbh); 825extern void SiS_SetCH70xxANDOR(struct SiS_Private *SiS_Pr, unsigned short reg,
944extern void SiS_DDC2Delay(SiS_Private *SiS_Pr, USHORT delaytime); 826 unsigned char myor, unsigned char myand);
945extern void SiS_SetChrontelGPIO(SiS_Private *SiS_Pr, USHORT myvbinfo); 827extern void SiS_DDC2Delay(struct SiS_Private *SiS_Pr, unsigned int delaytime);
946extern USHORT SiS_HandleDDC(SiS_Private *SiS_Pr, ULONG VBFlags, int VGAEngine, 828extern void SiS_SetChrontelGPIO(struct SiS_Private *SiS_Pr, unsigned short myvbinfo);
947 USHORT adaptnum, USHORT DDCdatatype, unsigned char *buffer); 829extern unsigned short SiS_HandleDDC(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
948extern USHORT SiS_ReadDDC1Bit(SiS_Private *SiS_Pr); 830 unsigned short adaptnum, unsigned short DDCdatatype, unsigned char *buffer,
949extern void SiS_Chrontel701xBLOn(SiS_Private *SiS_Pr, PSIS_HW_INFO HwDeviceInfo); 831 unsigned int VBFlags2);
950extern void SiS_Chrontel701xBLOff(SiS_Private *SiS_Pr); 832extern unsigned short SiS_ReadDDC1Bit(struct SiS_Private *SiS_Pr);
951extern void SiS_SiS30xBLOn(SiS_Private *SiS_Pr, PSIS_HW_INFO HwDeviceInfo); 833#ifdef CONFIG_FB_SIS_315
952extern void SiS_SiS30xBLOff(SiS_Private *SiS_Pr, PSIS_HW_INFO HwDeviceInfo); 834extern void SiS_Chrontel701xBLOn(struct SiS_Private *SiS_Pr);
835extern void SiS_Chrontel701xBLOff(struct SiS_Private *SiS_Pr);
836#endif
837extern void SiS_SiS30xBLOn(struct SiS_Private *SiS_Pr);
838extern void SiS_SiS30xBLOff(struct SiS_Private *SiS_Pr);
953#endif 839#endif
954 840
955 841
diff --git a/drivers/video/sis/vgatypes.h b/drivers/video/sis/vgatypes.h
index 507bba1a71..831b9f4226 100644
--- a/drivers/video/sis/vgatypes.h
+++ b/drivers/video/sis/vgatypes.h
@@ -3,7 +3,7 @@
3/* 3/*
4 * General type definitions for universal mode switching modules 4 * General type definitions for universal mode switching modules
5 * 5 *
6 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria 6 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
7 * 7 *
8 * If distributed as part of the Linux kernel, the following license terms 8 * If distributed as part of the Linux kernel, the following license terms
9 * apply: 9 * apply:
@@ -50,11 +50,10 @@
50 * 50 *
51 */ 51 */
52 52
53#ifndef _VGATYPES_ 53#ifndef _VGATYPES_H_
54#define _VGATYPES_ 54#define _VGATYPES_H_
55 55
56#ifdef LINUX_KERNEL /* We don't want the X driver to depend on kernel source */ 56#ifdef SIS_LINUX_KERNEL
57#include <linux/ioctl.h>
58#include <linux/version.h> 57#include <linux/version.h>
59#endif 58#endif
60 59
@@ -66,41 +65,13 @@
66#define TRUE 1 65#define TRUE 1
67#endif 66#endif
68 67
69#ifndef NULL
70#define NULL 0
71#endif
72
73#ifndef CHAR
74typedef char CHAR;
75#endif
76
77#ifndef SHORT
78typedef short SHORT;
79#endif
80
81#ifndef LONG
82typedef long LONG;
83#endif
84
85#ifndef UCHAR
86typedef unsigned char UCHAR;
87#endif
88
89#ifndef USHORT
90typedef unsigned short USHORT;
91#endif
92
93#ifndef ULONG
94typedef unsigned long ULONG;
95#endif
96
97#ifndef BOOLEAN 68#ifndef BOOLEAN
98typedef unsigned char BOOLEAN; 69typedef unsigned int BOOLEAN;
99#endif 70#endif
100 71
101#define SISIOMEMTYPE 72#define SISIOMEMTYPE
102 73
103#ifdef LINUX_KERNEL 74#ifdef SIS_LINUX_KERNEL
104typedef unsigned long SISIOADDRESS; 75typedef unsigned long SISIOADDRESS;
105#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8) 76#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8)
106#include <linux/types.h> /* Need __iomem */ 77#include <linux/types.h> /* Need __iomem */
@@ -109,7 +80,7 @@ typedef unsigned long SISIOADDRESS;
109#endif 80#endif
110#endif 81#endif
111 82
112#ifdef LINUX_XF86 83#ifdef SIS_XORG_XF86
113#if XF86_VERSION_CURRENT < XF86_VERSION_NUMERIC(4,2,0,0,0) 84#if XF86_VERSION_CURRENT < XF86_VERSION_NUMERIC(4,2,0,0,0)
114typedef unsigned long IOADDRESS; 85typedef unsigned long IOADDRESS;
115typedef unsigned long SISIOADDRESS; 86typedef unsigned long SISIOADDRESS;
@@ -118,7 +89,7 @@ typedef IOADDRESS SISIOADDRESS;
118#endif 89#endif
119#endif 90#endif
120 91
121enum _SIS_CHIP_TYPE { 92typedef enum _SIS_CHIP_TYPE {
122 SIS_VGALegacy = 0, 93 SIS_VGALegacy = 0,
123 SIS_530, 94 SIS_530,
124 SIS_OLD, 95 SIS_OLD,
@@ -128,115 +99,27 @@ enum _SIS_CHIP_TYPE {
128 SIS_540, 99 SIS_540,
129 SIS_315H, /* SiS 310 */ 100 SIS_315H, /* SiS 310 */
130 SIS_315, 101 SIS_315,
131 SIS_315PRO, 102 SIS_315PRO, /* SiS 325 */
132 SIS_550, 103 SIS_550,
133 SIS_650, 104 SIS_650,
134 SIS_740, 105 SIS_740,
135 SIS_330, 106 SIS_330,
136 SIS_661, 107 SIS_661,
137 SIS_741, 108 SIS_741,
138 SIS_660, 109 SIS_670,
110 SIS_660 = 35,
139 SIS_760, 111 SIS_760,
140 SIS_761, 112 SIS_761,
141 SIS_340, 113 SIS_762,
114 SIS_770,
115 SIS_340 = 55,
116 SIS_341,
117 SIS_342,
118 XGI_20 = 75,
119 XGI_40,
142 MAX_SIS_CHIP 120 MAX_SIS_CHIP
143}; 121} SIS_CHIP_TYPE;
144
145#ifndef SIS_HW_INFO
146typedef struct _SIS_HW_INFO SIS_HW_INFO, *PSIS_HW_INFO;
147
148struct _SIS_HW_INFO
149{
150#ifdef LINUX_XF86
151 PCITAG PciTag; /* PCI Tag */
152#endif
153
154 UCHAR *pjVirtualRomBase; /* ROM image */
155
156 BOOLEAN UseROM; /* Use the ROM image if provided */
157
158#ifdef LINUX_KERNEL
159 UCHAR SISIOMEMTYPE *pjVideoMemoryAddress;
160 /* base virtual memory address */
161 /* of Linear VGA memory */
162
163 ULONG ulVideoMemorySize; /* size, in bytes, of the memory on the board */
164#endif
165
166 SISIOADDRESS ulIOAddress; /* base I/O address of VGA ports (0x3B0; relocated) */
167
168 UCHAR jChipType; /* Used to Identify SiS Graphics Chip */
169 /* defined in the enum "SIS_CHIP_TYPE" (above or sisfb.h) */
170 122
171 UCHAR jChipRevision; /* Used to Identify SiS Graphics Chip Revision */
172
173 BOOLEAN bIntegratedMMEnabled;/* supporting integration MM enable */
174};
175#endif
176
177/* Addtional IOCTLs for communication sisfb <> X driver */
178/* If changing this, sisfb.h must also be changed (for sisfb) */
179
180#ifdef LINUX_XF86 /* We don't want the X driver to depend on the kernel source */
181
182/* ioctl for identifying and giving some info (esp. memory heap start) */
183#define SISFB_GET_INFO_SIZE 0x8004f300
184#define SISFB_GET_INFO 0x8000f301 /* Must be patched with result from ..._SIZE at D[29:16] */
185/* deprecated ioctl number (for older versions of sisfb) */
186#define SISFB_GET_INFO_OLD 0x80046ef8
187
188/* ioctls for tv parameters (position) */
189#define SISFB_SET_TVPOSOFFSET 0x4004f304
190
191/* lock sisfb from register access */
192#define SISFB_SET_LOCK 0x4004f306
193
194/* Structure argument for SISFB_GET_INFO ioctl */
195typedef struct _SISFB_INFO sisfb_info, *psisfb_info;
196
197struct _SISFB_INFO {
198 CARD32 sisfb_id; /* for identifying sisfb */
199#ifndef SISFB_ID
200#define SISFB_ID 0x53495346 /* Identify myself with 'SISF' */
201#endif
202 CARD32 chip_id; /* PCI ID of detected chip */
203 CARD32 memory; /* video memory in KB which sisfb manages */
204 CARD32 heapstart; /* heap start (= sisfb "mem" argument) in KB */
205 CARD8 fbvidmode; /* current sisfb mode */
206
207 CARD8 sisfb_version;
208 CARD8 sisfb_revision;
209 CARD8 sisfb_patchlevel;
210
211 CARD8 sisfb_caps; /* sisfb's capabilities */
212
213 CARD32 sisfb_tqlen; /* turbo queue length (in KB) */
214
215 CARD32 sisfb_pcibus; /* The card's PCI ID */
216 CARD32 sisfb_pcislot;
217 CARD32 sisfb_pcifunc;
218
219 CARD8 sisfb_lcdpdc;
220
221 CARD8 sisfb_lcda;
222
223 CARD32 sisfb_vbflags;
224 CARD32 sisfb_currentvbflags;
225
226 CARD32 sisfb_scalelcd;
227 CARD32 sisfb_specialtiming;
228
229 CARD8 sisfb_haveemi;
230 CARD8 sisfb_emi30,sisfb_emi31,sisfb_emi32,sisfb_emi33;
231 CARD8 sisfb_haveemilcd;
232
233 CARD8 sisfb_lcdpdca;
234
235 CARD16 sisfb_tvxpos, sisfb_tvypos; /* Warning: Values + 32 ! */
236
237 CARD8 reserved[208]; /* for future use */
238};
239#endif
240 123
241#endif 124#endif
242 125
diff --git a/drivers/video/sis/vstruct.h b/drivers/video/sis/vstruct.h
index d4d55c98bc..9ae32923c1 100644
--- a/drivers/video/sis/vstruct.h
+++ b/drivers/video/sis/vstruct.h
@@ -3,7 +3,7 @@
3/* 3/*
4 * General structure definitions for universal mode switching modules 4 * General structure definitions for universal mode switching modules
5 * 5 *
6 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria 6 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
7 * 7 *
8 * If distributed as part of the Linux kernel, the following license terms 8 * If distributed as part of the Linux kernel, the following license terms
9 * apply: 9 * apply:
@@ -50,627 +50,514 @@
50 * 50 *
51 */ 51 */
52 52
53#ifndef _VSTRUCT_ 53#ifndef _VSTRUCT_H_
54#define _VSTRUCT_ 54#define _VSTRUCT_H_
55 55
56typedef struct _SiS_PanelDelayTblStruct 56struct SiS_PanelDelayTbl {
57{ 57 unsigned char timer[2];
58 UCHAR timer[2]; 58};
59} SiS_PanelDelayTblStruct; 59
60 60struct SiS_LCDData {
61typedef struct _SiS_LCDDataStruct 61 unsigned short RVBHCMAX;
62{ 62 unsigned short RVBHCFACT;
63 USHORT RVBHCMAX; 63 unsigned short VGAHT;
64 USHORT RVBHCFACT; 64 unsigned short VGAVT;
65 USHORT VGAHT; 65 unsigned short LCDHT;
66 USHORT VGAVT; 66 unsigned short LCDVT;
67 USHORT LCDHT; 67};
68 USHORT LCDVT; 68
69} SiS_LCDDataStruct; 69struct SiS_TVData {
70 70 unsigned short RVBHCMAX;
71typedef struct _SiS_TVDataStruct 71 unsigned short RVBHCFACT;
72{ 72 unsigned short VGAHT;
73 USHORT RVBHCMAX; 73 unsigned short VGAVT;
74 USHORT RVBHCFACT; 74 unsigned short TVHDE;
75 USHORT VGAHT; 75 unsigned short TVVDE;
76 USHORT VGAVT; 76 unsigned short RVBHRS;
77 USHORT TVHDE; 77 unsigned char FlickerMode;
78 USHORT TVVDE; 78 unsigned short HALFRVBHRS;
79 USHORT RVBHRS; 79 unsigned short RVBHRS2;
80 UCHAR FlickerMode; 80 unsigned char RY1COE;
81 USHORT HALFRVBHRS; 81 unsigned char RY2COE;
82 UCHAR RY1COE; 82 unsigned char RY3COE;
83 UCHAR RY2COE; 83 unsigned char RY4COE;
84 UCHAR RY3COE; 84};
85 UCHAR RY4COE; 85
86} SiS_TVDataStruct; 86struct SiS_LVDSData {
87 87 unsigned short VGAHT;
88typedef struct _SiS_LVDSDataStruct 88 unsigned short VGAVT;
89{ 89 unsigned short LCDHT;
90 USHORT VGAHT; 90 unsigned short LCDVT;
91 USHORT VGAVT; 91};
92 USHORT LCDHT; 92
93 USHORT LCDVT; 93struct SiS_LVDSDes {
94} SiS_LVDSDataStruct; 94 unsigned short LCDHDES;
95 95 unsigned short LCDVDES;
96typedef struct _SiS_LVDSDesStruct 96};
97{ 97
98 USHORT LCDHDES; 98struct SiS_LVDSCRT1Data {
99 USHORT LCDVDES; 99 unsigned char CR[15];
100} SiS_LVDSDesStruct; 100};
101 101
102typedef struct _SiS_LVDSCRT1DataStruct 102struct SiS_CHTVRegData {
103{ 103 unsigned char Reg[16];
104 UCHAR CR[15]; 104};
105} SiS_LVDSCRT1DataStruct; 105
106 106struct SiS_St {
107typedef struct _SiS_LCDACRT1DataStruct 107 unsigned char St_ModeID;
108{ 108 unsigned short St_ModeFlag;
109 UCHAR CR[17]; 109 unsigned char St_StTableIndex;
110} SiS_LCDACRT1DataStruct; 110 unsigned char St_CRT2CRTC;
111 111 unsigned char St_ResInfo;
112typedef struct _SiS_CHTVRegDataStruct 112 unsigned char VB_StTVFlickerIndex;
113{ 113 unsigned char VB_StTVEdgeIndex;
114 UCHAR Reg[16]; 114 unsigned char VB_StTVYFilterIndex;
115} SiS_CHTVRegDataStruct; 115 unsigned char St_PDC;
116 116};
117typedef struct _SiS_StStruct 117
118{ 118struct SiS_VBMode {
119 UCHAR St_ModeID; 119 unsigned char ModeID;
120 USHORT St_ModeFlag; 120 unsigned char VB_TVDelayIndex;
121 UCHAR St_StTableIndex; 121 unsigned char VB_TVFlickerIndex;
122 UCHAR St_CRT2CRTC; 122 unsigned char VB_TVPhaseIndex;
123 UCHAR St_ResInfo; 123 unsigned char VB_TVYFilterIndex;
124 UCHAR VB_StTVFlickerIndex; 124 unsigned char VB_LCDDelayIndex;
125 UCHAR VB_StTVEdgeIndex; 125 unsigned char _VB_LCDHIndex;
126 UCHAR VB_StTVYFilterIndex; 126 unsigned char _VB_LCDVIndex;
127 UCHAR St_PDC; 127};
128} SiS_StStruct; 128
129 129struct SiS_StandTable_S {
130typedef struct _SiS_VBModeStruct 130 unsigned char CRT_COLS;
131{ 131 unsigned char ROWS;
132 UCHAR ModeID; 132 unsigned char CHAR_HEIGHT;
133 UCHAR VB_TVDelayIndex; 133 unsigned short CRT_LEN;
134 UCHAR VB_TVFlickerIndex; 134 unsigned char SR[4];
135 UCHAR VB_TVPhaseIndex; 135 unsigned char MISC;
136 UCHAR VB_TVYFilterIndex; 136 unsigned char CRTC[0x19];
137 UCHAR VB_LCDDelayIndex; 137 unsigned char ATTR[0x14];
138 UCHAR _VB_LCDHIndex; 138 unsigned char GRC[9];
139 UCHAR _VB_LCDVIndex; 139};
140} SiS_VBModeStruct; 140
141 141struct SiS_Ext {
142typedef struct _SiS_StandTableStruct 142 unsigned char Ext_ModeID;
143{ 143 unsigned short Ext_ModeFlag;
144 UCHAR CRT_COLS; 144 unsigned short Ext_VESAID;
145 UCHAR ROWS; 145 unsigned char Ext_RESINFO;
146 UCHAR CHAR_HEIGHT; 146 unsigned char VB_ExtTVFlickerIndex;
147 USHORT CRT_LEN; 147 unsigned char VB_ExtTVEdgeIndex;
148 UCHAR SR[4]; 148 unsigned char VB_ExtTVYFilterIndex;
149 UCHAR MISC; 149 unsigned char VB_ExtTVYFilterIndexROM661;
150 UCHAR CRTC[0x19]; 150 unsigned char REFindex;
151 UCHAR ATTR[0x14]; 151 char ROMMODEIDX661;
152 UCHAR GRC[9]; 152};
153} SiS_StandTableStruct; 153
154 154struct SiS_Ext2 {
155typedef struct _SiS_ExtStruct 155 unsigned short Ext_InfoFlag;
156{ 156 unsigned char Ext_CRT1CRTC;
157 UCHAR Ext_ModeID; 157 unsigned char Ext_CRTVCLK;
158 USHORT Ext_ModeFlag; 158 unsigned char Ext_CRT2CRTC;
159 USHORT Ext_VESAID; 159 unsigned char Ext_CRT2CRTC_NS;
160 UCHAR Ext_RESINFO; 160 unsigned char ModeID;
161 UCHAR VB_ExtTVFlickerIndex; 161 unsigned short XRes;
162 UCHAR VB_ExtTVEdgeIndex; 162 unsigned short YRes;
163 UCHAR VB_ExtTVYFilterIndex; 163 unsigned char Ext_PDC;
164 UCHAR VB_ExtTVYFilterIndexROM661; 164 unsigned char Ext_FakeCRT2CRTC;
165 UCHAR REFindex; 165 unsigned char Ext_FakeCRT2Clk;
166 CHAR ROMMODEIDX661; 166 unsigned char Ext_CRT1CRTC_NORM;
167} SiS_ExtStruct; 167 unsigned char Ext_CRTVCLK_NORM;
168 168 unsigned char Ext_CRT1CRTC_WIDE;
169typedef struct _SiS_Ext2Struct 169 unsigned char Ext_CRTVCLK_WIDE;
170{ 170};
171 USHORT Ext_InfoFlag; 171
172 UCHAR Ext_CRT1CRTC; 172struct SiS_Part2PortTbl {
173 UCHAR Ext_CRTVCLK; 173 unsigned char CR[12];
174 UCHAR Ext_CRT2CRTC; 174};
175 UCHAR Ext_CRT2CRTC_NS; 175
176 UCHAR ModeID; 176struct SiS_CRT1Table {
177 USHORT XRes; 177 unsigned char CR[17];
178 USHORT YRes; 178};
179 UCHAR Ext_PDC; 179
180} SiS_Ext2Struct; 180struct SiS_MCLKData {
181 181 unsigned char SR28,SR29,SR2A;
182typedef struct _SiS_Part2PortTblStruct 182 unsigned short CLOCK;
183{ 183};
184 UCHAR CR[12]; 184
185} SiS_Part2PortTblStruct; 185struct SiS_VCLKData {
186 186 unsigned char SR2B,SR2C;
187typedef struct _SiS_CRT1TableStruct 187 unsigned short CLOCK;
188{ 188};
189 UCHAR CR[17]; 189
190} SiS_CRT1TableStruct; 190struct SiS_VBVCLKData {
191 191 unsigned char Part4_A,Part4_B;
192typedef struct _SiS_MCLKDataStruct 192 unsigned short CLOCK;
193{ 193};
194 UCHAR SR28,SR29,SR2A; 194
195 USHORT CLOCK; 195struct SiS_StResInfo_S {
196} SiS_MCLKDataStruct; 196 unsigned short HTotal;
197 197 unsigned short VTotal;
198typedef struct _SiS_VCLKDataStruct 198};
199{ 199
200 UCHAR SR2B,SR2C; 200struct SiS_ModeResInfo_S {
201 USHORT CLOCK; 201 unsigned short HTotal;
202} SiS_VCLKDataStruct; 202 unsigned short VTotal;
203 203 unsigned char XChar;
204typedef struct _SiS_VBVCLKDataStruct 204 unsigned char YChar;
205{ 205};
206 UCHAR Part4_A,Part4_B;
207 USHORT CLOCK;
208} SiS_VBVCLKDataStruct;
209
210typedef struct _SiS_StResInfoStruct
211{
212 USHORT HTotal;
213 USHORT VTotal;
214} SiS_StResInfoStruct;
215
216typedef struct _SiS_ModeResInfoStruct
217{
218 USHORT HTotal;
219 USHORT VTotal;
220 UCHAR XChar;
221 UCHAR YChar;
222} SiS_ModeResInfoStruct;
223
224
225
226typedef UCHAR DRAM4Type[4];
227 206
228/* Defines for SiS_CustomT */ 207/* Defines for SiS_CustomT */
229/* Never change these for sisfb compatibility */ 208/* Never change these for sisfb compatibility */
230#define CUT_NONE 0 209#define CUT_NONE 0
231#define CUT_FORCENONE 1 210#define CUT_FORCENONE 1
232#define CUT_BARCO1366 2 211#define CUT_BARCO1366 2
233#define CUT_BARCO1024 3 212#define CUT_BARCO1024 3
234#define CUT_COMPAQ1280 4 213#define CUT_COMPAQ1280 4
235#define CUT_COMPAQ12802 5 214#define CUT_COMPAQ12802 5
236#define CUT_PANEL848 6 215#define CUT_PANEL848 6
237#define CUT_CLEVO1024 7 216#define CUT_CLEVO1024 7
238#define CUT_CLEVO10242 8 217#define CUT_CLEVO10242 8
239#define CUT_CLEVO1400 9 218#define CUT_CLEVO1400 9
240#define CUT_CLEVO14002 10 219#define CUT_CLEVO14002 10
241#define CUT_UNIWILL1024 11 220#define CUT_UNIWILL1024 11
242#define CUT_ASUSL3000D 12 221#define CUT_ASUSL3000D 12
243#define CUT_UNIWILL10242 13 222#define CUT_UNIWILL10242 13
244#define CUT_ACER1280 14 223#define CUT_ACER1280 14
245#define CUT_COMPAL1400_1 15 224#define CUT_COMPAL1400_1 15
246#define CUT_COMPAL1400_2 16 225#define CUT_COMPAL1400_2 16
247#define CUT_ASUSA2H_1 17 226#define CUT_ASUSA2H_1 17
248#define CUT_ASUSA2H_2 18 227#define CUT_ASUSA2H_2 18
249 228#define CUT_UNKNOWNLCD 19
250typedef struct _SiS_Private 229#define CUT_AOP8060 20
230#define CUT_PANEL856 21
231
232struct SiS_Private
251{ 233{
252#ifdef LINUX_KERNEL 234 unsigned char ChipType;
253 SISIOADDRESS RelIO; 235 unsigned char ChipRevision;
236#ifdef SIS_XORG_XF86
237 PCITAG PciTag;
254#endif 238#endif
255 SISIOADDRESS SiS_P3c4; 239#ifdef SIS_LINUX_KERNEL
256 SISIOADDRESS SiS_P3d4; 240 void *ivideo;
257 SISIOADDRESS SiS_P3c0;
258 SISIOADDRESS SiS_P3ce;
259 SISIOADDRESS SiS_P3c2;
260 SISIOADDRESS SiS_P3ca;
261 SISIOADDRESS SiS_P3c6;
262 SISIOADDRESS SiS_P3c7;
263 SISIOADDRESS SiS_P3c8;
264 SISIOADDRESS SiS_P3c9;
265 SISIOADDRESS SiS_P3cb;
266 SISIOADDRESS SiS_P3cd;
267 SISIOADDRESS SiS_P3da;
268 SISIOADDRESS SiS_Part1Port;
269 SISIOADDRESS SiS_Part2Port;
270 SISIOADDRESS SiS_Part3Port;
271 SISIOADDRESS SiS_Part4Port;
272 SISIOADDRESS SiS_Part5Port;
273 SISIOADDRESS SiS_VidCapt;
274 SISIOADDRESS SiS_VidPlay;
275 USHORT SiS_IF_DEF_LVDS;
276 USHORT SiS_IF_DEF_CH70xx;
277 USHORT SiS_IF_DEF_CONEX;
278 USHORT SiS_IF_DEF_TRUMPION;
279 USHORT SiS_IF_DEF_DSTN;
280 USHORT SiS_IF_DEF_FSTN;
281 USHORT SiS_SysFlags;
282 UCHAR SiS_VGAINFO;
283#ifdef LINUX_XF86
284 USHORT SiS_CP1, SiS_CP2, SiS_CP3, SiS_CP4;
285#endif 241#endif
286 BOOLEAN SiS_UseROM; 242 unsigned char *VirtualRomBase;
287 BOOLEAN SiS_ROMNew; 243 BOOLEAN UseROM;
288 BOOLEAN SiS_NeedRomModeData; 244#ifdef SIS_LINUX_KERNEL
289 BOOLEAN PanelSelfDetected; 245 unsigned char SISIOMEMTYPE *VideoMemoryAddress;
290 int SiS_CHOverScan; 246 unsigned int VideoMemorySize;
291 BOOLEAN SiS_CHSOverScan;
292 BOOLEAN SiS_ChSW;
293 BOOLEAN SiS_UseLCDA;
294 int SiS_UseOEM;
295 ULONG SiS_CustomT;
296 USHORT SiS_Backup70xx;
297 BOOLEAN HaveEMI;
298 BOOLEAN HaveEMILCD;
299 BOOLEAN OverruleEMI;
300 UCHAR EMI_30,EMI_31,EMI_32,EMI_33;
301 USHORT SiS_EMIOffset;
302 SHORT PDC, PDCA;
303 UCHAR SiS_MyCR63;
304 USHORT SiS_CRT1Mode;
305 USHORT SiS_flag_clearbuffer;
306 int SiS_RAMType;
307 UCHAR SiS_ChannelAB;
308 UCHAR SiS_DataBusWidth;
309 USHORT SiS_ModeType;
310 USHORT SiS_VBInfo;
311 USHORT SiS_TVMode;
312 USHORT SiS_LCDResInfo;
313 USHORT SiS_LCDTypeInfo;
314 USHORT SiS_LCDInfo;
315 USHORT SiS_LCDInfo661;
316 USHORT SiS_VBType;
317 USHORT SiS_VBExtInfo;
318 USHORT SiS_YPbPr;
319 USHORT SiS_SelectCRT2Rate;
320 USHORT SiS_SetFlag;
321 USHORT SiS_RVBHCFACT;
322 USHORT SiS_RVBHCMAX;
323 USHORT SiS_RVBHRS;
324 USHORT SiS_VGAVT;
325 USHORT SiS_VGAHT;
326 USHORT SiS_VT;
327 USHORT SiS_HT;
328 USHORT SiS_VGAVDE;
329 USHORT SiS_VGAHDE;
330 USHORT SiS_VDE;
331 USHORT SiS_HDE;
332 USHORT SiS_NewFlickerMode;
333 USHORT SiS_RY1COE;
334 USHORT SiS_RY2COE;
335 USHORT SiS_RY3COE;
336 USHORT SiS_RY4COE;
337 USHORT SiS_LCDHDES;
338 USHORT SiS_LCDVDES;
339 USHORT SiS_DDC_Port;
340 USHORT SiS_DDC_Index;
341 USHORT SiS_DDC_Data;
342 USHORT SiS_DDC_NData;
343 USHORT SiS_DDC_Clk;
344 USHORT SiS_DDC_NClk;
345 USHORT SiS_DDC_DeviceAddr;
346 USHORT SiS_DDC_ReadAddr;
347 USHORT SiS_DDC_SecAddr;
348 USHORT SiS_ChrontelInit;
349 BOOLEAN SiS_SensibleSR11;
350 USHORT SiS661LCD2TableSize;
351
352 USHORT SiS_PanelMinLVDS;
353 USHORT SiS_PanelMin301;
354
355 const SiS_StStruct *SiS_SModeIDTable;
356 const SiS_StandTableStruct *SiS_StandTable;
357 const SiS_ExtStruct *SiS_EModeIDTable;
358 const SiS_Ext2Struct *SiS_RefIndex;
359 const SiS_VBModeStruct *SiS_VBModeIDTable;
360 const SiS_CRT1TableStruct *SiS_CRT1Table;
361 const SiS_MCLKDataStruct *SiS_MCLKData_0;
362 const SiS_MCLKDataStruct *SiS_MCLKData_1;
363 SiS_VCLKDataStruct *SiS_VCLKData;
364 SiS_VBVCLKDataStruct *SiS_VBVCLKData;
365 const SiS_StResInfoStruct *SiS_StResInfo;
366 const SiS_ModeResInfoStruct *SiS_ModeResInfo;
367
368 const UCHAR *pSiS_OutputSelect;
369 const UCHAR *pSiS_SoftSetting;
370
371 const DRAM4Type *SiS_SR15; /* pointer : point to array */
372#ifdef LINUX_KERNEL
373 UCHAR *pSiS_SR07;
374 const DRAM4Type *SiS_CR40; /* pointer : point to array */
375 UCHAR *SiS_CR49;
376 UCHAR *SiS_SR25;
377 UCHAR *pSiS_SR1F;
378 UCHAR *pSiS_SR21;
379 UCHAR *pSiS_SR22;
380 UCHAR *pSiS_SR23;
381 UCHAR *pSiS_SR24;
382 UCHAR *pSiS_SR31;
383 UCHAR *pSiS_SR32;
384 UCHAR *pSiS_SR33;
385 UCHAR *pSiS_CRT2Data_1_2;
386 UCHAR *pSiS_CRT2Data_4_D;
387 UCHAR *pSiS_CRT2Data_4_E;
388 UCHAR *pSiS_CRT2Data_4_10;
389 const USHORT *pSiS_RGBSenseData;
390 const USHORT *pSiS_VideoSenseData;
391 const USHORT *pSiS_YCSenseData;
392 const USHORT *pSiS_RGBSenseData2;
393 const USHORT *pSiS_VideoSenseData2;
394 const USHORT *pSiS_YCSenseData2;
395#endif 247#endif
248 SISIOADDRESS IOAddress;
249 SISIOADDRESS IOAddress2; /* For dual chip XGI volari */
396 250
397 const SiS_PanelDelayTblStruct *SiS_PanelDelayTbl; 251#ifdef SIS_LINUX_KERNEL
398 const SiS_PanelDelayTblStruct *SiS_PanelDelayTblLVDS; 252 SISIOADDRESS RelIO;
253#endif
254 SISIOADDRESS SiS_P3c4;
255 SISIOADDRESS SiS_P3d4;
256 SISIOADDRESS SiS_P3c0;
257 SISIOADDRESS SiS_P3ce;
258 SISIOADDRESS SiS_P3c2;
259 SISIOADDRESS SiS_P3ca;
260 SISIOADDRESS SiS_P3c6;
261 SISIOADDRESS SiS_P3c7;
262 SISIOADDRESS SiS_P3c8;
263 SISIOADDRESS SiS_P3c9;
264 SISIOADDRESS SiS_P3cb;
265 SISIOADDRESS SiS_P3cc;
266 SISIOADDRESS SiS_P3cd;
267 SISIOADDRESS SiS_P3da;
268 SISIOADDRESS SiS_Part1Port;
269 SISIOADDRESS SiS_Part2Port;
270 SISIOADDRESS SiS_Part3Port;
271 SISIOADDRESS SiS_Part4Port;
272 SISIOADDRESS SiS_Part5Port;
273 SISIOADDRESS SiS_VidCapt;
274 SISIOADDRESS SiS_VidPlay;
275 unsigned short SiS_IF_DEF_LVDS;
276 unsigned short SiS_IF_DEF_CH70xx;
277 unsigned short SiS_IF_DEF_CONEX;
278 unsigned short SiS_IF_DEF_TRUMPION;
279 unsigned short SiS_IF_DEF_DSTN;
280 unsigned short SiS_IF_DEF_FSTN;
281 unsigned short SiS_SysFlags;
282 unsigned char SiS_VGAINFO;
283#ifdef SIS_XORG_XF86
284 unsigned short SiS_CP1, SiS_CP2, SiS_CP3, SiS_CP4;
285#endif
286 BOOLEAN SiS_UseROM;
287 BOOLEAN SiS_ROMNew;
288 BOOLEAN SiS_XGIROM;
289 BOOLEAN SiS_NeedRomModeData;
290 BOOLEAN PanelSelfDetected;
291 BOOLEAN DDCPortMixup;
292 int SiS_CHOverScan;
293 BOOLEAN SiS_CHSOverScan;
294 BOOLEAN SiS_ChSW;
295 BOOLEAN SiS_UseLCDA;
296 int SiS_UseOEM;
297 unsigned int SiS_CustomT;
298 int SiS_UseWide, SiS_UseWideCRT2;
299 int SiS_TVBlue;
300 unsigned short SiS_Backup70xx;
301 BOOLEAN HaveEMI;
302 BOOLEAN HaveEMILCD;
303 BOOLEAN OverruleEMI;
304 unsigned char EMI_30,EMI_31,EMI_32,EMI_33;
305 unsigned short SiS_EMIOffset;
306 unsigned short SiS_PWDOffset;
307 short PDC, PDCA;
308 unsigned char SiS_MyCR63;
309 unsigned short SiS_CRT1Mode;
310 unsigned short SiS_flag_clearbuffer;
311 int SiS_RAMType;
312 unsigned char SiS_ChannelAB;
313 unsigned char SiS_DataBusWidth;
314 unsigned short SiS_ModeType;
315 unsigned short SiS_VBInfo;
316 unsigned short SiS_TVMode;
317 unsigned short SiS_LCDResInfo;
318 unsigned short SiS_LCDTypeInfo;
319 unsigned short SiS_LCDInfo;
320 unsigned short SiS_LCDInfo661;
321 unsigned short SiS_VBType;
322 unsigned short SiS_VBExtInfo;
323 unsigned short SiS_YPbPr;
324 unsigned short SiS_SelectCRT2Rate;
325 unsigned short SiS_SetFlag;
326 unsigned short SiS_RVBHCFACT;
327 unsigned short SiS_RVBHCMAX;
328 unsigned short SiS_RVBHRS;
329 unsigned short SiS_RVBHRS2;
330 unsigned short SiS_VGAVT;
331 unsigned short SiS_VGAHT;
332 unsigned short SiS_VT;
333 unsigned short SiS_HT;
334 unsigned short SiS_VGAVDE;
335 unsigned short SiS_VGAHDE;
336 unsigned short SiS_VDE;
337 unsigned short SiS_HDE;
338 unsigned short SiS_NewFlickerMode;
339 unsigned short SiS_RY1COE;
340 unsigned short SiS_RY2COE;
341 unsigned short SiS_RY3COE;
342 unsigned short SiS_RY4COE;
343 unsigned short SiS_LCDHDES;
344 unsigned short SiS_LCDVDES;
345 unsigned short SiS_DDC_Port;
346 unsigned short SiS_DDC_Index;
347 unsigned short SiS_DDC_Data;
348 unsigned short SiS_DDC_NData;
349 unsigned short SiS_DDC_Clk;
350 unsigned short SiS_DDC_NClk;
351 unsigned short SiS_DDC_DeviceAddr;
352 unsigned short SiS_DDC_ReadAddr;
353 unsigned short SiS_DDC_SecAddr;
354 unsigned short SiS_ChrontelInit;
355 BOOLEAN SiS_SensibleSR11;
356 unsigned short SiS661LCD2TableSize;
357
358 unsigned short SiS_PanelMinLVDS;
359 unsigned short SiS_PanelMin301;
360
361 const struct SiS_St *SiS_SModeIDTable;
362 const struct SiS_StandTable_S *SiS_StandTable;
363 const struct SiS_Ext *SiS_EModeIDTable;
364 const struct SiS_Ext2 *SiS_RefIndex;
365 const struct SiS_VBMode *SiS_VBModeIDTable;
366 const struct SiS_CRT1Table *SiS_CRT1Table;
367 const struct SiS_MCLKData *SiS_MCLKData_0;
368 const struct SiS_MCLKData *SiS_MCLKData_1;
369 struct SiS_VCLKData *SiS_VCLKData;
370 struct SiS_VBVCLKData *SiS_VBVCLKData;
371 const struct SiS_StResInfo_S *SiS_StResInfo;
372 const struct SiS_ModeResInfo_S *SiS_ModeResInfo;
373
374 const unsigned char *pSiS_OutputSelect;
375 const unsigned char *pSiS_SoftSetting;
376
377 const unsigned char *SiS_SR15;
378
379 const struct SiS_PanelDelayTbl *SiS_PanelDelayTbl;
380 const struct SiS_PanelDelayTbl *SiS_PanelDelayTblLVDS;
399 381
400 /* SiS bridge */ 382 /* SiS bridge */
401 383
402 const UCHAR *SiS_NTSCPhase; 384 const struct SiS_LCDData *SiS_ExtLCD1024x768Data;
403 const UCHAR *SiS_PALPhase; 385 const struct SiS_LCDData *SiS_St2LCD1024x768Data;
404 const UCHAR *SiS_NTSCPhase2; 386 const struct SiS_LCDData *SiS_LCD1280x720Data;
405 const UCHAR *SiS_PALPhase2; 387 const struct SiS_LCDData *SiS_StLCD1280x768_2Data;
406 const UCHAR *SiS_PALMPhase; 388 const struct SiS_LCDData *SiS_ExtLCD1280x768_2Data;
407 const UCHAR *SiS_PALNPhase; 389 const struct SiS_LCDData *SiS_LCD1280x800Data;
408 const UCHAR *SiS_PALMPhase2; 390 const struct SiS_LCDData *SiS_LCD1280x800_2Data;
409 const UCHAR *SiS_PALNPhase2; 391 const struct SiS_LCDData *SiS_LCD1280x854Data;
410 const UCHAR *SiS_SpecialPhase; 392 const struct SiS_LCDData *SiS_LCD1280x960Data;
411 const UCHAR *SiS_SpecialPhaseM; 393 const struct SiS_LCDData *SiS_ExtLCD1280x1024Data;
412 const UCHAR *SiS_SpecialPhaseJ; 394 const struct SiS_LCDData *SiS_St2LCD1280x1024Data;
413 const SiS_LCDDataStruct *SiS_ExtLCD1024x768Data; 395 const struct SiS_LCDData *SiS_StLCD1400x1050Data;
414 const SiS_LCDDataStruct *SiS_St2LCD1024x768Data; 396 const struct SiS_LCDData *SiS_ExtLCD1400x1050Data;
415 const SiS_LCDDataStruct *SiS_LCD1280x720Data; 397 const struct SiS_LCDData *SiS_StLCD1600x1200Data;
416 const SiS_LCDDataStruct *SiS_StLCD1280x768_2Data; 398 const struct SiS_LCDData *SiS_ExtLCD1600x1200Data;
417 const SiS_LCDDataStruct *SiS_ExtLCD1280x768_2Data; 399 const struct SiS_LCDData *SiS_LCD1680x1050Data;
418 const SiS_LCDDataStruct *SiS_LCD1280x800Data; 400 const struct SiS_LCDData *SiS_NoScaleData;
419 const SiS_LCDDataStruct *SiS_LCD1280x800_2Data; 401 const struct SiS_TVData *SiS_StPALData;
420 const SiS_LCDDataStruct *SiS_LCD1280x960Data; 402 const struct SiS_TVData *SiS_ExtPALData;
421 const SiS_LCDDataStruct *SiS_ExtLCD1280x1024Data; 403 const struct SiS_TVData *SiS_StNTSCData;
422 const SiS_LCDDataStruct *SiS_St2LCD1280x1024Data; 404 const struct SiS_TVData *SiS_ExtNTSCData;
423 const SiS_LCDDataStruct *SiS_StLCD1400x1050Data; 405 const struct SiS_TVData *SiS_St1HiTVData;
424 const SiS_LCDDataStruct *SiS_ExtLCD1400x1050Data; 406 const struct SiS_TVData *SiS_St2HiTVData;
425 const SiS_LCDDataStruct *SiS_StLCD1600x1200Data; 407 const struct SiS_TVData *SiS_ExtHiTVData;
426 const SiS_LCDDataStruct *SiS_ExtLCD1600x1200Data; 408 const struct SiS_TVData *SiS_St525iData;
427 const SiS_LCDDataStruct *SiS_LCD1680x1050Data; 409 const struct SiS_TVData *SiS_St525pData;
428 const SiS_LCDDataStruct *SiS_NoScaleData; 410 const struct SiS_TVData *SiS_St750pData;
429 const SiS_TVDataStruct *SiS_StPALData; 411 const struct SiS_TVData *SiS_Ext525iData;
430 const SiS_TVDataStruct *SiS_ExtPALData; 412 const struct SiS_TVData *SiS_Ext525pData;
431 const SiS_TVDataStruct *SiS_StNTSCData; 413 const struct SiS_TVData *SiS_Ext750pData;
432 const SiS_TVDataStruct *SiS_ExtNTSCData; 414 const unsigned char *SiS_NTSCTiming;
433 const SiS_TVDataStruct *SiS_St1HiTVData; 415 const unsigned char *SiS_PALTiming;
434 const SiS_TVDataStruct *SiS_St2HiTVData; 416 const unsigned char *SiS_HiTVExtTiming;
435 const SiS_TVDataStruct *SiS_ExtHiTVData; 417 const unsigned char *SiS_HiTVSt1Timing;
436 const SiS_TVDataStruct *SiS_St525iData; 418 const unsigned char *SiS_HiTVSt2Timing;
437 const SiS_TVDataStruct *SiS_St525pData; 419 const unsigned char *SiS_HiTVGroup3Data;
438 const SiS_TVDataStruct *SiS_St750pData; 420 const unsigned char *SiS_HiTVGroup3Simu;
439 const SiS_TVDataStruct *SiS_Ext525iData;
440 const SiS_TVDataStruct *SiS_Ext525pData;
441 const SiS_TVDataStruct *SiS_Ext750pData;
442 const UCHAR *SiS_NTSCTiming;
443 const UCHAR *SiS_PALTiming;
444 const UCHAR *SiS_HiTVExtTiming;
445 const UCHAR *SiS_HiTVSt1Timing;
446 const UCHAR *SiS_HiTVSt2Timing;
447 const UCHAR *SiS_HiTVGroup3Data;
448 const UCHAR *SiS_HiTVGroup3Simu;
449#if 0 421#if 0
450 const UCHAR *SiS_HiTVTextTiming; 422 const unsigned char *SiS_HiTVTextTiming;
451 const UCHAR *SiS_HiTVGroup3Text; 423 const unsigned char *SiS_HiTVGroup3Text;
452#endif 424#endif
453 425
454 const SiS_Part2PortTblStruct *SiS_CRT2Part2_1024x768_1; 426 const struct SiS_Part2PortTbl *SiS_CRT2Part2_1024x768_1;
455 const SiS_Part2PortTblStruct *SiS_CRT2Part2_1280x1024_1; 427 const struct SiS_Part2PortTbl *SiS_CRT2Part2_1024x768_2;
456 const SiS_Part2PortTblStruct *SiS_CRT2Part2_1024x768_2; 428 const struct SiS_Part2PortTbl *SiS_CRT2Part2_1024x768_3;
457 const SiS_Part2PortTblStruct *SiS_CRT2Part2_1280x1024_2;
458 const SiS_Part2PortTblStruct *SiS_CRT2Part2_1024x768_3;
459 const SiS_Part2PortTblStruct *SiS_CRT2Part2_1280x1024_3;
460 429
461 /* LVDS, Chrontel */ 430 /* LVDS, Chrontel */
462 431
463 const SiS_LVDSDataStruct *SiS_LVDS800x600Data_1; 432 const struct SiS_LVDSData *SiS_LVDS320x240Data_1;
464 const SiS_LVDSDataStruct *SiS_LVDS800x600Data_2; 433 const struct SiS_LVDSData *SiS_LVDS320x240Data_2;
465 const SiS_LVDSDataStruct *SiS_LVDS1024x768Data_1; 434 const struct SiS_LVDSData *SiS_LVDS640x480Data_1;
466 const SiS_LVDSDataStruct *SiS_LVDS1024x768Data_2; 435 const struct SiS_LVDSData *SiS_LVDS800x600Data_1;
467 const SiS_LVDSDataStruct *SiS_LVDS1280x1024Data_1; 436 const struct SiS_LVDSData *SiS_LVDS1024x600Data_1;
468 const SiS_LVDSDataStruct *SiS_LVDS1280x1024Data_2; 437 const struct SiS_LVDSData *SiS_LVDS1024x768Data_1;
469 const SiS_LVDSDataStruct *SiS_LVDS1280x960Data_1; 438 const struct SiS_LVDSData *SiS_LVDSBARCO1366Data_1;
470 const SiS_LVDSDataStruct *SiS_LVDS1280x960Data_2; 439 const struct SiS_LVDSData *SiS_LVDSBARCO1366Data_2;
471 const SiS_LVDSDataStruct *SiS_LVDS1400x1050Data_1; 440 const struct SiS_LVDSData *SiS_LVDSBARCO1024Data_1;
472 const SiS_LVDSDataStruct *SiS_LVDS1400x1050Data_2; 441 const struct SiS_LVDSData *SiS_LVDS848x480Data_1;
473 const SiS_LVDSDataStruct *SiS_LVDS1600x1200Data_1; 442 const struct SiS_LVDSData *SiS_LVDS848x480Data_2;
474 const SiS_LVDSDataStruct *SiS_LVDS1600x1200Data_2; 443 const struct SiS_LVDSData *SiS_CHTVUNTSCData;
475 const SiS_LVDSDataStruct *SiS_LVDS1280x768Data_1; 444 const struct SiS_LVDSData *SiS_CHTVONTSCData;
476 const SiS_LVDSDataStruct *SiS_LVDS1280x768Data_2; 445 const struct SiS_LVDSData *SiS_CHTVUPALData;
477 const SiS_LVDSDataStruct *SiS_LVDS1024x600Data_1; 446 const struct SiS_LVDSData *SiS_CHTVOPALData;
478 const SiS_LVDSDataStruct *SiS_LVDS1024x600Data_2; 447 const struct SiS_LVDSData *SiS_CHTVUPALMData;
479 const SiS_LVDSDataStruct *SiS_LVDS1152x768Data_1; 448 const struct SiS_LVDSData *SiS_CHTVOPALMData;
480 const SiS_LVDSDataStruct *SiS_LVDS1152x768Data_2; 449 const struct SiS_LVDSData *SiS_CHTVUPALNData;
481 const SiS_LVDSDataStruct *SiS_LVDS640x480Data_1; 450 const struct SiS_LVDSData *SiS_CHTVOPALNData;
482 const SiS_LVDSDataStruct *SiS_LVDS640x480Data_2; 451 const struct SiS_LVDSData *SiS_CHTVSOPALData;
483 const SiS_LVDSDataStruct *SiS_LVDS320x480Data_1; 452
484 const SiS_LVDSDataStruct *SiS_LVDSXXXxXXXData_1; 453 const struct SiS_LVDSDes *SiS_PanelType04_1a;
485 const SiS_LVDSDataStruct *SiS_LVDSBARCO1366Data_1; 454 const struct SiS_LVDSDes *SiS_PanelType04_2a;
486 const SiS_LVDSDataStruct *SiS_LVDSBARCO1366Data_2; 455 const struct SiS_LVDSDes *SiS_PanelType04_1b;
487 const SiS_LVDSDataStruct *SiS_LVDSBARCO1024Data_1; 456 const struct SiS_LVDSDes *SiS_PanelType04_2b;
488 const SiS_LVDSDataStruct *SiS_LVDSBARCO1024Data_2; 457
489 const SiS_LVDSDataStruct *SiS_LVDS848x480Data_1; 458 const struct SiS_LVDSCRT1Data *SiS_LVDSCRT1320x240_1;
490 const SiS_LVDSDataStruct *SiS_LVDS848x480Data_2; 459 const struct SiS_LVDSCRT1Data *SiS_LVDSCRT1320x240_2;
491 const SiS_LVDSDataStruct *SiS_CHTVUNTSCData; 460 const struct SiS_LVDSCRT1Data *SiS_LVDSCRT1320x240_2_H;
492 const SiS_LVDSDataStruct *SiS_CHTVONTSCData; 461 const struct SiS_LVDSCRT1Data *SiS_LVDSCRT1320x240_3;
493 const SiS_LVDSDataStruct *SiS_CHTVUPALData; 462 const struct SiS_LVDSCRT1Data *SiS_LVDSCRT1320x240_3_H;
494 const SiS_LVDSDataStruct *SiS_CHTVOPALData; 463 const struct SiS_LVDSCRT1Data *SiS_LVDSCRT1640x480_1;
495 const SiS_LVDSDataStruct *SiS_CHTVUPALMData; 464 const struct SiS_LVDSCRT1Data *SiS_LVDSCRT1640x480_1_H;
496 const SiS_LVDSDataStruct *SiS_CHTVOPALMData; 465 const struct SiS_LVDSCRT1Data *SiS_CHTVCRT1UNTSC;
497 const SiS_LVDSDataStruct *SiS_CHTVUPALNData; 466 const struct SiS_LVDSCRT1Data *SiS_CHTVCRT1ONTSC;
498 const SiS_LVDSDataStruct *SiS_CHTVOPALNData; 467 const struct SiS_LVDSCRT1Data *SiS_CHTVCRT1UPAL;
499 const SiS_LVDSDataStruct *SiS_CHTVSOPALData; 468 const struct SiS_LVDSCRT1Data *SiS_CHTVCRT1OPAL;
500 469 const struct SiS_LVDSCRT1Data *SiS_CHTVCRT1SOPAL;
501 const SiS_LVDSDesStruct *SiS_PanelType00_1; 470
502 const SiS_LVDSDesStruct *SiS_PanelType01_1; 471 const struct SiS_CHTVRegData *SiS_CHTVReg_UNTSC;
503 const SiS_LVDSDesStruct *SiS_PanelType02_1; 472 const struct SiS_CHTVRegData *SiS_CHTVReg_ONTSC;
504 const SiS_LVDSDesStruct *SiS_PanelType03_1; 473 const struct SiS_CHTVRegData *SiS_CHTVReg_UPAL;
505 const SiS_LVDSDesStruct *SiS_PanelType04_1; 474 const struct SiS_CHTVRegData *SiS_CHTVReg_OPAL;
506 const SiS_LVDSDesStruct *SiS_PanelType05_1; 475 const struct SiS_CHTVRegData *SiS_CHTVReg_UPALM;
507 const SiS_LVDSDesStruct *SiS_PanelType06_1; 476 const struct SiS_CHTVRegData *SiS_CHTVReg_OPALM;
508 const SiS_LVDSDesStruct *SiS_PanelType07_1; 477 const struct SiS_CHTVRegData *SiS_CHTVReg_UPALN;
509 const SiS_LVDSDesStruct *SiS_PanelType08_1; 478 const struct SiS_CHTVRegData *SiS_CHTVReg_OPALN;
510 const SiS_LVDSDesStruct *SiS_PanelType09_1; 479 const struct SiS_CHTVRegData *SiS_CHTVReg_SOPAL;
511 const SiS_LVDSDesStruct *SiS_PanelType0a_1; 480
512 const SiS_LVDSDesStruct *SiS_PanelType0b_1; 481 const unsigned char *SiS_CHTVVCLKUNTSC;
513 const SiS_LVDSDesStruct *SiS_PanelType0c_1; 482 const unsigned char *SiS_CHTVVCLKONTSC;
514 const SiS_LVDSDesStruct *SiS_PanelType0d_1; 483 const unsigned char *SiS_CHTVVCLKUPAL;
515 const SiS_LVDSDesStruct *SiS_PanelType0e_1; 484 const unsigned char *SiS_CHTVVCLKOPAL;
516 const SiS_LVDSDesStruct *SiS_PanelType0f_1; 485 const unsigned char *SiS_CHTVVCLKUPALM;
517 const SiS_LVDSDesStruct *SiS_PanelTypeNS_1; 486 const unsigned char *SiS_CHTVVCLKOPALM;
518 const SiS_LVDSDesStruct *SiS_PanelType00_2; 487 const unsigned char *SiS_CHTVVCLKUPALN;
519 const SiS_LVDSDesStruct *SiS_PanelType01_2; 488 const unsigned char *SiS_CHTVVCLKOPALN;
520 const SiS_LVDSDesStruct *SiS_PanelType02_2; 489 const unsigned char *SiS_CHTVVCLKSOPAL;
521 const SiS_LVDSDesStruct *SiS_PanelType03_2; 490
522 const SiS_LVDSDesStruct *SiS_PanelType04_2; 491 unsigned short PanelXRes, PanelHT;
523 const SiS_LVDSDesStruct *SiS_PanelType05_2; 492 unsigned short PanelYRes, PanelVT;
524 const SiS_LVDSDesStruct *SiS_PanelType06_2; 493 unsigned short PanelHRS, PanelHRE;
525 const SiS_LVDSDesStruct *SiS_PanelType07_2; 494 unsigned short PanelVRS, PanelVRE;
526 const SiS_LVDSDesStruct *SiS_PanelType08_2; 495 unsigned short PanelVCLKIdx300;
527 const SiS_LVDSDesStruct *SiS_PanelType09_2; 496 unsigned short PanelVCLKIdx315;
528 const SiS_LVDSDesStruct *SiS_PanelType0a_2; 497 BOOLEAN Alternate1600x1200;
529 const SiS_LVDSDesStruct *SiS_PanelType0b_2; 498
530 const SiS_LVDSDesStruct *SiS_PanelType0c_2; 499 BOOLEAN UseCustomMode;
531 const SiS_LVDSDesStruct *SiS_PanelType0d_2; 500 BOOLEAN CRT1UsesCustomMode;
532 const SiS_LVDSDesStruct *SiS_PanelType0e_2; 501 unsigned short CHDisplay;
533 const SiS_LVDSDesStruct *SiS_PanelType0f_2; 502 unsigned short CHSyncStart;
534 const SiS_LVDSDesStruct *SiS_PanelTypeNS_2; 503 unsigned short CHSyncEnd;
535 const SiS_LVDSDesStruct *SiS_CHTVUNTSCDesData; 504 unsigned short CHTotal;
536 const SiS_LVDSDesStruct *SiS_CHTVONTSCDesData; 505 unsigned short CHBlankStart;
537 const SiS_LVDSDesStruct *SiS_CHTVUPALDesData; 506 unsigned short CHBlankEnd;
538 const SiS_LVDSDesStruct *SiS_CHTVOPALDesData; 507 unsigned short CVDisplay;
539 508 unsigned short CVSyncStart;
540 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT1800x600_1; 509 unsigned short CVSyncEnd;
541 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11024x768_1; 510 unsigned short CVTotal;
542 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11280x1024_1; 511 unsigned short CVBlankStart;
543 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11400x1050_1; 512 unsigned short CVBlankEnd;
544 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11280x768_1; 513 unsigned int CDClock;
545 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11024x600_1; 514 unsigned int CFlags;
546 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11152x768_1; 515 unsigned char CCRT1CRTC[17];
547 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11600x1200_1; 516 unsigned char CSR2B;
548 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT1800x600_1_H; 517 unsigned char CSR2C;
549 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11024x768_1_H; 518 unsigned short CSRClock;
550 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11280x1024_1_H; 519 unsigned short CSRClock_CRT1;
551 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11400x1050_1_H; 520 unsigned short CModeFlag;
552 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11280x768_1_H; 521 unsigned short CModeFlag_CRT1;
553 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11024x600_1_H; 522 unsigned short CInfoFlag;
554 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11152x768_1_H; 523
555 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11600x1200_1_H; 524 int LVDSHL;
556 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT1800x600_2; 525
557 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11024x768_2; 526 BOOLEAN Backup;
558 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11280x1024_2; 527 unsigned char Backup_Mode;
559 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11400x1050_2; 528 unsigned char Backup_14;
560 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11280x768_2; 529 unsigned char Backup_15;
561 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11024x600_2; 530 unsigned char Backup_16;
562 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11152x768_2; 531 unsigned char Backup_17;
563 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11600x1200_2; 532 unsigned char Backup_18;
564 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT1800x600_2_H; 533 unsigned char Backup_19;
565 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11024x768_2_H; 534 unsigned char Backup_1a;
566 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11280x1024_2_H; 535 unsigned char Backup_1b;
567 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11400x1050_2_H; 536 unsigned char Backup_1c;
568 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11280x768_2_H; 537 unsigned char Backup_1d;
569 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11024x600_2_H; 538
570 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11152x768_2_H; 539 unsigned char Init_P4_0E;
571 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT11600x1200_2_H; 540
572 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT1XXXxXXX_1; 541 int UsePanelScaler;
573 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT1XXXxXXX_1_H; 542 int CenterScreen;
574 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT1640x480_1; 543
575 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT1640x480_1_H; 544 unsigned short CP_Vendor, CP_Product;
576 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT1640x480_2; 545 BOOLEAN CP_HaveCustomData;
577 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT1640x480_2_H; 546 int CP_PreferredX, CP_PreferredY, CP_PreferredIndex;
578 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT1640x480_3; 547 int CP_MaxX, CP_MaxY, CP_MaxClock;
579 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT1640x480_3_H; 548 unsigned char CP_PrefSR2B, CP_PrefSR2C;
580 const SiS_LVDSCRT1DataStruct *SiS_LVDSCRT1320x480_1; 549 unsigned short CP_PrefClock;
581 const SiS_LVDSCRT1DataStruct *SiS_CHTVCRT1UNTSC; 550 BOOLEAN CP_Supports64048075;
582 const SiS_LVDSCRT1DataStruct *SiS_CHTVCRT1ONTSC; 551 int CP_HDisplay[7], CP_VDisplay[7]; /* For Custom LCD panel dimensions */
583 const SiS_LVDSCRT1DataStruct *SiS_CHTVCRT1UPAL; 552 int CP_HTotal[7], CP_VTotal[7];
584 const SiS_LVDSCRT1DataStruct *SiS_CHTVCRT1OPAL; 553 int CP_HSyncStart[7], CP_VSyncStart[7];
585 const SiS_LVDSCRT1DataStruct *SiS_CHTVCRT1SOPAL; 554 int CP_HSyncEnd[7], CP_VSyncEnd[7];
586 555 int CP_HBlankStart[7], CP_VBlankStart[7];
587 const SiS_CHTVRegDataStruct *SiS_CHTVReg_UNTSC; 556 int CP_HBlankEnd[7], CP_VBlankEnd[7];
588 const SiS_CHTVRegDataStruct *SiS_CHTVReg_ONTSC; 557 int CP_Clock[7];
589 const SiS_CHTVRegDataStruct *SiS_CHTVReg_UPAL; 558 BOOLEAN CP_DataValid[7];
590 const SiS_CHTVRegDataStruct *SiS_CHTVReg_OPAL; 559 BOOLEAN CP_HSync_P[7], CP_VSync_P[7], CP_SyncValid[7];
591 const SiS_CHTVRegDataStruct *SiS_CHTVReg_UPALM; 560};
592 const SiS_CHTVRegDataStruct *SiS_CHTVReg_OPALM;
593 const SiS_CHTVRegDataStruct *SiS_CHTVReg_UPALN;
594 const SiS_CHTVRegDataStruct *SiS_CHTVReg_OPALN;
595 const SiS_CHTVRegDataStruct *SiS_CHTVReg_SOPAL;
596
597 const UCHAR *SiS_CHTVVCLKUNTSC;
598 const UCHAR *SiS_CHTVVCLKONTSC;
599 const UCHAR *SiS_CHTVVCLKUPAL;
600 const UCHAR *SiS_CHTVVCLKOPAL;
601 const UCHAR *SiS_CHTVVCLKUPALM;
602 const UCHAR *SiS_CHTVVCLKOPALM;
603 const UCHAR *SiS_CHTVVCLKUPALN;
604 const UCHAR *SiS_CHTVVCLKOPALN;
605 const UCHAR *SiS_CHTVVCLKSOPAL;
606
607 USHORT PanelXRes, PanelHT;
608 USHORT PanelYRes, PanelVT;
609 USHORT PanelHRS, PanelHRE;
610 USHORT PanelVRS, PanelVRE;
611 USHORT PanelVCLKIdx300;
612 USHORT PanelVCLKIdx315;
613
614 BOOLEAN UseCustomMode;
615 BOOLEAN CRT1UsesCustomMode;
616 USHORT CHDisplay;
617 USHORT CHSyncStart;
618 USHORT CHSyncEnd;
619 USHORT CHTotal;
620 USHORT CHBlankStart;
621 USHORT CHBlankEnd;
622 USHORT CVDisplay;
623 USHORT CVSyncStart;
624 USHORT CVSyncEnd;
625 USHORT CVTotal;
626 USHORT CVBlankStart;
627 USHORT CVBlankEnd;
628 ULONG CDClock;
629 ULONG CFlags;
630 UCHAR CCRT1CRTC[17];
631 UCHAR CSR2B;
632 UCHAR CSR2C;
633 USHORT CSRClock;
634 USHORT CSRClock_CRT1;
635 USHORT CModeFlag;
636 USHORT CModeFlag_CRT1;
637 USHORT CInfoFlag;
638
639 int LVDSHL;
640
641 BOOLEAN Backup;
642 UCHAR Backup_Mode;
643 UCHAR Backup_14;
644 UCHAR Backup_15;
645 UCHAR Backup_16;
646 UCHAR Backup_17;
647 UCHAR Backup_18;
648 UCHAR Backup_19;
649 UCHAR Backup_1a;
650 UCHAR Backup_1b;
651 UCHAR Backup_1c;
652 UCHAR Backup_1d;
653
654 int UsePanelScaler;
655 int CenterScreen;
656
657 USHORT CP_Vendor, CP_Product;
658 BOOLEAN CP_HaveCustomData;
659 int CP_PreferredX, CP_PreferredY, CP_PreferredIndex;
660 int CP_MaxX, CP_MaxY, CP_MaxClock;
661 UCHAR CP_PrefSR2B, CP_PrefSR2C;
662 USHORT CP_PrefClock;
663 BOOLEAN CP_Supports64048075;
664 int CP_HDisplay[7], CP_VDisplay[7]; /* For Custom LCD panel dimensions */
665 int CP_HTotal[7], CP_VTotal[7];
666 int CP_HSyncStart[7], CP_VSyncStart[7];
667 int CP_HSyncEnd[7], CP_VSyncEnd[7];
668 int CP_HBlankStart[7], CP_VBlankStart[7];
669 int CP_HBlankEnd[7], CP_VBlankEnd[7];
670 int CP_Clock[7];
671 BOOLEAN CP_DataValid[7];
672 BOOLEAN CP_HSync_P[7], CP_VSync_P[7], CP_SyncValid[7];
673} SiS_Private;
674 561
675#endif 562#endif
676 563
diff --git a/drivers/video/tridentfb.c b/drivers/video/tridentfb.c
index 698ca9232e..81a6d9f188 100644
--- a/drivers/video/tridentfb.c
+++ b/drivers/video/tridentfb.c
@@ -1061,6 +1061,11 @@ static int __devinit trident_pci_probe(struct pci_dev * dev, const struct pci_de
1061 1061
1062 chip_id = id->device; 1062 chip_id = id->device;
1063 1063
1064 if(chip_id == CYBERBLADEi1)
1065 output("*** Please do use cyblafb, Cyberblade/i1 support "
1066 "will soon be removed from tridentfb!\n");
1067
1068
1064 /* If PCI id is 0x9660 then further detect chip type */ 1069 /* If PCI id is 0x9660 then further detect chip type */
1065 1070
1066 if (chip_id == TGUI9660) { 1071 if (chip_id == TGUI9660) {
diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
index a272592b03..1ca80264c7 100644
--- a/drivers/video/vesafb.c
+++ b/drivers/video/vesafb.c
@@ -19,6 +19,7 @@
19#include <linux/fb.h> 19#include <linux/fb.h>
20#include <linux/ioport.h> 20#include <linux/ioport.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <video/vga.h>
22#include <asm/io.h> 23#include <asm/io.h>
23#include <asm/mtrr.h> 24#include <asm/mtrr.h>
24 25
@@ -54,6 +55,7 @@ static unsigned short *pmi_base = NULL;
54static void (*pmi_start)(void); 55static void (*pmi_start)(void);
55static void (*pmi_pal)(void); 56static void (*pmi_pal)(void);
56static int depth; 57static int depth;
58static int vga_compat;
57 59
58/* --------------------------------------------------------------------- */ 60/* --------------------------------------------------------------------- */
59 61
@@ -86,6 +88,37 @@ static int vesafb_pan_display(struct fb_var_screeninfo *var,
86 return 0; 88 return 0;
87} 89}
88 90
91static int vesafb_blank(int blank, struct fb_info *info)
92{
93 int err = 1;
94
95 if (vga_compat) {
96 int loop = 10000;
97 u8 seq = 0, crtc17 = 0;
98
99 err = 0;
100
101 if (blank) {
102 seq = 0x20;
103 crtc17 = 0x00;
104 } else {
105 seq = 0x00;
106 crtc17 = 0x80;
107 }
108
109 vga_wseq(NULL, 0x00, 0x01);
110 seq |= vga_rseq(NULL, 0x01) & ~0x20;
111 vga_wseq(NULL, 0x00, seq);
112
113 crtc17 |= vga_rcrt(NULL, 0x17) & ~0x80;
114 while (loop--);
115 vga_wcrt(NULL, 0x17, crtc17);
116 vga_wseq(NULL, 0x00, 0x03);
117 }
118
119 return err;
120}
121
89static void vesa_setpalette(int regno, unsigned red, unsigned green, 122static void vesa_setpalette(int regno, unsigned red, unsigned green,
90 unsigned blue) 123 unsigned blue)
91{ 124{
@@ -176,6 +209,7 @@ static struct fb_ops vesafb_ops = {
176 .owner = THIS_MODULE, 209 .owner = THIS_MODULE,
177 .fb_setcolreg = vesafb_setcolreg, 210 .fb_setcolreg = vesafb_setcolreg,
178 .fb_pan_display = vesafb_pan_display, 211 .fb_pan_display = vesafb_pan_display,
212 .fb_blank = vesafb_blank,
179 .fb_fillrect = cfb_fillrect, 213 .fb_fillrect = cfb_fillrect,
180 .fb_copyarea = cfb_copyarea, 214 .fb_copyarea = cfb_copyarea,
181 .fb_imageblit = cfb_imageblit, 215 .fb_imageblit = cfb_imageblit,
@@ -429,6 +463,10 @@ static int __init vesafb_probe(struct device *device)
429 info->flags = FBINFO_FLAG_DEFAULT | 463 info->flags = FBINFO_FLAG_DEFAULT |
430 (ypan) ? FBINFO_HWACCEL_YPAN : 0; 464 (ypan) ? FBINFO_HWACCEL_YPAN : 0;
431 465
466 vga_compat = (screen_info.capabilities & 2) ? 0 : 1;
467 printk("vesafb: Mode is %sVGA compatible\n",
468 (vga_compat) ? "" : "not ");
469
432 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { 470 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
433 err = -ENOMEM; 471 err = -ENOMEM;
434 goto err; 472 goto err;
diff --git a/drivers/video/vgastate.c b/drivers/video/vgastate.c
index 0ea62d8bc7..ca92940f39 100644
--- a/drivers/video/vgastate.c
+++ b/drivers/video/vgastate.c
@@ -342,16 +342,11 @@ static void vga_cleanup(struct vgastate *state)
342 if (state->vidstate != NULL) { 342 if (state->vidstate != NULL) {
343 struct regstate *saved = (struct regstate *) state->vidstate; 343 struct regstate *saved = (struct regstate *) state->vidstate;
344 344
345 if (saved->vga_font0) 345 vfree(saved->vga_font0);
346 vfree(saved->vga_font0); 346 vfree(saved->vga_font1);
347 if (saved->vga_font1) 347 vfree(saved->vga_text);
348 vfree(saved->vga_font1); 348 vfree(saved->vga_cmap);
349 if (saved->vga_text) 349 vfree(saved->attr);
350 vfree(saved->vga_text);
351 if (saved->vga_cmap)
352 vfree(saved->vga_cmap);
353 if (saved->attr)
354 vfree(saved->attr);
355 kfree(saved); 350 kfree(saved);
356 state->vidstate = NULL; 351 state->vidstate = NULL;
357 } 352 }
diff --git a/fs/9p/9p.c b/fs/9p/9p.c
new file mode 100644
index 0000000000..e847f504a4
--- /dev/null
+++ b/fs/9p/9p.c
@@ -0,0 +1,359 @@
1/*
2 * linux/fs/9p/9p.c
3 *
4 * This file contains functions 9P2000 functions
5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to:
21 * Free Software Foundation
22 * 51 Franklin Street, Fifth Floor
23 * Boston, MA 02111-1301 USA
24 *
25 */
26
27#include <linux/config.h>
28#include <linux/module.h>
29#include <linux/errno.h>
30#include <linux/fs.h>
31#include <linux/idr.h>
32
33#include "debug.h"
34#include "v9fs.h"
35#include "9p.h"
36#include "mux.h"
37
38/**
39 * v9fs_t_version - negotiate protocol parameters with sever
40 * @v9ses: 9P2000 session information
41 * @msize: requested max size packet
42 * @version: requested version.extension string
43 * @fcall: pointer to response fcall pointer
44 *
45 */
46
47int
48v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize,
49 char *version, struct v9fs_fcall **fcall)
50{
51 struct v9fs_fcall msg;
52
53 dprintk(DEBUG_9P, "msize: %d version: %s\n", msize, version);
54 msg.id = TVERSION;
55 msg.params.tversion.msize = msize;
56 msg.params.tversion.version = version;
57
58 return v9fs_mux_rpc(v9ses, &msg, fcall);
59}
60
61/**
62 * v9fs_t_attach - mount the server
63 * @v9ses: 9P2000 session information
64 * @uname: user name doing the attach
65 * @aname: remote name being attached to
66 * @fid: mount fid to attatch to root node
67 * @afid: authentication fid (in this case result key)
68 * @fcall: pointer to response fcall pointer
69 *
70 */
71
72int
73v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
74 u32 fid, u32 afid, struct v9fs_fcall **fcall)
75{
76 struct v9fs_fcall msg;
77
78 dprintk(DEBUG_9P, "uname '%s' aname '%s' fid %d afid %d\n", uname,
79 aname, fid, afid);
80 msg.id = TATTACH;
81 msg.params.tattach.fid = fid;
82 msg.params.tattach.afid = afid;
83 msg.params.tattach.uname = uname;
84 msg.params.tattach.aname = aname;
85
86 return v9fs_mux_rpc(v9ses, &msg, fcall);
87}
88
89/**
90 * v9fs_t_clunk - release a fid (finish a transaction)
91 * @v9ses: 9P2000 session information
92 * @fid: fid to release
93 * @fcall: pointer to response fcall pointer
94 *
95 */
96
97int
98v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid,
99 struct v9fs_fcall **fcall)
100{
101 struct v9fs_fcall msg;
102
103 dprintk(DEBUG_9P, "fid %d\n", fid);
104 msg.id = TCLUNK;
105 msg.params.tclunk.fid = fid;
106
107 return v9fs_mux_rpc(v9ses, &msg, fcall);
108}
109
110/**
111 * v9fs_v9fs_t_flush - flush a pending transaction
112 * @v9ses: 9P2000 session information
113 * @tag: tid to release
114 *
115 */
116
117int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 tag)
118{
119 struct v9fs_fcall msg;
120
121 dprintk(DEBUG_9P, "oldtag %d\n", tag);
122 msg.id = TFLUSH;
123 msg.params.tflush.oldtag = tag;
124 return v9fs_mux_rpc(v9ses, &msg, NULL);
125}
126
127/**
128 * v9fs_t_stat - read a file's meta-data
129 * @v9ses: 9P2000 session information
130 * @fid: fid pointing to file or directory to get info about
131 * @fcall: pointer to response fcall
132 *
133 */
134
135int
136v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid, struct v9fs_fcall **fcall)
137{
138 struct v9fs_fcall msg;
139
140 dprintk(DEBUG_9P, "fid %d\n", fid);
141 if (fcall)
142 *fcall = NULL;
143
144 msg.id = TSTAT;
145 msg.params.tstat.fid = fid;
146 return v9fs_mux_rpc(v9ses, &msg, fcall);
147}
148
149/**
150 * v9fs_t_wstat - write a file's meta-data
151 * @v9ses: 9P2000 session information
152 * @fid: fid pointing to file or directory to write info about
153 * @stat: metadata
154 * @fcall: pointer to response fcall
155 *
156 */
157
158int
159v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid,
160 struct v9fs_stat *stat, struct v9fs_fcall **fcall)
161{
162 struct v9fs_fcall msg;
163
164 dprintk(DEBUG_9P, "fid %d length %d\n", fid, (int)stat->length);
165 msg.id = TWSTAT;
166 msg.params.twstat.fid = fid;
167 msg.params.twstat.stat = stat;
168
169 return v9fs_mux_rpc(v9ses, &msg, fcall);
170}
171
172/**
173 * v9fs_t_walk - walk a fid to a new file or directory
174 * @v9ses: 9P2000 session information
175 * @fid: fid to walk
176 * @newfid: new fid (for clone operations)
177 * @name: path to walk fid to
178 * @fcall: pointer to response fcall
179 *
180 */
181
182/* TODO: support multiple walk */
183
184int
185v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid,
186 char *name, struct v9fs_fcall **fcall)
187{
188 struct v9fs_fcall msg;
189
190 dprintk(DEBUG_9P, "fid %d newfid %d wname '%s'\n", fid, newfid, name);
191 msg.id = TWALK;
192 msg.params.twalk.fid = fid;
193 msg.params.twalk.newfid = newfid;
194
195 if (name) {
196 msg.params.twalk.nwname = 1;
197 msg.params.twalk.wnames = &name;
198 } else {
199 msg.params.twalk.nwname = 0;
200 }
201
202 return v9fs_mux_rpc(v9ses, &msg, fcall);
203}
204
205/**
206 * v9fs_t_open - open a file
207 *
208 * @v9ses - 9P2000 session information
209 * @fid - fid to open
210 * @mode - mode to open file (R, RW, etc)
211 * @fcall - pointer to response fcall
212 *
213 */
214
215int
216v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode,
217 struct v9fs_fcall **fcall)
218{
219 struct v9fs_fcall msg;
220 long errorno = -1;
221
222 dprintk(DEBUG_9P, "fid %d mode %d\n", fid, mode);
223 msg.id = TOPEN;
224 msg.params.topen.fid = fid;
225 msg.params.topen.mode = mode;
226
227 errorno = v9fs_mux_rpc(v9ses, &msg, fcall);
228
229 return errorno;
230}
231
232/**
233 * v9fs_t_remove - remove a file or directory
234 * @v9ses: 9P2000 session information
235 * @fid: fid to remove
236 * @fcall: pointer to response fcall
237 *
238 */
239
240int
241v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid,
242 struct v9fs_fcall **fcall)
243{
244 struct v9fs_fcall msg;
245
246 dprintk(DEBUG_9P, "fid %d\n", fid);
247 msg.id = TREMOVE;
248 msg.params.tremove.fid = fid;
249 return v9fs_mux_rpc(v9ses, &msg, fcall);
250}
251
252/**
253 * v9fs_t_create - create a file or directory
254 * @v9ses: 9P2000 session information
255 * @fid: fid to create
256 * @name: name of the file or directory to create
257 * @perm: permissions to create with
258 * @mode: mode to open file (R, RW, etc)
259 * @fcall: pointer to response fcall
260 *
261 */
262
263int
264v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name,
265 u32 perm, u8 mode, struct v9fs_fcall **fcall)
266{
267 struct v9fs_fcall msg;
268
269 dprintk(DEBUG_9P, "fid %d name '%s' perm %x mode %d\n",
270 fid, name, perm, mode);
271
272 msg.id = TCREATE;
273 msg.params.tcreate.fid = fid;
274 msg.params.tcreate.name = name;
275 msg.params.tcreate.perm = perm;
276 msg.params.tcreate.mode = mode;
277
278 return v9fs_mux_rpc(v9ses, &msg, fcall);
279}
280
281/**
282 * v9fs_t_read - read data
283 * @v9ses: 9P2000 session information
284 * @fid: fid to read from
285 * @offset: offset to start read at
286 * @count: how many bytes to read
287 * @fcall: pointer to response fcall (with data)
288 *
289 */
290
291int
292v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid, u64 offset,
293 u32 count, struct v9fs_fcall **fcall)
294{
295 struct v9fs_fcall msg;
296 struct v9fs_fcall *rc = NULL;
297 long errorno = -1;
298
299 dprintk(DEBUG_9P, "fid %d offset 0x%lx count 0x%x\n", fid,
300 (long unsigned int)offset, count);
301 msg.id = TREAD;
302 msg.params.tread.fid = fid;
303 msg.params.tread.offset = offset;
304 msg.params.tread.count = count;
305 errorno = v9fs_mux_rpc(v9ses, &msg, &rc);
306
307 if (!errorno) {
308 errorno = rc->params.rread.count;
309 dump_data(rc->params.rread.data, rc->params.rread.count);
310 }
311
312 if (fcall)
313 *fcall = rc;
314 else
315 kfree(rc);
316
317 return errorno;
318}
319
320/**
321 * v9fs_t_write - write data
322 * @v9ses: 9P2000 session information
323 * @fid: fid to write to
324 * @offset: offset to start write at
325 * @count: how many bytes to write
326 * @fcall: pointer to response fcall
327 *
328 */
329
330int
331v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid,
332 u64 offset, u32 count, void *data, struct v9fs_fcall **fcall)
333{
334 struct v9fs_fcall msg;
335 struct v9fs_fcall *rc = NULL;
336 long errorno = -1;
337
338 dprintk(DEBUG_9P, "fid %d offset 0x%llx count 0x%x\n", fid,
339 (unsigned long long)offset, count);
340 dump_data(data, count);
341
342 msg.id = TWRITE;
343 msg.params.twrite.fid = fid;
344 msg.params.twrite.offset = offset;
345 msg.params.twrite.count = count;
346 msg.params.twrite.data = data;
347
348 errorno = v9fs_mux_rpc(v9ses, &msg, &rc);
349
350 if (!errorno)
351 errorno = rc->params.rwrite.count;
352
353 if (fcall)
354 *fcall = rc;
355 else
356 kfree(rc);
357
358 return errorno;
359}
diff --git a/fs/9p/9p.h b/fs/9p/9p.h
new file mode 100644
index 0000000000..f55424216b
--- /dev/null
+++ b/fs/9p/9p.h
@@ -0,0 +1,341 @@
1/*
2 * linux/fs/9p/9p.h
3 *
4 * 9P protocol definitions.
5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to:
21 * Free Software Foundation
22 * 51 Franklin Street, Fifth Floor
23 * Boston, MA 02111-1301 USA
24 *
25 */
26
27/* Message Types */
28enum {
29 TVERSION = 100,
30 RVERSION,
31 TAUTH = 102,
32 RAUTH,
33 TATTACH = 104,
34 RATTACH,
35 TERROR = 106,
36 RERROR,
37 TFLUSH = 108,
38 RFLUSH,
39 TWALK = 110,
40 RWALK,
41 TOPEN = 112,
42 ROPEN,
43 TCREATE = 114,
44 RCREATE,
45 TREAD = 116,
46 RREAD,
47 TWRITE = 118,
48 RWRITE,
49 TCLUNK = 120,
50 RCLUNK,
51 TREMOVE = 122,
52 RREMOVE,
53 TSTAT = 124,
54 RSTAT,
55 TWSTAT = 126,
56 RWSTAT,
57};
58
59/* modes */
60enum {
61 V9FS_OREAD = 0x00,
62 V9FS_OWRITE = 0x01,
63 V9FS_ORDWR = 0x02,
64 V9FS_OEXEC = 0x03,
65 V9FS_OEXCL = 0x04,
66 V9FS_OTRUNC = 0x10,
67 V9FS_OREXEC = 0x20,
68 V9FS_ORCLOSE = 0x40,
69 V9FS_OAPPEND = 0x80,
70};
71
72/* permissions */
73enum {
74 V9FS_DMDIR = 0x80000000,
75 V9FS_DMAPPEND = 0x40000000,
76 V9FS_DMEXCL = 0x20000000,
77 V9FS_DMMOUNT = 0x10000000,
78 V9FS_DMAUTH = 0x08000000,
79 V9FS_DMTMP = 0x04000000,
80 V9FS_DMSYMLINK = 0x02000000,
81 V9FS_DMLINK = 0x01000000,
82 /* 9P2000.u extensions */
83 V9FS_DMDEVICE = 0x00800000,
84 V9FS_DMNAMEDPIPE = 0x00200000,
85 V9FS_DMSOCKET = 0x00100000,
86 V9FS_DMSETUID = 0x00080000,
87 V9FS_DMSETGID = 0x00040000,
88};
89
90/* qid.types */
91enum {
92 V9FS_QTDIR = 0x80,
93 V9FS_QTAPPEND = 0x40,
94 V9FS_QTEXCL = 0x20,
95 V9FS_QTMOUNT = 0x10,
96 V9FS_QTAUTH = 0x08,
97 V9FS_QTTMP = 0x04,
98 V9FS_QTSYMLINK = 0x02,
99 V9FS_QTLINK = 0x01,
100 V9FS_QTFILE = 0x00,
101};
102
103/* ample room for Twrite/Rread header (iounit) */
104#define V9FS_IOHDRSZ 24
105
106/* qids are the unique ID for a file (like an inode */
107struct v9fs_qid {
108 u8 type;
109 u32 version;
110 u64 path;
111};
112
113/* Plan 9 file metadata (stat) structure */
114struct v9fs_stat {
115 u16 size;
116 u16 type;
117 u32 dev;
118 struct v9fs_qid qid;
119 u32 mode;
120 u32 atime;
121 u32 mtime;
122 u64 length;
123 char *name;
124 char *uid;
125 char *gid;
126 char *muid;
127 char *extension; /* 9p2000.u extensions */
128 u32 n_uid; /* 9p2000.u extensions */
129 u32 n_gid; /* 9p2000.u extensions */
130 u32 n_muid; /* 9p2000.u extensions */
131 char data[0];
132};
133
134/* Structures for Protocol Operations */
135
136struct Tversion {
137 u32 msize;
138 char *version;
139};
140
141struct Rversion {
142 u32 msize;
143 char *version;
144};
145
146struct Tauth {
147 u32 afid;
148 char *uname;
149 char *aname;
150};
151
152struct Rauth {
153 struct v9fs_qid qid;
154};
155
156struct Rerror {
157 char *error;
158 u32 errno; /* 9p2000.u extension */
159};
160
161struct Tflush {
162 u32 oldtag;
163};
164
165struct Rflush {
166};
167
168struct Tattach {
169 u32 fid;
170 u32 afid;
171 char *uname;
172 char *aname;
173};
174
175struct Rattach {
176 struct v9fs_qid qid;
177};
178
179struct Twalk {
180 u32 fid;
181 u32 newfid;
182 u32 nwname;
183 char **wnames;
184};
185
186struct Rwalk {
187 u32 nwqid;
188 struct v9fs_qid *wqids;
189};
190
191struct Topen {
192 u32 fid;
193 u8 mode;
194};
195
196struct Ropen {
197 struct v9fs_qid qid;
198 u32 iounit;
199};
200
201struct Tcreate {
202 u32 fid;
203 char *name;
204 u32 perm;
205 u8 mode;
206};
207
208struct Rcreate {
209 struct v9fs_qid qid;
210 u32 iounit;
211};
212
213struct Tread {
214 u32 fid;
215 u64 offset;
216 u32 count;
217};
218
219struct Rread {
220 u32 count;
221 u8 *data;
222};
223
224struct Twrite {
225 u32 fid;
226 u64 offset;
227 u32 count;
228 u8 *data;
229};
230
231struct Rwrite {
232 u32 count;
233};
234
235struct Tclunk {
236 u32 fid;
237};
238
239struct Rclunk {
240};
241
242struct Tremove {
243 u32 fid;
244};
245
246struct Rremove {
247};
248
249struct Tstat {
250 u32 fid;
251};
252
253struct Rstat {
254 struct v9fs_stat *stat;
255};
256
257struct Twstat {
258 u32 fid;
259 struct v9fs_stat *stat;
260};
261
262struct Rwstat {
263};
264
265/*
266 * fcall is the primary packet structure
267 *
268 */
269
270struct v9fs_fcall {
271 u32 size;
272 u8 id;
273 u16 tag;
274
275 union {
276 struct Tversion tversion;
277 struct Rversion rversion;
278 struct Tauth tauth;
279 struct Rauth rauth;
280 struct Rerror rerror;
281 struct Tflush tflush;
282 struct Rflush rflush;
283 struct Tattach tattach;
284 struct Rattach rattach;
285 struct Twalk twalk;
286 struct Rwalk rwalk;
287 struct Topen topen;
288 struct Ropen ropen;
289 struct Tcreate tcreate;
290 struct Rcreate rcreate;
291 struct Tread tread;
292 struct Rread rread;
293 struct Twrite twrite;
294 struct Rwrite rwrite;
295 struct Tclunk tclunk;
296 struct Rclunk rclunk;
297 struct Tremove tremove;
298 struct Rremove rremove;
299 struct Tstat tstat;
300 struct Rstat rstat;
301 struct Twstat twstat;
302 struct Rwstat rwstat;
303 } params;
304};
305
306#define FCALL_ERROR(fcall) (fcall ? fcall->params.rerror.error : "")
307
308int v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize,
309 char *version, struct v9fs_fcall **rcall);
310
311int v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
312 u32 fid, u32 afid, struct v9fs_fcall **rcall);
313
314int v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid,
315 struct v9fs_fcall **rcall);
316
317int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 oldtag);
318
319int v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid,
320 struct v9fs_fcall **rcall);
321
322int v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid,
323 struct v9fs_stat *stat, struct v9fs_fcall **rcall);
324
325int v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid,
326 char *name, struct v9fs_fcall **rcall);
327
328int v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode,
329 struct v9fs_fcall **rcall);
330
331int v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid,
332 struct v9fs_fcall **rcall);
333
334int v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name,
335 u32 perm, u8 mode, struct v9fs_fcall **rcall);
336
337int v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid,
338 u64 offset, u32 count, struct v9fs_fcall **rcall);
339
340int v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset,
341 u32 count, void *data, struct v9fs_fcall **rcall);
diff --git a/fs/9p/Makefile b/fs/9p/Makefile
new file mode 100644
index 0000000000..e4e4ffe5a7
--- /dev/null
+++ b/fs/9p/Makefile
@@ -0,0 +1,17 @@
1obj-$(CONFIG_9P_FS) := 9p2000.o
2
39p2000-objs := \
4 vfs_super.o \
5 vfs_inode.o \
6 vfs_file.o \
7 vfs_dir.o \
8 vfs_dentry.o \
9 error.o \
10 mux.o \
11 trans_fd.o \
12 trans_sock.o \
13 9p.o \
14 conv.o \
15 v9fs.o \
16 fid.o
17
diff --git a/fs/9p/conv.c b/fs/9p/conv.c
new file mode 100644
index 0000000000..1554731bd6
--- /dev/null
+++ b/fs/9p/conv.c
@@ -0,0 +1,693 @@
1/*
2 * linux/fs/9p/conv.c
3 *
4 * 9P protocol conversion functions
5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to:
21 * Free Software Foundation
22 * 51 Franklin Street, Fifth Floor
23 * Boston, MA 02111-1301 USA
24 *
25 */
26
27#include <linux/config.h>
28#include <linux/module.h>
29#include <linux/errno.h>
30#include <linux/fs.h>
31#include <linux/idr.h>
32
33#include "debug.h"
34#include "v9fs.h"
35#include "9p.h"
36#include "conv.h"
37
38/*
39 * Buffer to help with string parsing
40 */
41struct cbuf {
42 unsigned char *sp;
43 unsigned char *p;
44 unsigned char *ep;
45};
46
47static inline void buf_init(struct cbuf *buf, void *data, int datalen)
48{
49 buf->sp = buf->p = data;
50 buf->ep = data + datalen;
51}
52
53static inline int buf_check_overflow(struct cbuf *buf)
54{
55 return buf->p > buf->ep;
56}
57
58static inline void buf_check_size(struct cbuf *buf, int len)
59{
60 if (buf->p+len > buf->ep) {
61 if (buf->p < buf->ep) {
62 eprintk(KERN_ERR, "buffer overflow\n");
63 buf->p = buf->ep + 1;
64 }
65 }
66}
67
68static inline void *buf_alloc(struct cbuf *buf, int len)
69{
70 void *ret = NULL;
71
72 buf_check_size(buf, len);
73 ret = buf->p;
74 buf->p += len;
75
76 return ret;
77}
78
79static inline void buf_put_int8(struct cbuf *buf, u8 val)
80{
81 buf_check_size(buf, 1);
82
83 buf->p[0] = val;
84 buf->p++;
85}
86
87static inline void buf_put_int16(struct cbuf *buf, u16 val)
88{
89 buf_check_size(buf, 2);
90
91 *(__le16 *) buf->p = cpu_to_le16(val);
92 buf->p += 2;
93}
94
95static inline void buf_put_int32(struct cbuf *buf, u32 val)
96{
97 buf_check_size(buf, 4);
98
99 *(__le32 *)buf->p = cpu_to_le32(val);
100 buf->p += 4;
101}
102
103static inline void buf_put_int64(struct cbuf *buf, u64 val)
104{
105 buf_check_size(buf, 8);
106
107 *(__le64 *)buf->p = cpu_to_le64(val);
108 buf->p += 8;
109}
110
111static inline void buf_put_stringn(struct cbuf *buf, const char *s, u16 slen)
112{
113 buf_check_size(buf, slen + 2);
114
115 buf_put_int16(buf, slen);
116 memcpy(buf->p, s, slen);
117 buf->p += slen;
118}
119
120static inline void buf_put_string(struct cbuf *buf, const char *s)
121{
122 buf_put_stringn(buf, s, strlen(s));
123}
124
125static inline void buf_put_data(struct cbuf *buf, void *data, u32 datalen)
126{
127 buf_check_size(buf, datalen);
128
129 memcpy(buf->p, data, datalen);
130 buf->p += datalen;
131}
132
133static inline u8 buf_get_int8(struct cbuf *buf)
134{
135 u8 ret = 0;
136
137 buf_check_size(buf, 1);
138 ret = buf->p[0];
139
140 buf->p++;
141
142 return ret;
143}
144
145static inline u16 buf_get_int16(struct cbuf *buf)
146{
147 u16 ret = 0;
148
149 buf_check_size(buf, 2);
150 ret = le16_to_cpu(*(__le16 *)buf->p);
151
152 buf->p += 2;
153
154 return ret;
155}
156
157static inline u32 buf_get_int32(struct cbuf *buf)
158{
159 u32 ret = 0;
160
161 buf_check_size(buf, 4);
162 ret = le32_to_cpu(*(__le32 *)buf->p);
163
164 buf->p += 4;
165
166 return ret;
167}
168
169static inline u64 buf_get_int64(struct cbuf *buf)
170{
171 u64 ret = 0;
172
173 buf_check_size(buf, 8);
174 ret = le64_to_cpu(*(__le64 *)buf->p);
175
176 buf->p += 8;
177
178 return ret;
179}
180
181static inline int
182buf_get_string(struct cbuf *buf, char *data, unsigned int datalen)
183{
184
185 u16 len = buf_get_int16(buf);
186 buf_check_size(buf, len);
187 if (len + 1 > datalen)
188 return 0;
189
190 memcpy(data, buf->p, len);
191 data[len] = 0;
192 buf->p += len;
193
194 return len + 1;
195}
196
197static inline char *buf_get_stringb(struct cbuf *buf, struct cbuf *sbuf)
198{
199 char *ret = NULL;
200 int n = buf_get_string(buf, sbuf->p, sbuf->ep - sbuf->p);
201
202 if (n > 0) {
203 ret = sbuf->p;
204 sbuf->p += n;
205 }
206
207 return ret;
208}
209
210static inline int buf_get_data(struct cbuf *buf, void *data, int datalen)
211{
212 buf_check_size(buf, datalen);
213
214 memcpy(data, buf->p, datalen);
215 buf->p += datalen;
216
217 return datalen;
218}
219
220static inline void *buf_get_datab(struct cbuf *buf, struct cbuf *dbuf,
221 int datalen)
222{
223 char *ret = NULL;
224 int n = 0;
225
226 buf_check_size(dbuf, datalen);
227
228 n = buf_get_data(buf, dbuf->p, datalen);
229
230 if (n > 0) {
231 ret = dbuf->p;
232 dbuf->p += n;
233 }
234
235 return ret;
236}
237
238/**
239 * v9fs_size_stat - calculate the size of a variable length stat struct
240 * @v9ses: session information
241 * @stat: metadata (stat) structure
242 *
243 */
244
245static int v9fs_size_stat(struct v9fs_session_info *v9ses,
246 struct v9fs_stat *stat)
247{
248 int size = 0;
249
250 if (stat == NULL) {
251 eprintk(KERN_ERR, "v9fs_size_stat: got a NULL stat pointer\n");
252 return 0;
253 }
254
255 size = /* 2 + *//* size[2] */
256 2 + /* type[2] */
257 4 + /* dev[4] */
258 1 + /* qid.type[1] */
259 4 + /* qid.vers[4] */
260 8 + /* qid.path[8] */
261 4 + /* mode[4] */
262 4 + /* atime[4] */
263 4 + /* mtime[4] */
264 8 + /* length[8] */
265 8; /* minimum sum of string lengths */
266
267 if (stat->name)
268 size += strlen(stat->name);
269 if (stat->uid)
270 size += strlen(stat->uid);
271 if (stat->gid)
272 size += strlen(stat->gid);
273 if (stat->muid)
274 size += strlen(stat->muid);
275
276 if (v9ses->extended) {
277 size += 4 + /* n_uid[4] */
278 4 + /* n_gid[4] */
279 4 + /* n_muid[4] */
280 2; /* string length of extension[4] */
281 if (stat->extension)
282 size += strlen(stat->extension);
283 }
284
285 return size;
286}
287
288/**
289 * serialize_stat - safely format a stat structure for transmission
290 * @v9ses: session info
291 * @stat: metadata (stat) structure
292 * @bufp: buffer to serialize structure into
293 *
294 */
295
296static int
297serialize_stat(struct v9fs_session_info *v9ses, struct v9fs_stat *stat,
298 struct cbuf *bufp)
299{
300 buf_put_int16(bufp, stat->size);
301 buf_put_int16(bufp, stat->type);
302 buf_put_int32(bufp, stat->dev);
303 buf_put_int8(bufp, stat->qid.type);
304 buf_put_int32(bufp, stat->qid.version);
305 buf_put_int64(bufp, stat->qid.path);
306 buf_put_int32(bufp, stat->mode);
307 buf_put_int32(bufp, stat->atime);
308 buf_put_int32(bufp, stat->mtime);
309 buf_put_int64(bufp, stat->length);
310
311 buf_put_string(bufp, stat->name);
312 buf_put_string(bufp, stat->uid);
313 buf_put_string(bufp, stat->gid);
314 buf_put_string(bufp, stat->muid);
315
316 if (v9ses->extended) {
317 buf_put_string(bufp, stat->extension);
318 buf_put_int32(bufp, stat->n_uid);
319 buf_put_int32(bufp, stat->n_gid);
320 buf_put_int32(bufp, stat->n_muid);
321 }
322
323 if (buf_check_overflow(bufp))
324 return 0;
325
326 return stat->size;
327}
328
329/**
330 * deserialize_stat - safely decode a recieved metadata (stat) structure
331 * @v9ses: session info
332 * @bufp: buffer to deserialize
333 * @stat: metadata (stat) structure
334 * @dbufp: buffer to deserialize variable strings into
335 *
336 */
337
338static inline int
339deserialize_stat(struct v9fs_session_info *v9ses, struct cbuf *bufp,
340 struct v9fs_stat *stat, struct cbuf *dbufp)
341{
342
343 stat->size = buf_get_int16(bufp);
344 stat->type = buf_get_int16(bufp);
345 stat->dev = buf_get_int32(bufp);
346 stat->qid.type = buf_get_int8(bufp);
347 stat->qid.version = buf_get_int32(bufp);
348 stat->qid.path = buf_get_int64(bufp);
349 stat->mode = buf_get_int32(bufp);
350 stat->atime = buf_get_int32(bufp);
351 stat->mtime = buf_get_int32(bufp);
352 stat->length = buf_get_int64(bufp);
353 stat->name = buf_get_stringb(bufp, dbufp);
354 stat->uid = buf_get_stringb(bufp, dbufp);
355 stat->gid = buf_get_stringb(bufp, dbufp);
356 stat->muid = buf_get_stringb(bufp, dbufp);
357
358 if (v9ses->extended) {
359 stat->extension = buf_get_stringb(bufp, dbufp);
360 stat->n_uid = buf_get_int32(bufp);
361 stat->n_gid = buf_get_int32(bufp);
362 stat->n_muid = buf_get_int32(bufp);
363 }
364
365 if (buf_check_overflow(bufp) || buf_check_overflow(dbufp))
366 return 0;
367
368 return stat->size + 2;
369}
370
371/**
372 * deserialize_statb - wrapper for decoding a received metadata structure
373 * @v9ses: session info
374 * @bufp: buffer to deserialize
375 * @dbufp: buffer to deserialize variable strings into
376 *
377 */
378
379static inline struct v9fs_stat *deserialize_statb(struct v9fs_session_info
380 *v9ses, struct cbuf *bufp,
381 struct cbuf *dbufp)
382{
383 struct v9fs_stat *ret = buf_alloc(dbufp, sizeof(struct v9fs_stat));
384
385 if (ret) {
386 int n = deserialize_stat(v9ses, bufp, ret, dbufp);
387 if (n <= 0)
388 return NULL;
389 }
390
391 return ret;
392}
393
394/**
395 * v9fs_deserialize_stat - decode a received metadata structure
396 * @v9ses: session info
397 * @buf: buffer to deserialize
398 * @buflen: length of received buffer
399 * @stat: metadata structure to decode into
400 * @statlen: length of destination metadata structure
401 *
402 */
403
404int
405v9fs_deserialize_stat(struct v9fs_session_info *v9ses, void *buf,
406 u32 buflen, struct v9fs_stat *stat, u32 statlen)
407{
408 struct cbuf buffer;
409 struct cbuf *bufp = &buffer;
410 struct cbuf dbuffer;
411 struct cbuf *dbufp = &dbuffer;
412
413 buf_init(bufp, buf, buflen);
414 buf_init(dbufp, (char *)stat + sizeof(struct v9fs_stat),
415 statlen - sizeof(struct v9fs_stat));
416
417 return deserialize_stat(v9ses, bufp, stat, dbufp);
418}
419
420static inline int
421v9fs_size_fcall(struct v9fs_session_info *v9ses, struct v9fs_fcall *fcall)
422{
423 int size = 4 + 1 + 2; /* size[4] msg[1] tag[2] */
424 int i = 0;
425
426 switch (fcall->id) {
427 default:
428 eprintk(KERN_ERR, "bad msg type %d\n", fcall->id);
429 return 0;
430 case TVERSION: /* msize[4] version[s] */
431 size += 4 + 2 + strlen(fcall->params.tversion.version);
432 break;
433 case TAUTH: /* afid[4] uname[s] aname[s] */
434 size += 4 + 2 + strlen(fcall->params.tauth.uname) +
435 2 + strlen(fcall->params.tauth.aname);
436 break;
437 case TFLUSH: /* oldtag[2] */
438 size += 2;
439 break;
440 case TATTACH: /* fid[4] afid[4] uname[s] aname[s] */
441 size += 4 + 4 + 2 + strlen(fcall->params.tattach.uname) +
442 2 + strlen(fcall->params.tattach.aname);
443 break;
444 case TWALK: /* fid[4] newfid[4] nwname[2] nwname*(wname[s]) */
445 size += 4 + 4 + 2;
446 /* now compute total for the array of names */
447 for (i = 0; i < fcall->params.twalk.nwname; i++)
448 size += 2 + strlen(fcall->params.twalk.wnames[i]);
449 break;
450 case TOPEN: /* fid[4] mode[1] */
451 size += 4 + 1;
452 break;
453 case TCREATE: /* fid[4] name[s] perm[4] mode[1] */
454 size += 4 + 2 + strlen(fcall->params.tcreate.name) + 4 + 1;
455 break;
456 case TREAD: /* fid[4] offset[8] count[4] */
457 size += 4 + 8 + 4;
458 break;
459 case TWRITE: /* fid[4] offset[8] count[4] data[count] */
460 size += 4 + 8 + 4 + fcall->params.twrite.count;
461 break;
462 case TCLUNK: /* fid[4] */
463 size += 4;
464 break;
465 case TREMOVE: /* fid[4] */
466 size += 4;
467 break;
468 case TSTAT: /* fid[4] */
469 size += 4;
470 break;
471 case TWSTAT: /* fid[4] stat[n] */
472 fcall->params.twstat.stat->size =
473 v9fs_size_stat(v9ses, fcall->params.twstat.stat);
474 size += 4 + 2 + 2 + fcall->params.twstat.stat->size;
475 }
476 return size;
477}
478
479/*
480 * v9fs_serialize_fcall - marshall fcall struct into a packet
481 * @v9ses: session information
482 * @fcall: structure to convert
483 * @data: buffer to serialize fcall into
484 * @datalen: length of buffer to serialize fcall into
485 *
486 */
487
488int
489v9fs_serialize_fcall(struct v9fs_session_info *v9ses, struct v9fs_fcall *fcall,
490 void *data, u32 datalen)
491{
492 int i = 0;
493 struct v9fs_stat *stat = NULL;
494 struct cbuf buffer;
495 struct cbuf *bufp = &buffer;
496
497 buf_init(bufp, data, datalen);
498
499 if (!fcall) {
500 eprintk(KERN_ERR, "no fcall\n");
501 return -EINVAL;
502 }
503
504 fcall->size = v9fs_size_fcall(v9ses, fcall);
505
506 buf_put_int32(bufp, fcall->size);
507 buf_put_int8(bufp, fcall->id);
508 buf_put_int16(bufp, fcall->tag);
509
510 dprintk(DEBUG_CONV, "size %d id %d tag %d\n", fcall->size, fcall->id,
511 fcall->tag);
512
513 /* now encode it */
514 switch (fcall->id) {
515 default:
516 eprintk(KERN_ERR, "bad msg type: %d\n", fcall->id);
517 return -EPROTO;
518 case TVERSION:
519 buf_put_int32(bufp, fcall->params.tversion.msize);
520 buf_put_string(bufp, fcall->params.tversion.version);
521 break;
522 case TAUTH:
523 buf_put_int32(bufp, fcall->params.tauth.afid);
524 buf_put_string(bufp, fcall->params.tauth.uname);
525 buf_put_string(bufp, fcall->params.tauth.aname);
526 break;
527 case TFLUSH:
528 buf_put_int16(bufp, fcall->params.tflush.oldtag);
529 break;
530 case TATTACH:
531 buf_put_int32(bufp, fcall->params.tattach.fid);
532 buf_put_int32(bufp, fcall->params.tattach.afid);
533 buf_put_string(bufp, fcall->params.tattach.uname);
534 buf_put_string(bufp, fcall->params.tattach.aname);
535 break;
536 case TWALK:
537 buf_put_int32(bufp, fcall->params.twalk.fid);
538 buf_put_int32(bufp, fcall->params.twalk.newfid);
539 buf_put_int16(bufp, fcall->params.twalk.nwname);
540 for (i = 0; i < fcall->params.twalk.nwname; i++)
541 buf_put_string(bufp, fcall->params.twalk.wnames[i]);
542 break;
543 case TOPEN:
544 buf_put_int32(bufp, fcall->params.topen.fid);
545 buf_put_int8(bufp, fcall->params.topen.mode);
546 break;
547 case TCREATE:
548 buf_put_int32(bufp, fcall->params.tcreate.fid);
549 buf_put_string(bufp, fcall->params.tcreate.name);
550 buf_put_int32(bufp, fcall->params.tcreate.perm);
551 buf_put_int8(bufp, fcall->params.tcreate.mode);
552 break;
553 case TREAD:
554 buf_put_int32(bufp, fcall->params.tread.fid);
555 buf_put_int64(bufp, fcall->params.tread.offset);
556 buf_put_int32(bufp, fcall->params.tread.count);
557 break;
558 case TWRITE:
559 buf_put_int32(bufp, fcall->params.twrite.fid);
560 buf_put_int64(bufp, fcall->params.twrite.offset);
561 buf_put_int32(bufp, fcall->params.twrite.count);
562 buf_put_data(bufp, fcall->params.twrite.data,
563 fcall->params.twrite.count);
564 break;
565 case TCLUNK:
566 buf_put_int32(bufp, fcall->params.tclunk.fid);
567 break;
568 case TREMOVE:
569 buf_put_int32(bufp, fcall->params.tremove.fid);
570 break;
571 case TSTAT:
572 buf_put_int32(bufp, fcall->params.tstat.fid);
573 break;
574 case TWSTAT:
575 buf_put_int32(bufp, fcall->params.twstat.fid);
576 stat = fcall->params.twstat.stat;
577
578 buf_put_int16(bufp, stat->size + 2);
579 serialize_stat(v9ses, stat, bufp);
580 break;
581 }
582
583 if (buf_check_overflow(bufp))
584 return -EIO;
585
586 return fcall->size;
587}
588
589/**
590 * deserialize_fcall - unmarshal a response
591 * @v9ses: session information
592 * @msgsize: size of rcall message
593 * @buf: recieved buffer
594 * @buflen: length of received buffer
595 * @rcall: fcall structure to populate
596 * @rcalllen: length of fcall structure to populate
597 *
598 */
599
600int
601v9fs_deserialize_fcall(struct v9fs_session_info *v9ses, u32 msgsize,
602 void *buf, u32 buflen, struct v9fs_fcall *rcall,
603 int rcalllen)
604{
605
606 struct cbuf buffer;
607 struct cbuf *bufp = &buffer;
608 struct cbuf dbuffer;
609 struct cbuf *dbufp = &dbuffer;
610 int i = 0;
611
612 buf_init(bufp, buf, buflen);
613 buf_init(dbufp, (char *)rcall + sizeof(struct v9fs_fcall),
614 rcalllen - sizeof(struct v9fs_fcall));
615
616 rcall->size = msgsize;
617 rcall->id = buf_get_int8(bufp);
618 rcall->tag = buf_get_int16(bufp);
619
620 dprintk(DEBUG_CONV, "size %d id %d tag %d\n", rcall->size, rcall->id,
621 rcall->tag);
622 switch (rcall->id) {
623 default:
624 eprintk(KERN_ERR, "unknown message type: %d\n", rcall->id);
625 return -EPROTO;
626 case RVERSION:
627 rcall->params.rversion.msize = buf_get_int32(bufp);
628 rcall->params.rversion.version = buf_get_stringb(bufp, dbufp);
629 break;
630 case RFLUSH:
631 break;
632 case RATTACH:
633 rcall->params.rattach.qid.type = buf_get_int8(bufp);
634 rcall->params.rattach.qid.version = buf_get_int32(bufp);
635 rcall->params.rattach.qid.path = buf_get_int64(bufp);
636 break;
637 case RWALK:
638 rcall->params.rwalk.nwqid = buf_get_int16(bufp);
639 rcall->params.rwalk.wqids = buf_alloc(bufp,
640 rcall->params.rwalk.nwqid * sizeof(struct v9fs_qid));
641 if (rcall->params.rwalk.wqids)
642 for (i = 0; i < rcall->params.rwalk.nwqid; i++) {
643 rcall->params.rwalk.wqids[i].type =
644 buf_get_int8(bufp);
645 rcall->params.rwalk.wqids[i].version =
646 buf_get_int16(bufp);
647 rcall->params.rwalk.wqids[i].path =
648 buf_get_int64(bufp);
649 }
650 break;
651 case ROPEN:
652 rcall->params.ropen.qid.type = buf_get_int8(bufp);
653 rcall->params.ropen.qid.version = buf_get_int32(bufp);
654 rcall->params.ropen.qid.path = buf_get_int64(bufp);
655 rcall->params.ropen.iounit = buf_get_int32(bufp);
656 break;
657 case RCREATE:
658 rcall->params.rcreate.qid.type = buf_get_int8(bufp);
659 rcall->params.rcreate.qid.version = buf_get_int32(bufp);
660 rcall->params.rcreate.qid.path = buf_get_int64(bufp);
661 rcall->params.rcreate.iounit = buf_get_int32(bufp);
662 break;
663 case RREAD:
664 rcall->params.rread.count = buf_get_int32(bufp);
665 rcall->params.rread.data = buf_get_datab(bufp, dbufp,
666 rcall->params.rread.count);
667 break;
668 case RWRITE:
669 rcall->params.rwrite.count = buf_get_int32(bufp);
670 break;
671 case RCLUNK:
672 break;
673 case RREMOVE:
674 break;
675 case RSTAT:
676 buf_get_int16(bufp);
677 rcall->params.rstat.stat =
678 deserialize_statb(v9ses, bufp, dbufp);
679 break;
680 case RWSTAT:
681 break;
682 case RERROR:
683 rcall->params.rerror.error = buf_get_stringb(bufp, dbufp);
684 if (v9ses->extended)
685 rcall->params.rerror.errno = buf_get_int16(bufp);
686 break;
687 }
688
689 if (buf_check_overflow(bufp) || buf_check_overflow(dbufp))
690 return -EIO;
691
692 return rcall->size;
693}
diff --git a/fs/9p/conv.h b/fs/9p/conv.h
new file mode 100644
index 0000000000..ee849613c6
--- /dev/null
+++ b/fs/9p/conv.h
@@ -0,0 +1,36 @@
1/*
2 * linux/fs/9p/conv.h
3 *
4 * 9P protocol conversion definitions
5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to:
21 * Free Software Foundation
22 * 51 Franklin Street, Fifth Floor
23 * Boston, MA 02111-1301 USA
24 *
25 */
26
27int v9fs_deserialize_stat(struct v9fs_session_info *, void *buf,
28 u32 buflen, struct v9fs_stat *stat, u32 statlen);
29int v9fs_serialize_fcall(struct v9fs_session_info *, struct v9fs_fcall *tcall,
30 void *buf, u32 buflen);
31int v9fs_deserialize_fcall(struct v9fs_session_info *, u32 msglen,
32 void *buf, u32 buflen, struct v9fs_fcall *rcall,
33 int rcalllen);
34
35/* this one is actually in error.c right now */
36int v9fs_errstr2errno(char *errstr);
diff --git a/fs/9p/debug.h b/fs/9p/debug.h
new file mode 100644
index 0000000000..4445f06919
--- /dev/null
+++ b/fs/9p/debug.h
@@ -0,0 +1,70 @@
1/*
2 * linux/fs/9p/debug.h - V9FS Debug Definitions
3 *
4 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
5 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
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:
19 * Free Software Foundation
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02111-1301 USA
22 *
23 */
24
25#define DEBUG_ERROR (1<<0)
26#define DEBUG_CURRENT (1<<1)
27#define DEBUG_9P (1<<2)
28#define DEBUG_VFS (1<<3)
29#define DEBUG_CONV (1<<4)
30#define DEBUG_MUX (1<<5)
31#define DEBUG_TRANS (1<<6)
32#define DEBUG_SLABS (1<<7)
33
34#define DEBUG_DUMP_PKT 0
35
36extern int v9fs_debug_level;
37
38#define dprintk(level, format, arg...) \
39do { \
40 if((v9fs_debug_level & level)==level) \
41 printk(KERN_NOTICE "-- %s (%d): " \
42 format , __FUNCTION__, current->pid , ## arg); \
43} while(0)
44
45#define eprintk(level, format, arg...) \
46do { \
47 printk(level "v9fs: %s (%d): " \
48 format , __FUNCTION__, current->pid , ## arg); \
49} while(0)
50
51#if DEBUG_DUMP_PKT
52static inline void dump_data(const unsigned char *data, unsigned int datalen)
53{
54 int i, j;
55 int len = datalen;
56
57 printk(KERN_DEBUG "data ");
58 for (i = 0; i < len; i += 4) {
59 for (j = 0; (j < 4) && (i + j < len); j++)
60 printk(KERN_DEBUG "%02x", data[i + j]);
61 printk(KERN_DEBUG " ");
62 }
63 printk(KERN_DEBUG "\n");
64}
65#else /* DEBUG_DUMP_PKT */
66static inline void dump_data(const unsigned char *data, unsigned int datalen)
67{
68
69}
70#endif /* DEBUG_DUMP_PKT */
diff --git a/fs/9p/error.c b/fs/9p/error.c
new file mode 100644
index 0000000000..fee5d19179
--- /dev/null
+++ b/fs/9p/error.c
@@ -0,0 +1,93 @@
1/*
2 * linux/fs/9p/error.c
3 *
4 * Error string handling
5 *
6 * Plan 9 uses error strings, Unix uses error numbers. These functions
7 * try to help manage that and provide for dynamically adding error
8 * mappings.
9 *
10 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
11 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to:
25 * Free Software Foundation
26 * 51 Franklin Street, Fifth Floor
27 * Boston, MA 02111-1301 USA
28 *
29 */
30
31#include <linux/config.h>
32#include <linux/module.h>
33
34#include <linux/list.h>
35#include <linux/jhash.h>
36
37#include "debug.h"
38#include "error.h"
39
40/**
41 * v9fs_error_init - preload
42 * @errstr: error string
43 *
44 */
45
46int v9fs_error_init(void)
47{
48 struct errormap *c;
49 int bucket;
50
51 /* initialize hash table */
52 for (bucket = 0; bucket < ERRHASHSZ; bucket++)
53 INIT_HLIST_HEAD(&hash_errmap[bucket]);
54
55 /* load initial error map into hash table */
56 for (c = errmap; c->name != NULL; c++) {
57 bucket = jhash(c->name, strlen(c->name), 0) % ERRHASHSZ;
58 INIT_HLIST_NODE(&c->list);
59 hlist_add_head(&c->list, &hash_errmap[bucket]);
60 }
61
62 return 1;
63}
64
65/**
66 * errstr2errno - convert error string to error number
67 * @errstr: error string
68 *
69 */
70
71int v9fs_errstr2errno(char *errstr)
72{
73 int errno = 0;
74 struct hlist_node *p = NULL;
75 struct errormap *c = NULL;
76 int bucket = jhash(errstr, strlen(errstr), 0) % ERRHASHSZ;
77
78 hlist_for_each_entry(c, p, &hash_errmap[bucket], list) {
79 if (!strcmp(c->name, errstr)) {
80 errno = c->val;
81 break;
82 }
83 }
84
85 if (errno == 0) {
86 /* TODO: if error isn't found, add it dynamically */
87 printk(KERN_ERR "%s: errstr :%s: not found\n", __FUNCTION__,
88 errstr);
89 errno = 1;
90 }
91
92 return -errno;
93}
diff --git a/fs/9p/error.h b/fs/9p/error.h
new file mode 100644
index 0000000000..78f89acf7c
--- /dev/null
+++ b/fs/9p/error.h
@@ -0,0 +1,178 @@
1/*
2 * linux/fs/9p/error.h
3 *
4 * Huge Nasty Error Table
5 *
6 * Plan 9 uses error strings, Unix uses error numbers. This table tries to
7 * match UNIX strings and Plan 9 strings to unix error numbers. It is used
8 * to preload the dynamic error table which can also track user-specific error
9 * strings.
10 *
11 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
12 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to:
26 * Free Software Foundation
27 * 51 Franklin Street, Fifth Floor
28 * Boston, MA 02111-1301 USA
29 *
30 */
31
32#include <linux/errno.h>
33#include <asm/errno.h>
34
35struct errormap {
36 char *name;
37 int val;
38
39 struct hlist_node list;
40};
41
42#define ERRHASHSZ 32
43static struct hlist_head hash_errmap[ERRHASHSZ];
44
45/* FixMe - reduce to a reasonable size */
46static struct errormap errmap[] = {
47 {"Operation not permitted", EPERM},
48 {"wstat prohibited", EPERM},
49 {"No such file or directory", ENOENT},
50 {"directory entry not found", ENOENT},
51 {"file not found", ENOENT},
52 {"Interrupted system call", EINTR},
53 {"Input/output error", EIO},
54 {"No such device or address", ENXIO},
55 {"Argument list too long", E2BIG},
56 {"Bad file descriptor", EBADF},
57 {"Resource temporarily unavailable", EAGAIN},
58 {"Cannot allocate memory", ENOMEM},
59 {"Permission denied", EACCES},
60 {"Bad address", EFAULT},
61 {"Block device required", ENOTBLK},
62 {"Device or resource busy", EBUSY},
63 {"File exists", EEXIST},
64 {"Invalid cross-device link", EXDEV},
65 {"No such device", ENODEV},
66 {"Not a directory", ENOTDIR},
67 {"Is a directory", EISDIR},
68 {"Invalid argument", EINVAL},
69 {"Too many open files in system", ENFILE},
70 {"Too many open files", EMFILE},
71 {"Text file busy", ETXTBSY},
72 {"File too large", EFBIG},
73 {"No space left on device", ENOSPC},
74 {"Illegal seek", ESPIPE},
75 {"Read-only file system", EROFS},
76 {"Too many links", EMLINK},
77 {"Broken pipe", EPIPE},
78 {"Numerical argument out of domain", EDOM},
79 {"Numerical result out of range", ERANGE},
80 {"Resource deadlock avoided", EDEADLK},
81 {"File name too long", ENAMETOOLONG},
82 {"No locks available", ENOLCK},
83 {"Function not implemented", ENOSYS},
84 {"Directory not empty", ENOTEMPTY},
85 {"Too many levels of symbolic links", ELOOP},
86 {"No message of desired type", ENOMSG},
87 {"Identifier removed", EIDRM},
88 {"No data available", ENODATA},
89 {"Machine is not on the network", ENONET},
90 {"Package not installed", ENOPKG},
91 {"Object is remote", EREMOTE},
92 {"Link has been severed", ENOLINK},
93 {"Communication error on send", ECOMM},
94 {"Protocol error", EPROTO},
95 {"Bad message", EBADMSG},
96 {"File descriptor in bad state", EBADFD},
97 {"Streams pipe error", ESTRPIPE},
98 {"Too many users", EUSERS},
99 {"Socket operation on non-socket", ENOTSOCK},
100 {"Message too long", EMSGSIZE},
101 {"Protocol not available", ENOPROTOOPT},
102 {"Protocol not supported", EPROTONOSUPPORT},
103 {"Socket type not supported", ESOCKTNOSUPPORT},
104 {"Operation not supported", EOPNOTSUPP},
105 {"Protocol family not supported", EPFNOSUPPORT},
106 {"Network is down", ENETDOWN},
107 {"Network is unreachable", ENETUNREACH},
108 {"Network dropped connection on reset", ENETRESET},
109 {"Software caused connection abort", ECONNABORTED},
110 {"Connection reset by peer", ECONNRESET},
111 {"No buffer space available", ENOBUFS},
112 {"Transport endpoint is already connected", EISCONN},
113 {"Transport endpoint is not connected", ENOTCONN},
114 {"Cannot send after transport endpoint shutdown", ESHUTDOWN},
115 {"Connection timed out", ETIMEDOUT},
116 {"Connection refused", ECONNREFUSED},
117 {"Host is down", EHOSTDOWN},
118 {"No route to host", EHOSTUNREACH},
119 {"Operation already in progress", EALREADY},
120 {"Operation now in progress", EINPROGRESS},
121 {"Is a named type file", EISNAM},
122 {"Remote I/O error", EREMOTEIO},
123 {"Disk quota exceeded", EDQUOT},
124/* errors from fossil, vacfs, and u9fs */
125 {"fid unknown or out of range", EBADF},
126 {"permission denied", EACCES},
127 {"file does not exist", ENOENT},
128 {"authentication failed", ECONNREFUSED},
129 {"bad offset in directory read", ESPIPE},
130 {"bad use of fid", EBADF},
131 {"wstat can't convert between files and directories", EPERM},
132 {"directory is not empty", ENOTEMPTY},
133 {"file exists", EEXIST},
134 {"file already exists", EEXIST},
135 {"file or directory already exists", EEXIST},
136 {"fid already in use", EBADF},
137 {"file in use", ETXTBSY},
138 {"i/o error", EIO},
139 {"file already open for I/O", ETXTBSY},
140 {"illegal mode", EINVAL},
141 {"illegal name", ENAMETOOLONG},
142 {"not a directory", ENOTDIR},
143 {"not a member of proposed group", EPERM},
144 {"not owner", EACCES},
145 {"only owner can change group in wstat", EACCES},
146 {"read only file system", EROFS},
147 {"no access to special file", EPERM},
148 {"i/o count too large", EIO},
149 {"unknown group", EINVAL},
150 {"unknown user", EINVAL},
151 {"bogus wstat buffer", EPROTO},
152 {"exclusive use file already open", EAGAIN},
153 {"corrupted directory entry", EIO},
154 {"corrupted file entry", EIO},
155 {"corrupted block label", EIO},
156 {"corrupted meta data", EIO},
157 {"illegal offset", EINVAL},
158 {"illegal path element", ENOENT},
159 {"root of file system is corrupted", EIO},
160 {"corrupted super block", EIO},
161 {"protocol botch", EPROTO},
162 {"file system is full", ENOSPC},
163 {"file is in use", EAGAIN},
164 {"directory entry is not allocated", ENOENT},
165 {"file is read only", EROFS},
166 {"file has been removed", EIDRM},
167 {"only support truncation to zero length", EPERM},
168 {"cannot remove root", EPERM},
169 {"file too big", EFBIG},
170 {"venti i/o error", EIO},
171 /* these are not errors */
172 {"u9fs rhostsauth: no authentication required", 0},
173 {"u9fs authnone: no authentication required", 0},
174 {NULL, -1}
175};
176
177extern int v9fs_error_init(void);
178extern int v9fs_errstr2errno(char *errstr);
diff --git a/fs/9p/fid.c b/fs/9p/fid.c
new file mode 100644
index 0000000000..821c9c4d76
--- /dev/null
+++ b/fs/9p/fid.c
@@ -0,0 +1,241 @@
1/*
2 * V9FS FID Management
3 *
4 * Copyright (C) 2005 by Eric Van Hensbergen <ericvh@gmail.com>
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:
18 * Free Software Foundation
19 * 51 Franklin Street, Fifth Floor
20 * Boston, MA 02111-1301 USA
21 *
22 */
23
24#include <linux/config.h>
25#include <linux/module.h>
26#include <linux/errno.h>
27#include <linux/fs.h>
28#include <linux/idr.h>
29
30#include "debug.h"
31#include "v9fs.h"
32#include "9p.h"
33#include "v9fs_vfs.h"
34#include "transport.h"
35#include "mux.h"
36#include "conv.h"
37#include "fid.h"
38
39/**
40 * v9fs_fid_insert - add a fid to a dentry
41 * @fid: fid to add
42 * @dentry: dentry that it is being added to
43 *
44 */
45
46static int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry)
47{
48 struct list_head *fid_list = (struct list_head *)dentry->d_fsdata;
49 dprintk(DEBUG_9P, "fid %d (%p) dentry %s (%p)\n", fid->fid, fid,
50 dentry->d_iname, dentry);
51 if (dentry->d_fsdata == NULL) {
52 dentry->d_fsdata =
53 kmalloc(sizeof(struct list_head), GFP_KERNEL);
54 if (dentry->d_fsdata == NULL) {
55 dprintk(DEBUG_ERROR, "Out of memory\n");
56 return -ENOMEM;
57 }
58 fid_list = (struct list_head *)dentry->d_fsdata;
59 INIT_LIST_HEAD(fid_list); /* Initialize list head */
60 }
61
62 fid->uid = current->uid;
63 fid->pid = current->pid;
64 list_add(&fid->list, fid_list);
65 return 0;
66}
67
68/**
69 * v9fs_fid_create - allocate a FID structure
70 * @dentry - dentry to link newly created fid to
71 *
72 */
73
74struct v9fs_fid *v9fs_fid_create(struct dentry *dentry)
75{
76 struct v9fs_fid *new;
77
78 new = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL);
79 if (new == NULL) {
80 dprintk(DEBUG_ERROR, "Out of Memory\n");
81 return ERR_PTR(-ENOMEM);
82 }
83
84 new->fid = -1;
85 new->fidopen = 0;
86 new->fidcreate = 0;
87 new->fidclunked = 0;
88 new->iounit = 0;
89
90 if (v9fs_fid_insert(new, dentry) == 0)
91 return new;
92 else {
93 dprintk(DEBUG_ERROR, "Problems inserting to dentry\n");
94 kfree(new);
95 return NULL;
96 }
97}
98
99/**
100 * v9fs_fid_destroy - deallocate a FID structure
101 * @fid: fid to destroy
102 *
103 */
104
105void v9fs_fid_destroy(struct v9fs_fid *fid)
106{
107 list_del(&fid->list);
108 kfree(fid);
109}
110
111/**
112 * v9fs_fid_lookup - retrieve the right fid from a particular dentry
113 * @dentry: dentry to look for fid in
114 * @type: intent of lookup (operation or traversal)
115 *
116 * search list of fids associated with a dentry for a fid with a matching
117 * thread id or uid. If that fails, look up the dentry's parents to see if you
118 * can find a matching fid.
119 *
120 */
121
122struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry, int type)
123{
124 struct list_head *fid_list = (struct list_head *)dentry->d_fsdata;
125 struct v9fs_fid *current_fid = NULL;
126 struct v9fs_fid *temp = NULL;
127 struct v9fs_fid *return_fid = NULL;
128 int found_parent = 0;
129 int found_user = 0;
130
131 dprintk(DEBUG_9P, " dentry: %s (%p) type %d\n", dentry->d_iname, dentry,
132 type);
133
134 if (fid_list && !list_empty(fid_list)) {
135 list_for_each_entry_safe(current_fid, temp, fid_list, list) {
136 if (current_fid->uid == current->uid) {
137 if (return_fid == NULL) {
138 if ((type == FID_OP)
139 || (!current_fid->fidopen)) {
140 return_fid = current_fid;
141 found_user = 1;
142 }
143 }
144 }
145 if (current_fid->pid == current->real_parent->pid) {
146 if ((return_fid == NULL) || (found_parent)
147 || (found_user)) {
148 if ((type == FID_OP)
149 || (!current_fid->fidopen)) {
150 return_fid = current_fid;
151 found_parent = 1;
152 found_user = 0;
153 }
154 }
155 }
156 if (current_fid->pid == current->pid) {
157 if ((type == FID_OP) ||
158 (!current_fid->fidopen)) {
159 return_fid = current_fid;
160 found_parent = 0;
161 found_user = 0;
162 }
163 }
164 }
165 }
166
167 /* we are at the root but didn't match */
168 if ((!return_fid) && (dentry->d_parent == dentry)) {
169 /* TODO: clone attach with new uid */
170 return_fid = current_fid;
171 }
172
173 if (!return_fid) {
174 struct dentry *par = current->fs->pwd->d_parent;
175 int count = 1;
176 while (par != NULL) {
177 if (par == dentry)
178 break;
179 count++;
180 if (par == par->d_parent) {
181 dprintk(DEBUG_ERROR,
182 "got to root without finding dentry\n");
183 break;
184 }
185 par = par->d_parent;
186 }
187
188/* XXX - there may be some duplication we can get rid of */
189 if (par == dentry) {
190 /* we need to fid_lookup the starting point */
191 int fidnum = -1;
192 int oldfid = -1;
193 int result = -1;
194 struct v9fs_session_info *v9ses =
195 v9fs_inode2v9ses(current->fs->pwd->d_inode);
196
197 current_fid =
198 v9fs_fid_lookup(current->fs->pwd, FID_WALK);
199 if (current_fid == NULL) {
200 dprintk(DEBUG_ERROR,
201 "process cwd doesn't have a fid\n");
202 return return_fid;
203 }
204 oldfid = current_fid->fid;
205 par = current->fs->pwd;
206 /* TODO: take advantage of multiwalk */
207
208 fidnum = v9fs_get_idpool(&v9ses->fidpool);
209 if (fidnum < 0) {
210 dprintk(DEBUG_ERROR,
211 "could not get a new fid num\n");
212 return return_fid;
213 }
214
215 while (par != dentry) {
216 result =
217 v9fs_t_walk(v9ses, oldfid, fidnum, "..",
218 NULL);
219 if (result < 0) {
220 dprintk(DEBUG_ERROR,
221 "problem walking to parent\n");
222
223 break;
224 }
225 oldfid = fidnum;
226 if (par == par->d_parent) {
227 dprintk(DEBUG_ERROR,
228 "can't find dentry\n");
229 break;
230 }
231 par = par->d_parent;
232 }
233 if (par == dentry) {
234 return_fid = v9fs_fid_create(dentry);
235 return_fid->fid = fidnum;
236 }
237 }
238 }
239
240 return return_fid;
241}
diff --git a/fs/9p/fid.h b/fs/9p/fid.h
new file mode 100644
index 0000000000..7db478ccca
--- /dev/null
+++ b/fs/9p/fid.h
@@ -0,0 +1,57 @@
1/*
2 * V9FS FID Management
3 *
4 * Copyright (C) 2005 by Eric Van Hensbergen <ericvh@gmail.com>
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:
18 * Free Software Foundation
19 * 51 Franklin Street, Fifth Floor
20 * Boston, MA 02111-1301 USA
21 *
22 */
23
24#include <linux/list.h>
25
26#define FID_OP 0
27#define FID_WALK 1
28
29struct v9fs_fid {
30 struct list_head list; /* list of fids associated with a dentry */
31 struct list_head active; /* XXX - debug */
32
33 u32 fid;
34 unsigned char fidopen; /* set when fid is opened */
35 unsigned char fidcreate; /* set when fid was just created */
36 unsigned char fidclunked; /* set when fid has already been clunked */
37
38 struct v9fs_qid qid;
39 u32 iounit;
40
41 /* readdir stuff */
42 int rdir_fpos;
43 loff_t rdir_pos;
44 struct v9fs_fcall *rdir_fcall;
45
46 /* management stuff */
47 pid_t pid; /* thread associated with this fid */
48 uid_t uid; /* user associated with this fid */
49
50 /* private data */
51 struct file *filp; /* backpointer to File struct for open files */
52 struct v9fs_session_info *v9ses; /* session info for this FID */
53};
54
55struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry, int type);
56void v9fs_fid_destroy(struct v9fs_fid *fid);
57struct v9fs_fid *v9fs_fid_create(struct dentry *);
diff --git a/fs/9p/mux.c b/fs/9p/mux.c
new file mode 100644
index 0000000000..8835b576f7
--- /dev/null
+++ b/fs/9p/mux.c
@@ -0,0 +1,475 @@
1/*
2 * linux/fs/9p/mux.c
3 *
4 * Protocol Multiplexer
5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2004 by Latchesar Ionkov <lucho@ionkov.net>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to:
21 * Free Software Foundation
22 * 51 Franklin Street, Fifth Floor
23 * Boston, MA 02111-1301 USA
24 *
25 */
26
27#include <linux/config.h>
28#include <linux/module.h>
29#include <linux/errno.h>
30#include <linux/fs.h>
31#include <linux/kthread.h>
32#include <linux/idr.h>
33
34#include "debug.h"
35#include "v9fs.h"
36#include "9p.h"
37#include "transport.h"
38#include "conv.h"
39#include "mux.h"
40
41/**
42 * dprintcond - print condition of session info
43 * @v9ses: session info structure
44 * @req: RPC request structure
45 *
46 */
47
48static inline int
49dprintcond(struct v9fs_session_info *v9ses, struct v9fs_rpcreq *req)
50{
51 dprintk(DEBUG_MUX, "condition: %d, %p\n", v9ses->transport->status,
52 req->rcall);
53 return 0;
54}
55
56/**
57 * xread - force read of a certain number of bytes
58 * @v9ses: session info structure
59 * @ptr: pointer to buffer
60 * @sz: number of bytes to read
61 *
62 * Chuck Cranor CS-533 project1
63 */
64
65static int xread(struct v9fs_session_info *v9ses, void *ptr, unsigned long sz)
66{
67 int rd = 0;
68 int ret = 0;
69 while (rd < sz) {
70 ret = v9ses->transport->read(v9ses->transport, ptr, sz - rd);
71 if (ret <= 0) {
72 dprintk(DEBUG_ERROR, "xread errno %d\n", ret);
73 return ret;
74 }
75 rd += ret;
76 ptr += ret;
77 }
78 return (rd);
79}
80
81/**
82 * read_message - read a full 9P2000 fcall packet
83 * @v9ses: session info structure
84 * @rcall: fcall structure to read into
85 * @rcalllen: size of fcall buffer
86 *
87 */
88
89static int
90read_message(struct v9fs_session_info *v9ses,
91 struct v9fs_fcall *rcall, int rcalllen)
92{
93 unsigned char buf[4];
94 void *data;
95 int size = 0;
96 int res = 0;
97
98 res = xread(v9ses, buf, sizeof(buf));
99 if (res < 0) {
100 dprintk(DEBUG_ERROR,
101 "Reading of count field failed returned: %d\n", res);
102 return res;
103 }
104
105 if (res < 4) {
106 dprintk(DEBUG_ERROR,
107 "Reading of count field failed returned: %d\n", res);
108 return -EIO;
109 }
110
111 size = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
112 dprintk(DEBUG_MUX, "got a packet count: %d\n", size);
113
114 /* adjust for the four bytes of size */
115 size -= 4;
116
117 if (size > v9ses->maxdata) {
118 dprintk(DEBUG_ERROR, "packet too big: %d\n", size);
119 return -E2BIG;
120 }
121
122 data = kmalloc(size, GFP_KERNEL);
123 if (!data) {
124 eprintk(KERN_WARNING, "out of memory\n");
125 return -ENOMEM;
126 }
127
128 res = xread(v9ses, data, size);
129 if (res < size) {
130 dprintk(DEBUG_ERROR, "Reading of fcall failed returned: %d\n",
131 res);
132 kfree(data);
133 return res;
134 }
135
136 /* we now have an in-memory string that is the reply.
137 * deserialize it. There is very little to go wrong at this point
138 * save for v9fs_alloc errors.
139 */
140 res = v9fs_deserialize_fcall(v9ses, size, data, v9ses->maxdata,
141 rcall, rcalllen);
142
143 kfree(data);
144
145 if (res < 0)
146 return res;
147
148 return 0;
149}
150
151/**
152 * v9fs_recv - receive an RPC response for a particular tag
153 * @v9ses: session info structure
154 * @req: RPC request structure
155 *
156 */
157
158static int v9fs_recv(struct v9fs_session_info *v9ses, struct v9fs_rpcreq *req)
159{
160 int ret = 0;
161
162 dprintk(DEBUG_MUX, "waiting for response: %d\n", req->tcall->tag);
163 ret = wait_event_interruptible(v9ses->read_wait,
164 ((v9ses->transport->status != Connected) ||
165 (req->rcall != 0) || (req->err < 0) ||
166 dprintcond(v9ses, req)));
167
168 dprintk(DEBUG_MUX, "got it: rcall %p\n", req->rcall);
169
170 spin_lock(&v9ses->muxlock);
171 list_del(&req->next);
172 spin_unlock(&v9ses->muxlock);
173
174 if (req->err < 0)
175 return req->err;
176
177 if (v9ses->transport->status == Disconnected)
178 return -ECONNRESET;
179
180 return ret;
181}
182
183/**
184 * v9fs_send - send a 9P request
185 * @v9ses: session info structure
186 * @req: RPC request to send
187 *
188 */
189
190static int v9fs_send(struct v9fs_session_info *v9ses, struct v9fs_rpcreq *req)
191{
192 int ret = -1;
193 void *data = NULL;
194 struct v9fs_fcall *tcall = req->tcall;
195
196 data = kmalloc(v9ses->maxdata + V9FS_IOHDRSZ, GFP_KERNEL);
197 if (!data)
198 return -ENOMEM;
199
200 tcall->size = 0; /* enforce size recalculation */
201 ret =
202 v9fs_serialize_fcall(v9ses, tcall, data,
203 v9ses->maxdata + V9FS_IOHDRSZ);
204 if (ret < 0)
205 goto free_data;
206
207 spin_lock(&v9ses->muxlock);
208 list_add(&req->next, &v9ses->mux_fcalls);
209 spin_unlock(&v9ses->muxlock);
210
211 dprintk(DEBUG_MUX, "sending message: tag %d size %d\n", tcall->tag,
212 tcall->size);
213 ret = v9ses->transport->write(v9ses->transport, data, tcall->size);
214
215 if (ret != tcall->size) {
216 spin_lock(&v9ses->muxlock);
217 list_del(&req->next);
218 kfree(req->rcall);
219
220 spin_unlock(&v9ses->muxlock);
221 if (ret >= 0)
222 ret = -EREMOTEIO;
223 } else
224 ret = 0;
225
226 free_data:
227 kfree(data);
228 return ret;
229}
230
231/**
232 * v9fs_mux_rpc - send a request, receive a response
233 * @v9ses: session info structure
234 * @tcall: fcall to send
235 * @rcall: buffer to place response into
236 *
237 */
238
239long
240v9fs_mux_rpc(struct v9fs_session_info *v9ses, struct v9fs_fcall *tcall,
241 struct v9fs_fcall **rcall)
242{
243 int tid = -1;
244 struct v9fs_fcall *fcall = NULL;
245 struct v9fs_rpcreq req;
246 int ret = -1;
247
248 if (!v9ses)
249 return -EINVAL;
250
251 if (!v9ses->transport || v9ses->transport->status != Connected)
252 return -EIO;
253
254 if (rcall)
255 *rcall = NULL;
256
257 if (tcall->id != TVERSION) {
258 tid = v9fs_get_idpool(&v9ses->tidpool);
259 if (tid < 0)
260 return -ENOMEM;
261 }
262
263 tcall->tag = tid;
264
265 req.tcall = tcall;
266 req.err = 0;
267 req.rcall = NULL;
268
269 ret = v9fs_send(v9ses, &req);
270
271 if (ret < 0) {
272 if (tcall->id != TVERSION)
273 v9fs_put_idpool(tid, &v9ses->tidpool);
274 dprintk(DEBUG_MUX, "error %d\n", ret);
275 return ret;
276 }
277
278 ret = v9fs_recv(v9ses, &req);
279
280 fcall = req.rcall;
281
282 dprintk(DEBUG_MUX, "received: tag=%x, ret=%d\n", tcall->tag, ret);
283 if (ret == -ERESTARTSYS) {
284 if (v9ses->transport->status != Disconnected
285 && tcall->id != TFLUSH) {
286 unsigned long flags;
287
288 dprintk(DEBUG_MUX, "flushing the tag: %d\n",
289 tcall->tag);
290 clear_thread_flag(TIF_SIGPENDING);
291 v9fs_t_flush(v9ses, tcall->tag);
292 spin_lock_irqsave(&current->sighand->siglock, flags);
293 recalc_sigpending();
294 spin_unlock_irqrestore(&current->sighand->siglock,
295 flags);
296 dprintk(DEBUG_MUX, "flushing done\n");
297 }
298
299 goto release_req;
300 } else if (ret < 0)
301 goto release_req;
302
303 if (!fcall)
304 ret = -EIO;
305 else {
306 if (fcall->id == RERROR) {
307 ret = v9fs_errstr2errno(fcall->params.rerror.error);
308 if (ret == 0) { /* string match failed */
309 if (fcall->params.rerror.errno)
310 ret = -(fcall->params.rerror.errno);
311 else
312 ret = -ESERVERFAULT;
313 }
314 } else if (fcall->id != tcall->id + 1) {
315 dprintk(DEBUG_ERROR,
316 "fcall mismatch: expected %d, got %d\n",
317 tcall->id + 1, fcall->id);
318 ret = -EIO;
319 }
320 }
321
322 release_req:
323 if (tcall->id != TVERSION)
324 v9fs_put_idpool(tid, &v9ses->tidpool);
325 if (rcall)
326 *rcall = fcall;
327 else
328 kfree(fcall);
329
330 return ret;
331}
332
333/**
334 * v9fs_mux_cancel_requests - cancels all pending requests
335 *
336 * @v9ses: session info structure
337 * @err: error code to return to the requests
338 */
339void v9fs_mux_cancel_requests(struct v9fs_session_info *v9ses, int err)
340{
341 struct v9fs_rpcreq *rptr;
342 struct v9fs_rpcreq *rreq;
343
344 dprintk(DEBUG_MUX, " %d\n", err);
345 spin_lock(&v9ses->muxlock);
346 list_for_each_entry_safe(rreq, rptr, &v9ses->mux_fcalls, next) {
347 rreq->err = err;
348 }
349 spin_unlock(&v9ses->muxlock);
350 wake_up_all(&v9ses->read_wait);
351}
352
353/**
354 * v9fs_recvproc - kproc to handle demultiplexing responses
355 * @data: session info structure
356 *
357 */
358
359static int v9fs_recvproc(void *data)
360{
361 struct v9fs_session_info *v9ses = (struct v9fs_session_info *)data;
362 struct v9fs_fcall *rcall = NULL;
363 struct v9fs_rpcreq *rptr;
364 struct v9fs_rpcreq *req;
365 struct v9fs_rpcreq *rreq;
366 int err = 0;
367
368 allow_signal(SIGKILL);
369 set_current_state(TASK_INTERRUPTIBLE);
370 complete(&v9ses->proccmpl);
371 while (!kthread_should_stop() && err >= 0) {
372 req = rptr = rreq = NULL;
373
374 rcall = kmalloc(v9ses->maxdata + V9FS_IOHDRSZ, GFP_KERNEL);
375 if (!rcall) {
376 eprintk(KERN_ERR, "no memory for buffers\n");
377 break;
378 }
379
380 err = read_message(v9ses, rcall, v9ses->maxdata + V9FS_IOHDRSZ);
381 spin_lock(&v9ses->muxlock);
382 if (err < 0) {
383 list_for_each_entry_safe(rreq, rptr, &v9ses->mux_fcalls, next) {
384 rreq->err = err;
385 }
386 if(err != -ERESTARTSYS)
387 eprintk(KERN_ERR,
388 "Transport error while reading message %d\n", err);
389 } else {
390 list_for_each_entry_safe(rreq, rptr, &v9ses->mux_fcalls, next) {
391 if (rreq->tcall->tag == rcall->tag) {
392 req = rreq;
393 req->rcall = rcall;
394 break;
395 }
396 }
397 }
398
399 if (req && (req->tcall->id == TFLUSH)) {
400 struct v9fs_rpcreq *treq = NULL;
401 list_for_each_entry_safe(treq, rptr, &v9ses->mux_fcalls, next) {
402 if (treq->tcall->tag ==
403 req->tcall->params.tflush.oldtag) {
404 list_del(&rptr->next);
405 kfree(treq->rcall);
406 break;
407 }
408 }
409 }
410
411 spin_unlock(&v9ses->muxlock);
412
413 if (!req) {
414 if (err >= 0)
415 dprintk(DEBUG_ERROR,
416 "unexpected response: id %d tag %d\n",
417 rcall->id, rcall->tag);
418
419 kfree(rcall);
420 }
421
422 wake_up_all(&v9ses->read_wait);
423 set_current_state(TASK_INTERRUPTIBLE);
424 }
425
426 v9ses->transport->close(v9ses->transport);
427
428 /* Inform all pending processes about the failure */
429 wake_up_all(&v9ses->read_wait);
430
431 if (signal_pending(current))
432 complete(&v9ses->proccmpl);
433
434 dprintk(DEBUG_MUX, "recvproc: end\n");
435 v9ses->recvproc = NULL;
436
437 return err >= 0;
438}
439
440/**
441 * v9fs_mux_init - initialize multiplexer (spawn kproc)
442 * @v9ses: session info structure
443 * @dev_name: mount device information (to create unique kproc)
444 *
445 */
446
447int v9fs_mux_init(struct v9fs_session_info *v9ses, const char *dev_name)
448{
449 char procname[60];
450
451 strncpy(procname, dev_name, sizeof(procname));
452 procname[sizeof(procname) - 1] = 0;
453
454 init_waitqueue_head(&v9ses->read_wait);
455 init_completion(&v9ses->fcread);
456 init_completion(&v9ses->proccmpl);
457 spin_lock_init(&v9ses->muxlock);
458 INIT_LIST_HEAD(&v9ses->mux_fcalls);
459 v9ses->recvproc = NULL;
460 v9ses->curfcall = NULL;
461
462 v9ses->recvproc = kthread_create(v9fs_recvproc, v9ses,
463 "v9fs_recvproc %s", procname);
464
465 if (IS_ERR(v9ses->recvproc)) {
466 eprintk(KERN_ERR, "cannot create receiving thread\n");
467 v9fs_session_close(v9ses);
468 return -ECONNABORTED;
469 }
470
471 wake_up_process(v9ses->recvproc);
472 wait_for_completion(&v9ses->proccmpl);
473
474 return 0;
475}
diff --git a/fs/9p/mux.h b/fs/9p/mux.h
new file mode 100644
index 0000000000..4994cb10ba
--- /dev/null
+++ b/fs/9p/mux.h
@@ -0,0 +1,41 @@
1/*
2 * linux/fs/9p/mux.h
3 *
4 * Multiplexer Definitions
5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
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:
20 * Free Software Foundation
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02111-1301 USA
23 *
24 */
25
26/* structure to manage each RPC transaction */
27
28struct v9fs_rpcreq {
29 struct v9fs_fcall *tcall;
30 struct v9fs_fcall *rcall;
31 int err; /* error code if response failed */
32
33 /* XXX - could we put scatter/gather buffers here? */
34
35 struct list_head next;
36};
37
38int v9fs_mux_init(struct v9fs_session_info *v9ses, const char *dev_name);
39long v9fs_mux_rpc(struct v9fs_session_info *v9ses,
40 struct v9fs_fcall *tcall, struct v9fs_fcall **rcall);
41void v9fs_mux_cancel_requests(struct v9fs_session_info *v9ses, int err);
diff --git a/fs/9p/trans_fd.c b/fs/9p/trans_fd.c
new file mode 100644
index 0000000000..63b58ce98f
--- /dev/null
+++ b/fs/9p/trans_fd.c
@@ -0,0 +1,172 @@
1/*
2 * linux/fs/9p/trans_fd.c
3 *
4 * File Descriptor Transport Layer
5 *
6 * Copyright (C) 2005 by Eric Van Hensbergen <ericvh@gmail.com>
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:
20 * Free Software Foundation
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02111-1301 USA
23 *
24 */
25
26#include <linux/config.h>
27#include <linux/module.h>
28#include <linux/net.h>
29#include <linux/ipv6.h>
30#include <linux/errno.h>
31#include <linux/kernel.h>
32#include <linux/un.h>
33#include <asm/uaccess.h>
34#include <linux/inet.h>
35#include <linux/idr.h>
36#include <linux/file.h>
37
38#include "debug.h"
39#include "v9fs.h"
40#include "transport.h"
41
42struct v9fs_trans_fd {
43 struct file *in_file;
44 struct file *out_file;
45};
46
47/**
48 * v9fs_fd_recv - receive from a socket
49 * @v9ses: session information
50 * @v: buffer to receive data into
51 * @len: size of receive buffer
52 *
53 */
54
55static int v9fs_fd_recv(struct v9fs_transport *trans, void *v, int len)
56{
57 struct v9fs_trans_fd *ts = trans ? trans->priv : NULL;
58
59 if (!trans || trans->status != Connected || !ts)
60 return -EIO;
61
62 return kernel_read(ts->in_file, ts->in_file->f_pos, v, len);
63}
64
65/**
66 * v9fs_fd_send - send to a socket
67 * @v9ses: session information
68 * @v: buffer to send data from
69 * @len: size of send buffer
70 *
71 */
72
73static int v9fs_fd_send(struct v9fs_transport *trans, void *v, int len)
74{
75 struct v9fs_trans_fd *ts = trans ? trans->priv : NULL;
76 mm_segment_t oldfs = get_fs();
77 int ret = 0;
78
79 if (!trans || trans->status != Connected || !ts)
80 return -EIO;
81
82 set_fs(get_ds());
83 /* The cast to a user pointer is valid due to the set_fs() */
84 ret = vfs_write(ts->out_file, (void __user *)v, len, &ts->out_file->f_pos);
85 set_fs(oldfs);
86
87 return ret;
88}
89
90/**
91 * v9fs_fd_init - initialize file descriptor transport
92 * @v9ses: session information
93 * @addr: address of server to mount
94 * @data: mount options
95 *
96 */
97
98static int
99v9fs_fd_init(struct v9fs_session_info *v9ses, const char *addr, char *data)
100{
101 struct v9fs_trans_fd *ts = NULL;
102 struct v9fs_transport *trans = v9ses->transport;
103
104 if((v9ses->wfdno == ~0) || (v9ses->rfdno == ~0)) {
105 printk(KERN_ERR "v9fs: Insufficient options for proto=fd\n");
106 return -ENOPROTOOPT;
107 }
108
109 sema_init(&trans->writelock, 1);
110 sema_init(&trans->readlock, 1);
111
112 ts = kmalloc(sizeof(struct v9fs_trans_fd), GFP_KERNEL);
113
114 if (!ts)
115 return -ENOMEM;
116
117 ts->in_file = fget( v9ses->rfdno );
118 ts->out_file = fget( v9ses->wfdno );
119
120 if (!ts->in_file || !ts->out_file) {
121 if (ts->in_file)
122 fput(ts->in_file);
123
124 if (ts->out_file)
125 fput(ts->out_file);
126
127 kfree(ts);
128 return -EIO;
129 }
130
131 trans->priv = ts;
132 trans->status = Connected;
133
134 return 0;
135}
136
137
138/**
139 * v9fs_fd_close - shutdown file descriptor
140 * @trans: private socket structure
141 *
142 */
143
144static void v9fs_fd_close(struct v9fs_transport *trans)
145{
146 struct v9fs_trans_fd *ts;
147
148 if (!trans)
149 return;
150
151 trans->status = Disconnected;
152 ts = trans->priv;
153
154 if (!ts)
155 return;
156
157 if (ts->in_file)
158 fput(ts->in_file);
159
160 if (ts->out_file)
161 fput(ts->out_file);
162
163 kfree(ts);
164}
165
166struct v9fs_transport v9fs_trans_fd = {
167 .init = v9fs_fd_init,
168 .write = v9fs_fd_send,
169 .read = v9fs_fd_recv,
170 .close = v9fs_fd_close,
171};
172
diff --git a/fs/9p/trans_sock.c b/fs/9p/trans_sock.c
new file mode 100644
index 0000000000..01e26f0013
--- /dev/null
+++ b/fs/9p/trans_sock.c
@@ -0,0 +1,290 @@
1/*
2 * linux/fs/9p/trans_socket.c
3 *
4 * Socket Transport Layer
5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 1997-2002 by Ron Minnich <rminnich@sarnoff.com>
8 * Copyright (C) 1995, 1996 by Olaf Kirch <okir@monad.swb.de>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to:
22 * Free Software Foundation
23 * 51 Franklin Street, Fifth Floor
24 * Boston, MA 02111-1301 USA
25 *
26 */
27
28#include <linux/config.h>
29#include <linux/module.h>
30#include <linux/net.h>
31#include <linux/ipv6.h>
32#include <linux/errno.h>
33#include <linux/kernel.h>
34#include <linux/un.h>
35#include <asm/uaccess.h>
36#include <linux/inet.h>
37#include <linux/idr.h>
38
39#include "debug.h"
40#include "v9fs.h"
41#include "transport.h"
42
43#define V9FS_PORT 564
44
45struct v9fs_trans_sock {
46 struct socket *s;
47};
48
49/**
50 * v9fs_sock_recv - receive from a socket
51 * @v9ses: session information
52 * @v: buffer to receive data into
53 * @len: size of receive buffer
54 *
55 */
56
57static int v9fs_sock_recv(struct v9fs_transport *trans, void *v, int len)
58{
59 struct msghdr msg;
60 struct kvec iov;
61 int result;
62 mm_segment_t oldfs;
63 struct v9fs_trans_sock *ts = trans ? trans->priv : NULL;
64
65 if (trans->status == Disconnected)
66 return -EREMOTEIO;
67
68 result = -EINVAL;
69
70 oldfs = get_fs();
71 set_fs(get_ds());
72
73 iov.iov_base = v;
74 iov.iov_len = len;
75 msg.msg_name = NULL;
76 msg.msg_namelen = 0;
77 msg.msg_iovlen = 1;
78 msg.msg_control = NULL;
79 msg.msg_controllen = 0;
80 msg.msg_namelen = 0;
81 msg.msg_flags = MSG_NOSIGNAL;
82
83 result = kernel_recvmsg(ts->s, &msg, &iov, 1, len, 0);
84
85 dprintk(DEBUG_TRANS, "socket state %d\n", ts->s->state);
86 set_fs(oldfs);
87
88 if (result <= 0) {
89 if (result != -ERESTARTSYS)
90 trans->status = Disconnected;
91 }
92
93 return result;
94}
95
96/**
97 * v9fs_sock_send - send to a socket
98 * @v9ses: session information
99 * @v: buffer to send data from
100 * @len: size of send buffer
101 *
102 */
103
104static int v9fs_sock_send(struct v9fs_transport *trans, void *v, int len)
105{
106 struct kvec iov;
107 struct msghdr msg;
108 int result = -1;
109 mm_segment_t oldfs;
110 struct v9fs_trans_sock *ts = trans ? trans->priv : NULL;
111
112 dprintk(DEBUG_TRANS, "Sending packet size %d (%x)\n", len, len);
113 dump_data(v, len);
114
115 down(&trans->writelock);
116
117 oldfs = get_fs();
118 set_fs(get_ds());
119 iov.iov_base = v;
120 iov.iov_len = len;
121 msg.msg_name = NULL;
122 msg.msg_namelen = 0;
123 msg.msg_iovlen = 1;
124 msg.msg_control = NULL;
125 msg.msg_controllen = 0;
126 msg.msg_namelen = 0;
127 msg.msg_flags = MSG_NOSIGNAL;
128 result = kernel_sendmsg(ts->s, &msg, &iov, 1, len);
129 set_fs(oldfs);
130
131 if (result < 0) {
132 if (result != -ERESTARTSYS)
133 trans->status = Disconnected;
134 }
135
136 up(&trans->writelock);
137 return result;
138}
139
140/**
141 * v9fs_tcp_init - initialize TCP socket
142 * @v9ses: session information
143 * @addr: address of server to mount
144 * @data: mount options
145 *
146 */
147
148static int
149v9fs_tcp_init(struct v9fs_session_info *v9ses, const char *addr, char *data)
150{
151 struct socket *csocket = NULL;
152 struct sockaddr_in sin_server;
153 int rc = 0;
154 struct v9fs_trans_sock *ts = NULL;
155 struct v9fs_transport *trans = v9ses->transport;
156
157 sema_init(&trans->writelock, 1);
158 sema_init(&trans->readlock, 1);
159
160 ts = kmalloc(sizeof(struct v9fs_trans_sock), GFP_KERNEL);
161
162 if (!ts)
163 return -ENOMEM;
164
165 trans->priv = ts;
166 ts->s = NULL;
167
168 if (!addr)
169 return -EINVAL;
170
171 dprintk(DEBUG_TRANS, "Connecting to %s\n", addr);
172
173 sin_server.sin_family = AF_INET;
174 sin_server.sin_addr.s_addr = in_aton(addr);
175 sin_server.sin_port = htons(v9ses->port);
176 sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &csocket);
177 rc = csocket->ops->connect(csocket,
178 (struct sockaddr *)&sin_server,
179 sizeof(struct sockaddr_in), 0);
180 if (rc < 0) {
181 eprintk(KERN_ERR,
182 "v9fs_trans_tcp: problem connecting socket to %s\n",
183 addr);
184 return rc;
185 }
186 csocket->sk->sk_allocation = GFP_NOIO;
187 ts->s = csocket;
188 trans->status = Connected;
189
190 return 0;
191}
192
193/**
194 * v9fs_unix_init - initialize UNIX domain socket
195 * @v9ses: session information
196 * @dev_name: path to named pipe
197 * @data: mount options
198 *
199 */
200
201static int
202v9fs_unix_init(struct v9fs_session_info *v9ses, const char *dev_name,
203 char *data)
204{
205 int rc;
206 struct socket *csocket;
207 struct sockaddr_un sun_server;
208 struct v9fs_transport *trans;
209 struct v9fs_trans_sock *ts;
210
211 rc = 0;
212 csocket = NULL;
213 trans = v9ses->transport;
214
215 if (strlen(dev_name) > UNIX_PATH_MAX) {
216 eprintk(KERN_ERR, "v9fs_trans_unix: address too long: %s\n",
217 dev_name);
218 return -ENOMEM;
219 }
220
221 ts = kmalloc(sizeof(struct v9fs_trans_sock), GFP_KERNEL);
222 if (!ts)
223 return -ENOMEM;
224
225 trans->priv = ts;
226 ts->s = NULL;
227
228 sema_init(&trans->writelock, 1);
229 sema_init(&trans->readlock, 1);
230
231 sun_server.sun_family = PF_UNIX;
232 strcpy(sun_server.sun_path, dev_name);
233 sock_create_kern(PF_UNIX, SOCK_STREAM, 0, &csocket);
234 rc = csocket->ops->connect(csocket, (struct sockaddr *)&sun_server,
235 sizeof(struct sockaddr_un) - 1, 0); /* -1 *is* important */
236 if (rc < 0) {
237 eprintk(KERN_ERR,
238 "v9fs_trans_unix: problem connecting socket: %s: %d\n",
239 dev_name, rc);
240 return rc;
241 }
242 csocket->sk->sk_allocation = GFP_NOIO;
243 ts->s = csocket;
244 trans->status = Connected;
245
246 return 0;
247}
248
249/**
250 * v9fs_sock_close - shutdown socket
251 * @trans: private socket structure
252 *
253 */
254
255static void v9fs_sock_close(struct v9fs_transport *trans)
256{
257 struct v9fs_trans_sock *ts;
258
259 if (!trans)
260 return;
261
262 ts = trans->priv;
263
264 if ((ts) && (ts->s)) {
265 dprintk(DEBUG_TRANS, "closing the socket %p\n", ts->s);
266 sock_release(ts->s);
267 ts->s = NULL;
268 trans->status = Disconnected;
269 dprintk(DEBUG_TRANS, "socket closed\n");
270 }
271
272 if (ts)
273 kfree(ts);
274
275 trans->priv = NULL;
276}
277
278struct v9fs_transport v9fs_trans_tcp = {
279 .init = v9fs_tcp_init,
280 .write = v9fs_sock_send,
281 .read = v9fs_sock_recv,
282 .close = v9fs_sock_close,
283};
284
285struct v9fs_transport v9fs_trans_unix = {
286 .init = v9fs_unix_init,
287 .write = v9fs_sock_send,
288 .read = v9fs_sock_recv,
289 .close = v9fs_sock_close,
290};
diff --git a/fs/9p/transport.h b/fs/9p/transport.h
new file mode 100644
index 0000000000..9e9cd418ef
--- /dev/null
+++ b/fs/9p/transport.h
@@ -0,0 +1,46 @@
1/*
2 * linux/fs/9p/transport.h
3 *
4 * Transport Definition
5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
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:
20 * Free Software Foundation
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02111-1301 USA
23 *
24 */
25
26enum v9fs_transport_status {
27 Connected,
28 Disconnected,
29 Hung,
30};
31
32struct v9fs_transport {
33 enum v9fs_transport_status status;
34 struct semaphore writelock;
35 struct semaphore readlock;
36 void *priv;
37
38 int (*init) (struct v9fs_session_info *, const char *, char *);
39 int (*write) (struct v9fs_transport *, void *, int);
40 int (*read) (struct v9fs_transport *, void *, int);
41 void (*close) (struct v9fs_transport *);
42};
43
44extern struct v9fs_transport v9fs_trans_tcp;
45extern struct v9fs_transport v9fs_trans_unix;
46extern struct v9fs_transport v9fs_trans_fd;
diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
new file mode 100644
index 0000000000..13bdbbab43
--- /dev/null
+++ b/fs/9p/v9fs.c
@@ -0,0 +1,452 @@
1/*
2 * linux/fs/9p/v9fs.c
3 *
4 * This file contains functions assisting in mapping VFS to 9P2000
5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to:
21 * Free Software Foundation
22 * 51 Franklin Street, Fifth Floor
23 * Boston, MA 02111-1301 USA
24 *
25 */
26
27#include <linux/config.h>
28#include <linux/module.h>
29#include <linux/errno.h>
30#include <linux/fs.h>
31#include <linux/parser.h>
32#include <linux/idr.h>
33
34#include "debug.h"
35#include "v9fs.h"
36#include "9p.h"
37#include "v9fs_vfs.h"
38#include "transport.h"
39#include "mux.h"
40#include "conv.h"
41
42/* TODO: sysfs or debugfs interface */
43int v9fs_debug_level = 0; /* feature-rific global debug level */
44
45/*
46 * Option Parsing (code inspired by NFS code)
47 *
48 */
49
50enum {
51 /* Options that take integer arguments */
52 Opt_port, Opt_msize, Opt_uid, Opt_gid, Opt_afid, Opt_debug,
53 Opt_rfdno, Opt_wfdno,
54 /* String options */
55 Opt_name, Opt_remotename,
56 /* Options that take no arguments */
57 Opt_legacy, Opt_nodevmap, Opt_unix, Opt_tcp, Opt_fd,
58 /* Error token */
59 Opt_err
60};
61
62static match_table_t tokens = {
63 {Opt_port, "port=%u"},
64 {Opt_msize, "msize=%u"},
65 {Opt_uid, "uid=%u"},
66 {Opt_gid, "gid=%u"},
67 {Opt_afid, "afid=%u"},
68 {Opt_rfdno, "rfdno=%u"},
69 {Opt_wfdno, "wfdno=%u"},
70 {Opt_debug, "debug=%u"},
71 {Opt_name, "name=%s"},
72 {Opt_remotename, "aname=%s"},
73 {Opt_unix, "proto=unix"},
74 {Opt_tcp, "proto=tcp"},
75 {Opt_fd, "proto=fd"},
76 {Opt_tcp, "tcp"},
77 {Opt_unix, "unix"},
78 {Opt_fd, "fd"},
79 {Opt_legacy, "noextend"},
80 {Opt_nodevmap, "nodevmap"},
81 {Opt_err, NULL}
82};
83
84/*
85 * Parse option string.
86 */
87
88/**
89 * v9fs_parse_options - parse mount options into session structure
90 * @options: options string passed from mount
91 * @v9ses: existing v9fs session information
92 *
93 */
94
95static void v9fs_parse_options(char *options, struct v9fs_session_info *v9ses)
96{
97 char *p;
98 substring_t args[MAX_OPT_ARGS];
99 int option;
100 int ret;
101
102 /* setup defaults */
103 v9ses->port = V9FS_PORT;
104 v9ses->maxdata = 9000;
105 v9ses->proto = PROTO_TCP;
106 v9ses->extended = 1;
107 v9ses->afid = ~0;
108 v9ses->debug = 0;
109 v9ses->rfdno = ~0;
110 v9ses->wfdno = ~0;
111
112 if (!options)
113 return;
114
115 while ((p = strsep(&options, ",")) != NULL) {
116 int token;
117 if (!*p)
118 continue;
119 token = match_token(p, tokens, args);
120 if (token < Opt_name) {
121 if ((ret = match_int(&args[0], &option)) < 0) {
122 dprintk(DEBUG_ERROR,
123 "integer field, but no integer?\n");
124 continue;
125 }
126
127 }
128 switch (token) {
129 case Opt_port:
130 v9ses->port = option;
131 break;
132 case Opt_msize:
133 v9ses->maxdata = option;
134 break;
135 case Opt_uid:
136 v9ses->uid = option;
137 break;
138 case Opt_gid:
139 v9ses->gid = option;
140 break;
141 case Opt_afid:
142 v9ses->afid = option;
143 break;
144 case Opt_rfdno:
145 v9ses->rfdno = option;
146 break;
147 case Opt_wfdno:
148 v9ses->wfdno = option;
149 break;
150 case Opt_debug:
151 v9ses->debug = option;
152 break;
153 case Opt_tcp:
154 v9ses->proto = PROTO_TCP;
155 break;
156 case Opt_unix:
157 v9ses->proto = PROTO_UNIX;
158 break;
159 case Opt_fd:
160 v9ses->proto = PROTO_FD;
161 break;
162 case Opt_name:
163 match_strcpy(v9ses->name, &args[0]);
164 break;
165 case Opt_remotename:
166 match_strcpy(v9ses->remotename, &args[0]);
167 break;
168 case Opt_legacy:
169 v9ses->extended = 0;
170 break;
171 case Opt_nodevmap:
172 v9ses->nodev = 1;
173 break;
174 default:
175 continue;
176 }
177 }
178}
179
180/**
181 * v9fs_inode2v9ses - safely extract v9fs session info from super block
182 * @inode: inode to extract information from
183 *
184 * Paranoid function to extract v9ses information from superblock,
185 * if anything is missing it will report an error.
186 *
187 */
188
189struct v9fs_session_info *v9fs_inode2v9ses(struct inode *inode)
190{
191 return (inode->i_sb->s_fs_info);
192}
193
194/**
195 * v9fs_get_idpool - allocate numeric id from pool
196 * @p - pool to allocate from
197 *
198 * XXX - This seems to be an awful generic function, should it be in idr.c with
199 * the lock included in struct idr?
200 */
201
202int v9fs_get_idpool(struct v9fs_idpool *p)
203{
204 int i = 0;
205 int error;
206
207retry:
208 if (idr_pre_get(&p->pool, GFP_KERNEL) == 0)
209 return 0;
210
211 if (down_interruptible(&p->lock) == -EINTR) {
212 eprintk(KERN_WARNING, "Interrupted while locking\n");
213 return -1;
214 }
215
216 error = idr_get_new(&p->pool, NULL, &i);
217 up(&p->lock);
218
219 if (error == -EAGAIN)
220 goto retry;
221 else if (error)
222 return -1;
223
224 return i;
225}
226
227/**
228 * v9fs_put_idpool - release numeric id from pool
229 * @p - pool to allocate from
230 *
231 * XXX - This seems to be an awful generic function, should it be in idr.c with
232 * the lock included in struct idr?
233 */
234
235void v9fs_put_idpool(int id, struct v9fs_idpool *p)
236{
237 if (down_interruptible(&p->lock) == -EINTR) {
238 eprintk(KERN_WARNING, "Interrupted while locking\n");
239 return;
240 }
241 idr_remove(&p->pool, id);
242 up(&p->lock);
243}
244
245/**
246 * v9fs_session_init - initialize session
247 * @v9ses: session information structure
248 * @dev_name: device being mounted
249 * @data: options
250 *
251 */
252
253int
254v9fs_session_init(struct v9fs_session_info *v9ses,
255 const char *dev_name, char *data)
256{
257 struct v9fs_fcall *fcall = NULL;
258 struct v9fs_transport *trans_proto;
259 int n = 0;
260 int newfid = -1;
261 int retval = -EINVAL;
262
263 v9ses->name = __getname();
264 if (!v9ses->name)
265 return -ENOMEM;
266
267 v9ses->remotename = __getname();
268 if (!v9ses->remotename) {
269 putname(v9ses->name);
270 return -ENOMEM;
271 }
272
273 strcpy(v9ses->name, V9FS_DEFUSER);
274 strcpy(v9ses->remotename, V9FS_DEFANAME);
275
276 v9fs_parse_options(data, v9ses);
277
278 /* set global debug level */
279 v9fs_debug_level = v9ses->debug;
280
281 /* id pools that are session-dependent: FIDs and TIDs */
282 idr_init(&v9ses->fidpool.pool);
283 init_MUTEX(&v9ses->fidpool.lock);
284 idr_init(&v9ses->tidpool.pool);
285 init_MUTEX(&v9ses->tidpool.lock);
286
287
288 switch (v9ses->proto) {
289 case PROTO_TCP:
290 trans_proto = &v9fs_trans_tcp;
291 break;
292 case PROTO_UNIX:
293 trans_proto = &v9fs_trans_unix;
294 *v9ses->remotename = 0;
295 break;
296 case PROTO_FD:
297 trans_proto = &v9fs_trans_fd;
298 *v9ses->remotename = 0;
299 break;
300 default:
301 printk(KERN_ERR "v9fs: Bad mount protocol %d\n", v9ses->proto);
302 retval = -ENOPROTOOPT;
303 goto SessCleanUp;
304 };
305
306 v9ses->transport = trans_proto;
307
308 if ((retval = v9ses->transport->init(v9ses, dev_name, data)) < 0) {
309 eprintk(KERN_ERR, "problem initializing transport\n");
310 goto SessCleanUp;
311 }
312
313 v9ses->inprogress = 0;
314 v9ses->shutdown = 0;
315 v9ses->session_hung = 0;
316
317 if ((retval = v9fs_mux_init(v9ses, dev_name)) < 0) {
318 dprintk(DEBUG_ERROR, "problem initializing mux\n");
319 goto SessCleanUp;
320 }
321
322 if (v9ses->afid == ~0) {
323 if (v9ses->extended)
324 retval =
325 v9fs_t_version(v9ses, v9ses->maxdata, "9P2000.u",
326 &fcall);
327 else
328 retval = v9fs_t_version(v9ses, v9ses->maxdata, "9P2000",
329 &fcall);
330
331 if (retval < 0) {
332 dprintk(DEBUG_ERROR, "v9fs_t_version failed\n");
333 goto FreeFcall;
334 }
335
336 /* Really should check for 9P1 and report error */
337 if (!strcmp(fcall->params.rversion.version, "9P2000.u")) {
338 dprintk(DEBUG_9P, "9P2000 UNIX extensions enabled\n");
339 v9ses->extended = 1;
340 } else {
341 dprintk(DEBUG_9P, "9P2000 legacy mode enabled\n");
342 v9ses->extended = 0;
343 }
344
345 n = fcall->params.rversion.msize;
346 kfree(fcall);
347
348 if (n < v9ses->maxdata)
349 v9ses->maxdata = n;
350 }
351
352 newfid = v9fs_get_idpool(&v9ses->fidpool);
353 if (newfid < 0) {
354 eprintk(KERN_WARNING, "couldn't allocate FID\n");
355 retval = -ENOMEM;
356 goto SessCleanUp;
357 }
358 /* it is a little bit ugly, but we have to prevent newfid */
359 /* being the same as afid, so if it is, get a new fid */
360 if (v9ses->afid != ~0 && newfid == v9ses->afid) {
361 newfid = v9fs_get_idpool(&v9ses->fidpool);
362 if (newfid < 0) {
363 eprintk(KERN_WARNING, "couldn't allocate FID\n");
364 retval = -ENOMEM;
365 goto SessCleanUp;
366 }
367 }
368
369 if ((retval =
370 v9fs_t_attach(v9ses, v9ses->name, v9ses->remotename, newfid,
371 v9ses->afid, NULL))
372 < 0) {
373 dprintk(DEBUG_ERROR, "cannot attach\n");
374 goto SessCleanUp;
375 }
376
377 if (v9ses->afid != ~0) {
378 if (v9fs_t_clunk(v9ses, v9ses->afid, NULL))
379 dprintk(DEBUG_ERROR, "clunk failed\n");
380 }
381
382 return newfid;
383
384 FreeFcall:
385 kfree(fcall);
386
387 SessCleanUp:
388 v9fs_session_close(v9ses);
389 return retval;
390}
391
392/**
393 * v9fs_session_close - shutdown a session
394 * @v9ses: session information structure
395 *
396 */
397
398void v9fs_session_close(struct v9fs_session_info *v9ses)
399{
400 if (v9ses->recvproc) {
401 send_sig(SIGKILL, v9ses->recvproc, 1);
402 wait_for_completion(&v9ses->proccmpl);
403 }
404
405 if (v9ses->transport)
406 v9ses->transport->close(v9ses->transport);
407
408 putname(v9ses->name);
409 putname(v9ses->remotename);
410}
411
412/**
413 * v9fs_session_cancel - mark transport as disconnected
414 * and cancel all pending requests.
415 */
416void v9fs_session_cancel(struct v9fs_session_info *v9ses) {
417 v9ses->transport->status = Disconnected;
418 v9fs_mux_cancel_requests(v9ses, -EIO);
419}
420
421extern int v9fs_error_init(void);
422
423/**
424 * v9fs_init - Initialize module
425 *
426 */
427
428static int __init init_v9fs(void)
429{
430 v9fs_error_init();
431
432 printk(KERN_INFO "Installing v9fs 9P2000 file system support\n");
433
434 return register_filesystem(&v9fs_fs_type);
435}
436
437/**
438 * v9fs_init - shutdown module
439 *
440 */
441
442static void __exit exit_v9fs(void)
443{
444 unregister_filesystem(&v9fs_fs_type);
445}
446
447module_init(init_v9fs)
448module_exit(exit_v9fs)
449
450MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
451MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>");
452MODULE_LICENSE("GPL");
diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h
new file mode 100644
index 0000000000..45dcef42bd
--- /dev/null
+++ b/fs/9p/v9fs.h
@@ -0,0 +1,103 @@
1/*
2 * V9FS definitions.
3 *
4 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
5 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
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:
19 * Free Software Foundation
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02111-1301 USA
22 *
23 */
24
25/*
26 * Idpool structure provides lock and id management
27 *
28 */
29
30struct v9fs_idpool {
31 struct semaphore lock;
32 struct idr pool;
33};
34
35/*
36 * Session structure provides information for an opened session
37 *
38 */
39
40struct v9fs_session_info {
41 /* options */
42 unsigned int maxdata;
43 unsigned char extended; /* set to 1 if we are using UNIX extensions */
44 unsigned char nodev; /* set to 1 if no disable device mapping */
45 unsigned short port; /* port to connect to */
46 unsigned short debug; /* debug level */
47 unsigned short proto; /* protocol to use */
48 unsigned int afid; /* authentication fid */
49 unsigned int rfdno; /* read file descriptor number */
50 unsigned int wfdno; /* write file descriptor number */
51
52
53 char *name; /* user name to mount as */
54 char *remotename; /* name of remote hierarchy being mounted */
55 unsigned int uid; /* default uid/muid for legacy support */
56 unsigned int gid; /* default gid for legacy support */
57
58 /* book keeping */
59 struct v9fs_idpool fidpool; /* The FID pool for file descriptors */
60 struct v9fs_idpool tidpool; /* The TID pool for transactions ids */
61
62 /* transport information */
63 struct v9fs_transport *transport;
64
65 int inprogress; /* session in progress => true */
66 int shutdown; /* session shutting down. no more attaches. */
67 unsigned char session_hung;
68
69 /* mux private data */
70 struct v9fs_fcall *curfcall;
71 wait_queue_head_t read_wait;
72 struct completion fcread;
73 struct completion proccmpl;
74 struct task_struct *recvproc;
75
76 spinlock_t muxlock;
77 struct list_head mux_fcalls;
78};
79
80/* possible values of ->proto */
81enum {
82 PROTO_TCP,
83 PROTO_UNIX,
84 PROTO_FD,
85};
86
87int v9fs_session_init(struct v9fs_session_info *, const char *, char *);
88struct v9fs_session_info *v9fs_inode2v9ses(struct inode *);
89void v9fs_session_close(struct v9fs_session_info *v9ses);
90int v9fs_get_idpool(struct v9fs_idpool *p);
91void v9fs_put_idpool(int id, struct v9fs_idpool *p);
92void v9fs_session_cancel(struct v9fs_session_info *v9ses);
93
94#define V9FS_MAGIC 0x01021997
95
96/* other default globals */
97#define V9FS_PORT 564
98#define V9FS_DEFUSER "nobody"
99#define V9FS_DEFANAME ""
100
101/* inital pool sizes for fids and tags */
102#define V9FS_START_FIDS 8192
103#define V9FS_START_TIDS 256
diff --git a/fs/9p/v9fs_vfs.h b/fs/9p/v9fs_vfs.h
new file mode 100644
index 0000000000..2f2cea7ee3
--- /dev/null
+++ b/fs/9p/v9fs_vfs.h
@@ -0,0 +1,53 @@
1/*
2 * V9FS VFS extensions.
3 *
4 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
5 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
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:
19 * Free Software Foundation
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02111-1301 USA
22 *
23 */
24
25/* plan9 semantics are that created files are implicitly opened.
26 * But linux semantics are that you call create, then open.
27 * the plan9 approach is superior as it provides an atomic
28 * open.
29 * we track the create fid here. When the file is opened, if fidopen is
30 * non-zero, we use the fid and can skip some steps.
31 * there may be a better way to do this, but I don't know it.
32 * one BAD way is to clunk the fid on create, then open it again:
33 * you lose the atomicity of file open
34 */
35
36/* special case:
37 * unlink calls remove, which is an implicit clunk. So we have to track
38 * that kind of thing so that we don't try to clunk a dead fid.
39 */
40
41extern struct file_system_type v9fs_fs_type;
42extern struct file_operations v9fs_file_operations;
43extern struct file_operations v9fs_dir_operations;
44extern struct dentry_operations v9fs_dentry_operations;
45
46struct inode *v9fs_get_inode(struct super_block *sb, int mode);
47ino_t v9fs_qid2ino(struct v9fs_qid *qid);
48void v9fs_mistat2inode(struct v9fs_stat *, struct inode *,
49 struct super_block *);
50int v9fs_dir_release(struct inode *inode, struct file *filp);
51int v9fs_file_open(struct inode *inode, struct file *file);
52void v9fs_inode2mistat(struct inode *inode, struct v9fs_stat *mistat);
53void v9fs_dentry_release(struct dentry *);
diff --git a/fs/9p/vfs_dentry.c b/fs/9p/vfs_dentry.c
new file mode 100644
index 0000000000..306c96741f
--- /dev/null
+++ b/fs/9p/vfs_dentry.c
@@ -0,0 +1,126 @@
1/*
2 * linux/fs/9p/vfs_dentry.c
3 *
4 * This file contians vfs dentry ops for the 9P2000 protocol.
5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to:
21 * Free Software Foundation
22 * 51 Franklin Street, Fifth Floor
23 * Boston, MA 02111-1301 USA
24 *
25 */
26
27#include <linux/module.h>
28#include <linux/errno.h>
29#include <linux/fs.h>
30#include <linux/file.h>
31#include <linux/pagemap.h>
32#include <linux/stat.h>
33#include <linux/string.h>
34#include <linux/smp_lock.h>
35#include <linux/inet.h>
36#include <linux/namei.h>
37#include <linux/idr.h>
38
39#include "debug.h"
40#include "v9fs.h"
41#include "9p.h"
42#include "v9fs_vfs.h"
43#include "conv.h"
44#include "fid.h"
45
46/**
47 * v9fs_dentry_validate - VFS dcache hook to validate cache
48 * @dentry: dentry that is being validated
49 * @nd: path data
50 *
51 * dcache really shouldn't be used for 9P2000 as at all due to
52 * potential attached semantics to directory traversal (walk).
53 *
54 * FUTURE: look into how to use dcache to allow multi-stage
55 * walks in Plan 9 & potential for better dcache operation which
56 * would remain valid for Plan 9 semantics. Older versions
57 * had validation via stat for those interested. However, since
58 * stat has the same approximate overhead as walk there really
59 * is no difference. The only improvement would be from a
60 * time-decay cache like NFS has and that undermines the
61 * synchronous nature of 9P2000.
62 *
63 */
64
65static int v9fs_dentry_validate(struct dentry *dentry, struct nameidata *nd)
66{
67 struct dentry *dc = current->fs->pwd;
68
69 dprintk(DEBUG_VFS, "dentry: %s (%p)\n", dentry->d_iname, dentry);
70 if (v9fs_fid_lookup(dentry, FID_OP)) {
71 dprintk(DEBUG_VFS, "VALID\n");
72 return 1;
73 }
74
75 while (dc != NULL) {
76 if (dc == dentry) {
77 dprintk(DEBUG_VFS, "VALID\n");
78 return 1;
79 }
80 if (dc == dc->d_parent)
81 break;
82
83 dc = dc->d_parent;
84 }
85
86 dprintk(DEBUG_VFS, "INVALID\n");
87 return 0;
88}
89
90/**
91 * v9fs_dentry_release - called when dentry is going to be freed
92 * @dentry: dentry that is being release
93 *
94 */
95
96void v9fs_dentry_release(struct dentry *dentry)
97{
98 dprintk(DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
99
100 if (dentry->d_fsdata != NULL) {
101 struct list_head *fid_list = dentry->d_fsdata;
102 struct v9fs_fid *temp = NULL;
103 struct v9fs_fid *current_fid = NULL;
104 struct v9fs_fcall *fcall = NULL;
105
106 list_for_each_entry_safe(current_fid, temp, fid_list, list) {
107 if (v9fs_t_clunk
108 (current_fid->v9ses, current_fid->fid, &fcall))
109 dprintk(DEBUG_ERROR, "clunk failed: %s\n",
110 FCALL_ERROR(fcall));
111
112 v9fs_put_idpool(current_fid->fid,
113 &current_fid->v9ses->fidpool);
114
115 kfree(fcall);
116 v9fs_fid_destroy(current_fid);
117 }
118
119 kfree(dentry->d_fsdata); /* free the list_head */
120 }
121}
122
123struct dentry_operations v9fs_dentry_operations = {
124 .d_revalidate = v9fs_dentry_validate,
125 .d_release = v9fs_dentry_release,
126};
diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c
new file mode 100644
index 0000000000..c478a73841
--- /dev/null
+++ b/fs/9p/vfs_dir.c
@@ -0,0 +1,226 @@
1/*
2 * linux/fs/9p/vfs_dir.c
3 *
4 * This file contains vfs directory ops for the 9P2000 protocol.
5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to:
21 * Free Software Foundation
22 * 51 Franklin Street, Fifth Floor
23 * Boston, MA 02111-1301 USA
24 *
25 */
26
27#include <linux/module.h>
28#include <linux/errno.h>
29#include <linux/fs.h>
30#include <linux/file.h>
31#include <linux/stat.h>
32#include <linux/string.h>
33#include <linux/smp_lock.h>
34#include <linux/inet.h>
35#include <linux/idr.h>
36
37#include "debug.h"
38#include "v9fs.h"
39#include "9p.h"
40#include "v9fs_vfs.h"
41#include "conv.h"
42#include "fid.h"
43
44/**
45 * dt_type - return file type
46 * @mistat: mistat structure
47 *
48 */
49
50static inline int dt_type(struct v9fs_stat *mistat)
51{
52 unsigned long perm = mistat->mode;
53 int rettype = DT_REG;
54
55 if (perm & V9FS_DMDIR)
56 rettype = DT_DIR;
57 if (perm & V9FS_DMSYMLINK)
58 rettype = DT_LNK;
59
60 return rettype;
61}
62
63/**
64 * v9fs_dir_readdir - read a directory
65 * @filep: opened file structure
66 * @dirent: directory structure ???
67 * @filldir: function to populate directory structure ???
68 *
69 */
70
71static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
72{
73 struct v9fs_fcall *fcall = NULL;
74 struct inode *inode = filp->f_dentry->d_inode;
75 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
76 struct v9fs_fid *file = filp->private_data;
77 unsigned int i, n;
78 int fid = -1;
79 int ret = 0;
80 struct v9fs_stat *mi = NULL;
81 int over = 0;
82
83 dprintk(DEBUG_VFS, "name %s\n", filp->f_dentry->d_name.name);
84
85 fid = file->fid;
86
87 mi = kmalloc(v9ses->maxdata, GFP_KERNEL);
88 if (!mi)
89 return -ENOMEM;
90
91 if (file->rdir_fcall && (filp->f_pos != file->rdir_pos)) {
92 kfree(file->rdir_fcall);
93 file->rdir_fcall = NULL;
94 }
95
96 if (file->rdir_fcall) {
97 n = file->rdir_fcall->params.rread.count;
98 i = file->rdir_fpos;
99 while (i < n) {
100 int s = v9fs_deserialize_stat(v9ses,
101 file->rdir_fcall->params.rread.data + i,
102 n - i, mi, v9ses->maxdata);
103
104 if (s == 0) {
105 dprintk(DEBUG_ERROR,
106 "error while deserializing mistat\n");
107 ret = -EIO;
108 goto FreeStructs;
109 }
110
111 over = filldir(dirent, mi->name, strlen(mi->name),
112 filp->f_pos, v9fs_qid2ino(&mi->qid),
113 dt_type(mi));
114
115 if (over) {
116 file->rdir_fpos = i;
117 file->rdir_pos = filp->f_pos;
118 break;
119 }
120
121 i += s;
122 filp->f_pos += s;
123 }
124
125 if (!over) {
126 kfree(file->rdir_fcall);
127 file->rdir_fcall = NULL;
128 }
129 }
130
131 while (!over) {
132 ret = v9fs_t_read(v9ses, fid, filp->f_pos,
133 v9ses->maxdata-V9FS_IOHDRSZ, &fcall);
134 if (ret < 0) {
135 dprintk(DEBUG_ERROR, "error while reading: %d: %p\n",
136 ret, fcall);
137 goto FreeStructs;
138 } else if (ret == 0)
139 break;
140
141 n = ret;
142 i = 0;
143 while (i < n) {
144 int s = v9fs_deserialize_stat(v9ses,
145 fcall->params.rread.data + i, n - i, mi,
146 v9ses->maxdata);
147
148 if (s == 0) {
149 dprintk(DEBUG_ERROR,
150 "error while deserializing mistat\n");
151 return -EIO;
152 }
153
154 over = filldir(dirent, mi->name, strlen(mi->name),
155 filp->f_pos, v9fs_qid2ino(&mi->qid),
156 dt_type(mi));
157
158 if (over) {
159 file->rdir_fcall = fcall;
160 file->rdir_fpos = i;
161 file->rdir_pos = filp->f_pos;
162 fcall = NULL;
163 break;
164 }
165
166 i += s;
167 filp->f_pos += s;
168 }
169
170 kfree(fcall);
171 }
172
173 FreeStructs:
174 kfree(fcall);
175 kfree(mi);
176 return ret;
177}
178
179/**
180 * v9fs_dir_release - close a directory
181 * @inode: inode of the directory
182 * @filp: file pointer to a directory
183 *
184 */
185
186int v9fs_dir_release(struct inode *inode, struct file *filp)
187{
188 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
189 struct v9fs_fid *fid = filp->private_data;
190 int fidnum = -1;
191
192 dprintk(DEBUG_VFS, "inode: %p filp: %p fid: %d\n", inode, filp,
193 fid->fid);
194 fidnum = fid->fid;
195
196 filemap_fdatawrite(inode->i_mapping);
197 filemap_fdatawait(inode->i_mapping);
198
199 if (fidnum >= 0) {
200 fid->fidopen--;
201 dprintk(DEBUG_VFS, "fidopen: %d v9f->fid: %d\n", fid->fidopen,
202 fid->fid);
203
204 if (fid->fidopen == 0) {
205 if (v9fs_t_clunk(v9ses, fidnum, NULL))
206 dprintk(DEBUG_ERROR, "clunk failed\n");
207
208 v9fs_put_idpool(fid->fid, &v9ses->fidpool);
209 }
210
211 kfree(fid->rdir_fcall);
212
213 filp->private_data = NULL;
214 v9fs_fid_destroy(fid);
215 }
216
217 d_drop(filp->f_dentry);
218 return 0;
219}
220
221struct file_operations v9fs_dir_operations = {
222 .read = generic_read_dir,
223 .readdir = v9fs_dir_readdir,
224 .open = v9fs_file_open,
225 .release = v9fs_dir_release,
226};
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
new file mode 100644
index 0000000000..1f8ae7d580
--- /dev/null
+++ b/fs/9p/vfs_file.c
@@ -0,0 +1,401 @@
1/*
2 * linux/fs/9p/vfs_file.c
3 *
4 * This file contians vfs file ops for 9P2000.
5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to:
21 * Free Software Foundation
22 * 51 Franklin Street, Fifth Floor
23 * Boston, MA 02111-1301 USA
24 *
25 */
26
27#include <linux/module.h>
28#include <linux/errno.h>
29#include <linux/fs.h>
30#include <linux/file.h>
31#include <linux/stat.h>
32#include <linux/string.h>
33#include <linux/smp_lock.h>
34#include <linux/inet.h>
35#include <linux/version.h>
36#include <linux/list.h>
37#include <asm/uaccess.h>
38#include <linux/idr.h>
39
40#include "debug.h"
41#include "v9fs.h"
42#include "9p.h"
43#include "v9fs_vfs.h"
44#include "fid.h"
45
46/**
47 * v9fs_file_open - open a file (or directory)
48 * @inode: inode to be opened
49 * @file: file being opened
50 *
51 */
52
53int v9fs_file_open(struct inode *inode, struct file *file)
54{
55 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
56 struct v9fs_fid *v9fid = v9fs_fid_lookup(file->f_dentry, FID_WALK);
57 struct v9fs_fid *v9newfid = NULL;
58 struct v9fs_fcall *fcall = NULL;
59 int open_mode = 0;
60 unsigned int iounit = 0;
61 int newfid = -1;
62 long result = -1;
63
64 dprintk(DEBUG_VFS, "inode: %p file: %p v9fid= %p\n", inode, file,
65 v9fid);
66
67 if (!v9fid) {
68 struct dentry *dentry = file->f_dentry;
69 dprintk(DEBUG_ERROR, "Couldn't resolve fid from dentry\n");
70
71 /* XXX - some duplication from lookup, generalize later */
72 /* basically vfs_lookup is too heavy weight */
73 v9fid = v9fs_fid_lookup(file->f_dentry, FID_OP);
74 if (!v9fid)
75 return -EBADF;
76
77 v9fid = v9fs_fid_lookup(dentry->d_parent, FID_WALK);
78 if (!v9fid)
79 return -EBADF;
80
81 newfid = v9fs_get_idpool(&v9ses->fidpool);
82 if (newfid < 0) {
83 eprintk(KERN_WARNING, "newfid fails!\n");
84 return -ENOSPC;
85 }
86
87 result =
88 v9fs_t_walk(v9ses, v9fid->fid, newfid,
89 (char *)file->f_dentry->d_name.name, NULL);
90 if (result < 0) {
91 v9fs_put_idpool(newfid, &v9ses->fidpool);
92 dprintk(DEBUG_ERROR, "rewalk didn't work\n");
93 return -EBADF;
94 }
95
96 v9fid = v9fs_fid_create(dentry);
97 if (v9fid == NULL) {
98 dprintk(DEBUG_ERROR, "couldn't insert\n");
99 return -ENOMEM;
100 }
101 v9fid->fid = newfid;
102 }
103
104 if (v9fid->fidcreate) {
105 /* create case */
106 newfid = v9fid->fid;
107 iounit = v9fid->iounit;
108 v9fid->fidcreate = 0;
109 } else {
110 if (!S_ISDIR(inode->i_mode))
111 newfid = v9fid->fid;
112 else {
113 newfid = v9fs_get_idpool(&v9ses->fidpool);
114 if (newfid < 0) {
115 eprintk(KERN_WARNING, "allocation failed\n");
116 return -ENOSPC;
117 }
118 /* This would be a somewhat critical clone */
119 result =
120 v9fs_t_walk(v9ses, v9fid->fid, newfid, NULL,
121 &fcall);
122 if (result < 0) {
123 dprintk(DEBUG_ERROR, "clone error: %s\n",
124 FCALL_ERROR(fcall));
125 kfree(fcall);
126 return result;
127 }
128
129 v9newfid = v9fs_fid_create(file->f_dentry);
130 v9newfid->fid = newfid;
131 v9newfid->qid = v9fid->qid;
132 v9newfid->iounit = v9fid->iounit;
133 v9newfid->fidopen = 0;
134 v9newfid->fidclunked = 0;
135 v9newfid->v9ses = v9ses;
136 v9fid = v9newfid;
137 kfree(fcall);
138 }
139
140 /* TODO: do special things for O_EXCL, O_NOFOLLOW, O_SYNC */
141 /* translate open mode appropriately */
142 open_mode = file->f_flags & 0x3;
143
144 if (file->f_flags & O_EXCL)
145 open_mode |= V9FS_OEXCL;
146
147 if (v9ses->extended) {
148 if (file->f_flags & O_TRUNC)
149 open_mode |= V9FS_OTRUNC;
150
151 if (file->f_flags & O_APPEND)
152 open_mode |= V9FS_OAPPEND;
153 }
154
155 result = v9fs_t_open(v9ses, newfid, open_mode, &fcall);
156 if (result < 0) {
157 dprintk(DEBUG_ERROR,
158 "open failed, open_mode 0x%x: %s\n", open_mode,
159 FCALL_ERROR(fcall));
160 kfree(fcall);
161 return result;
162 }
163
164 iounit = fcall->params.ropen.iounit;
165 kfree(fcall);
166 }
167
168
169 file->private_data = v9fid;
170
171 v9fid->rdir_pos = 0;
172 v9fid->rdir_fcall = NULL;
173 v9fid->fidopen = 1;
174 v9fid->filp = file;
175 v9fid->iounit = iounit;
176
177 return 0;
178}
179
180/**
181 * v9fs_file_lock - lock a file (or directory)
182 * @inode: inode to be opened
183 * @file: file being opened
184 *
185 * XXX - this looks like a local only lock, we should extend into 9P
186 * by using open exclusive
187 */
188
189static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl)
190{
191 int res = 0;
192 struct inode *inode = filp->f_dentry->d_inode;
193
194 dprintk(DEBUG_VFS, "filp: %p lock: %p\n", filp, fl);
195
196 /* No mandatory locks */
197 if ((inode->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID)
198 return -ENOLCK;
199
200 if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) {
201 filemap_fdatawrite(inode->i_mapping);
202 filemap_fdatawait(inode->i_mapping);
203 invalidate_inode_pages(&inode->i_data);
204 }
205
206 return res;
207}
208
209/**
210 * v9fs_read - read from a file (internal)
211 * @filep: file pointer to read
212 * @data: data buffer to read data into
213 * @count: size of buffer
214 * @offset: offset at which to read data
215 *
216 */
217
218static ssize_t
219v9fs_read(struct file *filp, char *buffer, size_t count, loff_t * offset)
220{
221 struct inode *inode = filp->f_dentry->d_inode;
222 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
223 struct v9fs_fid *v9f = filp->private_data;
224 struct v9fs_fcall *fcall = NULL;
225 int fid = v9f->fid;
226 int rsize = 0;
227 int result = 0;
228 int total = 0;
229
230 dprintk(DEBUG_VFS, "\n");
231
232 rsize = v9ses->maxdata - V9FS_IOHDRSZ;
233 if (v9f->iounit != 0 && rsize > v9f->iounit)
234 rsize = v9f->iounit;
235
236 do {
237 if (count < rsize)
238 rsize = count;
239
240 result = v9fs_t_read(v9ses, fid, *offset, rsize, &fcall);
241
242 if (result < 0) {
243 printk(KERN_ERR "9P2000: v9fs_t_read returned %d\n",
244 result);
245
246 kfree(fcall);
247 return total;
248 } else
249 *offset += result;
250
251 /* XXX - extra copy */
252 memcpy(buffer, fcall->params.rread.data, result);
253 count -= result;
254 buffer += result;
255 total += result;
256
257 kfree(fcall);
258
259 if (result < rsize)
260 break;
261 } while (count);
262
263 return total;
264}
265
266/**
267 * v9fs_file_read - read from a file
268 * @filep: file pointer to read
269 * @data: data buffer to read data into
270 * @count: size of buffer
271 * @offset: offset at which to read data
272 *
273 */
274
275static ssize_t
276v9fs_file_read(struct file *filp, char __user * data, size_t count,
277 loff_t * offset)
278{
279 int retval = -1;
280 int ret = 0;
281 char *buffer;
282
283 buffer = kmalloc(count, GFP_KERNEL);
284 if (!buffer)
285 return -ENOMEM;
286
287 retval = v9fs_read(filp, buffer, count, offset);
288 if (retval > 0) {
289 if ((ret = copy_to_user(data, buffer, retval)) != 0) {
290 dprintk(DEBUG_ERROR, "Problem copying to user %d\n",
291 ret);
292 retval = ret;
293 }
294 }
295
296 kfree(buffer);
297
298 return retval;
299}
300
301/**
302 * v9fs_write - write to a file
303 * @filep: file pointer to write
304 * @data: data buffer to write data from
305 * @count: size of buffer
306 * @offset: offset at which to write data
307 *
308 */
309
310static ssize_t
311v9fs_write(struct file *filp, char *buffer, size_t count, loff_t * offset)
312{
313 struct inode *inode = filp->f_dentry->d_inode;
314 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
315 struct v9fs_fid *v9fid = filp->private_data;
316 struct v9fs_fcall *fcall;
317 int fid = v9fid->fid;
318 int result = -EIO;
319 int rsize = 0;
320 int total = 0;
321
322 dprintk(DEBUG_VFS, "data %p count %d offset %x\n", buffer, (int)count,
323 (int)*offset);
324 rsize = v9ses->maxdata - V9FS_IOHDRSZ;
325 if (v9fid->iounit != 0 && rsize > v9fid->iounit)
326 rsize = v9fid->iounit;
327
328 dump_data(buffer, count);
329
330 do {
331 if (count < rsize)
332 rsize = count;
333
334 result =
335 v9fs_t_write(v9ses, fid, *offset, rsize, buffer, &fcall);
336 if (result < 0) {
337 eprintk(KERN_ERR, "error while writing: %s(%d)\n",
338 FCALL_ERROR(fcall), result);
339 kfree(fcall);
340 return result;
341 } else
342 *offset += result;
343
344 kfree(fcall);
345
346 if (result != rsize) {
347 eprintk(KERN_ERR,
348 "short write: v9fs_t_write returned %d\n",
349 result);
350 break;
351 }
352
353 count -= result;
354 buffer += result;
355 total += result;
356 } while (count);
357
358 return total;
359}
360
361/**
362 * v9fs_file_write - write to a file
363 * @filep: file pointer to write
364 * @data: data buffer to write data from
365 * @count: size of buffer
366 * @offset: offset at which to write data
367 *
368 */
369
370static ssize_t
371v9fs_file_write(struct file *filp, const char __user * data,
372 size_t count, loff_t * offset)
373{
374 int ret = -1;
375 char *buffer;
376
377 buffer = kmalloc(count, GFP_KERNEL);
378 if (buffer == NULL)
379 return -ENOMEM;
380
381 ret = copy_from_user(buffer, data, count);
382 if (ret) {
383 dprintk(DEBUG_ERROR, "Problem copying from user\n");
384 ret = -EFAULT;
385 } else {
386 ret = v9fs_write(filp, buffer, count, offset);
387 }
388
389 kfree(buffer);
390
391 return ret;
392}
393
394struct file_operations v9fs_file_operations = {
395 .llseek = generic_file_llseek,
396 .read = v9fs_file_read,
397 .write = v9fs_file_write,
398 .open = v9fs_file_open,
399 .release = v9fs_dir_release,
400 .lock = v9fs_file_lock,
401};
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
new file mode 100644
index 0000000000..0c13fc6000
--- /dev/null
+++ b/fs/9p/vfs_inode.c
@@ -0,0 +1,1338 @@
1/*
2 * linux/fs/9p/vfs_inode.c
3 *
4 * This file contains vfs inode ops for the 9P2000 protocol.
5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to:
21 * Free Software Foundation
22 * 51 Franklin Street, Fifth Floor
23 * Boston, MA 02111-1301 USA
24 *
25 */
26
27#include <linux/module.h>
28#include <linux/errno.h>
29#include <linux/fs.h>
30#include <linux/file.h>
31#include <linux/pagemap.h>
32#include <linux/stat.h>
33#include <linux/string.h>
34#include <linux/smp_lock.h>
35#include <linux/inet.h>
36#include <linux/namei.h>
37#include <linux/idr.h>
38
39#include "debug.h"
40#include "v9fs.h"
41#include "9p.h"
42#include "v9fs_vfs.h"
43#include "conv.h"
44#include "fid.h"
45
46static struct inode_operations v9fs_dir_inode_operations;
47static struct inode_operations v9fs_dir_inode_operations_ext;
48static struct inode_operations v9fs_file_inode_operations;
49static struct inode_operations v9fs_symlink_inode_operations;
50
51/**
52 * unixmode2p9mode - convert unix mode bits to plan 9
53 * @v9ses: v9fs session information
54 * @mode: mode to convert
55 *
56 */
57
58static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode)
59{
60 int res;
61 res = mode & 0777;
62 if (S_ISDIR(mode))
63 res |= V9FS_DMDIR;
64 if (v9ses->extended) {
65 if (S_ISLNK(mode))
66 res |= V9FS_DMSYMLINK;
67 if (v9ses->nodev == 0) {
68 if (S_ISSOCK(mode))
69 res |= V9FS_DMSOCKET;
70 if (S_ISFIFO(mode))
71 res |= V9FS_DMNAMEDPIPE;
72 if (S_ISBLK(mode))
73 res |= V9FS_DMDEVICE;
74 if (S_ISCHR(mode))
75 res |= V9FS_DMDEVICE;
76 }
77
78 if ((mode & S_ISUID) == S_ISUID)
79 res |= V9FS_DMSETUID;
80 if ((mode & S_ISGID) == S_ISGID)
81 res |= V9FS_DMSETGID;
82 if ((mode & V9FS_DMLINK))
83 res |= V9FS_DMLINK;
84 }
85
86 return res;
87}
88
89/**
90 * p9mode2unixmode- convert plan9 mode bits to unix mode bits
91 * @v9ses: v9fs session information
92 * @mode: mode to convert
93 *
94 */
95
96static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode)
97{
98 int res;
99
100 res = mode & 0777;
101
102 if ((mode & V9FS_DMDIR) == V9FS_DMDIR)
103 res |= S_IFDIR;
104 else if ((mode & V9FS_DMSYMLINK) && (v9ses->extended))
105 res |= S_IFLNK;
106 else if ((mode & V9FS_DMSOCKET) && (v9ses->extended)
107 && (v9ses->nodev == 0))
108 res |= S_IFSOCK;
109 else if ((mode & V9FS_DMNAMEDPIPE) && (v9ses->extended)
110 && (v9ses->nodev == 0))
111 res |= S_IFIFO;
112 else if ((mode & V9FS_DMDEVICE) && (v9ses->extended)
113 && (v9ses->nodev == 0))
114 res |= S_IFBLK;
115 else
116 res |= S_IFREG;
117
118 if (v9ses->extended) {
119 if ((mode & V9FS_DMSETUID) == V9FS_DMSETUID)
120 res |= S_ISUID;
121
122 if ((mode & V9FS_DMSETGID) == V9FS_DMSETGID)
123 res |= S_ISGID;
124 }
125
126 return res;
127}
128
129/**
130 * v9fs_blank_mistat - helper function to setup a 9P stat structure
131 * @v9ses: 9P session info (for determining extended mode)
132 * @mistat: structure to initialize
133 *
134 */
135
136static void
137v9fs_blank_mistat(struct v9fs_session_info *v9ses, struct v9fs_stat *mistat)
138{
139 mistat->type = ~0;
140 mistat->dev = ~0;
141 mistat->qid.type = ~0;
142 mistat->qid.version = ~0;
143 *((long long *)&mistat->qid.path) = ~0;
144 mistat->mode = ~0;
145 mistat->atime = ~0;
146 mistat->mtime = ~0;
147 mistat->length = ~0;
148 mistat->name = mistat->data;
149 mistat->uid = mistat->data;
150 mistat->gid = mistat->data;
151 mistat->muid = mistat->data;
152 if (v9ses->extended) {
153 mistat->n_uid = ~0;
154 mistat->n_gid = ~0;
155 mistat->n_muid = ~0;
156 mistat->extension = mistat->data;
157 }
158 *mistat->data = 0;
159}
160
161/**
162 * v9fs_mistat2unix - convert mistat to unix stat
163 * @mistat: Plan 9 metadata (mistat) structure
164 * @buf: unix metadata (stat) structure to populate
165 * @sb: superblock
166 *
167 */
168
169static void
170v9fs_mistat2unix(struct v9fs_stat *mistat, struct stat *buf,
171 struct super_block *sb)
172{
173 struct v9fs_session_info *v9ses = sb ? sb->s_fs_info : NULL;
174
175 buf->st_nlink = 1;
176
177 buf->st_atime = mistat->atime;
178 buf->st_mtime = mistat->mtime;
179 buf->st_ctime = mistat->mtime;
180
181 buf->st_uid = (unsigned short)-1;
182 buf->st_gid = (unsigned short)-1;
183
184 if (v9ses && v9ses->extended) {
185 /* TODO: string to uid mapping via user-space daemon */
186 if (mistat->n_uid != -1)
187 sscanf(mistat->uid, "%x", (unsigned int *)&buf->st_uid);
188
189 if (mistat->n_gid != -1)
190 sscanf(mistat->gid, "%x", (unsigned int *)&buf->st_gid);
191 }
192
193 if (buf->st_uid == (unsigned short)-1)
194 buf->st_uid = v9ses->uid;
195 if (buf->st_gid == (unsigned short)-1)
196 buf->st_gid = v9ses->gid;
197
198 buf->st_mode = p9mode2unixmode(v9ses, mistat->mode);
199 if ((S_ISBLK(buf->st_mode)) || (S_ISCHR(buf->st_mode))) {
200 char type = 0;
201 int major = -1;
202 int minor = -1;
203 sscanf(mistat->extension, "%c %u %u", &type, &major, &minor);
204 switch (type) {
205 case 'c':
206 buf->st_mode &= ~S_IFBLK;
207 buf->st_mode |= S_IFCHR;
208 break;
209 case 'b':
210 break;
211 default:
212 dprintk(DEBUG_ERROR, "Unknown special type %c (%s)\n",
213 type, mistat->extension);
214 };
215 buf->st_rdev = MKDEV(major, minor);
216 } else
217 buf->st_rdev = 0;
218
219 buf->st_size = mistat->length;
220
221 buf->st_blksize = sb->s_blocksize;
222 buf->st_blocks =
223 (buf->st_size + buf->st_blksize - 1) >> sb->s_blocksize_bits;
224}
225
226/**
227 * v9fs_get_inode - helper function to setup an inode
228 * @sb: superblock
229 * @mode: mode to setup inode with
230 *
231 */
232
233struct inode *v9fs_get_inode(struct super_block *sb, int mode)
234{
235 struct inode *inode = NULL;
236 struct v9fs_session_info *v9ses = sb->s_fs_info;
237
238 dprintk(DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
239
240 inode = new_inode(sb);
241 if (inode) {
242 inode->i_mode = mode;
243 inode->i_uid = current->fsuid;
244 inode->i_gid = current->fsgid;
245 inode->i_blksize = sb->s_blocksize;
246 inode->i_blocks = 0;
247 inode->i_rdev = 0;
248 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
249
250 switch (mode & S_IFMT) {
251 case S_IFIFO:
252 case S_IFBLK:
253 case S_IFCHR:
254 case S_IFSOCK:
255 if(!v9ses->extended) {
256 dprintk(DEBUG_ERROR, "special files without extended mode\n");
257 return ERR_PTR(-EINVAL);
258 }
259 init_special_inode(inode, inode->i_mode,
260 inode->i_rdev);
261 break;
262 case S_IFREG:
263 inode->i_op = &v9fs_file_inode_operations;
264 inode->i_fop = &v9fs_file_operations;
265 break;
266 case S_IFLNK:
267 if(!v9ses->extended) {
268 dprintk(DEBUG_ERROR, "extended modes used w/o 9P2000.u\n");
269 return ERR_PTR(-EINVAL);
270 }
271 inode->i_op = &v9fs_symlink_inode_operations;
272 break;
273 case S_IFDIR:
274 inode->i_nlink++;
275 if(v9ses->extended)
276 inode->i_op = &v9fs_dir_inode_operations_ext;
277 else
278 inode->i_op = &v9fs_dir_inode_operations;
279 inode->i_fop = &v9fs_dir_operations;
280 break;
281 default:
282 dprintk(DEBUG_ERROR, "BAD mode 0x%x S_IFMT 0x%x\n",
283 mode, mode & S_IFMT);
284 return ERR_PTR(-EINVAL);
285 }
286 } else {
287 eprintk(KERN_WARNING, "Problem allocating inode\n");
288 return ERR_PTR(-ENOMEM);
289 }
290 return inode;
291}
292
293/**
294 * v9fs_create - helper function to create files and directories
295 * @dir: directory inode file is being created in
296 * @file_dentry: dentry file is being created in
297 * @perm: permissions file is being created with
298 * @open_mode: resulting open mode for file
299 *
300 */
301
302static int
303v9fs_create(struct inode *dir,
304 struct dentry *file_dentry,
305 unsigned int perm, unsigned int open_mode)
306{
307 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
308 struct super_block *sb = dir->i_sb;
309 struct v9fs_fid *dirfid =
310 v9fs_fid_lookup(file_dentry->d_parent, FID_WALK);
311 struct v9fs_fid *fid = NULL;
312 struct inode *file_inode = NULL;
313 struct v9fs_fcall *fcall = NULL;
314 struct v9fs_qid qid;
315 struct stat newstat;
316 int dirfidnum = -1;
317 long newfid = -1;
318 int result = 0;
319 unsigned int iounit = 0;
320
321 perm = unixmode2p9mode(v9ses, perm);
322
323 dprintk(DEBUG_VFS, "dir: %p dentry: %p perm: %o mode: %o\n", dir,
324 file_dentry, perm, open_mode);
325
326 if (!dirfid)
327 return -EBADF;
328
329 dirfidnum = dirfid->fid;
330 if (dirfidnum < 0) {
331 dprintk(DEBUG_ERROR, "No fid for the directory #%lu\n",
332 dir->i_ino);
333 return -EBADF;
334 }
335
336 if (file_dentry->d_inode) {
337 dprintk(DEBUG_ERROR,
338 "Odd. There is an inode for dir %lu, name :%s:\n",
339 dir->i_ino, file_dentry->d_name.name);
340 return -EEXIST;
341 }
342
343 newfid = v9fs_get_idpool(&v9ses->fidpool);
344 if (newfid < 0) {
345 eprintk(KERN_WARNING, "no free fids available\n");
346 return -ENOSPC;
347 }
348
349 result = v9fs_t_walk(v9ses, dirfidnum, newfid, NULL, &fcall);
350 if (result < 0) {
351 dprintk(DEBUG_ERROR, "clone error: %s\n", FCALL_ERROR(fcall));
352 v9fs_put_idpool(newfid, &v9ses->fidpool);
353 newfid = 0;
354 goto CleanUpFid;
355 }
356
357 kfree(fcall);
358
359 result = v9fs_t_create(v9ses, newfid, (char *)file_dentry->d_name.name,
360 perm, open_mode, &fcall);
361 if (result < 0) {
362 dprintk(DEBUG_ERROR, "create fails: %s(%d)\n",
363 FCALL_ERROR(fcall), result);
364
365 goto CleanUpFid;
366 }
367
368 iounit = fcall->params.rcreate.iounit;
369 qid = fcall->params.rcreate.qid;
370 kfree(fcall);
371
372 fid = v9fs_fid_create(file_dentry);
373 if (!fid) {
374 result = -ENOMEM;
375 goto CleanUpFid;
376 }
377
378 fid->fid = newfid;
379 fid->fidopen = 0;
380 fid->fidcreate = 1;
381 fid->qid = qid;
382 fid->iounit = iounit;
383 fid->rdir_pos = 0;
384 fid->rdir_fcall = NULL;
385 fid->v9ses = v9ses;
386
387 if ((perm & V9FS_DMSYMLINK) || (perm & V9FS_DMLINK) ||
388 (perm & V9FS_DMNAMEDPIPE) || (perm & V9FS_DMSOCKET) ||
389 (perm & V9FS_DMDEVICE))
390 return 0;
391
392 result = v9fs_t_stat(v9ses, newfid, &fcall);
393 if (result < 0) {
394 dprintk(DEBUG_ERROR, "stat error: %s(%d)\n", FCALL_ERROR(fcall),
395 result);
396 goto CleanUpFid;
397 }
398
399 v9fs_mistat2unix(fcall->params.rstat.stat, &newstat, sb);
400
401 file_inode = v9fs_get_inode(sb, newstat.st_mode);
402 if ((!file_inode) || IS_ERR(file_inode)) {
403 dprintk(DEBUG_ERROR, "create inode failed\n");
404 result = -EBADF;
405 goto CleanUpFid;
406 }
407
408 v9fs_mistat2inode(fcall->params.rstat.stat, file_inode, sb);
409 kfree(fcall);
410 d_instantiate(file_dentry, file_inode);
411
412 if (perm & V9FS_DMDIR) {
413 if (v9fs_t_clunk(v9ses, newfid, &fcall))
414 dprintk(DEBUG_ERROR, "clunk for mkdir failed: %s\n",
415 FCALL_ERROR(fcall));
416
417 v9fs_put_idpool(newfid, &v9ses->fidpool);
418 kfree(fcall);
419 fid->fidopen = 0;
420 fid->fidcreate = 0;
421 d_drop(file_dentry);
422 }
423
424 return 0;
425
426 CleanUpFid:
427 kfree(fcall);
428
429 if (newfid) {
430 if (v9fs_t_clunk(v9ses, newfid, &fcall))
431 dprintk(DEBUG_ERROR, "clunk failed: %s\n",
432 FCALL_ERROR(fcall));
433
434 v9fs_put_idpool(newfid, &v9ses->fidpool);
435 kfree(fcall);
436 }
437 return result;
438}
439
440/**
441 * v9fs_remove - helper function to remove files and directories
442 * @dir: directory inode that is being deleted
443 * @file: dentry that is being deleted
444 * @rmdir: removing a directory
445 *
446 */
447
448static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
449{
450 struct v9fs_fcall *fcall = NULL;
451 struct super_block *sb = NULL;
452 struct v9fs_session_info *v9ses = NULL;
453 struct v9fs_fid *v9fid = NULL;
454 struct inode *file_inode = NULL;
455 int fid = -1;
456 int result = 0;
457
458 dprintk(DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file,
459 rmdir);
460
461 file_inode = file->d_inode;
462 sb = file_inode->i_sb;
463 v9ses = v9fs_inode2v9ses(file_inode);
464 v9fid = v9fs_fid_lookup(file, FID_OP);
465
466 if (!v9fid) {
467 dprintk(DEBUG_ERROR,
468 "no v9fs_fid\n");
469 return -EBADF;
470 }
471
472 fid = v9fid->fid;
473 if (fid < 0) {
474 dprintk(DEBUG_ERROR, "inode #%lu, no fid!\n",
475 file_inode->i_ino);
476 return -EBADF;
477 }
478
479 result = v9fs_t_remove(v9ses, fid, &fcall);
480 if (result < 0)
481 dprintk(DEBUG_ERROR, "remove of file fails: %s(%d)\n",
482 FCALL_ERROR(fcall), result);
483 else {
484 v9fs_put_idpool(fid, &v9ses->fidpool);
485 v9fs_fid_destroy(v9fid);
486 }
487
488 kfree(fcall);
489 return result;
490}
491
492/**
493 * v9fs_vfs_create - VFS hook to create files
494 * @inode: directory inode that is being deleted
495 * @dentry: dentry that is being deleted
496 * @perm: create permissions
497 * @nd: path information
498 *
499 */
500
501static int
502v9fs_vfs_create(struct inode *inode, struct dentry *dentry, int perm,
503 struct nameidata *nd)
504{
505 return v9fs_create(inode, dentry, perm, O_RDWR);
506}
507
508/**
509 * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
510 * @inode: inode that is being unlinked
511 * @dentry: dentry that is being unlinked
512 * @mode: mode for new directory
513 *
514 */
515
516static int v9fs_vfs_mkdir(struct inode *inode, struct dentry *dentry, int mode)
517{
518 return v9fs_create(inode, dentry, mode | S_IFDIR, O_RDONLY);
519}
520
521/**
522 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
523 * @dir: inode that is being walked from
524 * @dentry: dentry that is being walked to?
525 * @nameidata: path data
526 *
527 */
528
529static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
530 struct nameidata *nameidata)
531{
532 struct super_block *sb;
533 struct v9fs_session_info *v9ses;
534 struct v9fs_fid *dirfid;
535 struct v9fs_fid *fid;
536 struct inode *inode;
537 struct v9fs_fcall *fcall = NULL;
538 struct stat newstat;
539 int dirfidnum = -1;
540 int newfid = -1;
541 int result = 0;
542
543 dprintk(DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n",
544 dir, dentry->d_iname, dentry, nameidata);
545
546 sb = dir->i_sb;
547 v9ses = v9fs_inode2v9ses(dir);
548 dirfid = v9fs_fid_lookup(dentry->d_parent, FID_WALK);
549
550 if (!dirfid) {
551 dprintk(DEBUG_ERROR, "no dirfid\n");
552 return ERR_PTR(-EINVAL);
553 }
554
555 dirfidnum = dirfid->fid;
556
557 if (dirfidnum < 0) {
558 dprintk(DEBUG_ERROR, "no dirfid for inode %p, #%lu\n",
559 dir, dir->i_ino);
560 return ERR_PTR(-EBADF);
561 }
562
563 newfid = v9fs_get_idpool(&v9ses->fidpool);
564 if (newfid < 0) {
565 eprintk(KERN_WARNING, "newfid fails!\n");
566 return ERR_PTR(-ENOSPC);
567 }
568
569 result =
570 v9fs_t_walk(v9ses, dirfidnum, newfid, (char *)dentry->d_name.name,
571 NULL);
572 if (result < 0) {
573 v9fs_put_idpool(newfid, &v9ses->fidpool);
574 if (result == -ENOENT) {
575 d_add(dentry, NULL);
576 dprintk(DEBUG_ERROR,
577 "Return negative dentry %p count %d\n",
578 dentry, atomic_read(&dentry->d_count));
579 return NULL;
580 }
581 dprintk(DEBUG_ERROR, "walk error:%d\n", result);
582 goto FreeFcall;
583 }
584
585 result = v9fs_t_stat(v9ses, newfid, &fcall);
586 if (result < 0) {
587 dprintk(DEBUG_ERROR, "stat error\n");
588 goto FreeFcall;
589 }
590
591 v9fs_mistat2unix(fcall->params.rstat.stat, &newstat, sb);
592 inode = v9fs_get_inode(sb, newstat.st_mode);
593
594 if (IS_ERR(inode) && (PTR_ERR(inode) == -ENOSPC)) {
595 eprintk(KERN_WARNING, "inode alloc failes, returns %ld\n",
596 PTR_ERR(inode));
597
598 result = -ENOSPC;
599 goto FreeFcall;
600 }
601
602 inode->i_ino = v9fs_qid2ino(&fcall->params.rstat.stat->qid);
603
604 fid = v9fs_fid_create(dentry);
605 if (fid == NULL) {
606 dprintk(DEBUG_ERROR, "couldn't insert\n");
607 result = -ENOMEM;
608 goto FreeFcall;
609 }
610
611 fid->fid = newfid;
612 fid->fidopen = 0;
613 fid->v9ses = v9ses;
614 fid->qid = fcall->params.rstat.stat->qid;
615
616 dentry->d_op = &v9fs_dentry_operations;
617 v9fs_mistat2inode(fcall->params.rstat.stat, inode, inode->i_sb);
618
619 d_add(dentry, inode);
620 kfree(fcall);
621
622 return NULL;
623
624 FreeFcall:
625 kfree(fcall);
626 return ERR_PTR(result);
627}
628
629/**
630 * v9fs_vfs_unlink - VFS unlink hook to delete an inode
631 * @i: inode that is being unlinked
632 * @d: dentry that is being unlinked
633 *
634 */
635
636static int v9fs_vfs_unlink(struct inode *i, struct dentry *d)
637{
638 return v9fs_remove(i, d, 0);
639}
640
641/**
642 * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
643 * @i: inode that is being unlinked
644 * @d: dentry that is being unlinked
645 *
646 */
647
648static int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
649{
650 return v9fs_remove(i, d, 1);
651}
652
653/**
654 * v9fs_vfs_rename - VFS hook to rename an inode
655 * @old_dir: old dir inode
656 * @old_dentry: old dentry
657 * @new_dir: new dir inode
658 * @new_dentry: new dentry
659 *
660 */
661
662static int
663v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
664 struct inode *new_dir, struct dentry *new_dentry)
665{
666 struct inode *old_inode = old_dentry->d_inode;
667 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(old_inode);
668 struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry, FID_WALK);
669 struct v9fs_fid *olddirfid =
670 v9fs_fid_lookup(old_dentry->d_parent, FID_WALK);
671 struct v9fs_fid *newdirfid =
672 v9fs_fid_lookup(new_dentry->d_parent, FID_WALK);
673 struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL);
674 struct v9fs_fcall *fcall = NULL;
675 int fid = -1;
676 int olddirfidnum = -1;
677 int newdirfidnum = -1;
678 int retval = 0;
679
680 dprintk(DEBUG_VFS, "\n");
681
682 if (!mistat)
683 return -ENOMEM;
684
685 if ((!oldfid) || (!olddirfid) || (!newdirfid)) {
686 dprintk(DEBUG_ERROR, "problem with arguments\n");
687 return -EBADF;
688 }
689
690 /* 9P can only handle file rename in the same directory */
691 if (memcmp(&olddirfid->qid, &newdirfid->qid, sizeof(newdirfid->qid))) {
692 dprintk(DEBUG_ERROR, "old dir and new dir are different\n");
693 retval = -EPERM;
694 goto FreeFcallnBail;
695 }
696
697 fid = oldfid->fid;
698 olddirfidnum = olddirfid->fid;
699 newdirfidnum = newdirfid->fid;
700
701 if (fid < 0) {
702 dprintk(DEBUG_ERROR, "no fid for old file #%lu\n",
703 old_inode->i_ino);
704 retval = -EBADF;
705 goto FreeFcallnBail;
706 }
707
708 v9fs_blank_mistat(v9ses, mistat);
709
710 strcpy(mistat->data + 1, v9ses->name);
711 mistat->name = mistat->data + 1 + strlen(v9ses->name);
712
713 if (new_dentry->d_name.len >
714 (v9ses->maxdata - strlen(v9ses->name) - sizeof(struct v9fs_stat))) {
715 dprintk(DEBUG_ERROR, "new name too long\n");
716 goto FreeFcallnBail;
717 }
718
719 strcpy(mistat->name, new_dentry->d_name.name);
720 retval = v9fs_t_wstat(v9ses, fid, mistat, &fcall);
721
722 FreeFcallnBail:
723 kfree(mistat);
724
725 if (retval < 0)
726 dprintk(DEBUG_ERROR, "v9fs_t_wstat error: %s\n",
727 FCALL_ERROR(fcall));
728
729 kfree(fcall);
730 return retval;
731}
732
733/**
734 * v9fs_vfs_getattr - retreive file metadata
735 * @mnt - mount information
736 * @dentry - file to get attributes on
737 * @stat - metadata structure to populate
738 *
739 */
740
741static int
742v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
743 struct kstat *stat)
744{
745 struct v9fs_fcall *fcall = NULL;
746 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
747 struct v9fs_fid *fid = v9fs_fid_lookup(dentry, FID_OP);
748 int err = -EPERM;
749
750 dprintk(DEBUG_VFS, "dentry: %p\n", dentry);
751 if (!fid) {
752 dprintk(DEBUG_ERROR,
753 "couldn't find fid associated with dentry\n");
754 return -EBADF;
755 }
756
757 err = v9fs_t_stat(v9ses, fid->fid, &fcall);
758
759 if (err < 0)
760 dprintk(DEBUG_ERROR, "stat error\n");
761 else {
762 v9fs_mistat2inode(fcall->params.rstat.stat, dentry->d_inode,
763 dentry->d_inode->i_sb);
764 generic_fillattr(dentry->d_inode, stat);
765 }
766
767 kfree(fcall);
768 return err;
769}
770
771/**
772 * v9fs_vfs_setattr - set file metadata
773 * @dentry: file whose metadata to set
774 * @iattr: metadata assignment structure
775 *
776 */
777
778static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
779{
780 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
781 struct v9fs_fid *fid = v9fs_fid_lookup(dentry, FID_OP);
782 struct v9fs_fcall *fcall = NULL;
783 struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL);
784 int res = -EPERM;
785
786 dprintk(DEBUG_VFS, "\n");
787
788 if (!mistat)
789 return -ENOMEM;
790
791 if (!fid) {
792 dprintk(DEBUG_ERROR,
793 "Couldn't find fid associated with dentry\n");
794 return -EBADF;
795 }
796
797 v9fs_blank_mistat(v9ses, mistat);
798 if (iattr->ia_valid & ATTR_MODE)
799 mistat->mode = unixmode2p9mode(v9ses, iattr->ia_mode);
800
801 if (iattr->ia_valid & ATTR_MTIME)
802 mistat->mtime = iattr->ia_mtime.tv_sec;
803
804 if (iattr->ia_valid & ATTR_ATIME)
805 mistat->atime = iattr->ia_atime.tv_sec;
806
807 if (iattr->ia_valid & ATTR_SIZE)
808 mistat->length = iattr->ia_size;
809
810 if (v9ses->extended) {
811 char *ptr = mistat->data+1;
812
813 if (iattr->ia_valid & ATTR_UID) {
814 mistat->uid = ptr;
815 ptr += 1+sprintf(ptr, "%08x", iattr->ia_uid);
816 mistat->n_uid = iattr->ia_uid;
817 }
818
819 if (iattr->ia_valid & ATTR_GID) {
820 mistat->gid = ptr;
821 ptr += 1+sprintf(ptr, "%08x", iattr->ia_gid);
822 mistat->n_gid = iattr->ia_gid;
823 }
824 }
825
826 res = v9fs_t_wstat(v9ses, fid->fid, mistat, &fcall);
827
828 if (res < 0)
829 dprintk(DEBUG_ERROR, "wstat error: %s\n", FCALL_ERROR(fcall));
830
831 kfree(mistat);
832 kfree(fcall);
833
834 if (res >= 0)
835 res = inode_setattr(dentry->d_inode, iattr);
836
837 return res;
838}
839
840/**
841 * v9fs_mistat2inode - populate an inode structure with mistat info
842 * @mistat: Plan 9 metadata (mistat) structure
843 * @inode: inode to populate
844 * @sb: superblock of filesystem
845 *
846 */
847
848void
849v9fs_mistat2inode(struct v9fs_stat *mistat, struct inode *inode,
850 struct super_block *sb)
851{
852 struct v9fs_session_info *v9ses = sb->s_fs_info;
853
854 inode->i_nlink = 1;
855
856 inode->i_atime.tv_sec = mistat->atime;
857 inode->i_mtime.tv_sec = mistat->mtime;
858 inode->i_ctime.tv_sec = mistat->mtime;
859
860 inode->i_uid = -1;
861 inode->i_gid = -1;
862
863 if (v9ses->extended) {
864 /* TODO: string to uid mapping via user-space daemon */
865 inode->i_uid = mistat->n_uid;
866 inode->i_gid = mistat->n_gid;
867
868 if (mistat->n_uid == -1)
869 sscanf(mistat->uid, "%x", &inode->i_uid);
870
871 if (mistat->n_gid == -1)
872 sscanf(mistat->gid, "%x", &inode->i_gid);
873 }
874
875 if (inode->i_uid == -1)
876 inode->i_uid = v9ses->uid;
877 if (inode->i_gid == -1)
878 inode->i_gid = v9ses->gid;
879
880 inode->i_mode = p9mode2unixmode(v9ses, mistat->mode);
881 if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) {
882 char type = 0;
883 int major = -1;
884 int minor = -1;
885 sscanf(mistat->extension, "%c %u %u", &type, &major, &minor);
886 switch (type) {
887 case 'c':
888 inode->i_mode &= ~S_IFBLK;
889 inode->i_mode |= S_IFCHR;
890 break;
891 case 'b':
892 break;
893 default:
894 dprintk(DEBUG_ERROR, "Unknown special type %c (%s)\n",
895 type, mistat->extension);
896 };
897 inode->i_rdev = MKDEV(major, minor);
898 } else
899 inode->i_rdev = 0;
900
901 inode->i_size = mistat->length;
902
903 inode->i_blksize = sb->s_blocksize;
904 inode->i_blocks =
905 (inode->i_size + inode->i_blksize - 1) >> sb->s_blocksize_bits;
906}
907
908/**
909 * v9fs_qid2ino - convert qid into inode number
910 * @qid: qid to hash
911 *
912 * BUG: potential for inode number collisions?
913 */
914
915ino_t v9fs_qid2ino(struct v9fs_qid *qid)
916{
917 u64 path = qid->path + 2;
918 ino_t i = 0;
919
920 if (sizeof(ino_t) == sizeof(path))
921 memcpy(&i, &path, sizeof(ino_t));
922 else
923 i = (ino_t) (path ^ (path >> 32));
924
925 return i;
926}
927
928/**
929 * v9fs_vfs_symlink - helper function to create symlinks
930 * @dir: directory inode containing symlink
931 * @dentry: dentry for symlink
932 * @symname: symlink data
933 *
934 * See 9P2000.u RFC for more information
935 *
936 */
937
938static int
939v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
940{
941 int retval = -EPERM;
942 struct v9fs_fid *newfid;
943 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
944 struct v9fs_fcall *fcall = NULL;
945 struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL);
946
947 dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
948 symname);
949
950 if (!mistat)
951 return -ENOMEM;
952
953 if (!v9ses->extended) {
954 dprintk(DEBUG_ERROR, "not extended\n");
955 goto FreeFcall;
956 }
957
958 /* issue a create */
959 retval = v9fs_create(dir, dentry, S_IFLNK, 0);
960 if (retval != 0)
961 goto FreeFcall;
962
963 newfid = v9fs_fid_lookup(dentry, FID_OP);
964
965 /* issue a twstat */
966 v9fs_blank_mistat(v9ses, mistat);
967 strcpy(mistat->data + 1, symname);
968 mistat->extension = mistat->data + 1;
969 retval = v9fs_t_wstat(v9ses, newfid->fid, mistat, &fcall);
970 if (retval < 0) {
971 dprintk(DEBUG_ERROR, "v9fs_t_wstat error: %s\n",
972 FCALL_ERROR(fcall));
973 goto FreeFcall;
974 }
975
976 kfree(fcall);
977
978 if (v9fs_t_clunk(v9ses, newfid->fid, &fcall)) {
979 dprintk(DEBUG_ERROR, "clunk for symlink failed: %s\n",
980 FCALL_ERROR(fcall));
981 goto FreeFcall;
982 }
983
984 d_drop(dentry); /* FID - will this also clunk? */
985
986 FreeFcall:
987 kfree(mistat);
988 kfree(fcall);
989
990 return retval;
991}
992
993/**
994 * v9fs_readlink - read a symlink's location (internal version)
995 * @dentry: dentry for symlink
996 * @buffer: buffer to load symlink location into
997 * @buflen: length of buffer
998 *
999 */
1000
1001static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
1002{
1003 int retval = -EPERM;
1004
1005 struct v9fs_fcall *fcall = NULL;
1006 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
1007 struct v9fs_fid *fid = v9fs_fid_lookup(dentry, FID_OP);
1008
1009 if (!fid) {
1010 dprintk(DEBUG_ERROR, "could not resolve fid from dentry\n");
1011 retval = -EBADF;
1012 goto FreeFcall;
1013 }
1014
1015 if (!v9ses->extended) {
1016 retval = -EBADF;
1017 dprintk(DEBUG_ERROR, "not extended\n");
1018 goto FreeFcall;
1019 }
1020
1021 dprintk(DEBUG_VFS, " %s\n", dentry->d_name.name);
1022 retval = v9fs_t_stat(v9ses, fid->fid, &fcall);
1023
1024 if (retval < 0) {
1025 dprintk(DEBUG_ERROR, "stat error\n");
1026 goto FreeFcall;
1027 }
1028
1029 if (!fcall)
1030 return -EIO;
1031
1032 if (!(fcall->params.rstat.stat->mode & V9FS_DMSYMLINK)) {
1033 retval = -EINVAL;
1034 goto FreeFcall;
1035 }
1036
1037 /* copy extension buffer into buffer */
1038 if (strlen(fcall->params.rstat.stat->extension) < buflen)
1039 buflen = strlen(fcall->params.rstat.stat->extension);
1040
1041 memcpy(buffer, fcall->params.rstat.stat->extension, buflen + 1);
1042
1043 retval = buflen;
1044
1045 FreeFcall:
1046 kfree(fcall);
1047
1048 return retval;
1049}
1050
1051/**
1052 * v9fs_vfs_readlink - read a symlink's location
1053 * @dentry: dentry for symlink
1054 * @buf: buffer to load symlink location into
1055 * @buflen: length of buffer
1056 *
1057 */
1058
1059static int v9fs_vfs_readlink(struct dentry *dentry, char __user * buffer,
1060 int buflen)
1061{
1062 int retval;
1063 int ret;
1064 char *link = __getname();
1065
1066 if (strlen(link) < buflen)
1067 buflen = strlen(link);
1068
1069 dprintk(DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
1070
1071 retval = v9fs_readlink(dentry, link, buflen);
1072
1073 if (retval > 0) {
1074 if ((ret = copy_to_user(buffer, link, retval)) != 0) {
1075 dprintk(DEBUG_ERROR, "problem copying to user: %d\n",
1076 ret);
1077 retval = ret;
1078 }
1079 }
1080
1081 putname(link);
1082 return retval;
1083}
1084
1085/**
1086 * v9fs_vfs_follow_link - follow a symlink path
1087 * @dentry: dentry for symlink
1088 * @nd: nameidata
1089 *
1090 */
1091
1092static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
1093{
1094 int len = 0;
1095 char *link = __getname();
1096
1097 dprintk(DEBUG_VFS, "%s n", dentry->d_name.name);
1098
1099 if (!link)
1100 link = ERR_PTR(-ENOMEM);
1101 else {
1102 len = v9fs_readlink(dentry, link, strlen(link));
1103
1104 if (len < 0) {
1105 putname(link);
1106 link = ERR_PTR(len);
1107 } else
1108 link[len] = 0;
1109 }
1110 nd_set_link(nd, link);
1111
1112 return NULL;
1113}
1114
1115/**
1116 * v9fs_vfs_put_link - release a symlink path
1117 * @dentry: dentry for symlink
1118 * @nd: nameidata
1119 *
1120 */
1121
1122static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
1123{
1124 char *s = nd_get_link(nd);
1125
1126 dprintk(DEBUG_VFS, " %s %s\n", dentry->d_name.name, s);
1127 if (!IS_ERR(s))
1128 putname(s);
1129}
1130
1131/**
1132 * v9fs_vfs_link - create a hardlink
1133 * @old_dentry: dentry for file to link to
1134 * @dir: inode destination for new link
1135 * @dentry: dentry for link
1136 *
1137 */
1138
1139/* XXX - lots of code dup'd from symlink and creates,
1140 * figure out a better reuse strategy
1141 */
1142
1143static int
1144v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
1145 struct dentry *dentry)
1146{
1147 int retval = -EPERM;
1148 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
1149 struct v9fs_fcall *fcall = NULL;
1150 struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL);
1151 struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry, FID_OP);
1152 struct v9fs_fid *newfid = NULL;
1153 char *symname = __getname();
1154
1155 dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
1156 old_dentry->d_name.name);
1157
1158 if (!v9ses->extended) {
1159 dprintk(DEBUG_ERROR, "not extended\n");
1160 goto FreeMem;
1161 }
1162
1163 /* get fid of old_dentry */
1164 sprintf(symname, "hardlink(%d)\n", oldfid->fid);
1165
1166 /* issue a create */
1167 retval = v9fs_create(dir, dentry, V9FS_DMLINK, 0);
1168 if (retval != 0)
1169 goto FreeMem;
1170
1171 newfid = v9fs_fid_lookup(dentry, FID_OP);
1172 if (!newfid) {
1173 dprintk(DEBUG_ERROR, "couldn't resolve fid from dentry\n");
1174 goto FreeMem;
1175 }
1176
1177 /* issue a twstat */
1178 v9fs_blank_mistat(v9ses, mistat);
1179 strcpy(mistat->data + 1, symname);
1180 mistat->extension = mistat->data + 1;
1181 retval = v9fs_t_wstat(v9ses, newfid->fid, mistat, &fcall);
1182 if (retval < 0) {
1183 dprintk(DEBUG_ERROR, "v9fs_t_wstat error: %s\n",
1184 FCALL_ERROR(fcall));
1185 goto FreeMem;
1186 }
1187
1188 kfree(fcall);
1189
1190 if (v9fs_t_clunk(v9ses, newfid->fid, &fcall)) {
1191 dprintk(DEBUG_ERROR, "clunk for symlink failed: %s\n",
1192 FCALL_ERROR(fcall));
1193 goto FreeMem;
1194 }
1195
1196 d_drop(dentry); /* FID - will this also clunk? */
1197
1198 kfree(fcall);
1199 fcall = NULL;
1200
1201 FreeMem:
1202 kfree(mistat);
1203 kfree(fcall);
1204 putname(symname);
1205 return retval;
1206}
1207
1208/**
1209 * v9fs_vfs_mknod - create a special file
1210 * @dir: inode destination for new link
1211 * @dentry: dentry for file
1212 * @mode: mode for creation
1213 * @dev_t: device associated with special file
1214 *
1215 */
1216
1217static int
1218v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
1219{
1220 int retval = -EPERM;
1221 struct v9fs_fid *newfid;
1222 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
1223 struct v9fs_fcall *fcall = NULL;
1224 struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL);
1225 char *symname = __getname();
1226
1227 dprintk(DEBUG_VFS, " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
1228 dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev));
1229
1230 if (!mistat)
1231 return -ENOMEM;
1232
1233 if (!new_valid_dev(rdev)) {
1234 retval = -EINVAL;
1235 goto FreeMem;
1236 }
1237
1238 if (!v9ses->extended) {
1239 dprintk(DEBUG_ERROR, "not extended\n");
1240 goto FreeMem;
1241 }
1242
1243 /* issue a create */
1244 retval = v9fs_create(dir, dentry, mode, 0);
1245
1246 if (retval != 0)
1247 goto FreeMem;
1248
1249 newfid = v9fs_fid_lookup(dentry, FID_OP);
1250 if (!newfid) {
1251 dprintk(DEBUG_ERROR, "coudn't resove fid from dentry\n");
1252 retval = -EINVAL;
1253 goto FreeMem;
1254 }
1255
1256 /* build extension */
1257 if (S_ISBLK(mode))
1258 sprintf(symname, "b %u %u", MAJOR(rdev), MINOR(rdev));
1259 else if (S_ISCHR(mode))
1260 sprintf(symname, "c %u %u", MAJOR(rdev), MINOR(rdev));
1261 else if (S_ISFIFO(mode))
1262 ; /* DO NOTHING */
1263 else {
1264 retval = -EINVAL;
1265 goto FreeMem;
1266 }
1267
1268 if (!S_ISFIFO(mode)) {
1269 /* issue a twstat */
1270 v9fs_blank_mistat(v9ses, mistat);
1271 strcpy(mistat->data + 1, symname);
1272 mistat->extension = mistat->data + 1;
1273 retval = v9fs_t_wstat(v9ses, newfid->fid, mistat, &fcall);
1274 if (retval < 0) {
1275 dprintk(DEBUG_ERROR, "v9fs_t_wstat error: %s\n",
1276 FCALL_ERROR(fcall));
1277 goto FreeMem;
1278 }
1279 }
1280
1281 /* need to update dcache so we show up */
1282 kfree(fcall);
1283
1284 if (v9fs_t_clunk(v9ses, newfid->fid, &fcall)) {
1285 dprintk(DEBUG_ERROR, "clunk for symlink failed: %s\n",
1286 FCALL_ERROR(fcall));
1287 goto FreeMem;
1288 }
1289
1290 d_drop(dentry); /* FID - will this also clunk? */
1291
1292 FreeMem:
1293 kfree(mistat);
1294 kfree(fcall);
1295 putname(symname);
1296
1297 return retval;
1298}
1299
1300static struct inode_operations v9fs_dir_inode_operations_ext = {
1301 .create = v9fs_vfs_create,
1302 .lookup = v9fs_vfs_lookup,
1303 .symlink = v9fs_vfs_symlink,
1304 .link = v9fs_vfs_link,
1305 .unlink = v9fs_vfs_unlink,
1306 .mkdir = v9fs_vfs_mkdir,
1307 .rmdir = v9fs_vfs_rmdir,
1308 .mknod = v9fs_vfs_mknod,
1309 .rename = v9fs_vfs_rename,
1310 .readlink = v9fs_vfs_readlink,
1311 .getattr = v9fs_vfs_getattr,
1312 .setattr = v9fs_vfs_setattr,
1313};
1314
1315static struct inode_operations v9fs_dir_inode_operations = {
1316 .create = v9fs_vfs_create,
1317 .lookup = v9fs_vfs_lookup,
1318 .unlink = v9fs_vfs_unlink,
1319 .mkdir = v9fs_vfs_mkdir,
1320 .rmdir = v9fs_vfs_rmdir,
1321 .mknod = v9fs_vfs_mknod,
1322 .rename = v9fs_vfs_rename,
1323 .getattr = v9fs_vfs_getattr,
1324 .setattr = v9fs_vfs_setattr,
1325};
1326
1327static struct inode_operations v9fs_file_inode_operations = {
1328 .getattr = v9fs_vfs_getattr,
1329 .setattr = v9fs_vfs_setattr,
1330};
1331
1332static struct inode_operations v9fs_symlink_inode_operations = {
1333 .readlink = v9fs_vfs_readlink,
1334 .follow_link = v9fs_vfs_follow_link,
1335 .put_link = v9fs_vfs_put_link,
1336 .getattr = v9fs_vfs_getattr,
1337 .setattr = v9fs_vfs_setattr,
1338};
diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c
new file mode 100644
index 0000000000..868f350b2c
--- /dev/null
+++ b/fs/9p/vfs_super.c
@@ -0,0 +1,280 @@
1/*
2 * linux/fs/9p/vfs_super.c
3 *
4 * This file contians superblock ops for 9P2000. It is intended that
5 * you mount this file system on directories.
6 *
7 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
8 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to:
22 * Free Software Foundation
23 * 51 Franklin Street, Fifth Floor
24 * Boston, MA 02111-1301 USA
25 *
26 */
27
28#include <linux/kernel.h>
29#include <linux/config.h>
30#include <linux/module.h>
31#include <linux/errno.h>
32#include <linux/fs.h>
33#include <linux/file.h>
34#include <linux/stat.h>
35#include <linux/string.h>
36#include <linux/smp_lock.h>
37#include <linux/inet.h>
38#include <linux/pagemap.h>
39#include <linux/seq_file.h>
40#include <linux/mount.h>
41#include <linux/idr.h>
42
43#include "debug.h"
44#include "v9fs.h"
45#include "9p.h"
46#include "v9fs_vfs.h"
47#include "conv.h"
48#include "fid.h"
49
50static void v9fs_clear_inode(struct inode *);
51static struct super_operations v9fs_super_ops;
52
53/**
54 * v9fs_clear_inode - release an inode
55 * @inode: inode to release
56 *
57 */
58
59static void v9fs_clear_inode(struct inode *inode)
60{
61 filemap_fdatawrite(inode->i_mapping);
62}
63
64/**
65 * v9fs_set_super - set the superblock
66 * @s: super block
67 * @data: file system specific data
68 *
69 */
70
71static int v9fs_set_super(struct super_block *s, void *data)
72{
73 s->s_fs_info = data;
74 return set_anon_super(s, data);
75}
76
77/**
78 * v9fs_fill_super - populate superblock with info
79 * @sb: superblock
80 * @v9ses: session information
81 *
82 */
83
84static void
85v9fs_fill_super(struct super_block *sb, struct v9fs_session_info *v9ses,
86 int flags)
87{
88 sb->s_maxbytes = MAX_LFS_FILESIZE;
89 sb->s_blocksize_bits = fls(v9ses->maxdata - 1);
90 sb->s_blocksize = 1 << sb->s_blocksize_bits;
91 sb->s_magic = V9FS_MAGIC;
92 sb->s_op = &v9fs_super_ops;
93
94 sb->s_flags = flags | MS_ACTIVE | MS_SYNCHRONOUS | MS_DIRSYNC |
95 MS_NODIRATIME | MS_NOATIME;
96}
97
98/**
99 * v9fs_get_sb - mount a superblock
100 * @fs_type: file system type
101 * @flags: mount flags
102 * @dev_name: device name that was mounted
103 * @data: mount options
104 *
105 */
106
107static struct super_block *v9fs_get_sb(struct file_system_type
108 *fs_type, int flags,
109 const char *dev_name, void *data)
110{
111 struct super_block *sb = NULL;
112 struct v9fs_fcall *fcall = NULL;
113 struct inode *inode = NULL;
114 struct dentry *root = NULL;
115 struct v9fs_session_info *v9ses = NULL;
116 struct v9fs_fid *root_fid = NULL;
117 int mode = S_IRWXUGO | S_ISVTX;
118 uid_t uid = current->fsuid;
119 gid_t gid = current->fsgid;
120 int stat_result = 0;
121 int newfid = 0;
122 int retval = 0;
123
124 dprintk(DEBUG_VFS, " \n");
125
126 v9ses = kcalloc(1, sizeof(struct v9fs_session_info), GFP_KERNEL);
127 if (!v9ses)
128 return ERR_PTR(-ENOMEM);
129
130 if ((newfid = v9fs_session_init(v9ses, dev_name, data)) < 0) {
131 dprintk(DEBUG_ERROR, "problem initiating session\n");
132 retval = newfid;
133 goto free_session;
134 }
135
136 sb = sget(fs_type, NULL, v9fs_set_super, v9ses);
137
138 v9fs_fill_super(sb, v9ses, flags);
139
140 inode = v9fs_get_inode(sb, S_IFDIR | mode);
141 if (IS_ERR(inode)) {
142 retval = PTR_ERR(inode);
143 goto put_back_sb;
144 }
145
146 inode->i_uid = uid;
147 inode->i_gid = gid;
148
149 root = d_alloc_root(inode);
150
151 if (!root) {
152 retval = -ENOMEM;
153 goto release_inode;
154 }
155
156 sb->s_root = root;
157
158 /* Setup the Root Inode */
159 root_fid = v9fs_fid_create(root);
160 if (root_fid == NULL) {
161 retval = -ENOMEM;
162 goto release_dentry;
163 }
164
165 root_fid->fidopen = 0;
166 root_fid->v9ses = v9ses;
167
168 stat_result = v9fs_t_stat(v9ses, newfid, &fcall);
169 if (stat_result < 0) {
170 dprintk(DEBUG_ERROR, "stat error\n");
171 v9fs_t_clunk(v9ses, newfid, NULL);
172 v9fs_put_idpool(newfid, &v9ses->fidpool);
173 } else {
174 root_fid->fid = newfid;
175 root_fid->qid = fcall->params.rstat.stat->qid;
176 root->d_inode->i_ino =
177 v9fs_qid2ino(&fcall->params.rstat.stat->qid);
178 v9fs_mistat2inode(fcall->params.rstat.stat, root->d_inode, sb);
179 }
180
181 kfree(fcall);
182
183 if (stat_result < 0) {
184 retval = stat_result;
185 goto release_dentry;
186 }
187
188 return sb;
189
190 release_dentry:
191 dput(sb->s_root);
192
193 release_inode:
194 iput(inode);
195
196 put_back_sb:
197 up_write(&sb->s_umount);
198 deactivate_super(sb);
199 v9fs_session_close(v9ses);
200
201 free_session:
202 kfree(v9ses);
203
204 return ERR_PTR(retval);
205}
206
207/**
208 * v9fs_kill_super - Kill Superblock
209 * @s: superblock
210 *
211 */
212
213static void v9fs_kill_super(struct super_block *s)
214{
215 struct v9fs_session_info *v9ses = s->s_fs_info;
216
217 dprintk(DEBUG_VFS, " %p\n", s);
218
219 v9fs_dentry_release(s->s_root); /* clunk root */
220
221 kill_anon_super(s);
222
223 v9fs_session_close(v9ses);
224 kfree(v9ses);
225 dprintk(DEBUG_VFS, "exiting kill_super\n");
226}
227
228/**
229 * v9fs_show_options - Show mount options in /proc/mounts
230 * @m: seq_file to write to
231 * @mnt: mount descriptor
232 *
233 */
234
235static int v9fs_show_options(struct seq_file *m, struct vfsmount *mnt)
236{
237 struct v9fs_session_info *v9ses = mnt->mnt_sb->s_fs_info;
238
239 if (v9ses->debug != 0)
240 seq_printf(m, ",debug=%u", v9ses->debug);
241 if (v9ses->port != V9FS_PORT)
242 seq_printf(m, ",port=%u", v9ses->port);
243 if (v9ses->maxdata != 9000)
244 seq_printf(m, ",msize=%u", v9ses->maxdata);
245 if (v9ses->afid != ~0)
246 seq_printf(m, ",afid=%u", v9ses->afid);
247 if (v9ses->proto == PROTO_UNIX)
248 seq_puts(m, ",proto=unix");
249 if (v9ses->extended == 0)
250 seq_puts(m, ",noextend");
251 if (v9ses->nodev == 1)
252 seq_puts(m, ",nodevmap");
253 seq_printf(m, ",name=%s", v9ses->name);
254 seq_printf(m, ",aname=%s", v9ses->remotename);
255 seq_printf(m, ",uid=%u", v9ses->uid);
256 seq_printf(m, ",gid=%u", v9ses->gid);
257 return 0;
258}
259
260static void
261v9fs_umount_begin(struct super_block *sb)
262{
263 struct v9fs_session_info *v9ses = sb->s_fs_info;
264
265 v9fs_session_cancel(v9ses);
266}
267
268static struct super_operations v9fs_super_ops = {
269 .statfs = simple_statfs,
270 .clear_inode = v9fs_clear_inode,
271 .show_options = v9fs_show_options,
272 .umount_begin = v9fs_umount_begin,
273};
274
275struct file_system_type v9fs_fs_type = {
276 .name = "9P",
277 .get_sb = v9fs_get_sb,
278 .kill_sb = v9fs_kill_super,
279 .owner = THIS_MODULE,
280};
diff --git a/fs/Kconfig b/fs/Kconfig
index 5e817902cb..068ccea2f1 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -462,6 +462,19 @@ config AUTOFS4_FS
462 local network, you probably do not need an automounter, and can say 462 local network, you probably do not need an automounter, and can say
463 N here. 463 N here.
464 464
465config FUSE_FS
466 tristate "Filesystem in Userspace support"
467 help
468 With FUSE it is possible to implement a fully functional filesystem
469 in a userspace program.
470
471 There's also companion library: libfuse. This library along with
472 utilities is available from the FUSE homepage:
473 <http://fuse.sourceforge.net/>
474
475 If you want to develop a userspace FS, or if you want to use
476 a filesystem based on FUSE, answer Y or M.
477
465menu "CD-ROM/DVD Filesystems" 478menu "CD-ROM/DVD Filesystems"
466 479
467config ISO9660_FS 480config ISO9660_FS
@@ -1703,6 +1716,17 @@ config AFS_FS
1703config RXRPC 1716config RXRPC
1704 tristate 1717 tristate
1705 1718
1719config 9P_FS
1720 tristate "Plan 9 Resource Sharing Support (9P2000) (Experimental)"
1721 depends on INET && EXPERIMENTAL
1722 help
1723 If you say Y here, you will get experimental support for
1724 Plan 9 resource sharing via the 9P2000 protocol.
1725
1726 See <http://v9fs.sf.net> for more information.
1727
1728 If unsure, say N.
1729
1706endmenu 1730endmenu
1707 1731
1708menu "Partition Types" 1732menu "Partition Types"
diff --git a/fs/Makefile b/fs/Makefile
index 15158309de..1972da1862 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -89,11 +89,13 @@ obj-$(CONFIG_QNX4FS_FS) += qnx4/
89obj-$(CONFIG_AUTOFS_FS) += autofs/ 89obj-$(CONFIG_AUTOFS_FS) += autofs/
90obj-$(CONFIG_AUTOFS4_FS) += autofs4/ 90obj-$(CONFIG_AUTOFS4_FS) += autofs4/
91obj-$(CONFIG_ADFS_FS) += adfs/ 91obj-$(CONFIG_ADFS_FS) += adfs/
92obj-$(CONFIG_FUSE_FS) += fuse/
92obj-$(CONFIG_UDF_FS) += udf/ 93obj-$(CONFIG_UDF_FS) += udf/
93obj-$(CONFIG_RELAYFS_FS) += relayfs/ 94obj-$(CONFIG_RELAYFS_FS) += relayfs/
94obj-$(CONFIG_SUN_OPENPROMFS) += openpromfs/ 95obj-$(CONFIG_SUN_OPENPROMFS) += openpromfs/
95obj-$(CONFIG_JFS_FS) += jfs/ 96obj-$(CONFIG_JFS_FS) += jfs/
96obj-$(CONFIG_XFS_FS) += xfs/ 97obj-$(CONFIG_XFS_FS) += xfs/
98obj-$(CONFIG_9P_FS) += 9p/
97obj-$(CONFIG_AFS_FS) += afs/ 99obj-$(CONFIG_AFS_FS) += afs/
98obj-$(CONFIG_BEFS_FS) += befs/ 100obj-$(CONFIG_BEFS_FS) += befs/
99obj-$(CONFIG_HOSTFS) += hostfs/ 101obj-$(CONFIG_HOSTFS) += hostfs/
diff --git a/fs/affs/inode.c b/fs/affs/inode.c
index 7aa6f20045..9ebe881c67 100644
--- a/fs/affs/inode.c
+++ b/fs/affs/inode.c
@@ -255,6 +255,7 @@ void
255affs_delete_inode(struct inode *inode) 255affs_delete_inode(struct inode *inode)
256{ 256{
257 pr_debug("AFFS: delete_inode(ino=%lu, nlink=%u)\n", inode->i_ino, inode->i_nlink); 257 pr_debug("AFFS: delete_inode(ino=%lu, nlink=%u)\n", inode->i_ino, inode->i_nlink);
258 truncate_inode_pages(&inode->i_data, 0);
258 inode->i_size = 0; 259 inode->i_size = 0;
259 if (S_ISREG(inode->i_mode)) 260 if (S_ISREG(inode->i_mode))
260 affs_truncate(inode); 261 affs_truncate(inode);
diff --git a/fs/aio.c b/fs/aio.c
index 4f641abac3..38f62680fd 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -29,6 +29,7 @@
29#include <linux/highmem.h> 29#include <linux/highmem.h>
30#include <linux/workqueue.h> 30#include <linux/workqueue.h>
31#include <linux/security.h> 31#include <linux/security.h>
32#include <linux/rcuref.h>
32 33
33#include <asm/kmap_types.h> 34#include <asm/kmap_types.h>
34#include <asm/uaccess.h> 35#include <asm/uaccess.h>
@@ -499,7 +500,7 @@ static int __aio_put_req(struct kioctx *ctx, struct kiocb *req)
499 /* Must be done under the lock to serialise against cancellation. 500 /* Must be done under the lock to serialise against cancellation.
500 * Call this aio_fput as it duplicates fput via the fput_work. 501 * Call this aio_fput as it duplicates fput via the fput_work.
501 */ 502 */
502 if (unlikely(atomic_dec_and_test(&req->ki_filp->f_count))) { 503 if (unlikely(rcuref_dec_and_test(&req->ki_filp->f_count))) {
503 get_ioctx(ctx); 504 get_ioctx(ctx);
504 spin_lock(&fput_lock); 505 spin_lock(&fput_lock);
505 list_add(&req->ki_list, &fput_head); 506 list_add(&req->ki_list, &fput_head);
@@ -546,6 +547,24 @@ struct kioctx *lookup_ioctx(unsigned long ctx_id)
546 return ioctx; 547 return ioctx;
547} 548}
548 549
550static int lock_kiocb_action(void *param)
551{
552 schedule();
553 return 0;
554}
555
556static inline void lock_kiocb(struct kiocb *iocb)
557{
558 wait_on_bit_lock(&iocb->ki_flags, KIF_LOCKED, lock_kiocb_action,
559 TASK_UNINTERRUPTIBLE);
560}
561
562static inline void unlock_kiocb(struct kiocb *iocb)
563{
564 kiocbClearLocked(iocb);
565 wake_up_bit(&iocb->ki_flags, KIF_LOCKED);
566}
567
549/* 568/*
550 * use_mm 569 * use_mm
551 * Makes the calling kernel thread take on the specified 570 * Makes the calling kernel thread take on the specified
@@ -786,7 +805,9 @@ static int __aio_run_iocbs(struct kioctx *ctx)
786 * Hold an extra reference while retrying i/o. 805 * Hold an extra reference while retrying i/o.
787 */ 806 */
788 iocb->ki_users++; /* grab extra reference */ 807 iocb->ki_users++; /* grab extra reference */
808 lock_kiocb(iocb);
789 aio_run_iocb(iocb); 809 aio_run_iocb(iocb);
810 unlock_kiocb(iocb);
790 if (__aio_put_req(ctx, iocb)) /* drop extra ref */ 811 if (__aio_put_req(ctx, iocb)) /* drop extra ref */
791 put_ioctx(ctx); 812 put_ioctx(ctx);
792 } 813 }
@@ -1527,10 +1548,9 @@ int fastcall io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
1527 goto out_put_req; 1548 goto out_put_req;
1528 1549
1529 spin_lock_irq(&ctx->ctx_lock); 1550 spin_lock_irq(&ctx->ctx_lock);
1530 if (likely(list_empty(&ctx->run_list))) { 1551 aio_run_iocb(req);
1531 aio_run_iocb(req); 1552 unlock_kiocb(req);
1532 } else { 1553 if (!list_empty(&ctx->run_list)) {
1533 list_add_tail(&req->ki_run_list, &ctx->run_list);
1534 /* drain the run list */ 1554 /* drain the run list */
1535 while (__aio_run_iocbs(ctx)) 1555 while (__aio_run_iocbs(ctx))
1536 ; 1556 ;
@@ -1661,6 +1681,7 @@ asmlinkage long sys_io_cancel(aio_context_t ctx_id, struct iocb __user *iocb,
1661 if (NULL != cancel) { 1681 if (NULL != cancel) {
1662 struct io_event tmp; 1682 struct io_event tmp;
1663 pr_debug("calling cancel\n"); 1683 pr_debug("calling cancel\n");
1684 lock_kiocb(kiocb);
1664 memset(&tmp, 0, sizeof(tmp)); 1685 memset(&tmp, 0, sizeof(tmp));
1665 tmp.obj = (u64)(unsigned long)kiocb->ki_obj.user; 1686 tmp.obj = (u64)(unsigned long)kiocb->ki_obj.user;
1666 tmp.data = kiocb->ki_user_data; 1687 tmp.data = kiocb->ki_user_data;
@@ -1672,8 +1693,9 @@ asmlinkage long sys_io_cancel(aio_context_t ctx_id, struct iocb __user *iocb,
1672 if (copy_to_user(result, &tmp, sizeof(tmp))) 1693 if (copy_to_user(result, &tmp, sizeof(tmp)))
1673 ret = -EFAULT; 1694 ret = -EFAULT;
1674 } 1695 }
1696 unlock_kiocb(kiocb);
1675 } else 1697 } else
1676 printk(KERN_DEBUG "iocb has no cancel operation\n"); 1698 ret = -EINVAL;
1677 1699
1678 put_ioctx(ctx); 1700 put_ioctx(ctx);
1679 1701
diff --git a/fs/autofs/autofs_i.h b/fs/autofs/autofs_i.h
index 6171431272..990c28da5a 100644
--- a/fs/autofs/autofs_i.h
+++ b/fs/autofs/autofs_i.h
@@ -105,6 +105,7 @@ struct autofs_sb_info {
105 struct file *pipe; 105 struct file *pipe;
106 pid_t oz_pgrp; 106 pid_t oz_pgrp;
107 int catatonic; 107 int catatonic;
108 struct super_block *sb;
108 unsigned long exp_timeout; 109 unsigned long exp_timeout;
109 ino_t next_dir_ino; 110 ino_t next_dir_ino;
110 struct autofs_wait_queue *queues; /* Wait queue pointer */ 111 struct autofs_wait_queue *queues; /* Wait queue pointer */
@@ -134,7 +135,7 @@ void autofs_hash_insert(struct autofs_dirhash *,struct autofs_dir_ent *);
134void autofs_hash_delete(struct autofs_dir_ent *); 135void autofs_hash_delete(struct autofs_dir_ent *);
135struct autofs_dir_ent *autofs_hash_enum(const struct autofs_dirhash *,off_t *,struct autofs_dir_ent *); 136struct autofs_dir_ent *autofs_hash_enum(const struct autofs_dirhash *,off_t *,struct autofs_dir_ent *);
136void autofs_hash_dputall(struct autofs_dirhash *); 137void autofs_hash_dputall(struct autofs_dirhash *);
137void autofs_hash_nuke(struct autofs_dirhash *); 138void autofs_hash_nuke(struct autofs_sb_info *);
138 139
139/* Expiration-handling functions */ 140/* Expiration-handling functions */
140 141
diff --git a/fs/autofs/dirhash.c b/fs/autofs/dirhash.c
index 448143fd07..5ccfcf2631 100644
--- a/fs/autofs/dirhash.c
+++ b/fs/autofs/dirhash.c
@@ -232,13 +232,13 @@ void autofs_hash_dputall(struct autofs_dirhash *dh)
232 232
233/* Delete everything. This is used on filesystem destruction, so we 233/* Delete everything. This is used on filesystem destruction, so we
234 make no attempt to keep the pointers valid */ 234 make no attempt to keep the pointers valid */
235void autofs_hash_nuke(struct autofs_dirhash *dh) 235void autofs_hash_nuke(struct autofs_sb_info *sbi)
236{ 236{
237 int i; 237 int i;
238 struct autofs_dir_ent *ent, *nent; 238 struct autofs_dir_ent *ent, *nent;
239 239
240 for ( i = 0 ; i < AUTOFS_HASH_SIZE ; i++ ) { 240 for ( i = 0 ; i < AUTOFS_HASH_SIZE ; i++ ) {
241 for ( ent = dh->h[i] ; ent ; ent = nent ) { 241 for ( ent = sbi->dirhash.h[i] ; ent ; ent = nent ) {
242 nent = ent->next; 242 nent = ent->next;
243 if ( ent->dentry ) 243 if ( ent->dentry )
244 dput(ent->dentry); 244 dput(ent->dentry);
@@ -246,4 +246,5 @@ void autofs_hash_nuke(struct autofs_dirhash *dh)
246 kfree(ent); 246 kfree(ent);
247 } 247 }
248 } 248 }
249 shrink_dcache_sb(sbi->sb);
249} 250}
diff --git a/fs/autofs/inode.c b/fs/autofs/inode.c
index 4888c1fabb..65e5ed4219 100644
--- a/fs/autofs/inode.c
+++ b/fs/autofs/inode.c
@@ -27,7 +27,7 @@ static void autofs_put_super(struct super_block *sb)
27 if ( !sbi->catatonic ) 27 if ( !sbi->catatonic )
28 autofs_catatonic_mode(sbi); /* Free wait queues, close pipe */ 28 autofs_catatonic_mode(sbi); /* Free wait queues, close pipe */
29 29
30 autofs_hash_nuke(&sbi->dirhash); 30 autofs_hash_nuke(sbi);
31 for ( n = 0 ; n < AUTOFS_MAX_SYMLINKS ; n++ ) { 31 for ( n = 0 ; n < AUTOFS_MAX_SYMLINKS ; n++ ) {
32 if ( test_bit(n, sbi->symlink_bitmap) ) 32 if ( test_bit(n, sbi->symlink_bitmap) )
33 kfree(sbi->symlink[n].data); 33 kfree(sbi->symlink[n].data);
@@ -148,6 +148,7 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
148 s->s_magic = AUTOFS_SUPER_MAGIC; 148 s->s_magic = AUTOFS_SUPER_MAGIC;
149 s->s_op = &autofs_sops; 149 s->s_op = &autofs_sops;
150 s->s_time_gran = 1; 150 s->s_time_gran = 1;
151 sbi->sb = s;
151 152
152 root_inode = iget(s, AUTOFS_ROOT_INO); 153 root_inode = iget(s, AUTOFS_ROOT_INO);
153 root = d_alloc_root(root_inode); 154 root = d_alloc_root(root_inode);
diff --git a/fs/bfs/bfs.h b/fs/bfs/bfs.h
index 1020dbc88b..1fbc53f14a 100644
--- a/fs/bfs/bfs.h
+++ b/fs/bfs/bfs.h
@@ -20,7 +20,6 @@ struct bfs_sb_info {
20 unsigned long si_lasti; 20 unsigned long si_lasti;
21 unsigned long * si_imap; 21 unsigned long * si_imap;
22 struct buffer_head * si_sbh; /* buffer header w/superblock */ 22 struct buffer_head * si_sbh; /* buffer header w/superblock */
23 struct bfs_super_block * si_bfs_sb; /* superblock in si_sbh->b_data */
24}; 23};
25 24
26/* 25/*
diff --git a/fs/bfs/dir.c b/fs/bfs/dir.c
index 5a1e5ce057..e240c335eb 100644
--- a/fs/bfs/dir.c
+++ b/fs/bfs/dir.c
@@ -2,6 +2,7 @@
2 * fs/bfs/dir.c 2 * fs/bfs/dir.c
3 * BFS directory operations. 3 * BFS directory operations.
4 * Copyright (C) 1999,2000 Tigran Aivazian <tigran@veritas.com> 4 * Copyright (C) 1999,2000 Tigran Aivazian <tigran@veritas.com>
5 * Made endianness-clean by Andrew Stribblehill <ads@wompom.org> 2005
5 */ 6 */
6 7
7#include <linux/time.h> 8#include <linux/time.h>
@@ -20,9 +21,9 @@
20#define dprintf(x...) 21#define dprintf(x...)
21#endif 22#endif
22 23
23static int bfs_add_entry(struct inode * dir, const char * name, int namelen, int ino); 24static int bfs_add_entry(struct inode * dir, const unsigned char * name, int namelen, int ino);
24static struct buffer_head * bfs_find_entry(struct inode * dir, 25static struct buffer_head * bfs_find_entry(struct inode * dir,
25 const char * name, int namelen, struct bfs_dirent ** res_dir); 26 const unsigned char * name, int namelen, struct bfs_dirent ** res_dir);
26 27
27static int bfs_readdir(struct file * f, void * dirent, filldir_t filldir) 28static int bfs_readdir(struct file * f, void * dirent, filldir_t filldir)
28{ 29{
@@ -53,7 +54,7 @@ static int bfs_readdir(struct file * f, void * dirent, filldir_t filldir)
53 de = (struct bfs_dirent *)(bh->b_data + offset); 54 de = (struct bfs_dirent *)(bh->b_data + offset);
54 if (de->ino) { 55 if (de->ino) {
55 int size = strnlen(de->name, BFS_NAMELEN); 56 int size = strnlen(de->name, BFS_NAMELEN);
56 if (filldir(dirent, de->name, size, f->f_pos, de->ino, DT_UNKNOWN) < 0) { 57 if (filldir(dirent, de->name, size, f->f_pos, le16_to_cpu(de->ino), DT_UNKNOWN) < 0) {
57 brelse(bh); 58 brelse(bh);
58 unlock_kernel(); 59 unlock_kernel();
59 return 0; 60 return 0;
@@ -107,7 +108,7 @@ static int bfs_create(struct inode * dir, struct dentry * dentry, int mode,
107 inode->i_mapping->a_ops = &bfs_aops; 108 inode->i_mapping->a_ops = &bfs_aops;
108 inode->i_mode = mode; 109 inode->i_mode = mode;
109 inode->i_ino = ino; 110 inode->i_ino = ino;
110 BFS_I(inode)->i_dsk_ino = ino; 111 BFS_I(inode)->i_dsk_ino = cpu_to_le16(ino);
111 BFS_I(inode)->i_sblock = 0; 112 BFS_I(inode)->i_sblock = 0;
112 BFS_I(inode)->i_eblock = 0; 113 BFS_I(inode)->i_eblock = 0;
113 insert_inode_hash(inode); 114 insert_inode_hash(inode);
@@ -139,7 +140,7 @@ static struct dentry * bfs_lookup(struct inode * dir, struct dentry * dentry, st
139 lock_kernel(); 140 lock_kernel();
140 bh = bfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de); 141 bh = bfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de);
141 if (bh) { 142 if (bh) {
142 unsigned long ino = le32_to_cpu(de->ino); 143 unsigned long ino = (unsigned long)le16_to_cpu(de->ino);
143 brelse(bh); 144 brelse(bh);
144 inode = iget(dir->i_sb, ino); 145 inode = iget(dir->i_sb, ino);
145 if (!inode) { 146 if (!inode) {
@@ -183,7 +184,7 @@ static int bfs_unlink(struct inode * dir, struct dentry * dentry)
183 inode = dentry->d_inode; 184 inode = dentry->d_inode;
184 lock_kernel(); 185 lock_kernel();
185 bh = bfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de); 186 bh = bfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de);
186 if (!bh || de->ino != inode->i_ino) 187 if (!bh || le16_to_cpu(de->ino) != inode->i_ino)
187 goto out_brelse; 188 goto out_brelse;
188 189
189 if (!inode->i_nlink) { 190 if (!inode->i_nlink) {
@@ -224,7 +225,7 @@ static int bfs_rename(struct inode * old_dir, struct dentry * old_dentry,
224 old_dentry->d_name.name, 225 old_dentry->d_name.name,
225 old_dentry->d_name.len, &old_de); 226 old_dentry->d_name.len, &old_de);
226 227
227 if (!old_bh || old_de->ino != old_inode->i_ino) 228 if (!old_bh || le16_to_cpu(old_de->ino) != old_inode->i_ino)
228 goto end_rename; 229 goto end_rename;
229 230
230 error = -EPERM; 231 error = -EPERM;
@@ -270,7 +271,7 @@ struct inode_operations bfs_dir_inops = {
270 .rename = bfs_rename, 271 .rename = bfs_rename,
271}; 272};
272 273
273static int bfs_add_entry(struct inode * dir, const char * name, int namelen, int ino) 274static int bfs_add_entry(struct inode * dir, const unsigned char * name, int namelen, int ino)
274{ 275{
275 struct buffer_head * bh; 276 struct buffer_head * bh;
276 struct bfs_dirent * de; 277 struct bfs_dirent * de;
@@ -304,7 +305,7 @@ static int bfs_add_entry(struct inode * dir, const char * name, int namelen, int
304 } 305 }
305 dir->i_mtime = CURRENT_TIME_SEC; 306 dir->i_mtime = CURRENT_TIME_SEC;
306 mark_inode_dirty(dir); 307 mark_inode_dirty(dir);
307 de->ino = ino; 308 de->ino = cpu_to_le16((u16)ino);
308 for (i=0; i<BFS_NAMELEN; i++) 309 for (i=0; i<BFS_NAMELEN; i++)
309 de->name[i] = (i < namelen) ? name[i] : 0; 310 de->name[i] = (i < namelen) ? name[i] : 0;
310 mark_buffer_dirty(bh); 311 mark_buffer_dirty(bh);
@@ -317,7 +318,7 @@ static int bfs_add_entry(struct inode * dir, const char * name, int namelen, int
317 return -ENOSPC; 318 return -ENOSPC;
318} 319}
319 320
320static inline int bfs_namecmp(int len, const char * name, const char * buffer) 321static inline int bfs_namecmp(int len, const unsigned char * name, const char * buffer)
321{ 322{
322 if (len < BFS_NAMELEN && buffer[len]) 323 if (len < BFS_NAMELEN && buffer[len])
323 return 0; 324 return 0;
@@ -325,7 +326,7 @@ static inline int bfs_namecmp(int len, const char * name, const char * buffer)
325} 326}
326 327
327static struct buffer_head * bfs_find_entry(struct inode * dir, 328static struct buffer_head * bfs_find_entry(struct inode * dir,
328 const char * name, int namelen, struct bfs_dirent ** res_dir) 329 const unsigned char * name, int namelen, struct bfs_dirent ** res_dir)
329{ 330{
330 unsigned long block, offset; 331 unsigned long block, offset;
331 struct buffer_head * bh; 332 struct buffer_head * bh;
@@ -346,7 +347,7 @@ static struct buffer_head * bfs_find_entry(struct inode * dir,
346 } 347 }
347 de = (struct bfs_dirent *)(bh->b_data + offset); 348 de = (struct bfs_dirent *)(bh->b_data + offset);
348 offset += BFS_DIRENT_SIZE; 349 offset += BFS_DIRENT_SIZE;
349 if (de->ino && bfs_namecmp(namelen, name, de->name)) { 350 if (le16_to_cpu(de->ino) && bfs_namecmp(namelen, name, de->name)) {
350 *res_dir = de; 351 *res_dir = de;
351 return bh; 352 return bh;
352 } 353 }
diff --git a/fs/bfs/file.c b/fs/bfs/file.c
index 747fd1ea55..807723b65d 100644
--- a/fs/bfs/file.c
+++ b/fs/bfs/file.c
@@ -40,8 +40,8 @@ static int bfs_move_block(unsigned long from, unsigned long to, struct super_blo
40 return 0; 40 return 0;
41} 41}
42 42
43static int bfs_move_blocks(struct super_block *sb, unsigned long start, unsigned long end, 43static int bfs_move_blocks(struct super_block *sb, unsigned long start,
44 unsigned long where) 44 unsigned long end, unsigned long where)
45{ 45{
46 unsigned long i; 46 unsigned long i;
47 47
@@ -57,20 +57,21 @@ static int bfs_move_blocks(struct super_block *sb, unsigned long start, unsigned
57static int bfs_get_block(struct inode * inode, sector_t block, 57static int bfs_get_block(struct inode * inode, sector_t block,
58 struct buffer_head * bh_result, int create) 58 struct buffer_head * bh_result, int create)
59{ 59{
60 long phys; 60 unsigned long phys;
61 int err; 61 int err;
62 struct super_block *sb = inode->i_sb; 62 struct super_block *sb = inode->i_sb;
63 struct bfs_sb_info *info = BFS_SB(sb); 63 struct bfs_sb_info *info = BFS_SB(sb);
64 struct bfs_inode_info *bi = BFS_I(inode); 64 struct bfs_inode_info *bi = BFS_I(inode);
65 struct buffer_head *sbh = info->si_sbh; 65 struct buffer_head *sbh = info->si_sbh;
66 66
67 if (block < 0 || block > info->si_blocks) 67 if (block > info->si_blocks)
68 return -EIO; 68 return -EIO;
69 69
70 phys = bi->i_sblock + block; 70 phys = bi->i_sblock + block;
71 if (!create) { 71 if (!create) {
72 if (phys <= bi->i_eblock) { 72 if (phys <= bi->i_eblock) {
73 dprintf("c=%d, b=%08lx, phys=%08lx (granted)\n", create, block, phys); 73 dprintf("c=%d, b=%08lx, phys=%09lx (granted)\n",
74 create, (unsigned long)block, phys);
74 map_bh(bh_result, sb, phys); 75 map_bh(bh_result, sb, phys);
75 } 76 }
76 return 0; 77 return 0;
@@ -80,7 +81,7 @@ static int bfs_get_block(struct inode * inode, sector_t block,
80 of blocks allocated for this file, we can grant it */ 81 of blocks allocated for this file, we can grant it */
81 if (inode->i_size && phys <= bi->i_eblock) { 82 if (inode->i_size && phys <= bi->i_eblock) {
82 dprintf("c=%d, b=%08lx, phys=%08lx (interim block granted)\n", 83 dprintf("c=%d, b=%08lx, phys=%08lx (interim block granted)\n",
83 create, block, phys); 84 create, (unsigned long)block, phys);
84 map_bh(bh_result, sb, phys); 85 map_bh(bh_result, sb, phys);
85 return 0; 86 return 0;
86 } 87 }
@@ -88,11 +89,12 @@ static int bfs_get_block(struct inode * inode, sector_t block,
88 /* the rest has to be protected against itself */ 89 /* the rest has to be protected against itself */
89 lock_kernel(); 90 lock_kernel();
90 91
91 /* if the last data block for this file is the last allocated block, we can 92 /* if the last data block for this file is the last allocated
92 extend the file trivially, without moving it anywhere */ 93 block, we can extend the file trivially, without moving it
94 anywhere */
93 if (bi->i_eblock == info->si_lf_eblk) { 95 if (bi->i_eblock == info->si_lf_eblk) {
94 dprintf("c=%d, b=%08lx, phys=%08lx (simple extension)\n", 96 dprintf("c=%d, b=%08lx, phys=%08lx (simple extension)\n",
95 create, block, phys); 97 create, (unsigned long)block, phys);
96 map_bh(bh_result, sb, phys); 98 map_bh(bh_result, sb, phys);
97 info->si_freeb -= phys - bi->i_eblock; 99 info->si_freeb -= phys - bi->i_eblock;
98 info->si_lf_eblk = bi->i_eblock = phys; 100 info->si_lf_eblk = bi->i_eblock = phys;
@@ -114,7 +116,8 @@ static int bfs_get_block(struct inode * inode, sector_t block,
114 } else 116 } else
115 err = 0; 117 err = 0;
116 118
117 dprintf("c=%d, b=%08lx, phys=%08lx (moved)\n", create, block, phys); 119 dprintf("c=%d, b=%08lx, phys=%08lx (moved)\n",
120 create, (unsigned long)block, phys);
118 bi->i_sblock = phys; 121 bi->i_sblock = phys;
119 phys += block; 122 phys += block;
120 info->si_lf_eblk = bi->i_eblock = phys; 123 info->si_lf_eblk = bi->i_eblock = phys;
diff --git a/fs/bfs/inode.c b/fs/bfs/inode.c
index 64e0fb33fc..c7b39aa279 100644
--- a/fs/bfs/inode.c
+++ b/fs/bfs/inode.c
@@ -3,6 +3,8 @@
3 * BFS superblock and inode operations. 3 * BFS superblock and inode operations.
4 * Copyright (C) 1999,2000 Tigran Aivazian <tigran@veritas.com> 4 * Copyright (C) 1999,2000 Tigran Aivazian <tigran@veritas.com>
5 * From fs/minix, Copyright (C) 1991, 1992 Linus Torvalds. 5 * From fs/minix, Copyright (C) 1991, 1992 Linus Torvalds.
6 *
7 * Made endianness-clean by Andrew Stribblehill <ads@wompom.org>, 2005.
6 */ 8 */
7 9
8#include <linux/module.h> 10#include <linux/module.h>
@@ -54,46 +56,50 @@ static void bfs_read_inode(struct inode * inode)
54 off = (ino - BFS_ROOT_INO) % BFS_INODES_PER_BLOCK; 56 off = (ino - BFS_ROOT_INO) % BFS_INODES_PER_BLOCK;
55 di = (struct bfs_inode *)bh->b_data + off; 57 di = (struct bfs_inode *)bh->b_data + off;
56 58
57 inode->i_mode = 0x0000FFFF & di->i_mode; 59 inode->i_mode = 0x0000FFFF & le32_to_cpu(di->i_mode);
58 if (di->i_vtype == BFS_VDIR) { 60 if (le32_to_cpu(di->i_vtype) == BFS_VDIR) {
59 inode->i_mode |= S_IFDIR; 61 inode->i_mode |= S_IFDIR;
60 inode->i_op = &bfs_dir_inops; 62 inode->i_op = &bfs_dir_inops;
61 inode->i_fop = &bfs_dir_operations; 63 inode->i_fop = &bfs_dir_operations;
62 } else if (di->i_vtype == BFS_VREG) { 64 } else if (le32_to_cpu(di->i_vtype) == BFS_VREG) {
63 inode->i_mode |= S_IFREG; 65 inode->i_mode |= S_IFREG;
64 inode->i_op = &bfs_file_inops; 66 inode->i_op = &bfs_file_inops;
65 inode->i_fop = &bfs_file_operations; 67 inode->i_fop = &bfs_file_operations;
66 inode->i_mapping->a_ops = &bfs_aops; 68 inode->i_mapping->a_ops = &bfs_aops;
67 } 69 }
68 70
69 inode->i_uid = di->i_uid; 71 BFS_I(inode)->i_sblock = le32_to_cpu(di->i_sblock);
70 inode->i_gid = di->i_gid; 72 BFS_I(inode)->i_eblock = le32_to_cpu(di->i_eblock);
71 inode->i_nlink = di->i_nlink; 73 inode->i_uid = le32_to_cpu(di->i_uid);
74 inode->i_gid = le32_to_cpu(di->i_gid);
75 inode->i_nlink = le32_to_cpu(di->i_nlink);
72 inode->i_size = BFS_FILESIZE(di); 76 inode->i_size = BFS_FILESIZE(di);
73 inode->i_blocks = BFS_FILEBLOCKS(di); 77 inode->i_blocks = BFS_FILEBLOCKS(di);
78 if (inode->i_size || inode->i_blocks) dprintf("Registered inode with %lld size, %ld blocks\n", inode->i_size, inode->i_blocks);
74 inode->i_blksize = PAGE_SIZE; 79 inode->i_blksize = PAGE_SIZE;
75 inode->i_atime.tv_sec = di->i_atime; 80 inode->i_atime.tv_sec = le32_to_cpu(di->i_atime);
76 inode->i_mtime.tv_sec = di->i_mtime; 81 inode->i_mtime.tv_sec = le32_to_cpu(di->i_mtime);
77 inode->i_ctime.tv_sec = di->i_ctime; 82 inode->i_ctime.tv_sec = le32_to_cpu(di->i_ctime);
78 inode->i_atime.tv_nsec = 0; 83 inode->i_atime.tv_nsec = 0;
79 inode->i_mtime.tv_nsec = 0; 84 inode->i_mtime.tv_nsec = 0;
80 inode->i_ctime.tv_nsec = 0; 85 inode->i_ctime.tv_nsec = 0;
81 BFS_I(inode)->i_dsk_ino = di->i_ino; /* can be 0 so we store a copy */ 86 BFS_I(inode)->i_dsk_ino = le16_to_cpu(di->i_ino); /* can be 0 so we store a copy */
82 BFS_I(inode)->i_sblock = di->i_sblock;
83 BFS_I(inode)->i_eblock = di->i_eblock;
84 87
85 brelse(bh); 88 brelse(bh);
86} 89}
87 90
88static int bfs_write_inode(struct inode * inode, int unused) 91static int bfs_write_inode(struct inode * inode, int unused)
89{ 92{
90 unsigned long ino = inode->i_ino; 93 unsigned int ino = (u16)inode->i_ino;
94 unsigned long i_sblock;
91 struct bfs_inode * di; 95 struct bfs_inode * di;
92 struct buffer_head * bh; 96 struct buffer_head * bh;
93 int block, off; 97 int block, off;
94 98
99 dprintf("ino=%08x\n", ino);
100
95 if (ino < BFS_ROOT_INO || ino > BFS_SB(inode->i_sb)->si_lasti) { 101 if (ino < BFS_ROOT_INO || ino > BFS_SB(inode->i_sb)->si_lasti) {
96 printf("Bad inode number %s:%08lx\n", inode->i_sb->s_id, ino); 102 printf("Bad inode number %s:%08x\n", inode->i_sb->s_id, ino);
97 return -EIO; 103 return -EIO;
98 } 104 }
99 105
@@ -101,7 +107,7 @@ static int bfs_write_inode(struct inode * inode, int unused)
101 block = (ino - BFS_ROOT_INO)/BFS_INODES_PER_BLOCK + 1; 107 block = (ino - BFS_ROOT_INO)/BFS_INODES_PER_BLOCK + 1;
102 bh = sb_bread(inode->i_sb, block); 108 bh = sb_bread(inode->i_sb, block);
103 if (!bh) { 109 if (!bh) {
104 printf("Unable to read inode %s:%08lx\n", inode->i_sb->s_id, ino); 110 printf("Unable to read inode %s:%08x\n", inode->i_sb->s_id, ino);
105 unlock_kernel(); 111 unlock_kernel();
106 return -EIO; 112 return -EIO;
107 } 113 }
@@ -109,24 +115,26 @@ static int bfs_write_inode(struct inode * inode, int unused)
109 off = (ino - BFS_ROOT_INO)%BFS_INODES_PER_BLOCK; 115 off = (ino - BFS_ROOT_INO)%BFS_INODES_PER_BLOCK;
110 di = (struct bfs_inode *)bh->b_data + off; 116 di = (struct bfs_inode *)bh->b_data + off;
111 117
112 if (inode->i_ino == BFS_ROOT_INO) 118 if (ino == BFS_ROOT_INO)
113 di->i_vtype = BFS_VDIR; 119 di->i_vtype = cpu_to_le32(BFS_VDIR);
114 else 120 else
115 di->i_vtype = BFS_VREG; 121 di->i_vtype = cpu_to_le32(BFS_VREG);
116 122
117 di->i_ino = inode->i_ino; 123 di->i_ino = cpu_to_le16(ino);
118 di->i_mode = inode->i_mode; 124 di->i_mode = cpu_to_le32(inode->i_mode);
119 di->i_uid = inode->i_uid; 125 di->i_uid = cpu_to_le32(inode->i_uid);
120 di->i_gid = inode->i_gid; 126 di->i_gid = cpu_to_le32(inode->i_gid);
121 di->i_nlink = inode->i_nlink; 127 di->i_nlink = cpu_to_le32(inode->i_nlink);
122 di->i_atime = inode->i_atime.tv_sec; 128 di->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
123 di->i_mtime = inode->i_mtime.tv_sec; 129 di->i_mtime = cpu_to_le32(inode->i_mtime.tv_sec);
124 di->i_ctime = inode->i_ctime.tv_sec; 130 di->i_ctime = cpu_to_le32(inode->i_ctime.tv_sec);
125 di->i_sblock = BFS_I(inode)->i_sblock; 131 i_sblock = BFS_I(inode)->i_sblock;
126 di->i_eblock = BFS_I(inode)->i_eblock; 132 di->i_sblock = cpu_to_le32(i_sblock);
127 di->i_eoffset = di->i_sblock * BFS_BSIZE + inode->i_size - 1; 133 di->i_eblock = cpu_to_le32(BFS_I(inode)->i_eblock);
134 di->i_eoffset = cpu_to_le32(i_sblock * BFS_BSIZE + inode->i_size - 1);
128 135
129 mark_buffer_dirty(bh); 136 mark_buffer_dirty(bh);
137 dprintf("Written ino=%d into %d:%d\n",le16_to_cpu(di->i_ino),block,off);
130 brelse(bh); 138 brelse(bh);
131 unlock_kernel(); 139 unlock_kernel();
132 return 0; 140 return 0;
@@ -140,11 +148,14 @@ static void bfs_delete_inode(struct inode * inode)
140 int block, off; 148 int block, off;
141 struct super_block * s = inode->i_sb; 149 struct super_block * s = inode->i_sb;
142 struct bfs_sb_info * info = BFS_SB(s); 150 struct bfs_sb_info * info = BFS_SB(s);
151 struct bfs_inode_info * bi = BFS_I(inode);
143 152
144 dprintf("ino=%08lx\n", inode->i_ino); 153 dprintf("ino=%08lx\n", ino);
145 154
146 if (inode->i_ino < BFS_ROOT_INO || inode->i_ino > info->si_lasti) { 155 truncate_inode_pages(&inode->i_data, 0);
147 printf("invalid ino=%08lx\n", inode->i_ino); 156
157 if (ino < BFS_ROOT_INO || ino > info->si_lasti) {
158 printf("invalid ino=%08lx\n", ino);
148 return; 159 return;
149 } 160 }
150 161
@@ -160,13 +171,13 @@ static void bfs_delete_inode(struct inode * inode)
160 return; 171 return;
161 } 172 }
162 off = (ino - BFS_ROOT_INO)%BFS_INODES_PER_BLOCK; 173 off = (ino - BFS_ROOT_INO)%BFS_INODES_PER_BLOCK;
163 di = (struct bfs_inode *)bh->b_data + off; 174 di = (struct bfs_inode *) bh->b_data + off;
164 if (di->i_ino) { 175 if (bi->i_dsk_ino) {
165 info->si_freeb += BFS_FILEBLOCKS(di); 176 info->si_freeb += 1 + bi->i_eblock - bi->i_sblock;
166 info->si_freei++; 177 info->si_freei++;
167 clear_bit(di->i_ino, info->si_imap); 178 clear_bit(ino, info->si_imap);
168 dump_imap("delete_inode", s); 179 dump_imap("delete_inode", s);
169 } 180 }
170 di->i_ino = 0; 181 di->i_ino = 0;
171 di->i_sblock = 0; 182 di->i_sblock = 0;
172 mark_buffer_dirty(bh); 183 mark_buffer_dirty(bh);
@@ -272,14 +283,14 @@ static struct super_operations bfs_sops = {
272 283
273void dump_imap(const char *prefix, struct super_block * s) 284void dump_imap(const char *prefix, struct super_block * s)
274{ 285{
275#if 0 286#ifdef DEBUG
276 int i; 287 int i;
277 char *tmpbuf = (char *)get_zeroed_page(GFP_KERNEL); 288 char *tmpbuf = (char *)get_zeroed_page(GFP_KERNEL);
278 289
279 if (!tmpbuf) 290 if (!tmpbuf)
280 return; 291 return;
281 for (i=BFS_SB(s)->si_lasti; i>=0; i--) { 292 for (i=BFS_SB(s)->si_lasti; i>=0; i--) {
282 if (i>PAGE_SIZE-100) break; 293 if (i > PAGE_SIZE-100) break;
283 if (test_bit(i, BFS_SB(s)->si_imap)) 294 if (test_bit(i, BFS_SB(s)->si_imap))
284 strcat(tmpbuf, "1"); 295 strcat(tmpbuf, "1");
285 else 296 else
@@ -295,7 +306,7 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
295 struct buffer_head * bh; 306 struct buffer_head * bh;
296 struct bfs_super_block * bfs_sb; 307 struct bfs_super_block * bfs_sb;
297 struct inode * inode; 308 struct inode * inode;
298 int i, imap_len; 309 unsigned i, imap_len;
299 struct bfs_sb_info * info; 310 struct bfs_sb_info * info;
300 311
301 info = kmalloc(sizeof(*info), GFP_KERNEL); 312 info = kmalloc(sizeof(*info), GFP_KERNEL);
@@ -310,19 +321,18 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
310 if(!bh) 321 if(!bh)
311 goto out; 322 goto out;
312 bfs_sb = (struct bfs_super_block *)bh->b_data; 323 bfs_sb = (struct bfs_super_block *)bh->b_data;
313 if (bfs_sb->s_magic != BFS_MAGIC) { 324 if (le32_to_cpu(bfs_sb->s_magic) != BFS_MAGIC) {
314 if (!silent) 325 if (!silent)
315 printf("No BFS filesystem on %s (magic=%08x)\n", 326 printf("No BFS filesystem on %s (magic=%08x)\n",
316 s->s_id, bfs_sb->s_magic); 327 s->s_id, le32_to_cpu(bfs_sb->s_magic));
317 goto out; 328 goto out;
318 } 329 }
319 if (BFS_UNCLEAN(bfs_sb, s) && !silent) 330 if (BFS_UNCLEAN(bfs_sb, s) && !silent)
320 printf("%s is unclean, continuing\n", s->s_id); 331 printf("%s is unclean, continuing\n", s->s_id);
321 332
322 s->s_magic = BFS_MAGIC; 333 s->s_magic = BFS_MAGIC;
323 info->si_bfs_sb = bfs_sb;
324 info->si_sbh = bh; 334 info->si_sbh = bh;
325 info->si_lasti = (bfs_sb->s_start - BFS_BSIZE)/sizeof(struct bfs_inode) 335 info->si_lasti = (le32_to_cpu(bfs_sb->s_start) - BFS_BSIZE)/sizeof(struct bfs_inode)
326 + BFS_ROOT_INO - 1; 336 + BFS_ROOT_INO - 1;
327 337
328 imap_len = info->si_lasti/8 + 1; 338 imap_len = info->si_lasti/8 + 1;
@@ -346,8 +356,8 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
346 goto out; 356 goto out;
347 } 357 }
348 358
349 info->si_blocks = (bfs_sb->s_end + 1)>>BFS_BSIZE_BITS; /* for statfs(2) */ 359 info->si_blocks = (le32_to_cpu(bfs_sb->s_end) + 1)>>BFS_BSIZE_BITS; /* for statfs(2) */
350 info->si_freeb = (bfs_sb->s_end + 1 - bfs_sb->s_start)>>BFS_BSIZE_BITS; 360 info->si_freeb = (le32_to_cpu(bfs_sb->s_end) + 1 - cpu_to_le32(bfs_sb->s_start))>>BFS_BSIZE_BITS;
351 info->si_freei = 0; 361 info->si_freei = 0;
352 info->si_lf_eblk = 0; 362 info->si_lf_eblk = 0;
353 info->si_lf_sblk = 0; 363 info->si_lf_sblk = 0;
diff --git a/fs/buffer.c b/fs/buffer.c
index 1c62203a49..6cbfceabd9 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -40,6 +40,7 @@
40#include <linux/cpu.h> 40#include <linux/cpu.h>
41#include <linux/bitops.h> 41#include <linux/bitops.h>
42#include <linux/mpage.h> 42#include <linux/mpage.h>
43#include <linux/bit_spinlock.h>
43 44
44static int fsync_buffers_list(spinlock_t *lock, struct list_head *list); 45static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
45static void invalidate_bh_lrus(void); 46static void invalidate_bh_lrus(void);
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 3217ac5f6b..2335f14a15 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -3215,10 +3215,8 @@ cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb)
3215 } 3215 }
3216 3216
3217 cifs_sb->tcon = NULL; 3217 cifs_sb->tcon = NULL;
3218 if (ses) { 3218 if (ses)
3219 set_current_state(TASK_INTERRUPTIBLE); 3219 schedule_timeout_interruptible(msecs_to_jiffies(500));
3220 schedule_timeout(HZ / 2);
3221 }
3222 if (ses) 3220 if (ses)
3223 sesInfoFree(ses); 3221 sesInfoFree(ses);
3224 3222
diff --git a/fs/compat.c b/fs/compat.c
index 8c665705c6..ac3fb9ed8e 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -1619,6 +1619,7 @@ compat_sys_select(int n, compat_ulong_t __user *inp, compat_ulong_t __user *outp
1619 char *bits; 1619 char *bits;
1620 long timeout; 1620 long timeout;
1621 int size, max_fdset, ret = -EINVAL; 1621 int size, max_fdset, ret = -EINVAL;
1622 struct fdtable *fdt;
1622 1623
1623 timeout = MAX_SCHEDULE_TIMEOUT; 1624 timeout = MAX_SCHEDULE_TIMEOUT;
1624 if (tvp) { 1625 if (tvp) {
@@ -1644,7 +1645,10 @@ compat_sys_select(int n, compat_ulong_t __user *inp, compat_ulong_t __user *outp
1644 goto out_nofds; 1645 goto out_nofds;
1645 1646
1646 /* max_fdset can increase, so grab it once to avoid race */ 1647 /* max_fdset can increase, so grab it once to avoid race */
1647 max_fdset = current->files->max_fdset; 1648 rcu_read_lock();
1649 fdt = files_fdtable(current->files);
1650 max_fdset = fdt->max_fdset;
1651 rcu_read_unlock();
1648 if (n > max_fdset) 1652 if (n > max_fdset)
1649 n = max_fdset; 1653 n = max_fdset;
1650 1654
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 155e612635..e28a74203f 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -798,13 +798,16 @@ static int routing_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
798 r = (void *) &r4; 798 r = (void *) &r4;
799 } 799 }
800 800
801 if (ret) 801 if (ret) {
802 return -EFAULT; 802 ret = -EFAULT;
803 goto out;
804 }
803 805
804 set_fs (KERNEL_DS); 806 set_fs (KERNEL_DS);
805 ret = sys_ioctl (fd, cmd, (unsigned long) r); 807 ret = sys_ioctl (fd, cmd, (unsigned long) r);
806 set_fs (old_fs); 808 set_fs (old_fs);
807 809
810out:
808 if (mysock) 811 if (mysock)
809 sockfd_put(mysock); 812 sockfd_put(mysock);
810 813
diff --git a/fs/cramfs/uncompress.c b/fs/cramfs/uncompress.c
index 5034365b06..8def89f2c4 100644
--- a/fs/cramfs/uncompress.c
+++ b/fs/cramfs/uncompress.c
@@ -19,6 +19,7 @@
19#include <linux/errno.h> 19#include <linux/errno.h>
20#include <linux/vmalloc.h> 20#include <linux/vmalloc.h>
21#include <linux/zlib.h> 21#include <linux/zlib.h>
22#include <linux/cramfs_fs.h>
22 23
23static z_stream stream; 24static z_stream stream;
24static int initialized; 25static int initialized;
diff --git a/fs/dcache.c b/fs/dcache.c
index a15a2e1f55..7376b61269 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -337,12 +337,10 @@ struct dentry * d_find_alias(struct inode *inode)
337 */ 337 */
338void d_prune_aliases(struct inode *inode) 338void d_prune_aliases(struct inode *inode)
339{ 339{
340 struct list_head *tmp, *head = &inode->i_dentry; 340 struct dentry *dentry;
341restart: 341restart:
342 spin_lock(&dcache_lock); 342 spin_lock(&dcache_lock);
343 tmp = head; 343 list_for_each_entry(dentry, &inode->i_dentry, d_alias) {
344 while ((tmp = tmp->next) != head) {
345 struct dentry *dentry = list_entry(tmp, struct dentry, d_alias);
346 spin_lock(&dentry->d_lock); 344 spin_lock(&dentry->d_lock);
347 if (!atomic_read(&dentry->d_count)) { 345 if (!atomic_read(&dentry->d_count)) {
348 __dget_locked(dentry); 346 __dget_locked(dentry);
@@ -463,10 +461,7 @@ void shrink_dcache_sb(struct super_block * sb)
463 * superblock to the most recent end of the unused list. 461 * superblock to the most recent end of the unused list.
464 */ 462 */
465 spin_lock(&dcache_lock); 463 spin_lock(&dcache_lock);
466 next = dentry_unused.next; 464 list_for_each_safe(tmp, next, &dentry_unused) {
467 while (next != &dentry_unused) {
468 tmp = next;
469 next = tmp->next;
470 dentry = list_entry(tmp, struct dentry, d_lru); 465 dentry = list_entry(tmp, struct dentry, d_lru);
471 if (dentry->d_sb != sb) 466 if (dentry->d_sb != sb)
472 continue; 467 continue;
@@ -478,10 +473,7 @@ void shrink_dcache_sb(struct super_block * sb)
478 * Pass two ... free the dentries for this superblock. 473 * Pass two ... free the dentries for this superblock.
479 */ 474 */
480repeat: 475repeat:
481 next = dentry_unused.next; 476 list_for_each_safe(tmp, next, &dentry_unused) {
482 while (next != &dentry_unused) {
483 tmp = next;
484 next = tmp->next;
485 dentry = list_entry(tmp, struct dentry, d_lru); 477 dentry = list_entry(tmp, struct dentry, d_lru);
486 if (dentry->d_sb != sb) 478 if (dentry->d_sb != sb)
487 continue; 479 continue;
diff --git a/fs/exec.c b/fs/exec.c
index 222ab1c572..14dd03907c 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -798,6 +798,7 @@ no_thread_group:
798static inline void flush_old_files(struct files_struct * files) 798static inline void flush_old_files(struct files_struct * files)
799{ 799{
800 long j = -1; 800 long j = -1;
801 struct fdtable *fdt;
801 802
802 spin_lock(&files->file_lock); 803 spin_lock(&files->file_lock);
803 for (;;) { 804 for (;;) {
@@ -805,12 +806,13 @@ static inline void flush_old_files(struct files_struct * files)
805 806
806 j++; 807 j++;
807 i = j * __NFDBITS; 808 i = j * __NFDBITS;
808 if (i >= files->max_fds || i >= files->max_fdset) 809 fdt = files_fdtable(files);
810 if (i >= fdt->max_fds || i >= fdt->max_fdset)
809 break; 811 break;
810 set = files->close_on_exec->fds_bits[j]; 812 set = fdt->close_on_exec->fds_bits[j];
811 if (!set) 813 if (!set)
812 continue; 814 continue;
813 files->close_on_exec->fds_bits[j] = 0; 815 fdt->close_on_exec->fds_bits[j] = 0;
814 spin_unlock(&files->file_lock); 816 spin_unlock(&files->file_lock);
815 for ( ; set ; i++,set >>= 1) { 817 for ( ; set ; i++,set >>= 1) {
816 if (set & 1) { 818 if (set & 1) {
diff --git a/fs/ext2/ialloc.c b/fs/ext2/ialloc.c
index 161f156d98..c8d07030c8 100644
--- a/fs/ext2/ialloc.c
+++ b/fs/ext2/ialloc.c
@@ -615,6 +615,11 @@ got:
615 DQUOT_DROP(inode); 615 DQUOT_DROP(inode);
616 goto fail2; 616 goto fail2;
617 } 617 }
618 err = ext2_init_security(inode,dir);
619 if (err) {
620 DQUOT_FREE_INODE(inode);
621 goto fail2;
622 }
618 mark_inode_dirty(inode); 623 mark_inode_dirty(inode);
619 ext2_debug("allocating inode %lu\n", inode->i_ino); 624 ext2_debug("allocating inode %lu\n", inode->i_ino);
620 ext2_preread_inode(inode); 625 ext2_preread_inode(inode);
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index 53dceb0c65..fdba4d1d3c 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -71,6 +71,8 @@ void ext2_put_inode(struct inode *inode)
71 */ 71 */
72void ext2_delete_inode (struct inode * inode) 72void ext2_delete_inode (struct inode * inode)
73{ 73{
74 truncate_inode_pages(&inode->i_data, 0);
75
74 if (is_bad_inode(inode)) 76 if (is_bad_inode(inode))
75 goto no_delete; 77 goto no_delete;
76 EXT2_I(inode)->i_dtime = get_seconds(); 78 EXT2_I(inode)->i_dtime = get_seconds();
diff --git a/fs/ext2/xattr.h b/fs/ext2/xattr.h
index 5f3bfde3b8..67cfeb66e8 100644
--- a/fs/ext2/xattr.h
+++ b/fs/ext2/xattr.h
@@ -116,3 +116,11 @@ exit_ext2_xattr(void)
116 116
117# endif /* CONFIG_EXT2_FS_XATTR */ 117# endif /* CONFIG_EXT2_FS_XATTR */
118 118
119#ifdef CONFIG_EXT2_FS_SECURITY
120extern int ext2_init_security(struct inode *inode, struct inode *dir);
121#else
122static inline int ext2_init_security(struct inode *inode, struct inode *dir)
123{
124 return 0;
125}
126#endif
diff --git a/fs/ext2/xattr_security.c b/fs/ext2/xattr_security.c
index 6a6c59fbe5..a266127984 100644
--- a/fs/ext2/xattr_security.c
+++ b/fs/ext2/xattr_security.c
@@ -8,6 +8,7 @@
8#include <linux/fs.h> 8#include <linux/fs.h>
9#include <linux/smp_lock.h> 9#include <linux/smp_lock.h>
10#include <linux/ext2_fs.h> 10#include <linux/ext2_fs.h>
11#include <linux/security.h>
11#include "xattr.h" 12#include "xattr.h"
12 13
13static size_t 14static size_t
@@ -45,6 +46,27 @@ ext2_xattr_security_set(struct inode *inode, const char *name,
45 value, size, flags); 46 value, size, flags);
46} 47}
47 48
49int
50ext2_init_security(struct inode *inode, struct inode *dir)
51{
52 int err;
53 size_t len;
54 void *value;
55 char *name;
56
57 err = security_inode_init_security(inode, dir, &name, &value, &len);
58 if (err) {
59 if (err == -EOPNOTSUPP)
60 return 0;
61 return err;
62 }
63 err = ext2_xattr_set(inode, EXT2_XATTR_INDEX_SECURITY,
64 name, value, len, 0);
65 kfree(name);
66 kfree(value);
67 return err;
68}
69
48struct xattr_handler ext2_xattr_security_handler = { 70struct xattr_handler ext2_xattr_security_handler = {
49 .prefix = XATTR_SECURITY_PREFIX, 71 .prefix = XATTR_SECURITY_PREFIX,
50 .list = ext2_xattr_security_list, 72 .list = ext2_xattr_security_list,
diff --git a/fs/ext3/ialloc.c b/fs/ext3/ialloc.c
index 6981bd014e..96552769d0 100644
--- a/fs/ext3/ialloc.c
+++ b/fs/ext3/ialloc.c
@@ -607,6 +607,11 @@ got:
607 DQUOT_DROP(inode); 607 DQUOT_DROP(inode);
608 goto fail2; 608 goto fail2;
609 } 609 }
610 err = ext3_init_security(handle,inode, dir);
611 if (err) {
612 DQUOT_FREE_INODE(inode);
613 goto fail2;
614 }
610 err = ext3_mark_inode_dirty(handle, inode); 615 err = ext3_mark_inode_dirty(handle, inode);
611 if (err) { 616 if (err) {
612 ext3_std_error(sb, err); 617 ext3_std_error(sb, err);
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index 9989fdcf4d..b5177c90d6 100644
--- a/fs/ext3/inode.c
+++ b/fs/ext3/inode.c
@@ -187,6 +187,8 @@ void ext3_delete_inode (struct inode * inode)
187{ 187{
188 handle_t *handle; 188 handle_t *handle;
189 189
190 truncate_inode_pages(&inode->i_data, 0);
191
190 if (is_bad_inode(inode)) 192 if (is_bad_inode(inode))
191 goto no_delete; 193 goto no_delete;
192 194
diff --git a/fs/ext3/xattr.h b/fs/ext3/xattr.h
index eb31a69e82..2ceae38f3d 100644
--- a/fs/ext3/xattr.h
+++ b/fs/ext3/xattr.h
@@ -133,3 +133,14 @@ exit_ext3_xattr(void)
133#define ext3_xattr_handlers NULL 133#define ext3_xattr_handlers NULL
134 134
135# endif /* CONFIG_EXT3_FS_XATTR */ 135# endif /* CONFIG_EXT3_FS_XATTR */
136
137#ifdef CONFIG_EXT3_FS_SECURITY
138extern int ext3_init_security(handle_t *handle, struct inode *inode,
139 struct inode *dir);
140#else
141static inline int ext3_init_security(handle_t *handle, struct inode *inode,
142 struct inode *dir)
143{
144 return 0;
145}
146#endif
diff --git a/fs/ext3/xattr_security.c b/fs/ext3/xattr_security.c
index ddc1c41750..b9c40c1564 100644
--- a/fs/ext3/xattr_security.c
+++ b/fs/ext3/xattr_security.c
@@ -9,6 +9,7 @@
9#include <linux/smp_lock.h> 9#include <linux/smp_lock.h>
10#include <linux/ext3_jbd.h> 10#include <linux/ext3_jbd.h>
11#include <linux/ext3_fs.h> 11#include <linux/ext3_fs.h>
12#include <linux/security.h>
12#include "xattr.h" 13#include "xattr.h"
13 14
14static size_t 15static size_t
@@ -47,6 +48,27 @@ ext3_xattr_security_set(struct inode *inode, const char *name,
47 value, size, flags); 48 value, size, flags);
48} 49}
49 50
51int
52ext3_init_security(handle_t *handle, struct inode *inode, struct inode *dir)
53{
54 int err;
55 size_t len;
56 void *value;
57 char *name;
58
59 err = security_inode_init_security(inode, dir, &name, &value, &len);
60 if (err) {
61 if (err == -EOPNOTSUPP)
62 return 0;
63 return err;
64 }
65 err = ext3_xattr_set_handle(handle, inode, EXT3_XATTR_INDEX_SECURITY,
66 name, value, len, 0);
67 kfree(name);
68 kfree(value);
69 return err;
70}
71
50struct xattr_handler ext3_xattr_security_handler = { 72struct xattr_handler ext3_xattr_security_handler = {
51 .prefix = XATTR_SECURITY_PREFIX, 73 .prefix = XATTR_SECURITY_PREFIX,
52 .list = ext3_xattr_security_list, 74 .list = ext3_xattr_security_list,
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index 96ae85b67e..a7cbe68e22 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -335,6 +335,8 @@ EXPORT_SYMBOL(fat_build_inode);
335 335
336static void fat_delete_inode(struct inode *inode) 336static void fat_delete_inode(struct inode *inode)
337{ 337{
338 truncate_inode_pages(&inode->i_data, 0);
339
338 if (!is_bad_inode(inode)) { 340 if (!is_bad_inode(inode)) {
339 inode->i_size = 0; 341 inode->i_size = 0;
340 fat_truncate(inode); 342 fat_truncate(inode);
diff --git a/fs/fcntl.c b/fs/fcntl.c
index 6fbc9d8fcc..863b46e0d7 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -16,6 +16,7 @@
16#include <linux/security.h> 16#include <linux/security.h>
17#include <linux/ptrace.h> 17#include <linux/ptrace.h>
18#include <linux/signal.h> 18#include <linux/signal.h>
19#include <linux/rcupdate.h>
19 20
20#include <asm/poll.h> 21#include <asm/poll.h>
21#include <asm/siginfo.h> 22#include <asm/siginfo.h>
@@ -24,21 +25,25 @@
24void fastcall set_close_on_exec(unsigned int fd, int flag) 25void fastcall set_close_on_exec(unsigned int fd, int flag)
25{ 26{
26 struct files_struct *files = current->files; 27 struct files_struct *files = current->files;
28 struct fdtable *fdt;
27 spin_lock(&files->file_lock); 29 spin_lock(&files->file_lock);
30 fdt = files_fdtable(files);
28 if (flag) 31 if (flag)
29 FD_SET(fd, files->close_on_exec); 32 FD_SET(fd, fdt->close_on_exec);
30 else 33 else
31 FD_CLR(fd, files->close_on_exec); 34 FD_CLR(fd, fdt->close_on_exec);
32 spin_unlock(&files->file_lock); 35 spin_unlock(&files->file_lock);
33} 36}
34 37
35static inline int get_close_on_exec(unsigned int fd) 38static inline int get_close_on_exec(unsigned int fd)
36{ 39{
37 struct files_struct *files = current->files; 40 struct files_struct *files = current->files;
41 struct fdtable *fdt;
38 int res; 42 int res;
39 spin_lock(&files->file_lock); 43 rcu_read_lock();
40 res = FD_ISSET(fd, files->close_on_exec); 44 fdt = files_fdtable(files);
41 spin_unlock(&files->file_lock); 45 res = FD_ISSET(fd, fdt->close_on_exec);
46 rcu_read_unlock();
42 return res; 47 return res;
43} 48}
44 49
@@ -54,24 +59,26 @@ static int locate_fd(struct files_struct *files,
54 unsigned int newfd; 59 unsigned int newfd;
55 unsigned int start; 60 unsigned int start;
56 int error; 61 int error;
62 struct fdtable *fdt;
57 63
58 error = -EINVAL; 64 error = -EINVAL;
59 if (orig_start >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur) 65 if (orig_start >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
60 goto out; 66 goto out;
61 67
62repeat: 68repeat:
69 fdt = files_fdtable(files);
63 /* 70 /*
64 * Someone might have closed fd's in the range 71 * Someone might have closed fd's in the range
65 * orig_start..files->next_fd 72 * orig_start..fdt->next_fd
66 */ 73 */
67 start = orig_start; 74 start = orig_start;
68 if (start < files->next_fd) 75 if (start < fdt->next_fd)
69 start = files->next_fd; 76 start = fdt->next_fd;
70 77
71 newfd = start; 78 newfd = start;
72 if (start < files->max_fdset) { 79 if (start < fdt->max_fdset) {
73 newfd = find_next_zero_bit(files->open_fds->fds_bits, 80 newfd = find_next_zero_bit(fdt->open_fds->fds_bits,
74 files->max_fdset, start); 81 fdt->max_fdset, start);
75 } 82 }
76 83
77 error = -EMFILE; 84 error = -EMFILE;
@@ -89,9 +96,15 @@ repeat:
89 if (error) 96 if (error)
90 goto repeat; 97 goto repeat;
91 98
92 if (start <= files->next_fd) 99 /*
93 files->next_fd = newfd + 1; 100 * We reacquired files_lock, so we are safe as long as
94 101 * we reacquire the fdtable pointer and use it while holding
102 * the lock, no one can free it during that time.
103 */
104 fdt = files_fdtable(files);
105 if (start <= fdt->next_fd)
106 fdt->next_fd = newfd + 1;
107
95 error = newfd; 108 error = newfd;
96 109
97out: 110out:
@@ -101,13 +114,16 @@ out:
101static int dupfd(struct file *file, unsigned int start) 114static int dupfd(struct file *file, unsigned int start)
102{ 115{
103 struct files_struct * files = current->files; 116 struct files_struct * files = current->files;
117 struct fdtable *fdt;
104 int fd; 118 int fd;
105 119
106 spin_lock(&files->file_lock); 120 spin_lock(&files->file_lock);
107 fd = locate_fd(files, file, start); 121 fd = locate_fd(files, file, start);
108 if (fd >= 0) { 122 if (fd >= 0) {
109 FD_SET(fd, files->open_fds); 123 /* locate_fd() may have expanded fdtable, load the ptr */
110 FD_CLR(fd, files->close_on_exec); 124 fdt = files_fdtable(files);
125 FD_SET(fd, fdt->open_fds);
126 FD_CLR(fd, fdt->close_on_exec);
111 spin_unlock(&files->file_lock); 127 spin_unlock(&files->file_lock);
112 fd_install(fd, file); 128 fd_install(fd, file);
113 } else { 129 } else {
@@ -123,6 +139,7 @@ asmlinkage long sys_dup2(unsigned int oldfd, unsigned int newfd)
123 int err = -EBADF; 139 int err = -EBADF;
124 struct file * file, *tofree; 140 struct file * file, *tofree;
125 struct files_struct * files = current->files; 141 struct files_struct * files = current->files;
142 struct fdtable *fdt;
126 143
127 spin_lock(&files->file_lock); 144 spin_lock(&files->file_lock);
128 if (!(file = fcheck(oldfd))) 145 if (!(file = fcheck(oldfd)))
@@ -148,13 +165,14 @@ asmlinkage long sys_dup2(unsigned int oldfd, unsigned int newfd)
148 165
149 /* Yes. It's a race. In user space. Nothing sane to do */ 166 /* Yes. It's a race. In user space. Nothing sane to do */
150 err = -EBUSY; 167 err = -EBUSY;
151 tofree = files->fd[newfd]; 168 fdt = files_fdtable(files);
152 if (!tofree && FD_ISSET(newfd, files->open_fds)) 169 tofree = fdt->fd[newfd];
170 if (!tofree && FD_ISSET(newfd, fdt->open_fds))
153 goto out_fput; 171 goto out_fput;
154 172
155 files->fd[newfd] = file; 173 rcu_assign_pointer(fdt->fd[newfd], file);
156 FD_SET(newfd, files->open_fds); 174 FD_SET(newfd, fdt->open_fds);
157 FD_CLR(newfd, files->close_on_exec); 175 FD_CLR(newfd, fdt->close_on_exec);
158 spin_unlock(&files->file_lock); 176 spin_unlock(&files->file_lock);
159 177
160 if (tofree) 178 if (tofree)
diff --git a/fs/file.c b/fs/file.c
index 92b5f25985..2127a7b9dc 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -13,6 +13,25 @@
13#include <linux/vmalloc.h> 13#include <linux/vmalloc.h>
14#include <linux/file.h> 14#include <linux/file.h>
15#include <linux/bitops.h> 15#include <linux/bitops.h>
16#include <linux/interrupt.h>
17#include <linux/spinlock.h>
18#include <linux/rcupdate.h>
19#include <linux/workqueue.h>
20
21struct fdtable_defer {
22 spinlock_t lock;
23 struct work_struct wq;
24 struct timer_list timer;
25 struct fdtable *next;
26};
27
28/*
29 * We use this list to defer free fdtables that have vmalloced
30 * sets/arrays. By keeping a per-cpu list, we avoid having to embed
31 * the work_struct in fdtable itself which avoids a 64 byte (i386) increase in
32 * this per-task structure.
33 */
34static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list);
16 35
17 36
18/* 37/*
@@ -48,82 +67,143 @@ void free_fd_array(struct file **array, int num)
48 vfree(array); 67 vfree(array);
49} 68}
50 69
51/* 70static void __free_fdtable(struct fdtable *fdt)
52 * Expand the fd array in the files_struct. Called with the files 71{
53 * spinlock held for write. 72 int fdset_size, fdarray_size;
54 */
55 73
56static int expand_fd_array(struct files_struct *files, int nr) 74 fdset_size = fdt->max_fdset / 8;
57 __releases(files->file_lock) 75 fdarray_size = fdt->max_fds * sizeof(struct file *);
58 __acquires(files->file_lock) 76 free_fdset(fdt->open_fds, fdset_size);
77 free_fdset(fdt->close_on_exec, fdset_size);
78 free_fd_array(fdt->fd, fdarray_size);
79 kfree(fdt);
80}
81
82static void fdtable_timer(unsigned long data)
59{ 83{
60 struct file **new_fds; 84 struct fdtable_defer *fddef = (struct fdtable_defer *)data;
61 int error, nfds;
62 85
63 86 spin_lock(&fddef->lock);
64 error = -EMFILE; 87 /*
65 if (files->max_fds >= NR_OPEN || nr >= NR_OPEN) 88 * If someone already emptied the queue return.
89 */
90 if (!fddef->next)
66 goto out; 91 goto out;
92 if (!schedule_work(&fddef->wq))
93 mod_timer(&fddef->timer, 5);
94out:
95 spin_unlock(&fddef->lock);
96}
67 97
68 nfds = files->max_fds; 98static void free_fdtable_work(struct fdtable_defer *f)
69 spin_unlock(&files->file_lock); 99{
100 struct fdtable *fdt;
70 101
71 /* 102 spin_lock_bh(&f->lock);
72 * Expand to the max in easy steps, and keep expanding it until 103 fdt = f->next;
73 * we have enough for the requested fd array size. 104 f->next = NULL;
74 */ 105 spin_unlock_bh(&f->lock);
106 while(fdt) {
107 struct fdtable *next = fdt->next;
108 __free_fdtable(fdt);
109 fdt = next;
110 }
111}
75 112
76 do { 113static void free_fdtable_rcu(struct rcu_head *rcu)
77#if NR_OPEN_DEFAULT < 256 114{
78 if (nfds < 256) 115 struct fdtable *fdt = container_of(rcu, struct fdtable, rcu);
79 nfds = 256; 116 int fdset_size, fdarray_size;
80 else 117 struct fdtable_defer *fddef;
81#endif
82 if (nfds < (PAGE_SIZE / sizeof(struct file *)))
83 nfds = PAGE_SIZE / sizeof(struct file *);
84 else {
85 nfds = nfds * 2;
86 if (nfds > NR_OPEN)
87 nfds = NR_OPEN;
88 }
89 } while (nfds <= nr);
90 118
91 error = -ENOMEM; 119 BUG_ON(!fdt);
92 new_fds = alloc_fd_array(nfds); 120 fdset_size = fdt->max_fdset / 8;
93 spin_lock(&files->file_lock); 121 fdarray_size = fdt->max_fds * sizeof(struct file *);
94 if (!new_fds)
95 goto out;
96 122
97 /* Copy the existing array and install the new pointer */ 123 if (fdt->free_files) {
98 124 /*
99 if (nfds > files->max_fds) { 125 * The this fdtable was embedded in the files structure
100 struct file **old_fds; 126 * and the files structure itself was getting destroyed.
101 int i; 127 * It is now safe to free the files structure.
102 128 */
103 old_fds = xchg(&files->fd, new_fds); 129 kmem_cache_free(files_cachep, fdt->free_files);
104 i = xchg(&files->max_fds, nfds); 130 return;
105 131 }
106 /* Don't copy/clear the array if we are creating a new 132 if (fdt->max_fdset <= __FD_SETSIZE && fdt->max_fds <= NR_OPEN_DEFAULT) {
107 fd array for fork() */ 133 /*
108 if (i) { 134 * The fdtable was embedded
109 memcpy(new_fds, old_fds, i * sizeof(struct file *)); 135 */
110 /* clear the remainder of the array */ 136 return;
111 memset(&new_fds[i], 0, 137 }
112 (nfds-i) * sizeof(struct file *)); 138 if (fdset_size <= PAGE_SIZE && fdarray_size <= PAGE_SIZE) {
113 139 kfree(fdt->open_fds);
114 spin_unlock(&files->file_lock); 140 kfree(fdt->close_on_exec);
115 free_fd_array(old_fds, i); 141 kfree(fdt->fd);
116 spin_lock(&files->file_lock); 142 kfree(fdt);
117 }
118 } else { 143 } else {
119 /* Somebody expanded the array while we slept ... */ 144 fddef = &get_cpu_var(fdtable_defer_list);
120 spin_unlock(&files->file_lock); 145 spin_lock(&fddef->lock);
121 free_fd_array(new_fds, nfds); 146 fdt->next = fddef->next;
122 spin_lock(&files->file_lock); 147 fddef->next = fdt;
148 /*
149 * vmallocs are handled from the workqueue context.
150 * If the per-cpu workqueue is running, then we
151 * defer work scheduling through a timer.
152 */
153 if (!schedule_work(&fddef->wq))
154 mod_timer(&fddef->timer, 5);
155 spin_unlock(&fddef->lock);
156 put_cpu_var(fdtable_defer_list);
123 } 157 }
124 error = 0; 158}
125out: 159
126 return error; 160void free_fdtable(struct fdtable *fdt)
161{
162 if (fdt->free_files || fdt->max_fdset > __FD_SETSIZE ||
163 fdt->max_fds > NR_OPEN_DEFAULT)
164 call_rcu(&fdt->rcu, free_fdtable_rcu);
165}
166
167/*
168 * Expand the fdset in the files_struct. Called with the files spinlock
169 * held for write.
170 */
171static void copy_fdtable(struct fdtable *nfdt, struct fdtable *fdt)
172{
173 int i;
174 int count;
175
176 BUG_ON(nfdt->max_fdset < fdt->max_fdset);
177 BUG_ON(nfdt->max_fds < fdt->max_fds);
178 /* Copy the existing tables and install the new pointers */
179
180 i = fdt->max_fdset / (sizeof(unsigned long) * 8);
181 count = (nfdt->max_fdset - fdt->max_fdset) / 8;
182
183 /*
184 * Don't copy the entire array if the current fdset is
185 * not yet initialised.
186 */
187 if (i) {
188 memcpy (nfdt->open_fds, fdt->open_fds,
189 fdt->max_fdset/8);
190 memcpy (nfdt->close_on_exec, fdt->close_on_exec,
191 fdt->max_fdset/8);
192 memset (&nfdt->open_fds->fds_bits[i], 0, count);
193 memset (&nfdt->close_on_exec->fds_bits[i], 0, count);
194 }
195
196 /* Don't copy/clear the array if we are creating a new
197 fd array for fork() */
198 if (fdt->max_fds) {
199 memcpy(nfdt->fd, fdt->fd,
200 fdt->max_fds * sizeof(struct file *));
201 /* clear the remainder of the array */
202 memset(&nfdt->fd[fdt->max_fds], 0,
203 (nfdt->max_fds - fdt->max_fds) *
204 sizeof(struct file *));
205 }
206 nfdt->next_fd = fdt->next_fd;
127} 207}
128 208
129/* 209/*
@@ -154,26 +234,21 @@ void free_fdset(fd_set *array, int num)
154 vfree(array); 234 vfree(array);
155} 235}
156 236
157/* 237static struct fdtable *alloc_fdtable(int nr)
158 * Expand the fdset in the files_struct. Called with the files spinlock
159 * held for write.
160 */
161static int expand_fdset(struct files_struct *files, int nr)
162 __releases(file->file_lock)
163 __acquires(file->file_lock)
164{ 238{
165 fd_set *new_openset = NULL, *new_execset = NULL; 239 struct fdtable *fdt = NULL;
166 int error, nfds = 0; 240 int nfds = 0;
167 241 fd_set *new_openset = NULL, *new_execset = NULL;
168 error = -EMFILE; 242 struct file **new_fds;
169 if (files->max_fdset >= NR_OPEN || nr >= NR_OPEN)
170 goto out;
171 243
172 nfds = files->max_fdset; 244 fdt = kmalloc(sizeof(*fdt), GFP_KERNEL);
173 spin_unlock(&files->file_lock); 245 if (!fdt)
246 goto out;
247 memset(fdt, 0, sizeof(*fdt));
174 248
175 /* Expand to the max in easy steps */ 249 nfds = __FD_SETSIZE;
176 do { 250 /* Expand to the max in easy steps */
251 do {
177 if (nfds < (PAGE_SIZE * 8)) 252 if (nfds < (PAGE_SIZE * 8))
178 nfds = PAGE_SIZE * 8; 253 nfds = PAGE_SIZE * 8;
179 else { 254 else {
@@ -183,49 +258,88 @@ static int expand_fdset(struct files_struct *files, int nr)
183 } 258 }
184 } while (nfds <= nr); 259 } while (nfds <= nr);
185 260
186 error = -ENOMEM; 261 new_openset = alloc_fdset(nfds);
187 new_openset = alloc_fdset(nfds); 262 new_execset = alloc_fdset(nfds);
188 new_execset = alloc_fdset(nfds); 263 if (!new_openset || !new_execset)
189 spin_lock(&files->file_lock); 264 goto out;
190 if (!new_openset || !new_execset) 265 fdt->open_fds = new_openset;
266 fdt->close_on_exec = new_execset;
267 fdt->max_fdset = nfds;
268
269 nfds = NR_OPEN_DEFAULT;
270 /*
271 * Expand to the max in easy steps, and keep expanding it until
272 * we have enough for the requested fd array size.
273 */
274 do {
275#if NR_OPEN_DEFAULT < 256
276 if (nfds < 256)
277 nfds = 256;
278 else
279#endif
280 if (nfds < (PAGE_SIZE / sizeof(struct file *)))
281 nfds = PAGE_SIZE / sizeof(struct file *);
282 else {
283 nfds = nfds * 2;
284 if (nfds > NR_OPEN)
285 nfds = NR_OPEN;
286 }
287 } while (nfds <= nr);
288 new_fds = alloc_fd_array(nfds);
289 if (!new_fds)
290 goto out;
291 fdt->fd = new_fds;
292 fdt->max_fds = nfds;
293 fdt->free_files = NULL;
294 return fdt;
295out:
296 if (new_openset)
297 free_fdset(new_openset, nfds);
298 if (new_execset)
299 free_fdset(new_execset, nfds);
300 kfree(fdt);
301 return NULL;
302}
303
304/*
305 * Expands the file descriptor table - it will allocate a new fdtable and
306 * both fd array and fdset. It is expected to be called with the
307 * files_lock held.
308 */
309static int expand_fdtable(struct files_struct *files, int nr)
310 __releases(files->file_lock)
311 __acquires(files->file_lock)
312{
313 int error = 0;
314 struct fdtable *fdt;
315 struct fdtable *nfdt = NULL;
316
317 spin_unlock(&files->file_lock);
318 nfdt = alloc_fdtable(nr);
319 if (!nfdt) {
320 error = -ENOMEM;
321 spin_lock(&files->file_lock);
191 goto out; 322 goto out;
323 }
192 324
193 error = 0; 325 spin_lock(&files->file_lock);
194 326 fdt = files_fdtable(files);
195 /* Copy the existing tables and install the new pointers */ 327 /*
196 if (nfds > files->max_fdset) { 328 * Check again since another task may have expanded the
197 int i = files->max_fdset / (sizeof(unsigned long) * 8); 329 * fd table while we dropped the lock
198 int count = (nfds - files->max_fdset) / 8; 330 */
199 331 if (nr >= fdt->max_fds || nr >= fdt->max_fdset) {
200 /* 332 copy_fdtable(nfdt, fdt);
201 * Don't copy the entire array if the current fdset is 333 } else {
202 * not yet initialised. 334 /* Somebody expanded while we dropped file_lock */
203 */
204 if (i) {
205 memcpy (new_openset, files->open_fds, files->max_fdset/8);
206 memcpy (new_execset, files->close_on_exec, files->max_fdset/8);
207 memset (&new_openset->fds_bits[i], 0, count);
208 memset (&new_execset->fds_bits[i], 0, count);
209 }
210
211 nfds = xchg(&files->max_fdset, nfds);
212 new_openset = xchg(&files->open_fds, new_openset);
213 new_execset = xchg(&files->close_on_exec, new_execset);
214 spin_unlock(&files->file_lock); 335 spin_unlock(&files->file_lock);
215 free_fdset (new_openset, nfds); 336 __free_fdtable(nfdt);
216 free_fdset (new_execset, nfds);
217 spin_lock(&files->file_lock); 337 spin_lock(&files->file_lock);
218 return 0; 338 goto out;
219 } 339 }
220 /* Somebody expanded the array while we slept ... */ 340 rcu_assign_pointer(files->fdt, nfdt);
221 341 free_fdtable(fdt);
222out: 342out:
223 spin_unlock(&files->file_lock);
224 if (new_openset)
225 free_fdset(new_openset, nfds);
226 if (new_execset)
227 free_fdset(new_execset, nfds);
228 spin_lock(&files->file_lock);
229 return error; 343 return error;
230} 344}
231 345
@@ -237,18 +351,39 @@ out:
237int expand_files(struct files_struct *files, int nr) 351int expand_files(struct files_struct *files, int nr)
238{ 352{
239 int err, expand = 0; 353 int err, expand = 0;
354 struct fdtable *fdt;
240 355
241 if (nr >= files->max_fdset) { 356 fdt = files_fdtable(files);
242 expand = 1; 357 if (nr >= fdt->max_fdset || nr >= fdt->max_fds) {
243 if ((err = expand_fdset(files, nr))) 358 if (fdt->max_fdset >= NR_OPEN ||
359 fdt->max_fds >= NR_OPEN || nr >= NR_OPEN) {
360 err = -EMFILE;
244 goto out; 361 goto out;
245 } 362 }
246 if (nr >= files->max_fds) {
247 expand = 1; 363 expand = 1;
248 if ((err = expand_fd_array(files, nr))) 364 if ((err = expand_fdtable(files, nr)))
249 goto out; 365 goto out;
250 } 366 }
251 err = expand; 367 err = expand;
252out: 368out:
253 return err; 369 return err;
254} 370}
371
372static void __devinit fdtable_defer_list_init(int cpu)
373{
374 struct fdtable_defer *fddef = &per_cpu(fdtable_defer_list, cpu);
375 spin_lock_init(&fddef->lock);
376 INIT_WORK(&fddef->wq, (void (*)(void *))free_fdtable_work, fddef);
377 init_timer(&fddef->timer);
378 fddef->timer.data = (unsigned long)fddef;
379 fddef->timer.function = fdtable_timer;
380 fddef->next = NULL;
381}
382
383void __init files_defer_init(void)
384{
385 int i;
386 /* Really early - can't use for_each_cpu */
387 for (i = 0; i < NR_CPUS; i++)
388 fdtable_defer_list_init(i);
389}
diff --git a/fs/file_table.c b/fs/file_table.c
index 43e9e1737d..86ec8ae985 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -14,6 +14,7 @@
14#include <linux/fs.h> 14#include <linux/fs.h>
15#include <linux/security.h> 15#include <linux/security.h>
16#include <linux/eventpoll.h> 16#include <linux/eventpoll.h>
17#include <linux/rcupdate.h>
17#include <linux/mount.h> 18#include <linux/mount.h>
18#include <linux/cdev.h> 19#include <linux/cdev.h>
19#include <linux/fsnotify.h> 20#include <linux/fsnotify.h>
@@ -53,11 +54,17 @@ void filp_dtor(void * objp, struct kmem_cache_s *cachep, unsigned long dflags)
53 spin_unlock_irqrestore(&filp_count_lock, flags); 54 spin_unlock_irqrestore(&filp_count_lock, flags);
54} 55}
55 56
56static inline void file_free(struct file *f) 57static inline void file_free_rcu(struct rcu_head *head)
57{ 58{
59 struct file *f = container_of(head, struct file, f_rcuhead);
58 kmem_cache_free(filp_cachep, f); 60 kmem_cache_free(filp_cachep, f);
59} 61}
60 62
63static inline void file_free(struct file *f)
64{
65 call_rcu(&f->f_rcuhead, file_free_rcu);
66}
67
61/* Find an unused file structure and return a pointer to it. 68/* Find an unused file structure and return a pointer to it.
62 * Returns NULL, if there are no more free file structures or 69 * Returns NULL, if there are no more free file structures or
63 * we run out of memory. 70 * we run out of memory.
@@ -110,7 +117,7 @@ EXPORT_SYMBOL(get_empty_filp);
110 117
111void fastcall fput(struct file *file) 118void fastcall fput(struct file *file)
112{ 119{
113 if (atomic_dec_and_test(&file->f_count)) 120 if (rcuref_dec_and_test(&file->f_count))
114 __fput(file); 121 __fput(file);
115} 122}
116 123
@@ -156,11 +163,17 @@ struct file fastcall *fget(unsigned int fd)
156 struct file *file; 163 struct file *file;
157 struct files_struct *files = current->files; 164 struct files_struct *files = current->files;
158 165
159 spin_lock(&files->file_lock); 166 rcu_read_lock();
160 file = fcheck_files(files, fd); 167 file = fcheck_files(files, fd);
161 if (file) 168 if (file) {
162 get_file(file); 169 if (!rcuref_inc_lf(&file->f_count)) {
163 spin_unlock(&files->file_lock); 170 /* File object ref couldn't be taken */
171 rcu_read_unlock();
172 return NULL;
173 }
174 }
175 rcu_read_unlock();
176
164 return file; 177 return file;
165} 178}
166 179
@@ -182,21 +195,25 @@ struct file fastcall *fget_light(unsigned int fd, int *fput_needed)
182 if (likely((atomic_read(&files->count) == 1))) { 195 if (likely((atomic_read(&files->count) == 1))) {
183 file = fcheck_files(files, fd); 196 file = fcheck_files(files, fd);
184 } else { 197 } else {
185 spin_lock(&files->file_lock); 198 rcu_read_lock();
186 file = fcheck_files(files, fd); 199 file = fcheck_files(files, fd);
187 if (file) { 200 if (file) {
188 get_file(file); 201 if (rcuref_inc_lf(&file->f_count))
189 *fput_needed = 1; 202 *fput_needed = 1;
203 else
204 /* Didn't get the reference, someone's freed */
205 file = NULL;
190 } 206 }
191 spin_unlock(&files->file_lock); 207 rcu_read_unlock();
192 } 208 }
209
193 return file; 210 return file;
194} 211}
195 212
196 213
197void put_filp(struct file *file) 214void put_filp(struct file *file)
198{ 215{
199 if (atomic_dec_and_test(&file->f_count)) { 216 if (rcuref_dec_and_test(&file->f_count)) {
200 security_file_free(file); 217 security_file_free(file);
201 file_kill(file); 218 file_kill(file);
202 file_free(file); 219 file_free(file);
@@ -257,4 +274,5 @@ void __init files_init(unsigned long mempages)
257 files_stat.max_files = n; 274 files_stat.max_files = n;
258 if (files_stat.max_files < NR_FILE) 275 if (files_stat.max_files < NR_FILE)
259 files_stat.max_files = NR_FILE; 276 files_stat.max_files = NR_FILE;
277 files_defer_init();
260} 278}
diff --git a/fs/fuse/Makefile b/fs/fuse/Makefile
new file mode 100644
index 0000000000..c3e1f760ca
--- /dev/null
+++ b/fs/fuse/Makefile
@@ -0,0 +1,7 @@
1#
2# Makefile for the FUSE filesystem.
3#
4
5obj-$(CONFIG_FUSE_FS) += fuse.o
6
7fuse-objs := dev.o dir.o file.o inode.o
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
new file mode 100644
index 0000000000..d4c869c6d0
--- /dev/null
+++ b/fs/fuse/dev.c
@@ -0,0 +1,877 @@
1/*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu>
4
5 This program can be distributed under the terms of the GNU GPL.
6 See the file COPYING.
7*/
8
9#include "fuse_i.h"
10
11#include <linux/init.h>
12#include <linux/module.h>
13#include <linux/poll.h>
14#include <linux/uio.h>
15#include <linux/miscdevice.h>
16#include <linux/pagemap.h>
17#include <linux/file.h>
18#include <linux/slab.h>
19
20MODULE_ALIAS_MISCDEV(FUSE_MINOR);
21
22static kmem_cache_t *fuse_req_cachep;
23
24static inline struct fuse_conn *fuse_get_conn(struct file *file)
25{
26 struct fuse_conn *fc;
27 spin_lock(&fuse_lock);
28 fc = file->private_data;
29 if (fc && !fc->mounted)
30 fc = NULL;
31 spin_unlock(&fuse_lock);
32 return fc;
33}
34
35static inline void fuse_request_init(struct fuse_req *req)
36{
37 memset(req, 0, sizeof(*req));
38 INIT_LIST_HEAD(&req->list);
39 init_waitqueue_head(&req->waitq);
40 atomic_set(&req->count, 1);
41}
42
43struct fuse_req *fuse_request_alloc(void)
44{
45 struct fuse_req *req = kmem_cache_alloc(fuse_req_cachep, SLAB_KERNEL);
46 if (req)
47 fuse_request_init(req);
48 return req;
49}
50
51void fuse_request_free(struct fuse_req *req)
52{
53 kmem_cache_free(fuse_req_cachep, req);
54}
55
56static inline void block_sigs(sigset_t *oldset)
57{
58 sigset_t mask;
59
60 siginitsetinv(&mask, sigmask(SIGKILL));
61 sigprocmask(SIG_BLOCK, &mask, oldset);
62}
63
64static inline void restore_sigs(sigset_t *oldset)
65{
66 sigprocmask(SIG_SETMASK, oldset, NULL);
67}
68
69void fuse_reset_request(struct fuse_req *req)
70{
71 int preallocated = req->preallocated;
72 BUG_ON(atomic_read(&req->count) != 1);
73 fuse_request_init(req);
74 req->preallocated = preallocated;
75}
76
77static void __fuse_get_request(struct fuse_req *req)
78{
79 atomic_inc(&req->count);
80}
81
82/* Must be called with > 1 refcount */
83static void __fuse_put_request(struct fuse_req *req)
84{
85 BUG_ON(atomic_read(&req->count) < 2);
86 atomic_dec(&req->count);
87}
88
89static struct fuse_req *do_get_request(struct fuse_conn *fc)
90{
91 struct fuse_req *req;
92
93 spin_lock(&fuse_lock);
94 BUG_ON(list_empty(&fc->unused_list));
95 req = list_entry(fc->unused_list.next, struct fuse_req, list);
96 list_del_init(&req->list);
97 spin_unlock(&fuse_lock);
98 fuse_request_init(req);
99 req->preallocated = 1;
100 req->in.h.uid = current->fsuid;
101 req->in.h.gid = current->fsgid;
102 req->in.h.pid = current->pid;
103 return req;
104}
105
106/* This can return NULL, but only in case it's interrupted by a SIGKILL */
107struct fuse_req *fuse_get_request(struct fuse_conn *fc)
108{
109 int intr;
110 sigset_t oldset;
111
112 block_sigs(&oldset);
113 intr = down_interruptible(&fc->outstanding_sem);
114 restore_sigs(&oldset);
115 return intr ? NULL : do_get_request(fc);
116}
117
118static void fuse_putback_request(struct fuse_conn *fc, struct fuse_req *req)
119{
120 spin_lock(&fuse_lock);
121 if (req->preallocated)
122 list_add(&req->list, &fc->unused_list);
123 else
124 fuse_request_free(req);
125
126 /* If we are in debt decrease that first */
127 if (fc->outstanding_debt)
128 fc->outstanding_debt--;
129 else
130 up(&fc->outstanding_sem);
131 spin_unlock(&fuse_lock);
132}
133
134void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req)
135{
136 if (atomic_dec_and_test(&req->count))
137 fuse_putback_request(fc, req);
138}
139
140void fuse_release_background(struct fuse_req *req)
141{
142 iput(req->inode);
143 iput(req->inode2);
144 if (req->file)
145 fput(req->file);
146 spin_lock(&fuse_lock);
147 list_del(&req->bg_entry);
148 spin_unlock(&fuse_lock);
149}
150
151/*
152 * This function is called when a request is finished. Either a reply
153 * has arrived or it was interrupted (and not yet sent) or some error
154 * occured during communication with userspace, or the device file was
155 * closed. It decreases the referece count for the request. In case
156 * of a background request the referece to the stored objects are
157 * released. The requester thread is woken up (if still waiting), and
158 * finally the request is either freed or put on the unused_list
159 *
160 * Called with fuse_lock, unlocks it
161 */
162static void request_end(struct fuse_conn *fc, struct fuse_req *req)
163{
164 int putback;
165 req->finished = 1;
166 putback = atomic_dec_and_test(&req->count);
167 spin_unlock(&fuse_lock);
168 if (req->background) {
169 down_read(&fc->sbput_sem);
170 if (fc->mounted)
171 fuse_release_background(req);
172 up_read(&fc->sbput_sem);
173 }
174 wake_up(&req->waitq);
175 if (req->in.h.opcode == FUSE_INIT) {
176 int i;
177
178 if (req->misc.init_in_out.major != FUSE_KERNEL_VERSION)
179 fc->conn_error = 1;
180
181 /* After INIT reply is received other requests can go
182 out. So do (FUSE_MAX_OUTSTANDING - 1) number of
183 up()s on outstanding_sem. The last up() is done in
184 fuse_putback_request() */
185 for (i = 1; i < FUSE_MAX_OUTSTANDING; i++)
186 up(&fc->outstanding_sem);
187 }
188 if (putback)
189 fuse_putback_request(fc, req);
190}
191
192/*
193 * Unfortunately request interruption not just solves the deadlock
194 * problem, it causes problems too. These stem from the fact, that an
195 * interrupted request is continued to be processed in userspace,
196 * while all the locks and object references (inode and file) held
197 * during the operation are released.
198 *
199 * To release the locks is exactly why there's a need to interrupt the
200 * request, so there's not a lot that can be done about this, except
201 * introduce additional locking in userspace.
202 *
203 * More important is to keep inode and file references until userspace
204 * has replied, otherwise FORGET and RELEASE could be sent while the
205 * inode/file is still used by the filesystem.
206 *
207 * For this reason the concept of "background" request is introduced.
208 * An interrupted request is backgrounded if it has been already sent
209 * to userspace. Backgrounding involves getting an extra reference to
210 * inode(s) or file used in the request, and adding the request to
211 * fc->background list. When a reply is received for a background
212 * request, the object references are released, and the request is
213 * removed from the list. If the filesystem is unmounted while there
214 * are still background requests, the list is walked and references
215 * are released as if a reply was received.
216 *
217 * There's one more use for a background request. The RELEASE message is
218 * always sent as background, since it doesn't return an error or
219 * data.
220 */
221static void background_request(struct fuse_conn *fc, struct fuse_req *req)
222{
223 req->background = 1;
224 list_add(&req->bg_entry, &fc->background);
225 if (req->inode)
226 req->inode = igrab(req->inode);
227 if (req->inode2)
228 req->inode2 = igrab(req->inode2);
229 if (req->file)
230 get_file(req->file);
231}
232
233/* Called with fuse_lock held. Releases, and then reacquires it. */
234static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
235{
236 sigset_t oldset;
237
238 spin_unlock(&fuse_lock);
239 block_sigs(&oldset);
240 wait_event_interruptible(req->waitq, req->finished);
241 restore_sigs(&oldset);
242 spin_lock(&fuse_lock);
243 if (req->finished)
244 return;
245
246 req->out.h.error = -EINTR;
247 req->interrupted = 1;
248 if (req->locked) {
249 /* This is uninterruptible sleep, because data is
250 being copied to/from the buffers of req. During
251 locked state, there mustn't be any filesystem
252 operation (e.g. page fault), since that could lead
253 to deadlock */
254 spin_unlock(&fuse_lock);
255 wait_event(req->waitq, !req->locked);
256 spin_lock(&fuse_lock);
257 }
258 if (!req->sent && !list_empty(&req->list)) {
259 list_del(&req->list);
260 __fuse_put_request(req);
261 } else if (!req->finished && req->sent)
262 background_request(fc, req);
263}
264
265static unsigned len_args(unsigned numargs, struct fuse_arg *args)
266{
267 unsigned nbytes = 0;
268 unsigned i;
269
270 for (i = 0; i < numargs; i++)
271 nbytes += args[i].size;
272
273 return nbytes;
274}
275
276static void queue_request(struct fuse_conn *fc, struct fuse_req *req)
277{
278 fc->reqctr++;
279 /* zero is special */
280 if (fc->reqctr == 0)
281 fc->reqctr = 1;
282 req->in.h.unique = fc->reqctr;
283 req->in.h.len = sizeof(struct fuse_in_header) +
284 len_args(req->in.numargs, (struct fuse_arg *) req->in.args);
285 if (!req->preallocated) {
286 /* If request is not preallocated (either FORGET or
287 RELEASE), then still decrease outstanding_sem, so
288 user can't open infinite number of files while not
289 processing the RELEASE requests. However for
290 efficiency do it without blocking, so if down()
291 would block, just increase the debt instead */
292 if (down_trylock(&fc->outstanding_sem))
293 fc->outstanding_debt++;
294 }
295 list_add_tail(&req->list, &fc->pending);
296 wake_up(&fc->waitq);
297}
298
299/*
300 * This can only be interrupted by a SIGKILL
301 */
302void request_send(struct fuse_conn *fc, struct fuse_req *req)
303{
304 req->isreply = 1;
305 spin_lock(&fuse_lock);
306 if (!fc->connected)
307 req->out.h.error = -ENOTCONN;
308 else if (fc->conn_error)
309 req->out.h.error = -ECONNREFUSED;
310 else {
311 queue_request(fc, req);
312 /* acquire extra reference, since request is still needed
313 after request_end() */
314 __fuse_get_request(req);
315
316 request_wait_answer(fc, req);
317 }
318 spin_unlock(&fuse_lock);
319}
320
321static void request_send_nowait(struct fuse_conn *fc, struct fuse_req *req)
322{
323 spin_lock(&fuse_lock);
324 if (fc->connected) {
325 queue_request(fc, req);
326 spin_unlock(&fuse_lock);
327 } else {
328 req->out.h.error = -ENOTCONN;
329 request_end(fc, req);
330 }
331}
332
333void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req)
334{
335 req->isreply = 0;
336 request_send_nowait(fc, req);
337}
338
339void request_send_background(struct fuse_conn *fc, struct fuse_req *req)
340{
341 req->isreply = 1;
342 spin_lock(&fuse_lock);
343 background_request(fc, req);
344 spin_unlock(&fuse_lock);
345 request_send_nowait(fc, req);
346}
347
348void fuse_send_init(struct fuse_conn *fc)
349{
350 /* This is called from fuse_read_super() so there's guaranteed
351 to be a request available */
352 struct fuse_req *req = do_get_request(fc);
353 struct fuse_init_in_out *arg = &req->misc.init_in_out;
354 arg->major = FUSE_KERNEL_VERSION;
355 arg->minor = FUSE_KERNEL_MINOR_VERSION;
356 req->in.h.opcode = FUSE_INIT;
357 req->in.numargs = 1;
358 req->in.args[0].size = sizeof(*arg);
359 req->in.args[0].value = arg;
360 req->out.numargs = 1;
361 req->out.args[0].size = sizeof(*arg);
362 req->out.args[0].value = arg;
363 request_send_background(fc, req);
364}
365
366/*
367 * Lock the request. Up to the next unlock_request() there mustn't be
368 * anything that could cause a page-fault. If the request was already
369 * interrupted bail out.
370 */
371static inline int lock_request(struct fuse_req *req)
372{
373 int err = 0;
374 if (req) {
375 spin_lock(&fuse_lock);
376 if (req->interrupted)
377 err = -ENOENT;
378 else
379 req->locked = 1;
380 spin_unlock(&fuse_lock);
381 }
382 return err;
383}
384
385/*
386 * Unlock request. If it was interrupted during being locked, the
387 * requester thread is currently waiting for it to be unlocked, so
388 * wake it up.
389 */
390static inline void unlock_request(struct fuse_req *req)
391{
392 if (req) {
393 spin_lock(&fuse_lock);
394 req->locked = 0;
395 if (req->interrupted)
396 wake_up(&req->waitq);
397 spin_unlock(&fuse_lock);
398 }
399}
400
401struct fuse_copy_state {
402 int write;
403 struct fuse_req *req;
404 const struct iovec *iov;
405 unsigned long nr_segs;
406 unsigned long seglen;
407 unsigned long addr;
408 struct page *pg;
409 void *mapaddr;
410 void *buf;
411 unsigned len;
412};
413
414static void fuse_copy_init(struct fuse_copy_state *cs, int write,
415 struct fuse_req *req, const struct iovec *iov,
416 unsigned long nr_segs)
417{
418 memset(cs, 0, sizeof(*cs));
419 cs->write = write;
420 cs->req = req;
421 cs->iov = iov;
422 cs->nr_segs = nr_segs;
423}
424
425/* Unmap and put previous page of userspace buffer */
426static inline void fuse_copy_finish(struct fuse_copy_state *cs)
427{
428 if (cs->mapaddr) {
429 kunmap_atomic(cs->mapaddr, KM_USER0);
430 if (cs->write) {
431 flush_dcache_page(cs->pg);
432 set_page_dirty_lock(cs->pg);
433 }
434 put_page(cs->pg);
435 cs->mapaddr = NULL;
436 }
437}
438
439/*
440 * Get another pagefull of userspace buffer, and map it to kernel
441 * address space, and lock request
442 */
443static int fuse_copy_fill(struct fuse_copy_state *cs)
444{
445 unsigned long offset;
446 int err;
447
448 unlock_request(cs->req);
449 fuse_copy_finish(cs);
450 if (!cs->seglen) {
451 BUG_ON(!cs->nr_segs);
452 cs->seglen = cs->iov[0].iov_len;
453 cs->addr = (unsigned long) cs->iov[0].iov_base;
454 cs->iov ++;
455 cs->nr_segs --;
456 }
457 down_read(&current->mm->mmap_sem);
458 err = get_user_pages(current, current->mm, cs->addr, 1, cs->write, 0,
459 &cs->pg, NULL);
460 up_read(&current->mm->mmap_sem);
461 if (err < 0)
462 return err;
463 BUG_ON(err != 1);
464 offset = cs->addr % PAGE_SIZE;
465 cs->mapaddr = kmap_atomic(cs->pg, KM_USER0);
466 cs->buf = cs->mapaddr + offset;
467 cs->len = min(PAGE_SIZE - offset, cs->seglen);
468 cs->seglen -= cs->len;
469 cs->addr += cs->len;
470
471 return lock_request(cs->req);
472}
473
474/* Do as much copy to/from userspace buffer as we can */
475static inline int fuse_copy_do(struct fuse_copy_state *cs, void **val,
476 unsigned *size)
477{
478 unsigned ncpy = min(*size, cs->len);
479 if (val) {
480 if (cs->write)
481 memcpy(cs->buf, *val, ncpy);
482 else
483 memcpy(*val, cs->buf, ncpy);
484 *val += ncpy;
485 }
486 *size -= ncpy;
487 cs->len -= ncpy;
488 cs->buf += ncpy;
489 return ncpy;
490}
491
492/*
493 * Copy a page in the request to/from the userspace buffer. Must be
494 * done atomically
495 */
496static inline int fuse_copy_page(struct fuse_copy_state *cs, struct page *page,
497 unsigned offset, unsigned count, int zeroing)
498{
499 if (page && zeroing && count < PAGE_SIZE) {
500 void *mapaddr = kmap_atomic(page, KM_USER1);
501 memset(mapaddr, 0, PAGE_SIZE);
502 kunmap_atomic(mapaddr, KM_USER1);
503 }
504 while (count) {
505 int err;
506 if (!cs->len && (err = fuse_copy_fill(cs)))
507 return err;
508 if (page) {
509 void *mapaddr = kmap_atomic(page, KM_USER1);
510 void *buf = mapaddr + offset;
511 offset += fuse_copy_do(cs, &buf, &count);
512 kunmap_atomic(mapaddr, KM_USER1);
513 } else
514 offset += fuse_copy_do(cs, NULL, &count);
515 }
516 if (page && !cs->write)
517 flush_dcache_page(page);
518 return 0;
519}
520
521/* Copy pages in the request to/from userspace buffer */
522static int fuse_copy_pages(struct fuse_copy_state *cs, unsigned nbytes,
523 int zeroing)
524{
525 unsigned i;
526 struct fuse_req *req = cs->req;
527 unsigned offset = req->page_offset;
528 unsigned count = min(nbytes, (unsigned) PAGE_SIZE - offset);
529
530 for (i = 0; i < req->num_pages && (nbytes || zeroing); i++) {
531 struct page *page = req->pages[i];
532 int err = fuse_copy_page(cs, page, offset, count, zeroing);
533 if (err)
534 return err;
535
536 nbytes -= count;
537 count = min(nbytes, (unsigned) PAGE_SIZE);
538 offset = 0;
539 }
540 return 0;
541}
542
543/* Copy a single argument in the request to/from userspace buffer */
544static int fuse_copy_one(struct fuse_copy_state *cs, void *val, unsigned size)
545{
546 while (size) {
547 int err;
548 if (!cs->len && (err = fuse_copy_fill(cs)))
549 return err;
550 fuse_copy_do(cs, &val, &size);
551 }
552 return 0;
553}
554
555/* Copy request arguments to/from userspace buffer */
556static int fuse_copy_args(struct fuse_copy_state *cs, unsigned numargs,
557 unsigned argpages, struct fuse_arg *args,
558 int zeroing)
559{
560 int err = 0;
561 unsigned i;
562
563 for (i = 0; !err && i < numargs; i++) {
564 struct fuse_arg *arg = &args[i];
565 if (i == numargs - 1 && argpages)
566 err = fuse_copy_pages(cs, arg->size, zeroing);
567 else
568 err = fuse_copy_one(cs, arg->value, arg->size);
569 }
570 return err;
571}
572
573/* Wait until a request is available on the pending list */
574static void request_wait(struct fuse_conn *fc)
575{
576 DECLARE_WAITQUEUE(wait, current);
577
578 add_wait_queue_exclusive(&fc->waitq, &wait);
579 while (fc->mounted && list_empty(&fc->pending)) {
580 set_current_state(TASK_INTERRUPTIBLE);
581 if (signal_pending(current))
582 break;
583
584 spin_unlock(&fuse_lock);
585 schedule();
586 spin_lock(&fuse_lock);
587 }
588 set_current_state(TASK_RUNNING);
589 remove_wait_queue(&fc->waitq, &wait);
590}
591
592/*
593 * Read a single request into the userspace filesystem's buffer. This
594 * function waits until a request is available, then removes it from
595 * the pending list and copies request data to userspace buffer. If
596 * no reply is needed (FORGET) or request has been interrupted or
597 * there was an error during the copying then it's finished by calling
598 * request_end(). Otherwise add it to the processing list, and set
599 * the 'sent' flag.
600 */
601static ssize_t fuse_dev_readv(struct file *file, const struct iovec *iov,
602 unsigned long nr_segs, loff_t *off)
603{
604 int err;
605 struct fuse_conn *fc;
606 struct fuse_req *req;
607 struct fuse_in *in;
608 struct fuse_copy_state cs;
609 unsigned reqsize;
610
611 spin_lock(&fuse_lock);
612 fc = file->private_data;
613 err = -EPERM;
614 if (!fc)
615 goto err_unlock;
616 request_wait(fc);
617 err = -ENODEV;
618 if (!fc->mounted)
619 goto err_unlock;
620 err = -ERESTARTSYS;
621 if (list_empty(&fc->pending))
622 goto err_unlock;
623
624 req = list_entry(fc->pending.next, struct fuse_req, list);
625 list_del_init(&req->list);
626 spin_unlock(&fuse_lock);
627
628 in = &req->in;
629 reqsize = req->in.h.len;
630 fuse_copy_init(&cs, 1, req, iov, nr_segs);
631 err = -EINVAL;
632 if (iov_length(iov, nr_segs) >= reqsize) {
633 err = fuse_copy_one(&cs, &in->h, sizeof(in->h));
634 if (!err)
635 err = fuse_copy_args(&cs, in->numargs, in->argpages,
636 (struct fuse_arg *) in->args, 0);
637 }
638 fuse_copy_finish(&cs);
639
640 spin_lock(&fuse_lock);
641 req->locked = 0;
642 if (!err && req->interrupted)
643 err = -ENOENT;
644 if (err) {
645 if (!req->interrupted)
646 req->out.h.error = -EIO;
647 request_end(fc, req);
648 return err;
649 }
650 if (!req->isreply)
651 request_end(fc, req);
652 else {
653 req->sent = 1;
654 list_add_tail(&req->list, &fc->processing);
655 spin_unlock(&fuse_lock);
656 }
657 return reqsize;
658
659 err_unlock:
660 spin_unlock(&fuse_lock);
661 return err;
662}
663
664static ssize_t fuse_dev_read(struct file *file, char __user *buf,
665 size_t nbytes, loff_t *off)
666{
667 struct iovec iov;
668 iov.iov_len = nbytes;
669 iov.iov_base = buf;
670 return fuse_dev_readv(file, &iov, 1, off);
671}
672
673/* Look up request on processing list by unique ID */
674static struct fuse_req *request_find(struct fuse_conn *fc, u64 unique)
675{
676 struct list_head *entry;
677
678 list_for_each(entry, &fc->processing) {
679 struct fuse_req *req;
680 req = list_entry(entry, struct fuse_req, list);
681 if (req->in.h.unique == unique)
682 return req;
683 }
684 return NULL;
685}
686
687static int copy_out_args(struct fuse_copy_state *cs, struct fuse_out *out,
688 unsigned nbytes)
689{
690 unsigned reqsize = sizeof(struct fuse_out_header);
691
692 if (out->h.error)
693 return nbytes != reqsize ? -EINVAL : 0;
694
695 reqsize += len_args(out->numargs, out->args);
696
697 if (reqsize < nbytes || (reqsize > nbytes && !out->argvar))
698 return -EINVAL;
699 else if (reqsize > nbytes) {
700 struct fuse_arg *lastarg = &out->args[out->numargs-1];
701 unsigned diffsize = reqsize - nbytes;
702 if (diffsize > lastarg->size)
703 return -EINVAL;
704 lastarg->size -= diffsize;
705 }
706 return fuse_copy_args(cs, out->numargs, out->argpages, out->args,
707 out->page_zeroing);
708}
709
710/*
711 * Write a single reply to a request. First the header is copied from
712 * the write buffer. The request is then searched on the processing
713 * list by the unique ID found in the header. If found, then remove
714 * it from the list and copy the rest of the buffer to the request.
715 * The request is finished by calling request_end()
716 */
717static ssize_t fuse_dev_writev(struct file *file, const struct iovec *iov,
718 unsigned long nr_segs, loff_t *off)
719{
720 int err;
721 unsigned nbytes = iov_length(iov, nr_segs);
722 struct fuse_req *req;
723 struct fuse_out_header oh;
724 struct fuse_copy_state cs;
725 struct fuse_conn *fc = fuse_get_conn(file);
726 if (!fc)
727 return -ENODEV;
728
729 fuse_copy_init(&cs, 0, NULL, iov, nr_segs);
730 if (nbytes < sizeof(struct fuse_out_header))
731 return -EINVAL;
732
733 err = fuse_copy_one(&cs, &oh, sizeof(oh));
734 if (err)
735 goto err_finish;
736 err = -EINVAL;
737 if (!oh.unique || oh.error <= -1000 || oh.error > 0 ||
738 oh.len != nbytes)
739 goto err_finish;
740
741 spin_lock(&fuse_lock);
742 req = request_find(fc, oh.unique);
743 err = -EINVAL;
744 if (!req)
745 goto err_unlock;
746
747 list_del_init(&req->list);
748 if (req->interrupted) {
749 request_end(fc, req);
750 fuse_copy_finish(&cs);
751 return -ENOENT;
752 }
753 req->out.h = oh;
754 req->locked = 1;
755 cs.req = req;
756 spin_unlock(&fuse_lock);
757
758 err = copy_out_args(&cs, &req->out, nbytes);
759 fuse_copy_finish(&cs);
760
761 spin_lock(&fuse_lock);
762 req->locked = 0;
763 if (!err) {
764 if (req->interrupted)
765 err = -ENOENT;
766 } else if (!req->interrupted)
767 req->out.h.error = -EIO;
768 request_end(fc, req);
769
770 return err ? err : nbytes;
771
772 err_unlock:
773 spin_unlock(&fuse_lock);
774 err_finish:
775 fuse_copy_finish(&cs);
776 return err;
777}
778
779static ssize_t fuse_dev_write(struct file *file, const char __user *buf,
780 size_t nbytes, loff_t *off)
781{
782 struct iovec iov;
783 iov.iov_len = nbytes;
784 iov.iov_base = (char __user *) buf;
785 return fuse_dev_writev(file, &iov, 1, off);
786}
787
788static unsigned fuse_dev_poll(struct file *file, poll_table *wait)
789{
790 struct fuse_conn *fc = fuse_get_conn(file);
791 unsigned mask = POLLOUT | POLLWRNORM;
792
793 if (!fc)
794 return -ENODEV;
795
796 poll_wait(file, &fc->waitq, wait);
797
798 spin_lock(&fuse_lock);
799 if (!list_empty(&fc->pending))
800 mask |= POLLIN | POLLRDNORM;
801 spin_unlock(&fuse_lock);
802
803 return mask;
804}
805
806/* Abort all requests on the given list (pending or processing) */
807static void end_requests(struct fuse_conn *fc, struct list_head *head)
808{
809 while (!list_empty(head)) {
810 struct fuse_req *req;
811 req = list_entry(head->next, struct fuse_req, list);
812 list_del_init(&req->list);
813 req->out.h.error = -ECONNABORTED;
814 request_end(fc, req);
815 spin_lock(&fuse_lock);
816 }
817}
818
819static int fuse_dev_release(struct inode *inode, struct file *file)
820{
821 struct fuse_conn *fc;
822
823 spin_lock(&fuse_lock);
824 fc = file->private_data;
825 if (fc) {
826 fc->connected = 0;
827 end_requests(fc, &fc->pending);
828 end_requests(fc, &fc->processing);
829 fuse_release_conn(fc);
830 }
831 spin_unlock(&fuse_lock);
832 return 0;
833}
834
835struct file_operations fuse_dev_operations = {
836 .owner = THIS_MODULE,
837 .llseek = no_llseek,
838 .read = fuse_dev_read,
839 .readv = fuse_dev_readv,
840 .write = fuse_dev_write,
841 .writev = fuse_dev_writev,
842 .poll = fuse_dev_poll,
843 .release = fuse_dev_release,
844};
845
846static struct miscdevice fuse_miscdevice = {
847 .minor = FUSE_MINOR,
848 .name = "fuse",
849 .fops = &fuse_dev_operations,
850};
851
852int __init fuse_dev_init(void)
853{
854 int err = -ENOMEM;
855 fuse_req_cachep = kmem_cache_create("fuse_request",
856 sizeof(struct fuse_req),
857 0, 0, NULL, NULL);
858 if (!fuse_req_cachep)
859 goto out;
860
861 err = misc_register(&fuse_miscdevice);
862 if (err)
863 goto out_cache_clean;
864
865 return 0;
866
867 out_cache_clean:
868 kmem_cache_destroy(fuse_req_cachep);
869 out:
870 return err;
871}
872
873void fuse_dev_cleanup(void)
874{
875 misc_deregister(&fuse_miscdevice);
876 kmem_cache_destroy(fuse_req_cachep);
877}
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
new file mode 100644
index 0000000000..e79e49b3ee
--- /dev/null
+++ b/fs/fuse/dir.c
@@ -0,0 +1,982 @@
1/*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu>
4
5 This program can be distributed under the terms of the GNU GPL.
6 See the file COPYING.
7*/
8
9#include "fuse_i.h"
10
11#include <linux/pagemap.h>
12#include <linux/file.h>
13#include <linux/gfp.h>
14#include <linux/sched.h>
15#include <linux/namei.h>
16
17static inline unsigned long time_to_jiffies(unsigned long sec,
18 unsigned long nsec)
19{
20 struct timespec ts = {sec, nsec};
21 return jiffies + timespec_to_jiffies(&ts);
22}
23
24static void fuse_lookup_init(struct fuse_req *req, struct inode *dir,
25 struct dentry *entry,
26 struct fuse_entry_out *outarg)
27{
28 req->in.h.opcode = FUSE_LOOKUP;
29 req->in.h.nodeid = get_node_id(dir);
30 req->inode = dir;
31 req->in.numargs = 1;
32 req->in.args[0].size = entry->d_name.len + 1;
33 req->in.args[0].value = entry->d_name.name;
34 req->out.numargs = 1;
35 req->out.args[0].size = sizeof(struct fuse_entry_out);
36 req->out.args[0].value = outarg;
37}
38
39static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd)
40{
41 if (!entry->d_inode || is_bad_inode(entry->d_inode))
42 return 0;
43 else if (time_after(jiffies, entry->d_time)) {
44 int err;
45 struct fuse_entry_out outarg;
46 struct inode *inode = entry->d_inode;
47 struct fuse_inode *fi = get_fuse_inode(inode);
48 struct fuse_conn *fc = get_fuse_conn(inode);
49 struct fuse_req *req = fuse_get_request(fc);
50 if (!req)
51 return 0;
52
53 fuse_lookup_init(req, entry->d_parent->d_inode, entry, &outarg);
54 request_send(fc, req);
55 err = req->out.h.error;
56 if (!err) {
57 if (outarg.nodeid != get_node_id(inode)) {
58 fuse_send_forget(fc, req, outarg.nodeid, 1);
59 return 0;
60 }
61 fi->nlookup ++;
62 }
63 fuse_put_request(fc, req);
64 if (err || (outarg.attr.mode ^ inode->i_mode) & S_IFMT)
65 return 0;
66
67 fuse_change_attributes(inode, &outarg.attr);
68 entry->d_time = time_to_jiffies(outarg.entry_valid,
69 outarg.entry_valid_nsec);
70 fi->i_time = time_to_jiffies(outarg.attr_valid,
71 outarg.attr_valid_nsec);
72 }
73 return 1;
74}
75
76static struct dentry_operations fuse_dentry_operations = {
77 .d_revalidate = fuse_dentry_revalidate,
78};
79
80static int fuse_lookup_iget(struct inode *dir, struct dentry *entry,
81 struct inode **inodep)
82{
83 int err;
84 struct fuse_entry_out outarg;
85 struct inode *inode = NULL;
86 struct fuse_conn *fc = get_fuse_conn(dir);
87 struct fuse_req *req;
88
89 if (entry->d_name.len > FUSE_NAME_MAX)
90 return -ENAMETOOLONG;
91
92 req = fuse_get_request(fc);
93 if (!req)
94 return -EINTR;
95
96 fuse_lookup_init(req, dir, entry, &outarg);
97 request_send(fc, req);
98 err = req->out.h.error;
99 if (!err) {
100 inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
101 &outarg.attr);
102 if (!inode) {
103 fuse_send_forget(fc, req, outarg.nodeid, 1);
104 return -ENOMEM;
105 }
106 }
107 fuse_put_request(fc, req);
108 if (err && err != -ENOENT)
109 return err;
110
111 if (inode) {
112 struct fuse_inode *fi = get_fuse_inode(inode);
113 entry->d_time = time_to_jiffies(outarg.entry_valid,
114 outarg.entry_valid_nsec);
115 fi->i_time = time_to_jiffies(outarg.attr_valid,
116 outarg.attr_valid_nsec);
117 }
118
119 entry->d_op = &fuse_dentry_operations;
120 *inodep = inode;
121 return 0;
122}
123
124void fuse_invalidate_attr(struct inode *inode)
125{
126 get_fuse_inode(inode)->i_time = jiffies - 1;
127}
128
129static void fuse_invalidate_entry(struct dentry *entry)
130{
131 d_invalidate(entry);
132 entry->d_time = jiffies - 1;
133}
134
135static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
136 struct inode *dir, struct dentry *entry,
137 int mode)
138{
139 struct fuse_entry_out outarg;
140 struct inode *inode;
141 struct fuse_inode *fi;
142 int err;
143
144 req->in.h.nodeid = get_node_id(dir);
145 req->inode = dir;
146 req->out.numargs = 1;
147 req->out.args[0].size = sizeof(outarg);
148 req->out.args[0].value = &outarg;
149 request_send(fc, req);
150 err = req->out.h.error;
151 if (err) {
152 fuse_put_request(fc, req);
153 return err;
154 }
155 inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
156 &outarg.attr);
157 if (!inode) {
158 fuse_send_forget(fc, req, outarg.nodeid, 1);
159 return -ENOMEM;
160 }
161 fuse_put_request(fc, req);
162
163 /* Don't allow userspace to do really stupid things... */
164 if ((inode->i_mode ^ mode) & S_IFMT) {
165 iput(inode);
166 return -EIO;
167 }
168
169 entry->d_time = time_to_jiffies(outarg.entry_valid,
170 outarg.entry_valid_nsec);
171
172 fi = get_fuse_inode(inode);
173 fi->i_time = time_to_jiffies(outarg.attr_valid,
174 outarg.attr_valid_nsec);
175
176 d_instantiate(entry, inode);
177 fuse_invalidate_attr(dir);
178 return 0;
179}
180
181static int fuse_mknod(struct inode *dir, struct dentry *entry, int mode,
182 dev_t rdev)
183{
184 struct fuse_mknod_in inarg;
185 struct fuse_conn *fc = get_fuse_conn(dir);
186 struct fuse_req *req = fuse_get_request(fc);
187 if (!req)
188 return -EINTR;
189
190 memset(&inarg, 0, sizeof(inarg));
191 inarg.mode = mode;
192 inarg.rdev = new_encode_dev(rdev);
193 req->in.h.opcode = FUSE_MKNOD;
194 req->in.numargs = 2;
195 req->in.args[0].size = sizeof(inarg);
196 req->in.args[0].value = &inarg;
197 req->in.args[1].size = entry->d_name.len + 1;
198 req->in.args[1].value = entry->d_name.name;
199 return create_new_entry(fc, req, dir, entry, mode);
200}
201
202static int fuse_create(struct inode *dir, struct dentry *entry, int mode,
203 struct nameidata *nd)
204{
205 return fuse_mknod(dir, entry, mode, 0);
206}
207
208static int fuse_mkdir(struct inode *dir, struct dentry *entry, int mode)
209{
210 struct fuse_mkdir_in inarg;
211 struct fuse_conn *fc = get_fuse_conn(dir);
212 struct fuse_req *req = fuse_get_request(fc);
213 if (!req)
214 return -EINTR;
215
216 memset(&inarg, 0, sizeof(inarg));
217 inarg.mode = mode;
218 req->in.h.opcode = FUSE_MKDIR;
219 req->in.numargs = 2;
220 req->in.args[0].size = sizeof(inarg);
221 req->in.args[0].value = &inarg;
222 req->in.args[1].size = entry->d_name.len + 1;
223 req->in.args[1].value = entry->d_name.name;
224 return create_new_entry(fc, req, dir, entry, S_IFDIR);
225}
226
227static int fuse_symlink(struct inode *dir, struct dentry *entry,
228 const char *link)
229{
230 struct fuse_conn *fc = get_fuse_conn(dir);
231 unsigned len = strlen(link) + 1;
232 struct fuse_req *req;
233
234 if (len > FUSE_SYMLINK_MAX)
235 return -ENAMETOOLONG;
236
237 req = fuse_get_request(fc);
238 if (!req)
239 return -EINTR;
240
241 req->in.h.opcode = FUSE_SYMLINK;
242 req->in.numargs = 2;
243 req->in.args[0].size = entry->d_name.len + 1;
244 req->in.args[0].value = entry->d_name.name;
245 req->in.args[1].size = len;
246 req->in.args[1].value = link;
247 return create_new_entry(fc, req, dir, entry, S_IFLNK);
248}
249
250static int fuse_unlink(struct inode *dir, struct dentry *entry)
251{
252 int err;
253 struct fuse_conn *fc = get_fuse_conn(dir);
254 struct fuse_req *req = fuse_get_request(fc);
255 if (!req)
256 return -EINTR;
257
258 req->in.h.opcode = FUSE_UNLINK;
259 req->in.h.nodeid = get_node_id(dir);
260 req->inode = dir;
261 req->in.numargs = 1;
262 req->in.args[0].size = entry->d_name.len + 1;
263 req->in.args[0].value = entry->d_name.name;
264 request_send(fc, req);
265 err = req->out.h.error;
266 fuse_put_request(fc, req);
267 if (!err) {
268 struct inode *inode = entry->d_inode;
269
270 /* Set nlink to zero so the inode can be cleared, if
271 the inode does have more links this will be
272 discovered at the next lookup/getattr */
273 inode->i_nlink = 0;
274 fuse_invalidate_attr(inode);
275 fuse_invalidate_attr(dir);
276 } else if (err == -EINTR)
277 fuse_invalidate_entry(entry);
278 return err;
279}
280
281static int fuse_rmdir(struct inode *dir, struct dentry *entry)
282{
283 int err;
284 struct fuse_conn *fc = get_fuse_conn(dir);
285 struct fuse_req *req = fuse_get_request(fc);
286 if (!req)
287 return -EINTR;
288
289 req->in.h.opcode = FUSE_RMDIR;
290 req->in.h.nodeid = get_node_id(dir);
291 req->inode = dir;
292 req->in.numargs = 1;
293 req->in.args[0].size = entry->d_name.len + 1;
294 req->in.args[0].value = entry->d_name.name;
295 request_send(fc, req);
296 err = req->out.h.error;
297 fuse_put_request(fc, req);
298 if (!err) {
299 entry->d_inode->i_nlink = 0;
300 fuse_invalidate_attr(dir);
301 } else if (err == -EINTR)
302 fuse_invalidate_entry(entry);
303 return err;
304}
305
306static int fuse_rename(struct inode *olddir, struct dentry *oldent,
307 struct inode *newdir, struct dentry *newent)
308{
309 int err;
310 struct fuse_rename_in inarg;
311 struct fuse_conn *fc = get_fuse_conn(olddir);
312 struct fuse_req *req = fuse_get_request(fc);
313 if (!req)
314 return -EINTR;
315
316 memset(&inarg, 0, sizeof(inarg));
317 inarg.newdir = get_node_id(newdir);
318 req->in.h.opcode = FUSE_RENAME;
319 req->in.h.nodeid = get_node_id(olddir);
320 req->inode = olddir;
321 req->inode2 = newdir;
322 req->in.numargs = 3;
323 req->in.args[0].size = sizeof(inarg);
324 req->in.args[0].value = &inarg;
325 req->in.args[1].size = oldent->d_name.len + 1;
326 req->in.args[1].value = oldent->d_name.name;
327 req->in.args[2].size = newent->d_name.len + 1;
328 req->in.args[2].value = newent->d_name.name;
329 request_send(fc, req);
330 err = req->out.h.error;
331 fuse_put_request(fc, req);
332 if (!err) {
333 fuse_invalidate_attr(olddir);
334 if (olddir != newdir)
335 fuse_invalidate_attr(newdir);
336 } else if (err == -EINTR) {
337 /* If request was interrupted, DEITY only knows if the
338 rename actually took place. If the invalidation
339 fails (e.g. some process has CWD under the renamed
340 directory), then there can be inconsistency between
341 the dcache and the real filesystem. Tough luck. */
342 fuse_invalidate_entry(oldent);
343 if (newent->d_inode)
344 fuse_invalidate_entry(newent);
345 }
346
347 return err;
348}
349
350static int fuse_link(struct dentry *entry, struct inode *newdir,
351 struct dentry *newent)
352{
353 int err;
354 struct fuse_link_in inarg;
355 struct inode *inode = entry->d_inode;
356 struct fuse_conn *fc = get_fuse_conn(inode);
357 struct fuse_req *req = fuse_get_request(fc);
358 if (!req)
359 return -EINTR;
360
361 memset(&inarg, 0, sizeof(inarg));
362 inarg.oldnodeid = get_node_id(inode);
363 req->in.h.opcode = FUSE_LINK;
364 req->inode2 = inode;
365 req->in.numargs = 2;
366 req->in.args[0].size = sizeof(inarg);
367 req->in.args[0].value = &inarg;
368 req->in.args[1].size = newent->d_name.len + 1;
369 req->in.args[1].value = newent->d_name.name;
370 err = create_new_entry(fc, req, newdir, newent, inode->i_mode);
371 /* Contrary to "normal" filesystems it can happen that link
372 makes two "logical" inodes point to the same "physical"
373 inode. We invalidate the attributes of the old one, so it
374 will reflect changes in the backing inode (link count,
375 etc.)
376 */
377 if (!err || err == -EINTR)
378 fuse_invalidate_attr(inode);
379 return err;
380}
381
382int fuse_do_getattr(struct inode *inode)
383{
384 int err;
385 struct fuse_attr_out arg;
386 struct fuse_conn *fc = get_fuse_conn(inode);
387 struct fuse_req *req = fuse_get_request(fc);
388 if (!req)
389 return -EINTR;
390
391 req->in.h.opcode = FUSE_GETATTR;
392 req->in.h.nodeid = get_node_id(inode);
393 req->inode = inode;
394 req->out.numargs = 1;
395 req->out.args[0].size = sizeof(arg);
396 req->out.args[0].value = &arg;
397 request_send(fc, req);
398 err = req->out.h.error;
399 fuse_put_request(fc, req);
400 if (!err) {
401 if ((inode->i_mode ^ arg.attr.mode) & S_IFMT) {
402 make_bad_inode(inode);
403 err = -EIO;
404 } else {
405 struct fuse_inode *fi = get_fuse_inode(inode);
406 fuse_change_attributes(inode, &arg.attr);
407 fi->i_time = time_to_jiffies(arg.attr_valid,
408 arg.attr_valid_nsec);
409 }
410 }
411 return err;
412}
413
414/*
415 * Calling into a user-controlled filesystem gives the filesystem
416 * daemon ptrace-like capabilities over the requester process. This
417 * means, that the filesystem daemon is able to record the exact
418 * filesystem operations performed, and can also control the behavior
419 * of the requester process in otherwise impossible ways. For example
420 * it can delay the operation for arbitrary length of time allowing
421 * DoS against the requester.
422 *
423 * For this reason only those processes can call into the filesystem,
424 * for which the owner of the mount has ptrace privilege. This
425 * excludes processes started by other users, suid or sgid processes.
426 */
427static int fuse_allow_task(struct fuse_conn *fc, struct task_struct *task)
428{
429 if (fc->flags & FUSE_ALLOW_OTHER)
430 return 1;
431
432 if (task->euid == fc->user_id &&
433 task->suid == fc->user_id &&
434 task->uid == fc->user_id &&
435 task->egid == fc->group_id &&
436 task->sgid == fc->group_id &&
437 task->gid == fc->group_id)
438 return 1;
439
440 return 0;
441}
442
443static int fuse_revalidate(struct dentry *entry)
444{
445 struct inode *inode = entry->d_inode;
446 struct fuse_inode *fi = get_fuse_inode(inode);
447 struct fuse_conn *fc = get_fuse_conn(inode);
448
449 if (!fuse_allow_task(fc, current))
450 return -EACCES;
451 if (get_node_id(inode) != FUSE_ROOT_ID &&
452 time_before_eq(jiffies, fi->i_time))
453 return 0;
454
455 return fuse_do_getattr(inode);
456}
457
458static int fuse_permission(struct inode *inode, int mask, struct nameidata *nd)
459{
460 struct fuse_conn *fc = get_fuse_conn(inode);
461
462 if (!fuse_allow_task(fc, current))
463 return -EACCES;
464 else if (fc->flags & FUSE_DEFAULT_PERMISSIONS) {
465 int err = generic_permission(inode, mask, NULL);
466
467 /* If permission is denied, try to refresh file
468 attributes. This is also needed, because the root
469 node will at first have no permissions */
470 if (err == -EACCES) {
471 err = fuse_do_getattr(inode);
472 if (!err)
473 err = generic_permission(inode, mask, NULL);
474 }
475
476 /* FIXME: Need some mechanism to revoke permissions:
477 currently if the filesystem suddenly changes the
478 file mode, we will not be informed about it, and
479 continue to allow access to the file/directory.
480
481 This is actually not so grave, since the user can
482 simply keep access to the file/directory anyway by
483 keeping it open... */
484
485 return err;
486 } else {
487 int mode = inode->i_mode;
488 if ((mask & MAY_WRITE) && IS_RDONLY(inode) &&
489 (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
490 return -EROFS;
491 if ((mask & MAY_EXEC) && !S_ISDIR(mode) && !(mode & S_IXUGO))
492 return -EACCES;
493 return 0;
494 }
495}
496
497static int parse_dirfile(char *buf, size_t nbytes, struct file *file,
498 void *dstbuf, filldir_t filldir)
499{
500 while (nbytes >= FUSE_NAME_OFFSET) {
501 struct fuse_dirent *dirent = (struct fuse_dirent *) buf;
502 size_t reclen = FUSE_DIRENT_SIZE(dirent);
503 int over;
504 if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX)
505 return -EIO;
506 if (reclen > nbytes)
507 break;
508
509 over = filldir(dstbuf, dirent->name, dirent->namelen,
510 file->f_pos, dirent->ino, dirent->type);
511 if (over)
512 break;
513
514 buf += reclen;
515 nbytes -= reclen;
516 file->f_pos = dirent->off;
517 }
518
519 return 0;
520}
521
522static inline size_t fuse_send_readdir(struct fuse_req *req, struct file *file,
523 struct inode *inode, loff_t pos,
524 size_t count)
525{
526 return fuse_send_read_common(req, file, inode, pos, count, 1);
527}
528
529static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir)
530{
531 int err;
532 size_t nbytes;
533 struct page *page;
534 struct inode *inode = file->f_dentry->d_inode;
535 struct fuse_conn *fc = get_fuse_conn(inode);
536 struct fuse_req *req = fuse_get_request(fc);
537 if (!req)
538 return -EINTR;
539
540 page = alloc_page(GFP_KERNEL);
541 if (!page) {
542 fuse_put_request(fc, req);
543 return -ENOMEM;
544 }
545 req->num_pages = 1;
546 req->pages[0] = page;
547 nbytes = fuse_send_readdir(req, file, inode, file->f_pos, PAGE_SIZE);
548 err = req->out.h.error;
549 fuse_put_request(fc, req);
550 if (!err)
551 err = parse_dirfile(page_address(page), nbytes, file, dstbuf,
552 filldir);
553
554 __free_page(page);
555 fuse_invalidate_attr(inode); /* atime changed */
556 return err;
557}
558
559static char *read_link(struct dentry *dentry)
560{
561 struct inode *inode = dentry->d_inode;
562 struct fuse_conn *fc = get_fuse_conn(inode);
563 struct fuse_req *req = fuse_get_request(fc);
564 char *link;
565
566 if (!req)
567 return ERR_PTR(-EINTR);
568
569 link = (char *) __get_free_page(GFP_KERNEL);
570 if (!link) {
571 link = ERR_PTR(-ENOMEM);
572 goto out;
573 }
574 req->in.h.opcode = FUSE_READLINK;
575 req->in.h.nodeid = get_node_id(inode);
576 req->inode = inode;
577 req->out.argvar = 1;
578 req->out.numargs = 1;
579 req->out.args[0].size = PAGE_SIZE - 1;
580 req->out.args[0].value = link;
581 request_send(fc, req);
582 if (req->out.h.error) {
583 free_page((unsigned long) link);
584 link = ERR_PTR(req->out.h.error);
585 } else
586 link[req->out.args[0].size] = '\0';
587 out:
588 fuse_put_request(fc, req);
589 fuse_invalidate_attr(inode); /* atime changed */
590 return link;
591}
592
593static void free_link(char *link)
594{
595 if (!IS_ERR(link))
596 free_page((unsigned long) link);
597}
598
599static void *fuse_follow_link(struct dentry *dentry, struct nameidata *nd)
600{
601 nd_set_link(nd, read_link(dentry));
602 return NULL;
603}
604
605static void fuse_put_link(struct dentry *dentry, struct nameidata *nd, void *c)
606{
607 free_link(nd_get_link(nd));
608}
609
610static int fuse_dir_open(struct inode *inode, struct file *file)
611{
612 return fuse_open_common(inode, file, 1);
613}
614
615static int fuse_dir_release(struct inode *inode, struct file *file)
616{
617 return fuse_release_common(inode, file, 1);
618}
619
620static int fuse_dir_fsync(struct file *file, struct dentry *de, int datasync)
621{
622 /* nfsd can call this with no file */
623 return file ? fuse_fsync_common(file, de, datasync, 1) : 0;
624}
625
626static unsigned iattr_to_fattr(struct iattr *iattr, struct fuse_attr *fattr)
627{
628 unsigned ivalid = iattr->ia_valid;
629 unsigned fvalid = 0;
630
631 memset(fattr, 0, sizeof(*fattr));
632
633 if (ivalid & ATTR_MODE)
634 fvalid |= FATTR_MODE, fattr->mode = iattr->ia_mode;
635 if (ivalid & ATTR_UID)
636 fvalid |= FATTR_UID, fattr->uid = iattr->ia_uid;
637 if (ivalid & ATTR_GID)
638 fvalid |= FATTR_GID, fattr->gid = iattr->ia_gid;
639 if (ivalid & ATTR_SIZE)
640 fvalid |= FATTR_SIZE, fattr->size = iattr->ia_size;
641 /* You can only _set_ these together (they may change by themselves) */
642 if ((ivalid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) {
643 fvalid |= FATTR_ATIME | FATTR_MTIME;
644 fattr->atime = iattr->ia_atime.tv_sec;
645 fattr->mtime = iattr->ia_mtime.tv_sec;
646 }
647
648 return fvalid;
649}
650
651static int fuse_setattr(struct dentry *entry, struct iattr *attr)
652{
653 struct inode *inode = entry->d_inode;
654 struct fuse_conn *fc = get_fuse_conn(inode);
655 struct fuse_inode *fi = get_fuse_inode(inode);
656 struct fuse_req *req;
657 struct fuse_setattr_in inarg;
658 struct fuse_attr_out outarg;
659 int err;
660 int is_truncate = 0;
661
662 if (fc->flags & FUSE_DEFAULT_PERMISSIONS) {
663 err = inode_change_ok(inode, attr);
664 if (err)
665 return err;
666 }
667
668 if (attr->ia_valid & ATTR_SIZE) {
669 unsigned long limit;
670 is_truncate = 1;
671 limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
672 if (limit != RLIM_INFINITY && attr->ia_size > (loff_t) limit) {
673 send_sig(SIGXFSZ, current, 0);
674 return -EFBIG;
675 }
676 }
677
678 req = fuse_get_request(fc);
679 if (!req)
680 return -EINTR;
681
682 memset(&inarg, 0, sizeof(inarg));
683 inarg.valid = iattr_to_fattr(attr, &inarg.attr);
684 req->in.h.opcode = FUSE_SETATTR;
685 req->in.h.nodeid = get_node_id(inode);
686 req->inode = inode;
687 req->in.numargs = 1;
688 req->in.args[0].size = sizeof(inarg);
689 req->in.args[0].value = &inarg;
690 req->out.numargs = 1;
691 req->out.args[0].size = sizeof(outarg);
692 req->out.args[0].value = &outarg;
693 request_send(fc, req);
694 err = req->out.h.error;
695 fuse_put_request(fc, req);
696 if (!err) {
697 if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
698 make_bad_inode(inode);
699 err = -EIO;
700 } else {
701 if (is_truncate) {
702 loff_t origsize = i_size_read(inode);
703 i_size_write(inode, outarg.attr.size);
704 if (origsize > outarg.attr.size)
705 vmtruncate(inode, outarg.attr.size);
706 }
707 fuse_change_attributes(inode, &outarg.attr);
708 fi->i_time = time_to_jiffies(outarg.attr_valid,
709 outarg.attr_valid_nsec);
710 }
711 } else if (err == -EINTR)
712 fuse_invalidate_attr(inode);
713
714 return err;
715}
716
717static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry,
718 struct kstat *stat)
719{
720 struct inode *inode = entry->d_inode;
721 int err = fuse_revalidate(entry);
722 if (!err)
723 generic_fillattr(inode, stat);
724
725 return err;
726}
727
728static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
729 struct nameidata *nd)
730{
731 struct inode *inode;
732 int err = fuse_lookup_iget(dir, entry, &inode);
733 if (err)
734 return ERR_PTR(err);
735 if (inode && S_ISDIR(inode->i_mode)) {
736 /* Don't allow creating an alias to a directory */
737 struct dentry *alias = d_find_alias(inode);
738 if (alias && !(alias->d_flags & DCACHE_DISCONNECTED)) {
739 dput(alias);
740 iput(inode);
741 return ERR_PTR(-EIO);
742 }
743 }
744 return d_splice_alias(inode, entry);
745}
746
747static int fuse_setxattr(struct dentry *entry, const char *name,
748 const void *value, size_t size, int flags)
749{
750 struct inode *inode = entry->d_inode;
751 struct fuse_conn *fc = get_fuse_conn(inode);
752 struct fuse_req *req;
753 struct fuse_setxattr_in inarg;
754 int err;
755
756 if (size > FUSE_XATTR_SIZE_MAX)
757 return -E2BIG;
758
759 if (fc->no_setxattr)
760 return -EOPNOTSUPP;
761
762 req = fuse_get_request(fc);
763 if (!req)
764 return -EINTR;
765
766 memset(&inarg, 0, sizeof(inarg));
767 inarg.size = size;
768 inarg.flags = flags;
769 req->in.h.opcode = FUSE_SETXATTR;
770 req->in.h.nodeid = get_node_id(inode);
771 req->inode = inode;
772 req->in.numargs = 3;
773 req->in.args[0].size = sizeof(inarg);
774 req->in.args[0].value = &inarg;
775 req->in.args[1].size = strlen(name) + 1;
776 req->in.args[1].value = name;
777 req->in.args[2].size = size;
778 req->in.args[2].value = value;
779 request_send(fc, req);
780 err = req->out.h.error;
781 fuse_put_request(fc, req);
782 if (err == -ENOSYS) {
783 fc->no_setxattr = 1;
784 err = -EOPNOTSUPP;
785 }
786 return err;
787}
788
789static ssize_t fuse_getxattr(struct dentry *entry, const char *name,
790 void *value, size_t size)
791{
792 struct inode *inode = entry->d_inode;
793 struct fuse_conn *fc = get_fuse_conn(inode);
794 struct fuse_req *req;
795 struct fuse_getxattr_in inarg;
796 struct fuse_getxattr_out outarg;
797 ssize_t ret;
798
799 if (fc->no_getxattr)
800 return -EOPNOTSUPP;
801
802 req = fuse_get_request(fc);
803 if (!req)
804 return -EINTR;
805
806 memset(&inarg, 0, sizeof(inarg));
807 inarg.size = size;
808 req->in.h.opcode = FUSE_GETXATTR;
809 req->in.h.nodeid = get_node_id(inode);
810 req->inode = inode;
811 req->in.numargs = 2;
812 req->in.args[0].size = sizeof(inarg);
813 req->in.args[0].value = &inarg;
814 req->in.args[1].size = strlen(name) + 1;
815 req->in.args[1].value = name;
816 /* This is really two different operations rolled into one */
817 req->out.numargs = 1;
818 if (size) {
819 req->out.argvar = 1;
820 req->out.args[0].size = size;
821 req->out.args[0].value = value;
822 } else {
823 req->out.args[0].size = sizeof(outarg);
824 req->out.args[0].value = &outarg;
825 }
826 request_send(fc, req);
827 ret = req->out.h.error;
828 if (!ret)
829 ret = size ? req->out.args[0].size : outarg.size;
830 else {
831 if (ret == -ENOSYS) {
832 fc->no_getxattr = 1;
833 ret = -EOPNOTSUPP;
834 }
835 }
836 fuse_put_request(fc, req);
837 return ret;
838}
839
840static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size)
841{
842 struct inode *inode = entry->d_inode;
843 struct fuse_conn *fc = get_fuse_conn(inode);
844 struct fuse_req *req;
845 struct fuse_getxattr_in inarg;
846 struct fuse_getxattr_out outarg;
847 ssize_t ret;
848
849 if (fc->no_listxattr)
850 return -EOPNOTSUPP;
851
852 req = fuse_get_request(fc);
853 if (!req)
854 return -EINTR;
855
856 memset(&inarg, 0, sizeof(inarg));
857 inarg.size = size;
858 req->in.h.opcode = FUSE_LISTXATTR;
859 req->in.h.nodeid = get_node_id(inode);
860 req->inode = inode;
861 req->in.numargs = 1;
862 req->in.args[0].size = sizeof(inarg);
863 req->in.args[0].value = &inarg;
864 /* This is really two different operations rolled into one */
865 req->out.numargs = 1;
866 if (size) {
867 req->out.argvar = 1;
868 req->out.args[0].size = size;
869 req->out.args[0].value = list;
870 } else {
871 req->out.args[0].size = sizeof(outarg);
872 req->out.args[0].value = &outarg;
873 }
874 request_send(fc, req);
875 ret = req->out.h.error;
876 if (!ret)
877 ret = size ? req->out.args[0].size : outarg.size;
878 else {
879 if (ret == -ENOSYS) {
880 fc->no_listxattr = 1;
881 ret = -EOPNOTSUPP;
882 }
883 }
884 fuse_put_request(fc, req);
885 return ret;
886}
887
888static int fuse_removexattr(struct dentry *entry, const char *name)
889{
890 struct inode *inode = entry->d_inode;
891 struct fuse_conn *fc = get_fuse_conn(inode);
892 struct fuse_req *req;
893 int err;
894
895 if (fc->no_removexattr)
896 return -EOPNOTSUPP;
897
898 req = fuse_get_request(fc);
899 if (!req)
900 return -EINTR;
901
902 req->in.h.opcode = FUSE_REMOVEXATTR;
903 req->in.h.nodeid = get_node_id(inode);
904 req->inode = inode;
905 req->in.numargs = 1;
906 req->in.args[0].size = strlen(name) + 1;
907 req->in.args[0].value = name;
908 request_send(fc, req);
909 err = req->out.h.error;
910 fuse_put_request(fc, req);
911 if (err == -ENOSYS) {
912 fc->no_removexattr = 1;
913 err = -EOPNOTSUPP;
914 }
915 return err;
916}
917
918static struct inode_operations fuse_dir_inode_operations = {
919 .lookup = fuse_lookup,
920 .mkdir = fuse_mkdir,
921 .symlink = fuse_symlink,
922 .unlink = fuse_unlink,
923 .rmdir = fuse_rmdir,
924 .rename = fuse_rename,
925 .link = fuse_link,
926 .setattr = fuse_setattr,
927 .create = fuse_create,
928 .mknod = fuse_mknod,
929 .permission = fuse_permission,
930 .getattr = fuse_getattr,
931 .setxattr = fuse_setxattr,
932 .getxattr = fuse_getxattr,
933 .listxattr = fuse_listxattr,
934 .removexattr = fuse_removexattr,
935};
936
937static struct file_operations fuse_dir_operations = {
938 .llseek = generic_file_llseek,
939 .read = generic_read_dir,
940 .readdir = fuse_readdir,
941 .open = fuse_dir_open,
942 .release = fuse_dir_release,
943 .fsync = fuse_dir_fsync,
944};
945
946static struct inode_operations fuse_common_inode_operations = {
947 .setattr = fuse_setattr,
948 .permission = fuse_permission,
949 .getattr = fuse_getattr,
950 .setxattr = fuse_setxattr,
951 .getxattr = fuse_getxattr,
952 .listxattr = fuse_listxattr,
953 .removexattr = fuse_removexattr,
954};
955
956static struct inode_operations fuse_symlink_inode_operations = {
957 .setattr = fuse_setattr,
958 .follow_link = fuse_follow_link,
959 .put_link = fuse_put_link,
960 .readlink = generic_readlink,
961 .getattr = fuse_getattr,
962 .setxattr = fuse_setxattr,
963 .getxattr = fuse_getxattr,
964 .listxattr = fuse_listxattr,
965 .removexattr = fuse_removexattr,
966};
967
968void fuse_init_common(struct inode *inode)
969{
970 inode->i_op = &fuse_common_inode_operations;
971}
972
973void fuse_init_dir(struct inode *inode)
974{
975 inode->i_op = &fuse_dir_inode_operations;
976 inode->i_fop = &fuse_dir_operations;
977}
978
979void fuse_init_symlink(struct inode *inode)
980{
981 inode->i_op = &fuse_symlink_inode_operations;
982}
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
new file mode 100644
index 0000000000..6454022b05
--- /dev/null
+++ b/fs/fuse/file.c
@@ -0,0 +1,555 @@
1/*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu>
4
5 This program can be distributed under the terms of the GNU GPL.
6 See the file COPYING.
7*/
8
9#include "fuse_i.h"
10
11#include <linux/pagemap.h>
12#include <linux/slab.h>
13#include <linux/kernel.h>
14
15static struct file_operations fuse_direct_io_file_operations;
16
17int fuse_open_common(struct inode *inode, struct file *file, int isdir)
18{
19 struct fuse_conn *fc = get_fuse_conn(inode);
20 struct fuse_req *req;
21 struct fuse_open_in inarg;
22 struct fuse_open_out outarg;
23 struct fuse_file *ff;
24 int err;
25
26 err = generic_file_open(inode, file);
27 if (err)
28 return err;
29
30 /* If opening the root node, no lookup has been performed on
31 it, so the attributes must be refreshed */
32 if (get_node_id(inode) == FUSE_ROOT_ID) {
33 int err = fuse_do_getattr(inode);
34 if (err)
35 return err;
36 }
37
38 req = fuse_get_request(fc);
39 if (!req)
40 return -EINTR;
41
42 err = -ENOMEM;
43 ff = kmalloc(sizeof(struct fuse_file), GFP_KERNEL);
44 if (!ff)
45 goto out_put_request;
46
47 ff->release_req = fuse_request_alloc();
48 if (!ff->release_req) {
49 kfree(ff);
50 goto out_put_request;
51 }
52
53 memset(&inarg, 0, sizeof(inarg));
54 inarg.flags = file->f_flags & ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
55 req->in.h.opcode = isdir ? FUSE_OPENDIR : FUSE_OPEN;
56 req->in.h.nodeid = get_node_id(inode);
57 req->inode = inode;
58 req->in.numargs = 1;
59 req->in.args[0].size = sizeof(inarg);
60 req->in.args[0].value = &inarg;
61 req->out.numargs = 1;
62 req->out.args[0].size = sizeof(outarg);
63 req->out.args[0].value = &outarg;
64 request_send(fc, req);
65 err = req->out.h.error;
66 if (err) {
67 fuse_request_free(ff->release_req);
68 kfree(ff);
69 } else {
70 if (!isdir && (outarg.open_flags & FOPEN_DIRECT_IO))
71 file->f_op = &fuse_direct_io_file_operations;
72 if (!(outarg.open_flags & FOPEN_KEEP_CACHE))
73 invalidate_inode_pages(inode->i_mapping);
74 ff->fh = outarg.fh;
75 file->private_data = ff;
76 }
77
78 out_put_request:
79 fuse_put_request(fc, req);
80 return err;
81}
82
83int fuse_release_common(struct inode *inode, struct file *file, int isdir)
84{
85 struct fuse_conn *fc = get_fuse_conn(inode);
86 struct fuse_file *ff = file->private_data;
87 struct fuse_req *req = ff->release_req;
88 struct fuse_release_in *inarg = &req->misc.release_in;
89
90 inarg->fh = ff->fh;
91 inarg->flags = file->f_flags & ~O_EXCL;
92 req->in.h.opcode = isdir ? FUSE_RELEASEDIR : FUSE_RELEASE;
93 req->in.h.nodeid = get_node_id(inode);
94 req->inode = inode;
95 req->in.numargs = 1;
96 req->in.args[0].size = sizeof(struct fuse_release_in);
97 req->in.args[0].value = inarg;
98 request_send_background(fc, req);
99 kfree(ff);
100
101 /* Return value is ignored by VFS */
102 return 0;
103}
104
105static int fuse_open(struct inode *inode, struct file *file)
106{
107 return fuse_open_common(inode, file, 0);
108}
109
110static int fuse_release(struct inode *inode, struct file *file)
111{
112 return fuse_release_common(inode, file, 0);
113}
114
115static int fuse_flush(struct file *file)
116{
117 struct inode *inode = file->f_dentry->d_inode;
118 struct fuse_conn *fc = get_fuse_conn(inode);
119 struct fuse_file *ff = file->private_data;
120 struct fuse_req *req;
121 struct fuse_flush_in inarg;
122 int err;
123
124 if (fc->no_flush)
125 return 0;
126
127 req = fuse_get_request(fc);
128 if (!req)
129 return -EINTR;
130
131 memset(&inarg, 0, sizeof(inarg));
132 inarg.fh = ff->fh;
133 req->in.h.opcode = FUSE_FLUSH;
134 req->in.h.nodeid = get_node_id(inode);
135 req->inode = inode;
136 req->file = file;
137 req->in.numargs = 1;
138 req->in.args[0].size = sizeof(inarg);
139 req->in.args[0].value = &inarg;
140 request_send(fc, req);
141 err = req->out.h.error;
142 fuse_put_request(fc, req);
143 if (err == -ENOSYS) {
144 fc->no_flush = 1;
145 err = 0;
146 }
147 return err;
148}
149
150int fuse_fsync_common(struct file *file, struct dentry *de, int datasync,
151 int isdir)
152{
153 struct inode *inode = de->d_inode;
154 struct fuse_conn *fc = get_fuse_conn(inode);
155 struct fuse_file *ff = file->private_data;
156 struct fuse_req *req;
157 struct fuse_fsync_in inarg;
158 int err;
159
160 if ((!isdir && fc->no_fsync) || (isdir && fc->no_fsyncdir))
161 return 0;
162
163 req = fuse_get_request(fc);
164 if (!req)
165 return -EINTR;
166
167 memset(&inarg, 0, sizeof(inarg));
168 inarg.fh = ff->fh;
169 inarg.fsync_flags = datasync ? 1 : 0;
170 req->in.h.opcode = isdir ? FUSE_FSYNCDIR : FUSE_FSYNC;
171 req->in.h.nodeid = get_node_id(inode);
172 req->inode = inode;
173 req->file = file;
174 req->in.numargs = 1;
175 req->in.args[0].size = sizeof(inarg);
176 req->in.args[0].value = &inarg;
177 request_send(fc, req);
178 err = req->out.h.error;
179 fuse_put_request(fc, req);
180 if (err == -ENOSYS) {
181 if (isdir)
182 fc->no_fsyncdir = 1;
183 else
184 fc->no_fsync = 1;
185 err = 0;
186 }
187 return err;
188}
189
190static int fuse_fsync(struct file *file, struct dentry *de, int datasync)
191{
192 return fuse_fsync_common(file, de, datasync, 0);
193}
194
195size_t fuse_send_read_common(struct fuse_req *req, struct file *file,
196 struct inode *inode, loff_t pos, size_t count,
197 int isdir)
198{
199 struct fuse_conn *fc = get_fuse_conn(inode);
200 struct fuse_file *ff = file->private_data;
201 struct fuse_read_in inarg;
202
203 memset(&inarg, 0, sizeof(struct fuse_read_in));
204 inarg.fh = ff->fh;
205 inarg.offset = pos;
206 inarg.size = count;
207 req->in.h.opcode = isdir ? FUSE_READDIR : FUSE_READ;
208 req->in.h.nodeid = get_node_id(inode);
209 req->inode = inode;
210 req->file = file;
211 req->in.numargs = 1;
212 req->in.args[0].size = sizeof(struct fuse_read_in);
213 req->in.args[0].value = &inarg;
214 req->out.argpages = 1;
215 req->out.argvar = 1;
216 req->out.numargs = 1;
217 req->out.args[0].size = count;
218 request_send(fc, req);
219 return req->out.args[0].size;
220}
221
222static inline size_t fuse_send_read(struct fuse_req *req, struct file *file,
223 struct inode *inode, loff_t pos,
224 size_t count)
225{
226 return fuse_send_read_common(req, file, inode, pos, count, 0);
227}
228
229static int fuse_readpage(struct file *file, struct page *page)
230{
231 struct inode *inode = page->mapping->host;
232 struct fuse_conn *fc = get_fuse_conn(inode);
233 loff_t pos = (loff_t) page->index << PAGE_CACHE_SHIFT;
234 struct fuse_req *req = fuse_get_request(fc);
235 int err = -EINTR;
236 if (!req)
237 goto out;
238
239 req->out.page_zeroing = 1;
240 req->num_pages = 1;
241 req->pages[0] = page;
242 fuse_send_read(req, file, inode, pos, PAGE_CACHE_SIZE);
243 err = req->out.h.error;
244 fuse_put_request(fc, req);
245 if (!err)
246 SetPageUptodate(page);
247 fuse_invalidate_attr(inode); /* atime changed */
248 out:
249 unlock_page(page);
250 return err;
251}
252
253static int fuse_send_readpages(struct fuse_req *req, struct file *file,
254 struct inode *inode)
255{
256 loff_t pos = (loff_t) req->pages[0]->index << PAGE_CACHE_SHIFT;
257 size_t count = req->num_pages << PAGE_CACHE_SHIFT;
258 unsigned i;
259 req->out.page_zeroing = 1;
260 fuse_send_read(req, file, inode, pos, count);
261 for (i = 0; i < req->num_pages; i++) {
262 struct page *page = req->pages[i];
263 if (!req->out.h.error)
264 SetPageUptodate(page);
265 unlock_page(page);
266 }
267 return req->out.h.error;
268}
269
270struct fuse_readpages_data {
271 struct fuse_req *req;
272 struct file *file;
273 struct inode *inode;
274};
275
276static int fuse_readpages_fill(void *_data, struct page *page)
277{
278 struct fuse_readpages_data *data = _data;
279 struct fuse_req *req = data->req;
280 struct inode *inode = data->inode;
281 struct fuse_conn *fc = get_fuse_conn(inode);
282
283 if (req->num_pages &&
284 (req->num_pages == FUSE_MAX_PAGES_PER_REQ ||
285 (req->num_pages + 1) * PAGE_CACHE_SIZE > fc->max_read ||
286 req->pages[req->num_pages - 1]->index + 1 != page->index)) {
287 int err = fuse_send_readpages(req, data->file, inode);
288 if (err) {
289 unlock_page(page);
290 return err;
291 }
292 fuse_reset_request(req);
293 }
294 req->pages[req->num_pages] = page;
295 req->num_pages ++;
296 return 0;
297}
298
299static int fuse_readpages(struct file *file, struct address_space *mapping,
300 struct list_head *pages, unsigned nr_pages)
301{
302 struct inode *inode = mapping->host;
303 struct fuse_conn *fc = get_fuse_conn(inode);
304 struct fuse_readpages_data data;
305 int err;
306 data.file = file;
307 data.inode = inode;
308 data.req = fuse_get_request(fc);
309 if (!data.req)
310 return -EINTR;
311
312 err = read_cache_pages(mapping, pages, fuse_readpages_fill, &data);
313 if (!err && data.req->num_pages)
314 err = fuse_send_readpages(data.req, file, inode);
315 fuse_put_request(fc, data.req);
316 fuse_invalidate_attr(inode); /* atime changed */
317 return err;
318}
319
320static size_t fuse_send_write(struct fuse_req *req, struct file *file,
321 struct inode *inode, loff_t pos, size_t count)
322{
323 struct fuse_conn *fc = get_fuse_conn(inode);
324 struct fuse_file *ff = file->private_data;
325 struct fuse_write_in inarg;
326 struct fuse_write_out outarg;
327
328 memset(&inarg, 0, sizeof(struct fuse_write_in));
329 inarg.fh = ff->fh;
330 inarg.offset = pos;
331 inarg.size = count;
332 req->in.h.opcode = FUSE_WRITE;
333 req->in.h.nodeid = get_node_id(inode);
334 req->inode = inode;
335 req->file = file;
336 req->in.argpages = 1;
337 req->in.numargs = 2;
338 req->in.args[0].size = sizeof(struct fuse_write_in);
339 req->in.args[0].value = &inarg;
340 req->in.args[1].size = count;
341 req->out.numargs = 1;
342 req->out.args[0].size = sizeof(struct fuse_write_out);
343 req->out.args[0].value = &outarg;
344 request_send(fc, req);
345 return outarg.size;
346}
347
348static int fuse_prepare_write(struct file *file, struct page *page,
349 unsigned offset, unsigned to)
350{
351 /* No op */
352 return 0;
353}
354
355static int fuse_commit_write(struct file *file, struct page *page,
356 unsigned offset, unsigned to)
357{
358 int err;
359 size_t nres;
360 unsigned count = to - offset;
361 struct inode *inode = page->mapping->host;
362 struct fuse_conn *fc = get_fuse_conn(inode);
363 loff_t pos = ((loff_t) page->index << PAGE_CACHE_SHIFT) + offset;
364 struct fuse_req *req = fuse_get_request(fc);
365 if (!req)
366 return -EINTR;
367
368 req->num_pages = 1;
369 req->pages[0] = page;
370 req->page_offset = offset;
371 nres = fuse_send_write(req, file, inode, pos, count);
372 err = req->out.h.error;
373 fuse_put_request(fc, req);
374 if (!err && nres != count)
375 err = -EIO;
376 if (!err) {
377 pos += count;
378 if (pos > i_size_read(inode))
379 i_size_write(inode, pos);
380
381 if (offset == 0 && to == PAGE_CACHE_SIZE) {
382 clear_page_dirty(page);
383 SetPageUptodate(page);
384 }
385 }
386 fuse_invalidate_attr(inode);
387 return err;
388}
389
390static void fuse_release_user_pages(struct fuse_req *req, int write)
391{
392 unsigned i;
393
394 for (i = 0; i < req->num_pages; i++) {
395 struct page *page = req->pages[i];
396 if (write)
397 set_page_dirty_lock(page);
398 put_page(page);
399 }
400}
401
402static int fuse_get_user_pages(struct fuse_req *req, const char __user *buf,
403 unsigned nbytes, int write)
404{
405 unsigned long user_addr = (unsigned long) buf;
406 unsigned offset = user_addr & ~PAGE_MASK;
407 int npages;
408
409 /* This doesn't work with nfsd */
410 if (!current->mm)
411 return -EPERM;
412
413 nbytes = min(nbytes, (unsigned) FUSE_MAX_PAGES_PER_REQ << PAGE_SHIFT);
414 npages = (nbytes + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
415 npages = min(npages, FUSE_MAX_PAGES_PER_REQ);
416 down_read(&current->mm->mmap_sem);
417 npages = get_user_pages(current, current->mm, user_addr, npages, write,
418 0, req->pages, NULL);
419 up_read(&current->mm->mmap_sem);
420 if (npages < 0)
421 return npages;
422
423 req->num_pages = npages;
424 req->page_offset = offset;
425 return 0;
426}
427
428static ssize_t fuse_direct_io(struct file *file, const char __user *buf,
429 size_t count, loff_t *ppos, int write)
430{
431 struct inode *inode = file->f_dentry->d_inode;
432 struct fuse_conn *fc = get_fuse_conn(inode);
433 size_t nmax = write ? fc->max_write : fc->max_read;
434 loff_t pos = *ppos;
435 ssize_t res = 0;
436 struct fuse_req *req = fuse_get_request(fc);
437 if (!req)
438 return -EINTR;
439
440 while (count) {
441 size_t tmp;
442 size_t nres;
443 size_t nbytes = min(count, nmax);
444 int err = fuse_get_user_pages(req, buf, nbytes, !write);
445 if (err) {
446 res = err;
447 break;
448 }
449 tmp = (req->num_pages << PAGE_SHIFT) - req->page_offset;
450 nbytes = min(nbytes, tmp);
451 if (write)
452 nres = fuse_send_write(req, file, inode, pos, nbytes);
453 else
454 nres = fuse_send_read(req, file, inode, pos, nbytes);
455 fuse_release_user_pages(req, !write);
456 if (req->out.h.error) {
457 if (!res)
458 res = req->out.h.error;
459 break;
460 } else if (nres > nbytes) {
461 res = -EIO;
462 break;
463 }
464 count -= nres;
465 res += nres;
466 pos += nres;
467 buf += nres;
468 if (nres != nbytes)
469 break;
470 if (count)
471 fuse_reset_request(req);
472 }
473 fuse_put_request(fc, req);
474 if (res > 0) {
475 if (write && pos > i_size_read(inode))
476 i_size_write(inode, pos);
477 *ppos = pos;
478 }
479 fuse_invalidate_attr(inode);
480
481 return res;
482}
483
484static ssize_t fuse_direct_read(struct file *file, char __user *buf,
485 size_t count, loff_t *ppos)
486{
487 return fuse_direct_io(file, buf, count, ppos, 0);
488}
489
490static ssize_t fuse_direct_write(struct file *file, const char __user *buf,
491 size_t count, loff_t *ppos)
492{
493 struct inode *inode = file->f_dentry->d_inode;
494 ssize_t res;
495 /* Don't allow parallel writes to the same file */
496 down(&inode->i_sem);
497 res = fuse_direct_io(file, buf, count, ppos, 1);
498 up(&inode->i_sem);
499 return res;
500}
501
502static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)
503{
504 if ((vma->vm_flags & VM_SHARED)) {
505 if ((vma->vm_flags & VM_WRITE))
506 return -ENODEV;
507 else
508 vma->vm_flags &= ~VM_MAYWRITE;
509 }
510 return generic_file_mmap(file, vma);
511}
512
513static int fuse_set_page_dirty(struct page *page)
514{
515 printk("fuse_set_page_dirty: should not happen\n");
516 dump_stack();
517 return 0;
518}
519
520static struct file_operations fuse_file_operations = {
521 .llseek = generic_file_llseek,
522 .read = generic_file_read,
523 .write = generic_file_write,
524 .mmap = fuse_file_mmap,
525 .open = fuse_open,
526 .flush = fuse_flush,
527 .release = fuse_release,
528 .fsync = fuse_fsync,
529 .sendfile = generic_file_sendfile,
530};
531
532static struct file_operations fuse_direct_io_file_operations = {
533 .llseek = generic_file_llseek,
534 .read = fuse_direct_read,
535 .write = fuse_direct_write,
536 .open = fuse_open,
537 .flush = fuse_flush,
538 .release = fuse_release,
539 .fsync = fuse_fsync,
540 /* no mmap and sendfile */
541};
542
543static struct address_space_operations fuse_file_aops = {
544 .readpage = fuse_readpage,
545 .prepare_write = fuse_prepare_write,
546 .commit_write = fuse_commit_write,
547 .readpages = fuse_readpages,
548 .set_page_dirty = fuse_set_page_dirty,
549};
550
551void fuse_init_file_inode(struct inode *inode)
552{
553 inode->i_fop = &fuse_file_operations;
554 inode->i_data.a_ops = &fuse_file_aops;
555}
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
new file mode 100644
index 0000000000..24d761518d
--- /dev/null
+++ b/fs/fuse/fuse_i.h
@@ -0,0 +1,451 @@
1/*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu>
4
5 This program can be distributed under the terms of the GNU GPL.
6 See the file COPYING.
7*/
8
9#include <linux/fuse.h>
10#include <linux/fs.h>
11#include <linux/wait.h>
12#include <linux/list.h>
13#include <linux/spinlock.h>
14#include <linux/mm.h>
15#include <linux/backing-dev.h>
16#include <asm/semaphore.h>
17
18/** Max number of pages that can be used in a single read request */
19#define FUSE_MAX_PAGES_PER_REQ 32
20
21/** If more requests are outstanding, then the operation will block */
22#define FUSE_MAX_OUTSTANDING 10
23
24/** If the FUSE_DEFAULT_PERMISSIONS flag is given, the filesystem
25 module will check permissions based on the file mode. Otherwise no
26 permission checking is done in the kernel */
27#define FUSE_DEFAULT_PERMISSIONS (1 << 0)
28
29/** If the FUSE_ALLOW_OTHER flag is given, then not only the user
30 doing the mount will be allowed to access the filesystem */
31#define FUSE_ALLOW_OTHER (1 << 1)
32
33
34/** FUSE inode */
35struct fuse_inode {
36 /** Inode data */
37 struct inode inode;
38
39 /** Unique ID, which identifies the inode between userspace
40 * and kernel */
41 u64 nodeid;
42
43 /** Number of lookups on this inode */
44 u64 nlookup;
45
46 /** The request used for sending the FORGET message */
47 struct fuse_req *forget_req;
48
49 /** Time in jiffies until the file attributes are valid */
50 unsigned long i_time;
51};
52
53/** FUSE specific file data */
54struct fuse_file {
55 /** Request reserved for flush and release */
56 struct fuse_req *release_req;
57
58 /** File handle used by userspace */
59 u64 fh;
60};
61
62/** One input argument of a request */
63struct fuse_in_arg {
64 unsigned size;
65 const void *value;
66};
67
68/** The request input */
69struct fuse_in {
70 /** The request header */
71 struct fuse_in_header h;
72
73 /** True if the data for the last argument is in req->pages */
74 unsigned argpages:1;
75
76 /** Number of arguments */
77 unsigned numargs;
78
79 /** Array of arguments */
80 struct fuse_in_arg args[3];
81};
82
83/** One output argument of a request */
84struct fuse_arg {
85 unsigned size;
86 void *value;
87};
88
89/** The request output */
90struct fuse_out {
91 /** Header returned from userspace */
92 struct fuse_out_header h;
93
94 /** Last argument is variable length (can be shorter than
95 arg->size) */
96 unsigned argvar:1;
97
98 /** Last argument is a list of pages to copy data to */
99 unsigned argpages:1;
100
101 /** Zero partially or not copied pages */
102 unsigned page_zeroing:1;
103
104 /** Number or arguments */
105 unsigned numargs;
106
107 /** Array of arguments */
108 struct fuse_arg args[3];
109};
110
111struct fuse_req;
112struct fuse_conn;
113
114/**
115 * A request to the client
116 */
117struct fuse_req {
118 /** This can be on either unused_list, pending or processing
119 lists in fuse_conn */
120 struct list_head list;
121
122 /** Entry on the background list */
123 struct list_head bg_entry;
124
125 /** refcount */
126 atomic_t count;
127
128 /** True if the request has reply */
129 unsigned isreply:1;
130
131 /** The request is preallocated */
132 unsigned preallocated:1;
133
134 /** The request was interrupted */
135 unsigned interrupted:1;
136
137 /** Request is sent in the background */
138 unsigned background:1;
139
140 /** Data is being copied to/from the request */
141 unsigned locked:1;
142
143 /** Request has been sent to userspace */
144 unsigned sent:1;
145
146 /** The request is finished */
147 unsigned finished:1;
148
149 /** The request input */
150 struct fuse_in in;
151
152 /** The request output */
153 struct fuse_out out;
154
155 /** Used to wake up the task waiting for completion of request*/
156 wait_queue_head_t waitq;
157
158 /** Data for asynchronous requests */
159 union {
160 struct fuse_forget_in forget_in;
161 struct fuse_release_in release_in;
162 struct fuse_init_in_out init_in_out;
163 } misc;
164
165 /** page vector */
166 struct page *pages[FUSE_MAX_PAGES_PER_REQ];
167
168 /** number of pages in vector */
169 unsigned num_pages;
170
171 /** offset of data on first page */
172 unsigned page_offset;
173
174 /** Inode used in the request */
175 struct inode *inode;
176
177 /** Second inode used in the request (or NULL) */
178 struct inode *inode2;
179
180 /** File used in the request (or NULL) */
181 struct file *file;
182};
183
184/**
185 * A Fuse connection.
186 *
187 * This structure is created, when the filesystem is mounted, and is
188 * destroyed, when the client device is closed and the filesystem is
189 * unmounted.
190 */
191struct fuse_conn {
192 /** Reference count */
193 int count;
194
195 /** The user id for this mount */
196 uid_t user_id;
197
198 /** The group id for this mount */
199 gid_t group_id;
200
201 /** The fuse mount flags for this mount */
202 unsigned flags;
203
204 /** Maximum read size */
205 unsigned max_read;
206
207 /** Maximum write size */
208 unsigned max_write;
209
210 /** Readers of the connection are waiting on this */
211 wait_queue_head_t waitq;
212
213 /** The list of pending requests */
214 struct list_head pending;
215
216 /** The list of requests being processed */
217 struct list_head processing;
218
219 /** Requests put in the background (RELEASE or any other
220 interrupted request) */
221 struct list_head background;
222
223 /** Controls the maximum number of outstanding requests */
224 struct semaphore outstanding_sem;
225
226 /** This counts the number of outstanding requests if
227 outstanding_sem would go negative */
228 unsigned outstanding_debt;
229
230 /** RW semaphore for exclusion with fuse_put_super() */
231 struct rw_semaphore sbput_sem;
232
233 /** The list of unused requests */
234 struct list_head unused_list;
235
236 /** The next unique request id */
237 u64 reqctr;
238
239 /** Mount is active */
240 unsigned mounted : 1;
241
242 /** Connection established */
243 unsigned connected : 1;
244
245 /** Connection failed (version mismatch) */
246 unsigned conn_error : 1;
247
248 /** Is fsync not implemented by fs? */
249 unsigned no_fsync : 1;
250
251 /** Is fsyncdir not implemented by fs? */
252 unsigned no_fsyncdir : 1;
253
254 /** Is flush not implemented by fs? */
255 unsigned no_flush : 1;
256
257 /** Is setxattr not implemented by fs? */
258 unsigned no_setxattr : 1;
259
260 /** Is getxattr not implemented by fs? */
261 unsigned no_getxattr : 1;
262
263 /** Is listxattr not implemented by fs? */
264 unsigned no_listxattr : 1;
265
266 /** Is removexattr not implemented by fs? */
267 unsigned no_removexattr : 1;
268
269 /** Backing dev info */
270 struct backing_dev_info bdi;
271};
272
273static inline struct fuse_conn **get_fuse_conn_super_p(struct super_block *sb)
274{
275 return (struct fuse_conn **) &sb->s_fs_info;
276}
277
278static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
279{
280 return *get_fuse_conn_super_p(sb);
281}
282
283static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
284{
285 return get_fuse_conn_super(inode->i_sb);
286}
287
288static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
289{
290 return container_of(inode, struct fuse_inode, inode);
291}
292
293static inline u64 get_node_id(struct inode *inode)
294{
295 return get_fuse_inode(inode)->nodeid;
296}
297
298/** Device operations */
299extern struct file_operations fuse_dev_operations;
300
301/**
302 * This is the single global spinlock which protects FUSE's structures
303 *
304 * The following data is protected by this lock:
305 *
306 * - the private_data field of the device file
307 * - the s_fs_info field of the super block
308 * - unused_list, pending, processing lists in fuse_conn
309 * - background list in fuse_conn
310 * - the unique request ID counter reqctr in fuse_conn
311 * - the sb (super_block) field in fuse_conn
312 * - the file (device file) field in fuse_conn
313 */
314extern spinlock_t fuse_lock;
315
316/**
317 * Get a filled in inode
318 */
319struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid,
320 int generation, struct fuse_attr *attr);
321
322/**
323 * Send FORGET command
324 */
325void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
326 unsigned long nodeid, u64 nlookup);
327
328/**
329 * Send READ or READDIR request
330 */
331size_t fuse_send_read_common(struct fuse_req *req, struct file *file,
332 struct inode *inode, loff_t pos, size_t count,
333 int isdir);
334
335/**
336 * Send OPEN or OPENDIR request
337 */
338int fuse_open_common(struct inode *inode, struct file *file, int isdir);
339
340/**
341 * Send RELEASE or RELEASEDIR request
342 */
343int fuse_release_common(struct inode *inode, struct file *file, int isdir);
344
345/**
346 * Send FSYNC or FSYNCDIR request
347 */
348int fuse_fsync_common(struct file *file, struct dentry *de, int datasync,
349 int isdir);
350
351/**
352 * Initialise file operations on a regular file
353 */
354void fuse_init_file_inode(struct inode *inode);
355
356/**
357 * Initialise inode operations on regular files and special files
358 */
359void fuse_init_common(struct inode *inode);
360
361/**
362 * Initialise inode and file operations on a directory
363 */
364void fuse_init_dir(struct inode *inode);
365
366/**
367 * Initialise inode operations on a symlink
368 */
369void fuse_init_symlink(struct inode *inode);
370
371/**
372 * Change attributes of an inode
373 */
374void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr);
375
376/**
377 * Check if the connection can be released, and if yes, then free the
378 * connection structure
379 */
380void fuse_release_conn(struct fuse_conn *fc);
381
382/**
383 * Initialize the client device
384 */
385int fuse_dev_init(void);
386
387/**
388 * Cleanup the client device
389 */
390void fuse_dev_cleanup(void);
391
392/**
393 * Allocate a request
394 */
395struct fuse_req *fuse_request_alloc(void);
396
397/**
398 * Free a request
399 */
400void fuse_request_free(struct fuse_req *req);
401
402/**
403 * Reinitialize a request, the preallocated flag is left unmodified
404 */
405void fuse_reset_request(struct fuse_req *req);
406
407/**
408 * Reserve a preallocated request
409 */
410struct fuse_req *fuse_get_request(struct fuse_conn *fc);
411
412/**
413 * Decrement reference count of a request. If count goes to zero put
414 * on unused list (preallocated) or free reqest (not preallocated).
415 */
416void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
417
418/**
419 * Send a request (synchronous)
420 */
421void request_send(struct fuse_conn *fc, struct fuse_req *req);
422
423/**
424 * Send a request with no reply
425 */
426void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req);
427
428/**
429 * Send a request in the background
430 */
431void request_send_background(struct fuse_conn *fc, struct fuse_req *req);
432
433/**
434 * Release inodes and file assiciated with background request
435 */
436void fuse_release_background(struct fuse_req *req);
437
438/**
439 * Get the attributes of a file
440 */
441int fuse_do_getattr(struct inode *inode);
442
443/**
444 * Invalidate inode attributes
445 */
446void fuse_invalidate_attr(struct inode *inode);
447
448/**
449 * Send the INIT message
450 */
451void fuse_send_init(struct fuse_conn *fc);
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
new file mode 100644
index 0000000000..e69a546844
--- /dev/null
+++ b/fs/fuse/inode.c
@@ -0,0 +1,591 @@
1/*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu>
4
5 This program can be distributed under the terms of the GNU GPL.
6 See the file COPYING.
7*/
8
9#include "fuse_i.h"
10
11#include <linux/pagemap.h>
12#include <linux/slab.h>
13#include <linux/file.h>
14#include <linux/mount.h>
15#include <linux/seq_file.h>
16#include <linux/init.h>
17#include <linux/module.h>
18#include <linux/parser.h>
19#include <linux/statfs.h>
20
21MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>");
22MODULE_DESCRIPTION("Filesystem in Userspace");
23MODULE_LICENSE("GPL");
24
25spinlock_t fuse_lock;
26static kmem_cache_t *fuse_inode_cachep;
27
28#define FUSE_SUPER_MAGIC 0x65735546
29
30struct fuse_mount_data {
31 int fd;
32 unsigned rootmode;
33 unsigned user_id;
34 unsigned group_id;
35 unsigned fd_present : 1;
36 unsigned rootmode_present : 1;
37 unsigned user_id_present : 1;
38 unsigned group_id_present : 1;
39 unsigned flags;
40 unsigned max_read;
41};
42
43static struct inode *fuse_alloc_inode(struct super_block *sb)
44{
45 struct inode *inode;
46 struct fuse_inode *fi;
47
48 inode = kmem_cache_alloc(fuse_inode_cachep, SLAB_KERNEL);
49 if (!inode)
50 return NULL;
51
52 fi = get_fuse_inode(inode);
53 fi->i_time = jiffies - 1;
54 fi->nodeid = 0;
55 fi->nlookup = 0;
56 fi->forget_req = fuse_request_alloc();
57 if (!fi->forget_req) {
58 kmem_cache_free(fuse_inode_cachep, inode);
59 return NULL;
60 }
61
62 return inode;
63}
64
65static void fuse_destroy_inode(struct inode *inode)
66{
67 struct fuse_inode *fi = get_fuse_inode(inode);
68 if (fi->forget_req)
69 fuse_request_free(fi->forget_req);
70 kmem_cache_free(fuse_inode_cachep, inode);
71}
72
73static void fuse_read_inode(struct inode *inode)
74{
75 /* No op */
76}
77
78void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
79 unsigned long nodeid, u64 nlookup)
80{
81 struct fuse_forget_in *inarg = &req->misc.forget_in;
82 inarg->nlookup = nlookup;
83 req->in.h.opcode = FUSE_FORGET;
84 req->in.h.nodeid = nodeid;
85 req->in.numargs = 1;
86 req->in.args[0].size = sizeof(struct fuse_forget_in);
87 req->in.args[0].value = inarg;
88 request_send_noreply(fc, req);
89}
90
91static void fuse_clear_inode(struct inode *inode)
92{
93 if (inode->i_sb->s_flags & MS_ACTIVE) {
94 struct fuse_conn *fc = get_fuse_conn(inode);
95 struct fuse_inode *fi = get_fuse_inode(inode);
96 fuse_send_forget(fc, fi->forget_req, fi->nodeid, fi->nlookup);
97 fi->forget_req = NULL;
98 }
99}
100
101void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr)
102{
103 if (S_ISREG(inode->i_mode) && i_size_read(inode) != attr->size)
104 invalidate_inode_pages(inode->i_mapping);
105
106 inode->i_ino = attr->ino;
107 inode->i_mode = (inode->i_mode & S_IFMT) + (attr->mode & 07777);
108 inode->i_nlink = attr->nlink;
109 inode->i_uid = attr->uid;
110 inode->i_gid = attr->gid;
111 i_size_write(inode, attr->size);
112 inode->i_blksize = PAGE_CACHE_SIZE;
113 inode->i_blocks = attr->blocks;
114 inode->i_atime.tv_sec = attr->atime;
115 inode->i_atime.tv_nsec = attr->atimensec;
116 inode->i_mtime.tv_sec = attr->mtime;
117 inode->i_mtime.tv_nsec = attr->mtimensec;
118 inode->i_ctime.tv_sec = attr->ctime;
119 inode->i_ctime.tv_nsec = attr->ctimensec;
120}
121
122static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr)
123{
124 inode->i_mode = attr->mode & S_IFMT;
125 i_size_write(inode, attr->size);
126 if (S_ISREG(inode->i_mode)) {
127 fuse_init_common(inode);
128 fuse_init_file_inode(inode);
129 } else if (S_ISDIR(inode->i_mode))
130 fuse_init_dir(inode);
131 else if (S_ISLNK(inode->i_mode))
132 fuse_init_symlink(inode);
133 else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
134 S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
135 fuse_init_common(inode);
136 init_special_inode(inode, inode->i_mode,
137 new_decode_dev(attr->rdev));
138 } else {
139 /* Don't let user create weird files */
140 inode->i_mode = S_IFREG;
141 fuse_init_common(inode);
142 fuse_init_file_inode(inode);
143 }
144}
145
146static int fuse_inode_eq(struct inode *inode, void *_nodeidp)
147{
148 unsigned long nodeid = *(unsigned long *) _nodeidp;
149 if (get_node_id(inode) == nodeid)
150 return 1;
151 else
152 return 0;
153}
154
155static int fuse_inode_set(struct inode *inode, void *_nodeidp)
156{
157 unsigned long nodeid = *(unsigned long *) _nodeidp;
158 get_fuse_inode(inode)->nodeid = nodeid;
159 return 0;
160}
161
162struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid,
163 int generation, struct fuse_attr *attr)
164{
165 struct inode *inode;
166 struct fuse_inode *fi;
167 struct fuse_conn *fc = get_fuse_conn_super(sb);
168 int retried = 0;
169
170 retry:
171 inode = iget5_locked(sb, nodeid, fuse_inode_eq, fuse_inode_set, &nodeid);
172 if (!inode)
173 return NULL;
174
175 if ((inode->i_state & I_NEW)) {
176 inode->i_flags |= S_NOATIME|S_NOCMTIME;
177 inode->i_generation = generation;
178 inode->i_data.backing_dev_info = &fc->bdi;
179 fuse_init_inode(inode, attr);
180 unlock_new_inode(inode);
181 } else if ((inode->i_mode ^ attr->mode) & S_IFMT) {
182 BUG_ON(retried);
183 /* Inode has changed type, any I/O on the old should fail */
184 make_bad_inode(inode);
185 iput(inode);
186 retried = 1;
187 goto retry;
188 }
189
190 fi = get_fuse_inode(inode);
191 fi->nlookup ++;
192 fuse_change_attributes(inode, attr);
193 return inode;
194}
195
196static void fuse_put_super(struct super_block *sb)
197{
198 struct fuse_conn *fc = get_fuse_conn_super(sb);
199
200 down_write(&fc->sbput_sem);
201 while (!list_empty(&fc->background))
202 fuse_release_background(list_entry(fc->background.next,
203 struct fuse_req, bg_entry));
204
205 spin_lock(&fuse_lock);
206 fc->mounted = 0;
207 fc->user_id = 0;
208 fc->group_id = 0;
209 fc->flags = 0;
210 /* Flush all readers on this fs */
211 wake_up_all(&fc->waitq);
212 up_write(&fc->sbput_sem);
213 fuse_release_conn(fc);
214 spin_unlock(&fuse_lock);
215}
216
217static void convert_fuse_statfs(struct kstatfs *stbuf, struct fuse_kstatfs *attr)
218{
219 stbuf->f_type = FUSE_SUPER_MAGIC;
220 stbuf->f_bsize = attr->bsize;
221 stbuf->f_blocks = attr->blocks;
222 stbuf->f_bfree = attr->bfree;
223 stbuf->f_bavail = attr->bavail;
224 stbuf->f_files = attr->files;
225 stbuf->f_ffree = attr->ffree;
226 stbuf->f_namelen = attr->namelen;
227 /* fsid is left zero */
228}
229
230static int fuse_statfs(struct super_block *sb, struct kstatfs *buf)
231{
232 struct fuse_conn *fc = get_fuse_conn_super(sb);
233 struct fuse_req *req;
234 struct fuse_statfs_out outarg;
235 int err;
236
237 req = fuse_get_request(fc);
238 if (!req)
239 return -EINTR;
240
241 req->in.numargs = 0;
242 req->in.h.opcode = FUSE_STATFS;
243 req->out.numargs = 1;
244 req->out.args[0].size = sizeof(outarg);
245 req->out.args[0].value = &outarg;
246 request_send(fc, req);
247 err = req->out.h.error;
248 if (!err)
249 convert_fuse_statfs(buf, &outarg.st);
250 fuse_put_request(fc, req);
251 return err;
252}
253
254enum {
255 OPT_FD,
256 OPT_ROOTMODE,
257 OPT_USER_ID,
258 OPT_GROUP_ID,
259 OPT_DEFAULT_PERMISSIONS,
260 OPT_ALLOW_OTHER,
261 OPT_MAX_READ,
262 OPT_ERR
263};
264
265static match_table_t tokens = {
266 {OPT_FD, "fd=%u"},
267 {OPT_ROOTMODE, "rootmode=%o"},
268 {OPT_USER_ID, "user_id=%u"},
269 {OPT_GROUP_ID, "group_id=%u"},
270 {OPT_DEFAULT_PERMISSIONS, "default_permissions"},
271 {OPT_ALLOW_OTHER, "allow_other"},
272 {OPT_MAX_READ, "max_read=%u"},
273 {OPT_ERR, NULL}
274};
275
276static int parse_fuse_opt(char *opt, struct fuse_mount_data *d)
277{
278 char *p;
279 memset(d, 0, sizeof(struct fuse_mount_data));
280 d->max_read = ~0;
281
282 while ((p = strsep(&opt, ",")) != NULL) {
283 int token;
284 int value;
285 substring_t args[MAX_OPT_ARGS];
286 if (!*p)
287 continue;
288
289 token = match_token(p, tokens, args);
290 switch (token) {
291 case OPT_FD:
292 if (match_int(&args[0], &value))
293 return 0;
294 d->fd = value;
295 d->fd_present = 1;
296 break;
297
298 case OPT_ROOTMODE:
299 if (match_octal(&args[0], &value))
300 return 0;
301 d->rootmode = value;
302 d->rootmode_present = 1;
303 break;
304
305 case OPT_USER_ID:
306 if (match_int(&args[0], &value))
307 return 0;
308 d->user_id = value;
309 d->user_id_present = 1;
310 break;
311
312 case OPT_GROUP_ID:
313 if (match_int(&args[0], &value))
314 return 0;
315 d->group_id = value;
316 d->group_id_present = 1;
317 break;
318
319 case OPT_DEFAULT_PERMISSIONS:
320 d->flags |= FUSE_DEFAULT_PERMISSIONS;
321 break;
322
323 case OPT_ALLOW_OTHER:
324 d->flags |= FUSE_ALLOW_OTHER;
325 break;
326
327 case OPT_MAX_READ:
328 if (match_int(&args[0], &value))
329 return 0;
330 d->max_read = value;
331 break;
332
333 default:
334 return 0;
335 }
336 }
337
338 if (!d->fd_present || !d->rootmode_present ||
339 !d->user_id_present || !d->group_id_present)
340 return 0;
341
342 return 1;
343}
344
345static int fuse_show_options(struct seq_file *m, struct vfsmount *mnt)
346{
347 struct fuse_conn *fc = get_fuse_conn_super(mnt->mnt_sb);
348
349 seq_printf(m, ",user_id=%u", fc->user_id);
350 seq_printf(m, ",group_id=%u", fc->group_id);
351 if (fc->flags & FUSE_DEFAULT_PERMISSIONS)
352 seq_puts(m, ",default_permissions");
353 if (fc->flags & FUSE_ALLOW_OTHER)
354 seq_puts(m, ",allow_other");
355 if (fc->max_read != ~0)
356 seq_printf(m, ",max_read=%u", fc->max_read);
357 return 0;
358}
359
360static void free_conn(struct fuse_conn *fc)
361{
362 while (!list_empty(&fc->unused_list)) {
363 struct fuse_req *req;
364 req = list_entry(fc->unused_list.next, struct fuse_req, list);
365 list_del(&req->list);
366 fuse_request_free(req);
367 }
368 kfree(fc);
369}
370
371/* Must be called with the fuse lock held */
372void fuse_release_conn(struct fuse_conn *fc)
373{
374 fc->count--;
375 if (!fc->count)
376 free_conn(fc);
377}
378
379static struct fuse_conn *new_conn(void)
380{
381 struct fuse_conn *fc;
382
383 fc = kmalloc(sizeof(*fc), GFP_KERNEL);
384 if (fc != NULL) {
385 int i;
386 memset(fc, 0, sizeof(*fc));
387 init_waitqueue_head(&fc->waitq);
388 INIT_LIST_HEAD(&fc->pending);
389 INIT_LIST_HEAD(&fc->processing);
390 INIT_LIST_HEAD(&fc->unused_list);
391 INIT_LIST_HEAD(&fc->background);
392 sema_init(&fc->outstanding_sem, 0);
393 init_rwsem(&fc->sbput_sem);
394 for (i = 0; i < FUSE_MAX_OUTSTANDING; i++) {
395 struct fuse_req *req = fuse_request_alloc();
396 if (!req) {
397 free_conn(fc);
398 return NULL;
399 }
400 list_add(&req->list, &fc->unused_list);
401 }
402 fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE;
403 fc->bdi.unplug_io_fn = default_unplug_io_fn;
404 fc->reqctr = 0;
405 }
406 return fc;
407}
408
409static struct fuse_conn *get_conn(struct file *file, struct super_block *sb)
410{
411 struct fuse_conn *fc;
412
413 if (file->f_op != &fuse_dev_operations)
414 return ERR_PTR(-EINVAL);
415 fc = new_conn();
416 if (fc == NULL)
417 return ERR_PTR(-ENOMEM);
418 spin_lock(&fuse_lock);
419 if (file->private_data) {
420 free_conn(fc);
421 fc = ERR_PTR(-EINVAL);
422 } else {
423 file->private_data = fc;
424 *get_fuse_conn_super_p(sb) = fc;
425 fc->mounted = 1;
426 fc->connected = 1;
427 fc->count = 2;
428 }
429 spin_unlock(&fuse_lock);
430 return fc;
431}
432
433static struct inode *get_root_inode(struct super_block *sb, unsigned mode)
434{
435 struct fuse_attr attr;
436 memset(&attr, 0, sizeof(attr));
437
438 attr.mode = mode;
439 attr.ino = FUSE_ROOT_ID;
440 return fuse_iget(sb, 1, 0, &attr);
441}
442
443static struct super_operations fuse_super_operations = {
444 .alloc_inode = fuse_alloc_inode,
445 .destroy_inode = fuse_destroy_inode,
446 .read_inode = fuse_read_inode,
447 .clear_inode = fuse_clear_inode,
448 .put_super = fuse_put_super,
449 .statfs = fuse_statfs,
450 .show_options = fuse_show_options,
451};
452
453static int fuse_fill_super(struct super_block *sb, void *data, int silent)
454{
455 struct fuse_conn *fc;
456 struct inode *root;
457 struct fuse_mount_data d;
458 struct file *file;
459 int err;
460
461 if (!parse_fuse_opt((char *) data, &d))
462 return -EINVAL;
463
464 sb->s_blocksize = PAGE_CACHE_SIZE;
465 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
466 sb->s_magic = FUSE_SUPER_MAGIC;
467 sb->s_op = &fuse_super_operations;
468 sb->s_maxbytes = MAX_LFS_FILESIZE;
469
470 file = fget(d.fd);
471 if (!file)
472 return -EINVAL;
473
474 fc = get_conn(file, sb);
475 fput(file);
476 if (IS_ERR(fc))
477 return PTR_ERR(fc);
478
479 fc->flags = d.flags;
480 fc->user_id = d.user_id;
481 fc->group_id = d.group_id;
482 fc->max_read = d.max_read;
483 if (fc->max_read / PAGE_CACHE_SIZE < fc->bdi.ra_pages)
484 fc->bdi.ra_pages = fc->max_read / PAGE_CACHE_SIZE;
485 fc->max_write = FUSE_MAX_IN / 2;
486
487 err = -ENOMEM;
488 root = get_root_inode(sb, d.rootmode);
489 if (root == NULL)
490 goto err;
491
492 sb->s_root = d_alloc_root(root);
493 if (!sb->s_root) {
494 iput(root);
495 goto err;
496 }
497 fuse_send_init(fc);
498 return 0;
499
500 err:
501 spin_lock(&fuse_lock);
502 fuse_release_conn(fc);
503 spin_unlock(&fuse_lock);
504 return err;
505}
506
507static struct super_block *fuse_get_sb(struct file_system_type *fs_type,
508 int flags, const char *dev_name,
509 void *raw_data)
510{
511 return get_sb_nodev(fs_type, flags, raw_data, fuse_fill_super);
512}
513
514static struct file_system_type fuse_fs_type = {
515 .owner = THIS_MODULE,
516 .name = "fuse",
517 .get_sb = fuse_get_sb,
518 .kill_sb = kill_anon_super,
519};
520
521static void fuse_inode_init_once(void *foo, kmem_cache_t *cachep,
522 unsigned long flags)
523{
524 struct inode * inode = foo;
525
526 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
527 SLAB_CTOR_CONSTRUCTOR)
528 inode_init_once(inode);
529}
530
531static int __init fuse_fs_init(void)
532{
533 int err;
534
535 err = register_filesystem(&fuse_fs_type);
536 if (err)
537 printk("fuse: failed to register filesystem\n");
538 else {
539 fuse_inode_cachep = kmem_cache_create("fuse_inode",
540 sizeof(struct fuse_inode),
541 0, SLAB_HWCACHE_ALIGN,
542 fuse_inode_init_once, NULL);
543 if (!fuse_inode_cachep) {
544 unregister_filesystem(&fuse_fs_type);
545 err = -ENOMEM;
546 }
547 }
548
549 return err;
550}
551
552static void fuse_fs_cleanup(void)
553{
554 unregister_filesystem(&fuse_fs_type);
555 kmem_cache_destroy(fuse_inode_cachep);
556}
557
558static int __init fuse_init(void)
559{
560 int res;
561
562 printk("fuse init (API version %i.%i)\n",
563 FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION);
564
565 spin_lock_init(&fuse_lock);
566 res = fuse_fs_init();
567 if (res)
568 goto err;
569
570 res = fuse_dev_init();
571 if (res)
572 goto err_fs_cleanup;
573
574 return 0;
575
576 err_fs_cleanup:
577 fuse_fs_cleanup();
578 err:
579 return res;
580}
581
582static void __exit fuse_exit(void)
583{
584 printk(KERN_DEBUG "fuse exit\n");
585
586 fuse_fs_cleanup();
587 fuse_dev_cleanup();
588}
589
590module_init(fuse_init);
591module_exit(fuse_exit);
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index b2d18200a0..59c5062cd6 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -284,6 +284,7 @@ static struct inode *hostfs_alloc_inode(struct super_block *sb)
284 284
285static void hostfs_delete_inode(struct inode *inode) 285static void hostfs_delete_inode(struct inode *inode)
286{ 286{
287 truncate_inode_pages(&inode->i_data, 0);
287 if(HOSTFS_I(inode)->fd != -1) { 288 if(HOSTFS_I(inode)->fd != -1) {
288 close_file(&HOSTFS_I(inode)->fd); 289 close_file(&HOSTFS_I(inode)->fd);
289 HOSTFS_I(inode)->fd = -1; 290 HOSTFS_I(inode)->fd = -1;
diff --git a/fs/hpfs/inode.c b/fs/hpfs/inode.c
index 38b1741fa5..e3d17e9ea6 100644
--- a/fs/hpfs/inode.c
+++ b/fs/hpfs/inode.c
@@ -284,6 +284,7 @@ void hpfs_write_if_changed(struct inode *inode)
284 284
285void hpfs_delete_inode(struct inode *inode) 285void hpfs_delete_inode(struct inode *inode)
286{ 286{
287 truncate_inode_pages(&inode->i_data, 0);
287 lock_kernel(); 288 lock_kernel();
288 hpfs_remove_fnode(inode->i_sb, inode->i_ino); 289 hpfs_remove_fnode(inode->i_sb, inode->i_ino);
289 unlock_kernel(); 290 unlock_kernel();
diff --git a/fs/inode.c b/fs/inode.c
index 71df1b1e8f..f80a79ff15 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1034,19 +1034,21 @@ void generic_delete_inode(struct inode *inode)
1034 inodes_stat.nr_inodes--; 1034 inodes_stat.nr_inodes--;
1035 spin_unlock(&inode_lock); 1035 spin_unlock(&inode_lock);
1036 1036
1037 if (inode->i_data.nrpages)
1038 truncate_inode_pages(&inode->i_data, 0);
1039
1040 security_inode_delete(inode); 1037 security_inode_delete(inode);
1041 1038
1042 if (op->delete_inode) { 1039 if (op->delete_inode) {
1043 void (*delete)(struct inode *) = op->delete_inode; 1040 void (*delete)(struct inode *) = op->delete_inode;
1044 if (!is_bad_inode(inode)) 1041 if (!is_bad_inode(inode))
1045 DQUOT_INIT(inode); 1042 DQUOT_INIT(inode);
1046 /* s_op->delete_inode internally recalls clear_inode() */ 1043 /* Filesystems implementing their own
1044 * s_op->delete_inode are required to call
1045 * truncate_inode_pages and clear_inode()
1046 * internally */
1047 delete(inode); 1047 delete(inode);
1048 } else 1048 } else {
1049 truncate_inode_pages(&inode->i_data, 0);
1049 clear_inode(inode); 1050 clear_inode(inode);
1051 }
1050 spin_lock(&inode_lock); 1052 spin_lock(&inode_lock);
1051 hlist_del_init(&inode->i_hash); 1053 hlist_del_init(&inode->i_hash);
1052 spin_unlock(&inode_lock); 1054 spin_unlock(&inode_lock);
diff --git a/fs/jbd/transaction.c b/fs/jbd/transaction.c
index c6ec66fd87..49bbc2be3d 100644
--- a/fs/jbd/transaction.c
+++ b/fs/jbd/transaction.c
@@ -1340,8 +1340,7 @@ int journal_stop(handle_t *handle)
1340 if (handle->h_sync) { 1340 if (handle->h_sync) {
1341 do { 1341 do {
1342 old_handle_count = transaction->t_handle_count; 1342 old_handle_count = transaction->t_handle_count;
1343 set_current_state(TASK_UNINTERRUPTIBLE); 1343 schedule_timeout_uninterruptible(1);
1344 schedule_timeout(1);
1345 } while (old_handle_count != transaction->t_handle_count); 1344 } while (old_handle_count != transaction->t_handle_count);
1346 } 1345 }
1347 1346
diff --git a/fs/jffs/inode-v23.c b/fs/jffs/inode-v23.c
index 777b90057b..3dcc6d2162 100644
--- a/fs/jffs/inode-v23.c
+++ b/fs/jffs/inode-v23.c
@@ -1744,6 +1744,7 @@ jffs_delete_inode(struct inode *inode)
1744 D3(printk("jffs_delete_inode(): inode->i_ino == %lu\n", 1744 D3(printk("jffs_delete_inode(): inode->i_ino == %lu\n",
1745 inode->i_ino)); 1745 inode->i_ino));
1746 1746
1747 truncate_inode_pages(&inode->i_data, 0);
1747 lock_kernel(); 1748 lock_kernel();
1748 inode->i_size = 0; 1749 inode->i_size = 0;
1749 inode->i_blocks = 0; 1750 inode->i_blocks = 0;
diff --git a/fs/jffs/intrep.c b/fs/jffs/intrep.c
index 456d7e6e29..27f199e94c 100644
--- a/fs/jffs/intrep.c
+++ b/fs/jffs/intrep.c
@@ -1701,12 +1701,10 @@ jffs_find_file(struct jffs_control *c, __u32 ino)
1701{ 1701{
1702 struct jffs_file *f; 1702 struct jffs_file *f;
1703 int i = ino % c->hash_len; 1703 int i = ino % c->hash_len;
1704 struct list_head *tmp;
1705 1704
1706 D3(printk("jffs_find_file(): ino: %u\n", ino)); 1705 D3(printk("jffs_find_file(): ino: %u\n", ino));
1707 1706
1708 for (tmp = c->hash[i].next; tmp != &c->hash[i]; tmp = tmp->next) { 1707 list_for_each_entry(f, &c->hash[i], hash) {
1709 f = list_entry(tmp, struct jffs_file, hash);
1710 if (ino != f->ino) 1708 if (ino != f->ino)
1711 continue; 1709 continue;
1712 D3(printk("jffs_find_file(): Found file with ino " 1710 D3(printk("jffs_find_file(): Found file with ino "
@@ -2102,13 +2100,12 @@ jffs_foreach_file(struct jffs_control *c, int (*func)(struct jffs_file *))
2102 int result = 0; 2100 int result = 0;
2103 2101
2104 for (pos = 0; pos < c->hash_len; pos++) { 2102 for (pos = 0; pos < c->hash_len; pos++) {
2105 struct list_head *p, *next; 2103 struct jffs_file *f, *next;
2106 for (p = c->hash[pos].next; p != &c->hash[pos]; p = next) { 2104
2107 /* We need a reference to the next file in the 2105 /* We must do _safe, because 'func' might remove the
2108 list because `func' might remove the current 2106 current file 'f' from the list. */
2109 file `f'. */ 2107 list_for_each_entry_safe(f, next, &c->hash[pos], hash) {
2110 next = p->next; 2108 r = func(f);
2111 r = func(list_entry(p, struct jffs_file, hash));
2112 if (r < 0) 2109 if (r < 0)
2113 return r; 2110 return r;
2114 result += r; 2111 result += r;
@@ -2613,9 +2610,8 @@ jffs_print_hash_table(struct jffs_control *c)
2613 2610
2614 printk("JFFS: Dumping the file system's hash table...\n"); 2611 printk("JFFS: Dumping the file system's hash table...\n");
2615 for (i = 0; i < c->hash_len; i++) { 2612 for (i = 0; i < c->hash_len; i++) {
2616 struct list_head *p; 2613 struct jffs_file *f;
2617 for (p = c->hash[i].next; p != &c->hash[i]; p = p->next) { 2614 list_for_each_entry(f, &c->hash[i], hash) {
2618 struct jffs_file *f=list_entry(p,struct jffs_file,hash);
2619 printk("*** c->hash[%u]: \"%s\" " 2615 printk("*** c->hash[%u]: \"%s\" "
2620 "(ino: %u, pino: %u)\n", 2616 "(ino: %u, pino: %u)\n",
2621 i, (f->name ? f->name : ""), 2617 i, (f->name ? f->name : ""),
diff --git a/fs/jfs/acl.c b/fs/jfs/acl.c
index e892dab40c..461e4934ca 100644
--- a/fs/jfs/acl.c
+++ b/fs/jfs/acl.c
@@ -23,6 +23,7 @@
23#include <linux/quotaops.h> 23#include <linux/quotaops.h>
24#include <linux/posix_acl_xattr.h> 24#include <linux/posix_acl_xattr.h>
25#include "jfs_incore.h" 25#include "jfs_incore.h"
26#include "jfs_txnmgr.h"
26#include "jfs_xattr.h" 27#include "jfs_xattr.h"
27#include "jfs_acl.h" 28#include "jfs_acl.h"
28 29
@@ -75,7 +76,8 @@ static struct posix_acl *jfs_get_acl(struct inode *inode, int type)
75 return acl; 76 return acl;
76} 77}
77 78
78static int jfs_set_acl(struct inode *inode, int type, struct posix_acl *acl) 79static int jfs_set_acl(tid_t tid, struct inode *inode, int type,
80 struct posix_acl *acl)
79{ 81{
80 char *ea_name; 82 char *ea_name;
81 struct jfs_inode_info *ji = JFS_IP(inode); 83 struct jfs_inode_info *ji = JFS_IP(inode);
@@ -110,7 +112,7 @@ static int jfs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
110 if (rc < 0) 112 if (rc < 0)
111 goto out; 113 goto out;
112 } 114 }
113 rc = __jfs_setxattr(inode, ea_name, value, size, 0); 115 rc = __jfs_setxattr(tid, inode, ea_name, value, size, 0);
114out: 116out:
115 kfree(value); 117 kfree(value);
116 118
@@ -143,7 +145,7 @@ int jfs_permission(struct inode *inode, int mask, struct nameidata *nd)
143 return generic_permission(inode, mask, jfs_check_acl); 145 return generic_permission(inode, mask, jfs_check_acl);
144} 146}
145 147
146int jfs_init_acl(struct inode *inode, struct inode *dir) 148int jfs_init_acl(tid_t tid, struct inode *inode, struct inode *dir)
147{ 149{
148 struct posix_acl *acl = NULL; 150 struct posix_acl *acl = NULL;
149 struct posix_acl *clone; 151 struct posix_acl *clone;
@@ -159,7 +161,7 @@ int jfs_init_acl(struct inode *inode, struct inode *dir)
159 161
160 if (acl) { 162 if (acl) {
161 if (S_ISDIR(inode->i_mode)) { 163 if (S_ISDIR(inode->i_mode)) {
162 rc = jfs_set_acl(inode, ACL_TYPE_DEFAULT, acl); 164 rc = jfs_set_acl(tid, inode, ACL_TYPE_DEFAULT, acl);
163 if (rc) 165 if (rc)
164 goto cleanup; 166 goto cleanup;
165 } 167 }
@@ -173,7 +175,8 @@ int jfs_init_acl(struct inode *inode, struct inode *dir)
173 if (rc >= 0) { 175 if (rc >= 0) {
174 inode->i_mode = mode; 176 inode->i_mode = mode;
175 if (rc > 0) 177 if (rc > 0)
176 rc = jfs_set_acl(inode, ACL_TYPE_ACCESS, clone); 178 rc = jfs_set_acl(tid, inode, ACL_TYPE_ACCESS,
179 clone);
177 } 180 }
178 posix_acl_release(clone); 181 posix_acl_release(clone);
179cleanup: 182cleanup:
@@ -202,8 +205,15 @@ static int jfs_acl_chmod(struct inode *inode)
202 return -ENOMEM; 205 return -ENOMEM;
203 206
204 rc = posix_acl_chmod_masq(clone, inode->i_mode); 207 rc = posix_acl_chmod_masq(clone, inode->i_mode);
205 if (!rc) 208 if (!rc) {
206 rc = jfs_set_acl(inode, ACL_TYPE_ACCESS, clone); 209 tid_t tid = txBegin(inode->i_sb, 0);
210 down(&JFS_IP(inode)->commit_sem);
211 rc = jfs_set_acl(tid, inode, ACL_TYPE_ACCESS, clone);
212 if (!rc)
213 rc = txCommit(tid, 1, &inode, 0);
214 txEnd(tid);
215 up(&JFS_IP(inode)->commit_sem);
216 }
207 217
208 posix_acl_release(clone); 218 posix_acl_release(clone);
209 return rc; 219 return rc;
diff --git a/fs/jfs/inode.c b/fs/jfs/inode.c
index 767c7ecb42..0ec62d5310 100644
--- a/fs/jfs/inode.c
+++ b/fs/jfs/inode.c
@@ -128,21 +128,23 @@ void jfs_delete_inode(struct inode *inode)
128{ 128{
129 jfs_info("In jfs_delete_inode, inode = 0x%p", inode); 129 jfs_info("In jfs_delete_inode, inode = 0x%p", inode);
130 130
131 if (is_bad_inode(inode) || 131 if (!is_bad_inode(inode) &&
132 (JFS_IP(inode)->fileset != cpu_to_le32(FILESYSTEM_I))) 132 (JFS_IP(inode)->fileset == cpu_to_le32(FILESYSTEM_I))) {
133 return;
134 133
135 if (test_cflag(COMMIT_Freewmap, inode)) 134 truncate_inode_pages(&inode->i_data, 0);
136 jfs_free_zero_link(inode);
137 135
138 diFree(inode); 136 if (test_cflag(COMMIT_Freewmap, inode))
137 jfs_free_zero_link(inode);
139 138
140 /* 139 diFree(inode);
141 * Free the inode from the quota allocation. 140
142 */ 141 /*
143 DQUOT_INIT(inode); 142 * Free the inode from the quota allocation.
144 DQUOT_FREE_INODE(inode); 143 */
145 DQUOT_DROP(inode); 144 DQUOT_INIT(inode);
145 DQUOT_FREE_INODE(inode);
146 DQUOT_DROP(inode);
147 }
146 148
147 clear_inode(inode); 149 clear_inode(inode);
148} 150}
diff --git a/fs/jfs/jfs_acl.h b/fs/jfs/jfs_acl.h
index a3acd3eec0..a76293767c 100644
--- a/fs/jfs/jfs_acl.h
+++ b/fs/jfs/jfs_acl.h
@@ -21,8 +21,16 @@
21#ifdef CONFIG_JFS_POSIX_ACL 21#ifdef CONFIG_JFS_POSIX_ACL
22 22
23int jfs_permission(struct inode *, int, struct nameidata *); 23int jfs_permission(struct inode *, int, struct nameidata *);
24int jfs_init_acl(struct inode *, struct inode *); 24int jfs_init_acl(tid_t, struct inode *, struct inode *);
25int jfs_setattr(struct dentry *, struct iattr *); 25int jfs_setattr(struct dentry *, struct iattr *);
26 26
27#endif /* CONFIG_JFS_POSIX_ACL */ 27#else
28
29static inline int jfs_init_acl(tid_t tid, struct inode *inode,
30 struct inode *dir)
31{
32 return 0;
33}
34
35#endif
28#endif /* _H_JFS_ACL */ 36#endif /* _H_JFS_ACL */
diff --git a/fs/jfs/jfs_xattr.h b/fs/jfs/jfs_xattr.h
index a1052f3f0b..25e9990bcc 100644
--- a/fs/jfs/jfs_xattr.h
+++ b/fs/jfs/jfs_xattr.h
@@ -52,8 +52,8 @@ struct jfs_ea_list {
52#define END_EALIST(ealist) \ 52#define END_EALIST(ealist) \
53 ((struct jfs_ea *) (((char *) (ealist)) + EALIST_SIZE(ealist))) 53 ((struct jfs_ea *) (((char *) (ealist)) + EALIST_SIZE(ealist)))
54 54
55extern int __jfs_setxattr(struct inode *, const char *, const void *, size_t, 55extern int __jfs_setxattr(tid_t, struct inode *, const char *, const void *,
56 int); 56 size_t, int);
57extern int jfs_setxattr(struct dentry *, const char *, const void *, size_t, 57extern int jfs_setxattr(struct dentry *, const char *, const void *, size_t,
58 int); 58 int);
59extern ssize_t __jfs_getxattr(struct inode *, const char *, void *, size_t); 59extern ssize_t __jfs_getxattr(struct inode *, const char *, void *, size_t);
@@ -61,4 +61,14 @@ extern ssize_t jfs_getxattr(struct dentry *, const char *, void *, size_t);
61extern ssize_t jfs_listxattr(struct dentry *, char *, size_t); 61extern ssize_t jfs_listxattr(struct dentry *, char *, size_t);
62extern int jfs_removexattr(struct dentry *, const char *); 62extern int jfs_removexattr(struct dentry *, const char *);
63 63
64#ifdef CONFIG_JFS_SECURITY
65extern int jfs_init_security(tid_t, struct inode *, struct inode *);
66#else
67static inline int jfs_init_security(tid_t tid, struct inode *inode,
68 struct inode *dir)
69{
70 return 0;
71}
72#endif
73
64#endif /* H_JFS_XATTR */ 74#endif /* H_JFS_XATTR */
diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c
index 49ccde3937..1abe7343f9 100644
--- a/fs/jfs/namei.c
+++ b/fs/jfs/namei.c
@@ -39,6 +39,24 @@ struct dentry_operations jfs_ci_dentry_operations;
39static s64 commitZeroLink(tid_t, struct inode *); 39static s64 commitZeroLink(tid_t, struct inode *);
40 40
41/* 41/*
42 * NAME: free_ea_wmap(inode)
43 *
44 * FUNCTION: free uncommitted extended attributes from working map
45 *
46 */
47static inline void free_ea_wmap(struct inode *inode)
48{
49 dxd_t *ea = &JFS_IP(inode)->ea;
50
51 if (ea->flag & DXD_EXTENT) {
52 /* free EA pages from cache */
53 invalidate_dxd_metapages(inode, *ea);
54 dbFree(inode, addressDXD(ea), lengthDXD(ea));
55 }
56 ea->flag = 0;
57}
58
59/*
42 * NAME: jfs_create(dip, dentry, mode) 60 * NAME: jfs_create(dip, dentry, mode)
43 * 61 *
44 * FUNCTION: create a regular file in the parent directory <dip> 62 * FUNCTION: create a regular file in the parent directory <dip>
@@ -89,8 +107,19 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode,
89 down(&JFS_IP(dip)->commit_sem); 107 down(&JFS_IP(dip)->commit_sem);
90 down(&JFS_IP(ip)->commit_sem); 108 down(&JFS_IP(ip)->commit_sem);
91 109
110 rc = jfs_init_acl(tid, ip, dip);
111 if (rc)
112 goto out3;
113
114 rc = jfs_init_security(tid, ip, dip);
115 if (rc) {
116 txAbort(tid, 0);
117 goto out3;
118 }
119
92 if ((rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))) { 120 if ((rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))) {
93 jfs_err("jfs_create: dtSearch returned %d", rc); 121 jfs_err("jfs_create: dtSearch returned %d", rc);
122 txAbort(tid, 0);
94 goto out3; 123 goto out3;
95 } 124 }
96 125
@@ -139,6 +168,7 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode,
139 up(&JFS_IP(dip)->commit_sem); 168 up(&JFS_IP(dip)->commit_sem);
140 up(&JFS_IP(ip)->commit_sem); 169 up(&JFS_IP(ip)->commit_sem);
141 if (rc) { 170 if (rc) {
171 free_ea_wmap(ip);
142 ip->i_nlink = 0; 172 ip->i_nlink = 0;
143 iput(ip); 173 iput(ip);
144 } else 174 } else
@@ -147,11 +177,6 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode,
147 out2: 177 out2:
148 free_UCSname(&dname); 178 free_UCSname(&dname);
149 179
150#ifdef CONFIG_JFS_POSIX_ACL
151 if (rc == 0)
152 jfs_init_acl(ip, dip);
153#endif
154
155 out1: 180 out1:
156 181
157 jfs_info("jfs_create: rc:%d", rc); 182 jfs_info("jfs_create: rc:%d", rc);
@@ -216,8 +241,19 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
216 down(&JFS_IP(dip)->commit_sem); 241 down(&JFS_IP(dip)->commit_sem);
217 down(&JFS_IP(ip)->commit_sem); 242 down(&JFS_IP(ip)->commit_sem);
218 243
244 rc = jfs_init_acl(tid, ip, dip);
245 if (rc)
246 goto out3;
247
248 rc = jfs_init_security(tid, ip, dip);
249 if (rc) {
250 txAbort(tid, 0);
251 goto out3;
252 }
253
219 if ((rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))) { 254 if ((rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))) {
220 jfs_err("jfs_mkdir: dtSearch returned %d", rc); 255 jfs_err("jfs_mkdir: dtSearch returned %d", rc);
256 txAbort(tid, 0);
221 goto out3; 257 goto out3;
222 } 258 }
223 259
@@ -267,6 +303,7 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
267 up(&JFS_IP(dip)->commit_sem); 303 up(&JFS_IP(dip)->commit_sem);
268 up(&JFS_IP(ip)->commit_sem); 304 up(&JFS_IP(ip)->commit_sem);
269 if (rc) { 305 if (rc) {
306 free_ea_wmap(ip);
270 ip->i_nlink = 0; 307 ip->i_nlink = 0;
271 iput(ip); 308 iput(ip);
272 } else 309 } else
@@ -275,10 +312,6 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
275 out2: 312 out2:
276 free_UCSname(&dname); 313 free_UCSname(&dname);
277 314
278#ifdef CONFIG_JFS_POSIX_ACL
279 if (rc == 0)
280 jfs_init_acl(ip, dip);
281#endif
282 315
283 out1: 316 out1:
284 317
@@ -885,6 +918,10 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
885 down(&JFS_IP(dip)->commit_sem); 918 down(&JFS_IP(dip)->commit_sem);
886 down(&JFS_IP(ip)->commit_sem); 919 down(&JFS_IP(ip)->commit_sem);
887 920
921 rc = jfs_init_security(tid, ip, dip);
922 if (rc)
923 goto out3;
924
888 tblk = tid_to_tblock(tid); 925 tblk = tid_to_tblock(tid);
889 tblk->xflag |= COMMIT_CREATE; 926 tblk->xflag |= COMMIT_CREATE;
890 tblk->ino = ip->i_ino; 927 tblk->ino = ip->i_ino;
@@ -1000,6 +1037,7 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
1000 up(&JFS_IP(dip)->commit_sem); 1037 up(&JFS_IP(dip)->commit_sem);
1001 up(&JFS_IP(ip)->commit_sem); 1038 up(&JFS_IP(ip)->commit_sem);
1002 if (rc) { 1039 if (rc) {
1040 free_ea_wmap(ip);
1003 ip->i_nlink = 0; 1041 ip->i_nlink = 0;
1004 iput(ip); 1042 iput(ip);
1005 } else 1043 } else
@@ -1008,11 +1046,6 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
1008 out2: 1046 out2:
1009 free_UCSname(&dname); 1047 free_UCSname(&dname);
1010 1048
1011#ifdef CONFIG_JFS_POSIX_ACL
1012 if (rc == 0)
1013 jfs_init_acl(ip, dip);
1014#endif
1015
1016 out1: 1049 out1:
1017 jfs_info("jfs_symlink: rc:%d", rc); 1050 jfs_info("jfs_symlink: rc:%d", rc);
1018 return rc; 1051 return rc;
@@ -1328,8 +1361,20 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
1328 down(&JFS_IP(dir)->commit_sem); 1361 down(&JFS_IP(dir)->commit_sem);
1329 down(&JFS_IP(ip)->commit_sem); 1362 down(&JFS_IP(ip)->commit_sem);
1330 1363
1331 if ((rc = dtSearch(dir, &dname, &ino, &btstack, JFS_CREATE))) 1364 rc = jfs_init_acl(tid, ip, dir);
1365 if (rc)
1366 goto out3;
1367
1368 rc = jfs_init_security(tid, ip, dir);
1369 if (rc) {
1370 txAbort(tid, 0);
1332 goto out3; 1371 goto out3;
1372 }
1373
1374 if ((rc = dtSearch(dir, &dname, &ino, &btstack, JFS_CREATE))) {
1375 txAbort(tid, 0);
1376 goto out3;
1377 }
1333 1378
1334 tblk = tid_to_tblock(tid); 1379 tblk = tid_to_tblock(tid);
1335 tblk->xflag |= COMMIT_CREATE; 1380 tblk->xflag |= COMMIT_CREATE;
@@ -1337,8 +1382,10 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
1337 tblk->u.ixpxd = JFS_IP(ip)->ixpxd; 1382 tblk->u.ixpxd = JFS_IP(ip)->ixpxd;
1338 1383
1339 ino = ip->i_ino; 1384 ino = ip->i_ino;
1340 if ((rc = dtInsert(tid, dir, &dname, &ino, &btstack))) 1385 if ((rc = dtInsert(tid, dir, &dname, &ino, &btstack))) {
1386 txAbort(tid, 0);
1341 goto out3; 1387 goto out3;
1388 }
1342 1389
1343 ip->i_op = &jfs_file_inode_operations; 1390 ip->i_op = &jfs_file_inode_operations;
1344 jfs_ip->dev = new_encode_dev(rdev); 1391 jfs_ip->dev = new_encode_dev(rdev);
@@ -1360,6 +1407,7 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
1360 up(&JFS_IP(ip)->commit_sem); 1407 up(&JFS_IP(ip)->commit_sem);
1361 up(&JFS_IP(dir)->commit_sem); 1408 up(&JFS_IP(dir)->commit_sem);
1362 if (rc) { 1409 if (rc) {
1410 free_ea_wmap(ip);
1363 ip->i_nlink = 0; 1411 ip->i_nlink = 0;
1364 iput(ip); 1412 iput(ip);
1365 } else 1413 } else
@@ -1368,11 +1416,6 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
1368 out1: 1416 out1:
1369 free_UCSname(&dname); 1417 free_UCSname(&dname);
1370 1418
1371#ifdef CONFIG_JFS_POSIX_ACL
1372 if (rc == 0)
1373 jfs_init_acl(ip, dir);
1374#endif
1375
1376 out: 1419 out:
1377 jfs_info("jfs_mknod: returning %d", rc); 1420 jfs_info("jfs_mknod: returning %d", rc);
1378 return rc; 1421 return rc;
diff --git a/fs/jfs/xattr.c b/fs/jfs/xattr.c
index 554ec739e4..23aa5066b5 100644
--- a/fs/jfs/xattr.c
+++ b/fs/jfs/xattr.c
@@ -21,6 +21,7 @@
21#include <linux/xattr.h> 21#include <linux/xattr.h>
22#include <linux/posix_acl_xattr.h> 22#include <linux/posix_acl_xattr.h>
23#include <linux/quotaops.h> 23#include <linux/quotaops.h>
24#include <linux/security.h>
24#include "jfs_incore.h" 25#include "jfs_incore.h"
25#include "jfs_superblock.h" 26#include "jfs_superblock.h"
26#include "jfs_dmap.h" 27#include "jfs_dmap.h"
@@ -633,12 +634,12 @@ static void ea_release(struct inode *inode, struct ea_buffer *ea_buf)
633 } 634 }
634} 635}
635 636
636static int ea_put(struct inode *inode, struct ea_buffer *ea_buf, int new_size) 637static int ea_put(tid_t tid, struct inode *inode, struct ea_buffer *ea_buf,
638 int new_size)
637{ 639{
638 struct jfs_inode_info *ji = JFS_IP(inode); 640 struct jfs_inode_info *ji = JFS_IP(inode);
639 unsigned long old_blocks, new_blocks; 641 unsigned long old_blocks, new_blocks;
640 int rc = 0; 642 int rc = 0;
641 tid_t tid;
642 643
643 if (new_size == 0) { 644 if (new_size == 0) {
644 ea_release(inode, ea_buf); 645 ea_release(inode, ea_buf);
@@ -664,9 +665,6 @@ static int ea_put(struct inode *inode, struct ea_buffer *ea_buf, int new_size)
664 if (rc) 665 if (rc)
665 return rc; 666 return rc;
666 667
667 tid = txBegin(inode->i_sb, 0);
668 down(&ji->commit_sem);
669
670 old_blocks = new_blocks = 0; 668 old_blocks = new_blocks = 0;
671 669
672 if (ji->ea.flag & DXD_EXTENT) { 670 if (ji->ea.flag & DXD_EXTENT) {
@@ -695,11 +693,8 @@ static int ea_put(struct inode *inode, struct ea_buffer *ea_buf, int new_size)
695 DQUOT_FREE_BLOCK(inode, old_blocks); 693 DQUOT_FREE_BLOCK(inode, old_blocks);
696 694
697 inode->i_ctime = CURRENT_TIME; 695 inode->i_ctime = CURRENT_TIME;
698 rc = txCommit(tid, 1, &inode, 0);
699 txEnd(tid);
700 up(&ji->commit_sem);
701 696
702 return rc; 697 return 0;
703} 698}
704 699
705/* 700/*
@@ -810,8 +805,8 @@ static int can_set_xattr(struct inode *inode, const char *name,
810 return permission(inode, MAY_WRITE, NULL); 805 return permission(inode, MAY_WRITE, NULL);
811} 806}
812 807
813int __jfs_setxattr(struct inode *inode, const char *name, const void *value, 808int __jfs_setxattr(tid_t tid, struct inode *inode, const char *name,
814 size_t value_len, int flags) 809 const void *value, size_t value_len, int flags)
815{ 810{
816 struct jfs_ea_list *ealist; 811 struct jfs_ea_list *ealist;
817 struct jfs_ea *ea, *old_ea = NULL, *next_ea = NULL; 812 struct jfs_ea *ea, *old_ea = NULL, *next_ea = NULL;
@@ -825,9 +820,6 @@ int __jfs_setxattr(struct inode *inode, const char *name, const void *value,
825 int rc; 820 int rc;
826 int length; 821 int length;
827 822
828 if ((rc = can_set_xattr(inode, name, value, value_len)))
829 return rc;
830
831 if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) { 823 if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
832 os2name = kmalloc(namelen - XATTR_OS2_PREFIX_LEN + 1, 824 os2name = kmalloc(namelen - XATTR_OS2_PREFIX_LEN + 1,
833 GFP_KERNEL); 825 GFP_KERNEL);
@@ -939,7 +931,7 @@ int __jfs_setxattr(struct inode *inode, const char *name, const void *value,
939 931
940 ealist->size = cpu_to_le32(new_size); 932 ealist->size = cpu_to_le32(new_size);
941 933
942 rc = ea_put(inode, &ea_buf, new_size); 934 rc = ea_put(tid, inode, &ea_buf, new_size);
943 935
944 goto out; 936 goto out;
945 release: 937 release:
@@ -955,12 +947,29 @@ int __jfs_setxattr(struct inode *inode, const char *name, const void *value,
955int jfs_setxattr(struct dentry *dentry, const char *name, const void *value, 947int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
956 size_t value_len, int flags) 948 size_t value_len, int flags)
957{ 949{
950 struct inode *inode = dentry->d_inode;
951 struct jfs_inode_info *ji = JFS_IP(inode);
952 int rc;
953 tid_t tid;
954
955 if ((rc = can_set_xattr(inode, name, value, value_len)))
956 return rc;
957
958 if (value == NULL) { /* empty EA, do not remove */ 958 if (value == NULL) { /* empty EA, do not remove */
959 value = ""; 959 value = "";
960 value_len = 0; 960 value_len = 0;
961 } 961 }
962 962
963 return __jfs_setxattr(dentry->d_inode, name, value, value_len, flags); 963 tid = txBegin(inode->i_sb, 0);
964 down(&ji->commit_sem);
965 rc = __jfs_setxattr(tid, dentry->d_inode, name, value, value_len,
966 flags);
967 if (!rc)
968 rc = txCommit(tid, 1, &inode, 0);
969 txEnd(tid);
970 up(&ji->commit_sem);
971
972 return rc;
964} 973}
965 974
966static int can_get_xattr(struct inode *inode, const char *name) 975static int can_get_xattr(struct inode *inode, const char *name)
@@ -1122,5 +1131,56 @@ ssize_t jfs_listxattr(struct dentry * dentry, char *data, size_t buf_size)
1122 1131
1123int jfs_removexattr(struct dentry *dentry, const char *name) 1132int jfs_removexattr(struct dentry *dentry, const char *name)
1124{ 1133{
1125 return __jfs_setxattr(dentry->d_inode, name, NULL, 0, XATTR_REPLACE); 1134 struct inode *inode = dentry->d_inode;
1135 struct jfs_inode_info *ji = JFS_IP(inode);
1136 int rc;
1137 tid_t tid;
1138
1139 if ((rc = can_set_xattr(inode, name, NULL, 0)))
1140 return rc;
1141
1142 tid = txBegin(inode->i_sb, 0);
1143 down(&ji->commit_sem);
1144 rc = __jfs_setxattr(tid, dentry->d_inode, name, NULL, 0, XATTR_REPLACE);
1145 if (!rc)
1146 rc = txCommit(tid, 1, &inode, 0);
1147 txEnd(tid);
1148 up(&ji->commit_sem);
1149
1150 return rc;
1151}
1152
1153#ifdef CONFIG_JFS_SECURITY
1154int jfs_init_security(tid_t tid, struct inode *inode, struct inode *dir)
1155{
1156 int rc;
1157 size_t len;
1158 void *value;
1159 char *suffix;
1160 char *name;
1161
1162 rc = security_inode_init_security(inode, dir, &suffix, &value, &len);
1163 if (rc) {
1164 if (rc == -EOPNOTSUPP)
1165 return 0;
1166 return rc;
1167 }
1168 name = kmalloc(XATTR_SECURITY_PREFIX_LEN + 1 + strlen(suffix),
1169 GFP_NOFS);
1170 if (!name) {
1171 rc = -ENOMEM;
1172 goto kmalloc_failed;
1173 }
1174 strcpy(name, XATTR_SECURITY_PREFIX);
1175 strcpy(name + XATTR_SECURITY_PREFIX_LEN, suffix);
1176
1177 rc = __jfs_setxattr(tid, inode, name, value, len, 0);
1178
1179 kfree(name);
1180kmalloc_failed:
1181 kfree(suffix);
1182 kfree(value);
1183
1184 return rc;
1126} 1185}
1186#endif
diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
index 14b3ce87fa..87332f3014 100644
--- a/fs/lockd/clntproc.c
+++ b/fs/lockd/clntproc.c
@@ -299,8 +299,7 @@ nlmclnt_alloc_call(void)
299 return call; 299 return call;
300 } 300 }
301 printk("nlmclnt_alloc_call: failed, waiting for memory\n"); 301 printk("nlmclnt_alloc_call: failed, waiting for memory\n");
302 current->state = TASK_INTERRUPTIBLE; 302 schedule_timeout_interruptible(5*HZ);
303 schedule_timeout(5*HZ);
304 } 303 }
305 return NULL; 304 return NULL;
306} 305}
diff --git a/fs/locks.c b/fs/locks.c
index 11956b6179..c2c09b4798 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -2198,21 +2198,23 @@ void steal_locks(fl_owner_t from)
2198{ 2198{
2199 struct files_struct *files = current->files; 2199 struct files_struct *files = current->files;
2200 int i, j; 2200 int i, j;
2201 struct fdtable *fdt;
2201 2202
2202 if (from == files) 2203 if (from == files)
2203 return; 2204 return;
2204 2205
2205 lock_kernel(); 2206 lock_kernel();
2206 j = 0; 2207 j = 0;
2208 fdt = files_fdtable(files);
2207 for (;;) { 2209 for (;;) {
2208 unsigned long set; 2210 unsigned long set;
2209 i = j * __NFDBITS; 2211 i = j * __NFDBITS;
2210 if (i >= files->max_fdset || i >= files->max_fds) 2212 if (i >= fdt->max_fdset || i >= fdt->max_fds)
2211 break; 2213 break;
2212 set = files->open_fds->fds_bits[j++]; 2214 set = fdt->open_fds->fds_bits[j++];
2213 while (set) { 2215 while (set) {
2214 if (set & 1) { 2216 if (set & 1) {
2215 struct file *file = files->fd[i]; 2217 struct file *file = fdt->fd[i];
2216 if (file) 2218 if (file)
2217 __steal_locks(file, from); 2219 __steal_locks(file, from);
2218 } 2220 }
diff --git a/fs/minix/inode.c b/fs/minix/inode.c
index 3f18c21198..790cc0d0e9 100644
--- a/fs/minix/inode.c
+++ b/fs/minix/inode.c
@@ -24,6 +24,7 @@ static int minix_remount (struct super_block * sb, int * flags, char * data);
24 24
25static void minix_delete_inode(struct inode *inode) 25static void minix_delete_inode(struct inode *inode)
26{ 26{
27 truncate_inode_pages(&inode->i_data, 0);
27 inode->i_size = 0; 28 inode->i_size = 0;
28 minix_truncate(inode); 29 minix_truncate(inode);
29 minix_free_inode(inode); 30 minix_free_inode(inode);
diff --git a/fs/namei.c b/fs/namei.c
index 145e852c4b..21d85f1ac8 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1316,10 +1316,8 @@ int vfs_create(struct inode *dir, struct dentry *dentry, int mode,
1316 return error; 1316 return error;
1317 DQUOT_INIT(dir); 1317 DQUOT_INIT(dir);
1318 error = dir->i_op->create(dir, dentry, mode, nd); 1318 error = dir->i_op->create(dir, dentry, mode, nd);
1319 if (!error) { 1319 if (!error)
1320 fsnotify_create(dir, dentry->d_name.name); 1320 fsnotify_create(dir, dentry->d_name.name);
1321 security_inode_post_create(dir, dentry, mode);
1322 }
1323 return error; 1321 return error;
1324} 1322}
1325 1323
@@ -1635,10 +1633,8 @@ int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
1635 1633
1636 DQUOT_INIT(dir); 1634 DQUOT_INIT(dir);
1637 error = dir->i_op->mknod(dir, dentry, mode, dev); 1635 error = dir->i_op->mknod(dir, dentry, mode, dev);
1638 if (!error) { 1636 if (!error)
1639 fsnotify_create(dir, dentry->d_name.name); 1637 fsnotify_create(dir, dentry->d_name.name);
1640 security_inode_post_mknod(dir, dentry, mode, dev);
1641 }
1642 return error; 1638 return error;
1643} 1639}
1644 1640
@@ -1708,10 +1704,8 @@ int vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1708 1704
1709 DQUOT_INIT(dir); 1705 DQUOT_INIT(dir);
1710 error = dir->i_op->mkdir(dir, dentry, mode); 1706 error = dir->i_op->mkdir(dir, dentry, mode);
1711 if (!error) { 1707 if (!error)
1712 fsnotify_mkdir(dir, dentry->d_name.name); 1708 fsnotify_mkdir(dir, dentry->d_name.name);
1713 security_inode_post_mkdir(dir,dentry, mode);
1714 }
1715 return error; 1709 return error;
1716} 1710}
1717 1711
@@ -1947,10 +1941,8 @@ int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname, i
1947 1941
1948 DQUOT_INIT(dir); 1942 DQUOT_INIT(dir);
1949 error = dir->i_op->symlink(dir, dentry, oldname); 1943 error = dir->i_op->symlink(dir, dentry, oldname);
1950 if (!error) { 1944 if (!error)
1951 fsnotify_create(dir, dentry->d_name.name); 1945 fsnotify_create(dir, dentry->d_name.name);
1952 security_inode_post_symlink(dir, dentry, oldname);
1953 }
1954 return error; 1946 return error;
1955} 1947}
1956 1948
@@ -2020,10 +2012,8 @@ int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_de
2020 DQUOT_INIT(dir); 2012 DQUOT_INIT(dir);
2021 error = dir->i_op->link(old_dentry, dir, new_dentry); 2013 error = dir->i_op->link(old_dentry, dir, new_dentry);
2022 up(&old_dentry->d_inode->i_sem); 2014 up(&old_dentry->d_inode->i_sem);
2023 if (!error) { 2015 if (!error)
2024 fsnotify_create(dir, new_dentry->d_name.name); 2016 fsnotify_create(dir, new_dentry->d_name.name);
2025 security_inode_post_link(old_dentry, dir, new_dentry);
2026 }
2027 return error; 2017 return error;
2028} 2018}
2029 2019
@@ -2142,11 +2132,8 @@ static int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
2142 d_rehash(new_dentry); 2132 d_rehash(new_dentry);
2143 dput(new_dentry); 2133 dput(new_dentry);
2144 } 2134 }
2145 if (!error) { 2135 if (!error)
2146 d_move(old_dentry,new_dentry); 2136 d_move(old_dentry,new_dentry);
2147 security_inode_post_rename(old_dir, old_dentry,
2148 new_dir, new_dentry);
2149 }
2150 return error; 2137 return error;
2151} 2138}
2152 2139
@@ -2172,7 +2159,6 @@ static int vfs_rename_other(struct inode *old_dir, struct dentry *old_dentry,
2172 /* The following d_move() should become unconditional */ 2159 /* The following d_move() should become unconditional */
2173 if (!(old_dir->i_sb->s_type->fs_flags & FS_ODD_RENAME)) 2160 if (!(old_dir->i_sb->s_type->fs_flags & FS_ODD_RENAME))
2174 d_move(old_dentry, new_dentry); 2161 d_move(old_dentry, new_dentry);
2175 security_inode_post_rename(old_dir, old_dentry, new_dir, new_dentry);
2176 } 2162 }
2177 if (target) 2163 if (target)
2178 up(&target->i_sem); 2164 up(&target->i_sem);
diff --git a/fs/namespace.c b/fs/namespace.c
index 34156260c9..2fa9fdf7d6 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -537,7 +537,6 @@ lives_below_in_same_fs(struct dentry *d, struct dentry *dentry)
537static struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry) 537static struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry)
538{ 538{
539 struct vfsmount *res, *p, *q, *r, *s; 539 struct vfsmount *res, *p, *q, *r, *s;
540 struct list_head *h;
541 struct nameidata nd; 540 struct nameidata nd;
542 541
543 res = q = clone_mnt(mnt, dentry); 542 res = q = clone_mnt(mnt, dentry);
@@ -546,8 +545,7 @@ static struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry)
546 q->mnt_mountpoint = mnt->mnt_mountpoint; 545 q->mnt_mountpoint = mnt->mnt_mountpoint;
547 546
548 p = mnt; 547 p = mnt;
549 for (h = mnt->mnt_mounts.next; h != &mnt->mnt_mounts; h = h->next) { 548 list_for_each_entry(r, &mnt->mnt_mounts, mnt_child) {
550 r = list_entry(h, struct vfsmount, mnt_child);
551 if (!lives_below_in_same_fs(r->mnt_mountpoint, dentry)) 549 if (!lives_below_in_same_fs(r->mnt_mountpoint, dentry))
552 continue; 550 continue;
553 551
diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c
index 44795d2f4b..8c8839203c 100644
--- a/fs/ncpfs/inode.c
+++ b/fs/ncpfs/inode.c
@@ -286,6 +286,8 @@ ncp_iget(struct super_block *sb, struct ncp_entry_info *info)
286static void 286static void
287ncp_delete_inode(struct inode *inode) 287ncp_delete_inode(struct inode *inode)
288{ 288{
289 truncate_inode_pages(&inode->i_data, 0);
290
289 if (S_ISDIR(inode->i_mode)) { 291 if (S_ISDIR(inode->i_mode)) {
290 DDPRINTK("ncp_delete_inode: put directory %ld\n", inode->i_ino); 292 DDPRINTK("ncp_delete_inode: put directory %ld\n", inode->i_ino);
291 } 293 }
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 541b418327..6922469d6f 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -146,6 +146,8 @@ nfs_delete_inode(struct inode * inode)
146{ 146{
147 dprintk("NFS: delete_inode(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino); 147 dprintk("NFS: delete_inode(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino);
148 148
149 truncate_inode_pages(&inode->i_data, 0);
150
149 nfs_wb_all(inode); 151 nfs_wb_all(inode);
150 /* 152 /*
151 * The following should never happen... 153 * The following should never happen...
diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c
index 2681485cf2..edc9551404 100644
--- a/fs/nfs/nfs3proc.c
+++ b/fs/nfs/nfs3proc.c
@@ -34,8 +34,7 @@ nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
34 res = rpc_call_sync(clnt, msg, flags); 34 res = rpc_call_sync(clnt, msg, flags);
35 if (res != -EJUKEBOX) 35 if (res != -EJUKEBOX)
36 break; 36 break;
37 set_current_state(TASK_INTERRUPTIBLE); 37 schedule_timeout_interruptible(NFS_JUKEBOX_RETRY_TIME);
38 schedule_timeout(NFS_JUKEBOX_RETRY_TIME);
39 res = -ERESTARTSYS; 38 res = -ERESTARTSYS;
40 } while (!signalled()); 39 } while (!signalled());
41 rpc_clnt_sigunmask(clnt, &oldset); 40 rpc_clnt_sigunmask(clnt, &oldset);
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 0c5a308e49..9701ca8c94 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -2418,14 +2418,11 @@ static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
2418 *timeout = NFS4_POLL_RETRY_MAX; 2418 *timeout = NFS4_POLL_RETRY_MAX;
2419 rpc_clnt_sigmask(clnt, &oldset); 2419 rpc_clnt_sigmask(clnt, &oldset);
2420 if (clnt->cl_intr) { 2420 if (clnt->cl_intr) {
2421 set_current_state(TASK_INTERRUPTIBLE); 2421 schedule_timeout_interruptible(*timeout);
2422 schedule_timeout(*timeout);
2423 if (signalled()) 2422 if (signalled())
2424 res = -ERESTARTSYS; 2423 res = -ERESTARTSYS;
2425 } else { 2424 } else
2426 set_current_state(TASK_UNINTERRUPTIBLE); 2425 schedule_timeout_uninterruptible(*timeout);
2427 schedule_timeout(*timeout);
2428 }
2429 rpc_clnt_sigunmask(clnt, &oldset); 2426 rpc_clnt_sigunmask(clnt, &oldset);
2430 *timeout <<= 1; 2427 *timeout <<= 1;
2431 return res; 2428 return res;
@@ -2578,8 +2575,7 @@ int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4
2578static unsigned long 2575static unsigned long
2579nfs4_set_lock_task_retry(unsigned long timeout) 2576nfs4_set_lock_task_retry(unsigned long timeout)
2580{ 2577{
2581 current->state = TASK_INTERRUPTIBLE; 2578 schedule_timeout_interruptible(timeout);
2582 schedule_timeout(timeout);
2583 timeout <<= 1; 2579 timeout <<= 1;
2584 if (timeout > NFS4_LOCK_MAXTIMEOUT) 2580 if (timeout > NFS4_LOCK_MAXTIMEOUT)
2585 return NFS4_LOCK_MAXTIMEOUT; 2581 return NFS4_LOCK_MAXTIMEOUT;
diff --git a/fs/ntfs/aops.c b/fs/ntfs/aops.c
index 545236414d..b6cc8cf246 100644
--- a/fs/ntfs/aops.c
+++ b/fs/ntfs/aops.c
@@ -27,6 +27,7 @@
27#include <linux/swap.h> 27#include <linux/swap.h>
28#include <linux/buffer_head.h> 28#include <linux/buffer_head.h>
29#include <linux/writeback.h> 29#include <linux/writeback.h>
30#include <linux/bit_spinlock.h>
30 31
31#include "aops.h" 32#include "aops.h"
32#include "attrib.h" 33#include "attrib.h"
diff --git a/fs/open.c b/fs/open.c
index 4ee2dcc31c..2fac58c519 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -24,6 +24,7 @@
24#include <linux/personality.h> 24#include <linux/personality.h>
25#include <linux/pagemap.h> 25#include <linux/pagemap.h>
26#include <linux/syscalls.h> 26#include <linux/syscalls.h>
27#include <linux/rcupdate.h>
27 28
28#include <asm/unistd.h> 29#include <asm/unistd.h>
29 30
@@ -842,14 +843,16 @@ int get_unused_fd(void)
842{ 843{
843 struct files_struct * files = current->files; 844 struct files_struct * files = current->files;
844 int fd, error; 845 int fd, error;
846 struct fdtable *fdt;
845 847
846 error = -EMFILE; 848 error = -EMFILE;
847 spin_lock(&files->file_lock); 849 spin_lock(&files->file_lock);
848 850
849repeat: 851repeat:
850 fd = find_next_zero_bit(files->open_fds->fds_bits, 852 fdt = files_fdtable(files);
851 files->max_fdset, 853 fd = find_next_zero_bit(fdt->open_fds->fds_bits,
852 files->next_fd); 854 fdt->max_fdset,
855 fdt->next_fd);
853 856
854 /* 857 /*
855 * N.B. For clone tasks sharing a files structure, this test 858 * N.B. For clone tasks sharing a files structure, this test
@@ -872,14 +875,14 @@ repeat:
872 goto repeat; 875 goto repeat;
873 } 876 }
874 877
875 FD_SET(fd, files->open_fds); 878 FD_SET(fd, fdt->open_fds);
876 FD_CLR(fd, files->close_on_exec); 879 FD_CLR(fd, fdt->close_on_exec);
877 files->next_fd = fd + 1; 880 fdt->next_fd = fd + 1;
878#if 1 881#if 1
879 /* Sanity check */ 882 /* Sanity check */
880 if (files->fd[fd] != NULL) { 883 if (fdt->fd[fd] != NULL) {
881 printk(KERN_WARNING "get_unused_fd: slot %d not NULL!\n", fd); 884 printk(KERN_WARNING "get_unused_fd: slot %d not NULL!\n", fd);
882 files->fd[fd] = NULL; 885 fdt->fd[fd] = NULL;
883 } 886 }
884#endif 887#endif
885 error = fd; 888 error = fd;
@@ -893,9 +896,10 @@ EXPORT_SYMBOL(get_unused_fd);
893 896
894static inline void __put_unused_fd(struct files_struct *files, unsigned int fd) 897static inline void __put_unused_fd(struct files_struct *files, unsigned int fd)
895{ 898{
896 __FD_CLR(fd, files->open_fds); 899 struct fdtable *fdt = files_fdtable(files);
897 if (fd < files->next_fd) 900 __FD_CLR(fd, fdt->open_fds);
898 files->next_fd = fd; 901 if (fd < fdt->next_fd)
902 fdt->next_fd = fd;
899} 903}
900 904
901void fastcall put_unused_fd(unsigned int fd) 905void fastcall put_unused_fd(unsigned int fd)
@@ -924,10 +928,11 @@ EXPORT_SYMBOL(put_unused_fd);
924void fastcall fd_install(unsigned int fd, struct file * file) 928void fastcall fd_install(unsigned int fd, struct file * file)
925{ 929{
926 struct files_struct *files = current->files; 930 struct files_struct *files = current->files;
931 struct fdtable *fdt;
927 spin_lock(&files->file_lock); 932 spin_lock(&files->file_lock);
928 if (unlikely(files->fd[fd] != NULL)) 933 fdt = files_fdtable(files);
929 BUG(); 934 BUG_ON(fdt->fd[fd] != NULL);
930 files->fd[fd] = file; 935 rcu_assign_pointer(fdt->fd[fd], file);
931 spin_unlock(&files->file_lock); 936 spin_unlock(&files->file_lock);
932} 937}
933 938
@@ -1010,15 +1015,17 @@ asmlinkage long sys_close(unsigned int fd)
1010{ 1015{
1011 struct file * filp; 1016 struct file * filp;
1012 struct files_struct *files = current->files; 1017 struct files_struct *files = current->files;
1018 struct fdtable *fdt;
1013 1019
1014 spin_lock(&files->file_lock); 1020 spin_lock(&files->file_lock);
1015 if (fd >= files->max_fds) 1021 fdt = files_fdtable(files);
1022 if (fd >= fdt->max_fds)
1016 goto out_unlock; 1023 goto out_unlock;
1017 filp = files->fd[fd]; 1024 filp = fdt->fd[fd];
1018 if (!filp) 1025 if (!filp)
1019 goto out_unlock; 1026 goto out_unlock;
1020 files->fd[fd] = NULL; 1027 rcu_assign_pointer(fdt->fd[fd], NULL);
1021 FD_CLR(fd, files->close_on_exec); 1028 FD_CLR(fd, fdt->close_on_exec);
1022 __put_unused_fd(files, fd); 1029 __put_unused_fd(files, fd);
1023 spin_unlock(&files->file_lock); 1030 spin_unlock(&files->file_lock);
1024 return filp_close(filp, files); 1031 return filp_close(filp, files);
diff --git a/fs/pipe.c b/fs/pipe.c
index 2c7a23dde2..66aa0b938d 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -39,7 +39,11 @@ void pipe_wait(struct inode * inode)
39{ 39{
40 DEFINE_WAIT(wait); 40 DEFINE_WAIT(wait);
41 41
42 prepare_to_wait(PIPE_WAIT(*inode), &wait, TASK_INTERRUPTIBLE); 42 /*
43 * Pipes are system-local resources, so sleeping on them
44 * is considered a noninteractive wait:
45 */
46 prepare_to_wait(PIPE_WAIT(*inode), &wait, TASK_INTERRUPTIBLE|TASK_NONINTERACTIVE);
43 up(PIPE_SEM(*inode)); 47 up(PIPE_SEM(*inode));
44 schedule(); 48 schedule();
45 finish_wait(PIPE_WAIT(*inode), &wait); 49 finish_wait(PIPE_WAIT(*inode), &wait);
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 37668fe998..d88d518d30 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -159,6 +159,7 @@ static inline char * task_state(struct task_struct *p, char *buffer)
159{ 159{
160 struct group_info *group_info; 160 struct group_info *group_info;
161 int g; 161 int g;
162 struct fdtable *fdt = NULL;
162 163
163 read_lock(&tasklist_lock); 164 read_lock(&tasklist_lock);
164 buffer += sprintf(buffer, 165 buffer += sprintf(buffer,
@@ -179,10 +180,12 @@ static inline char * task_state(struct task_struct *p, char *buffer)
179 p->gid, p->egid, p->sgid, p->fsgid); 180 p->gid, p->egid, p->sgid, p->fsgid);
180 read_unlock(&tasklist_lock); 181 read_unlock(&tasklist_lock);
181 task_lock(p); 182 task_lock(p);
183 if (p->files)
184 fdt = files_fdtable(p->files);
182 buffer += sprintf(buffer, 185 buffer += sprintf(buffer,
183 "FDSize:\t%d\n" 186 "FDSize:\t%d\n"
184 "Groups:\t", 187 "Groups:\t",
185 p->files ? p->files->max_fds : 0); 188 fdt ? fdt->max_fds : 0);
186 189
187 group_info = p->group_info; 190 group_info = p->group_info;
188 get_group_info(group_info); 191 get_group_info(group_info);
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 84751f3f52..23db452ab4 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -62,6 +62,7 @@
62#include <linux/namespace.h> 62#include <linux/namespace.h>
63#include <linux/mm.h> 63#include <linux/mm.h>
64#include <linux/smp_lock.h> 64#include <linux/smp_lock.h>
65#include <linux/rcupdate.h>
65#include <linux/kallsyms.h> 66#include <linux/kallsyms.h>
66#include <linux/mount.h> 67#include <linux/mount.h>
67#include <linux/security.h> 68#include <linux/security.h>
@@ -283,16 +284,16 @@ static int proc_fd_link(struct inode *inode, struct dentry **dentry, struct vfsm
283 284
284 files = get_files_struct(task); 285 files = get_files_struct(task);
285 if (files) { 286 if (files) {
286 spin_lock(&files->file_lock); 287 rcu_read_lock();
287 file = fcheck_files(files, fd); 288 file = fcheck_files(files, fd);
288 if (file) { 289 if (file) {
289 *mnt = mntget(file->f_vfsmnt); 290 *mnt = mntget(file->f_vfsmnt);
290 *dentry = dget(file->f_dentry); 291 *dentry = dget(file->f_dentry);
291 spin_unlock(&files->file_lock); 292 rcu_read_unlock();
292 put_files_struct(files); 293 put_files_struct(files);
293 return 0; 294 return 0;
294 } 295 }
295 spin_unlock(&files->file_lock); 296 rcu_read_unlock();
296 put_files_struct(files); 297 put_files_struct(files);
297 } 298 }
298 return -ENOENT; 299 return -ENOENT;
@@ -1039,6 +1040,7 @@ static int proc_readfd(struct file * filp, void * dirent, filldir_t filldir)
1039 int retval; 1040 int retval;
1040 char buf[NUMBUF]; 1041 char buf[NUMBUF];
1041 struct files_struct * files; 1042 struct files_struct * files;
1043 struct fdtable *fdt;
1042 1044
1043 retval = -ENOENT; 1045 retval = -ENOENT;
1044 if (!pid_alive(p)) 1046 if (!pid_alive(p))
@@ -1061,15 +1063,16 @@ static int proc_readfd(struct file * filp, void * dirent, filldir_t filldir)
1061 files = get_files_struct(p); 1063 files = get_files_struct(p);
1062 if (!files) 1064 if (!files)
1063 goto out; 1065 goto out;
1064 spin_lock(&files->file_lock); 1066 rcu_read_lock();
1067 fdt = files_fdtable(files);
1065 for (fd = filp->f_pos-2; 1068 for (fd = filp->f_pos-2;
1066 fd < files->max_fds; 1069 fd < fdt->max_fds;
1067 fd++, filp->f_pos++) { 1070 fd++, filp->f_pos++) {
1068 unsigned int i,j; 1071 unsigned int i,j;
1069 1072
1070 if (!fcheck_files(files, fd)) 1073 if (!fcheck_files(files, fd))
1071 continue; 1074 continue;
1072 spin_unlock(&files->file_lock); 1075 rcu_read_unlock();
1073 1076
1074 j = NUMBUF; 1077 j = NUMBUF;
1075 i = fd; 1078 i = fd;
@@ -1081,12 +1084,12 @@ static int proc_readfd(struct file * filp, void * dirent, filldir_t filldir)
1081 1084
1082 ino = fake_ino(tid, PROC_TID_FD_DIR + fd); 1085 ino = fake_ino(tid, PROC_TID_FD_DIR + fd);
1083 if (filldir(dirent, buf+j, NUMBUF-j, fd+2, ino, DT_LNK) < 0) { 1086 if (filldir(dirent, buf+j, NUMBUF-j, fd+2, ino, DT_LNK) < 0) {
1084 spin_lock(&files->file_lock); 1087 rcu_read_lock();
1085 break; 1088 break;
1086 } 1089 }
1087 spin_lock(&files->file_lock); 1090 rcu_read_lock();
1088 } 1091 }
1089 spin_unlock(&files->file_lock); 1092 rcu_read_unlock();
1090 put_files_struct(files); 1093 put_files_struct(files);
1091 } 1094 }
1092out: 1095out:
@@ -1261,9 +1264,9 @@ static int tid_fd_revalidate(struct dentry *dentry, struct nameidata *nd)
1261 1264
1262 files = get_files_struct(task); 1265 files = get_files_struct(task);
1263 if (files) { 1266 if (files) {
1264 spin_lock(&files->file_lock); 1267 rcu_read_lock();
1265 if (fcheck_files(files, fd)) { 1268 if (fcheck_files(files, fd)) {
1266 spin_unlock(&files->file_lock); 1269 rcu_read_unlock();
1267 put_files_struct(files); 1270 put_files_struct(files);
1268 if (task_dumpable(task)) { 1271 if (task_dumpable(task)) {
1269 inode->i_uid = task->euid; 1272 inode->i_uid = task->euid;
@@ -1275,7 +1278,7 @@ static int tid_fd_revalidate(struct dentry *dentry, struct nameidata *nd)
1275 security_task_to_inode(task, inode); 1278 security_task_to_inode(task, inode);
1276 return 1; 1279 return 1;
1277 } 1280 }
1278 spin_unlock(&files->file_lock); 1281 rcu_read_unlock();
1279 put_files_struct(files); 1282 put_files_struct(files);
1280 } 1283 }
1281 d_drop(dentry); 1284 d_drop(dentry);
@@ -1367,7 +1370,7 @@ static struct dentry *proc_lookupfd(struct inode * dir, struct dentry * dentry,
1367 if (!files) 1370 if (!files)
1368 goto out_unlock; 1371 goto out_unlock;
1369 inode->i_mode = S_IFLNK; 1372 inode->i_mode = S_IFLNK;
1370 spin_lock(&files->file_lock); 1373 rcu_read_lock();
1371 file = fcheck_files(files, fd); 1374 file = fcheck_files(files, fd);
1372 if (!file) 1375 if (!file)
1373 goto out_unlock2; 1376 goto out_unlock2;
@@ -1375,7 +1378,7 @@ static struct dentry *proc_lookupfd(struct inode * dir, struct dentry * dentry,
1375 inode->i_mode |= S_IRUSR | S_IXUSR; 1378 inode->i_mode |= S_IRUSR | S_IXUSR;
1376 if (file->f_mode & 2) 1379 if (file->f_mode & 2)
1377 inode->i_mode |= S_IWUSR | S_IXUSR; 1380 inode->i_mode |= S_IWUSR | S_IXUSR;
1378 spin_unlock(&files->file_lock); 1381 rcu_read_unlock();
1379 put_files_struct(files); 1382 put_files_struct(files);
1380 inode->i_op = &proc_pid_link_inode_operations; 1383 inode->i_op = &proc_pid_link_inode_operations;
1381 inode->i_size = 64; 1384 inode->i_size = 64;
@@ -1385,7 +1388,7 @@ static struct dentry *proc_lookupfd(struct inode * dir, struct dentry * dentry,
1385 return NULL; 1388 return NULL;
1386 1389
1387out_unlock2: 1390out_unlock2:
1388 spin_unlock(&files->file_lock); 1391 rcu_read_unlock();
1389 put_files_struct(files); 1392 put_files_struct(files);
1390out_unlock: 1393out_unlock:
1391 iput(inode); 1394 iput(inode);
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 133c286851..effa6c0c46 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -60,6 +60,8 @@ static void proc_delete_inode(struct inode *inode)
60 struct proc_dir_entry *de; 60 struct proc_dir_entry *de;
61 struct task_struct *tsk; 61 struct task_struct *tsk;
62 62
63 truncate_inode_pages(&inode->i_data, 0);
64
63 /* Let go of any associated process */ 65 /* Let go of any associated process */
64 tsk = PROC_I(inode)->task; 66 tsk = PROC_I(inode)->task;
65 if (tsk) 67 if (tsk)
diff --git a/fs/qnx4/inode.c b/fs/qnx4/inode.c
index b79162a354..80f32911c0 100644
--- a/fs/qnx4/inode.c
+++ b/fs/qnx4/inode.c
@@ -63,6 +63,7 @@ int qnx4_sync_inode(struct inode *inode)
63static void qnx4_delete_inode(struct inode *inode) 63static void qnx4_delete_inode(struct inode *inode)
64{ 64{
65 QNX4DEBUG(("qnx4: deleting inode [%lu]\n", (unsigned long) inode->i_ino)); 65 QNX4DEBUG(("qnx4: deleting inode [%lu]\n", (unsigned long) inode->i_ino));
66 truncate_inode_pages(&inode->i_data, 0);
66 inode->i_size = 0; 67 inode->i_size = 0;
67 qnx4_truncate(inode); 68 qnx4_truncate(inode);
68 lock_kernel(); 69 lock_kernel();
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index ff291c973a..1a8a1bf215 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -33,6 +33,8 @@ void reiserfs_delete_inode(struct inode *inode)
33 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb); 33 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb);
34 struct reiserfs_transaction_handle th; 34 struct reiserfs_transaction_handle th;
35 35
36 truncate_inode_pages(&inode->i_data, 0);
37
36 reiserfs_write_lock(inode->i_sb); 38 reiserfs_write_lock(inode->i_sb);
37 39
38 /* The = 0 happens when we abort creating a new inode for some reason like lack of space.. */ 40 /* The = 0 happens when we abort creating a new inode for some reason like lack of space.. */
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index a8e29e9bbb..4b15761434 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -2868,8 +2868,7 @@ static void let_transaction_grow(struct super_block *sb, unsigned long trans_id)
2868 struct reiserfs_journal *journal = SB_JOURNAL(sb); 2868 struct reiserfs_journal *journal = SB_JOURNAL(sb);
2869 unsigned long bcount = journal->j_bcount; 2869 unsigned long bcount = journal->j_bcount;
2870 while (1) { 2870 while (1) {
2871 set_current_state(TASK_UNINTERRUPTIBLE); 2871 schedule_timeout_uninterruptible(1);
2872 schedule_timeout(1);
2873 journal->j_current_jl->j_state |= LIST_COMMIT_PENDING; 2872 journal->j_current_jl->j_state |= LIST_COMMIT_PENDING;
2874 while ((atomic_read(&journal->j_wcount) > 0 || 2873 while ((atomic_read(&journal->j_wcount) > 0 ||
2875 atomic_read(&journal->j_jlock)) && 2874 atomic_read(&journal->j_jlock)) &&
diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
index 6951c35755..44b02fc02e 100644
--- a/fs/reiserfs/super.c
+++ b/fs/reiserfs/super.c
@@ -1934,8 +1934,7 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1934 if (SB_AP_BITMAP(s)) 1934 if (SB_AP_BITMAP(s))
1935 brelse(SB_AP_BITMAP(s)[j].bh); 1935 brelse(SB_AP_BITMAP(s)[j].bh);
1936 } 1936 }
1937 if (SB_AP_BITMAP(s)) 1937 vfree(SB_AP_BITMAP(s));
1938 vfree(SB_AP_BITMAP(s));
1939 } 1938 }
1940 if (SB_BUFFER_WITH_SB(s)) 1939 if (SB_BUFFER_WITH_SB(s))
1941 brelse(SB_BUFFER_WITH_SB(s)); 1940 brelse(SB_BUFFER_WITH_SB(s));
diff --git a/fs/select.c b/fs/select.c
index b80e7eb0ac..f10a10317d 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -22,6 +22,7 @@
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/fs.h> 24#include <linux/fs.h>
25#include <linux/rcupdate.h>
25 26
26#include <asm/uaccess.h> 27#include <asm/uaccess.h>
27 28
@@ -132,11 +133,13 @@ static int max_select_fd(unsigned long n, fd_set_bits *fds)
132 unsigned long *open_fds; 133 unsigned long *open_fds;
133 unsigned long set; 134 unsigned long set;
134 int max; 135 int max;
136 struct fdtable *fdt;
135 137
136 /* handle last in-complete long-word first */ 138 /* handle last in-complete long-word first */
137 set = ~(~0UL << (n & (__NFDBITS-1))); 139 set = ~(~0UL << (n & (__NFDBITS-1)));
138 n /= __NFDBITS; 140 n /= __NFDBITS;
139 open_fds = current->files->open_fds->fds_bits+n; 141 fdt = files_fdtable(current->files);
142 open_fds = fdt->open_fds->fds_bits+n;
140 max = 0; 143 max = 0;
141 if (set) { 144 if (set) {
142 set &= BITS(fds, n); 145 set &= BITS(fds, n);
@@ -183,9 +186,9 @@ int do_select(int n, fd_set_bits *fds, long *timeout)
183 int retval, i; 186 int retval, i;
184 long __timeout = *timeout; 187 long __timeout = *timeout;
185 188
186 spin_lock(&current->files->file_lock); 189 rcu_read_lock();
187 retval = max_select_fd(n, fds); 190 retval = max_select_fd(n, fds);
188 spin_unlock(&current->files->file_lock); 191 rcu_read_unlock();
189 192
190 if (retval < 0) 193 if (retval < 0)
191 return retval; 194 return retval;
@@ -299,6 +302,7 @@ sys_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, s
299 char *bits; 302 char *bits;
300 long timeout; 303 long timeout;
301 int ret, size, max_fdset; 304 int ret, size, max_fdset;
305 struct fdtable *fdt;
302 306
303 timeout = MAX_SCHEDULE_TIMEOUT; 307 timeout = MAX_SCHEDULE_TIMEOUT;
304 if (tvp) { 308 if (tvp) {
@@ -326,7 +330,10 @@ sys_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, s
326 goto out_nofds; 330 goto out_nofds;
327 331
328 /* max_fdset can increase, so grab it once to avoid race */ 332 /* max_fdset can increase, so grab it once to avoid race */
329 max_fdset = current->files->max_fdset; 333 rcu_read_lock();
334 fdt = files_fdtable(current->files);
335 max_fdset = fdt->max_fdset;
336 rcu_read_unlock();
330 if (n > max_fdset) 337 if (n > max_fdset)
331 n = max_fdset; 338 n = max_fdset;
332 339
@@ -464,9 +471,15 @@ asmlinkage long sys_poll(struct pollfd __user * ufds, unsigned int nfds, long ti
464 unsigned int i; 471 unsigned int i;
465 struct poll_list *head; 472 struct poll_list *head;
466 struct poll_list *walk; 473 struct poll_list *walk;
474 struct fdtable *fdt;
475 int max_fdset;
467 476
468 /* Do a sanity check on nfds ... */ 477 /* Do a sanity check on nfds ... */
469 if (nfds > current->files->max_fdset && nfds > OPEN_MAX) 478 rcu_read_lock();
479 fdt = files_fdtable(current->files);
480 max_fdset = fdt->max_fdset;
481 rcu_read_unlock();
482 if (nfds > max_fdset && nfds > OPEN_MAX)
470 return -EINVAL; 483 return -EINVAL;
471 484
472 if (timeout) { 485 if (timeout) {
diff --git a/fs/smbfs/inode.c b/fs/smbfs/inode.c
index 4765aaac9f..10b994428f 100644
--- a/fs/smbfs/inode.c
+++ b/fs/smbfs/inode.c
@@ -331,6 +331,7 @@ static void
331smb_delete_inode(struct inode *ino) 331smb_delete_inode(struct inode *ino)
332{ 332{
333 DEBUG1("ino=%ld\n", ino->i_ino); 333 DEBUG1("ino=%ld\n", ino->i_ino);
334 truncate_inode_pages(&ino->i_data, 0);
334 lock_kernel(); 335 lock_kernel();
335 if (smb_close(ino)) 336 if (smb_close(ino))
336 PARANOIA("could not close inode %ld\n", ino->i_ino); 337 PARANOIA("could not close inode %ld\n", ino->i_ino);
diff --git a/fs/smbfs/proc.c b/fs/smbfs/proc.c
index 220babe91e..38ab558835 100644
--- a/fs/smbfs/proc.c
+++ b/fs/smbfs/proc.c
@@ -2397,8 +2397,7 @@ smb_proc_readdir_long(struct file *filp, void *dirent, filldir_t filldir,
2397 if (req->rq_rcls == ERRSRV && req->rq_err == ERRerror) { 2397 if (req->rq_rcls == ERRSRV && req->rq_err == ERRerror) {
2398 /* a damn Win95 bug - sometimes it clags if you 2398 /* a damn Win95 bug - sometimes it clags if you
2399 ask it too fast */ 2399 ask it too fast */
2400 current->state = TASK_INTERRUPTIBLE; 2400 schedule_timeout_interruptible(msecs_to_jiffies(200));
2401 schedule_timeout(HZ/5);
2402 continue; 2401 continue;
2403 } 2402 }
2404 2403
diff --git a/fs/sysv/inode.c b/fs/sysv/inode.c
index 0530077d9d..fa33eceb00 100644
--- a/fs/sysv/inode.c
+++ b/fs/sysv/inode.c
@@ -292,6 +292,7 @@ int sysv_sync_inode(struct inode * inode)
292 292
293static void sysv_delete_inode(struct inode *inode) 293static void sysv_delete_inode(struct inode *inode)
294{ 294{
295 truncate_inode_pages(&inode->i_data, 0);
295 inode->i_size = 0; 296 inode->i_size = 0;
296 sysv_truncate(inode); 297 sysv_truncate(inode);
297 lock_kernel(); 298 lock_kernel();
diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 3d68de39fa..b83890beaa 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -87,6 +87,8 @@ static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
87 */ 87 */
88void udf_delete_inode(struct inode * inode) 88void udf_delete_inode(struct inode * inode)
89{ 89{
90 truncate_inode_pages(&inode->i_data, 0);
91
90 if (is_bad_inode(inode)) 92 if (is_bad_inode(inode))
91 goto no_delete; 93 goto no_delete;
92 94
diff --git a/fs/ufs/inode.c b/fs/ufs/inode.c
index 718627ca8b..55f4aa16e3 100644
--- a/fs/ufs/inode.c
+++ b/fs/ufs/inode.c
@@ -804,6 +804,7 @@ int ufs_sync_inode (struct inode *inode)
804 804
805void ufs_delete_inode (struct inode * inode) 805void ufs_delete_inode (struct inode * inode)
806{ 806{
807 truncate_inode_pages(&inode->i_data, 0);
807 /*UFS_I(inode)->i_dtime = CURRENT_TIME;*/ 808 /*UFS_I(inode)->i_dtime = CURRENT_TIME;*/
808 lock_kernel(); 809 lock_kernel();
809 mark_inode_dirty(inode); 810 mark_inode_dirty(inode);
diff --git a/fs/xfs/linux-2.6/time.h b/fs/xfs/linux-2.6/time.h
index 6c6fd0faa8..b0d2873ab2 100644
--- a/fs/xfs/linux-2.6/time.h
+++ b/fs/xfs/linux-2.6/time.h
@@ -39,8 +39,7 @@ typedef struct timespec timespec_t;
39 39
40static inline void delay(long ticks) 40static inline void delay(long ticks)
41{ 41{
42 set_current_state(TASK_UNINTERRUPTIBLE); 42 schedule_timeout_uninterruptible(ticks);
43 schedule_timeout(ticks);
44} 43}
45 44
46static inline void nanotime(struct timespec *tvp) 45static inline void nanotime(struct timespec *tvp)
diff --git a/fs/xfs/linux-2.6/xfs_buf.c b/fs/xfs/linux-2.6/xfs_buf.c
index 655bf4a78a..e82cf72ac5 100644
--- a/fs/xfs/linux-2.6/xfs_buf.c
+++ b/fs/xfs/linux-2.6/xfs_buf.c
@@ -1780,10 +1780,10 @@ xfsbufd(
1780 xfsbufd_force_sleep = 0; 1780 xfsbufd_force_sleep = 0;
1781 } 1781 }
1782 1782
1783 set_current_state(TASK_INTERRUPTIBLE); 1783 schedule_timeout_interruptible
1784 schedule_timeout((xfs_buf_timer_centisecs * HZ) / 100); 1784 (xfs_buf_timer_centisecs * msecs_to_jiffies(10));
1785 1785
1786 age = (xfs_buf_age_centisecs * HZ) / 100; 1786 age = xfs_buf_age_centisecs * msecs_to_jiffies(10);
1787 spin_lock(&pbd_delwrite_lock); 1787 spin_lock(&pbd_delwrite_lock);
1788 list_for_each_entry_safe(pb, n, &pbd_delwrite_queue, pb_list) { 1788 list_for_each_entry_safe(pb, n, &pbd_delwrite_queue, pb_list) {
1789 PB_TRACE(pb, "walkq1", (long)pagebuf_ispin(pb)); 1789 PB_TRACE(pb, "walkq1", (long)pagebuf_ispin(pb));
diff --git a/fs/xfs/linux-2.6/xfs_super.c b/fs/xfs/linux-2.6/xfs_super.c
index 0da87bfc99..2302454d8d 100644
--- a/fs/xfs/linux-2.6/xfs_super.c
+++ b/fs/xfs/linux-2.6/xfs_super.c
@@ -467,7 +467,7 @@ xfs_flush_inode(
467 467
468 igrab(inode); 468 igrab(inode);
469 xfs_syncd_queue_work(vfs, inode, xfs_flush_inode_work); 469 xfs_syncd_queue_work(vfs, inode, xfs_flush_inode_work);
470 delay(HZ/2); 470 delay(msecs_to_jiffies(500));
471} 471}
472 472
473/* 473/*
@@ -492,7 +492,7 @@ xfs_flush_device(
492 492
493 igrab(inode); 493 igrab(inode);
494 xfs_syncd_queue_work(vfs, inode, xfs_flush_device_work); 494 xfs_syncd_queue_work(vfs, inode, xfs_flush_device_work);
495 delay(HZ/2); 495 delay(msecs_to_jiffies(500));
496 xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC); 496 xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
497} 497}
498 498
@@ -520,10 +520,9 @@ xfssyncd(
520 struct vfs_sync_work *work, *n; 520 struct vfs_sync_work *work, *n;
521 LIST_HEAD (tmp); 521 LIST_HEAD (tmp);
522 522
523 timeleft = (xfs_syncd_centisecs * HZ) / 100; 523 timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
524 for (;;) { 524 for (;;) {
525 set_current_state(TASK_INTERRUPTIBLE); 525 timeleft = schedule_timeout_interruptible(timeleft);
526 timeleft = schedule_timeout(timeleft);
527 /* swsusp */ 526 /* swsusp */
528 try_to_freeze(); 527 try_to_freeze();
529 if (kthread_should_stop()) 528 if (kthread_should_stop())
@@ -537,7 +536,8 @@ xfssyncd(
537 */ 536 */
538 if (!timeleft || list_empty(&vfsp->vfs_sync_list)) { 537 if (!timeleft || list_empty(&vfsp->vfs_sync_list)) {
539 if (!timeleft) 538 if (!timeleft)
540 timeleft = (xfs_syncd_centisecs * HZ) / 100; 539 timeleft = xfs_syncd_centisecs *
540 msecs_to_jiffies(10);
541 INIT_LIST_HEAD(&vfsp->vfs_sync_work.w_list); 541 INIT_LIST_HEAD(&vfsp->vfs_sync_work.w_list);
542 list_add_tail(&vfsp->vfs_sync_work.w_list, 542 list_add_tail(&vfsp->vfs_sync_work.w_list,
543 &vfsp->vfs_sync_list); 543 &vfsp->vfs_sync_list);
diff --git a/fs/xfs/support/ktrace.c b/fs/xfs/support/ktrace.c
index 3dae14c8c5..fa8394f943 100644
--- a/fs/xfs/support/ktrace.c
+++ b/fs/xfs/support/ktrace.c
@@ -170,7 +170,7 @@ ktrace_enter(
170 void *val14, 170 void *val14,
171 void *val15) 171 void *val15)
172{ 172{
173 static lock_t wrap_lock = SPIN_LOCK_UNLOCKED; 173 static DEFINE_SPINLOCK(wrap_lock);
174 unsigned long flags; 174 unsigned long flags;
175 int index; 175 int index;
176 ktrace_entry_t *ktep; 176 ktrace_entry_t *ktep;
diff --git a/include/asm-alpha/spinlock.h b/include/asm-alpha/spinlock.h
index 80780dba99..8197c69eff 100644
--- a/include/asm-alpha/spinlock.h
+++ b/include/asm-alpha/spinlock.h
@@ -6,7 +6,6 @@
6#include <linux/kernel.h> 6#include <linux/kernel.h>
7#include <asm/current.h> 7#include <asm/current.h>
8 8
9
10/* 9/*
11 * Simple spin lock operations. There are two variants, one clears IRQ's 10 * Simple spin lock operations. There are two variants, one clears IRQ's
12 * on the local processor, one does not. 11 * on the local processor, one does not.
@@ -14,43 +13,18 @@
14 * We make no fairness assumptions. They have a cost. 13 * We make no fairness assumptions. They have a cost.
15 */ 14 */
16 15
17typedef struct { 16#define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
18 volatile unsigned int lock; 17#define __raw_spin_is_locked(x) ((x)->lock != 0)
19#ifdef CONFIG_DEBUG_SPINLOCK 18#define __raw_spin_unlock_wait(x) \
20 int on_cpu; 19 do { cpu_relax(); } while ((x)->lock)
21 int line_no; 20
22 void *previous; 21static inline void __raw_spin_unlock(raw_spinlock_t * lock)
23 struct task_struct * task;
24 const char *base_file;
25#endif
26} spinlock_t;
27
28#ifdef CONFIG_DEBUG_SPINLOCK
29#define SPIN_LOCK_UNLOCKED (spinlock_t){ 0, -1, 0, NULL, NULL, NULL }
30#else
31#define SPIN_LOCK_UNLOCKED (spinlock_t){ 0 }
32#endif
33
34#define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while(0)
35#define spin_is_locked(x) ((x)->lock != 0)
36#define spin_unlock_wait(x) do { barrier(); } while ((x)->lock)
37
38#ifdef CONFIG_DEBUG_SPINLOCK
39extern void _raw_spin_unlock(spinlock_t * lock);
40extern void debug_spin_lock(spinlock_t * lock, const char *, int);
41extern int debug_spin_trylock(spinlock_t * lock, const char *, int);
42#define _raw_spin_lock(LOCK) \
43 debug_spin_lock(LOCK, __BASE_FILE__, __LINE__)
44#define _raw_spin_trylock(LOCK) \
45 debug_spin_trylock(LOCK, __BASE_FILE__, __LINE__)
46#else
47static inline void _raw_spin_unlock(spinlock_t * lock)
48{ 22{
49 mb(); 23 mb();
50 lock->lock = 0; 24 lock->lock = 0;
51} 25}
52 26
53static inline void _raw_spin_lock(spinlock_t * lock) 27static inline void __raw_spin_lock(raw_spinlock_t * lock)
54{ 28{
55 long tmp; 29 long tmp;
56 30
@@ -70,80 +44,64 @@ static inline void _raw_spin_lock(spinlock_t * lock)
70 : "m"(lock->lock) : "memory"); 44 : "m"(lock->lock) : "memory");
71} 45}
72 46
73static inline int _raw_spin_trylock(spinlock_t *lock) 47static inline int __raw_spin_trylock(raw_spinlock_t *lock)
74{ 48{
75 return !test_and_set_bit(0, &lock->lock); 49 return !test_and_set_bit(0, &lock->lock);
76} 50}
77#endif /* CONFIG_DEBUG_SPINLOCK */
78
79#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
80 51
81/***********************************************************/ 52/***********************************************************/
82 53
83typedef struct { 54static inline int __raw_read_can_lock(raw_rwlock_t *lock)
84 volatile unsigned int lock;
85} rwlock_t;
86
87#define RW_LOCK_UNLOCKED (rwlock_t){ 0 }
88
89#define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0)
90
91static inline int read_can_lock(rwlock_t *lock)
92{ 55{
93 return (lock->lock & 1) == 0; 56 return (lock->lock & 1) == 0;
94} 57}
95 58
96static inline int write_can_lock(rwlock_t *lock) 59static inline int __raw_write_can_lock(raw_rwlock_t *lock)
97{ 60{
98 return lock->lock == 0; 61 return lock->lock == 0;
99} 62}
100 63
101#ifdef CONFIG_DEBUG_RWLOCK 64static inline void __raw_read_lock(raw_rwlock_t *lock)
102extern void _raw_write_lock(rwlock_t * lock);
103extern void _raw_read_lock(rwlock_t * lock);
104#else
105static inline void _raw_write_lock(rwlock_t * lock)
106{ 65{
107 long regx; 66 long regx;
108 67
109 __asm__ __volatile__( 68 __asm__ __volatile__(
110 "1: ldl_l %1,%0\n" 69 "1: ldl_l %1,%0\n"
111 " bne %1,6f\n" 70 " blbs %1,6f\n"
112 " lda %1,1\n" 71 " subl %1,2,%1\n"
113 " stl_c %1,%0\n" 72 " stl_c %1,%0\n"
114 " beq %1,6f\n" 73 " beq %1,6f\n"
115 " mb\n" 74 " mb\n"
116 ".subsection 2\n" 75 ".subsection 2\n"
117 "6: ldl %1,%0\n" 76 "6: ldl %1,%0\n"
118 " bne %1,6b\n" 77 " blbs %1,6b\n"
119 " br 1b\n" 78 " br 1b\n"
120 ".previous" 79 ".previous"
121 : "=m" (*lock), "=&r" (regx) 80 : "=m" (*lock), "=&r" (regx)
122 : "m" (*lock) : "memory"); 81 : "m" (*lock) : "memory");
123} 82}
124 83
125static inline void _raw_read_lock(rwlock_t * lock) 84static inline void __raw_write_lock(raw_rwlock_t *lock)
126{ 85{
127 long regx; 86 long regx;
128 87
129 __asm__ __volatile__( 88 __asm__ __volatile__(
130 "1: ldl_l %1,%0\n" 89 "1: ldl_l %1,%0\n"
131 " blbs %1,6f\n" 90 " bne %1,6f\n"
132 " subl %1,2,%1\n" 91 " lda %1,1\n"
133 " stl_c %1,%0\n" 92 " stl_c %1,%0\n"
134 " beq %1,6f\n" 93 " beq %1,6f\n"
135 " mb\n" 94 " mb\n"
136 ".subsection 2\n" 95 ".subsection 2\n"
137 "6: ldl %1,%0\n" 96 "6: ldl %1,%0\n"
138 " blbs %1,6b\n" 97 " bne %1,6b\n"
139 " br 1b\n" 98 " br 1b\n"
140 ".previous" 99 ".previous"
141 : "=m" (*lock), "=&r" (regx) 100 : "=m" (*lock), "=&r" (regx)
142 : "m" (*lock) : "memory"); 101 : "m" (*lock) : "memory");
143} 102}
144#endif /* CONFIG_DEBUG_RWLOCK */
145 103
146static inline int _raw_read_trylock(rwlock_t * lock) 104static inline int __raw_read_trylock(raw_rwlock_t * lock)
147{ 105{
148 long regx; 106 long regx;
149 int success; 107 int success;
@@ -165,7 +123,7 @@ static inline int _raw_read_trylock(rwlock_t * lock)
165 return success; 123 return success;
166} 124}
167 125
168static inline int _raw_write_trylock(rwlock_t * lock) 126static inline int __raw_write_trylock(raw_rwlock_t * lock)
169{ 127{
170 long regx; 128 long regx;
171 int success; 129 int success;
@@ -187,13 +145,7 @@ static inline int _raw_write_trylock(rwlock_t * lock)
187 return success; 145 return success;
188} 146}
189 147
190static inline void _raw_write_unlock(rwlock_t * lock) 148static inline void __raw_read_unlock(raw_rwlock_t * lock)
191{
192 mb();
193 lock->lock = 0;
194}
195
196static inline void _raw_read_unlock(rwlock_t * lock)
197{ 149{
198 long regx; 150 long regx;
199 __asm__ __volatile__( 151 __asm__ __volatile__(
@@ -209,4 +161,10 @@ static inline void _raw_read_unlock(rwlock_t * lock)
209 : "m" (*lock) : "memory"); 161 : "m" (*lock) : "memory");
210} 162}
211 163
164static inline void __raw_write_unlock(raw_rwlock_t * lock)
165{
166 mb();
167 lock->lock = 0;
168}
169
212#endif /* _ALPHA_SPINLOCK_H */ 170#endif /* _ALPHA_SPINLOCK_H */
diff --git a/include/asm-alpha/spinlock_types.h b/include/asm-alpha/spinlock_types.h
new file mode 100644
index 0000000000..8141eb5ebf
--- /dev/null
+++ b/include/asm-alpha/spinlock_types.h
@@ -0,0 +1,20 @@
1#ifndef _ALPHA_SPINLOCK_TYPES_H
2#define _ALPHA_SPINLOCK_TYPES_H
3
4#ifndef __LINUX_SPINLOCK_TYPES_H
5# error "please don't include this file directly"
6#endif
7
8typedef struct {
9 volatile unsigned int lock;
10} raw_spinlock_t;
11
12#define __RAW_SPIN_LOCK_UNLOCKED { 0 }
13
14typedef struct {
15 volatile unsigned int lock;
16} raw_rwlock_t;
17
18#define __RAW_RW_LOCK_UNLOCKED { 0 }
19
20#endif
diff --git a/include/asm-arm/arch-pxa/pxafb.h b/include/asm-arm/arch-pxa/pxafb.h
index 27d71e9d41..21c0e16dce 100644
--- a/include/asm-arm/arch-pxa/pxafb.h
+++ b/include/asm-arm/arch-pxa/pxafb.h
@@ -66,3 +66,4 @@ struct pxafb_mach_info {
66 66
67}; 67};
68void set_pxa_fb_info(struct pxafb_mach_info *hard_pxa_fb_info); 68void set_pxa_fb_info(struct pxafb_mach_info *hard_pxa_fb_info);
69unsigned long pxafb_get_hsync_time(struct device *dev);
diff --git a/include/asm-arm/arch-s3c2410/fb.h b/include/asm-arm/arch-s3c2410/fb.h
new file mode 100644
index 0000000000..ac57bc887d
--- /dev/null
+++ b/include/asm-arm/arch-s3c2410/fb.h
@@ -0,0 +1,69 @@
1/* linux/include/asm/arch-s3c2410/fb.h
2 *
3 * Copyright (c) 2004 Arnaud Patard <arnaud.patard@rtp-net.org>
4 *
5 * Inspired by pxafb.h
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 *
12 * Changelog:
13 * 07-Sep-2004 RTP Created file
14 * 03-Nov-2004 BJD Updated and minor cleanups
15 * 03-Aug-2005 RTP Renamed to fb.h
16*/
17
18#ifndef __ASM_ARM_FB_H
19#define __ASM_ARM_FB_H
20
21#include <asm/arch/regs-lcd.h>
22
23struct s3c2410fb_val {
24 unsigned int defval;
25 unsigned int min;
26 unsigned int max;
27};
28
29struct s3c2410fb_hw {
30 unsigned long lcdcon1;
31 unsigned long lcdcon2;
32 unsigned long lcdcon3;
33 unsigned long lcdcon4;
34 unsigned long lcdcon5;
35};
36
37struct s3c2410fb_mach_info {
38 unsigned char fixed_syncs; /* do not update sync/border */
39
40 /* Screen size */
41 int width;
42 int height;
43
44 /* Screen info */
45 struct s3c2410fb_val xres;
46 struct s3c2410fb_val yres;
47 struct s3c2410fb_val bpp;
48
49 /* lcd configuration registers */
50 struct s3c2410fb_hw regs;
51
52 /* GPIOs */
53
54 unsigned long gpcup;
55 unsigned long gpcup_mask;
56 unsigned long gpccon;
57 unsigned long gpccon_mask;
58 unsigned long gpdup;
59 unsigned long gpdup_mask;
60 unsigned long gpdcon;
61 unsigned long gpdcon_mask;
62
63 /* lpc3600 control register */
64 unsigned long lpcsel;
65};
66
67void __init set_s3c2410fb_info(struct s3c2410fb_mach_info *hard_s3c2410fb_info);
68
69#endif /* __ASM_ARM_FB_H */
diff --git a/include/asm-arm/arch-s3c2410/regs-lcd.h b/include/asm-arm/arch-s3c2410/regs-lcd.h
index 7f882ea92b..b6b1b4e8bb 100644
--- a/include/asm-arm/arch-s3c2410/regs-lcd.h
+++ b/include/asm-arm/arch-s3c2410/regs-lcd.h
@@ -51,21 +51,32 @@
51 51
52#define S3C2410_LCDCON1_ENVID (1) 52#define S3C2410_LCDCON1_ENVID (1)
53 53
54#define S3C2410_LCDCON1_MODEMASK 0x1E
55
54#define S3C2410_LCDCON2_VBPD(x) ((x) << 24) 56#define S3C2410_LCDCON2_VBPD(x) ((x) << 24)
55#define S3C2410_LCDCON2_LINEVAL(x) ((x) << 14) 57#define S3C2410_LCDCON2_LINEVAL(x) ((x) << 14)
56#define S3C2410_LCDCON2_VFPD(x) ((x) << 6) 58#define S3C2410_LCDCON2_VFPD(x) ((x) << 6)
57#define S3C2410_LCDCON2_VSPW(x) ((x) << 0) 59#define S3C2410_LCDCON2_VSPW(x) ((x) << 0)
58 60
61#define S3C2410_LCDCON2_GET_VBPD(x) ( ((x) >> 24) & 0xFF)
62#define S3C2410_LCDCON2_GET_VFPD(x) ( ((x) >> 6) & 0xFF)
63#define S3C2410_LCDCON2_GET_VSPW(x) ( ((x) >> 0) & 0x3F)
64
59#define S3C2410_LCDCON3_HBPD(x) ((x) << 19) 65#define S3C2410_LCDCON3_HBPD(x) ((x) << 19)
60#define S3C2410_LCDCON3_WDLY(x) ((x) << 19) 66#define S3C2410_LCDCON3_WDLY(x) ((x) << 19)
61#define S3C2410_LCDCON3_HOZVAL(x) ((x) << 8) 67#define S3C2410_LCDCON3_HOZVAL(x) ((x) << 8)
62#define S3C2410_LCDCON3_HFPD(x) ((x) << 0) 68#define S3C2410_LCDCON3_HFPD(x) ((x) << 0)
63#define S3C2410_LCDCON3_LINEBLANK(x)((x) << 0) 69#define S3C2410_LCDCON3_LINEBLANK(x)((x) << 0)
64 70
71#define S3C2410_LCDCON3_GET_HBPD(x) ( ((x) >> 19) & 0x7F)
72#define S3C2410_LCDCON3_GET_HFPD(x) ( ((x) >> 0) & 0xFF)
73
65#define S3C2410_LCDCON4_MVAL(x) ((x) << 8) 74#define S3C2410_LCDCON4_MVAL(x) ((x) << 8)
66#define S3C2410_LCDCON4_HSPW(x) ((x) << 0) 75#define S3C2410_LCDCON4_HSPW(x) ((x) << 0)
67#define S3C2410_LCDCON4_WLH(x) ((x) << 0) 76#define S3C2410_LCDCON4_WLH(x) ((x) << 0)
68 77
78#define S3C2410_LCDCON4_GET_HSPW(x) ( ((x) >> 0) & 0xFF)
79
69#define S3C2410_LCDCON5_BPP24BL (1<<12) 80#define S3C2410_LCDCON5_BPP24BL (1<<12)
70#define S3C2410_LCDCON5_FRM565 (1<<11) 81#define S3C2410_LCDCON5_FRM565 (1<<11)
71#define S3C2410_LCDCON5_INVVCLK (1<<10) 82#define S3C2410_LCDCON5_INVVCLK (1<<10)
@@ -100,10 +111,16 @@
100#define S3C2410_DITHMODE S3C2410_LCDREG(0x4C) 111#define S3C2410_DITHMODE S3C2410_LCDREG(0x4C)
101#define S3C2410_TPAL S3C2410_LCDREG(0x50) 112#define S3C2410_TPAL S3C2410_LCDREG(0x50)
102 113
114#define S3C2410_TPAL_EN (1<<24)
115
103/* interrupt info */ 116/* interrupt info */
104#define S3C2410_LCDINTPND S3C2410_LCDREG(0x54) 117#define S3C2410_LCDINTPND S3C2410_LCDREG(0x54)
105#define S3C2410_LCDSRCPND S3C2410_LCDREG(0x58) 118#define S3C2410_LCDSRCPND S3C2410_LCDREG(0x58)
106#define S3C2410_LCDINTMSK S3C2410_LCDREG(0x5C) 119#define S3C2410_LCDINTMSK S3C2410_LCDREG(0x5C)
120#define S3C2410_LCDINT_FIWSEL (1<<2)
121#define S3C2410_LCDINT_FRSYNC (1<<1)
122#define S3C2410_LCDINT_FICNT (1<<0)
123
107#define S3C2410_LPCSEL S3C2410_LCDREG(0x60) 124#define S3C2410_LPCSEL S3C2410_LCDREG(0x60)
108 125
109#define S3C2410_TFTPAL(x) S3C2410_LCDREG((0x400 + (x)*4)) 126#define S3C2410_TFTPAL(x) S3C2410_LCDREG((0x400 + (x)*4))
diff --git a/include/asm-arm/spinlock.h b/include/asm-arm/spinlock.h
index 1f906d09b6..cb4906b455 100644
--- a/include/asm-arm/spinlock.h
+++ b/include/asm-arm/spinlock.h
@@ -16,21 +16,14 @@
16 * Unlocked value: 0 16 * Unlocked value: 0
17 * Locked value: 1 17 * Locked value: 1
18 */ 18 */
19typedef struct {
20 volatile unsigned int lock;
21#ifdef CONFIG_PREEMPT
22 unsigned int break_lock;
23#endif
24} spinlock_t;
25 19
26#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 } 20#define __raw_spin_is_locked(x) ((x)->lock != 0)
21#define __raw_spin_unlock_wait(lock) \
22 do { while (__raw_spin_is_locked(lock)) cpu_relax(); } while (0)
27 23
28#define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while (0) 24#define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
29#define spin_is_locked(x) ((x)->lock != 0)
30#define spin_unlock_wait(x) do { barrier(); } while (spin_is_locked(x))
31#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
32 25
33static inline void _raw_spin_lock(spinlock_t *lock) 26static inline void __raw_spin_lock(raw_spinlock_t *lock)
34{ 27{
35 unsigned long tmp; 28 unsigned long tmp;
36 29
@@ -47,7 +40,7 @@ static inline void _raw_spin_lock(spinlock_t *lock)
47 smp_mb(); 40 smp_mb();
48} 41}
49 42
50static inline int _raw_spin_trylock(spinlock_t *lock) 43static inline int __raw_spin_trylock(raw_spinlock_t *lock)
51{ 44{
52 unsigned long tmp; 45 unsigned long tmp;
53 46
@@ -67,7 +60,7 @@ static inline int _raw_spin_trylock(spinlock_t *lock)
67 } 60 }
68} 61}
69 62
70static inline void _raw_spin_unlock(spinlock_t *lock) 63static inline void __raw_spin_unlock(raw_spinlock_t *lock)
71{ 64{
72 smp_mb(); 65 smp_mb();
73 66
@@ -80,23 +73,14 @@ static inline void _raw_spin_unlock(spinlock_t *lock)
80 73
81/* 74/*
82 * RWLOCKS 75 * RWLOCKS
83 */ 76 *
84typedef struct { 77 *
85 volatile unsigned int lock;
86#ifdef CONFIG_PREEMPT
87 unsigned int break_lock;
88#endif
89} rwlock_t;
90
91#define RW_LOCK_UNLOCKED (rwlock_t) { 0 }
92#define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while (0)
93#define rwlock_is_locked(x) (*((volatile unsigned int *)(x)) != 0)
94
95/*
96 * Write locks are easy - we just set bit 31. When unlocking, we can 78 * Write locks are easy - we just set bit 31. When unlocking, we can
97 * just write zero since the lock is exclusively held. 79 * just write zero since the lock is exclusively held.
98 */ 80 */
99static inline void _raw_write_lock(rwlock_t *rw) 81#define rwlock_is_locked(x) (*((volatile unsigned int *)(x)) != 0)
82
83static inline void __raw_write_lock(rwlock_t *rw)
100{ 84{
101 unsigned long tmp; 85 unsigned long tmp;
102 86
@@ -113,7 +97,7 @@ static inline void _raw_write_lock(rwlock_t *rw)
113 smp_mb(); 97 smp_mb();
114} 98}
115 99
116static inline int _raw_write_trylock(rwlock_t *rw) 100static inline int __raw_write_trylock(rwlock_t *rw)
117{ 101{
118 unsigned long tmp; 102 unsigned long tmp;
119 103
@@ -133,7 +117,7 @@ static inline int _raw_write_trylock(rwlock_t *rw)
133 } 117 }
134} 118}
135 119
136static inline void _raw_write_unlock(rwlock_t *rw) 120static inline void __raw_write_unlock(raw_rwlock_t *rw)
137{ 121{
138 smp_mb(); 122 smp_mb();
139 123
@@ -156,7 +140,7 @@ static inline void _raw_write_unlock(rwlock_t *rw)
156 * currently active. However, we know we won't have any write 140 * currently active. However, we know we won't have any write
157 * locks. 141 * locks.
158 */ 142 */
159static inline void _raw_read_lock(rwlock_t *rw) 143static inline void __raw_read_lock(raw_rwlock_t *rw)
160{ 144{
161 unsigned long tmp, tmp2; 145 unsigned long tmp, tmp2;
162 146
@@ -173,7 +157,7 @@ static inline void _raw_read_lock(rwlock_t *rw)
173 smp_mb(); 157 smp_mb();
174} 158}
175 159
176static inline void _raw_read_unlock(rwlock_t *rw) 160static inline void __raw_read_unlock(rwlock_t *rw)
177{ 161{
178 unsigned long tmp, tmp2; 162 unsigned long tmp, tmp2;
179 163
@@ -190,6 +174,6 @@ static inline void _raw_read_unlock(rwlock_t *rw)
190 : "cc"); 174 : "cc");
191} 175}
192 176
193#define _raw_read_trylock(lock) generic_raw_read_trylock(lock) 177#define __raw_read_trylock(lock) generic__raw_read_trylock(lock)
194 178
195#endif /* __ASM_SPINLOCK_H */ 179#endif /* __ASM_SPINLOCK_H */
diff --git a/include/asm-arm/spinlock_types.h b/include/asm-arm/spinlock_types.h
new file mode 100644
index 0000000000..43e83f6d2e
--- /dev/null
+++ b/include/asm-arm/spinlock_types.h
@@ -0,0 +1,20 @@
1#ifndef __ASM_SPINLOCK_TYPES_H
2#define __ASM_SPINLOCK_TYPES_H
3
4#ifndef __LINUX_SPINLOCK_TYPES_H
5# error "please don't include this file directly"
6#endif
7
8typedef struct {
9 volatile unsigned int lock;
10} raw_spinlock_t;
11
12#define __RAW_SPIN_LOCK_UNLOCKED { 0 }
13
14typedef struct {
15 volatile unsigned int lock;
16} raw_rwlock_t;
17
18#define __RAW_RW_LOCK_UNLOCKED { 0 }
19
20#endif
diff --git a/include/asm-arm/unistd.h b/include/asm-arm/unistd.h
index 278de61224..c49df635a8 100644
--- a/include/asm-arm/unistd.h
+++ b/include/asm-arm/unistd.h
@@ -355,6 +355,9 @@
355#define __NR_inotify_init (__NR_SYSCALL_BASE+316) 355#define __NR_inotify_init (__NR_SYSCALL_BASE+316)
356#define __NR_inotify_add_watch (__NR_SYSCALL_BASE+317) 356#define __NR_inotify_add_watch (__NR_SYSCALL_BASE+317)
357#define __NR_inotify_rm_watch (__NR_SYSCALL_BASE+318) 357#define __NR_inotify_rm_watch (__NR_SYSCALL_BASE+318)
358#define __NR_mbind (__NR_SYSCALL_BASE+319)
359#define __NR_get_mempolicy (__NR_SYSCALL_BASE+320)
360#define __NR_set_mempolicy (__NR_SYSCALL_BASE+321)
358 361
359/* 362/*
360 * The following SWIs are ARM private. 363 * The following SWIs are ARM private.
diff --git a/include/asm-arm26/hardirq.h b/include/asm-arm26/hardirq.h
index 791ee1da9b..dc28daab8a 100644
--- a/include/asm-arm26/hardirq.h
+++ b/include/asm-arm26/hardirq.h
@@ -22,8 +22,6 @@ typedef struct {
22# error HARDIRQ_BITS is too low! 22# error HARDIRQ_BITS is too low!
23#endif 23#endif
24 24
25#define irq_enter() (preempt_count() += HARDIRQ_OFFSET)
26
27#ifndef CONFIG_SMP 25#ifndef CONFIG_SMP
28 26
29extern asmlinkage void __do_softirq(void); 27extern asmlinkage void __do_softirq(void);
diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h
index faff403e10..7d0298347e 100644
--- a/include/asm-generic/tlb.h
+++ b/include/asm-generic/tlb.h
@@ -23,7 +23,11 @@
23 * and page free order so much.. 23 * and page free order so much..
24 */ 24 */
25#ifdef CONFIG_SMP 25#ifdef CONFIG_SMP
26 #define FREE_PTE_NR 506 26 #ifdef ARCH_FREE_PTR_NR
27 #define FREE_PTR_NR ARCH_FREE_PTR_NR
28 #else
29 #define FREE_PTE_NR 506
30 #endif
27 #define tlb_fast_mode(tlb) ((tlb)->nr == ~0U) 31 #define tlb_fast_mode(tlb) ((tlb)->nr == ~0U)
28#else 32#else
29 #define FREE_PTE_NR 1 33 #define FREE_PTE_NR 1
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 6f857be2b6..a9c55490fb 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -103,3 +103,41 @@
103 VMLINUX_SYMBOL(__kprobes_text_start) = .; \ 103 VMLINUX_SYMBOL(__kprobes_text_start) = .; \
104 *(.kprobes.text) \ 104 *(.kprobes.text) \
105 VMLINUX_SYMBOL(__kprobes_text_end) = .; 105 VMLINUX_SYMBOL(__kprobes_text_end) = .;
106
107 /* DWARF debug sections.
108 Symbols in the DWARF debugging sections are relative to
109 the beginning of the section so we begin them at 0. */
110#define DWARF_DEBUG \
111 /* DWARF 1 */ \
112 .debug 0 : { *(.debug) } \
113 .line 0 : { *(.line) } \
114 /* GNU DWARF 1 extensions */ \
115 .debug_srcinfo 0 : { *(.debug_srcinfo) } \
116 .debug_sfnames 0 : { *(.debug_sfnames) } \
117 /* DWARF 1.1 and DWARF 2 */ \
118 .debug_aranges 0 : { *(.debug_aranges) } \
119 .debug_pubnames 0 : { *(.debug_pubnames) } \
120 /* DWARF 2 */ \
121 .debug_info 0 : { *(.debug_info \
122 .gnu.linkonce.wi.*) } \
123 .debug_abbrev 0 : { *(.debug_abbrev) } \
124 .debug_line 0 : { *(.debug_line) } \
125 .debug_frame 0 : { *(.debug_frame) } \
126 .debug_str 0 : { *(.debug_str) } \
127 .debug_loc 0 : { *(.debug_loc) } \
128 .debug_macinfo 0 : { *(.debug_macinfo) } \
129 /* SGI/MIPS DWARF 2 extensions */ \
130 .debug_weaknames 0 : { *(.debug_weaknames) } \
131 .debug_funcnames 0 : { *(.debug_funcnames) } \
132 .debug_typenames 0 : { *(.debug_typenames) } \
133 .debug_varnames 0 : { *(.debug_varnames) } \
134
135 /* Stabs debugging sections. */
136#define STABS_DEBUG \
137 .stab 0 : { *(.stab) } \
138 .stabstr 0 : { *(.stabstr) } \
139 .stab.excl 0 : { *(.stab.excl) } \
140 .stab.exclstr 0 : { *(.stab.exclstr) } \
141 .stab.index 0 : { *(.stab.index) } \
142 .stab.indexstr 0 : { *(.stab.indexstr) } \
143 .comment 0 : { *(.comment) }
diff --git a/include/asm-i386/apic.h b/include/asm-i386/apic.h
index 6a1b188228..8c454aa58a 100644
--- a/include/asm-i386/apic.h
+++ b/include/asm-i386/apic.h
@@ -130,6 +130,8 @@ extern unsigned int nmi_watchdog;
130#define NMI_LOCAL_APIC 2 130#define NMI_LOCAL_APIC 2
131#define NMI_INVALID 3 131#define NMI_INVALID 3
132 132
133extern int disable_timer_pin_1;
134
133#else /* !CONFIG_X86_LOCAL_APIC */ 135#else /* !CONFIG_X86_LOCAL_APIC */
134static inline void lapic_shutdown(void) { } 136static inline void lapic_shutdown(void) { }
135 137
diff --git a/include/asm-i386/div64.h b/include/asm-i386/div64.h
index 28ed8b296a..75c67c785b 100644
--- a/include/asm-i386/div64.h
+++ b/include/asm-i386/div64.h
@@ -35,7 +35,7 @@
35 */ 35 */
36#define div_long_long_rem(a,b,c) div_ll_X_l_rem(a,b,c) 36#define div_long_long_rem(a,b,c) div_ll_X_l_rem(a,b,c)
37 37
38extern inline long 38static inline long
39div_ll_X_l_rem(long long divs, long div, long *rem) 39div_ll_X_l_rem(long long divs, long div, long *rem)
40{ 40{
41 long dum2; 41 long dum2;
diff --git a/include/asm-i386/mach-default/mach_reboot.h b/include/asm-i386/mach-default/mach_reboot.h
index 521e227db6..06ae4d81ba 100644
--- a/include/asm-i386/mach-default/mach_reboot.h
+++ b/include/asm-i386/mach-default/mach_reboot.h
@@ -22,7 +22,15 @@ static inline void mach_reboot(void)
22 for (i = 0; i < 100; i++) { 22 for (i = 0; i < 100; i++) {
23 kb_wait(); 23 kb_wait();
24 udelay(50); 24 udelay(50);
25 outb(0xfe, 0x64); /* pulse reset low */ 25 outb(0x60, 0x64); /* write Controller Command Byte */
26 udelay(50);
27 kb_wait();
28 udelay(50);
29 outb(0x14, 0x60); /* set "System flag" */
30 udelay(50);
31 kb_wait();
32 udelay(50);
33 outb(0xfe, 0x64); /* pulse reset low */
26 udelay(50); 34 udelay(50);
27 } 35 }
28} 36}
diff --git a/include/asm-i386/mmzone.h b/include/asm-i386/mmzone.h
index 516421300e..348fe3a487 100644
--- a/include/asm-i386/mmzone.h
+++ b/include/asm-i386/mmzone.h
@@ -29,7 +29,7 @@ static inline void get_memcfg_numa(void)
29#ifdef CONFIG_X86_NUMAQ 29#ifdef CONFIG_X86_NUMAQ
30 if (get_memcfg_numaq()) 30 if (get_memcfg_numaq())
31 return; 31 return;
32#elif CONFIG_ACPI_SRAT 32#elif defined(CONFIG_ACPI_SRAT)
33 if (get_memcfg_from_srat()) 33 if (get_memcfg_from_srat())
34 return; 34 return;
35#endif 35#endif
diff --git a/include/asm-i386/numa.h b/include/asm-i386/numa.h
new file mode 100644
index 0000000000..96fcb157db
--- /dev/null
+++ b/include/asm-i386/numa.h
@@ -0,0 +1,3 @@
1
2int pxm_to_nid(int pxm);
3
diff --git a/include/asm-i386/processor.h b/include/asm-i386/processor.h
index 37bef8ed7b..0a4ec76437 100644
--- a/include/asm-i386/processor.h
+++ b/include/asm-i386/processor.h
@@ -679,7 +679,7 @@ static inline void rep_nop(void)
679 However we don't do prefetches for pre XP Athlons currently 679 However we don't do prefetches for pre XP Athlons currently
680 That should be fixed. */ 680 That should be fixed. */
681#define ARCH_HAS_PREFETCH 681#define ARCH_HAS_PREFETCH
682extern inline void prefetch(const void *x) 682static inline void prefetch(const void *x)
683{ 683{
684 alternative_input(ASM_NOP4, 684 alternative_input(ASM_NOP4,
685 "prefetchnta (%1)", 685 "prefetchnta (%1)",
@@ -693,7 +693,7 @@ extern inline void prefetch(const void *x)
693 693
694/* 3dnow! prefetch to get an exclusive cache line. Useful for 694/* 3dnow! prefetch to get an exclusive cache line. Useful for
695 spinlocks to avoid one state transition in the cache coherency protocol. */ 695 spinlocks to avoid one state transition in the cache coherency protocol. */
696extern inline void prefetchw(const void *x) 696static inline void prefetchw(const void *x)
697{ 697{
698 alternative_input(ASM_NOP4, 698 alternative_input(ASM_NOP4,
699 "prefetchw (%1)", 699 "prefetchw (%1)",
diff --git a/include/asm-i386/spinlock.h b/include/asm-i386/spinlock.h
index f9ff31f400..23604350cd 100644
--- a/include/asm-i386/spinlock.h
+++ b/include/asm-i386/spinlock.h
@@ -7,46 +7,21 @@
7#include <linux/config.h> 7#include <linux/config.h>
8#include <linux/compiler.h> 8#include <linux/compiler.h>
9 9
10asmlinkage int printk(const char * fmt, ...)
11 __attribute__ ((format (printf, 1, 2)));
12
13/* 10/*
14 * Your basic SMP spinlocks, allowing only a single CPU anywhere 11 * Your basic SMP spinlocks, allowing only a single CPU anywhere
15 */ 12 *
16
17typedef struct {
18 volatile unsigned int slock;
19#ifdef CONFIG_DEBUG_SPINLOCK
20 unsigned magic;
21#endif
22#ifdef CONFIG_PREEMPT
23 unsigned int break_lock;
24#endif
25} spinlock_t;
26
27#define SPINLOCK_MAGIC 0xdead4ead
28
29#ifdef CONFIG_DEBUG_SPINLOCK
30#define SPINLOCK_MAGIC_INIT , SPINLOCK_MAGIC
31#else
32#define SPINLOCK_MAGIC_INIT /* */
33#endif
34
35#define SPIN_LOCK_UNLOCKED (spinlock_t) { 1 SPINLOCK_MAGIC_INIT }
36
37#define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while(0)
38
39/*
40 * Simple spin lock operations. There are two variants, one clears IRQ's 13 * Simple spin lock operations. There are two variants, one clears IRQ's
41 * on the local processor, one does not. 14 * on the local processor, one does not.
42 * 15 *
43 * We make no fairness assumptions. They have a cost. 16 * We make no fairness assumptions. They have a cost.
17 *
18 * (the type definitions are in asm/spinlock_types.h)
44 */ 19 */
45 20
46#define spin_is_locked(x) (*(volatile signed char *)(&(x)->slock) <= 0) 21#define __raw_spin_is_locked(x) \
47#define spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x)) 22 (*(volatile signed char *)(&(x)->slock) <= 0)
48 23
49#define spin_lock_string \ 24#define __raw_spin_lock_string \
50 "\n1:\t" \ 25 "\n1:\t" \
51 "lock ; decb %0\n\t" \ 26 "lock ; decb %0\n\t" \
52 "jns 3f\n" \ 27 "jns 3f\n" \
@@ -57,7 +32,7 @@ typedef struct {
57 "jmp 1b\n" \ 32 "jmp 1b\n" \
58 "3:\n\t" 33 "3:\n\t"
59 34
60#define spin_lock_string_flags \ 35#define __raw_spin_lock_string_flags \
61 "\n1:\t" \ 36 "\n1:\t" \
62 "lock ; decb %0\n\t" \ 37 "lock ; decb %0\n\t" \
63 "jns 4f\n\t" \ 38 "jns 4f\n\t" \
@@ -73,86 +48,71 @@ typedef struct {
73 "jmp 1b\n" \ 48 "jmp 1b\n" \
74 "4:\n\t" 49 "4:\n\t"
75 50
51static inline void __raw_spin_lock(raw_spinlock_t *lock)
52{
53 __asm__ __volatile__(
54 __raw_spin_lock_string
55 :"=m" (lock->slock) : : "memory");
56}
57
58static inline void __raw_spin_lock_flags(raw_spinlock_t *lock, unsigned long flags)
59{
60 __asm__ __volatile__(
61 __raw_spin_lock_string_flags
62 :"=m" (lock->slock) : "r" (flags) : "memory");
63}
64
65static inline int __raw_spin_trylock(raw_spinlock_t *lock)
66{
67 char oldval;
68 __asm__ __volatile__(
69 "xchgb %b0,%1"
70 :"=q" (oldval), "=m" (lock->slock)
71 :"0" (0) : "memory");
72 return oldval > 0;
73}
74
76/* 75/*
77 * This works. Despite all the confusion. 76 * __raw_spin_unlock based on writing $1 to the low byte.
78 * (except on PPro SMP or if we are using OOSTORE) 77 * This method works. Despite all the confusion.
78 * (except on PPro SMP or if we are using OOSTORE, so we use xchgb there)
79 * (PPro errata 66, 92) 79 * (PPro errata 66, 92)
80 */ 80 */
81 81
82#if !defined(CONFIG_X86_OOSTORE) && !defined(CONFIG_X86_PPRO_FENCE) 82#if !defined(CONFIG_X86_OOSTORE) && !defined(CONFIG_X86_PPRO_FENCE)
83 83
84#define spin_unlock_string \ 84#define __raw_spin_unlock_string \
85 "movb $1,%0" \ 85 "movb $1,%0" \
86 :"=m" (lock->slock) : : "memory" 86 :"=m" (lock->slock) : : "memory"
87 87
88 88
89static inline void _raw_spin_unlock(spinlock_t *lock) 89static inline void __raw_spin_unlock(raw_spinlock_t *lock)
90{ 90{
91#ifdef CONFIG_DEBUG_SPINLOCK
92 BUG_ON(lock->magic != SPINLOCK_MAGIC);
93 BUG_ON(!spin_is_locked(lock));
94#endif
95 __asm__ __volatile__( 91 __asm__ __volatile__(
96 spin_unlock_string 92 __raw_spin_unlock_string
97 ); 93 );
98} 94}
99 95
100#else 96#else
101 97
102#define spin_unlock_string \ 98#define __raw_spin_unlock_string \
103 "xchgb %b0, %1" \ 99 "xchgb %b0, %1" \
104 :"=q" (oldval), "=m" (lock->slock) \ 100 :"=q" (oldval), "=m" (lock->slock) \
105 :"0" (oldval) : "memory" 101 :"0" (oldval) : "memory"
106 102
107static inline void _raw_spin_unlock(spinlock_t *lock) 103static inline void __raw_spin_unlock(raw_spinlock_t *lock)
108{ 104{
109 char oldval = 1; 105 char oldval = 1;
110#ifdef CONFIG_DEBUG_SPINLOCK
111 BUG_ON(lock->magic != SPINLOCK_MAGIC);
112 BUG_ON(!spin_is_locked(lock));
113#endif
114 __asm__ __volatile__(
115 spin_unlock_string
116 );
117}
118 106
119#endif
120
121static inline int _raw_spin_trylock(spinlock_t *lock)
122{
123 char oldval;
124 __asm__ __volatile__( 107 __asm__ __volatile__(
125 "xchgb %b0,%1" 108 __raw_spin_unlock_string
126 :"=q" (oldval), "=m" (lock->slock) 109 );
127 :"0" (0) : "memory");
128 return oldval > 0;
129} 110}
130 111
131static inline void _raw_spin_lock(spinlock_t *lock)
132{
133#ifdef CONFIG_DEBUG_SPINLOCK
134 if (unlikely(lock->magic != SPINLOCK_MAGIC)) {
135 printk("eip: %p\n", __builtin_return_address(0));
136 BUG();
137 }
138#endif 112#endif
139 __asm__ __volatile__(
140 spin_lock_string
141 :"=m" (lock->slock) : : "memory");
142}
143 113
144static inline void _raw_spin_lock_flags (spinlock_t *lock, unsigned long flags) 114#define __raw_spin_unlock_wait(lock) \
145{ 115 do { while (__raw_spin_is_locked(lock)) cpu_relax(); } while (0)
146#ifdef CONFIG_DEBUG_SPINLOCK
147 if (unlikely(lock->magic != SPINLOCK_MAGIC)) {
148 printk("eip: %p\n", __builtin_return_address(0));
149 BUG();
150 }
151#endif
152 __asm__ __volatile__(
153 spin_lock_string_flags
154 :"=m" (lock->slock) : "r" (flags) : "memory");
155}
156 116
157/* 117/*
158 * Read-write spinlocks, allowing multiple readers 118 * Read-write spinlocks, allowing multiple readers
@@ -163,72 +123,41 @@ static inline void _raw_spin_lock_flags (spinlock_t *lock, unsigned long flags)
163 * can "mix" irq-safe locks - any writer needs to get a 123 * can "mix" irq-safe locks - any writer needs to get a
164 * irq-safe write-lock, but readers can get non-irqsafe 124 * irq-safe write-lock, but readers can get non-irqsafe
165 * read-locks. 125 * read-locks.
126 *
127 * On x86, we implement read-write locks as a 32-bit counter
128 * with the high bit (sign) being the "contended" bit.
129 *
130 * The inline assembly is non-obvious. Think about it.
131 *
132 * Changed to use the same technique as rw semaphores. See
133 * semaphore.h for details. -ben
134 *
135 * the helpers are in arch/i386/kernel/semaphore.c
166 */ 136 */
167typedef struct {
168 volatile unsigned int lock;
169#ifdef CONFIG_DEBUG_SPINLOCK
170 unsigned magic;
171#endif
172#ifdef CONFIG_PREEMPT
173 unsigned int break_lock;
174#endif
175} rwlock_t;
176
177#define RWLOCK_MAGIC 0xdeaf1eed
178
179#ifdef CONFIG_DEBUG_SPINLOCK
180#define RWLOCK_MAGIC_INIT , RWLOCK_MAGIC
181#else
182#define RWLOCK_MAGIC_INIT /* */
183#endif
184
185#define RW_LOCK_UNLOCKED (rwlock_t) { RW_LOCK_BIAS RWLOCK_MAGIC_INIT }
186
187#define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0)
188 137
189/** 138/**
190 * read_can_lock - would read_trylock() succeed? 139 * read_can_lock - would read_trylock() succeed?
191 * @lock: the rwlock in question. 140 * @lock: the rwlock in question.
192 */ 141 */
193#define read_can_lock(x) ((int)(x)->lock > 0) 142#define __raw_read_can_lock(x) ((int)(x)->lock > 0)
194 143
195/** 144/**
196 * write_can_lock - would write_trylock() succeed? 145 * write_can_lock - would write_trylock() succeed?
197 * @lock: the rwlock in question. 146 * @lock: the rwlock in question.
198 */ 147 */
199#define write_can_lock(x) ((x)->lock == RW_LOCK_BIAS) 148#define __raw_write_can_lock(x) ((x)->lock == RW_LOCK_BIAS)
200 149
201/* 150static inline void __raw_read_lock(raw_rwlock_t *rw)
202 * On x86, we implement read-write locks as a 32-bit counter
203 * with the high bit (sign) being the "contended" bit.
204 *
205 * The inline assembly is non-obvious. Think about it.
206 *
207 * Changed to use the same technique as rw semaphores. See
208 * semaphore.h for details. -ben
209 */
210/* the spinlock helpers are in arch/i386/kernel/semaphore.c */
211
212static inline void _raw_read_lock(rwlock_t *rw)
213{ 151{
214#ifdef CONFIG_DEBUG_SPINLOCK
215 BUG_ON(rw->magic != RWLOCK_MAGIC);
216#endif
217 __build_read_lock(rw, "__read_lock_failed"); 152 __build_read_lock(rw, "__read_lock_failed");
218} 153}
219 154
220static inline void _raw_write_lock(rwlock_t *rw) 155static inline void __raw_write_lock(raw_rwlock_t *rw)
221{ 156{
222#ifdef CONFIG_DEBUG_SPINLOCK
223 BUG_ON(rw->magic != RWLOCK_MAGIC);
224#endif
225 __build_write_lock(rw, "__write_lock_failed"); 157 __build_write_lock(rw, "__write_lock_failed");
226} 158}
227 159
228#define _raw_read_unlock(rw) asm volatile("lock ; incl %0" :"=m" ((rw)->lock) : : "memory") 160static inline int __raw_read_trylock(raw_rwlock_t *lock)
229#define _raw_write_unlock(rw) asm volatile("lock ; addl $" RW_LOCK_BIAS_STR ",%0":"=m" ((rw)->lock) : : "memory")
230
231static inline int _raw_read_trylock(rwlock_t *lock)
232{ 161{
233 atomic_t *count = (atomic_t *)lock; 162 atomic_t *count = (atomic_t *)lock;
234 atomic_dec(count); 163 atomic_dec(count);
@@ -238,7 +167,7 @@ static inline int _raw_read_trylock(rwlock_t *lock)
238 return 0; 167 return 0;
239} 168}
240 169
241static inline int _raw_write_trylock(rwlock_t *lock) 170static inline int __raw_write_trylock(raw_rwlock_t *lock)
242{ 171{
243 atomic_t *count = (atomic_t *)lock; 172 atomic_t *count = (atomic_t *)lock;
244 if (atomic_sub_and_test(RW_LOCK_BIAS, count)) 173 if (atomic_sub_and_test(RW_LOCK_BIAS, count))
@@ -247,4 +176,15 @@ static inline int _raw_write_trylock(rwlock_t *lock)
247 return 0; 176 return 0;
248} 177}
249 178
179static inline void __raw_read_unlock(raw_rwlock_t *rw)
180{
181 asm volatile("lock ; incl %0" :"=m" (rw->lock) : : "memory");
182}
183
184static inline void __raw_write_unlock(raw_rwlock_t *rw)
185{
186 asm volatile("lock ; addl $" RW_LOCK_BIAS_STR ", %0"
187 : "=m" (rw->lock) : : "memory");
188}
189
250#endif /* __ASM_SPINLOCK_H */ 190#endif /* __ASM_SPINLOCK_H */
diff --git a/include/asm-i386/spinlock_types.h b/include/asm-i386/spinlock_types.h
new file mode 100644
index 0000000000..59efe849f3
--- /dev/null
+++ b/include/asm-i386/spinlock_types.h
@@ -0,0 +1,20 @@
1#ifndef __ASM_SPINLOCK_TYPES_H
2#define __ASM_SPINLOCK_TYPES_H
3
4#ifndef __LINUX_SPINLOCK_TYPES_H
5# error "please don't include this file directly"
6#endif
7
8typedef struct {
9 volatile unsigned int slock;
10} raw_spinlock_t;
11
12#define __RAW_SPIN_LOCK_UNLOCKED { 1 }
13
14typedef struct {
15 volatile unsigned int lock;
16} raw_rwlock_t;
17
18#define __RAW_RW_LOCK_UNLOCKED { RW_LOCK_BIAS }
19
20#endif
diff --git a/include/asm-i386/thread_info.h b/include/asm-i386/thread_info.h
index e2cb9fa6f5..8fbf791651 100644
--- a/include/asm-i386/thread_info.h
+++ b/include/asm-i386/thread_info.h
@@ -48,7 +48,7 @@ struct thread_info {
48 48
49#else /* !__ASSEMBLY__ */ 49#else /* !__ASSEMBLY__ */
50 50
51#include <asm/asm_offsets.h> 51#include <asm/asm-offsets.h>
52 52
53#endif 53#endif
54 54
diff --git a/include/asm-i386/topology.h b/include/asm-i386/topology.h
index 2461b73178..0ec27c9e8e 100644
--- a/include/asm-i386/topology.h
+++ b/include/asm-i386/topology.h
@@ -60,7 +60,7 @@ static inline int node_to_first_cpu(int node)
60 return first_cpu(mask); 60 return first_cpu(mask);
61} 61}
62 62
63#define pcibus_to_node(bus) mp_bus_id_to_node[(bus)->number] 63#define pcibus_to_node(bus) ((long) (bus)->sysdata)
64#define pcibus_to_cpumask(bus) node_to_cpumask(pcibus_to_node(bus)) 64#define pcibus_to_cpumask(bus) node_to_cpumask(pcibus_to_node(bus))
65 65
66/* sched_domains SD_NODE_INIT for NUMAQ machines */ 66/* sched_domains SD_NODE_INIT for NUMAQ machines */
diff --git a/include/asm-i386/unistd.h b/include/asm-i386/unistd.h
index a7cb377745..fbaf90a396 100644
--- a/include/asm-i386/unistd.h
+++ b/include/asm-i386/unistd.h
@@ -332,7 +332,7 @@ type name(type1 arg1) \
332long __res; \ 332long __res; \
333__asm__ volatile ("int $0x80" \ 333__asm__ volatile ("int $0x80" \
334 : "=a" (__res) \ 334 : "=a" (__res) \
335 : "0" (__NR_##name),"b" ((long)(arg1))); \ 335 : "0" (__NR_##name),"b" ((long)(arg1)) : "memory"); \
336__syscall_return(type,__res); \ 336__syscall_return(type,__res); \
337} 337}
338 338
@@ -342,7 +342,7 @@ type name(type1 arg1,type2 arg2) \
342long __res; \ 342long __res; \
343__asm__ volatile ("int $0x80" \ 343__asm__ volatile ("int $0x80" \
344 : "=a" (__res) \ 344 : "=a" (__res) \
345 : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2))); \ 345 : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)) : "memory"); \
346__syscall_return(type,__res); \ 346__syscall_return(type,__res); \
347} 347}
348 348
@@ -353,7 +353,7 @@ long __res; \
353__asm__ volatile ("int $0x80" \ 353__asm__ volatile ("int $0x80" \
354 : "=a" (__res) \ 354 : "=a" (__res) \
355 : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ 355 : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
356 "d" ((long)(arg3))); \ 356 "d" ((long)(arg3)) : "memory"); \
357__syscall_return(type,__res); \ 357__syscall_return(type,__res); \
358} 358}
359 359
@@ -364,7 +364,7 @@ long __res; \
364__asm__ volatile ("int $0x80" \ 364__asm__ volatile ("int $0x80" \
365 : "=a" (__res) \ 365 : "=a" (__res) \
366 : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ 366 : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
367 "d" ((long)(arg3)),"S" ((long)(arg4))); \ 367 "d" ((long)(arg3)),"S" ((long)(arg4)) : "memory"); \
368__syscall_return(type,__res); \ 368__syscall_return(type,__res); \
369} 369}
370 370
@@ -376,7 +376,7 @@ long __res; \
376__asm__ volatile ("int $0x80" \ 376__asm__ volatile ("int $0x80" \
377 : "=a" (__res) \ 377 : "=a" (__res) \
378 : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ 378 : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
379 "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \ 379 "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)) : "memory"); \
380__syscall_return(type,__res); \ 380__syscall_return(type,__res); \
381} 381}
382 382
@@ -389,7 +389,7 @@ __asm__ volatile ("push %%ebp ; movl %%eax,%%ebp ; movl %1,%%eax ; int $0x80 ; p
389 : "=a" (__res) \ 389 : "=a" (__res) \
390 : "i" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ 390 : "i" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
391 "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)), \ 391 "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)), \
392 "0" ((long)(arg6))); \ 392 "0" ((long)(arg6)) : "memory"); \
393__syscall_return(type,__res); \ 393__syscall_return(type,__res); \
394} 394}
395 395
diff --git a/include/asm-ia64/mca.h b/include/asm-ia64/mca.h
index 149ad01184..97a28b8b2d 100644
--- a/include/asm-ia64/mca.h
+++ b/include/asm-ia64/mca.h
@@ -11,8 +11,6 @@
11#ifndef _ASM_IA64_MCA_H 11#ifndef _ASM_IA64_MCA_H
12#define _ASM_IA64_MCA_H 12#define _ASM_IA64_MCA_H
13 13
14#define IA64_MCA_STACK_SIZE 8192
15
16#if !defined(__ASSEMBLY__) 14#if !defined(__ASSEMBLY__)
17 15
18#include <linux/interrupt.h> 16#include <linux/interrupt.h>
@@ -48,7 +46,8 @@ typedef union cmcv_reg_u {
48 46
49enum { 47enum {
50 IA64_MCA_RENDEZ_CHECKIN_NOTDONE = 0x0, 48 IA64_MCA_RENDEZ_CHECKIN_NOTDONE = 0x0,
51 IA64_MCA_RENDEZ_CHECKIN_DONE = 0x1 49 IA64_MCA_RENDEZ_CHECKIN_DONE = 0x1,
50 IA64_MCA_RENDEZ_CHECKIN_INIT = 0x2,
52}; 51};
53 52
54/* Information maintained by the MC infrastructure */ 53/* Information maintained by the MC infrastructure */
@@ -63,18 +62,42 @@ typedef struct ia64_mc_info_s {
63 62
64} ia64_mc_info_t; 63} ia64_mc_info_t;
65 64
66typedef struct ia64_mca_sal_to_os_state_s { 65/* Handover state from SAL to OS and vice versa, for both MCA and INIT events.
67 u64 imsto_os_gp; /* GP of the os registered with the SAL */ 66 * Besides the handover state, it also contains some saved registers from the
68 u64 imsto_pal_proc; /* PAL_PROC entry point - physical addr */ 67 * time of the event.
69 u64 imsto_sal_proc; /* SAL_PROC entry point - physical addr */ 68 * Note: mca_asm.S depends on the precise layout of this structure.
70 u64 imsto_sal_gp; /* GP of the SAL - physical */ 69 */
71 u64 imsto_rendez_state; /* Rendez state information */ 70
72 u64 imsto_sal_check_ra; /* Return address in SAL_CHECK while going 71struct ia64_sal_os_state {
73 * back to SAL from OS after MCA handling. 72 /* SAL to OS, must be at offset 0 */
74 */ 73 u64 os_gp; /* GP of the os registered with the SAL, physical */
75 u64 pal_min_state; /* from PAL in r17 */ 74 u64 pal_proc; /* PAL_PROC entry point, physical */
76 u64 proc_state_param; /* from PAL in r18. See SDV 2:268 11.3.2.1 */ 75 u64 sal_proc; /* SAL_PROC entry point, physical */
77} ia64_mca_sal_to_os_state_t; 76 u64 rv_rc; /* MCA - Rendezvous state, INIT - reason code */
77 u64 proc_state_param; /* from R18 */
78 u64 monarch; /* 1 for a monarch event, 0 for a slave */
79 /* common, must follow SAL to OS */
80 u64 sal_ra; /* Return address in SAL, physical */
81 u64 sal_gp; /* GP of the SAL - physical */
82 pal_min_state_area_t *pal_min_state; /* from R17. physical in asm, virtual in C */
83 u64 prev_IA64_KR_CURRENT; /* previous value of IA64_KR(CURRENT) */
84 struct task_struct *prev_task; /* previous task, NULL if it is not useful */
85 /* Some interrupt registers are not saved in minstate, pt_regs or
86 * switch_stack. Because MCA/INIT can occur when interrupts are
87 * disabled, we need to save the additional interrupt registers over
88 * MCA/INIT and resume.
89 */
90 u64 isr;
91 u64 ifa;
92 u64 itir;
93 u64 iipa;
94 u64 iim;
95 u64 iha;
96 /* OS to SAL, must follow common */
97 u64 os_status; /* OS status to SAL, enum below */
98 u64 context; /* 0 if return to same context
99 1 if return to new context */
100};
78 101
79enum { 102enum {
80 IA64_MCA_CORRECTED = 0x0, /* Error has been corrected by OS_MCA */ 103 IA64_MCA_CORRECTED = 0x0, /* Error has been corrected by OS_MCA */
@@ -84,35 +107,21 @@ enum {
84}; 107};
85 108
86enum { 109enum {
110 IA64_INIT_RESUME = 0x0, /* Resume after return from INIT */
111 IA64_INIT_WARM_BOOT = -1, /* Warm boot of the system need from SAL */
112};
113
114enum {
87 IA64_MCA_SAME_CONTEXT = 0x0, /* SAL to return to same context */ 115 IA64_MCA_SAME_CONTEXT = 0x0, /* SAL to return to same context */
88 IA64_MCA_NEW_CONTEXT = -1 /* SAL to return to new context */ 116 IA64_MCA_NEW_CONTEXT = -1 /* SAL to return to new context */
89}; 117};
90 118
91typedef struct ia64_mca_os_to_sal_state_s {
92 u64 imots_os_status; /* OS status to SAL as to what happened
93 * with the MCA handling.
94 */
95 u64 imots_sal_gp; /* GP of the SAL - physical */
96 u64 imots_context; /* 0 if return to same context
97 1 if return to new context */
98 u64 *imots_new_min_state; /* Pointer to structure containing
99 * new values of registers in the min state
100 * save area.
101 */
102 u64 imots_sal_check_ra; /* Return address in SAL_CHECK while going
103 * back to SAL from OS after MCA handling.
104 */
105} ia64_mca_os_to_sal_state_t;
106
107/* Per-CPU MCA state that is too big for normal per-CPU variables. */ 119/* Per-CPU MCA state that is too big for normal per-CPU variables. */
108 120
109struct ia64_mca_cpu { 121struct ia64_mca_cpu {
110 u64 stack[IA64_MCA_STACK_SIZE/8]; /* MCA memory-stack */ 122 u64 mca_stack[KERNEL_STACK_SIZE/8];
111 u64 proc_state_dump[512];
112 u64 stackframe[32];
113 u64 rbstore[IA64_MCA_STACK_SIZE/8]; /* MCA reg.-backing store */
114 u64 init_stack[KERNEL_STACK_SIZE/8]; 123 u64 init_stack[KERNEL_STACK_SIZE/8];
115} __attribute__ ((aligned(16))); 124};
116 125
117/* Array of physical addresses of each CPU's MCA area. */ 126/* Array of physical addresses of each CPU's MCA area. */
118extern unsigned long __per_cpu_mca[NR_CPUS]; 127extern unsigned long __per_cpu_mca[NR_CPUS];
@@ -121,12 +130,29 @@ extern void ia64_mca_init(void);
121extern void ia64_mca_cpu_init(void *); 130extern void ia64_mca_cpu_init(void *);
122extern void ia64_os_mca_dispatch(void); 131extern void ia64_os_mca_dispatch(void);
123extern void ia64_os_mca_dispatch_end(void); 132extern void ia64_os_mca_dispatch_end(void);
124extern void ia64_mca_ucmc_handler(void); 133extern void ia64_mca_ucmc_handler(struct pt_regs *, struct ia64_sal_os_state *);
134extern void ia64_init_handler(struct pt_regs *,
135 struct switch_stack *,
136 struct ia64_sal_os_state *);
125extern void ia64_monarch_init_handler(void); 137extern void ia64_monarch_init_handler(void);
126extern void ia64_slave_init_handler(void); 138extern void ia64_slave_init_handler(void);
127extern void ia64_mca_cmc_vector_setup(void); 139extern void ia64_mca_cmc_vector_setup(void);
128extern int ia64_reg_MCA_extension(void*); 140extern int ia64_reg_MCA_extension(int (*fn)(void *, struct ia64_sal_os_state *));
129extern void ia64_unreg_MCA_extension(void); 141extern void ia64_unreg_MCA_extension(void);
142extern u64 ia64_get_rnat(u64 *);
143
144#else /* __ASSEMBLY__ */
145
146#define IA64_MCA_CORRECTED 0x0 /* Error has been corrected by OS_MCA */
147#define IA64_MCA_WARM_BOOT -1 /* Warm boot of the system need from SAL */
148#define IA64_MCA_COLD_BOOT -2 /* Cold boot of the system need from SAL */
149#define IA64_MCA_HALT -3 /* System to be halted by SAL */
150
151#define IA64_INIT_RESUME 0x0 /* Resume after return from INIT */
152#define IA64_INIT_WARM_BOOT -1 /* Warm boot of the system need from SAL */
153
154#define IA64_MCA_SAME_CONTEXT 0x0 /* SAL to return to same context */
155#define IA64_MCA_NEW_CONTEXT -1 /* SAL to return to new context */
130 156
131#endif /* !__ASSEMBLY__ */ 157#endif /* !__ASSEMBLY__ */
132#endif /* _ASM_IA64_MCA_H */ 158#endif /* _ASM_IA64_MCA_H */
diff --git a/include/asm-ia64/mca_asm.h b/include/asm-ia64/mca_asm.h
index 836953e0f9..27c9203d8c 100644
--- a/include/asm-ia64/mca_asm.h
+++ b/include/asm-ia64/mca_asm.h
@@ -8,6 +8,8 @@
8 * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com> 8 * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
9 * Copyright (C) 2002 Intel Corp. 9 * Copyright (C) 2002 Intel Corp.
10 * Copyright (C) 2002 Jenna Hall <jenna.s.hall@intel.com> 10 * Copyright (C) 2002 Jenna Hall <jenna.s.hall@intel.com>
11 * Copyright (C) 2005 Silicon Graphics, Inc
12 * Copyright (C) 2005 Keith Owens <kaos@sgi.com>
11 */ 13 */
12#ifndef _ASM_IA64_MCA_ASM_H 14#ifndef _ASM_IA64_MCA_ASM_H
13#define _ASM_IA64_MCA_ASM_H 15#define _ASM_IA64_MCA_ASM_H
@@ -207,106 +209,33 @@
207 ;; 209 ;;
208 210
209/* 211/*
210 * The following offsets capture the order in which the 212 * The MCA and INIT stacks in struct ia64_mca_cpu look like normal kernel
211 * RSE related registers from the old context are 213 * stacks, except that the SAL/OS state and a switch_stack are stored near the
212 * saved onto the new stack frame. 214 * top of the MCA/INIT stack. To support concurrent entry to MCA or INIT, as
215 * well as MCA over INIT, each event needs its own SAL/OS state. All entries
216 * are 16 byte aligned.
213 * 217 *
214 * +-----------------------+ 218 * +---------------------------+
215 * |NDIRTY [BSP - BSPSTORE]| 219 * | pt_regs |
216 * +-----------------------+ 220 * +---------------------------+
217 * | RNAT | 221 * | switch_stack |
218 * +-----------------------+ 222 * +---------------------------+
219 * | BSPSTORE | 223 * | SAL/OS state |
220 * +-----------------------+ 224 * +---------------------------+
221 * | IFS | 225 * | 16 byte scratch area |
222 * +-----------------------+ 226 * +---------------------------+ <-------- SP at start of C MCA handler
223 * | PFS | 227 * | ..... |
224 * +-----------------------+ 228 * +---------------------------+
225 * | RSC | 229 * | RBS for MCA/INIT handler |
226 * +-----------------------+ <-------- Bottom of new stack frame 230 * +---------------------------+
231 * | struct task for MCA/INIT |
232 * +---------------------------+ <-------- Bottom of MCA/INIT stack
227 */ 233 */
228#define rse_rsc_offset 0
229#define rse_pfs_offset (rse_rsc_offset+0x08)
230#define rse_ifs_offset (rse_pfs_offset+0x08)
231#define rse_bspstore_offset (rse_ifs_offset+0x08)
232#define rse_rnat_offset (rse_bspstore_offset+0x08)
233#define rse_ndirty_offset (rse_rnat_offset+0x08)
234 234
235/* 235#define ALIGN16(x) ((x)&~15)
236 * rse_switch_context 236#define MCA_PT_REGS_OFFSET ALIGN16(KERNEL_STACK_SIZE-IA64_PT_REGS_SIZE)
237 * 237#define MCA_SWITCH_STACK_OFFSET ALIGN16(MCA_PT_REGS_OFFSET-IA64_SWITCH_STACK_SIZE)
238 * 1. Save old RSC onto the new stack frame 238#define MCA_SOS_OFFSET ALIGN16(MCA_SWITCH_STACK_OFFSET-IA64_SAL_OS_STATE_SIZE)
239 * 2. Save PFS onto new stack frame 239#define MCA_SP_OFFSET ALIGN16(MCA_SOS_OFFSET-16)
240 * 3. Cover the old frame and start a new frame.
241 * 4. Save IFS onto new stack frame
242 * 5. Save the old BSPSTORE on the new stack frame
243 * 6. Save the old RNAT on the new stack frame
244 * 7. Write BSPSTORE with the new backing store pointer
245 * 8. Read and save the new BSP to calculate the #dirty registers
246 * NOTE: Look at pages 11-10, 11-11 in PRM Vol 2
247 */
248#define rse_switch_context(temp,p_stackframe,p_bspstore) \
249 ;; \
250 mov temp=ar.rsc;; \
251 st8 [p_stackframe]=temp,8;; \
252 mov temp=ar.pfs;; \
253 st8 [p_stackframe]=temp,8; \
254 cover ;; \
255 mov temp=cr.ifs;; \
256 st8 [p_stackframe]=temp,8;; \
257 mov temp=ar.bspstore;; \
258 st8 [p_stackframe]=temp,8;; \
259 mov temp=ar.rnat;; \
260 st8 [p_stackframe]=temp,8; \
261 mov ar.bspstore=p_bspstore;; \
262 mov temp=ar.bsp;; \
263 sub temp=temp,p_bspstore;; \
264 st8 [p_stackframe]=temp,8;;
265
266/*
267 * rse_return_context
268 * 1. Allocate a zero-sized frame
269 * 2. Store the number of dirty registers RSC.loadrs field
270 * 3. Issue a loadrs to insure that any registers from the interrupted
271 * context which were saved on the new stack frame have been loaded
272 * back into the stacked registers
273 * 4. Restore BSPSTORE
274 * 5. Restore RNAT
275 * 6. Restore PFS
276 * 7. Restore IFS
277 * 8. Restore RSC
278 * 9. Issue an RFI
279 */
280#define rse_return_context(psr_mask_reg,temp,p_stackframe) \
281 ;; \
282 alloc temp=ar.pfs,0,0,0,0; \
283 add p_stackframe=rse_ndirty_offset,p_stackframe;; \
284 ld8 temp=[p_stackframe];; \
285 shl temp=temp,16;; \
286 mov ar.rsc=temp;; \
287 loadrs;; \
288 add p_stackframe=-rse_ndirty_offset+rse_bspstore_offset,p_stackframe;;\
289 ld8 temp=[p_stackframe];; \
290 mov ar.bspstore=temp;; \
291 add p_stackframe=-rse_bspstore_offset+rse_rnat_offset,p_stackframe;;\
292 ld8 temp=[p_stackframe];; \
293 mov ar.rnat=temp;; \
294 add p_stackframe=-rse_rnat_offset+rse_pfs_offset,p_stackframe;; \
295 ld8 temp=[p_stackframe];; \
296 mov ar.pfs=temp;; \
297 add p_stackframe=-rse_pfs_offset+rse_ifs_offset,p_stackframe;; \
298 ld8 temp=[p_stackframe];; \
299 mov cr.ifs=temp;; \
300 add p_stackframe=-rse_ifs_offset+rse_rsc_offset,p_stackframe;; \
301 ld8 temp=[p_stackframe];; \
302 mov ar.rsc=temp ; \
303 mov temp=psr;; \
304 or temp=temp,psr_mask_reg;; \
305 mov cr.ipsr=temp;; \
306 mov temp=ip;; \
307 add temp=0x30,temp;; \
308 mov cr.iip=temp;; \
309 srlz.i;; \
310 rfi;;
311 240
312#endif /* _ASM_IA64_MCA_ASM_H */ 241#endif /* _ASM_IA64_MCA_ASM_H */
diff --git a/include/asm-ia64/ptrace.h b/include/asm-ia64/ptrace.h
index 0bef195384..fc544929ac 100644
--- a/include/asm-ia64/ptrace.h
+++ b/include/asm-ia64/ptrace.h
@@ -57,7 +57,7 @@
57#include <linux/config.h> 57#include <linux/config.h>
58 58
59#include <asm/fpu.h> 59#include <asm/fpu.h>
60#include <asm/offsets.h> 60#include <asm/asm-offsets.h>
61 61
62/* 62/*
63 * Base-2 logarithm of number of pages to allocate per task structure 63 * Base-2 logarithm of number of pages to allocate per task structure
@@ -119,7 +119,7 @@ struct pt_regs {
119 unsigned long ar_unat; /* interrupted task's NaT register (preserved) */ 119 unsigned long ar_unat; /* interrupted task's NaT register (preserved) */
120 unsigned long ar_pfs; /* prev function state */ 120 unsigned long ar_pfs; /* prev function state */
121 unsigned long ar_rsc; /* RSE configuration */ 121 unsigned long ar_rsc; /* RSE configuration */
122 /* The following two are valid only if cr_ipsr.cpl > 0: */ 122 /* The following two are valid only if cr_ipsr.cpl > 0 || ti->flags & _TIF_MCA_INIT */
123 unsigned long ar_rnat; /* RSE NaT */ 123 unsigned long ar_rnat; /* RSE NaT */
124 unsigned long ar_bspstore; /* RSE bspstore */ 124 unsigned long ar_bspstore; /* RSE bspstore */
125 125
diff --git a/include/asm-ia64/sn/sn_feature_sets.h b/include/asm-ia64/sn/sn_feature_sets.h
new file mode 100644
index 0000000000..e68a80853d
--- /dev/null
+++ b/include/asm-ia64/sn/sn_feature_sets.h
@@ -0,0 +1,57 @@
1#ifndef _ASM_IA64_SN_FEATURE_SETS_H
2#define _ASM_IA64_SN_FEATURE_SETS_H
3
4/*
5 * SN PROM Features
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 *
11 * Copyright (c) 2005 Silicon Graphics, Inc. All rights reserved.
12 */
13
14
15#include <asm/types.h>
16#include <asm/bitops.h>
17
18/* --------------------- PROM Features -----------------------------*/
19extern int sn_prom_feature_available(int id);
20
21#define MAX_PROM_FEATURE_SETS 2
22
23/*
24 * The following defines features that may or may not be supported by the
25 * current PROM. The OS uses sn_prom_feature_available(feature) to test for
26 * the presence of a PROM feature. Down rev (old) PROMs will always test
27 * "false" for new features.
28 *
29 * Use:
30 * if (sn_prom_feature_available(PRF_FEATURE_XXX))
31 * ...
32 */
33
34/*
35 * Example: feature XXX
36 */
37#define PRF_FEATURE_XXX 0
38
39
40
41/* --------------------- OS Features -------------------------------*/
42
43/*
44 * The following defines OS features that are optionally present in
45 * the operating system.
46 * During boot, PROM is notified of these features via a series of calls:
47 *
48 * ia64_sn_set_os_feature(feature1);
49 *
50 * Once enabled, a feature cannot be disabled.
51 *
52 * By default, features are disabled unless explicitly enabled.
53 */
54#define OSF_MCA_SLV_TO_OS_INIT_SLV 0
55#define OSF_FEAT_LOG_SBES 1
56
57#endif /* _ASM_IA64_SN_FEATURE_SETS_H */
diff --git a/include/asm-ia64/sn/sn_sal.h b/include/asm-ia64/sn/sn_sal.h
index e67825ad19..fea35b33d4 100644
--- a/include/asm-ia64/sn/sn_sal.h
+++ b/include/asm-ia64/sn/sn_sal.h
@@ -80,6 +80,9 @@
80#define SN_SAL_RESERVED_DO_NOT_USE 0x02000062 80#define SN_SAL_RESERVED_DO_NOT_USE 0x02000062
81#define SN_SAL_IOIF_GET_PCI_TOPOLOGY 0x02000064 81#define SN_SAL_IOIF_GET_PCI_TOPOLOGY 0x02000064
82 82
83#define SN_SAL_GET_PROM_FEATURE_SET 0x02000065
84#define SN_SAL_SET_OS_FEATURE_SET 0x02000066
85
83/* 86/*
84 * Service-specific constants 87 * Service-specific constants
85 */ 88 */
@@ -118,8 +121,8 @@
118/* 121/*
119 * Error Handling Features 122 * Error Handling Features
120 */ 123 */
121#define SAL_ERR_FEAT_MCA_SLV_TO_OS_INIT_SLV 0x1 124#define SAL_ERR_FEAT_MCA_SLV_TO_OS_INIT_SLV 0x1 // obsolete
122#define SAL_ERR_FEAT_LOG_SBES 0x2 125#define SAL_ERR_FEAT_LOG_SBES 0x2 // obsolete
123#define SAL_ERR_FEAT_MFR_OVERRIDE 0x4 126#define SAL_ERR_FEAT_MFR_OVERRIDE 0x4
124#define SAL_ERR_FEAT_SBE_THRESHOLD 0xffff0000 127#define SAL_ERR_FEAT_SBE_THRESHOLD 0xffff0000
125 128
@@ -152,12 +155,6 @@ sn_sal_rev(void)
152} 155}
153 156
154/* 157/*
155 * Specify the minimum PROM revsion required for this kernel.
156 * Note that they're stored in hex format...
157 */
158#define SN_SAL_MIN_VERSION 0x0404
159
160/*
161 * Returns the master console nasid, if the call fails, return an illegal 158 * Returns the master console nasid, if the call fails, return an illegal
162 * value. 159 * value.
163 */ 160 */
@@ -336,7 +333,7 @@ ia64_sn_plat_cpei_handler(void)
336} 333}
337 334
338/* 335/*
339 * Set Error Handling Features 336 * Set Error Handling Features (Obsolete)
340 */ 337 */
341static inline u64 338static inline u64
342ia64_sn_plat_set_error_handling_features(void) 339ia64_sn_plat_set_error_handling_features(void)
@@ -1052,4 +1049,25 @@ ia64_sn_is_fake_prom(void)
1052 return (rv.status == 0); 1049 return (rv.status == 0);
1053} 1050}
1054 1051
1052static inline int
1053ia64_sn_get_prom_feature_set(int set, unsigned long *feature_set)
1054{
1055 struct ia64_sal_retval rv;
1056
1057 SAL_CALL_NOLOCK(rv, SN_SAL_GET_PROM_FEATURE_SET, set, 0, 0, 0, 0, 0, 0);
1058 if (rv.status != 0)
1059 return rv.status;
1060 *feature_set = rv.v0;
1061 return 0;
1062}
1063
1064static inline int
1065ia64_sn_set_os_feature(int feature)
1066{
1067 struct ia64_sal_retval rv;
1068
1069 SAL_CALL_NOLOCK(rv, SN_SAL_SET_OS_FEATURE_SET, feature, 0, 0, 0, 0, 0, 0);
1070 return rv.status;
1071}
1072
1055#endif /* _ASM_IA64_SN_SN_SAL_H */ 1073#endif /* _ASM_IA64_SN_SN_SAL_H */
diff --git a/include/asm-ia64/spinlock.h b/include/asm-ia64/spinlock.h
index d2430aa0d4..5b78611411 100644
--- a/include/asm-ia64/spinlock.h
+++ b/include/asm-ia64/spinlock.h
@@ -17,28 +17,20 @@
17#include <asm/intrinsics.h> 17#include <asm/intrinsics.h>
18#include <asm/system.h> 18#include <asm/system.h>
19 19
20typedef struct { 20#define __raw_spin_lock_init(x) ((x)->lock = 0)
21 volatile unsigned int lock;
22#ifdef CONFIG_PREEMPT
23 unsigned int break_lock;
24#endif
25} spinlock_t;
26
27#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 }
28#define spin_lock_init(x) ((x)->lock = 0)
29 21
30#ifdef ASM_SUPPORTED 22#ifdef ASM_SUPPORTED
31/* 23/*
32 * Try to get the lock. If we fail to get the lock, make a non-standard call to 24 * Try to get the lock. If we fail to get the lock, make a non-standard call to
33 * ia64_spinlock_contention(). We do not use a normal call because that would force all 25 * ia64_spinlock_contention(). We do not use a normal call because that would force all
34 * callers of spin_lock() to be non-leaf routines. Instead, ia64_spinlock_contention() is 26 * callers of __raw_spin_lock() to be non-leaf routines. Instead, ia64_spinlock_contention() is
35 * carefully coded to touch only those registers that spin_lock() marks "clobbered". 27 * carefully coded to touch only those registers that __raw_spin_lock() marks "clobbered".
36 */ 28 */
37 29
38#define IA64_SPINLOCK_CLOBBERS "ar.ccv", "ar.pfs", "p14", "p15", "r27", "r28", "r29", "r30", "b6", "memory" 30#define IA64_SPINLOCK_CLOBBERS "ar.ccv", "ar.pfs", "p14", "p15", "r27", "r28", "r29", "r30", "b6", "memory"
39 31
40static inline void 32static inline void
41_raw_spin_lock_flags (spinlock_t *lock, unsigned long flags) 33__raw_spin_lock_flags (raw_spinlock_t *lock, unsigned long flags)
42{ 34{
43 register volatile unsigned int *ptr asm ("r31") = &lock->lock; 35 register volatile unsigned int *ptr asm ("r31") = &lock->lock;
44 36
@@ -94,17 +86,17 @@ _raw_spin_lock_flags (spinlock_t *lock, unsigned long flags)
94#endif 86#endif
95} 87}
96 88
97#define _raw_spin_lock(lock) _raw_spin_lock_flags(lock, 0) 89#define __raw_spin_lock(lock) __raw_spin_lock_flags(lock, 0)
98 90
99/* Unlock by doing an ordered store and releasing the cacheline with nta */ 91/* Unlock by doing an ordered store and releasing the cacheline with nta */
100static inline void _raw_spin_unlock(spinlock_t *x) { 92static inline void __raw_spin_unlock(raw_spinlock_t *x) {
101 barrier(); 93 barrier();
102 asm volatile ("st4.rel.nta [%0] = r0\n\t" :: "r"(x)); 94 asm volatile ("st4.rel.nta [%0] = r0\n\t" :: "r"(x));
103} 95}
104 96
105#else /* !ASM_SUPPORTED */ 97#else /* !ASM_SUPPORTED */
106#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock) 98#define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
107# define _raw_spin_lock(x) \ 99# define __raw_spin_lock(x) \
108do { \ 100do { \
109 __u32 *ia64_spinlock_ptr = (__u32 *) (x); \ 101 __u32 *ia64_spinlock_ptr = (__u32 *) (x); \
110 __u64 ia64_spinlock_val; \ 102 __u64 ia64_spinlock_val; \
@@ -117,29 +109,20 @@ do { \
117 } while (ia64_spinlock_val); \ 109 } while (ia64_spinlock_val); \
118 } \ 110 } \
119} while (0) 111} while (0)
120#define _raw_spin_unlock(x) do { barrier(); ((spinlock_t *) x)->lock = 0; } while (0) 112#define __raw_spin_unlock(x) do { barrier(); ((raw_spinlock_t *) x)->lock = 0; } while (0)
121#endif /* !ASM_SUPPORTED */ 113#endif /* !ASM_SUPPORTED */
122 114
123#define spin_is_locked(x) ((x)->lock != 0) 115#define __raw_spin_is_locked(x) ((x)->lock != 0)
124#define _raw_spin_trylock(x) (cmpxchg_acq(&(x)->lock, 0, 1) == 0) 116#define __raw_spin_trylock(x) (cmpxchg_acq(&(x)->lock, 0, 1) == 0)
125#define spin_unlock_wait(x) do { barrier(); } while ((x)->lock) 117#define __raw_spin_unlock_wait(lock) \
126 118 do { while (__raw_spin_is_locked(lock)) cpu_relax(); } while (0)
127typedef struct {
128 volatile unsigned int read_counter : 24;
129 volatile unsigned int write_lock : 8;
130#ifdef CONFIG_PREEMPT
131 unsigned int break_lock;
132#endif
133} rwlock_t;
134#define RW_LOCK_UNLOCKED (rwlock_t) { 0, 0 }
135 119
136#define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0) 120#define __raw_read_can_lock(rw) (*(volatile int *)(rw) >= 0)
137#define read_can_lock(rw) (*(volatile int *)(rw) >= 0) 121#define __raw_write_can_lock(rw) (*(volatile int *)(rw) == 0)
138#define write_can_lock(rw) (*(volatile int *)(rw) == 0)
139 122
140#define _raw_read_lock(rw) \ 123#define __raw_read_lock(rw) \
141do { \ 124do { \
142 rwlock_t *__read_lock_ptr = (rw); \ 125 raw_rwlock_t *__read_lock_ptr = (rw); \
143 \ 126 \
144 while (unlikely(ia64_fetchadd(1, (int *) __read_lock_ptr, acq) < 0)) { \ 127 while (unlikely(ia64_fetchadd(1, (int *) __read_lock_ptr, acq) < 0)) { \
145 ia64_fetchadd(-1, (int *) __read_lock_ptr, rel); \ 128 ia64_fetchadd(-1, (int *) __read_lock_ptr, rel); \
@@ -148,14 +131,14 @@ do { \
148 } \ 131 } \
149} while (0) 132} while (0)
150 133
151#define _raw_read_unlock(rw) \ 134#define __raw_read_unlock(rw) \
152do { \ 135do { \
153 rwlock_t *__read_lock_ptr = (rw); \ 136 raw_rwlock_t *__read_lock_ptr = (rw); \
154 ia64_fetchadd(-1, (int *) __read_lock_ptr, rel); \ 137 ia64_fetchadd(-1, (int *) __read_lock_ptr, rel); \
155} while (0) 138} while (0)
156 139
157#ifdef ASM_SUPPORTED 140#ifdef ASM_SUPPORTED
158#define _raw_write_lock(rw) \ 141#define __raw_write_lock(rw) \
159do { \ 142do { \
160 __asm__ __volatile__ ( \ 143 __asm__ __volatile__ ( \
161 "mov ar.ccv = r0\n" \ 144 "mov ar.ccv = r0\n" \
@@ -170,7 +153,7 @@ do { \
170 :: "r"(rw) : "ar.ccv", "p7", "r2", "r29", "memory"); \ 153 :: "r"(rw) : "ar.ccv", "p7", "r2", "r29", "memory"); \
171} while(0) 154} while(0)
172 155
173#define _raw_write_trylock(rw) \ 156#define __raw_write_trylock(rw) \
174({ \ 157({ \
175 register long result; \ 158 register long result; \
176 \ 159 \
@@ -182,7 +165,7 @@ do { \
182 (result == 0); \ 165 (result == 0); \
183}) 166})
184 167
185static inline void _raw_write_unlock(rwlock_t *x) 168static inline void __raw_write_unlock(raw_rwlock_t *x)
186{ 169{
187 u8 *y = (u8 *)x; 170 u8 *y = (u8 *)x;
188 barrier(); 171 barrier();
@@ -191,7 +174,7 @@ static inline void _raw_write_unlock(rwlock_t *x)
191 174
192#else /* !ASM_SUPPORTED */ 175#else /* !ASM_SUPPORTED */
193 176
194#define _raw_write_lock(l) \ 177#define __raw_write_lock(l) \
195({ \ 178({ \
196 __u64 ia64_val, ia64_set_val = ia64_dep_mi(-1, 0, 31, 1); \ 179 __u64 ia64_val, ia64_set_val = ia64_dep_mi(-1, 0, 31, 1); \
197 __u32 *ia64_write_lock_ptr = (__u32 *) (l); \ 180 __u32 *ia64_write_lock_ptr = (__u32 *) (l); \
@@ -202,7 +185,7 @@ static inline void _raw_write_unlock(rwlock_t *x)
202 } while (ia64_val); \ 185 } while (ia64_val); \
203}) 186})
204 187
205#define _raw_write_trylock(rw) \ 188#define __raw_write_trylock(rw) \
206({ \ 189({ \
207 __u64 ia64_val; \ 190 __u64 ia64_val; \
208 __u64 ia64_set_val = ia64_dep_mi(-1, 0, 31,1); \ 191 __u64 ia64_set_val = ia64_dep_mi(-1, 0, 31,1); \
@@ -210,7 +193,7 @@ static inline void _raw_write_unlock(rwlock_t *x)
210 (ia64_val == 0); \ 193 (ia64_val == 0); \
211}) 194})
212 195
213static inline void _raw_write_unlock(rwlock_t *x) 196static inline void __raw_write_unlock(raw_rwlock_t *x)
214{ 197{
215 barrier(); 198 barrier();
216 x->write_lock = 0; 199 x->write_lock = 0;
@@ -218,6 +201,6 @@ static inline void _raw_write_unlock(rwlock_t *x)
218 201
219#endif /* !ASM_SUPPORTED */ 202#endif /* !ASM_SUPPORTED */
220 203
221#define _raw_read_trylock(lock) generic_raw_read_trylock(lock) 204#define __raw_read_trylock(lock) generic__raw_read_trylock(lock)
222 205
223#endif /* _ASM_IA64_SPINLOCK_H */ 206#endif /* _ASM_IA64_SPINLOCK_H */
diff --git a/include/asm-ia64/spinlock_types.h b/include/asm-ia64/spinlock_types.h
new file mode 100644
index 0000000000..474e46f1ab
--- /dev/null
+++ b/include/asm-ia64/spinlock_types.h
@@ -0,0 +1,21 @@
1#ifndef _ASM_IA64_SPINLOCK_TYPES_H
2#define _ASM_IA64_SPINLOCK_TYPES_H
3
4#ifndef __LINUX_SPINLOCK_TYPES_H
5# error "please don't include this file directly"
6#endif
7
8typedef struct {
9 volatile unsigned int lock;
10} raw_spinlock_t;
11
12#define __RAW_SPIN_LOCK_UNLOCKED { 0 }
13
14typedef struct {
15 volatile unsigned int read_counter : 31;
16 volatile unsigned int write_lock : 1;
17} raw_rwlock_t;
18
19#define __RAW_RW_LOCK_UNLOCKED { 0, 0 }
20
21#endif
diff --git a/include/asm-ia64/system.h b/include/asm-ia64/system.h
index 33256db4a7..635235fa1e 100644
--- a/include/asm-ia64/system.h
+++ b/include/asm-ia64/system.h
@@ -275,6 +275,7 @@ extern void ia64_load_extra (struct task_struct *task);
275 */ 275 */
276#define __ARCH_WANT_UNLOCKED_CTXSW 276#define __ARCH_WANT_UNLOCKED_CTXSW
277 277
278#define ARCH_HAS_PREFETCH_SWITCH_STACK
278#define ia64_platform_is(x) (strcmp(x, platform_name) == 0) 279#define ia64_platform_is(x) (strcmp(x, platform_name) == 0)
279 280
280void cpu_idle_wait(void); 281void cpu_idle_wait(void);
diff --git a/include/asm-ia64/thread_info.h b/include/asm-ia64/thread_info.h
index 7dc8951708..cf4a950a0f 100644
--- a/include/asm-ia64/thread_info.h
+++ b/include/asm-ia64/thread_info.h
@@ -5,7 +5,7 @@
5#ifndef _ASM_IA64_THREAD_INFO_H 5#ifndef _ASM_IA64_THREAD_INFO_H
6#define _ASM_IA64_THREAD_INFO_H 6#define _ASM_IA64_THREAD_INFO_H
7 7
8#include <asm/offsets.h> 8#include <asm/asm-offsets.h>
9#include <asm/processor.h> 9#include <asm/processor.h>
10#include <asm/ptrace.h> 10#include <asm/ptrace.h>
11 11
@@ -76,6 +76,7 @@ struct thread_info {
76#define TIF_SIGDELAYED 5 /* signal delayed from MCA/INIT/NMI/PMI context */ 76#define TIF_SIGDELAYED 5 /* signal delayed from MCA/INIT/NMI/PMI context */
77#define TIF_POLLING_NRFLAG 16 /* true if poll_idle() is polling TIF_NEED_RESCHED */ 77#define TIF_POLLING_NRFLAG 16 /* true if poll_idle() is polling TIF_NEED_RESCHED */
78#define TIF_MEMDIE 17 78#define TIF_MEMDIE 17
79#define TIF_MCA_INIT 18 /* this task is processing MCA or INIT */
79 80
80#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) 81#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
81#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT) 82#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
@@ -85,6 +86,7 @@ struct thread_info {
85#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED) 86#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
86#define _TIF_SIGDELAYED (1 << TIF_SIGDELAYED) 87#define _TIF_SIGDELAYED (1 << TIF_SIGDELAYED)
87#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG) 88#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
89#define _TIF_MCA_INIT (1 << TIF_MCA_INIT)
88 90
89/* "work to do on user-return" bits */ 91/* "work to do on user-return" bits */
90#define TIF_ALLWORK_MASK (_TIF_NOTIFY_RESUME|_TIF_SIGPENDING|_TIF_NEED_RESCHED|_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SIGDELAYED) 92#define TIF_ALLWORK_MASK (_TIF_NOTIFY_RESUME|_TIF_SIGPENDING|_TIF_NEED_RESCHED|_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SIGDELAYED)
diff --git a/include/asm-ia64/unwind.h b/include/asm-ia64/unwind.h
index 61426ad3ec..5df0276b04 100644
--- a/include/asm-ia64/unwind.h
+++ b/include/asm-ia64/unwind.h
@@ -114,13 +114,6 @@ extern void unw_remove_unwind_table (void *handle);
114 */ 114 */
115extern void unw_init_from_blocked_task (struct unw_frame_info *info, struct task_struct *t); 115extern void unw_init_from_blocked_task (struct unw_frame_info *info, struct task_struct *t);
116 116
117/*
118 * Prepare to unwind from interruption. The pt-regs and switch-stack structures must have
119 * be "adjacent" (no state modifications between pt-regs and switch-stack).
120 */
121extern void unw_init_from_interruption (struct unw_frame_info *info, struct task_struct *t,
122 struct pt_regs *pt, struct switch_stack *sw);
123
124extern void unw_init_frame_info (struct unw_frame_info *info, struct task_struct *t, 117extern void unw_init_frame_info (struct unw_frame_info *info, struct task_struct *t,
125 struct switch_stack *sw); 118 struct switch_stack *sw);
126 119
diff --git a/include/asm-m32r/spinlock.h b/include/asm-m32r/spinlock.h
index 6608d8371c..7de7def28d 100644
--- a/include/asm-m32r/spinlock.h
+++ b/include/asm-m32r/spinlock.h
@@ -14,57 +14,30 @@
14#include <asm/atomic.h> 14#include <asm/atomic.h>
15#include <asm/page.h> 15#include <asm/page.h>
16 16
17extern int printk(const char * fmt, ...)
18 __attribute__ ((format (printf, 1, 2)));
19
20#define RW_LOCK_BIAS 0x01000000
21#define RW_LOCK_BIAS_STR "0x01000000"
22
23/* 17/*
24 * Your basic SMP spinlocks, allowing only a single CPU anywhere 18 * Your basic SMP spinlocks, allowing only a single CPU anywhere
25 */ 19 *
26 20 * (the type definitions are in asm/spinlock_types.h)
27typedef struct { 21 *
28 volatile int slock;
29#ifdef CONFIG_DEBUG_SPINLOCK
30 unsigned magic;
31#endif
32#ifdef CONFIG_PREEMPT
33 unsigned int break_lock;
34#endif
35} spinlock_t;
36
37#define SPINLOCK_MAGIC 0xdead4ead
38
39#ifdef CONFIG_DEBUG_SPINLOCK
40#define SPINLOCK_MAGIC_INIT , SPINLOCK_MAGIC
41#else
42#define SPINLOCK_MAGIC_INIT /* */
43#endif
44
45#define SPIN_LOCK_UNLOCKED (spinlock_t) { 1 SPINLOCK_MAGIC_INIT }
46
47#define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while(0)
48
49/*
50 * Simple spin lock operations. There are two variants, one clears IRQ's 22 * Simple spin lock operations. There are two variants, one clears IRQ's
51 * on the local processor, one does not. 23 * on the local processor, one does not.
52 * 24 *
53 * We make no fairness assumptions. They have a cost. 25 * We make no fairness assumptions. They have a cost.
54 */ 26 */
55 27
56#define spin_is_locked(x) (*(volatile int *)(&(x)->slock) <= 0) 28#define __raw_spin_is_locked(x) (*(volatile int *)(&(x)->slock) <= 0)
57#define spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x)) 29#define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
58#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock) 30#define __raw_spin_unlock_wait(x) \
31 do { cpu_relax(); } while (__raw_spin_is_locked(x))
59 32
60/** 33/**
61 * _raw_spin_trylock - Try spin lock and return a result 34 * __raw_spin_trylock - Try spin lock and return a result
62 * @lock: Pointer to the lock variable 35 * @lock: Pointer to the lock variable
63 * 36 *
64 * _raw_spin_trylock() tries to get the lock and returns a result. 37 * __raw_spin_trylock() tries to get the lock and returns a result.
65 * On the m32r, the result value is 1 (= Success) or 0 (= Failure). 38 * On the m32r, the result value is 1 (= Success) or 0 (= Failure).
66 */ 39 */
67static inline int _raw_spin_trylock(spinlock_t *lock) 40static inline int __raw_spin_trylock(raw_spinlock_t *lock)
68{ 41{
69 int oldval; 42 int oldval;
70 unsigned long tmp1, tmp2; 43 unsigned long tmp1, tmp2;
@@ -78,7 +51,7 @@ static inline int _raw_spin_trylock(spinlock_t *lock)
78 * } 51 * }
79 */ 52 */
80 __asm__ __volatile__ ( 53 __asm__ __volatile__ (
81 "# spin_trylock \n\t" 54 "# __raw_spin_trylock \n\t"
82 "ldi %1, #0; \n\t" 55 "ldi %1, #0; \n\t"
83 "mvfc %2, psw; \n\t" 56 "mvfc %2, psw; \n\t"
84 "clrpsw #0x40 -> nop; \n\t" 57 "clrpsw #0x40 -> nop; \n\t"
@@ -97,16 +70,10 @@ static inline int _raw_spin_trylock(spinlock_t *lock)
97 return (oldval > 0); 70 return (oldval > 0);
98} 71}
99 72
100static inline void _raw_spin_lock(spinlock_t *lock) 73static inline void __raw_spin_lock(raw_spinlock_t *lock)
101{ 74{
102 unsigned long tmp0, tmp1; 75 unsigned long tmp0, tmp1;
103 76
104#ifdef CONFIG_DEBUG_SPINLOCK
105 if (unlikely(lock->magic != SPINLOCK_MAGIC)) {
106 printk("pc: %p\n", __builtin_return_address(0));
107 BUG();
108 }
109#endif
110 /* 77 /*
111 * lock->slock : =1 : unlock 78 * lock->slock : =1 : unlock
112 * : <=0 : lock 79 * : <=0 : lock
@@ -118,7 +85,7 @@ static inline void _raw_spin_lock(spinlock_t *lock)
118 * } 85 * }
119 */ 86 */
120 __asm__ __volatile__ ( 87 __asm__ __volatile__ (
121 "# spin_lock \n\t" 88 "# __raw_spin_lock \n\t"
122 ".fillinsn \n" 89 ".fillinsn \n"
123 "1: \n\t" 90 "1: \n\t"
124 "mvfc %1, psw; \n\t" 91 "mvfc %1, psw; \n\t"
@@ -145,12 +112,8 @@ static inline void _raw_spin_lock(spinlock_t *lock)
145 ); 112 );
146} 113}
147 114
148static inline void _raw_spin_unlock(spinlock_t *lock) 115static inline void __raw_spin_unlock(raw_spinlock_t *lock)
149{ 116{
150#ifdef CONFIG_DEBUG_SPINLOCK
151 BUG_ON(lock->magic != SPINLOCK_MAGIC);
152 BUG_ON(!spin_is_locked(lock));
153#endif
154 mb(); 117 mb();
155 lock->slock = 1; 118 lock->slock = 1;
156} 119}
@@ -164,59 +127,32 @@ static inline void _raw_spin_unlock(spinlock_t *lock)
164 * can "mix" irq-safe locks - any writer needs to get a 127 * can "mix" irq-safe locks - any writer needs to get a
165 * irq-safe write-lock, but readers can get non-irqsafe 128 * irq-safe write-lock, but readers can get non-irqsafe
166 * read-locks. 129 * read-locks.
130 *
131 * On x86, we implement read-write locks as a 32-bit counter
132 * with the high bit (sign) being the "contended" bit.
133 *
134 * The inline assembly is non-obvious. Think about it.
135 *
136 * Changed to use the same technique as rw semaphores. See
137 * semaphore.h for details. -ben
167 */ 138 */
168typedef struct {
169 volatile int lock;
170#ifdef CONFIG_DEBUG_SPINLOCK
171 unsigned magic;
172#endif
173#ifdef CONFIG_PREEMPT
174 unsigned int break_lock;
175#endif
176} rwlock_t;
177
178#define RWLOCK_MAGIC 0xdeaf1eed
179
180#ifdef CONFIG_DEBUG_SPINLOCK
181#define RWLOCK_MAGIC_INIT , RWLOCK_MAGIC
182#else
183#define RWLOCK_MAGIC_INIT /* */
184#endif
185
186#define RW_LOCK_UNLOCKED (rwlock_t) { RW_LOCK_BIAS RWLOCK_MAGIC_INIT }
187
188#define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0)
189 139
190/** 140/**
191 * read_can_lock - would read_trylock() succeed? 141 * read_can_lock - would read_trylock() succeed?
192 * @lock: the rwlock in question. 142 * @lock: the rwlock in question.
193 */ 143 */
194#define read_can_lock(x) ((int)(x)->lock > 0) 144#define __raw_read_can_lock(x) ((int)(x)->lock > 0)
195 145
196/** 146/**
197 * write_can_lock - would write_trylock() succeed? 147 * write_can_lock - would write_trylock() succeed?
198 * @lock: the rwlock in question. 148 * @lock: the rwlock in question.
199 */ 149 */
200#define write_can_lock(x) ((x)->lock == RW_LOCK_BIAS) 150#define __raw_write_can_lock(x) ((x)->lock == RW_LOCK_BIAS)
201
202/*
203 * On x86, we implement read-write locks as a 32-bit counter
204 * with the high bit (sign) being the "contended" bit.
205 *
206 * The inline assembly is non-obvious. Think about it.
207 *
208 * Changed to use the same technique as rw semaphores. See
209 * semaphore.h for details. -ben
210 */
211/* the spinlock helpers are in arch/i386/kernel/semaphore.c */
212 151
213static inline void _raw_read_lock(rwlock_t *rw) 152static inline void __raw_read_lock(raw_rwlock_t *rw)
214{ 153{
215 unsigned long tmp0, tmp1; 154 unsigned long tmp0, tmp1;
216 155
217#ifdef CONFIG_DEBUG_SPINLOCK
218 BUG_ON(rw->magic != RWLOCK_MAGIC);
219#endif
220 /* 156 /*
221 * rw->lock : >0 : unlock 157 * rw->lock : >0 : unlock
222 * : <=0 : lock 158 * : <=0 : lock
@@ -264,13 +200,10 @@ static inline void _raw_read_lock(rwlock_t *rw)
264 ); 200 );
265} 201}
266 202
267static inline void _raw_write_lock(rwlock_t *rw) 203static inline void __raw_write_lock(raw_rwlock_t *rw)
268{ 204{
269 unsigned long tmp0, tmp1, tmp2; 205 unsigned long tmp0, tmp1, tmp2;
270 206
271#ifdef CONFIG_DEBUG_SPINLOCK
272 BUG_ON(rw->magic != RWLOCK_MAGIC);
273#endif
274 /* 207 /*
275 * rw->lock : =RW_LOCK_BIAS_STR : unlock 208 * rw->lock : =RW_LOCK_BIAS_STR : unlock
276 * : !=RW_LOCK_BIAS_STR : lock 209 * : !=RW_LOCK_BIAS_STR : lock
@@ -320,7 +253,7 @@ static inline void _raw_write_lock(rwlock_t *rw)
320 ); 253 );
321} 254}
322 255
323static inline void _raw_read_unlock(rwlock_t *rw) 256static inline void __raw_read_unlock(raw_rwlock_t *rw)
324{ 257{
325 unsigned long tmp0, tmp1; 258 unsigned long tmp0, tmp1;
326 259
@@ -342,7 +275,7 @@ static inline void _raw_read_unlock(rwlock_t *rw)
342 ); 275 );
343} 276}
344 277
345static inline void _raw_write_unlock(rwlock_t *rw) 278static inline void __raw_write_unlock(raw_rwlock_t *rw)
346{ 279{
347 unsigned long tmp0, tmp1, tmp2; 280 unsigned long tmp0, tmp1, tmp2;
348 281
@@ -366,9 +299,9 @@ static inline void _raw_write_unlock(rwlock_t *rw)
366 ); 299 );
367} 300}
368 301
369#define _raw_read_trylock(lock) generic_raw_read_trylock(lock) 302#define __raw_read_trylock(lock) generic__raw_read_trylock(lock)
370 303
371static inline int _raw_write_trylock(rwlock_t *lock) 304static inline int __raw_write_trylock(raw_rwlock_t *lock)
372{ 305{
373 atomic_t *count = (atomic_t *)lock; 306 atomic_t *count = (atomic_t *)lock;
374 if (atomic_sub_and_test(RW_LOCK_BIAS, count)) 307 if (atomic_sub_and_test(RW_LOCK_BIAS, count))
diff --git a/include/asm-m32r/spinlock_types.h b/include/asm-m32r/spinlock_types.h
new file mode 100644
index 0000000000..7e9941c45f
--- /dev/null
+++ b/include/asm-m32r/spinlock_types.h
@@ -0,0 +1,23 @@
1#ifndef _ASM_M32R_SPINLOCK_TYPES_H
2#define _ASM_M32R_SPINLOCK_TYPES_H
3
4#ifndef __LINUX_SPINLOCK_TYPES_H
5# error "please don't include this file directly"
6#endif
7
8typedef struct {
9 volatile int slock;
10} raw_spinlock_t;
11
12#define __RAW_SPIN_LOCK_UNLOCKED { 1 }
13
14typedef struct {
15 volatile int lock;
16} raw_rwlock_t;
17
18#define RW_LOCK_BIAS 0x01000000
19#define RW_LOCK_BIAS_STR "0x01000000"
20
21#define __RAW_RW_LOCK_UNLOCKED { RW_LOCK_BIAS }
22
23#endif
diff --git a/include/asm-m68knommu/bitops.h b/include/asm-m68knommu/bitops.h
index f95e32b404..c42f88a9b9 100644
--- a/include/asm-m68knommu/bitops.h
+++ b/include/asm-m68knommu/bitops.h
@@ -259,7 +259,7 @@ static __inline__ int __test_bit(int nr, const volatile unsigned long * addr)
259#define find_first_bit(addr, size) \ 259#define find_first_bit(addr, size) \
260 find_next_bit((addr), (size), 0) 260 find_next_bit((addr), (size), 0)
261 261
262static __inline__ int find_next_zero_bit (void * addr, int size, int offset) 262static __inline__ int find_next_zero_bit (const void * addr, int size, int offset)
263{ 263{
264 unsigned long *p = ((unsigned long *) addr) + (offset >> 5); 264 unsigned long *p = ((unsigned long *) addr) + (offset >> 5);
265 unsigned long result = offset & ~31UL; 265 unsigned long result = offset & ~31UL;
diff --git a/include/asm-m68knommu/checksum.h b/include/asm-m68knommu/checksum.h
index 92cf102c25..294ec7583a 100644
--- a/include/asm-m68knommu/checksum.h
+++ b/include/asm-m68knommu/checksum.h
@@ -25,7 +25,8 @@ unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum)
25 * better 64-bit) boundary 25 * better 64-bit) boundary
26 */ 26 */
27 27
28unsigned int csum_partial_copy(const char *src, char *dst, int len, int sum); 28unsigned int csum_partial_copy(const unsigned char *src, unsigned char *dst,
29 int len, int sum);
29 30
30 31
31/* 32/*
@@ -35,8 +36,8 @@ unsigned int csum_partial_copy(const char *src, char *dst, int len, int sum);
35 * better 64-bit) boundary 36 * better 64-bit) boundary
36 */ 37 */
37 38
38extern unsigned int csum_partial_copy_from_user(const char *src, char *dst, 39extern unsigned int csum_partial_copy_from_user(const unsigned char *src,
39 int len, int sum, int *csum_err); 40 unsigned char *dst, int len, int sum, int *csum_err);
40 41
41#define csum_partial_copy_nocheck(src, dst, len, sum) \ 42#define csum_partial_copy_nocheck(src, dst, len, sum) \
42 csum_partial_copy((src), (dst), (len), (sum)) 43 csum_partial_copy((src), (dst), (len), (sum))
diff --git a/include/asm-m68knommu/m527xsim.h b/include/asm-m68knommu/m527xsim.h
index d280d013da..e7878d0f7d 100644
--- a/include/asm-m68knommu/m527xsim.h
+++ b/include/asm-m68knommu/m527xsim.h
@@ -37,13 +37,14 @@
37/* 37/*
38 * SDRAM configuration registers. 38 * SDRAM configuration registers.
39 */ 39 */
40#ifdef CONFIG_M5271EVB 40#ifdef CONFIG_M5271
41#define MCFSIM_DCR 0x40 /* SDRAM control */ 41#define MCFSIM_DCR 0x40 /* SDRAM control */
42#define MCFSIM_DACR0 0x48 /* SDRAM base address 0 */ 42#define MCFSIM_DACR0 0x48 /* SDRAM base address 0 */
43#define MCFSIM_DMR0 0x4c /* SDRAM address mask 0 */ 43#define MCFSIM_DMR0 0x4c /* SDRAM address mask 0 */
44#define MCFSIM_DACR1 0x50 /* SDRAM base address 1 */ 44#define MCFSIM_DACR1 0x50 /* SDRAM base address 1 */
45#define MCFSIM_DMR1 0x54 /* SDRAM address mask 1 */ 45#define MCFSIM_DMR1 0x54 /* SDRAM address mask 1 */
46#else 46#endif
47#ifdef CONFIG_M5275
47#define MCFSIM_DMR 0x40 /* SDRAM mode */ 48#define MCFSIM_DMR 0x40 /* SDRAM mode */
48#define MCFSIM_DCR 0x44 /* SDRAM control */ 49#define MCFSIM_DCR 0x44 /* SDRAM control */
49#define MCFSIM_DCFG1 0x48 /* SDRAM configuration 1 */ 50#define MCFSIM_DCFG1 0x48 /* SDRAM configuration 1 */
@@ -54,5 +55,21 @@
54#define MCFSIM_DMR1 0x5c /* SDRAM address mask 1 */ 55#define MCFSIM_DMR1 0x5c /* SDRAM address mask 1 */
55#endif 56#endif
56 57
58/*
59 * GPIO pins setups to enable the UARTs.
60 */
61#ifdef CONFIG_M5271
62#define MCF_GPIO_PAR_UART 0x100048 /* PAR UART address */
63#define UART0_ENABLE_MASK 0x000f
64#define UART1_ENABLE_MASK 0x0ff0
65#define UART2_ENABLE_MASK 0x3000
66#endif
67#ifdef CONFIG_M5275
68#define MCF_GPIO_PAR_UART 0x10007c /* PAR UART address */
69#define UART0_ENABLE_MASK 0x000f
70#define UART1_ENABLE_MASK 0x00f0
71#define UART2_ENABLE_MASK 0x3f00
72#endif
73
57/****************************************************************************/ 74/****************************************************************************/
58#endif /* m527xsim_h */ 75#endif /* m527xsim_h */
diff --git a/include/asm-m68knommu/m528xsim.h b/include/asm-m68knommu/m528xsim.h
index 371993a206..610774a17f 100644
--- a/include/asm-m68knommu/m528xsim.h
+++ b/include/asm-m68knommu/m528xsim.h
@@ -41,5 +41,117 @@
41#define MCFSIM_DACR1 0x50 /* SDRAM base address 1 */ 41#define MCFSIM_DACR1 0x50 /* SDRAM base address 1 */
42#define MCFSIM_DMR1 0x54 /* SDRAM address mask 1 */ 42#define MCFSIM_DMR1 0x54 /* SDRAM address mask 1 */
43 43
44/*
45 * Derek Cheung - 6 Feb 2005
46 * add I2C and QSPI register definition using Freescale's MCF5282
47 */
48/* set Port AS pin for I2C or UART */
49#define MCF5282_GPIO_PASPAR (volatile u16 *) (MCF_IPSBAR + 0x00100056)
50
51/* Interrupt Mask Register Register Low */
52#define MCF5282_INTC0_IMRL (volatile u32 *) (MCF_IPSBAR + 0x0C0C)
53/* Interrupt Control Register 7 */
54#define MCF5282_INTC0_ICR17 (volatile u8 *) (MCF_IPSBAR + 0x0C51)
55
56
57
58/*********************************************************************
59*
60* Inter-IC (I2C) Module
61*
62*********************************************************************/
63/* Read/Write access macros for general use */
64#define MCF5282_I2C_I2ADR (volatile u8 *) (MCF_IPSBAR + 0x0300) // Address
65#define MCF5282_I2C_I2FDR (volatile u8 *) (MCF_IPSBAR + 0x0304) // Freq Divider
66#define MCF5282_I2C_I2CR (volatile u8 *) (MCF_IPSBAR + 0x0308) // Control
67#define MCF5282_I2C_I2SR (volatile u8 *) (MCF_IPSBAR + 0x030C) // Status
68#define MCF5282_I2C_I2DR (volatile u8 *) (MCF_IPSBAR + 0x0310) // Data I/O
69
70/* Bit level definitions and macros */
71#define MCF5282_I2C_I2ADR_ADDR(x) (((x)&0x7F)<<0x01)
72
73#define MCF5282_I2C_I2FDR_IC(x) (((x)&0x3F))
74
75#define MCF5282_I2C_I2CR_IEN (0x80) // I2C enable
76#define MCF5282_I2C_I2CR_IIEN (0x40) // interrupt enable
77#define MCF5282_I2C_I2CR_MSTA (0x20) // master/slave mode
78#define MCF5282_I2C_I2CR_MTX (0x10) // transmit/receive mode
79#define MCF5282_I2C_I2CR_TXAK (0x08) // transmit acknowledge enable
80#define MCF5282_I2C_I2CR_RSTA (0x04) // repeat start
81
82#define MCF5282_I2C_I2SR_ICF (0x80) // data transfer bit
83#define MCF5282_I2C_I2SR_IAAS (0x40) // I2C addressed as a slave
84#define MCF5282_I2C_I2SR_IBB (0x20) // I2C bus busy
85#define MCF5282_I2C_I2SR_IAL (0x10) // aribitration lost
86#define MCF5282_I2C_I2SR_SRW (0x04) // slave read/write
87#define MCF5282_I2C_I2SR_IIF (0x02) // I2C interrupt
88#define MCF5282_I2C_I2SR_RXAK (0x01) // received acknowledge
89
90
91
92/*********************************************************************
93*
94* Queued Serial Peripheral Interface (QSPI) Module
95*
96*********************************************************************/
97/* Derek - 21 Feb 2005 */
98/* change to the format used in I2C */
99/* Read/Write access macros for general use */
100#define MCF5282_QSPI_QMR MCF_IPSBAR + 0x0340
101#define MCF5282_QSPI_QDLYR MCF_IPSBAR + 0x0344
102#define MCF5282_QSPI_QWR MCF_IPSBAR + 0x0348
103#define MCF5282_QSPI_QIR MCF_IPSBAR + 0x034C
104#define MCF5282_QSPI_QAR MCF_IPSBAR + 0x0350
105#define MCF5282_QSPI_QDR MCF_IPSBAR + 0x0354
106#define MCF5282_QSPI_QCR MCF_IPSBAR + 0x0354
107
108/* Bit level definitions and macros */
109#define MCF5282_QSPI_QMR_MSTR (0x8000)
110#define MCF5282_QSPI_QMR_DOHIE (0x4000)
111#define MCF5282_QSPI_QMR_BITS_16 (0x0000)
112#define MCF5282_QSPI_QMR_BITS_8 (0x2000)
113#define MCF5282_QSPI_QMR_BITS_9 (0x2400)
114#define MCF5282_QSPI_QMR_BITS_10 (0x2800)
115#define MCF5282_QSPI_QMR_BITS_11 (0x2C00)
116#define MCF5282_QSPI_QMR_BITS_12 (0x3000)
117#define MCF5282_QSPI_QMR_BITS_13 (0x3400)
118#define MCF5282_QSPI_QMR_BITS_14 (0x3800)
119#define MCF5282_QSPI_QMR_BITS_15 (0x3C00)
120#define MCF5282_QSPI_QMR_CPOL (0x0200)
121#define MCF5282_QSPI_QMR_CPHA (0x0100)
122#define MCF5282_QSPI_QMR_BAUD(x) (((x)&0x00FF))
123
124#define MCF5282_QSPI_QDLYR_SPE (0x80)
125#define MCF5282_QSPI_QDLYR_QCD(x) (((x)&0x007F)<<8)
126#define MCF5282_QSPI_QDLYR_DTL(x) (((x)&0x00FF))
127
128#define MCF5282_QSPI_QWR_HALT (0x8000)
129#define MCF5282_QSPI_QWR_WREN (0x4000)
130#define MCF5282_QSPI_QWR_WRTO (0x2000)
131#define MCF5282_QSPI_QWR_CSIV (0x1000)
132#define MCF5282_QSPI_QWR_ENDQP(x) (((x)&0x000F)<<8)
133#define MCF5282_QSPI_QWR_CPTQP(x) (((x)&0x000F)<<4)
134#define MCF5282_QSPI_QWR_NEWQP(x) (((x)&0x000F))
135
136#define MCF5282_QSPI_QIR_WCEFB (0x8000)
137#define MCF5282_QSPI_QIR_ABRTB (0x4000)
138#define MCF5282_QSPI_QIR_ABRTL (0x1000)
139#define MCF5282_QSPI_QIR_WCEFE (0x0800)
140#define MCF5282_QSPI_QIR_ABRTE (0x0400)
141#define MCF5282_QSPI_QIR_SPIFE (0x0100)
142#define MCF5282_QSPI_QIR_WCEF (0x0008)
143#define MCF5282_QSPI_QIR_ABRT (0x0004)
144#define MCF5282_QSPI_QIR_SPIF (0x0001)
145
146#define MCF5282_QSPI_QAR_ADDR(x) (((x)&0x003F))
147
148#define MCF5282_QSPI_QDR_COMMAND(x) (((x)&0xFF00))
149#define MCF5282_QSPI_QCR_DATA(x) (((x)&0x00FF)<<8)
150#define MCF5282_QSPI_QCR_CONT (0x8000)
151#define MCF5282_QSPI_QCR_BITSE (0x4000)
152#define MCF5282_QSPI_QCR_DT (0x2000)
153#define MCF5282_QSPI_QCR_DSCK (0x1000)
154#define MCF5282_QSPI_QCR_CS (((x)&0x000F)<<8)
155
44/****************************************************************************/ 156/****************************************************************************/
45#endif /* m528xsim_h */ 157#endif /* m528xsim_h */
diff --git a/include/asm-m68knommu/mcfcache.h b/include/asm-m68knommu/mcfcache.h
index bdd8c53ef3..b17cd92097 100644
--- a/include/asm-m68knommu/mcfcache.h
+++ b/include/asm-m68knommu/mcfcache.h
@@ -33,7 +33,7 @@
33.endm 33.endm
34#endif /* CONFIG_M5206 || CONFIG_M5206e || CONFIG_M5272 */ 34#endif /* CONFIG_M5206 || CONFIG_M5206e || CONFIG_M5272 */
35 35
36#if defined(CONFIG_M527x) 36#if defined(CONFIG_M523x) || defined(CONFIG_M527x)
37/* 37/*
38 * New version 2 cores have a configurable split cache arrangement. 38 * New version 2 cores have a configurable split cache arrangement.
39 * For now I am just enabling instruction cache - but ultimately I 39 * For now I am just enabling instruction cache - but ultimately I
@@ -51,23 +51,20 @@
51 movec %d0,%CACR /* enable cache */ 51 movec %d0,%CACR /* enable cache */
52 nop 52 nop
53.endm 53.endm
54#endif /* CONFIG_M527x */ 54#endif /* CONFIG_M523x || CONFIG_M527x */
55 55
56#if defined(CONFIG_M528x) 56#if defined(CONFIG_M528x)
57/*
58 * Cache is totally broken on early 5282 silicon. So far now we
59 * disable its cache all together.
60 */
61.macro CACHE_ENABLE 57.macro CACHE_ENABLE
62 movel #0x01000000,%d0
63 movec %d0,%CACR /* invalidate cache */
64 nop 58 nop
65 movel #0x0000c000,%d0 /* set SDRAM cached only */ 59 movel #0x01000000, %d0
66 movec %d0,%ACR0 60 movec %d0, %CACR /* Invalidate cache */
67 movel #0x00000000,%d0 /* no other regions cached */ 61 nop
68 movec %d0,%ACR1 62 movel #0x0000c020, %d0 /* Set SDRAM cached only */
69 movel #0x00000000,%d0 /* configure cache */ 63 movec %d0, %ACR0
70 movec %d0,%CACR /* enable cache */ 64 movel #0xff00c000, %d0 /* Cache Flash also */
65 movec %d0, %ACR1
66 movel #0x80000200, %d0 /* Setup cache mask */
67 movec %d0, %CACR /* Enable cache */
71 nop 68 nop
72.endm 69.endm
73#endif /* CONFIG_M528x */ 70#endif /* CONFIG_M528x */
diff --git a/include/asm-m68knommu/mcfdma.h b/include/asm-m68knommu/mcfdma.h
index 350c6090b5..b93f8ba8a2 100644
--- a/include/asm-m68knommu/mcfdma.h
+++ b/include/asm-m68knommu/mcfdma.h
@@ -21,7 +21,7 @@
21#define MCFDMA_BASE1 0x240 /* Base address of DMA 1 */ 21#define MCFDMA_BASE1 0x240 /* Base address of DMA 1 */
22#elif defined(CONFIG_M5272) 22#elif defined(CONFIG_M5272)
23#define MCFDMA_BASE0 0x0e0 /* Base address of DMA 0 */ 23#define MCFDMA_BASE0 0x0e0 /* Base address of DMA 0 */
24#elif defined(CONFIG_M527x) || defined(CONFIG_M528x) 24#elif defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
25/* These are relative to the IPSBAR, not MBAR */ 25/* These are relative to the IPSBAR, not MBAR */
26#define MCFDMA_BASE0 0x100 /* Base address of DMA 0 */ 26#define MCFDMA_BASE0 0x100 /* Base address of DMA 0 */
27#define MCFDMA_BASE1 0x140 /* Base address of DMA 1 */ 27#define MCFDMA_BASE1 0x140 /* Base address of DMA 1 */
diff --git a/include/asm-mips/asmmacro-32.h b/include/asm-mips/asmmacro-32.h
index ac8823df25..11daf5ceb7 100644
--- a/include/asm-mips/asmmacro-32.h
+++ b/include/asm-mips/asmmacro-32.h
@@ -7,7 +7,7 @@
7#ifndef _ASM_ASMMACRO_32_H 7#ifndef _ASM_ASMMACRO_32_H
8#define _ASM_ASMMACRO_32_H 8#define _ASM_ASMMACRO_32_H
9 9
10#include <asm/offset.h> 10#include <asm/asm-offsets.h>
11#include <asm/regdef.h> 11#include <asm/regdef.h>
12#include <asm/fpregdef.h> 12#include <asm/fpregdef.h>
13#include <asm/mipsregs.h> 13#include <asm/mipsregs.h>
diff --git a/include/asm-mips/asmmacro-64.h b/include/asm-mips/asmmacro-64.h
index bbed35511f..559c355b9b 100644
--- a/include/asm-mips/asmmacro-64.h
+++ b/include/asm-mips/asmmacro-64.h
@@ -8,7 +8,7 @@
8#ifndef _ASM_ASMMACRO_64_H 8#ifndef _ASM_ASMMACRO_64_H
9#define _ASM_ASMMACRO_64_H 9#define _ASM_ASMMACRO_64_H
10 10
11#include <asm/offset.h> 11#include <asm/asm-offsets.h>
12#include <asm/regdef.h> 12#include <asm/regdef.h>
13#include <asm/fpregdef.h> 13#include <asm/fpregdef.h>
14#include <asm/mipsregs.h> 14#include <asm/mipsregs.h>
diff --git a/include/asm-mips/irq.h b/include/asm-mips/irq.h
index b90b11d0b8..3f2470e9e6 100644
--- a/include/asm-mips/irq.h
+++ b/include/asm-mips/irq.h
@@ -49,7 +49,4 @@ do { \
49 49
50extern void arch_init_irq(void); 50extern void arch_init_irq(void);
51 51
52struct irqaction;
53int handle_IRQ_event(unsigned int, struct pt_regs *, struct irqaction *);
54
55#endif /* _ASM_IRQ_H */ 52#endif /* _ASM_IRQ_H */
diff --git a/include/asm-mips/sim.h b/include/asm-mips/sim.h
index 3ccfe09fa7..9c2af1b00e 100644
--- a/include/asm-mips/sim.h
+++ b/include/asm-mips/sim.h
@@ -11,7 +11,7 @@
11 11
12#include <linux/config.h> 12#include <linux/config.h>
13 13
14#include <asm/offset.h> 14#include <asm/asm-offsets.h>
15 15
16#define __str2(x) #x 16#define __str2(x) #x
17#define __str(x) __str2(x) 17#define __str(x) __str2(x)
diff --git a/include/asm-mips/spinlock.h b/include/asm-mips/spinlock.h
index 114d3eb98a..4d0135b111 100644
--- a/include/asm-mips/spinlock.h
+++ b/include/asm-mips/spinlock.h
@@ -16,20 +16,10 @@
16 * Your basic SMP spinlocks, allowing only a single CPU anywhere 16 * Your basic SMP spinlocks, allowing only a single CPU anywhere
17 */ 17 */
18 18
19typedef struct { 19#define __raw_spin_is_locked(x) ((x)->lock != 0)
20 volatile unsigned int lock; 20#define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
21#ifdef CONFIG_PREEMPT 21#define __raw_spin_unlock_wait(x) \
22 unsigned int break_lock; 22 do { cpu_relax(); } while ((x)->lock)
23#endif
24} spinlock_t;
25
26#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 }
27
28#define spin_lock_init(x) do { (x)->lock = 0; } while(0)
29
30#define spin_is_locked(x) ((x)->lock != 0)
31#define spin_unlock_wait(x) do { barrier(); } while ((x)->lock)
32#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
33 23
34/* 24/*
35 * Simple spin lock operations. There are two variants, one clears IRQ's 25 * Simple spin lock operations. There are two variants, one clears IRQ's
@@ -38,13 +28,13 @@ typedef struct {
38 * We make no fairness assumptions. They have a cost. 28 * We make no fairness assumptions. They have a cost.
39 */ 29 */
40 30
41static inline void _raw_spin_lock(spinlock_t *lock) 31static inline void __raw_spin_lock(raw_spinlock_t *lock)
42{ 32{
43 unsigned int tmp; 33 unsigned int tmp;
44 34
45 if (R10000_LLSC_WAR) { 35 if (R10000_LLSC_WAR) {
46 __asm__ __volatile__( 36 __asm__ __volatile__(
47 " .set noreorder # _raw_spin_lock \n" 37 " .set noreorder # __raw_spin_lock \n"
48 "1: ll %1, %2 \n" 38 "1: ll %1, %2 \n"
49 " bnez %1, 1b \n" 39 " bnez %1, 1b \n"
50 " li %1, 1 \n" 40 " li %1, 1 \n"
@@ -58,7 +48,7 @@ static inline void _raw_spin_lock(spinlock_t *lock)
58 : "memory"); 48 : "memory");
59 } else { 49 } else {
60 __asm__ __volatile__( 50 __asm__ __volatile__(
61 " .set noreorder # _raw_spin_lock \n" 51 " .set noreorder # __raw_spin_lock \n"
62 "1: ll %1, %2 \n" 52 "1: ll %1, %2 \n"
63 " bnez %1, 1b \n" 53 " bnez %1, 1b \n"
64 " li %1, 1 \n" 54 " li %1, 1 \n"
@@ -72,10 +62,10 @@ static inline void _raw_spin_lock(spinlock_t *lock)
72 } 62 }
73} 63}
74 64
75static inline void _raw_spin_unlock(spinlock_t *lock) 65static inline void __raw_spin_unlock(raw_spinlock_t *lock)
76{ 66{
77 __asm__ __volatile__( 67 __asm__ __volatile__(
78 " .set noreorder # _raw_spin_unlock \n" 68 " .set noreorder # __raw_spin_unlock \n"
79 " sync \n" 69 " sync \n"
80 " sw $0, %0 \n" 70 " sw $0, %0 \n"
81 " .set\treorder \n" 71 " .set\treorder \n"
@@ -84,13 +74,13 @@ static inline void _raw_spin_unlock(spinlock_t *lock)
84 : "memory"); 74 : "memory");
85} 75}
86 76
87static inline unsigned int _raw_spin_trylock(spinlock_t *lock) 77static inline unsigned int __raw_spin_trylock(raw_spinlock_t *lock)
88{ 78{
89 unsigned int temp, res; 79 unsigned int temp, res;
90 80
91 if (R10000_LLSC_WAR) { 81 if (R10000_LLSC_WAR) {
92 __asm__ __volatile__( 82 __asm__ __volatile__(
93 " .set noreorder # _raw_spin_trylock \n" 83 " .set noreorder # __raw_spin_trylock \n"
94 "1: ll %0, %3 \n" 84 "1: ll %0, %3 \n"
95 " ori %2, %0, 1 \n" 85 " ori %2, %0, 1 \n"
96 " sc %2, %1 \n" 86 " sc %2, %1 \n"
@@ -104,7 +94,7 @@ static inline unsigned int _raw_spin_trylock(spinlock_t *lock)
104 : "memory"); 94 : "memory");
105 } else { 95 } else {
106 __asm__ __volatile__( 96 __asm__ __volatile__(
107 " .set noreorder # _raw_spin_trylock \n" 97 " .set noreorder # __raw_spin_trylock \n"
108 "1: ll %0, %3 \n" 98 "1: ll %0, %3 \n"
109 " ori %2, %0, 1 \n" 99 " ori %2, %0, 1 \n"
110 " sc %2, %1 \n" 100 " sc %2, %1 \n"
@@ -129,24 +119,13 @@ static inline unsigned int _raw_spin_trylock(spinlock_t *lock)
129 * read-locks. 119 * read-locks.
130 */ 120 */
131 121
132typedef struct { 122static inline void __raw_read_lock(raw_rwlock_t *rw)
133 volatile unsigned int lock;
134#ifdef CONFIG_PREEMPT
135 unsigned int break_lock;
136#endif
137} rwlock_t;
138
139#define RW_LOCK_UNLOCKED (rwlock_t) { 0 }
140
141#define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0)
142
143static inline void _raw_read_lock(rwlock_t *rw)
144{ 123{
145 unsigned int tmp; 124 unsigned int tmp;
146 125
147 if (R10000_LLSC_WAR) { 126 if (R10000_LLSC_WAR) {
148 __asm__ __volatile__( 127 __asm__ __volatile__(
149 " .set noreorder # _raw_read_lock \n" 128 " .set noreorder # __raw_read_lock \n"
150 "1: ll %1, %2 \n" 129 "1: ll %1, %2 \n"
151 " bltz %1, 1b \n" 130 " bltz %1, 1b \n"
152 " addu %1, 1 \n" 131 " addu %1, 1 \n"
@@ -160,7 +139,7 @@ static inline void _raw_read_lock(rwlock_t *rw)
160 : "memory"); 139 : "memory");
161 } else { 140 } else {
162 __asm__ __volatile__( 141 __asm__ __volatile__(
163 " .set noreorder # _raw_read_lock \n" 142 " .set noreorder # __raw_read_lock \n"
164 "1: ll %1, %2 \n" 143 "1: ll %1, %2 \n"
165 " bltz %1, 1b \n" 144 " bltz %1, 1b \n"
166 " addu %1, 1 \n" 145 " addu %1, 1 \n"
@@ -177,13 +156,13 @@ static inline void _raw_read_lock(rwlock_t *rw)
177/* Note the use of sub, not subu which will make the kernel die with an 156/* Note the use of sub, not subu which will make the kernel die with an
178 overflow exception if we ever try to unlock an rwlock that is already 157 overflow exception if we ever try to unlock an rwlock that is already
179 unlocked or is being held by a writer. */ 158 unlocked or is being held by a writer. */
180static inline void _raw_read_unlock(rwlock_t *rw) 159static inline void __raw_read_unlock(raw_rwlock_t *rw)
181{ 160{
182 unsigned int tmp; 161 unsigned int tmp;
183 162
184 if (R10000_LLSC_WAR) { 163 if (R10000_LLSC_WAR) {
185 __asm__ __volatile__( 164 __asm__ __volatile__(
186 "1: ll %1, %2 # _raw_read_unlock \n" 165 "1: ll %1, %2 # __raw_read_unlock \n"
187 " sub %1, 1 \n" 166 " sub %1, 1 \n"
188 " sc %1, %0 \n" 167 " sc %1, %0 \n"
189 " beqzl %1, 1b \n" 168 " beqzl %1, 1b \n"
@@ -193,7 +172,7 @@ static inline void _raw_read_unlock(rwlock_t *rw)
193 : "memory"); 172 : "memory");
194 } else { 173 } else {
195 __asm__ __volatile__( 174 __asm__ __volatile__(
196 " .set noreorder # _raw_read_unlock \n" 175 " .set noreorder # __raw_read_unlock \n"
197 "1: ll %1, %2 \n" 176 "1: ll %1, %2 \n"
198 " sub %1, 1 \n" 177 " sub %1, 1 \n"
199 " sc %1, %0 \n" 178 " sc %1, %0 \n"
@@ -206,13 +185,13 @@ static inline void _raw_read_unlock(rwlock_t *rw)
206 } 185 }
207} 186}
208 187
209static inline void _raw_write_lock(rwlock_t *rw) 188static inline void __raw_write_lock(raw_rwlock_t *rw)
210{ 189{
211 unsigned int tmp; 190 unsigned int tmp;
212 191
213 if (R10000_LLSC_WAR) { 192 if (R10000_LLSC_WAR) {
214 __asm__ __volatile__( 193 __asm__ __volatile__(
215 " .set noreorder # _raw_write_lock \n" 194 " .set noreorder # __raw_write_lock \n"
216 "1: ll %1, %2 \n" 195 "1: ll %1, %2 \n"
217 " bnez %1, 1b \n" 196 " bnez %1, 1b \n"
218 " lui %1, 0x8000 \n" 197 " lui %1, 0x8000 \n"
@@ -226,7 +205,7 @@ static inline void _raw_write_lock(rwlock_t *rw)
226 : "memory"); 205 : "memory");
227 } else { 206 } else {
228 __asm__ __volatile__( 207 __asm__ __volatile__(
229 " .set noreorder # _raw_write_lock \n" 208 " .set noreorder # __raw_write_lock \n"
230 "1: ll %1, %2 \n" 209 "1: ll %1, %2 \n"
231 " bnez %1, 1b \n" 210 " bnez %1, 1b \n"
232 " lui %1, 0x8000 \n" 211 " lui %1, 0x8000 \n"
@@ -241,26 +220,26 @@ static inline void _raw_write_lock(rwlock_t *rw)
241 } 220 }
242} 221}
243 222
244static inline void _raw_write_unlock(rwlock_t *rw) 223static inline void __raw_write_unlock(raw_rwlock_t *rw)
245{ 224{
246 __asm__ __volatile__( 225 __asm__ __volatile__(
247 " sync # _raw_write_unlock \n" 226 " sync # __raw_write_unlock \n"
248 " sw $0, %0 \n" 227 " sw $0, %0 \n"
249 : "=m" (rw->lock) 228 : "=m" (rw->lock)
250 : "m" (rw->lock) 229 : "m" (rw->lock)
251 : "memory"); 230 : "memory");
252} 231}
253 232
254#define _raw_read_trylock(lock) generic_raw_read_trylock(lock) 233#define __raw_read_trylock(lock) generic__raw_read_trylock(lock)
255 234
256static inline int _raw_write_trylock(rwlock_t *rw) 235static inline int __raw_write_trylock(raw_rwlock_t *rw)
257{ 236{
258 unsigned int tmp; 237 unsigned int tmp;
259 int ret; 238 int ret;
260 239
261 if (R10000_LLSC_WAR) { 240 if (R10000_LLSC_WAR) {
262 __asm__ __volatile__( 241 __asm__ __volatile__(
263 " .set noreorder # _raw_write_trylock \n" 242 " .set noreorder # __raw_write_trylock \n"
264 " li %2, 0 \n" 243 " li %2, 0 \n"
265 "1: ll %1, %3 \n" 244 "1: ll %1, %3 \n"
266 " bnez %1, 2f \n" 245 " bnez %1, 2f \n"
@@ -277,7 +256,7 @@ static inline int _raw_write_trylock(rwlock_t *rw)
277 : "memory"); 256 : "memory");
278 } else { 257 } else {
279 __asm__ __volatile__( 258 __asm__ __volatile__(
280 " .set noreorder # _raw_write_trylock \n" 259 " .set noreorder # __raw_write_trylock \n"
281 " li %2, 0 \n" 260 " li %2, 0 \n"
282 "1: ll %1, %3 \n" 261 "1: ll %1, %3 \n"
283 " bnez %1, 2f \n" 262 " bnez %1, 2f \n"
diff --git a/include/asm-mips/spinlock_types.h b/include/asm-mips/spinlock_types.h
new file mode 100644
index 0000000000..ce26c5048b
--- /dev/null
+++ b/include/asm-mips/spinlock_types.h
@@ -0,0 +1,20 @@
1#ifndef _ASM_SPINLOCK_TYPES_H
2#define _ASM_SPINLOCK_TYPES_H
3
4#ifndef __LINUX_SPINLOCK_TYPES_H
5# error "please don't include this file directly"
6#endif
7
8typedef struct {
9 volatile unsigned int lock;
10} raw_spinlock_t;
11
12#define __RAW_SPIN_LOCK_UNLOCKED { 0 }
13
14typedef struct {
15 volatile unsigned int lock;
16} raw_rwlock_t;
17
18#define __RAW_RW_LOCK_UNLOCKED { 0 }
19
20#endif
diff --git a/include/asm-mips/stackframe.h b/include/asm-mips/stackframe.h
index fb42f99f85..7b5e64600b 100644
--- a/include/asm-mips/stackframe.h
+++ b/include/asm-mips/stackframe.h
@@ -15,7 +15,7 @@
15 15
16#include <asm/asm.h> 16#include <asm/asm.h>
17#include <asm/mipsregs.h> 17#include <asm/mipsregs.h>
18#include <asm/offset.h> 18#include <asm/asm-offsets.h>
19 19
20 .macro SAVE_AT 20 .macro SAVE_AT
21 .set push 21 .set push
diff --git a/include/asm-mips/vr41xx/tb0287.h b/include/asm-mips/vr41xx/tb0287.h
new file mode 100644
index 0000000000..dd9832313a
--- /dev/null
+++ b/include/asm-mips/vr41xx/tb0287.h
@@ -0,0 +1,43 @@
1/*
2 * tb0287.h, Include file for TANBAC TB0287 mini-ITX board.
3 *
4 * Copyright (C) 2005 Media Lab Inc. <ito@mlb.co.jp>
5 *
6 * This code is largely based on tb0219.h.
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#ifndef __TANBAC_TB0287_H
23#define __TANBAC_TB0287_H
24
25#include <asm/vr41xx/vr41xx.h>
26
27/*
28 * General-Purpose I/O Pin Number
29 */
30#define TB0287_PCI_SLOT_PIN 2
31#define TB0287_SM501_PIN 3
32#define TB0287_SIL680A_PIN 8
33#define TB0287_RTL8110_PIN 13
34
35/*
36 * Interrupt Number
37 */
38#define TB0287_PCI_SLOT_IRQ GIU_IRQ(TB0287_PCI_SLOT_PIN)
39#define TB0287_SM501_IRQ GIU_IRQ(TB0287_SM501_PIN)
40#define TB0287_SIL680A_IRQ GIU_IRQ(TB0287_SIL680A_PIN)
41#define TB0287_RTL8110_IRQ GIU_IRQ(TB0287_RTL8110_PIN)
42
43#endif /* __TANBAC_TB0287_H */
diff --git a/include/asm-parisc/assembly.h b/include/asm-parisc/assembly.h
index cbc286f49b..30b023411f 100644
--- a/include/asm-parisc/assembly.h
+++ b/include/asm-parisc/assembly.h
@@ -63,7 +63,7 @@
63 .level 2.0w 63 .level 2.0w
64#endif 64#endif
65 65
66#include <asm/offsets.h> 66#include <asm/asm-offsets.h>
67#include <asm/page.h> 67#include <asm/page.h>
68 68
69#include <asm/asmregs.h> 69#include <asm/asmregs.h>
diff --git a/include/asm-parisc/atomic.h b/include/asm-parisc/atomic.h
index e24f7579ad..048a2c7fd0 100644
--- a/include/asm-parisc/atomic.h
+++ b/include/asm-parisc/atomic.h
@@ -24,19 +24,19 @@
24# define ATOMIC_HASH_SIZE 4 24# define ATOMIC_HASH_SIZE 4
25# define ATOMIC_HASH(a) (&(__atomic_hash[ (((unsigned long) a)/L1_CACHE_BYTES) & (ATOMIC_HASH_SIZE-1) ])) 25# define ATOMIC_HASH(a) (&(__atomic_hash[ (((unsigned long) a)/L1_CACHE_BYTES) & (ATOMIC_HASH_SIZE-1) ]))
26 26
27extern spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned; 27extern raw_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned;
28 28
29/* Can't use _raw_spin_lock_irq because of #include problems, so 29/* Can't use raw_spin_lock_irq because of #include problems, so
30 * this is the substitute */ 30 * this is the substitute */
31#define _atomic_spin_lock_irqsave(l,f) do { \ 31#define _atomic_spin_lock_irqsave(l,f) do { \
32 spinlock_t *s = ATOMIC_HASH(l); \ 32 raw_spinlock_t *s = ATOMIC_HASH(l); \
33 local_irq_save(f); \ 33 local_irq_save(f); \
34 _raw_spin_lock(s); \ 34 __raw_spin_lock(s); \
35} while(0) 35} while(0)
36 36
37#define _atomic_spin_unlock_irqrestore(l,f) do { \ 37#define _atomic_spin_unlock_irqrestore(l,f) do { \
38 spinlock_t *s = ATOMIC_HASH(l); \ 38 raw_spinlock_t *s = ATOMIC_HASH(l); \
39 _raw_spin_unlock(s); \ 39 __raw_spin_unlock(s); \
40 local_irq_restore(f); \ 40 local_irq_restore(f); \
41} while(0) 41} while(0)
42 42
diff --git a/include/asm-parisc/bitops.h b/include/asm-parisc/bitops.h
index 928e5ef850..af7db694b2 100644
--- a/include/asm-parisc/bitops.h
+++ b/include/asm-parisc/bitops.h
@@ -2,7 +2,7 @@
2#define _PARISC_BITOPS_H 2#define _PARISC_BITOPS_H
3 3
4#include <linux/compiler.h> 4#include <linux/compiler.h>
5#include <asm/system.h> 5#include <asm/spinlock.h>
6#include <asm/byteorder.h> 6#include <asm/byteorder.h>
7#include <asm/atomic.h> 7#include <asm/atomic.h>
8 8
diff --git a/include/asm-parisc/cacheflush.h b/include/asm-parisc/cacheflush.h
index 06732719d9..aa592d8c0e 100644
--- a/include/asm-parisc/cacheflush.h
+++ b/include/asm-parisc/cacheflush.h
@@ -3,6 +3,7 @@
3 3
4#include <linux/config.h> 4#include <linux/config.h>
5#include <linux/mm.h> 5#include <linux/mm.h>
6#include <asm/cache.h> /* for flush_user_dcache_range_asm() proto */
6 7
7/* The usual comment is "Caches aren't brain-dead on the <architecture>". 8/* The usual comment is "Caches aren't brain-dead on the <architecture>".
8 * Unfortunately, that doesn't apply to PA-RISC. */ 9 * Unfortunately, that doesn't apply to PA-RISC. */
diff --git a/include/asm-parisc/processor.h b/include/asm-parisc/processor.h
index 0b61f51d84..a9dfadd056 100644
--- a/include/asm-parisc/processor.h
+++ b/include/asm-parisc/processor.h
@@ -11,6 +11,7 @@
11#ifndef __ASSEMBLY__ 11#ifndef __ASSEMBLY__
12#include <linux/config.h> 12#include <linux/config.h>
13#include <linux/threads.h> 13#include <linux/threads.h>
14#include <linux/spinlock_types.h>
14 15
15#include <asm/hardware.h> 16#include <asm/hardware.h>
16#include <asm/page.h> 17#include <asm/page.h>
diff --git a/include/asm-parisc/spinlock.h b/include/asm-parisc/spinlock.h
index 679ea1c651..43eaa6e742 100644
--- a/include/asm-parisc/spinlock.h
+++ b/include/asm-parisc/spinlock.h
@@ -2,30 +2,25 @@
2#define __ASM_SPINLOCK_H 2#define __ASM_SPINLOCK_H
3 3
4#include <asm/system.h> 4#include <asm/system.h>
5#include <asm/processor.h>
6#include <asm/spinlock_types.h>
5 7
6/* Note that PA-RISC has to use `1' to mean unlocked and `0' to mean locked 8/* Note that PA-RISC has to use `1' to mean unlocked and `0' to mean locked
7 * since it only has load-and-zero. Moreover, at least on some PA processors, 9 * since it only has load-and-zero. Moreover, at least on some PA processors,
8 * the semaphore address has to be 16-byte aligned. 10 * the semaphore address has to be 16-byte aligned.
9 */ 11 */
10 12
11#ifndef CONFIG_DEBUG_SPINLOCK 13static inline int __raw_spin_is_locked(raw_spinlock_t *x)
12
13#define __SPIN_LOCK_UNLOCKED { { 1, 1, 1, 1 } }
14#undef SPIN_LOCK_UNLOCKED
15#define SPIN_LOCK_UNLOCKED (spinlock_t) __SPIN_LOCK_UNLOCKED
16
17#define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while(0)
18
19static inline int spin_is_locked(spinlock_t *x)
20{ 14{
21 volatile unsigned int *a = __ldcw_align(x); 15 volatile unsigned int *a = __ldcw_align(x);
22 return *a == 0; 16 return *a == 0;
23} 17}
24 18
25#define spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x)) 19#define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
26#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock) 20#define __raw_spin_unlock_wait(x) \
21 do { cpu_relax(); } while (__raw_spin_is_locked(x))
27 22
28static inline void _raw_spin_lock(spinlock_t *x) 23static inline void __raw_spin_lock(raw_spinlock_t *x)
29{ 24{
30 volatile unsigned int *a; 25 volatile unsigned int *a;
31 26
@@ -36,7 +31,7 @@ static inline void _raw_spin_lock(spinlock_t *x)
36 mb(); 31 mb();
37} 32}
38 33
39static inline void _raw_spin_unlock(spinlock_t *x) 34static inline void __raw_spin_unlock(raw_spinlock_t *x)
40{ 35{
41 volatile unsigned int *a; 36 volatile unsigned int *a;
42 mb(); 37 mb();
@@ -45,7 +40,7 @@ static inline void _raw_spin_unlock(spinlock_t *x)
45 mb(); 40 mb();
46} 41}
47 42
48static inline int _raw_spin_trylock(spinlock_t *x) 43static inline int __raw_spin_trylock(raw_spinlock_t *x)
49{ 44{
50 volatile unsigned int *a; 45 volatile unsigned int *a;
51 int ret; 46 int ret;
@@ -57,131 +52,38 @@ static inline int _raw_spin_trylock(spinlock_t *x)
57 52
58 return ret; 53 return ret;
59} 54}
60
61#define spin_lock_own(LOCK, LOCATION) ((void)0)
62
63#else /* !(CONFIG_DEBUG_SPINLOCK) */
64
65#define SPINLOCK_MAGIC 0x1D244B3C
66
67#define __SPIN_LOCK_UNLOCKED { { 1, 1, 1, 1 }, SPINLOCK_MAGIC, 10, __FILE__ , NULL, 0, -1, NULL, NULL }
68#undef SPIN_LOCK_UNLOCKED
69#define SPIN_LOCK_UNLOCKED (spinlock_t) __SPIN_LOCK_UNLOCKED
70
71#define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while(0)
72
73#define CHECK_LOCK(x) \
74 do { \
75 if (unlikely((x)->magic != SPINLOCK_MAGIC)) { \
76 printk(KERN_ERR "%s:%d: spin_is_locked" \
77 " on uninitialized spinlock %p.\n", \
78 __FILE__, __LINE__, (x)); \
79 } \
80 } while(0)
81
82#define spin_is_locked(x) \
83 ({ \
84 CHECK_LOCK(x); \
85 volatile unsigned int *a = __ldcw_align(x); \
86 if (unlikely((*a == 0) && (x)->babble)) { \
87 (x)->babble--; \
88 printk("KERN_WARNING \
89 %s:%d: spin_is_locked(%s/%p) already" \
90 " locked by %s:%d in %s at %p(%d)\n", \
91 __FILE__,__LINE__, (x)->module, (x), \
92 (x)->bfile, (x)->bline, (x)->task->comm,\
93 (x)->previous, (x)->oncpu); \
94 } \
95 *a == 0; \
96 })
97
98#define spin_unlock_wait(x) \
99 do { \
100 CHECK_LOCK(x); \
101 volatile unsigned int *a = __ldcw_align(x); \
102 if (unlikely((*a == 0) && (x)->babble)) { \
103 (x)->babble--; \
104 printk("KERN_WARNING \
105 %s:%d: spin_unlock_wait(%s/%p)" \
106 " owned by %s:%d in %s at %p(%d)\n", \
107 __FILE__,__LINE__, (x)->module, (x), \
108 (x)->bfile, (x)->bline, (x)->task->comm,\
109 (x)->previous, (x)->oncpu); \
110 } \
111 barrier(); \
112 } while (*((volatile unsigned char *)(__ldcw_align(x))) == 0)
113
114extern void _dbg_spin_lock(spinlock_t *lock, const char *base_file, int line_no);
115extern void _dbg_spin_unlock(spinlock_t *lock, const char *, int);
116extern int _dbg_spin_trylock(spinlock_t * lock, const char *, int);
117
118#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
119
120#define _raw_spin_unlock(lock) _dbg_spin_unlock(lock, __FILE__, __LINE__)
121#define _raw_spin_lock(lock) _dbg_spin_lock(lock, __FILE__, __LINE__)
122#define _raw_spin_trylock(lock) _dbg_spin_trylock(lock, __FILE__, __LINE__)
123
124/* just in case we need it */
125#define spin_lock_own(LOCK, LOCATION) \
126do { \
127 volatile unsigned int *a = __ldcw_align(LOCK); \
128 if (!((*a == 0) && ((LOCK)->oncpu == smp_processor_id()))) \
129 printk("KERN_WARNING \
130 %s: called on %d from %p but lock %s on %d\n", \
131 LOCATION, smp_processor_id(), \
132 __builtin_return_address(0), \
133 (*a == 0) ? "taken" : "freed", (LOCK)->on_cpu); \
134} while (0)
135
136#endif /* !(CONFIG_DEBUG_SPINLOCK) */
137 55
138/* 56/*
139 * Read-write spinlocks, allowing multiple readers 57 * Read-write spinlocks, allowing multiple readers
140 * but only one writer. 58 * but only one writer.
141 */ 59 */
142typedef struct {
143 spinlock_t lock;
144 volatile int counter;
145#ifdef CONFIG_PREEMPT
146 unsigned int break_lock;
147#endif
148} rwlock_t;
149
150#define RW_LOCK_UNLOCKED (rwlock_t) { __SPIN_LOCK_UNLOCKED, 0 }
151
152#define rwlock_init(lp) do { *(lp) = RW_LOCK_UNLOCKED; } while (0)
153 60
154#define _raw_read_trylock(lock) generic_raw_read_trylock(lock) 61#define __raw_read_trylock(lock) generic__raw_read_trylock(lock)
155 62
156/* read_lock, read_unlock are pretty straightforward. Of course it somehow 63/* read_lock, read_unlock are pretty straightforward. Of course it somehow
157 * sucks we end up saving/restoring flags twice for read_lock_irqsave aso. */ 64 * sucks we end up saving/restoring flags twice for read_lock_irqsave aso. */
158 65
159#ifdef CONFIG_DEBUG_RWLOCK 66static __inline__ void __raw_read_lock(raw_rwlock_t *rw)
160extern void _dbg_read_lock(rwlock_t * rw, const char *bfile, int bline);
161#define _raw_read_lock(rw) _dbg_read_lock(rw, __FILE__, __LINE__)
162#else
163static __inline__ void _raw_read_lock(rwlock_t *rw)
164{ 67{
165 unsigned long flags; 68 unsigned long flags;
166 local_irq_save(flags); 69 local_irq_save(flags);
167 _raw_spin_lock(&rw->lock); 70 __raw_spin_lock(&rw->lock);
168 71
169 rw->counter++; 72 rw->counter++;
170 73
171 _raw_spin_unlock(&rw->lock); 74 __raw_spin_unlock(&rw->lock);
172 local_irq_restore(flags); 75 local_irq_restore(flags);
173} 76}
174#endif /* CONFIG_DEBUG_RWLOCK */
175 77
176static __inline__ void _raw_read_unlock(rwlock_t *rw) 78static __inline__ void __raw_read_unlock(raw_rwlock_t *rw)
177{ 79{
178 unsigned long flags; 80 unsigned long flags;
179 local_irq_save(flags); 81 local_irq_save(flags);
180 _raw_spin_lock(&rw->lock); 82 __raw_spin_lock(&rw->lock);
181 83
182 rw->counter--; 84 rw->counter--;
183 85
184 _raw_spin_unlock(&rw->lock); 86 __raw_spin_unlock(&rw->lock);
185 local_irq_restore(flags); 87 local_irq_restore(flags);
186} 88}
187 89
@@ -194,20 +96,17 @@ static __inline__ void _raw_read_unlock(rwlock_t *rw)
194 * writers) in interrupt handlers someone fucked up and we'd dead-lock 96 * writers) in interrupt handlers someone fucked up and we'd dead-lock
195 * sooner or later anyway. prumpf */ 97 * sooner or later anyway. prumpf */
196 98
197#ifdef CONFIG_DEBUG_RWLOCK 99static __inline__ void __raw_write_lock(raw_rwlock_t *rw)
198extern void _dbg_write_lock(rwlock_t * rw, const char *bfile, int bline);
199#define _raw_write_lock(rw) _dbg_write_lock(rw, __FILE__, __LINE__)
200#else
201static __inline__ void _raw_write_lock(rwlock_t *rw)
202{ 100{
203retry: 101retry:
204 _raw_spin_lock(&rw->lock); 102 __raw_spin_lock(&rw->lock);
205 103
206 if(rw->counter != 0) { 104 if(rw->counter != 0) {
207 /* this basically never happens */ 105 /* this basically never happens */
208 _raw_spin_unlock(&rw->lock); 106 __raw_spin_unlock(&rw->lock);
209 107
210 while(rw->counter != 0); 108 while (rw->counter != 0)
109 cpu_relax();
211 110
212 goto retry; 111 goto retry;
213 } 112 }
@@ -215,26 +114,21 @@ retry:
215 /* got it. now leave without unlocking */ 114 /* got it. now leave without unlocking */
216 rw->counter = -1; /* remember we are locked */ 115 rw->counter = -1; /* remember we are locked */
217} 116}
218#endif /* CONFIG_DEBUG_RWLOCK */
219 117
220/* write_unlock is absolutely trivial - we don't have to wait for anything */ 118/* write_unlock is absolutely trivial - we don't have to wait for anything */
221 119
222static __inline__ void _raw_write_unlock(rwlock_t *rw) 120static __inline__ void __raw_write_unlock(raw_rwlock_t *rw)
223{ 121{
224 rw->counter = 0; 122 rw->counter = 0;
225 _raw_spin_unlock(&rw->lock); 123 __raw_spin_unlock(&rw->lock);
226} 124}
227 125
228#ifdef CONFIG_DEBUG_RWLOCK 126static __inline__ int __raw_write_trylock(raw_rwlock_t *rw)
229extern int _dbg_write_trylock(rwlock_t * rw, const char *bfile, int bline);
230#define _raw_write_trylock(rw) _dbg_write_trylock(rw, __FILE__, __LINE__)
231#else
232static __inline__ int _raw_write_trylock(rwlock_t *rw)
233{ 127{
234 _raw_spin_lock(&rw->lock); 128 __raw_spin_lock(&rw->lock);
235 if (rw->counter != 0) { 129 if (rw->counter != 0) {
236 /* this basically never happens */ 130 /* this basically never happens */
237 _raw_spin_unlock(&rw->lock); 131 __raw_spin_unlock(&rw->lock);
238 132
239 return 0; 133 return 0;
240 } 134 }
@@ -243,14 +137,13 @@ static __inline__ int _raw_write_trylock(rwlock_t *rw)
243 rw->counter = -1; /* remember we are locked */ 137 rw->counter = -1; /* remember we are locked */
244 return 1; 138 return 1;
245} 139}
246#endif /* CONFIG_DEBUG_RWLOCK */
247 140
248static __inline__ int is_read_locked(rwlock_t *rw) 141static __inline__ int __raw_is_read_locked(raw_rwlock_t *rw)
249{ 142{
250 return rw->counter > 0; 143 return rw->counter > 0;
251} 144}
252 145
253static __inline__ int is_write_locked(rwlock_t *rw) 146static __inline__ int __raw_is_write_locked(raw_rwlock_t *rw)
254{ 147{
255 return rw->counter < 0; 148 return rw->counter < 0;
256} 149}
diff --git a/include/asm-parisc/spinlock_types.h b/include/asm-parisc/spinlock_types.h
new file mode 100644
index 0000000000..785bba822f
--- /dev/null
+++ b/include/asm-parisc/spinlock_types.h
@@ -0,0 +1,21 @@
1#ifndef __ASM_SPINLOCK_TYPES_H
2#define __ASM_SPINLOCK_TYPES_H
3
4#ifndef __LINUX_SPINLOCK_TYPES_H
5# error "please don't include this file directly"
6#endif
7
8typedef struct {
9 volatile unsigned int lock[4];
10} raw_spinlock_t;
11
12#define __RAW_SPIN_LOCK_UNLOCKED { { 1, 1, 1, 1 } }
13
14typedef struct {
15 raw_spinlock_t lock;
16 volatile int counter;
17} raw_rwlock_t;
18
19#define __RAW_RW_LOCK_UNLOCKED { __RAW_SPIN_LOCK_UNLOCKED, 0 }
20
21#endif
diff --git a/include/asm-parisc/system.h b/include/asm-parisc/system.h
index 81c5433390..26ff844a21 100644
--- a/include/asm-parisc/system.h
+++ b/include/asm-parisc/system.h
@@ -160,29 +160,7 @@ static inline void set_eiem(unsigned long val)
160}) 160})
161 161
162#ifdef CONFIG_SMP 162#ifdef CONFIG_SMP
163/* 163# define __lock_aligned __attribute__((__section__(".data.lock_aligned")))
164 * Your basic SMP spinlocks, allowing only a single CPU anywhere
165 */
166
167typedef struct {
168 volatile unsigned int lock[4];
169#ifdef CONFIG_DEBUG_SPINLOCK
170 unsigned long magic;
171 volatile unsigned int babble;
172 const char *module;
173 char *bfile;
174 int bline;
175 int oncpu;
176 void *previous;
177 struct task_struct * task;
178#endif
179#ifdef CONFIG_PREEMPT
180 unsigned int break_lock;
181#endif
182} spinlock_t;
183
184#define __lock_aligned __attribute__((__section__(".data.lock_aligned")))
185
186#endif 164#endif
187 165
188#define KERNEL_START (0x10100000 - 0x1000) 166#define KERNEL_START (0x10100000 - 0x1000)
diff --git a/include/asm-powerpc/siginfo.h b/include/asm-powerpc/siginfo.h
index 538ea8ef50..12f1bce037 100644
--- a/include/asm-powerpc/siginfo.h
+++ b/include/asm-powerpc/siginfo.h
@@ -15,4 +15,12 @@
15 15
16#include <asm-generic/siginfo.h> 16#include <asm-generic/siginfo.h>
17 17
18/*
19 * SIGTRAP si_codes
20 */
21#define TRAP_BRANCH (__SI_FAULT|3) /* process taken branch trap */
22#define TRAP_HWBKPT (__SI_FAULT|4) /* hardware breakpoint or watchpoint */
23#undef NSIGTRAP
24#define NSIGTRAP 4
25
18#endif /* _ASM_POWERPC_SIGINFO_H */ 26#endif /* _ASM_POWERPC_SIGINFO_H */
diff --git a/include/asm-ppc/irq.h b/include/asm-ppc/irq.h
index b4b270457e..55752474d0 100644
--- a/include/asm-ppc/irq.h
+++ b/include/asm-ppc/irq.h
@@ -404,9 +404,5 @@ extern unsigned long ppc_cached_irq_mask[NR_MASK_WORDS];
404extern unsigned long ppc_lost_interrupts[NR_MASK_WORDS]; 404extern unsigned long ppc_lost_interrupts[NR_MASK_WORDS];
405extern atomic_t ppc_n_lost_interrupts; 405extern atomic_t ppc_n_lost_interrupts;
406 406
407struct irqaction;
408struct pt_regs;
409int handle_IRQ_event(unsigned int, struct pt_regs *, struct irqaction *);
410
411#endif /* _ASM_IRQ_H */ 407#endif /* _ASM_IRQ_H */
412#endif /* __KERNEL__ */ 408#endif /* __KERNEL__ */
diff --git a/include/asm-ppc/ptrace.h b/include/asm-ppc/ptrace.h
index 9d4e4ea530..7043c164b5 100644
--- a/include/asm-ppc/ptrace.h
+++ b/include/asm-ppc/ptrace.h
@@ -142,4 +142,11 @@ do { \
142#define PTRACE_GETEVRREGS 20 142#define PTRACE_GETEVRREGS 20
143#define PTRACE_SETEVRREGS 21 143#define PTRACE_SETEVRREGS 21
144 144
145/*
146 * Get or set a debug register. The first 16 are DABR registers and the
147 * second 16 are IABR registers.
148 */
149#define PTRACE_GET_DEBUGREG 25
150#define PTRACE_SET_DEBUGREG 26
151
145#endif 152#endif
diff --git a/include/asm-ppc/reg.h b/include/asm-ppc/reg.h
index 88b4222154..73c33e3ef9 100644
--- a/include/asm-ppc/reg.h
+++ b/include/asm-ppc/reg.h
@@ -366,12 +366,6 @@
366#define PVR_STB03XXX 0x40310000 366#define PVR_STB03XXX 0x40310000
367#define PVR_NP405H 0x41410000 367#define PVR_NP405H 0x41410000
368#define PVR_NP405L 0x41610000 368#define PVR_NP405L 0x41610000
369#define PVR_440GP_RB 0x40120440
370#define PVR_440GP_RC1 0x40120481
371#define PVR_440GP_RC2 0x40200481
372#define PVR_440GX_RA 0x51b21850
373#define PVR_440GX_RB 0x51b21851
374#define PVR_440GX_RC 0x51b21892
375#define PVR_601 0x00010000 369#define PVR_601 0x00010000
376#define PVR_602 0x00050000 370#define PVR_602 0x00050000
377#define PVR_603 0x00030000 371#define PVR_603 0x00030000
diff --git a/include/asm-ppc/smp.h b/include/asm-ppc/smp.h
index 17530c232c..829481c0a9 100644
--- a/include/asm-ppc/smp.h
+++ b/include/asm-ppc/smp.h
@@ -41,6 +41,10 @@ extern void smp_send_xmon_break(int cpu);
41struct pt_regs; 41struct pt_regs;
42extern void smp_message_recv(int, struct pt_regs *); 42extern void smp_message_recv(int, struct pt_regs *);
43 43
44extern int __cpu_disable(void);
45extern void __cpu_die(unsigned int cpu);
46extern void cpu_die(void) __attribute__((noreturn));
47
44#define NO_PROC_ID 0xFF /* No processor magic marker */ 48#define NO_PROC_ID 0xFF /* No processor magic marker */
45#define PROC_CHANGE_PENALTY 20 49#define PROC_CHANGE_PENALTY 20
46 50
@@ -64,6 +68,8 @@ extern struct klock_info_struct klock_info;
64 68
65#else /* !(CONFIG_SMP) */ 69#else /* !(CONFIG_SMP) */
66 70
71static inline void cpu_die(void) { }
72
67#endif /* !(CONFIG_SMP) */ 73#endif /* !(CONFIG_SMP) */
68 74
69#endif /* !(_PPC_SMP_H) */ 75#endif /* !(_PPC_SMP_H) */
diff --git a/include/asm-ppc/spinlock.h b/include/asm-ppc/spinlock.h
index 909199aae1..20edcf2a6e 100644
--- a/include/asm-ppc/spinlock.h
+++ b/include/asm-ppc/spinlock.h
@@ -5,41 +5,21 @@
5 5
6/* 6/*
7 * Simple spin lock operations. 7 * Simple spin lock operations.
8 *
9 * (the type definitions are in asm/raw_spinlock_types.h)
8 */ 10 */
9 11
10typedef struct { 12#define __raw_spin_is_locked(x) ((x)->lock != 0)
11 volatile unsigned long lock; 13#define __raw_spin_unlock_wait(lock) \
12#ifdef CONFIG_DEBUG_SPINLOCK 14 do { while (__raw_spin_is_locked(lock)) cpu_relax(); } while (0)
13 volatile unsigned long owner_pc; 15#define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
14 volatile unsigned long owner_cpu; 16
15#endif 17static inline void __raw_spin_lock(raw_spinlock_t *lock)
16#ifdef CONFIG_PREEMPT
17 unsigned int break_lock;
18#endif
19} spinlock_t;
20
21#ifdef __KERNEL__
22#ifdef CONFIG_DEBUG_SPINLOCK
23#define SPINLOCK_DEBUG_INIT , 0, 0
24#else
25#define SPINLOCK_DEBUG_INIT /* */
26#endif
27
28#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 SPINLOCK_DEBUG_INIT }
29
30#define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while(0)
31#define spin_is_locked(x) ((x)->lock != 0)
32#define spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x))
33#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
34
35#ifndef CONFIG_DEBUG_SPINLOCK
36
37static inline void _raw_spin_lock(spinlock_t *lock)
38{ 18{
39 unsigned long tmp; 19 unsigned long tmp;
40 20
41 __asm__ __volatile__( 21 __asm__ __volatile__(
42 "b 1f # spin_lock\n\ 22 "b 1f # __raw_spin_lock\n\
432: lwzx %0,0,%1\n\ 232: lwzx %0,0,%1\n\
44 cmpwi 0,%0,0\n\ 24 cmpwi 0,%0,0\n\
45 bne+ 2b\n\ 25 bne+ 2b\n\
@@ -55,21 +35,13 @@ static inline void _raw_spin_lock(spinlock_t *lock)
55 : "cr0", "memory"); 35 : "cr0", "memory");
56} 36}
57 37
58static inline void _raw_spin_unlock(spinlock_t *lock) 38static inline void __raw_spin_unlock(raw_spinlock_t *lock)
59{ 39{
60 __asm__ __volatile__("eieio # spin_unlock": : :"memory"); 40 __asm__ __volatile__("eieio # __raw_spin_unlock": : :"memory");
61 lock->lock = 0; 41 lock->lock = 0;
62} 42}
63 43
64#define _raw_spin_trylock(l) (!test_and_set_bit(0,&(l)->lock)) 44#define __raw_spin_trylock(l) (!test_and_set_bit(0,&(l)->lock))
65
66#else
67
68extern void _raw_spin_lock(spinlock_t *lock);
69extern void _raw_spin_unlock(spinlock_t *lock);
70extern int _raw_spin_trylock(spinlock_t *lock);
71
72#endif
73 45
74/* 46/*
75 * Read-write spinlocks, allowing multiple readers 47 * Read-write spinlocks, allowing multiple readers
@@ -81,22 +53,11 @@ extern int _raw_spin_trylock(spinlock_t *lock);
81 * irq-safe write-lock, but readers can get non-irqsafe 53 * irq-safe write-lock, but readers can get non-irqsafe
82 * read-locks. 54 * read-locks.
83 */ 55 */
84typedef struct {
85 volatile signed int lock;
86#ifdef CONFIG_PREEMPT
87 unsigned int break_lock;
88#endif
89} rwlock_t;
90 56
91#define RW_LOCK_UNLOCKED (rwlock_t) { 0 } 57#define __raw_read_can_lock(rw) ((rw)->lock >= 0)
92#define rwlock_init(lp) do { *(lp) = RW_LOCK_UNLOCKED; } while(0) 58#define __raw_write_can_lock(rw) (!(rw)->lock)
93 59
94#define read_can_lock(rw) ((rw)->lock >= 0) 60static __inline__ int __raw_read_trylock(raw_rwlock_t *rw)
95#define write_can_lock(rw) (!(rw)->lock)
96
97#ifndef CONFIG_DEBUG_SPINLOCK
98
99static __inline__ int _raw_read_trylock(rwlock_t *rw)
100{ 61{
101 signed int tmp; 62 signed int tmp;
102 63
@@ -116,7 +77,7 @@ static __inline__ int _raw_read_trylock(rwlock_t *rw)
116 return tmp > 0; 77 return tmp > 0;
117} 78}
118 79
119static __inline__ void _raw_read_lock(rwlock_t *rw) 80static __inline__ void __raw_read_lock(raw_rwlock_t *rw)
120{ 81{
121 signed int tmp; 82 signed int tmp;
122 83
@@ -137,7 +98,7 @@ static __inline__ void _raw_read_lock(rwlock_t *rw)
137 : "cr0", "memory"); 98 : "cr0", "memory");
138} 99}
139 100
140static __inline__ void _raw_read_unlock(rwlock_t *rw) 101static __inline__ void __raw_read_unlock(raw_rwlock_t *rw)
141{ 102{
142 signed int tmp; 103 signed int tmp;
143 104
@@ -153,7 +114,7 @@ static __inline__ void _raw_read_unlock(rwlock_t *rw)
153 : "cr0", "memory"); 114 : "cr0", "memory");
154} 115}
155 116
156static __inline__ int _raw_write_trylock(rwlock_t *rw) 117static __inline__ int __raw_write_trylock(raw_rwlock_t *rw)
157{ 118{
158 signed int tmp; 119 signed int tmp;
159 120
@@ -173,7 +134,7 @@ static __inline__ int _raw_write_trylock(rwlock_t *rw)
173 return tmp == 0; 134 return tmp == 0;
174} 135}
175 136
176static __inline__ void _raw_write_lock(rwlock_t *rw) 137static __inline__ void __raw_write_lock(raw_rwlock_t *rw)
177{ 138{
178 signed int tmp; 139 signed int tmp;
179 140
@@ -194,22 +155,10 @@ static __inline__ void _raw_write_lock(rwlock_t *rw)
194 : "cr0", "memory"); 155 : "cr0", "memory");
195} 156}
196 157
197static __inline__ void _raw_write_unlock(rwlock_t *rw) 158static __inline__ void __raw_write_unlock(raw_rwlock_t *rw)
198{ 159{
199 __asm__ __volatile__("eieio # write_unlock": : :"memory"); 160 __asm__ __volatile__("eieio # write_unlock": : :"memory");
200 rw->lock = 0; 161 rw->lock = 0;
201} 162}
202 163
203#else
204
205extern void _raw_read_lock(rwlock_t *rw);
206extern void _raw_read_unlock(rwlock_t *rw);
207extern void _raw_write_lock(rwlock_t *rw);
208extern void _raw_write_unlock(rwlock_t *rw);
209extern int _raw_read_trylock(rwlock_t *rw);
210extern int _raw_write_trylock(rwlock_t *rw);
211
212#endif
213
214#endif /* __ASM_SPINLOCK_H */ 164#endif /* __ASM_SPINLOCK_H */
215#endif /* __KERNEL__ */
diff --git a/include/asm-ppc/spinlock_types.h b/include/asm-ppc/spinlock_types.h
new file mode 100644
index 0000000000..7919ccc75b
--- /dev/null
+++ b/include/asm-ppc/spinlock_types.h
@@ -0,0 +1,20 @@
1#ifndef __ASM_SPINLOCK_TYPES_H
2#define __ASM_SPINLOCK_TYPES_H
3
4#ifndef __LINUX_SPINLOCK_TYPES_H
5# error "please don't include this file directly"
6#endif
7
8typedef struct {
9 volatile unsigned long lock;
10} raw_spinlock_t;
11
12#define __RAW_SPIN_LOCK_UNLOCKED { 0 }
13
14typedef struct {
15 volatile signed int lock;
16} raw_rwlock_t;
17
18#define __RAW_RW_LOCK_UNLOCKED { 0 }
19
20#endif
diff --git a/include/asm-ppc/system.h b/include/asm-ppc/system.h
index 513a334c58..d754ab570f 100644
--- a/include/asm-ppc/system.h
+++ b/include/asm-ppc/system.h
@@ -88,6 +88,7 @@ extern void *cacheable_memcpy(void *, const void *, unsigned int);
88extern int do_page_fault(struct pt_regs *, unsigned long, unsigned long); 88extern int do_page_fault(struct pt_regs *, unsigned long, unsigned long);
89extern void bad_page_fault(struct pt_regs *, unsigned long, int); 89extern void bad_page_fault(struct pt_regs *, unsigned long, int);
90extern void die(const char *, struct pt_regs *, long); 90extern void die(const char *, struct pt_regs *, long);
91extern void _exception(int, struct pt_regs *, int, unsigned long);
91#ifdef CONFIG_BOOKE_WDT 92#ifdef CONFIG_BOOKE_WDT
92extern u32 booke_wdt_enabled; 93extern u32 booke_wdt_enabled;
93extern u32 booke_wdt_period; 94extern u32 booke_wdt_period;
diff --git a/include/asm-ppc64/hvcall.h b/include/asm-ppc64/hvcall.h
index 4f668a4baf..ab7c3cf248 100644
--- a/include/asm-ppc64/hvcall.h
+++ b/include/asm-ppc64/hvcall.h
@@ -56,6 +56,11 @@
56#define H_PP1 (1UL<<(63-62)) 56#define H_PP1 (1UL<<(63-62))
57#define H_PP2 (1UL<<(63-63)) 57#define H_PP2 (1UL<<(63-63))
58 58
59/* DABRX flags */
60#define H_DABRX_HYPERVISOR (1UL<<(63-61))
61#define H_DABRX_KERNEL (1UL<<(63-62))
62#define H_DABRX_USER (1UL<<(63-63))
63
59/* pSeries hypervisor opcodes */ 64/* pSeries hypervisor opcodes */
60#define H_REMOVE 0x04 65#define H_REMOVE 0x04
61#define H_ENTER 0x08 66#define H_ENTER 0x08
@@ -101,6 +106,7 @@
101#define H_VIO_SIGNAL 0x104 106#define H_VIO_SIGNAL 0x104
102#define H_SEND_CRQ 0x108 107#define H_SEND_CRQ 0x108
103#define H_COPY_RDMA 0x110 108#define H_COPY_RDMA 0x110
109#define H_SET_XDABR 0x134
104#define H_STUFF_TCE 0x138 110#define H_STUFF_TCE 0x138
105#define H_PUT_TCE_INDIRECT 0x13C 111#define H_PUT_TCE_INDIRECT 0x13C
106#define H_VTERM_PARTNER_INFO 0x150 112#define H_VTERM_PARTNER_INFO 0x150
diff --git a/include/asm-ppc64/machdep.h b/include/asm-ppc64/machdep.h
index 9a1ef4427e..8027160ec9 100644
--- a/include/asm-ppc64/machdep.h
+++ b/include/asm-ppc64/machdep.h
@@ -88,6 +88,7 @@ struct machdep_calls {
88 88
89 /* PCI stuff */ 89 /* PCI stuff */
90 void (*pcibios_fixup)(void); 90 void (*pcibios_fixup)(void);
91 int (*pci_probe_mode)(struct pci_bus *);
91 92
92 void (*restart)(char *cmd); 93 void (*restart)(char *cmd);
93 void (*power_off)(void); 94 void (*power_off)(void);
@@ -173,10 +174,6 @@ extern sys_ctrler_t sys_ctrler;
173void ppc64_boot_msg(unsigned int src, const char *msg); 174void ppc64_boot_msg(unsigned int src, const char *msg);
174/* Print a termination message (print only -- does not stop the kernel) */ 175/* Print a termination message (print only -- does not stop the kernel) */
175void ppc64_terminate_msg(unsigned int src, const char *msg); 176void ppc64_terminate_msg(unsigned int src, const char *msg);
176/* Print something that needs attention (device error, etc) */
177void ppc64_attention_msg(unsigned int src, const char *msg);
178/* Print a dump progress message. */
179void ppc64_dump_msg(unsigned int src, const char *msg);
180 177
181static inline void log_error(char *buf, unsigned int err_type, int fatal) 178static inline void log_error(char *buf, unsigned int err_type, int fatal)
182{ 179{
diff --git a/include/asm-ppc64/pci-bridge.h b/include/asm-ppc64/pci-bridge.h
index 6b4a5b1f69..d8991389ab 100644
--- a/include/asm-ppc64/pci-bridge.h
+++ b/include/asm-ppc64/pci-bridge.h
@@ -119,5 +119,10 @@ static inline struct pci_controller *pci_bus_to_host(struct pci_bus *bus)
119 return PCI_DN(busdn)->phb; 119 return PCI_DN(busdn)->phb;
120} 120}
121 121
122/* Return values for ppc_md.pci_probe_mode function */
123#define PCI_PROBE_NONE -1 /* Don't look at this bus at all */
124#define PCI_PROBE_NORMAL 0 /* Do normal PCI probing */
125#define PCI_PROBE_DEVTREE 1 /* Instantiate from device tree */
126
122#endif 127#endif
123#endif /* __KERNEL__ */ 128#endif /* __KERNEL__ */
diff --git a/include/asm-ppc64/plpar_wrappers.h b/include/asm-ppc64/plpar_wrappers.h
index f4a5fb7d67..72dd2449ee 100644
--- a/include/asm-ppc64/plpar_wrappers.h
+++ b/include/asm-ppc64/plpar_wrappers.h
@@ -107,5 +107,14 @@ static inline long plpar_put_term_char(unsigned long termno,
107 lbuf[1]); 107 lbuf[1]);
108} 108}
109 109
110static inline long plpar_set_xdabr(unsigned long address, unsigned long flags)
111{
112 return plpar_hcall_norets(H_SET_XDABR, address, flags);
113}
114
115static inline long plpar_set_dabr(unsigned long val)
116{
117 return plpar_hcall_norets(H_SET_DABR, val);
118}
110 119
111#endif /* _PPC64_PLPAR_WRAPPERS_H */ 120#endif /* _PPC64_PLPAR_WRAPPERS_H */
diff --git a/include/asm-ppc64/processor.h b/include/asm-ppc64/processor.h
index 8bd7aa9593..4146189006 100644
--- a/include/asm-ppc64/processor.h
+++ b/include/asm-ppc64/processor.h
@@ -433,6 +433,7 @@ struct thread_struct {
433 unsigned long start_tb; /* Start purr when proc switched in */ 433 unsigned long start_tb; /* Start purr when proc switched in */
434 unsigned long accum_tb; /* Total accumilated purr for process */ 434 unsigned long accum_tb; /* Total accumilated purr for process */
435 unsigned long vdso_base; /* base of the vDSO library */ 435 unsigned long vdso_base; /* base of the vDSO library */
436 unsigned long dabr; /* Data address breakpoint register */
436#ifdef CONFIG_ALTIVEC 437#ifdef CONFIG_ALTIVEC
437 /* Complete AltiVec register set */ 438 /* Complete AltiVec register set */
438 vector128 vr[32] __attribute((aligned(16))); 439 vector128 vr[32] __attribute((aligned(16)));
diff --git a/include/asm-ppc64/ptrace-common.h b/include/asm-ppc64/ptrace-common.h
index af03547f9c..b1babb7296 100644
--- a/include/asm-ppc64/ptrace-common.h
+++ b/include/asm-ppc64/ptrace-common.h
@@ -11,6 +11,10 @@
11 11
12#ifndef _PPC64_PTRACE_COMMON_H 12#ifndef _PPC64_PTRACE_COMMON_H
13#define _PPC64_PTRACE_COMMON_H 13#define _PPC64_PTRACE_COMMON_H
14
15#include <linux/config.h>
16#include <asm/system.h>
17
14/* 18/*
15 * Set of msr bits that gdb can change on behalf of a process. 19 * Set of msr bits that gdb can change on behalf of a process.
16 */ 20 */
@@ -69,4 +73,92 @@ static inline void clear_single_step(struct task_struct *task)
69 clear_ti_thread_flag(task->thread_info, TIF_SINGLESTEP); 73 clear_ti_thread_flag(task->thread_info, TIF_SINGLESTEP);
70} 74}
71 75
76#ifdef CONFIG_ALTIVEC
77/*
78 * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
79 * The transfer totals 34 quadword. Quadwords 0-31 contain the
80 * corresponding vector registers. Quadword 32 contains the vscr as the
81 * last word (offset 12) within that quadword. Quadword 33 contains the
82 * vrsave as the first word (offset 0) within the quadword.
83 *
84 * This definition of the VMX state is compatible with the current PPC32
85 * ptrace interface. This allows signal handling and ptrace to use the
86 * same structures. This also simplifies the implementation of a bi-arch
87 * (combined (32- and 64-bit) gdb.
88 */
89
90/*
91 * Get contents of AltiVec register state in task TASK
92 */
93static inline int get_vrregs(unsigned long __user *data,
94 struct task_struct *task)
95{
96 unsigned long regsize;
97
98 /* copy AltiVec registers VR[0] .. VR[31] */
99 regsize = 32 * sizeof(vector128);
100 if (copy_to_user(data, task->thread.vr, regsize))
101 return -EFAULT;
102 data += (regsize / sizeof(unsigned long));
103
104 /* copy VSCR */
105 regsize = 1 * sizeof(vector128);
106 if (copy_to_user(data, &task->thread.vscr, regsize))
107 return -EFAULT;
108 data += (regsize / sizeof(unsigned long));
109
110 /* copy VRSAVE */
111 if (put_user(task->thread.vrsave, (u32 __user *)data))
112 return -EFAULT;
113
114 return 0;
115}
116
117/*
118 * Write contents of AltiVec register state into task TASK.
119 */
120static inline int set_vrregs(struct task_struct *task,
121 unsigned long __user *data)
122{
123 unsigned long regsize;
124
125 /* copy AltiVec registers VR[0] .. VR[31] */
126 regsize = 32 * sizeof(vector128);
127 if (copy_from_user(task->thread.vr, data, regsize))
128 return -EFAULT;
129 data += (regsize / sizeof(unsigned long));
130
131 /* copy VSCR */
132 regsize = 1 * sizeof(vector128);
133 if (copy_from_user(&task->thread.vscr, data, regsize))
134 return -EFAULT;
135 data += (regsize / sizeof(unsigned long));
136
137 /* copy VRSAVE */
138 if (get_user(task->thread.vrsave, (u32 __user *)data))
139 return -EFAULT;
140
141 return 0;
142}
143#endif
144
145static inline int ptrace_set_debugreg(struct task_struct *task,
146 unsigned long addr, unsigned long data)
147{
148 /* We only support one DABR and no IABRS at the moment */
149 if (addr > 0)
150 return -EINVAL;
151
152 /* The bottom 3 bits are flags */
153 if ((data & ~0x7UL) >= TASK_SIZE)
154 return -EIO;
155
156 /* Ensure translation is on */
157 if (data && !(data & DABR_TRANSLATION))
158 return -EIO;
159
160 task->thread.dabr = data;
161 return 0;
162}
163
72#endif /* _PPC64_PTRACE_COMMON_H */ 164#endif /* _PPC64_PTRACE_COMMON_H */
diff --git a/include/asm-ppc64/ptrace.h b/include/asm-ppc64/ptrace.h
index c96aad28fc..3a55377f1f 100644
--- a/include/asm-ppc64/ptrace.h
+++ b/include/asm-ppc64/ptrace.h
@@ -25,56 +25,49 @@
25 */ 25 */
26 26
27#ifndef __ASSEMBLY__ 27#ifndef __ASSEMBLY__
28#define PPC_REG unsigned long 28
29struct pt_regs { 29struct pt_regs {
30 PPC_REG gpr[32]; 30 unsigned long gpr[32];
31 PPC_REG nip; 31 unsigned long nip;
32 PPC_REG msr; 32 unsigned long msr;
33 PPC_REG orig_gpr3; /* Used for restarting system calls */ 33 unsigned long orig_gpr3; /* Used for restarting system calls */
34 PPC_REG ctr; 34 unsigned long ctr;
35 PPC_REG link; 35 unsigned long link;
36 PPC_REG xer; 36 unsigned long xer;
37 PPC_REG ccr; 37 unsigned long ccr;
38 PPC_REG softe; /* Soft enabled/disabled */ 38 unsigned long softe; /* Soft enabled/disabled */
39 PPC_REG trap; /* Reason for being here */ 39 unsigned long trap; /* Reason for being here */
40 PPC_REG dar; /* Fault registers */ 40 unsigned long dar; /* Fault registers */
41 PPC_REG dsisr; 41 unsigned long dsisr;
42 PPC_REG result; /* Result of a system call */ 42 unsigned long result; /* Result of a system call */
43}; 43};
44 44
45#define PPC_REG_32 unsigned int
46struct pt_regs32 { 45struct pt_regs32 {
47 PPC_REG_32 gpr[32]; 46 unsigned int gpr[32];
48 PPC_REG_32 nip; 47 unsigned int nip;
49 PPC_REG_32 msr; 48 unsigned int msr;
50 PPC_REG_32 orig_gpr3; /* Used for restarting system calls */ 49 unsigned int orig_gpr3; /* Used for restarting system calls */
51 PPC_REG_32 ctr; 50 unsigned int ctr;
52 PPC_REG_32 link; 51 unsigned int link;
53 PPC_REG_32 xer; 52 unsigned int xer;
54 PPC_REG_32 ccr; 53 unsigned int ccr;
55 PPC_REG_32 mq; /* 601 only (not used at present) */ 54 unsigned int mq; /* 601 only (not used at present) */
56 /* Used on APUS to hold IPL value. */ 55 unsigned int trap; /* Reason for being here */
57 PPC_REG_32 trap; /* Reason for being here */ 56 unsigned int dar; /* Fault registers */
58 PPC_REG_32 dar; /* Fault registers */ 57 unsigned int dsisr;
59 PPC_REG_32 dsisr; 58 unsigned int result; /* Result of a system call */
60 PPC_REG_32 result; /* Result of a system call */
61}; 59};
62 60
61#ifdef __KERNEL__
62
63#define instruction_pointer(regs) ((regs)->nip) 63#define instruction_pointer(regs) ((regs)->nip)
64
64#ifdef CONFIG_SMP 65#ifdef CONFIG_SMP
65extern unsigned long profile_pc(struct pt_regs *regs); 66extern unsigned long profile_pc(struct pt_regs *regs);
66#else 67#else
67#define profile_pc(regs) instruction_pointer(regs) 68#define profile_pc(regs) instruction_pointer(regs)
68#endif 69#endif
69 70
70#endif /* __ASSEMBLY__ */
71
72#define STACK_FRAME_OVERHEAD 112 /* size of minimum stack frame */
73
74/* Size of dummy stack frame allocated when calling signal handler. */
75#define __SIGNAL_FRAMESIZE 128
76#define __SIGNAL_FRAMESIZE32 64
77
78#define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1) 71#define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1)
79 72
80#define force_successful_syscall_return() \ 73#define force_successful_syscall_return() \
@@ -89,6 +82,16 @@ extern unsigned long profile_pc(struct pt_regs *regs);
89#define TRAP(regs) ((regs)->trap & ~0xF) 82#define TRAP(regs) ((regs)->trap & ~0xF)
90#define CHECK_FULL_REGS(regs) BUG_ON(regs->trap & 1) 83#define CHECK_FULL_REGS(regs) BUG_ON(regs->trap & 1)
91 84
85#endif /* __KERNEL__ */
86
87#endif /* __ASSEMBLY__ */
88
89#define STACK_FRAME_OVERHEAD 112 /* size of minimum stack frame */
90
91/* Size of dummy stack frame allocated when calling signal handler. */
92#define __SIGNAL_FRAMESIZE 128
93#define __SIGNAL_FRAMESIZE32 64
94
92/* 95/*
93 * Offsets used by 'ptrace' system call interface. 96 * Offsets used by 'ptrace' system call interface.
94 */ 97 */
@@ -135,17 +138,21 @@ extern unsigned long profile_pc(struct pt_regs *regs);
135#define PT_XER 37 138#define PT_XER 37
136#define PT_CCR 38 139#define PT_CCR 38
137#define PT_SOFTE 39 140#define PT_SOFTE 39
141#define PT_TRAP 40
142#define PT_DAR 41
143#define PT_DSISR 42
138#define PT_RESULT 43 144#define PT_RESULT 43
139 145
140#define PT_FPR0 48 146#define PT_FPR0 48
141 147
142/* Kernel and userspace will both use this PT_FPSCR value. 32-bit apps will have 148/*
143 * visibility to the asm-ppc/ptrace.h header instead of this one. 149 * Kernel and userspace will both use this PT_FPSCR value. 32-bit apps will
150 * have visibility to the asm-ppc/ptrace.h header instead of this one.
144 */ 151 */
145#define PT_FPSCR (PT_FPR0 + 32) /* each FP reg occupies 1 slot in 64-bit space */ 152#define PT_FPSCR (PT_FPR0 + 32) /* each FP reg occupies 1 slot in 64-bit space */
146 153
147#ifdef __KERNEL__ 154#ifdef __KERNEL__
148#define PT_FPSCR32 (PT_FPR0 + 2*32 + 1) /* each FP reg occupies 2 32-bit userspace slots */ 155#define PT_FPSCR32 (PT_FPR0 + 2*32 + 1) /* each FP reg occupies 2 32-bit userspace slots */
149#endif 156#endif
150 157
151#define PT_VR0 82 /* each Vector reg occupies 2 slots in 64-bit */ 158#define PT_VR0 82 /* each Vector reg occupies 2 slots in 64-bit */
@@ -173,17 +180,34 @@ extern unsigned long profile_pc(struct pt_regs *regs);
173#define PTRACE_GETVRREGS 18 180#define PTRACE_GETVRREGS 18
174#define PTRACE_SETVRREGS 19 181#define PTRACE_SETVRREGS 19
175 182
176/* Additional PTRACE requests implemented on PowerPC. */ 183/*
177#define PPC_PTRACE_GETREGS 0x99 /* Get GPRs 0 - 31 */ 184 * While we dont have 64bit book E processors, we need to reserve the
178#define PPC_PTRACE_SETREGS 0x98 /* Set GPRs 0 - 31 */ 185 * relevant ptrace calls for 32bit compatibility.
179#define PPC_PTRACE_GETFPREGS 0x97 /* Get FPRs 0 - 31 */ 186 */
180#define PPC_PTRACE_SETFPREGS 0x96 /* Set FPRs 0 - 31 */ 187#if 0
181#define PPC_PTRACE_PEEKTEXT_3264 0x95 /* Read word at location ADDR on a 64-bit process from a 32-bit process. */ 188#define PTRACE_GETEVRREGS 20
182#define PPC_PTRACE_PEEKDATA_3264 0x94 /* Read word at location ADDR on a 64-bit process from a 32-bit process. */ 189#define PTRACE_SETEVRREGS 21
183#define PPC_PTRACE_POKETEXT_3264 0x93 /* Write word at location ADDR on a 64-bit process from a 32-bit process. */ 190#endif
184#define PPC_PTRACE_POKEDATA_3264 0x92 /* Write word at location ADDR on a 64-bit process from a 32-bit process. */
185#define PPC_PTRACE_PEEKUSR_3264 0x91 /* Read a register (specified by ADDR) out of the "user area" on a 64-bit process from a 32-bit process. */
186#define PPC_PTRACE_POKEUSR_3264 0x90 /* Write DATA into location ADDR within the "user area" on a 64-bit process from a 32-bit process. */
187 191
192/*
193 * Get or set a debug register. The first 16 are DABR registers and the
194 * second 16 are IABR registers.
195 */
196#define PTRACE_GET_DEBUGREG 25
197#define PTRACE_SET_DEBUGREG 26
198
199/* Additional PTRACE requests implemented on PowerPC. */
200#define PPC_PTRACE_GETREGS 0x99 /* Get GPRs 0 - 31 */
201#define PPC_PTRACE_SETREGS 0x98 /* Set GPRs 0 - 31 */
202#define PPC_PTRACE_GETFPREGS 0x97 /* Get FPRs 0 - 31 */
203#define PPC_PTRACE_SETFPREGS 0x96 /* Set FPRs 0 - 31 */
204
205/* Calls to trace a 64bit program from a 32bit program */
206#define PPC_PTRACE_PEEKTEXT_3264 0x95
207#define PPC_PTRACE_PEEKDATA_3264 0x94
208#define PPC_PTRACE_POKETEXT_3264 0x93
209#define PPC_PTRACE_POKEDATA_3264 0x92
210#define PPC_PTRACE_PEEKUSR_3264 0x91
211#define PPC_PTRACE_POKEUSR_3264 0x90
188 212
189#endif /* _PPC64_PTRACE_H */ 213#endif /* _PPC64_PTRACE_H */
diff --git a/include/asm-ppc64/spinlock.h b/include/asm-ppc64/spinlock.h
index acd11564dd..14cb895bb6 100644
--- a/include/asm-ppc64/spinlock.h
+++ b/include/asm-ppc64/spinlock.h
@@ -15,36 +15,42 @@
15 * modify it under the terms of the GNU General Public License 15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 16 * as published by the Free Software Foundation; either version
17 * 2 of the License, or (at your option) any later version. 17 * 2 of the License, or (at your option) any later version.
18 *
19 * (the type definitions are in asm/spinlock_types.h)
18 */ 20 */
19#include <linux/config.h> 21#include <linux/config.h>
20#include <asm/paca.h> 22#include <asm/paca.h>
21#include <asm/hvcall.h> 23#include <asm/hvcall.h>
22#include <asm/iSeries/HvCall.h> 24#include <asm/iSeries/HvCall.h>
23 25
24typedef struct { 26#define __raw_spin_is_locked(x) ((x)->slock != 0)
25 volatile unsigned int lock;
26#ifdef CONFIG_PREEMPT
27 unsigned int break_lock;
28#endif
29} spinlock_t;
30 27
31typedef struct { 28/*
32 volatile signed int lock; 29 * This returns the old value in the lock, so we succeeded
33#ifdef CONFIG_PREEMPT 30 * in getting the lock if the return value is 0.
34 unsigned int break_lock; 31 */
35#endif 32static __inline__ unsigned long __spin_trylock(raw_spinlock_t *lock)
36} rwlock_t; 33{
34 unsigned long tmp, tmp2;
37 35
38#ifdef __KERNEL__ 36 __asm__ __volatile__(
39#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 } 37" lwz %1,%3(13) # __spin_trylock\n\
381: lwarx %0,0,%2\n\
39 cmpwi 0,%0,0\n\
40 bne- 2f\n\
41 stwcx. %1,0,%2\n\
42 bne- 1b\n\
43 isync\n\
442:" : "=&r" (tmp), "=&r" (tmp2)
45 : "r" (&lock->slock), "i" (offsetof(struct paca_struct, lock_token))
46 : "cr0", "memory");
40 47
41#define spin_is_locked(x) ((x)->lock != 0) 48 return tmp;
42#define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while(0) 49}
43 50
44static __inline__ void _raw_spin_unlock(spinlock_t *lock) 51static int __inline__ __raw_spin_trylock(raw_spinlock_t *lock)
45{ 52{
46 __asm__ __volatile__("lwsync # spin_unlock": : :"memory"); 53 return __spin_trylock(lock) == 0;
47 lock->lock = 0;
48} 54}
49 55
50/* 56/*
@@ -64,44 +70,15 @@ static __inline__ void _raw_spin_unlock(spinlock_t *lock)
64#if defined(CONFIG_PPC_SPLPAR) || defined(CONFIG_PPC_ISERIES) 70#if defined(CONFIG_PPC_SPLPAR) || defined(CONFIG_PPC_ISERIES)
65/* We only yield to the hypervisor if we are in shared processor mode */ 71/* We only yield to the hypervisor if we are in shared processor mode */
66#define SHARED_PROCESSOR (get_paca()->lppaca.shared_proc) 72#define SHARED_PROCESSOR (get_paca()->lppaca.shared_proc)
67extern void __spin_yield(spinlock_t *lock); 73extern void __spin_yield(raw_spinlock_t *lock);
68extern void __rw_yield(rwlock_t *lock); 74extern void __rw_yield(raw_rwlock_t *lock);
69#else /* SPLPAR || ISERIES */ 75#else /* SPLPAR || ISERIES */
70#define __spin_yield(x) barrier() 76#define __spin_yield(x) barrier()
71#define __rw_yield(x) barrier() 77#define __rw_yield(x) barrier()
72#define SHARED_PROCESSOR 0 78#define SHARED_PROCESSOR 0
73#endif 79#endif
74extern void spin_unlock_wait(spinlock_t *lock);
75
76/*
77 * This returns the old value in the lock, so we succeeded
78 * in getting the lock if the return value is 0.
79 */
80static __inline__ unsigned long __spin_trylock(spinlock_t *lock)
81{
82 unsigned long tmp, tmp2;
83
84 __asm__ __volatile__(
85" lwz %1,%3(13) # __spin_trylock\n\
861: lwarx %0,0,%2\n\
87 cmpwi 0,%0,0\n\
88 bne- 2f\n\
89 stwcx. %1,0,%2\n\
90 bne- 1b\n\
91 isync\n\
922:" : "=&r" (tmp), "=&r" (tmp2)
93 : "r" (&lock->lock), "i" (offsetof(struct paca_struct, lock_token))
94 : "cr0", "memory");
95
96 return tmp;
97}
98
99static int __inline__ _raw_spin_trylock(spinlock_t *lock)
100{
101 return __spin_trylock(lock) == 0;
102}
103 80
104static void __inline__ _raw_spin_lock(spinlock_t *lock) 81static void __inline__ __raw_spin_lock(raw_spinlock_t *lock)
105{ 82{
106 while (1) { 83 while (1) {
107 if (likely(__spin_trylock(lock) == 0)) 84 if (likely(__spin_trylock(lock) == 0))
@@ -110,12 +87,12 @@ static void __inline__ _raw_spin_lock(spinlock_t *lock)
110 HMT_low(); 87 HMT_low();
111 if (SHARED_PROCESSOR) 88 if (SHARED_PROCESSOR)
112 __spin_yield(lock); 89 __spin_yield(lock);
113 } while (unlikely(lock->lock != 0)); 90 } while (unlikely(lock->slock != 0));
114 HMT_medium(); 91 HMT_medium();
115 } 92 }
116} 93}
117 94
118static void __inline__ _raw_spin_lock_flags(spinlock_t *lock, unsigned long flags) 95static void __inline__ __raw_spin_lock_flags(raw_spinlock_t *lock, unsigned long flags)
119{ 96{
120 unsigned long flags_dis; 97 unsigned long flags_dis;
121 98
@@ -128,12 +105,20 @@ static void __inline__ _raw_spin_lock_flags(spinlock_t *lock, unsigned long flag
128 HMT_low(); 105 HMT_low();
129 if (SHARED_PROCESSOR) 106 if (SHARED_PROCESSOR)
130 __spin_yield(lock); 107 __spin_yield(lock);
131 } while (unlikely(lock->lock != 0)); 108 } while (unlikely(lock->slock != 0));
132 HMT_medium(); 109 HMT_medium();
133 local_irq_restore(flags_dis); 110 local_irq_restore(flags_dis);
134 } 111 }
135} 112}
136 113
114static __inline__ void __raw_spin_unlock(raw_spinlock_t *lock)
115{
116 __asm__ __volatile__("lwsync # __raw_spin_unlock": : :"memory");
117 lock->slock = 0;
118}
119
120extern void __raw_spin_unlock_wait(raw_spinlock_t *lock);
121
137/* 122/*
138 * Read-write spinlocks, allowing multiple readers 123 * Read-write spinlocks, allowing multiple readers
139 * but only one writer. 124 * but only one writer.
@@ -144,24 +129,15 @@ static void __inline__ _raw_spin_lock_flags(spinlock_t *lock, unsigned long flag
144 * irq-safe write-lock, but readers can get non-irqsafe 129 * irq-safe write-lock, but readers can get non-irqsafe
145 * read-locks. 130 * read-locks.
146 */ 131 */
147#define RW_LOCK_UNLOCKED (rwlock_t) { 0 }
148 132
149#define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0) 133#define __raw_read_can_lock(rw) ((rw)->lock >= 0)
150 134#define __raw_write_can_lock(rw) (!(rw)->lock)
151#define read_can_lock(rw) ((rw)->lock >= 0)
152#define write_can_lock(rw) (!(rw)->lock)
153
154static __inline__ void _raw_write_unlock(rwlock_t *rw)
155{
156 __asm__ __volatile__("lwsync # write_unlock": : :"memory");
157 rw->lock = 0;
158}
159 135
160/* 136/*
161 * This returns the old value in the lock + 1, 137 * This returns the old value in the lock + 1,
162 * so we got a read lock if the return value is > 0. 138 * so we got a read lock if the return value is > 0.
163 */ 139 */
164static long __inline__ __read_trylock(rwlock_t *rw) 140static long __inline__ __read_trylock(raw_rwlock_t *rw)
165{ 141{
166 long tmp; 142 long tmp;
167 143
@@ -180,45 +156,11 @@ static long __inline__ __read_trylock(rwlock_t *rw)
180 return tmp; 156 return tmp;
181} 157}
182 158
183static int __inline__ _raw_read_trylock(rwlock_t *rw)
184{
185 return __read_trylock(rw) > 0;
186}
187
188static void __inline__ _raw_read_lock(rwlock_t *rw)
189{
190 while (1) {
191 if (likely(__read_trylock(rw) > 0))
192 break;
193 do {
194 HMT_low();
195 if (SHARED_PROCESSOR)
196 __rw_yield(rw);
197 } while (unlikely(rw->lock < 0));
198 HMT_medium();
199 }
200}
201
202static void __inline__ _raw_read_unlock(rwlock_t *rw)
203{
204 long tmp;
205
206 __asm__ __volatile__(
207 "eieio # read_unlock\n\
2081: lwarx %0,0,%1\n\
209 addic %0,%0,-1\n\
210 stwcx. %0,0,%1\n\
211 bne- 1b"
212 : "=&r"(tmp)
213 : "r"(&rw->lock)
214 : "cr0", "memory");
215}
216
217/* 159/*
218 * This returns the old value in the lock, 160 * This returns the old value in the lock,
219 * so we got the write lock if the return value is 0. 161 * so we got the write lock if the return value is 0.
220 */ 162 */
221static __inline__ long __write_trylock(rwlock_t *rw) 163static __inline__ long __write_trylock(raw_rwlock_t *rw)
222{ 164{
223 long tmp, tmp2; 165 long tmp, tmp2;
224 166
@@ -237,12 +179,21 @@ static __inline__ long __write_trylock(rwlock_t *rw)
237 return tmp; 179 return tmp;
238} 180}
239 181
240static int __inline__ _raw_write_trylock(rwlock_t *rw) 182static void __inline__ __raw_read_lock(raw_rwlock_t *rw)
241{ 183{
242 return __write_trylock(rw) == 0; 184 while (1) {
185 if (likely(__read_trylock(rw) > 0))
186 break;
187 do {
188 HMT_low();
189 if (SHARED_PROCESSOR)
190 __rw_yield(rw);
191 } while (unlikely(rw->lock < 0));
192 HMT_medium();
193 }
243} 194}
244 195
245static void __inline__ _raw_write_lock(rwlock_t *rw) 196static void __inline__ __raw_write_lock(raw_rwlock_t *rw)
246{ 197{
247 while (1) { 198 while (1) {
248 if (likely(__write_trylock(rw) == 0)) 199 if (likely(__write_trylock(rw) == 0))
@@ -256,5 +207,35 @@ static void __inline__ _raw_write_lock(rwlock_t *rw)
256 } 207 }
257} 208}
258 209
259#endif /* __KERNEL__ */ 210static int __inline__ __raw_read_trylock(raw_rwlock_t *rw)
211{
212 return __read_trylock(rw) > 0;
213}
214
215static int __inline__ __raw_write_trylock(raw_rwlock_t *rw)
216{
217 return __write_trylock(rw) == 0;
218}
219
220static void __inline__ __raw_read_unlock(raw_rwlock_t *rw)
221{
222 long tmp;
223
224 __asm__ __volatile__(
225 "eieio # read_unlock\n\
2261: lwarx %0,0,%1\n\
227 addic %0,%0,-1\n\
228 stwcx. %0,0,%1\n\
229 bne- 1b"
230 : "=&r"(tmp)
231 : "r"(&rw->lock)
232 : "cr0", "memory");
233}
234
235static __inline__ void __raw_write_unlock(raw_rwlock_t *rw)
236{
237 __asm__ __volatile__("lwsync # write_unlock": : :"memory");
238 rw->lock = 0;
239}
240
260#endif /* __ASM_SPINLOCK_H */ 241#endif /* __ASM_SPINLOCK_H */
diff --git a/include/asm-ppc64/spinlock_types.h b/include/asm-ppc64/spinlock_types.h
new file mode 100644
index 0000000000..a37c8eabb9
--- /dev/null
+++ b/include/asm-ppc64/spinlock_types.h
@@ -0,0 +1,20 @@
1#ifndef __ASM_SPINLOCK_TYPES_H
2#define __ASM_SPINLOCK_TYPES_H
3
4#ifndef __LINUX_SPINLOCK_TYPES_H
5# error "please don't include this file directly"
6#endif
7
8typedef struct {
9 volatile unsigned int slock;
10} raw_spinlock_t;
11
12#define __RAW_SPIN_LOCK_UNLOCKED { 0 }
13
14typedef struct {
15 volatile signed int lock;
16} raw_rwlock_t;
17
18#define __RAW_RW_LOCK_UNLOCKED { 0 }
19
20#endif
diff --git a/include/asm-ppc64/system.h b/include/asm-ppc64/system.h
index c0396428cc..375015c62f 100644
--- a/include/asm-ppc64/system.h
+++ b/include/asm-ppc64/system.h
@@ -101,6 +101,9 @@ static inline int debugger_dabr_match(struct pt_regs *regs) { return 0; }
101static inline int debugger_fault_handler(struct pt_regs *regs) { return 0; } 101static inline int debugger_fault_handler(struct pt_regs *regs) { return 0; }
102#endif 102#endif
103 103
104extern int set_dabr(unsigned long dabr);
105extern void _exception(int signr, struct pt_regs *regs, int code,
106 unsigned long addr);
104extern int fix_alignment(struct pt_regs *regs); 107extern int fix_alignment(struct pt_regs *regs);
105extern void bad_page_fault(struct pt_regs *regs, unsigned long address, 108extern void bad_page_fault(struct pt_regs *regs, unsigned long address,
106 int sig); 109 int sig);
diff --git a/include/asm-s390/spinlock.h b/include/asm-s390/spinlock.h
index 321b23bba1..273dbecf8a 100644
--- a/include/asm-s390/spinlock.h
+++ b/include/asm-s390/spinlock.h
@@ -27,25 +27,19 @@ _raw_compare_and_swap(volatile unsigned int *lock,
27 * on the local processor, one does not. 27 * on the local processor, one does not.
28 * 28 *
29 * We make no fairness assumptions. They have a cost. 29 * We make no fairness assumptions. They have a cost.
30 *
31 * (the type definitions are in asm/spinlock_types.h)
30 */ 32 */
31 33
32typedef struct { 34#define __raw_spin_is_locked(x) ((x)->lock != 0)
33 volatile unsigned int lock; 35#define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
34#ifdef CONFIG_PREEMPT 36#define __raw_spin_unlock_wait(lock) \
35 unsigned int break_lock; 37 do { while (__raw_spin_is_locked(lock)) cpu_relax(); } while (0)
36#endif
37} __attribute__ ((aligned (4))) spinlock_t;
38
39#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 }
40#define spin_lock_init(lp) do { (lp)->lock = 0; } while(0)
41#define spin_unlock_wait(lp) do { barrier(); } while(((volatile spinlock_t *)(lp))->lock)
42#define spin_is_locked(x) ((x)->lock != 0)
43#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
44 38
45extern void _raw_spin_lock_wait(spinlock_t *lp, unsigned int pc); 39extern void _raw_spin_lock_wait(raw_spinlock_t *lp, unsigned int pc);
46extern int _raw_spin_trylock_retry(spinlock_t *lp, unsigned int pc); 40extern int _raw_spin_trylock_retry(raw_spinlock_t *lp, unsigned int pc);
47 41
48static inline void _raw_spin_lock(spinlock_t *lp) 42static inline void __raw_spin_lock(raw_spinlock_t *lp)
49{ 43{
50 unsigned long pc = 1 | (unsigned long) __builtin_return_address(0); 44 unsigned long pc = 1 | (unsigned long) __builtin_return_address(0);
51 45
@@ -53,7 +47,7 @@ static inline void _raw_spin_lock(spinlock_t *lp)
53 _raw_spin_lock_wait(lp, pc); 47 _raw_spin_lock_wait(lp, pc);
54} 48}
55 49
56static inline int _raw_spin_trylock(spinlock_t *lp) 50static inline int __raw_spin_trylock(raw_spinlock_t *lp)
57{ 51{
58 unsigned long pc = 1 | (unsigned long) __builtin_return_address(0); 52 unsigned long pc = 1 | (unsigned long) __builtin_return_address(0);
59 53
@@ -62,7 +56,7 @@ static inline int _raw_spin_trylock(spinlock_t *lp)
62 return _raw_spin_trylock_retry(lp, pc); 56 return _raw_spin_trylock_retry(lp, pc);
63} 57}
64 58
65static inline void _raw_spin_unlock(spinlock_t *lp) 59static inline void __raw_spin_unlock(raw_spinlock_t *lp)
66{ 60{
67 _raw_compare_and_swap(&lp->lock, lp->lock, 0); 61 _raw_compare_and_swap(&lp->lock, lp->lock, 0);
68} 62}
@@ -77,36 +71,25 @@ static inline void _raw_spin_unlock(spinlock_t *lp)
77 * irq-safe write-lock, but readers can get non-irqsafe 71 * irq-safe write-lock, but readers can get non-irqsafe
78 * read-locks. 72 * read-locks.
79 */ 73 */
80typedef struct {
81 volatile unsigned int lock;
82 volatile unsigned long owner_pc;
83#ifdef CONFIG_PREEMPT
84 unsigned int break_lock;
85#endif
86} rwlock_t;
87
88#define RW_LOCK_UNLOCKED (rwlock_t) { 0, 0 }
89
90#define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0)
91 74
92/** 75/**
93 * read_can_lock - would read_trylock() succeed? 76 * read_can_lock - would read_trylock() succeed?
94 * @lock: the rwlock in question. 77 * @lock: the rwlock in question.
95 */ 78 */
96#define read_can_lock(x) ((int)(x)->lock >= 0) 79#define __raw_read_can_lock(x) ((int)(x)->lock >= 0)
97 80
98/** 81/**
99 * write_can_lock - would write_trylock() succeed? 82 * write_can_lock - would write_trylock() succeed?
100 * @lock: the rwlock in question. 83 * @lock: the rwlock in question.
101 */ 84 */
102#define write_can_lock(x) ((x)->lock == 0) 85#define __raw_write_can_lock(x) ((x)->lock == 0)
103 86
104extern void _raw_read_lock_wait(rwlock_t *lp); 87extern void _raw_read_lock_wait(raw_rwlock_t *lp);
105extern int _raw_read_trylock_retry(rwlock_t *lp); 88extern int _raw_read_trylock_retry(raw_rwlock_t *lp);
106extern void _raw_write_lock_wait(rwlock_t *lp); 89extern void _raw_write_lock_wait(raw_rwlock_t *lp);
107extern int _raw_write_trylock_retry(rwlock_t *lp); 90extern int _raw_write_trylock_retry(raw_rwlock_t *lp);
108 91
109static inline void _raw_read_lock(rwlock_t *rw) 92static inline void __raw_read_lock(raw_rwlock_t *rw)
110{ 93{
111 unsigned int old; 94 unsigned int old;
112 old = rw->lock & 0x7fffffffU; 95 old = rw->lock & 0x7fffffffU;
@@ -114,7 +97,7 @@ static inline void _raw_read_lock(rwlock_t *rw)
114 _raw_read_lock_wait(rw); 97 _raw_read_lock_wait(rw);
115} 98}
116 99
117static inline void _raw_read_unlock(rwlock_t *rw) 100static inline void __raw_read_unlock(raw_rwlock_t *rw)
118{ 101{
119 unsigned int old, cmp; 102 unsigned int old, cmp;
120 103
@@ -125,18 +108,18 @@ static inline void _raw_read_unlock(rwlock_t *rw)
125 } while (cmp != old); 108 } while (cmp != old);
126} 109}
127 110
128static inline void _raw_write_lock(rwlock_t *rw) 111static inline void __raw_write_lock(raw_rwlock_t *rw)
129{ 112{
130 if (unlikely(_raw_compare_and_swap(&rw->lock, 0, 0x80000000) != 0)) 113 if (unlikely(_raw_compare_and_swap(&rw->lock, 0, 0x80000000) != 0))
131 _raw_write_lock_wait(rw); 114 _raw_write_lock_wait(rw);
132} 115}
133 116
134static inline void _raw_write_unlock(rwlock_t *rw) 117static inline void __raw_write_unlock(raw_rwlock_t *rw)
135{ 118{
136 _raw_compare_and_swap(&rw->lock, 0x80000000, 0); 119 _raw_compare_and_swap(&rw->lock, 0x80000000, 0);
137} 120}
138 121
139static inline int _raw_read_trylock(rwlock_t *rw) 122static inline int __raw_read_trylock(raw_rwlock_t *rw)
140{ 123{
141 unsigned int old; 124 unsigned int old;
142 old = rw->lock & 0x7fffffffU; 125 old = rw->lock & 0x7fffffffU;
@@ -145,7 +128,7 @@ static inline int _raw_read_trylock(rwlock_t *rw)
145 return _raw_read_trylock_retry(rw); 128 return _raw_read_trylock_retry(rw);
146} 129}
147 130
148static inline int _raw_write_trylock(rwlock_t *rw) 131static inline int __raw_write_trylock(raw_rwlock_t *rw)
149{ 132{
150 if (likely(_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)) 133 if (likely(_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0))
151 return 1; 134 return 1;
diff --git a/include/asm-s390/spinlock_types.h b/include/asm-s390/spinlock_types.h
new file mode 100644
index 0000000000..f79a221620
--- /dev/null
+++ b/include/asm-s390/spinlock_types.h
@@ -0,0 +1,21 @@
1#ifndef __ASM_SPINLOCK_TYPES_H
2#define __ASM_SPINLOCK_TYPES_H
3
4#ifndef __LINUX_SPINLOCK_TYPES_H
5# error "please don't include this file directly"
6#endif
7
8typedef struct {
9 volatile unsigned int lock;
10} __attribute__ ((aligned (4))) raw_spinlock_t;
11
12#define __RAW_SPIN_LOCK_UNLOCKED { 0 }
13
14typedef struct {
15 volatile unsigned int lock;
16 volatile unsigned int owner_pc;
17} raw_rwlock_t;
18
19#define __RAW_RW_LOCK_UNLOCKED { 0, 0 }
20
21#endif
diff --git a/include/asm-sh/irq.h b/include/asm-sh/irq.h
index 831e52ee45..614a8c13b7 100644
--- a/include/asm-sh/irq.h
+++ b/include/asm-sh/irq.h
@@ -587,10 +587,6 @@ static inline int generic_irq_demux(int irq)
587#define irq_canonicalize(irq) (irq) 587#define irq_canonicalize(irq) (irq)
588#define irq_demux(irq) __irq_demux(sh_mv.mv_irq_demux(irq)) 588#define irq_demux(irq) __irq_demux(sh_mv.mv_irq_demux(irq))
589 589
590struct irqaction;
591struct pt_regs;
592int handle_IRQ_event(unsigned int, struct pt_regs *, struct irqaction *);
593
594#if defined(CONFIG_CPU_SUBTYPE_SH73180) 590#if defined(CONFIG_CPU_SUBTYPE_SH73180)
595#include <asm/irq-sh73180.h> 591#include <asm/irq-sh73180.h>
596#endif 592#endif
diff --git a/include/asm-sh/spinlock.h b/include/asm-sh/spinlock.h
index e770b55649..846322d4c3 100644
--- a/include/asm-sh/spinlock.h
+++ b/include/asm-sh/spinlock.h
@@ -15,20 +15,11 @@
15/* 15/*
16 * Your basic SMP spinlocks, allowing only a single CPU anywhere 16 * Your basic SMP spinlocks, allowing only a single CPU anywhere
17 */ 17 */
18typedef struct {
19 volatile unsigned long lock;
20#ifdef CONFIG_PREEMPT
21 unsigned int break_lock;
22#endif
23} spinlock_t;
24 18
25#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 } 19#define __raw_spin_is_locked(x) ((x)->lock != 0)
26 20#define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
27#define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while(0) 21#define __raw_spin_unlock_wait(x) \
28 22 do { cpu_relax(); } while (__raw_spin_is_locked(x))
29#define spin_is_locked(x) ((x)->lock != 0)
30#define spin_unlock_wait(x) do { barrier(); } while (spin_is_locked(x))
31#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
32 23
33/* 24/*
34 * Simple spin lock operations. There are two variants, one clears IRQ's 25 * Simple spin lock operations. There are two variants, one clears IRQ's
@@ -36,7 +27,7 @@ typedef struct {
36 * 27 *
37 * We make no fairness assumptions. They have a cost. 28 * We make no fairness assumptions. They have a cost.
38 */ 29 */
39static inline void _raw_spin_lock(spinlock_t *lock) 30static inline void __raw_spin_lock(raw_spinlock_t *lock)
40{ 31{
41 __asm__ __volatile__ ( 32 __asm__ __volatile__ (
42 "1:\n\t" 33 "1:\n\t"
@@ -49,14 +40,14 @@ static inline void _raw_spin_lock(spinlock_t *lock)
49 ); 40 );
50} 41}
51 42
52static inline void _raw_spin_unlock(spinlock_t *lock) 43static inline void __raw_spin_unlock(raw_spinlock_t *lock)
53{ 44{
54 assert_spin_locked(lock); 45 assert_spin_locked(lock);
55 46
56 lock->lock = 0; 47 lock->lock = 0;
57} 48}
58 49
59#define _raw_spin_trylock(x) (!test_and_set_bit(0, &(x)->lock)) 50#define __raw_spin_trylock(x) (!test_and_set_bit(0, &(x)->lock))
60 51
61/* 52/*
62 * Read-write spinlocks, allowing multiple readers but only one writer. 53 * Read-write spinlocks, allowing multiple readers but only one writer.
@@ -66,51 +57,40 @@ static inline void _raw_spin_unlock(spinlock_t *lock)
66 * needs to get a irq-safe write-lock, but readers can get non-irqsafe 57 * needs to get a irq-safe write-lock, but readers can get non-irqsafe
67 * read-locks. 58 * read-locks.
68 */ 59 */
69typedef struct { 60
70 spinlock_t lock; 61static inline void __raw_read_lock(raw_rwlock_t *rw)
71 atomic_t counter;
72#ifdef CONFIG_PREEMPT
73 unsigned int break_lock;
74#endif
75} rwlock_t;
76
77#define RW_LOCK_BIAS 0x01000000
78#define RW_LOCK_UNLOCKED (rwlock_t) { { 0 }, { RW_LOCK_BIAS } }
79#define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while (0)
80
81static inline void _raw_read_lock(rwlock_t *rw)
82{ 62{
83 _raw_spin_lock(&rw->lock); 63 __raw_spin_lock(&rw->lock);
84 64
85 atomic_inc(&rw->counter); 65 atomic_inc(&rw->counter);
86 66
87 _raw_spin_unlock(&rw->lock); 67 __raw_spin_unlock(&rw->lock);
88} 68}
89 69
90static inline void _raw_read_unlock(rwlock_t *rw) 70static inline void __raw_read_unlock(raw_rwlock_t *rw)
91{ 71{
92 _raw_spin_lock(&rw->lock); 72 __raw_spin_lock(&rw->lock);
93 73
94 atomic_dec(&rw->counter); 74 atomic_dec(&rw->counter);
95 75
96 _raw_spin_unlock(&rw->lock); 76 __raw_spin_unlock(&rw->lock);
97} 77}
98 78
99static inline void _raw_write_lock(rwlock_t *rw) 79static inline void __raw_write_lock(raw_rwlock_t *rw)
100{ 80{
101 _raw_spin_lock(&rw->lock); 81 __raw_spin_lock(&rw->lock);
102 atomic_set(&rw->counter, -1); 82 atomic_set(&rw->counter, -1);
103} 83}
104 84
105static inline void _raw_write_unlock(rwlock_t *rw) 85static inline void __raw_write_unlock(raw_rwlock_t *rw)
106{ 86{
107 atomic_set(&rw->counter, 0); 87 atomic_set(&rw->counter, 0);
108 _raw_spin_unlock(&rw->lock); 88 __raw_spin_unlock(&rw->lock);
109} 89}
110 90
111#define _raw_read_trylock(lock) generic_raw_read_trylock(lock) 91#define __raw_read_trylock(lock) generic__raw_read_trylock(lock)
112 92
113static inline int _raw_write_trylock(rwlock_t *rw) 93static inline int __raw_write_trylock(raw_rwlock_t *rw)
114{ 94{
115 if (atomic_sub_and_test(RW_LOCK_BIAS, &rw->counter)) 95 if (atomic_sub_and_test(RW_LOCK_BIAS, &rw->counter))
116 return 1; 96 return 1;
@@ -121,4 +101,3 @@ static inline int _raw_write_trylock(rwlock_t *rw)
121} 101}
122 102
123#endif /* __ASM_SH_SPINLOCK_H */ 103#endif /* __ASM_SH_SPINLOCK_H */
124
diff --git a/include/asm-sh/spinlock_types.h b/include/asm-sh/spinlock_types.h
new file mode 100644
index 0000000000..8c41b6c3aa
--- /dev/null
+++ b/include/asm-sh/spinlock_types.h
@@ -0,0 +1,22 @@
1#ifndef __ASM_SH_SPINLOCK_TYPES_H
2#define __ASM_SH_SPINLOCK_TYPES_H
3
4#ifndef __LINUX_SPINLOCK_TYPES_H
5# error "please don't include this file directly"
6#endif
7
8typedef struct {
9 volatile unsigned long lock;
10} raw_spinlock_t;
11
12#define __SPIN_LOCK_UNLOCKED { 0 }
13
14typedef struct {
15 raw_spinlock_t lock;
16 atomic_t counter;
17} raw_rwlock_t;
18
19#define RW_LOCK_BIAS 0x01000000
20#define __RAW_RW_LOCK_UNLOCKED { { 0 }, { RW_LOCK_BIAS } }
21
22#endif
diff --git a/include/asm-sparc/ptrace.h b/include/asm-sparc/ptrace.h
index dd9d94d7e0..a8ecb2d697 100644
--- a/include/asm-sparc/ptrace.h
+++ b/include/asm-sparc/ptrace.h
@@ -73,11 +73,11 @@ extern void show_regs(struct pt_regs *);
73#endif 73#endif
74 74
75/* 75/*
76 * The asm_offsets.h is a generated file, so we cannot include it. 76 * The asm-offsets.h is a generated file, so we cannot include it.
77 * It may be OK for glibc headers, but it's utterly pointless for C code. 77 * It may be OK for glibc headers, but it's utterly pointless for C code.
78 * The assembly code using those offsets has to include it explicitly. 78 * The assembly code using those offsets has to include it explicitly.
79 */ 79 */
80/* #include <asm/asm_offsets.h> */ 80/* #include <asm/asm-offsets.h> */
81 81
82/* These are for pt_regs. */ 82/* These are for pt_regs. */
83#define PT_PSR 0x0 83#define PT_PSR 0x0
diff --git a/include/asm-sparc/spinlock.h b/include/asm-sparc/spinlock.h
index 0cbd87ad49..111727a2bb 100644
--- a/include/asm-sparc/spinlock.h
+++ b/include/asm-sparc/spinlock.h
@@ -12,96 +12,12 @@
12 12
13#include <asm/psr.h> 13#include <asm/psr.h>
14 14
15#ifdef CONFIG_DEBUG_SPINLOCK 15#define __raw_spin_is_locked(lock) (*((volatile unsigned char *)(lock)) != 0)
16struct _spinlock_debug {
17 unsigned char lock;
18 unsigned long owner_pc;
19#ifdef CONFIG_PREEMPT
20 unsigned int break_lock;
21#endif
22};
23typedef struct _spinlock_debug spinlock_t;
24
25#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0, 0 }
26#define spin_lock_init(lp) do { *(lp)= SPIN_LOCK_UNLOCKED; } while(0)
27#define spin_is_locked(lp) (*((volatile unsigned char *)(&((lp)->lock))) != 0)
28#define spin_unlock_wait(lp) do { barrier(); } while(*(volatile unsigned char *)(&(lp)->lock))
29
30extern void _do_spin_lock(spinlock_t *lock, char *str);
31extern int _spin_trylock(spinlock_t *lock);
32extern void _do_spin_unlock(spinlock_t *lock);
33
34#define _raw_spin_trylock(lp) _spin_trylock(lp)
35#define _raw_spin_lock(lock) _do_spin_lock(lock, "spin_lock")
36#define _raw_spin_unlock(lock) _do_spin_unlock(lock)
37
38struct _rwlock_debug {
39 volatile unsigned int lock;
40 unsigned long owner_pc;
41 unsigned long reader_pc[NR_CPUS];
42#ifdef CONFIG_PREEMPT
43 unsigned int break_lock;
44#endif
45};
46typedef struct _rwlock_debug rwlock_t;
47
48#define RW_LOCK_UNLOCKED (rwlock_t) { 0, 0, {0} }
49
50#define rwlock_init(lp) do { *(lp)= RW_LOCK_UNLOCKED; } while(0)
51
52extern void _do_read_lock(rwlock_t *rw, char *str);
53extern void _do_read_unlock(rwlock_t *rw, char *str);
54extern void _do_write_lock(rwlock_t *rw, char *str);
55extern void _do_write_unlock(rwlock_t *rw);
56
57#define _raw_read_lock(lock) \
58do { unsigned long flags; \
59 local_irq_save(flags); \
60 _do_read_lock(lock, "read_lock"); \
61 local_irq_restore(flags); \
62} while(0)
63
64#define _raw_read_unlock(lock) \
65do { unsigned long flags; \
66 local_irq_save(flags); \
67 _do_read_unlock(lock, "read_unlock"); \
68 local_irq_restore(flags); \
69} while(0)
70
71#define _raw_write_lock(lock) \
72do { unsigned long flags; \
73 local_irq_save(flags); \
74 _do_write_lock(lock, "write_lock"); \
75 local_irq_restore(flags); \
76} while(0)
77
78#define _raw_write_unlock(lock) \
79do { unsigned long flags; \
80 local_irq_save(flags); \
81 _do_write_unlock(lock); \
82 local_irq_restore(flags); \
83} while(0)
84
85#else /* !CONFIG_DEBUG_SPINLOCK */
86
87typedef struct {
88 unsigned char lock;
89#ifdef CONFIG_PREEMPT
90 unsigned int break_lock;
91#endif
92} spinlock_t;
93
94#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 }
95
96#define spin_lock_init(lock) (*((unsigned char *)(lock)) = 0)
97#define spin_is_locked(lock) (*((volatile unsigned char *)(lock)) != 0)
98 16
99#define spin_unlock_wait(lock) \ 17#define __raw_spin_unlock_wait(lock) \
100do { \ 18 do { while (__raw_spin_is_locked(lock)) cpu_relax(); } while (0)
101 barrier(); \
102} while(*((volatile unsigned char *)lock))
103 19
104extern __inline__ void _raw_spin_lock(spinlock_t *lock) 20extern __inline__ void __raw_spin_lock(raw_spinlock_t *lock)
105{ 21{
106 __asm__ __volatile__( 22 __asm__ __volatile__(
107 "\n1:\n\t" 23 "\n1:\n\t"
@@ -121,7 +37,7 @@ extern __inline__ void _raw_spin_lock(spinlock_t *lock)
121 : "g2", "memory", "cc"); 37 : "g2", "memory", "cc");
122} 38}
123 39
124extern __inline__ int _raw_spin_trylock(spinlock_t *lock) 40extern __inline__ int __raw_spin_trylock(raw_spinlock_t *lock)
125{ 41{
126 unsigned int result; 42 unsigned int result;
127 __asm__ __volatile__("ldstub [%1], %0" 43 __asm__ __volatile__("ldstub [%1], %0"
@@ -131,7 +47,7 @@ extern __inline__ int _raw_spin_trylock(spinlock_t *lock)
131 return (result == 0); 47 return (result == 0);
132} 48}
133 49
134extern __inline__ void _raw_spin_unlock(spinlock_t *lock) 50extern __inline__ void __raw_spin_unlock(raw_spinlock_t *lock)
135{ 51{
136 __asm__ __volatile__("stb %%g0, [%0]" : : "r" (lock) : "memory"); 52 __asm__ __volatile__("stb %%g0, [%0]" : : "r" (lock) : "memory");
137} 53}
@@ -147,23 +63,11 @@ extern __inline__ void _raw_spin_unlock(spinlock_t *lock)
147 * 63 *
148 * XXX This might create some problems with my dual spinlock 64 * XXX This might create some problems with my dual spinlock
149 * XXX scheme, deadlocks etc. -DaveM 65 * XXX scheme, deadlocks etc. -DaveM
150 */ 66 *
151typedef struct { 67 * Sort of like atomic_t's on Sparc, but even more clever.
152 volatile unsigned int lock;
153#ifdef CONFIG_PREEMPT
154 unsigned int break_lock;
155#endif
156} rwlock_t;
157
158#define RW_LOCK_UNLOCKED (rwlock_t) { 0 }
159
160#define rwlock_init(lp) do { *(lp)= RW_LOCK_UNLOCKED; } while(0)
161
162
163/* Sort of like atomic_t's on Sparc, but even more clever.
164 * 68 *
165 * ------------------------------------ 69 * ------------------------------------
166 * | 24-bit counter | wlock | rwlock_t 70 * | 24-bit counter | wlock | raw_rwlock_t
167 * ------------------------------------ 71 * ------------------------------------
168 * 31 8 7 0 72 * 31 8 7 0
169 * 73 *
@@ -174,9 +78,9 @@ typedef struct {
174 * 78 *
175 * Unfortunately this scheme limits us to ~16,000,000 cpus. 79 * Unfortunately this scheme limits us to ~16,000,000 cpus.
176 */ 80 */
177extern __inline__ void _read_lock(rwlock_t *rw) 81extern __inline__ void __read_lock(raw_rwlock_t *rw)
178{ 82{
179 register rwlock_t *lp asm("g1"); 83 register raw_rwlock_t *lp asm("g1");
180 lp = rw; 84 lp = rw;
181 __asm__ __volatile__( 85 __asm__ __volatile__(
182 "mov %%o7, %%g4\n\t" 86 "mov %%o7, %%g4\n\t"
@@ -187,16 +91,16 @@ extern __inline__ void _read_lock(rwlock_t *rw)
187 : "g2", "g4", "memory", "cc"); 91 : "g2", "g4", "memory", "cc");
188} 92}
189 93
190#define _raw_read_lock(lock) \ 94#define __raw_read_lock(lock) \
191do { unsigned long flags; \ 95do { unsigned long flags; \
192 local_irq_save(flags); \ 96 local_irq_save(flags); \
193 _read_lock(lock); \ 97 __raw_read_lock(lock); \
194 local_irq_restore(flags); \ 98 local_irq_restore(flags); \
195} while(0) 99} while(0)
196 100
197extern __inline__ void _read_unlock(rwlock_t *rw) 101extern __inline__ void __read_unlock(raw_rwlock_t *rw)
198{ 102{
199 register rwlock_t *lp asm("g1"); 103 register raw_rwlock_t *lp asm("g1");
200 lp = rw; 104 lp = rw;
201 __asm__ __volatile__( 105 __asm__ __volatile__(
202 "mov %%o7, %%g4\n\t" 106 "mov %%o7, %%g4\n\t"
@@ -207,16 +111,16 @@ extern __inline__ void _read_unlock(rwlock_t *rw)
207 : "g2", "g4", "memory", "cc"); 111 : "g2", "g4", "memory", "cc");
208} 112}
209 113
210#define _raw_read_unlock(lock) \ 114#define __raw_read_unlock(lock) \
211do { unsigned long flags; \ 115do { unsigned long flags; \
212 local_irq_save(flags); \ 116 local_irq_save(flags); \
213 _read_unlock(lock); \ 117 __raw_read_unlock(lock); \
214 local_irq_restore(flags); \ 118 local_irq_restore(flags); \
215} while(0) 119} while(0)
216 120
217extern __inline__ void _raw_write_lock(rwlock_t *rw) 121extern __inline__ void __raw_write_lock(raw_rwlock_t *rw)
218{ 122{
219 register rwlock_t *lp asm("g1"); 123 register raw_rwlock_t *lp asm("g1");
220 lp = rw; 124 lp = rw;
221 __asm__ __volatile__( 125 __asm__ __volatile__(
222 "mov %%o7, %%g4\n\t" 126 "mov %%o7, %%g4\n\t"
@@ -227,11 +131,9 @@ extern __inline__ void _raw_write_lock(rwlock_t *rw)
227 : "g2", "g4", "memory", "cc"); 131 : "g2", "g4", "memory", "cc");
228} 132}
229 133
230#define _raw_write_unlock(rw) do { (rw)->lock = 0; } while(0) 134#define __raw_write_unlock(rw) do { (rw)->lock = 0; } while(0)
231
232#endif /* CONFIG_DEBUG_SPINLOCK */
233 135
234#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock) 136#define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
235 137
236#endif /* !(__ASSEMBLY__) */ 138#endif /* !(__ASSEMBLY__) */
237 139
diff --git a/include/asm-sparc/spinlock_types.h b/include/asm-sparc/spinlock_types.h
new file mode 100644
index 0000000000..0a0fb116c4
--- /dev/null
+++ b/include/asm-sparc/spinlock_types.h
@@ -0,0 +1,20 @@
1#ifndef __SPARC_SPINLOCK_TYPES_H
2#define __SPARC_SPINLOCK_TYPES_H
3
4#ifndef __LINUX_SPINLOCK_TYPES_H
5# error "please don't include this file directly"
6#endif
7
8typedef struct {
9 unsigned char lock;
10} raw_spinlock_t;
11
12#define __RAW_SPIN_LOCK_UNLOCKED { 0 }
13
14typedef struct {
15 volatile unsigned int lock;
16} raw_rwlock_t;
17
18#define __RAW_RW_LOCK_UNLOCKED { 0 }
19
20#endif
diff --git a/include/asm-sparc64/spinlock.h b/include/asm-sparc64/spinlock.h
index a02c4370eb..ec85d12d73 100644
--- a/include/asm-sparc64/spinlock.h
+++ b/include/asm-sparc64/spinlock.h
@@ -29,24 +29,13 @@
29 * must be pre-V9 branches. 29 * must be pre-V9 branches.
30 */ 30 */
31 31
32#ifndef CONFIG_DEBUG_SPINLOCK 32#define __raw_spin_is_locked(lp) ((lp)->lock != 0)
33 33
34typedef struct { 34#define __raw_spin_unlock_wait(lp) \
35 volatile unsigned char lock; 35 do { rmb(); \
36#ifdef CONFIG_PREEMPT 36 } while((lp)->lock)
37 unsigned int break_lock;
38#endif
39} spinlock_t;
40#define SPIN_LOCK_UNLOCKED (spinlock_t) {0,}
41 37
42#define spin_lock_init(lp) do { *(lp)= SPIN_LOCK_UNLOCKED; } while(0) 38static inline void __raw_spin_lock(raw_spinlock_t *lock)
43#define spin_is_locked(lp) ((lp)->lock != 0)
44
45#define spin_unlock_wait(lp) \
46do { rmb(); \
47} while((lp)->lock)
48
49static inline void _raw_spin_lock(spinlock_t *lock)
50{ 39{
51 unsigned long tmp; 40 unsigned long tmp;
52 41
@@ -67,7 +56,7 @@ static inline void _raw_spin_lock(spinlock_t *lock)
67 : "memory"); 56 : "memory");
68} 57}
69 58
70static inline int _raw_spin_trylock(spinlock_t *lock) 59static inline int __raw_spin_trylock(raw_spinlock_t *lock)
71{ 60{
72 unsigned long result; 61 unsigned long result;
73 62
@@ -81,7 +70,7 @@ static inline int _raw_spin_trylock(spinlock_t *lock)
81 return (result == 0UL); 70 return (result == 0UL);
82} 71}
83 72
84static inline void _raw_spin_unlock(spinlock_t *lock) 73static inline void __raw_spin_unlock(raw_spinlock_t *lock)
85{ 74{
86 __asm__ __volatile__( 75 __asm__ __volatile__(
87" membar #StoreStore | #LoadStore\n" 76" membar #StoreStore | #LoadStore\n"
@@ -91,7 +80,7 @@ static inline void _raw_spin_unlock(spinlock_t *lock)
91 : "memory"); 80 : "memory");
92} 81}
93 82
94static inline void _raw_spin_lock_flags(spinlock_t *lock, unsigned long flags) 83static inline void __raw_spin_lock_flags(raw_spinlock_t *lock, unsigned long flags)
95{ 84{
96 unsigned long tmp1, tmp2; 85 unsigned long tmp1, tmp2;
97 86
@@ -115,51 +104,9 @@ static inline void _raw_spin_lock_flags(spinlock_t *lock, unsigned long flags)
115 : "memory"); 104 : "memory");
116} 105}
117 106
118#else /* !(CONFIG_DEBUG_SPINLOCK) */
119
120typedef struct {
121 volatile unsigned char lock;
122 unsigned int owner_pc, owner_cpu;
123#ifdef CONFIG_PREEMPT
124 unsigned int break_lock;
125#endif
126} spinlock_t;
127#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0, 0, 0xff }
128#define spin_lock_init(lp) do { *(lp)= SPIN_LOCK_UNLOCKED; } while(0)
129#define spin_is_locked(__lock) ((__lock)->lock != 0)
130#define spin_unlock_wait(__lock) \
131do { \
132 rmb(); \
133} while((__lock)->lock)
134
135extern void _do_spin_lock(spinlock_t *lock, char *str, unsigned long caller);
136extern void _do_spin_unlock(spinlock_t *lock);
137extern int _do_spin_trylock(spinlock_t *lock, unsigned long caller);
138
139#define _raw_spin_trylock(lp) \
140 _do_spin_trylock(lp, (unsigned long) __builtin_return_address(0))
141#define _raw_spin_lock(lock) \
142 _do_spin_lock(lock, "spin_lock", \
143 (unsigned long) __builtin_return_address(0))
144#define _raw_spin_unlock(lock) _do_spin_unlock(lock)
145#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
146
147#endif /* CONFIG_DEBUG_SPINLOCK */
148
149/* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */ 107/* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
150 108
151#ifndef CONFIG_DEBUG_SPINLOCK 109static void inline __read_lock(raw_rwlock_t *lock)
152
153typedef struct {
154 volatile unsigned int lock;
155#ifdef CONFIG_PREEMPT
156 unsigned int break_lock;
157#endif
158} rwlock_t;
159#define RW_LOCK_UNLOCKED (rwlock_t) {0,}
160#define rwlock_init(lp) do { *(lp) = RW_LOCK_UNLOCKED; } while(0)
161
162static void inline __read_lock(rwlock_t *lock)
163{ 110{
164 unsigned long tmp1, tmp2; 111 unsigned long tmp1, tmp2;
165 112
@@ -184,7 +131,7 @@ static void inline __read_lock(rwlock_t *lock)
184 : "memory"); 131 : "memory");
185} 132}
186 133
187static void inline __read_unlock(rwlock_t *lock) 134static void inline __read_unlock(raw_rwlock_t *lock)
188{ 135{
189 unsigned long tmp1, tmp2; 136 unsigned long tmp1, tmp2;
190 137
@@ -201,7 +148,7 @@ static void inline __read_unlock(rwlock_t *lock)
201 : "memory"); 148 : "memory");
202} 149}
203 150
204static void inline __write_lock(rwlock_t *lock) 151static void inline __write_lock(raw_rwlock_t *lock)
205{ 152{
206 unsigned long mask, tmp1, tmp2; 153 unsigned long mask, tmp1, tmp2;
207 154
@@ -228,7 +175,7 @@ static void inline __write_lock(rwlock_t *lock)
228 : "memory"); 175 : "memory");
229} 176}
230 177
231static void inline __write_unlock(rwlock_t *lock) 178static void inline __write_unlock(raw_rwlock_t *lock)
232{ 179{
233 __asm__ __volatile__( 180 __asm__ __volatile__(
234" membar #LoadStore | #StoreStore\n" 181" membar #LoadStore | #StoreStore\n"
@@ -238,7 +185,7 @@ static void inline __write_unlock(rwlock_t *lock)
238 : "memory"); 185 : "memory");
239} 186}
240 187
241static int inline __write_trylock(rwlock_t *lock) 188static int inline __write_trylock(raw_rwlock_t *lock)
242{ 189{
243 unsigned long mask, tmp1, tmp2, result; 190 unsigned long mask, tmp1, tmp2, result;
244 191
@@ -263,78 +210,15 @@ static int inline __write_trylock(rwlock_t *lock)
263 return result; 210 return result;
264} 211}
265 212
266#define _raw_read_lock(p) __read_lock(p) 213#define __raw_read_lock(p) __read_lock(p)
267#define _raw_read_unlock(p) __read_unlock(p) 214#define __raw_read_unlock(p) __read_unlock(p)
268#define _raw_write_lock(p) __write_lock(p) 215#define __raw_write_lock(p) __write_lock(p)
269#define _raw_write_unlock(p) __write_unlock(p) 216#define __raw_write_unlock(p) __write_unlock(p)
270#define _raw_write_trylock(p) __write_trylock(p) 217#define __raw_write_trylock(p) __write_trylock(p)
271 218
272#else /* !(CONFIG_DEBUG_SPINLOCK) */ 219#define __raw_read_trylock(lock) generic__raw_read_trylock(lock)
273 220#define __raw_read_can_lock(rw) (!((rw)->lock & 0x80000000UL))
274typedef struct { 221#define __raw_write_can_lock(rw) (!(rw)->lock)
275 volatile unsigned long lock;
276 unsigned int writer_pc, writer_cpu;
277 unsigned int reader_pc[NR_CPUS];
278#ifdef CONFIG_PREEMPT
279 unsigned int break_lock;
280#endif
281} rwlock_t;
282#define RW_LOCK_UNLOCKED (rwlock_t) { 0, 0, 0xff, { } }
283#define rwlock_init(lp) do { *(lp) = RW_LOCK_UNLOCKED; } while(0)
284
285extern void _do_read_lock(rwlock_t *rw, char *str, unsigned long caller);
286extern void _do_read_unlock(rwlock_t *rw, char *str, unsigned long caller);
287extern void _do_write_lock(rwlock_t *rw, char *str, unsigned long caller);
288extern void _do_write_unlock(rwlock_t *rw, unsigned long caller);
289extern int _do_write_trylock(rwlock_t *rw, char *str, unsigned long caller);
290
291#define _raw_read_lock(lock) \
292do { unsigned long flags; \
293 local_irq_save(flags); \
294 _do_read_lock(lock, "read_lock", \
295 (unsigned long) __builtin_return_address(0)); \
296 local_irq_restore(flags); \
297} while(0)
298
299#define _raw_read_unlock(lock) \
300do { unsigned long flags; \
301 local_irq_save(flags); \
302 _do_read_unlock(lock, "read_unlock", \
303 (unsigned long) __builtin_return_address(0)); \
304 local_irq_restore(flags); \
305} while(0)
306
307#define _raw_write_lock(lock) \
308do { unsigned long flags; \
309 local_irq_save(flags); \
310 _do_write_lock(lock, "write_lock", \
311 (unsigned long) __builtin_return_address(0)); \
312 local_irq_restore(flags); \
313} while(0)
314
315#define _raw_write_unlock(lock) \
316do { unsigned long flags; \
317 local_irq_save(flags); \
318 _do_write_unlock(lock, \
319 (unsigned long) __builtin_return_address(0)); \
320 local_irq_restore(flags); \
321} while(0)
322
323#define _raw_write_trylock(lock) \
324({ unsigned long flags; \
325 int val; \
326 local_irq_save(flags); \
327 val = _do_write_trylock(lock, "write_trylock", \
328 (unsigned long) __builtin_return_address(0)); \
329 local_irq_restore(flags); \
330 val; \
331})
332
333#endif /* CONFIG_DEBUG_SPINLOCK */
334
335#define _raw_read_trylock(lock) generic_raw_read_trylock(lock)
336#define read_can_lock(rw) (!((rw)->lock & 0x80000000UL))
337#define write_can_lock(rw) (!(rw)->lock)
338 222
339#endif /* !(__ASSEMBLY__) */ 223#endif /* !(__ASSEMBLY__) */
340 224
diff --git a/include/asm-sparc64/spinlock_types.h b/include/asm-sparc64/spinlock_types.h
new file mode 100644
index 0000000000..e128112a0d
--- /dev/null
+++ b/include/asm-sparc64/spinlock_types.h
@@ -0,0 +1,20 @@
1#ifndef __SPARC64_SPINLOCK_TYPES_H
2#define __SPARC64_SPINLOCK_TYPES_H
3
4#ifndef __LINUX_SPINLOCK_TYPES_H
5# error "please don't include this file directly"
6#endif
7
8typedef struct {
9 volatile unsigned char lock;
10} raw_spinlock_t;
11
12#define __RAW_SPIN_LOCK_UNLOCKED { 0 }
13
14typedef struct {
15 volatile unsigned int lock;
16} raw_rwlock_t;
17
18#define __RAW_RW_LOCK_UNLOCKED { 0 }
19
20#endif
diff --git a/include/asm-um/page.h b/include/asm-um/page.h
index bd850a2491..2c192abe9a 100644
--- a/include/asm-um/page.h
+++ b/include/asm-um/page.h
@@ -96,8 +96,7 @@ extern unsigned long uml_physmem;
96 96
97#define __va_space (8*1024*1024) 97#define __va_space (8*1024*1024)
98 98
99extern unsigned long to_phys(void *virt); 99#include "mem.h"
100extern void *to_virt(unsigned long phys);
101 100
102/* Cast to unsigned long before casting to void * to avoid a warning from 101/* Cast to unsigned long before casting to void * to avoid a warning from
103 * mmap_kmem about cutting a long long down to a void *. Not sure that 102 * mmap_kmem about cutting a long long down to a void *. Not sure that
diff --git a/include/asm-um/pgtable.h b/include/asm-um/pgtable.h
index b48e0966ec..ed06170e0e 100644
--- a/include/asm-um/pgtable.h
+++ b/include/asm-um/pgtable.h
@@ -326,14 +326,22 @@ static inline void set_pte(pte_t *pteptr, pte_t pteval)
326} 326}
327#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval) 327#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
328 328
329extern phys_t page_to_phys(struct page *page);
330
331/* 329/*
332 * Conversion functions: convert a page and protection to a page entry, 330 * Conversion functions: convert a page and protection to a page entry,
333 * and a page entry and page directory to the page they refer to. 331 * and a page entry and page directory to the page they refer to.
334 */ 332 */
335 333
336extern pte_t mk_pte(struct page *page, pgprot_t pgprot); 334#define phys_to_page(phys) pfn_to_page(phys_to_pfn(phys))
335#define __virt_to_page(virt) phys_to_page(__pa(virt))
336#define page_to_phys(page) pfn_to_phys(page_to_pfn(page))
337
338#define mk_pte(page, pgprot) \
339 ({ pte_t pte; \
340 \
341 pte_set_val(pte, page_to_phys(page), (pgprot)); \
342 if (pte_present(pte)) \
343 pte_mknewprot(pte_mknewpage(pte)); \
344 pte;})
337 345
338static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) 346static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
339{ 347{
@@ -410,8 +418,6 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
410#endif 418#endif
411#endif 419#endif
412 420
413extern struct page *phys_to_page(const unsigned long phys);
414extern struct page *__virt_to_page(const unsigned long virt);
415#define virt_to_page(addr) __virt_to_page((const unsigned long) addr) 421#define virt_to_page(addr) __virt_to_page((const unsigned long) addr)
416 422
417/* 423/*
diff --git a/include/asm-um/spinlock_types.h b/include/asm-um/spinlock_types.h
new file mode 100644
index 0000000000..e5a94294bf
--- /dev/null
+++ b/include/asm-um/spinlock_types.h
@@ -0,0 +1,6 @@
1#ifndef __UM_SPINLOCK_TYPES_H
2#define __UM_SPINLOCK_TYPES_H
3
4#include "asm/arch/spinlock_types.h"
5
6#endif
diff --git a/include/asm-x86_64/apic.h b/include/asm-x86_64/apic.h
index 16ec82e16b..6c5d5ca838 100644
--- a/include/asm-x86_64/apic.h
+++ b/include/asm-x86_64/apic.h
@@ -109,9 +109,10 @@ extern unsigned int nmi_watchdog;
109#define NMI_LOCAL_APIC 2 109#define NMI_LOCAL_APIC 2
110#define NMI_INVALID 3 110#define NMI_INVALID 3
111 111
112extern int disable_timer_pin_1;
113
112#endif /* CONFIG_X86_LOCAL_APIC */ 114#endif /* CONFIG_X86_LOCAL_APIC */
113 115
114#define esr_disable 0
115extern unsigned boot_cpu_id; 116extern unsigned boot_cpu_id;
116 117
117#endif /* __ASM_APIC_H */ 118#endif /* __ASM_APIC_H */
diff --git a/include/asm-x86_64/apicdef.h b/include/asm-x86_64/apicdef.h
index 9388062c4f..fb1c99ac66 100644
--- a/include/asm-x86_64/apicdef.h
+++ b/include/asm-x86_64/apicdef.h
@@ -113,6 +113,7 @@
113#define APIC_BASE (fix_to_virt(FIX_APIC_BASE)) 113#define APIC_BASE (fix_to_virt(FIX_APIC_BASE))
114 114
115#define MAX_IO_APICS 128 115#define MAX_IO_APICS 128
116#define MAX_LOCAL_APIC 256
116 117
117/* 118/*
118 * All x86-64 systems are xAPIC compatible. 119 * All x86-64 systems are xAPIC compatible.
diff --git a/include/asm-x86_64/bug.h b/include/asm-x86_64/bug.h
index eed7856672..80ac1fe966 100644
--- a/include/asm-x86_64/bug.h
+++ b/include/asm-x86_64/bug.h
@@ -9,10 +9,8 @@
9 */ 9 */
10struct bug_frame { 10struct bug_frame {
11 unsigned char ud2[2]; 11 unsigned char ud2[2];
12 unsigned char mov; 12 unsigned char push;
13 /* should use 32bit offset instead, but the assembler doesn't 13 signed int filename;
14 like it */
15 char *filename;
16 unsigned char ret; 14 unsigned char ret;
17 unsigned short line; 15 unsigned short line;
18} __attribute__((packed)); 16} __attribute__((packed));
@@ -25,8 +23,8 @@ struct bug_frame {
25 The magic numbers generate mov $64bitimm,%eax ; ret $offset. */ 23 The magic numbers generate mov $64bitimm,%eax ; ret $offset. */
26#define BUG() \ 24#define BUG() \
27 asm volatile( \ 25 asm volatile( \
28 "ud2 ; .byte 0xa3 ; .quad %c1 ; .byte 0xc2 ; .short %c0" :: \ 26 "ud2 ; pushq $%c1 ; ret $%c0" :: \
29 "i"(__LINE__), "i" (__stringify(__FILE__))) 27 "i"(__LINE__), "i" (__FILE__))
30void out_of_line_bug(void); 28void out_of_line_bug(void);
31#else 29#else
32static inline void out_of_line_bug(void) { } 30static inline void out_of_line_bug(void) { }
diff --git a/include/asm-x86_64/calling.h b/include/asm-x86_64/calling.h
index 0bc12655fa..fc2c5a6c26 100644
--- a/include/asm-x86_64/calling.h
+++ b/include/asm-x86_64/calling.h
@@ -65,27 +65,36 @@
65 .if \skipr11 65 .if \skipr11
66 .else 66 .else
67 movq (%rsp),%r11 67 movq (%rsp),%r11
68 CFI_RESTORE r11
68 .endif 69 .endif
69 .if \skipr8910 70 .if \skipr8910
70 .else 71 .else
71 movq 1*8(%rsp),%r10 72 movq 1*8(%rsp),%r10
73 CFI_RESTORE r10
72 movq 2*8(%rsp),%r9 74 movq 2*8(%rsp),%r9
75 CFI_RESTORE r9
73 movq 3*8(%rsp),%r8 76 movq 3*8(%rsp),%r8
77 CFI_RESTORE r8
74 .endif 78 .endif
75 .if \skiprax 79 .if \skiprax
76 .else 80 .else
77 movq 4*8(%rsp),%rax 81 movq 4*8(%rsp),%rax
82 CFI_RESTORE rax
78 .endif 83 .endif
79 .if \skiprcx 84 .if \skiprcx
80 .else 85 .else
81 movq 5*8(%rsp),%rcx 86 movq 5*8(%rsp),%rcx
87 CFI_RESTORE rcx
82 .endif 88 .endif
83 .if \skiprdx 89 .if \skiprdx
84 .else 90 .else
85 movq 6*8(%rsp),%rdx 91 movq 6*8(%rsp),%rdx
92 CFI_RESTORE rdx
86 .endif 93 .endif
87 movq 7*8(%rsp),%rsi 94 movq 7*8(%rsp),%rsi
95 CFI_RESTORE rsi
88 movq 8*8(%rsp),%rdi 96 movq 8*8(%rsp),%rdi
97 CFI_RESTORE rdi
89 .if ARG_SKIP+\addskip > 0 98 .if ARG_SKIP+\addskip > 0
90 addq $ARG_SKIP+\addskip,%rsp 99 addq $ARG_SKIP+\addskip,%rsp
91 CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip) 100 CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
@@ -124,11 +133,17 @@
124 133
125 .macro RESTORE_REST 134 .macro RESTORE_REST
126 movq (%rsp),%r15 135 movq (%rsp),%r15
136 CFI_RESTORE r15
127 movq 1*8(%rsp),%r14 137 movq 1*8(%rsp),%r14
138 CFI_RESTORE r14
128 movq 2*8(%rsp),%r13 139 movq 2*8(%rsp),%r13
140 CFI_RESTORE r13
129 movq 3*8(%rsp),%r12 141 movq 3*8(%rsp),%r12
142 CFI_RESTORE r12
130 movq 4*8(%rsp),%rbp 143 movq 4*8(%rsp),%rbp
144 CFI_RESTORE rbp
131 movq 5*8(%rsp),%rbx 145 movq 5*8(%rsp),%rbx
146 CFI_RESTORE rbx
132 addq $REST_SKIP,%rsp 147 addq $REST_SKIP,%rsp
133 CFI_ADJUST_CFA_OFFSET -(REST_SKIP) 148 CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
134 .endm 149 .endm
@@ -146,11 +161,3 @@
146 .macro icebp 161 .macro icebp
147 .byte 0xf1 162 .byte 0xf1
148 .endm 163 .endm
149
150#ifdef CONFIG_FRAME_POINTER
151#define ENTER enter
152#define LEAVE leave
153#else
154#define ENTER
155#define LEAVE
156#endif
diff --git a/include/asm-x86_64/current.h b/include/asm-x86_64/current.h
index 7db560ee6f..bc8adecee6 100644
--- a/include/asm-x86_64/current.h
+++ b/include/asm-x86_64/current.h
@@ -17,7 +17,7 @@ static inline struct task_struct *get_current(void)
17#else 17#else
18 18
19#ifndef ASM_OFFSET_H 19#ifndef ASM_OFFSET_H
20#include <asm/offset.h> 20#include <asm/asm-offsets.h>
21#endif 21#endif
22 22
23#define GET_CURRENT(reg) movq %gs:(pda_pcurrent),reg 23#define GET_CURRENT(reg) movq %gs:(pda_pcurrent),reg
diff --git a/include/asm-x86_64/desc.h b/include/asm-x86_64/desc.h
index c89b58bebe..594e610f4a 100644
--- a/include/asm-x86_64/desc.h
+++ b/include/asm-x86_64/desc.h
@@ -191,7 +191,7 @@ static inline void load_TLS(struct thread_struct *t, unsigned int cpu)
191/* 191/*
192 * load one particular LDT into the current CPU 192 * load one particular LDT into the current CPU
193 */ 193 */
194extern inline void load_LDT_nolock (mm_context_t *pc, int cpu) 194static inline void load_LDT_nolock (mm_context_t *pc, int cpu)
195{ 195{
196 int count = pc->size; 196 int count = pc->size;
197 197
diff --git a/include/asm-x86_64/dma-mapping.h b/include/asm-x86_64/dma-mapping.h
index a416dc3163..e784fdc524 100644
--- a/include/asm-x86_64/dma-mapping.h
+++ b/include/asm-x86_64/dma-mapping.h
@@ -85,6 +85,11 @@ static inline void dma_sync_single_for_device(struct device *hwdev,
85 flush_write_buffers(); 85 flush_write_buffers();
86} 86}
87 87
88#define dma_sync_single_range_for_cpu(dev, dma_handle, offset, size, dir) \
89 dma_sync_single_for_cpu(dev, dma_handle, size, dir)
90#define dma_sync_single_range_for_device(dev, dma_handle, offset, size, dir) \
91 dma_sync_single_for_device(dev, dma_handle, size, dir)
92
88static inline void dma_sync_sg_for_cpu(struct device *hwdev, 93static inline void dma_sync_sg_for_cpu(struct device *hwdev,
89 struct scatterlist *sg, 94 struct scatterlist *sg,
90 int nelems, int direction) 95 int nelems, int direction)
diff --git a/include/asm-x86_64/dwarf2.h b/include/asm-x86_64/dwarf2.h
index afd4212e86..582757fc03 100644
--- a/include/asm-x86_64/dwarf2.h
+++ b/include/asm-x86_64/dwarf2.h
@@ -24,6 +24,10 @@
24#define CFI_ADJUST_CFA_OFFSET .cfi_adjust_cfa_offset 24#define CFI_ADJUST_CFA_OFFSET .cfi_adjust_cfa_offset
25#define CFI_OFFSET .cfi_offset 25#define CFI_OFFSET .cfi_offset
26#define CFI_REL_OFFSET .cfi_rel_offset 26#define CFI_REL_OFFSET .cfi_rel_offset
27#define CFI_REGISTER .cfi_register
28#define CFI_RESTORE .cfi_restore
29#define CFI_REMEMBER_STATE .cfi_remember_state
30#define CFI_RESTORE_STATE .cfi_restore_state
27 31
28#else 32#else
29 33
@@ -36,6 +40,10 @@
36#define CFI_ADJUST_CFA_OFFSET # 40#define CFI_ADJUST_CFA_OFFSET #
37#define CFI_OFFSET # 41#define CFI_OFFSET #
38#define CFI_REL_OFFSET # 42#define CFI_REL_OFFSET #
43#define CFI_REGISTER #
44#define CFI_RESTORE #
45#define CFI_REMEMBER_STATE #
46#define CFI_RESTORE_STATE #
39 47
40#endif 48#endif
41 49
diff --git a/include/asm-x86_64/fixmap.h b/include/asm-x86_64/fixmap.h
index cf8b16cbe8..a582cfcf22 100644
--- a/include/asm-x86_64/fixmap.h
+++ b/include/asm-x86_64/fixmap.h
@@ -76,7 +76,7 @@ extern void __this_fixmap_does_not_exist(void);
76 * directly without translation, we catch the bug with a NULL-deference 76 * directly without translation, we catch the bug with a NULL-deference
77 * kernel oops. Illegal ranges of incoming indices are caught too. 77 * kernel oops. Illegal ranges of incoming indices are caught too.
78 */ 78 */
79extern inline unsigned long fix_to_virt(const unsigned int idx) 79static inline unsigned long fix_to_virt(const unsigned int idx)
80{ 80{
81 /* 81 /*
82 * this branch gets completely eliminated after inlining, 82 * this branch gets completely eliminated after inlining,
diff --git a/include/asm-x86_64/hardirq.h b/include/asm-x86_64/hardirq.h
index 27c381fa1c..8661b476fb 100644
--- a/include/asm-x86_64/hardirq.h
+++ b/include/asm-x86_64/hardirq.h
@@ -9,11 +9,12 @@
9 9
10#define __ARCH_IRQ_STAT 1 10#define __ARCH_IRQ_STAT 1
11 11
12/* Generate a lvalue for a pda member. Should fix softirq.c instead to use 12#define local_softirq_pending() read_pda(__softirq_pending)
13 special access macros. This would generate better code. */
14#define __IRQ_STAT(cpu,member) (read_pda(me)->member)
15 13
16#include <linux/irq_cpustat.h> /* Standard mappings for irq_cpustat_t above */ 14#define __ARCH_SET_SOFTIRQ_PENDING 1
15
16#define set_softirq_pending(x) write_pda(__softirq_pending, (x))
17#define or_softirq_pending(x) or_pda(__softirq_pending, (x))
17 18
18/* 19/*
19 * 'what should we do if we get a hw irq event on an illegal vector'. 20 * 'what should we do if we get a hw irq event on an illegal vector'.
diff --git a/include/asm-x86_64/hw_irq.h b/include/asm-x86_64/hw_irq.h
index 2b5cb2865d..dc97668ea0 100644
--- a/include/asm-x86_64/hw_irq.h
+++ b/include/asm-x86_64/hw_irq.h
@@ -26,6 +26,7 @@
26struct hw_interrupt_type; 26struct hw_interrupt_type;
27#endif 27#endif
28 28
29#define NMI_VECTOR 0x02
29/* 30/*
30 * IDT vectors usable for external interrupt sources start 31 * IDT vectors usable for external interrupt sources start
31 * at 0x20: 32 * at 0x20:
@@ -50,14 +51,15 @@ struct hw_interrupt_type;
50 */ 51 */
51#define SPURIOUS_APIC_VECTOR 0xff 52#define SPURIOUS_APIC_VECTOR 0xff
52#define ERROR_APIC_VECTOR 0xfe 53#define ERROR_APIC_VECTOR 0xfe
53#define INVALIDATE_TLB_VECTOR 0xfd 54#define RESCHEDULE_VECTOR 0xfd
54#define RESCHEDULE_VECTOR 0xfc 55#define CALL_FUNCTION_VECTOR 0xfc
55#define TASK_MIGRATION_VECTOR 0xfb 56#define KDB_VECTOR 0xfb /* reserved for KDB */
56#define CALL_FUNCTION_VECTOR 0xfa 57#define THERMAL_APIC_VECTOR 0xfa
57#define KDB_VECTOR 0xf9 58/* 0xf9 free */
58 59#define INVALIDATE_TLB_VECTOR_END 0xf8
59#define THERMAL_APIC_VECTOR 0xf0 60#define INVALIDATE_TLB_VECTOR_START 0xf0 /* f0-f8 used for TLB flush */
60 61
62#define NUM_INVALIDATE_TLB_VECTORS 8
61 63
62/* 64/*
63 * Local APIC timer IRQ vector is on a different priority level, 65 * Local APIC timer IRQ vector is on a different priority level,
diff --git a/include/asm-x86_64/io.h b/include/asm-x86_64/io.h
index 37fc3f149a..52ff269fe0 100644
--- a/include/asm-x86_64/io.h
+++ b/include/asm-x86_64/io.h
@@ -48,7 +48,7 @@
48 * Talk about misusing macros.. 48 * Talk about misusing macros..
49 */ 49 */
50#define __OUT1(s,x) \ 50#define __OUT1(s,x) \
51extern inline void out##s(unsigned x value, unsigned short port) { 51static inline void out##s(unsigned x value, unsigned short port) {
52 52
53#define __OUT2(s,s1,s2) \ 53#define __OUT2(s,s1,s2) \
54__asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1" 54__asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
@@ -58,7 +58,7 @@ __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "Nd" (port)); } \
58__OUT1(s##_p,x) __OUT2(s,s1,"w") __FULL_SLOW_DOWN_IO : : "a" (value), "Nd" (port));} \ 58__OUT1(s##_p,x) __OUT2(s,s1,"w") __FULL_SLOW_DOWN_IO : : "a" (value), "Nd" (port));} \
59 59
60#define __IN1(s) \ 60#define __IN1(s) \
61extern inline RETURN_TYPE in##s(unsigned short port) { RETURN_TYPE _v; 61static inline RETURN_TYPE in##s(unsigned short port) { RETURN_TYPE _v;
62 62
63#define __IN2(s,s1,s2) \ 63#define __IN2(s,s1,s2) \
64__asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0" 64__asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
@@ -68,12 +68,12 @@ __IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \
68__IN1(s##_p) __IN2(s,s1,"w") __FULL_SLOW_DOWN_IO : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \ 68__IN1(s##_p) __IN2(s,s1,"w") __FULL_SLOW_DOWN_IO : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \
69 69
70#define __INS(s) \ 70#define __INS(s) \
71extern inline void ins##s(unsigned short port, void * addr, unsigned long count) \ 71static inline void ins##s(unsigned short port, void * addr, unsigned long count) \
72{ __asm__ __volatile__ ("rep ; ins" #s \ 72{ __asm__ __volatile__ ("rep ; ins" #s \
73: "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); } 73: "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
74 74
75#define __OUTS(s) \ 75#define __OUTS(s) \
76extern inline void outs##s(unsigned short port, const void * addr, unsigned long count) \ 76static inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
77{ __asm__ __volatile__ ("rep ; outs" #s \ 77{ __asm__ __volatile__ ("rep ; outs" #s \
78: "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); } 78: "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
79 79
@@ -110,12 +110,12 @@ __OUTS(l)
110 * Change virtual addresses to physical addresses and vv. 110 * Change virtual addresses to physical addresses and vv.
111 * These are pretty trivial 111 * These are pretty trivial
112 */ 112 */
113extern inline unsigned long virt_to_phys(volatile void * address) 113static inline unsigned long virt_to_phys(volatile void * address)
114{ 114{
115 return __pa(address); 115 return __pa(address);
116} 116}
117 117
118extern inline void * phys_to_virt(unsigned long address) 118static inline void * phys_to_virt(unsigned long address)
119{ 119{
120 return __va(address); 120 return __va(address);
121} 121}
@@ -130,7 +130,7 @@ extern inline void * phys_to_virt(unsigned long address)
130 130
131extern void __iomem *__ioremap(unsigned long offset, unsigned long size, unsigned long flags); 131extern void __iomem *__ioremap(unsigned long offset, unsigned long size, unsigned long flags);
132 132
133extern inline void __iomem * ioremap (unsigned long offset, unsigned long size) 133static inline void __iomem * ioremap (unsigned long offset, unsigned long size)
134{ 134{
135 return __ioremap(offset, size, 0); 135 return __ioremap(offset, size, 0);
136} 136}
diff --git a/include/asm-x86_64/ipi.h b/include/asm-x86_64/ipi.h
index 5e166b9d3b..022e9d340a 100644
--- a/include/asm-x86_64/ipi.h
+++ b/include/asm-x86_64/ipi.h
@@ -31,9 +31,20 @@
31 31
32static inline unsigned int __prepare_ICR (unsigned int shortcut, int vector, unsigned int dest) 32static inline unsigned int __prepare_ICR (unsigned int shortcut, int vector, unsigned int dest)
33{ 33{
34 unsigned int icr = APIC_DM_FIXED | shortcut | vector | dest; 34 unsigned int icr = shortcut | dest;
35 if (vector == KDB_VECTOR) 35
36 icr = (icr & (~APIC_VECTOR_MASK)) | APIC_DM_NMI; 36 switch (vector) {
37 default:
38 icr |= APIC_DM_FIXED | vector;
39 break;
40 case NMI_VECTOR:
41 /*
42 * Setup KDB IPI to be delivered as an NMI
43 */
44 case KDB_VECTOR:
45 icr |= APIC_DM_NMI;
46 break;
47 }
37 return icr; 48 return icr;
38} 49}
39 50
@@ -66,7 +77,7 @@ static inline void __send_IPI_shortcut(unsigned int shortcut, int vector, unsign
66 /* 77 /*
67 * Send the IPI. The write to APIC_ICR fires this off. 78 * Send the IPI. The write to APIC_ICR fires this off.
68 */ 79 */
69 apic_write_around(APIC_ICR, cfg); 80 apic_write(APIC_ICR, cfg);
70} 81}
71 82
72 83
@@ -92,7 +103,7 @@ static inline void send_IPI_mask_sequence(cpumask_t mask, int vector)
92 * prepare target chip field 103 * prepare target chip field
93 */ 104 */
94 cfg = __prepare_ICR2(x86_cpu_to_apicid[query_cpu]); 105 cfg = __prepare_ICR2(x86_cpu_to_apicid[query_cpu]);
95 apic_write_around(APIC_ICR2, cfg); 106 apic_write(APIC_ICR2, cfg);
96 107
97 /* 108 /*
98 * program the ICR 109 * program the ICR
@@ -102,7 +113,7 @@ static inline void send_IPI_mask_sequence(cpumask_t mask, int vector)
102 /* 113 /*
103 * Send the IPI. The write to APIC_ICR fires this off. 114 * Send the IPI. The write to APIC_ICR fires this off.
104 */ 115 */
105 apic_write_around(APIC_ICR, cfg); 116 apic_write(APIC_ICR, cfg);
106 } 117 }
107 local_irq_restore(flags); 118 local_irq_restore(flags);
108} 119}
diff --git a/include/asm-x86_64/irq.h b/include/asm-x86_64/irq.h
index 4482657777..fb724ba37a 100644
--- a/include/asm-x86_64/irq.h
+++ b/include/asm-x86_64/irq.h
@@ -48,10 +48,6 @@ static __inline__ int irq_canonicalize(int irq)
48#define ARCH_HAS_NMI_WATCHDOG /* See include/linux/nmi.h */ 48#define ARCH_HAS_NMI_WATCHDOG /* See include/linux/nmi.h */
49#endif 49#endif
50 50
51struct irqaction;
52struct pt_regs;
53int handle_IRQ_event(unsigned int, struct pt_regs *, struct irqaction *);
54
55#ifdef CONFIG_HOTPLUG_CPU 51#ifdef CONFIG_HOTPLUG_CPU
56#include <linux/cpumask.h> 52#include <linux/cpumask.h>
57extern void fixup_irqs(cpumask_t map); 53extern void fixup_irqs(cpumask_t map);
diff --git a/include/asm-x86_64/kdebug.h b/include/asm-x86_64/kdebug.h
index b90341994d..f604e84c53 100644
--- a/include/asm-x86_64/kdebug.h
+++ b/include/asm-x86_64/kdebug.h
@@ -46,7 +46,7 @@ extern void die(const char *,struct pt_regs *,long);
46extern void __die(const char *,struct pt_regs *,long); 46extern void __die(const char *,struct pt_regs *,long);
47extern void show_registers(struct pt_regs *regs); 47extern void show_registers(struct pt_regs *regs);
48extern void dump_pagetable(unsigned long); 48extern void dump_pagetable(unsigned long);
49extern void oops_begin(void); 49extern unsigned long oops_begin(void);
50extern void oops_end(void); 50extern void oops_end(unsigned long);
51 51
52#endif 52#endif
diff --git a/include/asm-x86_64/local.h b/include/asm-x86_64/local.h
index c954f15c1a..3e72c41727 100644
--- a/include/asm-x86_64/local.h
+++ b/include/asm-x86_64/local.h
@@ -29,7 +29,7 @@ static __inline__ void local_dec(local_t *v)
29 :"m" (v->counter)); 29 :"m" (v->counter));
30} 30}
31 31
32static __inline__ void local_add(unsigned long i, local_t *v) 32static __inline__ void local_add(unsigned int i, local_t *v)
33{ 33{
34 __asm__ __volatile__( 34 __asm__ __volatile__(
35 "addl %1,%0" 35 "addl %1,%0"
@@ -37,7 +37,7 @@ static __inline__ void local_add(unsigned long i, local_t *v)
37 :"ir" (i), "m" (v->counter)); 37 :"ir" (i), "m" (v->counter));
38} 38}
39 39
40static __inline__ void local_sub(unsigned long i, local_t *v) 40static __inline__ void local_sub(unsigned int i, local_t *v)
41{ 41{
42 __asm__ __volatile__( 42 __asm__ __volatile__(
43 "subl %1,%0" 43 "subl %1,%0"
diff --git a/include/asm-x86_64/mmzone.h b/include/asm-x86_64/mmzone.h
index 768413751b..b40c661f11 100644
--- a/include/asm-x86_64/mmzone.h
+++ b/include/asm-x86_64/mmzone.h
@@ -12,7 +12,7 @@
12 12
13#include <asm/smp.h> 13#include <asm/smp.h>
14 14
15#define NODEMAPSIZE 0xff 15#define NODEMAPSIZE 0xfff
16 16
17/* Simple perfect hash to map physical addresses to node numbers */ 17/* Simple perfect hash to map physical addresses to node numbers */
18extern int memnode_shift; 18extern int memnode_shift;
@@ -54,7 +54,7 @@ static inline __attribute__((pure)) int phys_to_nid(unsigned long addr)
54 54
55#define pfn_valid(pfn) ((pfn) >= num_physpages ? 0 : \ 55#define pfn_valid(pfn) ((pfn) >= num_physpages ? 0 : \
56 ({ u8 nid__ = pfn_to_nid(pfn); \ 56 ({ u8 nid__ = pfn_to_nid(pfn); \
57 nid__ != 0xff && (pfn) >= node_start_pfn(nid__) && (pfn) <= node_end_pfn(nid__); })) 57 nid__ != 0xff && (pfn) >= node_start_pfn(nid__) && (pfn) < node_end_pfn(nid__); }))
58#endif 58#endif
59 59
60#define local_mapnr(kvaddr) \ 60#define local_mapnr(kvaddr) \
diff --git a/include/asm-x86_64/msr.h b/include/asm-x86_64/msr.h
index ba15279a79..4d727f3f55 100644
--- a/include/asm-x86_64/msr.h
+++ b/include/asm-x86_64/msr.h
@@ -29,22 +29,37 @@
29#define wrmsrl(msr,val) wrmsr(msr,(__u32)((__u64)(val)),((__u64)(val))>>32) 29#define wrmsrl(msr,val) wrmsr(msr,(__u32)((__u64)(val)),((__u64)(val))>>32)
30 30
31/* wrmsr with exception handling */ 31/* wrmsr with exception handling */
32#define wrmsr_safe(msr,a,b) ({ int ret__; \ 32#define wrmsr_safe(msr,a,b) ({ int ret__; \
33 asm volatile("2: wrmsr ; xorl %0,%0\n" \ 33 asm volatile("2: wrmsr ; xorl %0,%0\n" \
34 "1:\n\t" \ 34 "1:\n\t" \
35 ".section .fixup,\"ax\"\n\t" \ 35 ".section .fixup,\"ax\"\n\t" \
36 "3: movl %4,%0 ; jmp 1b\n\t" \ 36 "3: movl %4,%0 ; jmp 1b\n\t" \
37 ".previous\n\t" \ 37 ".previous\n\t" \
38 ".section __ex_table,\"a\"\n" \ 38 ".section __ex_table,\"a\"\n" \
39 " .align 8\n\t" \ 39 " .align 8\n\t" \
40 " .quad 2b,3b\n\t" \ 40 " .quad 2b,3b\n\t" \
41 ".previous" \ 41 ".previous" \
42 : "=a" (ret__) \ 42 : "=a" (ret__) \
43 : "c" (msr), "0" (a), "d" (b), "i" (-EFAULT));\ 43 : "c" (msr), "0" (a), "d" (b), "i" (-EFAULT)); \
44 ret__; }) 44 ret__; })
45 45
46#define checking_wrmsrl(msr,val) wrmsr_safe(msr,(u32)(val),(u32)((val)>>32)) 46#define checking_wrmsrl(msr,val) wrmsr_safe(msr,(u32)(val),(u32)((val)>>32))
47 47
48#define rdmsr_safe(msr,a,b) \
49 ({ int ret__; \
50 asm volatile ("1: rdmsr\n" \
51 "2:\n" \
52 ".section .fixup,\"ax\"\n" \
53 "3: movl %4,%0\n" \
54 " jmp 2b\n" \
55 ".previous\n" \
56 ".section __ex_table,\"a\"\n" \
57 " .align 8\n" \
58 " .quad 1b,3b\n" \
59 ".previous":"=&bDS" (ret__), "=a"(a), "=d"(b)\
60 :"c"(msr), "i"(-EIO), "0"(0)); \
61 ret__; })
62
48#define rdtsc(low,high) \ 63#define rdtsc(low,high) \
49 __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high)) 64 __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
50 65
@@ -64,7 +79,7 @@
64 : "=a" (low), "=d" (high) \ 79 : "=a" (low), "=d" (high) \
65 : "c" (counter)) 80 : "c" (counter))
66 81
67extern inline void cpuid(int op, unsigned int *eax, unsigned int *ebx, 82static inline void cpuid(int op, unsigned int *eax, unsigned int *ebx,
68 unsigned int *ecx, unsigned int *edx) 83 unsigned int *ecx, unsigned int *edx)
69{ 84{
70 __asm__("cpuid" 85 __asm__("cpuid"
@@ -90,7 +105,7 @@ static inline void cpuid_count(int op, int count, int *eax, int *ebx, int *ecx,
90/* 105/*
91 * CPUID functions returning a single datum 106 * CPUID functions returning a single datum
92 */ 107 */
93extern inline unsigned int cpuid_eax(unsigned int op) 108static inline unsigned int cpuid_eax(unsigned int op)
94{ 109{
95 unsigned int eax; 110 unsigned int eax;
96 111
@@ -100,7 +115,7 @@ extern inline unsigned int cpuid_eax(unsigned int op)
100 : "bx", "cx", "dx"); 115 : "bx", "cx", "dx");
101 return eax; 116 return eax;
102} 117}
103extern inline unsigned int cpuid_ebx(unsigned int op) 118static inline unsigned int cpuid_ebx(unsigned int op)
104{ 119{
105 unsigned int eax, ebx; 120 unsigned int eax, ebx;
106 121
@@ -110,7 +125,7 @@ extern inline unsigned int cpuid_ebx(unsigned int op)
110 : "cx", "dx" ); 125 : "cx", "dx" );
111 return ebx; 126 return ebx;
112} 127}
113extern inline unsigned int cpuid_ecx(unsigned int op) 128static inline unsigned int cpuid_ecx(unsigned int op)
114{ 129{
115 unsigned int eax, ecx; 130 unsigned int eax, ecx;
116 131
@@ -120,7 +135,7 @@ extern inline unsigned int cpuid_ecx(unsigned int op)
120 : "bx", "dx" ); 135 : "bx", "dx" );
121 return ecx; 136 return ecx;
122} 137}
123extern inline unsigned int cpuid_edx(unsigned int op) 138static inline unsigned int cpuid_edx(unsigned int op)
124{ 139{
125 unsigned int eax, edx; 140 unsigned int eax, edx;
126 141
diff --git a/include/asm-x86_64/numa.h b/include/asm-x86_64/numa.h
index 5c363a1482..bcf55c3f7f 100644
--- a/include/asm-x86_64/numa.h
+++ b/include/asm-x86_64/numa.h
@@ -9,6 +9,7 @@ struct node {
9}; 9};
10 10
11extern int compute_hash_shift(struct node *nodes, int numnodes); 11extern int compute_hash_shift(struct node *nodes, int numnodes);
12extern int pxm_to_node(int nid);
12 13
13#define ZONE_ALIGN (1UL << (MAX_ORDER+PAGE_SHIFT)) 14#define ZONE_ALIGN (1UL << (MAX_ORDER+PAGE_SHIFT))
14 15
@@ -16,6 +17,8 @@ extern void numa_add_cpu(int cpu);
16extern void numa_init_array(void); 17extern void numa_init_array(void);
17extern int numa_off; 18extern int numa_off;
18 19
20extern unsigned char apicid_to_node[256];
21
19#define NUMA_NO_NODE 0xff 22#define NUMA_NO_NODE 0xff
20 23
21#endif 24#endif
diff --git a/include/asm-x86_64/page.h b/include/asm-x86_64/page.h
index 135ffaa039..e5ab4d231f 100644
--- a/include/asm-x86_64/page.h
+++ b/include/asm-x86_64/page.h
@@ -32,6 +32,8 @@
32#ifdef __KERNEL__ 32#ifdef __KERNEL__
33#ifndef __ASSEMBLY__ 33#ifndef __ASSEMBLY__
34 34
35extern unsigned long end_pfn;
36
35void clear_page(void *); 37void clear_page(void *);
36void copy_page(void *, void *); 38void copy_page(void *, void *);
37 39
@@ -111,7 +113,7 @@ typedef struct { unsigned long pgprot; } pgprot_t;
111#ifdef CONFIG_FLATMEM 113#ifdef CONFIG_FLATMEM
112#define pfn_to_page(pfn) (mem_map + (pfn)) 114#define pfn_to_page(pfn) (mem_map + (pfn))
113#define page_to_pfn(page) ((unsigned long)((page) - mem_map)) 115#define page_to_pfn(page) ((unsigned long)((page) - mem_map))
114#define pfn_valid(pfn) ((pfn) < max_mapnr) 116#define pfn_valid(pfn) ((pfn) < end_pfn)
115#endif 117#endif
116 118
117#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) 119#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
diff --git a/include/asm-x86_64/pci.h b/include/asm-x86_64/pci.h
index eeb3088a1c..5a82a6762c 100644
--- a/include/asm-x86_64/pci.h
+++ b/include/asm-x86_64/pci.h
@@ -50,10 +50,10 @@ extern int iommu_setup(char *opt);
50 * address space. The networking and block device layers use 50 * address space. The networking and block device layers use
51 * this boolean for bounce buffer decisions 51 * this boolean for bounce buffer decisions
52 * 52 *
53 * On AMD64 it mostly equals, but we set it to zero to tell some subsystems 53 * On x86-64 it mostly equals, but we set it to zero to tell some subsystems
54 * that an IOMMU is available. 54 * that an hard or soft IOMMU is available.
55 */ 55 */
56#define PCI_DMA_BUS_IS_PHYS (no_iommu ? 1 : 0) 56#define PCI_DMA_BUS_IS_PHYS 0
57 57
58/* 58/*
59 * x86-64 always supports DAC, but sometimes it is useful to force 59 * x86-64 always supports DAC, but sometimes it is useful to force
diff --git a/include/asm-x86_64/pda.h b/include/asm-x86_64/pda.h
index 36b766cfc4..bbf89aa8a1 100644
--- a/include/asm-x86_64/pda.h
+++ b/include/asm-x86_64/pda.h
@@ -10,10 +10,8 @@
10struct x8664_pda { 10struct x8664_pda {
11 struct task_struct *pcurrent; /* Current process */ 11 struct task_struct *pcurrent; /* Current process */
12 unsigned long data_offset; /* Per cpu data offset from linker address */ 12 unsigned long data_offset; /* Per cpu data offset from linker address */
13 struct x8664_pda *me; /* Pointer to itself */
14 unsigned long kernelstack; /* top of kernel stack for current */ 13 unsigned long kernelstack; /* top of kernel stack for current */
15 unsigned long oldrsp; /* user rsp for system call */ 14 unsigned long oldrsp; /* user rsp for system call */
16 unsigned long irqrsp; /* Old rsp for interrupts. */
17 int irqcount; /* Irq nesting counter. Starts with -1 */ 15 int irqcount; /* Irq nesting counter. Starts with -1 */
18 int cpunumber; /* Logical CPU number */ 16 int cpunumber; /* Logical CPU number */
19 char *irqstackptr; /* top of irqstack */ 17 char *irqstackptr; /* top of irqstack */
@@ -22,7 +20,7 @@ struct x8664_pda {
22 struct mm_struct *active_mm; 20 struct mm_struct *active_mm;
23 int mmu_state; 21 int mmu_state;
24 unsigned apic_timer_irqs; 22 unsigned apic_timer_irqs;
25} ____cacheline_aligned; 23} ____cacheline_aligned_in_smp;
26 24
27 25
28#define IRQSTACK_ORDER 2 26#define IRQSTACK_ORDER 2
@@ -42,13 +40,14 @@ extern void __bad_pda_field(void);
42#define pda_offset(field) offsetof(struct x8664_pda, field) 40#define pda_offset(field) offsetof(struct x8664_pda, field)
43 41
44#define pda_to_op(op,field,val) do { \ 42#define pda_to_op(op,field,val) do { \
43 typedef typeof_field(struct x8664_pda, field) T__; \
45 switch (sizeof_field(struct x8664_pda, field)) { \ 44 switch (sizeof_field(struct x8664_pda, field)) { \
46case 2: \ 45case 2: \
47asm volatile(op "w %0,%%gs:%P1"::"r" (val),"i"(pda_offset(field)):"memory"); break; \ 46asm volatile(op "w %0,%%gs:%P1"::"ri" ((T__)val),"i"(pda_offset(field)):"memory"); break; \
48case 4: \ 47case 4: \
49asm volatile(op "l %0,%%gs:%P1"::"r" (val),"i"(pda_offset(field)):"memory"); break; \ 48asm volatile(op "l %0,%%gs:%P1"::"ri" ((T__)val),"i"(pda_offset(field)):"memory"); break; \
50case 8: \ 49case 8: \
51asm volatile(op "q %0,%%gs:%P1"::"r" (val),"i"(pda_offset(field)):"memory"); break; \ 50asm volatile(op "q %0,%%gs:%P1"::"ri" ((T__)val),"i"(pda_offset(field)):"memory"); break; \
52 default: __bad_pda_field(); \ 51 default: __bad_pda_field(); \
53 } \ 52 } \
54 } while (0) 53 } while (0)
@@ -58,7 +57,7 @@ asm volatile(op "q %0,%%gs:%P1"::"r" (val),"i"(pda_offset(field)):"memory"); bre
58 * Unfortunately removing them causes all hell to break lose currently. 57 * Unfortunately removing them causes all hell to break lose currently.
59 */ 58 */
60#define pda_from_op(op,field) ({ \ 59#define pda_from_op(op,field) ({ \
61 typedef typeof_field(struct x8664_pda, field) T__; T__ ret__; \ 60 typeof_field(struct x8664_pda, field) ret__; \
62 switch (sizeof_field(struct x8664_pda, field)) { \ 61 switch (sizeof_field(struct x8664_pda, field)) { \
63case 2: \ 62case 2: \
64asm volatile(op "w %%gs:%P1,%0":"=r" (ret__):"i"(pda_offset(field)):"memory"); break;\ 63asm volatile(op "w %%gs:%P1,%0":"=r" (ret__):"i"(pda_offset(field)):"memory"); break;\
@@ -75,6 +74,7 @@ asm volatile(op "q %%gs:%P1,%0":"=r" (ret__):"i"(pda_offset(field)):"memory"); b
75#define write_pda(field,val) pda_to_op("mov",field,val) 74#define write_pda(field,val) pda_to_op("mov",field,val)
76#define add_pda(field,val) pda_to_op("add",field,val) 75#define add_pda(field,val) pda_to_op("add",field,val)
77#define sub_pda(field,val) pda_to_op("sub",field,val) 76#define sub_pda(field,val) pda_to_op("sub",field,val)
77#define or_pda(field,val) pda_to_op("or",field,val)
78 78
79#endif 79#endif
80 80
diff --git a/include/asm-x86_64/pgalloc.h b/include/asm-x86_64/pgalloc.h
index deadd14697..08cad2482b 100644
--- a/include/asm-x86_64/pgalloc.h
+++ b/include/asm-x86_64/pgalloc.h
@@ -18,12 +18,12 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *p
18 set_pmd(pmd, __pmd(_PAGE_TABLE | (page_to_pfn(pte) << PAGE_SHIFT))); 18 set_pmd(pmd, __pmd(_PAGE_TABLE | (page_to_pfn(pte) << PAGE_SHIFT)));
19} 19}
20 20
21extern __inline__ pmd_t *get_pmd(void) 21static inline pmd_t *get_pmd(void)
22{ 22{
23 return (pmd_t *)get_zeroed_page(GFP_KERNEL); 23 return (pmd_t *)get_zeroed_page(GFP_KERNEL);
24} 24}
25 25
26extern __inline__ void pmd_free(pmd_t *pmd) 26static inline void pmd_free(pmd_t *pmd)
27{ 27{
28 BUG_ON((unsigned long)pmd & (PAGE_SIZE-1)); 28 BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
29 free_page((unsigned long)pmd); 29 free_page((unsigned long)pmd);
@@ -86,13 +86,13 @@ static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long add
86/* Should really implement gc for free page table pages. This could be 86/* Should really implement gc for free page table pages. This could be
87 done with a reference count in struct page. */ 87 done with a reference count in struct page. */
88 88
89extern __inline__ void pte_free_kernel(pte_t *pte) 89static inline void pte_free_kernel(pte_t *pte)
90{ 90{
91 BUG_ON((unsigned long)pte & (PAGE_SIZE-1)); 91 BUG_ON((unsigned long)pte & (PAGE_SIZE-1));
92 free_page((unsigned long)pte); 92 free_page((unsigned long)pte);
93} 93}
94 94
95extern inline void pte_free(struct page *pte) 95static inline void pte_free(struct page *pte)
96{ 96{
97 __free_page(pte); 97 __free_page(pte);
98} 98}
diff --git a/include/asm-x86_64/pgtable.h b/include/asm-x86_64/pgtable.h
index 5e0f2fdab0..1dc110ba82 100644
--- a/include/asm-x86_64/pgtable.h
+++ b/include/asm-x86_64/pgtable.h
@@ -85,7 +85,7 @@ static inline void set_pud(pud_t *dst, pud_t val)
85 pud_val(*dst) = pud_val(val); 85 pud_val(*dst) = pud_val(val);
86} 86}
87 87
88extern inline void pud_clear (pud_t *pud) 88static inline void pud_clear (pud_t *pud)
89{ 89{
90 set_pud(pud, __pud(0)); 90 set_pud(pud, __pud(0));
91} 91}
@@ -95,7 +95,7 @@ static inline void set_pgd(pgd_t *dst, pgd_t val)
95 pgd_val(*dst) = pgd_val(val); 95 pgd_val(*dst) = pgd_val(val);
96} 96}
97 97
98extern inline void pgd_clear (pgd_t * pgd) 98static inline void pgd_clear (pgd_t * pgd)
99{ 99{
100 set_pgd(pgd, __pgd(0)); 100 set_pgd(pgd, __pgd(0));
101} 101}
@@ -375,7 +375,7 @@ static inline pte_t mk_pte_phys(unsigned long physpage, pgprot_t pgprot)
375} 375}
376 376
377/* Change flags of a PTE */ 377/* Change flags of a PTE */
378extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot) 378static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
379{ 379{
380 pte_val(pte) &= _PAGE_CHG_MASK; 380 pte_val(pte) &= _PAGE_CHG_MASK;
381 pte_val(pte) |= pgprot_val(newprot); 381 pte_val(pte) |= pgprot_val(newprot);
diff --git a/include/asm-x86_64/processor.h b/include/asm-x86_64/processor.h
index a832199944..03837d34fb 100644
--- a/include/asm-x86_64/processor.h
+++ b/include/asm-x86_64/processor.h
@@ -254,7 +254,13 @@ struct thread_struct {
254 u64 tls_array[GDT_ENTRY_TLS_ENTRIES]; 254 u64 tls_array[GDT_ENTRY_TLS_ENTRIES];
255} __attribute__((aligned(16))); 255} __attribute__((aligned(16)));
256 256
257#define INIT_THREAD {} 257#define INIT_THREAD { \
258 .rsp0 = (unsigned long)&init_stack + sizeof(init_stack) \
259}
260
261#define INIT_TSS { \
262 .rsp0 = (unsigned long)&init_stack + sizeof(init_stack) \
263}
258 264
259#define INIT_MMAP \ 265#define INIT_MMAP \
260{ &init_mm, 0, 0, NULL, PAGE_SHARED, VM_READ | VM_WRITE | VM_EXEC, 1, NULL, NULL } 266{ &init_mm, 0, 0, NULL, PAGE_SHARED, VM_READ | VM_WRITE | VM_EXEC, 1, NULL, NULL }
@@ -375,13 +381,13 @@ struct extended_sigtable {
375#define ASM_NOP_MAX 8 381#define ASM_NOP_MAX 8
376 382
377/* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */ 383/* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
378extern inline void rep_nop(void) 384static inline void rep_nop(void)
379{ 385{
380 __asm__ __volatile__("rep;nop": : :"memory"); 386 __asm__ __volatile__("rep;nop": : :"memory");
381} 387}
382 388
383/* Stop speculative execution */ 389/* Stop speculative execution */
384extern inline void sync_core(void) 390static inline void sync_core(void)
385{ 391{
386 int tmp; 392 int tmp;
387 asm volatile("cpuid" : "=a" (tmp) : "0" (1) : "ebx","ecx","edx","memory"); 393 asm volatile("cpuid" : "=a" (tmp) : "0" (1) : "ebx","ecx","edx","memory");
diff --git a/include/asm-x86_64/proto.h b/include/asm-x86_64/proto.h
index 6c813eb521..dbb37b0adb 100644
--- a/include/asm-x86_64/proto.h
+++ b/include/asm-x86_64/proto.h
@@ -8,7 +8,6 @@
8struct cpuinfo_x86; 8struct cpuinfo_x86;
9struct pt_regs; 9struct pt_regs;
10 10
11extern void get_cpu_vendor(struct cpuinfo_x86*);
12extern void start_kernel(void); 11extern void start_kernel(void);
13extern void pda_init(int); 12extern void pda_init(int);
14 13
@@ -75,9 +74,6 @@ extern void acpi_reserve_bootmem(void);
75 74
76extern void swap_low_mappings(void); 75extern void swap_low_mappings(void);
77 76
78extern void oops_begin(void);
79extern void die(const char *,struct pt_regs *,long);
80extern void __die(const char * str, struct pt_regs * regs, long err);
81extern void __show_regs(struct pt_regs * regs); 77extern void __show_regs(struct pt_regs * regs);
82extern void show_regs(struct pt_regs * regs); 78extern void show_regs(struct pt_regs * regs);
83 79
@@ -94,8 +90,6 @@ extern int unhandled_signal(struct task_struct *tsk, int sig);
94extern void select_idle_routine(const struct cpuinfo_x86 *c); 90extern void select_idle_routine(const struct cpuinfo_x86 *c);
95extern void swiotlb_init(void); 91extern void swiotlb_init(void);
96 92
97extern unsigned long max_mapnr;
98extern unsigned long end_pfn;
99extern unsigned long table_start, table_end; 93extern unsigned long table_start, table_end;
100 94
101extern int exception_trace; 95extern int exception_trace;
diff --git a/include/asm-x86_64/signal.h b/include/asm-x86_64/signal.h
index fe9b96d948..f8d5579853 100644
--- a/include/asm-x86_64/signal.h
+++ b/include/asm-x86_64/signal.h
@@ -143,23 +143,23 @@ typedef struct sigaltstack {
143#undef __HAVE_ARCH_SIG_BITOPS 143#undef __HAVE_ARCH_SIG_BITOPS
144#if 0 144#if 0
145 145
146extern __inline__ void sigaddset(sigset_t *set, int _sig) 146static inline void sigaddset(sigset_t *set, int _sig)
147{ 147{
148 __asm__("btsq %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc"); 148 __asm__("btsq %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc");
149} 149}
150 150
151extern __inline__ void sigdelset(sigset_t *set, int _sig) 151static inline void sigdelset(sigset_t *set, int _sig)
152{ 152{
153 __asm__("btrq %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc"); 153 __asm__("btrq %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc");
154} 154}
155 155
156extern __inline__ int __const_sigismember(sigset_t *set, int _sig) 156static inline int __const_sigismember(sigset_t *set, int _sig)
157{ 157{
158 unsigned long sig = _sig - 1; 158 unsigned long sig = _sig - 1;
159 return 1 & (set->sig[sig / _NSIG_BPW] >> (sig & ~(_NSIG_BPW-1))); 159 return 1 & (set->sig[sig / _NSIG_BPW] >> (sig & ~(_NSIG_BPW-1)));
160} 160}
161 161
162extern __inline__ int __gen_sigismember(sigset_t *set, int _sig) 162static inline int __gen_sigismember(sigset_t *set, int _sig)
163{ 163{
164 int ret; 164 int ret;
165 __asm__("btq %2,%1\n\tsbbq %0,%0" 165 __asm__("btq %2,%1\n\tsbbq %0,%0"
@@ -172,7 +172,7 @@ extern __inline__ int __gen_sigismember(sigset_t *set, int _sig)
172 __const_sigismember((set),(sig)) : \ 172 __const_sigismember((set),(sig)) : \
173 __gen_sigismember((set),(sig))) 173 __gen_sigismember((set),(sig)))
174 174
175extern __inline__ int sigfindinword(unsigned long word) 175static inline int sigfindinword(unsigned long word)
176{ 176{
177 __asm__("bsfq %1,%0" : "=r"(word) : "rm"(word) : "cc"); 177 __asm__("bsfq %1,%0" : "=r"(word) : "rm"(word) : "cc");
178 return word; 178 return word;
diff --git a/include/asm-x86_64/smp.h b/include/asm-x86_64/smp.h
index de8b57b2b6..24e32611f0 100644
--- a/include/asm-x86_64/smp.h
+++ b/include/asm-x86_64/smp.h
@@ -72,7 +72,7 @@ static inline int num_booting_cpus(void)
72 72
73#define raw_smp_processor_id() read_pda(cpunumber) 73#define raw_smp_processor_id() read_pda(cpunumber)
74 74
75extern __inline int hard_smp_processor_id(void) 75static inline int hard_smp_processor_id(void)
76{ 76{
77 /* we don't want to mark this access volatile - bad code generation */ 77 /* we don't want to mark this access volatile - bad code generation */
78 return GET_APIC_ID(*(unsigned int *)(APIC_BASE+APIC_ID)); 78 return GET_APIC_ID(*(unsigned int *)(APIC_BASE+APIC_ID));
diff --git a/include/asm-x86_64/spinlock.h b/include/asm-x86_64/spinlock.h
index 5aeb57a3ba..69636831ad 100644
--- a/include/asm-x86_64/spinlock.h
+++ b/include/asm-x86_64/spinlock.h
@@ -6,47 +6,21 @@
6#include <asm/page.h> 6#include <asm/page.h>
7#include <linux/config.h> 7#include <linux/config.h>
8 8
9extern int printk(const char * fmt, ...)
10 __attribute__ ((format (printf, 1, 2)));
11
12/* 9/*
13 * Your basic SMP spinlocks, allowing only a single CPU anywhere 10 * Your basic SMP spinlocks, allowing only a single CPU anywhere
14 */ 11 *
15
16typedef struct {
17 volatile unsigned int lock;
18#ifdef CONFIG_DEBUG_SPINLOCK
19 unsigned magic;
20#endif
21#ifdef CONFIG_PREEMPT
22 unsigned int break_lock;
23#endif
24} spinlock_t;
25
26#define SPINLOCK_MAGIC 0xdead4ead
27
28#ifdef CONFIG_DEBUG_SPINLOCK
29#define SPINLOCK_MAGIC_INIT , SPINLOCK_MAGIC
30#else
31#define SPINLOCK_MAGIC_INIT /* */
32#endif
33
34#define SPIN_LOCK_UNLOCKED (spinlock_t) { 1 SPINLOCK_MAGIC_INIT }
35
36#define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while(0)
37
38/*
39 * Simple spin lock operations. There are two variants, one clears IRQ's 12 * Simple spin lock operations. There are two variants, one clears IRQ's
40 * on the local processor, one does not. 13 * on the local processor, one does not.
41 * 14 *
42 * We make no fairness assumptions. They have a cost. 15 * We make no fairness assumptions. They have a cost.
16 *
17 * (the type definitions are in asm/spinlock_types.h)
43 */ 18 */
44 19
45#define spin_is_locked(x) (*(volatile signed char *)(&(x)->lock) <= 0) 20#define __raw_spin_is_locked(x) \
46#define spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x)) 21 (*(volatile signed char *)(&(x)->slock) <= 0)
47#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
48 22
49#define spin_lock_string \ 23#define __raw_spin_lock_string \
50 "\n1:\t" \ 24 "\n1:\t" \
51 "lock ; decb %0\n\t" \ 25 "lock ; decb %0\n\t" \
52 "js 2f\n" \ 26 "js 2f\n" \
@@ -58,74 +32,40 @@ typedef struct {
58 "jmp 1b\n" \ 32 "jmp 1b\n" \
59 LOCK_SECTION_END 33 LOCK_SECTION_END
60 34
61/* 35#define __raw_spin_unlock_string \
62 * This works. Despite all the confusion.
63 * (except on PPro SMP or if we are using OOSTORE)
64 * (PPro errata 66, 92)
65 */
66
67#if !defined(CONFIG_X86_OOSTORE) && !defined(CONFIG_X86_PPRO_FENCE)
68
69#define spin_unlock_string \
70 "movb $1,%0" \ 36 "movb $1,%0" \
71 :"=m" (lock->lock) : : "memory" 37 :"=m" (lock->slock) : : "memory"
72
73
74static inline void _raw_spin_unlock(spinlock_t *lock)
75{
76#ifdef CONFIG_DEBUG_SPINLOCK
77 BUG_ON(lock->magic != SPINLOCK_MAGIC);
78 assert_spin_locked(lock);
79#endif
80 __asm__ __volatile__(
81 spin_unlock_string
82 );
83}
84
85#else
86
87#define spin_unlock_string \
88 "xchgb %b0, %1" \
89 :"=q" (oldval), "=m" (lock->lock) \
90 :"0" (oldval) : "memory"
91 38
92static inline void _raw_spin_unlock(spinlock_t *lock) 39static inline void __raw_spin_lock(raw_spinlock_t *lock)
93{ 40{
94 char oldval = 1;
95#ifdef CONFIG_DEBUG_SPINLOCK
96 BUG_ON(lock->magic != SPINLOCK_MAGIC);
97 assert_spin_locked(lock);
98#endif
99 __asm__ __volatile__( 41 __asm__ __volatile__(
100 spin_unlock_string 42 __raw_spin_lock_string
101 ); 43 :"=m" (lock->slock) : : "memory");
102} 44}
103 45
104#endif 46#define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
105 47
106static inline int _raw_spin_trylock(spinlock_t *lock) 48static inline int __raw_spin_trylock(raw_spinlock_t *lock)
107{ 49{
108 char oldval; 50 char oldval;
51
109 __asm__ __volatile__( 52 __asm__ __volatile__(
110 "xchgb %b0,%1" 53 "xchgb %b0,%1"
111 :"=q" (oldval), "=m" (lock->lock) 54 :"=q" (oldval), "=m" (lock->slock)
112 :"0" (0) : "memory"); 55 :"0" (0) : "memory");
56
113 return oldval > 0; 57 return oldval > 0;
114} 58}
115 59
116static inline void _raw_spin_lock(spinlock_t *lock) 60static inline void __raw_spin_unlock(raw_spinlock_t *lock)
117{ 61{
118#ifdef CONFIG_DEBUG_SPINLOCK
119 if (lock->magic != SPINLOCK_MAGIC) {
120 printk("eip: %p\n", __builtin_return_address(0));
121 BUG();
122 }
123#endif
124 __asm__ __volatile__( 62 __asm__ __volatile__(
125 spin_lock_string 63 __raw_spin_unlock_string
126 :"=m" (lock->lock) : : "memory"); 64 );
127} 65}
128 66
67#define __raw_spin_unlock_wait(lock) \
68 do { while (__raw_spin_is_locked(lock)) cpu_relax(); } while (0)
129 69
130/* 70/*
131 * Read-write spinlocks, allowing multiple readers 71 * Read-write spinlocks, allowing multiple readers
@@ -136,33 +76,7 @@ static inline void _raw_spin_lock(spinlock_t *lock)
136 * can "mix" irq-safe locks - any writer needs to get a 76 * can "mix" irq-safe locks - any writer needs to get a
137 * irq-safe write-lock, but readers can get non-irqsafe 77 * irq-safe write-lock, but readers can get non-irqsafe
138 * read-locks. 78 * read-locks.
139 */ 79 *
140typedef struct {
141 volatile unsigned int lock;
142#ifdef CONFIG_DEBUG_SPINLOCK
143 unsigned magic;
144#endif
145#ifdef CONFIG_PREEMPT
146 unsigned int break_lock;
147#endif
148} rwlock_t;
149
150#define RWLOCK_MAGIC 0xdeaf1eed
151
152#ifdef CONFIG_DEBUG_SPINLOCK
153#define RWLOCK_MAGIC_INIT , RWLOCK_MAGIC
154#else
155#define RWLOCK_MAGIC_INIT /* */
156#endif
157
158#define RW_LOCK_UNLOCKED (rwlock_t) { RW_LOCK_BIAS RWLOCK_MAGIC_INIT }
159
160#define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0)
161
162#define read_can_lock(x) ((int)(x)->lock > 0)
163#define write_can_lock(x) ((x)->lock == RW_LOCK_BIAS)
164
165/*
166 * On x86, we implement read-write locks as a 32-bit counter 80 * On x86, we implement read-write locks as a 32-bit counter
167 * with the high bit (sign) being the "contended" bit. 81 * with the high bit (sign) being the "contended" bit.
168 * 82 *
@@ -170,29 +84,24 @@ typedef struct {
170 * 84 *
171 * Changed to use the same technique as rw semaphores. See 85 * Changed to use the same technique as rw semaphores. See
172 * semaphore.h for details. -ben 86 * semaphore.h for details. -ben
87 *
88 * the helpers are in arch/i386/kernel/semaphore.c
173 */ 89 */
174/* the spinlock helpers are in arch/i386/kernel/semaphore.c */
175 90
176static inline void _raw_read_lock(rwlock_t *rw) 91#define __raw_read_can_lock(x) ((int)(x)->lock > 0)
92#define __raw_write_can_lock(x) ((x)->lock == RW_LOCK_BIAS)
93
94static inline void __raw_read_lock(raw_rwlock_t *rw)
177{ 95{
178#ifdef CONFIG_DEBUG_SPINLOCK
179 BUG_ON(rw->magic != RWLOCK_MAGIC);
180#endif
181 __build_read_lock(rw, "__read_lock_failed"); 96 __build_read_lock(rw, "__read_lock_failed");
182} 97}
183 98
184static inline void _raw_write_lock(rwlock_t *rw) 99static inline void __raw_write_lock(raw_rwlock_t *rw)
185{ 100{
186#ifdef CONFIG_DEBUG_SPINLOCK
187 BUG_ON(rw->magic != RWLOCK_MAGIC);
188#endif
189 __build_write_lock(rw, "__write_lock_failed"); 101 __build_write_lock(rw, "__write_lock_failed");
190} 102}
191 103
192#define _raw_read_unlock(rw) asm volatile("lock ; incl %0" :"=m" ((rw)->lock) : : "memory") 104static inline int __raw_read_trylock(raw_rwlock_t *lock)
193#define _raw_write_unlock(rw) asm volatile("lock ; addl $" RW_LOCK_BIAS_STR ",%0":"=m" ((rw)->lock) : : "memory")
194
195static inline int _raw_read_trylock(rwlock_t *lock)
196{ 105{
197 atomic_t *count = (atomic_t *)lock; 106 atomic_t *count = (atomic_t *)lock;
198 atomic_dec(count); 107 atomic_dec(count);
@@ -202,7 +111,7 @@ static inline int _raw_read_trylock(rwlock_t *lock)
202 return 0; 111 return 0;
203} 112}
204 113
205static inline int _raw_write_trylock(rwlock_t *lock) 114static inline int __raw_write_trylock(raw_rwlock_t *lock)
206{ 115{
207 atomic_t *count = (atomic_t *)lock; 116 atomic_t *count = (atomic_t *)lock;
208 if (atomic_sub_and_test(RW_LOCK_BIAS, count)) 117 if (atomic_sub_and_test(RW_LOCK_BIAS, count))
@@ -211,4 +120,15 @@ static inline int _raw_write_trylock(rwlock_t *lock)
211 return 0; 120 return 0;
212} 121}
213 122
123static inline void __raw_read_unlock(raw_rwlock_t *rw)
124{
125 asm volatile("lock ; incl %0" :"=m" (rw->lock) : : "memory");
126}
127
128static inline void __raw_write_unlock(raw_rwlock_t *rw)
129{
130 asm volatile("lock ; addl $" RW_LOCK_BIAS_STR ",%0"
131 : "=m" (rw->lock) : : "memory");
132}
133
214#endif /* __ASM_SPINLOCK_H */ 134#endif /* __ASM_SPINLOCK_H */
diff --git a/include/asm-x86_64/spinlock_types.h b/include/asm-x86_64/spinlock_types.h
new file mode 100644
index 0000000000..59efe849f3
--- /dev/null
+++ b/include/asm-x86_64/spinlock_types.h
@@ -0,0 +1,20 @@
1#ifndef __ASM_SPINLOCK_TYPES_H
2#define __ASM_SPINLOCK_TYPES_H
3
4#ifndef __LINUX_SPINLOCK_TYPES_H
5# error "please don't include this file directly"
6#endif
7
8typedef struct {
9 volatile unsigned int slock;
10} raw_spinlock_t;
11
12#define __RAW_SPIN_LOCK_UNLOCKED { 1 }
13
14typedef struct {
15 volatile unsigned int lock;
16} raw_rwlock_t;
17
18#define __RAW_RW_LOCK_UNLOCKED { RW_LOCK_BIAS }
19
20#endif
diff --git a/include/asm-x86_64/system.h b/include/asm-x86_64/system.h
index 8606e170a7..85348e02ad 100644
--- a/include/asm-x86_64/system.h
+++ b/include/asm-x86_64/system.h
@@ -188,7 +188,7 @@ static inline void write_cr4(unsigned long val)
188 188
189#define __xg(x) ((volatile long *)(x)) 189#define __xg(x) ((volatile long *)(x))
190 190
191extern inline void set_64bit(volatile unsigned long *ptr, unsigned long val) 191static inline void set_64bit(volatile unsigned long *ptr, unsigned long val)
192{ 192{
193 *ptr = val; 193 *ptr = val;
194} 194}
@@ -253,19 +253,19 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
253 case 2: 253 case 2:
254 __asm__ __volatile__(LOCK_PREFIX "cmpxchgw %w1,%2" 254 __asm__ __volatile__(LOCK_PREFIX "cmpxchgw %w1,%2"
255 : "=a"(prev) 255 : "=a"(prev)
256 : "q"(new), "m"(*__xg(ptr)), "0"(old) 256 : "r"(new), "m"(*__xg(ptr)), "0"(old)
257 : "memory"); 257 : "memory");
258 return prev; 258 return prev;
259 case 4: 259 case 4:
260 __asm__ __volatile__(LOCK_PREFIX "cmpxchgl %k1,%2" 260 __asm__ __volatile__(LOCK_PREFIX "cmpxchgl %k1,%2"
261 : "=a"(prev) 261 : "=a"(prev)
262 : "q"(new), "m"(*__xg(ptr)), "0"(old) 262 : "r"(new), "m"(*__xg(ptr)), "0"(old)
263 : "memory"); 263 : "memory");
264 return prev; 264 return prev;
265 case 8: 265 case 8:
266 __asm__ __volatile__(LOCK_PREFIX "cmpxchgq %1,%2" 266 __asm__ __volatile__(LOCK_PREFIX "cmpxchgq %1,%2"
267 : "=a"(prev) 267 : "=a"(prev)
268 : "q"(new), "m"(*__xg(ptr)), "0"(old) 268 : "r"(new), "m"(*__xg(ptr)), "0"(old)
269 : "memory"); 269 : "memory");
270 return prev; 270 return prev;
271 } 271 }
diff --git a/include/asm-x86_64/timex.h b/include/asm-x86_64/timex.h
index 24ecf6a637..f971f45d6d 100644
--- a/include/asm-x86_64/timex.h
+++ b/include/asm-x86_64/timex.h
@@ -6,7 +6,6 @@
6#ifndef _ASMx8664_TIMEX_H 6#ifndef _ASMx8664_TIMEX_H
7#define _ASMx8664_TIMEX_H 7#define _ASMx8664_TIMEX_H
8 8
9#include <linux/config.h>
10#include <asm/8253pit.h> 9#include <asm/8253pit.h>
11#include <asm/msr.h> 10#include <asm/msr.h>
12#include <asm/vsyscall.h> 11#include <asm/vsyscall.h>
diff --git a/include/asm-x86_64/tlbflush.h b/include/asm-x86_64/tlbflush.h
index 505b0cf906..4a9c20ea9b 100644
--- a/include/asm-x86_64/tlbflush.h
+++ b/include/asm-x86_64/tlbflush.h
@@ -109,6 +109,10 @@ static inline void flush_tlb_range(struct vm_area_struct * vma, unsigned long st
109#define TLBSTATE_OK 1 109#define TLBSTATE_OK 1
110#define TLBSTATE_LAZY 2 110#define TLBSTATE_LAZY 2
111 111
112/* Roughly an IPI every 20MB with 4k pages for freeing page table
113 ranges. Cost is about 42k of memory for each CPU. */
114#define ARCH_FREE_PTE_NR 5350
115
112#endif 116#endif
113 117
114#define flush_tlb_kernel_range(start, end) flush_tlb_all() 118#define flush_tlb_kernel_range(start, end) flush_tlb_all()
diff --git a/include/asm-x86_64/topology.h b/include/asm-x86_64/topology.h
index c1bc3fad48..1c603cd7e4 100644
--- a/include/asm-x86_64/topology.h
+++ b/include/asm-x86_64/topology.h
@@ -13,7 +13,6 @@
13extern cpumask_t cpu_online_map; 13extern cpumask_t cpu_online_map;
14 14
15extern unsigned char cpu_to_node[]; 15extern unsigned char cpu_to_node[];
16extern unsigned char pci_bus_to_node[];
17extern cpumask_t node_to_cpumask[]; 16extern cpumask_t node_to_cpumask[];
18 17
19#ifdef CONFIG_ACPI_NUMA 18#ifdef CONFIG_ACPI_NUMA
@@ -26,7 +25,7 @@ extern int __node_distance(int, int);
26#define parent_node(node) (node) 25#define parent_node(node) (node)
27#define node_to_first_cpu(node) (__ffs(node_to_cpumask[node])) 26#define node_to_first_cpu(node) (__ffs(node_to_cpumask[node]))
28#define node_to_cpumask(node) (node_to_cpumask[node]) 27#define node_to_cpumask(node) (node_to_cpumask[node])
29#define pcibus_to_node(bus) pci_bus_to_node[(bus)->number] 28#define pcibus_to_node(bus) ((long)(bus->sysdata))
30#define pcibus_to_cpumask(bus) node_to_cpumask(pcibus_to_node(bus)); 29#define pcibus_to_cpumask(bus) node_to_cpumask(pcibus_to_node(bus));
31 30
32/* sched_domains SD_NODE_INIT for x86_64 machines */ 31/* sched_domains SD_NODE_INIT for x86_64 machines */
diff --git a/include/asm-x86_64/vsyscall.h b/include/asm-x86_64/vsyscall.h
index 2872da23fc..438a3f52f8 100644
--- a/include/asm-x86_64/vsyscall.h
+++ b/include/asm-x86_64/vsyscall.h
@@ -29,7 +29,6 @@ enum vsyscall_num {
29 29
30struct vxtime_data { 30struct vxtime_data {
31 long hpet_address; /* HPET base address */ 31 long hpet_address; /* HPET base address */
32 unsigned long hz; /* HPET clocks / sec */
33 int last; 32 int last;
34 unsigned long last_tsc; 33 unsigned long last_tsc;
35 long quot; 34 long quot;
diff --git a/include/asm-xtensa/ptrace.h b/include/asm-xtensa/ptrace.h
index 2848a5ff83..aa4fd7fb3c 100644
--- a/include/asm-xtensa/ptrace.h
+++ b/include/asm-xtensa/ptrace.h
@@ -127,7 +127,7 @@ extern void show_regs(struct pt_regs *);
127#else /* __ASSEMBLY__ */ 127#else /* __ASSEMBLY__ */
128 128
129#ifdef __KERNEL__ 129#ifdef __KERNEL__
130# include <asm/offsets.h> 130# include <asm/asm-offsets.h>
131#define PT_REGS_OFFSET (KERNEL_STACK_SIZE - PT_USER_SIZE) 131#define PT_REGS_OFFSET (KERNEL_STACK_SIZE - PT_USER_SIZE)
132#endif 132#endif
133 133
diff --git a/include/asm-xtensa/uaccess.h b/include/asm-xtensa/uaccess.h
index fc268ac923..06a22b83ba 100644
--- a/include/asm-xtensa/uaccess.h
+++ b/include/asm-xtensa/uaccess.h
@@ -25,7 +25,7 @@
25 25
26#define _ASMLANGUAGE 26#define _ASMLANGUAGE
27#include <asm/current.h> 27#include <asm/current.h>
28#include <asm/offsets.h> 28#include <asm/asm-offsets.h>
29#include <asm/processor.h> 29#include <asm/processor.h>
30 30
31/* 31/*
diff --git a/include/linux/bfs_fs.h b/include/linux/bfs_fs.h
index f7f0913cd1..c1237aa92e 100644
--- a/include/linux/bfs_fs.h
+++ b/include/linux/bfs_fs.h
@@ -14,8 +14,9 @@
14#define BFS_INODES_PER_BLOCK 8 14#define BFS_INODES_PER_BLOCK 8
15 15
16/* SVR4 vnode type values (bfs_inode->i_vtype) */ 16/* SVR4 vnode type values (bfs_inode->i_vtype) */
17#define BFS_VDIR 2 17#define BFS_VDIR 2L
18#define BFS_VREG 1 18#define BFS_VREG 1L
19
19 20
20/* BFS inode layout on disk */ 21/* BFS inode layout on disk */
21struct bfs_inode { 22struct bfs_inode {
@@ -58,22 +59,22 @@ struct bfs_super_block {
58 __u32 s_padding[118]; 59 __u32 s_padding[118];
59}; 60};
60 61
61#define BFS_NZFILESIZE(ip) \
62 (((ip)->i_eoffset + 1) - (ip)->i_sblock * BFS_BSIZE)
63
64#define BFS_FILESIZE(ip) \
65 ((ip)->i_sblock == 0 ? 0 : BFS_NZFILESIZE(ip))
66
67#define BFS_FILEBLOCKS(ip) \
68 ((ip)->i_sblock == 0 ? 0 : ((ip)->i_eblock + 1) - (ip)->i_sblock)
69 62
70#define BFS_OFF2INO(offset) \ 63#define BFS_OFF2INO(offset) \
71 ((((offset) - BFS_BSIZE) / sizeof(struct bfs_inode)) + BFS_ROOT_INO) 64 ((((offset) - BFS_BSIZE) / sizeof(struct bfs_inode)) + BFS_ROOT_INO)
72 65
73#define BFS_INO2OFF(ino) \ 66#define BFS_INO2OFF(ino) \
74 ((__u32)(((ino) - BFS_ROOT_INO) * sizeof(struct bfs_inode)) + BFS_BSIZE) 67 ((__u32)(((ino) - BFS_ROOT_INO) * sizeof(struct bfs_inode)) + BFS_BSIZE)
68#define BFS_NZFILESIZE(ip) \
69 ((cpu_to_le32((ip)->i_eoffset) + 1) - cpu_to_le32((ip)->i_sblock) * BFS_BSIZE)
70
71#define BFS_FILESIZE(ip) \
72 ((ip)->i_sblock == 0 ? 0 : BFS_NZFILESIZE(ip))
75 73
74#define BFS_FILEBLOCKS(ip) \
75 ((ip)->i_sblock == 0 ? 0 : (cpu_to_le32((ip)->i_eblock) + 1) - cpu_to_le32((ip)->i_sblock))
76#define BFS_UNCLEAN(bfs_sb, sb) \ 76#define BFS_UNCLEAN(bfs_sb, sb) \
77 ((bfs_sb->s_from != -1) && (bfs_sb->s_to != -1) && !(sb->s_flags & MS_RDONLY)) 77 ((cpu_to_le32(bfs_sb->s_from) != -1) && (cpu_to_le32(bfs_sb->s_to) != -1) && !(sb->s_flags & MS_RDONLY))
78
78 79
79#endif /* _LINUX_BFS_FS_H */ 80#endif /* _LINUX_BFS_FS_H */
diff --git a/include/linux/bio.h b/include/linux/bio.h
index cdaf03a14a..6e1c79c8b6 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -314,9 +314,8 @@ void zero_fill_bio(struct bio *bio);
314 * bvec_kmap_irq and bvec_kunmap_irq!! 314 * bvec_kmap_irq and bvec_kunmap_irq!!
315 * 315 *
316 * This function MUST be inlined - it plays with the CPU interrupt flags. 316 * This function MUST be inlined - it plays with the CPU interrupt flags.
317 * Hence the `extern inline'.
318 */ 317 */
319extern inline char *bvec_kmap_irq(struct bio_vec *bvec, unsigned long *flags) 318static inline char *bvec_kmap_irq(struct bio_vec *bvec, unsigned long *flags)
320{ 319{
321 unsigned long addr; 320 unsigned long addr;
322 321
@@ -332,7 +331,7 @@ extern inline char *bvec_kmap_irq(struct bio_vec *bvec, unsigned long *flags)
332 return (char *) addr + bvec->bv_offset; 331 return (char *) addr + bvec->bv_offset;
333} 332}
334 333
335extern inline void bvec_kunmap_irq(char *buffer, unsigned long *flags) 334static inline void bvec_kunmap_irq(char *buffer, unsigned long *flags)
336{ 335{
337 unsigned long ptr = (unsigned long) buffer & PAGE_MASK; 336 unsigned long ptr = (unsigned long) buffer & PAGE_MASK;
338 337
@@ -345,7 +344,7 @@ extern inline void bvec_kunmap_irq(char *buffer, unsigned long *flags)
345#define bvec_kunmap_irq(buf, flags) do { *(flags) = 0; } while (0) 344#define bvec_kunmap_irq(buf, flags) do { *(flags) = 0; } while (0)
346#endif 345#endif
347 346
348extern inline char *__bio_kmap_irq(struct bio *bio, unsigned short idx, 347static inline char *__bio_kmap_irq(struct bio *bio, unsigned short idx,
349 unsigned long *flags) 348 unsigned long *flags)
350{ 349{
351 return bvec_kmap_irq(bio_iovec_idx(bio, idx), flags); 350 return bvec_kmap_irq(bio_iovec_idx(bio, idx), flags);
diff --git a/include/linux/bit_spinlock.h b/include/linux/bit_spinlock.h
new file mode 100644
index 0000000000..6b20af0bbb
--- /dev/null
+++ b/include/linux/bit_spinlock.h
@@ -0,0 +1,77 @@
1#ifndef __LINUX_BIT_SPINLOCK_H
2#define __LINUX_BIT_SPINLOCK_H
3
4/*
5 * bit-based spin_lock()
6 *
7 * Don't use this unless you really need to: spin_lock() and spin_unlock()
8 * are significantly faster.
9 */
10static inline void bit_spin_lock(int bitnum, unsigned long *addr)
11{
12 /*
13 * Assuming the lock is uncontended, this never enters
14 * the body of the outer loop. If it is contended, then
15 * within the inner loop a non-atomic test is used to
16 * busywait with less bus contention for a good time to
17 * attempt to acquire the lock bit.
18 */
19 preempt_disable();
20#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
21 while (test_and_set_bit(bitnum, addr)) {
22 while (test_bit(bitnum, addr)) {
23 preempt_enable();
24 cpu_relax();
25 preempt_disable();
26 }
27 }
28#endif
29 __acquire(bitlock);
30}
31
32/*
33 * Return true if it was acquired
34 */
35static inline int bit_spin_trylock(int bitnum, unsigned long *addr)
36{
37 preempt_disable();
38#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
39 if (test_and_set_bit(bitnum, addr)) {
40 preempt_enable();
41 return 0;
42 }
43#endif
44 __acquire(bitlock);
45 return 1;
46}
47
48/*
49 * bit-based spin_unlock()
50 */
51static inline void bit_spin_unlock(int bitnum, unsigned long *addr)
52{
53#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
54 BUG_ON(!test_bit(bitnum, addr));
55 smp_mb__before_clear_bit();
56 clear_bit(bitnum, addr);
57#endif
58 preempt_enable();
59 __release(bitlock);
60}
61
62/*
63 * Return true if the lock is held.
64 */
65static inline int bit_spin_is_locked(int bitnum, unsigned long *addr)
66{
67#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
68 return test_bit(bitnum, addr);
69#elif defined CONFIG_PREEMPT
70 return preempt_count();
71#else
72 return 1;
73#endif
74}
75
76#endif /* __LINUX_BIT_SPINLOCK_H */
77
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index aefa26fbae..efdc9b5bc0 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -728,7 +728,7 @@ static inline unsigned int blksize_bits(unsigned int size)
728 return bits; 728 return bits;
729} 729}
730 730
731extern inline unsigned int block_size(struct block_device *bdev) 731static inline unsigned int block_size(struct block_device *bdev)
732{ 732{
733 return bdev->bd_block_size; 733 return bdev->bd_block_size;
734} 734}
diff --git a/include/linux/chio.h b/include/linux/chio.h
index 63035ae67e..a404c111c9 100644
--- a/include/linux/chio.h
+++ b/include/linux/chio.h
@@ -96,7 +96,7 @@ struct changer_position {
96 */ 96 */
97struct changer_element_status { 97struct changer_element_status {
98 int ces_type; 98 int ces_type;
99 unsigned char *ces_data; 99 unsigned char __user *ces_data;
100}; 100};
101#define CESTATUS_FULL 0x01 /* full */ 101#define CESTATUS_FULL 0x01 /* full */
102#define CESTATUS_IMPEXP 0x02 /* media was imported (inserted by sysop) */ 102#define CESTATUS_IMPEXP 0x02 /* media was imported (inserted by sysop) */
diff --git a/include/linux/dccp.h b/include/linux/dccp.h
index 007c290f74..8bf4bacb50 100644
--- a/include/linux/dccp.h
+++ b/include/linux/dccp.h
@@ -432,7 +432,10 @@ struct dccp_sock {
432 struct ccid *dccps_hc_rx_ccid; 432 struct ccid *dccps_hc_rx_ccid;
433 struct ccid *dccps_hc_tx_ccid; 433 struct ccid *dccps_hc_tx_ccid;
434 struct dccp_options_received dccps_options_received; 434 struct dccp_options_received dccps_options_received;
435 struct timeval dccps_epoch;
435 enum dccp_role dccps_role:2; 436 enum dccp_role dccps_role:2;
437 __u8 dccps_hc_rx_insert_options:1;
438 __u8 dccps_hc_tx_insert_options:1;
436}; 439};
437 440
438static inline struct dccp_sock *dccp_sk(const struct sock *sk) 441static inline struct dccp_sock *dccp_sk(const struct sock *sk)
diff --git a/include/linux/dmapool.h b/include/linux/dmapool.h
index e60bfdac34..4932ee5c77 100644
--- a/include/linux/dmapool.h
+++ b/include/linux/dmapool.h
@@ -19,7 +19,8 @@ struct dma_pool *dma_pool_create(const char *name, struct device *dev,
19 19
20void dma_pool_destroy(struct dma_pool *pool); 20void dma_pool_destroy(struct dma_pool *pool);
21 21
22void *dma_pool_alloc(struct dma_pool *pool, int mem_flags, dma_addr_t *handle); 22void *dma_pool_alloc(struct dma_pool *pool, unsigned int __nocast mem_flags,
23 dma_addr_t *handle);
23 24
24void dma_pool_free(struct dma_pool *pool, void *vaddr, dma_addr_t addr); 25void dma_pool_free(struct dma_pool *pool, void *vaddr, dma_addr_t addr);
25 26
diff --git a/include/linux/dmi.h b/include/linux/dmi.h
index c30175e8de..a415f1d93e 100644
--- a/include/linux/dmi.h
+++ b/include/linux/dmi.h
@@ -70,7 +70,7 @@ extern struct dmi_device * dmi_find_device(int type, const char *name,
70 70
71static inline int dmi_check_system(struct dmi_system_id *list) { return 0; } 71static inline int dmi_check_system(struct dmi_system_id *list) { return 0; }
72static inline char * dmi_get_system_info(int field) { return NULL; } 72static inline char * dmi_get_system_info(int field) { return NULL; }
73static struct dmi_device * dmi_find_device(int type, const char *name, 73static inline struct dmi_device * dmi_find_device(int type, const char *name,
74 struct dmi_device *from) { return NULL; } 74 struct dmi_device *from) { return NULL; }
75 75
76#endif 76#endif
diff --git a/include/linux/fb.h b/include/linux/fb.h
index bc24beeed9..82e39cd0c4 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -107,6 +107,8 @@
107#define FB_ACCEL_NV_20 44 /* nVidia Arch 20 */ 107#define FB_ACCEL_NV_20 44 /* nVidia Arch 20 */
108#define FB_ACCEL_NV_30 45 /* nVidia Arch 30 */ 108#define FB_ACCEL_NV_30 45 /* nVidia Arch 30 */
109#define FB_ACCEL_NV_40 46 /* nVidia Arch 40 */ 109#define FB_ACCEL_NV_40 46 /* nVidia Arch 40 */
110#define FB_ACCEL_XGI_VOLARI_V 47 /* XGI Volari V3XT, V5, V8 */
111#define FB_ACCEL_XGI_VOLARI_Z 48 /* XGI Volari Z7 */
110#define FB_ACCEL_NEOMAGIC_NM2070 90 /* NeoMagic NM2070 */ 112#define FB_ACCEL_NEOMAGIC_NM2070 90 /* NeoMagic NM2070 */
111#define FB_ACCEL_NEOMAGIC_NM2090 91 /* NeoMagic NM2090 */ 113#define FB_ACCEL_NEOMAGIC_NM2090 91 /* NeoMagic NM2090 */
112#define FB_ACCEL_NEOMAGIC_NM2093 92 /* NeoMagic NM2093 */ 114#define FB_ACCEL_NEOMAGIC_NM2093 92 /* NeoMagic NM2093 */
@@ -495,6 +497,9 @@ struct fb_cursor_user {
495#define FB_EVENT_BLANK 0x08 497#define FB_EVENT_BLANK 0x08
496/* Private modelist is to be replaced */ 498/* Private modelist is to be replaced */
497#define FB_EVENT_NEW_MODELIST 0x09 499#define FB_EVENT_NEW_MODELIST 0x09
500/* The resolution of the passed in fb_info about to change and
501 all vc's should be changed */
502#define FB_EVENT_MODE_CHANGE_ALL 0x0A
498 503
499struct fb_event { 504struct fb_event {
500 struct fb_info *info; 505 struct fb_info *info;
@@ -820,13 +825,29 @@ extern void fb_pad_unaligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 idx,
820 u32 height, u32 shift_high, u32 shift_low, u32 mod); 825 u32 height, u32 shift_high, u32 shift_low, u32 mod);
821extern void fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, u32 height); 826extern void fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, u32 height);
822extern void fb_set_suspend(struct fb_info *info, int state); 827extern void fb_set_suspend(struct fb_info *info, int state);
823extern int fb_get_color_depth(struct fb_var_screeninfo *var); 828extern int fb_get_color_depth(struct fb_var_screeninfo *var,
829 struct fb_fix_screeninfo *fix);
824extern int fb_get_options(char *name, char **option); 830extern int fb_get_options(char *name, char **option);
825extern int fb_new_modelist(struct fb_info *info); 831extern int fb_new_modelist(struct fb_info *info);
826 832
827extern struct fb_info *registered_fb[FB_MAX]; 833extern struct fb_info *registered_fb[FB_MAX];
828extern int num_registered_fb; 834extern int num_registered_fb;
829 835
836static inline void __fb_pad_aligned_buffer(u8 *dst, u32 d_pitch,
837 u8 *src, u32 s_pitch, u32 height)
838{
839 int i, j;
840
841 d_pitch -= s_pitch;
842
843 for (i = height; i--; ) {
844 /* s_pitch is a few bytes at the most, memcpy is suboptimal */
845 for (j = 0; j < s_pitch; j++)
846 *dst++ = *src++;
847 dst += d_pitch;
848 }
849}
850
830/* drivers/video/fbsysfs.c */ 851/* drivers/video/fbsysfs.c */
831extern struct fb_info *framebuffer_alloc(size_t size, struct device *dev); 852extern struct fb_info *framebuffer_alloc(size_t size, struct device *dev);
832extern void framebuffer_release(struct fb_info *info); 853extern void framebuffer_release(struct fb_info *info);
@@ -856,8 +877,11 @@ extern int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var,
856extern int fb_validate_mode(const struct fb_var_screeninfo *var, 877extern int fb_validate_mode(const struct fb_var_screeninfo *var,
857 struct fb_info *info); 878 struct fb_info *info);
858extern int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var); 879extern int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var);
859extern void fb_edid_to_monspecs(unsigned char *edid, struct fb_monspecs *specs); 880extern const unsigned char *fb_firmware_edid(struct device *device);
881extern void fb_edid_to_monspecs(unsigned char *edid,
882 struct fb_monspecs *specs);
860extern void fb_destroy_modedb(struct fb_videomode *modedb); 883extern void fb_destroy_modedb(struct fb_videomode *modedb);
884extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
861 885
862/* drivers/video/modedb.c */ 886/* drivers/video/modedb.c */
863#define VESA_MODEDB_SIZE 34 887#define VESA_MODEDB_SIZE 34
diff --git a/include/linux/file.h b/include/linux/file.h
index 5206beb9a8..f5bbd4c508 100644
--- a/include/linux/file.h
+++ b/include/linux/file.h
@@ -9,6 +9,7 @@
9#include <linux/posix_types.h> 9#include <linux/posix_types.h>
10#include <linux/compiler.h> 10#include <linux/compiler.h>
11#include <linux/spinlock.h> 11#include <linux/spinlock.h>
12#include <linux/rcupdate.h>
12 13
13/* 14/*
14 * The default fd array needs to be at least BITS_PER_LONG, 15 * The default fd array needs to be at least BITS_PER_LONG,
@@ -16,23 +17,33 @@
16 */ 17 */
17#define NR_OPEN_DEFAULT BITS_PER_LONG 18#define NR_OPEN_DEFAULT BITS_PER_LONG
18 19
20struct fdtable {
21 unsigned int max_fds;
22 int max_fdset;
23 int next_fd;
24 struct file ** fd; /* current fd array */
25 fd_set *close_on_exec;
26 fd_set *open_fds;
27 struct rcu_head rcu;
28 struct files_struct *free_files;
29 struct fdtable *next;
30};
31
19/* 32/*
20 * Open file table structure 33 * Open file table structure
21 */ 34 */
22struct files_struct { 35struct files_struct {
23 atomic_t count; 36 atomic_t count;
24 spinlock_t file_lock; /* Protects all the below members. Nests inside tsk->alloc_lock */ 37 spinlock_t file_lock; /* Protects all the below members. Nests inside tsk->alloc_lock */
25 int max_fds; 38 struct fdtable *fdt;
26 int max_fdset; 39 struct fdtable fdtab;
27 int next_fd;
28 struct file ** fd; /* current fd array */
29 fd_set *close_on_exec;
30 fd_set *open_fds;
31 fd_set close_on_exec_init; 40 fd_set close_on_exec_init;
32 fd_set open_fds_init; 41 fd_set open_fds_init;
33 struct file * fd_array[NR_OPEN_DEFAULT]; 42 struct file * fd_array[NR_OPEN_DEFAULT];
34}; 43};
35 44
45#define files_fdtable(files) (rcu_dereference((files)->fdt))
46
36extern void FASTCALL(__fput(struct file *)); 47extern void FASTCALL(__fput(struct file *));
37extern void FASTCALL(fput(struct file *)); 48extern void FASTCALL(fput(struct file *));
38 49
@@ -59,13 +70,16 @@ extern fd_set *alloc_fdset(int);
59extern void free_fdset(fd_set *, int); 70extern void free_fdset(fd_set *, int);
60 71
61extern int expand_files(struct files_struct *, int nr); 72extern int expand_files(struct files_struct *, int nr);
73extern void free_fdtable(struct fdtable *fdt);
74extern void __init files_defer_init(void);
62 75
63static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd) 76static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd)
64{ 77{
65 struct file * file = NULL; 78 struct file * file = NULL;
79 struct fdtable *fdt = files_fdtable(files);
66 80
67 if (fd < files->max_fds) 81 if (fd < fdt->max_fds)
68 file = files->fd[fd]; 82 file = rcu_dereference(fdt->fd[fd]);
69 return file; 83 return file;
70} 84}
71 85
diff --git a/include/linux/fs.h b/include/linux/fs.h
index fd93ab7da9..e0b77c5af9 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -9,6 +9,7 @@
9#include <linux/config.h> 9#include <linux/config.h>
10#include <linux/limits.h> 10#include <linux/limits.h>
11#include <linux/ioctl.h> 11#include <linux/ioctl.h>
12#include <linux/rcuref.h>
12 13
13/* 14/*
14 * It's silly to have NR_OPEN bigger than NR_FILE, but you can change 15 * It's silly to have NR_OPEN bigger than NR_FILE, but you can change
@@ -597,12 +598,13 @@ struct file {
597 spinlock_t f_ep_lock; 598 spinlock_t f_ep_lock;
598#endif /* #ifdef CONFIG_EPOLL */ 599#endif /* #ifdef CONFIG_EPOLL */
599 struct address_space *f_mapping; 600 struct address_space *f_mapping;
601 struct rcu_head f_rcuhead;
600}; 602};
601extern spinlock_t files_lock; 603extern spinlock_t files_lock;
602#define file_list_lock() spin_lock(&files_lock); 604#define file_list_lock() spin_lock(&files_lock);
603#define file_list_unlock() spin_unlock(&files_lock); 605#define file_list_unlock() spin_unlock(&files_lock);
604 606
605#define get_file(x) atomic_inc(&(x)->f_count) 607#define get_file(x) rcuref_inc(&(x)->f_count)
606#define file_count(x) atomic_read(&(x)->f_count) 608#define file_count(x) atomic_read(&(x)->f_count)
607 609
608#define MAX_NON_LFS ((1UL<<31) - 1) 610#define MAX_NON_LFS ((1UL<<31) - 1)
@@ -1507,8 +1509,6 @@ extern void do_generic_mapping_read(struct address_space *mapping,
1507 loff_t *, read_descriptor_t *, read_actor_t); 1509 loff_t *, read_descriptor_t *, read_actor_t);
1508extern void 1510extern void
1509file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping); 1511file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping);
1510extern ssize_t generic_file_direct_IO(int rw, struct kiocb *iocb,
1511 const struct iovec *iov, loff_t offset, unsigned long nr_segs);
1512extern ssize_t generic_file_readv(struct file *filp, const struct iovec *iov, 1512extern ssize_t generic_file_readv(struct file *filp, const struct iovec *iov,
1513 unsigned long nr_segs, loff_t *ppos); 1513 unsigned long nr_segs, loff_t *ppos);
1514ssize_t generic_file_writev(struct file *filp, const struct iovec *iov, 1514ssize_t generic_file_writev(struct file *filp, const struct iovec *iov,
diff --git a/include/linux/fuse.h b/include/linux/fuse.h
new file mode 100644
index 0000000000..acbeb96a33
--- /dev/null
+++ b/include/linux/fuse.h
@@ -0,0 +1,259 @@
1/*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu>
4
5 This program can be distributed under the terms of the GNU GPL.
6 See the file COPYING.
7*/
8
9/* This file defines the kernel interface of FUSE */
10
11#include <asm/types.h>
12
13/** Version number of this interface */
14#define FUSE_KERNEL_VERSION 7
15
16/** Minor version number of this interface */
17#define FUSE_KERNEL_MINOR_VERSION 2
18
19/** The node ID of the root inode */
20#define FUSE_ROOT_ID 1
21
22/** The major number of the fuse character device */
23#define FUSE_MAJOR 10
24
25/** The minor number of the fuse character device */
26#define FUSE_MINOR 229
27
28/* Make sure all structures are padded to 64bit boundary, so 32bit
29 userspace works under 64bit kernels */
30
31struct fuse_attr {
32 __u64 ino;
33 __u64 size;
34 __u64 blocks;
35 __u64 atime;
36 __u64 mtime;
37 __u64 ctime;
38 __u32 atimensec;
39 __u32 mtimensec;
40 __u32 ctimensec;
41 __u32 mode;
42 __u32 nlink;
43 __u32 uid;
44 __u32 gid;
45 __u32 rdev;
46};
47
48struct fuse_kstatfs {
49 __u64 blocks;
50 __u64 bfree;
51 __u64 bavail;
52 __u64 files;
53 __u64 ffree;
54 __u32 bsize;
55 __u32 namelen;
56};
57
58#define FATTR_MODE (1 << 0)
59#define FATTR_UID (1 << 1)
60#define FATTR_GID (1 << 2)
61#define FATTR_SIZE (1 << 3)
62#define FATTR_ATIME (1 << 4)
63#define FATTR_MTIME (1 << 5)
64#define FATTR_CTIME (1 << 6)
65
66/**
67 * Flags returned by the OPEN request
68 *
69 * FOPEN_DIRECT_IO: bypass page cache for this open file
70 * FOPEN_KEEP_CACHE: don't invalidate the data cache on open
71 */
72#define FOPEN_DIRECT_IO (1 << 0)
73#define FOPEN_KEEP_CACHE (1 << 1)
74
75enum fuse_opcode {
76 FUSE_LOOKUP = 1,
77 FUSE_FORGET = 2, /* no reply */
78 FUSE_GETATTR = 3,
79 FUSE_SETATTR = 4,
80 FUSE_READLINK = 5,
81 FUSE_SYMLINK = 6,
82 FUSE_MKNOD = 8,
83 FUSE_MKDIR = 9,
84 FUSE_UNLINK = 10,
85 FUSE_RMDIR = 11,
86 FUSE_RENAME = 12,
87 FUSE_LINK = 13,
88 FUSE_OPEN = 14,
89 FUSE_READ = 15,
90 FUSE_WRITE = 16,
91 FUSE_STATFS = 17,
92 FUSE_RELEASE = 18,
93 FUSE_FSYNC = 20,
94 FUSE_SETXATTR = 21,
95 FUSE_GETXATTR = 22,
96 FUSE_LISTXATTR = 23,
97 FUSE_REMOVEXATTR = 24,
98 FUSE_FLUSH = 25,
99 FUSE_INIT = 26,
100 FUSE_OPENDIR = 27,
101 FUSE_READDIR = 28,
102 FUSE_RELEASEDIR = 29,
103 FUSE_FSYNCDIR = 30
104};
105
106/* Conservative buffer size for the client */
107#define FUSE_MAX_IN 8192
108
109#define FUSE_NAME_MAX 1024
110#define FUSE_SYMLINK_MAX 4096
111#define FUSE_XATTR_SIZE_MAX 4096
112
113struct fuse_entry_out {
114 __u64 nodeid; /* Inode ID */
115 __u64 generation; /* Inode generation: nodeid:gen must
116 be unique for the fs's lifetime */
117 __u64 entry_valid; /* Cache timeout for the name */
118 __u64 attr_valid; /* Cache timeout for the attributes */
119 __u32 entry_valid_nsec;
120 __u32 attr_valid_nsec;
121 struct fuse_attr attr;
122};
123
124struct fuse_forget_in {
125 __u64 nlookup;
126};
127
128struct fuse_attr_out {
129 __u64 attr_valid; /* Cache timeout for the attributes */
130 __u32 attr_valid_nsec;
131 __u32 dummy;
132 struct fuse_attr attr;
133};
134
135struct fuse_mknod_in {
136 __u32 mode;
137 __u32 rdev;
138};
139
140struct fuse_mkdir_in {
141 __u32 mode;
142 __u32 padding;
143};
144
145struct fuse_rename_in {
146 __u64 newdir;
147};
148
149struct fuse_link_in {
150 __u64 oldnodeid;
151};
152
153struct fuse_setattr_in {
154 __u32 valid;
155 __u32 padding;
156 struct fuse_attr attr;
157};
158
159struct fuse_open_in {
160 __u32 flags;
161 __u32 padding;
162};
163
164struct fuse_open_out {
165 __u64 fh;
166 __u32 open_flags;
167 __u32 padding;
168};
169
170struct fuse_release_in {
171 __u64 fh;
172 __u32 flags;
173 __u32 padding;
174};
175
176struct fuse_flush_in {
177 __u64 fh;
178 __u32 flush_flags;
179 __u32 padding;
180};
181
182struct fuse_read_in {
183 __u64 fh;
184 __u64 offset;
185 __u32 size;
186 __u32 padding;
187};
188
189struct fuse_write_in {
190 __u64 fh;
191 __u64 offset;
192 __u32 size;
193 __u32 write_flags;
194};
195
196struct fuse_write_out {
197 __u32 size;
198 __u32 padding;
199};
200
201struct fuse_statfs_out {
202 struct fuse_kstatfs st;
203};
204
205struct fuse_fsync_in {
206 __u64 fh;
207 __u32 fsync_flags;
208 __u32 padding;
209};
210
211struct fuse_setxattr_in {
212 __u32 size;
213 __u32 flags;
214};
215
216struct fuse_getxattr_in {
217 __u32 size;
218 __u32 padding;
219};
220
221struct fuse_getxattr_out {
222 __u32 size;
223 __u32 padding;
224};
225
226struct fuse_init_in_out {
227 __u32 major;
228 __u32 minor;
229};
230
231struct fuse_in_header {
232 __u32 len;
233 __u32 opcode;
234 __u64 unique;
235 __u64 nodeid;
236 __u32 uid;
237 __u32 gid;
238 __u32 pid;
239 __u32 padding;
240};
241
242struct fuse_out_header {
243 __u32 len;
244 __s32 error;
245 __u64 unique;
246};
247
248struct fuse_dirent {
249 __u64 ino;
250 __u64 off;
251 __u32 namelen;
252 __u32 type;
253 char name[0];
254};
255
256#define FUSE_NAME_OFFSET ((unsigned) ((struct fuse_dirent *) 0)->name)
257#define FUSE_DIRENT_ALIGN(x) (((x) + sizeof(__u64) - 1) & ~(sizeof(__u64) - 1))
258#define FUSE_DIRENT_SIZE(d) \
259 FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + (d)->namelen)
diff --git a/include/linux/in6.h b/include/linux/in6.h
index bd32b79d62..304aaedea3 100644
--- a/include/linux/in6.h
+++ b/include/linux/in6.h
@@ -198,27 +198,43 @@ struct in6_flowlabel_req
198 * MCAST_MSFILTER 48 198 * MCAST_MSFILTER 48
199 */ 199 */
200 200
201/* RFC3542 advanced socket options (50-67) */ 201/*
202#define IPV6_RECVPKTINFO 50 202 * Advanced API (RFC3542) (1)
203#define IPV6_PKTINFO 51 203 *
204#if 0 204 * Note: IPV6_RECVRTHDRDSTOPTS does not exist. see net/ipv6/datagram.c.
205#define IPV6_RECVPATHMTU 52 205 */
206#define IPV6_PATHMTU 53 206
207#define IPV6_DONTFRAG 54 207#define IPV6_RECVPKTINFO 49
208#define IPV6_USE_MIN_MTU 55 208#define IPV6_PKTINFO 50
209#endif 209#define IPV6_RECVHOPLIMIT 51
210#define IPV6_RECVHOPOPTS 56 210#define IPV6_HOPLIMIT 52
211#define IPV6_HOPOPTS 57 211#define IPV6_RECVHOPOPTS 53
212#if 0 212#define IPV6_HOPOPTS 54
213#define IPV6_RECVRTHDRDSTOPTS 58 /* Unused, see net/ipv6/datagram.c */ 213#define IPV6_RTHDRDSTOPTS 55
214#define IPV6_RECVRTHDR 56
215#define IPV6_RTHDR 57
216#define IPV6_RECVDSTOPTS 58
217#define IPV6_DSTOPTS 59
218#if 0 /* not yet */
219#define IPV6_RECVPATHMTU 60
220#define IPV6_PATHMTU 61
221#define IPV6_DONTFRAG 62
222#define IPV6_USE_MIN_MTU 63
214#endif 223#endif
215#define IPV6_RTHDRDSTOPTS 59 224
216#define IPV6_RECVRTHDR 60 225/*
217#define IPV6_RTHDR 61 226 * Netfilter
218#define IPV6_RECVDSTOPTS 62 227 *
219#define IPV6_DSTOPTS 63 228 * Following socket options are used in ip6_tables;
220#define IPV6_RECVHOPLIMIT 64 229 * see include/linux/netfilter_ipv6/ip6_tables.h.
221#define IPV6_HOPLIMIT 65 230 *
231 * IP6T_SO_SET_REPLACE / IP6T_SO_GET_INFO 64
232 * IP6T_SO_SET_ADD_COUNTERS / IP6T_SO_GET_ENTRIES 65
233 */
234
235/*
236 * Advanced API (RFC3542) (2)
237 */
222#define IPV6_RECVTCLASS 66 238#define IPV6_RECVTCLASS 66
223#define IPV6_TCLASS 67 239#define IPV6_TCLASS 67
224 240
diff --git a/include/linux/init_task.h b/include/linux/init_task.h
index c727c195a9..68ab5f2ab9 100644
--- a/include/linux/init_task.h
+++ b/include/linux/init_task.h
@@ -2,17 +2,27 @@
2#define _LINUX__INIT_TASK_H 2#define _LINUX__INIT_TASK_H
3 3
4#include <linux/file.h> 4#include <linux/file.h>
5#include <linux/rcupdate.h>
5 6
6#define INIT_FILES \ 7#define INIT_FDTABLE \
7{ \ 8{ \
8 .count = ATOMIC_INIT(1), \
9 .file_lock = SPIN_LOCK_UNLOCKED, \
10 .max_fds = NR_OPEN_DEFAULT, \ 9 .max_fds = NR_OPEN_DEFAULT, \
11 .max_fdset = __FD_SETSIZE, \ 10 .max_fdset = __FD_SETSIZE, \
12 .next_fd = 0, \ 11 .next_fd = 0, \
13 .fd = &init_files.fd_array[0], \ 12 .fd = &init_files.fd_array[0], \
14 .close_on_exec = &init_files.close_on_exec_init, \ 13 .close_on_exec = &init_files.close_on_exec_init, \
15 .open_fds = &init_files.open_fds_init, \ 14 .open_fds = &init_files.open_fds_init, \
15 .rcu = RCU_HEAD_INIT, \
16 .free_files = NULL, \
17 .next = NULL, \
18}
19
20#define INIT_FILES \
21{ \
22 .count = ATOMIC_INIT(1), \
23 .file_lock = SPIN_LOCK_UNLOCKED, \
24 .fdt = &init_files.fdtab, \
25 .fdtab = INIT_FDTABLE, \
16 .close_on_exec_init = { { 0, } }, \ 26 .close_on_exec_init = { { 0, } }, \
17 .open_fds_init = { { 0, } }, \ 27 .open_fds_init = { { 0, } }, \
18 .fd_array = { NULL, } \ 28 .fd_array = { NULL, } \
diff --git a/include/linux/input.h b/include/linux/input.h
index 4767e54295..e8c296ff62 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -289,6 +289,8 @@ struct input_absinfo {
289#define KEY_SCROLLDOWN 178 289#define KEY_SCROLLDOWN 178
290#define KEY_KPLEFTPAREN 179 290#define KEY_KPLEFTPAREN 179
291#define KEY_KPRIGHTPAREN 180 291#define KEY_KPRIGHTPAREN 180
292#define KEY_NEW 181
293#define KEY_REDO 182
292 294
293#define KEY_F13 183 295#define KEY_F13 183
294#define KEY_F14 184 296#define KEY_F14 184
@@ -335,6 +337,12 @@ struct input_absinfo {
335#define KEY_KBDILLUMDOWN 229 337#define KEY_KBDILLUMDOWN 229
336#define KEY_KBDILLUMUP 230 338#define KEY_KBDILLUMUP 230
337 339
340#define KEY_SEND 231
341#define KEY_REPLY 232
342#define KEY_FORWARDMAIL 233
343#define KEY_SAVE 234
344#define KEY_DOCUMENTS 235
345
338#define KEY_UNKNOWN 240 346#define KEY_UNKNOWN 240
339 347
340#define BTN_MISC 0x100 348#define BTN_MISC 0x100
diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index d99e7aeb7d..0a90205184 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -57,6 +57,11 @@ extern void disable_irq(unsigned int irq);
57extern void enable_irq(unsigned int irq); 57extern void enable_irq(unsigned int irq);
58#endif 58#endif
59 59
60#ifndef __ARCH_SET_SOFTIRQ_PENDING
61#define set_softirq_pending(x) (local_softirq_pending() = (x))
62#define or_softirq_pending(x) (local_softirq_pending() |= (x))
63#endif
64
60/* 65/*
61 * Temporary defines for UP kernels, until all code gets fixed. 66 * Temporary defines for UP kernels, until all code gets fixed.
62 */ 67 */
@@ -123,7 +128,7 @@ struct softirq_action
123asmlinkage void do_softirq(void); 128asmlinkage void do_softirq(void);
124extern void open_softirq(int nr, void (*action)(struct softirq_action*), void *data); 129extern void open_softirq(int nr, void (*action)(struct softirq_action*), void *data);
125extern void softirq_init(void); 130extern void softirq_init(void);
126#define __raise_softirq_irqoff(nr) do { local_softirq_pending() |= 1UL << (nr); } while (0) 131#define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
127extern void FASTCALL(raise_softirq_irqoff(unsigned int nr)); 132extern void FASTCALL(raise_softirq_irqoff(unsigned int nr));
128extern void FASTCALL(raise_softirq(unsigned int nr)); 133extern void FASTCALL(raise_softirq(unsigned int nr));
129 134
diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h
index 6c5f7b39a4..bb6f88e140 100644
--- a/include/linux/ipv6.h
+++ b/include/linux/ipv6.h
@@ -68,7 +68,7 @@ struct ipv6_opt_hdr {
68 68
69struct rt0_hdr { 69struct rt0_hdr {
70 struct ipv6_rt_hdr rt_hdr; 70 struct ipv6_rt_hdr rt_hdr;
71 __u32 bitmap; /* strict/loose bit map */ 71 __u32 reserved;
72 struct in6_addr addr[0]; 72 struct in6_addr addr[0];
73 73
74#define rt0_type rt_hdr.type 74#define rt0_type rt_hdr.type
diff --git a/include/linux/jbd.h b/include/linux/jbd.h
index 84321a4cac..de097269bd 100644
--- a/include/linux/jbd.h
+++ b/include/linux/jbd.h
@@ -28,6 +28,7 @@
28#include <linux/buffer_head.h> 28#include <linux/buffer_head.h>
29#include <linux/journal-head.h> 29#include <linux/journal-head.h>
30#include <linux/stddef.h> 30#include <linux/stddef.h>
31#include <linux/bit_spinlock.h>
31#include <asm/semaphore.h> 32#include <asm/semaphore.h>
32#endif 33#endif
33 34
diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
index d7a2555a88..6acfdbba73 100644
--- a/include/linux/jiffies.h
+++ b/include/linux/jiffies.h
@@ -254,23 +254,23 @@ static inline u64 get_jiffies_64(void)
254 */ 254 */
255static inline unsigned int jiffies_to_msecs(const unsigned long j) 255static inline unsigned int jiffies_to_msecs(const unsigned long j)
256{ 256{
257#if HZ <= 1000 && !(1000 % HZ) 257#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
258 return (1000 / HZ) * j; 258 return (MSEC_PER_SEC / HZ) * j;
259#elif HZ > 1000 && !(HZ % 1000) 259#elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
260 return (j + (HZ / 1000) - 1)/(HZ / 1000); 260 return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC);
261#else 261#else
262 return (j * 1000) / HZ; 262 return (j * MSEC_PER_SEC) / HZ;
263#endif 263#endif
264} 264}
265 265
266static inline unsigned int jiffies_to_usecs(const unsigned long j) 266static inline unsigned int jiffies_to_usecs(const unsigned long j)
267{ 267{
268#if HZ <= 1000000 && !(1000000 % HZ) 268#if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
269 return (1000000 / HZ) * j; 269 return (USEC_PER_SEC / HZ) * j;
270#elif HZ > 1000000 && !(HZ % 1000000) 270#elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)
271 return (j + (HZ / 1000000) - 1)/(HZ / 1000000); 271 return (j + (HZ / USEC_PER_SEC) - 1)/(HZ / USEC_PER_SEC);
272#else 272#else
273 return (j * 1000000) / HZ; 273 return (j * USEC_PER_SEC) / HZ;
274#endif 274#endif
275} 275}
276 276
@@ -278,12 +278,12 @@ static inline unsigned long msecs_to_jiffies(const unsigned int m)
278{ 278{
279 if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET)) 279 if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
280 return MAX_JIFFY_OFFSET; 280 return MAX_JIFFY_OFFSET;
281#if HZ <= 1000 && !(1000 % HZ) 281#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
282 return (m + (1000 / HZ) - 1) / (1000 / HZ); 282 return (m + (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ);
283#elif HZ > 1000 && !(HZ % 1000) 283#elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
284 return m * (HZ / 1000); 284 return m * (HZ / MSEC_PER_SEC);
285#else 285#else
286 return (m * HZ + 999) / 1000; 286 return (m * HZ + MSEC_PER_SEC - 1) / MSEC_PER_SEC;
287#endif 287#endif
288} 288}
289 289
@@ -291,12 +291,12 @@ static inline unsigned long usecs_to_jiffies(const unsigned int u)
291{ 291{
292 if (u > jiffies_to_usecs(MAX_JIFFY_OFFSET)) 292 if (u > jiffies_to_usecs(MAX_JIFFY_OFFSET))
293 return MAX_JIFFY_OFFSET; 293 return MAX_JIFFY_OFFSET;
294#if HZ <= 1000000 && !(1000000 % HZ) 294#if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
295 return (u + (1000000 / HZ) - 1) / (1000000 / HZ); 295 return (u + (USEC_PER_SEC / HZ) - 1) / (USEC_PER_SEC / HZ);
296#elif HZ > 1000000 && !(HZ % 1000000) 296#elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)
297 return u * (HZ / 1000000); 297 return u * (HZ / USEC_PER_SEC);
298#else 298#else
299 return (u * HZ + 999999) / 1000000; 299 return (u * HZ + USEC_PER_SEC - 1) / USEC_PER_SEC;
300#endif 300#endif
301} 301}
302 302
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 6caaba0af4..7349058ed7 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -315,8 +315,11 @@ static inline struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, void *s
315 pci_bus_add_devices(root_bus); 315 pci_bus_add_devices(root_bus);
316 return root_bus; 316 return root_bus;
317} 317}
318struct pci_bus *pci_create_bus(struct device *parent, int bus, struct pci_ops *ops, void *sysdata);
319struct pci_bus * pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int busnr);
318int pci_scan_slot(struct pci_bus *bus, int devfn); 320int pci_scan_slot(struct pci_bus *bus, int devfn);
319struct pci_dev * pci_scan_single_device(struct pci_bus *bus, int devfn); 321struct pci_dev * pci_scan_single_device(struct pci_bus *bus, int devfn);
322void pci_device_add(struct pci_dev *dev, struct pci_bus *bus);
320unsigned int pci_scan_child_bus(struct pci_bus *bus); 323unsigned int pci_scan_child_bus(struct pci_bus *bus);
321void pci_bus_add_device(struct pci_dev *dev); 324void pci_bus_add_device(struct pci_dev *dev);
322void pci_read_bridge_bases(struct pci_bus *child); 325void pci_read_bridge_bases(struct pci_bus *child);
@@ -326,6 +329,7 @@ extern struct pci_dev *pci_dev_get(struct pci_dev *dev);
326extern void pci_dev_put(struct pci_dev *dev); 329extern void pci_dev_put(struct pci_dev *dev);
327extern void pci_remove_bus(struct pci_bus *b); 330extern void pci_remove_bus(struct pci_bus *b);
328extern void pci_remove_bus_device(struct pci_dev *dev); 331extern void pci_remove_bus_device(struct pci_dev *dev);
332void pci_setup_cardbus(struct pci_bus *bus);
329 333
330/* Generic PCI functions exported to card drivers */ 334/* Generic PCI functions exported to card drivers */
331 335
@@ -391,8 +395,8 @@ int pci_assign_resource(struct pci_dev *dev, int i);
391void pci_restore_bars(struct pci_dev *dev); 395void pci_restore_bars(struct pci_dev *dev);
392 396
393/* ROM control related routines */ 397/* ROM control related routines */
394void __iomem *pci_map_rom(struct pci_dev *pdev, size_t *size); 398void __iomem __must_check *pci_map_rom(struct pci_dev *pdev, size_t *size);
395void __iomem *pci_map_rom_copy(struct pci_dev *pdev, size_t *size); 399void __iomem __must_check *pci_map_rom_copy(struct pci_dev *pdev, size_t *size);
396void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom); 400void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom);
397void pci_remove_rom(struct pci_dev *pdev); 401void pci_remove_rom(struct pci_dev *pdev);
398 402
diff --git a/include/linux/radix-tree.h b/include/linux/radix-tree.h
index 8081a281fa..9c51917b1c 100644
--- a/include/linux/radix-tree.h
+++ b/include/linux/radix-tree.h
@@ -24,7 +24,7 @@
24 24
25struct radix_tree_root { 25struct radix_tree_root {
26 unsigned int height; 26 unsigned int height;
27 int gfp_mask; 27 unsigned int gfp_mask;
28 struct radix_tree_node *rnode; 28 struct radix_tree_node *rnode;
29}; 29};
30 30
@@ -50,7 +50,7 @@ void *radix_tree_delete(struct radix_tree_root *, unsigned long);
50unsigned int 50unsigned int
51radix_tree_gang_lookup(struct radix_tree_root *root, void **results, 51radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
52 unsigned long first_index, unsigned int max_items); 52 unsigned long first_index, unsigned int max_items);
53int radix_tree_preload(int gfp_mask); 53int radix_tree_preload(unsigned int __nocast gfp_mask);
54void radix_tree_init(void); 54void radix_tree_init(void);
55void *radix_tree_tag_set(struct radix_tree_root *root, 55void *radix_tree_tag_set(struct radix_tree_root *root,
56 unsigned long index, int tag); 56 unsigned long index, int tag);
diff --git a/include/linux/raid/bitmap.h b/include/linux/raid/bitmap.h
index 4bf1659f8a..9de99198ca 100644
--- a/include/linux/raid/bitmap.h
+++ b/include/linux/raid/bitmap.h
@@ -7,7 +7,7 @@
7#define BITMAP_H 1 7#define BITMAP_H 1
8 8
9#define BITMAP_MAJOR 3 9#define BITMAP_MAJOR 3
10#define BITMAP_MINOR 38 10#define BITMAP_MINOR 39
11 11
12/* 12/*
13 * in-memory bitmap: 13 * in-memory bitmap:
@@ -147,8 +147,9 @@ typedef struct bitmap_super_s {
147 __u32 state; /* 48 bitmap state information */ 147 __u32 state; /* 48 bitmap state information */
148 __u32 chunksize; /* 52 the bitmap chunk size in bytes */ 148 __u32 chunksize; /* 52 the bitmap chunk size in bytes */
149 __u32 daemon_sleep; /* 56 seconds between disk flushes */ 149 __u32 daemon_sleep; /* 56 seconds between disk flushes */
150 __u32 write_behind; /* 60 number of outstanding write-behind writes */
150 151
151 __u8 pad[256 - 60]; /* set to zero */ 152 __u8 pad[256 - 64]; /* set to zero */
152} bitmap_super_t; 153} bitmap_super_t;
153 154
154/* notes: 155/* notes:
@@ -226,6 +227,9 @@ struct bitmap {
226 227
227 unsigned long flags; 228 unsigned long flags;
228 229
230 unsigned long max_write_behind; /* write-behind mode */
231 atomic_t behind_writes;
232
229 /* 233 /*
230 * the bitmap daemon - periodically wakes up and sweeps the bitmap 234 * the bitmap daemon - periodically wakes up and sweeps the bitmap
231 * file, cleaning up bits and flushing out pages to disk as necessary 235 * file, cleaning up bits and flushing out pages to disk as necessary
@@ -260,9 +264,10 @@ int bitmap_setallbits(struct bitmap *bitmap);
260void bitmap_write_all(struct bitmap *bitmap); 264void bitmap_write_all(struct bitmap *bitmap);
261 265
262/* these are exported */ 266/* these are exported */
263int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors); 267int bitmap_startwrite(struct bitmap *bitmap, sector_t offset,
264void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, 268 unsigned long sectors, int behind);
265 int success); 269void bitmap_endwrite(struct bitmap *bitmap, sector_t offset,
270 unsigned long sectors, int success, int behind);
266int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int degraded); 271int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int degraded);
267void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int aborted); 272void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int aborted);
268void bitmap_close_sync(struct bitmap *bitmap); 273void bitmap_close_sync(struct bitmap *bitmap);
diff --git a/include/linux/raid/linear.h b/include/linux/raid/linear.h
index e04c4fe45b..7eaf290e10 100644
--- a/include/linux/raid/linear.h
+++ b/include/linux/raid/linear.h
@@ -14,8 +14,8 @@ typedef struct dev_info dev_info_t;
14struct linear_private_data 14struct linear_private_data
15{ 15{
16 dev_info_t **hash_table; 16 dev_info_t **hash_table;
17 dev_info_t *smallest; 17 sector_t hash_spacing;
18 int nr_zones; 18 int preshift; /* shift before dividing by hash_spacing */
19 dev_info_t disks[0]; 19 dev_info_t disks[0];
20}; 20};
21 21
diff --git a/include/linux/raid/md_k.h b/include/linux/raid/md_k.h
index 8c14ba565a..ebce949b14 100644
--- a/include/linux/raid/md_k.h
+++ b/include/linux/raid/md_k.h
@@ -86,70 +86,6 @@ typedef struct mdk_rdev_s mdk_rdev_t;
86#define MAX_CHUNK_SIZE (4096*1024) 86#define MAX_CHUNK_SIZE (4096*1024)
87 87
88/* 88/*
89 * default readahead
90 */
91
92static inline int disk_faulty(mdp_disk_t * d)
93{
94 return d->state & (1 << MD_DISK_FAULTY);
95}
96
97static inline int disk_active(mdp_disk_t * d)
98{
99 return d->state & (1 << MD_DISK_ACTIVE);
100}
101
102static inline int disk_sync(mdp_disk_t * d)
103{
104 return d->state & (1 << MD_DISK_SYNC);
105}
106
107static inline int disk_spare(mdp_disk_t * d)
108{
109 return !disk_sync(d) && !disk_active(d) && !disk_faulty(d);
110}
111
112static inline int disk_removed(mdp_disk_t * d)
113{
114 return d->state & (1 << MD_DISK_REMOVED);
115}
116
117static inline void mark_disk_faulty(mdp_disk_t * d)
118{
119 d->state |= (1 << MD_DISK_FAULTY);
120}
121
122static inline void mark_disk_active(mdp_disk_t * d)
123{
124 d->state |= (1 << MD_DISK_ACTIVE);
125}
126
127static inline void mark_disk_sync(mdp_disk_t * d)
128{
129 d->state |= (1 << MD_DISK_SYNC);
130}
131
132static inline void mark_disk_spare(mdp_disk_t * d)
133{
134 d->state = 0;
135}
136
137static inline void mark_disk_removed(mdp_disk_t * d)
138{
139 d->state = (1 << MD_DISK_FAULTY) | (1 << MD_DISK_REMOVED);
140}
141
142static inline void mark_disk_inactive(mdp_disk_t * d)
143{
144 d->state &= ~(1 << MD_DISK_ACTIVE);
145}
146
147static inline void mark_disk_nonsync(mdp_disk_t * d)
148{
149 d->state &= ~(1 << MD_DISK_SYNC);
150}
151
152/*
153 * MD's 'extended' device 89 * MD's 'extended' device
154 */ 90 */
155struct mdk_rdev_s 91struct mdk_rdev_s
@@ -166,6 +102,7 @@ struct mdk_rdev_s
166 int sb_loaded; 102 int sb_loaded;
167 sector_t data_offset; /* start of data in array */ 103 sector_t data_offset; /* start of data in array */
168 sector_t sb_offset; 104 sector_t sb_offset;
105 int sb_size; /* bytes in the superblock */
169 int preferred_minor; /* autorun support */ 106 int preferred_minor; /* autorun support */
170 107
171 /* A device can be in one of three states based on two flags: 108 /* A device can be in one of three states based on two flags:
@@ -181,6 +118,9 @@ struct mdk_rdev_s
181 int faulty; /* if faulty do not issue IO requests */ 118 int faulty; /* if faulty do not issue IO requests */
182 int in_sync; /* device is a full member of the array */ 119 int in_sync; /* device is a full member of the array */
183 120
121 unsigned long flags; /* Should include faulty and in_sync here. */
122#define WriteMostly 4 /* Avoid reading if at all possible */
123
184 int desc_nr; /* descriptor index in the superblock */ 124 int desc_nr; /* descriptor index in the superblock */
185 int raid_disk; /* role of device in array */ 125 int raid_disk; /* role of device in array */
186 int saved_raid_disk; /* role that device used to have in the 126 int saved_raid_disk; /* role that device used to have in the
@@ -272,12 +212,19 @@ struct mddev_s
272 atomic_t writes_pending; 212 atomic_t writes_pending;
273 request_queue_t *queue; /* for plugging ... */ 213 request_queue_t *queue; /* for plugging ... */
274 214
215 atomic_t write_behind; /* outstanding async IO */
216 unsigned int max_write_behind; /* 0 = sync */
217
275 struct bitmap *bitmap; /* the bitmap for the device */ 218 struct bitmap *bitmap; /* the bitmap for the device */
276 struct file *bitmap_file; /* the bitmap file */ 219 struct file *bitmap_file; /* the bitmap file */
277 long bitmap_offset; /* offset from superblock of 220 long bitmap_offset; /* offset from superblock of
278 * start of bitmap. May be 221 * start of bitmap. May be
279 * negative, but not '0' 222 * negative, but not '0'
280 */ 223 */
224 long default_bitmap_offset; /* this is the offset to use when
225 * hot-adding a bitmap. It should
226 * eventually be settable by sysfs.
227 */
281 228
282 struct list_head all_mddevs; 229 struct list_head all_mddevs;
283}; 230};
@@ -314,6 +261,12 @@ struct mdk_personality_s
314 int (*resize) (mddev_t *mddev, sector_t sectors); 261 int (*resize) (mddev_t *mddev, sector_t sectors);
315 int (*reshape) (mddev_t *mddev, int raid_disks); 262 int (*reshape) (mddev_t *mddev, int raid_disks);
316 int (*reconfig) (mddev_t *mddev, int layout, int chunk_size); 263 int (*reconfig) (mddev_t *mddev, int layout, int chunk_size);
264 /* quiesce moves between quiescence states
265 * 0 - fully active
266 * 1 - no new requests allowed
267 * others - reserved
268 */
269 void (*quiesce) (mddev_t *mddev, int state);
317}; 270};
318 271
319 272
diff --git a/include/linux/raid/md_p.h b/include/linux/raid/md_p.h
index dc65cd4354..c100fa5d4b 100644
--- a/include/linux/raid/md_p.h
+++ b/include/linux/raid/md_p.h
@@ -79,6 +79,11 @@
79#define MD_DISK_SYNC 2 /* disk is in sync with the raid set */ 79#define MD_DISK_SYNC 2 /* disk is in sync with the raid set */
80#define MD_DISK_REMOVED 3 /* disk is in sync with the raid set */ 80#define MD_DISK_REMOVED 3 /* disk is in sync with the raid set */
81 81
82#define MD_DISK_WRITEMOSTLY 9 /* disk is "write-mostly" is RAID1 config.
83 * read requests will only be sent here in
84 * dire need
85 */
86
82typedef struct mdp_device_descriptor_s { 87typedef struct mdp_device_descriptor_s {
83 __u32 number; /* 0 Device number in the entire set */ 88 __u32 number; /* 0 Device number in the entire set */
84 __u32 major; /* 1 Device major number */ 89 __u32 major; /* 1 Device major number */
@@ -193,7 +198,7 @@ struct mdp_superblock_1 {
193 198
194 __u64 ctime; /* lo 40 bits are seconds, top 24 are microseconds or 0*/ 199 __u64 ctime; /* lo 40 bits are seconds, top 24 are microseconds or 0*/
195 __u32 level; /* -4 (multipath), -1 (linear), 0,1,4,5 */ 200 __u32 level; /* -4 (multipath), -1 (linear), 0,1,4,5 */
196 __u32 layout; /* only for raid5 currently */ 201 __u32 layout; /* only for raid5 and raid10 currently */
197 __u64 size; /* used size of component devices, in 512byte sectors */ 202 __u64 size; /* used size of component devices, in 512byte sectors */
198 203
199 __u32 chunksize; /* in 512byte sectors */ 204 __u32 chunksize; /* in 512byte sectors */
@@ -212,7 +217,9 @@ struct mdp_superblock_1 {
212 __u32 dev_number; /* permanent identifier of this device - not role in raid */ 217 __u32 dev_number; /* permanent identifier of this device - not role in raid */
213 __u32 cnt_corrected_read; /* number of read errors that were corrected by re-writing */ 218 __u32 cnt_corrected_read; /* number of read errors that were corrected by re-writing */
214 __u8 device_uuid[16]; /* user-space setable, ignored by kernel */ 219 __u8 device_uuid[16]; /* user-space setable, ignored by kernel */
215 __u8 pad2[64-56]; /* set to 0 when writing */ 220 __u8 devflags; /* per-device flags. Only one defined...*/
221#define WriteMostly1 1 /* mask for writemostly flag in above */
222 __u8 pad2[64-57]; /* set to 0 when writing */
216 223
217 /* array state information - 64 bytes */ 224 /* array state information - 64 bytes */
218 __u64 utime; /* 40 bits second, 24 btes microseconds */ 225 __u64 utime; /* 40 bits second, 24 btes microseconds */
@@ -231,5 +238,10 @@ struct mdp_superblock_1 {
231 __u16 dev_roles[0]; /* role in array, or 0xffff for a spare, or 0xfffe for faulty */ 238 __u16 dev_roles[0]; /* role in array, or 0xffff for a spare, or 0xfffe for faulty */
232}; 239};
233 240
241/* feature_map bits */
242#define MD_FEATURE_BITMAP_OFFSET 1
243
244#define MD_FEATURE_ALL 1
245
234#endif 246#endif
235 247
diff --git a/include/linux/raid/raid1.h b/include/linux/raid/raid1.h
index 9d93cf12e8..60e19b6675 100644
--- a/include/linux/raid/raid1.h
+++ b/include/linux/raid/raid1.h
@@ -80,6 +80,9 @@ struct r1bio_s {
80 atomic_t remaining; /* 'have we finished' count, 80 atomic_t remaining; /* 'have we finished' count,
81 * used from IRQ handlers 81 * used from IRQ handlers
82 */ 82 */
83 atomic_t behind_remaining; /* number of write-behind ios remaining
84 * in this BehindIO request
85 */
83 sector_t sector; 86 sector_t sector;
84 int sectors; 87 int sectors;
85 unsigned long state; 88 unsigned long state;
@@ -107,4 +110,14 @@ struct r1bio_s {
107#define R1BIO_Uptodate 0 110#define R1BIO_Uptodate 0
108#define R1BIO_IsSync 1 111#define R1BIO_IsSync 1
109#define R1BIO_Degraded 2 112#define R1BIO_Degraded 2
113#define R1BIO_BehindIO 3
114/* For write-behind requests, we call bi_end_io when
115 * the last non-write-behind device completes, providing
116 * any write was successful. Otherwise we call when
117 * any write-behind write succeeds, otherwise we call
118 * with failure when last write completes (and all failed).
119 * Record that bi_end_io was called with this flag...
120 */
121#define R1BIO_Returned 4
122
110#endif 123#endif
diff --git a/include/linux/raid/raid5.h b/include/linux/raid/raid5.h
index d63ddcb4af..176fc653c2 100644
--- a/include/linux/raid/raid5.h
+++ b/include/linux/raid/raid5.h
@@ -134,6 +134,7 @@ struct stripe_head {
134 unsigned long state; /* state flags */ 134 unsigned long state; /* state flags */
135 atomic_t count; /* nr of active thread/requests */ 135 atomic_t count; /* nr of active thread/requests */
136 spinlock_t lock; 136 spinlock_t lock;
137 int bm_seq; /* sequence number for bitmap flushes */
137 struct r5dev { 138 struct r5dev {
138 struct bio req; 139 struct bio req;
139 struct bio_vec vec; 140 struct bio_vec vec;
@@ -165,12 +166,13 @@ struct stripe_head {
165/* 166/*
166 * Stripe state 167 * Stripe state
167 */ 168 */
168#define STRIPE_ERROR 1
169#define STRIPE_HANDLE 2 169#define STRIPE_HANDLE 2
170#define STRIPE_SYNCING 3 170#define STRIPE_SYNCING 3
171#define STRIPE_INSYNC 4 171#define STRIPE_INSYNC 4
172#define STRIPE_PREREAD_ACTIVE 5 172#define STRIPE_PREREAD_ACTIVE 5
173#define STRIPE_DELAYED 6 173#define STRIPE_DELAYED 6
174#define STRIPE_DEGRADED 7
175#define STRIPE_BIT_DELAY 8
174 176
175/* 177/*
176 * Plugging: 178 * Plugging:
@@ -210,10 +212,20 @@ struct raid5_private_data {
210 212
211 struct list_head handle_list; /* stripes needing handling */ 213 struct list_head handle_list; /* stripes needing handling */
212 struct list_head delayed_list; /* stripes that have plugged requests */ 214 struct list_head delayed_list; /* stripes that have plugged requests */
215 struct list_head bitmap_list; /* stripes delaying awaiting bitmap update */
213 atomic_t preread_active_stripes; /* stripes with scheduled io */ 216 atomic_t preread_active_stripes; /* stripes with scheduled io */
214 217
215 char cache_name[20]; 218 char cache_name[20];
216 kmem_cache_t *slab_cache; /* for allocating stripes */ 219 kmem_cache_t *slab_cache; /* for allocating stripes */
220
221 int seq_flush, seq_write;
222 int quiesce;
223
224 int fullsync; /* set to 1 if a full sync is needed,
225 * (fresh device added).
226 * Cleared when a sync completes.
227 */
228
217 /* 229 /*
218 * Free stripes pool 230 * Free stripes pool
219 */ 231 */
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index fd276adf0f..4e65eb44ad 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -52,8 +52,8 @@ struct rcu_head {
52 void (*func)(struct rcu_head *head); 52 void (*func)(struct rcu_head *head);
53}; 53};
54 54
55#define RCU_HEAD_INIT(head) { .next = NULL, .func = NULL } 55#define RCU_HEAD_INIT { .next = NULL, .func = NULL }
56#define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT(head) 56#define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
57#define INIT_RCU_HEAD(ptr) do { \ 57#define INIT_RCU_HEAD(ptr) do { \
58 (ptr)->next = NULL; (ptr)->func = NULL; \ 58 (ptr)->next = NULL; (ptr)->func = NULL; \
59} while (0) 59} while (0)
diff --git a/include/linux/rcuref.h b/include/linux/rcuref.h
new file mode 100644
index 0000000000..e1adbba14b
--- /dev/null
+++ b/include/linux/rcuref.h
@@ -0,0 +1,220 @@
1/*
2 * rcuref.h
3 *
4 * Reference counting for elements of lists/arrays protected by
5 * RCU.
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 * Copyright (C) IBM Corporation, 2005
22 *
23 * Author: Dipankar Sarma <dipankar@in.ibm.com>
24 * Ravikiran Thirumalai <kiran_th@gmail.com>
25 *
26 * See Documentation/RCU/rcuref.txt for detailed user guide.
27 *
28 */
29
30#ifndef _RCUREF_H_
31#define _RCUREF_H_
32
33#ifdef __KERNEL__
34
35#include <linux/types.h>
36#include <linux/interrupt.h>
37#include <linux/spinlock.h>
38#include <asm/atomic.h>
39
40/*
41 * These APIs work on traditional atomic_t counters used in the
42 * kernel for reference counting. Under special circumstances
43 * where a lock-free get() operation races with a put() operation
44 * these APIs can be used. See Documentation/RCU/rcuref.txt.
45 */
46
47#ifdef __HAVE_ARCH_CMPXCHG
48
49/**
50 * rcuref_inc - increment refcount for object.
51 * @rcuref: reference counter in the object in question.
52 *
53 * This should be used only for objects where we use RCU and
54 * use the rcuref_inc_lf() api to acquire a reference
55 * in a lock-free reader-side critical section.
56 */
57static inline void rcuref_inc(atomic_t *rcuref)
58{
59 atomic_inc(rcuref);
60}
61
62/**
63 * rcuref_dec - decrement refcount for object.
64 * @rcuref: reference counter in the object in question.
65 *
66 * This should be used only for objects where we use RCU and
67 * use the rcuref_inc_lf() api to acquire a reference
68 * in a lock-free reader-side critical section.
69 */
70static inline void rcuref_dec(atomic_t *rcuref)
71{
72 atomic_dec(rcuref);
73}
74
75/**
76 * rcuref_dec_and_test - decrement refcount for object and test
77 * @rcuref: reference counter in the object.
78 * @release: pointer to the function that will clean up the object
79 * when the last reference to the object is released.
80 * This pointer is required.
81 *
82 * Decrement the refcount, and if 0, return 1. Else return 0.
83 *
84 * This should be used only for objects where we use RCU and
85 * use the rcuref_inc_lf() api to acquire a reference
86 * in a lock-free reader-side critical section.
87 */
88static inline int rcuref_dec_and_test(atomic_t *rcuref)
89{
90 return atomic_dec_and_test(rcuref);
91}
92
93/*
94 * cmpxchg is needed on UP too, if deletions to the list/array can happen
95 * in interrupt context.
96 */
97
98/**
99 * rcuref_inc_lf - Take reference to an object in a read-side
100 * critical section protected by RCU.
101 * @rcuref: reference counter in the object in question.
102 *
103 * Try and increment the refcount by 1. The increment might fail if
104 * the reference counter has been through a 1 to 0 transition and
105 * is no longer part of the lock-free list.
106 * Returns non-zero on successful increment and zero otherwise.
107 */
108static inline int rcuref_inc_lf(atomic_t *rcuref)
109{
110 int c, old;
111 c = atomic_read(rcuref);
112 while (c && (old = cmpxchg(&rcuref->counter, c, c + 1)) != c)
113 c = old;
114 return c;
115}
116
117#else /* !__HAVE_ARCH_CMPXCHG */
118
119extern spinlock_t __rcuref_hash[];
120
121/*
122 * Use a hash table of locks to protect the reference count
123 * since cmpxchg is not available in this arch.
124 */
125#ifdef CONFIG_SMP
126#define RCUREF_HASH_SIZE 4
127#define RCUREF_HASH(k) \
128 (&__rcuref_hash[(((unsigned long)k)>>8) & (RCUREF_HASH_SIZE-1)])
129#else
130#define RCUREF_HASH_SIZE 1
131#define RCUREF_HASH(k) &__rcuref_hash[0]
132#endif /* CONFIG_SMP */
133
134/**
135 * rcuref_inc - increment refcount for object.
136 * @rcuref: reference counter in the object in question.
137 *
138 * This should be used only for objects where we use RCU and
139 * use the rcuref_inc_lf() api to acquire a reference in a lock-free
140 * reader-side critical section.
141 */
142static inline void rcuref_inc(atomic_t *rcuref)
143{
144 unsigned long flags;
145 spin_lock_irqsave(RCUREF_HASH(rcuref), flags);
146 rcuref->counter += 1;
147 spin_unlock_irqrestore(RCUREF_HASH(rcuref), flags);
148}
149
150/**
151 * rcuref_dec - decrement refcount for object.
152 * @rcuref: reference counter in the object in question.
153 *
154 * This should be used only for objects where we use RCU and
155 * use the rcuref_inc_lf() api to acquire a reference in a lock-free
156 * reader-side critical section.
157 */
158static inline void rcuref_dec(atomic_t *rcuref)
159{
160 unsigned long flags;
161 spin_lock_irqsave(RCUREF_HASH(rcuref), flags);
162 rcuref->counter -= 1;
163 spin_unlock_irqrestore(RCUREF_HASH(rcuref), flags);
164}
165
166/**
167 * rcuref_dec_and_test - decrement refcount for object and test
168 * @rcuref: reference counter in the object.
169 * @release: pointer to the function that will clean up the object
170 * when the last reference to the object is released.
171 * This pointer is required.
172 *
173 * Decrement the refcount, and if 0, return 1. Else return 0.
174 *
175 * This should be used only for objects where we use RCU and
176 * use the rcuref_inc_lf() api to acquire a reference in a lock-free
177 * reader-side critical section.
178 */
179static inline int rcuref_dec_and_test(atomic_t *rcuref)
180{
181 unsigned long flags;
182 spin_lock_irqsave(RCUREF_HASH(rcuref), flags);
183 rcuref->counter--;
184 if (!rcuref->counter) {
185 spin_unlock_irqrestore(RCUREF_HASH(rcuref), flags);
186 return 1;
187 } else {
188 spin_unlock_irqrestore(RCUREF_HASH(rcuref), flags);
189 return 0;
190 }
191}
192
193/**
194 * rcuref_inc_lf - Take reference to an object of a lock-free collection
195 * by traversing a lock-free list/array.
196 * @rcuref: reference counter in the object in question.
197 *
198 * Try and increment the refcount by 1. The increment might fail if
199 * the reference counter has been through a 1 to 0 transition and
200 * object is no longer part of the lock-free list.
201 * Returns non-zero on successful increment and zero otherwise.
202 */
203static inline int rcuref_inc_lf(atomic_t *rcuref)
204{
205 int ret;
206 unsigned long flags;
207 spin_lock_irqsave(RCUREF_HASH(rcuref), flags);
208 if (rcuref->counter)
209 ret = rcuref->counter++;
210 else
211 ret = 0;
212 spin_unlock_irqrestore(RCUREF_HASH(rcuref), flags);
213 return ret;
214}
215
216
217#endif /* !__HAVE_ARCH_CMPXCHG */
218
219#endif /* __KERNEL__ */
220#endif /* _RCUREF_H_ */
diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
index 17e458e17e..af00b10294 100644
--- a/include/linux/reiserfs_fs.h
+++ b/include/linux/reiserfs_fs.h
@@ -2097,7 +2097,7 @@ void reiserfs_free_block(struct reiserfs_transaction_handle *th, struct inode *,
2097 b_blocknr_t, int for_unformatted); 2097 b_blocknr_t, int for_unformatted);
2098int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *, b_blocknr_t *, int, 2098int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *, b_blocknr_t *, int,
2099 int); 2099 int);
2100extern inline int reiserfs_new_form_blocknrs(struct tree_balance *tb, 2100static inline int reiserfs_new_form_blocknrs(struct tree_balance *tb,
2101 b_blocknr_t * new_blocknrs, 2101 b_blocknr_t * new_blocknrs,
2102 int amount_needed) 2102 int amount_needed)
2103{ 2103{
@@ -2113,7 +2113,7 @@ extern inline int reiserfs_new_form_blocknrs(struct tree_balance *tb,
2113 0); 2113 0);
2114} 2114}
2115 2115
2116extern inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle 2116static inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle
2117 *th, struct inode *inode, 2117 *th, struct inode *inode,
2118 b_blocknr_t * new_blocknrs, 2118 b_blocknr_t * new_blocknrs,
2119 struct path *path, long block) 2119 struct path *path, long block)
@@ -2130,7 +2130,7 @@ extern inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle
2130} 2130}
2131 2131
2132#ifdef REISERFS_PREALLOCATE 2132#ifdef REISERFS_PREALLOCATE
2133extern inline int reiserfs_new_unf_blocknrs2(struct reiserfs_transaction_handle 2133static inline int reiserfs_new_unf_blocknrs2(struct reiserfs_transaction_handle
2134 *th, struct inode *inode, 2134 *th, struct inode *inode,
2135 b_blocknr_t * new_blocknrs, 2135 b_blocknr_t * new_blocknrs,
2136 struct path *path, long block) 2136 struct path *path, long block)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index ea1b5f32ec..38c8654aaa 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -114,6 +114,7 @@ extern unsigned long nr_iowait(void);
114#define TASK_TRACED 8 114#define TASK_TRACED 8
115#define EXIT_ZOMBIE 16 115#define EXIT_ZOMBIE 16
116#define EXIT_DEAD 32 116#define EXIT_DEAD 32
117#define TASK_NONINTERACTIVE 64
117 118
118#define __set_task_state(tsk, state_value) \ 119#define __set_task_state(tsk, state_value) \
119 do { (tsk)->state = (state_value); } while (0) 120 do { (tsk)->state = (state_value); } while (0)
@@ -202,6 +203,8 @@ extern int in_sched_functions(unsigned long addr);
202 203
203#define MAX_SCHEDULE_TIMEOUT LONG_MAX 204#define MAX_SCHEDULE_TIMEOUT LONG_MAX
204extern signed long FASTCALL(schedule_timeout(signed long timeout)); 205extern signed long FASTCALL(schedule_timeout(signed long timeout));
206extern signed long schedule_timeout_interruptible(signed long timeout);
207extern signed long schedule_timeout_uninterruptible(signed long timeout);
205asmlinkage void schedule(void); 208asmlinkage void schedule(void);
206 209
207struct namespace; 210struct namespace;
@@ -604,6 +607,11 @@ extern int groups_search(struct group_info *group_info, gid_t grp);
604#define GROUP_AT(gi, i) \ 607#define GROUP_AT(gi, i) \
605 ((gi)->blocks[(i)/NGROUPS_PER_BLOCK][(i)%NGROUPS_PER_BLOCK]) 608 ((gi)->blocks[(i)/NGROUPS_PER_BLOCK][(i)%NGROUPS_PER_BLOCK])
606 609
610#ifdef ARCH_HAS_PREFETCH_SWITCH_STACK
611extern void prefetch_stack(struct task_struct*);
612#else
613static inline void prefetch_stack(struct task_struct *t) { }
614#endif
607 615
608struct audit_context; /* See audit.c */ 616struct audit_context; /* See audit.c */
609struct mempolicy; 617struct mempolicy;
@@ -895,6 +903,8 @@ extern int task_curr(const task_t *p);
895extern int idle_cpu(int cpu); 903extern int idle_cpu(int cpu);
896extern int sched_setscheduler(struct task_struct *, int, struct sched_param *); 904extern int sched_setscheduler(struct task_struct *, int, struct sched_param *);
897extern task_t *idle_task(int cpu); 905extern task_t *idle_task(int cpu);
906extern task_t *curr_task(int cpu);
907extern void set_curr_task(int cpu, task_t *p);
898 908
899void yield(void); 909void yield(void);
900 910
diff --git a/include/linux/security.h b/include/linux/security.h
index 7aab6ab7c5..55b02e1c73 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -250,29 +250,37 @@ struct swap_info_struct;
250 * @inode contains the inode structure. 250 * @inode contains the inode structure.
251 * Deallocate the inode security structure and set @inode->i_security to 251 * Deallocate the inode security structure and set @inode->i_security to
252 * NULL. 252 * NULL.
253 * @inode_init_security:
254 * Obtain the security attribute name suffix and value to set on a newly
255 * created inode and set up the incore security field for the new inode.
256 * This hook is called by the fs code as part of the inode creation
257 * transaction and provides for atomic labeling of the inode, unlike
258 * the post_create/mkdir/... hooks called by the VFS. The hook function
259 * is expected to allocate the name and value via kmalloc, with the caller
260 * being responsible for calling kfree after using them.
261 * If the security module does not use security attributes or does
262 * not wish to put a security attribute on this particular inode,
263 * then it should return -EOPNOTSUPP to skip this processing.
264 * @inode contains the inode structure of the newly created inode.
265 * @dir contains the inode structure of the parent directory.
266 * @name will be set to the allocated name suffix (e.g. selinux).
267 * @value will be set to the allocated attribute value.
268 * @len will be set to the length of the value.
269 * Returns 0 if @name and @value have been successfully set,
270 * -EOPNOTSUPP if no security attribute is needed, or
271 * -ENOMEM on memory allocation failure.
253 * @inode_create: 272 * @inode_create:
254 * Check permission to create a regular file. 273 * Check permission to create a regular file.
255 * @dir contains inode structure of the parent of the new file. 274 * @dir contains inode structure of the parent of the new file.
256 * @dentry contains the dentry structure for the file to be created. 275 * @dentry contains the dentry structure for the file to be created.
257 * @mode contains the file mode of the file to be created. 276 * @mode contains the file mode of the file to be created.
258 * Return 0 if permission is granted. 277 * Return 0 if permission is granted.
259 * @inode_post_create:
260 * Set the security attributes on a newly created regular file. This hook
261 * is called after a file has been successfully created.
262 * @dir contains the inode structure of the parent directory of the new file.
263 * @dentry contains the the dentry structure for the newly created file.
264 * @mode contains the file mode.
265 * @inode_link: 278 * @inode_link:
266 * Check permission before creating a new hard link to a file. 279 * Check permission before creating a new hard link to a file.
267 * @old_dentry contains the dentry structure for an existing link to the file. 280 * @old_dentry contains the dentry structure for an existing link to the file.
268 * @dir contains the inode structure of the parent directory of the new link. 281 * @dir contains the inode structure of the parent directory of the new link.
269 * @new_dentry contains the dentry structure for the new link. 282 * @new_dentry contains the dentry structure for the new link.
270 * Return 0 if permission is granted. 283 * Return 0 if permission is granted.
271 * @inode_post_link:
272 * Set security attributes for a new hard link to a file.
273 * @old_dentry contains the dentry structure for the existing link.
274 * @dir contains the inode structure of the parent directory of the new file.
275 * @new_dentry contains the dentry structure for the new file link.
276 * @inode_unlink: 284 * @inode_unlink:
277 * Check the permission to remove a hard link to a file. 285 * Check the permission to remove a hard link to a file.
278 * @dir contains the inode structure of parent directory of the file. 286 * @dir contains the inode structure of parent directory of the file.
@@ -284,13 +292,6 @@ struct swap_info_struct;
284 * @dentry contains the dentry structure of the symbolic link. 292 * @dentry contains the dentry structure of the symbolic link.
285 * @old_name contains the pathname of file. 293 * @old_name contains the pathname of file.
286 * Return 0 if permission is granted. 294 * Return 0 if permission is granted.
287 * @inode_post_symlink:
288 * @dir contains the inode structure of the parent directory of the new link.
289 * @dentry contains the dentry structure of new symbolic link.
290 * @old_name contains the pathname of file.
291 * Set security attributes for a newly created symbolic link. Note that
292 * @dentry->d_inode may be NULL, since the filesystem might not
293 * instantiate the dentry (e.g. NFS).
294 * @inode_mkdir: 295 * @inode_mkdir:
295 * Check permissions to create a new directory in the existing directory 296 * Check permissions to create a new directory in the existing directory
296 * associated with inode strcture @dir. 297 * associated with inode strcture @dir.
@@ -298,11 +299,6 @@ struct swap_info_struct;
298 * @dentry contains the dentry structure of new directory. 299 * @dentry contains the dentry structure of new directory.
299 * @mode contains the mode of new directory. 300 * @mode contains the mode of new directory.
300 * Return 0 if permission is granted. 301 * Return 0 if permission is granted.
301 * @inode_post_mkdir:
302 * Set security attributes on a newly created directory.
303 * @dir contains the inode structure of parent of the directory to be created.
304 * @dentry contains the dentry structure of new directory.
305 * @mode contains the mode of new directory.
306 * @inode_rmdir: 302 * @inode_rmdir:
307 * Check the permission to remove a directory. 303 * Check the permission to remove a directory.
308 * @dir contains the inode structure of parent of the directory to be removed. 304 * @dir contains the inode structure of parent of the directory to be removed.
@@ -318,13 +314,6 @@ struct swap_info_struct;
318 * @mode contains the mode of the new file. 314 * @mode contains the mode of the new file.
319 * @dev contains the the device number. 315 * @dev contains the the device number.
320 * Return 0 if permission is granted. 316 * Return 0 if permission is granted.
321 * @inode_post_mknod:
322 * Set security attributes on a newly created special file (or socket or
323 * fifo file created via the mknod system call).
324 * @dir contains the inode structure of parent of the new node.
325 * @dentry contains the dentry structure of the new node.
326 * @mode contains the mode of the new node.
327 * @dev contains the the device number.
328 * @inode_rename: 317 * @inode_rename:
329 * Check for permission to rename a file or directory. 318 * Check for permission to rename a file or directory.
330 * @old_dir contains the inode structure for parent of the old link. 319 * @old_dir contains the inode structure for parent of the old link.
@@ -332,12 +321,6 @@ struct swap_info_struct;
332 * @new_dir contains the inode structure for parent of the new link. 321 * @new_dir contains the inode structure for parent of the new link.
333 * @new_dentry contains the dentry structure of the new link. 322 * @new_dentry contains the dentry structure of the new link.
334 * Return 0 if permission is granted. 323 * Return 0 if permission is granted.
335 * @inode_post_rename:
336 * Set security attributes on a renamed file or directory.
337 * @old_dir contains the inode structure for parent of the old link.
338 * @old_dentry contains the dentry structure of the old link.
339 * @new_dir contains the inode structure for parent of the new link.
340 * @new_dentry contains the dentry structure of the new link.
341 * @inode_readlink: 324 * @inode_readlink:
342 * Check the permission to read the symbolic link. 325 * Check the permission to read the symbolic link.
343 * @dentry contains the dentry structure for the file link. 326 * @dentry contains the dentry structure for the file link.
@@ -1080,34 +1063,21 @@ struct security_operations {
1080 1063
1081 int (*inode_alloc_security) (struct inode *inode); 1064 int (*inode_alloc_security) (struct inode *inode);
1082 void (*inode_free_security) (struct inode *inode); 1065 void (*inode_free_security) (struct inode *inode);
1066 int (*inode_init_security) (struct inode *inode, struct inode *dir,
1067 char **name, void **value, size_t *len);
1083 int (*inode_create) (struct inode *dir, 1068 int (*inode_create) (struct inode *dir,
1084 struct dentry *dentry, int mode); 1069 struct dentry *dentry, int mode);
1085 void (*inode_post_create) (struct inode *dir,
1086 struct dentry *dentry, int mode);
1087 int (*inode_link) (struct dentry *old_dentry, 1070 int (*inode_link) (struct dentry *old_dentry,
1088 struct inode *dir, struct dentry *new_dentry); 1071 struct inode *dir, struct dentry *new_dentry);
1089 void (*inode_post_link) (struct dentry *old_dentry,
1090 struct inode *dir, struct dentry *new_dentry);
1091 int (*inode_unlink) (struct inode *dir, struct dentry *dentry); 1072 int (*inode_unlink) (struct inode *dir, struct dentry *dentry);
1092 int (*inode_symlink) (struct inode *dir, 1073 int (*inode_symlink) (struct inode *dir,
1093 struct dentry *dentry, const char *old_name); 1074 struct dentry *dentry, const char *old_name);
1094 void (*inode_post_symlink) (struct inode *dir,
1095 struct dentry *dentry,
1096 const char *old_name);
1097 int (*inode_mkdir) (struct inode *dir, struct dentry *dentry, int mode); 1075 int (*inode_mkdir) (struct inode *dir, struct dentry *dentry, int mode);
1098 void (*inode_post_mkdir) (struct inode *dir, struct dentry *dentry,
1099 int mode);
1100 int (*inode_rmdir) (struct inode *dir, struct dentry *dentry); 1076 int (*inode_rmdir) (struct inode *dir, struct dentry *dentry);
1101 int (*inode_mknod) (struct inode *dir, struct dentry *dentry, 1077 int (*inode_mknod) (struct inode *dir, struct dentry *dentry,
1102 int mode, dev_t dev); 1078 int mode, dev_t dev);
1103 void (*inode_post_mknod) (struct inode *dir, struct dentry *dentry,
1104 int mode, dev_t dev);
1105 int (*inode_rename) (struct inode *old_dir, struct dentry *old_dentry, 1079 int (*inode_rename) (struct inode *old_dir, struct dentry *old_dentry,
1106 struct inode *new_dir, struct dentry *new_dentry); 1080 struct inode *new_dir, struct dentry *new_dentry);
1107 void (*inode_post_rename) (struct inode *old_dir,
1108 struct dentry *old_dentry,
1109 struct inode *new_dir,
1110 struct dentry *new_dentry);
1111 int (*inode_readlink) (struct dentry *dentry); 1081 int (*inode_readlink) (struct dentry *dentry);
1112 int (*inode_follow_link) (struct dentry *dentry, struct nameidata *nd); 1082 int (*inode_follow_link) (struct dentry *dentry, struct nameidata *nd);
1113 int (*inode_permission) (struct inode *inode, int mask, struct nameidata *nd); 1083 int (*inode_permission) (struct inode *inode, int mask, struct nameidata *nd);
@@ -1442,6 +1412,17 @@ static inline void security_inode_free (struct inode *inode)
1442 return; 1412 return;
1443 security_ops->inode_free_security (inode); 1413 security_ops->inode_free_security (inode);
1444} 1414}
1415
1416static inline int security_inode_init_security (struct inode *inode,
1417 struct inode *dir,
1418 char **name,
1419 void **value,
1420 size_t *len)
1421{
1422 if (unlikely (IS_PRIVATE (inode)))
1423 return -EOPNOTSUPP;
1424 return security_ops->inode_init_security (inode, dir, name, value, len);
1425}
1445 1426
1446static inline int security_inode_create (struct inode *dir, 1427static inline int security_inode_create (struct inode *dir,
1447 struct dentry *dentry, 1428 struct dentry *dentry,
@@ -1452,15 +1433,6 @@ static inline int security_inode_create (struct inode *dir,
1452 return security_ops->inode_create (dir, dentry, mode); 1433 return security_ops->inode_create (dir, dentry, mode);
1453} 1434}
1454 1435
1455static inline void security_inode_post_create (struct inode *dir,
1456 struct dentry *dentry,
1457 int mode)
1458{
1459 if (dentry->d_inode && unlikely (IS_PRIVATE (dentry->d_inode)))
1460 return;
1461 security_ops->inode_post_create (dir, dentry, mode);
1462}
1463
1464static inline int security_inode_link (struct dentry *old_dentry, 1436static inline int security_inode_link (struct dentry *old_dentry,
1465 struct inode *dir, 1437 struct inode *dir,
1466 struct dentry *new_dentry) 1438 struct dentry *new_dentry)
@@ -1470,15 +1442,6 @@ static inline int security_inode_link (struct dentry *old_dentry,
1470 return security_ops->inode_link (old_dentry, dir, new_dentry); 1442 return security_ops->inode_link (old_dentry, dir, new_dentry);
1471} 1443}
1472 1444
1473static inline void security_inode_post_link (struct dentry *old_dentry,
1474 struct inode *dir,
1475 struct dentry *new_dentry)
1476{
1477 if (new_dentry->d_inode && unlikely (IS_PRIVATE (new_dentry->d_inode)))
1478 return;
1479 security_ops->inode_post_link (old_dentry, dir, new_dentry);
1480}
1481
1482static inline int security_inode_unlink (struct inode *dir, 1445static inline int security_inode_unlink (struct inode *dir,
1483 struct dentry *dentry) 1446 struct dentry *dentry)
1484{ 1447{
@@ -1496,15 +1459,6 @@ static inline int security_inode_symlink (struct inode *dir,
1496 return security_ops->inode_symlink (dir, dentry, old_name); 1459 return security_ops->inode_symlink (dir, dentry, old_name);
1497} 1460}
1498 1461
1499static inline void security_inode_post_symlink (struct inode *dir,
1500 struct dentry *dentry,
1501 const char *old_name)
1502{
1503 if (dentry->d_inode && unlikely (IS_PRIVATE (dentry->d_inode)))
1504 return;
1505 security_ops->inode_post_symlink (dir, dentry, old_name);
1506}
1507
1508static inline int security_inode_mkdir (struct inode *dir, 1462static inline int security_inode_mkdir (struct inode *dir,
1509 struct dentry *dentry, 1463 struct dentry *dentry,
1510 int mode) 1464 int mode)
@@ -1514,15 +1468,6 @@ static inline int security_inode_mkdir (struct inode *dir,
1514 return security_ops->inode_mkdir (dir, dentry, mode); 1468 return security_ops->inode_mkdir (dir, dentry, mode);
1515} 1469}
1516 1470
1517static inline void security_inode_post_mkdir (struct inode *dir,
1518 struct dentry *dentry,
1519 int mode)
1520{
1521 if (dentry->d_inode && unlikely (IS_PRIVATE (dentry->d_inode)))
1522 return;
1523 security_ops->inode_post_mkdir (dir, dentry, mode);
1524}
1525
1526static inline int security_inode_rmdir (struct inode *dir, 1471static inline int security_inode_rmdir (struct inode *dir,
1527 struct dentry *dentry) 1472 struct dentry *dentry)
1528{ 1473{
@@ -1540,15 +1485,6 @@ static inline int security_inode_mknod (struct inode *dir,
1540 return security_ops->inode_mknod (dir, dentry, mode, dev); 1485 return security_ops->inode_mknod (dir, dentry, mode, dev);
1541} 1486}
1542 1487
1543static inline void security_inode_post_mknod (struct inode *dir,
1544 struct dentry *dentry,
1545 int mode, dev_t dev)
1546{
1547 if (dentry->d_inode && unlikely (IS_PRIVATE (dentry->d_inode)))
1548 return;
1549 security_ops->inode_post_mknod (dir, dentry, mode, dev);
1550}
1551
1552static inline int security_inode_rename (struct inode *old_dir, 1488static inline int security_inode_rename (struct inode *old_dir,
1553 struct dentry *old_dentry, 1489 struct dentry *old_dentry,
1554 struct inode *new_dir, 1490 struct inode *new_dir,
@@ -1561,18 +1497,6 @@ static inline int security_inode_rename (struct inode *old_dir,
1561 new_dir, new_dentry); 1497 new_dir, new_dentry);
1562} 1498}
1563 1499
1564static inline void security_inode_post_rename (struct inode *old_dir,
1565 struct dentry *old_dentry,
1566 struct inode *new_dir,
1567 struct dentry *new_dentry)
1568{
1569 if (unlikely (IS_PRIVATE (old_dentry->d_inode) ||
1570 (new_dentry->d_inode && IS_PRIVATE (new_dentry->d_inode))))
1571 return;
1572 security_ops->inode_post_rename (old_dir, old_dentry,
1573 new_dir, new_dentry);
1574}
1575
1576static inline int security_inode_readlink (struct dentry *dentry) 1500static inline int security_inode_readlink (struct dentry *dentry)
1577{ 1501{
1578 if (unlikely (IS_PRIVATE (dentry->d_inode))) 1502 if (unlikely (IS_PRIVATE (dentry->d_inode)))
@@ -2171,6 +2095,15 @@ static inline int security_inode_alloc (struct inode *inode)
2171 2095
2172static inline void security_inode_free (struct inode *inode) 2096static inline void security_inode_free (struct inode *inode)
2173{ } 2097{ }
2098
2099static inline int security_inode_init_security (struct inode *inode,
2100 struct inode *dir,
2101 char **name,
2102 void **value,
2103 size_t *len)
2104{
2105 return -EOPNOTSUPP;
2106}
2174 2107
2175static inline int security_inode_create (struct inode *dir, 2108static inline int security_inode_create (struct inode *dir,
2176 struct dentry *dentry, 2109 struct dentry *dentry,
@@ -2179,11 +2112,6 @@ static inline int security_inode_create (struct inode *dir,
2179 return 0; 2112 return 0;
2180} 2113}
2181 2114
2182static inline void security_inode_post_create (struct inode *dir,
2183 struct dentry *dentry,
2184 int mode)
2185{ }
2186
2187static inline int security_inode_link (struct dentry *old_dentry, 2115static inline int security_inode_link (struct dentry *old_dentry,
2188 struct inode *dir, 2116 struct inode *dir,
2189 struct dentry *new_dentry) 2117 struct dentry *new_dentry)
@@ -2191,11 +2119,6 @@ static inline int security_inode_link (struct dentry *old_dentry,
2191 return 0; 2119 return 0;
2192} 2120}
2193 2121
2194static inline void security_inode_post_link (struct dentry *old_dentry,
2195 struct inode *dir,
2196 struct dentry *new_dentry)
2197{ }
2198
2199static inline int security_inode_unlink (struct inode *dir, 2122static inline int security_inode_unlink (struct inode *dir,
2200 struct dentry *dentry) 2123 struct dentry *dentry)
2201{ 2124{
@@ -2209,11 +2132,6 @@ static inline int security_inode_symlink (struct inode *dir,
2209 return 0; 2132 return 0;
2210} 2133}
2211 2134
2212static inline void security_inode_post_symlink (struct inode *dir,
2213 struct dentry *dentry,
2214 const char *old_name)
2215{ }
2216
2217static inline int security_inode_mkdir (struct inode *dir, 2135static inline int security_inode_mkdir (struct inode *dir,
2218 struct dentry *dentry, 2136 struct dentry *dentry,
2219 int mode) 2137 int mode)
@@ -2221,11 +2139,6 @@ static inline int security_inode_mkdir (struct inode *dir,
2221 return 0; 2139 return 0;
2222} 2140}
2223 2141
2224static inline void security_inode_post_mkdir (struct inode *dir,
2225 struct dentry *dentry,
2226 int mode)
2227{ }
2228
2229static inline int security_inode_rmdir (struct inode *dir, 2142static inline int security_inode_rmdir (struct inode *dir,
2230 struct dentry *dentry) 2143 struct dentry *dentry)
2231{ 2144{
@@ -2239,11 +2152,6 @@ static inline int security_inode_mknod (struct inode *dir,
2239 return 0; 2152 return 0;
2240} 2153}
2241 2154
2242static inline void security_inode_post_mknod (struct inode *dir,
2243 struct dentry *dentry,
2244 int mode, dev_t dev)
2245{ }
2246
2247static inline int security_inode_rename (struct inode *old_dir, 2155static inline int security_inode_rename (struct inode *old_dir,
2248 struct dentry *old_dentry, 2156 struct dentry *old_dentry,
2249 struct inode *new_dir, 2157 struct inode *new_dir,
@@ -2252,12 +2160,6 @@ static inline int security_inode_rename (struct inode *old_dir,
2252 return 0; 2160 return 0;
2253} 2161}
2254 2162
2255static inline void security_inode_post_rename (struct inode *old_dir,
2256 struct dentry *old_dentry,
2257 struct inode *new_dir,
2258 struct dentry *new_dentry)
2259{ }
2260
2261static inline int security_inode_readlink (struct dentry *dentry) 2163static inline int security_inode_readlink (struct dentry *dentry)
2262{ 2164{
2263 return 0; 2165 return 0;
diff --git a/include/linux/slab.h b/include/linux/slab.h
index 42a6bea58a..1f356f3bbc 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -118,7 +118,8 @@ extern void kfree(const void *);
118extern unsigned int ksize(const void *); 118extern unsigned int ksize(const void *);
119 119
120#ifdef CONFIG_NUMA 120#ifdef CONFIG_NUMA
121extern void *kmem_cache_alloc_node(kmem_cache_t *, int flags, int node); 121extern void *kmem_cache_alloc_node(kmem_cache_t *,
122 unsigned int __nocast flags, int node);
122extern void *kmalloc_node(size_t size, unsigned int __nocast flags, int node); 123extern void *kmalloc_node(size_t size, unsigned int __nocast flags, int node);
123#else 124#else
124static inline void *kmem_cache_alloc_node(kmem_cache_t *cachep, int flags, int node) 125static inline void *kmem_cache_alloc_node(kmem_cache_t *cachep, int flags, int node)
diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h
index d6ba068719..cdc99a2784 100644
--- a/include/linux/spinlock.h
+++ b/include/linux/spinlock.h
@@ -2,7 +2,48 @@
2#define __LINUX_SPINLOCK_H 2#define __LINUX_SPINLOCK_H
3 3
4/* 4/*
5 * include/linux/spinlock.h - generic locking declarations 5 * include/linux/spinlock.h - generic spinlock/rwlock declarations
6 *
7 * here's the role of the various spinlock/rwlock related include files:
8 *
9 * on SMP builds:
10 *
11 * asm/spinlock_types.h: contains the raw_spinlock_t/raw_rwlock_t and the
12 * initializers
13 *
14 * linux/spinlock_types.h:
15 * defines the generic type and initializers
16 *
17 * asm/spinlock.h: contains the __raw_spin_*()/etc. lowlevel
18 * implementations, mostly inline assembly code
19 *
20 * (also included on UP-debug builds:)
21 *
22 * linux/spinlock_api_smp.h:
23 * contains the prototypes for the _spin_*() APIs.
24 *
25 * linux/spinlock.h: builds the final spin_*() APIs.
26 *
27 * on UP builds:
28 *
29 * linux/spinlock_type_up.h:
30 * contains the generic, simplified UP spinlock type.
31 * (which is an empty structure on non-debug builds)
32 *
33 * linux/spinlock_types.h:
34 * defines the generic type and initializers
35 *
36 * linux/spinlock_up.h:
37 * contains the __raw_spin_*()/etc. version of UP
38 * builds. (which are NOPs on non-debug, non-preempt
39 * builds)
40 *
41 * (included on UP-non-debug builds:)
42 *
43 * linux/spinlock_api_up.h:
44 * builds the _spin_*() APIs.
45 *
46 * linux/spinlock.h: builds the final spin_*() APIs.
6 */ 47 */
7 48
8#include <linux/config.h> 49#include <linux/config.h>
@@ -13,7 +54,6 @@
13#include <linux/kernel.h> 54#include <linux/kernel.h>
14#include <linux/stringify.h> 55#include <linux/stringify.h>
15 56
16#include <asm/processor.h> /* for cpu relax */
17#include <asm/system.h> 57#include <asm/system.h>
18 58
19/* 59/*
@@ -35,423 +75,84 @@
35#define __lockfunc fastcall __attribute__((section(".spinlock.text"))) 75#define __lockfunc fastcall __attribute__((section(".spinlock.text")))
36 76
37/* 77/*
38 * If CONFIG_SMP is set, pull in the _raw_* definitions 78 * Pull the raw_spinlock_t and raw_rwlock_t definitions:
39 */ 79 */
40#ifdef CONFIG_SMP 80#include <linux/spinlock_types.h>
41
42#define assert_spin_locked(x) BUG_ON(!spin_is_locked(x))
43#include <asm/spinlock.h>
44
45int __lockfunc _spin_trylock(spinlock_t *lock);
46int __lockfunc _read_trylock(rwlock_t *lock);
47int __lockfunc _write_trylock(rwlock_t *lock);
48
49void __lockfunc _spin_lock(spinlock_t *lock) __acquires(spinlock_t);
50void __lockfunc _read_lock(rwlock_t *lock) __acquires(rwlock_t);
51void __lockfunc _write_lock(rwlock_t *lock) __acquires(rwlock_t);
52
53void __lockfunc _spin_unlock(spinlock_t *lock) __releases(spinlock_t);
54void __lockfunc _read_unlock(rwlock_t *lock) __releases(rwlock_t);
55void __lockfunc _write_unlock(rwlock_t *lock) __releases(rwlock_t);
56
57unsigned long __lockfunc _spin_lock_irqsave(spinlock_t *lock) __acquires(spinlock_t);
58unsigned long __lockfunc _read_lock_irqsave(rwlock_t *lock) __acquires(rwlock_t);
59unsigned long __lockfunc _write_lock_irqsave(rwlock_t *lock) __acquires(rwlock_t);
60
61void __lockfunc _spin_lock_irq(spinlock_t *lock) __acquires(spinlock_t);
62void __lockfunc _spin_lock_bh(spinlock_t *lock) __acquires(spinlock_t);
63void __lockfunc _read_lock_irq(rwlock_t *lock) __acquires(rwlock_t);
64void __lockfunc _read_lock_bh(rwlock_t *lock) __acquires(rwlock_t);
65void __lockfunc _write_lock_irq(rwlock_t *lock) __acquires(rwlock_t);
66void __lockfunc _write_lock_bh(rwlock_t *lock) __acquires(rwlock_t);
67
68void __lockfunc _spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags) __releases(spinlock_t);
69void __lockfunc _spin_unlock_irq(spinlock_t *lock) __releases(spinlock_t);
70void __lockfunc _spin_unlock_bh(spinlock_t *lock) __releases(spinlock_t);
71void __lockfunc _read_unlock_irqrestore(rwlock_t *lock, unsigned long flags) __releases(rwlock_t);
72void __lockfunc _read_unlock_irq(rwlock_t *lock) __releases(rwlock_t);
73void __lockfunc _read_unlock_bh(rwlock_t *lock) __releases(rwlock_t);
74void __lockfunc _write_unlock_irqrestore(rwlock_t *lock, unsigned long flags) __releases(rwlock_t);
75void __lockfunc _write_unlock_irq(rwlock_t *lock) __releases(rwlock_t);
76void __lockfunc _write_unlock_bh(rwlock_t *lock) __releases(rwlock_t);
77
78int __lockfunc _spin_trylock_bh(spinlock_t *lock);
79int __lockfunc generic_raw_read_trylock(rwlock_t *lock);
80int in_lock_functions(unsigned long addr);
81
82#else
83 81
84#define in_lock_functions(ADDR) 0 82extern int __lockfunc generic__raw_read_trylock(raw_rwlock_t *lock);
85 83
86#if !defined(CONFIG_PREEMPT) && !defined(CONFIG_DEBUG_SPINLOCK)
87# define _atomic_dec_and_lock(atomic,lock) atomic_dec_and_test(atomic)
88# define ATOMIC_DEC_AND_LOCK
89#endif
90
91#ifdef CONFIG_DEBUG_SPINLOCK
92
93#define SPINLOCK_MAGIC 0x1D244B3C
94typedef struct {
95 unsigned long magic;
96 volatile unsigned long lock;
97 volatile unsigned int babble;
98 const char *module;
99 char *owner;
100 int oline;
101} spinlock_t;
102#define SPIN_LOCK_UNLOCKED (spinlock_t) { SPINLOCK_MAGIC, 0, 10, __FILE__ , NULL, 0}
103
104#define spin_lock_init(x) \
105 do { \
106 (x)->magic = SPINLOCK_MAGIC; \
107 (x)->lock = 0; \
108 (x)->babble = 5; \
109 (x)->module = __FILE__; \
110 (x)->owner = NULL; \
111 (x)->oline = 0; \
112 } while (0)
113
114#define CHECK_LOCK(x) \
115 do { \
116 if ((x)->magic != SPINLOCK_MAGIC) { \
117 printk(KERN_ERR "%s:%d: spin_is_locked on uninitialized spinlock %p.\n", \
118 __FILE__, __LINE__, (x)); \
119 } \
120 } while(0)
121
122#define _raw_spin_lock(x) \
123 do { \
124 CHECK_LOCK(x); \
125 if ((x)->lock&&(x)->babble) { \
126 (x)->babble--; \
127 printk("%s:%d: spin_lock(%s:%p) already locked by %s/%d\n", \
128 __FILE__,__LINE__, (x)->module, \
129 (x), (x)->owner, (x)->oline); \
130 } \
131 (x)->lock = 1; \
132 (x)->owner = __FILE__; \
133 (x)->oline = __LINE__; \
134 } while (0)
135
136/* without debugging, spin_is_locked on UP always says
137 * FALSE. --> printk if already locked. */
138#define spin_is_locked(x) \
139 ({ \
140 CHECK_LOCK(x); \
141 if ((x)->lock&&(x)->babble) { \
142 (x)->babble--; \
143 printk("%s:%d: spin_is_locked(%s:%p) already locked by %s/%d\n", \
144 __FILE__,__LINE__, (x)->module, \
145 (x), (x)->owner, (x)->oline); \
146 } \
147 0; \
148 })
149
150/* with debugging, assert_spin_locked() on UP does check
151 * the lock value properly */
152#define assert_spin_locked(x) \
153 ({ \
154 CHECK_LOCK(x); \
155 BUG_ON(!(x)->lock); \
156 })
157
158/* without debugging, spin_trylock on UP always says
159 * TRUE. --> printk if already locked. */
160#define _raw_spin_trylock(x) \
161 ({ \
162 CHECK_LOCK(x); \
163 if ((x)->lock&&(x)->babble) { \
164 (x)->babble--; \
165 printk("%s:%d: spin_trylock(%s:%p) already locked by %s/%d\n", \
166 __FILE__,__LINE__, (x)->module, \
167 (x), (x)->owner, (x)->oline); \
168 } \
169 (x)->lock = 1; \
170 (x)->owner = __FILE__; \
171 (x)->oline = __LINE__; \
172 1; \
173 })
174
175#define spin_unlock_wait(x) \
176 do { \
177 CHECK_LOCK(x); \
178 if ((x)->lock&&(x)->babble) { \
179 (x)->babble--; \
180 printk("%s:%d: spin_unlock_wait(%s:%p) owned by %s/%d\n", \
181 __FILE__,__LINE__, (x)->module, (x), \
182 (x)->owner, (x)->oline); \
183 }\
184 } while (0)
185
186#define _raw_spin_unlock(x) \
187 do { \
188 CHECK_LOCK(x); \
189 if (!(x)->lock&&(x)->babble) { \
190 (x)->babble--; \
191 printk("%s:%d: spin_unlock(%s:%p) not locked\n", \
192 __FILE__,__LINE__, (x)->module, (x));\
193 } \
194 (x)->lock = 0; \
195 } while (0)
196#else
197/* 84/*
198 * gcc versions before ~2.95 have a nasty bug with empty initializers. 85 * Pull the __raw*() functions/declarations (UP-nondebug doesnt need them):
199 */ 86 */
200#if (__GNUC__ > 2) 87#if defined(CONFIG_SMP)
201 typedef struct { } spinlock_t; 88# include <asm/spinlock.h>
202 #define SPIN_LOCK_UNLOCKED (spinlock_t) { }
203#else 89#else
204 typedef struct { int gcc_is_buggy; } spinlock_t; 90# include <linux/spinlock_up.h>
205 #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 }
206#endif 91#endif
207 92
93#define spin_lock_init(lock) do { *(lock) = SPIN_LOCK_UNLOCKED; } while (0)
94#define rwlock_init(lock) do { *(lock) = RW_LOCK_UNLOCKED; } while (0)
95
96#define spin_is_locked(lock) __raw_spin_is_locked(&(lock)->raw_lock)
97
98/**
99 * spin_unlock_wait - wait until the spinlock gets unlocked
100 * @lock: the spinlock in question.
101 */
102#define spin_unlock_wait(lock) __raw_spin_unlock_wait(&(lock)->raw_lock)
103
208/* 104/*
209 * If CONFIG_SMP is unset, declare the _raw_* definitions as nops 105 * Pull the _spin_*()/_read_*()/_write_*() functions/declarations:
210 */ 106 */
211#define spin_lock_init(lock) do { (void)(lock); } while(0) 107#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
212#define _raw_spin_lock(lock) do { (void)(lock); } while(0) 108# include <linux/spinlock_api_smp.h>
213#define spin_is_locked(lock) ((void)(lock), 0)
214#define assert_spin_locked(lock) do { (void)(lock); } while(0)
215#define _raw_spin_trylock(lock) (((void)(lock), 1))
216#define spin_unlock_wait(lock) (void)(lock)
217#define _raw_spin_unlock(lock) do { (void)(lock); } while(0)
218#endif /* CONFIG_DEBUG_SPINLOCK */
219
220/* RW spinlocks: No debug version */
221
222#if (__GNUC__ > 2)
223 typedef struct { } rwlock_t;
224 #define RW_LOCK_UNLOCKED (rwlock_t) { }
225#else 109#else
226 typedef struct { int gcc_is_buggy; } rwlock_t; 110# include <linux/spinlock_api_up.h>
227 #define RW_LOCK_UNLOCKED (rwlock_t) { 0 }
228#endif 111#endif
229 112
230#define rwlock_init(lock) do { (void)(lock); } while(0) 113#ifdef CONFIG_DEBUG_SPINLOCK
231#define _raw_read_lock(lock) do { (void)(lock); } while(0) 114 extern void _raw_spin_lock(spinlock_t *lock);
232#define _raw_read_unlock(lock) do { (void)(lock); } while(0) 115#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
233#define _raw_write_lock(lock) do { (void)(lock); } while(0) 116 extern int _raw_spin_trylock(spinlock_t *lock);
234#define _raw_write_unlock(lock) do { (void)(lock); } while(0) 117 extern void _raw_spin_unlock(spinlock_t *lock);
235#define read_can_lock(lock) (((void)(lock), 1)) 118
236#define write_can_lock(lock) (((void)(lock), 1)) 119 extern void _raw_read_lock(rwlock_t *lock);
237#define _raw_read_trylock(lock) ({ (void)(lock); (1); }) 120 extern int _raw_read_trylock(rwlock_t *lock);
238#define _raw_write_trylock(lock) ({ (void)(lock); (1); }) 121 extern void _raw_read_unlock(rwlock_t *lock);
239 122 extern void _raw_write_lock(rwlock_t *lock);
240#define _spin_trylock(lock) ({preempt_disable(); _raw_spin_trylock(lock) ? \ 123 extern int _raw_write_trylock(rwlock_t *lock);
241 1 : ({preempt_enable(); 0;});}) 124 extern void _raw_write_unlock(rwlock_t *lock);
242 125#else
243#define _read_trylock(lock) ({preempt_disable();_raw_read_trylock(lock) ? \ 126# define _raw_spin_unlock(lock) __raw_spin_unlock(&(lock)->raw_lock)
244 1 : ({preempt_enable(); 0;});}) 127# define _raw_spin_trylock(lock) __raw_spin_trylock(&(lock)->raw_lock)
245 128# define _raw_spin_lock(lock) __raw_spin_lock(&(lock)->raw_lock)
246#define _write_trylock(lock) ({preempt_disable(); _raw_write_trylock(lock) ? \ 129# define _raw_spin_lock_flags(lock, flags) \
247 1 : ({preempt_enable(); 0;});}) 130 __raw_spin_lock_flags(&(lock)->raw_lock, *(flags))
248 131# define _raw_read_lock(rwlock) __raw_read_lock(&(rwlock)->raw_lock)
249#define _spin_trylock_bh(lock) ({preempt_disable(); local_bh_disable(); \ 132# define _raw_write_lock(rwlock) __raw_write_lock(&(rwlock)->raw_lock)
250 _raw_spin_trylock(lock) ? \ 133# define _raw_read_unlock(rwlock) __raw_read_unlock(&(rwlock)->raw_lock)
251 1 : ({preempt_enable_no_resched(); local_bh_enable(); 0;});}) 134# define _raw_write_unlock(rwlock) __raw_write_unlock(&(rwlock)->raw_lock)
252 135# define _raw_read_trylock(rwlock) __raw_read_trylock(&(rwlock)->raw_lock)
253#define _spin_lock(lock) \ 136# define _raw_write_trylock(rwlock) __raw_write_trylock(&(rwlock)->raw_lock)
254do { \ 137#endif
255 preempt_disable(); \
256 _raw_spin_lock(lock); \
257 __acquire(lock); \
258} while(0)
259
260#define _write_lock(lock) \
261do { \
262 preempt_disable(); \
263 _raw_write_lock(lock); \
264 __acquire(lock); \
265} while(0)
266
267#define _read_lock(lock) \
268do { \
269 preempt_disable(); \
270 _raw_read_lock(lock); \
271 __acquire(lock); \
272} while(0)
273
274#define _spin_unlock(lock) \
275do { \
276 _raw_spin_unlock(lock); \
277 preempt_enable(); \
278 __release(lock); \
279} while (0)
280
281#define _write_unlock(lock) \
282do { \
283 _raw_write_unlock(lock); \
284 preempt_enable(); \
285 __release(lock); \
286} while(0)
287
288#define _read_unlock(lock) \
289do { \
290 _raw_read_unlock(lock); \
291 preempt_enable(); \
292 __release(lock); \
293} while(0)
294
295#define _spin_lock_irqsave(lock, flags) \
296do { \
297 local_irq_save(flags); \
298 preempt_disable(); \
299 _raw_spin_lock(lock); \
300 __acquire(lock); \
301} while (0)
302
303#define _spin_lock_irq(lock) \
304do { \
305 local_irq_disable(); \
306 preempt_disable(); \
307 _raw_spin_lock(lock); \
308 __acquire(lock); \
309} while (0)
310
311#define _spin_lock_bh(lock) \
312do { \
313 local_bh_disable(); \
314 preempt_disable(); \
315 _raw_spin_lock(lock); \
316 __acquire(lock); \
317} while (0)
318
319#define _read_lock_irqsave(lock, flags) \
320do { \
321 local_irq_save(flags); \
322 preempt_disable(); \
323 _raw_read_lock(lock); \
324 __acquire(lock); \
325} while (0)
326
327#define _read_lock_irq(lock) \
328do { \
329 local_irq_disable(); \
330 preempt_disable(); \
331 _raw_read_lock(lock); \
332 __acquire(lock); \
333} while (0)
334
335#define _read_lock_bh(lock) \
336do { \
337 local_bh_disable(); \
338 preempt_disable(); \
339 _raw_read_lock(lock); \
340 __acquire(lock); \
341} while (0)
342
343#define _write_lock_irqsave(lock, flags) \
344do { \
345 local_irq_save(flags); \
346 preempt_disable(); \
347 _raw_write_lock(lock); \
348 __acquire(lock); \
349} while (0)
350 138
351#define _write_lock_irq(lock) \ 139#define read_can_lock(rwlock) __raw_read_can_lock(&(rwlock)->raw_lock)
352do { \ 140#define write_can_lock(rwlock) __raw_write_can_lock(&(rwlock)->raw_lock)
353 local_irq_disable(); \
354 preempt_disable(); \
355 _raw_write_lock(lock); \
356 __acquire(lock); \
357} while (0)
358
359#define _write_lock_bh(lock) \
360do { \
361 local_bh_disable(); \
362 preempt_disable(); \
363 _raw_write_lock(lock); \
364 __acquire(lock); \
365} while (0)
366
367#define _spin_unlock_irqrestore(lock, flags) \
368do { \
369 _raw_spin_unlock(lock); \
370 local_irq_restore(flags); \
371 preempt_enable(); \
372 __release(lock); \
373} while (0)
374
375#define _spin_unlock_irq(lock) \
376do { \
377 _raw_spin_unlock(lock); \
378 local_irq_enable(); \
379 preempt_enable(); \
380 __release(lock); \
381} while (0)
382
383#define _spin_unlock_bh(lock) \
384do { \
385 _raw_spin_unlock(lock); \
386 preempt_enable_no_resched(); \
387 local_bh_enable(); \
388 __release(lock); \
389} while (0)
390
391#define _write_unlock_bh(lock) \
392do { \
393 _raw_write_unlock(lock); \
394 preempt_enable_no_resched(); \
395 local_bh_enable(); \
396 __release(lock); \
397} while (0)
398
399#define _read_unlock_irqrestore(lock, flags) \
400do { \
401 _raw_read_unlock(lock); \
402 local_irq_restore(flags); \
403 preempt_enable(); \
404 __release(lock); \
405} while (0)
406
407#define _write_unlock_irqrestore(lock, flags) \
408do { \
409 _raw_write_unlock(lock); \
410 local_irq_restore(flags); \
411 preempt_enable(); \
412 __release(lock); \
413} while (0)
414
415#define _read_unlock_irq(lock) \
416do { \
417 _raw_read_unlock(lock); \
418 local_irq_enable(); \
419 preempt_enable(); \
420 __release(lock); \
421} while (0)
422
423#define _read_unlock_bh(lock) \
424do { \
425 _raw_read_unlock(lock); \
426 preempt_enable_no_resched(); \
427 local_bh_enable(); \
428 __release(lock); \
429} while (0)
430
431#define _write_unlock_irq(lock) \
432do { \
433 _raw_write_unlock(lock); \
434 local_irq_enable(); \
435 preempt_enable(); \
436 __release(lock); \
437} while (0)
438
439#endif /* !SMP */
440 141
441/* 142/*
442 * Define the various spin_lock and rw_lock methods. Note we define these 143 * Define the various spin_lock and rw_lock methods. Note we define these
443 * regardless of whether CONFIG_SMP or CONFIG_PREEMPT are set. The various 144 * regardless of whether CONFIG_SMP or CONFIG_PREEMPT are set. The various
444 * methods are defined as nops in the case they are not required. 145 * methods are defined as nops in the case they are not required.
445 */ 146 */
446#define spin_trylock(lock) __cond_lock(_spin_trylock(lock)) 147#define spin_trylock(lock) __cond_lock(_spin_trylock(lock))
447#define read_trylock(lock) __cond_lock(_read_trylock(lock)) 148#define read_trylock(lock) __cond_lock(_read_trylock(lock))
448#define write_trylock(lock) __cond_lock(_write_trylock(lock)) 149#define write_trylock(lock) __cond_lock(_write_trylock(lock))
449 150
450#define spin_lock(lock) _spin_lock(lock) 151#define spin_lock(lock) _spin_lock(lock)
451#define write_lock(lock) _write_lock(lock) 152#define write_lock(lock) _write_lock(lock)
452#define read_lock(lock) _read_lock(lock) 153#define read_lock(lock) _read_lock(lock)
453 154
454#ifdef CONFIG_SMP 155#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
455#define spin_lock_irqsave(lock, flags) flags = _spin_lock_irqsave(lock) 156#define spin_lock_irqsave(lock, flags) flags = _spin_lock_irqsave(lock)
456#define read_lock_irqsave(lock, flags) flags = _read_lock_irqsave(lock) 157#define read_lock_irqsave(lock, flags) flags = _read_lock_irqsave(lock)
457#define write_lock_irqsave(lock, flags) flags = _write_lock_irqsave(lock) 158#define write_lock_irqsave(lock, flags) flags = _write_lock_irqsave(lock)
@@ -470,137 +171,59 @@ do { \
470#define write_lock_irq(lock) _write_lock_irq(lock) 171#define write_lock_irq(lock) _write_lock_irq(lock)
471#define write_lock_bh(lock) _write_lock_bh(lock) 172#define write_lock_bh(lock) _write_lock_bh(lock)
472 173
473#define spin_unlock(lock) _spin_unlock(lock) 174#define spin_unlock(lock) _spin_unlock(lock)
474#define write_unlock(lock) _write_unlock(lock) 175#define write_unlock(lock) _write_unlock(lock)
475#define read_unlock(lock) _read_unlock(lock) 176#define read_unlock(lock) _read_unlock(lock)
476 177
477#define spin_unlock_irqrestore(lock, flags) _spin_unlock_irqrestore(lock, flags) 178#define spin_unlock_irqrestore(lock, flags) \
179 _spin_unlock_irqrestore(lock, flags)
478#define spin_unlock_irq(lock) _spin_unlock_irq(lock) 180#define spin_unlock_irq(lock) _spin_unlock_irq(lock)
479#define spin_unlock_bh(lock) _spin_unlock_bh(lock) 181#define spin_unlock_bh(lock) _spin_unlock_bh(lock)
480 182
481#define read_unlock_irqrestore(lock, flags) _read_unlock_irqrestore(lock, flags) 183#define read_unlock_irqrestore(lock, flags) \
482#define read_unlock_irq(lock) _read_unlock_irq(lock) 184 _read_unlock_irqrestore(lock, flags)
483#define read_unlock_bh(lock) _read_unlock_bh(lock) 185#define read_unlock_irq(lock) _read_unlock_irq(lock)
186#define read_unlock_bh(lock) _read_unlock_bh(lock)
484 187
485#define write_unlock_irqrestore(lock, flags) _write_unlock_irqrestore(lock, flags) 188#define write_unlock_irqrestore(lock, flags) \
486#define write_unlock_irq(lock) _write_unlock_irq(lock) 189 _write_unlock_irqrestore(lock, flags)
487#define write_unlock_bh(lock) _write_unlock_bh(lock) 190#define write_unlock_irq(lock) _write_unlock_irq(lock)
191#define write_unlock_bh(lock) _write_unlock_bh(lock)
488 192
489#define spin_trylock_bh(lock) __cond_lock(_spin_trylock_bh(lock)) 193#define spin_trylock_bh(lock) __cond_lock(_spin_trylock_bh(lock))
490 194
491#define spin_trylock_irq(lock) \ 195#define spin_trylock_irq(lock) \
492({ \ 196({ \
493 local_irq_disable(); \ 197 local_irq_disable(); \
494 _spin_trylock(lock) ? \ 198 _spin_trylock(lock) ? \
495 1 : ({local_irq_enable(); 0; }); \ 199 1 : ({ local_irq_enable(); 0; }); \
496}) 200})
497 201
498#define spin_trylock_irqsave(lock, flags) \ 202#define spin_trylock_irqsave(lock, flags) \
499({ \ 203({ \
500 local_irq_save(flags); \ 204 local_irq_save(flags); \
501 _spin_trylock(lock) ? \ 205 _spin_trylock(lock) ? \
502 1 : ({local_irq_restore(flags); 0;}); \ 206 1 : ({ local_irq_restore(flags); 0; }); \
503}) 207})
504 208
505#ifdef CONFIG_LOCKMETER
506extern void _metered_spin_lock (spinlock_t *lock);
507extern void _metered_spin_unlock (spinlock_t *lock);
508extern int _metered_spin_trylock(spinlock_t *lock);
509extern void _metered_read_lock (rwlock_t *lock);
510extern void _metered_read_unlock (rwlock_t *lock);
511extern void _metered_write_lock (rwlock_t *lock);
512extern void _metered_write_unlock (rwlock_t *lock);
513extern int _metered_read_trylock (rwlock_t *lock);
514extern int _metered_write_trylock(rwlock_t *lock);
515#endif
516
517/* "lock on reference count zero" */
518#ifndef ATOMIC_DEC_AND_LOCK
519#include <asm/atomic.h>
520extern int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock);
521#endif
522
523#define atomic_dec_and_lock(atomic,lock) __cond_lock(_atomic_dec_and_lock(atomic,lock))
524
525/*
526 * bit-based spin_lock()
527 *
528 * Don't use this unless you really need to: spin_lock() and spin_unlock()
529 * are significantly faster.
530 */
531static inline void bit_spin_lock(int bitnum, unsigned long *addr)
532{
533 /*
534 * Assuming the lock is uncontended, this never enters
535 * the body of the outer loop. If it is contended, then
536 * within the inner loop a non-atomic test is used to
537 * busywait with less bus contention for a good time to
538 * attempt to acquire the lock bit.
539 */
540 preempt_disable();
541#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
542 while (test_and_set_bit(bitnum, addr)) {
543 while (test_bit(bitnum, addr)) {
544 preempt_enable();
545 cpu_relax();
546 preempt_disable();
547 }
548 }
549#endif
550 __acquire(bitlock);
551}
552
553/* 209/*
554 * Return true if it was acquired 210 * Pull the atomic_t declaration:
211 * (asm-mips/atomic.h needs above definitions)
555 */ 212 */
556static inline int bit_spin_trylock(int bitnum, unsigned long *addr) 213#include <asm/atomic.h>
557{ 214/**
558 preempt_disable(); 215 * atomic_dec_and_lock - lock on reaching reference count zero
559#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) 216 * @atomic: the atomic counter
560 if (test_and_set_bit(bitnum, addr)) { 217 * @lock: the spinlock in question
561 preempt_enable();
562 return 0;
563 }
564#endif
565 __acquire(bitlock);
566 return 1;
567}
568
569/*
570 * bit-based spin_unlock()
571 */
572static inline void bit_spin_unlock(int bitnum, unsigned long *addr)
573{
574#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
575 BUG_ON(!test_bit(bitnum, addr));
576 smp_mb__before_clear_bit();
577 clear_bit(bitnum, addr);
578#endif
579 preempt_enable();
580 __release(bitlock);
581}
582
583/*
584 * Return true if the lock is held.
585 */ 218 */
586static inline int bit_spin_is_locked(int bitnum, unsigned long *addr) 219extern int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock);
587{ 220#define atomic_dec_and_lock(atomic, lock) \
588#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) 221 __cond_lock(_atomic_dec_and_lock(atomic, lock))
589 return test_bit(bitnum, addr);
590#elif defined CONFIG_PREEMPT
591 return preempt_count();
592#else
593 return 1;
594#endif
595}
596
597#define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
598#define DEFINE_RWLOCK(x) rwlock_t x = RW_LOCK_UNLOCKED
599 222
600/** 223/**
601 * spin_can_lock - would spin_trylock() succeed? 224 * spin_can_lock - would spin_trylock() succeed?
602 * @lock: the spinlock in question. 225 * @lock: the spinlock in question.
603 */ 226 */
604#define spin_can_lock(lock) (!spin_is_locked(lock)) 227#define spin_can_lock(lock) (!spin_is_locked(lock))
605 228
606#endif /* __LINUX_SPINLOCK_H */ 229#endif /* __LINUX_SPINLOCK_H */
diff --git a/include/linux/spinlock_api_smp.h b/include/linux/spinlock_api_smp.h
new file mode 100644
index 0000000000..78e6989ffb
--- /dev/null
+++ b/include/linux/spinlock_api_smp.h
@@ -0,0 +1,57 @@
1#ifndef __LINUX_SPINLOCK_API_SMP_H
2#define __LINUX_SPINLOCK_API_SMP_H
3
4#ifndef __LINUX_SPINLOCK_H
5# error "please don't include this file directly"
6#endif
7
8/*
9 * include/linux/spinlock_api_smp.h
10 *
11 * spinlock API declarations on SMP (and debug)
12 * (implemented in kernel/spinlock.c)
13 *
14 * portions Copyright 2005, Red Hat, Inc., Ingo Molnar
15 * Released under the General Public License (GPL).
16 */
17
18int in_lock_functions(unsigned long addr);
19
20#define assert_spin_locked(x) BUG_ON(!spin_is_locked(x))
21
22void __lockfunc _spin_lock(spinlock_t *lock) __acquires(spinlock_t);
23void __lockfunc _read_lock(rwlock_t *lock) __acquires(rwlock_t);
24void __lockfunc _write_lock(rwlock_t *lock) __acquires(rwlock_t);
25void __lockfunc _spin_lock_bh(spinlock_t *lock) __acquires(spinlock_t);
26void __lockfunc _read_lock_bh(rwlock_t *lock) __acquires(rwlock_t);
27void __lockfunc _write_lock_bh(rwlock_t *lock) __acquires(rwlock_t);
28void __lockfunc _spin_lock_irq(spinlock_t *lock) __acquires(spinlock_t);
29void __lockfunc _read_lock_irq(rwlock_t *lock) __acquires(rwlock_t);
30void __lockfunc _write_lock_irq(rwlock_t *lock) __acquires(rwlock_t);
31unsigned long __lockfunc _spin_lock_irqsave(spinlock_t *lock)
32 __acquires(spinlock_t);
33unsigned long __lockfunc _read_lock_irqsave(rwlock_t *lock)
34 __acquires(rwlock_t);
35unsigned long __lockfunc _write_lock_irqsave(rwlock_t *lock)
36 __acquires(rwlock_t);
37int __lockfunc _spin_trylock(spinlock_t *lock);
38int __lockfunc _read_trylock(rwlock_t *lock);
39int __lockfunc _write_trylock(rwlock_t *lock);
40int __lockfunc _spin_trylock_bh(spinlock_t *lock);
41void __lockfunc _spin_unlock(spinlock_t *lock) __releases(spinlock_t);
42void __lockfunc _read_unlock(rwlock_t *lock) __releases(rwlock_t);
43void __lockfunc _write_unlock(rwlock_t *lock) __releases(rwlock_t);
44void __lockfunc _spin_unlock_bh(spinlock_t *lock) __releases(spinlock_t);
45void __lockfunc _read_unlock_bh(rwlock_t *lock) __releases(rwlock_t);
46void __lockfunc _write_unlock_bh(rwlock_t *lock) __releases(rwlock_t);
47void __lockfunc _spin_unlock_irq(spinlock_t *lock) __releases(spinlock_t);
48void __lockfunc _read_unlock_irq(rwlock_t *lock) __releases(rwlock_t);
49void __lockfunc _write_unlock_irq(rwlock_t *lock) __releases(rwlock_t);
50void __lockfunc _spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags)
51 __releases(spinlock_t);
52void __lockfunc _read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
53 __releases(rwlock_t);
54void __lockfunc _write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
55 __releases(rwlock_t);
56
57#endif /* __LINUX_SPINLOCK_API_SMP_H */
diff --git a/include/linux/spinlock_api_up.h b/include/linux/spinlock_api_up.h
new file mode 100644
index 0000000000..cd81cee566
--- /dev/null
+++ b/include/linux/spinlock_api_up.h
@@ -0,0 +1,80 @@
1#ifndef __LINUX_SPINLOCK_API_UP_H
2#define __LINUX_SPINLOCK_API_UP_H
3
4#ifndef __LINUX_SPINLOCK_H
5# error "please don't include this file directly"
6#endif
7
8/*
9 * include/linux/spinlock_api_up.h
10 *
11 * spinlock API implementation on UP-nondebug (inlined implementation)
12 *
13 * portions Copyright 2005, Red Hat, Inc., Ingo Molnar
14 * Released under the General Public License (GPL).
15 */
16
17#define in_lock_functions(ADDR) 0
18
19#define assert_spin_locked(lock) do { (void)(lock); } while (0)
20
21/*
22 * In the UP-nondebug case there's no real locking going on, so the
23 * only thing we have to do is to keep the preempt counts and irq
24 * flags straight, to supress compiler warnings of unused lock
25 * variables, and to add the proper checker annotations:
26 */
27#define __LOCK(lock) \
28 do { preempt_disable(); __acquire(lock); (void)(lock); } while (0)
29
30#define __LOCK_BH(lock) \
31 do { local_bh_disable(); __LOCK(lock); } while (0)
32
33#define __LOCK_IRQ(lock) \
34 do { local_irq_disable(); __LOCK(lock); } while (0)
35
36#define __LOCK_IRQSAVE(lock, flags) \
37 do { local_irq_save(flags); __LOCK(lock); } while (0)
38
39#define __UNLOCK(lock) \
40 do { preempt_enable(); __release(lock); (void)(lock); } while (0)
41
42#define __UNLOCK_BH(lock) \
43 do { preempt_enable_no_resched(); local_bh_enable(); __release(lock); (void)(lock); } while (0)
44
45#define __UNLOCK_IRQ(lock) \
46 do { local_irq_enable(); __UNLOCK(lock); } while (0)
47
48#define __UNLOCK_IRQRESTORE(lock, flags) \
49 do { local_irq_restore(flags); __UNLOCK(lock); } while (0)
50
51#define _spin_lock(lock) __LOCK(lock)
52#define _read_lock(lock) __LOCK(lock)
53#define _write_lock(lock) __LOCK(lock)
54#define _spin_lock_bh(lock) __LOCK_BH(lock)
55#define _read_lock_bh(lock) __LOCK_BH(lock)
56#define _write_lock_bh(lock) __LOCK_BH(lock)
57#define _spin_lock_irq(lock) __LOCK_IRQ(lock)
58#define _read_lock_irq(lock) __LOCK_IRQ(lock)
59#define _write_lock_irq(lock) __LOCK_IRQ(lock)
60#define _spin_lock_irqsave(lock, flags) __LOCK_IRQSAVE(lock, flags)
61#define _read_lock_irqsave(lock, flags) __LOCK_IRQSAVE(lock, flags)
62#define _write_lock_irqsave(lock, flags) __LOCK_IRQSAVE(lock, flags)
63#define _spin_trylock(lock) ({ __LOCK(lock); 1; })
64#define _read_trylock(lock) ({ __LOCK(lock); 1; })
65#define _write_trylock(lock) ({ __LOCK(lock); 1; })
66#define _spin_trylock_bh(lock) ({ __LOCK_BH(lock); 1; })
67#define _spin_unlock(lock) __UNLOCK(lock)
68#define _read_unlock(lock) __UNLOCK(lock)
69#define _write_unlock(lock) __UNLOCK(lock)
70#define _spin_unlock_bh(lock) __UNLOCK_BH(lock)
71#define _write_unlock_bh(lock) __UNLOCK_BH(lock)
72#define _read_unlock_bh(lock) __UNLOCK_BH(lock)
73#define _spin_unlock_irq(lock) __UNLOCK_IRQ(lock)
74#define _read_unlock_irq(lock) __UNLOCK_IRQ(lock)
75#define _write_unlock_irq(lock) __UNLOCK_IRQ(lock)
76#define _spin_unlock_irqrestore(lock, flags) __UNLOCK_IRQRESTORE(lock, flags)
77#define _read_unlock_irqrestore(lock, flags) __UNLOCK_IRQRESTORE(lock, flags)
78#define _write_unlock_irqrestore(lock, flags) __UNLOCK_IRQRESTORE(lock, flags)
79
80#endif /* __LINUX_SPINLOCK_API_UP_H */
diff --git a/include/linux/spinlock_types.h b/include/linux/spinlock_types.h
new file mode 100644
index 0000000000..9cb51e0703
--- /dev/null
+++ b/include/linux/spinlock_types.h
@@ -0,0 +1,67 @@
1#ifndef __LINUX_SPINLOCK_TYPES_H
2#define __LINUX_SPINLOCK_TYPES_H
3
4/*
5 * include/linux/spinlock_types.h - generic spinlock type definitions
6 * and initializers
7 *
8 * portions Copyright 2005, Red Hat, Inc., Ingo Molnar
9 * Released under the General Public License (GPL).
10 */
11
12#if defined(CONFIG_SMP)
13# include <asm/spinlock_types.h>
14#else
15# include <linux/spinlock_types_up.h>
16#endif
17
18typedef struct {
19 raw_spinlock_t raw_lock;
20#if defined(CONFIG_PREEMPT) && defined(CONFIG_SMP)
21 unsigned int break_lock;
22#endif
23#ifdef CONFIG_DEBUG_SPINLOCK
24 unsigned int magic, owner_cpu;
25 void *owner;
26#endif
27} spinlock_t;
28
29#define SPINLOCK_MAGIC 0xdead4ead
30
31typedef struct {
32 raw_rwlock_t raw_lock;
33#if defined(CONFIG_PREEMPT) && defined(CONFIG_SMP)
34 unsigned int break_lock;
35#endif
36#ifdef CONFIG_DEBUG_SPINLOCK
37 unsigned int magic, owner_cpu;
38 void *owner;
39#endif
40} rwlock_t;
41
42#define RWLOCK_MAGIC 0xdeaf1eed
43
44#define SPINLOCK_OWNER_INIT ((void *)-1L)
45
46#ifdef CONFIG_DEBUG_SPINLOCK
47# define SPIN_LOCK_UNLOCKED \
48 (spinlock_t) { .raw_lock = __RAW_SPIN_LOCK_UNLOCKED, \
49 .magic = SPINLOCK_MAGIC, \
50 .owner = SPINLOCK_OWNER_INIT, \
51 .owner_cpu = -1 }
52#define RW_LOCK_UNLOCKED \
53 (rwlock_t) { .raw_lock = __RAW_RW_LOCK_UNLOCKED, \
54 .magic = RWLOCK_MAGIC, \
55 .owner = SPINLOCK_OWNER_INIT, \
56 .owner_cpu = -1 }
57#else
58# define SPIN_LOCK_UNLOCKED \
59 (spinlock_t) { .raw_lock = __RAW_SPIN_LOCK_UNLOCKED }
60#define RW_LOCK_UNLOCKED \
61 (rwlock_t) { .raw_lock = __RAW_RW_LOCK_UNLOCKED }
62#endif
63
64#define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
65#define DEFINE_RWLOCK(x) rwlock_t x = RW_LOCK_UNLOCKED
66
67#endif /* __LINUX_SPINLOCK_TYPES_H */
diff --git a/include/linux/spinlock_types_up.h b/include/linux/spinlock_types_up.h
new file mode 100644
index 0000000000..def2d173a8
--- /dev/null
+++ b/include/linux/spinlock_types_up.h
@@ -0,0 +1,51 @@
1#ifndef __LINUX_SPINLOCK_TYPES_UP_H
2#define __LINUX_SPINLOCK_TYPES_UP_H
3
4#ifndef __LINUX_SPINLOCK_TYPES_H
5# error "please don't include this file directly"
6#endif
7
8/*
9 * include/linux/spinlock_types_up.h - spinlock type definitions for UP
10 *
11 * portions Copyright 2005, Red Hat, Inc., Ingo Molnar
12 * Released under the General Public License (GPL).
13 */
14
15#ifdef CONFIG_DEBUG_SPINLOCK
16
17typedef struct {
18 volatile unsigned int slock;
19} raw_spinlock_t;
20
21#define __RAW_SPIN_LOCK_UNLOCKED { 1 }
22
23#else
24
25/*
26 * All gcc 2.95 versions and early versions of 2.96 have a nasty bug
27 * with empty initializers.
28 */
29#if (__GNUC__ > 2)
30typedef struct { } raw_spinlock_t;
31
32#define __RAW_SPIN_LOCK_UNLOCKED { }
33#else
34typedef struct { int gcc_is_buggy; } raw_spinlock_t;
35#define __RAW_SPIN_LOCK_UNLOCKED (raw_spinlock_t) { 0 }
36#endif
37
38#endif
39
40#if (__GNUC__ > 2)
41typedef struct {
42 /* no debug version on UP */
43} raw_rwlock_t;
44
45#define __RAW_RW_LOCK_UNLOCKED { }
46#else
47typedef struct { int gcc_is_buggy; } raw_rwlock_t;
48#define __RAW_RW_LOCK_UNLOCKED (raw_rwlock_t) { 0 }
49#endif
50
51#endif /* __LINUX_SPINLOCK_TYPES_UP_H */
diff --git a/include/linux/spinlock_up.h b/include/linux/spinlock_up.h
new file mode 100644
index 0000000000..31accf2f0b
--- /dev/null
+++ b/include/linux/spinlock_up.h
@@ -0,0 +1,74 @@
1#ifndef __LINUX_SPINLOCK_UP_H
2#define __LINUX_SPINLOCK_UP_H
3
4#ifndef __LINUX_SPINLOCK_H
5# error "please don't include this file directly"
6#endif
7
8/*
9 * include/linux/spinlock_up.h - UP-debug version of spinlocks.
10 *
11 * portions Copyright 2005, Red Hat, Inc., Ingo Molnar
12 * Released under the General Public License (GPL).
13 *
14 * In the debug case, 1 means unlocked, 0 means locked. (the values
15 * are inverted, to catch initialization bugs)
16 *
17 * No atomicity anywhere, we are on UP.
18 */
19
20#ifdef CONFIG_DEBUG_SPINLOCK
21
22#define __raw_spin_is_locked(x) ((x)->slock == 0)
23
24static inline void __raw_spin_lock(raw_spinlock_t *lock)
25{
26 lock->slock = 0;
27}
28
29static inline void
30__raw_spin_lock_flags(raw_spinlock_t *lock, unsigned long flags)
31{
32 local_irq_save(flags);
33 lock->slock = 0;
34}
35
36static inline int __raw_spin_trylock(raw_spinlock_t *lock)
37{
38 char oldval = lock->slock;
39
40 lock->slock = 0;
41
42 return oldval > 0;
43}
44
45static inline void __raw_spin_unlock(raw_spinlock_t *lock)
46{
47 lock->slock = 1;
48}
49
50/*
51 * Read-write spinlocks. No debug version.
52 */
53#define __raw_read_lock(lock) do { (void)(lock); } while (0)
54#define __raw_write_lock(lock) do { (void)(lock); } while (0)
55#define __raw_read_trylock(lock) ({ (void)(lock); 1; })
56#define __raw_write_trylock(lock) ({ (void)(lock); 1; })
57#define __raw_read_unlock(lock) do { (void)(lock); } while (0)
58#define __raw_write_unlock(lock) do { (void)(lock); } while (0)
59
60#else /* DEBUG_SPINLOCK */
61#define __raw_spin_is_locked(lock) ((void)(lock), 0)
62/* for sched.c and kernel_lock.c: */
63# define __raw_spin_lock(lock) do { (void)(lock); } while (0)
64# define __raw_spin_unlock(lock) do { (void)(lock); } while (0)
65# define __raw_spin_trylock(lock) ({ (void)(lock); 1; })
66#endif /* DEBUG_SPINLOCK */
67
68#define __raw_read_can_lock(lock) (((void)(lock), 1))
69#define __raw_write_can_lock(lock) (((void)(lock), 1))
70
71#define __raw_spin_unlock_wait(lock) \
72 do { cpu_relax(); } while (__raw_spin_is_locked(lock))
73
74#endif /* __LINUX_SPINLOCK_UP_H */
diff --git a/include/linux/time.h b/include/linux/time.h
index c10d4c21c1..8e83f4e778 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -28,17 +28,10 @@ struct timezone {
28#ifdef __KERNEL__ 28#ifdef __KERNEL__
29 29
30/* Parameters used to convert the timespec values */ 30/* Parameters used to convert the timespec values */
31#ifndef USEC_PER_SEC 31#define MSEC_PER_SEC (1000L)
32#define USEC_PER_SEC (1000000L) 32#define USEC_PER_SEC (1000000L)
33#endif
34
35#ifndef NSEC_PER_SEC
36#define NSEC_PER_SEC (1000000000L) 33#define NSEC_PER_SEC (1000000000L)
37#endif
38
39#ifndef NSEC_PER_USEC
40#define NSEC_PER_USEC (1000L) 34#define NSEC_PER_USEC (1000L)
41#endif
42 35
43static __inline__ int timespec_equal(struct timespec *a, struct timespec *b) 36static __inline__ int timespec_equal(struct timespec *a, struct timespec *b)
44{ 37{
diff --git a/include/linux/timer.h b/include/linux/timer.h
index 221f81ac20..3340f3bd13 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -32,6 +32,10 @@ extern struct timer_base_s __init_timer_base;
32 .magic = TIMER_MAGIC, \ 32 .magic = TIMER_MAGIC, \
33 } 33 }
34 34
35#define DEFINE_TIMER(_name, _function, _expires, _data) \
36 struct timer_list _name = \
37 TIMER_INITIALIZER(_function, _expires, _data)
38
35void fastcall init_timer(struct timer_list * timer); 39void fastcall init_timer(struct timer_list * timer);
36 40
37/*** 41/***
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 59ff42c629..1267f88ece 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -74,7 +74,8 @@ struct screen_info {
74 u16 vesapm_off; /* 0x30 */ 74 u16 vesapm_off; /* 0x30 */
75 u16 pages; /* 0x32 */ 75 u16 pages; /* 0x32 */
76 u16 vesa_attributes; /* 0x34 */ 76 u16 vesa_attributes; /* 0x34 */
77 /* 0x36 -- 0x3f reserved for future expansion */ 77 u32 capabilities; /* 0x36 */
78 /* 0x3a -- 0x3f reserved for future expansion */
78}; 79};
79 80
80extern struct screen_info screen_info; 81extern struct screen_info screen_info;
diff --git a/include/linux/videodev.h b/include/linux/videodev.h
index 9d6fbde3d2..1cc8c31b79 100644
--- a/include/linux/videodev.h
+++ b/include/linux/videodev.h
@@ -3,7 +3,6 @@
3 3
4#include <linux/compiler.h> 4#include <linux/compiler.h>
5#include <linux/types.h> 5#include <linux/types.h>
6#include <linux/version.h>
7 6
8#define HAVE_V4L2 1 7#define HAVE_V4L2 1
9#include <linux/videodev2.h> 8#include <linux/videodev2.h>
@@ -29,7 +28,6 @@ struct video_device
29 void (*release)(struct video_device *vfd); 28 void (*release)(struct video_device *vfd);
30 29
31 30
32#if 1 /* to be removed in 2.7.x */
33 /* obsolete -- fops->owner is used instead */ 31 /* obsolete -- fops->owner is used instead */
34 struct module *owner; 32 struct module *owner;
35 /* dev->driver_data will be used instead some day. 33 /* dev->driver_data will be used instead some day.
@@ -37,7 +35,6 @@ struct video_device
37 * so the switch over will be transparent for you. 35 * so the switch over will be transparent for you.
38 * Or use {pci|usb}_{get|set}_drvdata() directly. */ 36 * Or use {pci|usb}_{get|set}_drvdata() directly. */
39 void *priv; 37 void *priv;
40#endif
41 38
42 /* for videodev.c intenal usage -- please don't touch */ 39 /* for videodev.c intenal usage -- please don't touch */
43 int users; /* video_exclusive_{open|close} ... */ 40 int users; /* video_exclusive_{open|close} ... */
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index acbfc52557..f623a33b9a 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -270,7 +270,6 @@ struct v4l2_timecode
270/* The above is based on SMPTE timecodes */ 270/* The above is based on SMPTE timecodes */
271 271
272 272
273#if 1
274/* 273/*
275 * M P E G C O M P R E S S I O N P A R A M E T E R S 274 * M P E G C O M P R E S S I O N P A R A M E T E R S
276 * 275 *
@@ -357,7 +356,6 @@ struct v4l2_mpeg_compression {
357 /* I don't expect the above being perfect yet ;) */ 356 /* I don't expect the above being perfect yet ;) */
358 __u32 reserved_5[8]; 357 __u32 reserved_5[8];
359}; 358};
360#endif
361 359
362struct v4l2_jpegcompression 360struct v4l2_jpegcompression
363{ 361{
@@ -871,10 +869,8 @@ struct v4l2_streamparm
871#define VIDIOC_ENUM_FMT _IOWR ('V', 2, struct v4l2_fmtdesc) 869#define VIDIOC_ENUM_FMT _IOWR ('V', 2, struct v4l2_fmtdesc)
872#define VIDIOC_G_FMT _IOWR ('V', 4, struct v4l2_format) 870#define VIDIOC_G_FMT _IOWR ('V', 4, struct v4l2_format)
873#define VIDIOC_S_FMT _IOWR ('V', 5, struct v4l2_format) 871#define VIDIOC_S_FMT _IOWR ('V', 5, struct v4l2_format)
874#if 1 /* experimental */
875#define VIDIOC_G_MPEGCOMP _IOR ('V', 6, struct v4l2_mpeg_compression) 872#define VIDIOC_G_MPEGCOMP _IOR ('V', 6, struct v4l2_mpeg_compression)
876#define VIDIOC_S_MPEGCOMP _IOW ('V', 7, struct v4l2_mpeg_compression) 873#define VIDIOC_S_MPEGCOMP _IOW ('V', 7, struct v4l2_mpeg_compression)
877#endif
878#define VIDIOC_REQBUFS _IOWR ('V', 8, struct v4l2_requestbuffers) 874#define VIDIOC_REQBUFS _IOWR ('V', 8, struct v4l2_requestbuffers)
879#define VIDIOC_QUERYBUF _IOWR ('V', 9, struct v4l2_buffer) 875#define VIDIOC_QUERYBUF _IOWR ('V', 9, struct v4l2_buffer)
880#define VIDIOC_G_FBUF _IOR ('V', 10, struct v4l2_framebuffer) 876#define VIDIOC_G_FBUF _IOR ('V', 10, struct v4l2_framebuffer)
diff --git a/include/linux/writeback.h b/include/linux/writeback.h
index 542dbaee65..343d883d69 100644
--- a/include/linux/writeback.h
+++ b/include/linux/writeback.h
@@ -109,8 +109,6 @@ int pdflush_operation(void (*fn)(unsigned long), unsigned long arg0);
109int do_writepages(struct address_space *mapping, struct writeback_control *wbc); 109int do_writepages(struct address_space *mapping, struct writeback_control *wbc);
110int sync_page_range(struct inode *inode, struct address_space *mapping, 110int sync_page_range(struct inode *inode, struct address_space *mapping,
111 loff_t pos, size_t count); 111 loff_t pos, size_t count);
112int sync_page_range_nolock(struct inode *inode, struct address_space
113 *mapping, loff_t pos, size_t count);
114 112
115/* pdflush.c */ 113/* pdflush.c */
116extern int nr_pdflush_threads; /* Global so it can be exported to sysctl 114extern int nr_pdflush_threads; /* Global so it can be exported to sysctl
diff --git a/include/media/audiochip.h b/include/media/audiochip.h
index cd831168fd..a7ceee9fc5 100644
--- a/include/media/audiochip.h
+++ b/include/media/audiochip.h
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: audiochip.h,v 1.5 2005/06/16 22:59:16 hhackmann Exp $
3 */ 2 */
4 3
5#ifndef AUDIOCHIP_H 4#ifndef AUDIOCHIP_H
diff --git a/include/media/id.h b/include/media/id.h
index 801ddef301..6d02c94cdc 100644
--- a/include/media/id.h
+++ b/include/media/id.h
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: id.h,v 1.4 2005/06/12 04:19:19 mchehab Exp $
3 */ 2 */
4 3
5/* FIXME: this temporarely, until these are included in linux/i2c-id.h */ 4/* FIXME: this temporarely, until these are included in linux/i2c-id.h */
diff --git a/include/media/ir-common.h b/include/media/ir-common.h
index 698670547f..01b56822df 100644
--- a/include/media/ir-common.h
+++ b/include/media/ir-common.h
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: ir-common.h,v 1.9 2005/05/15 19:01:26 mchehab Exp $
3 * 2 *
4 * some common structs and functions to handle infrared remotes via 3 * some common structs and functions to handle infrared remotes via
5 * input layer ... 4 * input layer ...
@@ -21,11 +20,11 @@
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */ 21 */
23 22
24#include <linux/version.h>
25#include <linux/input.h> 23#include <linux/input.h>
26 24
27 25
28#define IR_TYPE_RC5 1 26#define IR_TYPE_RC5 1
27#define IR_TYPE_PD 2 /* Pulse distance encoded IR */
29#define IR_TYPE_OTHER 99 28#define IR_TYPE_OTHER 99
30 29
31#define IR_KEYTAB_TYPE u32 30#define IR_KEYTAB_TYPE u32
@@ -60,6 +59,7 @@ void ir_input_keydown(struct input_dev *dev, struct ir_input_state *ir,
60u32 ir_extract_bits(u32 data, u32 mask); 59u32 ir_extract_bits(u32 data, u32 mask);
61int ir_dump_samples(u32 *samples, int count); 60int ir_dump_samples(u32 *samples, int count);
62int ir_decode_biphase(u32 *samples, int count, int low, int high); 61int ir_decode_biphase(u32 *samples, int count, int low, int high);
62int ir_decode_pulsedistance(u32 *samples, int count, int low, int high);
63 63
64/* 64/*
65 * Local variables: 65 * Local variables:
diff --git a/include/media/saa7146.h b/include/media/saa7146.h
index 3dfb8d670e..2a897c3a6a 100644
--- a/include/media/saa7146.h
+++ b/include/media/saa7146.h
@@ -1,7 +1,6 @@
1#ifndef __SAA7146__ 1#ifndef __SAA7146__
2#define __SAA7146__ 2#define __SAA7146__
3 3
4#include <linux/version.h> /* for version macros */
5#include <linux/module.h> /* for module-version */ 4#include <linux/module.h> /* for module-version */
6#include <linux/delay.h> /* for delay-stuff */ 5#include <linux/delay.h> /* for delay-stuff */
7#include <linux/slab.h> /* for kmalloc/kfree */ 6#include <linux/slab.h> /* for kmalloc/kfree */
@@ -15,12 +14,7 @@
15#include <linux/vmalloc.h> /* for vmalloc() */ 14#include <linux/vmalloc.h> /* for vmalloc() */
16#include <linux/mm.h> /* for vmalloc_to_page() */ 15#include <linux/mm.h> /* for vmalloc_to_page() */
17 16
18/* ugly, but necessary to build the dvb stuff under 2.4. */ 17#define SAA7146_VERSION_CODE 0x000500 /* 0.5.0 */
19#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,51)
20 #include "dvb_functions.h"
21#endif
22
23#define SAA7146_VERSION_CODE KERNEL_VERSION(0,5,0)
24 18
25#define saa7146_write(sxy,adr,dat) writel((dat),(sxy->mem+(adr))) 19#define saa7146_write(sxy,adr,dat) writel((dat),(sxy->mem+(adr)))
26#define saa7146_read(sxy,adr) readl(sxy->mem+(adr)) 20#define saa7146_read(sxy,adr) readl(sxy->mem+(adr))
@@ -33,13 +27,8 @@ extern unsigned int saa7146_debug;
33 #define DEBUG_VARIABLE saa7146_debug 27 #define DEBUG_VARIABLE saa7146_debug
34#endif 28#endif
35 29
36#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,51)
37#define DEBUG_PROLOG printk("%s: %s(): ",__stringify(KBUILD_BASENAME),__FUNCTION__)
38#define INFO(x) { printk("%s: ",__stringify(KBUILD_BASENAME)); printk x; }
39#else
40#define DEBUG_PROLOG printk("%s: %s(): ",__stringify(KBUILD_MODNAME),__FUNCTION__) 30#define DEBUG_PROLOG printk("%s: %s(): ",__stringify(KBUILD_MODNAME),__FUNCTION__)
41#define INFO(x) { printk("%s: ",__stringify(KBUILD_MODNAME)); printk x; } 31#define INFO(x) { printk("%s: ",__stringify(KBUILD_MODNAME)); printk x; }
42#endif
43 32
44#define ERR(x) { DEBUG_PROLOG; printk x; } 33#define ERR(x) { DEBUG_PROLOG; printk x; }
45 34
diff --git a/include/media/tuner.h b/include/media/tuner.h
index eeaa15ddee..4ad08e24a1 100644
--- a/include/media/tuner.h
+++ b/include/media/tuner.h
@@ -1,6 +1,4 @@
1 1/*
2/* $Id: tuner.h,v 1.45 2005/07/28 18:41:21 mchehab Exp $
3 *
4 tuner.h - definition for different tuners 2 tuner.h - definition for different tuners
5 3
6 Copyright (C) 1997 Markus Schroeder (schroedm@uni-duesseldorf.de) 4 Copyright (C) 1997 Markus Schroeder (schroedm@uni-duesseldorf.de)
@@ -28,88 +26,90 @@
28 26
29#define ADDR_UNSET (255) 27#define ADDR_UNSET (255)
30 28
31#define TUNER_TEMIC_PAL 0 /* 4002 FH5 (3X 7756, 9483) */ 29#define TUNER_TEMIC_PAL 0 /* 4002 FH5 (3X 7756, 9483) */
32#define TUNER_PHILIPS_PAL_I 1 30#define TUNER_PHILIPS_PAL_I 1
33#define TUNER_PHILIPS_NTSC 2 31#define TUNER_PHILIPS_NTSC 2
34#define TUNER_PHILIPS_SECAM 3 /* you must actively select B/G, L, L` */ 32#define TUNER_PHILIPS_SECAM 3 /* you must actively select B/G, L, L` */
35 33
36#define TUNER_ABSENT 4 34#define TUNER_ABSENT 4
37#define TUNER_PHILIPS_PAL 5 35#define TUNER_PHILIPS_PAL 5
38#define TUNER_TEMIC_NTSC 6 /* 4032 FY5 (3X 7004, 9498, 9789) */ 36#define TUNER_TEMIC_NTSC 6 /* 4032 FY5 (3X 7004, 9498, 9789) */
39#define TUNER_TEMIC_PAL_I 7 /* 4062 FY5 (3X 8501, 9957) */ 37#define TUNER_TEMIC_PAL_I 7 /* 4062 FY5 (3X 8501, 9957) */
40 38
41#define TUNER_TEMIC_4036FY5_NTSC 8 /* 4036 FY5 (3X 1223, 1981, 7686) */ 39#define TUNER_TEMIC_4036FY5_NTSC 8 /* 4036 FY5 (3X 1223, 1981, 7686) */
42#define TUNER_ALPS_TSBH1_NTSC 9 40#define TUNER_ALPS_TSBH1_NTSC 9
43#define TUNER_ALPS_TSBE1_PAL 10 41#define TUNER_ALPS_TSBE1_PAL 10
44#define TUNER_ALPS_TSBB5_PAL_I 11 42#define TUNER_ALPS_TSBB5_PAL_I 11
45 43
46#define TUNER_ALPS_TSBE5_PAL 12 44#define TUNER_ALPS_TSBE5_PAL 12
47#define TUNER_ALPS_TSBC5_PAL 13 45#define TUNER_ALPS_TSBC5_PAL 13
48#define TUNER_TEMIC_4006FH5_PAL 14 /* 4006 FH5 (3X 9500, 9501, 7291) */ 46#define TUNER_TEMIC_4006FH5_PAL 14 /* 4006 FH5 (3X 9500, 9501, 7291) */
49#define TUNER_ALPS_TSHC6_NTSC 15 47#define TUNER_ALPS_TSHC6_NTSC 15
50 48
51#define TUNER_TEMIC_PAL_DK 16 /* 4016 FY5 (3X 1392, 1393) */ 49#define TUNER_TEMIC_PAL_DK 16 /* 4016 FY5 (3X 1392, 1393) */
52#define TUNER_PHILIPS_NTSC_M 17 50#define TUNER_PHILIPS_NTSC_M 17
53#define TUNER_TEMIC_4066FY5_PAL_I 18 /* 4066 FY5 (3X 7032, 7035) */ 51#define TUNER_TEMIC_4066FY5_PAL_I 18 /* 4066 FY5 (3X 7032, 7035) */
54#define TUNER_TEMIC_4006FN5_MULTI_PAL 19 /* B/G, I and D/K autodetected (3X 7595, 7606, 7657)*/ 52#define TUNER_TEMIC_4006FN5_MULTI_PAL 19 /* B/G, I and D/K autodetected (3X 7595, 7606, 7657) */
55 53
56#define TUNER_TEMIC_4009FR5_PAL 20 /* incl. FM radio (3X 7607, 7488, 7711)*/ 54#define TUNER_TEMIC_4009FR5_PAL 20 /* incl. FM radio (3X 7607, 7488, 7711) */
57#define TUNER_TEMIC_4039FR5_NTSC 21 /* incl. FM radio (3X 7246, 7578, 7732)*/ 55#define TUNER_TEMIC_4039FR5_NTSC 21 /* incl. FM radio (3X 7246, 7578, 7732) */
58#define TUNER_TEMIC_4046FM5 22 /* you must actively select B/G, D/K, I, L, L` ! (3X 7804, 7806, 8103, 8104)*/ 56#define TUNER_TEMIC_4046FM5 22 /* you must actively select B/G, D/K, I, L, L` ! (3X 7804, 7806, 8103, 8104) */
59#define TUNER_PHILIPS_PAL_DK 23 57#define TUNER_PHILIPS_PAL_DK 23
60 58
61#define TUNER_PHILIPS_FQ1216ME 24 /* you must actively select B/G/D/K, I, L, L` */ 59#define TUNER_PHILIPS_FQ1216ME 24 /* you must actively select B/G/D/K, I, L, L` */
62#define TUNER_LG_PAL_I_FM 25 60#define TUNER_LG_PAL_I_FM 25
63#define TUNER_LG_PAL_I 26 61#define TUNER_LG_PAL_I 26
64#define TUNER_LG_NTSC_FM 27 62#define TUNER_LG_NTSC_FM 27
65 63
66#define TUNER_LG_PAL_FM 28 64#define TUNER_LG_PAL_FM 28
67#define TUNER_LG_PAL 29 65#define TUNER_LG_PAL 29
68#define TUNER_TEMIC_4009FN5_MULTI_PAL_FM 30 /* B/G, I and D/K autodetected (3X 8155, 8160, 8163)*/ 66#define TUNER_TEMIC_4009FN5_MULTI_PAL_FM 30 /* B/G, I and D/K autodetected (3X 8155, 8160, 8163) */
69#define TUNER_SHARP_2U5JF5540_NTSC 31 67#define TUNER_SHARP_2U5JF5540_NTSC 31
70 68
71#define TUNER_Samsung_PAL_TCPM9091PD27 32 69#define TUNER_Samsung_PAL_TCPM9091PD27 32
72#define TUNER_MT2032 33 70#define TUNER_MT2032 33
73#define TUNER_TEMIC_4106FH5 34 /* 4106 FH5 (3X 7808, 7865)*/ 71#define TUNER_TEMIC_4106FH5 34 /* 4106 FH5 (3X 7808, 7865) */
74#define TUNER_TEMIC_4012FY5 35 /* 4012 FY5 (3X 0971, 1099)*/ 72#define TUNER_TEMIC_4012FY5 35 /* 4012 FY5 (3X 0971, 1099) */
75 73
76#define TUNER_TEMIC_4136FY5 36 /* 4136 FY5 (3X 7708, 7746)*/ 74#define TUNER_TEMIC_4136FY5 36 /* 4136 FY5 (3X 7708, 7746) */
77#define TUNER_LG_PAL_NEW_TAPC 37 75#define TUNER_LG_PAL_NEW_TAPC 37
78#define TUNER_PHILIPS_FM1216ME_MK3 38 76#define TUNER_PHILIPS_FM1216ME_MK3 38
79#define TUNER_LG_NTSC_NEW_TAPC 39 77#define TUNER_LG_NTSC_NEW_TAPC 39
80 78
81#define TUNER_HITACHI_NTSC 40 79#define TUNER_HITACHI_NTSC 40
82#define TUNER_PHILIPS_PAL_MK 41 80#define TUNER_PHILIPS_PAL_MK 41
83#define TUNER_PHILIPS_ATSC 42 81#define TUNER_PHILIPS_ATSC 42
84#define TUNER_PHILIPS_FM1236_MK3 43 82#define TUNER_PHILIPS_FM1236_MK3 43
85 83
86#define TUNER_PHILIPS_4IN1 44 /* ATI TV Wonder Pro - Conexant */ 84#define TUNER_PHILIPS_4IN1 44 /* ATI TV Wonder Pro - Conexant */
87/* Microtune mergeged with Temic 12/31/1999 partially financed by Alps - these may be similar to Temic */ 85/* Microtune mergeged with Temic 12/31/1999 partially financed by Alps - these may be similar to Temic */
88#define TUNER_MICROTUNE_4049FM5 45 86#define TUNER_MICROTUNE_4049FM5 45
89#define TUNER_LG_NTSC_TAPE 47 87#define TUNER_MICROTUNE_4042_FI5 46
90 88#define TUNER_LG_NTSC_TAPE 47
91#define TUNER_TNF_8831BGFF 48 89
92#define TUNER_MICROTUNE_4042FI5 49 /* DViCO FusionHDTV 3 Gold-Q - 4042 FI5 (3X 8147) */ 90#define TUNER_TNF_8831BGFF 48
93#define TUNER_TCL_2002N 50 91#define TUNER_MICROTUNE_4042FI5 49 /* DViCO FusionHDTV 3 Gold-Q - 4042 FI5 (3X 8147) */
94#define TUNER_PHILIPS_FM1256_IH3 51 92#define TUNER_TCL_2002N 50
95 93#define TUNER_PHILIPS_FM1256_IH3 51
96#define TUNER_THOMSON_DTT7610 52 94
97#define TUNER_PHILIPS_FQ1286 53 95#define TUNER_THOMSON_DTT7610 52
98#define TUNER_PHILIPS_TDA8290 54 96#define TUNER_PHILIPS_FQ1286 53
99#define TUNER_LG_PAL_TAPE 55 /* Hauppauge PVR-150 PAL */ 97#define TUNER_PHILIPS_TDA8290 54
100 98#define TUNER_LG_PAL_TAPE 55 /* Hauppauge PVR-150 PAL */
101#define TUNER_PHILIPS_FQ1216AME_MK4 56 /* Hauppauge PVR-150 PAL */ 99
102#define TUNER_PHILIPS_FQ1236A_MK4 57 /* Hauppauge PVR-500MCE NTSC */ 100#define TUNER_PHILIPS_FQ1216AME_MK4 56 /* Hauppauge PVR-150 PAL */
103 101#define TUNER_PHILIPS_FQ1236A_MK4 57 /* Hauppauge PVR-500MCE NTSC */
104#define TUNER_YMEC_TVF_8531MF 58 102#define TUNER_YMEC_TVF_8531MF 58
105#define TUNER_YMEC_TVF_5533MF 59 /* Pixelview Pro Ultra NTSC */ 103#define TUNER_YMEC_TVF_5533MF 59 /* Pixelview Pro Ultra NTSC */
106#define TUNER_THOMSON_DTT7611 60 /* DViCO FusionHDTV 3 Gold-T */ 104
107#define TUNER_TENA_9533_DI 61 105#define TUNER_THOMSON_DTT7611 60 /* DViCO FusionHDTV 3 Gold-T */
108 106#define TUNER_TENA_9533_DI 61
109#define TUNER_TEA5767 62 /* Only FM Radio Tuner */ 107#define TUNER_TEA5767 62 /* Only FM Radio Tuner */
110#define TUNER_PHILIPS_FMD1216ME_MK3 63 108#define TUNER_PHILIPS_FMD1216ME_MK3 63
111#define TUNER_LG_TDVS_H062F 64 /* DViCO FusionHDTV 5 */ 109
112#define TUNER_YMEC_TVF66T5_B_DFF 65 /* Acorp Y878F */ 110#define TUNER_LG_TDVS_H062F 64 /* DViCO FusionHDTV 5 */
111#define TUNER_YMEC_TVF66T5_B_DFF 65 /* Acorp Y878F */
112#define TUNER_LG_NTSC_TALN_MINI 66
113 113
114#define NOTUNER 0 114#define NOTUNER 0
115#define PAL 1 /* PAL_BG */ 115#define PAL 1 /* PAL_BG */
@@ -117,7 +117,7 @@
117#define NTSC 3 117#define NTSC 3
118#define SECAM 4 118#define SECAM 4
119#define ATSC 5 119#define ATSC 5
120#define RADIO 6 120#define RADIO 6
121 121
122#define NoTuner 0 122#define NoTuner 0
123#define Philips 1 123#define Philips 1
@@ -134,6 +134,7 @@
134#define THOMSON 12 134#define THOMSON 12
135 135
136#define TUNER_SET_TYPE_ADDR _IOW('T',3,int) 136#define TUNER_SET_TYPE_ADDR _IOW('T',3,int)
137#define TUNER_SET_STANDBY _IOW('T',4,int)
137#define TDA9887_SET_CONFIG _IOW('t',5,int) 138#define TDA9887_SET_CONFIG _IOW('t',5,int)
138 139
139/* tv card specific */ 140/* tv card specific */
@@ -153,9 +154,6 @@
153 154
154#ifdef __KERNEL__ 155#ifdef __KERNEL__
155 156
156#define I2C_ADDR_TDA8290 0x4b
157#define I2C_ADDR_TDA8275 0x61
158
159enum tuner_mode { 157enum tuner_mode {
160 T_UNINITIALIZED = 0, 158 T_UNINITIALIZED = 0,
161 T_RADIO = 1 << V4L2_TUNER_RADIO, 159 T_RADIO = 1 << V4L2_TUNER_RADIO,
@@ -165,21 +163,21 @@ enum tuner_mode {
165}; 163};
166 164
167struct tuner_setup { 165struct tuner_setup {
168 unsigned short addr; 166 unsigned short addr;
169 unsigned int type; 167 unsigned int type;
170 unsigned int mode_mask; 168 unsigned int mode_mask;
171}; 169};
172 170
173struct tuner { 171struct tuner {
174 /* device */ 172 /* device */
175 struct i2c_client i2c; 173 struct i2c_client i2c;
176 174
177 unsigned int type; /* chip type */ 175 unsigned int type; /* chip type */
178 176
179 unsigned int mode; 177 unsigned int mode;
180 unsigned int mode_mask; /* Combination of allowable modes */ 178 unsigned int mode_mask; /* Combination of allowable modes */
181 179
182 unsigned int freq; /* keep track of the current settings */ 180 unsigned int freq; /* keep track of the current settings */
183 unsigned int audmode; 181 unsigned int audmode;
184 v4l2_std_id std; 182 v4l2_std_id std;
185 183
@@ -198,6 +196,7 @@ struct tuner {
198 void (*radio_freq)(struct i2c_client *c, unsigned int freq); 196 void (*radio_freq)(struct i2c_client *c, unsigned int freq);
199 int (*has_signal)(struct i2c_client *c); 197 int (*has_signal)(struct i2c_client *c);
200 int (*is_stereo)(struct i2c_client *c); 198 int (*is_stereo)(struct i2c_client *c);
199 void (*standby)(struct i2c_client *c);
201}; 200};
202 201
203extern unsigned int tuner_debug; 202extern unsigned int tuner_debug;
@@ -209,16 +208,20 @@ extern int tea5767_tuner_init(struct i2c_client *c);
209extern int default_tuner_init(struct i2c_client *c); 208extern int default_tuner_init(struct i2c_client *c);
210extern int tea5767_autodetection(struct i2c_client *c); 209extern int tea5767_autodetection(struct i2c_client *c);
211 210
212#define tuner_warn(fmt, arg...) \ 211#define tuner_warn(fmt, arg...) do {\
213 dev_printk(KERN_WARNING , &t->i2c.dev , fmt , ## arg) 212 printk(KERN_WARNING "%s %d-%04x: " fmt, t->i2c.driver->name, \
214#define tuner_info(fmt, arg...) \ 213 t->i2c.adapter->nr, t->i2c.addr , ##arg); } while (0)
215 dev_printk(KERN_INFO , &t->i2c.dev , fmt , ## arg) 214#define tuner_info(fmt, arg...) do {\
216#define tuner_dbg(fmt, arg...) \ 215 printk(KERN_INFO "%s %d-%04x: " fmt, t->i2c.driver->name, \
217 if (tuner_debug) dev_printk(KERN_DEBUG , &t->i2c.dev , fmt , ## arg) 216 t->i2c.adapter->nr, t->i2c.addr , ##arg); } while (0)
217#define tuner_dbg(fmt, arg...) do {\
218 if (tuner_debug) \
219 printk(KERN_DEBUG "%s %d-%04x: " fmt, t->i2c.driver->name, \
220 t->i2c.adapter->nr, t->i2c.addr , ##arg); } while (0)
218 221
219#endif /* __KERNEL__ */ 222#endif /* __KERNEL__ */
220 223
221#endif 224#endif /* _TUNER_H */
222 225
223/* 226/*
224 * Overrides for Emacs so that we follow Linus's tabbing style. 227 * Overrides for Emacs so that we follow Linus's tabbing style.
diff --git a/include/media/tveeprom.h b/include/media/tveeprom.h
index 854a2c2f10..e2035c7da0 100644
--- a/include/media/tveeprom.h
+++ b/include/media/tveeprom.h
@@ -1,18 +1,21 @@
1/* 1/*
2 * $Id: tveeprom.h,v 1.2 2005/06/12 04:19:19 mchehab Exp $
3 */ 2 */
4 3
5struct tveeprom { 4struct tveeprom {
6 u32 has_radio; 5 u32 has_radio;
6 u32 has_ir; /* 0: no IR, 1: IR present, 2: unknown */
7 7
8 u32 tuner_type; 8 u32 tuner_type;
9 u32 tuner_formats; 9 u32 tuner_formats;
10 10
11 u32 tuner2_type;
12 u32 tuner2_formats;
13
11 u32 digitizer; 14 u32 digitizer;
12 u32 digitizer_formats; 15 u32 digitizer_formats;
13 16
14 u32 audio_processor; 17 u32 audio_processor;
15 /* a_p_fmts? */ 18 u32 decoder_processor;
16 19
17 u32 model; 20 u32 model;
18 u32 revision; 21 u32 revision;
@@ -20,7 +23,7 @@ struct tveeprom {
20 char rev_str[5]; 23 char rev_str[5];
21}; 24};
22 25
23void tveeprom_hauppauge_analog(struct tveeprom *tvee, 26void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
24 unsigned char *eeprom_data); 27 unsigned char *eeprom_data);
25 28
26int tveeprom_read(struct i2c_client *c, unsigned char *eedata, int len); 29int tveeprom_read(struct i2c_client *c, unsigned char *eedata, int len);
diff --git a/include/media/video-buf.h b/include/media/video-buf.h
index ae6da6de98..ae8d7a0004 100644
--- a/include/media/video-buf.h
+++ b/include/media/video-buf.h
@@ -1,5 +1,4 @@
1/* 1/*
2 * $Id: video-buf.h,v 1.9 2004/11/07 13:17:15 kraxel Exp $
3 * 2 *
4 * generic helper functions for video4linux capture buffers, to handle 3 * generic helper functions for video4linux capture buffers, to handle
5 * memory management and PCI DMA. Right now bttv + saa7134 use it. 4 * memory management and PCI DMA. Right now bttv + saa7134 use it.
diff --git a/include/pcmcia/ds.h b/include/pcmcia/ds.h
index b707a60335..cb8b6e6ce6 100644
--- a/include/pcmcia/ds.h
+++ b/include/pcmcia/ds.h
@@ -151,6 +151,8 @@ struct pcmcia_device {
151 uniquely define a pcmcia_device */ 151 uniquely define a pcmcia_device */
152 struct pcmcia_socket *socket; 152 struct pcmcia_socket *socket;
153 153
154 char *devname;
155
154 u8 device_no; 156 u8 device_no;
155 157
156 /* the hardware "function" device; certain subdevices can 158 /* the hardware "function" device; certain subdevices can
diff --git a/include/rdma/ib_cm.h b/include/rdma/ib_cm.h
index 77fe903920..5308683c8c 100644
--- a/include/rdma/ib_cm.h
+++ b/include/rdma/ib_cm.h
@@ -290,6 +290,7 @@ struct ib_cm_id {
290 enum ib_cm_lap_state lap_state; /* internal CM/debug use */ 290 enum ib_cm_lap_state lap_state; /* internal CM/debug use */
291 __be32 local_id; 291 __be32 local_id;
292 __be32 remote_id; 292 __be32 remote_id;
293 u32 remote_cm_qpn; /* 1 unless redirected */
293}; 294};
294 295
295/** 296/**
diff --git a/include/rdma/ib_mad.h b/include/rdma/ib_mad.h
index fc6b1c18ff..53184a38fd 100644
--- a/include/rdma/ib_mad.h
+++ b/include/rdma/ib_mad.h
@@ -173,6 +173,27 @@ struct ib_vendor_mad {
173 u8 data[216]; 173 u8 data[216];
174}; 174};
175 175
176struct ib_class_port_info
177{
178 u8 base_version;
179 u8 class_version;
180 __be16 capability_mask;
181 u8 reserved[3];
182 u8 resp_time_value;
183 u8 redirect_gid[16];
184 __be32 redirect_tcslfl;
185 __be16 redirect_lid;
186 __be16 redirect_pkey;
187 __be32 redirect_qp;
188 __be32 redirect_qkey;
189 u8 trap_gid[16];
190 __be32 trap_tcslfl;
191 __be16 trap_lid;
192 __be16 trap_pkey;
193 __be32 trap_hlqp;
194 __be32 trap_qkey;
195};
196
176/** 197/**
177 * ib_mad_send_buf - MAD data buffer and work request for sends. 198 * ib_mad_send_buf - MAD data buffer and work request for sends.
178 * @mad: References an allocated MAD data buffer. The size of the data 199 * @mad: References an allocated MAD data buffer. The size of the data
diff --git a/include/rdma/ib_sa.h b/include/rdma/ib_sa.h
index c022edfc49..a7555c800e 100644
--- a/include/rdma/ib_sa.h
+++ b/include/rdma/ib_sa.h
@@ -46,7 +46,36 @@ enum {
46 46
47 IB_SA_METHOD_GET_TABLE = 0x12, 47 IB_SA_METHOD_GET_TABLE = 0x12,
48 IB_SA_METHOD_GET_TABLE_RESP = 0x92, 48 IB_SA_METHOD_GET_TABLE_RESP = 0x92,
49 IB_SA_METHOD_DELETE = 0x15 49 IB_SA_METHOD_DELETE = 0x15,
50 IB_SA_METHOD_DELETE_RESP = 0x95,
51 IB_SA_METHOD_GET_MULTI = 0x14,
52 IB_SA_METHOD_GET_MULTI_RESP = 0x94,
53 IB_SA_METHOD_GET_TRACE_TBL = 0x13
54};
55
56enum {
57 IB_SA_ATTR_CLASS_PORTINFO = 0x01,
58 IB_SA_ATTR_NOTICE = 0x02,
59 IB_SA_ATTR_INFORM_INFO = 0x03,
60 IB_SA_ATTR_NODE_REC = 0x11,
61 IB_SA_ATTR_PORT_INFO_REC = 0x12,
62 IB_SA_ATTR_SL2VL_REC = 0x13,
63 IB_SA_ATTR_SWITCH_REC = 0x14,
64 IB_SA_ATTR_LINEAR_FDB_REC = 0x15,
65 IB_SA_ATTR_RANDOM_FDB_REC = 0x16,
66 IB_SA_ATTR_MCAST_FDB_REC = 0x17,
67 IB_SA_ATTR_SM_INFO_REC = 0x18,
68 IB_SA_ATTR_LINK_REC = 0x20,
69 IB_SA_ATTR_GUID_INFO_REC = 0x30,
70 IB_SA_ATTR_SERVICE_REC = 0x31,
71 IB_SA_ATTR_PARTITION_REC = 0x33,
72 IB_SA_ATTR_PATH_REC = 0x35,
73 IB_SA_ATTR_VL_ARB_REC = 0x36,
74 IB_SA_ATTR_MC_MEMBER_REC = 0x38,
75 IB_SA_ATTR_TRACE_REC = 0x39,
76 IB_SA_ATTR_MULTI_PATH_REC = 0x3a,
77 IB_SA_ATTR_SERVICE_ASSOC_REC = 0x3b,
78 IB_SA_ATTR_INFORM_INFO_REC = 0xf3
50}; 79};
51 80
52enum ib_sa_selector { 81enum ib_sa_selector {
diff --git a/include/rdma/ib_user_cm.h b/include/rdma/ib_user_cm.h
index 72182d1677..e4d1654276 100644
--- a/include/rdma/ib_user_cm.h
+++ b/include/rdma/ib_user_cm.h
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Intel Corporation. All rights reserved.
3 * 4 *
4 * This software is available to you under a choice of one of two 5 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 6 * licenses. You may choose to be licensed under the terms of the GNU
@@ -37,7 +38,7 @@
37 38
38#include <linux/types.h> 39#include <linux/types.h>
39 40
40#define IB_USER_CM_ABI_VERSION 1 41#define IB_USER_CM_ABI_VERSION 2
41 42
42enum { 43enum {
43 IB_USER_CM_CMD_CREATE_ID, 44 IB_USER_CM_CMD_CREATE_ID,
@@ -60,6 +61,7 @@ enum {
60 IB_USER_CM_CMD_SEND_SIDR_REP, 61 IB_USER_CM_CMD_SEND_SIDR_REP,
61 62
62 IB_USER_CM_CMD_EVENT, 63 IB_USER_CM_CMD_EVENT,
64 IB_USER_CM_CMD_INIT_QP_ATTR,
63}; 65};
64/* 66/*
65 * command ABI structures. 67 * command ABI structures.
@@ -71,6 +73,7 @@ struct ib_ucm_cmd_hdr {
71}; 73};
72 74
73struct ib_ucm_create_id { 75struct ib_ucm_create_id {
76 __u64 uid;
74 __u64 response; 77 __u64 response;
75}; 78};
76 79
@@ -79,9 +82,14 @@ struct ib_ucm_create_id_resp {
79}; 82};
80 83
81struct ib_ucm_destroy_id { 84struct ib_ucm_destroy_id {
85 __u64 response;
82 __u32 id; 86 __u32 id;
83}; 87};
84 88
89struct ib_ucm_destroy_id_resp {
90 __u32 events_reported;
91};
92
85struct ib_ucm_attr_id { 93struct ib_ucm_attr_id {
86 __u64 response; 94 __u64 response;
87 __u32 id; 95 __u32 id;
@@ -94,6 +102,64 @@ struct ib_ucm_attr_id_resp {
94 __be32 remote_id; 102 __be32 remote_id;
95}; 103};
96 104
105struct ib_ucm_init_qp_attr {
106 __u64 response;
107 __u32 id;
108 __u32 qp_state;
109};
110
111struct ib_ucm_ah_attr {
112 __u8 grh_dgid[16];
113 __u32 grh_flow_label;
114 __u16 dlid;
115 __u16 reserved;
116 __u8 grh_sgid_index;
117 __u8 grh_hop_limit;
118 __u8 grh_traffic_class;
119 __u8 sl;
120 __u8 src_path_bits;
121 __u8 static_rate;
122 __u8 is_global;
123 __u8 port_num;
124};
125
126struct ib_ucm_init_qp_attr_resp {
127 __u32 qp_attr_mask;
128 __u32 qp_state;
129 __u32 cur_qp_state;
130 __u32 path_mtu;
131 __u32 path_mig_state;
132 __u32 qkey;
133 __u32 rq_psn;
134 __u32 sq_psn;
135 __u32 dest_qp_num;
136 __u32 qp_access_flags;
137
138 struct ib_ucm_ah_attr ah_attr;
139 struct ib_ucm_ah_attr alt_ah_attr;
140
141 /* ib_qp_cap */
142 __u32 max_send_wr;
143 __u32 max_recv_wr;
144 __u32 max_send_sge;
145 __u32 max_recv_sge;
146 __u32 max_inline_data;
147
148 __u16 pkey_index;
149 __u16 alt_pkey_index;
150 __u8 en_sqd_async_notify;
151 __u8 sq_draining;
152 __u8 max_rd_atomic;
153 __u8 max_dest_rd_atomic;
154 __u8 min_rnr_timer;
155 __u8 port_num;
156 __u8 timeout;
157 __u8 retry_cnt;
158 __u8 rnr_retry;
159 __u8 alt_port_num;
160 __u8 alt_timeout;
161};
162
97struct ib_ucm_listen { 163struct ib_ucm_listen {
98 __be64 service_id; 164 __be64 service_id;
99 __be64 service_mask; 165 __be64 service_mask;
@@ -157,6 +223,7 @@ struct ib_ucm_req {
157}; 223};
158 224
159struct ib_ucm_rep { 225struct ib_ucm_rep {
226 __u64 uid;
160 __u64 data; 227 __u64 data;
161 __u32 id; 228 __u32 id;
162 __u32 qpn; 229 __u32 qpn;
@@ -232,7 +299,6 @@ struct ib_ucm_event_get {
232}; 299};
233 300
234struct ib_ucm_req_event_resp { 301struct ib_ucm_req_event_resp {
235 __u32 listen_id;
236 /* device */ 302 /* device */
237 /* port */ 303 /* port */
238 struct ib_ucm_path_rec primary_path; 304 struct ib_ucm_path_rec primary_path;
@@ -287,7 +353,6 @@ struct ib_ucm_apr_event_resp {
287}; 353};
288 354
289struct ib_ucm_sidr_req_event_resp { 355struct ib_ucm_sidr_req_event_resp {
290 __u32 listen_id;
291 /* device */ 356 /* device */
292 /* port */ 357 /* port */
293 __u16 pkey; 358 __u16 pkey;
@@ -307,6 +372,7 @@ struct ib_ucm_sidr_rep_event_resp {
307#define IB_UCM_PRES_ALTERNATE 0x08 372#define IB_UCM_PRES_ALTERNATE 0x08
308 373
309struct ib_ucm_event_resp { 374struct ib_ucm_event_resp {
375 __u64 uid;
310 __u32 id; 376 __u32 id;
311 __u32 event; 377 __u32 event;
312 __u32 present; 378 __u32 present;
diff --git a/include/rdma/ib_user_verbs.h b/include/rdma/ib_user_verbs.h
index 7ebb01c8f9..fd85725391 100644
--- a/include/rdma/ib_user_verbs.h
+++ b/include/rdma/ib_user_verbs.h
@@ -42,7 +42,7 @@
42 * Increment this value if any changes that break userspace ABI 42 * Increment this value if any changes that break userspace ABI
43 * compatibility are made. 43 * compatibility are made.
44 */ 44 */
45#define IB_USER_VERBS_ABI_VERSION 1 45#define IB_USER_VERBS_ABI_VERSION 2
46 46
47enum { 47enum {
48 IB_USER_VERBS_CMD_QUERY_PARAMS, 48 IB_USER_VERBS_CMD_QUERY_PARAMS,
@@ -292,7 +292,14 @@ struct ib_uverbs_create_cq_resp {
292}; 292};
293 293
294struct ib_uverbs_destroy_cq { 294struct ib_uverbs_destroy_cq {
295 __u64 response;
295 __u32 cq_handle; 296 __u32 cq_handle;
297 __u32 reserved;
298};
299
300struct ib_uverbs_destroy_cq_resp {
301 __u32 comp_events_reported;
302 __u32 async_events_reported;
296}; 303};
297 304
298struct ib_uverbs_create_qp { 305struct ib_uverbs_create_qp {
@@ -372,7 +379,13 @@ struct ib_uverbs_modify_qp_resp {
372}; 379};
373 380
374struct ib_uverbs_destroy_qp { 381struct ib_uverbs_destroy_qp {
382 __u64 response;
375 __u32 qp_handle; 383 __u32 qp_handle;
384 __u32 reserved;
385};
386
387struct ib_uverbs_destroy_qp_resp {
388 __u32 events_reported;
376}; 389};
377 390
378struct ib_uverbs_attach_mcast { 391struct ib_uverbs_attach_mcast {
@@ -416,7 +429,13 @@ struct ib_uverbs_modify_srq {
416}; 429};
417 430
418struct ib_uverbs_destroy_srq { 431struct ib_uverbs_destroy_srq {
432 __u64 response;
419 __u32 srq_handle; 433 __u32 srq_handle;
434 __u32 reserved;
435};
436
437struct ib_uverbs_destroy_srq_resp {
438 __u32 events_reported;
420}; 439};
421 440
422#endif /* IB_USER_VERBS_H */ 441#endif /* IB_USER_VERBS_H */
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 389e8ebe9c..d6361dab03 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -910,11 +910,10 @@ int snd_pcm_format_big_endian(snd_pcm_format_t format);
910 * Returns 1 if the given PCM format is CPU-endian, 0 if 910 * Returns 1 if the given PCM format is CPU-endian, 0 if
911 * opposite, or a negative error code if endian not specified. 911 * opposite, or a negative error code if endian not specified.
912 */ 912 */
913/* int snd_pcm_format_cpu_endian(snd_pcm_format_t format); */
914#ifdef SNDRV_LITTLE_ENDIAN 913#ifdef SNDRV_LITTLE_ENDIAN
915#define snd_pcm_format_cpu_endian snd_pcm_format_little_endian 914#define snd_pcm_format_cpu_endian(format) snd_pcm_format_little_endian(format)
916#else 915#else
917#define snd_pcm_format_cpu_endian snd_pcm_format_big_endian 916#define snd_pcm_format_cpu_endian(format) snd_pcm_format_big_endian(format)
918#endif 917#endif
919int snd_pcm_format_width(snd_pcm_format_t format); /* in bits */ 918int snd_pcm_format_width(snd_pcm_format_t format); /* in bits */
920int snd_pcm_format_physical_width(snd_pcm_format_t format); /* in bits */ 919int snd_pcm_format_physical_width(snd_pcm_format_t format); /* in bits */
diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
index ad3c3be33c..b82e408e75 100644
--- a/include/sound/tea575x-tuner.h
+++ b/include/sound/tea575x-tuner.h
@@ -34,9 +34,7 @@ struct snd_tea575x_ops {
34struct snd_tea575x { 34struct snd_tea575x {
35 snd_card_t *card; 35 snd_card_t *card;
36 struct video_device vd; /* video device */ 36 struct video_device vd; /* video device */
37#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0)
38 struct file_operations fops; 37 struct file_operations fops;
39#endif
40 int dev_nr; /* requested device number + 1 */ 38 int dev_nr; /* requested device number + 1 */
41 int vd_registered; /* video device is registered */ 39 int vd_registered; /* video device is registered */
42 int tea5759; /* 5759 chip is present */ 40 int tea5759; /* 5759 chip is present */
diff --git a/include/video/cyblafb.h b/include/video/cyblafb.h
new file mode 100644
index 0000000000..a9948232b1
--- /dev/null
+++ b/include/video/cyblafb.h
@@ -0,0 +1,171 @@
1
2#ifndef CYBLAFB_DEBUG
3#define CYBLAFB_DEBUG 0
4#endif
5
6#if CYBLAFB_DEBUG
7#define debug(f,a...) printk("%s:" f, __FUNCTION__ , ## a);
8#else
9#define debug(f,a...)
10#endif
11
12#define output(f, a...) printk("cyblafb: " f, ## a)
13
14#define Kb (1024)
15#define Mb (Kb*Kb)
16
17/* PCI IDS of supported cards temporarily here */
18
19#define CYBERBLADEi1 0x8500
20
21/* these defines are for 'lcd' variable */
22#define LCD_STRETCH 0
23#define LCD_CENTER 1
24#define LCD_BIOS 2
25
26/* display types */
27#define DISPLAY_CRT 0
28#define DISPLAY_FP 1
29
30#define ROP_S 0xCC
31
32#define point(x,y) ((y)<<16|(x))
33
34//
35// Attribute Regs, ARxx, 3c0/3c1
36//
37#define AR00 0x00
38#define AR01 0x01
39#define AR02 0x02
40#define AR03 0x03
41#define AR04 0x04
42#define AR05 0x05
43#define AR06 0x06
44#define AR07 0x07
45#define AR08 0x08
46#define AR09 0x09
47#define AR0A 0x0A
48#define AR0B 0x0B
49#define AR0C 0x0C
50#define AR0D 0x0D
51#define AR0E 0x0E
52#define AR0F 0x0F
53#define AR10 0x10
54#define AR12 0x12
55#define AR13 0x13
56
57//
58// Sequencer Regs, SRxx, 3c4/3c5
59//
60#define SR00 0x00
61#define SR01 0x01
62#define SR02 0x02
63#define SR03 0x03
64#define SR04 0x04
65#define SR0D 0x0D
66#define SR0E 0x0E
67#define SR11 0x11
68#define SR18 0x18
69#define SR19 0x19
70
71//
72//
73//
74#define CR00 0x00
75#define CR01 0x01
76#define CR02 0x02
77#define CR03 0x03
78#define CR04 0x04
79#define CR05 0x05
80#define CR06 0x06
81#define CR07 0x07
82#define CR08 0x08
83#define CR09 0x09
84#define CR0A 0x0A
85#define CR0B 0x0B
86#define CR0C 0x0C
87#define CR0D 0x0D
88#define CR0E 0x0E
89#define CR0F 0x0F
90#define CR10 0x10
91#define CR11 0x11
92#define CR12 0x12
93#define CR13 0x13
94#define CR14 0x14
95#define CR15 0x15
96#define CR16 0x16
97#define CR17 0x17
98#define CR18 0x18
99#define CR19 0x19
100#define CR1A 0x1A
101#define CR1B 0x1B
102#define CR1C 0x1C
103#define CR1D 0x1D
104#define CR1E 0x1E
105#define CR1F 0x1F
106#define CR20 0x20
107#define CR21 0x21
108#define CR27 0x27
109#define CR29 0x29
110#define CR2A 0x2A
111#define CR2B 0x2B
112#define CR2D 0x2D
113#define CR2F 0x2F
114#define CR36 0x36
115#define CR38 0x38
116#define CR39 0x39
117#define CR3A 0x3A
118#define CR55 0x55
119#define CR56 0x56
120#define CR57 0x57
121#define CR58 0x58
122
123//
124//
125//
126
127#define GR00 0x01
128#define GR01 0x01
129#define GR02 0x02
130#define GR03 0x03
131#define GR04 0x04
132#define GR05 0x05
133#define GR06 0x06
134#define GR07 0x07
135#define GR08 0x08
136#define GR0F 0x0F
137#define GR20 0x20
138#define GR23 0x23
139#define GR2F 0x2F
140#define GR30 0x30
141#define GR31 0x31
142#define GR33 0x33
143#define GR52 0x52
144#define GR53 0x53
145#define GR5D 0x5d
146
147
148//
149// Graphics Engine
150//
151#define GEBase 0x2100 // could be mapped elsewhere if we like it
152#define GE00 (GEBase+0x00) // source 1, p 111
153#define GE04 (GEBase+0x04) // source 2, p 111
154#define GE08 (GEBase+0x08) // destination 1, p 111
155#define GE0C (GEBase+0x0C) // destination 2, p 112
156#define GE20 (GEBase+0x20) // engine status, p 113
157#define GE24 (GEBase+0x24) // reset all GE pointers
158#define GE44 (GEBase+0x44) // command register, p 126
159#define GE48 (GEBase+0x48) // raster operation, p 127
160#define GE60 (GEBase+0x60) // foreground color, p 128
161#define GE64 (GEBase+0x64) // background color, p 128
162#define GE6C (GEBase+0x6C) // Pattern and Style, p 129, ok
163#define GE9C (GEBase+0x9C) // pixel engine data port, p 125
164#define GEB8 (GEBase+0xB8) // Destination Stride / Buffer Base 0, p 133
165#define GEBC (GEBase+0xBC) // Destination Stride / Buffer Base 1, p 133
166#define GEC0 (GEBase+0xC0) // Destination Stride / Buffer Base 2, p 133
167#define GEC4 (GEBase+0xC4) // Destination Stride / Buffer Base 3, p 133
168#define GEC8 (GEBase+0xC8) // Source Stride / Buffer Base 0, p 133
169#define GECC (GEBase+0xCC) // Source Stride / Buffer Base 1, p 133
170#define GED0 (GEBase+0xD0) // Source Stride / Buffer Base 2, p 133
171#define GED4 (GEBase+0xD4) // Source Stride / Buffer Base 3, p 133
diff --git a/include/video/sisfb.h b/include/video/sisfb.h
index 136bf79164..e402eb5b3c 100644
--- a/include/video/sisfb.h
+++ b/include/video/sisfb.h
@@ -1,5 +1,7 @@
1/* 1/*
2 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria. 2 * sisfb.h - definitions for the SiS framebuffer driver
3 *
4 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria.
3 * 5 *
4 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -16,8 +18,8 @@
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
17 */ 19 */
18 20
19#ifndef _LINUX_SISFB 21#ifndef _LINUX_SISFB_H_
20#define _LINUX_SISFB 22#define _LINUX_SISFB_H_
21 23
22#include <asm/ioctl.h> 24#include <asm/ioctl.h>
23#include <asm/types.h> 25#include <asm/types.h>
@@ -26,47 +28,35 @@
26/* PUBLIC */ 28/* PUBLIC */
27/**********************************************/ 29/**********************************************/
28 30
29/* vbflags */ 31/* vbflags, public (others in sis.h) */
30#define CRT2_DEFAULT 0x00000001 32#define CRT2_DEFAULT 0x00000001
31#define CRT2_LCD 0x00000002 /* TW: Never change the order of the CRT2_XXX entries */ 33#define CRT2_LCD 0x00000002
32#define CRT2_TV 0x00000004 /* (see SISCycleCRT2Type()) */ 34#define CRT2_TV 0x00000004
33#define CRT2_VGA 0x00000008 35#define CRT2_VGA 0x00000008
34#define TV_NTSC 0x00000010 36#define TV_NTSC 0x00000010
35#define TV_PAL 0x00000020 37#define TV_PAL 0x00000020
36#define TV_HIVISION 0x00000040 38#define TV_HIVISION 0x00000040
37#define TV_YPBPR 0x00000080 39#define TV_YPBPR 0x00000080
38#define TV_AVIDEO 0x00000100 40#define TV_AVIDEO 0x00000100
39#define TV_SVIDEO 0x00000200 41#define TV_SVIDEO 0x00000200
40#define TV_SCART 0x00000400 42#define TV_SCART 0x00000400
41#define VB_CONEXANT 0x00000800 /* 661 series only */ 43#define TV_PALM 0x00001000
42#define VB_TRUMPION VB_CONEXANT /* 300 series only */ 44#define TV_PALN 0x00002000
43#define TV_PALM 0x00001000
44#define TV_PALN 0x00002000
45#define TV_NTSCJ 0x00001000 45#define TV_NTSCJ 0x00001000
46#define VB_302ELV 0x00004000 46#define TV_CHSCART 0x00008000
47#define TV_CHSCART 0x00008000 47#define TV_CHYPBPR525I 0x00010000
48#define TV_CHYPBPR525I 0x00010000
49#define CRT1_VGA 0x00000000 48#define CRT1_VGA 0x00000000
50#define CRT1_LCDA 0x00020000 49#define CRT1_LCDA 0x00020000
51#define VGA2_CONNECTED 0x00040000 50#define VGA2_CONNECTED 0x00040000
52#define VB_DISPTYPE_CRT1 0x00080000 /* CRT1 connected and used */ 51#define VB_DISPTYPE_CRT1 0x00080000 /* CRT1 connected and used */
53#define VB_301 0x00100000 /* Video bridge type */ 52#define VB_SINGLE_MODE 0x20000000 /* CRT1 or CRT2; determined by DISPTYPE_CRTx */
54#define VB_301B 0x00200000 53#define VB_MIRROR_MODE 0x40000000 /* CRT1 + CRT2 identical (mirror mode) */
55#define VB_302B 0x00400000 54#define VB_DUALVIEW_MODE 0x80000000 /* CRT1 + CRT2 independent (dual head mode) */
56#define VB_30xBDH 0x00800000 /* 30xB DH version (w/o LCD support) */
57#define VB_LVDS 0x01000000
58#define VB_CHRONTEL 0x02000000
59#define VB_301LV 0x04000000
60#define VB_302LV 0x08000000
61#define VB_301C 0x10000000
62#define VB_SINGLE_MODE 0x20000000 /* CRT1 or CRT2; determined by DISPTYPE_CRTx */
63#define VB_MIRROR_MODE 0x40000000 /* CRT1 + CRT2 identical (mirror mode) */
64#define VB_DUALVIEW_MODE 0x80000000 /* CRT1 + CRT2 independent (dual head mode) */
65 55
66/* Aliases: */ 56/* Aliases: */
67#define CRT2_ENABLE (CRT2_LCD | CRT2_TV | CRT2_VGA) 57#define CRT2_ENABLE (CRT2_LCD | CRT2_TV | CRT2_VGA)
68#define TV_STANDARD (TV_NTSC | TV_PAL | TV_PALM | TV_PALN | TV_NTSCJ) 58#define TV_STANDARD (TV_NTSC | TV_PAL | TV_PALM | TV_PALN | TV_NTSCJ)
69#define TV_INTERFACE (TV_AVIDEO|TV_SVIDEO|TV_SCART|TV_HIVISION|TV_YPBPR|TV_CHSCART|TV_CHYPBPR525I) 59#define TV_INTERFACE (TV_AVIDEO|TV_SVIDEO|TV_SCART|TV_HIVISION|TV_YPBPR|TV_CHSCART|TV_CHYPBPR525I)
70 60
71/* Only if TV_YPBPR is set: */ 61/* Only if TV_YPBPR is set: */
72#define TV_YPBPR525I TV_NTSC 62#define TV_YPBPR525I TV_NTSC
@@ -75,89 +65,118 @@
75#define TV_YPBPR1080I TV_PALN 65#define TV_YPBPR1080I TV_PALN
76#define TV_YPBPRALL (TV_YPBPR525I | TV_YPBPR525P | TV_YPBPR750P | TV_YPBPR1080I) 66#define TV_YPBPRALL (TV_YPBPR525I | TV_YPBPR525P | TV_YPBPR750P | TV_YPBPR1080I)
77 67
78#define VB_SISBRIDGE (VB_301|VB_301B|VB_301C|VB_302B|VB_301LV|VB_302LV|VB_302ELV)
79#define VB_SISTVBRIDGE (VB_301|VB_301B|VB_301C|VB_302B|VB_301LV|VB_302LV)
80#define VB_VIDEOBRIDGE (VB_SISBRIDGE | VB_LVDS | VB_CHRONTEL | VB_CONEXANT)
81
82#define VB_DISPTYPE_DISP2 CRT2_ENABLE 68#define VB_DISPTYPE_DISP2 CRT2_ENABLE
83#define VB_DISPTYPE_CRT2 CRT2_ENABLE 69#define VB_DISPTYPE_CRT2 CRT2_ENABLE
84#define VB_DISPTYPE_DISP1 VB_DISPTYPE_CRT1 70#define VB_DISPTYPE_DISP1 VB_DISPTYPE_CRT1
85#define VB_DISPMODE_SINGLE VB_SINGLE_MODE 71#define VB_DISPMODE_SINGLE VB_SINGLE_MODE
86#define VB_DISPMODE_MIRROR VB_MIRROR_MODE 72#define VB_DISPMODE_MIRROR VB_MIRROR_MODE
87#define VB_DISPMODE_DUAL VB_DUALVIEW_MODE 73#define VB_DISPMODE_DUAL VB_DUALVIEW_MODE
88#define VB_DISPLAY_MODE (SINGLE_MODE | MIRROR_MODE | DUALVIEW_MODE) 74#define VB_DISPLAY_MODE (SINGLE_MODE | MIRROR_MODE | DUALVIEW_MODE)
89 75
90/* Structure argument for SISFB_GET_INFO ioctl */ 76/* Structure argument for SISFB_GET_INFO ioctl */
91typedef struct _SISFB_INFO sisfb_info, *psisfb_info; 77struct sisfb_info {
92 78 __u32 sisfb_id; /* for identifying sisfb */
93struct _SISFB_INFO {
94 __u32 sisfb_id; /* for identifying sisfb */
95#ifndef SISFB_ID 79#ifndef SISFB_ID
96#define SISFB_ID 0x53495346 /* Identify myself with 'SISF' */ 80#define SISFB_ID 0x53495346 /* Identify myself with 'SISF' */
97#endif 81#endif
98 __u32 chip_id; /* PCI-ID of detected chip */ 82 __u32 chip_id; /* PCI-ID of detected chip */
99 __u32 memory; /* video memory in KB which sisfb manages */ 83 __u32 memory; /* total video memory in KB */
100 __u32 heapstart; /* heap start (= sisfb "mem" argument) in KB */ 84 __u32 heapstart; /* heap start offset in KB */
101 __u8 fbvidmode; /* current sisfb mode */ 85 __u8 fbvidmode; /* current sisfb mode */
102 86
103 __u8 sisfb_version; 87 __u8 sisfb_version;
104 __u8 sisfb_revision; 88 __u8 sisfb_revision;
105 __u8 sisfb_patchlevel; 89 __u8 sisfb_patchlevel;
106 90
107 __u8 sisfb_caps; /* sisfb capabilities */ 91 __u8 sisfb_caps; /* sisfb capabilities */
108 92
109 __u32 sisfb_tqlen; /* turbo queue length (in KB) */ 93 __u32 sisfb_tqlen; /* turbo queue length (in KB) */
110 94
111 __u32 sisfb_pcibus; /* The card's PCI ID */ 95 __u32 sisfb_pcibus; /* The card's PCI ID */
112 __u32 sisfb_pcislot; 96 __u32 sisfb_pcislot;
113 __u32 sisfb_pcifunc; 97 __u32 sisfb_pcifunc;
98
99 __u8 sisfb_lcdpdc; /* PanelDelayCompensation */
100
101 __u8 sisfb_lcda; /* Detected status of LCDA for low res/text modes */
102
103 __u32 sisfb_vbflags;
104 __u32 sisfb_currentvbflags;
105
106 __u32 sisfb_scalelcd;
107 __u32 sisfb_specialtiming;
108
109 __u8 sisfb_haveemi;
110 __u8 sisfb_emi30,sisfb_emi31,sisfb_emi32,sisfb_emi33;
111 __u8 sisfb_haveemilcd;
114 112
115 __u8 sisfb_lcdpdc; /* PanelDelayCompensation */ 113 __u8 sisfb_lcdpdca; /* PanelDelayCompensation for LCD-via-CRT1 */
116 114
117 __u8 sisfb_lcda; /* Detected status of LCDA for low res/text modes */ 115 __u16 sisfb_tvxpos, sisfb_tvypos; /* Warning: Values + 32 ! */
118 116
119 __u32 sisfb_vbflags; 117 __u32 sisfb_heapsize; /* heap size (in KB) */
120 __u32 sisfb_currentvbflags; 118 __u32 sisfb_videooffset; /* Offset of viewport in video memory (in bytes) */
121 119
122 __u32 sisfb_scalelcd; 120 __u32 sisfb_curfstn; /* currently running FSTN/DSTN mode */
123 __u32 sisfb_specialtiming; 121 __u32 sisfb_curdstn;
124 122
125 __u8 sisfb_haveemi; 123 __u16 sisfb_pci_vendor; /* PCI vendor (SiS or XGI) */
126 __u8 sisfb_emi30,sisfb_emi31,sisfb_emi32,sisfb_emi33;
127 __u8 sisfb_haveemilcd;
128 124
129 __u8 sisfb_lcdpdca; /* PanelDelayCompensation for LCD-via-CRT1 */ 125 __u32 sisfb_vbflags2; /* ivideo->vbflags2 */
130 126
131 __u16 sisfb_tvxpos, sisfb_tvypos; /* Warning: Values + 32 ! */ 127 __u8 sisfb_can_post; /* sisfb can POST this card */
128 __u8 sisfb_card_posted; /* card is POSTED */
129 __u8 sisfb_was_boot_device; /* This card was the boot video device (ie is primary) */
132 130
133 __u8 reserved[208]; /* for future use */ 131 __u8 reserved[183]; /* for future use */
132};
133
134#define SISFB_CMD_GETVBFLAGS 0x55AA0001 /* no arg; result[1] = vbflags */
135#define SISFB_CMD_SWITCHCRT1 0x55AA0010 /* arg[0]: 99 = query, 0 = off, 1 = on */
136/* more to come */
137
138#define SISFB_CMD_ERR_OK 0x80000000 /* command succeeded */
139#define SISFB_CMD_ERR_LOCKED 0x80000001 /* sisfb is locked */
140#define SISFB_CMD_ERR_EARLY 0x80000002 /* request before sisfb took over gfx system */
141#define SISFB_CMD_ERR_NOVB 0x80000003 /* No video bridge */
142#define SISFB_CMD_ERR_NOCRT2 0x80000004 /* can't change CRT1 status, CRT2 disabled */
143/* more to come */
144#define SISFB_CMD_ERR_UNKNOWN 0x8000ffff /* Unknown command */
145#define SISFB_CMD_ERR_OTHER 0x80010000 /* Other error */
146
147/* Argument for SISFB_CMD ioctl */
148struct sisfb_cmd {
149 __u32 sisfb_cmd;
150 __u32 sisfb_arg[16];
151 __u32 sisfb_result[4];
134}; 152};
135 153
136/* Addtional IOCTLs for communication sisfb <> X driver */ 154/* Addtional IOCTLs for communication sisfb <> X driver */
137/* If changing this, vgatypes.h must also be changed (for X driver) */ 155/* If changing this, vgatypes.h must also be changed (for X driver) */
138 156
139/* ioctl for identifying and giving some info (esp. memory heap start) */ 157/* ioctl for identifying and giving some info (esp. memory heap start) */
140#define SISFB_GET_INFO_SIZE _IOR(0xF3,0x00,__u32) 158#define SISFB_GET_INFO_SIZE _IOR(0xF3,0x00,__u32)
141#define SISFB_GET_INFO _IOR(0xF3,0x01,struct _SISFB_INFO) 159#define SISFB_GET_INFO _IOR(0xF3,0x01,struct sisfb_info)
142 160
143/* ioctrl to get current vertical retrace status */ 161/* ioctrl to get current vertical retrace status */
144#define SISFB_GET_VBRSTATUS _IOR(0xF3,0x02,__u32) 162#define SISFB_GET_VBRSTATUS _IOR(0xF3,0x02,__u32)
145 163
146/* ioctl to enable/disable panning auto-maximize (like nomax parameter) */ 164/* ioctl to enable/disable panning auto-maximize (like nomax parameter) */
147#define SISFB_GET_AUTOMAXIMIZE _IOR(0xF3,0x03,__u32) 165#define SISFB_GET_AUTOMAXIMIZE _IOR(0xF3,0x03,__u32)
148#define SISFB_SET_AUTOMAXIMIZE _IOW(0xF3,0x03,__u32) 166#define SISFB_SET_AUTOMAXIMIZE _IOW(0xF3,0x03,__u32)
149 167
150/* ioctls to relocate TV output (x=D[31:16], y=D[15:0], + 32)*/ 168/* ioctls to relocate TV output (x=D[31:16], y=D[15:0], + 32)*/
151#define SISFB_GET_TVPOSOFFSET _IOR(0xF3,0x04,__u32) 169#define SISFB_GET_TVPOSOFFSET _IOR(0xF3,0x04,__u32)
152#define SISFB_SET_TVPOSOFFSET _IOW(0xF3,0x04,__u32) 170#define SISFB_SET_TVPOSOFFSET _IOW(0xF3,0x04,__u32)
171
172/* ioctl for internal sisfb commands (sisfbctrl) */
173#define SISFB_COMMAND _IOWR(0xF3,0x05,struct sisfb_cmd)
153 174
154/* ioctl for locking sisfb (no register access during lock) */ 175/* ioctl for locking sisfb (no register access during lock) */
155/* As of now, only used to avoid register access during 176/* As of now, only used to avoid register access during
156 * the ioctls listed above. 177 * the ioctls listed above.
157 */ 178 */
158#define SISFB_SET_LOCK _IOW(0xF3,0x06,__u32) 179#define SISFB_SET_LOCK _IOW(0xF3,0x06,__u32)
159
160/* more to come soon */
161 180
162/* ioctls 0xF3 up to 0x3F reserved for sisfb */ 181/* ioctls 0xF3 up to 0x3F reserved for sisfb */
163 182
@@ -165,7 +184,7 @@ struct _SISFB_INFO {
165/* The following are deprecated and should not be used anymore: */ 184/* The following are deprecated and should not be used anymore: */
166/****************************************************************/ 185/****************************************************************/
167/* ioctl for identifying and giving some info (esp. memory heap start) */ 186/* ioctl for identifying and giving some info (esp. memory heap start) */
168#define SISFB_GET_INFO_OLD _IOR('n',0xF8,__u32) 187#define SISFB_GET_INFO_OLD _IOR('n',0xF8,__u32)
169/* ioctrl to get current vertical retrace status */ 188/* ioctrl to get current vertical retrace status */
170#define SISFB_GET_VBRSTATUS_OLD _IOR('n',0xF9,__u32) 189#define SISFB_GET_VBRSTATUS_OLD _IOR('n',0xF9,__u32)
171/* ioctl to enable/disable panning auto-maximize (like nomax parameter) */ 190/* ioctl to enable/disable panning auto-maximize (like nomax parameter) */
@@ -177,8 +196,8 @@ struct _SISFB_INFO {
177 196
178/* For fb memory manager (FBIO_ALLOC, FBIO_FREE) */ 197/* For fb memory manager (FBIO_ALLOC, FBIO_FREE) */
179struct sis_memreq { 198struct sis_memreq {
180 __u32 offset; 199 __u32 offset;
181 __u32 size; 200 __u32 size;
182}; 201};
183 202
184/**********************************************/ 203/**********************************************/
@@ -187,12 +206,19 @@ struct sis_memreq {
187/**********************************************/ 206/**********************************************/
188 207
189#ifdef __KERNEL__ 208#ifdef __KERNEL__
209
210#include <linux/pci.h>
211
190#define UNKNOWN_VGA 0 212#define UNKNOWN_VGA 0
191#define SIS_300_VGA 1 213#define SIS_300_VGA 1
192#define SIS_315_VGA 2 214#define SIS_315_VGA 2
193 215
216#define SISFB_HAVE_MALLOC_NEW
194extern void sis_malloc(struct sis_memreq *req); 217extern void sis_malloc(struct sis_memreq *req);
218extern void sis_malloc_new(struct pci_dev *pdev, struct sis_memreq *req);
219
195extern void sis_free(u32 base); 220extern void sis_free(u32 base);
221extern void sis_free_new(struct pci_dev *pdev, u32 base);
196#endif 222#endif
197 223
198#endif 224#endif
diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index 0acf245f44..3a92601150 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -69,7 +69,7 @@ struct mqueue_inode_info {
69 69
70 struct sigevent notify; 70 struct sigevent notify;
71 pid_t notify_owner; 71 pid_t notify_owner;
72 struct user_struct *user; /* user who created, for accouting */ 72 struct user_struct *user; /* user who created, for accounting */
73 struct sock *notify_sock; 73 struct sock *notify_sock;
74 struct sk_buff *notify_cookie; 74 struct sk_buff *notify_cookie;
75 75
diff --git a/kernel/Makefile b/kernel/Makefile
index 8d57a2f122..ff4dc02ce1 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -12,6 +12,7 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o profile.o \
12obj-$(CONFIG_FUTEX) += futex.o 12obj-$(CONFIG_FUTEX) += futex.o
13obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o 13obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
14obj-$(CONFIG_SMP) += cpu.o spinlock.o 14obj-$(CONFIG_SMP) += cpu.o spinlock.o
15obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o
15obj-$(CONFIG_UID16) += uid16.o 16obj-$(CONFIG_UID16) += uid16.o
16obj-$(CONFIG_MODULES) += module.o 17obj-$(CONFIG_MODULES) += module.o
17obj-$(CONFIG_KALLSYMS) += kallsyms.o 18obj-$(CONFIG_KALLSYMS) += kallsyms.o
diff --git a/kernel/acct.c b/kernel/acct.c
index f70e6027cc..b756f52749 100644
--- a/kernel/acct.c
+++ b/kernel/acct.c
@@ -165,7 +165,7 @@ out:
165} 165}
166 166
167/* 167/*
168 * Close the old accouting file (if currently open) and then replace 168 * Close the old accounting file (if currently open) and then replace
169 * it with file (if non-NULL). 169 * it with file (if non-NULL).
170 * 170 *
171 * NOTE: acct_globals.lock MUST be held on entry and exit. 171 * NOTE: acct_globals.lock MUST be held on entry and exit.
@@ -199,11 +199,16 @@ static void acct_file_reopen(struct file *file)
199 } 199 }
200} 200}
201 201
202/* 202/**
203 * sys_acct() is the only system call needed to implement process 203 * sys_acct - enable/disable process accounting
204 * accounting. It takes the name of the file where accounting records 204 * @name: file name for accounting records or NULL to shutdown accounting
205 * should be written. If the filename is NULL, accounting will be 205 *
206 * shutdown. 206 * Returns 0 for success or negative errno values for failure.
207 *
208 * sys_acct() is the only system call needed to implement process
209 * accounting. It takes the name of the file where accounting records
210 * should be written. If the filename is NULL, accounting will be
211 * shutdown.
207 */ 212 */
208asmlinkage long sys_acct(const char __user *name) 213asmlinkage long sys_acct(const char __user *name)
209{ 214{
@@ -250,9 +255,12 @@ asmlinkage long sys_acct(const char __user *name)
250 return (0); 255 return (0);
251} 256}
252 257
253/* 258/**
254 * If the accouting is turned on for a file in the filesystem pointed 259 * acct_auto_close - turn off a filesystem's accounting if it is on
255 * to by sb, turn accouting off. 260 * @sb: super block for the filesystem
261 *
262 * If the accounting is turned on for a file in the filesystem pointed
263 * to by sb, turn accounting off.
256 */ 264 */
257void acct_auto_close(struct super_block *sb) 265void acct_auto_close(struct super_block *sb)
258{ 266{
@@ -503,8 +511,11 @@ static void do_acct_process(long exitcode, struct file *file)
503 set_fs(fs); 511 set_fs(fs);
504} 512}
505 513
506/* 514/**
507 * acct_process - now just a wrapper around do_acct_process 515 * acct_process - now just a wrapper around do_acct_process
516 * @exitcode: task exit code
517 *
518 * handles process accounting for an exiting task
508 */ 519 */
509void acct_process(long exitcode) 520void acct_process(long exitcode)
510{ 521{
@@ -530,9 +541,9 @@ void acct_process(long exitcode)
530} 541}
531 542
532 543
533/* 544/**
534 * acct_update_integrals 545 * acct_update_integrals - update mm integral fields in task_struct
535 * - update mm integral fields in task_struct 546 * @tsk: task_struct for accounting
536 */ 547 */
537void acct_update_integrals(struct task_struct *tsk) 548void acct_update_integrals(struct task_struct *tsk)
538{ 549{
@@ -547,9 +558,9 @@ void acct_update_integrals(struct task_struct *tsk)
547 } 558 }
548} 559}
549 560
550/* 561/**
551 * acct_clear_integrals 562 * acct_clear_integrals - clear the mm integral fields in task_struct
552 * - clear the mm integral fields in task_struct 563 * @tsk: task_struct whose accounting fields are cleared
553 */ 564 */
554void acct_clear_integrals(struct task_struct *tsk) 565void acct_clear_integrals(struct task_struct *tsk)
555{ 566{
diff --git a/kernel/compat.c b/kernel/compat.c
index ddfcaaa866..102296e21e 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -48,8 +48,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
48 if (!time_after(expire, now)) 48 if (!time_after(expire, now))
49 return 0; 49 return 0;
50 50
51 current->state = TASK_INTERRUPTIBLE; 51 expire = schedule_timeout_interruptible(expire - now);
52 expire = schedule_timeout(expire - now);
53 if (expire == 0) 52 if (expire == 0)
54 return 0; 53 return 0;
55 54
@@ -82,8 +81,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
82 return -EINVAL; 81 return -EINVAL;
83 82
84 expire = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec); 83 expire = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec);
85 current->state = TASK_INTERRUPTIBLE; 84 expire = schedule_timeout_interruptible(expire);
86 expire = schedule_timeout(expire);
87 if (expire == 0) 85 if (expire == 0)
88 return 0; 86 return 0;
89 87
@@ -795,8 +793,7 @@ compat_sys_rt_sigtimedwait (compat_sigset_t __user *uthese,
795 recalc_sigpending(); 793 recalc_sigpending();
796 spin_unlock_irq(&current->sighand->siglock); 794 spin_unlock_irq(&current->sighand->siglock);
797 795
798 current->state = TASK_INTERRUPTIBLE; 796 timeout = schedule_timeout_interruptible(timeout);
799 timeout = schedule_timeout(timeout);
800 797
801 spin_lock_irq(&current->sighand->siglock); 798 spin_lock_irq(&current->sighand->siglock);
802 sig = dequeue_signal(current, &s, &info); 799 sig = dequeue_signal(current, &s, &info);
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 1f06e76901..79866bc6b3 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -180,6 +180,42 @@ static struct super_block *cpuset_sb = NULL;
180 */ 180 */
181 181
182static DECLARE_MUTEX(cpuset_sem); 182static DECLARE_MUTEX(cpuset_sem);
183static struct task_struct *cpuset_sem_owner;
184static int cpuset_sem_depth;
185
186/*
187 * The global cpuset semaphore cpuset_sem can be needed by the
188 * memory allocator to update a tasks mems_allowed (see the calls
189 * to cpuset_update_current_mems_allowed()) or to walk up the
190 * cpuset hierarchy to find a mem_exclusive cpuset see the calls
191 * to cpuset_excl_nodes_overlap()).
192 *
193 * But if the memory allocation is being done by cpuset.c code, it
194 * usually already holds cpuset_sem. Double tripping on a kernel
195 * semaphore deadlocks the current task, and any other task that
196 * subsequently tries to obtain the lock.
197 *
198 * Run all up's and down's on cpuset_sem through the following
199 * wrappers, which will detect this nested locking, and avoid
200 * deadlocking.
201 */
202
203static inline void cpuset_down(struct semaphore *psem)
204{
205 if (cpuset_sem_owner != current) {
206 down(psem);
207 cpuset_sem_owner = current;
208 }
209 cpuset_sem_depth++;
210}
211
212static inline void cpuset_up(struct semaphore *psem)
213{
214 if (--cpuset_sem_depth == 0) {
215 cpuset_sem_owner = NULL;
216 up(psem);
217 }
218}
183 219
184/* 220/*
185 * A couple of forward declarations required, due to cyclic reference loop: 221 * A couple of forward declarations required, due to cyclic reference loop:
@@ -522,19 +558,10 @@ static void guarantee_online_mems(const struct cpuset *cs, nodemask_t *pmask)
522 * Refresh current tasks mems_allowed and mems_generation from 558 * Refresh current tasks mems_allowed and mems_generation from
523 * current tasks cpuset. Call with cpuset_sem held. 559 * current tasks cpuset. Call with cpuset_sem held.
524 * 560 *
525 * Be sure to call refresh_mems() on any cpuset operation which 561 * This routine is needed to update the per-task mems_allowed
526 * (1) holds cpuset_sem, and (2) might possibly alloc memory. 562 * data, within the tasks context, when it is trying to allocate
527 * Call after obtaining cpuset_sem lock, before any possible 563 * memory (in various mm/mempolicy.c routines) and notices
528 * allocation. Otherwise one risks trying to allocate memory 564 * that some other task has been modifying its cpuset.
529 * while the task cpuset_mems_generation is not the same as
530 * the mems_generation in its cpuset, which would deadlock on
531 * cpuset_sem in cpuset_update_current_mems_allowed().
532 *
533 * Since we hold cpuset_sem, once refresh_mems() is called, the
534 * test (current->cpuset_mems_generation != cs->mems_generation)
535 * in cpuset_update_current_mems_allowed() will remain false,
536 * until we drop cpuset_sem. Anyone else who would change our
537 * cpusets mems_generation needs to lock cpuset_sem first.
538 */ 565 */
539 566
540static void refresh_mems(void) 567static void refresh_mems(void)
@@ -840,7 +867,7 @@ static ssize_t cpuset_common_file_write(struct file *file, const char __user *us
840 } 867 }
841 buffer[nbytes] = 0; /* nul-terminate */ 868 buffer[nbytes] = 0; /* nul-terminate */
842 869
843 down(&cpuset_sem); 870 cpuset_down(&cpuset_sem);
844 871
845 if (is_removed(cs)) { 872 if (is_removed(cs)) {
846 retval = -ENODEV; 873 retval = -ENODEV;
@@ -874,7 +901,7 @@ static ssize_t cpuset_common_file_write(struct file *file, const char __user *us
874 if (retval == 0) 901 if (retval == 0)
875 retval = nbytes; 902 retval = nbytes;
876out2: 903out2:
877 up(&cpuset_sem); 904 cpuset_up(&cpuset_sem);
878 cpuset_release_agent(pathbuf); 905 cpuset_release_agent(pathbuf);
879out1: 906out1:
880 kfree(buffer); 907 kfree(buffer);
@@ -914,9 +941,9 @@ static int cpuset_sprintf_cpulist(char *page, struct cpuset *cs)
914{ 941{
915 cpumask_t mask; 942 cpumask_t mask;
916 943
917 down(&cpuset_sem); 944 cpuset_down(&cpuset_sem);
918 mask = cs->cpus_allowed; 945 mask = cs->cpus_allowed;
919 up(&cpuset_sem); 946 cpuset_up(&cpuset_sem);
920 947
921 return cpulist_scnprintf(page, PAGE_SIZE, mask); 948 return cpulist_scnprintf(page, PAGE_SIZE, mask);
922} 949}
@@ -925,9 +952,9 @@ static int cpuset_sprintf_memlist(char *page, struct cpuset *cs)
925{ 952{
926 nodemask_t mask; 953 nodemask_t mask;
927 954
928 down(&cpuset_sem); 955 cpuset_down(&cpuset_sem);
929 mask = cs->mems_allowed; 956 mask = cs->mems_allowed;
930 up(&cpuset_sem); 957 cpuset_up(&cpuset_sem);
931 958
932 return nodelist_scnprintf(page, PAGE_SIZE, mask); 959 return nodelist_scnprintf(page, PAGE_SIZE, mask);
933} 960}
@@ -972,6 +999,10 @@ static ssize_t cpuset_common_file_read(struct file *file, char __user *buf,
972 *s++ = '\n'; 999 *s++ = '\n';
973 *s = '\0'; 1000 *s = '\0';
974 1001
1002 /* Do nothing if *ppos is at the eof or beyond the eof. */
1003 if (s - page <= *ppos)
1004 return 0;
1005
975 start = page + *ppos; 1006 start = page + *ppos;
976 n = s - start; 1007 n = s - start;
977 retval = n - copy_to_user(buf, start, min(n, nbytes)); 1008 retval = n - copy_to_user(buf, start, min(n, nbytes));
@@ -1330,8 +1361,7 @@ static long cpuset_create(struct cpuset *parent, const char *name, int mode)
1330 if (!cs) 1361 if (!cs)
1331 return -ENOMEM; 1362 return -ENOMEM;
1332 1363
1333 down(&cpuset_sem); 1364 cpuset_down(&cpuset_sem);
1334 refresh_mems();
1335 cs->flags = 0; 1365 cs->flags = 0;
1336 if (notify_on_release(parent)) 1366 if (notify_on_release(parent))
1337 set_bit(CS_NOTIFY_ON_RELEASE, &cs->flags); 1367 set_bit(CS_NOTIFY_ON_RELEASE, &cs->flags);
@@ -1356,14 +1386,14 @@ static long cpuset_create(struct cpuset *parent, const char *name, int mode)
1356 * will down() this new directory's i_sem and if we race with 1386 * will down() this new directory's i_sem and if we race with
1357 * another mkdir, we might deadlock. 1387 * another mkdir, we might deadlock.
1358 */ 1388 */
1359 up(&cpuset_sem); 1389 cpuset_up(&cpuset_sem);
1360 1390
1361 err = cpuset_populate_dir(cs->dentry); 1391 err = cpuset_populate_dir(cs->dentry);
1362 /* If err < 0, we have a half-filled directory - oh well ;) */ 1392 /* If err < 0, we have a half-filled directory - oh well ;) */
1363 return 0; 1393 return 0;
1364err: 1394err:
1365 list_del(&cs->sibling); 1395 list_del(&cs->sibling);
1366 up(&cpuset_sem); 1396 cpuset_up(&cpuset_sem);
1367 kfree(cs); 1397 kfree(cs);
1368 return err; 1398 return err;
1369} 1399}
@@ -1385,14 +1415,13 @@ static int cpuset_rmdir(struct inode *unused_dir, struct dentry *dentry)
1385 1415
1386 /* the vfs holds both inode->i_sem already */ 1416 /* the vfs holds both inode->i_sem already */
1387 1417
1388 down(&cpuset_sem); 1418 cpuset_down(&cpuset_sem);
1389 refresh_mems();
1390 if (atomic_read(&cs->count) > 0) { 1419 if (atomic_read(&cs->count) > 0) {
1391 up(&cpuset_sem); 1420 cpuset_up(&cpuset_sem);
1392 return -EBUSY; 1421 return -EBUSY;
1393 } 1422 }
1394 if (!list_empty(&cs->children)) { 1423 if (!list_empty(&cs->children)) {
1395 up(&cpuset_sem); 1424 cpuset_up(&cpuset_sem);
1396 return -EBUSY; 1425 return -EBUSY;
1397 } 1426 }
1398 parent = cs->parent; 1427 parent = cs->parent;
@@ -1408,7 +1437,7 @@ static int cpuset_rmdir(struct inode *unused_dir, struct dentry *dentry)
1408 spin_unlock(&d->d_lock); 1437 spin_unlock(&d->d_lock);
1409 cpuset_d_remove_dir(d); 1438 cpuset_d_remove_dir(d);
1410 dput(d); 1439 dput(d);
1411 up(&cpuset_sem); 1440 cpuset_up(&cpuset_sem);
1412 cpuset_release_agent(pathbuf); 1441 cpuset_release_agent(pathbuf);
1413 return 0; 1442 return 0;
1414} 1443}
@@ -1511,10 +1540,10 @@ void cpuset_exit(struct task_struct *tsk)
1511 if (notify_on_release(cs)) { 1540 if (notify_on_release(cs)) {
1512 char *pathbuf = NULL; 1541 char *pathbuf = NULL;
1513 1542
1514 down(&cpuset_sem); 1543 cpuset_down(&cpuset_sem);
1515 if (atomic_dec_and_test(&cs->count)) 1544 if (atomic_dec_and_test(&cs->count))
1516 check_for_release(cs, &pathbuf); 1545 check_for_release(cs, &pathbuf);
1517 up(&cpuset_sem); 1546 cpuset_up(&cpuset_sem);
1518 cpuset_release_agent(pathbuf); 1547 cpuset_release_agent(pathbuf);
1519 } else { 1548 } else {
1520 atomic_dec(&cs->count); 1549 atomic_dec(&cs->count);
@@ -1535,11 +1564,11 @@ cpumask_t cpuset_cpus_allowed(const struct task_struct *tsk)
1535{ 1564{
1536 cpumask_t mask; 1565 cpumask_t mask;
1537 1566
1538 down(&cpuset_sem); 1567 cpuset_down(&cpuset_sem);
1539 task_lock((struct task_struct *)tsk); 1568 task_lock((struct task_struct *)tsk);
1540 guarantee_online_cpus(tsk->cpuset, &mask); 1569 guarantee_online_cpus(tsk->cpuset, &mask);
1541 task_unlock((struct task_struct *)tsk); 1570 task_unlock((struct task_struct *)tsk);
1542 up(&cpuset_sem); 1571 cpuset_up(&cpuset_sem);
1543 1572
1544 return mask; 1573 return mask;
1545} 1574}
@@ -1564,9 +1593,9 @@ void cpuset_update_current_mems_allowed(void)
1564 if (!cs) 1593 if (!cs)
1565 return; /* task is exiting */ 1594 return; /* task is exiting */
1566 if (current->cpuset_mems_generation != cs->mems_generation) { 1595 if (current->cpuset_mems_generation != cs->mems_generation) {
1567 down(&cpuset_sem); 1596 cpuset_down(&cpuset_sem);
1568 refresh_mems(); 1597 refresh_mems();
1569 up(&cpuset_sem); 1598 cpuset_up(&cpuset_sem);
1570 } 1599 }
1571} 1600}
1572 1601
@@ -1665,14 +1694,14 @@ int cpuset_zone_allowed(struct zone *z, unsigned int __nocast gfp_mask)
1665 return 0; 1694 return 0;
1666 1695
1667 /* Not hardwall and node outside mems_allowed: scan up cpusets */ 1696 /* Not hardwall and node outside mems_allowed: scan up cpusets */
1668 down(&cpuset_sem); 1697 cpuset_down(&cpuset_sem);
1669 cs = current->cpuset; 1698 cs = current->cpuset;
1670 if (!cs) 1699 if (!cs)
1671 goto done; /* current task exiting */ 1700 goto done; /* current task exiting */
1672 cs = nearest_exclusive_ancestor(cs); 1701 cs = nearest_exclusive_ancestor(cs);
1673 allowed = node_isset(node, cs->mems_allowed); 1702 allowed = node_isset(node, cs->mems_allowed);
1674done: 1703done:
1675 up(&cpuset_sem); 1704 cpuset_up(&cpuset_sem);
1676 return allowed; 1705 return allowed;
1677} 1706}
1678 1707
@@ -1693,7 +1722,7 @@ int cpuset_excl_nodes_overlap(const struct task_struct *p)
1693 const struct cpuset *cs1, *cs2; /* my and p's cpuset ancestors */ 1722 const struct cpuset *cs1, *cs2; /* my and p's cpuset ancestors */
1694 int overlap = 0; /* do cpusets overlap? */ 1723 int overlap = 0; /* do cpusets overlap? */
1695 1724
1696 down(&cpuset_sem); 1725 cpuset_down(&cpuset_sem);
1697 cs1 = current->cpuset; 1726 cs1 = current->cpuset;
1698 if (!cs1) 1727 if (!cs1)
1699 goto done; /* current task exiting */ 1728 goto done; /* current task exiting */
@@ -1704,7 +1733,7 @@ int cpuset_excl_nodes_overlap(const struct task_struct *p)
1704 cs2 = nearest_exclusive_ancestor(cs2); 1733 cs2 = nearest_exclusive_ancestor(cs2);
1705 overlap = nodes_intersects(cs1->mems_allowed, cs2->mems_allowed); 1734 overlap = nodes_intersects(cs1->mems_allowed, cs2->mems_allowed);
1706done: 1735done:
1707 up(&cpuset_sem); 1736 cpuset_up(&cpuset_sem);
1708 1737
1709 return overlap; 1738 return overlap;
1710} 1739}
@@ -1727,7 +1756,7 @@ static int proc_cpuset_show(struct seq_file *m, void *v)
1727 return -ENOMEM; 1756 return -ENOMEM;
1728 1757
1729 tsk = m->private; 1758 tsk = m->private;
1730 down(&cpuset_sem); 1759 cpuset_down(&cpuset_sem);
1731 task_lock(tsk); 1760 task_lock(tsk);
1732 cs = tsk->cpuset; 1761 cs = tsk->cpuset;
1733 task_unlock(tsk); 1762 task_unlock(tsk);
@@ -1742,7 +1771,7 @@ static int proc_cpuset_show(struct seq_file *m, void *v)
1742 seq_puts(m, buf); 1771 seq_puts(m, buf);
1743 seq_putc(m, '\n'); 1772 seq_putc(m, '\n');
1744out: 1773out:
1745 up(&cpuset_sem); 1774 cpuset_up(&cpuset_sem);
1746 kfree(buf); 1775 kfree(buf);
1747 return retval; 1776 return retval;
1748} 1777}
diff --git a/kernel/exit.c b/kernel/exit.c
index 5b0fb9f09f..6d2089a1bc 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -368,17 +368,19 @@ EXPORT_SYMBOL(daemonize);
368static inline void close_files(struct files_struct * files) 368static inline void close_files(struct files_struct * files)
369{ 369{
370 int i, j; 370 int i, j;
371 struct fdtable *fdt;
371 372
372 j = 0; 373 j = 0;
374 fdt = files_fdtable(files);
373 for (;;) { 375 for (;;) {
374 unsigned long set; 376 unsigned long set;
375 i = j * __NFDBITS; 377 i = j * __NFDBITS;
376 if (i >= files->max_fdset || i >= files->max_fds) 378 if (i >= fdt->max_fdset || i >= fdt->max_fds)
377 break; 379 break;
378 set = files->open_fds->fds_bits[j++]; 380 set = fdt->open_fds->fds_bits[j++];
379 while (set) { 381 while (set) {
380 if (set & 1) { 382 if (set & 1) {
381 struct file * file = xchg(&files->fd[i], NULL); 383 struct file * file = xchg(&fdt->fd[i], NULL);
382 if (file) 384 if (file)
383 filp_close(file, files); 385 filp_close(file, files);
384 } 386 }
@@ -403,18 +405,22 @@ struct files_struct *get_files_struct(struct task_struct *task)
403 405
404void fastcall put_files_struct(struct files_struct *files) 406void fastcall put_files_struct(struct files_struct *files)
405{ 407{
408 struct fdtable *fdt;
409
406 if (atomic_dec_and_test(&files->count)) { 410 if (atomic_dec_and_test(&files->count)) {
407 close_files(files); 411 close_files(files);
408 /* 412 /*
409 * Free the fd and fdset arrays if we expanded them. 413 * Free the fd and fdset arrays if we expanded them.
414 * If the fdtable was embedded, pass files for freeing
415 * at the end of the RCU grace period. Otherwise,
416 * you can free files immediately.
410 */ 417 */
411 if (files->fd != &files->fd_array[0]) 418 fdt = files_fdtable(files);
412 free_fd_array(files->fd, files->max_fds); 419 if (fdt == &files->fdtab)
413 if (files->max_fdset > __FD_SETSIZE) { 420 fdt->free_files = files;
414 free_fdset(files->open_fds, files->max_fdset); 421 else
415 free_fdset(files->close_on_exec, files->max_fdset); 422 kmem_cache_free(files_cachep, files);
416 } 423 free_fdtable(fdt);
417 kmem_cache_free(files_cachep, files);
418 } 424 }
419} 425}
420 426
diff --git a/kernel/fork.c b/kernel/fork.c
index 7e1ead9a6b..8149f36028 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -35,6 +35,7 @@
35#include <linux/syscalls.h> 35#include <linux/syscalls.h>
36#include <linux/jiffies.h> 36#include <linux/jiffies.h>
37#include <linux/futex.h> 37#include <linux/futex.h>
38#include <linux/rcupdate.h>
38#include <linux/ptrace.h> 39#include <linux/ptrace.h>
39#include <linux/mount.h> 40#include <linux/mount.h>
40#include <linux/audit.h> 41#include <linux/audit.h>
@@ -176,6 +177,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
176 177
177 /* One for us, one for whoever does the "release_task()" (usually parent) */ 178 /* One for us, one for whoever does the "release_task()" (usually parent) */
178 atomic_set(&tsk->usage,2); 179 atomic_set(&tsk->usage,2);
180 atomic_set(&tsk->fs_excl, 0);
179 return tsk; 181 return tsk;
180} 182}
181 183
@@ -564,24 +566,53 @@ static inline int copy_fs(unsigned long clone_flags, struct task_struct * tsk)
564 return 0; 566 return 0;
565} 567}
566 568
567static int count_open_files(struct files_struct *files, int size) 569static int count_open_files(struct fdtable *fdt)
568{ 570{
571 int size = fdt->max_fdset;
569 int i; 572 int i;
570 573
571 /* Find the last open fd */ 574 /* Find the last open fd */
572 for (i = size/(8*sizeof(long)); i > 0; ) { 575 for (i = size/(8*sizeof(long)); i > 0; ) {
573 if (files->open_fds->fds_bits[--i]) 576 if (fdt->open_fds->fds_bits[--i])
574 break; 577 break;
575 } 578 }
576 i = (i+1) * 8 * sizeof(long); 579 i = (i+1) * 8 * sizeof(long);
577 return i; 580 return i;
578} 581}
579 582
583static struct files_struct *alloc_files(void)
584{
585 struct files_struct *newf;
586 struct fdtable *fdt;
587
588 newf = kmem_cache_alloc(files_cachep, SLAB_KERNEL);
589 if (!newf)
590 goto out;
591
592 atomic_set(&newf->count, 1);
593
594 spin_lock_init(&newf->file_lock);
595 fdt = &newf->fdtab;
596 fdt->next_fd = 0;
597 fdt->max_fds = NR_OPEN_DEFAULT;
598 fdt->max_fdset = __FD_SETSIZE;
599 fdt->close_on_exec = &newf->close_on_exec_init;
600 fdt->open_fds = &newf->open_fds_init;
601 fdt->fd = &newf->fd_array[0];
602 INIT_RCU_HEAD(&fdt->rcu);
603 fdt->free_files = NULL;
604 fdt->next = NULL;
605 rcu_assign_pointer(newf->fdt, fdt);
606out:
607 return newf;
608}
609
580static int copy_files(unsigned long clone_flags, struct task_struct * tsk) 610static int copy_files(unsigned long clone_flags, struct task_struct * tsk)
581{ 611{
582 struct files_struct *oldf, *newf; 612 struct files_struct *oldf, *newf;
583 struct file **old_fds, **new_fds; 613 struct file **old_fds, **new_fds;
584 int open_files, size, i, error = 0, expand; 614 int open_files, size, i, error = 0, expand;
615 struct fdtable *old_fdt, *new_fdt;
585 616
586 /* 617 /*
587 * A background process may not have any files ... 618 * A background process may not have any files ...
@@ -602,35 +633,27 @@ static int copy_files(unsigned long clone_flags, struct task_struct * tsk)
602 */ 633 */
603 tsk->files = NULL; 634 tsk->files = NULL;
604 error = -ENOMEM; 635 error = -ENOMEM;
605 newf = kmem_cache_alloc(files_cachep, SLAB_KERNEL); 636 newf = alloc_files();
606 if (!newf) 637 if (!newf)
607 goto out; 638 goto out;
608 639
609 atomic_set(&newf->count, 1);
610
611 spin_lock_init(&newf->file_lock);
612 newf->next_fd = 0;
613 newf->max_fds = NR_OPEN_DEFAULT;
614 newf->max_fdset = __FD_SETSIZE;
615 newf->close_on_exec = &newf->close_on_exec_init;
616 newf->open_fds = &newf->open_fds_init;
617 newf->fd = &newf->fd_array[0];
618
619 spin_lock(&oldf->file_lock); 640 spin_lock(&oldf->file_lock);
620 641 old_fdt = files_fdtable(oldf);
621 open_files = count_open_files(oldf, oldf->max_fdset); 642 new_fdt = files_fdtable(newf);
643 size = old_fdt->max_fdset;
644 open_files = count_open_files(old_fdt);
622 expand = 0; 645 expand = 0;
623 646
624 /* 647 /*
625 * Check whether we need to allocate a larger fd array or fd set. 648 * Check whether we need to allocate a larger fd array or fd set.
626 * Note: we're not a clone task, so the open count won't change. 649 * Note: we're not a clone task, so the open count won't change.
627 */ 650 */
628 if (open_files > newf->max_fdset) { 651 if (open_files > new_fdt->max_fdset) {
629 newf->max_fdset = 0; 652 new_fdt->max_fdset = 0;
630 expand = 1; 653 expand = 1;
631 } 654 }
632 if (open_files > newf->max_fds) { 655 if (open_files > new_fdt->max_fds) {
633 newf->max_fds = 0; 656 new_fdt->max_fds = 0;
634 expand = 1; 657 expand = 1;
635 } 658 }
636 659
@@ -642,14 +665,21 @@ static int copy_files(unsigned long clone_flags, struct task_struct * tsk)
642 spin_unlock(&newf->file_lock); 665 spin_unlock(&newf->file_lock);
643 if (error < 0) 666 if (error < 0)
644 goto out_release; 667 goto out_release;
668 new_fdt = files_fdtable(newf);
669 /*
670 * Reacquire the oldf lock and a pointer to its fd table
671 * who knows it may have a new bigger fd table. We need
672 * the latest pointer.
673 */
645 spin_lock(&oldf->file_lock); 674 spin_lock(&oldf->file_lock);
675 old_fdt = files_fdtable(oldf);
646 } 676 }
647 677
648 old_fds = oldf->fd; 678 old_fds = old_fdt->fd;
649 new_fds = newf->fd; 679 new_fds = new_fdt->fd;
650 680
651 memcpy(newf->open_fds->fds_bits, oldf->open_fds->fds_bits, open_files/8); 681 memcpy(new_fdt->open_fds->fds_bits, old_fdt->open_fds->fds_bits, open_files/8);
652 memcpy(newf->close_on_exec->fds_bits, oldf->close_on_exec->fds_bits, open_files/8); 682 memcpy(new_fdt->close_on_exec->fds_bits, old_fdt->close_on_exec->fds_bits, open_files/8);
653 683
654 for (i = open_files; i != 0; i--) { 684 for (i = open_files; i != 0; i--) {
655 struct file *f = *old_fds++; 685 struct file *f = *old_fds++;
@@ -662,24 +692,24 @@ static int copy_files(unsigned long clone_flags, struct task_struct * tsk)
662 * is partway through open(). So make sure that this 692 * is partway through open(). So make sure that this
663 * fd is available to the new process. 693 * fd is available to the new process.
664 */ 694 */
665 FD_CLR(open_files - i, newf->open_fds); 695 FD_CLR(open_files - i, new_fdt->open_fds);
666 } 696 }
667 *new_fds++ = f; 697 rcu_assign_pointer(*new_fds++, f);
668 } 698 }
669 spin_unlock(&oldf->file_lock); 699 spin_unlock(&oldf->file_lock);
670 700
671 /* compute the remainder to be cleared */ 701 /* compute the remainder to be cleared */
672 size = (newf->max_fds - open_files) * sizeof(struct file *); 702 size = (new_fdt->max_fds - open_files) * sizeof(struct file *);
673 703
674 /* This is long word aligned thus could use a optimized version */ 704 /* This is long word aligned thus could use a optimized version */
675 memset(new_fds, 0, size); 705 memset(new_fds, 0, size);
676 706
677 if (newf->max_fdset > open_files) { 707 if (new_fdt->max_fdset > open_files) {
678 int left = (newf->max_fdset-open_files)/8; 708 int left = (new_fdt->max_fdset-open_files)/8;
679 int start = open_files / (8 * sizeof(unsigned long)); 709 int start = open_files / (8 * sizeof(unsigned long));
680 710
681 memset(&newf->open_fds->fds_bits[start], 0, left); 711 memset(&new_fdt->open_fds->fds_bits[start], 0, left);
682 memset(&newf->close_on_exec->fds_bits[start], 0, left); 712 memset(&new_fdt->close_on_exec->fds_bits[start], 0, left);
683 } 713 }
684 714
685 tsk->files = newf; 715 tsk->files = newf;
@@ -688,9 +718,9 @@ out:
688 return error; 718 return error;
689 719
690out_release: 720out_release:
691 free_fdset (newf->close_on_exec, newf->max_fdset); 721 free_fdset (new_fdt->close_on_exec, new_fdt->max_fdset);
692 free_fdset (newf->open_fds, newf->max_fdset); 722 free_fdset (new_fdt->open_fds, new_fdt->max_fdset);
693 free_fd_array(newf->fd, newf->max_fds); 723 free_fd_array(new_fdt->fd, new_fdt->max_fds);
694 kmem_cache_free(files_cachep, newf); 724 kmem_cache_free(files_cachep, newf);
695 goto out; 725 goto out;
696} 726}
@@ -1115,6 +1145,9 @@ static task_t *copy_process(unsigned long clone_flags,
1115 __get_cpu_var(process_counts)++; 1145 __get_cpu_var(process_counts)++;
1116 } 1146 }
1117 1147
1148 if (!current->signal->tty && p->signal->tty)
1149 p->signal->tty = NULL;
1150
1118 nr_threads++; 1151 nr_threads++;
1119 total_forks++; 1152 total_forks++;
1120 write_unlock_irq(&tasklist_lock); 1153 write_unlock_irq(&tasklist_lock);
diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
index f436993bd5..bef3b6901b 100644
--- a/kernel/rcupdate.c
+++ b/kernel/rcupdate.c
@@ -45,6 +45,7 @@
45#include <linux/percpu.h> 45#include <linux/percpu.h>
46#include <linux/notifier.h> 46#include <linux/notifier.h>
47#include <linux/rcupdate.h> 47#include <linux/rcupdate.h>
48#include <linux/rcuref.h>
48#include <linux/cpu.h> 49#include <linux/cpu.h>
49 50
50/* Definition for rcupdate control block. */ 51/* Definition for rcupdate control block. */
@@ -72,6 +73,19 @@ DEFINE_PER_CPU(struct rcu_data, rcu_bh_data) = { 0L };
72static DEFINE_PER_CPU(struct tasklet_struct, rcu_tasklet) = {NULL}; 73static DEFINE_PER_CPU(struct tasklet_struct, rcu_tasklet) = {NULL};
73static int maxbatch = 10; 74static int maxbatch = 10;
74 75
76#ifndef __HAVE_ARCH_CMPXCHG
77/*
78 * We use an array of spinlocks for the rcurefs -- similar to ones in sparc
79 * 32 bit atomic_t implementations, and a hash function similar to that
80 * for our refcounting needs.
81 * Can't help multiprocessors which donot have cmpxchg :(
82 */
83
84spinlock_t __rcuref_hash[RCUREF_HASH_SIZE] = {
85 [0 ... (RCUREF_HASH_SIZE-1)] = SPIN_LOCK_UNLOCKED
86};
87#endif
88
75/** 89/**
76 * call_rcu - Queue an RCU callback for invocation after a grace period. 90 * call_rcu - Queue an RCU callback for invocation after a grace period.
77 * @head: structure to be used for queueing the RCU updates. 91 * @head: structure to be used for queueing the RCU updates.
diff --git a/kernel/sched.c b/kernel/sched.c
index 18b95520a2..81b3a96ed2 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -875,7 +875,7 @@ static int migrate_task(task_t *p, int dest_cpu, migration_req_t *req)
875 * smp_call_function() if an IPI is sent by the same process we are 875 * smp_call_function() if an IPI is sent by the same process we are
876 * waiting to become inactive. 876 * waiting to become inactive.
877 */ 877 */
878void wait_task_inactive(task_t * p) 878void wait_task_inactive(task_t *p)
879{ 879{
880 unsigned long flags; 880 unsigned long flags;
881 runqueue_t *rq; 881 runqueue_t *rq;
@@ -966,8 +966,11 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, int this_cpu)
966 int local_group; 966 int local_group;
967 int i; 967 int i;
968 968
969 /* Skip over this group if it has no CPUs allowed */
970 if (!cpus_intersects(group->cpumask, p->cpus_allowed))
971 goto nextgroup;
972
969 local_group = cpu_isset(this_cpu, group->cpumask); 973 local_group = cpu_isset(this_cpu, group->cpumask);
970 /* XXX: put a cpus allowed check */
971 974
972 /* Tally up the load of all CPUs in the group */ 975 /* Tally up the load of all CPUs in the group */
973 avg_load = 0; 976 avg_load = 0;
@@ -992,6 +995,7 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, int this_cpu)
992 min_load = avg_load; 995 min_load = avg_load;
993 idlest = group; 996 idlest = group;
994 } 997 }
998nextgroup:
995 group = group->next; 999 group = group->next;
996 } while (group != sd->groups); 1000 } while (group != sd->groups);
997 1001
@@ -1003,13 +1007,18 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, int this_cpu)
1003/* 1007/*
1004 * find_idlest_queue - find the idlest runqueue among the cpus in group. 1008 * find_idlest_queue - find the idlest runqueue among the cpus in group.
1005 */ 1009 */
1006static int find_idlest_cpu(struct sched_group *group, int this_cpu) 1010static int
1011find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
1007{ 1012{
1013 cpumask_t tmp;
1008 unsigned long load, min_load = ULONG_MAX; 1014 unsigned long load, min_load = ULONG_MAX;
1009 int idlest = -1; 1015 int idlest = -1;
1010 int i; 1016 int i;
1011 1017
1012 for_each_cpu_mask(i, group->cpumask) { 1018 /* Traverse only the allowed CPUs */
1019 cpus_and(tmp, group->cpumask, p->cpus_allowed);
1020
1021 for_each_cpu_mask(i, tmp) {
1013 load = source_load(i, 0); 1022 load = source_load(i, 0);
1014 1023
1015 if (load < min_load || (load == min_load && i == this_cpu)) { 1024 if (load < min_load || (load == min_load && i == this_cpu)) {
@@ -1052,7 +1061,7 @@ static int sched_balance_self(int cpu, int flag)
1052 if (!group) 1061 if (!group)
1053 goto nextlevel; 1062 goto nextlevel;
1054 1063
1055 new_cpu = find_idlest_cpu(group, cpu); 1064 new_cpu = find_idlest_cpu(group, t, cpu);
1056 if (new_cpu == -1 || new_cpu == cpu) 1065 if (new_cpu == -1 || new_cpu == cpu)
1057 goto nextlevel; 1066 goto nextlevel;
1058 1067
@@ -1127,7 +1136,7 @@ static inline int wake_idle(int cpu, task_t *p)
1127 * 1136 *
1128 * returns failure only if the task is already active. 1137 * returns failure only if the task is already active.
1129 */ 1138 */
1130static int try_to_wake_up(task_t * p, unsigned int state, int sync) 1139static int try_to_wake_up(task_t *p, unsigned int state, int sync)
1131{ 1140{
1132 int cpu, this_cpu, success = 0; 1141 int cpu, this_cpu, success = 0;
1133 unsigned long flags; 1142 unsigned long flags;
@@ -1252,6 +1261,16 @@ out_activate:
1252 } 1261 }
1253 1262
1254 /* 1263 /*
1264 * Tasks that have marked their sleep as noninteractive get
1265 * woken up without updating their sleep average. (i.e. their
1266 * sleep is handled in a priority-neutral manner, no priority
1267 * boost and no penalty.)
1268 */
1269 if (old_state & TASK_NONINTERACTIVE)
1270 __activate_task(p, rq);
1271 else
1272 activate_task(p, rq, cpu == this_cpu);
1273 /*
1255 * Sync wakeups (i.e. those types of wakeups where the waker 1274 * Sync wakeups (i.e. those types of wakeups where the waker
1256 * has indicated that it will leave the CPU in short order) 1275 * has indicated that it will leave the CPU in short order)
1257 * don't trigger a preemption, if the woken up task will run on 1276 * don't trigger a preemption, if the woken up task will run on
@@ -1259,7 +1278,6 @@ out_activate:
1259 * the waker guarantees that the freshly woken up task is going 1278 * the waker guarantees that the freshly woken up task is going
1260 * to be considered on this CPU.) 1279 * to be considered on this CPU.)
1261 */ 1280 */
1262 activate_task(p, rq, cpu == this_cpu);
1263 if (!sync || cpu != this_cpu) { 1281 if (!sync || cpu != this_cpu) {
1264 if (TASK_PREEMPTS_CURR(p, rq)) 1282 if (TASK_PREEMPTS_CURR(p, rq))
1265 resched_task(rq->curr); 1283 resched_task(rq->curr);
@@ -1274,7 +1292,7 @@ out:
1274 return success; 1292 return success;
1275} 1293}
1276 1294
1277int fastcall wake_up_process(task_t * p) 1295int fastcall wake_up_process(task_t *p)
1278{ 1296{
1279 return try_to_wake_up(p, TASK_STOPPED | TASK_TRACED | 1297 return try_to_wake_up(p, TASK_STOPPED | TASK_TRACED |
1280 TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE, 0); 1298 TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE, 0);
@@ -1353,7 +1371,7 @@ void fastcall sched_fork(task_t *p, int clone_flags)
1353 * that must be done for every newly created context, then puts the task 1371 * that must be done for every newly created context, then puts the task
1354 * on the runqueue and wakes it. 1372 * on the runqueue and wakes it.
1355 */ 1373 */
1356void fastcall wake_up_new_task(task_t * p, unsigned long clone_flags) 1374void fastcall wake_up_new_task(task_t *p, unsigned long clone_flags)
1357{ 1375{
1358 unsigned long flags; 1376 unsigned long flags;
1359 int this_cpu, cpu; 1377 int this_cpu, cpu;
@@ -1436,7 +1454,7 @@ void fastcall wake_up_new_task(task_t * p, unsigned long clone_flags)
1436 * artificially, because any timeslice recovered here 1454 * artificially, because any timeslice recovered here
1437 * was given away by the parent in the first place.) 1455 * was given away by the parent in the first place.)
1438 */ 1456 */
1439void fastcall sched_exit(task_t * p) 1457void fastcall sched_exit(task_t *p)
1440{ 1458{
1441 unsigned long flags; 1459 unsigned long flags;
1442 runqueue_t *rq; 1460 runqueue_t *rq;
@@ -1511,6 +1529,10 @@ static inline void finish_task_switch(runqueue_t *rq, task_t *prev)
1511 * Manfred Spraul <manfred@colorfullife.com> 1529 * Manfred Spraul <manfred@colorfullife.com>
1512 */ 1530 */
1513 prev_task_flags = prev->flags; 1531 prev_task_flags = prev->flags;
1532#ifdef CONFIG_DEBUG_SPINLOCK
1533 /* this is a valid case when another task releases the spinlock */
1534 rq->lock.owner = current;
1535#endif
1514 finish_arch_switch(prev); 1536 finish_arch_switch(prev);
1515 finish_lock_switch(rq, prev); 1537 finish_lock_switch(rq, prev);
1516 if (mm) 1538 if (mm)
@@ -1753,7 +1775,8 @@ void pull_task(runqueue_t *src_rq, prio_array_t *src_array, task_t *p,
1753 */ 1775 */
1754static inline 1776static inline
1755int can_migrate_task(task_t *p, runqueue_t *rq, int this_cpu, 1777int can_migrate_task(task_t *p, runqueue_t *rq, int this_cpu,
1756 struct sched_domain *sd, enum idle_type idle, int *all_pinned) 1778 struct sched_domain *sd, enum idle_type idle,
1779 int *all_pinned)
1757{ 1780{
1758 /* 1781 /*
1759 * We do not migrate tasks that are: 1782 * We do not migrate tasks that are:
@@ -1883,10 +1906,11 @@ out:
1883 */ 1906 */
1884static struct sched_group * 1907static struct sched_group *
1885find_busiest_group(struct sched_domain *sd, int this_cpu, 1908find_busiest_group(struct sched_domain *sd, int this_cpu,
1886 unsigned long *imbalance, enum idle_type idle) 1909 unsigned long *imbalance, enum idle_type idle, int *sd_idle)
1887{ 1910{
1888 struct sched_group *busiest = NULL, *this = NULL, *group = sd->groups; 1911 struct sched_group *busiest = NULL, *this = NULL, *group = sd->groups;
1889 unsigned long max_load, avg_load, total_load, this_load, total_pwr; 1912 unsigned long max_load, avg_load, total_load, this_load, total_pwr;
1913 unsigned long max_pull;
1890 int load_idx; 1914 int load_idx;
1891 1915
1892 max_load = this_load = total_load = total_pwr = 0; 1916 max_load = this_load = total_load = total_pwr = 0;
@@ -1908,6 +1932,9 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
1908 avg_load = 0; 1932 avg_load = 0;
1909 1933
1910 for_each_cpu_mask(i, group->cpumask) { 1934 for_each_cpu_mask(i, group->cpumask) {
1935 if (*sd_idle && !idle_cpu(i))
1936 *sd_idle = 0;
1937
1911 /* Bias balancing toward cpus of our domain */ 1938 /* Bias balancing toward cpus of our domain */
1912 if (local_group) 1939 if (local_group)
1913 load = target_load(i, load_idx); 1940 load = target_load(i, load_idx);
@@ -1933,7 +1960,7 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
1933 group = group->next; 1960 group = group->next;
1934 } while (group != sd->groups); 1961 } while (group != sd->groups);
1935 1962
1936 if (!busiest || this_load >= max_load) 1963 if (!busiest || this_load >= max_load || max_load <= SCHED_LOAD_SCALE)
1937 goto out_balanced; 1964 goto out_balanced;
1938 1965
1939 avg_load = (SCHED_LOAD_SCALE * total_load) / total_pwr; 1966 avg_load = (SCHED_LOAD_SCALE * total_load) / total_pwr;
@@ -1953,8 +1980,12 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
1953 * by pulling tasks to us. Be careful of negative numbers as they'll 1980 * by pulling tasks to us. Be careful of negative numbers as they'll
1954 * appear as very large values with unsigned longs. 1981 * appear as very large values with unsigned longs.
1955 */ 1982 */
1983
1984 /* Don't want to pull so many tasks that a group would go idle */
1985 max_pull = min(max_load - avg_load, max_load - SCHED_LOAD_SCALE);
1986
1956 /* How much load to actually move to equalise the imbalance */ 1987 /* How much load to actually move to equalise the imbalance */
1957 *imbalance = min((max_load - avg_load) * busiest->cpu_power, 1988 *imbalance = min(max_pull * busiest->cpu_power,
1958 (avg_load - this_load) * this->cpu_power) 1989 (avg_load - this_load) * this->cpu_power)
1959 / SCHED_LOAD_SCALE; 1990 / SCHED_LOAD_SCALE;
1960 1991
@@ -2051,11 +2082,14 @@ static int load_balance(int this_cpu, runqueue_t *this_rq,
2051 unsigned long imbalance; 2082 unsigned long imbalance;
2052 int nr_moved, all_pinned = 0; 2083 int nr_moved, all_pinned = 0;
2053 int active_balance = 0; 2084 int active_balance = 0;
2085 int sd_idle = 0;
2086
2087 if (idle != NOT_IDLE && sd->flags & SD_SHARE_CPUPOWER)
2088 sd_idle = 1;
2054 2089
2055 spin_lock(&this_rq->lock);
2056 schedstat_inc(sd, lb_cnt[idle]); 2090 schedstat_inc(sd, lb_cnt[idle]);
2057 2091
2058 group = find_busiest_group(sd, this_cpu, &imbalance, idle); 2092 group = find_busiest_group(sd, this_cpu, &imbalance, idle, &sd_idle);
2059 if (!group) { 2093 if (!group) {
2060 schedstat_inc(sd, lb_nobusyg[idle]); 2094 schedstat_inc(sd, lb_nobusyg[idle]);
2061 goto out_balanced; 2095 goto out_balanced;
@@ -2079,19 +2113,16 @@ static int load_balance(int this_cpu, runqueue_t *this_rq,
2079 * still unbalanced. nr_moved simply stays zero, so it is 2113 * still unbalanced. nr_moved simply stays zero, so it is
2080 * correctly treated as an imbalance. 2114 * correctly treated as an imbalance.
2081 */ 2115 */
2082 double_lock_balance(this_rq, busiest); 2116 double_rq_lock(this_rq, busiest);
2083 nr_moved = move_tasks(this_rq, this_cpu, busiest, 2117 nr_moved = move_tasks(this_rq, this_cpu, busiest,
2084 imbalance, sd, idle, 2118 imbalance, sd, idle, &all_pinned);
2085 &all_pinned); 2119 double_rq_unlock(this_rq, busiest);
2086 spin_unlock(&busiest->lock);
2087 2120
2088 /* All tasks on this runqueue were pinned by CPU affinity */ 2121 /* All tasks on this runqueue were pinned by CPU affinity */
2089 if (unlikely(all_pinned)) 2122 if (unlikely(all_pinned))
2090 goto out_balanced; 2123 goto out_balanced;
2091 } 2124 }
2092 2125
2093 spin_unlock(&this_rq->lock);
2094
2095 if (!nr_moved) { 2126 if (!nr_moved) {
2096 schedstat_inc(sd, lb_failed[idle]); 2127 schedstat_inc(sd, lb_failed[idle]);
2097 sd->nr_balance_failed++; 2128 sd->nr_balance_failed++;
@@ -2099,6 +2130,16 @@ static int load_balance(int this_cpu, runqueue_t *this_rq,
2099 if (unlikely(sd->nr_balance_failed > sd->cache_nice_tries+2)) { 2130 if (unlikely(sd->nr_balance_failed > sd->cache_nice_tries+2)) {
2100 2131
2101 spin_lock(&busiest->lock); 2132 spin_lock(&busiest->lock);
2133
2134 /* don't kick the migration_thread, if the curr
2135 * task on busiest cpu can't be moved to this_cpu
2136 */
2137 if (!cpu_isset(this_cpu, busiest->curr->cpus_allowed)) {
2138 spin_unlock(&busiest->lock);
2139 all_pinned = 1;
2140 goto out_one_pinned;
2141 }
2142
2102 if (!busiest->active_balance) { 2143 if (!busiest->active_balance) {
2103 busiest->active_balance = 1; 2144 busiest->active_balance = 1;
2104 busiest->push_cpu = this_cpu; 2145 busiest->push_cpu = this_cpu;
@@ -2131,19 +2172,23 @@ static int load_balance(int this_cpu, runqueue_t *this_rq,
2131 sd->balance_interval *= 2; 2172 sd->balance_interval *= 2;
2132 } 2173 }
2133 2174
2175 if (!nr_moved && !sd_idle && sd->flags & SD_SHARE_CPUPOWER)
2176 return -1;
2134 return nr_moved; 2177 return nr_moved;
2135 2178
2136out_balanced: 2179out_balanced:
2137 spin_unlock(&this_rq->lock);
2138
2139 schedstat_inc(sd, lb_balanced[idle]); 2180 schedstat_inc(sd, lb_balanced[idle]);
2140 2181
2141 sd->nr_balance_failed = 0; 2182 sd->nr_balance_failed = 0;
2183
2184out_one_pinned:
2142 /* tune up the balancing interval */ 2185 /* tune up the balancing interval */
2143 if ((all_pinned && sd->balance_interval < MAX_PINNED_INTERVAL) || 2186 if ((all_pinned && sd->balance_interval < MAX_PINNED_INTERVAL) ||
2144 (sd->balance_interval < sd->max_interval)) 2187 (sd->balance_interval < sd->max_interval))
2145 sd->balance_interval *= 2; 2188 sd->balance_interval *= 2;
2146 2189
2190 if (!sd_idle && sd->flags & SD_SHARE_CPUPOWER)
2191 return -1;
2147 return 0; 2192 return 0;
2148} 2193}
2149 2194
@@ -2161,9 +2206,13 @@ static int load_balance_newidle(int this_cpu, runqueue_t *this_rq,
2161 runqueue_t *busiest = NULL; 2206 runqueue_t *busiest = NULL;
2162 unsigned long imbalance; 2207 unsigned long imbalance;
2163 int nr_moved = 0; 2208 int nr_moved = 0;
2209 int sd_idle = 0;
2210
2211 if (sd->flags & SD_SHARE_CPUPOWER)
2212 sd_idle = 1;
2164 2213
2165 schedstat_inc(sd, lb_cnt[NEWLY_IDLE]); 2214 schedstat_inc(sd, lb_cnt[NEWLY_IDLE]);
2166 group = find_busiest_group(sd, this_cpu, &imbalance, NEWLY_IDLE); 2215 group = find_busiest_group(sd, this_cpu, &imbalance, NEWLY_IDLE, &sd_idle);
2167 if (!group) { 2216 if (!group) {
2168 schedstat_inc(sd, lb_nobusyg[NEWLY_IDLE]); 2217 schedstat_inc(sd, lb_nobusyg[NEWLY_IDLE]);
2169 goto out_balanced; 2218 goto out_balanced;
@@ -2177,22 +2226,30 @@ static int load_balance_newidle(int this_cpu, runqueue_t *this_rq,
2177 2226
2178 BUG_ON(busiest == this_rq); 2227 BUG_ON(busiest == this_rq);
2179 2228
2180 /* Attempt to move tasks */
2181 double_lock_balance(this_rq, busiest);
2182
2183 schedstat_add(sd, lb_imbalance[NEWLY_IDLE], imbalance); 2229 schedstat_add(sd, lb_imbalance[NEWLY_IDLE], imbalance);
2184 nr_moved = move_tasks(this_rq, this_cpu, busiest, 2230
2231 nr_moved = 0;
2232 if (busiest->nr_running > 1) {
2233 /* Attempt to move tasks */
2234 double_lock_balance(this_rq, busiest);
2235 nr_moved = move_tasks(this_rq, this_cpu, busiest,
2185 imbalance, sd, NEWLY_IDLE, NULL); 2236 imbalance, sd, NEWLY_IDLE, NULL);
2186 if (!nr_moved) 2237 spin_unlock(&busiest->lock);
2238 }
2239
2240 if (!nr_moved) {
2187 schedstat_inc(sd, lb_failed[NEWLY_IDLE]); 2241 schedstat_inc(sd, lb_failed[NEWLY_IDLE]);
2188 else 2242 if (!sd_idle && sd->flags & SD_SHARE_CPUPOWER)
2243 return -1;
2244 } else
2189 sd->nr_balance_failed = 0; 2245 sd->nr_balance_failed = 0;
2190 2246
2191 spin_unlock(&busiest->lock);
2192 return nr_moved; 2247 return nr_moved;
2193 2248
2194out_balanced: 2249out_balanced:
2195 schedstat_inc(sd, lb_balanced[NEWLY_IDLE]); 2250 schedstat_inc(sd, lb_balanced[NEWLY_IDLE]);
2251 if (!sd_idle && sd->flags & SD_SHARE_CPUPOWER)
2252 return -1;
2196 sd->nr_balance_failed = 0; 2253 sd->nr_balance_failed = 0;
2197 return 0; 2254 return 0;
2198} 2255}
@@ -2317,7 +2374,11 @@ static void rebalance_tick(int this_cpu, runqueue_t *this_rq,
2317 2374
2318 if (j - sd->last_balance >= interval) { 2375 if (j - sd->last_balance >= interval) {
2319 if (load_balance(this_cpu, this_rq, sd, idle)) { 2376 if (load_balance(this_cpu, this_rq, sd, idle)) {
2320 /* We've pulled tasks over so no longer idle */ 2377 /*
2378 * We've pulled tasks over so either we're no
2379 * longer idle, or one of our SMT siblings is
2380 * not idle.
2381 */
2321 idle = NOT_IDLE; 2382 idle = NOT_IDLE;
2322 } 2383 }
2323 sd->last_balance += interval; 2384 sd->last_balance += interval;
@@ -2576,6 +2637,13 @@ out:
2576} 2637}
2577 2638
2578#ifdef CONFIG_SCHED_SMT 2639#ifdef CONFIG_SCHED_SMT
2640static inline void wakeup_busy_runqueue(runqueue_t *rq)
2641{
2642 /* If an SMT runqueue is sleeping due to priority reasons wake it up */
2643 if (rq->curr == rq->idle && rq->nr_running)
2644 resched_task(rq->idle);
2645}
2646
2579static inline void wake_sleeping_dependent(int this_cpu, runqueue_t *this_rq) 2647static inline void wake_sleeping_dependent(int this_cpu, runqueue_t *this_rq)
2580{ 2648{
2581 struct sched_domain *tmp, *sd = NULL; 2649 struct sched_domain *tmp, *sd = NULL;
@@ -2609,12 +2677,7 @@ static inline void wake_sleeping_dependent(int this_cpu, runqueue_t *this_rq)
2609 for_each_cpu_mask(i, sibling_map) { 2677 for_each_cpu_mask(i, sibling_map) {
2610 runqueue_t *smt_rq = cpu_rq(i); 2678 runqueue_t *smt_rq = cpu_rq(i);
2611 2679
2612 /* 2680 wakeup_busy_runqueue(smt_rq);
2613 * If an SMT sibling task is sleeping due to priority
2614 * reasons wake it up now.
2615 */
2616 if (smt_rq->curr == smt_rq->idle && smt_rq->nr_running)
2617 resched_task(smt_rq->idle);
2618 } 2681 }
2619 2682
2620 for_each_cpu_mask(i, sibling_map) 2683 for_each_cpu_mask(i, sibling_map)
@@ -2625,6 +2688,16 @@ static inline void wake_sleeping_dependent(int this_cpu, runqueue_t *this_rq)
2625 */ 2688 */
2626} 2689}
2627 2690
2691/*
2692 * number of 'lost' timeslices this task wont be able to fully
2693 * utilize, if another task runs on a sibling. This models the
2694 * slowdown effect of other tasks running on siblings:
2695 */
2696static inline unsigned long smt_slice(task_t *p, struct sched_domain *sd)
2697{
2698 return p->time_slice * (100 - sd->per_cpu_gain) / 100;
2699}
2700
2628static inline int dependent_sleeper(int this_cpu, runqueue_t *this_rq) 2701static inline int dependent_sleeper(int this_cpu, runqueue_t *this_rq)
2629{ 2702{
2630 struct sched_domain *tmp, *sd = NULL; 2703 struct sched_domain *tmp, *sd = NULL;
@@ -2668,6 +2741,10 @@ static inline int dependent_sleeper(int this_cpu, runqueue_t *this_rq)
2668 runqueue_t *smt_rq = cpu_rq(i); 2741 runqueue_t *smt_rq = cpu_rq(i);
2669 task_t *smt_curr = smt_rq->curr; 2742 task_t *smt_curr = smt_rq->curr;
2670 2743
2744 /* Kernel threads do not participate in dependent sleeping */
2745 if (!p->mm || !smt_curr->mm || rt_task(p))
2746 goto check_smt_task;
2747
2671 /* 2748 /*
2672 * If a user task with lower static priority than the 2749 * If a user task with lower static priority than the
2673 * running task on the SMT sibling is trying to schedule, 2750 * running task on the SMT sibling is trying to schedule,
@@ -2676,21 +2753,45 @@ static inline int dependent_sleeper(int this_cpu, runqueue_t *this_rq)
2676 * task from using an unfair proportion of the 2753 * task from using an unfair proportion of the
2677 * physical cpu's resources. -ck 2754 * physical cpu's resources. -ck
2678 */ 2755 */
2679 if (((smt_curr->time_slice * (100 - sd->per_cpu_gain) / 100) > 2756 if (rt_task(smt_curr)) {
2680 task_timeslice(p) || rt_task(smt_curr)) && 2757 /*
2681 p->mm && smt_curr->mm && !rt_task(p)) 2758 * With real time tasks we run non-rt tasks only
2682 ret = 1; 2759 * per_cpu_gain% of the time.
2760 */
2761 if ((jiffies % DEF_TIMESLICE) >
2762 (sd->per_cpu_gain * DEF_TIMESLICE / 100))
2763 ret = 1;
2764 } else
2765 if (smt_curr->static_prio < p->static_prio &&
2766 !TASK_PREEMPTS_CURR(p, smt_rq) &&
2767 smt_slice(smt_curr, sd) > task_timeslice(p))
2768 ret = 1;
2769
2770check_smt_task:
2771 if ((!smt_curr->mm && smt_curr != smt_rq->idle) ||
2772 rt_task(smt_curr))
2773 continue;
2774 if (!p->mm) {
2775 wakeup_busy_runqueue(smt_rq);
2776 continue;
2777 }
2683 2778
2684 /* 2779 /*
2685 * Reschedule a lower priority task on the SMT sibling, 2780 * Reschedule a lower priority task on the SMT sibling for
2686 * or wake it up if it has been put to sleep for priority 2781 * it to be put to sleep, or wake it up if it has been put to
2687 * reasons. 2782 * sleep for priority reasons to see if it should run now.
2688 */ 2783 */
2689 if ((((p->time_slice * (100 - sd->per_cpu_gain) / 100) > 2784 if (rt_task(p)) {
2690 task_timeslice(smt_curr) || rt_task(p)) && 2785 if ((jiffies % DEF_TIMESLICE) >
2691 smt_curr->mm && p->mm && !rt_task(smt_curr)) || 2786 (sd->per_cpu_gain * DEF_TIMESLICE / 100))
2692 (smt_curr == smt_rq->idle && smt_rq->nr_running)) 2787 resched_task(smt_curr);
2693 resched_task(smt_curr); 2788 } else {
2789 if (TASK_PREEMPTS_CURR(p, smt_rq) &&
2790 smt_slice(p, sd) > task_timeslice(smt_curr))
2791 resched_task(smt_curr);
2792 else
2793 wakeup_busy_runqueue(smt_rq);
2794 }
2694 } 2795 }
2695out_unlock: 2796out_unlock:
2696 for_each_cpu_mask(i, sibling_map) 2797 for_each_cpu_mask(i, sibling_map)
@@ -2888,6 +2989,7 @@ switch_tasks:
2888 if (next == rq->idle) 2989 if (next == rq->idle)
2889 schedstat_inc(rq, sched_goidle); 2990 schedstat_inc(rq, sched_goidle);
2890 prefetch(next); 2991 prefetch(next);
2992 prefetch_stack(next);
2891 clear_tsk_need_resched(prev); 2993 clear_tsk_need_resched(prev);
2892 rcu_qsctr_inc(task_cpu(prev)); 2994 rcu_qsctr_inc(task_cpu(prev));
2893 2995
@@ -3015,7 +3117,8 @@ need_resched:
3015 3117
3016#endif /* CONFIG_PREEMPT */ 3118#endif /* CONFIG_PREEMPT */
3017 3119
3018int default_wake_function(wait_queue_t *curr, unsigned mode, int sync, void *key) 3120int default_wake_function(wait_queue_t *curr, unsigned mode, int sync,
3121 void *key)
3019{ 3122{
3020 task_t *p = curr->private; 3123 task_t *p = curr->private;
3021 return try_to_wake_up(p, mode, sync); 3124 return try_to_wake_up(p, mode, sync);
@@ -3057,7 +3160,7 @@ static void __wake_up_common(wait_queue_head_t *q, unsigned int mode,
3057 * @key: is directly passed to the wakeup function 3160 * @key: is directly passed to the wakeup function
3058 */ 3161 */
3059void fastcall __wake_up(wait_queue_head_t *q, unsigned int mode, 3162void fastcall __wake_up(wait_queue_head_t *q, unsigned int mode,
3060 int nr_exclusive, void *key) 3163 int nr_exclusive, void *key)
3061{ 3164{
3062 unsigned long flags; 3165 unsigned long flags;
3063 3166
@@ -3089,7 +3192,8 @@ void fastcall __wake_up_locked(wait_queue_head_t *q, unsigned int mode)
3089 * 3192 *
3090 * On UP it can prevent extra preemption. 3193 * On UP it can prevent extra preemption.
3091 */ 3194 */
3092void fastcall __wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr_exclusive) 3195void fastcall
3196__wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr_exclusive)
3093{ 3197{
3094 unsigned long flags; 3198 unsigned long flags;
3095 int sync = 1; 3199 int sync = 1;
@@ -3280,7 +3384,8 @@ void fastcall __sched interruptible_sleep_on(wait_queue_head_t *q)
3280 3384
3281EXPORT_SYMBOL(interruptible_sleep_on); 3385EXPORT_SYMBOL(interruptible_sleep_on);
3282 3386
3283long fastcall __sched interruptible_sleep_on_timeout(wait_queue_head_t *q, long timeout) 3387long fastcall __sched
3388interruptible_sleep_on_timeout(wait_queue_head_t *q, long timeout)
3284{ 3389{
3285 SLEEP_ON_VAR 3390 SLEEP_ON_VAR
3286 3391
@@ -3499,7 +3604,8 @@ static void __setscheduler(struct task_struct *p, int policy, int prio)
3499 * @policy: new policy. 3604 * @policy: new policy.
3500 * @param: structure containing the new RT priority. 3605 * @param: structure containing the new RT priority.
3501 */ 3606 */
3502int sched_setscheduler(struct task_struct *p, int policy, struct sched_param *param) 3607int sched_setscheduler(struct task_struct *p, int policy,
3608 struct sched_param *param)
3503{ 3609{
3504 int retval; 3610 int retval;
3505 int oldprio, oldpolicy = -1; 3611 int oldprio, oldpolicy = -1;
@@ -3519,7 +3625,7 @@ recheck:
3519 * 1..MAX_USER_RT_PRIO-1, valid priority for SCHED_NORMAL is 0. 3625 * 1..MAX_USER_RT_PRIO-1, valid priority for SCHED_NORMAL is 0.
3520 */ 3626 */
3521 if (param->sched_priority < 0 || 3627 if (param->sched_priority < 0 ||
3522 (p->mm && param->sched_priority > MAX_USER_RT_PRIO-1) || 3628 (p->mm && param->sched_priority > MAX_USER_RT_PRIO-1) ||
3523 (!p->mm && param->sched_priority > MAX_RT_PRIO-1)) 3629 (!p->mm && param->sched_priority > MAX_RT_PRIO-1))
3524 return -EINVAL; 3630 return -EINVAL;
3525 if ((policy == SCHED_NORMAL) != (param->sched_priority == 0)) 3631 if ((policy == SCHED_NORMAL) != (param->sched_priority == 0))
@@ -3582,7 +3688,8 @@ recheck:
3582} 3688}
3583EXPORT_SYMBOL_GPL(sched_setscheduler); 3689EXPORT_SYMBOL_GPL(sched_setscheduler);
3584 3690
3585static int do_sched_setscheduler(pid_t pid, int policy, struct sched_param __user *param) 3691static int
3692do_sched_setscheduler(pid_t pid, int policy, struct sched_param __user *param)
3586{ 3693{
3587 int retval; 3694 int retval;
3588 struct sched_param lparam; 3695 struct sched_param lparam;
@@ -3849,7 +3956,7 @@ asmlinkage long sys_sched_yield(void)
3849 if (rt_task(current)) 3956 if (rt_task(current))
3850 target = rq->active; 3957 target = rq->active;
3851 3958
3852 if (current->array->nr_active == 1) { 3959 if (array->nr_active == 1) {
3853 schedstat_inc(rq, yld_act_empty); 3960 schedstat_inc(rq, yld_act_empty);
3854 if (!rq->expired->nr_active) 3961 if (!rq->expired->nr_active)
3855 schedstat_inc(rq, yld_both_empty); 3962 schedstat_inc(rq, yld_both_empty);
@@ -3913,7 +4020,7 @@ EXPORT_SYMBOL(cond_resched);
3913 * operations here to prevent schedule() from being called twice (once via 4020 * operations here to prevent schedule() from being called twice (once via
3914 * spin_unlock(), once by hand). 4021 * spin_unlock(), once by hand).
3915 */ 4022 */
3916int cond_resched_lock(spinlock_t * lock) 4023int cond_resched_lock(spinlock_t *lock)
3917{ 4024{
3918 int ret = 0; 4025 int ret = 0;
3919 4026
@@ -4096,7 +4203,7 @@ static inline struct task_struct *younger_sibling(struct task_struct *p)
4096 return list_entry(p->sibling.next,struct task_struct,sibling); 4203 return list_entry(p->sibling.next,struct task_struct,sibling);
4097} 4204}
4098 4205
4099static void show_task(task_t * p) 4206static void show_task(task_t *p)
4100{ 4207{
4101 task_t *relative; 4208 task_t *relative;
4102 unsigned state; 4209 unsigned state;
@@ -4122,7 +4229,7 @@ static void show_task(task_t * p)
4122#endif 4229#endif
4123#ifdef CONFIG_DEBUG_STACK_USAGE 4230#ifdef CONFIG_DEBUG_STACK_USAGE
4124 { 4231 {
4125 unsigned long * n = (unsigned long *) (p->thread_info+1); 4232 unsigned long *n = (unsigned long *) (p->thread_info+1);
4126 while (!*n) 4233 while (!*n)
4127 n++; 4234 n++;
4128 free = (unsigned long) n - (unsigned long)(p->thread_info+1); 4235 free = (unsigned long) n - (unsigned long)(p->thread_info+1);
@@ -4331,7 +4438,7 @@ out:
4331 * thread migration by bumping thread off CPU then 'pushing' onto 4438 * thread migration by bumping thread off CPU then 'pushing' onto
4332 * another runqueue. 4439 * another runqueue.
4333 */ 4440 */
4334static int migration_thread(void * data) 4441static int migration_thread(void *data)
4335{ 4442{
4336 runqueue_t *rq; 4443 runqueue_t *rq;
4337 int cpu = (long)data; 4444 int cpu = (long)data;
@@ -5495,3 +5602,47 @@ void normalize_rt_tasks(void)
5495} 5602}
5496 5603
5497#endif /* CONFIG_MAGIC_SYSRQ */ 5604#endif /* CONFIG_MAGIC_SYSRQ */
5605
5606#ifdef CONFIG_IA64
5607/*
5608 * These functions are only useful for the IA64 MCA handling.
5609 *
5610 * They can only be called when the whole system has been
5611 * stopped - every CPU needs to be quiescent, and no scheduling
5612 * activity can take place. Using them for anything else would
5613 * be a serious bug, and as a result, they aren't even visible
5614 * under any other configuration.
5615 */
5616
5617/**
5618 * curr_task - return the current task for a given cpu.
5619 * @cpu: the processor in question.
5620 *
5621 * ONLY VALID WHEN THE WHOLE SYSTEM IS STOPPED!
5622 */
5623task_t *curr_task(int cpu)
5624{
5625 return cpu_curr(cpu);
5626}
5627
5628/**
5629 * set_curr_task - set the current task for a given cpu.
5630 * @cpu: the processor in question.
5631 * @p: the task pointer to set.
5632 *
5633 * Description: This function must only be used when non-maskable interrupts
5634 * are serviced on a separate stack. It allows the architecture to switch the
5635 * notion of the current task on a cpu in a non-blocking manner. This function
5636 * must be called with all CPU's synchronized, and interrupts disabled, the
5637 * and caller must save the original value of the current task (see
5638 * curr_task() above) and restore that value before reenabling interrupts and
5639 * re-starting the system.
5640 *
5641 * ONLY VALID WHEN THE WHOLE SYSTEM IS STOPPED!
5642 */
5643void set_curr_task(int cpu, task_t *p)
5644{
5645 cpu_curr(cpu) = p;
5646}
5647
5648#endif
diff --git a/kernel/signal.c b/kernel/signal.c
index 4980a07323..b92c3c9f8b 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2221,8 +2221,7 @@ sys_rt_sigtimedwait(const sigset_t __user *uthese,
2221 recalc_sigpending(); 2221 recalc_sigpending();
2222 spin_unlock_irq(&current->sighand->siglock); 2222 spin_unlock_irq(&current->sighand->siglock);
2223 2223
2224 current->state = TASK_INTERRUPTIBLE; 2224 timeout = schedule_timeout_interruptible(timeout);
2225 timeout = schedule_timeout(timeout);
2226 2225
2227 try_to_freeze(); 2226 try_to_freeze();
2228 spin_lock_irq(&current->sighand->siglock); 2227 spin_lock_irq(&current->sighand->siglock);
diff --git a/kernel/softirq.c b/kernel/softirq.c
index b4ab6af1de..f766b2fc48 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -84,7 +84,7 @@ asmlinkage void __do_softirq(void)
84 cpu = smp_processor_id(); 84 cpu = smp_processor_id();
85restart: 85restart:
86 /* Reset the pending bitmask before enabling irqs */ 86 /* Reset the pending bitmask before enabling irqs */
87 local_softirq_pending() = 0; 87 set_softirq_pending(0);
88 88
89 local_irq_enable(); 89 local_irq_enable();
90 90
diff --git a/kernel/spinlock.c b/kernel/spinlock.c
index 0c3f9d8bbe..0375fcd592 100644
--- a/kernel/spinlock.c
+++ b/kernel/spinlock.c
@@ -3,7 +3,10 @@
3 * 3 *
4 * Author: Zwane Mwaikambo <zwane@fsmlabs.com> 4 * Author: Zwane Mwaikambo <zwane@fsmlabs.com>
5 * 5 *
6 * Copyright (2004) Ingo Molnar 6 * Copyright (2004, 2005) Ingo Molnar
7 *
8 * This file contains the spinlock/rwlock implementations for the
9 * SMP and the DEBUG_SPINLOCK cases. (UP-nondebug inlines them)
7 */ 10 */
8 11
9#include <linux/config.h> 12#include <linux/config.h>
@@ -17,12 +20,12 @@
17 * Generic declaration of the raw read_trylock() function, 20 * Generic declaration of the raw read_trylock() function,
18 * architectures are supposed to optimize this: 21 * architectures are supposed to optimize this:
19 */ 22 */
20int __lockfunc generic_raw_read_trylock(rwlock_t *lock) 23int __lockfunc generic__raw_read_trylock(raw_rwlock_t *lock)
21{ 24{
22 _raw_read_lock(lock); 25 __raw_read_lock(lock);
23 return 1; 26 return 1;
24} 27}
25EXPORT_SYMBOL(generic_raw_read_trylock); 28EXPORT_SYMBOL(generic__raw_read_trylock);
26 29
27int __lockfunc _spin_trylock(spinlock_t *lock) 30int __lockfunc _spin_trylock(spinlock_t *lock)
28{ 31{
@@ -57,7 +60,7 @@ int __lockfunc _write_trylock(rwlock_t *lock)
57} 60}
58EXPORT_SYMBOL(_write_trylock); 61EXPORT_SYMBOL(_write_trylock);
59 62
60#ifndef CONFIG_PREEMPT 63#if !defined(CONFIG_PREEMPT) || !defined(CONFIG_SMP)
61 64
62void __lockfunc _read_lock(rwlock_t *lock) 65void __lockfunc _read_lock(rwlock_t *lock)
63{ 66{
@@ -72,7 +75,7 @@ unsigned long __lockfunc _spin_lock_irqsave(spinlock_t *lock)
72 75
73 local_irq_save(flags); 76 local_irq_save(flags);
74 preempt_disable(); 77 preempt_disable();
75 _raw_spin_lock_flags(lock, flags); 78 _raw_spin_lock_flags(lock, &flags);
76 return flags; 79 return flags;
77} 80}
78EXPORT_SYMBOL(_spin_lock_irqsave); 81EXPORT_SYMBOL(_spin_lock_irqsave);
diff --git a/kernel/timer.c b/kernel/timer.c
index 13e2b513be..f4152fcd9f 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -1154,6 +1154,20 @@ fastcall signed long __sched schedule_timeout(signed long timeout)
1154 1154
1155EXPORT_SYMBOL(schedule_timeout); 1155EXPORT_SYMBOL(schedule_timeout);
1156 1156
1157signed long __sched schedule_timeout_interruptible(signed long timeout)
1158{
1159 set_current_state(TASK_INTERRUPTIBLE);
1160 return schedule_timeout(timeout);
1161}
1162EXPORT_SYMBOL(schedule_timeout_interruptible);
1163
1164signed long __sched schedule_timeout_uninterruptible(signed long timeout)
1165{
1166 set_current_state(TASK_UNINTERRUPTIBLE);
1167 return schedule_timeout(timeout);
1168}
1169EXPORT_SYMBOL(schedule_timeout_uninterruptible);
1170
1157/* Thread ID - the internal kernel "pid" */ 1171/* Thread ID - the internal kernel "pid" */
1158asmlinkage long sys_gettid(void) 1172asmlinkage long sys_gettid(void)
1159{ 1173{
@@ -1170,8 +1184,7 @@ static long __sched nanosleep_restart(struct restart_block *restart)
1170 if (!time_after(expire, now)) 1184 if (!time_after(expire, now))
1171 return 0; 1185 return 0;
1172 1186
1173 current->state = TASK_INTERRUPTIBLE; 1187 expire = schedule_timeout_interruptible(expire - now);
1174 expire = schedule_timeout(expire - now);
1175 1188
1176 ret = 0; 1189 ret = 0;
1177 if (expire) { 1190 if (expire) {
@@ -1199,8 +1212,7 @@ asmlinkage long sys_nanosleep(struct timespec __user *rqtp, struct timespec __us
1199 return -EINVAL; 1212 return -EINVAL;
1200 1213
1201 expire = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec); 1214 expire = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec);
1202 current->state = TASK_INTERRUPTIBLE; 1215 expire = schedule_timeout_interruptible(expire);
1203 expire = schedule_timeout(expire);
1204 1216
1205 ret = 0; 1217 ret = 0;
1206 if (expire) { 1218 if (expire) {
@@ -1598,10 +1610,8 @@ void msleep(unsigned int msecs)
1598{ 1610{
1599 unsigned long timeout = msecs_to_jiffies(msecs) + 1; 1611 unsigned long timeout = msecs_to_jiffies(msecs) + 1;
1600 1612
1601 while (timeout) { 1613 while (timeout)
1602 set_current_state(TASK_UNINTERRUPTIBLE); 1614 timeout = schedule_timeout_uninterruptible(timeout);
1603 timeout = schedule_timeout(timeout);
1604 }
1605} 1615}
1606 1616
1607EXPORT_SYMBOL(msleep); 1617EXPORT_SYMBOL(msleep);
@@ -1614,10 +1624,8 @@ unsigned long msleep_interruptible(unsigned int msecs)
1614{ 1624{
1615 unsigned long timeout = msecs_to_jiffies(msecs) + 1; 1625 unsigned long timeout = msecs_to_jiffies(msecs) + 1;
1616 1626
1617 while (timeout && !signal_pending(current)) { 1627 while (timeout && !signal_pending(current))
1618 set_current_state(TASK_INTERRUPTIBLE); 1628 timeout = schedule_timeout_interruptible(timeout);
1619 timeout = schedule_timeout(timeout);
1620 }
1621 return jiffies_to_msecs(timeout); 1629 return jiffies_to_msecs(timeout);
1622} 1630}
1623 1631
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 3754c9a8f5..016e89a44a 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -170,11 +170,11 @@ config DEBUG_FS
170 170
171config FRAME_POINTER 171config FRAME_POINTER
172 bool "Compile the kernel with frame pointers" 172 bool "Compile the kernel with frame pointers"
173 depends on DEBUG_KERNEL && ((X86 && !X86_64) || CRIS || M68K || M68KNOMMU || FRV || UML) 173 depends on DEBUG_KERNEL && (X86 || CRIS || M68K || M68KNOMMU || FRV || UML)
174 default y if DEBUG_INFO && UML 174 default y if DEBUG_INFO && UML
175 help 175 help
176 If you say Y here the resulting kernel image will be slightly larger 176 If you say Y here the resulting kernel image will be slightly larger
177 and slower, but it will give very useful debugging information. 177 and slower, but it might give very useful debugging information
178 If you don't debug the kernel, you can say N, but we may not be able 178 on some architectures or you use external debuggers.
179 to solve problems without frame pointers. 179 If you don't debug the kernel, you can say N.
180 180
diff --git a/lib/Makefile b/lib/Makefile
index d9c38ba05e..44a4675069 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -16,6 +16,7 @@ CFLAGS_kobject.o += -DDEBUG
16CFLAGS_kobject_uevent.o += -DDEBUG 16CFLAGS_kobject_uevent.o += -DDEBUG
17endif 17endif
18 18
19obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o
19lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o 20lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
20lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o 21lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
21lib-$(CONFIG_SEMAPHORE_SLEEPERS) += semaphore-sleepers.o 22lib-$(CONFIG_SEMAPHORE_SLEEPERS) += semaphore-sleepers.o
diff --git a/lib/dec_and_lock.c b/lib/dec_and_lock.c
index 6658d81e18..2377af057d 100644
--- a/lib/dec_and_lock.c
+++ b/lib/dec_and_lock.c
@@ -25,8 +25,6 @@
25 * this is trivially done efficiently using a load-locked 25 * this is trivially done efficiently using a load-locked
26 * store-conditional approach, for example. 26 * store-conditional approach, for example.
27 */ 27 */
28
29#ifndef ATOMIC_DEC_AND_LOCK
30int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock) 28int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
31{ 29{
32 spin_lock(lock); 30 spin_lock(lock);
@@ -37,4 +35,3 @@ int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
37} 35}
38 36
39EXPORT_SYMBOL(_atomic_dec_and_lock); 37EXPORT_SYMBOL(_atomic_dec_and_lock);
40#endif
diff --git a/lib/kernel_lock.c b/lib/kernel_lock.c
index bd2bc5d887..cb5490ec00 100644
--- a/lib/kernel_lock.c
+++ b/lib/kernel_lock.c
@@ -177,8 +177,7 @@ static inline void __lock_kernel(void)
177 177
178static inline void __unlock_kernel(void) 178static inline void __unlock_kernel(void)
179{ 179{
180 _raw_spin_unlock(&kernel_flag); 180 spin_unlock(&kernel_flag);
181 preempt_enable();
182} 181}
183 182
184/* 183/*
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index b972dd2928..6a8bc6e064 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -110,7 +110,7 @@ radix_tree_node_free(struct radix_tree_node *node)
110 * success, return zero, with preemption disabled. On error, return -ENOMEM 110 * success, return zero, with preemption disabled. On error, return -ENOMEM
111 * with preemption not disabled. 111 * with preemption not disabled.
112 */ 112 */
113int radix_tree_preload(int gfp_mask) 113int radix_tree_preload(unsigned int __nocast gfp_mask)
114{ 114{
115 struct radix_tree_preload *rtp; 115 struct radix_tree_preload *rtp;
116 struct radix_tree_node *node; 116 struct radix_tree_node *node;
diff --git a/lib/sort.c b/lib/sort.c
index b73dbb0e7c..ddc4d35df2 100644
--- a/lib/sort.c
+++ b/lib/sort.c
@@ -6,15 +6,16 @@
6 6
7#include <linux/kernel.h> 7#include <linux/kernel.h>
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/sort.h>
9 10
10void u32_swap(void *a, void *b, int size) 11static void u32_swap(void *a, void *b, int size)
11{ 12{
12 u32 t = *(u32 *)a; 13 u32 t = *(u32 *)a;
13 *(u32 *)a = *(u32 *)b; 14 *(u32 *)a = *(u32 *)b;
14 *(u32 *)b = t; 15 *(u32 *)b = t;
15} 16}
16 17
17void generic_swap(void *a, void *b, int size) 18static void generic_swap(void *a, void *b, int size)
18{ 19{
19 char t; 20 char t;
20 21
diff --git a/lib/spinlock_debug.c b/lib/spinlock_debug.c
new file mode 100644
index 0000000000..906ad101ea
--- /dev/null
+++ b/lib/spinlock_debug.c
@@ -0,0 +1,257 @@
1/*
2 * Copyright 2005, Red Hat, Inc., Ingo Molnar
3 * Released under the General Public License (GPL).
4 *
5 * This file contains the spinlock/rwlock implementations for
6 * DEBUG_SPINLOCK.
7 */
8
9#include <linux/config.h>
10#include <linux/spinlock.h>
11#include <linux/interrupt.h>
12#include <linux/delay.h>
13
14static void spin_bug(spinlock_t *lock, const char *msg)
15{
16 static long print_once = 1;
17 struct task_struct *owner = NULL;
18
19 if (xchg(&print_once, 0)) {
20 if (lock->owner && lock->owner != SPINLOCK_OWNER_INIT)
21 owner = lock->owner;
22 printk("BUG: spinlock %s on CPU#%d, %s/%d\n",
23 msg, smp_processor_id(), current->comm, current->pid);
24 printk(" lock: %p, .magic: %08x, .owner: %s/%d, .owner_cpu: %d\n",
25 lock, lock->magic,
26 owner ? owner->comm : "<none>",
27 owner ? owner->pid : -1,
28 lock->owner_cpu);
29 dump_stack();
30#ifdef CONFIG_SMP
31 /*
32 * We cannot continue on SMP:
33 */
34// panic("bad locking");
35#endif
36 }
37}
38
39#define SPIN_BUG_ON(cond, lock, msg) if (unlikely(cond)) spin_bug(lock, msg)
40
41static inline void debug_spin_lock_before(spinlock_t *lock)
42{
43 SPIN_BUG_ON(lock->magic != SPINLOCK_MAGIC, lock, "bad magic");
44 SPIN_BUG_ON(lock->owner == current, lock, "recursion");
45 SPIN_BUG_ON(lock->owner_cpu == raw_smp_processor_id(),
46 lock, "cpu recursion");
47}
48
49static inline void debug_spin_lock_after(spinlock_t *lock)
50{
51 lock->owner_cpu = raw_smp_processor_id();
52 lock->owner = current;
53}
54
55static inline void debug_spin_unlock(spinlock_t *lock)
56{
57 SPIN_BUG_ON(lock->magic != SPINLOCK_MAGIC, lock, "bad magic");
58 SPIN_BUG_ON(!spin_is_locked(lock), lock, "already unlocked");
59 SPIN_BUG_ON(lock->owner != current, lock, "wrong owner");
60 SPIN_BUG_ON(lock->owner_cpu != raw_smp_processor_id(),
61 lock, "wrong CPU");
62 lock->owner = SPINLOCK_OWNER_INIT;
63 lock->owner_cpu = -1;
64}
65
66static void __spin_lock_debug(spinlock_t *lock)
67{
68 int print_once = 1;
69 u64 i;
70
71 for (;;) {
72 for (i = 0; i < loops_per_jiffy * HZ; i++) {
73 cpu_relax();
74 if (__raw_spin_trylock(&lock->raw_lock))
75 return;
76 }
77 /* lockup suspected: */
78 if (print_once) {
79 print_once = 0;
80 printk("BUG: spinlock lockup on CPU#%d, %s/%d, %p\n",
81 smp_processor_id(), current->comm, current->pid,
82 lock);
83 dump_stack();
84 }
85 }
86}
87
88void _raw_spin_lock(spinlock_t *lock)
89{
90 debug_spin_lock_before(lock);
91 if (unlikely(!__raw_spin_trylock(&lock->raw_lock)))
92 __spin_lock_debug(lock);
93 debug_spin_lock_after(lock);
94}
95
96int _raw_spin_trylock(spinlock_t *lock)
97{
98 int ret = __raw_spin_trylock(&lock->raw_lock);
99
100 if (ret)
101 debug_spin_lock_after(lock);
102#ifndef CONFIG_SMP
103 /*
104 * Must not happen on UP:
105 */
106 SPIN_BUG_ON(!ret, lock, "trylock failure on UP");
107#endif
108 return ret;
109}
110
111void _raw_spin_unlock(spinlock_t *lock)
112{
113 debug_spin_unlock(lock);
114 __raw_spin_unlock(&lock->raw_lock);
115}
116
117static void rwlock_bug(rwlock_t *lock, const char *msg)
118{
119 static long print_once = 1;
120
121 if (xchg(&print_once, 0)) {
122 printk("BUG: rwlock %s on CPU#%d, %s/%d, %p\n", msg,
123 smp_processor_id(), current->comm, current->pid, lock);
124 dump_stack();
125#ifdef CONFIG_SMP
126 /*
127 * We cannot continue on SMP:
128 */
129 panic("bad locking");
130#endif
131 }
132}
133
134#define RWLOCK_BUG_ON(cond, lock, msg) if (unlikely(cond)) rwlock_bug(lock, msg)
135
136static void __read_lock_debug(rwlock_t *lock)
137{
138 int print_once = 1;
139 u64 i;
140
141 for (;;) {
142 for (i = 0; i < loops_per_jiffy * HZ; i++) {
143 cpu_relax();
144 if (__raw_read_trylock(&lock->raw_lock))
145 return;
146 }
147 /* lockup suspected: */
148 if (print_once) {
149 print_once = 0;
150 printk("BUG: read-lock lockup on CPU#%d, %s/%d, %p\n",
151 smp_processor_id(), current->comm, current->pid,
152 lock);
153 dump_stack();
154 }
155 }
156}
157
158void _raw_read_lock(rwlock_t *lock)
159{
160 RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic");
161 if (unlikely(!__raw_read_trylock(&lock->raw_lock)))
162 __read_lock_debug(lock);
163}
164
165int _raw_read_trylock(rwlock_t *lock)
166{
167 int ret = __raw_read_trylock(&lock->raw_lock);
168
169#ifndef CONFIG_SMP
170 /*
171 * Must not happen on UP:
172 */
173 RWLOCK_BUG_ON(!ret, lock, "trylock failure on UP");
174#endif
175 return ret;
176}
177
178void _raw_read_unlock(rwlock_t *lock)
179{
180 RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic");
181 __raw_read_unlock(&lock->raw_lock);
182}
183
184static inline void debug_write_lock_before(rwlock_t *lock)
185{
186 RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic");
187 RWLOCK_BUG_ON(lock->owner == current, lock, "recursion");
188 RWLOCK_BUG_ON(lock->owner_cpu == raw_smp_processor_id(),
189 lock, "cpu recursion");
190}
191
192static inline void debug_write_lock_after(rwlock_t *lock)
193{
194 lock->owner_cpu = raw_smp_processor_id();
195 lock->owner = current;
196}
197
198static inline void debug_write_unlock(rwlock_t *lock)
199{
200 RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic");
201 RWLOCK_BUG_ON(lock->owner != current, lock, "wrong owner");
202 RWLOCK_BUG_ON(lock->owner_cpu != raw_smp_processor_id(),
203 lock, "wrong CPU");
204 lock->owner = SPINLOCK_OWNER_INIT;
205 lock->owner_cpu = -1;
206}
207
208static void __write_lock_debug(rwlock_t *lock)
209{
210 int print_once = 1;
211 u64 i;
212
213 for (;;) {
214 for (i = 0; i < loops_per_jiffy * HZ; i++) {
215 cpu_relax();
216 if (__raw_write_trylock(&lock->raw_lock))
217 return;
218 }
219 /* lockup suspected: */
220 if (print_once) {
221 print_once = 0;
222 printk("BUG: write-lock lockup on CPU#%d, %s/%d, %p\n",
223 smp_processor_id(), current->comm, current->pid,
224 lock);
225 dump_stack();
226 }
227 }
228}
229
230void _raw_write_lock(rwlock_t *lock)
231{
232 debug_write_lock_before(lock);
233 if (unlikely(!__raw_write_trylock(&lock->raw_lock)))
234 __write_lock_debug(lock);
235 debug_write_lock_after(lock);
236}
237
238int _raw_write_trylock(rwlock_t *lock)
239{
240 int ret = __raw_write_trylock(&lock->raw_lock);
241
242 if (ret)
243 debug_write_lock_after(lock);
244#ifndef CONFIG_SMP
245 /*
246 * Must not happen on UP:
247 */
248 RWLOCK_BUG_ON(!ret, lock, "trylock failure on UP");
249#endif
250 return ret;
251}
252
253void _raw_write_unlock(rwlock_t *lock)
254{
255 debug_write_unlock(lock);
256 __raw_write_unlock(&lock->raw_lock);
257}
diff --git a/mm/bootmem.c b/mm/bootmem.c
index c1330cc197..8ec4e4c2a1 100644
--- a/mm/bootmem.c
+++ b/mm/bootmem.c
@@ -61,9 +61,17 @@ static unsigned long __init init_bootmem_core (pg_data_t *pgdat,
61{ 61{
62 bootmem_data_t *bdata = pgdat->bdata; 62 bootmem_data_t *bdata = pgdat->bdata;
63 unsigned long mapsize = ((end - start)+7)/8; 63 unsigned long mapsize = ((end - start)+7)/8;
64 64 static struct pglist_data *pgdat_last;
65 pgdat->pgdat_next = pgdat_list; 65
66 pgdat_list = pgdat; 66 pgdat->pgdat_next = NULL;
67 /* Add new nodes last so that bootmem always starts
68 searching in the first nodes, not the last ones */
69 if (pgdat_last)
70 pgdat_last->pgdat_next = pgdat;
71 else {
72 pgdat_list = pgdat;
73 pgdat_last = pgdat;
74 }
67 75
68 mapsize = ALIGN(mapsize, sizeof(long)); 76 mapsize = ALIGN(mapsize, sizeof(long));
69 bdata->node_bootmem_map = phys_to_virt(mapstart << PAGE_SHIFT); 77 bdata->node_bootmem_map = phys_to_virt(mapstart << PAGE_SHIFT);
diff --git a/mm/filemap.c b/mm/filemap.c
index 88611928e7..b5346576e5 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -37,6 +37,10 @@
37#include <asm/uaccess.h> 37#include <asm/uaccess.h>
38#include <asm/mman.h> 38#include <asm/mman.h>
39 39
40static ssize_t
41generic_file_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
42 loff_t offset, unsigned long nr_segs);
43
40/* 44/*
41 * Shared mappings implemented 30.11.1994. It's not fully working yet, 45 * Shared mappings implemented 30.11.1994. It's not fully working yet,
42 * though. 46 * though.
@@ -301,8 +305,9 @@ EXPORT_SYMBOL(sync_page_range);
301 * as it forces O_SYNC writers to different parts of the same file 305 * as it forces O_SYNC writers to different parts of the same file
302 * to be serialised right until io completion. 306 * to be serialised right until io completion.
303 */ 307 */
304int sync_page_range_nolock(struct inode *inode, struct address_space *mapping, 308static int sync_page_range_nolock(struct inode *inode,
305 loff_t pos, size_t count) 309 struct address_space *mapping,
310 loff_t pos, size_t count)
306{ 311{
307 pgoff_t start = pos >> PAGE_CACHE_SHIFT; 312 pgoff_t start = pos >> PAGE_CACHE_SHIFT;
308 pgoff_t end = (pos + count - 1) >> PAGE_CACHE_SHIFT; 313 pgoff_t end = (pos + count - 1) >> PAGE_CACHE_SHIFT;
@@ -317,7 +322,6 @@ int sync_page_range_nolock(struct inode *inode, struct address_space *mapping,
317 ret = wait_on_page_writeback_range(mapping, start, end); 322 ret = wait_on_page_writeback_range(mapping, start, end);
318 return ret; 323 return ret;
319} 324}
320EXPORT_SYMBOL(sync_page_range_nolock);
321 325
322/** 326/**
323 * filemap_fdatawait - walk the list of under-writeback pages of the given 327 * filemap_fdatawait - walk the list of under-writeback pages of the given
@@ -2008,7 +2012,7 @@ generic_file_buffered_write(struct kiocb *iocb, const struct iovec *iov,
2008} 2012}
2009EXPORT_SYMBOL(generic_file_buffered_write); 2013EXPORT_SYMBOL(generic_file_buffered_write);
2010 2014
2011ssize_t 2015static ssize_t
2012__generic_file_aio_write_nolock(struct kiocb *iocb, const struct iovec *iov, 2016__generic_file_aio_write_nolock(struct kiocb *iocb, const struct iovec *iov,
2013 unsigned long nr_segs, loff_t *ppos) 2017 unsigned long nr_segs, loff_t *ppos)
2014{ 2018{
@@ -2108,7 +2112,7 @@ generic_file_aio_write_nolock(struct kiocb *iocb, const struct iovec *iov,
2108 return ret; 2112 return ret;
2109} 2113}
2110 2114
2111ssize_t 2115static ssize_t
2112__generic_file_write_nolock(struct file *file, const struct iovec *iov, 2116__generic_file_write_nolock(struct file *file, const struct iovec *iov,
2113 unsigned long nr_segs, loff_t *ppos) 2117 unsigned long nr_segs, loff_t *ppos)
2114{ 2118{
@@ -2229,7 +2233,7 @@ EXPORT_SYMBOL(generic_file_writev);
2229 * Called under i_sem for writes to S_ISREG files. Returns -EIO if something 2233 * Called under i_sem for writes to S_ISREG files. Returns -EIO if something
2230 * went wrong during pagecache shootdown. 2234 * went wrong during pagecache shootdown.
2231 */ 2235 */
2232ssize_t 2236static ssize_t
2233generic_file_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, 2237generic_file_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
2234 loff_t offset, unsigned long nr_segs) 2238 loff_t offset, unsigned long nr_segs)
2235{ 2239{
@@ -2264,4 +2268,3 @@ generic_file_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
2264 } 2268 }
2265 return retval; 2269 return retval;
2266} 2270}
2267EXPORT_SYMBOL_GPL(generic_file_direct_IO);
diff --git a/mm/memory.c b/mm/memory.c
index 788a628103..ae8161f1f4 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2225,7 +2225,7 @@ void update_mem_hiwater(struct task_struct *tsk)
2225#if !defined(__HAVE_ARCH_GATE_AREA) 2225#if !defined(__HAVE_ARCH_GATE_AREA)
2226 2226
2227#if defined(AT_SYSINFO_EHDR) 2227#if defined(AT_SYSINFO_EHDR)
2228struct vm_area_struct gate_vma; 2228static struct vm_area_struct gate_vma;
2229 2229
2230static int __init gate_vma_init(void) 2230static int __init gate_vma_init(void)
2231{ 2231{
diff --git a/mm/nommu.c b/mm/nommu.c
index fd4e8df0f0..064d704428 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -57,6 +57,11 @@ DECLARE_RWSEM(nommu_vma_sem);
57struct vm_operations_struct generic_file_vm_ops = { 57struct vm_operations_struct generic_file_vm_ops = {
58}; 58};
59 59
60EXPORT_SYMBOL(vmalloc);
61EXPORT_SYMBOL(vfree);
62EXPORT_SYMBOL(vmalloc_to_page);
63EXPORT_SYMBOL(vmalloc_32);
64
60/* 65/*
61 * Handle all mappings that got truncated by a "truncate()" 66 * Handle all mappings that got truncated by a "truncate()"
62 * system call. 67 * system call.
@@ -142,6 +147,8 @@ int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
142 return(i); 147 return(i);
143} 148}
144 149
150EXPORT_SYMBOL(get_user_pages);
151
145DEFINE_RWLOCK(vmlist_lock); 152DEFINE_RWLOCK(vmlist_lock);
146struct vm_struct *vmlist; 153struct vm_struct *vmlist;
147 154
@@ -852,7 +859,7 @@ unsigned long do_mmap_pgoff(struct file *file,
852 error_getting_vma: 859 error_getting_vma:
853 up_write(&nommu_vma_sem); 860 up_write(&nommu_vma_sem);
854 kfree(vml); 861 kfree(vml);
855 printk("Allocation of vml for %lu byte allocation from process %d failed\n", 862 printk("Allocation of vma for %lu byte allocation from process %d failed\n",
856 len, current->pid); 863 len, current->pid);
857 show_free_areas(); 864 show_free_areas();
858 return -ENOMEM; 865 return -ENOMEM;
@@ -909,7 +916,7 @@ int do_munmap(struct mm_struct *mm, unsigned long addr, size_t len)
909 916
910 for (parent = &mm->context.vmlist; *parent; parent = &(*parent)->next) 917 for (parent = &mm->context.vmlist; *parent; parent = &(*parent)->next)
911 if ((*parent)->vma->vm_start == addr && 918 if ((*parent)->vma->vm_start == addr &&
912 (*parent)->vma->vm_end == end) 919 ((len == 0) || ((*parent)->vma->vm_end == end)))
913 goto found; 920 goto found;
914 921
915 printk("munmap of non-mmaped memory by process %d (%s): %p\n", 922 printk("munmap of non-mmaped memory by process %d (%s): %p\n",
@@ -1054,7 +1061,8 @@ struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
1054int remap_pfn_range(struct vm_area_struct *vma, unsigned long from, 1061int remap_pfn_range(struct vm_area_struct *vma, unsigned long from,
1055 unsigned long to, unsigned long size, pgprot_t prot) 1062 unsigned long to, unsigned long size, pgprot_t prot)
1056{ 1063{
1057 return -EPERM; 1064 vma->vm_start = vma->vm_pgoff << PAGE_SHIFT;
1065 return 0;
1058} 1066}
1059 1067
1060void swap_unplug_io_fn(struct backing_dev_info *bdi, struct page *page) 1068void swap_unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
@@ -1073,9 +1081,10 @@ void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
1073 1081
1074void update_mem_hiwater(struct task_struct *tsk) 1082void update_mem_hiwater(struct task_struct *tsk)
1075{ 1083{
1076 unsigned long rss = get_mm_counter(tsk->mm, rss); 1084 unsigned long rss;
1077 1085
1078 if (likely(tsk->mm)) { 1086 if (likely(tsk->mm)) {
1087 rss = get_mm_counter(tsk->mm, rss);
1079 if (tsk->mm->hiwater_rss < rss) 1088 if (tsk->mm->hiwater_rss < rss)
1080 tsk->mm->hiwater_rss = rss; 1089 tsk->mm->hiwater_rss = rss;
1081 if (tsk->mm->hiwater_vm < tsk->mm->total_vm) 1090 if (tsk->mm->hiwater_vm < tsk->mm->total_vm)
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 5ec8da12cf..ac3bf33e53 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -300,6 +300,5 @@ retry:
300 * Give "p" a good chance of killing itself before we 300 * Give "p" a good chance of killing itself before we
301 * retry to allocate memory. 301 * retry to allocate memory.
302 */ 302 */
303 __set_current_state(TASK_INTERRUPTIBLE); 303 schedule_timeout_interruptible(1);
304 schedule_timeout(1);
305} 304}
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index a6329fa8f8..0166ea15c9 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -368,10 +368,8 @@ int wakeup_pdflush(long nr_pages)
368static void wb_timer_fn(unsigned long unused); 368static void wb_timer_fn(unsigned long unused);
369static void laptop_timer_fn(unsigned long unused); 369static void laptop_timer_fn(unsigned long unused);
370 370
371static struct timer_list wb_timer = 371static DEFINE_TIMER(wb_timer, wb_timer_fn, 0, 0);
372 TIMER_INITIALIZER(wb_timer_fn, 0, 0); 372static DEFINE_TIMER(laptop_mode_wb_timer, laptop_timer_fn, 0, 0);
373static struct timer_list laptop_mode_wb_timer =
374 TIMER_INITIALIZER(laptop_timer_fn, 0, 0);
375 373
376/* 374/*
377 * Periodic writeback of "old" data. 375 * Periodic writeback of "old" data.
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 3974fd81d2..c5823c395f 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -335,7 +335,7 @@ static inline void free_pages_check(const char *function, struct page *page)
335/* 335/*
336 * Frees a list of pages. 336 * Frees a list of pages.
337 * Assumes all pages on list are in same zone, and of same order. 337 * Assumes all pages on list are in same zone, and of same order.
338 * count is the number of pages to free, or 0 for all on the list. 338 * count is the number of pages to free.
339 * 339 *
340 * If the zone was previously in an "all pages pinned" state then look to 340 * If the zone was previously in an "all pages pinned" state then look to
341 * see if this freeing clears that state. 341 * see if this freeing clears that state.
diff --git a/mm/shmem.c b/mm/shmem.c
index db2c9e8d99..1f7aeb210c 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -666,6 +666,7 @@ static void shmem_delete_inode(struct inode *inode)
666 struct shmem_inode_info *info = SHMEM_I(inode); 666 struct shmem_inode_info *info = SHMEM_I(inode);
667 667
668 if (inode->i_op->truncate == shmem_truncate) { 668 if (inode->i_op->truncate == shmem_truncate) {
669 truncate_inode_pages(inode->i_mapping, 0);
669 shmem_unacct_size(info->flags, inode->i_size); 670 shmem_unacct_size(info->flags, inode->i_size);
670 inode->i_size = 0; 671 inode->i_size = 0;
671 shmem_truncate(inode); 672 shmem_truncate(inode);
@@ -1607,6 +1608,15 @@ shmem_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
1607 int error = -ENOSPC; 1608 int error = -ENOSPC;
1608 1609
1609 if (inode) { 1610 if (inode) {
1611 error = security_inode_init_security(inode, dir, NULL, NULL,
1612 NULL);
1613 if (error) {
1614 if (error != -EOPNOTSUPP) {
1615 iput(inode);
1616 return error;
1617 }
1618 error = 0;
1619 }
1610 if (dir->i_mode & S_ISGID) { 1620 if (dir->i_mode & S_ISGID) {
1611 inode->i_gid = dir->i_gid; 1621 inode->i_gid = dir->i_gid;
1612 if (S_ISDIR(mode)) 1622 if (S_ISDIR(mode))
@@ -1616,7 +1626,6 @@ shmem_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
1616 dir->i_ctime = dir->i_mtime = CURRENT_TIME; 1626 dir->i_ctime = dir->i_mtime = CURRENT_TIME;
1617 d_instantiate(dentry, inode); 1627 d_instantiate(dentry, inode);
1618 dget(dentry); /* Extra count - pin the dentry in core */ 1628 dget(dentry); /* Extra count - pin the dentry in core */
1619 error = 0;
1620 } 1629 }
1621 return error; 1630 return error;
1622} 1631}
@@ -1746,6 +1755,16 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s
1746 if (!inode) 1755 if (!inode)
1747 return -ENOSPC; 1756 return -ENOSPC;
1748 1757
1758 error = security_inode_init_security(inode, dir, NULL, NULL,
1759 NULL);
1760 if (error) {
1761 if (error != -EOPNOTSUPP) {
1762 iput(inode);
1763 return error;
1764 }
1765 error = 0;
1766 }
1767
1749 info = SHMEM_I(inode); 1768 info = SHMEM_I(inode);
1750 inode->i_size = len-1; 1769 inode->i_size = len-1;
1751 if (len <= (char *)inode - (char *)info) { 1770 if (len <= (char *)inode - (char *)info) {
diff --git a/mm/slab.c b/mm/slab.c
index d7c4443991..9e876d6dfa 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -75,6 +75,15 @@
75 * 75 *
76 * At present, each engine can be growing a cache. This should be blocked. 76 * At present, each engine can be growing a cache. This should be blocked.
77 * 77 *
78 * 15 March 2005. NUMA slab allocator.
79 * Shai Fultheim <shai@scalex86.org>.
80 * Shobhit Dayal <shobhit@calsoftinc.com>
81 * Alok N Kataria <alokk@calsoftinc.com>
82 * Christoph Lameter <christoph@lameter.com>
83 *
84 * Modified the slab allocator to be node aware on NUMA systems.
85 * Each node has its own list of partial, free and full slabs.
86 * All object allocations for a node occur from node specific slab lists.
78 */ 87 */
79 88
80#include <linux/config.h> 89#include <linux/config.h>
@@ -93,6 +102,7 @@
93#include <linux/module.h> 102#include <linux/module.h>
94#include <linux/rcupdate.h> 103#include <linux/rcupdate.h>
95#include <linux/string.h> 104#include <linux/string.h>
105#include <linux/nodemask.h>
96 106
97#include <asm/uaccess.h> 107#include <asm/uaccess.h>
98#include <asm/cacheflush.h> 108#include <asm/cacheflush.h>
@@ -212,6 +222,7 @@ struct slab {
212 void *s_mem; /* including colour offset */ 222 void *s_mem; /* including colour offset */
213 unsigned int inuse; /* num of objs active in slab */ 223 unsigned int inuse; /* num of objs active in slab */
214 kmem_bufctl_t free; 224 kmem_bufctl_t free;
225 unsigned short nodeid;
215}; 226};
216 227
217/* 228/*
@@ -239,7 +250,6 @@ struct slab_rcu {
239/* 250/*
240 * struct array_cache 251 * struct array_cache
241 * 252 *
242 * Per cpu structures
243 * Purpose: 253 * Purpose:
244 * - LIFO ordering, to hand out cache-warm objects from _alloc 254 * - LIFO ordering, to hand out cache-warm objects from _alloc
245 * - reduce the number of linked list operations 255 * - reduce the number of linked list operations
@@ -254,6 +264,13 @@ struct array_cache {
254 unsigned int limit; 264 unsigned int limit;
255 unsigned int batchcount; 265 unsigned int batchcount;
256 unsigned int touched; 266 unsigned int touched;
267 spinlock_t lock;
268 void *entry[0]; /*
269 * Must have this definition in here for the proper
270 * alignment of array_cache. Also simplifies accessing
271 * the entries.
272 * [0] is for gcc 2.95. It should really be [].
273 */
257}; 274};
258 275
259/* bootstrap: The caches do not work without cpuarrays anymore, 276/* bootstrap: The caches do not work without cpuarrays anymore,
@@ -266,34 +283,83 @@ struct arraycache_init {
266}; 283};
267 284
268/* 285/*
269 * The slab lists of all objects. 286 * The slab lists for all objects.
270 * Hopefully reduce the internal fragmentation
271 * NUMA: The spinlock could be moved from the kmem_cache_t
272 * into this structure, too. Figure out what causes
273 * fewer cross-node spinlock operations.
274 */ 287 */
275struct kmem_list3 { 288struct kmem_list3 {
276 struct list_head slabs_partial; /* partial list first, better asm code */ 289 struct list_head slabs_partial; /* partial list first, better asm code */
277 struct list_head slabs_full; 290 struct list_head slabs_full;
278 struct list_head slabs_free; 291 struct list_head slabs_free;
279 unsigned long free_objects; 292 unsigned long free_objects;
280 int free_touched;
281 unsigned long next_reap; 293 unsigned long next_reap;
282 struct array_cache *shared; 294 int free_touched;
295 unsigned int free_limit;
296 spinlock_t list_lock;
297 struct array_cache *shared; /* shared per node */
298 struct array_cache **alien; /* on other nodes */
283}; 299};
284 300
285#define LIST3_INIT(parent) \ 301/*
286 { \ 302 * Need this for bootstrapping a per node allocator.
287 .slabs_full = LIST_HEAD_INIT(parent.slabs_full), \ 303 */
288 .slabs_partial = LIST_HEAD_INIT(parent.slabs_partial), \ 304#define NUM_INIT_LISTS (2 * MAX_NUMNODES + 1)
289 .slabs_free = LIST_HEAD_INIT(parent.slabs_free) \ 305struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
306#define CACHE_CACHE 0
307#define SIZE_AC 1
308#define SIZE_L3 (1 + MAX_NUMNODES)
309
310/*
311 * This function may be completely optimized away if
312 * a constant is passed to it. Mostly the same as
313 * what is in linux/slab.h except it returns an
314 * index.
315 */
316static inline int index_of(const size_t size)
317{
318 if (__builtin_constant_p(size)) {
319 int i = 0;
320
321#define CACHE(x) \
322 if (size <=x) \
323 return i; \
324 else \
325 i++;
326#include "linux/kmalloc_sizes.h"
327#undef CACHE
328 {
329 extern void __bad_size(void);
330 __bad_size();
331 }
290 } 332 }
291#define list3_data(cachep) \ 333 return 0;
292 (&(cachep)->lists) 334}
335
336#define INDEX_AC index_of(sizeof(struct arraycache_init))
337#define INDEX_L3 index_of(sizeof(struct kmem_list3))
338
339static inline void kmem_list3_init(struct kmem_list3 *parent)
340{
341 INIT_LIST_HEAD(&parent->slabs_full);
342 INIT_LIST_HEAD(&parent->slabs_partial);
343 INIT_LIST_HEAD(&parent->slabs_free);
344 parent->shared = NULL;
345 parent->alien = NULL;
346 spin_lock_init(&parent->list_lock);
347 parent->free_objects = 0;
348 parent->free_touched = 0;
349}
293 350
294/* NUMA: per-node */ 351#define MAKE_LIST(cachep, listp, slab, nodeid) \
295#define list3_data_ptr(cachep, ptr) \ 352 do { \
296 list3_data(cachep) 353 INIT_LIST_HEAD(listp); \
354 list_splice(&(cachep->nodelists[nodeid]->slab), listp); \
355 } while (0)
356
357#define MAKE_ALL_LISTS(cachep, ptr, nodeid) \
358 do { \
359 MAKE_LIST((cachep), (&(ptr)->slabs_full), slabs_full, nodeid); \
360 MAKE_LIST((cachep), (&(ptr)->slabs_partial), slabs_partial, nodeid); \
361 MAKE_LIST((cachep), (&(ptr)->slabs_free), slabs_free, nodeid); \
362 } while (0)
297 363
298/* 364/*
299 * kmem_cache_t 365 * kmem_cache_t
@@ -306,13 +372,12 @@ struct kmem_cache_s {
306 struct array_cache *array[NR_CPUS]; 372 struct array_cache *array[NR_CPUS];
307 unsigned int batchcount; 373 unsigned int batchcount;
308 unsigned int limit; 374 unsigned int limit;
309/* 2) touched by every alloc & free from the backend */ 375 unsigned int shared;
310 struct kmem_list3 lists;
311 /* NUMA: kmem_3list_t *nodelists[MAX_NUMNODES] */
312 unsigned int objsize; 376 unsigned int objsize;
377/* 2) touched by every alloc & free from the backend */
378 struct kmem_list3 *nodelists[MAX_NUMNODES];
313 unsigned int flags; /* constant flags */ 379 unsigned int flags; /* constant flags */
314 unsigned int num; /* # of objs per slab */ 380 unsigned int num; /* # of objs per slab */
315 unsigned int free_limit; /* upper limit of objects in the lists */
316 spinlock_t spinlock; 381 spinlock_t spinlock;
317 382
318/* 3) cache_grow/shrink */ 383/* 3) cache_grow/shrink */
@@ -349,6 +414,7 @@ struct kmem_cache_s {
349 unsigned long errors; 414 unsigned long errors;
350 unsigned long max_freeable; 415 unsigned long max_freeable;
351 unsigned long node_allocs; 416 unsigned long node_allocs;
417 unsigned long node_frees;
352 atomic_t allochit; 418 atomic_t allochit;
353 atomic_t allocmiss; 419 atomic_t allocmiss;
354 atomic_t freehit; 420 atomic_t freehit;
@@ -384,6 +450,7 @@ struct kmem_cache_s {
384 } while (0) 450 } while (0)
385#define STATS_INC_ERR(x) ((x)->errors++) 451#define STATS_INC_ERR(x) ((x)->errors++)
386#define STATS_INC_NODEALLOCS(x) ((x)->node_allocs++) 452#define STATS_INC_NODEALLOCS(x) ((x)->node_allocs++)
453#define STATS_INC_NODEFREES(x) ((x)->node_frees++)
387#define STATS_SET_FREEABLE(x, i) \ 454#define STATS_SET_FREEABLE(x, i) \
388 do { if ((x)->max_freeable < i) \ 455 do { if ((x)->max_freeable < i) \
389 (x)->max_freeable = i; \ 456 (x)->max_freeable = i; \
@@ -402,6 +469,7 @@ struct kmem_cache_s {
402#define STATS_SET_HIGH(x) do { } while (0) 469#define STATS_SET_HIGH(x) do { } while (0)
403#define STATS_INC_ERR(x) do { } while (0) 470#define STATS_INC_ERR(x) do { } while (0)
404#define STATS_INC_NODEALLOCS(x) do { } while (0) 471#define STATS_INC_NODEALLOCS(x) do { } while (0)
472#define STATS_INC_NODEFREES(x) do { } while (0)
405#define STATS_SET_FREEABLE(x, i) \ 473#define STATS_SET_FREEABLE(x, i) \
406 do { } while (0) 474 do { } while (0)
407 475
@@ -534,9 +602,9 @@ static struct arraycache_init initarray_generic =
534 602
535/* internal cache of cache description objs */ 603/* internal cache of cache description objs */
536static kmem_cache_t cache_cache = { 604static kmem_cache_t cache_cache = {
537 .lists = LIST3_INIT(cache_cache.lists),
538 .batchcount = 1, 605 .batchcount = 1,
539 .limit = BOOT_CPUCACHE_ENTRIES, 606 .limit = BOOT_CPUCACHE_ENTRIES,
607 .shared = 1,
540 .objsize = sizeof(kmem_cache_t), 608 .objsize = sizeof(kmem_cache_t),
541 .flags = SLAB_NO_REAP, 609 .flags = SLAB_NO_REAP,
542 .spinlock = SPIN_LOCK_UNLOCKED, 610 .spinlock = SPIN_LOCK_UNLOCKED,
@@ -557,7 +625,6 @@ static struct list_head cache_chain;
557 * SLAB_RECLAIM_ACCOUNT turns this on per-slab 625 * SLAB_RECLAIM_ACCOUNT turns this on per-slab
558 */ 626 */
559atomic_t slab_reclaim_pages; 627atomic_t slab_reclaim_pages;
560EXPORT_SYMBOL(slab_reclaim_pages);
561 628
562/* 629/*
563 * chicken and egg problem: delay the per-cpu array allocation 630 * chicken and egg problem: delay the per-cpu array allocation
@@ -565,7 +632,8 @@ EXPORT_SYMBOL(slab_reclaim_pages);
565 */ 632 */
566static enum { 633static enum {
567 NONE, 634 NONE,
568 PARTIAL, 635 PARTIAL_AC,
636 PARTIAL_L3,
569 FULL 637 FULL
570} g_cpucache_up; 638} g_cpucache_up;
571 639
@@ -574,11 +642,7 @@ static DEFINE_PER_CPU(struct work_struct, reap_work);
574static void free_block(kmem_cache_t* cachep, void** objpp, int len); 642static void free_block(kmem_cache_t* cachep, void** objpp, int len);
575static void enable_cpucache (kmem_cache_t *cachep); 643static void enable_cpucache (kmem_cache_t *cachep);
576static void cache_reap (void *unused); 644static void cache_reap (void *unused);
577 645static int __node_shrink(kmem_cache_t *cachep, int node);
578static inline void **ac_entry(struct array_cache *ac)
579{
580 return (void**)(ac+1);
581}
582 646
583static inline struct array_cache *ac_data(kmem_cache_t *cachep) 647static inline struct array_cache *ac_data(kmem_cache_t *cachep)
584{ 648{
@@ -676,48 +740,160 @@ static void __devinit start_cpu_timer(int cpu)
676 } 740 }
677} 741}
678 742
679static struct array_cache *alloc_arraycache(int cpu, int entries, 743static struct array_cache *alloc_arraycache(int node, int entries,
680 int batchcount) 744 int batchcount)
681{ 745{
682 int memsize = sizeof(void*)*entries+sizeof(struct array_cache); 746 int memsize = sizeof(void*)*entries+sizeof(struct array_cache);
683 struct array_cache *nc = NULL; 747 struct array_cache *nc = NULL;
684 748
685 if (cpu == -1) 749 nc = kmalloc_node(memsize, GFP_KERNEL, node);
686 nc = kmalloc(memsize, GFP_KERNEL);
687 else
688 nc = kmalloc_node(memsize, GFP_KERNEL, cpu_to_node(cpu));
689
690 if (nc) { 750 if (nc) {
691 nc->avail = 0; 751 nc->avail = 0;
692 nc->limit = entries; 752 nc->limit = entries;
693 nc->batchcount = batchcount; 753 nc->batchcount = batchcount;
694 nc->touched = 0; 754 nc->touched = 0;
755 spin_lock_init(&nc->lock);
695 } 756 }
696 return nc; 757 return nc;
697} 758}
698 759
760#ifdef CONFIG_NUMA
761static inline struct array_cache **alloc_alien_cache(int node, int limit)
762{
763 struct array_cache **ac_ptr;
764 int memsize = sizeof(void*)*MAX_NUMNODES;
765 int i;
766
767 if (limit > 1)
768 limit = 12;
769 ac_ptr = kmalloc_node(memsize, GFP_KERNEL, node);
770 if (ac_ptr) {
771 for_each_node(i) {
772 if (i == node || !node_online(i)) {
773 ac_ptr[i] = NULL;
774 continue;
775 }
776 ac_ptr[i] = alloc_arraycache(node, limit, 0xbaadf00d);
777 if (!ac_ptr[i]) {
778 for (i--; i <=0; i--)
779 kfree(ac_ptr[i]);
780 kfree(ac_ptr);
781 return NULL;
782 }
783 }
784 }
785 return ac_ptr;
786}
787
788static inline void free_alien_cache(struct array_cache **ac_ptr)
789{
790 int i;
791
792 if (!ac_ptr)
793 return;
794
795 for_each_node(i)
796 kfree(ac_ptr[i]);
797
798 kfree(ac_ptr);
799}
800
801static inline void __drain_alien_cache(kmem_cache_t *cachep, struct array_cache *ac, int node)
802{
803 struct kmem_list3 *rl3 = cachep->nodelists[node];
804
805 if (ac->avail) {
806 spin_lock(&rl3->list_lock);
807 free_block(cachep, ac->entry, ac->avail);
808 ac->avail = 0;
809 spin_unlock(&rl3->list_lock);
810 }
811}
812
813static void drain_alien_cache(kmem_cache_t *cachep, struct kmem_list3 *l3)
814{
815 int i=0;
816 struct array_cache *ac;
817 unsigned long flags;
818
819 for_each_online_node(i) {
820 ac = l3->alien[i];
821 if (ac) {
822 spin_lock_irqsave(&ac->lock, flags);
823 __drain_alien_cache(cachep, ac, i);
824 spin_unlock_irqrestore(&ac->lock, flags);
825 }
826 }
827}
828#else
829#define alloc_alien_cache(node, limit) do { } while (0)
830#define free_alien_cache(ac_ptr) do { } while (0)
831#define drain_alien_cache(cachep, l3) do { } while (0)
832#endif
833
699static int __devinit cpuup_callback(struct notifier_block *nfb, 834static int __devinit cpuup_callback(struct notifier_block *nfb,
700 unsigned long action, void *hcpu) 835 unsigned long action, void *hcpu)
701{ 836{
702 long cpu = (long)hcpu; 837 long cpu = (long)hcpu;
703 kmem_cache_t* cachep; 838 kmem_cache_t* cachep;
839 struct kmem_list3 *l3 = NULL;
840 int node = cpu_to_node(cpu);
841 int memsize = sizeof(struct kmem_list3);
842 struct array_cache *nc = NULL;
704 843
705 switch (action) { 844 switch (action) {
706 case CPU_UP_PREPARE: 845 case CPU_UP_PREPARE:
707 down(&cache_chain_sem); 846 down(&cache_chain_sem);
847 /* we need to do this right in the beginning since
848 * alloc_arraycache's are going to use this list.
849 * kmalloc_node allows us to add the slab to the right
850 * kmem_list3 and not this cpu's kmem_list3
851 */
852
708 list_for_each_entry(cachep, &cache_chain, next) { 853 list_for_each_entry(cachep, &cache_chain, next) {
709 struct array_cache *nc; 854 /* setup the size64 kmemlist for cpu before we can
855 * begin anything. Make sure some other cpu on this
856 * node has not already allocated this
857 */
858 if (!cachep->nodelists[node]) {
859 if (!(l3 = kmalloc_node(memsize,
860 GFP_KERNEL, node)))
861 goto bad;
862 kmem_list3_init(l3);
863 l3->next_reap = jiffies + REAPTIMEOUT_LIST3 +
864 ((unsigned long)cachep)%REAPTIMEOUT_LIST3;
865
866 cachep->nodelists[node] = l3;
867 }
868
869 spin_lock_irq(&cachep->nodelists[node]->list_lock);
870 cachep->nodelists[node]->free_limit =
871 (1 + nr_cpus_node(node)) *
872 cachep->batchcount + cachep->num;
873 spin_unlock_irq(&cachep->nodelists[node]->list_lock);
874 }
710 875
711 nc = alloc_arraycache(cpu, cachep->limit, cachep->batchcount); 876 /* Now we can go ahead with allocating the shared array's
877 & array cache's */
878 list_for_each_entry(cachep, &cache_chain, next) {
879 nc = alloc_arraycache(node, cachep->limit,
880 cachep->batchcount);
712 if (!nc) 881 if (!nc)
713 goto bad; 882 goto bad;
714
715 spin_lock_irq(&cachep->spinlock);
716 cachep->array[cpu] = nc; 883 cachep->array[cpu] = nc;
717 cachep->free_limit = (1+num_online_cpus())*cachep->batchcount
718 + cachep->num;
719 spin_unlock_irq(&cachep->spinlock);
720 884
885 l3 = cachep->nodelists[node];
886 BUG_ON(!l3);
887 if (!l3->shared) {
888 if (!(nc = alloc_arraycache(node,
889 cachep->shared*cachep->batchcount,
890 0xbaadf00d)))
891 goto bad;
892
893 /* we are serialised from CPU_DEAD or
894 CPU_UP_CANCELLED by the cpucontrol lock */
895 l3->shared = nc;
896 }
721 } 897 }
722 up(&cache_chain_sem); 898 up(&cache_chain_sem);
723 break; 899 break;
@@ -732,13 +908,51 @@ static int __devinit cpuup_callback(struct notifier_block *nfb,
732 908
733 list_for_each_entry(cachep, &cache_chain, next) { 909 list_for_each_entry(cachep, &cache_chain, next) {
734 struct array_cache *nc; 910 struct array_cache *nc;
911 cpumask_t mask;
735 912
913 mask = node_to_cpumask(node);
736 spin_lock_irq(&cachep->spinlock); 914 spin_lock_irq(&cachep->spinlock);
737 /* cpu is dead; no one can alloc from it. */ 915 /* cpu is dead; no one can alloc from it. */
738 nc = cachep->array[cpu]; 916 nc = cachep->array[cpu];
739 cachep->array[cpu] = NULL; 917 cachep->array[cpu] = NULL;
740 cachep->free_limit -= cachep->batchcount; 918 l3 = cachep->nodelists[node];
741 free_block(cachep, ac_entry(nc), nc->avail); 919
920 if (!l3)
921 goto unlock_cache;
922
923 spin_lock(&l3->list_lock);
924
925 /* Free limit for this kmem_list3 */
926 l3->free_limit -= cachep->batchcount;
927 if (nc)
928 free_block(cachep, nc->entry, nc->avail);
929
930 if (!cpus_empty(mask)) {
931 spin_unlock(&l3->list_lock);
932 goto unlock_cache;
933 }
934
935 if (l3->shared) {
936 free_block(cachep, l3->shared->entry,
937 l3->shared->avail);
938 kfree(l3->shared);
939 l3->shared = NULL;
940 }
941 if (l3->alien) {
942 drain_alien_cache(cachep, l3);
943 free_alien_cache(l3->alien);
944 l3->alien = NULL;
945 }
946
947 /* free slabs belonging to this node */
948 if (__node_shrink(cachep, node)) {
949 cachep->nodelists[node] = NULL;
950 spin_unlock(&l3->list_lock);
951 kfree(l3);
952 } else {
953 spin_unlock(&l3->list_lock);
954 }
955unlock_cache:
742 spin_unlock_irq(&cachep->spinlock); 956 spin_unlock_irq(&cachep->spinlock);
743 kfree(nc); 957 kfree(nc);
744 } 958 }
@@ -754,6 +968,25 @@ bad:
754 968
755static struct notifier_block cpucache_notifier = { &cpuup_callback, NULL, 0 }; 969static struct notifier_block cpucache_notifier = { &cpuup_callback, NULL, 0 };
756 970
971/*
972 * swap the static kmem_list3 with kmalloced memory
973 */
974static void init_list(kmem_cache_t *cachep, struct kmem_list3 *list,
975 int nodeid)
976{
977 struct kmem_list3 *ptr;
978
979 BUG_ON(cachep->nodelists[nodeid] != list);
980 ptr = kmalloc_node(sizeof(struct kmem_list3), GFP_KERNEL, nodeid);
981 BUG_ON(!ptr);
982
983 local_irq_disable();
984 memcpy(ptr, list, sizeof(struct kmem_list3));
985 MAKE_ALL_LISTS(cachep, ptr, nodeid);
986 cachep->nodelists[nodeid] = ptr;
987 local_irq_enable();
988}
989
757/* Initialisation. 990/* Initialisation.
758 * Called after the gfp() functions have been enabled, and before smp_init(). 991 * Called after the gfp() functions have been enabled, and before smp_init().
759 */ 992 */
@@ -762,6 +995,13 @@ void __init kmem_cache_init(void)
762 size_t left_over; 995 size_t left_over;
763 struct cache_sizes *sizes; 996 struct cache_sizes *sizes;
764 struct cache_names *names; 997 struct cache_names *names;
998 int i;
999
1000 for (i = 0; i < NUM_INIT_LISTS; i++) {
1001 kmem_list3_init(&initkmem_list3[i]);
1002 if (i < MAX_NUMNODES)
1003 cache_cache.nodelists[i] = NULL;
1004 }
765 1005
766 /* 1006 /*
767 * Fragmentation resistance on low memory - only use bigger 1007 * Fragmentation resistance on low memory - only use bigger
@@ -770,21 +1010,24 @@ void __init kmem_cache_init(void)
770 if (num_physpages > (32 << 20) >> PAGE_SHIFT) 1010 if (num_physpages > (32 << 20) >> PAGE_SHIFT)
771 slab_break_gfp_order = BREAK_GFP_ORDER_HI; 1011 slab_break_gfp_order = BREAK_GFP_ORDER_HI;
772 1012
773
774 /* Bootstrap is tricky, because several objects are allocated 1013 /* Bootstrap is tricky, because several objects are allocated
775 * from caches that do not exist yet: 1014 * from caches that do not exist yet:
776 * 1) initialize the cache_cache cache: it contains the kmem_cache_t 1015 * 1) initialize the cache_cache cache: it contains the kmem_cache_t
777 * structures of all caches, except cache_cache itself: cache_cache 1016 * structures of all caches, except cache_cache itself: cache_cache
778 * is statically allocated. 1017 * is statically allocated.
779 * Initially an __init data area is used for the head array, it's 1018 * Initially an __init data area is used for the head array and the
780 * replaced with a kmalloc allocated array at the end of the bootstrap. 1019 * kmem_list3 structures, it's replaced with a kmalloc allocated
1020 * array at the end of the bootstrap.
781 * 2) Create the first kmalloc cache. 1021 * 2) Create the first kmalloc cache.
782 * The kmem_cache_t for the new cache is allocated normally. An __init 1022 * The kmem_cache_t for the new cache is allocated normally.
783 * data area is used for the head array. 1023 * An __init data area is used for the head array.
784 * 3) Create the remaining kmalloc caches, with minimally sized head arrays. 1024 * 3) Create the remaining kmalloc caches, with minimally sized
1025 * head arrays.
785 * 4) Replace the __init data head arrays for cache_cache and the first 1026 * 4) Replace the __init data head arrays for cache_cache and the first
786 * kmalloc cache with kmalloc allocated arrays. 1027 * kmalloc cache with kmalloc allocated arrays.
787 * 5) Resize the head arrays of the kmalloc caches to their final sizes. 1028 * 5) Replace the __init data for kmem_list3 for cache_cache and
1029 * the other cache's with kmalloc allocated memory.
1030 * 6) Resize the head arrays of the kmalloc caches to their final sizes.
788 */ 1031 */
789 1032
790 /* 1) create the cache_cache */ 1033 /* 1) create the cache_cache */
@@ -793,6 +1036,7 @@ void __init kmem_cache_init(void)
793 list_add(&cache_cache.next, &cache_chain); 1036 list_add(&cache_cache.next, &cache_chain);
794 cache_cache.colour_off = cache_line_size(); 1037 cache_cache.colour_off = cache_line_size();
795 cache_cache.array[smp_processor_id()] = &initarray_cache.cache; 1038 cache_cache.array[smp_processor_id()] = &initarray_cache.cache;
1039 cache_cache.nodelists[numa_node_id()] = &initkmem_list3[CACHE_CACHE];
796 1040
797 cache_cache.objsize = ALIGN(cache_cache.objsize, cache_line_size()); 1041 cache_cache.objsize = ALIGN(cache_cache.objsize, cache_line_size());
798 1042
@@ -810,15 +1054,33 @@ void __init kmem_cache_init(void)
810 sizes = malloc_sizes; 1054 sizes = malloc_sizes;
811 names = cache_names; 1055 names = cache_names;
812 1056
1057 /* Initialize the caches that provide memory for the array cache
1058 * and the kmem_list3 structures first.
1059 * Without this, further allocations will bug
1060 */
1061
1062 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
1063 sizes[INDEX_AC].cs_size, ARCH_KMALLOC_MINALIGN,
1064 (ARCH_KMALLOC_FLAGS | SLAB_PANIC), NULL, NULL);
1065
1066 if (INDEX_AC != INDEX_L3)
1067 sizes[INDEX_L3].cs_cachep =
1068 kmem_cache_create(names[INDEX_L3].name,
1069 sizes[INDEX_L3].cs_size, ARCH_KMALLOC_MINALIGN,
1070 (ARCH_KMALLOC_FLAGS | SLAB_PANIC), NULL, NULL);
1071
813 while (sizes->cs_size != ULONG_MAX) { 1072 while (sizes->cs_size != ULONG_MAX) {
814 /* For performance, all the general caches are L1 aligned. 1073 /*
1074 * For performance, all the general caches are L1 aligned.
815 * This should be particularly beneficial on SMP boxes, as it 1075 * This should be particularly beneficial on SMP boxes, as it
816 * eliminates "false sharing". 1076 * eliminates "false sharing".
817 * Note for systems short on memory removing the alignment will 1077 * Note for systems short on memory removing the alignment will
818 * allow tighter packing of the smaller caches. */ 1078 * allow tighter packing of the smaller caches.
819 sizes->cs_cachep = kmem_cache_create(names->name, 1079 */
820 sizes->cs_size, ARCH_KMALLOC_MINALIGN, 1080 if(!sizes->cs_cachep)
821 (ARCH_KMALLOC_FLAGS | SLAB_PANIC), NULL, NULL); 1081 sizes->cs_cachep = kmem_cache_create(names->name,
1082 sizes->cs_size, ARCH_KMALLOC_MINALIGN,
1083 (ARCH_KMALLOC_FLAGS | SLAB_PANIC), NULL, NULL);
822 1084
823 /* Inc off-slab bufctl limit until the ceiling is hit. */ 1085 /* Inc off-slab bufctl limit until the ceiling is hit. */
824 if (!(OFF_SLAB(sizes->cs_cachep))) { 1086 if (!(OFF_SLAB(sizes->cs_cachep))) {
@@ -837,24 +1099,47 @@ void __init kmem_cache_init(void)
837 /* 4) Replace the bootstrap head arrays */ 1099 /* 4) Replace the bootstrap head arrays */
838 { 1100 {
839 void * ptr; 1101 void * ptr;
840 1102
841 ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL); 1103 ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL);
1104
842 local_irq_disable(); 1105 local_irq_disable();
843 BUG_ON(ac_data(&cache_cache) != &initarray_cache.cache); 1106 BUG_ON(ac_data(&cache_cache) != &initarray_cache.cache);
844 memcpy(ptr, ac_data(&cache_cache), sizeof(struct arraycache_init)); 1107 memcpy(ptr, ac_data(&cache_cache),
1108 sizeof(struct arraycache_init));
845 cache_cache.array[smp_processor_id()] = ptr; 1109 cache_cache.array[smp_processor_id()] = ptr;
846 local_irq_enable(); 1110 local_irq_enable();
847 1111
848 ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL); 1112 ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL);
1113
849 local_irq_disable(); 1114 local_irq_disable();
850 BUG_ON(ac_data(malloc_sizes[0].cs_cachep) != &initarray_generic.cache); 1115 BUG_ON(ac_data(malloc_sizes[INDEX_AC].cs_cachep)
851 memcpy(ptr, ac_data(malloc_sizes[0].cs_cachep), 1116 != &initarray_generic.cache);
1117 memcpy(ptr, ac_data(malloc_sizes[INDEX_AC].cs_cachep),
852 sizeof(struct arraycache_init)); 1118 sizeof(struct arraycache_init));
853 malloc_sizes[0].cs_cachep->array[smp_processor_id()] = ptr; 1119 malloc_sizes[INDEX_AC].cs_cachep->array[smp_processor_id()] =
1120 ptr;
854 local_irq_enable(); 1121 local_irq_enable();
855 } 1122 }
1123 /* 5) Replace the bootstrap kmem_list3's */
1124 {
1125 int node;
1126 /* Replace the static kmem_list3 structures for the boot cpu */
1127 init_list(&cache_cache, &initkmem_list3[CACHE_CACHE],
1128 numa_node_id());
1129
1130 for_each_online_node(node) {
1131 init_list(malloc_sizes[INDEX_AC].cs_cachep,
1132 &initkmem_list3[SIZE_AC+node], node);
1133
1134 if (INDEX_AC != INDEX_L3) {
1135 init_list(malloc_sizes[INDEX_L3].cs_cachep,
1136 &initkmem_list3[SIZE_L3+node],
1137 node);
1138 }
1139 }
1140 }
856 1141
857 /* 5) resize the head arrays to their final sizes */ 1142 /* 6) resize the head arrays to their final sizes */
858 { 1143 {
859 kmem_cache_t *cachep; 1144 kmem_cache_t *cachep;
860 down(&cache_chain_sem); 1145 down(&cache_chain_sem);
@@ -870,7 +1155,6 @@ void __init kmem_cache_init(void)
870 * that initializes ac_data for all new cpus 1155 * that initializes ac_data for all new cpus
871 */ 1156 */
872 register_cpu_notifier(&cpucache_notifier); 1157 register_cpu_notifier(&cpucache_notifier);
873
874 1158
875 /* The reap timers are started later, with a module init call: 1159 /* The reap timers are started later, with a module init call:
876 * That part of the kernel is not yet operational. 1160 * That part of the kernel is not yet operational.
@@ -885,10 +1169,8 @@ static int __init cpucache_init(void)
885 * Register the timers that return unneeded 1169 * Register the timers that return unneeded
886 * pages to gfp. 1170 * pages to gfp.
887 */ 1171 */
888 for (cpu = 0; cpu < NR_CPUS; cpu++) { 1172 for_each_online_cpu(cpu)
889 if (cpu_online(cpu)) 1173 start_cpu_timer(cpu);
890 start_cpu_timer(cpu);
891 }
892 1174
893 return 0; 1175 return 0;
894} 1176}
@@ -1167,6 +1449,20 @@ static void slab_destroy (kmem_cache_t *cachep, struct slab *slabp)
1167 } 1449 }
1168} 1450}
1169 1451
1452/* For setting up all the kmem_list3s for cache whose objsize is same
1453 as size of kmem_list3. */
1454static inline void set_up_list3s(kmem_cache_t *cachep, int index)
1455{
1456 int node;
1457
1458 for_each_online_node(node) {
1459 cachep->nodelists[node] = &initkmem_list3[index+node];
1460 cachep->nodelists[node]->next_reap = jiffies +
1461 REAPTIMEOUT_LIST3 +
1462 ((unsigned long)cachep)%REAPTIMEOUT_LIST3;
1463 }
1464}
1465
1170/** 1466/**
1171 * kmem_cache_create - Create a cache. 1467 * kmem_cache_create - Create a cache.
1172 * @name: A string which is used in /proc/slabinfo to identify this cache. 1468 * @name: A string which is used in /proc/slabinfo to identify this cache.
@@ -1320,7 +1616,7 @@ kmem_cache_create (const char *name, size_t size, size_t align,
1320 size += BYTES_PER_WORD; 1616 size += BYTES_PER_WORD;
1321 } 1617 }
1322#if FORCED_DEBUG && defined(CONFIG_DEBUG_PAGEALLOC) 1618#if FORCED_DEBUG && defined(CONFIG_DEBUG_PAGEALLOC)
1323 if (size > 128 && cachep->reallen > cache_line_size() && size < PAGE_SIZE) { 1619 if (size >= malloc_sizes[INDEX_L3+1].cs_size && cachep->reallen > cache_line_size() && size < PAGE_SIZE) {
1324 cachep->dbghead += PAGE_SIZE - size; 1620 cachep->dbghead += PAGE_SIZE - size;
1325 size = PAGE_SIZE; 1621 size = PAGE_SIZE;
1326 } 1622 }
@@ -1422,13 +1718,9 @@ next:
1422 cachep->gfpflags |= GFP_DMA; 1718 cachep->gfpflags |= GFP_DMA;
1423 spin_lock_init(&cachep->spinlock); 1719 spin_lock_init(&cachep->spinlock);
1424 cachep->objsize = size; 1720 cachep->objsize = size;
1425 /* NUMA */
1426 INIT_LIST_HEAD(&cachep->lists.slabs_full);
1427 INIT_LIST_HEAD(&cachep->lists.slabs_partial);
1428 INIT_LIST_HEAD(&cachep->lists.slabs_free);
1429 1721
1430 if (flags & CFLGS_OFF_SLAB) 1722 if (flags & CFLGS_OFF_SLAB)
1431 cachep->slabp_cache = kmem_find_general_cachep(slab_size,0); 1723 cachep->slabp_cache = kmem_find_general_cachep(slab_size, 0u);
1432 cachep->ctor = ctor; 1724 cachep->ctor = ctor;
1433 cachep->dtor = dtor; 1725 cachep->dtor = dtor;
1434 cachep->name = name; 1726 cachep->name = name;
@@ -1444,11 +1736,43 @@ next:
1444 * the cache that's used by kmalloc(24), otherwise 1736 * the cache that's used by kmalloc(24), otherwise
1445 * the creation of further caches will BUG(). 1737 * the creation of further caches will BUG().
1446 */ 1738 */
1447 cachep->array[smp_processor_id()] = &initarray_generic.cache; 1739 cachep->array[smp_processor_id()] =
1448 g_cpucache_up = PARTIAL; 1740 &initarray_generic.cache;
1741
1742 /* If the cache that's used by
1743 * kmalloc(sizeof(kmem_list3)) is the first cache,
1744 * then we need to set up all its list3s, otherwise
1745 * the creation of further caches will BUG().
1746 */
1747 set_up_list3s(cachep, SIZE_AC);
1748 if (INDEX_AC == INDEX_L3)
1749 g_cpucache_up = PARTIAL_L3;
1750 else
1751 g_cpucache_up = PARTIAL_AC;
1449 } else { 1752 } else {
1450 cachep->array[smp_processor_id()] = kmalloc(sizeof(struct arraycache_init),GFP_KERNEL); 1753 cachep->array[smp_processor_id()] =
1754 kmalloc(sizeof(struct arraycache_init),
1755 GFP_KERNEL);
1756
1757 if (g_cpucache_up == PARTIAL_AC) {
1758 set_up_list3s(cachep, SIZE_L3);
1759 g_cpucache_up = PARTIAL_L3;
1760 } else {
1761 int node;
1762 for_each_online_node(node) {
1763
1764 cachep->nodelists[node] =
1765 kmalloc_node(sizeof(struct kmem_list3),
1766 GFP_KERNEL, node);
1767 BUG_ON(!cachep->nodelists[node]);
1768 kmem_list3_init(cachep->nodelists[node]);
1769 }
1770 }
1451 } 1771 }
1772 cachep->nodelists[numa_node_id()]->next_reap =
1773 jiffies + REAPTIMEOUT_LIST3 +
1774 ((unsigned long)cachep)%REAPTIMEOUT_LIST3;
1775
1452 BUG_ON(!ac_data(cachep)); 1776 BUG_ON(!ac_data(cachep));
1453 ac_data(cachep)->avail = 0; 1777 ac_data(cachep)->avail = 0;
1454 ac_data(cachep)->limit = BOOT_CPUCACHE_ENTRIES; 1778 ac_data(cachep)->limit = BOOT_CPUCACHE_ENTRIES;
@@ -1456,13 +1780,8 @@ next:
1456 ac_data(cachep)->touched = 0; 1780 ac_data(cachep)->touched = 0;
1457 cachep->batchcount = 1; 1781 cachep->batchcount = 1;
1458 cachep->limit = BOOT_CPUCACHE_ENTRIES; 1782 cachep->limit = BOOT_CPUCACHE_ENTRIES;
1459 cachep->free_limit = (1+num_online_cpus())*cachep->batchcount
1460 + cachep->num;
1461 } 1783 }
1462 1784
1463 cachep->lists.next_reap = jiffies + REAPTIMEOUT_LIST3 +
1464 ((unsigned long)cachep)%REAPTIMEOUT_LIST3;
1465
1466 /* Need the semaphore to access the chain. */ 1785 /* Need the semaphore to access the chain. */
1467 down(&cache_chain_sem); 1786 down(&cache_chain_sem);
1468 { 1787 {
@@ -1519,13 +1838,23 @@ static void check_spinlock_acquired(kmem_cache_t *cachep)
1519{ 1838{
1520#ifdef CONFIG_SMP 1839#ifdef CONFIG_SMP
1521 check_irq_off(); 1840 check_irq_off();
1522 BUG_ON(spin_trylock(&cachep->spinlock)); 1841 assert_spin_locked(&cachep->nodelists[numa_node_id()]->list_lock);
1523#endif 1842#endif
1524} 1843}
1844
1845static inline void check_spinlock_acquired_node(kmem_cache_t *cachep, int node)
1846{
1847#ifdef CONFIG_SMP
1848 check_irq_off();
1849 assert_spin_locked(&cachep->nodelists[node]->list_lock);
1850#endif
1851}
1852
1525#else 1853#else
1526#define check_irq_off() do { } while(0) 1854#define check_irq_off() do { } while(0)
1527#define check_irq_on() do { } while(0) 1855#define check_irq_on() do { } while(0)
1528#define check_spinlock_acquired(x) do { } while(0) 1856#define check_spinlock_acquired(x) do { } while(0)
1857#define check_spinlock_acquired_node(x, y) do { } while(0)
1529#endif 1858#endif
1530 1859
1531/* 1860/*
@@ -1547,7 +1876,7 @@ static void smp_call_function_all_cpus(void (*func) (void *arg), void *arg)
1547} 1876}
1548 1877
1549static void drain_array_locked(kmem_cache_t* cachep, 1878static void drain_array_locked(kmem_cache_t* cachep,
1550 struct array_cache *ac, int force); 1879 struct array_cache *ac, int force, int node);
1551 1880
1552static void do_drain(void *arg) 1881static void do_drain(void *arg)
1553{ 1882{
@@ -1556,59 +1885,82 @@ static void do_drain(void *arg)
1556 1885
1557 check_irq_off(); 1886 check_irq_off();
1558 ac = ac_data(cachep); 1887 ac = ac_data(cachep);
1559 spin_lock(&cachep->spinlock); 1888 spin_lock(&cachep->nodelists[numa_node_id()]->list_lock);
1560 free_block(cachep, &ac_entry(ac)[0], ac->avail); 1889 free_block(cachep, ac->entry, ac->avail);
1561 spin_unlock(&cachep->spinlock); 1890 spin_unlock(&cachep->nodelists[numa_node_id()]->list_lock);
1562 ac->avail = 0; 1891 ac->avail = 0;
1563} 1892}
1564 1893
1565static void drain_cpu_caches(kmem_cache_t *cachep) 1894static void drain_cpu_caches(kmem_cache_t *cachep)
1566{ 1895{
1896 struct kmem_list3 *l3;
1897 int node;
1898
1567 smp_call_function_all_cpus(do_drain, cachep); 1899 smp_call_function_all_cpus(do_drain, cachep);
1568 check_irq_on(); 1900 check_irq_on();
1569 spin_lock_irq(&cachep->spinlock); 1901 spin_lock_irq(&cachep->spinlock);
1570 if (cachep->lists.shared) 1902 for_each_online_node(node) {
1571 drain_array_locked(cachep, cachep->lists.shared, 1); 1903 l3 = cachep->nodelists[node];
1904 if (l3) {
1905 spin_lock(&l3->list_lock);
1906 drain_array_locked(cachep, l3->shared, 1, node);
1907 spin_unlock(&l3->list_lock);
1908 if (l3->alien)
1909 drain_alien_cache(cachep, l3);
1910 }
1911 }
1572 spin_unlock_irq(&cachep->spinlock); 1912 spin_unlock_irq(&cachep->spinlock);
1573} 1913}
1574 1914
1575 1915static int __node_shrink(kmem_cache_t *cachep, int node)
1576/* NUMA shrink all list3s */
1577static int __cache_shrink(kmem_cache_t *cachep)
1578{ 1916{
1579 struct slab *slabp; 1917 struct slab *slabp;
1918 struct kmem_list3 *l3 = cachep->nodelists[node];
1580 int ret; 1919 int ret;
1581 1920
1582 drain_cpu_caches(cachep); 1921 for (;;) {
1583
1584 check_irq_on();
1585 spin_lock_irq(&cachep->spinlock);
1586
1587 for(;;) {
1588 struct list_head *p; 1922 struct list_head *p;
1589 1923
1590 p = cachep->lists.slabs_free.prev; 1924 p = l3->slabs_free.prev;
1591 if (p == &cachep->lists.slabs_free) 1925 if (p == &l3->slabs_free)
1592 break; 1926 break;
1593 1927
1594 slabp = list_entry(cachep->lists.slabs_free.prev, struct slab, list); 1928 slabp = list_entry(l3->slabs_free.prev, struct slab, list);
1595#if DEBUG 1929#if DEBUG
1596 if (slabp->inuse) 1930 if (slabp->inuse)
1597 BUG(); 1931 BUG();
1598#endif 1932#endif
1599 list_del(&slabp->list); 1933 list_del(&slabp->list);
1600 1934
1601 cachep->lists.free_objects -= cachep->num; 1935 l3->free_objects -= cachep->num;
1602 spin_unlock_irq(&cachep->spinlock); 1936 spin_unlock_irq(&l3->list_lock);
1603 slab_destroy(cachep, slabp); 1937 slab_destroy(cachep, slabp);
1604 spin_lock_irq(&cachep->spinlock); 1938 spin_lock_irq(&l3->list_lock);
1605 } 1939 }
1606 ret = !list_empty(&cachep->lists.slabs_full) || 1940 ret = !list_empty(&l3->slabs_full) ||
1607 !list_empty(&cachep->lists.slabs_partial); 1941 !list_empty(&l3->slabs_partial);
1608 spin_unlock_irq(&cachep->spinlock);
1609 return ret; 1942 return ret;
1610} 1943}
1611 1944
1945static int __cache_shrink(kmem_cache_t *cachep)
1946{
1947 int ret = 0, i = 0;
1948 struct kmem_list3 *l3;
1949
1950 drain_cpu_caches(cachep);
1951
1952 check_irq_on();
1953 for_each_online_node(i) {
1954 l3 = cachep->nodelists[i];
1955 if (l3) {
1956 spin_lock_irq(&l3->list_lock);
1957 ret += __node_shrink(cachep, i);
1958 spin_unlock_irq(&l3->list_lock);
1959 }
1960 }
1961 return (ret ? 1 : 0);
1962}
1963
1612/** 1964/**
1613 * kmem_cache_shrink - Shrink a cache. 1965 * kmem_cache_shrink - Shrink a cache.
1614 * @cachep: The cache to shrink. 1966 * @cachep: The cache to shrink.
@@ -1645,6 +1997,7 @@ EXPORT_SYMBOL(kmem_cache_shrink);
1645int kmem_cache_destroy(kmem_cache_t * cachep) 1997int kmem_cache_destroy(kmem_cache_t * cachep)
1646{ 1998{
1647 int i; 1999 int i;
2000 struct kmem_list3 *l3;
1648 2001
1649 if (!cachep || in_interrupt()) 2002 if (!cachep || in_interrupt())
1650 BUG(); 2003 BUG();
@@ -1672,15 +2025,17 @@ int kmem_cache_destroy(kmem_cache_t * cachep)
1672 if (unlikely(cachep->flags & SLAB_DESTROY_BY_RCU)) 2025 if (unlikely(cachep->flags & SLAB_DESTROY_BY_RCU))
1673 synchronize_rcu(); 2026 synchronize_rcu();
1674 2027
1675 /* no cpu_online check required here since we clear the percpu 2028 for_each_online_cpu(i)
1676 * array on cpu offline and set this to NULL.
1677 */
1678 for (i = 0; i < NR_CPUS; i++)
1679 kfree(cachep->array[i]); 2029 kfree(cachep->array[i]);
1680 2030
1681 /* NUMA: free the list3 structures */ 2031 /* NUMA: free the list3 structures */
1682 kfree(cachep->lists.shared); 2032 for_each_online_node(i) {
1683 cachep->lists.shared = NULL; 2033 if ((l3 = cachep->nodelists[i])) {
2034 kfree(l3->shared);
2035 free_alien_cache(l3->alien);
2036 kfree(l3);
2037 }
2038 }
1684 kmem_cache_free(&cache_cache, cachep); 2039 kmem_cache_free(&cache_cache, cachep);
1685 2040
1686 unlock_cpu_hotplug(); 2041 unlock_cpu_hotplug();
@@ -1690,8 +2045,8 @@ int kmem_cache_destroy(kmem_cache_t * cachep)
1690EXPORT_SYMBOL(kmem_cache_destroy); 2045EXPORT_SYMBOL(kmem_cache_destroy);
1691 2046
1692/* Get the memory for a slab management obj. */ 2047/* Get the memory for a slab management obj. */
1693static struct slab* alloc_slabmgmt(kmem_cache_t *cachep, 2048static struct slab* alloc_slabmgmt(kmem_cache_t *cachep, void *objp,
1694 void *objp, int colour_off, unsigned int __nocast local_flags) 2049 int colour_off, unsigned int __nocast local_flags)
1695{ 2050{
1696 struct slab *slabp; 2051 struct slab *slabp;
1697 2052
@@ -1722,7 +2077,7 @@ static void cache_init_objs(kmem_cache_t *cachep,
1722 int i; 2077 int i;
1723 2078
1724 for (i = 0; i < cachep->num; i++) { 2079 for (i = 0; i < cachep->num; i++) {
1725 void* objp = slabp->s_mem+cachep->objsize*i; 2080 void *objp = slabp->s_mem+cachep->objsize*i;
1726#if DEBUG 2081#if DEBUG
1727 /* need to poison the objs? */ 2082 /* need to poison the objs? */
1728 if (cachep->flags & SLAB_POISON) 2083 if (cachep->flags & SLAB_POISON)
@@ -1799,6 +2154,7 @@ static int cache_grow(kmem_cache_t *cachep, unsigned int __nocast flags, int nod
1799 size_t offset; 2154 size_t offset;
1800 unsigned int local_flags; 2155 unsigned int local_flags;
1801 unsigned long ctor_flags; 2156 unsigned long ctor_flags;
2157 struct kmem_list3 *l3;
1802 2158
1803 /* Be lazy and only check for valid flags here, 2159 /* Be lazy and only check for valid flags here,
1804 * keeping it out of the critical path in kmem_cache_alloc(). 2160 * keeping it out of the critical path in kmem_cache_alloc().
@@ -1830,6 +2186,7 @@ static int cache_grow(kmem_cache_t *cachep, unsigned int __nocast flags, int nod
1830 2186
1831 spin_unlock(&cachep->spinlock); 2187 spin_unlock(&cachep->spinlock);
1832 2188
2189 check_irq_off();
1833 if (local_flags & __GFP_WAIT) 2190 if (local_flags & __GFP_WAIT)
1834 local_irq_enable(); 2191 local_irq_enable();
1835 2192
@@ -1841,8 +2198,9 @@ static int cache_grow(kmem_cache_t *cachep, unsigned int __nocast flags, int nod
1841 */ 2198 */
1842 kmem_flagcheck(cachep, flags); 2199 kmem_flagcheck(cachep, flags);
1843 2200
1844 2201 /* Get mem for the objs.
1845 /* Get mem for the objs. */ 2202 * Attempt to allocate a physical page from 'nodeid',
2203 */
1846 if (!(objp = kmem_getpages(cachep, flags, nodeid))) 2204 if (!(objp = kmem_getpages(cachep, flags, nodeid)))
1847 goto failed; 2205 goto failed;
1848 2206
@@ -1850,6 +2208,7 @@ static int cache_grow(kmem_cache_t *cachep, unsigned int __nocast flags, int nod
1850 if (!(slabp = alloc_slabmgmt(cachep, objp, offset, local_flags))) 2208 if (!(slabp = alloc_slabmgmt(cachep, objp, offset, local_flags)))
1851 goto opps1; 2209 goto opps1;
1852 2210
2211 slabp->nodeid = nodeid;
1853 set_slab_attr(cachep, slabp, objp); 2212 set_slab_attr(cachep, slabp, objp);
1854 2213
1855 cache_init_objs(cachep, slabp, ctor_flags); 2214 cache_init_objs(cachep, slabp, ctor_flags);
@@ -1857,13 +2216,14 @@ static int cache_grow(kmem_cache_t *cachep, unsigned int __nocast flags, int nod
1857 if (local_flags & __GFP_WAIT) 2216 if (local_flags & __GFP_WAIT)
1858 local_irq_disable(); 2217 local_irq_disable();
1859 check_irq_off(); 2218 check_irq_off();
1860 spin_lock(&cachep->spinlock); 2219 l3 = cachep->nodelists[nodeid];
2220 spin_lock(&l3->list_lock);
1861 2221
1862 /* Make slab active. */ 2222 /* Make slab active. */
1863 list_add_tail(&slabp->list, &(list3_data(cachep)->slabs_free)); 2223 list_add_tail(&slabp->list, &(l3->slabs_free));
1864 STATS_INC_GROWN(cachep); 2224 STATS_INC_GROWN(cachep);
1865 list3_data(cachep)->free_objects += cachep->num; 2225 l3->free_objects += cachep->num;
1866 spin_unlock(&cachep->spinlock); 2226 spin_unlock(&l3->list_lock);
1867 return 1; 2227 return 1;
1868opps1: 2228opps1:
1869 kmem_freepages(cachep, objp); 2229 kmem_freepages(cachep, objp);
@@ -1969,7 +2329,6 @@ static void check_slabp(kmem_cache_t *cachep, struct slab *slabp)
1969 kmem_bufctl_t i; 2329 kmem_bufctl_t i;
1970 int entries = 0; 2330 int entries = 0;
1971 2331
1972 check_spinlock_acquired(cachep);
1973 /* Check slab's freelist to see if this obj is there. */ 2332 /* Check slab's freelist to see if this obj is there. */
1974 for (i = slabp->free; i != BUFCTL_END; i = slab_bufctl(slabp)[i]) { 2333 for (i = slabp->free; i != BUFCTL_END; i = slab_bufctl(slabp)[i]) {
1975 entries++; 2334 entries++;
@@ -2012,10 +2371,11 @@ retry:
2012 */ 2371 */
2013 batchcount = BATCHREFILL_LIMIT; 2372 batchcount = BATCHREFILL_LIMIT;
2014 } 2373 }
2015 l3 = list3_data(cachep); 2374 l3 = cachep->nodelists[numa_node_id()];
2375
2376 BUG_ON(ac->avail > 0 || !l3);
2377 spin_lock(&l3->list_lock);
2016 2378
2017 BUG_ON(ac->avail > 0);
2018 spin_lock(&cachep->spinlock);
2019 if (l3->shared) { 2379 if (l3->shared) {
2020 struct array_cache *shared_array = l3->shared; 2380 struct array_cache *shared_array = l3->shared;
2021 if (shared_array->avail) { 2381 if (shared_array->avail) {
@@ -2023,8 +2383,9 @@ retry:
2023 batchcount = shared_array->avail; 2383 batchcount = shared_array->avail;
2024 shared_array->avail -= batchcount; 2384 shared_array->avail -= batchcount;
2025 ac->avail = batchcount; 2385 ac->avail = batchcount;
2026 memcpy(ac_entry(ac), &ac_entry(shared_array)[shared_array->avail], 2386 memcpy(ac->entry,
2027 sizeof(void*)*batchcount); 2387 &(shared_array->entry[shared_array->avail]),
2388 sizeof(void*)*batchcount);
2028 shared_array->touched = 1; 2389 shared_array->touched = 1;
2029 goto alloc_done; 2390 goto alloc_done;
2030 } 2391 }
@@ -2051,7 +2412,8 @@ retry:
2051 STATS_SET_HIGH(cachep); 2412 STATS_SET_HIGH(cachep);
2052 2413
2053 /* get obj pointer */ 2414 /* get obj pointer */
2054 ac_entry(ac)[ac->avail++] = slabp->s_mem + slabp->free*cachep->objsize; 2415 ac->entry[ac->avail++] = slabp->s_mem +
2416 slabp->free*cachep->objsize;
2055 2417
2056 slabp->inuse++; 2418 slabp->inuse++;
2057 next = slab_bufctl(slabp)[slabp->free]; 2419 next = slab_bufctl(slabp)[slabp->free];
@@ -2073,12 +2435,12 @@ retry:
2073must_grow: 2435must_grow:
2074 l3->free_objects -= ac->avail; 2436 l3->free_objects -= ac->avail;
2075alloc_done: 2437alloc_done:
2076 spin_unlock(&cachep->spinlock); 2438 spin_unlock(&l3->list_lock);
2077 2439
2078 if (unlikely(!ac->avail)) { 2440 if (unlikely(!ac->avail)) {
2079 int x; 2441 int x;
2080 x = cache_grow(cachep, flags, -1); 2442 x = cache_grow(cachep, flags, numa_node_id());
2081 2443
2082 // cache_grow can reenable interrupts, then ac could change. 2444 // cache_grow can reenable interrupts, then ac could change.
2083 ac = ac_data(cachep); 2445 ac = ac_data(cachep);
2084 if (!x && ac->avail == 0) // no objects in sight? abort 2446 if (!x && ac->avail == 0) // no objects in sight? abort
@@ -2088,7 +2450,7 @@ alloc_done:
2088 goto retry; 2450 goto retry;
2089 } 2451 }
2090 ac->touched = 1; 2452 ac->touched = 1;
2091 return ac_entry(ac)[--ac->avail]; 2453 return ac->entry[--ac->avail];
2092} 2454}
2093 2455
2094static inline void 2456static inline void
@@ -2160,7 +2522,7 @@ static inline void *__cache_alloc(kmem_cache_t *cachep, unsigned int __nocast fl
2160 if (likely(ac->avail)) { 2522 if (likely(ac->avail)) {
2161 STATS_INC_ALLOCHIT(cachep); 2523 STATS_INC_ALLOCHIT(cachep);
2162 ac->touched = 1; 2524 ac->touched = 1;
2163 objp = ac_entry(ac)[--ac->avail]; 2525 objp = ac->entry[--ac->avail];
2164 } else { 2526 } else {
2165 STATS_INC_ALLOCMISS(cachep); 2527 STATS_INC_ALLOCMISS(cachep);
2166 objp = cache_alloc_refill(cachep, flags); 2528 objp = cache_alloc_refill(cachep, flags);
@@ -2172,33 +2534,104 @@ static inline void *__cache_alloc(kmem_cache_t *cachep, unsigned int __nocast fl
2172 return objp; 2534 return objp;
2173} 2535}
2174 2536
2175/* 2537#ifdef CONFIG_NUMA
2176 * NUMA: different approach needed if the spinlock is moved into 2538/*
2177 * the l3 structure 2539 * A interface to enable slab creation on nodeid
2178 */ 2540 */
2541static void *__cache_alloc_node(kmem_cache_t *cachep, int flags, int nodeid)
2542{
2543 struct list_head *entry;
2544 struct slab *slabp;
2545 struct kmem_list3 *l3;
2546 void *obj;
2547 kmem_bufctl_t next;
2548 int x;
2549
2550 l3 = cachep->nodelists[nodeid];
2551 BUG_ON(!l3);
2552
2553retry:
2554 spin_lock(&l3->list_lock);
2555 entry = l3->slabs_partial.next;
2556 if (entry == &l3->slabs_partial) {
2557 l3->free_touched = 1;
2558 entry = l3->slabs_free.next;
2559 if (entry == &l3->slabs_free)
2560 goto must_grow;
2561 }
2562
2563 slabp = list_entry(entry, struct slab, list);
2564 check_spinlock_acquired_node(cachep, nodeid);
2565 check_slabp(cachep, slabp);
2566
2567 STATS_INC_NODEALLOCS(cachep);
2568 STATS_INC_ACTIVE(cachep);
2569 STATS_SET_HIGH(cachep);
2570
2571 BUG_ON(slabp->inuse == cachep->num);
2572
2573 /* get obj pointer */
2574 obj = slabp->s_mem + slabp->free*cachep->objsize;
2575 slabp->inuse++;
2576 next = slab_bufctl(slabp)[slabp->free];
2577#if DEBUG
2578 slab_bufctl(slabp)[slabp->free] = BUFCTL_FREE;
2579#endif
2580 slabp->free = next;
2581 check_slabp(cachep, slabp);
2582 l3->free_objects--;
2583 /* move slabp to correct slabp list: */
2584 list_del(&slabp->list);
2179 2585
2586 if (slabp->free == BUFCTL_END) {
2587 list_add(&slabp->list, &l3->slabs_full);
2588 } else {
2589 list_add(&slabp->list, &l3->slabs_partial);
2590 }
2591
2592 spin_unlock(&l3->list_lock);
2593 goto done;
2594
2595must_grow:
2596 spin_unlock(&l3->list_lock);
2597 x = cache_grow(cachep, flags, nodeid);
2598
2599 if (!x)
2600 return NULL;
2601
2602 goto retry;
2603done:
2604 return obj;
2605}
2606#endif
2607
2608/*
2609 * Caller needs to acquire correct kmem_list's list_lock
2610 */
2180static void free_block(kmem_cache_t *cachep, void **objpp, int nr_objects) 2611static void free_block(kmem_cache_t *cachep, void **objpp, int nr_objects)
2181{ 2612{
2182 int i; 2613 int i;
2183 2614 struct kmem_list3 *l3;
2184 check_spinlock_acquired(cachep);
2185
2186 /* NUMA: move add into loop */
2187 cachep->lists.free_objects += nr_objects;
2188 2615
2189 for (i = 0; i < nr_objects; i++) { 2616 for (i = 0; i < nr_objects; i++) {
2190 void *objp = objpp[i]; 2617 void *objp = objpp[i];
2191 struct slab *slabp; 2618 struct slab *slabp;
2192 unsigned int objnr; 2619 unsigned int objnr;
2620 int nodeid = 0;
2193 2621
2194 slabp = GET_PAGE_SLAB(virt_to_page(objp)); 2622 slabp = GET_PAGE_SLAB(virt_to_page(objp));
2623 nodeid = slabp->nodeid;
2624 l3 = cachep->nodelists[nodeid];
2195 list_del(&slabp->list); 2625 list_del(&slabp->list);
2196 objnr = (objp - slabp->s_mem) / cachep->objsize; 2626 objnr = (objp - slabp->s_mem) / cachep->objsize;
2627 check_spinlock_acquired_node(cachep, nodeid);
2197 check_slabp(cachep, slabp); 2628 check_slabp(cachep, slabp);
2629
2630
2198#if DEBUG 2631#if DEBUG
2199 if (slab_bufctl(slabp)[objnr] != BUFCTL_FREE) { 2632 if (slab_bufctl(slabp)[objnr] != BUFCTL_FREE) {
2200 printk(KERN_ERR "slab: double free detected in cache '%s', objp %p.\n", 2633 printk(KERN_ERR "slab: double free detected in cache "
2201 cachep->name, objp); 2634 "'%s', objp %p\n", cachep->name, objp);
2202 BUG(); 2635 BUG();
2203 } 2636 }
2204#endif 2637#endif
@@ -2206,24 +2639,23 @@ static void free_block(kmem_cache_t *cachep, void **objpp, int nr_objects)
2206 slabp->free = objnr; 2639 slabp->free = objnr;
2207 STATS_DEC_ACTIVE(cachep); 2640 STATS_DEC_ACTIVE(cachep);
2208 slabp->inuse--; 2641 slabp->inuse--;
2642 l3->free_objects++;
2209 check_slabp(cachep, slabp); 2643 check_slabp(cachep, slabp);
2210 2644
2211 /* fixup slab chains */ 2645 /* fixup slab chains */
2212 if (slabp->inuse == 0) { 2646 if (slabp->inuse == 0) {
2213 if (cachep->lists.free_objects > cachep->free_limit) { 2647 if (l3->free_objects > l3->free_limit) {
2214 cachep->lists.free_objects -= cachep->num; 2648 l3->free_objects -= cachep->num;
2215 slab_destroy(cachep, slabp); 2649 slab_destroy(cachep, slabp);
2216 } else { 2650 } else {
2217 list_add(&slabp->list, 2651 list_add(&slabp->list, &l3->slabs_free);
2218 &list3_data_ptr(cachep, objp)->slabs_free);
2219 } 2652 }
2220 } else { 2653 } else {
2221 /* Unconditionally move a slab to the end of the 2654 /* Unconditionally move a slab to the end of the
2222 * partial list on free - maximum time for the 2655 * partial list on free - maximum time for the
2223 * other objects to be freed, too. 2656 * other objects to be freed, too.
2224 */ 2657 */
2225 list_add_tail(&slabp->list, 2658 list_add_tail(&slabp->list, &l3->slabs_partial);
2226 &list3_data_ptr(cachep, objp)->slabs_partial);
2227 } 2659 }
2228 } 2660 }
2229} 2661}
@@ -2231,36 +2663,38 @@ static void free_block(kmem_cache_t *cachep, void **objpp, int nr_objects)
2231static void cache_flusharray(kmem_cache_t *cachep, struct array_cache *ac) 2663static void cache_flusharray(kmem_cache_t *cachep, struct array_cache *ac)
2232{ 2664{
2233 int batchcount; 2665 int batchcount;
2666 struct kmem_list3 *l3;
2234 2667
2235 batchcount = ac->batchcount; 2668 batchcount = ac->batchcount;
2236#if DEBUG 2669#if DEBUG
2237 BUG_ON(!batchcount || batchcount > ac->avail); 2670 BUG_ON(!batchcount || batchcount > ac->avail);
2238#endif 2671#endif
2239 check_irq_off(); 2672 check_irq_off();
2240 spin_lock(&cachep->spinlock); 2673 l3 = cachep->nodelists[numa_node_id()];
2241 if (cachep->lists.shared) { 2674 spin_lock(&l3->list_lock);
2242 struct array_cache *shared_array = cachep->lists.shared; 2675 if (l3->shared) {
2676 struct array_cache *shared_array = l3->shared;
2243 int max = shared_array->limit-shared_array->avail; 2677 int max = shared_array->limit-shared_array->avail;
2244 if (max) { 2678 if (max) {
2245 if (batchcount > max) 2679 if (batchcount > max)
2246 batchcount = max; 2680 batchcount = max;
2247 memcpy(&ac_entry(shared_array)[shared_array->avail], 2681 memcpy(&(shared_array->entry[shared_array->avail]),
2248 &ac_entry(ac)[0], 2682 ac->entry,
2249 sizeof(void*)*batchcount); 2683 sizeof(void*)*batchcount);
2250 shared_array->avail += batchcount; 2684 shared_array->avail += batchcount;
2251 goto free_done; 2685 goto free_done;
2252 } 2686 }
2253 } 2687 }
2254 2688
2255 free_block(cachep, &ac_entry(ac)[0], batchcount); 2689 free_block(cachep, ac->entry, batchcount);
2256free_done: 2690free_done:
2257#if STATS 2691#if STATS
2258 { 2692 {
2259 int i = 0; 2693 int i = 0;
2260 struct list_head *p; 2694 struct list_head *p;
2261 2695
2262 p = list3_data(cachep)->slabs_free.next; 2696 p = l3->slabs_free.next;
2263 while (p != &(list3_data(cachep)->slabs_free)) { 2697 while (p != &(l3->slabs_free)) {
2264 struct slab *slabp; 2698 struct slab *slabp;
2265 2699
2266 slabp = list_entry(p, struct slab, list); 2700 slabp = list_entry(p, struct slab, list);
@@ -2272,12 +2706,13 @@ free_done:
2272 STATS_SET_FREEABLE(cachep, i); 2706 STATS_SET_FREEABLE(cachep, i);
2273 } 2707 }
2274#endif 2708#endif
2275 spin_unlock(&cachep->spinlock); 2709 spin_unlock(&l3->list_lock);
2276 ac->avail -= batchcount; 2710 ac->avail -= batchcount;
2277 memmove(&ac_entry(ac)[0], &ac_entry(ac)[batchcount], 2711 memmove(ac->entry, &(ac->entry[batchcount]),
2278 sizeof(void*)*ac->avail); 2712 sizeof(void*)*ac->avail);
2279} 2713}
2280 2714
2715
2281/* 2716/*
2282 * __cache_free 2717 * __cache_free
2283 * Release an obj back to its cache. If the obj has a constructed 2718 * Release an obj back to its cache. If the obj has a constructed
@@ -2292,14 +2727,46 @@ static inline void __cache_free(kmem_cache_t *cachep, void *objp)
2292 check_irq_off(); 2727 check_irq_off();
2293 objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0)); 2728 objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
2294 2729
2730 /* Make sure we are not freeing a object from another
2731 * node to the array cache on this cpu.
2732 */
2733#ifdef CONFIG_NUMA
2734 {
2735 struct slab *slabp;
2736 slabp = GET_PAGE_SLAB(virt_to_page(objp));
2737 if (unlikely(slabp->nodeid != numa_node_id())) {
2738 struct array_cache *alien = NULL;
2739 int nodeid = slabp->nodeid;
2740 struct kmem_list3 *l3 = cachep->nodelists[numa_node_id()];
2741
2742 STATS_INC_NODEFREES(cachep);
2743 if (l3->alien && l3->alien[nodeid]) {
2744 alien = l3->alien[nodeid];
2745 spin_lock(&alien->lock);
2746 if (unlikely(alien->avail == alien->limit))
2747 __drain_alien_cache(cachep,
2748 alien, nodeid);
2749 alien->entry[alien->avail++] = objp;
2750 spin_unlock(&alien->lock);
2751 } else {
2752 spin_lock(&(cachep->nodelists[nodeid])->
2753 list_lock);
2754 free_block(cachep, &objp, 1);
2755 spin_unlock(&(cachep->nodelists[nodeid])->
2756 list_lock);
2757 }
2758 return;
2759 }
2760 }
2761#endif
2295 if (likely(ac->avail < ac->limit)) { 2762 if (likely(ac->avail < ac->limit)) {
2296 STATS_INC_FREEHIT(cachep); 2763 STATS_INC_FREEHIT(cachep);
2297 ac_entry(ac)[ac->avail++] = objp; 2764 ac->entry[ac->avail++] = objp;
2298 return; 2765 return;
2299 } else { 2766 } else {
2300 STATS_INC_FREEMISS(cachep); 2767 STATS_INC_FREEMISS(cachep);
2301 cache_flusharray(cachep, ac); 2768 cache_flusharray(cachep, ac);
2302 ac_entry(ac)[ac->avail++] = objp; 2769 ac->entry[ac->avail++] = objp;
2303 } 2770 }
2304} 2771}
2305 2772
@@ -2369,81 +2836,30 @@ out:
2369 * Identical to kmem_cache_alloc, except that this function is slow 2836 * Identical to kmem_cache_alloc, except that this function is slow
2370 * and can sleep. And it will allocate memory on the given node, which 2837 * and can sleep. And it will allocate memory on the given node, which
2371 * can improve the performance for cpu bound structures. 2838 * can improve the performance for cpu bound structures.
2839 * New and improved: it will now make sure that the object gets
2840 * put on the correct node list so that there is no false sharing.
2372 */ 2841 */
2373void *kmem_cache_alloc_node(kmem_cache_t *cachep, int flags, int nodeid) 2842void *kmem_cache_alloc_node(kmem_cache_t *cachep, unsigned int __nocast flags, int nodeid)
2374{ 2843{
2375 int loop; 2844 unsigned long save_flags;
2376 void *objp; 2845 void *ptr;
2377 struct slab *slabp;
2378 kmem_bufctl_t next;
2379
2380 if (nodeid == -1)
2381 return kmem_cache_alloc(cachep, flags);
2382
2383 for (loop = 0;;loop++) {
2384 struct list_head *q;
2385
2386 objp = NULL;
2387 check_irq_on();
2388 spin_lock_irq(&cachep->spinlock);
2389 /* walk through all partial and empty slab and find one
2390 * from the right node */
2391 list_for_each(q,&cachep->lists.slabs_partial) {
2392 slabp = list_entry(q, struct slab, list);
2393
2394 if (page_to_nid(virt_to_page(slabp->s_mem)) == nodeid ||
2395 loop > 2)
2396 goto got_slabp;
2397 }
2398 list_for_each(q, &cachep->lists.slabs_free) {
2399 slabp = list_entry(q, struct slab, list);
2400 2846
2401 if (page_to_nid(virt_to_page(slabp->s_mem)) == nodeid || 2847 if (nodeid == numa_node_id() || nodeid == -1)
2402 loop > 2) 2848 return __cache_alloc(cachep, flags);
2403 goto got_slabp;
2404 }
2405 spin_unlock_irq(&cachep->spinlock);
2406 2849
2407 local_irq_disable(); 2850 if (unlikely(!cachep->nodelists[nodeid])) {
2408 if (!cache_grow(cachep, flags, nodeid)) { 2851 /* Fall back to __cache_alloc if we run into trouble */
2409 local_irq_enable(); 2852 printk(KERN_WARNING "slab: not allocating in inactive node %d for cache %s\n", nodeid, cachep->name);
2410 return NULL; 2853 return __cache_alloc(cachep,flags);
2411 }
2412 local_irq_enable();
2413 } 2854 }
2414got_slabp:
2415 /* found one: allocate object */
2416 check_slabp(cachep, slabp);
2417 check_spinlock_acquired(cachep);
2418
2419 STATS_INC_ALLOCED(cachep);
2420 STATS_INC_ACTIVE(cachep);
2421 STATS_SET_HIGH(cachep);
2422 STATS_INC_NODEALLOCS(cachep);
2423 2855
2424 objp = slabp->s_mem + slabp->free*cachep->objsize; 2856 cache_alloc_debugcheck_before(cachep, flags);
2425 2857 local_irq_save(save_flags);
2426 slabp->inuse++; 2858 ptr = __cache_alloc_node(cachep, flags, nodeid);
2427 next = slab_bufctl(slabp)[slabp->free]; 2859 local_irq_restore(save_flags);
2428#if DEBUG 2860 ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, __builtin_return_address(0));
2429 slab_bufctl(slabp)[slabp->free] = BUFCTL_FREE;
2430#endif
2431 slabp->free = next;
2432 check_slabp(cachep, slabp);
2433
2434 /* move slabp to correct slabp list: */
2435 list_del(&slabp->list);
2436 if (slabp->free == BUFCTL_END)
2437 list_add(&slabp->list, &cachep->lists.slabs_full);
2438 else
2439 list_add(&slabp->list, &cachep->lists.slabs_partial);
2440
2441 list3_data(cachep)->free_objects--;
2442 spin_unlock_irq(&cachep->spinlock);
2443 2861
2444 objp = cache_alloc_debugcheck_after(cachep, GFP_KERNEL, objp, 2862 return ptr;
2445 __builtin_return_address(0));
2446 return objp;
2447} 2863}
2448EXPORT_SYMBOL(kmem_cache_alloc_node); 2864EXPORT_SYMBOL(kmem_cache_alloc_node);
2449 2865
@@ -2513,11 +2929,18 @@ void *__alloc_percpu(size_t size, size_t align)
2513 if (!pdata) 2929 if (!pdata)
2514 return NULL; 2930 return NULL;
2515 2931
2516 for (i = 0; i < NR_CPUS; i++) { 2932 /*
2517 if (!cpu_possible(i)) 2933 * Cannot use for_each_online_cpu since a cpu may come online
2518 continue; 2934 * and we have no way of figuring out how to fix the array
2519 pdata->ptrs[i] = kmalloc_node(size, GFP_KERNEL, 2935 * that we have allocated then....
2520 cpu_to_node(i)); 2936 */
2937 for_each_cpu(i) {
2938 int node = cpu_to_node(i);
2939
2940 if (node_online(node))
2941 pdata->ptrs[i] = kmalloc_node(size, GFP_KERNEL, node);
2942 else
2943 pdata->ptrs[i] = kmalloc(size, GFP_KERNEL);
2521 2944
2522 if (!pdata->ptrs[i]) 2945 if (!pdata->ptrs[i])
2523 goto unwind_oom; 2946 goto unwind_oom;
@@ -2575,6 +2998,8 @@ EXPORT_SYMBOL(kzalloc);
2575 * kfree - free previously allocated memory 2998 * kfree - free previously allocated memory
2576 * @objp: pointer returned by kmalloc. 2999 * @objp: pointer returned by kmalloc.
2577 * 3000 *
3001 * If @objp is NULL, no operation is performed.
3002 *
2578 * Don't free memory not originally allocated by kmalloc() 3003 * Don't free memory not originally allocated by kmalloc()
2579 * or you will run into trouble. 3004 * or you will run into trouble.
2580 */ 3005 */
@@ -2607,11 +3032,11 @@ free_percpu(const void *objp)
2607 int i; 3032 int i;
2608 struct percpu_data *p = (struct percpu_data *) (~(unsigned long) objp); 3033 struct percpu_data *p = (struct percpu_data *) (~(unsigned long) objp);
2609 3034
2610 for (i = 0; i < NR_CPUS; i++) { 3035 /*
2611 if (!cpu_possible(i)) 3036 * We allocate for all cpus so we cannot use for online cpu here.
2612 continue; 3037 */
3038 for_each_cpu(i)
2613 kfree(p->ptrs[i]); 3039 kfree(p->ptrs[i]);
2614 }
2615 kfree(p); 3040 kfree(p);
2616} 3041}
2617EXPORT_SYMBOL(free_percpu); 3042EXPORT_SYMBOL(free_percpu);
@@ -2629,6 +3054,64 @@ const char *kmem_cache_name(kmem_cache_t *cachep)
2629} 3054}
2630EXPORT_SYMBOL_GPL(kmem_cache_name); 3055EXPORT_SYMBOL_GPL(kmem_cache_name);
2631 3056
3057/*
3058 * This initializes kmem_list3 for all nodes.
3059 */
3060static int alloc_kmemlist(kmem_cache_t *cachep)
3061{
3062 int node;
3063 struct kmem_list3 *l3;
3064 int err = 0;
3065
3066 for_each_online_node(node) {
3067 struct array_cache *nc = NULL, *new;
3068 struct array_cache **new_alien = NULL;
3069#ifdef CONFIG_NUMA
3070 if (!(new_alien = alloc_alien_cache(node, cachep->limit)))
3071 goto fail;
3072#endif
3073 if (!(new = alloc_arraycache(node, (cachep->shared*
3074 cachep->batchcount), 0xbaadf00d)))
3075 goto fail;
3076 if ((l3 = cachep->nodelists[node])) {
3077
3078 spin_lock_irq(&l3->list_lock);
3079
3080 if ((nc = cachep->nodelists[node]->shared))
3081 free_block(cachep, nc->entry,
3082 nc->avail);
3083
3084 l3->shared = new;
3085 if (!cachep->nodelists[node]->alien) {
3086 l3->alien = new_alien;
3087 new_alien = NULL;
3088 }
3089 l3->free_limit = (1 + nr_cpus_node(node))*
3090 cachep->batchcount + cachep->num;
3091 spin_unlock_irq(&l3->list_lock);
3092 kfree(nc);
3093 free_alien_cache(new_alien);
3094 continue;
3095 }
3096 if (!(l3 = kmalloc_node(sizeof(struct kmem_list3),
3097 GFP_KERNEL, node)))
3098 goto fail;
3099
3100 kmem_list3_init(l3);
3101 l3->next_reap = jiffies + REAPTIMEOUT_LIST3 +
3102 ((unsigned long)cachep)%REAPTIMEOUT_LIST3;
3103 l3->shared = new;
3104 l3->alien = new_alien;
3105 l3->free_limit = (1 + nr_cpus_node(node))*
3106 cachep->batchcount + cachep->num;
3107 cachep->nodelists[node] = l3;
3108 }
3109 return err;
3110fail:
3111 err = -ENOMEM;
3112 return err;
3113}
3114
2632struct ccupdate_struct { 3115struct ccupdate_struct {
2633 kmem_cache_t *cachep; 3116 kmem_cache_t *cachep;
2634 struct array_cache *new[NR_CPUS]; 3117 struct array_cache *new[NR_CPUS];
@@ -2641,7 +3124,7 @@ static void do_ccupdate_local(void *info)
2641 3124
2642 check_irq_off(); 3125 check_irq_off();
2643 old = ac_data(new->cachep); 3126 old = ac_data(new->cachep);
2644 3127
2645 new->cachep->array[smp_processor_id()] = new->new[smp_processor_id()]; 3128 new->cachep->array[smp_processor_id()] = new->new[smp_processor_id()];
2646 new->new[smp_processor_id()] = old; 3129 new->new[smp_processor_id()] = old;
2647} 3130}
@@ -2651,54 +3134,43 @@ static int do_tune_cpucache(kmem_cache_t *cachep, int limit, int batchcount,
2651 int shared) 3134 int shared)
2652{ 3135{
2653 struct ccupdate_struct new; 3136 struct ccupdate_struct new;
2654 struct array_cache *new_shared; 3137 int i, err;
2655 int i;
2656 3138
2657 memset(&new.new,0,sizeof(new.new)); 3139 memset(&new.new,0,sizeof(new.new));
2658 for (i = 0; i < NR_CPUS; i++) { 3140 for_each_online_cpu(i) {
2659 if (cpu_online(i)) { 3141 new.new[i] = alloc_arraycache(cpu_to_node(i), limit, batchcount);
2660 new.new[i] = alloc_arraycache(i, limit, batchcount); 3142 if (!new.new[i]) {
2661 if (!new.new[i]) { 3143 for (i--; i >= 0; i--) kfree(new.new[i]);
2662 for (i--; i >= 0; i--) kfree(new.new[i]); 3144 return -ENOMEM;
2663 return -ENOMEM;
2664 }
2665 } else {
2666 new.new[i] = NULL;
2667 } 3145 }
2668 } 3146 }
2669 new.cachep = cachep; 3147 new.cachep = cachep;
2670 3148
2671 smp_call_function_all_cpus(do_ccupdate_local, (void *)&new); 3149 smp_call_function_all_cpus(do_ccupdate_local, (void *)&new);
2672 3150
2673 check_irq_on(); 3151 check_irq_on();
2674 spin_lock_irq(&cachep->spinlock); 3152 spin_lock_irq(&cachep->spinlock);
2675 cachep->batchcount = batchcount; 3153 cachep->batchcount = batchcount;
2676 cachep->limit = limit; 3154 cachep->limit = limit;
2677 cachep->free_limit = (1+num_online_cpus())*cachep->batchcount + cachep->num; 3155 cachep->shared = shared;
2678 spin_unlock_irq(&cachep->spinlock); 3156 spin_unlock_irq(&cachep->spinlock);
2679 3157
2680 for (i = 0; i < NR_CPUS; i++) { 3158 for_each_online_cpu(i) {
2681 struct array_cache *ccold = new.new[i]; 3159 struct array_cache *ccold = new.new[i];
2682 if (!ccold) 3160 if (!ccold)
2683 continue; 3161 continue;
2684 spin_lock_irq(&cachep->spinlock); 3162 spin_lock_irq(&cachep->nodelists[cpu_to_node(i)]->list_lock);
2685 free_block(cachep, ac_entry(ccold), ccold->avail); 3163 free_block(cachep, ccold->entry, ccold->avail);
2686 spin_unlock_irq(&cachep->spinlock); 3164 spin_unlock_irq(&cachep->nodelists[cpu_to_node(i)]->list_lock);
2687 kfree(ccold); 3165 kfree(ccold);
2688 } 3166 }
2689 new_shared = alloc_arraycache(-1, batchcount*shared, 0xbaadf00d);
2690 if (new_shared) {
2691 struct array_cache *old;
2692 3167
2693 spin_lock_irq(&cachep->spinlock); 3168 err = alloc_kmemlist(cachep);
2694 old = cachep->lists.shared; 3169 if (err) {
2695 cachep->lists.shared = new_shared; 3170 printk(KERN_ERR "alloc_kmemlist failed for %s, error %d.\n",
2696 if (old) 3171 cachep->name, -err);
2697 free_block(cachep, ac_entry(old), old->avail); 3172 BUG();
2698 spin_unlock_irq(&cachep->spinlock);
2699 kfree(old);
2700 } 3173 }
2701
2702 return 0; 3174 return 0;
2703} 3175}
2704 3176
@@ -2756,11 +3228,11 @@ static void enable_cpucache(kmem_cache_t *cachep)
2756} 3228}
2757 3229
2758static void drain_array_locked(kmem_cache_t *cachep, 3230static void drain_array_locked(kmem_cache_t *cachep,
2759 struct array_cache *ac, int force) 3231 struct array_cache *ac, int force, int node)
2760{ 3232{
2761 int tofree; 3233 int tofree;
2762 3234
2763 check_spinlock_acquired(cachep); 3235 check_spinlock_acquired_node(cachep, node);
2764 if (ac->touched && !force) { 3236 if (ac->touched && !force) {
2765 ac->touched = 0; 3237 ac->touched = 0;
2766 } else if (ac->avail) { 3238 } else if (ac->avail) {
@@ -2768,9 +3240,9 @@ static void drain_array_locked(kmem_cache_t *cachep,
2768 if (tofree > ac->avail) { 3240 if (tofree > ac->avail) {
2769 tofree = (ac->avail+1)/2; 3241 tofree = (ac->avail+1)/2;
2770 } 3242 }
2771 free_block(cachep, ac_entry(ac), tofree); 3243 free_block(cachep, ac->entry, tofree);
2772 ac->avail -= tofree; 3244 ac->avail -= tofree;
2773 memmove(&ac_entry(ac)[0], &ac_entry(ac)[tofree], 3245 memmove(ac->entry, &(ac->entry[tofree]),
2774 sizeof(void*)*ac->avail); 3246 sizeof(void*)*ac->avail);
2775 } 3247 }
2776} 3248}
@@ -2789,6 +3261,7 @@ static void drain_array_locked(kmem_cache_t *cachep,
2789static void cache_reap(void *unused) 3261static void cache_reap(void *unused)
2790{ 3262{
2791 struct list_head *walk; 3263 struct list_head *walk;
3264 struct kmem_list3 *l3;
2792 3265
2793 if (down_trylock(&cache_chain_sem)) { 3266 if (down_trylock(&cache_chain_sem)) {
2794 /* Give up. Setup the next iteration. */ 3267 /* Give up. Setup the next iteration. */
@@ -2809,27 +3282,32 @@ static void cache_reap(void *unused)
2809 3282
2810 check_irq_on(); 3283 check_irq_on();
2811 3284
2812 spin_lock_irq(&searchp->spinlock); 3285 l3 = searchp->nodelists[numa_node_id()];
3286 if (l3->alien)
3287 drain_alien_cache(searchp, l3);
3288 spin_lock_irq(&l3->list_lock);
2813 3289
2814 drain_array_locked(searchp, ac_data(searchp), 0); 3290 drain_array_locked(searchp, ac_data(searchp), 0,
3291 numa_node_id());
2815 3292
2816 if(time_after(searchp->lists.next_reap, jiffies)) 3293 if (time_after(l3->next_reap, jiffies))
2817 goto next_unlock; 3294 goto next_unlock;
2818 3295
2819 searchp->lists.next_reap = jiffies + REAPTIMEOUT_LIST3; 3296 l3->next_reap = jiffies + REAPTIMEOUT_LIST3;
2820 3297
2821 if (searchp->lists.shared) 3298 if (l3->shared)
2822 drain_array_locked(searchp, searchp->lists.shared, 0); 3299 drain_array_locked(searchp, l3->shared, 0,
3300 numa_node_id());
2823 3301
2824 if (searchp->lists.free_touched) { 3302 if (l3->free_touched) {
2825 searchp->lists.free_touched = 0; 3303 l3->free_touched = 0;
2826 goto next_unlock; 3304 goto next_unlock;
2827 } 3305 }
2828 3306
2829 tofree = (searchp->free_limit+5*searchp->num-1)/(5*searchp->num); 3307 tofree = (l3->free_limit+5*searchp->num-1)/(5*searchp->num);
2830 do { 3308 do {
2831 p = list3_data(searchp)->slabs_free.next; 3309 p = l3->slabs_free.next;
2832 if (p == &(list3_data(searchp)->slabs_free)) 3310 if (p == &(l3->slabs_free))
2833 break; 3311 break;
2834 3312
2835 slabp = list_entry(p, struct slab, list); 3313 slabp = list_entry(p, struct slab, list);
@@ -2842,13 +3320,13 @@ static void cache_reap(void *unused)
2842 * searchp cannot disappear, we hold 3320 * searchp cannot disappear, we hold
2843 * cache_chain_lock 3321 * cache_chain_lock
2844 */ 3322 */
2845 searchp->lists.free_objects -= searchp->num; 3323 l3->free_objects -= searchp->num;
2846 spin_unlock_irq(&searchp->spinlock); 3324 spin_unlock_irq(&l3->list_lock);
2847 slab_destroy(searchp, slabp); 3325 slab_destroy(searchp, slabp);
2848 spin_lock_irq(&searchp->spinlock); 3326 spin_lock_irq(&l3->list_lock);
2849 } while(--tofree > 0); 3327 } while(--tofree > 0);
2850next_unlock: 3328next_unlock:
2851 spin_unlock_irq(&searchp->spinlock); 3329 spin_unlock_irq(&l3->list_lock);
2852next: 3330next:
2853 cond_resched(); 3331 cond_resched();
2854 } 3332 }
@@ -2882,7 +3360,7 @@ static void *s_start(struct seq_file *m, loff_t *pos)
2882 seq_puts(m, " : slabdata <active_slabs> <num_slabs> <sharedavail>"); 3360 seq_puts(m, " : slabdata <active_slabs> <num_slabs> <sharedavail>");
2883#if STATS 3361#if STATS
2884 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped>" 3362 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped>"
2885 " <error> <maxfreeable> <freelimit> <nodeallocs>"); 3363 " <error> <maxfreeable> <nodeallocs> <remotefrees>");
2886 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>"); 3364 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
2887#endif 3365#endif
2888 seq_putc(m, '\n'); 3366 seq_putc(m, '\n');
@@ -2917,39 +3395,53 @@ static int s_show(struct seq_file *m, void *p)
2917 unsigned long active_objs; 3395 unsigned long active_objs;
2918 unsigned long num_objs; 3396 unsigned long num_objs;
2919 unsigned long active_slabs = 0; 3397 unsigned long active_slabs = 0;
2920 unsigned long num_slabs; 3398 unsigned long num_slabs, free_objects = 0, shared_avail = 0;
2921 const char *name; 3399 const char *name;
2922 char *error = NULL; 3400 char *error = NULL;
3401 int node;
3402 struct kmem_list3 *l3;
2923 3403
2924 check_irq_on(); 3404 check_irq_on();
2925 spin_lock_irq(&cachep->spinlock); 3405 spin_lock_irq(&cachep->spinlock);
2926 active_objs = 0; 3406 active_objs = 0;
2927 num_slabs = 0; 3407 num_slabs = 0;
2928 list_for_each(q,&cachep->lists.slabs_full) { 3408 for_each_online_node(node) {
2929 slabp = list_entry(q, struct slab, list); 3409 l3 = cachep->nodelists[node];
2930 if (slabp->inuse != cachep->num && !error) 3410 if (!l3)
2931 error = "slabs_full accounting error"; 3411 continue;
2932 active_objs += cachep->num; 3412
2933 active_slabs++; 3413 spin_lock(&l3->list_lock);
2934 } 3414
2935 list_for_each(q,&cachep->lists.slabs_partial) { 3415 list_for_each(q,&l3->slabs_full) {
2936 slabp = list_entry(q, struct slab, list); 3416 slabp = list_entry(q, struct slab, list);
2937 if (slabp->inuse == cachep->num && !error) 3417 if (slabp->inuse != cachep->num && !error)
2938 error = "slabs_partial inuse accounting error"; 3418 error = "slabs_full accounting error";
2939 if (!slabp->inuse && !error) 3419 active_objs += cachep->num;
2940 error = "slabs_partial/inuse accounting error"; 3420 active_slabs++;
2941 active_objs += slabp->inuse; 3421 }
2942 active_slabs++; 3422 list_for_each(q,&l3->slabs_partial) {
2943 } 3423 slabp = list_entry(q, struct slab, list);
2944 list_for_each(q,&cachep->lists.slabs_free) { 3424 if (slabp->inuse == cachep->num && !error)
2945 slabp = list_entry(q, struct slab, list); 3425 error = "slabs_partial inuse accounting error";
2946 if (slabp->inuse && !error) 3426 if (!slabp->inuse && !error)
2947 error = "slabs_free/inuse accounting error"; 3427 error = "slabs_partial/inuse accounting error";
2948 num_slabs++; 3428 active_objs += slabp->inuse;
3429 active_slabs++;
3430 }
3431 list_for_each(q,&l3->slabs_free) {
3432 slabp = list_entry(q, struct slab, list);
3433 if (slabp->inuse && !error)
3434 error = "slabs_free/inuse accounting error";
3435 num_slabs++;
3436 }
3437 free_objects += l3->free_objects;
3438 shared_avail += l3->shared->avail;
3439
3440 spin_unlock(&l3->list_lock);
2949 } 3441 }
2950 num_slabs+=active_slabs; 3442 num_slabs+=active_slabs;
2951 num_objs = num_slabs*cachep->num; 3443 num_objs = num_slabs*cachep->num;
2952 if (num_objs - active_objs != cachep->lists.free_objects && !error) 3444 if (num_objs - active_objs != free_objects && !error)
2953 error = "free_objects accounting error"; 3445 error = "free_objects accounting error";
2954 3446
2955 name = cachep->name; 3447 name = cachep->name;
@@ -2961,9 +3453,9 @@ static int s_show(struct seq_file *m, void *p)
2961 cachep->num, (1<<cachep->gfporder)); 3453 cachep->num, (1<<cachep->gfporder));
2962 seq_printf(m, " : tunables %4u %4u %4u", 3454 seq_printf(m, " : tunables %4u %4u %4u",
2963 cachep->limit, cachep->batchcount, 3455 cachep->limit, cachep->batchcount,
2964 cachep->lists.shared->limit/cachep->batchcount); 3456 cachep->shared);
2965 seq_printf(m, " : slabdata %6lu %6lu %6u", 3457 seq_printf(m, " : slabdata %6lu %6lu %6lu",
2966 active_slabs, num_slabs, cachep->lists.shared->avail); 3458 active_slabs, num_slabs, shared_avail);
2967#if STATS 3459#if STATS
2968 { /* list3 stats */ 3460 { /* list3 stats */
2969 unsigned long high = cachep->high_mark; 3461 unsigned long high = cachep->high_mark;
@@ -2972,12 +3464,13 @@ static int s_show(struct seq_file *m, void *p)
2972 unsigned long reaped = cachep->reaped; 3464 unsigned long reaped = cachep->reaped;
2973 unsigned long errors = cachep->errors; 3465 unsigned long errors = cachep->errors;
2974 unsigned long max_freeable = cachep->max_freeable; 3466 unsigned long max_freeable = cachep->max_freeable;
2975 unsigned long free_limit = cachep->free_limit;
2976 unsigned long node_allocs = cachep->node_allocs; 3467 unsigned long node_allocs = cachep->node_allocs;
3468 unsigned long node_frees = cachep->node_frees;
2977 3469
2978 seq_printf(m, " : globalstat %7lu %6lu %5lu %4lu %4lu %4lu %4lu %4lu", 3470 seq_printf(m, " : globalstat %7lu %6lu %5lu %4lu \
2979 allocs, high, grown, reaped, errors, 3471 %4lu %4lu %4lu %4lu",
2980 max_freeable, free_limit, node_allocs); 3472 allocs, high, grown, reaped, errors,
3473 max_freeable, node_allocs, node_frees);
2981 } 3474 }
2982 /* cpu stats */ 3475 /* cpu stats */
2983 { 3476 {
@@ -3056,9 +3549,10 @@ ssize_t slabinfo_write(struct file *file, const char __user *buffer,
3056 batchcount < 1 || 3549 batchcount < 1 ||
3057 batchcount > limit || 3550 batchcount > limit ||
3058 shared < 0) { 3551 shared < 0) {
3059 res = -EINVAL; 3552 res = 0;
3060 } else { 3553 } else {
3061 res = do_tune_cpucache(cachep, limit, batchcount, shared); 3554 res = do_tune_cpucache(cachep, limit,
3555 batchcount, shared);
3062 } 3556 }
3063 break; 3557 break;
3064 } 3558 }
diff --git a/mm/swap_state.c b/mm/swap_state.c
index 029e56eb5e..adbc2b426c 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -67,8 +67,8 @@ void show_swap_cache_info(void)
67 * __add_to_swap_cache resembles add_to_page_cache on swapper_space, 67 * __add_to_swap_cache resembles add_to_page_cache on swapper_space,
68 * but sets SwapCache flag and private instead of mapping and index. 68 * but sets SwapCache flag and private instead of mapping and index.
69 */ 69 */
70static int __add_to_swap_cache(struct page *page, 70static int __add_to_swap_cache(struct page *page, swp_entry_t entry,
71 swp_entry_t entry, int gfp_mask) 71 unsigned int __nocast gfp_mask)
72{ 72{
73 int error; 73 int error;
74 74
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 4b6e8bf986..0184f510aa 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1153,8 +1153,7 @@ asmlinkage long sys_swapoff(const char __user * specialfile)
1153 p->highest_bit = 0; /* cuts scans short */ 1153 p->highest_bit = 0; /* cuts scans short */
1154 while (p->flags >= SWP_SCANNING) { 1154 while (p->flags >= SWP_SCANNING) {
1155 spin_unlock(&swap_lock); 1155 spin_unlock(&swap_lock);
1156 set_current_state(TASK_UNINTERRUPTIBLE); 1156 schedule_timeout_uninterruptible(1);
1157 schedule_timeout(1);
1158 spin_lock(&swap_lock); 1157 spin_lock(&swap_lock);
1159 } 1158 }
1160 1159
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 67b358e57e..13c3d82968 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -332,9 +332,10 @@ void __vunmap(void *addr, int deallocate_pages)
332 * @addr: memory base address 332 * @addr: memory base address
333 * 333 *
334 * Free the virtually contiguous memory area starting at @addr, as 334 * Free the virtually contiguous memory area starting at @addr, as
335 * obtained from vmalloc(), vmalloc_32() or __vmalloc(). 335 * obtained from vmalloc(), vmalloc_32() or __vmalloc(). If @addr is
336 * NULL, no operation is performed.
336 * 337 *
337 * May not be called in interrupt context. 338 * Must not be called in interrupt context.
338 */ 339 */
339void vfree(void *addr) 340void vfree(void *addr)
340{ 341{
@@ -352,7 +353,7 @@ EXPORT_SYMBOL(vfree);
352 * Free the virtually contiguous memory area starting at @addr, 353 * Free the virtually contiguous memory area starting at @addr,
353 * which was created from the page array passed to vmap(). 354 * which was created from the page array passed to vmap().
354 * 355 *
355 * May not be called in interrupt context. 356 * Must not be called in interrupt context.
356 */ 357 */
357void vunmap(void *addr) 358void vunmap(void *addr)
358{ 359{
diff --git a/net/atm/mpc.c b/net/atm/mpc.c
index 17a81ebe7e..526d953141 100644
--- a/net/atm/mpc.c
+++ b/net/atm/mpc.c
@@ -105,7 +105,7 @@ extern void mpc_proc_clean(void);
105 105
106struct mpoa_client *mpcs = NULL; /* FIXME */ 106struct mpoa_client *mpcs = NULL; /* FIXME */
107static struct atm_mpoa_qos *qos_head = NULL; 107static struct atm_mpoa_qos *qos_head = NULL;
108static struct timer_list mpc_timer = TIMER_INITIALIZER(NULL, 0, 0); 108static DEFINE_TIMER(mpc_timer, NULL, 0, 0);
109 109
110 110
111static struct mpoa_client *find_mpc_by_itfnum(int itf) 111static struct mpoa_client *find_mpc_by_itfnum(int itf)
diff --git a/net/core/dst.c b/net/core/dst.c
index 334790da9f..470c05bc4c 100644
--- a/net/core/dst.c
+++ b/net/core/dst.c
@@ -39,8 +39,7 @@ static unsigned long dst_gc_timer_inc = DST_GC_MAX;
39static void dst_run_gc(unsigned long); 39static void dst_run_gc(unsigned long);
40static void ___dst_free(struct dst_entry * dst); 40static void ___dst_free(struct dst_entry * dst);
41 41
42static struct timer_list dst_gc_timer = 42static DEFINE_TIMER(dst_gc_timer, dst_run_gc, DST_GC_MIN, 0);
43 TIMER_INITIALIZER(dst_run_gc, DST_GC_MIN, 0);
44 43
45static void dst_run_gc(unsigned long dummy) 44static void dst_run_gc(unsigned long dummy)
46{ 45{
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index a1a9a7abff..5265dfd699 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -645,10 +645,10 @@ int netpoll_setup(struct netpoll *np)
645 645
646 npinfo->rx_flags = 0; 646 npinfo->rx_flags = 0;
647 npinfo->rx_np = NULL; 647 npinfo->rx_np = NULL;
648 npinfo->poll_lock = SPIN_LOCK_UNLOCKED; 648 spin_lock_init(&npinfo->poll_lock);
649 npinfo->poll_owner = -1; 649 npinfo->poll_owner = -1;
650 npinfo->tries = MAX_RETRIES; 650 npinfo->tries = MAX_RETRIES;
651 npinfo->rx_lock = SPIN_LOCK_UNLOCKED; 651 spin_lock_init(&npinfo->rx_lock);
652 } else 652 } else
653 npinfo = ndev->npinfo; 653 npinfo = ndev->npinfo;
654 654
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 8eb083b604..b3ad49fa7d 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -503,7 +503,7 @@ static int pg_delay_d = 0;
503static int pg_clone_skb_d = 0; 503static int pg_clone_skb_d = 0;
504static int debug = 0; 504static int debug = 0;
505 505
506static spinlock_t _thread_lock = SPIN_LOCK_UNLOCKED; 506static DEFINE_SPINLOCK(_thread_lock);
507static struct pktgen_thread *pktgen_threads = NULL; 507static struct pktgen_thread *pktgen_threads = NULL;
508 508
509static char module_fname[128]; 509static char module_fname[128];
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c
index 7bf3b3a91e..e05f4f955e 100644
--- a/net/dccp/ccids/ccid3.c
+++ b/net/dccp/ccids/ccid3.c
@@ -43,12 +43,22 @@
43#include "ccid3.h" 43#include "ccid3.h"
44 44
45/* 45/*
46 * Reason for maths with 10 here is to avoid 32 bit overflow when a is big. 46 * Reason for maths here is to avoid 32 bit overflow when a is big.
47 * With this we get close to the limit.
47 */ 48 */
48static inline u32 usecs_div(const u32 a, const u32 b) 49static inline u32 usecs_div(const u32 a, const u32 b)
49{ 50{
50 const u32 tmp = a * (USEC_PER_SEC / 10); 51 const u32 div = a < (UINT_MAX / (USEC_PER_SEC / 10)) ? 10 :
51 return b > 20 ? tmp / (b / 10) : tmp; 52 a < (UINT_MAX / (USEC_PER_SEC / 50)) ? 50 :
53 a < (UINT_MAX / (USEC_PER_SEC / 100)) ? 100 :
54 a < (UINT_MAX / (USEC_PER_SEC / 500)) ? 500 :
55 a < (UINT_MAX / (USEC_PER_SEC / 1000)) ? 1000 :
56 a < (UINT_MAX / (USEC_PER_SEC / 5000)) ? 5000 :
57 a < (UINT_MAX / (USEC_PER_SEC / 10000)) ? 10000 :
58 a < (UINT_MAX / (USEC_PER_SEC / 50000)) ? 50000 :
59 100000;
60 const u32 tmp = a * (USEC_PER_SEC / div);
61 return (b >= 2 * div) ? tmp / (b / div) : tmp;
52} 62}
53 63
54static int ccid3_debug; 64static int ccid3_debug;
@@ -68,13 +78,11 @@ static struct dccp_li_hist *ccid3_li_hist;
68 78
69static int ccid3_init(struct sock *sk) 79static int ccid3_init(struct sock *sk)
70{ 80{
71 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
72 return 0; 81 return 0;
73} 82}
74 83
75static void ccid3_exit(struct sock *sk) 84static void ccid3_exit(struct sock *sk)
76{ 85{
77 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
78} 86}
79 87
80/* TFRC sender states */ 88/* TFRC sender states */
@@ -102,8 +110,7 @@ static const char *ccid3_tx_state_name(enum ccid3_hc_tx_states state)
102static inline void ccid3_hc_tx_set_state(struct sock *sk, 110static inline void ccid3_hc_tx_set_state(struct sock *sk,
103 enum ccid3_hc_tx_states state) 111 enum ccid3_hc_tx_states state)
104{ 112{
105 struct dccp_sock *dp = dccp_sk(sk); 113 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
106 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
107 enum ccid3_hc_tx_states oldstate = hctx->ccid3hctx_state; 114 enum ccid3_hc_tx_states oldstate = hctx->ccid3hctx_state;
108 115
109 ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", 116 ccid3_pr_debug("%s(%p) %-8.8s -> %s\n",
@@ -144,8 +151,7 @@ static inline void ccid3_calc_new_delta(struct ccid3_hc_tx_sock *hctx)
144 */ 151 */
145static void ccid3_hc_tx_update_x(struct sock *sk) 152static void ccid3_hc_tx_update_x(struct sock *sk)
146{ 153{
147 struct dccp_sock *dp = dccp_sk(sk); 154 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
148 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
149 155
150 /* To avoid large error in calcX */ 156 /* To avoid large error in calcX */
151 if (hctx->ccid3hctx_p >= TFRC_SMALLEST_P) { 157 if (hctx->ccid3hctx_p >= TFRC_SMALLEST_P) {
@@ -159,7 +165,7 @@ static void ccid3_hc_tx_update_x(struct sock *sk)
159 } else { 165 } else {
160 struct timeval now; 166 struct timeval now;
161 167
162 do_gettimeofday(&now); 168 dccp_timestamp(sk, &now);
163 if (timeval_delta(&now, &hctx->ccid3hctx_t_ld) >= 169 if (timeval_delta(&now, &hctx->ccid3hctx_t_ld) >=
164 hctx->ccid3hctx_rtt) { 170 hctx->ccid3hctx_rtt) {
165 hctx->ccid3hctx_x = max_t(u32, min_t(u32, hctx->ccid3hctx_x_recv, 171 hctx->ccid3hctx_x = max_t(u32, min_t(u32, hctx->ccid3hctx_x_recv,
@@ -174,9 +180,8 @@ static void ccid3_hc_tx_update_x(struct sock *sk)
174static void ccid3_hc_tx_no_feedback_timer(unsigned long data) 180static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
175{ 181{
176 struct sock *sk = (struct sock *)data; 182 struct sock *sk = (struct sock *)data;
177 struct dccp_sock *dp = dccp_sk(sk);
178 unsigned long next_tmout = 0; 183 unsigned long next_tmout = 0;
179 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; 184 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
180 185
181 bh_lock_sock(sk); 186 bh_lock_sock(sk);
182 if (sock_owned_by_user(sk)) { 187 if (sock_owned_by_user(sk)) {
@@ -274,20 +279,20 @@ static int ccid3_hc_tx_send_packet(struct sock *sk,
274 struct sk_buff *skb, int len) 279 struct sk_buff *skb, int len)
275{ 280{
276 struct dccp_sock *dp = dccp_sk(sk); 281 struct dccp_sock *dp = dccp_sk(sk);
277 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; 282 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
278 struct dccp_tx_hist_entry *new_packet; 283 struct dccp_tx_hist_entry *new_packet;
279 struct timeval now; 284 struct timeval now;
280 long delay; 285 long delay;
281 int rc = -ENOTCONN; 286 int rc = -ENOTCONN;
282 287
283 /* Check if pure ACK or Terminating*/ 288 BUG_ON(hctx == NULL || hctx->ccid3hctx_state == TFRC_SSTATE_TERM);
284 289
290 /* Check if pure ACK or Terminating*/
285 /* 291 /*
286 * XXX: We only call this function for DATA and DATAACK, on, these 292 * XXX: We only call this function for DATA and DATAACK, on, these
287 * packets can have zero length, but why the comment about "pure ACK"? 293 * packets can have zero length, but why the comment about "pure ACK"?
288 */ 294 */
289 if (hctx == NULL || len == 0 || 295 if (unlikely(len == 0))
290 hctx->ccid3hctx_state == TFRC_SSTATE_TERM)
291 goto out; 296 goto out;
292 297
293 /* See if last packet allocated was not sent */ 298 /* See if last packet allocated was not sent */
@@ -297,23 +302,20 @@ static int ccid3_hc_tx_send_packet(struct sock *sk,
297 SLAB_ATOMIC); 302 SLAB_ATOMIC);
298 303
299 rc = -ENOBUFS; 304 rc = -ENOBUFS;
300 if (new_packet == NULL) { 305 if (unlikely(new_packet == NULL)) {
301 ccid3_pr_debug("%s, sk=%p, not enough mem to add " 306 LIMIT_NETDEBUG(KERN_WARNING "%s: %s, sk=%p, not enough "
302 "to history, send refused\n", 307 "mem to add to history, send refused\n",
303 dccp_role(sk), sk); 308 __FUNCTION__, dccp_role(sk), sk);
304 goto out; 309 goto out;
305 } 310 }
306 311
307 dccp_tx_hist_add_entry(&hctx->ccid3hctx_hist, new_packet); 312 dccp_tx_hist_add_entry(&hctx->ccid3hctx_hist, new_packet);
308 } 313 }
309 314
310 do_gettimeofday(&now); 315 dccp_timestamp(sk, &now);
311 316
312 switch (hctx->ccid3hctx_state) { 317 switch (hctx->ccid3hctx_state) {
313 case TFRC_SSTATE_NO_SENT: 318 case TFRC_SSTATE_NO_SENT:
314 ccid3_pr_debug("%s, sk=%p, first packet(%llu)\n",
315 dccp_role(sk), sk, dp->dccps_gss);
316
317 hctx->ccid3hctx_no_feedback_timer.function = ccid3_hc_tx_no_feedback_timer; 319 hctx->ccid3hctx_no_feedback_timer.function = ccid3_hc_tx_no_feedback_timer;
318 hctx->ccid3hctx_no_feedback_timer.data = (unsigned long)sk; 320 hctx->ccid3hctx_no_feedback_timer.data = (unsigned long)sk;
319 sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, 321 sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer,
@@ -321,7 +323,7 @@ static int ccid3_hc_tx_send_packet(struct sock *sk,
321 hctx->ccid3hctx_last_win_count = 0; 323 hctx->ccid3hctx_last_win_count = 0;
322 hctx->ccid3hctx_t_last_win_count = now; 324 hctx->ccid3hctx_t_last_win_count = now;
323 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK); 325 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK);
324 hctx->ccid3hctx_t_ipi = TFRC_INITIAL_TIMEOUT; 326 hctx->ccid3hctx_t_ipi = TFRC_INITIAL_IPI;
325 327
326 /* Set nominal send time for initial packet */ 328 /* Set nominal send time for initial packet */
327 hctx->ccid3hctx_t_nom = now; 329 hctx->ccid3hctx_t_nom = now;
@@ -334,7 +336,6 @@ static int ccid3_hc_tx_send_packet(struct sock *sk,
334 case TFRC_SSTATE_FBACK: 336 case TFRC_SSTATE_FBACK:
335 delay = (timeval_delta(&now, &hctx->ccid3hctx_t_nom) - 337 delay = (timeval_delta(&now, &hctx->ccid3hctx_t_nom) -
336 hctx->ccid3hctx_delta); 338 hctx->ccid3hctx_delta);
337 ccid3_pr_debug("send_packet delay=%ld\n", delay);
338 delay /= -1000; 339 delay /= -1000;
339 /* divide by -1000 is to convert to ms and get sign right */ 340 /* divide by -1000 is to convert to ms and get sign right */
340 rc = delay > 0 ? delay : 0; 341 rc = delay > 0 ? delay : 0;
@@ -348,29 +349,25 @@ static int ccid3_hc_tx_send_packet(struct sock *sk,
348 } 349 }
349 350
350 /* Can we send? if so add options and add to packet history */ 351 /* Can we send? if so add options and add to packet history */
351 if (rc == 0) 352 if (rc == 0) {
353 dp->dccps_hc_tx_insert_options = 1;
352 new_packet->dccphtx_ccval = 354 new_packet->dccphtx_ccval =
353 DCCP_SKB_CB(skb)->dccpd_ccval = 355 DCCP_SKB_CB(skb)->dccpd_ccval =
354 hctx->ccid3hctx_last_win_count; 356 hctx->ccid3hctx_last_win_count;
357 }
355out: 358out:
356 return rc; 359 return rc;
357} 360}
358 361
359static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len) 362static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len)
360{ 363{
361 struct dccp_sock *dp = dccp_sk(sk); 364 const struct dccp_sock *dp = dccp_sk(sk);
362 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; 365 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
363 struct timeval now; 366 struct timeval now;
364 367
365 BUG_ON(hctx == NULL); 368 BUG_ON(hctx == NULL || hctx->ccid3hctx_state == TFRC_SSTATE_TERM);
366
367 if (hctx->ccid3hctx_state == TFRC_SSTATE_TERM) {
368 ccid3_pr_debug("%s, sk=%p, while state is TFRC_SSTATE_TERM!\n",
369 dccp_role(sk), sk);
370 return;
371 }
372 369
373 do_gettimeofday(&now); 370 dccp_timestamp(sk, &now);
374 371
375 /* check if we have sent a data packet */ 372 /* check if we have sent a data packet */
376 if (len > 0) { 373 if (len > 0) {
@@ -378,14 +375,14 @@ static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len)
378 struct dccp_tx_hist_entry *packet; 375 struct dccp_tx_hist_entry *packet;
379 376
380 packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist); 377 packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist);
381 if (packet == NULL) { 378 if (unlikely(packet == NULL)) {
382 printk(KERN_CRIT "%s: packet doesn't exists in " 379 LIMIT_NETDEBUG(KERN_WARNING "%s: packet doesn't "
383 "history!\n", __FUNCTION__); 380 "exists in history!\n", __FUNCTION__);
384 return; 381 return;
385 } 382 }
386 if (packet->dccphtx_sent) { 383 if (unlikely(packet->dccphtx_sent)) {
387 printk(KERN_CRIT "%s: no unsent packet in history!\n", 384 LIMIT_NETDEBUG(KERN_WARNING "%s: no unsent packet in "
388 __FUNCTION__); 385 "history!\n", __FUNCTION__);
389 return; 386 return;
390 } 387 }
391 packet->dccphtx_tstamp = now; 388 packet->dccphtx_tstamp = now;
@@ -445,24 +442,18 @@ static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len)
445 442
446static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) 443static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
447{ 444{
448 struct dccp_sock *dp = dccp_sk(sk); 445 const struct dccp_sock *dp = dccp_sk(sk);
449 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; 446 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
450 struct ccid3_options_received *opt_recv; 447 struct ccid3_options_received *opt_recv;
451 struct dccp_tx_hist_entry *packet; 448 struct dccp_tx_hist_entry *packet;
449 struct timeval now;
452 unsigned long next_tmout; 450 unsigned long next_tmout;
453 u32 t_elapsed; 451 u32 t_elapsed;
454 u32 pinv; 452 u32 pinv;
455 u32 x_recv; 453 u32 x_recv;
456 u32 r_sample; 454 u32 r_sample;
457 455
458 if (hctx == NULL) 456 BUG_ON(hctx == NULL || hctx->ccid3hctx_state == TFRC_SSTATE_TERM);
459 return;
460
461 if (hctx->ccid3hctx_state == TFRC_SSTATE_TERM) {
462 ccid3_pr_debug("%s, sk=%p, received a packet when "
463 "terminating!\n", dccp_role(sk), sk);
464 return;
465 }
466 457
467 /* we are only interested in ACKs */ 458 /* we are only interested in ACKs */
468 if (!(DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK || 459 if (!(DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK ||
@@ -471,7 +462,7 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
471 462
472 opt_recv = &hctx->ccid3hctx_options_received; 463 opt_recv = &hctx->ccid3hctx_options_received;
473 464
474 t_elapsed = dp->dccps_options_received.dccpor_elapsed_time; 465 t_elapsed = dp->dccps_options_received.dccpor_elapsed_time * 10;
475 x_recv = opt_recv->ccid3or_receive_rate; 466 x_recv = opt_recv->ccid3or_receive_rate;
476 pinv = opt_recv->ccid3or_loss_event_rate; 467 pinv = opt_recv->ccid3or_loss_event_rate;
477 468
@@ -486,19 +477,24 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
486 /* get t_recvdata from history */ 477 /* get t_recvdata from history */
487 packet = dccp_tx_hist_find_entry(&hctx->ccid3hctx_hist, 478 packet = dccp_tx_hist_find_entry(&hctx->ccid3hctx_hist,
488 DCCP_SKB_CB(skb)->dccpd_ack_seq); 479 DCCP_SKB_CB(skb)->dccpd_ack_seq);
489 if (packet == NULL) { 480 if (unlikely(packet == NULL)) {
490 ccid3_pr_debug("%s, sk=%p, seqno %llu(%s) does't " 481 LIMIT_NETDEBUG(KERN_WARNING "%s: %s, sk=%p, seqno "
491 "exist in history!\n", 482 "%llu(%s) does't exist in history!\n",
492 dccp_role(sk), sk, 483 __FUNCTION__, dccp_role(sk), sk,
493 DCCP_SKB_CB(skb)->dccpd_ack_seq, 484 (unsigned long long)DCCP_SKB_CB(skb)->dccpd_ack_seq,
494 dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type)); 485 dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type));
495 return; 486 return;
496 } 487 }
497 488
498 /* Update RTT */ 489 /* Update RTT */
499 r_sample = timeval_now_delta(&packet->dccphtx_tstamp); 490 dccp_timestamp(sk, &now);
500 /* FIXME: */ 491 r_sample = timeval_delta(&now, &packet->dccphtx_tstamp);
501 // r_sample -= usecs_to_jiffies(t_elapsed * 10); 492 if (unlikely(r_sample <= t_elapsed))
493 LIMIT_NETDEBUG(KERN_WARNING "%s: r_sample=%uus, "
494 "t_elapsed=%uus\n",
495 __FUNCTION__, r_sample, t_elapsed);
496 else
497 r_sample -= t_elapsed;
502 498
503 /* Update RTT estimate by 499 /* Update RTT estimate by
504 * If (No feedback recv) 500 * If (No feedback recv)
@@ -591,11 +587,11 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
591 587
592static void ccid3_hc_tx_insert_options(struct sock *sk, struct sk_buff *skb) 588static void ccid3_hc_tx_insert_options(struct sock *sk, struct sk_buff *skb)
593{ 589{
594 const struct dccp_sock *dp = dccp_sk(sk); 590 const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
595 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; 591
592 BUG_ON(hctx == NULL);
596 593
597 if (hctx == NULL || !(sk->sk_state == DCCP_OPEN || 594 if (!(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN))
598 sk->sk_state == DCCP_PARTOPEN))
599 return; 595 return;
600 596
601 DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count; 597 DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count;
@@ -606,12 +602,11 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
606 unsigned char *value) 602 unsigned char *value)
607{ 603{
608 int rc = 0; 604 int rc = 0;
609 struct dccp_sock *dp = dccp_sk(sk); 605 const struct dccp_sock *dp = dccp_sk(sk);
610 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; 606 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
611 struct ccid3_options_received *opt_recv; 607 struct ccid3_options_received *opt_recv;
612 608
613 if (hctx == NULL) 609 BUG_ON(hctx == NULL);
614 return 0;
615 610
616 opt_recv = &hctx->ccid3hctx_options_received; 611 opt_recv = &hctx->ccid3hctx_options_received;
617 612
@@ -625,10 +620,10 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
625 620
626 switch (option) { 621 switch (option) {
627 case TFRC_OPT_LOSS_EVENT_RATE: 622 case TFRC_OPT_LOSS_EVENT_RATE:
628 if (len != 4) { 623 if (unlikely(len != 4)) {
629 ccid3_pr_debug("%s, sk=%p, invalid len for " 624 LIMIT_NETDEBUG(KERN_WARNING "%s: %s, sk=%p, invalid "
630 "TFRC_OPT_LOSS_EVENT_RATE\n", 625 "len for TFRC_OPT_LOSS_EVENT_RATE\n",
631 dccp_role(sk), sk); 626 __FUNCTION__, dccp_role(sk), sk);
632 rc = -EINVAL; 627 rc = -EINVAL;
633 } else { 628 } else {
634 opt_recv->ccid3or_loss_event_rate = ntohl(*(u32 *)value); 629 opt_recv->ccid3or_loss_event_rate = ntohl(*(u32 *)value);
@@ -646,10 +641,10 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
646 opt_recv->ccid3or_loss_intervals_len); 641 opt_recv->ccid3or_loss_intervals_len);
647 break; 642 break;
648 case TFRC_OPT_RECEIVE_RATE: 643 case TFRC_OPT_RECEIVE_RATE:
649 if (len != 4) { 644 if (unlikely(len != 4)) {
650 ccid3_pr_debug("%s, sk=%p, invalid len for " 645 LIMIT_NETDEBUG(KERN_WARNING "%s: %s, sk=%p, invalid "
651 "TFRC_OPT_RECEIVE_RATE\n", 646 "len for TFRC_OPT_RECEIVE_RATE\n",
652 dccp_role(sk), sk); 647 __FUNCTION__, dccp_role(sk), sk);
653 rc = -EINVAL; 648 rc = -EINVAL;
654 } else { 649 } else {
655 opt_recv->ccid3or_receive_rate = ntohl(*(u32 *)value); 650 opt_recv->ccid3or_receive_rate = ntohl(*(u32 *)value);
@@ -668,13 +663,11 @@ static int ccid3_hc_tx_init(struct sock *sk)
668 struct dccp_sock *dp = dccp_sk(sk); 663 struct dccp_sock *dp = dccp_sk(sk);
669 struct ccid3_hc_tx_sock *hctx; 664 struct ccid3_hc_tx_sock *hctx;
670 665
671 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); 666 dp->dccps_hc_tx_ccid_private = kmalloc(sizeof(*hctx), gfp_any());
672 667 if (dp->dccps_hc_tx_ccid_private == NULL)
673 hctx = dp->dccps_hc_tx_ccid_private = kmalloc(sizeof(*hctx),
674 gfp_any());
675 if (hctx == NULL)
676 return -ENOMEM; 668 return -ENOMEM;
677 669
670 hctx = ccid3_hc_tx_sk(sk);
678 memset(hctx, 0, sizeof(*hctx)); 671 memset(hctx, 0, sizeof(*hctx));
679 672
680 if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE && 673 if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE &&
@@ -696,9 +689,8 @@ static int ccid3_hc_tx_init(struct sock *sk)
696static void ccid3_hc_tx_exit(struct sock *sk) 689static void ccid3_hc_tx_exit(struct sock *sk)
697{ 690{
698 struct dccp_sock *dp = dccp_sk(sk); 691 struct dccp_sock *dp = dccp_sk(sk);
699 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; 692 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
700 693
701 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
702 BUG_ON(hctx == NULL); 694 BUG_ON(hctx == NULL);
703 695
704 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_TERM); 696 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_TERM);
@@ -738,8 +730,7 @@ static const char *ccid3_rx_state_name(enum ccid3_hc_rx_states state)
738static inline void ccid3_hc_rx_set_state(struct sock *sk, 730static inline void ccid3_hc_rx_set_state(struct sock *sk,
739 enum ccid3_hc_rx_states state) 731 enum ccid3_hc_rx_states state)
740{ 732{
741 struct dccp_sock *dp = dccp_sk(sk); 733 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
742 struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
743 enum ccid3_hc_rx_states oldstate = hcrx->ccid3hcrx_state; 734 enum ccid3_hc_rx_states oldstate = hcrx->ccid3hcrx_state;
744 735
745 ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", 736 ccid3_pr_debug("%s(%p) %-8.8s -> %s\n",
@@ -751,14 +742,14 @@ static inline void ccid3_hc_rx_set_state(struct sock *sk,
751 742
752static void ccid3_hc_rx_send_feedback(struct sock *sk) 743static void ccid3_hc_rx_send_feedback(struct sock *sk)
753{ 744{
745 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
754 struct dccp_sock *dp = dccp_sk(sk); 746 struct dccp_sock *dp = dccp_sk(sk);
755 struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
756 struct dccp_rx_hist_entry *packet; 747 struct dccp_rx_hist_entry *packet;
757 struct timeval now; 748 struct timeval now;
758 749
759 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); 750 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
760 751
761 do_gettimeofday(&now); 752 dccp_timestamp(sk, &now);
762 753
763 switch (hcrx->ccid3hcrx_state) { 754 switch (hcrx->ccid3hcrx_state) {
764 case TFRC_RSTATE_NO_DATA: 755 case TFRC_RSTATE_NO_DATA:
@@ -767,11 +758,8 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk)
767 case TFRC_RSTATE_DATA: { 758 case TFRC_RSTATE_DATA: {
768 const u32 delta = timeval_delta(&now, 759 const u32 delta = timeval_delta(&now,
769 &hcrx->ccid3hcrx_tstamp_last_feedback); 760 &hcrx->ccid3hcrx_tstamp_last_feedback);
770 761 hcrx->ccid3hcrx_x_recv = usecs_div(hcrx->ccid3hcrx_bytes_recv,
771 hcrx->ccid3hcrx_x_recv = (hcrx->ccid3hcrx_bytes_recv * 762 delta);
772 USEC_PER_SEC);
773 if (likely(delta > 1))
774 hcrx->ccid3hcrx_x_recv /= delta;
775 } 763 }
776 break; 764 break;
777 default: 765 default:
@@ -782,10 +770,10 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk)
782 } 770 }
783 771
784 packet = dccp_rx_hist_find_data_packet(&hcrx->ccid3hcrx_hist); 772 packet = dccp_rx_hist_find_data_packet(&hcrx->ccid3hcrx_hist);
785 if (packet == NULL) { 773 if (unlikely(packet == NULL)) {
786 printk(KERN_CRIT "%s: %s, sk=%p, no data packet in history!\n", 774 LIMIT_NETDEBUG(KERN_WARNING "%s: %s, sk=%p, no data packet "
787 __FUNCTION__, dccp_role(sk), sk); 775 "in history!\n",
788 dump_stack(); 776 __FUNCTION__, dccp_role(sk), sk);
789 return; 777 return;
790 } 778 }
791 779
@@ -801,17 +789,18 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk)
801 hcrx->ccid3hcrx_pinv = ~0; 789 hcrx->ccid3hcrx_pinv = ~0;
802 else 790 else
803 hcrx->ccid3hcrx_pinv = 1000000 / hcrx->ccid3hcrx_p; 791 hcrx->ccid3hcrx_pinv = 1000000 / hcrx->ccid3hcrx_p;
792 dp->dccps_hc_rx_insert_options = 1;
804 dccp_send_ack(sk); 793 dccp_send_ack(sk);
805} 794}
806 795
807static void ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb) 796static void ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)
808{ 797{
809 const struct dccp_sock *dp = dccp_sk(sk); 798 const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
810 u32 x_recv, pinv; 799 u32 x_recv, pinv;
811 struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
812 800
813 if (hcrx == NULL || !(sk->sk_state == DCCP_OPEN || 801 BUG_ON(hcrx == NULL);
814 sk->sk_state == DCCP_PARTOPEN)) 802
803 if (!(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN))
815 return; 804 return;
816 805
817 DCCP_SKB_CB(skb)->dccpd_ccval = hcrx->ccid3hcrx_last_counter; 806 DCCP_SKB_CB(skb)->dccpd_ccval = hcrx->ccid3hcrx_last_counter;
@@ -837,8 +826,7 @@ static void ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)
837 826
838static u32 ccid3_hc_rx_calc_first_li(struct sock *sk) 827static u32 ccid3_hc_rx_calc_first_li(struct sock *sk)
839{ 828{
840 struct dccp_sock *dp = dccp_sk(sk); 829 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
841 struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
842 struct dccp_rx_hist_entry *entry, *next, *tail = NULL; 830 struct dccp_rx_hist_entry *entry, *next, *tail = NULL;
843 u32 rtt, delta, x_recv, fval, p, tmp2; 831 u32 rtt, delta, x_recv, fval, p, tmp2;
844 struct timeval tstamp = { 0, }; 832 struct timeval tstamp = { 0, };
@@ -869,17 +857,17 @@ static u32 ccid3_hc_rx_calc_first_li(struct sock *sk)
869 } 857 }
870 } 858 }
871 859
872 if (step == 0) { 860 if (unlikely(step == 0)) {
873 printk(KERN_CRIT "%s: %s, sk=%p, packet history contains no " 861 LIMIT_NETDEBUG(KERN_WARNING "%s: %s, sk=%p, packet history "
874 "data packets!\n", 862 "contains no data packets!\n",
875 __FUNCTION__, dccp_role(sk), sk); 863 __FUNCTION__, dccp_role(sk), sk);
876 return ~0; 864 return ~0;
877 } 865 }
878 866
879 if (interval == 0) { 867 if (unlikely(interval == 0)) {
880 ccid3_pr_debug("%s, sk=%p, Could not find a win_count " 868 LIMIT_NETDEBUG(KERN_WARNING "%s: %s, sk=%p, Could not find a "
881 "interval > 0. Defaulting to 1\n", 869 "win_count interval > 0. Defaulting to 1\n",
882 dccp_role(sk), sk); 870 __FUNCTION__, dccp_role(sk), sk);
883 interval = 1; 871 interval = 1;
884 } 872 }
885found: 873found:
@@ -889,10 +877,9 @@ found:
889 if (rtt == 0) 877 if (rtt == 0)
890 rtt = 1; 878 rtt = 1;
891 879
892 delta = timeval_now_delta(&hcrx->ccid3hcrx_tstamp_last_feedback); 880 dccp_timestamp(sk, &tstamp);
893 x_recv = hcrx->ccid3hcrx_bytes_recv * USEC_PER_SEC; 881 delta = timeval_delta(&tstamp, &hcrx->ccid3hcrx_tstamp_last_feedback);
894 if (likely(delta > 1)) 882 x_recv = usecs_div(hcrx->ccid3hcrx_bytes_recv, delta);
895 x_recv /= delta;
896 883
897 tmp1 = (u64)x_recv * (u64)rtt; 884 tmp1 = (u64)x_recv * (u64)rtt;
898 do_div(tmp1,10000000); 885 do_div(tmp1,10000000);
@@ -911,8 +898,7 @@ found:
911 898
912static void ccid3_hc_rx_update_li(struct sock *sk, u64 seq_loss, u8 win_loss) 899static void ccid3_hc_rx_update_li(struct sock *sk, u64 seq_loss, u8 win_loss)
913{ 900{
914 struct dccp_sock *dp = dccp_sk(sk); 901 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
915 struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
916 902
917 if (seq_loss != DCCP_MAX_SEQNO + 1 && 903 if (seq_loss != DCCP_MAX_SEQNO + 1 &&
918 list_empty(&hcrx->ccid3hcrx_li_hist)) { 904 list_empty(&hcrx->ccid3hcrx_li_hist)) {
@@ -924,14 +910,14 @@ static void ccid3_hc_rx_update_li(struct sock *sk, u64 seq_loss, u8 win_loss)
924 if (li_tail == NULL) 910 if (li_tail == NULL)
925 return; 911 return;
926 li_tail->dccplih_interval = ccid3_hc_rx_calc_first_li(sk); 912 li_tail->dccplih_interval = ccid3_hc_rx_calc_first_li(sk);
927 } 913 } else
928 /* FIXME: find end of interval */ 914 LIMIT_NETDEBUG(KERN_WARNING "%s: FIXME: find end of "
915 "interval\n", __FUNCTION__);
929} 916}
930 917
931static void ccid3_hc_rx_detect_loss(struct sock *sk) 918static void ccid3_hc_rx_detect_loss(struct sock *sk)
932{ 919{
933 struct dccp_sock *dp = dccp_sk(sk); 920 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
934 struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
935 u8 win_loss; 921 u8 win_loss;
936 const u64 seq_loss = dccp_rx_hist_detect_loss(&hcrx->ccid3hcrx_hist, 922 const u64 seq_loss = dccp_rx_hist_detect_loss(&hcrx->ccid3hcrx_hist,
937 &hcrx->ccid3hcrx_li_hist, 923 &hcrx->ccid3hcrx_li_hist,
@@ -942,22 +928,19 @@ static void ccid3_hc_rx_detect_loss(struct sock *sk)
942 928
943static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) 929static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
944{ 930{
945 struct dccp_sock *dp = dccp_sk(sk); 931 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
946 struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
947 const struct dccp_options_received *opt_recv; 932 const struct dccp_options_received *opt_recv;
948 struct dccp_rx_hist_entry *packet; 933 struct dccp_rx_hist_entry *packet;
949 struct timeval now; 934 struct timeval now;
950 u8 win_count; 935 u8 win_count;
951 u32 p_prev; 936 u32 p_prev, r_sample, t_elapsed;
952 int ins; 937 int ins;
953 938
954 if (hcrx == NULL) 939 BUG_ON(hcrx == NULL ||
955 return; 940 !(hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA ||
956
957 BUG_ON(!(hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA ||
958 hcrx->ccid3hcrx_state == TFRC_RSTATE_DATA)); 941 hcrx->ccid3hcrx_state == TFRC_RSTATE_DATA));
959 942
960 opt_recv = &dp->dccps_options_received; 943 opt_recv = &dccp_sk(sk)->dccps_options_received;
961 944
962 switch (DCCP_SKB_CB(skb)->dccpd_type) { 945 switch (DCCP_SKB_CB(skb)->dccpd_type) {
963 case DCCP_PKT_ACK: 946 case DCCP_PKT_ACK:
@@ -967,10 +950,24 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
967 if (opt_recv->dccpor_timestamp_echo == 0) 950 if (opt_recv->dccpor_timestamp_echo == 0)
968 break; 951 break;
969 p_prev = hcrx->ccid3hcrx_rtt; 952 p_prev = hcrx->ccid3hcrx_rtt;
970 do_gettimeofday(&now); 953 dccp_timestamp(sk, &now);
971 hcrx->ccid3hcrx_rtt = timeval_usecs(&now) - 954 timeval_sub_usecs(&now, opt_recv->dccpor_timestamp_echo * 10);
972 (opt_recv->dccpor_timestamp_echo - 955 r_sample = timeval_usecs(&now);
973 opt_recv->dccpor_elapsed_time) * 10; 956 t_elapsed = opt_recv->dccpor_elapsed_time * 10;
957
958 if (unlikely(r_sample <= t_elapsed))
959 LIMIT_NETDEBUG(KERN_WARNING "%s: r_sample=%uus, "
960 "t_elapsed=%uus\n",
961 __FUNCTION__, r_sample, t_elapsed);
962 else
963 r_sample -= t_elapsed;
964
965 if (hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA)
966 hcrx->ccid3hcrx_rtt = r_sample;
967 else
968 hcrx->ccid3hcrx_rtt = (hcrx->ccid3hcrx_rtt * 9) / 10 +
969 r_sample / 10;
970
974 if (p_prev != hcrx->ccid3hcrx_rtt) 971 if (p_prev != hcrx->ccid3hcrx_rtt)
975 ccid3_pr_debug("%s, New RTT=%luus, elapsed time=%u\n", 972 ccid3_pr_debug("%s, New RTT=%luus, elapsed time=%u\n",
976 dccp_role(sk), hcrx->ccid3hcrx_rtt, 973 dccp_role(sk), hcrx->ccid3hcrx_rtt,
@@ -978,19 +975,16 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
978 break; 975 break;
979 case DCCP_PKT_DATA: 976 case DCCP_PKT_DATA:
980 break; 977 break;
981 default: 978 default: /* We're not interested in other packet types, move along */
982 ccid3_pr_debug("%s, sk=%p, not DATA/DATAACK/ACK packet(%s)\n",
983 dccp_role(sk), sk,
984 dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type));
985 return; 979 return;
986 } 980 }
987 981
988 packet = dccp_rx_hist_entry_new(ccid3_rx_hist, opt_recv->dccpor_ndp, 982 packet = dccp_rx_hist_entry_new(ccid3_rx_hist, sk, opt_recv->dccpor_ndp,
989 skb, SLAB_ATOMIC); 983 skb, SLAB_ATOMIC);
990 if (packet == NULL) { 984 if (unlikely(packet == NULL)) {
991 ccid3_pr_debug("%s, sk=%p, Not enough mem to add rx packet " 985 LIMIT_NETDEBUG(KERN_WARNING "%s: %s, sk=%p, Not enough mem to "
992 "to history (consider it lost)!", 986 "add rx packet to history, consider it lost!\n",
993 dccp_role(sk), sk); 987 __FUNCTION__, dccp_role(sk), sk);
994 return; 988 return;
995 } 989 }
996 990
@@ -1017,7 +1011,7 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
1017 if (ins != 0) 1011 if (ins != 0)
1018 break; 1012 break;
1019 1013
1020 do_gettimeofday(&now); 1014 dccp_timestamp(sk, &now);
1021 if (timeval_delta(&now, &hcrx->ccid3hcrx_tstamp_last_ack) >= 1015 if (timeval_delta(&now, &hcrx->ccid3hcrx_tstamp_last_ack) >=
1022 hcrx->ccid3hcrx_rtt) { 1016 hcrx->ccid3hcrx_rtt) {
1023 hcrx->ccid3hcrx_tstamp_last_ack = now; 1017 hcrx->ccid3hcrx_tstamp_last_ack = now;
@@ -1056,11 +1050,11 @@ static int ccid3_hc_rx_init(struct sock *sk)
1056 1050
1057 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); 1051 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
1058 1052
1059 hcrx = dp->dccps_hc_rx_ccid_private = kmalloc(sizeof(*hcrx), 1053 dp->dccps_hc_rx_ccid_private = kmalloc(sizeof(*hcrx), gfp_any());
1060 gfp_any()); 1054 if (dp->dccps_hc_rx_ccid_private == NULL)
1061 if (hcrx == NULL)
1062 return -ENOMEM; 1055 return -ENOMEM;
1063 1056
1057 hcrx = ccid3_hc_rx_sk(sk);
1064 memset(hcrx, 0, sizeof(*hcrx)); 1058 memset(hcrx, 0, sizeof(*hcrx));
1065 1059
1066 if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE && 1060 if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE &&
@@ -1072,23 +1066,18 @@ static int ccid3_hc_rx_init(struct sock *sk)
1072 hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA; 1066 hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA;
1073 INIT_LIST_HEAD(&hcrx->ccid3hcrx_hist); 1067 INIT_LIST_HEAD(&hcrx->ccid3hcrx_hist);
1074 INIT_LIST_HEAD(&hcrx->ccid3hcrx_li_hist); 1068 INIT_LIST_HEAD(&hcrx->ccid3hcrx_li_hist);
1075 /* 1069 dccp_timestamp(sk, &hcrx->ccid3hcrx_tstamp_last_ack);
1076 * XXX this seems to be paranoid, need to think more about this, for 1070 hcrx->ccid3hcrx_tstamp_last_feedback = hcrx->ccid3hcrx_tstamp_last_ack;
1077 * now start with something different than zero. -acme 1071 hcrx->ccid3hcrx_rtt = 5000; /* XXX 5ms for now... */
1078 */
1079 hcrx->ccid3hcrx_rtt = USEC_PER_SEC / 5;
1080 return 0; 1072 return 0;
1081} 1073}
1082 1074
1083static void ccid3_hc_rx_exit(struct sock *sk) 1075static void ccid3_hc_rx_exit(struct sock *sk)
1084{ 1076{
1077 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
1085 struct dccp_sock *dp = dccp_sk(sk); 1078 struct dccp_sock *dp = dccp_sk(sk);
1086 struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
1087 1079
1088 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); 1080 BUG_ON(hcrx == NULL);
1089
1090 if (hcrx == NULL)
1091 return;
1092 1081
1093 ccid3_hc_rx_set_state(sk, TFRC_RSTATE_TERM); 1082 ccid3_hc_rx_set_state(sk, TFRC_RSTATE_TERM);
1094 1083
@@ -1104,11 +1093,9 @@ static void ccid3_hc_rx_exit(struct sock *sk)
1104 1093
1105static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info) 1094static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info)
1106{ 1095{
1107 const struct dccp_sock *dp = dccp_sk(sk); 1096 const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
1108 const struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
1109 1097
1110 if (hcrx == NULL) 1098 BUG_ON(hcrx == NULL);
1111 return;
1112 1099
1113 info->tcpi_ca_state = hcrx->ccid3hcrx_state; 1100 info->tcpi_ca_state = hcrx->ccid3hcrx_state;
1114 info->tcpi_options |= TCPI_OPT_TIMESTAMPS; 1101 info->tcpi_options |= TCPI_OPT_TIMESTAMPS;
@@ -1117,11 +1104,9 @@ static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info)
1117 1104
1118static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info) 1105static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info)
1119{ 1106{
1120 const struct dccp_sock *dp = dccp_sk(sk); 1107 const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
1121 const struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
1122 1108
1123 if (hctx == NULL) 1109 BUG_ON(hctx == NULL);
1124 return;
1125 1110
1126 info->tcpi_rto = hctx->ccid3hctx_t_rto; 1111 info->tcpi_rto = hctx->ccid3hctx_t_rto;
1127 info->tcpi_rtt = hctx->ccid3hctx_rtt; 1112 info->tcpi_rtt = hctx->ccid3hctx_rtt;
diff --git a/net/dccp/ccids/ccid3.h b/net/dccp/ccids/ccid3.h
index ee8cbace66..eb248778ee 100644
--- a/net/dccp/ccids/ccid3.h
+++ b/net/dccp/ccids/ccid3.h
@@ -48,6 +48,8 @@
48/* Two seconds as per CCID3 spec */ 48/* Two seconds as per CCID3 spec */
49#define TFRC_INITIAL_TIMEOUT (2 * USEC_PER_SEC) 49#define TFRC_INITIAL_TIMEOUT (2 * USEC_PER_SEC)
50 50
51#define TFRC_INITIAL_IPI (USEC_PER_SEC / 4)
52
51/* In usecs - half the scheduling granularity as per RFC3448 4.6 */ 53/* In usecs - half the scheduling granularity as per RFC3448 4.6 */
52#define TFRC_OPSYS_HALF_TIME_GRAN (USEC_PER_SEC / (2 * HZ)) 54#define TFRC_OPSYS_HALF_TIME_GRAN (USEC_PER_SEC / (2 * HZ))
53 55
@@ -115,7 +117,7 @@ struct ccid3_hc_rx_sock {
115 u64 ccid3hcrx_seqno_last_counter:48, 117 u64 ccid3hcrx_seqno_last_counter:48,
116 ccid3hcrx_state:8, 118 ccid3hcrx_state:8,
117 ccid3hcrx_last_counter:4; 119 ccid3hcrx_last_counter:4;
118 unsigned long ccid3hcrx_rtt; 120 u32 ccid3hcrx_rtt;
119 u32 ccid3hcrx_p; 121 u32 ccid3hcrx_p;
120 u32 ccid3hcrx_bytes_recv; 122 u32 ccid3hcrx_bytes_recv;
121 struct timeval ccid3hcrx_tstamp_last_feedback; 123 struct timeval ccid3hcrx_tstamp_last_feedback;
@@ -128,10 +130,14 @@ struct ccid3_hc_rx_sock {
128 u32 ccid3hcrx_x_recv; 130 u32 ccid3hcrx_x_recv;
129}; 131};
130 132
131#define ccid3_hc_tx_field(s,field) (s->dccps_hc_tx_ccid_private == NULL ? 0 : \ 133static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk)
132 ((struct ccid3_hc_tx_sock *)s->dccps_hc_tx_ccid_private)->ccid3hctx_##field) 134{
135 return dccp_sk(sk)->dccps_hc_tx_ccid_private;
136}
133 137
134#define ccid3_hc_rx_field(s,field) (s->dccps_hc_rx_ccid_private == NULL ? 0 : \ 138static inline struct ccid3_hc_rx_sock *ccid3_hc_rx_sk(const struct sock *sk)
135 ((struct ccid3_hc_rx_sock *)s->dccps_hc_rx_ccid_private)->ccid3hcrx_##field) 139{
140 return dccp_sk(sk)->dccps_hc_rx_ccid_private;
141}
136 142
137#endif /* _DCCP_CCID3_H_ */ 143#endif /* _DCCP_CCID3_H_ */
diff --git a/net/dccp/ccids/lib/packet_history.h b/net/dccp/ccids/lib/packet_history.h
index fb90a91aa9..b375ebdb7d 100644
--- a/net/dccp/ccids/lib/packet_history.h
+++ b/net/dccp/ccids/lib/packet_history.h
@@ -134,6 +134,7 @@ static inline struct dccp_tx_hist_entry *
134 134
135static inline struct dccp_rx_hist_entry * 135static inline struct dccp_rx_hist_entry *
136 dccp_rx_hist_entry_new(struct dccp_rx_hist *hist, 136 dccp_rx_hist_entry_new(struct dccp_rx_hist *hist,
137 const struct sock *sk,
137 const u32 ndp, 138 const u32 ndp,
138 const struct sk_buff *skb, 139 const struct sk_buff *skb,
139 const unsigned int __nocast prio) 140 const unsigned int __nocast prio)
@@ -148,7 +149,7 @@ static inline struct dccp_rx_hist_entry *
148 entry->dccphrx_ccval = dh->dccph_ccval; 149 entry->dccphrx_ccval = dh->dccph_ccval;
149 entry->dccphrx_type = dh->dccph_type; 150 entry->dccphrx_type = dh->dccph_type;
150 entry->dccphrx_ndp = ndp; 151 entry->dccphrx_ndp = ndp;
151 do_gettimeofday(&(entry->dccphrx_tstamp)); 152 dccp_timestamp(sk, &entry->dccphrx_tstamp);
152 } 153 }
153 154
154 return entry; 155 return entry;
diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h
index 33456c0d59..95c4630b3b 100644
--- a/net/dccp/dccp.h
+++ b/net/dccp/dccp.h
@@ -426,10 +426,13 @@ extern struct dccp_ackpkts *
426 dccp_ackpkts_alloc(unsigned int len, 426 dccp_ackpkts_alloc(unsigned int len,
427 const unsigned int __nocast priority); 427 const unsigned int __nocast priority);
428extern void dccp_ackpkts_free(struct dccp_ackpkts *ap); 428extern void dccp_ackpkts_free(struct dccp_ackpkts *ap);
429extern int dccp_ackpkts_add(struct dccp_ackpkts *ap, u64 ackno, u8 state); 429extern int dccp_ackpkts_add(struct dccp_ackpkts *ap, const struct sock *sk,
430 u64 ackno, u8 state);
430extern void dccp_ackpkts_check_rcv_ackno(struct dccp_ackpkts *ap, 431extern void dccp_ackpkts_check_rcv_ackno(struct dccp_ackpkts *ap,
431 struct sock *sk, u64 ackno); 432 struct sock *sk, u64 ackno);
432 433
434extern void dccp_timestamp(const struct sock *sk, struct timeval *tv);
435
433static inline suseconds_t timeval_usecs(const struct timeval *tv) 436static inline suseconds_t timeval_usecs(const struct timeval *tv)
434{ 437{
435 return tv->tv_sec * USEC_PER_SEC + tv->tv_usec; 438 return tv->tv_sec * USEC_PER_SEC + tv->tv_usec;
@@ -468,17 +471,6 @@ static inline void timeval_sub_usecs(struct timeval *tv,
468 } 471 }
469} 472}
470 473
471/*
472 * Returns the difference in usecs between timeval
473 * passed in and current time
474 */
475static inline suseconds_t timeval_now_delta(const struct timeval *tv)
476{
477 struct timeval now;
478 do_gettimeofday(&now);
479 return timeval_delta(&now, tv);
480}
481
482#ifdef CONFIG_IP_DCCP_DEBUG 474#ifdef CONFIG_IP_DCCP_DEBUG
483extern void dccp_ackvector_print(const u64 ackno, 475extern void dccp_ackvector_print(const u64 ackno,
484 const unsigned char *vector, int len); 476 const unsigned char *vector, int len);
diff --git a/net/dccp/input.c b/net/dccp/input.c
index ef29cef1da..c60bc3433f 100644
--- a/net/dccp/input.c
+++ b/net/dccp/input.c
@@ -170,7 +170,7 @@ int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
170 if (dp->dccps_options.dccpo_send_ack_vector) { 170 if (dp->dccps_options.dccpo_send_ack_vector) {
171 struct dccp_ackpkts *ap = dp->dccps_hc_rx_ackpkts; 171 struct dccp_ackpkts *ap = dp->dccps_hc_rx_ackpkts;
172 172
173 if (dccp_ackpkts_add(dp->dccps_hc_rx_ackpkts, 173 if (dccp_ackpkts_add(dp->dccps_hc_rx_ackpkts, sk,
174 DCCP_SKB_CB(skb)->dccpd_seq, 174 DCCP_SKB_CB(skb)->dccpd_seq,
175 DCCP_ACKPKTS_STATE_RECEIVED)) { 175 DCCP_ACKPKTS_STATE_RECEIVED)) {
176 LIMIT_NETDEBUG(KERN_WARNING "DCCP: acknowledgeable " 176 LIMIT_NETDEBUG(KERN_WARNING "DCCP: acknowledgeable "
@@ -498,7 +498,7 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
498 * DCCP_ACKPKTS_STATE_ECN_MARKED 498 * DCCP_ACKPKTS_STATE_ECN_MARKED
499 */ 499 */
500 if (dp->dccps_options.dccpo_send_ack_vector) { 500 if (dp->dccps_options.dccpo_send_ack_vector) {
501 if (dccp_ackpkts_add(dp->dccps_hc_rx_ackpkts, 501 if (dccp_ackpkts_add(dp->dccps_hc_rx_ackpkts, sk,
502 DCCP_SKB_CB(skb)->dccpd_seq, 502 DCCP_SKB_CB(skb)->dccpd_seq,
503 DCCP_ACKPKTS_STATE_RECEIVED)) 503 DCCP_ACKPKTS_STATE_RECEIVED))
504 goto discard; 504 goto discard;
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index 3fc75dbee4..2afaa464e7 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -641,16 +641,12 @@ int dccp_v4_send_reset(struct sock *sk, enum dccp_reset_codes code)
641 641
642 skb = dccp_make_reset(sk, sk->sk_dst_cache, code); 642 skb = dccp_make_reset(sk, sk->sk_dst_cache, code);
643 if (skb != NULL) { 643 if (skb != NULL) {
644 const struct dccp_sock *dp = dccp_sk(sk);
645 const struct inet_sock *inet = inet_sk(sk); 644 const struct inet_sock *inet = inet_sk(sk);
646 645
647 err = ip_build_and_send_pkt(skb, sk, 646 err = ip_build_and_send_pkt(skb, sk,
648 inet->saddr, inet->daddr, NULL); 647 inet->saddr, inet->daddr, NULL);
649 if (err == NET_XMIT_CN) 648 if (err == NET_XMIT_CN)
650 err = 0; 649 err = 0;
651
652 ccid_hc_rx_exit(dp->dccps_hc_rx_ccid, sk);
653 ccid_hc_tx_exit(dp->dccps_hc_tx_ccid, sk);
654 } 650 }
655 651
656 return err; 652 return err;
@@ -1243,6 +1239,7 @@ static int dccp_v4_init_sock(struct sock *sk)
1243 static int dccp_ctl_socket_init = 1; 1239 static int dccp_ctl_socket_init = 1;
1244 1240
1245 dccp_options_init(&dp->dccps_options); 1241 dccp_options_init(&dp->dccps_options);
1242 do_gettimeofday(&dp->dccps_epoch);
1246 1243
1247 if (dp->dccps_options.dccpo_send_ack_vector) { 1244 if (dp->dccps_options.dccpo_send_ack_vector) {
1248 dp->dccps_hc_rx_ackpkts = 1245 dp->dccps_hc_rx_ackpkts =
diff --git a/net/dccp/minisocks.c b/net/dccp/minisocks.c
index ce5dff4ac2..18461bc04c 100644
--- a/net/dccp/minisocks.c
+++ b/net/dccp/minisocks.c
@@ -96,6 +96,7 @@ struct sock *dccp_create_openreq_child(struct sock *sk,
96 newdp->dccps_hc_rx_ackpkts = NULL; 96 newdp->dccps_hc_rx_ackpkts = NULL;
97 newdp->dccps_role = DCCP_ROLE_SERVER; 97 newdp->dccps_role = DCCP_ROLE_SERVER;
98 newicsk->icsk_rto = DCCP_TIMEOUT_INIT; 98 newicsk->icsk_rto = DCCP_TIMEOUT_INIT;
99 do_gettimeofday(&newdp->dccps_epoch);
99 100
100 if (newdp->dccps_options.dccpo_send_ack_vector) { 101 if (newdp->dccps_options.dccpo_send_ack_vector) {
101 newdp->dccps_hc_rx_ackpkts = 102 newdp->dccps_hc_rx_ackpkts =
diff --git a/net/dccp/options.c b/net/dccp/options.c
index 382c5894ac..d4c4242d8d 100644
--- a/net/dccp/options.c
+++ b/net/dccp/options.c
@@ -72,6 +72,7 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
72 struct dccp_options_received *opt_recv = &dp->dccps_options_received; 72 struct dccp_options_received *opt_recv = &dp->dccps_options_received;
73 unsigned char opt, len; 73 unsigned char opt, len;
74 unsigned char *value; 74 unsigned char *value;
75 u32 elapsed_time;
75 76
76 memset(opt_recv, 0, sizeof(*opt_recv)); 77 memset(opt_recv, 0, sizeof(*opt_recv));
77 78
@@ -139,7 +140,7 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
139 opt_recv->dccpor_timestamp = ntohl(*(u32 *)value); 140 opt_recv->dccpor_timestamp = ntohl(*(u32 *)value);
140 141
141 dp->dccps_timestamp_echo = opt_recv->dccpor_timestamp; 142 dp->dccps_timestamp_echo = opt_recv->dccpor_timestamp;
142 do_gettimeofday(&dp->dccps_timestamp_time); 143 dccp_timestamp(sk, &dp->dccps_timestamp_time);
143 144
144 dccp_pr_debug("%sTIMESTAMP=%u, ackno=%llu\n", 145 dccp_pr_debug("%sTIMESTAMP=%u, ackno=%llu\n",
145 debug_prefix, opt_recv->dccpor_timestamp, 146 debug_prefix, opt_recv->dccpor_timestamp,
@@ -159,18 +160,18 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
159 (unsigned long long) 160 (unsigned long long)
160 DCCP_SKB_CB(skb)->dccpd_ack_seq); 161 DCCP_SKB_CB(skb)->dccpd_ack_seq);
161 162
162 if (len > 4) {
163 if (len == 6)
164 opt_recv->dccpor_elapsed_time =
165 ntohs(*(u16 *)(value + 4));
166 else
167 opt_recv->dccpor_elapsed_time =
168 ntohl(*(u32 *)(value + 4));
169 163
170 dccp_pr_debug("%sTIMESTAMP_ECHO ELAPSED_TIME=%d\n", 164 if (len == 4)
171 debug_prefix, 165 break;
172 opt_recv->dccpor_elapsed_time); 166
173 } 167 if (len == 6)
168 elapsed_time = ntohs(*(u16 *)(value + 4));
169 else
170 elapsed_time = ntohl(*(u32 *)(value + 4));
171
172 /* Give precedence to the biggest ELAPSED_TIME */
173 if (elapsed_time > opt_recv->dccpor_elapsed_time)
174 opt_recv->dccpor_elapsed_time = elapsed_time;
174 break; 175 break;
175 case DCCPO_ELAPSED_TIME: 176 case DCCPO_ELAPSED_TIME:
176 if (len != 2 && len != 4) 177 if (len != 2 && len != 4)
@@ -180,14 +181,15 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
180 continue; 181 continue;
181 182
182 if (len == 2) 183 if (len == 2)
183 opt_recv->dccpor_elapsed_time = 184 elapsed_time = ntohs(*(u16 *)value);
184 ntohs(*(u16 *)value);
185 else 185 else
186 opt_recv->dccpor_elapsed_time = 186 elapsed_time = ntohl(*(u32 *)value);
187 ntohl(*(u32 *)value); 187
188 if (elapsed_time > opt_recv->dccpor_elapsed_time)
189 opt_recv->dccpor_elapsed_time = elapsed_time;
188 190
189 dccp_pr_debug("%sELAPSED_TIME=%d\n", debug_prefix, 191 dccp_pr_debug("%sELAPSED_TIME=%d\n", debug_prefix,
190 opt_recv->dccpor_elapsed_time); 192 elapsed_time);
191 break; 193 break;
192 /* 194 /*
193 * From draft-ietf-dccp-spec-11.txt: 195 * From draft-ietf-dccp-spec-11.txt:
@@ -359,9 +361,13 @@ static void dccp_insert_option_ack_vector(struct sock *sk, struct sk_buff *skb)
359#endif 361#endif
360 struct dccp_ackpkts *ap = dp->dccps_hc_rx_ackpkts; 362 struct dccp_ackpkts *ap = dp->dccps_hc_rx_ackpkts;
361 int len = ap->dccpap_buf_vector_len + 2; 363 int len = ap->dccpap_buf_vector_len + 2;
362 const u32 elapsed_time = timeval_now_delta(&ap->dccpap_time) / 10; 364 struct timeval now;
365 u32 elapsed_time;
363 unsigned char *to, *from; 366 unsigned char *to, *from;
364 367
368 dccp_timestamp(sk, &now);
369 elapsed_time = timeval_delta(&now, &ap->dccpap_time) / 10;
370
365 if (elapsed_time != 0) 371 if (elapsed_time != 0)
366 dccp_insert_option_elapsed_time(sk, skb, elapsed_time); 372 dccp_insert_option_elapsed_time(sk, skb, elapsed_time);
367 373
@@ -426,13 +432,29 @@ static void dccp_insert_option_ack_vector(struct sock *sk, struct sk_buff *skb)
426 (unsigned long long) ap->dccpap_ack_ackno); 432 (unsigned long long) ap->dccpap_ack_ackno);
427} 433}
428 434
435void dccp_timestamp(const struct sock *sk, struct timeval *tv)
436{
437 const struct dccp_sock *dp = dccp_sk(sk);
438
439 do_gettimeofday(tv);
440 tv->tv_sec -= dp->dccps_epoch.tv_sec;
441 tv->tv_usec -= dp->dccps_epoch.tv_usec;
442
443 while (tv->tv_usec < 0) {
444 tv->tv_sec--;
445 tv->tv_usec += USEC_PER_SEC;
446 }
447}
448
449EXPORT_SYMBOL_GPL(dccp_timestamp);
450
429void dccp_insert_option_timestamp(struct sock *sk, struct sk_buff *skb) 451void dccp_insert_option_timestamp(struct sock *sk, struct sk_buff *skb)
430{ 452{
431 struct timeval tv; 453 struct timeval tv;
432 u32 now; 454 u32 now;
433 455
434 do_gettimeofday(&tv); 456 dccp_timestamp(sk, &tv);
435 now = (tv.tv_sec * USEC_PER_SEC + tv.tv_usec) / 10; 457 now = timeval_usecs(&tv) / 10;
436 /* yes this will overflow but that is the point as we want a 458 /* yes this will overflow but that is the point as we want a
437 * 10 usec 32 bit timer which mean it wraps every 11.9 hours */ 459 * 10 usec 32 bit timer which mean it wraps every 11.9 hours */
438 460
@@ -450,13 +472,17 @@ static void dccp_insert_option_timestamp_echo(struct sock *sk,
450 const char *debug_prefix = dp->dccps_role == DCCP_ROLE_CLIENT ? 472 const char *debug_prefix = dp->dccps_role == DCCP_ROLE_CLIENT ?
451 "CLIENT TX opt: " : "server TX opt: "; 473 "CLIENT TX opt: " : "server TX opt: ";
452#endif 474#endif
475 struct timeval now;
453 u32 tstamp_echo; 476 u32 tstamp_echo;
454 const u32 elapsed_time = 477 u32 elapsed_time;
455 timeval_now_delta(&dp->dccps_timestamp_time) / 10; 478 int len, elapsed_time_len;
456 const int elapsed_time_len = dccp_elapsed_time_len(elapsed_time);
457 const int len = 6 + elapsed_time_len;
458 unsigned char *to; 479 unsigned char *to;
459 480
481 dccp_timestamp(sk, &now);
482 elapsed_time = timeval_delta(&now, &dp->dccps_timestamp_time) / 10;
483 elapsed_time_len = dccp_elapsed_time_len(elapsed_time);
484 len = 6 + elapsed_time_len;
485
460 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN) { 486 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN) {
461 LIMIT_NETDEBUG(KERN_INFO "DCCP: packet too small to insert " 487 LIMIT_NETDEBUG(KERN_INFO "DCCP: packet too small to insert "
462 "timestamp echo!\n"); 488 "timestamp echo!\n");
@@ -505,13 +531,18 @@ void dccp_insert_options(struct sock *sk, struct sk_buff *skb)
505 (dp->dccps_hc_rx_ackpkts->dccpap_buf_ackno != 531 (dp->dccps_hc_rx_ackpkts->dccpap_buf_ackno !=
506 DCCP_MAX_SEQNO + 1)) 532 DCCP_MAX_SEQNO + 1))
507 dccp_insert_option_ack_vector(sk, skb); 533 dccp_insert_option_ack_vector(sk, skb);
508
509 if (dp->dccps_timestamp_echo != 0) 534 if (dp->dccps_timestamp_echo != 0)
510 dccp_insert_option_timestamp_echo(sk, skb); 535 dccp_insert_option_timestamp_echo(sk, skb);
511 } 536 }
512 537
513 ccid_hc_rx_insert_options(dp->dccps_hc_rx_ccid, sk, skb); 538 if (dp->dccps_hc_rx_insert_options) {
514 ccid_hc_tx_insert_options(dp->dccps_hc_tx_ccid, sk, skb); 539 ccid_hc_rx_insert_options(dp->dccps_hc_rx_ccid, sk, skb);
540 dp->dccps_hc_rx_insert_options = 0;
541 }
542 if (dp->dccps_hc_tx_insert_options) {
543 ccid_hc_tx_insert_options(dp->dccps_hc_tx_ccid, sk, skb);
544 dp->dccps_hc_tx_insert_options = 0;
545 }
515 546
516 /* XXX: insert other options when appropriate */ 547 /* XXX: insert other options when appropriate */
517 548
@@ -616,7 +647,8 @@ static inline int dccp_ackpkts_set_buf_head_state(struct dccp_ackpkts *ap,
616/* 647/*
617 * Implements the draft-ietf-dccp-spec-11.txt Appendix A 648 * Implements the draft-ietf-dccp-spec-11.txt Appendix A
618 */ 649 */
619int dccp_ackpkts_add(struct dccp_ackpkts *ap, u64 ackno, u8 state) 650int dccp_ackpkts_add(struct dccp_ackpkts *ap, const struct sock *sk,
651 u64 ackno, u8 state)
620{ 652{
621 /* 653 /*
622 * Check at the right places if the buffer is full, if it is, tell the 654 * Check at the right places if the buffer is full, if it is, tell the
@@ -697,7 +729,7 @@ int dccp_ackpkts_add(struct dccp_ackpkts *ap, u64 ackno, u8 state)
697 } 729 }
698 730
699 ap->dccpap_buf_ackno = ackno; 731 ap->dccpap_buf_ackno = ackno;
700 do_gettimeofday(&ap->dccpap_time); 732 dccp_timestamp(sk, &ap->dccpap_time);
701out: 733out:
702 dccp_pr_debug(""); 734 dccp_pr_debug("");
703 dccp_ackpkts_print(ap); 735 dccp_ackpkts_print(ap);
diff --git a/net/dccp/output.c b/net/dccp/output.c
index 28de157a43..ea6d0e91e5 100644
--- a/net/dccp/output.c
+++ b/net/dccp/output.c
@@ -522,7 +522,4 @@ void dccp_send_close(struct sock *sk, const int active)
522 dccp_transmit_skb(sk, skb_clone(skb, prio)); 522 dccp_transmit_skb(sk, skb_clone(skb, prio));
523 } else 523 } else
524 dccp_transmit_skb(sk, skb); 524 dccp_transmit_skb(sk, skb);
525
526 ccid_hc_rx_exit(dp->dccps_hc_rx_ccid, sk);
527 ccid_hc_tx_exit(dp->dccps_hc_tx_ccid, sk);
528} 525}
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index 2c915f305b..3407f190af 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -117,8 +117,7 @@ static struct dn_rt_hash_bucket *dn_rt_hash_table;
117static unsigned dn_rt_hash_mask; 117static unsigned dn_rt_hash_mask;
118 118
119static struct timer_list dn_route_timer; 119static struct timer_list dn_route_timer;
120static struct timer_list dn_rt_flush_timer = 120static DEFINE_TIMER(dn_rt_flush_timer, dn_run_flush, 0, 0);
121 TIMER_INITIALIZER(dn_run_flush, 0, 0);
122int decnet_dst_gc_interval = 2; 121int decnet_dst_gc_interval = 2;
123 122
124static struct dst_ops dn_dst_ops = { 123static struct dst_ops dn_dst_ops = {
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index bf147f8db3..a9d84f9344 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -1248,11 +1248,6 @@ module_init(inet_init);
1248/* ------------------------------------------------------------------------ */ 1248/* ------------------------------------------------------------------------ */
1249 1249
1250#ifdef CONFIG_PROC_FS 1250#ifdef CONFIG_PROC_FS
1251#ifdef CONFIG_IP_FIB_TRIE
1252extern int fib_stat_proc_init(void);
1253extern void fib_stat_proc_exit(void);
1254#endif
1255
1256static int __init ipv4_proc_init(void) 1251static int __init ipv4_proc_init(void)
1257{ 1252{
1258 int rc = 0; 1253 int rc = 0;
@@ -1265,19 +1260,11 @@ static int __init ipv4_proc_init(void)
1265 goto out_udp; 1260 goto out_udp;
1266 if (fib_proc_init()) 1261 if (fib_proc_init())
1267 goto out_fib; 1262 goto out_fib;
1268#ifdef CONFIG_IP_FIB_TRIE
1269 if (fib_stat_proc_init())
1270 goto out_fib_stat;
1271#endif
1272 if (ip_misc_proc_init()) 1263 if (ip_misc_proc_init())
1273 goto out_misc; 1264 goto out_misc;
1274out: 1265out:
1275 return rc; 1266 return rc;
1276out_misc: 1267out_misc:
1277#ifdef CONFIG_IP_FIB_TRIE
1278 fib_stat_proc_exit();
1279out_fib_stat:
1280#endif
1281 fib_proc_exit(); 1268 fib_proc_exit();
1282out_fib: 1269out_fib:
1283 udp4_proc_exit(); 1270 udp4_proc_exit();
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index b2dea4e5da..1b63b48241 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -43,7 +43,7 @@
43 * 2 of the License, or (at your option) any later version. 43 * 2 of the License, or (at your option) any later version.
44 */ 44 */
45 45
46#define VERSION "0.402" 46#define VERSION "0.403"
47 47
48#include <linux/config.h> 48#include <linux/config.h>
49#include <asm/uaccess.h> 49#include <asm/uaccess.h>
@@ -164,7 +164,6 @@ static struct node *resize(struct trie *t, struct tnode *tn);
164static struct tnode *inflate(struct trie *t, struct tnode *tn); 164static struct tnode *inflate(struct trie *t, struct tnode *tn);
165static struct tnode *halve(struct trie *t, struct tnode *tn); 165static struct tnode *halve(struct trie *t, struct tnode *tn);
166static void tnode_free(struct tnode *tn); 166static void tnode_free(struct tnode *tn);
167static void trie_dump_seq(struct seq_file *seq, struct trie *t);
168 167
169static kmem_cache_t *fn_alias_kmem __read_mostly; 168static kmem_cache_t *fn_alias_kmem __read_mostly;
170static struct trie *trie_local = NULL, *trie_main = NULL; 169static struct trie *trie_local = NULL, *trie_main = NULL;
@@ -1971,558 +1970,525 @@ struct fib_table * __init fib_hash_init(int id)
1971 return tb; 1970 return tb;
1972} 1971}
1973 1972
1974/* Trie dump functions */ 1973#ifdef CONFIG_PROC_FS
1974/* Depth first Trie walk iterator */
1975struct fib_trie_iter {
1976 struct tnode *tnode;
1977 struct trie *trie;
1978 unsigned index;
1979 unsigned depth;
1980};
1975 1981
1976static void putspace_seq(struct seq_file *seq, int n) 1982static struct node *fib_trie_get_next(struct fib_trie_iter *iter)
1977{ 1983{
1978 while (n--) 1984 struct tnode *tn = iter->tnode;
1979 seq_printf(seq, " "); 1985 unsigned cindex = iter->index;
1980} 1986 struct tnode *p;
1981 1987
1982static void printbin_seq(struct seq_file *seq, unsigned int v, int bits) 1988 pr_debug("get_next iter={node=%p index=%d depth=%d}\n",
1983{ 1989 iter->tnode, iter->index, iter->depth);
1984 while (bits--) 1990rescan:
1985 seq_printf(seq, "%s", (v & (1<<bits))?"1":"0"); 1991 while (cindex < (1<<tn->bits)) {
1986} 1992 struct node *n = tnode_get_child(tn, cindex);
1987 1993
1988static void printnode_seq(struct seq_file *seq, int indent, struct node *n, 1994 if (n) {
1989 int pend, int cindex, int bits) 1995 if (IS_LEAF(n)) {
1990{ 1996 iter->tnode = tn;
1991 putspace_seq(seq, indent); 1997 iter->index = cindex + 1;
1992 if (IS_LEAF(n)) 1998 } else {
1993 seq_printf(seq, "|"); 1999 /* push down one level */
1994 else 2000 iter->tnode = (struct tnode *) n;
1995 seq_printf(seq, "+"); 2001 iter->index = 0;
1996 if (bits) { 2002 ++iter->depth;
1997 seq_printf(seq, "%d/", cindex); 2003 }
1998 printbin_seq(seq, cindex, bits); 2004 return n;
1999 seq_printf(seq, ": "); 2005 }
2000 } else
2001 seq_printf(seq, "<root>: ");
2002 seq_printf(seq, "%s:%p ", IS_LEAF(n)?"Leaf":"Internal node", n);
2003 2006
2004 if (IS_LEAF(n)) { 2007 ++cindex;
2005 struct leaf *l = (struct leaf *)n; 2008 }
2006 struct fib_alias *fa;
2007 int i;
2008 2009
2009 seq_printf(seq, "key=%d.%d.%d.%d\n", 2010 /* Current node exhausted, pop back up */
2010 n->key >> 24, (n->key >> 16) % 256, (n->key >> 8) % 256, n->key % 256); 2011 p = NODE_PARENT(tn);
2011 2012 if (p) {
2012 for (i = 32; i >= 0; i--) 2013 cindex = tkey_extract_bits(tn->key, p->pos, p->bits)+1;
2013 if (find_leaf_info(&l->list, i)) { 2014 tn = p;
2014 struct list_head *fa_head = get_fa_head(l, i); 2015 --iter->depth;
2015 2016 goto rescan;
2016 if (!fa_head)
2017 continue;
2018
2019 if (list_empty(fa_head))
2020 continue;
2021
2022 putspace_seq(seq, indent+2);
2023 seq_printf(seq, "{/%d...dumping}\n", i);
2024
2025 list_for_each_entry_rcu(fa, fa_head, fa_list) {
2026 putspace_seq(seq, indent+2);
2027 if (fa->fa_info == NULL) {
2028 seq_printf(seq, "Error fa_info=NULL\n");
2029 continue;
2030 }
2031 if (fa->fa_info->fib_nh == NULL) {
2032 seq_printf(seq, "Error _fib_nh=NULL\n");
2033 continue;
2034 }
2035
2036 seq_printf(seq, "{type=%d scope=%d TOS=%d}\n",
2037 fa->fa_type,
2038 fa->fa_scope,
2039 fa->fa_tos);
2040 }
2041 }
2042 } else {
2043 struct tnode *tn = (struct tnode *)n;
2044 int plen = ((struct tnode *)n)->pos;
2045 t_key prf = MASK_PFX(n->key, plen);
2046
2047 seq_printf(seq, "key=%d.%d.%d.%d/%d\n",
2048 prf >> 24, (prf >> 16) % 256, (prf >> 8) % 256, prf % 256, plen);
2049
2050 putspace_seq(seq, indent); seq_printf(seq, "| ");
2051 seq_printf(seq, "{key prefix=%08x/", tn->key & TKEY_GET_MASK(0, tn->pos));
2052 printbin_seq(seq, tkey_extract_bits(tn->key, 0, tn->pos), tn->pos);
2053 seq_printf(seq, "}\n");
2054 putspace_seq(seq, indent); seq_printf(seq, "| ");
2055 seq_printf(seq, "{pos=%d", tn->pos);
2056 seq_printf(seq, " (skip=%d bits)", tn->pos - pend);
2057 seq_printf(seq, " bits=%d (%u children)}\n", tn->bits, (1 << tn->bits));
2058 putspace_seq(seq, indent); seq_printf(seq, "| ");
2059 seq_printf(seq, "{empty=%d full=%d}\n", tn->empty_children, tn->full_children);
2060 } 2017 }
2018
2019 /* got root? */
2020 return NULL;
2061} 2021}
2062 2022
2063static void trie_dump_seq(struct seq_file *seq, struct trie *t) 2023static struct node *fib_trie_get_first(struct fib_trie_iter *iter,
2024 struct trie *t)
2064{ 2025{
2065 struct node *n; 2026 struct node *n = rcu_dereference(t->trie);
2066 int cindex = 0;
2067 int indent = 1;
2068 int pend = 0;
2069 int depth = 0;
2070 struct tnode *tn;
2071
2072 rcu_read_lock();
2073 n = rcu_dereference(t->trie);
2074 seq_printf(seq, "------ trie_dump of t=%p ------\n", t);
2075 2027
2076 if (!n) { 2028 if (n && IS_TNODE(n)) {
2077 seq_printf(seq, "------ trie is empty\n"); 2029 iter->tnode = (struct tnode *) n;
2078 2030 iter->trie = t;
2079 rcu_read_unlock(); 2031 iter->index = 0;
2080 return; 2032 iter->depth = 0;
2033 return n;
2081 } 2034 }
2035 return NULL;
2036}
2082 2037
2083 printnode_seq(seq, indent, n, pend, cindex, 0); 2038static void trie_collect_stats(struct trie *t, struct trie_stat *s)
2084 2039{
2085 if (!IS_TNODE(n)) { 2040 struct node *n;
2086 rcu_read_unlock(); 2041 struct fib_trie_iter iter;
2087 return;
2088 }
2089
2090 tn = (struct tnode *)n;
2091 pend = tn->pos+tn->bits;
2092 putspace_seq(seq, indent); seq_printf(seq, "\\--\n");
2093 indent += 3;
2094 depth++;
2095
2096 while (tn && cindex < (1 << tn->bits)) {
2097 struct node *child = rcu_dereference(tn->child[cindex]);
2098 if (!child)
2099 cindex++;
2100 else {
2101 /* Got a child */
2102 printnode_seq(seq, indent, child, pend,
2103 cindex, tn->bits);
2104
2105 if (IS_LEAF(child))
2106 cindex++;
2107
2108 else {
2109 /*
2110 * New tnode. Decend one level
2111 */
2112
2113 depth++;
2114 n = child;
2115 tn = (struct tnode *)n;
2116 pend = tn->pos+tn->bits;
2117 putspace_seq(seq, indent);
2118 seq_printf(seq, "\\--\n");
2119 indent += 3;
2120 cindex = 0;
2121 }
2122 }
2123
2124 /*
2125 * Test if we are done
2126 */
2127
2128 while (cindex >= (1 << tn->bits)) {
2129 /*
2130 * Move upwards and test for root
2131 * pop off all traversed nodes
2132 */
2133 2042
2134 if (NODE_PARENT(tn) == NULL) { 2043 memset(s, 0, sizeof(*s));
2135 tn = NULL;
2136 break;
2137 }
2138 2044
2139 cindex = tkey_extract_bits(tn->key, NODE_PARENT(tn)->pos, NODE_PARENT(tn)->bits); 2045 rcu_read_lock();
2140 cindex++; 2046 for (n = fib_trie_get_first(&iter, t); n;
2141 tn = NODE_PARENT(tn); 2047 n = fib_trie_get_next(&iter)) {
2142 pend = tn->pos + tn->bits; 2048 if (IS_LEAF(n)) {
2143 indent -= 3; 2049 s->leaves++;
2144 depth--; 2050 s->totdepth += iter.depth;
2051 if (iter.depth > s->maxdepth)
2052 s->maxdepth = iter.depth;
2053 } else {
2054 const struct tnode *tn = (const struct tnode *) n;
2055 int i;
2056
2057 s->tnodes++;
2058 s->nodesizes[tn->bits]++;
2059 for (i = 0; i < (1<<tn->bits); i++)
2060 if (!tn->child[i])
2061 s->nullpointers++;
2145 } 2062 }
2146 } 2063 }
2147 rcu_read_unlock(); 2064 rcu_read_unlock();
2148} 2065}
2149 2066
2150static struct trie_stat *trie_stat_new(void) 2067/*
2068 * This outputs /proc/net/fib_triestats
2069 */
2070static void trie_show_stats(struct seq_file *seq, struct trie_stat *stat)
2151{ 2071{
2152 struct trie_stat *s; 2072 unsigned i, max, pointers, bytes, avdepth;
2153 int i;
2154 2073
2155 s = kmalloc(sizeof(struct trie_stat), GFP_KERNEL); 2074 if (stat->leaves)
2156 if (!s) 2075 avdepth = stat->totdepth*100 / stat->leaves;
2157 return NULL; 2076 else
2077 avdepth = 0;
2158 2078
2159 s->totdepth = 0; 2079 seq_printf(seq, "\tAver depth: %d.%02d\n", avdepth / 100, avdepth % 100 );
2160 s->maxdepth = 0; 2080 seq_printf(seq, "\tMax depth: %u\n", stat->maxdepth);
2161 s->tnodes = 0;
2162 s->leaves = 0;
2163 s->nullpointers = 0;
2164 2081
2165 for (i = 0; i < MAX_CHILDS; i++) 2082 seq_printf(seq, "\tLeaves: %u\n", stat->leaves);
2166 s->nodesizes[i] = 0;
2167 2083
2168 return s; 2084 bytes = sizeof(struct leaf) * stat->leaves;
2169} 2085 seq_printf(seq, "\tInternal nodes: %d\n\t", stat->tnodes);
2086 bytes += sizeof(struct tnode) * stat->tnodes;
2170 2087
2171static struct trie_stat *trie_collect_stats(struct trie *t) 2088 max = MAX_CHILDS-1;
2172{ 2089 while (max >= 0 && stat->nodesizes[max] == 0)
2173 struct node *n; 2090 max--;
2174 struct trie_stat *s = trie_stat_new();
2175 int cindex = 0;
2176 int pend = 0;
2177 int depth = 0;
2178 2091
2179 if (!s) 2092 pointers = 0;
2180 return NULL; 2093 for (i = 1; i <= max; i++)
2094 if (stat->nodesizes[i] != 0) {
2095 seq_printf(seq, " %d: %d", i, stat->nodesizes[i]);
2096 pointers += (1<<i) * stat->nodesizes[i];
2097 }
2098 seq_putc(seq, '\n');
2099 seq_printf(seq, "\tPointers: %d\n", pointers);
2181 2100
2182 rcu_read_lock(); 2101 bytes += sizeof(struct node *) * pointers;
2183 n = rcu_dereference(t->trie); 2102 seq_printf(seq, "Null ptrs: %d\n", stat->nullpointers);
2103 seq_printf(seq, "Total size: %d kB\n", (bytes + 1023) / 1024);
2184 2104
2185 if (!n) 2105#ifdef CONFIG_IP_FIB_TRIE_STATS
2186 return s; 2106 seq_printf(seq, "Counters:\n---------\n");
2107 seq_printf(seq,"gets = %d\n", t->stats.gets);
2108 seq_printf(seq,"backtracks = %d\n", t->stats.backtrack);
2109 seq_printf(seq,"semantic match passed = %d\n", t->stats.semantic_match_passed);
2110 seq_printf(seq,"semantic match miss = %d\n", t->stats.semantic_match_miss);
2111 seq_printf(seq,"null node hit= %d\n", t->stats.null_node_hit);
2112 seq_printf(seq,"skipped node resize = %d\n", t->stats.resize_node_skipped);
2113#ifdef CLEAR_STATS
2114 memset(&(t->stats), 0, sizeof(t->stats));
2115#endif
2116#endif /* CONFIG_IP_FIB_TRIE_STATS */
2117}
2187 2118
2188 if (IS_TNODE(n)) { 2119static int fib_triestat_seq_show(struct seq_file *seq, void *v)
2189 struct tnode *tn = (struct tnode *)n; 2120{
2190 pend = tn->pos+tn->bits; 2121 struct trie_stat *stat;
2191 s->nodesizes[tn->bits]++;
2192 depth++;
2193
2194 while (tn && cindex < (1 << tn->bits)) {
2195 struct node *ch = rcu_dereference(tn->child[cindex]);
2196 if (ch) {
2197
2198 /* Got a child */
2199
2200 if (IS_LEAF(tn->child[cindex])) {
2201 cindex++;
2202
2203 /* stats */
2204 if (depth > s->maxdepth)
2205 s->maxdepth = depth;
2206 s->totdepth += depth;
2207 s->leaves++;
2208 } else {
2209 /*
2210 * New tnode. Decend one level
2211 */
2212
2213 s->tnodes++;
2214 s->nodesizes[tn->bits]++;
2215 depth++;
2216
2217 n = ch;
2218 tn = (struct tnode *)n;
2219 pend = tn->pos+tn->bits;
2220
2221 cindex = 0;
2222 }
2223 } else {
2224 cindex++;
2225 s->nullpointers++;
2226 }
2227 2122
2228 /* 2123 stat = kmalloc(sizeof(*stat), GFP_KERNEL);
2229 * Test if we are done 2124 if (!stat)
2230 */ 2125 return -ENOMEM;
2231 2126
2232 while (cindex >= (1 << tn->bits)) { 2127 seq_printf(seq, "Basic info: size of leaf: %Zd bytes, size of tnode: %Zd bytes.\n",
2233 /* 2128 sizeof(struct leaf), sizeof(struct tnode));
2234 * Move upwards and test for root
2235 * pop off all traversed nodes
2236 */
2237 2129
2238 if (NODE_PARENT(tn) == NULL) { 2130 if (trie_local) {
2239 tn = NULL; 2131 seq_printf(seq, "Local:\n");
2240 n = NULL; 2132 trie_collect_stats(trie_local, stat);
2241 break; 2133 trie_show_stats(seq, stat);
2242 } 2134 }
2243 2135
2244 cindex = tkey_extract_bits(tn->key, NODE_PARENT(tn)->pos, NODE_PARENT(tn)->bits); 2136 if (trie_main) {
2245 tn = NODE_PARENT(tn); 2137 seq_printf(seq, "Main:\n");
2246 cindex++; 2138 trie_collect_stats(trie_main, stat);
2247 n = (struct node *)tn; 2139 trie_show_stats(seq, stat);
2248 pend = tn->pos+tn->bits;
2249 depth--;
2250 }
2251 }
2252 } 2140 }
2141 kfree(stat);
2253 2142
2254 rcu_read_unlock(); 2143 return 0;
2255 return s;
2256} 2144}
2257 2145
2258#ifdef CONFIG_PROC_FS 2146static int fib_triestat_seq_open(struct inode *inode, struct file *file)
2259
2260static struct fib_alias *fib_triestat_get_first(struct seq_file *seq)
2261{ 2147{
2262 return NULL; 2148 return single_open(file, fib_triestat_seq_show, NULL);
2263} 2149}
2264 2150
2265static struct fib_alias *fib_triestat_get_next(struct seq_file *seq) 2151static struct file_operations fib_triestat_fops = {
2152 .owner = THIS_MODULE,
2153 .open = fib_triestat_seq_open,
2154 .read = seq_read,
2155 .llseek = seq_lseek,
2156 .release = single_release,
2157};
2158
2159static struct node *fib_trie_get_idx(struct fib_trie_iter *iter,
2160 loff_t pos)
2266{ 2161{
2162 loff_t idx = 0;
2163 struct node *n;
2164
2165 for (n = fib_trie_get_first(iter, trie_local);
2166 n; ++idx, n = fib_trie_get_next(iter)) {
2167 if (pos == idx)
2168 return n;
2169 }
2170
2171 for (n = fib_trie_get_first(iter, trie_main);
2172 n; ++idx, n = fib_trie_get_next(iter)) {
2173 if (pos == idx)
2174 return n;
2175 }
2267 return NULL; 2176 return NULL;
2268} 2177}
2269 2178
2270static void *fib_triestat_seq_start(struct seq_file *seq, loff_t *pos) 2179static void *fib_trie_seq_start(struct seq_file *seq, loff_t *pos)
2271{ 2180{
2272 if (!ip_fib_main_table) 2181 rcu_read_lock();
2273 return NULL; 2182 if (*pos == 0)
2274
2275 if (*pos)
2276 return fib_triestat_get_next(seq);
2277 else
2278 return SEQ_START_TOKEN; 2183 return SEQ_START_TOKEN;
2184 return fib_trie_get_idx(seq->private, *pos - 1);
2279} 2185}
2280 2186
2281static void *fib_triestat_seq_next(struct seq_file *seq, void *v, loff_t *pos) 2187static void *fib_trie_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2282{ 2188{
2189 struct fib_trie_iter *iter = seq->private;
2190 void *l = v;
2191
2283 ++*pos; 2192 ++*pos;
2284 if (v == SEQ_START_TOKEN) 2193 if (v == SEQ_START_TOKEN)
2285 return fib_triestat_get_first(seq); 2194 return fib_trie_get_idx(iter, 0);
2286 else
2287 return fib_triestat_get_next(seq);
2288}
2289 2195
2290static void fib_triestat_seq_stop(struct seq_file *seq, void *v) 2196 v = fib_trie_get_next(iter);
2291{ 2197 BUG_ON(v == l);
2198 if (v)
2199 return v;
2292 2200
2293} 2201 /* continue scan in next trie */
2202 if (iter->trie == trie_local)
2203 return fib_trie_get_first(iter, trie_main);
2294 2204
2295/* 2205 return NULL;
2296 * This outputs /proc/net/fib_triestats 2206}
2297 *
2298 * It always works in backward compatibility mode.
2299 * The format of the file is not supposed to be changed.
2300 */
2301 2207
2302static void collect_and_show(struct trie *t, struct seq_file *seq) 2208static void fib_trie_seq_stop(struct seq_file *seq, void *v)
2303{ 2209{
2304 int bytes = 0; /* How many bytes are used, a ref is 4 bytes */ 2210 rcu_read_unlock();
2305 int i, max, pointers; 2211}
2306 struct trie_stat *stat;
2307 int avdepth;
2308
2309 stat = trie_collect_stats(t);
2310
2311 bytes = 0;
2312 seq_printf(seq, "trie=%p\n", t);
2313
2314 if (stat) {
2315 if (stat->leaves)
2316 avdepth = stat->totdepth*100 / stat->leaves;
2317 else
2318 avdepth = 0;
2319 seq_printf(seq, "Aver depth: %d.%02d\n", avdepth / 100, avdepth % 100);
2320 seq_printf(seq, "Max depth: %4d\n", stat->maxdepth);
2321 2212
2322 seq_printf(seq, "Leaves: %d\n", stat->leaves); 2213static void seq_indent(struct seq_file *seq, int n)
2323 bytes += sizeof(struct leaf) * stat->leaves; 2214{
2324 seq_printf(seq, "Internal nodes: %d\n", stat->tnodes); 2215 while (n-- > 0) seq_puts(seq, " ");
2325 bytes += sizeof(struct tnode) * stat->tnodes; 2216}
2326 2217
2327 max = MAX_CHILDS-1; 2218static inline const char *rtn_scope(enum rt_scope_t s)
2219{
2220 static char buf[32];
2328 2221
2329 while (max >= 0 && stat->nodesizes[max] == 0) 2222 switch(s) {
2330 max--; 2223 case RT_SCOPE_UNIVERSE: return "universe";
2331 pointers = 0; 2224 case RT_SCOPE_SITE: return "site";
2225 case RT_SCOPE_LINK: return "link";
2226 case RT_SCOPE_HOST: return "host";
2227 case RT_SCOPE_NOWHERE: return "nowhere";
2228 default:
2229 snprintf(buf, sizeof(buf), "scope=%d", s);
2230 return buf;
2231 }
2232}
2332 2233
2333 for (i = 1; i <= max; i++) 2234static const char *rtn_type_names[__RTN_MAX] = {
2334 if (stat->nodesizes[i] != 0) { 2235 [RTN_UNSPEC] = "UNSPEC",
2335 seq_printf(seq, " %d: %d", i, stat->nodesizes[i]); 2236 [RTN_UNICAST] = "UNICAST",
2336 pointers += (1<<i) * stat->nodesizes[i]; 2237 [RTN_LOCAL] = "LOCAL",
2337 } 2238 [RTN_BROADCAST] = "BROADCAST",
2338 seq_printf(seq, "\n"); 2239 [RTN_ANYCAST] = "ANYCAST",
2339 seq_printf(seq, "Pointers: %d\n", pointers); 2240 [RTN_MULTICAST] = "MULTICAST",
2340 bytes += sizeof(struct node *) * pointers; 2241 [RTN_BLACKHOLE] = "BLACKHOLE",
2341 seq_printf(seq, "Null ptrs: %d\n", stat->nullpointers); 2242 [RTN_UNREACHABLE] = "UNREACHABLE",
2342 seq_printf(seq, "Total size: %d kB\n", bytes / 1024); 2243 [RTN_PROHIBIT] = "PROHIBIT",
2244 [RTN_THROW] = "THROW",
2245 [RTN_NAT] = "NAT",
2246 [RTN_XRESOLVE] = "XRESOLVE",
2247};
2343 2248
2344 kfree(stat); 2249static inline const char *rtn_type(unsigned t)
2345 } 2250{
2251 static char buf[32];
2346 2252
2347#ifdef CONFIG_IP_FIB_TRIE_STATS 2253 if (t < __RTN_MAX && rtn_type_names[t])
2348 seq_printf(seq, "Counters:\n---------\n"); 2254 return rtn_type_names[t];
2349 seq_printf(seq,"gets = %d\n", t->stats.gets); 2255 snprintf(buf, sizeof(buf), "type %d", t);
2350 seq_printf(seq,"backtracks = %d\n", t->stats.backtrack); 2256 return buf;
2351 seq_printf(seq,"semantic match passed = %d\n", t->stats.semantic_match_passed);
2352 seq_printf(seq,"semantic match miss = %d\n", t->stats.semantic_match_miss);
2353 seq_printf(seq,"null node hit= %d\n", t->stats.null_node_hit);
2354 seq_printf(seq,"skipped node resize = %d\n", t->stats.resize_node_skipped);
2355#ifdef CLEAR_STATS
2356 memset(&(t->stats), 0, sizeof(t->stats));
2357#endif
2358#endif /* CONFIG_IP_FIB_TRIE_STATS */
2359} 2257}
2360 2258
2361static int fib_triestat_seq_show(struct seq_file *seq, void *v) 2259/* Pretty print the trie */
2260static int fib_trie_seq_show(struct seq_file *seq, void *v)
2362{ 2261{
2363 char bf[128]; 2262 const struct fib_trie_iter *iter = seq->private;
2263 struct node *n = v;
2364 2264
2365 if (v == SEQ_START_TOKEN) { 2265 if (v == SEQ_START_TOKEN)
2366 seq_printf(seq, "Basic info: size of leaf: %Zd bytes, size of tnode: %Zd bytes.\n", 2266 return 0;
2367 sizeof(struct leaf), sizeof(struct tnode));
2368 if (trie_local)
2369 collect_and_show(trie_local, seq);
2370 2267
2371 if (trie_main) 2268 if (IS_TNODE(n)) {
2372 collect_and_show(trie_main, seq); 2269 struct tnode *tn = (struct tnode *) n;
2373 } else { 2270 t_key prf = ntohl(MASK_PFX(tn->key, tn->pos));
2374 snprintf(bf, sizeof(bf), "*\t%08X\t%08X", 200, 400);
2375 2271
2376 seq_printf(seq, "%-127s\n", bf); 2272 if (!NODE_PARENT(n)) {
2273 if (iter->trie == trie_local)
2274 seq_puts(seq, "<local>:\n");
2275 else
2276 seq_puts(seq, "<main>:\n");
2277 } else {
2278 seq_indent(seq, iter->depth-1);
2279 seq_printf(seq, " +-- %d.%d.%d.%d/%d\n",
2280 NIPQUAD(prf), tn->pos);
2281 }
2282 } else {
2283 struct leaf *l = (struct leaf *) n;
2284 int i;
2285 u32 val = ntohl(l->key);
2286
2287 seq_indent(seq, iter->depth);
2288 seq_printf(seq, " |-- %d.%d.%d.%d\n", NIPQUAD(val));
2289 for (i = 32; i >= 0; i--) {
2290 struct leaf_info *li = find_leaf_info(&l->list, i);
2291 if (li) {
2292 struct fib_alias *fa;
2293 list_for_each_entry_rcu(fa, &li->falh, fa_list) {
2294 seq_indent(seq, iter->depth+1);
2295 seq_printf(seq, " /%d %s %s", i,
2296 rtn_scope(fa->fa_scope),
2297 rtn_type(fa->fa_type));
2298 if (fa->fa_tos)
2299 seq_printf(seq, "tos =%d\n",
2300 fa->fa_tos);
2301 seq_putc(seq, '\n');
2302 }
2303 }
2304 }
2377 } 2305 }
2306
2378 return 0; 2307 return 0;
2379} 2308}
2380 2309
2381static struct seq_operations fib_triestat_seq_ops = { 2310static struct seq_operations fib_trie_seq_ops = {
2382 .start = fib_triestat_seq_start, 2311 .start = fib_trie_seq_start,
2383 .next = fib_triestat_seq_next, 2312 .next = fib_trie_seq_next,
2384 .stop = fib_triestat_seq_stop, 2313 .stop = fib_trie_seq_stop,
2385 .show = fib_triestat_seq_show, 2314 .show = fib_trie_seq_show,
2386}; 2315};
2387 2316
2388static int fib_triestat_seq_open(struct inode *inode, struct file *file) 2317static int fib_trie_seq_open(struct inode *inode, struct file *file)
2389{ 2318{
2390 struct seq_file *seq; 2319 struct seq_file *seq;
2391 int rc = -ENOMEM; 2320 int rc = -ENOMEM;
2321 struct fib_trie_iter *s = kmalloc(sizeof(*s), GFP_KERNEL);
2392 2322
2393 rc = seq_open(file, &fib_triestat_seq_ops); 2323 if (!s)
2324 goto out;
2325
2326 rc = seq_open(file, &fib_trie_seq_ops);
2394 if (rc) 2327 if (rc)
2395 goto out_kfree; 2328 goto out_kfree;
2396 2329
2397 seq = file->private_data; 2330 seq = file->private_data;
2331 seq->private = s;
2332 memset(s, 0, sizeof(*s));
2398out: 2333out:
2399 return rc; 2334 return rc;
2400out_kfree: 2335out_kfree:
2336 kfree(s);
2401 goto out; 2337 goto out;
2402} 2338}
2403 2339
2404static struct file_operations fib_triestat_seq_fops = { 2340static struct file_operations fib_trie_fops = {
2405 .owner = THIS_MODULE, 2341 .owner = THIS_MODULE,
2406 .open = fib_triestat_seq_open, 2342 .open = fib_trie_seq_open,
2407 .read = seq_read, 2343 .read = seq_read,
2408 .llseek = seq_lseek, 2344 .llseek = seq_lseek,
2409 .release = seq_release_private, 2345 .release = seq_release_private,
2410}; 2346};
2411 2347
2412int __init fib_stat_proc_init(void) 2348static unsigned fib_flag_trans(int type, u32 mask, const struct fib_info *fi)
2413{
2414 if (!proc_net_fops_create("fib_triestat", S_IRUGO, &fib_triestat_seq_fops))
2415 return -ENOMEM;
2416 return 0;
2417}
2418
2419void __init fib_stat_proc_exit(void)
2420{ 2349{
2421 proc_net_remove("fib_triestat"); 2350 static unsigned type2flags[RTN_MAX + 1] = {
2422} 2351 [7] = RTF_REJECT, [8] = RTF_REJECT,
2352 };
2353 unsigned flags = type2flags[type];
2423 2354
2424static struct fib_alias *fib_trie_get_first(struct seq_file *seq) 2355 if (fi && fi->fib_nh->nh_gw)
2425{ 2356 flags |= RTF_GATEWAY;
2426 return NULL; 2357 if (mask == 0xFFFFFFFF)
2358 flags |= RTF_HOST;
2359 flags |= RTF_UP;
2360 return flags;
2427} 2361}
2428 2362
2429static struct fib_alias *fib_trie_get_next(struct seq_file *seq) 2363/*
2364 * This outputs /proc/net/route.
2365 * The format of the file is not supposed to be changed
2366 * and needs to be same as fib_hash output to avoid breaking
2367 * legacy utilities
2368 */
2369static int fib_route_seq_show(struct seq_file *seq, void *v)
2430{ 2370{
2431 return NULL; 2371 struct leaf *l = v;
2432} 2372 int i;
2373 char bf[128];
2433 2374
2434static void *fib_trie_seq_start(struct seq_file *seq, loff_t *pos) 2375 if (v == SEQ_START_TOKEN) {
2435{ 2376 seq_printf(seq, "%-127s\n", "Iface\tDestination\tGateway "
2436 if (!ip_fib_main_table) 2377 "\tFlags\tRefCnt\tUse\tMetric\tMask\t\tMTU"
2437 return NULL; 2378 "\tWindow\tIRTT");
2379 return 0;
2380 }
2438 2381
2439 if (*pos) 2382 if (IS_TNODE(l))
2440 return fib_trie_get_next(seq); 2383 return 0;
2441 else
2442 return SEQ_START_TOKEN;
2443}
2444 2384
2445static void *fib_trie_seq_next(struct seq_file *seq, void *v, loff_t *pos) 2385 for (i=32; i>=0; i--) {
2446{ 2386 struct leaf_info *li = find_leaf_info(&l->list, i);
2447 ++*pos; 2387 struct fib_alias *fa;
2448 if (v == SEQ_START_TOKEN) 2388 u32 mask, prefix;
2449 return fib_trie_get_first(seq);
2450 else
2451 return fib_trie_get_next(seq);
2452 2389
2453} 2390 if (!li)
2391 continue;
2454 2392
2455static void fib_trie_seq_stop(struct seq_file *seq, void *v) 2393 mask = inet_make_mask(li->plen);
2456{ 2394 prefix = htonl(l->key);
2457}
2458 2395
2459/* 2396 list_for_each_entry_rcu(fa, &li->falh, fa_list) {
2460 * This outputs /proc/net/fib_trie. 2397 const struct fib_info *fi = rcu_dereference(fa->fa_info);
2461 * 2398 unsigned flags = fib_flag_trans(fa->fa_type, mask, fi);
2462 * It always works in backward compatibility mode.
2463 * The format of the file is not supposed to be changed.
2464 */
2465 2399
2466static int fib_trie_seq_show(struct seq_file *seq, void *v) 2400 if (fa->fa_type == RTN_BROADCAST
2467{ 2401 || fa->fa_type == RTN_MULTICAST)
2468 char bf[128]; 2402 continue;
2469 2403
2470 if (v == SEQ_START_TOKEN) { 2404 if (fi)
2471 if (trie_local) 2405 snprintf(bf, sizeof(bf),
2472 trie_dump_seq(seq, trie_local); 2406 "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u",
2407 fi->fib_dev ? fi->fib_dev->name : "*",
2408 prefix,
2409 fi->fib_nh->nh_gw, flags, 0, 0,
2410 fi->fib_priority,
2411 mask,
2412 (fi->fib_advmss ? fi->fib_advmss + 40 : 0),
2413 fi->fib_window,
2414 fi->fib_rtt >> 3);
2415 else
2416 snprintf(bf, sizeof(bf),
2417 "*\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u",
2418 prefix, 0, flags, 0, 0, 0,
2419 mask, 0, 0, 0);
2473 2420
2474 if (trie_main) 2421 seq_printf(seq, "%-127s\n", bf);
2475 trie_dump_seq(seq, trie_main); 2422 }
2476 } else {
2477 snprintf(bf, sizeof(bf),
2478 "*\t%08X\t%08X", 200, 400);
2479 seq_printf(seq, "%-127s\n", bf);
2480 } 2423 }
2481 2424
2482 return 0; 2425 return 0;
2483} 2426}
2484 2427
2485static struct seq_operations fib_trie_seq_ops = { 2428static struct seq_operations fib_route_seq_ops = {
2486 .start = fib_trie_seq_start, 2429 .start = fib_trie_seq_start,
2487 .next = fib_trie_seq_next, 2430 .next = fib_trie_seq_next,
2488 .stop = fib_trie_seq_stop, 2431 .stop = fib_trie_seq_stop,
2489 .show = fib_trie_seq_show, 2432 .show = fib_route_seq_show,
2490}; 2433};
2491 2434
2492static int fib_trie_seq_open(struct inode *inode, struct file *file) 2435static int fib_route_seq_open(struct inode *inode, struct file *file)
2493{ 2436{
2494 struct seq_file *seq; 2437 struct seq_file *seq;
2495 int rc = -ENOMEM; 2438 int rc = -ENOMEM;
2439 struct fib_trie_iter *s = kmalloc(sizeof(*s), GFP_KERNEL);
2496 2440
2497 rc = seq_open(file, &fib_trie_seq_ops); 2441 if (!s)
2442 goto out;
2443
2444 rc = seq_open(file, &fib_route_seq_ops);
2498 if (rc) 2445 if (rc)
2499 goto out_kfree; 2446 goto out_kfree;
2500 2447
2501 seq = file->private_data; 2448 seq = file->private_data;
2449 seq->private = s;
2450 memset(s, 0, sizeof(*s));
2502out: 2451out:
2503 return rc; 2452 return rc;
2504out_kfree: 2453out_kfree:
2454 kfree(s);
2505 goto out; 2455 goto out;
2506} 2456}
2507 2457
2508static struct file_operations fib_trie_seq_fops = { 2458static struct file_operations fib_route_fops = {
2509 .owner = THIS_MODULE, 2459 .owner = THIS_MODULE,
2510 .open = fib_trie_seq_open, 2460 .open = fib_route_seq_open,
2511 .read = seq_read, 2461 .read = seq_read,
2512 .llseek = seq_lseek, 2462 .llseek = seq_lseek,
2513 .release= seq_release_private, 2463 .release = seq_release_private,
2514}; 2464};
2515 2465
2516int __init fib_proc_init(void) 2466int __init fib_proc_init(void)
2517{ 2467{
2518 if (!proc_net_fops_create("fib_trie", S_IRUGO, &fib_trie_seq_fops)) 2468 if (!proc_net_fops_create("fib_trie", S_IRUGO, &fib_trie_fops))
2519 return -ENOMEM; 2469 goto out1;
2470
2471 if (!proc_net_fops_create("fib_triestat", S_IRUGO, &fib_triestat_fops))
2472 goto out2;
2473
2474 if (!proc_net_fops_create("route", S_IRUGO, &fib_route_fops))
2475 goto out3;
2476
2520 return 0; 2477 return 0;
2478
2479out3:
2480 proc_net_remove("fib_triestat");
2481out2:
2482 proc_net_remove("fib_trie");
2483out1:
2484 return -ENOMEM;
2521} 2485}
2522 2486
2523void __init fib_proc_exit(void) 2487void __init fib_proc_exit(void)
2524{ 2488{
2525 proc_net_remove("fib_trie"); 2489 proc_net_remove("fib_trie");
2490 proc_net_remove("fib_triestat");
2491 proc_net_remove("route");
2526} 2492}
2527 2493
2528#endif /* CONFIG_PROC_FS */ 2494#endif /* CONFIG_PROC_FS */
diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index f84ba9c965..2fc3fd3892 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -100,8 +100,7 @@ DEFINE_SPINLOCK(inet_peer_unused_lock);
100#define PEER_MAX_CLEANUP_WORK 30 100#define PEER_MAX_CLEANUP_WORK 30
101 101
102static void peer_check_expire(unsigned long dummy); 102static void peer_check_expire(unsigned long dummy);
103static struct timer_list peer_periodic_timer = 103static DEFINE_TIMER(peer_periodic_timer, peer_check_expire, 0, 0);
104 TIMER_INITIALIZER(peer_check_expire, 0, 0);
105 104
106/* Exported for sysctl_net_ipv4. */ 105/* Exported for sysctl_net_ipv4. */
107int inet_peer_gc_mintime = 10 * HZ, 106int inet_peer_gc_mintime = 10 * HZ,
diff --git a/net/ipv4/netfilter/ipt_owner.c b/net/ipv4/netfilter/ipt_owner.c
index c1889f8826..0cee2862ed 100644
--- a/net/ipv4/netfilter/ipt_owner.c
+++ b/net/ipv4/netfilter/ipt_owner.c
@@ -11,6 +11,7 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/skbuff.h> 12#include <linux/skbuff.h>
13#include <linux/file.h> 13#include <linux/file.h>
14#include <linux/rcupdate.h>
14#include <net/sock.h> 15#include <net/sock.h>
15 16
16#include <linux/netfilter_ipv4/ipt_owner.h> 17#include <linux/netfilter_ipv4/ipt_owner.h>
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 15e1134da1..c10e4435e3 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -485,11 +485,6 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len, unsigned int mss
485 TCP_SKB_CB(buff)->when = TCP_SKB_CB(skb)->when; 485 TCP_SKB_CB(buff)->when = TCP_SKB_CB(skb)->when;
486 buff->tstamp = skb->tstamp; 486 buff->tstamp = skb->tstamp;
487 487
488 if (TCP_SKB_CB(skb)->sacked & TCPCB_LOST) {
489 tp->lost_out -= tcp_skb_pcount(skb);
490 tp->left_out -= tcp_skb_pcount(skb);
491 }
492
493 old_factor = tcp_skb_pcount(skb); 488 old_factor = tcp_skb_pcount(skb);
494 489
495 /* Fix up tso_factor for both original and new SKB. */ 490 /* Fix up tso_factor for both original and new SKB. */
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 6d6fb74f3b..2fea3f4402 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -123,8 +123,7 @@ DEFINE_RWLOCK(addrconf_lock);
123 123
124static void addrconf_verify(unsigned long); 124static void addrconf_verify(unsigned long);
125 125
126static struct timer_list addr_chk_timer = 126static DEFINE_TIMER(addr_chk_timer, addrconf_verify, 0, 0);
127 TIMER_INITIALIZER(addrconf_verify, 0, 0);
128static DEFINE_SPINLOCK(addrconf_verify_lock); 127static DEFINE_SPINLOCK(addrconf_verify_lock);
129 128
130static void addrconf_join_anycast(struct inet6_ifaddr *ifp); 129static void addrconf_join_anycast(struct inet6_ifaddr *ifp);
diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c
index 4712272821..922549581a 100644
--- a/net/ipv6/exthdrs.c
+++ b/net/ipv6/exthdrs.c
@@ -406,8 +406,7 @@ ipv6_invert_rthdr(struct sock *sk, struct ipv6_rt_hdr *hdr)
406 406
407 memcpy(opt->srcrt, hdr, sizeof(*hdr)); 407 memcpy(opt->srcrt, hdr, sizeof(*hdr));
408 irthdr = (struct rt0_hdr*)opt->srcrt; 408 irthdr = (struct rt0_hdr*)opt->srcrt;
409 /* Obsolete field, MBZ, when originated by us */ 409 irthdr->reserved = 0;
410 irthdr->bitmap = 0;
411 opt->srcrt->segments_left = n; 410 opt->srcrt->segments_left = n;
412 for (i=0; i<n; i++) 411 for (i=0; i<n; i++)
413 memcpy(irthdr->addr+i, rthdr->addr+(n-1-i), 16); 412 memcpy(irthdr->addr+i, rthdr->addr+(n-1-i), 16);
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 16af874c9e..4fcc5a7acf 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -92,7 +92,7 @@ static struct fib6_node * fib6_repair_tree(struct fib6_node *fn);
92 92
93static __u32 rt_sernum; 93static __u32 rt_sernum;
94 94
95static struct timer_list ip6_fib_timer = TIMER_INITIALIZER(fib6_run_gc, 0, 0); 95static DEFINE_TIMER(ip6_fib_timer, fib6_run_gc, 0, 0);
96 96
97struct fib6_walker_t fib6_walker_list = { 97struct fib6_walker_t fib6_walker_list = {
98 .prev = &fib6_walker_list, 98 .prev = &fib6_walker_list,
diff --git a/net/ipv6/ip6_flowlabel.c b/net/ipv6/ip6_flowlabel.c
index a7db762de1..f841bde30c 100644
--- a/net/ipv6/ip6_flowlabel.c
+++ b/net/ipv6/ip6_flowlabel.c
@@ -50,7 +50,7 @@ static atomic_t fl_size = ATOMIC_INIT(0);
50static struct ip6_flowlabel *fl_ht[FL_HASH_MASK+1]; 50static struct ip6_flowlabel *fl_ht[FL_HASH_MASK+1];
51 51
52static void ip6_fl_gc(unsigned long dummy); 52static void ip6_fl_gc(unsigned long dummy);
53static struct timer_list ip6_fl_gc_timer = TIMER_INITIALIZER(ip6_fl_gc, 0, 0); 53static DEFINE_TIMER(ip6_fl_gc_timer, ip6_fl_gc, 0, 0);
54 54
55/* FL hash table lock: it protects only of GC */ 55/* FL hash table lock: it protects only of GC */
56 56
diff --git a/net/ipv6/netfilter/ip6t_owner.c b/net/ipv6/netfilter/ip6t_owner.c
index 9b91decbfd..4de4cdad4b 100644
--- a/net/ipv6/netfilter/ip6t_owner.c
+++ b/net/ipv6/netfilter/ip6t_owner.c
@@ -11,6 +11,7 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/skbuff.h> 12#include <linux/skbuff.h>
13#include <linux/file.h> 13#include <linux/file.h>
14#include <linux/rcupdate.h>
14#include <net/sock.h> 15#include <net/sock.h>
15 16
16#include <linux/netfilter_ipv6/ip6t_owner.h> 17#include <linux/netfilter_ipv6/ip6t_owner.h>
diff --git a/net/ipv6/netfilter/ip6t_rt.c b/net/ipv6/netfilter/ip6t_rt.c
index a9526b773d..2bb670037d 100644
--- a/net/ipv6/netfilter/ip6t_rt.c
+++ b/net/ipv6/netfilter/ip6t_rt.c
@@ -161,8 +161,8 @@ match(const struct sk_buff *skb,
161 ((rtinfo->hdrlen == hdrlen) ^ 161 ((rtinfo->hdrlen == hdrlen) ^
162 !!(rtinfo->invflags & IP6T_RT_INV_LEN)))); 162 !!(rtinfo->invflags & IP6T_RT_INV_LEN))));
163 DEBUGP("res %02X %02X %02X ", 163 DEBUGP("res %02X %02X %02X ",
164 (rtinfo->flags & IP6T_RT_RES), ((struct rt0_hdr *)rh)->bitmap, 164 (rtinfo->flags & IP6T_RT_RES), ((struct rt0_hdr *)rh)->reserved,
165 !((rtinfo->flags & IP6T_RT_RES) && (((struct rt0_hdr *)rh)->bitmap))); 165 !((rtinfo->flags & IP6T_RT_RES) && (((struct rt0_hdr *)rh)->reserved)));
166 166
167 ret = (rh != NULL) 167 ret = (rh != NULL)
168 && 168 &&
@@ -179,12 +179,12 @@ match(const struct sk_buff *skb,
179 !!(rtinfo->invflags & IP6T_RT_INV_TYP))); 179 !!(rtinfo->invflags & IP6T_RT_INV_TYP)));
180 180
181 if (ret && (rtinfo->flags & IP6T_RT_RES)) { 181 if (ret && (rtinfo->flags & IP6T_RT_RES)) {
182 u_int32_t *bp, _bitmap; 182 u_int32_t *rp, _reserved;
183 bp = skb_header_pointer(skb, 183 rp = skb_header_pointer(skb,
184 ptr + offsetof(struct rt0_hdr, bitmap), 184 ptr + offsetof(struct rt0_hdr, reserved),
185 sizeof(_bitmap), &_bitmap); 185 sizeof(_reserved), &_reserved);
186 186
187 ret = (*bp == 0); 187 ret = (*rp == 0);
188 } 188 }
189 189
190 DEBUGP("#%d ",rtinfo->addrnr); 190 DEBUGP("#%d ",rtinfo->addrnr);
diff --git a/net/netrom/nr_loopback.c b/net/netrom/nr_loopback.c
index 165b2abce1..e856ae1b36 100644
--- a/net/netrom/nr_loopback.c
+++ b/net/netrom/nr_loopback.c
@@ -17,7 +17,7 @@
17static void nr_loopback_timer(unsigned long); 17static void nr_loopback_timer(unsigned long);
18 18
19static struct sk_buff_head loopback_queue; 19static struct sk_buff_head loopback_queue;
20static struct timer_list loopback_timer = TIMER_INITIALIZER(nr_loopback_timer, 0, 0); 20static DEFINE_TIMER(loopback_timer, nr_loopback_timer, 0, 0);
21 21
22void __init nr_loopback_init(void) 22void __init nr_loopback_init(void)
23{ 23{
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 737681cb9a..31570b9a6e 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -1194,7 +1194,7 @@ EXPORT_SYMBOL(psched_time_base);
1194 * with 32-bit get_cycles(). Safe up to 4GHz CPU. 1194 * with 32-bit get_cycles(). Safe up to 4GHz CPU.
1195 */ 1195 */
1196static void psched_tick(unsigned long); 1196static void psched_tick(unsigned long);
1197static struct timer_list psched_timer = TIMER_INITIALIZER(psched_tick, 0, 0); 1197static DEFINE_TIMER(psched_timer, psched_tick, 0, 0);
1198 1198
1199static void psched_tick(unsigned long dummy) 1199static void psched_tick(unsigned long dummy)
1200{ 1200{
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 9087273abf..db3c708e54 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -49,6 +49,9 @@ build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
49cmd = @$(if $($(quiet)cmd_$(1)),\ 49cmd = @$(if $($(quiet)cmd_$(1)),\
50 echo ' $(subst ','\'',$($(quiet)cmd_$(1)))' &&) $(cmd_$(1)) 50 echo ' $(subst ','\'',$($(quiet)cmd_$(1)))' &&) $(cmd_$(1))
51 51
52# Add $(obj)/ for paths that is not absolute
53objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
54
52### 55###
53# if_changed - execute command if any prerequisite is newer than 56# if_changed - execute command if any prerequisite is newer than
54# target, or command line has changed 57# target, or command line has changed
diff --git a/scripts/reference_discarded.pl b/scripts/reference_discarded.pl
index f04f627368..c2d54148a9 100644
--- a/scripts/reference_discarded.pl
+++ b/scripts/reference_discarded.pl
@@ -91,12 +91,7 @@ foreach $object (keys(%object)) {
91 $from !~ /\.exit\.data$/ && 91 $from !~ /\.exit\.data$/ &&
92 $from !~ /\.altinstructions$/ && 92 $from !~ /\.altinstructions$/ &&
93 $from !~ /\.pdr$/ && 93 $from !~ /\.pdr$/ &&
94 $from !~ /\.debug_info$/ && 94 $from !~ /\.debug_.*$/ &&
95 $from !~ /\.debug_aranges$/ &&
96 $from !~ /\.debug_ranges$/ &&
97 $from !~ /\.debug_line$/ &&
98 $from !~ /\.debug_frame$/ &&
99 $from !~ /\.debug_loc$/ &&
100 $from !~ /\.exitcall\.exit$/ && 95 $from !~ /\.exitcall\.exit$/ &&
101 $from !~ /\.eh_frame$/ && 96 $from !~ /\.eh_frame$/ &&
102 $from !~ /\.stab$/)) { 97 $from !~ /\.stab$/)) {
diff --git a/security/dummy.c b/security/dummy.c
index 6ff8875864..9623a61dfc 100644
--- a/security/dummy.c
+++ b/security/dummy.c
@@ -258,16 +258,16 @@ static void dummy_inode_free_security (struct inode *inode)
258 return; 258 return;
259} 259}
260 260
261static int dummy_inode_create (struct inode *inode, struct dentry *dentry, 261static int dummy_inode_init_security (struct inode *inode, struct inode *dir,
262 int mask) 262 char **name, void **value, size_t *len)
263{ 263{
264 return 0; 264 return -EOPNOTSUPP;
265} 265}
266 266
267static void dummy_inode_post_create (struct inode *inode, struct dentry *dentry, 267static int dummy_inode_create (struct inode *inode, struct dentry *dentry,
268 int mask) 268 int mask)
269{ 269{
270 return; 270 return 0;
271} 271}
272 272
273static int dummy_inode_link (struct dentry *old_dentry, struct inode *inode, 273static int dummy_inode_link (struct dentry *old_dentry, struct inode *inode,
@@ -276,13 +276,6 @@ static int dummy_inode_link (struct dentry *old_dentry, struct inode *inode,
276 return 0; 276 return 0;
277} 277}
278 278
279static void dummy_inode_post_link (struct dentry *old_dentry,
280 struct inode *inode,
281 struct dentry *new_dentry)
282{
283 return;
284}
285
286static int dummy_inode_unlink (struct inode *inode, struct dentry *dentry) 279static int dummy_inode_unlink (struct inode *inode, struct dentry *dentry)
287{ 280{
288 return 0; 281 return 0;
@@ -294,24 +287,12 @@ static int dummy_inode_symlink (struct inode *inode, struct dentry *dentry,
294 return 0; 287 return 0;
295} 288}
296 289
297static void dummy_inode_post_symlink (struct inode *inode,
298 struct dentry *dentry, const char *name)
299{
300 return;
301}
302
303static int dummy_inode_mkdir (struct inode *inode, struct dentry *dentry, 290static int dummy_inode_mkdir (struct inode *inode, struct dentry *dentry,
304 int mask) 291 int mask)
305{ 292{
306 return 0; 293 return 0;
307} 294}
308 295
309static void dummy_inode_post_mkdir (struct inode *inode, struct dentry *dentry,
310 int mask)
311{
312 return;
313}
314
315static int dummy_inode_rmdir (struct inode *inode, struct dentry *dentry) 296static int dummy_inode_rmdir (struct inode *inode, struct dentry *dentry)
316{ 297{
317 return 0; 298 return 0;
@@ -323,12 +304,6 @@ static int dummy_inode_mknod (struct inode *inode, struct dentry *dentry,
323 return 0; 304 return 0;
324} 305}
325 306
326static void dummy_inode_post_mknod (struct inode *inode, struct dentry *dentry,
327 int mode, dev_t dev)
328{
329 return;
330}
331
332static int dummy_inode_rename (struct inode *old_inode, 307static int dummy_inode_rename (struct inode *old_inode,
333 struct dentry *old_dentry, 308 struct dentry *old_dentry,
334 struct inode *new_inode, 309 struct inode *new_inode,
@@ -337,14 +312,6 @@ static int dummy_inode_rename (struct inode *old_inode,
337 return 0; 312 return 0;
338} 313}
339 314
340static void dummy_inode_post_rename (struct inode *old_inode,
341 struct dentry *old_dentry,
342 struct inode *new_inode,
343 struct dentry *new_dentry)
344{
345 return;
346}
347
348static int dummy_inode_readlink (struct dentry *dentry) 315static int dummy_inode_readlink (struct dentry *dentry)
349{ 316{
350 return 0; 317 return 0;
@@ -886,20 +853,15 @@ void security_fixup_ops (struct security_operations *ops)
886 set_to_dummy_if_null(ops, sb_post_pivotroot); 853 set_to_dummy_if_null(ops, sb_post_pivotroot);
887 set_to_dummy_if_null(ops, inode_alloc_security); 854 set_to_dummy_if_null(ops, inode_alloc_security);
888 set_to_dummy_if_null(ops, inode_free_security); 855 set_to_dummy_if_null(ops, inode_free_security);
856 set_to_dummy_if_null(ops, inode_init_security);
889 set_to_dummy_if_null(ops, inode_create); 857 set_to_dummy_if_null(ops, inode_create);
890 set_to_dummy_if_null(ops, inode_post_create);
891 set_to_dummy_if_null(ops, inode_link); 858 set_to_dummy_if_null(ops, inode_link);
892 set_to_dummy_if_null(ops, inode_post_link);
893 set_to_dummy_if_null(ops, inode_unlink); 859 set_to_dummy_if_null(ops, inode_unlink);
894 set_to_dummy_if_null(ops, inode_symlink); 860 set_to_dummy_if_null(ops, inode_symlink);
895 set_to_dummy_if_null(ops, inode_post_symlink);
896 set_to_dummy_if_null(ops, inode_mkdir); 861 set_to_dummy_if_null(ops, inode_mkdir);
897 set_to_dummy_if_null(ops, inode_post_mkdir);
898 set_to_dummy_if_null(ops, inode_rmdir); 862 set_to_dummy_if_null(ops, inode_rmdir);
899 set_to_dummy_if_null(ops, inode_mknod); 863 set_to_dummy_if_null(ops, inode_mknod);
900 set_to_dummy_if_null(ops, inode_post_mknod);
901 set_to_dummy_if_null(ops, inode_rename); 864 set_to_dummy_if_null(ops, inode_rename);
902 set_to_dummy_if_null(ops, inode_post_rename);
903 set_to_dummy_if_null(ops, inode_readlink); 865 set_to_dummy_if_null(ops, inode_readlink);
904 set_to_dummy_if_null(ops, inode_follow_link); 866 set_to_dummy_if_null(ops, inode_follow_link);
905 set_to_dummy_if_null(ops, inode_permission); 867 set_to_dummy_if_null(ops, inode_permission);
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 8641f8894b..f40c8221ec 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -1265,85 +1265,6 @@ static int inode_security_set_sid(struct inode *inode, u32 sid)
1265 return 0; 1265 return 0;
1266} 1266}
1267 1267
1268/* Set the security attributes on a newly created file. */
1269static int post_create(struct inode *dir,
1270 struct dentry *dentry)
1271{
1272
1273 struct task_security_struct *tsec;
1274 struct inode *inode;
1275 struct inode_security_struct *dsec;
1276 struct superblock_security_struct *sbsec;
1277 u32 newsid;
1278 char *context;
1279 unsigned int len;
1280 int rc;
1281
1282 tsec = current->security;
1283 dsec = dir->i_security;
1284 sbsec = dir->i_sb->s_security;
1285
1286 inode = dentry->d_inode;
1287 if (!inode) {
1288 /* Some file system types (e.g. NFS) may not instantiate
1289 a dentry for all create operations (e.g. symlink),
1290 so we have to check to see if the inode is non-NULL. */
1291 printk(KERN_WARNING "post_create: no inode, dir (dev=%s, "
1292 "ino=%ld)\n", dir->i_sb->s_id, dir->i_ino);
1293 return 0;
1294 }
1295
1296 if (tsec->create_sid && sbsec->behavior != SECURITY_FS_USE_MNTPOINT) {
1297 newsid = tsec->create_sid;
1298 } else {
1299 rc = security_transition_sid(tsec->sid, dsec->sid,
1300 inode_mode_to_security_class(inode->i_mode),
1301 &newsid);
1302 if (rc) {
1303 printk(KERN_WARNING "post_create: "
1304 "security_transition_sid failed, rc=%d (dev=%s "
1305 "ino=%ld)\n",
1306 -rc, inode->i_sb->s_id, inode->i_ino);
1307 return rc;
1308 }
1309 }
1310
1311 rc = inode_security_set_sid(inode, newsid);
1312 if (rc) {
1313 printk(KERN_WARNING "post_create: inode_security_set_sid "
1314 "failed, rc=%d (dev=%s ino=%ld)\n",
1315 -rc, inode->i_sb->s_id, inode->i_ino);
1316 return rc;
1317 }
1318
1319 if (sbsec->behavior == SECURITY_FS_USE_XATTR &&
1320 inode->i_op->setxattr) {
1321 /* Use extended attributes. */
1322 rc = security_sid_to_context(newsid, &context, &len);
1323 if (rc) {
1324 printk(KERN_WARNING "post_create: sid_to_context "
1325 "failed, rc=%d (dev=%s ino=%ld)\n",
1326 -rc, inode->i_sb->s_id, inode->i_ino);
1327 return rc;
1328 }
1329 down(&inode->i_sem);
1330 rc = inode->i_op->setxattr(dentry,
1331 XATTR_NAME_SELINUX,
1332 context, len, 0);
1333 up(&inode->i_sem);
1334 kfree(context);
1335 if (rc < 0) {
1336 printk(KERN_WARNING "post_create: setxattr failed, "
1337 "rc=%d (dev=%s ino=%ld)\n",
1338 -rc, inode->i_sb->s_id, inode->i_ino);
1339 return rc;
1340 }
1341 }
1342
1343 return 0;
1344}
1345
1346
1347/* Hook functions begin here. */ 1268/* Hook functions begin here. */
1348 1269
1349static int selinux_ptrace(struct task_struct *parent, struct task_struct *child) 1270static int selinux_ptrace(struct task_struct *parent, struct task_struct *child)
@@ -1673,6 +1594,7 @@ static inline void flush_unauthorized_files(struct files_struct * files)
1673 struct avc_audit_data ad; 1594 struct avc_audit_data ad;
1674 struct file *file, *devnull = NULL; 1595 struct file *file, *devnull = NULL;
1675 struct tty_struct *tty = current->signal->tty; 1596 struct tty_struct *tty = current->signal->tty;
1597 struct fdtable *fdt;
1676 long j = -1; 1598 long j = -1;
1677 1599
1678 if (tty) { 1600 if (tty) {
@@ -1706,9 +1628,10 @@ static inline void flush_unauthorized_files(struct files_struct * files)
1706 1628
1707 j++; 1629 j++;
1708 i = j * __NFDBITS; 1630 i = j * __NFDBITS;
1709 if (i >= files->max_fds || i >= files->max_fdset) 1631 fdt = files_fdtable(files);
1632 if (i >= fdt->max_fds || i >= fdt->max_fdset)
1710 break; 1633 break;
1711 set = files->open_fds->fds_bits[j]; 1634 set = fdt->open_fds->fds_bits[j];
1712 if (!set) 1635 if (!set)
1713 continue; 1636 continue;
1714 spin_unlock(&files->file_lock); 1637 spin_unlock(&files->file_lock);
@@ -1729,7 +1652,7 @@ static inline void flush_unauthorized_files(struct files_struct * files)
1729 continue; 1652 continue;
1730 } 1653 }
1731 if (devnull) { 1654 if (devnull) {
1732 atomic_inc(&devnull->f_count); 1655 rcuref_inc(&devnull->f_count);
1733 } else { 1656 } else {
1734 devnull = dentry_open(dget(selinux_null), mntget(selinuxfs_mount), O_RDWR); 1657 devnull = dentry_open(dget(selinux_null), mntget(selinuxfs_mount), O_RDWR);
1735 if (!devnull) { 1658 if (!devnull) {
@@ -2018,14 +1941,64 @@ static void selinux_inode_free_security(struct inode *inode)
2018 inode_free_security(inode); 1941 inode_free_security(inode);
2019} 1942}
2020 1943
2021static int selinux_inode_create(struct inode *dir, struct dentry *dentry, int mask) 1944static int selinux_inode_init_security(struct inode *inode, struct inode *dir,
1945 char **name, void **value,
1946 size_t *len)
2022{ 1947{
2023 return may_create(dir, dentry, SECCLASS_FILE); 1948 struct task_security_struct *tsec;
1949 struct inode_security_struct *dsec;
1950 struct superblock_security_struct *sbsec;
1951 struct inode_security_struct *isec;
1952 u32 newsid, clen;
1953 int rc;
1954 char *namep = NULL, *context;
1955
1956 tsec = current->security;
1957 dsec = dir->i_security;
1958 sbsec = dir->i_sb->s_security;
1959 isec = inode->i_security;
1960
1961 if (tsec->create_sid && sbsec->behavior != SECURITY_FS_USE_MNTPOINT) {
1962 newsid = tsec->create_sid;
1963 } else {
1964 rc = security_transition_sid(tsec->sid, dsec->sid,
1965 inode_mode_to_security_class(inode->i_mode),
1966 &newsid);
1967 if (rc) {
1968 printk(KERN_WARNING "%s: "
1969 "security_transition_sid failed, rc=%d (dev=%s "
1970 "ino=%ld)\n",
1971 __FUNCTION__,
1972 -rc, inode->i_sb->s_id, inode->i_ino);
1973 return rc;
1974 }
1975 }
1976
1977 inode_security_set_sid(inode, newsid);
1978
1979 if (name) {
1980 namep = kstrdup(XATTR_SELINUX_SUFFIX, GFP_KERNEL);
1981 if (!namep)
1982 return -ENOMEM;
1983 *name = namep;
1984 }
1985
1986 if (value && len) {
1987 rc = security_sid_to_context(newsid, &context, &clen);
1988 if (rc) {
1989 kfree(namep);
1990 return rc;
1991 }
1992 *value = context;
1993 *len = clen;
1994 }
1995
1996 return 0;
2024} 1997}
2025 1998
2026static void selinux_inode_post_create(struct inode *dir, struct dentry *dentry, int mask) 1999static int selinux_inode_create(struct inode *dir, struct dentry *dentry, int mask)
2027{ 2000{
2028 post_create(dir, dentry); 2001 return may_create(dir, dentry, SECCLASS_FILE);
2029} 2002}
2030 2003
2031static int selinux_inode_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry) 2004static int selinux_inode_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry)
@@ -2038,11 +2011,6 @@ static int selinux_inode_link(struct dentry *old_dentry, struct inode *dir, stru
2038 return may_link(dir, old_dentry, MAY_LINK); 2011 return may_link(dir, old_dentry, MAY_LINK);
2039} 2012}
2040 2013
2041static void selinux_inode_post_link(struct dentry *old_dentry, struct inode *inode, struct dentry *new_dentry)
2042{
2043 return;
2044}
2045
2046static int selinux_inode_unlink(struct inode *dir, struct dentry *dentry) 2014static int selinux_inode_unlink(struct inode *dir, struct dentry *dentry)
2047{ 2015{
2048 int rc; 2016 int rc;
@@ -2058,21 +2026,11 @@ static int selinux_inode_symlink(struct inode *dir, struct dentry *dentry, const
2058 return may_create(dir, dentry, SECCLASS_LNK_FILE); 2026 return may_create(dir, dentry, SECCLASS_LNK_FILE);
2059} 2027}
2060 2028
2061static void selinux_inode_post_symlink(struct inode *dir, struct dentry *dentry, const char *name)
2062{
2063 post_create(dir, dentry);
2064}
2065
2066static int selinux_inode_mkdir(struct inode *dir, struct dentry *dentry, int mask) 2029static int selinux_inode_mkdir(struct inode *dir, struct dentry *dentry, int mask)
2067{ 2030{
2068 return may_create(dir, dentry, SECCLASS_DIR); 2031 return may_create(dir, dentry, SECCLASS_DIR);
2069} 2032}
2070 2033
2071static void selinux_inode_post_mkdir(struct inode *dir, struct dentry *dentry, int mask)
2072{
2073 post_create(dir, dentry);
2074}
2075
2076static int selinux_inode_rmdir(struct inode *dir, struct dentry *dentry) 2034static int selinux_inode_rmdir(struct inode *dir, struct dentry *dentry)
2077{ 2035{
2078 return may_link(dir, dentry, MAY_RMDIR); 2036 return may_link(dir, dentry, MAY_RMDIR);
@@ -2089,23 +2047,12 @@ static int selinux_inode_mknod(struct inode *dir, struct dentry *dentry, int mod
2089 return may_create(dir, dentry, inode_mode_to_security_class(mode)); 2047 return may_create(dir, dentry, inode_mode_to_security_class(mode));
2090} 2048}
2091 2049
2092static void selinux_inode_post_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
2093{
2094 post_create(dir, dentry);
2095}
2096
2097static int selinux_inode_rename(struct inode *old_inode, struct dentry *old_dentry, 2050static int selinux_inode_rename(struct inode *old_inode, struct dentry *old_dentry,
2098 struct inode *new_inode, struct dentry *new_dentry) 2051 struct inode *new_inode, struct dentry *new_dentry)
2099{ 2052{
2100 return may_rename(old_inode, old_dentry, new_inode, new_dentry); 2053 return may_rename(old_inode, old_dentry, new_inode, new_dentry);
2101} 2054}
2102 2055
2103static void selinux_inode_post_rename(struct inode *old_inode, struct dentry *old_dentry,
2104 struct inode *new_inode, struct dentry *new_dentry)
2105{
2106 return;
2107}
2108
2109static int selinux_inode_readlink(struct dentry *dentry) 2056static int selinux_inode_readlink(struct dentry *dentry)
2110{ 2057{
2111 return dentry_has_perm(current, NULL, dentry, FILE__READ); 2058 return dentry_has_perm(current, NULL, dentry, FILE__READ);
@@ -4298,20 +4245,15 @@ static struct security_operations selinux_ops = {
4298 4245
4299 .inode_alloc_security = selinux_inode_alloc_security, 4246 .inode_alloc_security = selinux_inode_alloc_security,
4300 .inode_free_security = selinux_inode_free_security, 4247 .inode_free_security = selinux_inode_free_security,
4248 .inode_init_security = selinux_inode_init_security,
4301 .inode_create = selinux_inode_create, 4249 .inode_create = selinux_inode_create,
4302 .inode_post_create = selinux_inode_post_create,
4303 .inode_link = selinux_inode_link, 4250 .inode_link = selinux_inode_link,
4304 .inode_post_link = selinux_inode_post_link,
4305 .inode_unlink = selinux_inode_unlink, 4251 .inode_unlink = selinux_inode_unlink,
4306 .inode_symlink = selinux_inode_symlink, 4252 .inode_symlink = selinux_inode_symlink,
4307 .inode_post_symlink = selinux_inode_post_symlink,
4308 .inode_mkdir = selinux_inode_mkdir, 4253 .inode_mkdir = selinux_inode_mkdir,
4309 .inode_post_mkdir = selinux_inode_post_mkdir,
4310 .inode_rmdir = selinux_inode_rmdir, 4254 .inode_rmdir = selinux_inode_rmdir,
4311 .inode_mknod = selinux_inode_mknod, 4255 .inode_mknod = selinux_inode_mknod,
4312 .inode_post_mknod = selinux_inode_post_mknod,
4313 .inode_rename = selinux_inode_rename, 4256 .inode_rename = selinux_inode_rename,
4314 .inode_post_rename = selinux_inode_post_rename,
4315 .inode_readlink = selinux_inode_readlink, 4257 .inode_readlink = selinux_inode_readlink,
4316 .inode_follow_link = selinux_inode_follow_link, 4258 .inode_follow_link = selinux_inode_follow_link,
4317 .inode_permission = selinux_inode_permission, 4259 .inode_permission = selinux_inode_permission,
diff --git a/sound/isa/sb/sb16_csp.c b/sound/isa/sb/sb16_csp.c
index b62920eead..d64790bcd8 100644
--- a/sound/isa/sb/sb16_csp.c
+++ b/sound/isa/sb/sb16_csp.c
@@ -42,8 +42,6 @@ MODULE_LICENSE("GPL");
42#else 42#else
43#define CSP_HDR_VALUE(a,b,c,d) ((d) | ((c)<<8) | ((b)<<16) | ((a)<<24)) 43#define CSP_HDR_VALUE(a,b,c,d) ((d) | ((c)<<8) | ((b)<<16) | ((a)<<24))
44#endif 44#endif
45#define LE_SHORT(v) le16_to_cpu(v)
46#define LE_INT(v) le32_to_cpu(v)
47 45
48#define RIFF_HEADER CSP_HDR_VALUE('R', 'I', 'F', 'F') 46#define RIFF_HEADER CSP_HDR_VALUE('R', 'I', 'F', 'F')
49#define CSP__HEADER CSP_HDR_VALUE('C', 'S', 'P', ' ') 47#define CSP__HEADER CSP_HDR_VALUE('C', 'S', 'P', ' ')
@@ -56,20 +54,20 @@ MODULE_LICENSE("GPL");
56/* 54/*
57 * RIFF data format 55 * RIFF data format
58 */ 56 */
59typedef struct riff_header { 57struct riff_header {
60 __u32 name; 58 __u32 name;
61 __u32 len; 59 __u32 len;
62} riff_header_t; 60};
63 61
64typedef struct desc_header { 62struct desc_header {
65 riff_header_t info; 63 struct riff_header info;
66 __u16 func_nr; 64 __u16 func_nr;
67 __u16 VOC_type; 65 __u16 VOC_type;
68 __u16 flags_play_rec; 66 __u16 flags_play_rec;
69 __u16 flags_16bit_8bit; 67 __u16 flags_16bit_8bit;
70 __u16 flags_stereo_mono; 68 __u16 flags_stereo_mono;
71 __u16 flags_rates; 69 __u16 flags_rates;
72} desc_header_t; 70};
73 71
74/* 72/*
75 * prototypes 73 * prototypes
@@ -302,9 +300,9 @@ static int snd_sb_csp_riff_load(snd_sb_csp_t * p, snd_sb_csp_microcode_t __user
302 unsigned char __user *data_end; 300 unsigned char __user *data_end;
303 unsigned short func_nr = 0; 301 unsigned short func_nr = 0;
304 302
305 riff_header_t file_h, item_h, code_h; 303 struct riff_header file_h, item_h, code_h;
306 __u32 item_type; 304 __u32 item_type;
307 desc_header_t funcdesc_h; 305 struct desc_header funcdesc_h;
308 306
309 unsigned long flags; 307 unsigned long flags;
310 int err; 308 int err;
@@ -316,12 +314,12 @@ static int snd_sb_csp_riff_load(snd_sb_csp_t * p, snd_sb_csp_microcode_t __user
316 if (copy_from_user(&file_h, data_ptr, sizeof(file_h))) 314 if (copy_from_user(&file_h, data_ptr, sizeof(file_h)))
317 return -EFAULT; 315 return -EFAULT;
318 if ((file_h.name != RIFF_HEADER) || 316 if ((file_h.name != RIFF_HEADER) ||
319 (LE_INT(file_h.len) >= SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE - sizeof(file_h))) { 317 (le32_to_cpu(file_h.len) >= SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE - sizeof(file_h))) {
320 snd_printd("%s: Invalid RIFF header\n", __FUNCTION__); 318 snd_printd("%s: Invalid RIFF header\n", __FUNCTION__);
321 return -EINVAL; 319 return -EINVAL;
322 } 320 }
323 data_ptr += sizeof(file_h); 321 data_ptr += sizeof(file_h);
324 data_end = data_ptr + LE_INT(file_h.len); 322 data_end = data_ptr + le32_to_cpu(file_h.len);
325 323
326 if (copy_from_user(&item_type, data_ptr, sizeof(item_type))) 324 if (copy_from_user(&item_type, data_ptr, sizeof(item_type)))
327 return -EFAULT; 325 return -EFAULT;
@@ -331,7 +329,7 @@ static int snd_sb_csp_riff_load(snd_sb_csp_t * p, snd_sb_csp_microcode_t __user
331 } 329 }
332 data_ptr += sizeof (item_type); 330 data_ptr += sizeof (item_type);
333 331
334 for (; data_ptr < data_end; data_ptr += LE_INT(item_h.len)) { 332 for (; data_ptr < data_end; data_ptr += le32_to_cpu(item_h.len)) {
335 if (copy_from_user(&item_h, data_ptr, sizeof(item_h))) 333 if (copy_from_user(&item_h, data_ptr, sizeof(item_h)))
336 return -EFAULT; 334 return -EFAULT;
337 data_ptr += sizeof(item_h); 335 data_ptr += sizeof(item_h);
@@ -344,7 +342,7 @@ static int snd_sb_csp_riff_load(snd_sb_csp_t * p, snd_sb_csp_microcode_t __user
344 case FUNC_HEADER: 342 case FUNC_HEADER:
345 if (copy_from_user(&funcdesc_h, data_ptr + sizeof(item_type), sizeof(funcdesc_h))) 343 if (copy_from_user(&funcdesc_h, data_ptr + sizeof(item_type), sizeof(funcdesc_h)))
346 return -EFAULT; 344 return -EFAULT;
347 func_nr = LE_SHORT(funcdesc_h.func_nr); 345 func_nr = le16_to_cpu(funcdesc_h.func_nr);
348 break; 346 break;
349 case CODE_HEADER: 347 case CODE_HEADER:
350 if (func_nr != info.func_req) 348 if (func_nr != info.func_req)
@@ -370,11 +368,11 @@ static int snd_sb_csp_riff_load(snd_sb_csp_t * p, snd_sb_csp_microcode_t __user
370 if (code_h.name != INIT_HEADER) 368 if (code_h.name != INIT_HEADER)
371 break; 369 break;
372 data_ptr += sizeof(code_h); 370 data_ptr += sizeof(code_h);
373 err = snd_sb_csp_load_user(p, data_ptr, LE_INT(code_h.len), 371 err = snd_sb_csp_load_user(p, data_ptr, le32_to_cpu(code_h.len),
374 SNDRV_SB_CSP_LOAD_INITBLOCK); 372 SNDRV_SB_CSP_LOAD_INITBLOCK);
375 if (err) 373 if (err)
376 return err; 374 return err;
377 data_ptr += LE_INT(code_h.len); 375 data_ptr += le32_to_cpu(code_h.len);
378 } 376 }
379 /* main microcode block */ 377 /* main microcode block */
380 if (copy_from_user(&code_h, data_ptr, sizeof(code_h))) 378 if (copy_from_user(&code_h, data_ptr, sizeof(code_h)))
@@ -386,17 +384,17 @@ static int snd_sb_csp_riff_load(snd_sb_csp_t * p, snd_sb_csp_microcode_t __user
386 } 384 }
387 data_ptr += sizeof(code_h); 385 data_ptr += sizeof(code_h);
388 err = snd_sb_csp_load_user(p, data_ptr, 386 err = snd_sb_csp_load_user(p, data_ptr,
389 LE_INT(code_h.len), 0); 387 le32_to_cpu(code_h.len), 0);
390 if (err) 388 if (err)
391 return err; 389 return err;
392 390
393 /* fill in codec header */ 391 /* fill in codec header */
394 strlcpy(p->codec_name, info.codec_name, sizeof(p->codec_name)); 392 strlcpy(p->codec_name, info.codec_name, sizeof(p->codec_name));
395 p->func_nr = func_nr; 393 p->func_nr = func_nr;
396 p->mode = LE_SHORT(funcdesc_h.flags_play_rec); 394 p->mode = le16_to_cpu(funcdesc_h.flags_play_rec);
397 switch (LE_SHORT(funcdesc_h.VOC_type)) { 395 switch (le16_to_cpu(funcdesc_h.VOC_type)) {
398 case 0x0001: /* QSound decoder */ 396 case 0x0001: /* QSound decoder */
399 if (LE_SHORT(funcdesc_h.flags_play_rec) == SNDRV_SB_CSP_MODE_DSP_WRITE) { 397 if (le16_to_cpu(funcdesc_h.flags_play_rec) == SNDRV_SB_CSP_MODE_DSP_WRITE) {
400 if (snd_sb_qsound_build(p) == 0) 398 if (snd_sb_qsound_build(p) == 0)
401 /* set QSound flag and clear all other mode flags */ 399 /* set QSound flag and clear all other mode flags */
402 p->mode = SNDRV_SB_CSP_MODE_QSOUND; 400 p->mode = SNDRV_SB_CSP_MODE_QSOUND;
@@ -426,12 +424,12 @@ static int snd_sb_csp_riff_load(snd_sb_csp_t * p, snd_sb_csp_microcode_t __user
426 p->mode = 0; 424 p->mode = 0;
427 snd_printd("%s: Unsupported CSP codec type: 0x%04x\n", 425 snd_printd("%s: Unsupported CSP codec type: 0x%04x\n",
428 __FUNCTION__, 426 __FUNCTION__,
429 LE_SHORT(funcdesc_h.VOC_type)); 427 le16_to_cpu(funcdesc_h.VOC_type));
430 return -EINVAL; 428 return -EINVAL;
431 } 429 }
432 p->acc_channels = LE_SHORT(funcdesc_h.flags_stereo_mono); 430 p->acc_channels = le16_to_cpu(funcdesc_h.flags_stereo_mono);
433 p->acc_width = LE_SHORT(funcdesc_h.flags_16bit_8bit); 431 p->acc_width = le16_to_cpu(funcdesc_h.flags_16bit_8bit);
434 p->acc_rates = LE_SHORT(funcdesc_h.flags_rates); 432 p->acc_rates = le16_to_cpu(funcdesc_h.flags_rates);
435 433
436 /* Decouple CSP from IRQ and DMAREQ lines */ 434 /* Decouple CSP from IRQ and DMAREQ lines */
437 spin_lock_irqsave(&p->chip->reg_lock, flags); 435 spin_lock_irqsave(&p->chip->reg_lock, flags);
diff --git a/sound/oss/midibuf.c b/sound/oss/midibuf.c
index b2676fa346..6982556ded 100644
--- a/sound/oss/midibuf.c
+++ b/sound/oss/midibuf.c
@@ -50,7 +50,7 @@ static struct midi_parms parms[MAX_MIDI_DEV];
50static void midi_poll(unsigned long dummy); 50static void midi_poll(unsigned long dummy);
51 51
52 52
53static struct timer_list poll_timer = TIMER_INITIALIZER(midi_poll, 0, 0); 53static DEFINE_TIMER(poll_timer, midi_poll, 0, 0);
54 54
55static volatile int open_devs; 55static volatile int open_devs;
56static DEFINE_SPINLOCK(lock); 56static DEFINE_SPINLOCK(lock);
diff --git a/sound/oss/skeleton.c b/sound/oss/skeleton.c
deleted file mode 100644
index 8fea783dd0..0000000000
--- a/sound/oss/skeleton.c
+++ /dev/null
@@ -1,219 +0,0 @@
1/*
2 * PCI sound skeleton example
3 *
4 * (c) 1998 Red Hat Software
5 *
6 * This software may be used and distributed according to the
7 * terms of the GNU General Public License, incorporated herein by
8 * reference.
9 *
10 * This example is designed to be built in the linux/drivers/sound
11 * directory as part of a kernel build. The example is modular only
12 * drop me a note once you have a working modular driver and want
13 * to integrate it with the main code.
14 * -- Alan <alan@redhat.com>
15 *
16 * This is a first draft. Please report any errors, corrections or
17 * improvements to me.
18 */
19
20#include <linux/module.h>
21#include <linux/delay.h>
22#include <linux/errno.h>
23#include <linux/fs.h>
24#include <linux/kernel.h>
25#include <linux/pci.h>
26
27#include <asm/io.h>
28
29#include "sound_config.h"
30
31/*
32 * Define our PCI vendor ID here
33 */
34
35#ifndef PCI_VENDOR_MYIDENT
36#define PCI_VENDOR_MYIDENT 0x125D
37
38/*
39 * PCI identity for the card.
40 */
41
42#define PCI_DEVICE_ID_MYIDENT_MYCARD1 0x1969
43#endif
44
45#define CARD_NAME "ExampleWave 3D Pro Ultra ThingyWotsit"
46
47#define MAX_CARDS 8
48
49/*
50 * Each address_info object holds the information about one of
51 * our card resources. In this case the MSS emulation of our
52 * ficticious card. Its used to manage and attach things.
53 */
54
55static struct address_info mss_data[MAX_CARDS];
56static int cards;
57
58/*
59 * Install the actual card. This is an example
60 */
61
62static int mycard_install(struct pci_dev *pcidev)
63{
64 int iobase;
65 int mssbase;
66 int mpubase;
67 u8 x;
68 u16 w;
69 u32 v;
70 int i;
71 int dma;
72
73 /*
74 * Our imaginary code has its I/O on PCI address 0, a
75 * MSS on PCI address 1 and an MPU on address 2
76 *
77 * For the example we will only initialise the MSS
78 */
79
80 iobase = pci_resource_start(pcidev, 0);
81 mssbase = pci_resource_start(pcidev, 1);
82 mpubase = pci_resource_start(pcidev, 2);
83
84 /*
85 * Reset the board
86 */
87
88 /*
89 * Wait for completion. udelay() waits in microseconds
90 */
91
92 udelay(100);
93
94 /*
95 * Ok card ready. Begin setup proper. You might for example
96 * load the firmware here
97 */
98
99 dma = card_specific_magic(ioaddr);
100
101 /*
102 * Turn on legacy mode (example), There are also byte and
103 * dword (32bit) PCI configuration function calls
104 */
105
106 pci_read_config_word(pcidev, 0x40, &w);
107 w&=~(1<<15); /* legacy decode on */
108 w|=(1<<14); /* Reserved write as 1 in this case */
109 w|=(1<<3)|(1<<1)|(1<<0); /* SB on , FM on, MPU on */
110 pci_write_config_word(pcidev, 0x40, w);
111
112 /*
113 * Let the user know we found his toy.
114 */
115
116 printk(KERN_INFO "Programmed "CARD_NAME" at 0x%X to legacy mode.\n",
117 iobase);
118
119 /*
120 * Now set it up the description of the card
121 */
122
123 mss_data[cards].io_base = mssbase;
124 mss_data[cards].irq = pcidev->irq;
125 mss_data[cards].dma = dma;
126
127 /*
128 * Check there is an MSS present
129 */
130
131 if(ad1848_detect(mssbase, NULL, mss_data[cards].osp)==0)
132 return 0;
133
134 /*
135 * Initialize it
136 */
137
138 mss_data[cards].slots[3] = ad1848_init("MyCard MSS 16bit",
139 mssbase,
140 mss_data[cards].irq,
141 mss_data[cards].dma,
142 mss_data[cards].dma,
143 0,
144 0,
145 THIS_MODULE);
146
147 cards++;
148 return 1;
149}
150
151
152/*
153 * This loop walks the PCI configuration database and finds where
154 * the sound cards are.
155 */
156
157int init_mycard(void)
158{
159 struct pci_dev *pcidev=NULL;
160 int count=0;
161
162 while((pcidev = pci_find_device(PCI_VENDOR_MYIDENT, PCI_DEVICE_ID_MYIDENT_MYCARD1, pcidev))!=NULL)
163 {
164 if (pci_enable_device(pcidev))
165 continue;
166 count+=mycard_install(pcidev);
167 if(count)
168 return 0;
169 if(count==MAX_CARDS)
170 break;
171 }
172
173 if(count==0)
174 return -ENODEV;
175 return 0;
176}
177
178/*
179 * This function is called when the user or kernel loads the
180 * module into memory.
181 */
182
183
184int init_module(void)
185{
186 if(init_mycard()<0)
187 {
188 printk(KERN_ERR "No "CARD_NAME" cards found.\n");
189 return -ENODEV;
190 }
191
192 return 0;
193}
194
195/*
196 * This is called when it is removed. It will only be removed
197 * when its use count is 0.
198 */
199
200void cleanup_module(void)
201{
202 for(i=0;i< cards; i++)
203 {
204 /*
205 * Free attached resources
206 */
207
208 ad1848_unload(mss_data[i].io_base,
209 mss_data[i].irq,
210 mss_data[i].dma,
211 mss_data[i].dma,
212 0);
213 /*
214 * And disconnect the device from the kernel
215 */
216 sound_unload_audiodevice(mss_data[i].slots[3]);
217 }
218}
219
diff --git a/sound/oss/soundcard.c b/sound/oss/soundcard.c
index a686be936a..95fa81e26d 100644
--- a/sound/oss/soundcard.c
+++ b/sound/oss/soundcard.c
@@ -681,8 +681,7 @@ static void do_sequencer_timer(unsigned long dummy)
681} 681}
682 682
683 683
684static struct timer_list seq_timer = 684static DEFINE_TIMER(seq_timer, do_sequencer_timer, 0, 0);
685 TIMER_INITIALIZER(do_sequencer_timer, 0, 0);
686 685
687void request_sound_timer(int count) 686void request_sound_timer(int count)
688{ 687{
diff --git a/sound/oss/sys_timer.c b/sound/oss/sys_timer.c
index 6afe29b763..c9d04518b1 100644
--- a/sound/oss/sys_timer.c
+++ b/sound/oss/sys_timer.c
@@ -28,8 +28,7 @@ static unsigned long prev_event_time;
28 28
29static void poll_def_tmr(unsigned long dummy); 29static void poll_def_tmr(unsigned long dummy);
30static DEFINE_SPINLOCK(lock); 30static DEFINE_SPINLOCK(lock);
31 31static DEFINE_TIMER(def_tmr, poll_def_tmr, 0, 0);
32static struct timer_list def_tmr = TIMER_INITIALIZER(poll_def_tmr, 0, 0);
33 32
34static unsigned long 33static unsigned long
35tmr2ticks(int tmr_value) 34tmr2ticks(int tmr_value)
diff --git a/sound/oss/uart6850.c b/sound/oss/uart6850.c
index be00cf1286..74ae75f9e2 100644
--- a/sound/oss/uart6850.c
+++ b/sound/oss/uart6850.c
@@ -78,8 +78,7 @@ static void (*midi_input_intr) (int dev, unsigned char data);
78static void poll_uart6850(unsigned long dummy); 78static void poll_uart6850(unsigned long dummy);
79 79
80 80
81static struct timer_list uart6850_timer = 81static DEFINE_TIMER(uart6850_timer, poll_uart6850, 0, 0);
82 TIMER_INITIALIZER(poll_uart6850, 0, 0);
83 82
84static void uart6850_input_loop(void) 83static void uart6850_input_loop(void)
85{ 84{